WEBVTT

0:00:00.000 --> 0:00:08.700
<v A>Hosting provided by HostTornado. They offer website hosting packages, dedicated servers, and VPS solutions. HostT.net.

0:00:15.600 --> 0:00:20.780
<v A>Programming Throwdown, Episode 38: SimD. Take it away, Patrick.

0:00:21.920 --> 0:00:29.980
<v B>We're going to start off here, Episode 38, with a question from a viewer. Well, we don't have viewers. Listener. A listener question. Although today we do have viewers.

0:00:30.220 --> 0:00:35.060
<v A>This is actually the first time we have viewers. Last time we had viewer.

0:00:37.300 --> 0:00:40.733
<v B>But I don't know that it was one of our viewers who asked this question. It

0:00:40.767 --> 0:00:42.580
<v A>was definitely a listener, though. That's a good point.

0:00:42.980 --> 0:00:48.968
<v B>A listener. And they asked, well, I should give credit to at least the first name of the person, but I don't have it. But it's okay. You

0:00:48.968 --> 0:00:49.609
<v A>don't know who you

0:00:49.609 --> 0:00:49.744
<v B>are.

0:00:51.280 --> 0:01:21.030
<v B>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

0:01:21.030 --> 0:01:31.100
<v A>interrupt. The asker was Matthew. I won't say his last name. Actually, his last name is right on G+. It was Matthew Alabastro. Thank you for the awesome question. We love it.

0:01:32.680 --> 0:02:47.899
<v B>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.

0:02:49.579 --> 0:03:45.019
<v A>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.

0:03:45.959 --> 0:04:13.380
<v B>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.

0:04:14.380 --> 0:05:43.400
<v A>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.

0:05:47.180 --> 0:06:16.140
<v A>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.

0:06:16.400 --> 0:06:39.445
<v B>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.

0:06:39.560 --> 0:06:42.979
<v A>You've been buying those like rugs, the Indian rugs or something.

0:06:44.620 --> 0:07:02.340
<v A>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.

0:07:02.520 --> 0:07:04.521
<v B>That's really odd. Well, the one I've always

0:07:04.521 --> 0:07:06.074
<v A>heard before. I think they're very expensive. Oh,

0:07:06.074 --> 0:07:18.480
<v B>maybe. Is that teenagers typically go buy shoes and then buy gas for them and all their friends? So if you fill up like me and my spouse's car and then I went to the mall and bought something or whatever. And like that'll trigger it.

0:07:19.099 --> 0:07:19.940
<v A>Oh, wow.

0:07:19.940 --> 0:07:34.964
<v B>But no, specifically what it triggered mine was I made a change in like my—like I had moved. So I made a change in my address and then I ordered some computer parts online. And apparently that also looks exactly like someone stole your credit card. Which

0:07:34.964 --> 0:07:35.580
<v A>Makes sense. Oh, interesting.

0:07:35.580 --> 0:07:50.060
<v B>But you know, some computer made a mistake, right? Like I didn't commit fraud. Yeah, right. But did it really make a mistake? No, it probably did execute the rules it was told to. But from my point of view, it was a mistake. There was no fraud.

0:07:50.840 --> 0:08:36.360
<v A>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.

0:08:36.820 --> 0:09:14.400
<v B>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.

0:09:15.260 --> 0:09:17.969
<v A>Yeah. You know, very large number is

0:09:17.969 --> 0:09:23.217
<v B>now a negative, large negative number because the first bit got flipped, right? Like that can't happen. Yeah,

0:09:23.250 --> 0:09:25.967
<v A>Right. You know, statistically it's basically

0:09:25.967 --> 0:09:29.380
<v B>Not going to happen, but for someone it will happen.

0:09:29.380 --> 0:09:57.355
<v A>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,

0:09:57.355 --> 0:10:11.540
<v B>I guess that's what I was trying to say. Yeah. So the chance of your computer having a cosmic event change it in a meaningful way is, you know, one in a billion. But the chance of a cosmic ray affecting someone's computer in a meaningful way is, you know, very high in a given day.

0:10:12.200 --> 0:10:13.040
<v A>Yeah, right, right.

