About this episodeThis show covers SIMD: A set of languages for fast array operations. Tools of the show: Jason: OpenEmu Patrick: Mint.com. Books of the…
This show covers SIMD: A set of languages for fast array operations. Tools of the show: Jason: OpenEmu Patrick: Mint.com. Books of the show: Jason: Emacs Quick Reference Card: http://www.gnu.org/software/emacs/refcards/pdf/refcard.pdf Patrick: The Mote in God’s Eye http://amzn.to/1AwlOaf
★ Support this podcast on Patreon ★Transcript
From the publisherThis transcript comes from the podcast’s own feed, shown as the publisher wrote it.
SIMD
are. And the question was, do computers ever make mistakes? This is a good question. And some people, I think this was actually posted in our Google Plus community. And so, actually, someone had written back, and we'll share our own opinions. But one of the things when you first are introduced to computers is you're told, like, the computer doesn't ever make a mistake. It only does what you tell it to do. And sometimes, as programmers, we write bugs or faults. So, quick
Yep. Thank you. And so, you're always told computers don't make mistakes. But, you know, it's always a programmer's fault or some software that was broken or wrong. And then the person who responded actually, you know, got the thing, the same thing that first came to my mind when I read the question, which is that there actually is sometimes the processors, the thing which are the, oh, simply the brain of the computer. But the thing that we think about when we think about a computer, you're typically thinking about the processor doing the work. And it does sometimes have logic flaws, things that it's supposed to do. And there's several famous ones. But one is that, you know, sometimes you have different lines that are supposed to correspond. Like if you do a divide by zero, then that should be a certain kind of error. But sometimes that will be actually triggerable by other stuff or won't get triggered at all. And then this can cause a problem because it means your processor doesn't do the expected behavior. And there's, we talked about one, I think it was last episode or two episodes ago, where it turns out the estimation for Pi in some of the Intel processors isn't as accurate by several, like 10 bits or something as it could be. And it leads to kind of errors in trigonometric functions near Pi.
Yeah, I mean, another one. I'm just, there's a link to it. But I'll put a link in the show notes. But there's this FDIV bug in like the '90s with Pentium where like they would—I don't remember this. I mean, I could read the article, but basically it's something to do with like the division, like calculating the remainder of the division or something. But yeah, basically they got it wrong in the processor. And you know, it just means that there are certain divisions that you can do them, but it won't give you the answer that you want it to. And you know, sometimes through some Christmas miracle, you can solve it in software by changing the firmware of the processor and things like that. But I mean, really, you know, many times it's just there's nothing that you can do about it. I mean, it's just etched. It's as if like, you know, you bought the wrong screwdriver or something, right? You're just kind of done.
But surprisingly, sometimes these bugs, you know, quote unquote bugs, linger around. So there's some quirk that wasn't intended, but then if Intel has a quirk in their current line of processors, AMD is faced with the situation of trying to either replicate the bug or, you know, fixing it. But then having compiler writers trying to determine which processor is being used if they want to work around it, which is why it makes it difficult to fix software. Yep.
Yep. And I mean, a lot of this—I mean, there's one thing I didn't realize until I moved to the West Coast. There's a ton of cross-pollination. So, you know, there's a ton of like Intel people who are at AMD and, you know, AMD people at Google and Google people at Facebook, and Facebook, you know what I mean? And so, you know, obviously you can't just take the technology from one company and give it to the other. But it's like if at the end of the day, there's a core group of people and they agree on a way to do floating point, and then one of them leaves and goes to AMD and he implements almost the exact same way. And now you have the same bug on, you know, 99% of the world's processors. I actually thought of this like in a totally different way, which is not the common way, obviously, because no one else seemed to think of it this way. But also it's like it's very esoteric in hindsight. But the first thing I thought when I saw this was in the context of like machine learning and things like that, like do computers ever make mistakes? Like in a sense that do they not do what you want them to do? And I think that this is actually kind of interesting. It's really it's like now we're things are getting kind of very high level with computers. And I mean, you're doing a lot of like statistical analysis and all these like stochastic processes and things like that. And it's not really clear. Like at some point, the computer will start making mistakes. Like right now, it's like if anything is wrong, it's always our fault. And in reality, there's always, you know, you as a programmer can change things and the computer ultimately is supposed to be reproducible. But we're getting more and more into like crazy AI things, robotics, things like that. And so at some point, I mean, the computer will be kind of making mistakes. I mean, it's like I don't know if that crossover will ever happen.
So, I mean, computers can make mistakes in certain ways, depending on how you think about it. Besides, as we say, like if you get sometimes my credit card—I've had a couple of times it detect what it thought was fraud. Right? Which is some computer. There's no person saying they're looking at my credit card history. But some computer determines that my current spending habit looks a lot like someone who stole my credit card. And sometimes they're right. One time they were right.
You've been buying those like rugs, the Indian rugs or something. That's like the number one thing. If someone steals your credit card, they will buy Indian rugs. In fact, somebody, when they had the whole PlayStation fiasco, my credit card was one of the ones stolen. And sure enough, Capital One calls me up and says, 'Did you buy, you know, four Indian rugs?' That's like the first thing they asked me.
Yeah, yeah. I mean, that's the kind of thing, like if it, if you, if you, you know, I'm assuming they built this really complicated fraud system that like projected all of your credit card purchases to some like really high dimensional latent space. I mean, at some point it's like, I guess making a mistake comes down to responsibility. Like, I mean, I guess at the end of the day, you're always responsible for the computer, you know? But I mean, like, look at these algorithmic trading computers where they do machine learning to predict stock market prices and things like that. I mean, in that case, you're saying, look, the computer's doing the trading, you know, hopefully it wins more than it loses. But at the end of the day, it's like, I don't know if that's really, yeah, the responsibility thing is kind of fuzzy.
So another mistake can be, it has sort of gotten to your stochastic processes thing. But that if you are running your processor at, you know, high temperature or close to, you know, its power limits, you can have glitches, which cause problems. Or, you know, you always hear this classic thing, but it is actually true that there are, you know, cosmic events, radiation, cosmic rays, which cause logic levels to flip or invert temporarily. And can inject noise at some level into the computer. And then the computer can think a zero is a one, right? And then all of a sudden that changes everything.
Yeah, there's this interesting TED Talk from the security chief of Twitter. And basically she said, like, I don't remember exactly, I'm going to kind of butcher this, but she's saying something like, you know, if there's a one in a million chance that some crazy event would happen. Like your stalker happens to find you on Twitter randomly. Like if that's a one in a million chance, then it happens 50 times an hour in Twitter. You know what I mean? Like just, and it's just kind of like. No,
Okay, cool. So, yeah, I don't know how I got on this, but somehow I—oh yeah. So I feel very compelled to like, I'm working with a lot of people who are just fresh out of college. And so, it's kind of cool. Like, it feels like you're looking at yourself, like, but younger or just less experienced. Because they did all—they're doing all the same things I did. And it's like, I, you know, can't obviously fault them for it. But it's like, I think it's like, in hindsight, it's clear. Like, there are lessons that neither one of us—like, no one, myself nor any of these other people have learned the easy way. And we're all having to learn it the hard way. Actually, well, hopefully I can make it so that they don't have to learn it the hard way. But I wanted to take a little bit of time to talk about like rookie software engineer mistakes. So the
Oh, there was a core question. And it said, what do old software engineers in Silicon Valley do? Or like, what happens to old software engineers? And the number one answer was this guy. He said they become well-paid software engineers. I don't know if that's true or not. But, but it was kind of interesting. It made me think that like, there really aren't that many old software engineers. Like, you don't see a lot of 50, 60 year old software engineers. And there's, there's probably a bunch of reasons for that. Wait, I
Anyways, I digress. Yeah. But so that's why we're thinking we're old, right? Anyways. So, a couple of rookie software engineer mistakes. One of them, and this is a big one, is like making assumptions. And it's either because you want to, you know, kind of save time or save processing or you don't want to change the schema or something like that. So, like, you know, I purposely didn't—like, no one on my team actually said any of these or anything like that. But this is like a fictitious example: you have some document system and you store the timestamp for all the documents. And then all of a sudden you need to know whether a document was created by an admin or not. And rather than having some Boolean which says, you know, created by admin, you say, oh, I know what I'll do. You know, if the timestamp is negative, I'll just flip the sign of the timestamp. If it's negative, then it's an admin. And so, like, things like that work. But the problem is you're kind of setting up a landmine for your future self. You know what I mean? Because you're now, like, adding this cognitive overhead where you have to remember this sort of association that you only made up because it was kind of convenient, you know, given the circumstances. And so, you see just a ton of this kind of stuff where, you know, people will—people will just kind of, it's not really a shortcut. Because, like, often it doesn't save that much time. You're
Yeah, exactly. I mean, another case of this—it's like a little bit of a different vein. But it's where someone starts off with, like, current measurement. Like, double current measurement. And then they need the previous measurement. So they're, like, double previous measurement, double current measurement. And you're like, okay. But then they realize they need the last ten measurements. And they're like, previous, previous measurement. You know what I mean? And it's just like it just grows organically. And the next thing you know, you like have this ridiculous thing that could just be an array. Right.
Or the other pet peeve of mine is even in—you know, I guess this is more common maybe in dynamically typed languages like Python. But I even see people do this in C, but like you'll have some, you know, unsigned 8-bit integer that is getting some value from a function. Then later, they also use it to get a value from a different function, like later in that function, you know. But now these are two different things, but they just reuse the same variable. And it's like up here the variable meant this. Now down here the variable means this. Like why don't you just create a new—like, the compiler will, you know, optimize this away. There's no reason for you to reuse the same variable name twice. Like in a loop, like if you're looping and the loops aren't related, like fine. I'm okay having the variable i counter or whatever be used. But like syntactically, like they don't. It's just like here's one value. Then here's a value from a completely unrelated function that also just happens to be of the same size. And I no longer needed the other one, so I'll just reuse the name. It's like oh, just create a new name.
Yeah, yeah. That stuff is brutal. Another one that I see a lot is people who don't put like asserts or exceptions or like to some extent tests in their code. I mean, everyone always complains about no tests. But even just like asserts and exceptions, you know, I mean it doesn't take much time to as you're going through say okay you know I expect this list to have three things in it. So if it doesn't have three things then blow up, you know. Like code a lot of the code I write like you know a few days later will blow up or a week later will blow up. And usually it's because some other part of the system like violated one of the assumptions that I wrote, you know. And or even you know even if it blows up like if it blows up like a year later it's even better, right? Because instead of just some really weird runtime condition that maybe you don't even notice for a long time it's like a year later all of a sudden it's like boom exception. I expected the list to be three and now it's four. And usually you know the exception will fire immediately after someone makes the change that causes the problem, right? So you don't have these like really weird latent issues that you have to like go back and play detective to figure out, you know?
As you work in really, really large systems, this is where like continuous integration and unit tests become absolutely crucial. So even if you test your code, if you've changed something that other people were assuming about your code, and they don't also have tests or you know there isn't some system kind of doing integration testing, then it can go undiscovered for a while. So,
Somebody in the chat said they don't like it when negative one is used to represent a failure state. That is another good thing. Like you see that where it's like the function you know returns an int but yet you know they want they really want to return an int and you know something else for the status. But instead of returning like a pair, they return an int, and they're like okay this is going to be positive except it's negative one if this and it's negative two if like cows are flying and it's negative three if it's a Monday, and you're just like ah,
I can't deal. Yeah. Well similarly yes I did have this problem with a new person on a team. I had to help try to convince them, which I don't know how successful I was, but they had where they would call some computation function. It would return a result. Then you needed to call another function that said whether the value returned was currently valid or not. Mm-hmm. So like you know some state is being tracked and you need to call first and say hey is this other function going to be valid if I call it, or if I've called it, is it currently valid? And I was like why don't you just return Boolean of whether it's valid? And then like you know in this case it was C. So you know and then pass a pointer in and then you'll know like if it's valid the value in the pointer is now you know the pointer the destination is now set to it. And they're like I don't know. Like why can't you just call this other function? I'm like well because then if someone doesn't call that function then like they have no idea if like you're just going to give them garbage.
The last one: reinventing the wheel. You know, there's like a ton of good source code out there. A lot of it is very liberally licensed. You don't need to go and create your own hash table and things like that. There's a lot of it for you. And so yeah, I think this is a big one, actually. And I think that like, actually, connecting up libraries is really hard. I mean, especially in a lower-level language like C. You know, wiring together libraries—you know, they might have different structs and you have to maybe do some fancy casting or you have to translate back and forth. And doing that stuff efficiently is really hard. Like, it's cerebral. And coding something from scratch is much more mechanical in a sense; it's easier. But when you code from scratch, you're going to introduce all these errors that you're going to have to debug. You're not going to write perfect code. And you're not going to write code that's as well-tested as an open-source library that's ubiquitous, right? So yeah, so this is just another one that I kind of tend to see a lot of: people just trying to depending on your
Yeah, I guess it depends on, like, usually the lawyer cats are pretty responsive. We had an issue where they didn't approve Emacs 24, but people were just using it. Nobody really thought anything of it. And finally, somebody was like, 'Oh, we should probably ask the lawyer cats.' And they sent an email and it was approved, like, within a couple hours. Yeah.
Oh, I'm not saying all lawyers are bad. I just mean, typically, depending on your company, they may or may, you, as programmers, we sometimes say, 'Oh, I know this license is friendly,' or 'you know, fine to use.' Or this is in the public domain. I'll just go ahead and use it. But, you know, there's also someone needs to be tracking everything you're using because typically you're also supposed to at least give credit or cite. Oh,
Time for the news. News. You go first. Okay. So I got the first article. And I'm not super good with Markov chains. So I don't know how good this description of Markov chains in this article is. But I thought it was a really interesting—this isn't how I traditionally see Markov chains. But it was an interesting approach that, the link will be in the show notes. But this person had read a Reddit posting of a challenge, of a programming challenge: How do you simulate this collection of particles undergoing radioactive decay? Where you get here's the starting number of particles in various states, and here's the probability that a particle decays from one state to another state, the second state to a third state, so on and so forth. And so they were talking about that, you know, if you have a million particles, one way to do it is, you know, essentially pick a random number for each of the particles and then determine based on the probability specified if that particular particle, you know, transitions state or not. And how that this, you know, obviously is very costly and slow. And then instead how that, you know, what they were saying was using Markov chains, but what amounts to creating a probability matrices and what they were calling a transfer function that you can essentially do a matrix multiplication and essentially do the same thing almost exactly. So you're not simulating each particle, but you're simulating kind of all of them simultaneously, you know, undergoing this. And then what populations will you end up with at the end? It was a good, it was a good article. So
Yeah. Yeah. So that was one of those things that kind of blew my mind. I mean, a while back, it's like this idea where, that sort of—I'm trying to see if I can grok this. So it's like, oh yeah, it's like, you know, if you're if you have a 50% chance of something happening and everyone in America has that chance, then that means half the people in America have it and half don't. So this idea of going from like chance to, you know, sample like populations, it's sort of like, yeah, like if you if 10% of the people have a tattoo, there's like 30 million people with tattoos or something like that. Like that whole going from like percentages to like, it's like, oh yeah. You know, like at some point when the sample size is large enough, percentages become fractions.
Yeah. Actually this, I was given an interview question, which is exactly this problem. Oh really? Yeah. The interview question was, I'm totally going to butcher this, but it was something to the effect of, It was something about like disk seeking. So, you know, it's like you want to write data in a way where when you read the data, you could read it, you know, just consecutively. And so it's like, but you don't know for sure how you're going to read the data. But anyway, it boiled down to like treating the problem of like going from one item of data you're reading to the next, treating it as a Markov chain.
My new article is Axis: Destroy your friends with math functions. It looks pretty cool. I saw the video, I tried to play it, but they don't have a single player. So, I haven't actually played it yet, but I think the idea is, you know, there's some islands that are, you can think of them as like walls you can't hit. And then there's a tank or some enemy that you have to draw some function that carves its way around these walls and hits the person. And it's like that game, Scorched Earth.
Yeah. Where like you had the angle and the velocity of a, you know, basically you defined a ray and based on that ray, you shot a projectile that, you know, arced with gravity and had to hit somebody. So it's that kind of idea, but they really took it to the next level. You come up with some crazy sine wave that like dodges a wall and hits somebody. So, I thought it was pretty cool. Sounds like a very nerdy game. Yeah. I mean, if you want to destroy us, feel free to invite us. I don't actually know. I think the way the multiplayer works is you have to send someone a link or something. So, but yeah, try it out. Yeah. Let us know what you think.
Next article is why Python is slow. And for the sake of time, I won't go into all of the reasons enumerated in this article, but it's a very fascinating under the hood look at the mechanics of Python. So, you know, we talk about, oh, Python is dynamically typed and interpreted, but you know, like what, what is the actual thing going under the hood that causes it to be that much slower than C++ or whatever. And this guy did a really good job of breaking it down kind of piece by piece. And it gives a lot of insight, you know, that you would never think about kind of ordinarily. You might at a high level say, oh, Python, you know, uses an object to represent an integer, but how exactly? And this article goes into that. So check it
Out. Yeah, it's awesome. Um, yeah. So this next one is the day I lost a ton of money, and it's a—I'm censoring it. Yeah. It's a, it's a ton of money. Um, an S ton of money. And that's not like an S expression, different kind of S. Oh. But basically, it's from this guy who's like a day trader and it just kind of blew my mind. Like just how this whole thing works and how these people like, you know, try to analyze the market or don't in this case and just lose a ton of other people's money. I mean, it's kind of sad, but the whole thing is kind of interesting. It has some funny pictures and stuff like that. So, I haven't read this.
Yeah. So basically this guy, you know, it's all about his—it's like your stereotypical, you know, rise to power and then eminent destruction. So, yeah. So, time for book of the show. My book of the show is Emacs quick reference card, but it's not only Emacs. In general, reference cards are pretty awesome. I have had the Emacs reference card like taped to my computer monitor for—I don't know—way too long, but I have one of
Yeah, that's a good question. So the, you know, some of these things which are more like kind of muscle memory type things. It's really good to have a reference card. Sometimes like you're right there on the spot and you're like, oh, I want to, you know, move this line up to lines. But like, I don't want to like cut it and paste it or, you know, like if you're feeling kind of adventurous, you can just look at the quick reference card and, it might have something, you can slowly add it to your repository. So for things like Emacs, Vim, you know, Eclipse, things which have keyboard shortcuts. Also if like, if you're learning a brand new language, rather than just like hitting Google every time, it's like, how do I do a for loop? How do I add? You know, it's like have a quick reference card and it will help you through. Like I had this when I was learning Swift, someone had already made a Swift quick reference card or maybe even Apple had made it. I don't know. I have to double check, but I had this quick reference card and it reminded me of, you know, the obvious things until I got familiar. Yeah. So what's the Java quick reference card say?
Well, first of all, it's crazy like description of the collections. Like List is a part of a collection. An abstract set is you've related to a Set, which is part of a collection. Like it has this like giant map on one part and has like all the keywords. So a lot of it is kind of, I don't know, maybe I consider too low level. Like here's the built-in types. Here's declaration modifiers. Yeah,
declaration modifier, which I didn't know existed in Java strict FP. And it says strictly apply I triple E seven, five, four to a class or method, but I don't know, like I can vaguely guess at what that means. Cause I understand the words that are written here, but I don't like, I'd have to go look this up anyways.
Oh, okay. I'm putting the same one now. Oh, this is intense. So I'm not sure that's useful. The one from NYU, if you search for quick reference card, Java quick reference card, that one actually looks pretty good. It's a second link. Cause the first one's an Android app. Okay. But yeah, I again, like, like this is really, I mean, this is for two things, either muscle memory kind of things like, like Emacs, you know, your editor where there's like a huge deep learning curve, like a huge deep learning curve and you just don't want to bite it all at once because a lot of it is situational, right? It's good for those things. And it's good for, you know, Java. I'm a Java programmer. It's day one. And, you know, I don't know how to do anything yet. So, you know, if you're picking up a new language, you know, duct tape the quick reference card to your head.
My book of the show, again, not being useful, but being entertaining is The Moat in God's Eye. This is a book co-written by Larry Niven and Jerry Pournelle. It was written in 1974. So I really am digging these like 1970s and 80s books because this one actually doesn't show its age as much as some of the other ones I've read, but I didn't realize it was written in 1974 when I was starting to read it. I was actually listening to this one on audio. But when I was starting to read it, I didn't actually realize it was written that long ago. So, and there were some weird mentions of like personal computers and like having audible, like connect, like almost like an audible modem was being described. And I'm like, that's kind of weird. And later I looked at, but I managed to read the whole story and not realize that it was written in 1974. And I looked it
So these people are like, very prolific writers. If you've ever heard of Ringworld, I think that was also—hang on, I'm going to which one, but that's Larry Niven as well. In the seventies, wrote this Ringworld book. Oh, okay. And I saw, I actually went to a talk that he did, and he's continuing to write books in the Ringworld series, even as early, like as recently as a year or two ago. Oh, wow. So that's kind of crazy. Jerry Pournelle also writes to still to now, I think.
Yeah. Same here. Okay. I haven't ever written anything. I have a friend who is an English major, and she writes like short stories, and they actually have kind of like we have hackathons. They have like hackathons basically where it's like write a book in a month, and she just writes, you know, eight hours a day or something ridiculous.
Tool of the show. My tool of the show is OpenEmu, which is pretty freaking awesome. It's Mac only, which is a shame, but it has an unbelievable UI. Okay. So OpenEmu is what's called an emulator front end. And so what that means is, you know, they take a lot of emulators. Most emulators have like a command line interface, right? So you can just execute the emulator. You know, they might have a little GUI. If you run the emulator as a little program, it'll pop up a little GUI, usually something just really crappy where you open a file. Like SNES, right? Had that really ghetto-looking GUI. But if you were to run SNES with arguments, you can actually launch SNES and go straight to a game, right? So people have created front ends where the whole point is to give you a better user interface, and give you a window into your library of cartridges that you legally own. So, this OpenEmu is pretty epic. You can see from the screenshot if you're watching the Twitch stream, like this, it kind of looks like iTunes. It has this; it actually downloads the cover art for you. So there must be some open source or some repository where they can get these all these covers. So they have covers for almost everything and download the cover art. It analyzes the hash of the ROM to figure out what game it is, and then they correct the file name, the title, all that stuff. So like, it's like iTunes, legit, you know, figures out the artist, in this case, the developers, whatever. I can't believe you just
I think it was Coin. Coin did this really badly actually. Okay. Well, it's my new pet peeve. Yeah. Okay. So I love your pet peeve. But anyways, so. Wait, no, you hate my pet peeve. No. No, I love your pet peeve. The thing I hate you love. A peeve that you have a pet peeve. That's not my pet peeve. Okay. Anyway. It's pretty cool. Another thing that these guys get right, which is genius, is like when he's obvious, like can't believe I didn't think of that kind of things, is they basically, they bought one of, you know, the most common joysticks. Like if you just go on Logitech and try and buy a PC joystick and also like the Xbox controller, and like they just bought all of these and then for each one, they configured it how it should be. And then if you plug in like a Logitech or Xbox controller, you don't have to set all the little keys. Like say, oh, this is the up arrow on my controller. Cause they've done it for a lot of the popular controllers. That's like, yeah. It's like clever little add-on. It's pretty cool. Check it out if you're into that. So that's my tool to show. Mine is
So yeah, I think this is one of those things where it actually used to work better than it does now. Oh really? Wow. Sort of. Because I think as far as I can tell, what happens is the credit card companies have their own solutions, right? And their own things they want to go. And so they're not super keen on the idea of like making sure to stay compatible with Mint.com every change.
Even though, like, you know, as a customer, I want them to stay compatible. You know, they want to force me into using, like, you know, Oh, American Express, use the American—my, your American Express app on your phone. It's like, well, I want to use Mint because I could just have one. Yeah. Right. Anyways. So I
So I just bear through the pain, but when it works, it works really beautifully, which is like, I don't have to go to my bank and my credit card, and other stuff to see. I just go to Mint, and it tells me like, here's where you're at. And they get the graphics right where I can go and say how I've been doing over the last year. Like what, like, what is my trajectory been? Have I been spending more than I make or making more than I spend? Like what are the months where I spend the most? Like why all that kind of analysis, which for me, like, I don't stick to us, you know, like allocate fully allocated budget where it's like, you know, you have $10 to spend on, you know, coffee houses.
Yeah. Yeah. That's exactly—I'm exactly in the same boat, right? Like there are a few things, like you know, and think about it, right? Like cable and phone right away. That's like, you know, it could be up to $200 for some people, right? A month. Yep. That is absolutely gigantic. I mean, that dwarfs your gas bill. Well, maybe depending on how much you drive. Well, that definitely dwarfs your coffee bill. But yeah, I mean, you're absolutely right that there are a handful of things that people spend just an incredible amount of money on, and reducing even just a little bit there can make a huge difference. Like I was finally able to get my family off text messaging. And I mean, that's significant. I mean, it saved us like $20 a month, you know? I mean, it's like, you know, probably more than we spend in gas. Cause I take the bus, I take the shuttle to work. So yeah, we probably saved almost our entire gas bill just in getting rid of SMS.
Yeah. So SIMD, right off that, we'll spoil it for everyone. Single Instruction, Multiple Data. And so what that means is, you know, like a canonical example is, you know, I have three lists. I have two lists with a bunch of numbers in them. And then I have a third list that I want to hold the sum of the numbers of the first two lists, but I want to be like an element-wise sum. So I take the first element of the two lists, add them up; take the second element of the two lists, add them up. And it's like the same exact instruction, right? So you could, you know, like you could as a, like if you could just have the assembly code or what have you say, you know, put the first item in a register, you know, put the first item from both lists and two registers, add them up, put that in the third list; do it again, do it again, do it again, do it again. Right? But if you're doing something like so obvious, like the same exact operation, but you're just doing it on different spots of the memory, then you can do what's called Single Instruction, Multiple Data, where you say something like, take these 10 things and add them together. But because you're doing exactly the same thing to all 10, you don't have to repeat yourself. You just say, do it to all 10. And, it just kind of magically works.
So, so the way this what does buy you is parallelism, as Jason described. So things go faster, and that's always a good thing. People like faster. And the way it works is in the processor, you can think about, so, so like as Jason was saying, you're, you know, adding these element-wise, all these things in a list. So if you have each element in the list is eight bits wide and you have a 64-bit ALU (Arithmetic Logic Unit). So you have the ability to add 64-bit numbers. You could add two 64-bit numbers, or you could add eight eight-bit numbers. And the only difference is you need to prevent the carry between each eight-bit number. So typically there's a carry bit where, you know, if two numbers are one, it has in binary, it has to carry to the next digit.
So you have eight with carries. Then you have a boundary between eight bits that has the ability to either carry or not, depending on if it's a normal 64-bit add or a SIMD 64-bit add. And when you're doing a SIMD 64-bit add on each of the eight boundaries—or seven boundaries, each of the seven boundaries—you disable the carry bits. And so what happens is then when you add two 64-bit numbers, you're actually adding eight eight-bit numbers and storing the result with no carries between them. And so that allows you to do instead of saying, normally you would have to move an eight-bit number into the 64-bit register, move another eight-bit number into the 64-bit register, add the two, store them in a 64-bit register, and then write that out to memory. But all the rest of that 50—well, oh, 50, uh, 56.
And so what it turns out is normally the instruction set will support like 64-bit integers, but they'll have 128-bit special, two special 128-bit registers and corresponding ALU with this option, but they'll have the ability to do it on 32-bit boundaries, 64-bit boundaries, you know, various divisions, because you may not always want to do as many as possible, but typically like the eight-bit boundary example I gave wouldn't be very useful. People don't want to only add eight bits at a time. So you typically, you'd have like a 32-bit boundary, a 64-bit boundary, 128-bit boundary for 256-bit wide SIMD would be very
So typically I think most of it—so we'll get to this in a minute—a lot of it is used for graphics. And so you're typically dealing with 32-bit numbers and you want to do—we'll get to why later for 32-bit numbers. And so it's very common to have 128-bit. Oh, okay. But like I said, these are all just like, it's a concept, right? So I'm sure every variation has been done at some point. Yeah, that's kind of architecturally how it works. And like I said, the ALU is for addition, but it would also be the same supported operations for division, multiplication, reciprocals, bit masking, you know, all those kinds of things would typically be supported in a similar fashion. Gotcha. We've previously talked a little bit about GPU programming. I think we did an episode on CUDA, and a difference between this and the way GPUs work is that in SIMD, if you have a branching logic statement, if statements, even though the GPU doesn't handle that great, it has support for handling because each thing is running on its own minimally functional processor, but it is its own processor. So they can be doing slightly different things. You just lose some efficiency. But with SIMD instructions, you actually cannot. So you, like we said, you're treating—it becomes a 128-bit number, a 256-bit number. And it just has these weird boundaries within it, but you're responsible for shuffling the data into that number and back out. And so you can't make decisions. Like if the second item is this, and at the same time, if the third item is this, like you would have to do those
Gotcha. Okay. Yeah. And so the things you may have heard of before, which are implementations of SIMD, specifically Pentium. If you remember way back, you had heard of MMX processors. I think this is Multimedia Extensions. And so you'll often hear of these as like some sort of extension, because what it's saying is you have the normal instruction set, then there's some supported extension to that instruction set, which allows for this, you know, extra wide operations to take place. Also SSE. So SSE was Simultaneous SIMD Execution or Extension. One of those, something like that. So those are Pentium. So SSE, SSE two. So I think there's
Yeah. So, you'll have heard of those before. And then for ARM processor getting powerful now or getting common now. And, ARM processors also have their version of SIMD, which is called NEON. And you'll hear these a lot with multimedia. The reason why is because like I was saying, so graphics processing, video codecs, audio, this kind of thing, because these have a lot of, I don't know the exact right word, blind operations, where you just want to blindly apply the same mathematical function to a lot of data all at the same time. Okay. And so, these extensions are really good at speeding those things up and you can get, like we were saying, so if you can do four or eight 32-bit instructions at one time, that's like a four X or eight X speed up for that portion of the code. So some examples that we want to do, we talked about, like you could add two numbers in a list, you could do cross products, you could do dot products, you could do averaging. So averaging would be a little bit where you start to get into some trickiness, right? So for averaging, if you have, let's say four 32-bit numbers, you can do at a time and you have, sixteen items in your list, you'd want to add two sets of four twice. So you have four and four,
Exactly right. So you'd have, now you have done three operations. Then you will no longer be able to use SIMD really, because you need to add that one last remaining set of four together, and then divide by the total number of elements. But you can see how you, depending on how many operations you have, you can get a very large speed up.
Also had a suggestion about earlier. We have our first follower, which is pretty awesome. Another one you'll hear a lot is a four by four matrix multiply. And so in graphics, this is because you have typically three-dimensional rotation matrices and coordinates that are stored for triangles and various, and you store the fourth one to account for some mathematical quirk. I don't know if we ever talked about that before.
do a four by four. I feel like we talked about it briefly, but yeah, we didn't go into a lot of detail, but let's just say that there's some funky math you can do using 4D math, which has no relationship to what you're actually doing, but just mathematically like gives you some niceties. Is that like a one-liner that can kind of wrap it up? And
Yeah. Just to put this in perspective, right? Like if you're doing, let's say you're making a video game, right? And, you have some dude, you know, like Grand Theft Auto style and he's running and he's holding like two Uzis, like John, we were like dual wielding Uzis. Right. So now it's like you want to render, you know, a bullet coming out of the Uzi. So you need to do a transformation to go from the universe to the camera, a transformation to go from the camera to the person you're looking at. That's another, you know, matrix multiply that transformation to go from that person's frame of reference to his hand, one to go from the hand to the barrel of the gun and another one to account from the barrel of the gun out to the bullet. Right. So it's like if the bullets rotating, you know,
To do another one for that, for the spin. Right. So, so you have to do like 10 of these four by four matrix multiplies just to like know where the bullet is. Like you haven't even drawn the bullet. If you want to draw the little triangles of the bullet, now you have to do one of those for each of those triangles. Right. So you're doing a lot of them. So, yeah.
So any speed of you, and this is why, like I was saying before, these typically have names like associated with multimedia or graphics is because that's where you'll see a lot of the use. Same thing like audio processing, you know, you'll want to apply some filter, and typically at every point in the signal, you want to look at the surrounding few points. So now what you basically end up with is like you shift an element in, you apply the same operations, you shift the next element in, you apply the same operations. You just keep doing that over and over again. And this is where you can really get the kind of naive big speed ups because it's really, really well.
And what it amounts to is you're writing assembly code. Like you're not, but you are because you basically need to worry about everything. Like I need to load up the special registers with data exactly arranged how I need it. Then I need to do specifically like these low-level operations. Then I need to get the data back out. These are the kinds of things you typically worry about when you're doing like assembly programming. And this is very, very similar. I find it. And so you typically kind of wrap it in a function, you stick that function somewhere and you call in with a very nice data classes or objects. I pass them in. Then you do this very kind of horrendous, but fast, know, assembly-level kind of programming. And then you kind of pass it back out in a nice class. Oh, gotcha.
or overflows or underflows or. Oh, I see. Yeah. It depends. But, but yes, this is the general flow of it. And so obviously that's painful, but the good news is, if you're writing a graphics library and you optimize some part of that, right? People are calling into your API, not to your, they're not going to try to write these SIMD instructions themselves. Yeah,
that's true. I mean, for most people out there, you know, you're just relying on, you know, if you're using Unity or whatever for the game engine, you're relying on them to do the this stuff for you. So, but actually you can write code which does SIMD and not even know it. What? And that's with I know that's automatic vectorization, which I actually, you know, remember when this came out. Like, I remember when GCC 4.7 came out and I was like, I just, I just remember my mind being blown. Cause I don't really stay up to date on compilers. Like, you know, research or anything like that. So like, I didn't realize that this, you know, was an effort. And then all of a sudden it's like, Oh yeah, SIMD for free. It's just like, what? But yeah, basically, you know, the compiler, the guys who write the compiler are very bright. They analyze your for loops. And if the for loop looks like it's doing something trivial enough that they can, capture all of the side effects and, isolate it, then they will try to replace your code with SIMD code, which does the same thing, but much faster. It's pretty freaking amazing. In GCC 4.7, it was very, very simple. So even like you couldn't use a vector, you know, if you had a vector of floats, the way that like vector, you know, when you actually do the the bracket on an STL vector, it passes it through this inline function. And most of the time it does nothing, but if you're in debug mode, it'll check or do a couple other things. And just the fact that that function was in the way caused like all STL vectors to not be supported. And you have to, you actually had to like create a pointer of the vector and just like, you know, so you basically have to do it yourself. But, but since then it's come a long way. And now even if like, you know, you add two vectors of floats in C++, it'll, it'll vectorize it. If it could make some guarantees about the size and things like that, which is pretty cool. It's also coming to Java. It's not there yet, but, that's one of these kind of amazing things. Like if they build automatic vectorization into the Java Virtual Machine, then like, it's just going to completely change the runtime profile of every Java program ever. I mean, like, like who knows what's going to happen,
The other thing like we're saying is like, if your library, like Unity or whatever supports that, you get it. Also there are of course libraries and I didn't write any down here because I'm not up to date on these right now, but where you could get a package of like, here's common operations you'd want to do. And here they are implemented in ways that are very amenable to GCC doing auto vectorization or already
instructions themselves. Right. So you may have like a wrapper that you pass in STL. Like for instance, like Jason was saying, the STL vectors in C++ didn't work well, but you could have someone else. Well, probably, and you can find it cause I've seen these before have written code that says like, you know, here's how to do four by four matrix multiply and SIMD that takes in the vector, the STL vector and outputs STL vector. Right. And then, yeah, exactly. It wouldn't be a vector. It'd be the matrix, but, um, you know, takes a matrix and outputs a matrix. And then it handles the exact massaging into the right form and back out. And that's the only thing that gets you right. And that, those are, you know, obviously very useful because it saves you a lot of time.
save it. So I don't know too much about it, but basically, so BLAS stands for Basic Linear Algebra System. And the idea is, you know, if you want to like add two matrices or invert a matrix or do kind of these kind of mathematical operations that you do in like MATLAB or one of these other tools, but you know, you're not using MATLAB, you're using, you know, Python or C++ or something. There's a, this library, the set of libraries that are BLAS libraries. And basically it's what Patrick is saying. These guys have just killed themselves making like the most epic matrix inversion code ever, the most epic, you know, add two vectors together code ever. And, you can just use the BLAS library whenever you want to do one of those
made the mistake one time of compiling Atlas, which is a BLAS implementation. I didn't want to use the one that was like built into Ubuntu. And I was like, Oh, I'll just build my own. And it took something like eight hours to build. And basically it's like, you know, trying every possible, you know, yeah. Yeah. It's like trying every possible way to build this library just to give you an extra 1%. I've never looked. I don't
That's right. Like the one you get from Ubuntu isn't made for your machine. It's made for, you know, someone's machine who's building the Ubuntu distribution. And so, yeah, Patrick's right. Like if you build it from scratch after the eight hours, you will have something that is like 1% faster or more maybe.
gaming, like I said, this is all about like doing graphics processing, audio processing, video processing, all things that have a very legitimate reason these days to be done in a web browser. And if you're going to do that, you're going to want to take advantage of SIMD because it does give like, you know, it's very conceivable to have like an 8x, 10x improvement by implementing this stuff. And that's big.
Yeah. Yeah, totally. I mean, me and some buddies wrote an emulator in effectively JavaScript, written in Dart. Actually, we talked about it on one of our shows. And the emulator, you know, like rendering all the pixels actually only takes like one or 2% of the time, but just executing the Nintendo CPU, which is just, you know, like a one megahertz CPU or something ridiculous takes like over 90% of the time. And it's because a lot of times you're just doing simple operations, but on the web, they're just so painfully slow. And so this SIMD is part of a bigger effort to sort of fix that problem. Yep. So
Yeah. Yeah, totally. I mean, I think that it's only a matter of time before we get, like, we already have NScriptEngine and some of these technologies for taking, you know, like desktop applications and basically compiling them for the web and it just kind of magically works, but it's still like very early stages. And so this is like sort of building more of that scaffolding so that we can one day get to a place where you could just build something for your desktop and the web and it would just kind of magically do what you want. Well, I Think that's a wrap. Yeah. Cool. Thanks everyone for following us on the stream, and you know, we got some good feedback there. Pretty cool. It's been a while since we did a show, but as you can expect with the vacation—I was on vacation, Patrick's on vacation, Thanksgiving's coming up—so it's that time of year where it's hard to find time. Yeah. We'll try to do one before Christmas, but
Yeah, it's possible, but we should be able to grab some time. I think we can pull it off, but if not, we'll see you guys in January. But anyways, it's always fun to do the show, and you know, I'm trying to think, do we have anything newsworthy, like Meta, anything to talk about? I didn't look up like
So, yeah, I don't think we have much meta to say. This is a pretty cool one. I definitely want to cover Rust, that programming language. And we got some other requests for languages, so we'll be covering that. We get a lot of—actually the majority of our feedback is still on Google Plus, which is awesome. I mean, we have Facebook and Twitter; a couple of people asked for those, but still, you know, the majority of the content is happening on the G+ page. So definitely check that out. And send us an email; you know, we read all of them. Sometimes we read them on the show. Sometimes we say your full name and embarrass you. And I don't think we've ever read
