Embedded - 190: Trust Me, I'm Right (Repeat)
Episode Date: May 7, 2020Matt Godbolt (@mattgodbolt) spoke with us about settling arguments with Compiler Explorer. March Micro Madness is here! Compiler Explorer comes in different flavors: https://rust.godbolt.org/ http...s://d.godbolt.org/ https://go.godbolt.org/ https://gcc.godbolt.org/ You can see the beta version by putting a beta on the end:  https://gcc.godbolt.org/beta/ This a fully open source project. You can read the code and/or run your own version: https://github.com/mattgodbolt/compiler-explorer https://github.com/mattgodbolt/compiler-explorer-image Matt works at DRW working on low latency software. Note that DRW is hiring for software engineers. You can read about the evolution of Compiler Explorer on their blog. Matt’s personal blog is xania.org. You might like parts about 6502 Timings. He also has several conference talks on YouTube including x86 Internals for Fun & Profit and Emulating a 6502 in Javascript. Matt was previously at Argonaut Games. Jason Turner of C++ Weekly and his C++17 Commodore 64 Could a Neuroscientist Understand a Microprocessor? paper (with a nod to Don’t Panic GeoCast’s Fun Paper Friday) Â
Transcript
Discussion (0)
Welcome to Embedded. I'm Eliseo White with Christopher White. Our guest this week is
Matt Godbolt. We talked about his Compiler Explorer projects a few weeks ago, and now
he's here to answer our questions. Before we get started, I want to tell you about march micro madness this is a silly
little thing where we compare all of the different embedded platforms try to figure out which one is
the best to give in completely arbitrary criteria yeah it's pretty silly so if you want to check it
out please look on embedded.fm slash blog or check the Twitter feed or, I don't know, email me.
I'll send you a bracket.
It'll be fun.
Please get your notes in by the 15th of March.
After that, we will start telling you all the answers.
Now let's get to Matt.
He can tell us all the answers.
Hi, Matt.
May I say your name is the name I would like to have?
Thank you. Hi, Alicia. Hi, Chris. Yeah, my name has done me very well. It's a very memorable thing.
Can you tell us a little about yourself?
Sure. So I'm a software engineer at a trading company in Chicago, where I work on super cool
low latency stuff in C++ on a variety of interesting
hardware and software. Some of it is more embedded-y type stuff than others. Others is just
boring servers. My employer would like me to note that we are hiring. And so if you're interested in
anything I talk about today, drw.com slash careers will get you to our hiring page. So I've been at
for six years. Earlier, prior to that, I used to work at Google
where I made the YouTube mobile app or worked on it. And then I spent about 13 years making computer
games before that. And in my spare time, I make a website that we're probably going to talk a little
bit about. And I also like emulating old computer game hardware like the Sega Master System and things like that.
The computer games. That was for Argonaut?
Correct, yes.
What games might we have heard of?
Well, that's always the embarrassing question that I get asked at dinner parties and things whenever I bring out the, oh, I used to work in computer games. Oh, cool. Anything I've heard of?
And you're like, well, probably not because I'm a lot older than I look and it was a long time ago so this was uh the games that I worked on the most um no well-known
game was a game called croc legend of the gobos which yes I I take from the blank sound from your
end that you're kind of going that doesn't sound familiar to me it was it came out around the same
time as uh mario 64 and it
was the playstation's answer to mario 64 as a little crocodile running around and stuff which
was pretty cool but it was in like 1996 i think um i've also worked on one of the swat games which
are well known as a genre but i'm almost certain that you never have seen the game that i worked
on which was one for the original xbox um i worked PSP games, Manhunt, and Dreamcast game.
Oh, look, the Dreamcast.
Nobody seemed to ever have them.
That's my favorite console of all time.
But yes, again, if I say, oh, I worked on a Dreamcast game, most people look at me now and go, what's the Dreamcast?
Every once in a while, I'll say I wrote a book.
And they'll say, have I heard of it?
And I'll be like, no, no, really, you never have.
I've heard of your book.
I'm looking at the Wikipedia page.
There's like 30 games on here that they did.
This is a lot of stuff.
Star Fox, the original Star Fox.
That was before my time, sadly, although I worked with some of the engineers there.
And one of my more interesting claims to fame is that because of our connection with nintendo so we were kind of like the uh the developers of the super effects
chip at the time oh right the royal we um the company that i worked for had um worked on the
super effects chip it was their sort of idea um because of that connection with nintendo um when
uh when the nintendo execs used to visit they would pop into the office and say hi just for old time's sake.
And so at the time, Miyamoto, the legendary designer of Mario
and Zelda, was doing a tour, and I got to play my own game
against him, which is like this most amazing moment ever.
And yeah, it's, yeah.
So I was pretty blessed to work for that company.
So the Super effects chip i just
just a second i want to talk about it it's fine i seem to recall it it was like a graphics chip
that was jammed into a cart like the game cartridge that's my understanding yeah it's like
um so around the same time um like the amigas and the ataris were around and they had like dedicated
um hardware for blitting memory right that kind of stuff so it
wasn't much more than that i think it had something like six or seven different op codes
and but yeah it because there was a cartridge format you could put extra hardware on the
cartridge and i'm still not clear how it was able to kind of i don't know take control of the bus
or do whatever it did to actually like go from being a passive ROM that
presumably the rest of the cartridge was into something which was proactively pushing data
back down into the display hardware but evidently they found a way to do it and and yeah so we we
worked on a few other games that used the super effects chip none of which were as famous as
Star Fox and then ultimately we spun a separate company off, which actually lasted for a lot longer than the, than Argonaut did.
They made the ARC arc processor,
which was used in a whole bunch of like routers and things.
No one's ever heard of it.
I worked on it.
I worked on it.
Sorry.
I think it rings a bell, but not a very loud one.
Right. sure.
All right, well, I'm going to go on to lightning round,
except that lightning round is still on sabbatical.
Last week it didn't even call in or anything.
Rude.
So I hear you have 122 terrible jokes and one interesting fact to tell us.
Yeah, I will save you the jokes.
My children gave me some jokes, but they are so bad. I would feel remiss if your kids didn't get something on
the air. No, it's quite all right, honestly. All right, I'll give you one, one of my children's
jokes. Why did the man throw his clock out the window? Because he wanted to see time fly. You
see, this is the kind of thing I have to put up with um but yeah so my interesting fact
is um i was lucky enough to grow up in the tiny tiny village just outside of london
where the very first computer program was written by ada lovelace that's pretty good that's pretty
good all right we'll go with that so the reason we've asked you on the show was because christopher found this neat website called
uh godbolt.io or godbolt.org i think we should probably get it right
seeing as he's on now and it is but i thought that i worked but maybe i'm wrong so
i'm gonna have to buy that domain now aren aren't I? Sorry. It costs you $10 a year just for you.
And it was interesting because he would type in small functions programs
and it would show the assembly using different compilers.
And he spent a lot of time saying,
well, what do you think about this?
What do you think about this?
What if I do this chip instead? Because there were a lot of time saying, well, what do you think about this? What do you think about this?
What if I do this chip instead?
Because there were a lot of compilers.
There was the MSP430, and it sometimes had hundreds of assembly commands where a GCC might have like three.
GCC for x86.
Right.
Yeah.
And so when Chris brought it to me, I was like, okay, that's cool.
Let's talk about it, and then we talked about it for a second,
and then suddenly I'm talking to the creator.
So maybe I should have asked you to describe what Compiler Explorer is. At least you would know the right URL for it.
Well, that's true, but I think you did a better job of describing it than i ever would
i mean so compiler explorer like you say is like a website where you can type in c code um i now
support rust and d and go and i've got a backlog of other languages to support as well and then
on one side you type the code and on the other side you get to see what happens after the compiler
has had a go at it and generated assembly. And the reason a compiler explorer was created
was kind of an argument ender.
It was something that a colleague and I were debating
some of the new features that were coming up
in the C++ programming language about six years ago.
And we're like, well, we can't use this new way
because we're hardcore programmers, we're low-level guys,
we need it to be as fast as possible.
We know what the assembly, ultimately what assembly we would like the compiler to generate,
so we're going to write it in the way that means
that the assembly gets generated the way we would like.
And then we're like, well, maybe we should check.
And we used the new feature, and lo and behold,
the compiler was actually smarter than we were
and was able to generate the instruction stream
even when we wrote it in a much more readable way
than the way that we would have traditionally written it.
So it kind of opened the door to like,
hey, maybe we should spend more time
looking at what this compiler is doing for us,
the kind of things it does behind the scenes,
the kind of things it's good at,
the kind of things it gets wrong.
And what started out as a sort of small shell script
that ran the compiler and then
piped it through about 10 or 11 different sort of filtering and cut commands in Unix, and then
spat it out in a little terminal window, quickly grew into being a website to do exactly the same
thing. A website implies a lot more than a shell script. I mean, this is a server and a web page, and it's nicely formatted.
I don't really have any idea how it'd go from, okay, I have a nifty shell script to a web server that people complain about when it's not up.
Yes, quite.
It goes one step at a time, like all these things.
I didn't plan for it to become as big as it is and to have as much traffic as it does.
I was scratching my own itch.
And for a long time, it ran, well, for a few months,
it ran just on a node in my company, just inside our own intranet.
And yeah, I mean, I've had some experience of JavaScript development before.
And I've had some experience with Node.jsjs just as like tinkering on things.
And so putting together a open source,
like JavaScript widget that knew how to edit C++ type code
was easier than I thought.
You know, you Google for it, you find something,
you whack it in a webpage.
Then putting a little handler that says,
anytime it changes, post it to this URL.
And then on the other end of that URL, you basically paste together your shell script and put it into the
node server and then post back the results. And then, you know, you format it on the other side
of the page. And so it's only a few hundred lines of code to start with. And then it starts to grow.
And then you start putting in your features and then you get permission to open source it. And
you put it on the outside world and you run it on your home computer and
then your adsl isn't fast enough and then you you go onto the amazon free tier and start running it
uh in the cloud and then you start getting hit by hacker news and then you start spinning up more
and more instances and then before you know it you're spending a couple of hundred bucks a month
on various bits and pieces to keep the thing running but it's been hugely
rewarding i i love it it's um it's it's amazing how many people seem to be using it for teaching
which i think is probably the best use for it i i people seem to be too frightened of what goes on
underneath the code they're writing um maybe not so much in the embedded world because i think you're
that much closer to the metal but certainly if you're writing C++ for large applications, it's like you feel like two or three tiers removed from what's really happening.
And you don't really need to understand.
And I would say that you always need to understand what's going on underneath you.
And to have some understanding of what the machine code does is, I think, super important, even if you're not writing some low latency
program. And so to have that immediacy, I think, is super important. Yeah, I think the immediacy
is really key because you can always look at the list file, right, that comes out of a compiler,
but it's a bit tedious and, you know, you have to go do it and this allows you to make changes on the fly and see
things instantly. Uh, I think that's really helpful for it. Like you said,
education.
How often do you find yourself writing a function that you think, well,
maybe this should go in a new file or maybe it should be a new header file or
whatever. And you think to yourself, but if I make a new file,
that takes a while that I have to add it to the make file or my build system. And then I have to like add it to source control or whatever. I'll just
put it in the top of this file. And so, you know, it's very easy to kid yourself into doing the
wrong thing about, you know, either software design in this case, or, you know, asking yourself,
well, I wonder if I wrote it this way or this way, and when you write it and then you build it,
then you look at the list file and then you turn it around,
it doesn't feel as natural as just typing away in a website
and just having it there.
The immediacy is really important.
And if you've ever used a language that has a REPL,
you know, like the Pythons of this world,
the Rubies, even JavaScript,
you know, that kind of tinkering feel
is kind of lost in C++ and C.
And this kind of brings it back i feel i mean
there are there are other just just to be fair there are other online compilers out there um i
don't think any of them show the disassembly of what you're doing some of them execute the code
which is cool but they all kind of have this ide feel where you type in the code and then you have
to press a button and then you have to wait like five or six seconds for it to be posted off and
come back to you and while that's valuable and and is useful to be able to share links to other people
to say like hey this is what happens when you compile this code and see the output um the real
beauty i think of something like compiler explorer is this tinkering this this sort of moving around
and going well what happens i make it unsigned does that change the compiler output oh it does
that's interesting i wonder why. I also think,
when I was playing with it, I tried obvious stuff like, okay, let's see what happens
when I throw volatile on here.
What does the compiler do?
Oh, it stops optimizing.
Panic!
It produces worse code because now it can no longer
make certain assumptions about this variable.
And then just simple stuff like,
what's a postfix operator versus a prefix operator. How does that change things?
Because that's kind of confusing sometimes for people, especially when it's in a loop or
conditional. Right. And, you know, people who've been programming C++ for a long time have kind of
been beaten into them that pre-increment is the right way to do things. You know, like,
for i equals zero, i is less than foo, plus plus i is the way to write your loop. And you kind of
forget why. Exactly. Somebody new comes in and says, you know, someone for i equals zero, i is less than foo, plus plus i is the way to write your loop. And you kind of forget why.
Exactly.
Somebody new comes in and says, you know, someone out of school says,
well, why do you write your loops that way?
I'm like, I don't know.
I just, I guess, oh, yeah, I forgot that there was this reason why.
I wonder if it still holds.
And you kind of copy paste your code into it and go, oh,
I guess it doesn't matter if I do i plus plus or plus plus i.
It's the same.
Now, it didn't necessarily used to be the
same yes and I say that because I spend most of my time at the pretty much the cutting edge of
the compiler spectrum so I'm using you know newer versions of GCC newer versions of Clang and I'm
using x86 where a lot of effort has been placed on it and i'm turning the optimization levels up really
really high in conversation with people who are developing on embedded systems i've discovered
that oftentimes they ship without even optimizing because the debuggability goes away and a lot of
these kind of these sweeping statements that i'm making about like oh you can use all the new
features in the language and they're free turn out not to be true if you don't allow the compiler to
do some level of optimization it's a constant out not to be true if you don't allow the compiler to do some level of optimization.
It's a constant battle too, because
if you don't turn optimization on,
you can run out of space.
You have to weigh the debug
ability against that.
But the optimization question is actually another big one
because that can be
a mystery for people.
They just crank it up to 03 or whatever.
What does that
mean and i found when i was playing with this that i could produce some really simple code
and turn the optimizer way up and i would get assembly this is like what is it doing it's just
amazing really smart stuff that i you know i had to pull out a pad and paper i think i had a simple
example just a case switch statement where it was like uh three cases and it
would check an integer against an integer and then it would like add something to it if it was you
know the various cases and for one of the compilers it did this weird short circuit thing where it
combined three of the cases into one but not the other it was just crazy but that's that's the kind
of stuff that you don't really see unless you're looking at the assembly your code produces all the time.
Right, right.
This would be a good interview question.
I mean, they make us write stuff on whiteboards for interviews.
Instead, we should have to write it down and then put it through the compiler explorer and explain the assembly.
I'm not sure I could sometimes.
That's harsh.
That's harsh.
I have to Google everything. One of the bigger
things on my to-do list is to actually have like tool tips over the assembly language so that it
can actually tell you what the heck each instruction is because I don't know. Now, yes, exactly. You'd
have to. And particularly as Chris says, if you turn the optimizer up to like 11, then you suddenly
get all these crazy, strange architectural things. And you're like, what is that?
Oh, okay, that's the lesser known instruction
that does this really weird thing.
Okay, but that happens to be useful here.
Although one of the compilers in particular,
Clang has got some amazing optimization.
So a friend of mine was demonstrating
that if you write a small function
that effectively sums all of the numbers up to n,
Clang is smart enough to back that out to the closed-form solution
if you can prove it won't overflow, which is mind-blowingly clever.
Yes, I saw that too.
Isn't that amazing?
You know, n plus 1 over 2 or whatever it turns out to be.
And it's like, yep, I'll just do that.
And you're like, you've taken away my loop.
Where's my loop gone?
You don't need it.
But how often do you need to do that and you're like you've taken away my loop where's my loop gone you don't need it yeah but how often do you need to do that such that it's worth writing a compiler with that level
of complexity it's the beauty of open source anyone can add their own little rules and pattern
matches to to clang and if it if it fires on your sequence of operations then then great i mean
maybe it'll save one person a few cycles one day.
Yeah, how much stuff it just short-circuited to nothing was amazing.
Commonly, I get little emails off of people saying,
oh, I tried this on your Compiler Explorer,
and all I get is a RET instruction.
Exactly, yes.
I'm like, yeah, because you're not doing anything,
and you've turned the optimizer up to the highest setting.
Up to 11.
Sorry, I said 11 before.
03 is usually the highest you can put it on.
So one of the things I found really fun was actually deciding,
okay, what do I have to do to trick, not trick it?
A little bit, yeah, I guess.
How do I trick the compiler to stop optimizing something away?
So take it to... You mentioned volatile is one, but that turns off everything.
But like some of the closed form things, like you mentioned,
I noticed that happening a lot.
It's like, okay, how far do I have to change this
before it doesn't figure it out?
And it was actually, I mean, it was really hard in some cases.
You had to really say, you know, make it so it couldn't figure something out.
Right, right, right.
It is really difficult.
I mean, and obviously I'd like to sort of say something
about like optimization and stuff,
which is what we use it for as well.
It's like, is this faster than whatever?
Just looking at the assembly code
is not always a great indication
of how much faster or otherwise something's going to be.
Particularly on x86,
where there's a million clever things going on,
even underneath the layer of the the
assembly instructions you know the microcode and whatever but the same kind of problem arises when
you do benchmarking of code so obviously if you're trying to benchmark two pieces of code um is it
fast to do x or y by actually measuring the speed of it the compiler can just as easily throw away
all the code and you'll end up compiling you know comparing an empty ret
instruction with another empty ret instruction so there are similar tricks that you have to know
um for like writing micro benchmarks as you do for like compiler explorer snippets and you know
in the case of gcc usually you use some kind of crazy empty asm statement which is enough to make
gcc freak out that it can't um assume um anything before or after the asm statement has uh hasn't
changed and that kind of prevents it well one of the other things is looking at different
what that this makes easy is uh looking at different instructions that architectures yeah
oh my gosh incredible i mean it's like okay x86 wow it's you know they have you know
instructions that probably to the equivalent of 90 instructions on MSP430.
Right.
And it has ARM.
Yeah, it was not just the optimization of the compilers, which I found pretty interesting.
But it was the way the different chips, the assembly tells you a lot about what the chip is doing.
Absolutely. There's not much to hide in those instructions it's it's it can be surprising sometimes what does come out i mean one
of my favorite little mini optimizations is um you know pretty much on every piece of hardware ever
divide is the most expensive thing you can do um some chips don't even have a divider and then and then they come out with the
with the cortex m4f and a divide is like one instruction and i i i suddenly am losing all
of these arguments that i had ever had what is it doing how does it do does it have like a
four billion entry lookup table no it'd have to be four billion by four billion
i don't remember how many clocks it is but it's very comparable to it's very fast it was ridiculous
and terrifying
even Intel
Intel's are like
anywhere between 90 and 120 cycles
and it's not pipeline
so like everything else on the Intel
is like oh it's a one cycle thing
but you can do three of them at a time
and you can start the next one
on the next clock cycle
which is like a third of a nanosecond
it's insane
and yet you hit divide
it's like oh this is the one and only divide
that can happen on this CPU for the next 100 cycles.
You're like, what?
And of course, everyone's favorite data structure
is a hash map.
And what does a hash map do?
You kind of, you hash your thing
and then you modulus it by the size of the table.
And a modulus is just a divide in plain clothes.
And so suddenly you're like,
well, this is kind of important.
Why are you not spending more time making the divide fast?
But the point of that was that if you divide by a
constant this compiler is smart enough to go well you know what i can do here is i can multiply by
the reciprocal i can work out the reciprocal beforehand and i'll multiply by do some magic
shifting to account for um like overflow underflow kind of things or rounding and boom there you go
it's like well that's five cycles that's much better yes and, and you have your little square function as the demo in Compiler Explorer.
If you go in, it just returns num times num.
And I added in a divide by 93.
And looking at the different ones,
yes, the GCC for x86 split that into a number of constants
and tried to do the best it could to make that smarter and
um avr gcc calls 97 library and functions in order to get it done which is sort of embarrassing for
it i just i love the idea that these are are separate they're all doing the same thing but it in such different ways right there's yeah and
in fairness the some of the embedded compilers i've got on there are somewhat out of date now
and that's kind of my third other part-time job is just building um compilers finding space for
them on on amazon and making sure they work and and you know, compilers are big pieces of code
and they're really complicated to configure.
And Clang is lovely.
They seem to have realized that if you make it very,
very difficult to get and build,
then no one's going to help you out.
And Clang has got an amazing community
that are working on it.
And, you know, GCC has too as well,
but almost everyone on GCC seems to be working
for a company that has a very vested interest in the GCC compiler,
whereas Clang has more of a feel of hobbyists can have a little bit of a go on it.
And it makes a huge difference.
You just get Clang and type CMake and make and it's done,
whereas GCC is like, oh, well, run this shell script,
and then, oh, yeah, you need that thing,
and that needs to be configured the right way on this thing,
you need to disable that.
It's a pain, but one of the things that Compiler Explorer
is good for as well is regressions in compilers,
and I've had a number of people link to it.
If I look through the HTTP referrers from bugs
that have been posted both with Clang and GCC,
so people will say, hey, this is bad code,
or this is very suboptimal code.
But look, it used to be fine on these three versions of the compiler.
It seems to have come in on this version.
And it's much easier than checking out and building
all of the different versions of the compiler yourself
if you can rely on Compiler Explorer to have had them for you
and you can look at the assembly output.
Yes, exactly.
Okay, so you said you did this because you wanted to end arguments, and I can totally see how you can do that. Let's not argue about whether the incrementer goes before or after prefix or postfix. Let's try it and see. Have you lost any arguments due to your own creation? I lose them with myself all the time. I can't think
of a, uh, an obvious case where someone has come with to me and shown something, but I'm sure it
has happened. I'm, I'm not that smart. Um, but oftentimes I will, I will make a guess and I've
got into the habit now of pasting stuff in and just, you know, checking my assumptions all the
time, which is, you know, worthwhile in, in anything is to check it is to go back and make
sure that what you believe is true is still true. Um, but yeah, like, you know, range in anything is to check it is to go back and make sure that what you believe is true is still true um but yeah like you know range fours in c++ 11 um was something
i thought would be slower or um you know for i equals zero to vector dot size versus the range
fourth version you know they turn out to be the same code in fact actually i've got a situation
where a range four is slightly faster than the sort of traditional iterating pattern
that one might make over a std vector.
Again, I don't know how much C++ code
gets done in the embedded space,
but if you're using vectors,
probably you're losing
if you're going to be doing dynamic allocations
and all that kind of stuff.
But if you are using something like a vector,
then particularly if you're calling out to another function function i think a lot of people don't realize when you call a function and if the compiler can't tell what
that function is doing i.e it can't look inside the body of that function because maybe it's
defined in a header file somewhere else then it has to assume the worst and even when you're
iterating over a structure it goes well that function i'm calling could easily modify that
structure so i have to check everything again on the way out whereas when you're using a range for over a structure, it goes, well, that function I'm calling could easily modify that structure.
So I have to check everything again on the way out. Whereas when you're using a range for the
range for is designed to take a copy of everything that's pertinent, like how big the thing is
that you're iterating over. And so the compiler knows that it has its own private copy in that
particular instance, and the code comes out slightly better but you have to make a copy first you have to
make a copy but usually that's like a like a for a vector would be the size of the vector and it
just be shoved into a register one of the the the registers that doesn't get whacked by calling a
function by convention and then you know that it's going to be pretty cheap has this made you
better at writing code that generates the assembly you want,
or has it made it so that you care less because the compilers are more able to optimize your code?
That is a great question.
A bit of both, I think.
Where it's really helped me, actually, is in none of these cases.
It's those weird cases where i've noticed a
performance problem in something um at work and then i've pasted the code in and i've been utterly
surprised as to what i've actually asked the compiler to do you know the compiler sometimes
hamstrung by the idiot writing the code um in as much as you're like well why are you doing all
this huge thing and you realize oh i'm passing a 4k array by value. Oh, I should probably not do that.
Or, you know, something like that.
You're forcing some copy to be taken
or you're otherwise just doing something dumb
that the compiler is not smart enough to realize you don't need to do.
So often it's those kinds of things
that I've rather embarrassingly found in my own code.
Do you think this encourages people to write assembly more?
I hope so. I hope so. I mean, the number of assembly instructions I have written in the last six years myself is probably in the low hundreds. And I mean, I've written tons of C++ in my day job. So it's very, very rare that you need to get down and dirty and actually write assembly.
But I think, like I said earlier, the understanding what goes on underneath,
having an appreciation for what the compiler has to do,
first of all, like in terms of what semantically have I asked the compiler to do?
Have I asked it to copy 4K every time because it's going to do it,
even if it's dressed up in some other way that makes it not so obvious that that copy's happening. And then you're underneath that, like, well, in order to do this, what actually does the
compiler need to do? You know, like the hash map, it's like I'm asking it to do a modulus. That's
a divide, but that's tough, right? That takes a while. So maybe there's another way I could do
this if you need the performance. But yeah, so just being able to look underneath and understand
what's going on
and i mean it's turtles all the way down because when i first started on this i was i got more and
more fascinated by um x86 instructions in general having sort of stared at them for so long and i
embarked on a bit of a mission to try and work out well what happens underneath those instructions
what was all this microcode stuff i've heard about and if you start googling around for that
you'll discover that the rabbit hole just keeps going down and down and down and
down and uh the what what's uh what do you think you're seeing on the instruction side of the pain
of compiler explorer is just merely a hint to the processor to actually carry out something that does
the effective same thing that you've asked it to do in whichever way it chooses. It's more like a kind of JIT compiler for x86
into some hidden language underneath the hood.
It's miraculous.
It makes me glad that I work on an embedded system
that these assembly instructions are what it's going to run.
Are you going to work on microcoding Explorer next?
I mean, if Intel would publish them,
I mean, there's a lot of smart people out there
that are doing amazing work to reverse as much as they can
of what's going on.
So there are people that are researching this.
And yeah, there's unfortunately Intel quite reasonably
don't want to tell us what's going on underneath the hood.
That's important to them.
I totally think that looking at the assembly is a good idea but i liked what you said about writing code to generate the
assembly you want and so you can write c code that leads to what assembly your goal is and yet still
be in a higher level language that is generally more
easily maintained. I've done that for some projects where they ask for optimized assembly
code and I say, okay, how about if I make optimized C code that generates optimized
assembly code? And then we're all a little happier here. Right. I mean, that's certainly,
that's my experience. I mean, I grew up writing assembly for like
6502s and Z80s. And I begrudgingly moved to C as a kind of hybrid macro assembler
that was slightly better than the assembler I was using before. And then when C++ became more of a
thing, I sort of went, well, I guess it's convenient to not have to worry about these things. And so I
kind of crawled up another level. And in my heart of hearts, I'm still an assembly hacker. But as I say, I've hardly written any for a while, because
you can get the compiler to generate the assembly you want. But there's a danger there. And that is,
it turns out compiler writers are usually smarter than you are. And if you think to yourself,
I need to divide this number by 100, and you write the divide instruction, you probably have missed a trick where you could have done the reciprocal multiply.
Or you've missed a trick where you would have used a table that was the right size
for the values that the compiler can prove that the function accepts.
And, you know, assembly instructions, writing assembly is a bit like craftsmanship.
You know, you're crafting out by hand absolutely everything.
And it's wonderful and it's beautiful. And you understand how everything fits together. But if someone asks you. You know, you're crafting out by hand absolutely everything, and it's wonderful and it's beautiful,
and you understand how everything fits together.
But if someone asks you to change something, you're like,
wow, we've got to go back and redo everything
because I've assumed the whole way through
that this particular register is going to hold this critical value,
and now I've run out of registers and I have to do something new.
I have to probably throw everything out the door and start again.
Whereas, obviously, if the compiler was smart enough to work that out,
then, okay, you might hit a small speed bump, because the compiler is now going to
do something smarter and have to move everything around itself. But it does it for you.
And it is incredibly detail oriented. And the compiler has a lot more time to think about
optimizations than you do, because that's all it ever thinks about. It doesn't have to worry about
email or your boss walking by. Quite. And he doesn't have to worry about email or your boss walking by.
Quite.
And it doesn't have to worry about the readability of the code,
which kind of comes back to the debugability problem,
which you guys face.
But, you know, that can be moved up and down as you see fit.
But yeah, you can still make sure that the code that you write
is maintainable, is understandable,
is written for humans, really, first and foremost.
And secondarily, you then rely the compiler to do the right thing.
Yeah, because the code you get out of there,
I mean, it may not be in order that makes sense when you read it.
I mean, it might hoist things in various places
and might vector to something that, oh, you know,
it might consolidate code that looks similar to other code and suddenly you're
like, where am I? Why are you doing this? Oh, it's decided that these two things are
the same. So, yeah, it's really hard to be better than, unless you're
really sitting at it and trying to be clever for a long time. Sometimes there's
a loop or two that you have to have super fast response
because you're controlling something
if you're like bit banging something and yes very yeah uh and so that makes sense or after you've
gotten 6k of of audio data and you need to put it into a buffer after filtering it that sort of
thing sometimes yeah you it makes sense if your processor has to do it fast.
Sure.
But, I mean, assembly is so hard to read.
Well, the only other place I've really had to use it is when the compiler, for whatever reason, isn't quite smart enough to use a special instruction or two.
Right.
There's a SIMD instruction or whatever.
Maybe it's out of date by a revision and you can't do it.
It's kind of a bootloader.
I mean, all of my boot tables are in assembly,
but that's just a bunch of labels.
Yeah.
Right, right.
So, yeah, in terms of those special instructions,
most of the time, of course, you do get intrinsics to do it.
But I think you were just about to say that if the compiler is out of date,
then obviously you have to go and use the assembly instruction yourself.
And sometimes, like like special registers as well um aren't modeled very well by um you know msr model specific
registers and things like that aren't modeled by anything in any compiler i'm aware of although
i know people have been layering um like c++ constructs over these kind of things and then
relying on the compiler to be smart enough to optimize them together to then read and write registers in the correct way.
There are certain restrictions on bit fields that you can access
and things like that.
So I feel that there is something to be said
for high-level abstractions that allow you to say,
like, agree the contract of these low-level things.
And if you can get the code to be generated correctly,
then everyone's happy, right?
You get the model-specific register gets written to in the right way,
and you say, oh, let's just turn on the hardware interrupt bit
for this particular peripheral or whatever.
And then you don't have to worry.
Actually, you have to read, modify, write it or something like that.
But sometimes that has to do with having the compiler
exactly set up for your processor.
You support many compilers over many general lines.
I mean, you have an ARM compiler,
but I guess I'd have to put in the compiler options
to get the thumb and Cortex-M4f right uh sorts of things do people constantly want you to
add their compiler and their features um not i mean yes uh that is definitely true i mean i have
a backlog if you go into the github issues you can see how many things are like add new compiler x or
whatever um the majority of the compilers that are up there will have like the target flags to to the GitHub issues, you can see how many things are like add new compiler X or whatever.
The majority of the compilers that are up there will have the target flags to allow you to target.
If it's an ARM compiler, you'll be able to do thumb,
you'll be able to do various cortex families
and things like that, because most of the clangs
and GCCs have, if they're compiled for ARM,
they have most of the processes as a selectable feature.
I'm working on more and more commercial products.
We already have the Intel's x86 compiler up there
for a couple of revisions,
and we've got Microsoft's Windows compiler up there,
which works through...
Oh, wow, I didn't see that.
A horrific set of wine hacks to make it run on Linux.
And there are a couple of other commercial compilers
that I'm kind of working with the vendors to try and get up there. I know there's a couple of other commercial compilers that I'm kind of working with the vendors
to try and get up there
I know there's a C++ compiler
that the embedded world seems to use
and it's got a funny name
Kiel or something?
Kyle
Kyle, right
so that's probably something I should try and work with
to get up there
IAR is the other one
that's either one of
what are those two usually?
those two are the big name C++ ones.
Right.
But I know that from listening to some of your other shows that, you know, C++ in embedded is still something which is fairly nascent.
And there's sort of a divide between the C folk and the C++ folk, or maybe the assembly folk and the C folk as well.
There's not too many assembly folk left anymore.
I mean all the pick people, but
they're all double E's.
We're going to get email on that one.
Wow.
We're seeing a little bit more
C++ and we've had discussions
about it, but it's
resource hungry if you turn on all the
features and do all the stuff that
traditional C++ programmers like to do. But there's features that i i like from c++ that are perfectly
usable um right like constexpr in the latest sort of c++ um say 14 and 17 um which is which was i
think c++ 17 for those who follow this stuff was ratified man last night um at kona they were there
was a committee meeting and they ratified it and And so you should see that coming out soon.
I believe Clang 4.0 is going to be out in a week or two's time
and it will support everything that they've agreed, which is just incredible.
I know, they're great.
The Clang devs are mental.
They go to the committee meetings and then in the evenings,
they go back to their hotel and they work on the features that were agreed that day.
They're animals. It's amazing.
So kudos to them.
But yeah, so constexpr.
Constexpr is something which can be provably compile-time evaluated.
And I think for the embedded space,
that is going to be an invaluable thing.
Back in the day when I was writing 6502 demos,
you'd want, well, I need a sign table over here so you'd end up like writing some code to write to create a sign table
and then you'd write it out to disk and then you would then read it back in again as like a binary
blob and all that kind of stuff it's like now you could write a function which was like okay this is
how i do a sign it's a constexpr function so the compiler can evaluate it at compile time and then
i'm going to have an array which is the size of my sign table. And I'm going to say, well, I'm going to initialize it again
in a constexpr way.
And lo and behold, I'm going to have just a sign table
that's in a place that I can get access,
you know, stuff like that.
I love that.
There's a guy who does, a friend of mine, Jason Turner,
who does these videos where, like,
demonstrating C++ features.
And he has done some mental stuff where he's taken
the output of the
compiler and he kind of post-processes it
to generate 6502 assembly
he's written a Commodore 64 game
using C++17
constexpr stuff to generate
all of the assets
and the whole game and the register accesses
and the screen accesses and everything
cross-compiling it to just a regular 6502,
and then he runs it on a real Commodore 64.
So he's trying to show the point,
prove the point that you can cram onto a computer
with extremely limited resources some amazing things,
and you can use all the latest features of C++
and still not have to worry
about running out of memory or
using
too much CPU time
to...
It was enough for him to write a game.
Do you have a link?
Has he published that anywhere?
Yes, I think it was...
That one was on a CppCon video,
so I'll make sure you have that
for the show notes.
Cool.
Wow.
I mean, there's so many.
Well, I'm just glad that people are still,
there's still progress being made,
and while we're all stuck in C and being curmudgeons.
But this constexpr thing sounds really cool
because it's making the compiler do my work for me.
Yes.
Being the lazy creature I am, I would rather the compiler did as much of the work for me as possible.
And it's probably going to be less buggy than if I hand do it.
I just, okay, yeah, checkbox that one.
You can keep polymorphism though, frankly.
I will have that in 2037. Thatism though. I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I,
I, keep those two you you mentioned github um because this is an open source project you you made it uh
in part for yourself a little bit for your company but mostly for yourself and then you just said okay
you know everybody should get to use it and once everybody started to use it you said
well heck why don't you all make your own is that the path to open source or was it open source the whole time?
I mean, yeah, it was.
So yeah, I developed it in-house
for only a few weeks
before I thought this has more legs than that.
And just by default, I put it on GitHub.
And people do bring it down
and use it locally
because people have their own compilers and things.
And I've tried to make it as easy as possible
for you to just git clone the source and then basically just type make and it should
in theory just work.
I'm aware that the Google compiler team
use it themselves. I had an ex-colleague
from there email me and say I can't walk down the corridor where the compiler team are
without seeing your website up on all of their monitors as they're
tinkering and changing optimizations in the compiler themselves, which was, you know, hugely
rewarding to hear. And as I said before, you know, people quoted in bug reports for compilers. It's
pretty awesome. And it's great that you're making so much money from it absolutely well i have now got a patreon thing so i was nagged and nagged for putting a donate button
on there and i have sort of certain feelings about what uh my site is and it's for me and
it's not really for anyone else and whatever but then people say look people rely on your site now
we need it to be up how can we make sure it's up and i'm like well i suppose as long as the amazon
bill's covered and they're like cool all right put a patreon link up and i did and
you know i said it cost me you know something like 70 bucks i think it's like the the level
running rate when i'm not having to renew things and um i'm embarrassed to say i have like three
times that being donated currently and it's staggering And I'm not quite sure what I'm going to do with this,
with this money,
but,
um,
hopefully it will allow me to,
yes,
exactly.
I can throw a party.
I'm thinking I need to get like,
so I still have friends in the games industry and I would like them to like
design me some cool logos and things.
And then I can send people out some,
some t-shirts or some like stickers or things like that.
But that's about the best thing I can think of to do with it.
Well, and it gives you impetus to continue working on it.
It gives me guilt that I'm not working on it.
Well, okay, I didn't want to say it that way, but yes.
It gives you a little bit of cash to go to a conference
that you might not be able to afford,
and yet you might meet people there who could either help
or who are using it.
Be glad you built something people want to help, want to contribute to.
Thank you.
That's a really nice way of putting it.
You've allayed my fear slightly.
It was hard for us too.
This is a therapy session, right?
This is going pretty well.
Thank you, guys.
None of this will air.
Just lean back on the couch.
All right.
Tell me about your mother so in your github repo i saw and you mentioned earlier you have rust and d and go as alternative
languages do you use any of those not really sounded kind of accusatory it was i didn't mean
it do you use any of that stuff do you? Do you cheat on C++ with these other languages?
Oh, God.
It was going to go to, should I be interested in any of those?
So maybe I was already setting up to, why would I bother?
I mean, yes.
Yes, you should be interested in those languages anything that challenges the dominance of c and c++ is like the the one and
only uh systems programming language is is worth um a look at and i'm i'm not sure but i would not
be surprised if the reason c++ 11 and 14 and 17 have started coming out back to back in the sort
of sudden movement forward in that um that space is because of the competition suddenly we have
competition go came out d has always been around a little bit and then you know rust is probably
the number one competitor for like a real systems programming language where you don't have to worry
about a garbage collector you don't have um uh any kind of big library, systems library that comes alongside it.
And I've been watching Rust pretty closely.
In my view, it's an interesting difference from C.
I mean, the thing about C is that you can take all sorts of shortcuts,
dangerous or otherwise, and it's kind of caveat emptor.
You've made the mistake yourself.
You break it, you get to keep both pieces.
With Rust, if it comp compiles it almost certainly works and in c it's that's not true if
it compiles i mean you know there's the five steps isn't it does it compile does it link does it
core dump immediately and then does it actually do what you want it to do and that's only four
steps sorry four steps of compiling your program and getting it working. Whereas with Rust, yeah, if it builds,
then you probably don't have any data races.
You probably aren't doing anything
where you're modifying something
which you otherwise assumed was immutable.
And that's wonderful,
but it does mean you're fighting the compiler quite a lot.
And if you're used, like me, to just going,
well, I know when I can relax the constraints
because I know by construction,
my program at initialization does these things and never does them again and i know that there's
single threaded at that point and then it becomes multi-threaded later on say it's hard to explain
that to the compiler say look look look i'm i trust me i'm right this time the flip side is of
course is when that isn't true anymore you don't get told that in c you just find out the hard way
that you've got a horrible data race and a core dump and you've scratched your head for three weeks
trying to work out what on earth went on.
So Rust, I think,
is probably the best candidate so far.
D is interesting too.
It does generate some interesting code
and it can be pretty performant,
but I think I have an allergy to garbage collection
and I just don't like it when i have like an allergy to garbage collection um
and i just don't like it when my cpu time gets taken away from me by something that's actually
in my own process yeah i noticed you don't have swift i do not have swift that's a good point
um does swift even run on a non-mac it does swift.org uh ubuntu there's two ubuntu uh downloads yeah thanks chris
now i've got another thing sorry my to-do list file a bug report yes actually i do i do said i
have the world's worst memory the proper response is chris just do it yourself there's a github
patch is welcome yeah it's true i mean some people in like so the d community actually have
there's a couple of guys
in the d community who have picked up on like the administrivia of um adding new compilers and
things so like as well as the the github that actually sort of holds the code for compiler
explorer there's a separate github which has like the the magic shell scripts and the aws config and
everything to actually run uh the site and all the the Docker images and other sort of buzzword-y type web-sounding things.
So I accept pull requests on that,
and so people can actually add compilers
by just effectively adding yet another line
to the download all the compilers.sh file.
And then another pull request in the other one,
which is like, here's the live.config file,
then I will just add this path to, you know,
ops compiler explorer, new compiler.exe.
And that's been really quite nice.
And I've been able to point people now at that
when they nag me and say, can you please add this compiler?
And say, well, here's a pull request that added these other compilers.
Maybe you just use that as a template.
And then all I have to do is come down in the morning
and press click my button on my computer and magic happens
and the images get rebuilt and the website gets updated with a new compiler
it must be what being a manager feels like oh please don't say that so i have one more turned
away from a therapy session into some kind of something else i have one more feature request
while i'm while i'm making a pertinent please. Please, go for it. Are you familiar with Visual Studio Code?
Yes, I am.
Would it be possible
to make an extension so that I could
select a function and have it
go to here and then
have it show up in a VS Code window right next
to my... I want to integrate this with my
IDE. I actually was wondering, I mean
it is open source, but
I can imagine wanting to do that for a number of different IDEs. I don't know how that infrastructure works on their side. And there's nothing to stop you from adding something
to Visual Studio Code as well.
I don't use it myself, but I have added a relatively recently,
I added an API endpoint that's like a public API endpoint.
So you can even just run a curl command
with a tiny bit of C code or whatever code
and have it just post back a text representation of the output.
But it also supports JSON. So you can get all the colorization and not the colorizations,
some of the information that the website uses itself to actually show the code. So in theory,
you could use that or you could just pop up a web view with the right things in there. And if people
want to have requests for how to do that better, then um then sorry on my side that is how i can make
it easy for people to like post a snippet of code and get back like a fully formed web page of
the results then i'll be all ears and in fact actually if you go there's a beta version a
hidden beta version of the site um not hidden anymore of course um if you go to any of the um
the the addresses you know gcc.gobble.org or d.gobble.org or so on,
slash beta, then you get the new version,
which is the thing I'm working on right now,
a whole bunch of UI modifications
so that you can actually have multiple source code up at run
so you can, like, compare side by side
two different versions of maybe the same function
rather than the tricks you have to do at the moment.
And there's a diff view as well,
so you can actually run a diff of the two compiler outputs side by side
and sort of see like which op codes changed.
And obviously that only works when the changes are very small.
If the compiler decides to completely rewrite the thing,
then it's a big mass of red and green.
But it's kind of an interesting way of showing,
okay, look, these two things are identical,
except for that one instruction,
which is like a sign extension instruction,
which got added in because of use to sign value or that kind of thing um and the the
thing that ties that back into what you were saying about visual studio code is that now uses a new
widget to display the c++ code on or the rust code which is actually the same widget that visual
studio.code uses they've open sourced that microsoft the changed company that it has become
have now open sourced the monaco editor that's the the kind
of the editor that they use inside visual studio.co so it's uh it's a really nice editor it supports
a whole bunch of like auto completes and things and as time ticks on i'm sure it will get better
and better so if i understand properly matt just told chris to build it himself yes and
and have a good time with that, right?
That's fine.
That's pretty much it, yeah.
I'll add it to my list of other projects that I haven't started or finished.
Yeah, I heard on one of your other episodes that you maintain a list of things to feel
guilty about that you aren't working on.
It only continues to get longer.
And it's the back of that one.
You do have a pretty long GitHub request list.
One of the things that I saw in there was improved security.
Oh, that's a good question.
Why?
I mean, why is security...
People are dumping their code.
This is a great honeypot.
You just collect everybody's code, right?
Actually, that's something that's been on my to-do list forever.
My wife is a lawyer. I have yet to take advantage of that and write a privacy policy. I mean, for the record,
I don't keep anything. I don't like it. The only thing that, uh, the only code that gets stored is
while it's being compiled. And then I throw it away. I am not interested in what people are
using it for, but you're right. It would be an interesting honeypot if you were like that,
but I need to make that explicit. So I'll get on that at some point yeah because what you really want
to do is spend all your time reading other people's crappy code exactly um but yeah the
security is it turns out that compilers are extremely big and complicated pieces of code
that are not written to be secure and a number of secure potential security via
violate not violate security issues could arise from running a compiler for example gcc allows
you to supply a minus f plugin command line option which allows you to load into gcc an
arbitrary dll on your system as being an extension point you could conceive that someone could write a piece of code as a hacker hacking sort of piece of code have it built somehow find a bug where it
gets left on the system and then they could in the subsequent compile load it in and execute it as a
plug-in to gcc itself and then of course you lose your control of your your your amazon instance and
and you're very sad so i have had several hacking attempts on the site.
You know, people mostly are just doing it because they're interested.
And almost all of them have emailed me.
I've had only one case where I've noticed something awry has gone on.
And I have had a lot of help from those people who have said,
hey, would you mind?
In fact, people have asked before,
would you mind if I had a go at the site?
Because I'm now reasonably confident that it's it's at least difficult to
do that um and yeah so i've learned a few lessons along the way and that that particular github
request is more a issue is more about me remembering that um a couple of very difficult
to take advantage of situations where it exists but there's layers and
layers of security uh the compilers themselves i i actually run kind of under a um a trick on
unix where you can pre-load a library and i basically pre-load a library that stubs out all
of the file system api to go through a check which says can you read or write this file am i going to
let you read and write this file so you can't to let you read or write this file? So you can't load up the et cetera password file.
You can't load up.
Because people do that.
The first thing they do is like hash include,
slash proc, slash self, slash,
and then start looking at all sorts of things
you can get access to.
You know, it's a huge attack vector.
Oh, wow.
Yeah, I didn't even consider that.
And on the to-do list as well is to actually execute the code,
which then obviously is much more interesting for people.
You know, obviously, it's one thing to stare at the assembly,
and obviously that's the primary raison d'etre of Compiler Explorer.
But, you know, of course you've written something,
and you want to make sure that the output of your program
is what you expect too.
So I can see why people would want to do that,
but you can also see why I would be reluctant to allow people to do that.
So I have some ideas on that that and i have a couple of branches which uh implement it in what i believe
is a secure a secure way but um i've yet to pull the trigger and actually push that live i'm a
little scared as to what's going to happen yeah i would be yeah so you weren't actually responsible
for the aws outage last week?
Oh, my words.
No, it wasn't me, but it did consume. You were affected by it.
I was.
It consumed half of my day at work.
And my company are extremely good at letting me kind of get on with my open source projects when it makes sense.
And if something like this happens during the day, they're going to turn a blind eye to me working on it. But it was four hours along before I realized
that actually it wasn't just the S3
that Amazon said it was that was down.
Unfortunately, all of their systems
back onto S3 themselves.
And so what had happened,
I had a momentary spike in demand on Compiler Explorer
and the new instance had popped up.
But because of the S3 problems,
it failed to start up properly one of the like
initialization things is it pulls down a bunch of configuration from s3 some of the things like
the compilers that i can't um the license keys for compilers that are commercial are stored on s3
where i no one else can get to and that's the only way i can kind of hide them away from the github
repository um and uh after cascading failures, eventually the, um, watchdog system that kind of, um,
reduces the number of instances that run decided erroneously to kill the one instance that was
actually working. And then I spent four hours debugging for one of that had happened. And then
eventually I saw on Amazon, Oh yeah, by the way, this is what happened. I'm like, Oh, great.
But, uh, it was not my fault, but, but of course it did affect me and it's surprising and
yeah and there were a lot of people who were pretty pretty miffed it's pretty stressful yeah
it's one of those things where you know people are emailing you say hey do you know your site's
down i'm like yes don't rub it in i'm doing what i can to bring it back and i'm trying to build new
images and then the docker repository where i store like the intermediate images docker went down because
they back onto s3 and i'm like i can't even push what i think might be a fix for it and
and it was never you yeah and it was never me and and you know i do tell to people that that
it should be straightforward to run a local instance and i encourage people to do that
um but obviously that doesn't give you access to all the compilers in the world straightforward to run a local instance. And I encourage people to do that. But obviously,
that doesn't give you access to all the compilers in the world. It just gives you, you know, access
to your own compilers in a way that you're familiar with. But maybe that's enough for most
people. So I would say, you know, grab a local copy. And if it's not easy to type make and get
it working, then then file a bug, and I'll see what I can do to help you or fix it up. So can you tell us a bit about your regular job?
You mentioned super cool, low latency stuff.
Is that super cool as in cooled or just as in interesting?
Super interesting, I should say.
So, I mean, my background is like computer games, as I've said before,
with a small gap at Google doing essentially similar things um so i've always loved making things go fast finding interesting ways to achieve um
goals to make it as as quick as possible and unbeknownst to me this skill set that i've
developed you know putting more and more explosions on a screen on a dreamcast is actually kind of valuable to the financial world where for some things that
are traded being able to react quickly to things happening in the market is a very valuable thing
to do and so I kind of fell into a role at DOW where I am working on really really interesting
problems of the form.
How quickly can we receive information from an exchange,
get it to the place where it's valuable to use,
and then send an order to another exchange or the same exchange
or make some decisions based on it?
And there's a million different ways of making that go fast.
Sometimes it involves interesting pieces of hardware,
either networking equipment or otherwise, you know, computational equipment.
Other times it just means writing damn good algorithms that scale really, really well.
It's a really interesting wide range of things.
And so I sometimes work on like the minutiae of assembly.
And other times I'm more worried about how we can get like some
training done um for artificial intelligence type stuff quickly across like a fleet of few
of computers so it's it's it's really interesting and and unbeknownst to me finance is kind of
interesting i always wrote it off as being that boring thing people in suits do but i'm glad to
say i've never won a suit in my in in my, for my day job in my life.
And I still don't have to.
And,
and it's not like,
you know,
if you,
if you've ever thought about what traders are like,
you kind of picture this for Wolf of Wall Street kind of thing where
everyone's shouting by and sell into phones and smashing desks when they,
they lose money.
And it's much,
much more,
it's much more like a bunch of really,
really smart people working on interesting problems with
loads and loads of monitors with loads of like displays of what the markets are doing but it's
it's really really interesting most people are like math phds rather than like big shouty men
is this one of those things where you need to know how far the distance that a light can travel in a nanosecond
i would say that's kind of important yeah location location from time to time we have to measure how
long our fiber optic cables are yeah that's crazy and you're in chicago that's right yeah we we so
that's our the mothership of of the company there's about 500 of us in Chicago, but we have offices in Singapore. We have one in London. And I'm sure we've got another one somewhere else, but I can't remember it.
And you did say you're hiring. Are you hiring for jobs like yours? Absolutely, yeah. We're always looking for smart people to join us, be it C and C++ people like me.
We're always looking for low latency kind of people.
But there's an awful lot of other stuff that goes on at a trading firm.
A lot of our research tools and things are written in Python, and it's more about the big data.
It's more about how quickly can we get people to research a new trade?
How quickly can they express what the kind of thing they're interested in?
How quickly can they run it over five years of data with petabytes of information that's been stored and squirreled away?
So there's a continuum between people like me who fuss over little things and the big picture kind of people.
That sounds pretty interesting.
Well, I think we probably
should let you go.
Chris, do you have any questions?
Thousands.
Where's my...
When's he going to put the 6502 compiler in
and the Z80 compiler?
That's true.
I'm not even
sure if those are available easily.
Well, certainly the little transpiler thing that Jason Turner worked on is on the cards to convert x86 instructions to 6502, which is a mind-boggling thing in itself.
Yes, sort of.
Did you see the paper about the 6502 in neuroscience?
That's awesome.
Yes.
Yeah.
The amount of attention to detail that's being done
on the 6502, it just warms my heart. It really does. Yeah. The approach of looking at it like
it was a human brain or an animal brain and trying to derive what it was doing, I thought
was a really interesting thing, not only because of the methodology that it exposes, how neuroscientists view the world,
but also as to kind of how far we have to go
in order to understand something
which is perfectly explainable
if you realize how it was designed to start with.
But if you just look at it as a unit,
yeah, there was a fascinating paper.
I loved it.
And of course, that was only really paved
by the amazing guys who took the lid off of 6502 and took all those high resolution photographs of it and reverse engineered the transistor list, which is just crazy.
You know, 3000 transistors and reverse engineering how they work and then exposing it and sort of making an open source document so that you can go and see how those transistors actually work it's it's amazing so uh the upside of the paper for people who haven't
seen it is that they looked at a running computer 6502 based uh with similar techniques to how they
look at brain function when you know sometimes they put somebody in an fmri and then say okay
sing a song we'll see where your brain lights up oh, there's the song singing parts of your brain.
And so they write all these papers and say,
oh, we figured out, you know,
where the watching jeopardy section of your brain is.
And they're kind of bogus.
And this actually kind of proved
that they were slightly bogus
because even something as simple
as a microprocessor from the late 70s,
they watched it run a program and it's like, we have no idea this stuff's lighting up and we don't well they had three programs three games and they were just watching the boot up of each game
and they cut like a few transistors and they decided that was the donkey kong part of your
brain part of the 6502 brain because donkey Kong no longer ran if you cut those.
And it was like so obviously bogus.
And it's a great analogy to what's going on in brain science where it's like, oh, yeah.
And brain science is way more complicated.
Neurons are way more complicated than transistors because they have all these inputs.
Yeah, I heard about this on the Don't Panic Geocast, and I've just been boggled by how cool it is
and how much fun it must have been to do that research.
All right, I was trying to close the show,
and then I got totally distracted.
Oh, so you asked me if I had more stuff to ask.
Do you?
No, I can be done.
All right.
Matt, do you have any thoughts you'd like to leave us with?
Yeah, I would say never be afraid to take the lid off of something and see what's underneath,
be it the library you're using, the compiler you're using, the CPU you're using,
or indeed in the case of the guys in the 6502, the top of the chip
and what on earth is going on with those transistors.
Excellent.
Look under the hood.
I like that.
Our guest has been Matt Godbolt,
creator of Compiler Explorer,
which you can try out on godbolt.org.
He's also a senior software engineer at DRW Trading Group.
Thank you for being with us, Matt.
Thank you both.
It's been a lot of fun.
Links to everything that we can remember
will be in the show notes and on embedded fm you can subscribe to the newsletter read the blog
contact us all the good stuff there and thank you now thank you now to Christopher for producing and co-hosting. And of course, thank you for listening.
I do have a link, something.
I have.
This is how quickly it falls apart once the show ends, is it?
Yes.
I've got a thing.
I have a thought to leave you with about arguments from Amy Poehler.
And I thought it was sort of one of those things that it happens to people.
And she says, if you do start crying in an argument and somebody asks you why, you can always say, I'm just crying because of how wrong you are.
Embedded is an independently produced radio show that focuses on the many aspects of engineering.
It is a production of Logical Elegance, an embedded software consulting company in California.
If there are advertisements in the show, we did not put them there and do not receive money from them.
At this time, our sponsors are Logical Elegance and listeners like you.