0:10:13.680 --> 0:10:22.020
<v B>So but yeah, so, yeah, okay. I don't know. Does it make any relevant difference today? Probably not, but it is an interesting question.

0:10:22.880 --> 0:10:23.680
<v A>Yeah, yeah, totally. Totally.

0:10:25.239 --> 0:10:30.500
<v A>So for like kind of, do you want to do news first or do you want to cover this? Let's cover this.

0:10:30.599 --> 0:10:31.199
<v B>Let's cover this.

0:10:31.640 --> 0:11:29.307
<v A>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

0:11:29.796 --> 0:11:33.319
<v B>TLDR of this intro is that you're getting old.

0:11:34.880 --> 0:11:37.800
<v B>I mean, wise. I mean, wise. Wise. You're getting wise.

0:11:38.640 --> 0:12:10.212
<v A>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

0:12:10.718 --> 0:12:10.959
<v B>Okay.

0:12:11.880 --> 0:13:09.440
<v A>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.

0:13:11.100 --> 0:13:37.169
<v A>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

0:13:38.822 --> 0:13:44.729
<v A>kind of, it's not really a shortcut. Because, like, often it doesn't save that much time. You're

0:13:44.729 --> 0:13:59.160
<v B>Overloading. Yeah, I do see this a lot. Yeah, yeah, yeah, exactly. Optimization, yeah, you're overloading a field or a value to mean multiple things, and it just makes it convoluted instead of breaking out to explicit fields.

0:13:59.800 --> 0:14:30.620
<v A>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.

0:14:30.620 --> 0:15:31.740
<v B>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.

0:15:32.920 --> 0:15:34.280
<v A>Yeah, yeah. That stuff is brutal.

0:15:35.820 --> 0:16:50.480
<v A>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?

0:16:50.480 --> 0:17:17.455
<v B>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,

0:17:18.079 --> 0:17:18.280
<v A>Yep.

0:17:18.660 --> 0:17:20.639
<v B>Yeah, totally. And that's hard, right? So.

0:17:21.440 --> 0:17:52.454
<v A>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,

0:17:52.454 --> 0:18:55.380
<v B>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.

0:18:56.360 --> 0:19:01.017
<v A>Yeah. I mean, this is why you're forcing them to you know study that. And they're like well, they

0:19:01.017 --> 0:19:09.880
<v B>could ignore the fact that you're returning a Boolean. I'm like yeah but at least it's like more obvious to someone reviewing the code that hey why is this returning a Boolean and why are you ignoring it?

0:19:10.680 --> 0:19:18.880
<v A>Yeah, right, right. I mean, in some languages you can't ignore return values. Like not without the compiler getting mad at you and stuff.

0:19:19.000 --> 0:19:19.840
<v B>Which is a good thing.

0:19:20.320 --> 0:19:29.260
<v A>Yeah, that's right. So, okay. Cool, man. Do you do exceptions in C? I don't think. Yeah. So, can't do anything there.

0:19:29.800 --> 0:19:31.120
<v B>But I do have assertions.

0:19:32.139 --> 0:19:33.000
<v A>Oh, okay. That's good.

0:19:33.120 --> 0:19:40.360
<v B>And typically the way I see it is that you have assertions disabled when you're in release, but in debug you have them.

0:19:41.080 --> 0:19:41.920
<v A>Yeah, that makes sense.

0:19:42.200 --> 0:19:55.800
<v B>And so that always leads to this debate: Should you have non-disableable assertions? And so then you end up with debug-only assertions and then regular assertions. And what is the semantics around it? But it gets really.

0:19:56.520 --> 0:20:05.901
<v A>Yeah, then it depends sort of on, you know, do you want your goal to be that the system survives anything? Yeah, or is your goal that like, you fail loudly? Like,

0:20:05.901 --> 0:20:11.300
<v B>Can you even theoretically recover from this? Yeah, right. So, yeah, well.

0:20:12.900 --> 0:20:15.580
<v A>The last one: reinventing the wheel.

0:20:17.660 --> 0:21:27.964
<v A>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

0:21:27.964 --> 0:21:32.860
<v B>Company, using open-source libraries may or may not get you into endless waiting with the lawyers.

0:21:36.030 --> 0:21:42.820
<v A>Yeah, so it depends on the license. Like, I think some licenses are. Am I a lawyer? No.

0:21:42.919 --> 0:21:50.980
<v B>Yeah, okay. Then if you work at any large company, regardless of that, you know, this, this license is safe to use, they'll first want it to be reviewed by a lawyer.

0:21:52.020 --> 0:21:53.850
<v A>Yeah, that's true. There are lawyers. That's

0:21:54.087 --> 0:21:57.500
<v B>Just, that, yeah. That's typically a problem.

0:21:57.520 --> 0:22:18.400
<v A>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.

0:22:20.300 --> 0:22:41.978
<v B>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,

0:22:41.978 --> 0:22:43.345
<v A>Yeah, yeah. You're using something,

0:22:43.345 --> 0:22:48.560
<v B>Right? So you have to make sure you have procedures in place so that you are keeping track of everything you're using.

0:22:49.400 --> 0:23:02.959
<v A>Yeah, definitely. Actually, that's interesting. I wonder if there's a Git hook for that, you know, where it somehow, like, Git can become aware of your open source libraries you're using. I don't know.

0:23:05.417 --> 0:23:06.500
<v A>I don't know where I'm going with that.

0:23:07.500 --> 0:24:42.584
<v B>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

0:24:42.719 --> 0:24:48.880
<v A>For really large numbers. You're solving like the recurrence, right? That's right. Yeah. You're solving like several steps in one.

0:24:49.040 --> 0:24:54.780
<v B>Yeah. Cool. And so it wouldn't—I, I didn't exactly, I know I'm trying to remember, but I, you know,

0:24:54.780 --> 0:24:57.974
<v A>I don't think this would work for a really small number. Like if you had, you

0:24:57.974 --> 0:25:09.120
<v B>know, three particles, right? Like it's random, so maybe it'll work, but you're going to have some weird stuff going on. But when you get into large numbers, right? Like it really all does. It all just becomes statistical.

0:25:10.460 --> 0:25:18.595
<v A>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,

0:25:20.721 --> 0:25:24.839
<v A>that sort of—I'm trying to see if I can grok this. So it's

0:25:26.594 --> 0:26:06.939
<v A>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.

0:26:07.840 --> 0:26:19.665
<v B>Yeah. It's not exactly—I'm not a statistician, but it's like your confidence interval, right? So like if 10% have tattoos and you have five people, like how many people have tattoos? It's like,

0:26:19.986 --> 0:26:20.965
<v A>Well, if all

0:26:21.977 --> 0:26:24.812
<v B>five did, that doesn't really prove anything. Like

0:26:24.812 --> 0:26:25.572
<v A>it doesn't

0:26:25.572 --> 0:26:33.160
<v B>say for certain that your 10% was wrong. It just like could be that you got really a very rare, a low probability event happened.

0:26:33.700 --> 0:26:34.100
<v A>Right.

0:26:34.220 --> 0:26:47.860
<v B>But you know, if you're, like you said, a hundred million people and you say 10% have tattoos, you're going to be plus or minus a few, like, you know, in the 99% confidence interval, your standard, like the amount of variance you expect to see is really low.

0:26:48.480 --> 0:26:49.540
<v A>That's right. Yeah.

0:26:49.639 --> 0:27:00.540
<v B>So this is taking that same approach, but it was an interesting thing to remind us that when you start to deal with very large numbers of something that you maybe need to step away from actually literally simulating it.

0:27:01.360 --> 0:27:13.227
<v A>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,

0:27:14.880 --> 0:27:45.080
<v A>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.

0:27:45.480 --> 0:27:50.820
<v B>Oh. And it was, it ended up being exactly this. So, so yeah. So read this article. Check this out.

0:27:50.879 --> 0:27:52.840
<v A>You could answer an interview question.

0:27:55.499 --> 0:27:57.034
<v B>So mine is,

0:27:57.034 --> 0:28:32.159
<v A>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.

0:28:32.340 --> 0:28:33.130
<v B>Oh yeah. Yeah. Yeah.

0:28:33.380 --> 0:29:11.980
<v A>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.

0:29:12.540 --> 0:29:55.564
<v B>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

0:29:55.564 --> 0:29:56.240
<v A>Out. Yeah, it's awesome.

0:29:58.200 --> 0:30:11.123
<v A>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

0:30:13.047 --> 0:30:48.602
<v A>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.

0:30:48.602 --> 0:30:53.700
<v B>Yet, but it was—it is interesting. I just skimmed it. I was like, 'Well, what is going on here?'

0:30:54.620 --> 0:31:06.180
<v A>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.

0:31:07.940 --> 0:31:09.820
<v A>So, yeah.

0:31:11.637 --> 0:31:34.755
<v A>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

0:31:34.755 --> 0:31:35.400
<v B>these for GDB.

0:31:36.680 --> 0:31:40.120
<v A>Oh, do you really? Yes. Are there really that many commands in GDB?

0:31:40.920 --> 0:31:41.900
<v B>Yes.

0:31:42.619 --> 0:31:52.780
<v A>Oh, have you used GDB before? Sure. The only thing I've done with GDB is halt the program when there's a C++ exception. So I know like two commands in GDB.

0:31:53.040 --> 0:31:55.560
<v B>Oh, there are yes, many, many commands in GDB.

0:31:56.000 --> 0:32:07.797
<v A>Oh, okay. So, yeah, in general there's a reference card for almost everything. Like if you're doing Java, there's a Java reference card. And I'm curious what a Java reference card

0:32:07.797 --> 0:32:08.708
<v B>has on it.

0:32:08.939 --> 0:33:13.060
<v A>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?

0:33:13.139 --> 0:33:35.344
<v B>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,

0:33:36.154 --> 0:33:38.517
<v A>I think I'm like the description from like, here's a

0:33:38.517 --> 0:33:54.860
<v B>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.

0:33:55.220 --> 0:34:01.860
<v A>Are you looking at the one from NYU.edu? No. Oh, I just typed in Java quick reference card.

0:34:02.080 --> 0:34:08.655
<v B>I typed in just Java reference card. I'm looking at one from. Oh. AC.UK. University of Glasgow. Glasgow.

0:34:08.740 --> 0:34:24.620
<v A>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.

0:34:26.420 --> 0:35:02.920
<v A>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.

0:35:03.400 --> 0:35:05.423
<v B>Oh, okay. It's

0:35:05.423 --> 0:35:09.820
<v A>moving on. Duct tape it to your monitor and, it helps a lot.

0:35:09.980 --> 0:36:03.878
<v B>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

0:36:03.912 --> 0:36:04.637
<v A>up, and I'm like,

0:36:04.637 --> 0:36:20.220
<v B>Oh, now that I know it's written in 1974, I understand these weird, like the computers they did have were very limited, and they had weird nuances to them. Yeah. Right. And so, now I've ruined it if you decide to read it, but it is a really good book.

0:36:20.220 --> 0:36:22.460
<v A>In the future, we'll have microwaves.

0:36:23.680 --> 0:36:31.540
<v B>Well, yeah. Well, so it's like, you know, Oh, the magnetic memory storage was one megabyte in size. It's like,

0:36:31.570 --> 0:36:32.481
<v A>that's

0:36:32.481 --> 0:36:33.443
<v B>so

0:36:33.764 --> 0:36:34.860
<v A>good.

0:36:36.320 --> 0:36:39.100
<v B>No, that's not exactly, but you know, something sort of like that.

0:36:39.180 --> 0:36:41.931
<v A>Yeah. Right. No, it's hilarious. And, but

0:36:41.931 --> 0:36:59.312
<v B>they managed to do a really good job actually of avoiding specific technologies, which has got to be hard to do. Yeah. Yeah, definitely. And so, but anyways, it's a, it's a story about, I don't like saying too much cause I don't, I don't want to ruin anything, but it's a space sci-fi adventure. So

0:37:00.359 --> 0:37:01.169
<v A>cool, man. Check

0:37:01.169 --> 0:37:10.280
<v B>It out. I really enjoyed it. And apparently I just found out when I was getting the link for the show notes that there's now, there's actually a sequel that was written in like the nineties. So now I like want to read the sequel.

0:37:10.700 --> 0:37:14.027
<v A>Oh, is it by the same person? Well, it's two people, Larry Niven and

0:37:14.027 --> 0:37:18.780
<v B>Jerry Pournelle. They're both science fiction authors, and they got together to write this book and the sequel.

0:37:19.580 --> 0:37:22.420
<v A>Wow. So they got together 20 years later to write the sequel.

0:37:22.500 --> 0:37:51.945
<v B>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

0:37:54.207 --> 0:37:55.500
<v B>still to now, I think.

0:37:55.520 --> 0:38:00.653
<v A>Have you ever written a short story or a book or anything? When I was

0:38:00.653 --> 0:38:02.360
<v B>in high school for school assignments?

0:38:03.900 --> 0:38:23.540
<v A>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.

0:38:25.520 --> 0:38:27.759
<v B>All right. Time for tool of the show.

0:38:28.259 --> 0:40:22.757
<v A>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

0:40:22.757 --> 0:40:25.200
<v B>used 'legit' and 'emulation' in the sentence together.

0:40:26.640 --> 0:40:33.962
<v A>So this is pretty epic. Pretty exciting. They even have a cool website. No. And

0:40:33.962 --> 0:40:45.620
<v B>No. What? Their website has my new, my newest pet peeve is the equivalent of the blink tag where you scroll down and stuff animates as you're scrolling. Like you don't like that. Oh, I hate that.

0:40:45.980 --> 0:40:52.964
<v A>Really? Oh, so much. I think it's so good. No. Oh, why? I think it looks awesome. No,

0:40:52.964 --> 0:40:55.832
<v B>it's awful. I think it's like,

0:40:55.832 --> 0:41:04.034
<v A>It's like a movie. You should feel bad if you write websites like that. It's like a movie that you can watch over and over again. No. So they, after the Apple announcement,

0:41:04.034 --> 0:41:12.201
<v B>for like the, is it the new iPad or the new iPhone? They did a website like this and it's just awful. So confusing. I very

0:41:12.201 --> 0:41:16.032
<v A>much just like it. There's one direction. Well, so this

0:41:16.032 --> 0:41:21.220
<v B>one actually doesn't scroll back until you scroll off screen. That's even weirder.

0:41:21.780 --> 0:41:28.200
<v A>That is weird. I like it when it's like, I can sort of relive the moment. Yeah. Yeah. Yeah.

0:41:28.200 --> 0:41:36.279
<v B>We had a website or news article like last time. And after I talked about it, I tried to actually read the whole thing and I had to give up because it was like doing this.

0:41:36.299 --> 0:42:41.318
<v A>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

0:42:41.318 --> 0:42:47.849
<v B>mint.com. I think we've probably, I'm sure we've talked about it before, but I don't care because I was just thinking the other day how, how awesome it is. Okay.

0:42:48.080 --> 0:42:48.895
<v A>So if

0:42:48.895 --> 0:42:49.958
<v B>you're not using

0:42:49.958 --> 0:42:57.220
<v A>Mint.com is completely broken. It's still—I just haven't been keeping up to date. I need to like reconnect it to my accounts and everything.

0:42:57.420 --> 0:43:21.900
<v B>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.

0:43:22.763 --> 0:43:23.759
<v A>Oh, and so

0:43:23.759 --> 0:43:40.583
<v B>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

0:43:40.583 --> 0:43:41.494
<v A>do occasionally there's periods

0:43:41.494 --> 0:43:44.640
<v B>where stuff stops working and then they eventually fix it.

0:43:45.740 --> 0:43:46.034
<v A>Okay.

0:43:46.220 --> 0:44:25.080
<v B>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.

0:44:25.380 --> 0:44:28.322
<v A>That never makes sense. It's usually, I think what you're doing, you know,

0:44:28.322 --> 0:44:36.372
<v B>but I don't, but what I do like is keeping tabs on where I'm spending money and like, right. Thinking about it. Like, hey, you know, that's a lot of money. I should cut back on that.

0:44:36.524 --> 0:44:42.200
<v A>Because yeah, it's Amdahl's Law, right? You get the biggest return for minimizing the biggest expense, right?

0:44:42.320 --> 0:44:56.800
<v B>Yeah. That. And also just like the fact that when you look at it in one place, you say, Oh, that's kind of a lot. Like I get, I should cut that back. And then I have been successful in doing it that, and I don't, the hassle of a budget never made me stick to it.

0:44:56.800 --> 0:45:53.960
<v A>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.

0:45:54.660 --> 0:46:04.341
<v B>Nice. Yeah. And I so like it for you looking at, and like I said, the trends to like, wow, I spend how much on clothes or whatever, like, Oh, that's kind of crazy. And like,

0:46:04.341 --> 0:46:06.540
<v A>Oh, your clothes spending is out of control.

0:46:06.680 --> 0:46:15.820
<v B>It's like, I know, which is kind of obvious, I guess, but like November and December we ended up buying, you know, Christmas gifts or whatever for family. And so then like spending in November and December are typically high.

0:46:16.540 --> 0:46:17.352
<v A>Right. And so,

0:46:17.352 --> 0:46:25.740
<v B>Like, Oh, okay. Like I know to be careful the next couple of months and like stuff not related to Christmas spending that I can wait because I know Christmas spending is going to be high.

0:46:25.740 --> 0:46:27.419
<v A>Yeah. Don't buy that shirt.

0:46:29.660 --> 0:46:30.060
<v A>Okay.

0:46:31.379 --> 0:46:38.560
<v B>Anyways, mint.com. You actually is clothes a large expense for you? No, I was just trying to say something generic and not very personal.

0:46:39.240 --> 0:46:46.022
<v A>I'm just giving you a hard time. That's my pet peeve is when I'm not giving Patrick a hard time. Are you

0:46:46.124 --> 0:46:50.020
<v B>saying I don't look stylish and handsome enough to be spending a lot on my clothes?

0:46:50.460 --> 0:46:56.380
<v A>I think you look so handsome that I demanded you show your face in the podcast and in the stream.

0:46:59.200 --> 0:47:02.357
<v A>Sim D. Sim D. All right. So

0:47:02.357 --> 0:47:03.040
<v B>right off the top.

0:47:03.920 --> 0:48:24.440
<v A>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.

0:48:25.120 --> 0:49:17.200
<v B>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.

0:49:17.980 --> 0:49:19.804
<v A>And so you need to be able to turn that off

0:49:19.804 --> 0:50:11.920
<v B>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.

0:50:12.235 --> 0:50:14.412
<v A>So late at night, 56. Oh man. It's too late.

0:50:14.412 --> 0:50:24.520
<v B>at night. 56 bits are all just going to be zero. So you're adding zero plus zero plus zero plus, you know, 56 times. And that's just a waste. Yeah. Right. Right. So that's how SIMD buys you an advantage. And I always

0:50:24.520 --> 0:50:33.902
<v A>thought that, I mean, so correct me if I'm wrong, like, but, and, and I'm probably wrong, but what is, I always thought that it was a separate processor than the ALU. Like I thought it was like a

0:50:33.902 --> 0:50:47.060
<v B>code. Sometimes, sometimes not. It is; these are all, this is like at a fundamental architectural—like they share these similarities, but sometimes just like floating point unit can be a separate thing or inline. Like it's just an architectural decision.

0:50:47.959 --> 0:50:49.259
<v A>Gotcha. Okay. That makes sense.

0:50:49.260 --> 0:51:30.980
<v B>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

0:51:30.980 --> 0:51:43.410
<v A>Common. Gotcha. So if it's 256-bit wide SIMD, then you can do what? You can add eight numbers in one instruction. Okay. Got it. Yeah. But

0:51:44.389 --> 0:53:16.611
<v B>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

0:53:17.455 --> 0:53:18.839
<v A>sequentially. Gotcha. And so that's

0:53:18.839 --> 0:53:33.640
<v B>That's a big difference. But the other difference is it's cheaper from a Silicon perspective to implement this, right? So, as opposed to a whole swarm of specialized GPU processors, some of the

0:53:33.640 --> 0:53:40.793
<v A>Common ones, like performance—like, is it the same? I mean, is it worse than a GPU or different? Oh, it's different. Depends on what

0:53:40.911 --> 0:53:53.770
<v B>you want to do, right? Like they're all different. So the GPU has advantages, but there are—it's more costly, right? So you're not going to typically; it's done in a different way. So like in a

0:53:54.242 --> 0:53:57.972
<v A>low-power, small processor, there's no way you'll ever have like

0:53:57.972 --> 0:54:00.030
<v B>a whole bunch of GPU cores.

0:54:01.400 --> 0:54:12.889
<v A>Gotcha. Cause they were talking at one time about like Intel wanted to put a GPU on the die motherboard. Yeah. On the actual core.

0:54:12.889 --> 0:54:21.820
<v B>Yeah. So you still have to—typically you would still want different memory because the access patterns are different. So you'd want to move back and forth between anyways, it gets complicated.

0:54:21.884 --> 0:54:23.453
<v A>Oh, I see.

0:54:23.453 --> 0:54:24.499
<v B>They're just

0:54:24.499 --> 0:54:25.680
<v A>two different tools.

0:54:25.680 --> 0:55:05.759
<v B>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

0:55:05.759 --> 0:55:07.024
<v A>like Penny three, Penny fours.

0:55:07.500 --> 0:55:41.145
<v B>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

0:55:42.664 --> 0:55:56.980
<v B>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.

0:55:58.759 --> 0:56:24.480
<v B>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,

0:56:24.480 --> 0:56:27.569
<v A>four and four, and you do them simultaneously. And

0:56:27.569 --> 0:56:36.158
<v B>then you'd have two sets of four resultant. Then you'd add those two sets. So now you've done three operations. This is really hard to describe over all. It

0:56:36.158 --> 0:56:37.997
<v A>becomes like a pair. It's like a pyramid.

0:56:37.997 --> 0:56:57.460
<v B>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.

0:56:58.360 --> 0:57:07.630
<v A>Yeah. Right. So, just a shout out to Pano DK who just subscribed to or followed the stream. Um, so thanks. Nice. Oh, he

0:57:08.136 --> 0:57:33.128
<v B>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.

0:57:33.364 --> 0:57:35.035
<v A>Yeah. Like the Quaternions, right? Yeah.

0:57:35.035 --> 0:57:36.360
<v B>So you typically

0:57:36.402 --> 0:57:54.846
<v A>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

0:57:54.846 --> 0:58:02.963
<v B>So I appreciate this. So this is four by four matrix multiply with pretty much all these kinds of SIMD instructions that works really well. And gives you a big speed up.

0:58:02.963 --> 0:58:03.975
<v A>Because you're doing that

0:58:03.975 --> 0:58:07.924
<v B>over and over and over again, 'cause you're doing coordinate transform after coordinate transform after coordinate. Yeah.

0:58:07.924 --> 0:58:15.130
<v A>Yeah. Just to put this in perspective, right? Like if you're doing, let's say you're making a video game, right? And,

0:58:16.665 --> 0:58:59.140
<v A>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,

0:58:59.140 --> 0:59:01.300
<v B>Like the spin of the bullet. Yeah. They have

0:59:01.975 --> 0:59:19.609
<v A>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.

0:59:20.402 --> 0:59:51.000
<v B>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.

0:59:53.123 --> 0:59:54.169
<v A>Suited. Gotcha. Makes

0:59:54.169 --> 1:00:05.300
<v B>sense. But this takes a lot of like, you know, hand power. And I, so I've written in several of these SIMD languages or not called languages, SIMD styles and almost

1:00:05.340 --> 1:00:06.623
<v A>extensions or extensions. Sure.

1:00:07.281 --> 1:00:53.130
<v B>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.

1:00:53.333 --> 1:01:02.648
<v A>That's the way I've kind of what happens if you get it wrong? Like, I mean, it probably doesn't throw an exception, right? I mean, like, do you end up with weird numbers or does it like literally, well, it

1:01:02.648 --> 1:01:03.940
<v B>depends on what you mean by mess

1:01:03.940 --> 1:01:11.811
<v A>it up. I, well, let's say like you have some kind of out-of-bounds or something like that. Like, do you get weird numbers or does the whole computer crash? It's typically like wraps

1:01:11.811 --> 1:01:32.095
<v B>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,

1:01:33.225 --> 1:02:53.702
<v A>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

1:02:55.289 --> 1:04:15.160
<v A>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,

1:04:16.289 --> 1:04:19.022
<v B>right? Yeah. I guess it depends on how they support it. I

1:04:19.022 --> 1:04:20.980
<v A>Don't know the exact specifics, but yeah. Um, the

1:04:21.722 --> 1:04:44.014
<v B>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

1:04:44.014 --> 1:04:45.027
<v A>have some

1:04:45.094 --> 1:05:29.240
<v B>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.

1:05:30.180 --> 1:05:46.755
<v A>Yeah. One thing that I realized I just searched on, on, our programming throwdown sort of agendas of all time. We've never talked about BLAS. Do you want to talk about BLAS? I think we should save it for a tool of the, okay. All right. Why

1:05:46.755 --> 1:05:49.253
<v B>don't you give the high level summary and then we'll

1:05:49.253 --> 1:06:38.660
<v A>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

1:06:38.660 --> 1:06:50.104
<v B>things. Yep. And they do some pretty clever stuff. And there's some pretty clever stuff about how to determine like, because there's no one right optimal way to do something. It's going

1:06:50.948 --> 1:06:51.842
<v A>to vary by

1:06:52.028 --> 1:07:03.469
<v B>your L1 and L2 cache size, by your number of hyper-threaded cores and by the number of your processor clock speed and like every variable of your computer system. And so I

1:07:03.469 --> 1:07:29.018
<v A>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

1:07:29.018 --> 1:07:36.308
<v B>know. Well, we can talk about later. I don't know if they do something intelligent, like gradient descent or something, or if they just straight out, like try every permutation. Yeah. I don't

1:07:36.899 --> 1:07:50.905
<v A>know if they do like something intelligent or if it's just a, yeah, like you said, it's just a raw parameter suite. Um, but, but, uh, okay. But yeah, it takes a really, really, really long time. And, uh, you know, most OSs will have it built in.

1:07:51.006 --> 1:08:01.435
<v B>And it'll be, you know, 90 something percent. I'm making up a percentage as, as fast as it can be. But if you compile it yourself, they do some really clever things to make it as fast as it can be. Yeah.

1:08:02.667 --> 1:08:22.242
<v A>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.

1:08:22.461 --> 1:08:29.447
<v B>Yep. Yeah. So everything's on the web now and everybody's trying to do graphics on the web. So of course, SIMD is coming to the web.

1:08:30.561 --> 1:08:33.683
<v A>Yeah, that's pretty wild, right? I mean, so if you're going to do

1:08:34.040 --> 1:08:55.367
<v B>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.

1:08:56.447 --> 1:09:39.614
<v A>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

1:09:40.052 --> 1:09:47.393
<v B>this is a SIMD is going to be added to Dart or so it said a year ago. So I assume it's already there. So

1:09:47.393 --> 1:09:49.958
<v A>man, you're right. This is a year old. I didn't even

1:09:50.734 --> 1:09:54.902
<v B>notice. So, you're starting to see a lot of these things. And again, you will

1:09:56.995 --> 1:09:59.419
<v B>continue as more and more people do stuff in the browser.

1:10:01.440 --> 1:10:33.377
<v A>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

1:10:34.896 --> 1:11:03.870
<v A>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

1:11:03.870 --> 1:11:04.880
<v B>it may end up being January.

1:11:05.929 --> 1:11:28.219
<v A>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

1:11:28.219 --> 1:11:29.959
<v B>how many reviews we have or anything.

1:11:31.107 --> 1:12:10.440
<v A>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

1:12:10.440 --> 1:12:12.130
<v B>anybody's name who told us not to, but

1:12:12.788 --> 1:12:16.686
<v A>no, I am totally kidding. Yes. I mean, if you want

1:12:16.686 --> 1:12:19.572
<v B>to remain anonymous, we will do that. Yeah.

1:12:20.567 --> 1:12:26.035
<v A>If you want to remain anonymous with your anonymity, anonymity, anonymity in tech. All right.

1:12:26.035 --> 1:12:29.240
<v B>It's late. So we're going to call it a wrap.

1:12:31.030 --> 1:12:33.059
<v B>All right. See you guys later. Stopping recording.

1:12:34.900 --> 1:12:56.740
<v A>The intro music is Axo by Binar Pilot. Programming Throwdown is distributed under a Creative Commons Attribution-ShareAlike 2.0 license. You're free to share, copy, distribute, transmit the work to remix, adapt the work, but you must provide an attribution to Patrick and I, and ShareAlike in kind.

