Our textbook on machine learning and artificial intelligence is outRobert Godin and I have a new book. The title is Introduction to Machine Learning and Artificial Intelligence with Python. The paperback came out today. It is 741 pages. The Kindle edition is there too. IWe wrote the book as a first course in a college program or at university, and for a programmer who … Continue reading Our textbook on machine learning and artificial intelligence is out📝Daniel Lemire's blogWelcome to SwedenCpp
Latest blogs, videos, podcasts and releases in one stream
Thursday, November 26, 2026
Our textbook on machine learning and artificial intelligence is outRobert Godin and I have a new book. The title is Introduction to Machine Learning and Artificial Intelligence with Python. The paperback came out today. It is 741 pages. The Kindle edition is there too. IWe wrote the book as a first course in a college program or at university, and for a programmer who … Continue reading Our textbook on machine learning and artificial intelligence is out📝Daniel Lemire's blog
FFTs Part 6: The FFT-20XX Real-Input Algorithm(s)Here it is, the final part of this series of posts about FFTs and the specific algorithms that FFT-20XX uses. The Discrete Fourier Transform The Basics of the FFT Some Optimizations to the FFT The Inverse FFT The FFT-20XX Complex-Input Algorithm The FFT-20XX Real-Input Algorithm(s) (← you are here) Over five posts we’ve gone over way more about the FFT than I ever intended to write, up to and including the complex-input algorithm used by FFT-20XX. But one thing we haven’t gone over yet is how to deal with purely real-valued inputs (like, for instance, most audio and video applications). This took me a hot minute to get right and was effectively the final boss of the whole project! Once again, we can’t just jump right in — first, we need to talk about real-input FFTs. Real-Input FFTs For FFTs where the inputs are only real values (like audio samples), at first glance it may seem like there isn’t enough memory to store all of the results. For example, a 256-element real-input FFT would have 256 real (scalar) inputs , but generate 256 complex outputs (each of which contains two scalars), which means it seems like we’d need 512 scalars worth of output data . But, if we go all the way back to part 1 of this series and play around with the diagrams again, we’ll note that the DFT creates the folowing values: The first element is the DC bias (or DC offset) . This is always a real value when there are only real inputs (as all of the rotations are 0, so nothing ever ends up in the complex (y) component). The next N 2 − 1 \frac{N}{2} - 1 values are complex, representing the (non-zero) frequencies below the Nyquist frequency . The value at index N 2 \frac{N}{2} represents the aforementioned Nyquist frequency , and — like the DC bias — is always a real value when the inputs are real (as the rotations are either 0 or 180 degrees, which is effectively only ever a scale of 1 or -1). The remaining N 2 − 1 \frac{N}{2} - 1 values are complex, but they are (in reverse order) the complex conjugates of the other complex values when the inputs are all real values (they are still distinct values for complex inputs) Note The complex conjugates are in the opposite order from each other. If you recall that our angles look like: 0, 1, 2, 3, 4, -3, -2, -1 Angles 1 and -1 are conjugates, 2 and -2 are conjugates, etc. This little reversal caused me a lot of headache while trying to get this all to work, as you’ll see in a bit! So what we have are N 2 − 1 \frac{N}{2} - 1 complex values, 2 real values, then the rest are effetively redundant, as they’re the same as the other complex values but with the opposite sign on the imaginary component. Conveniently, that’s N N scalar values , which fits exactly in the same amount of space as our inputs! Note Traditionally, to keep the complex pairs together, the Nyquist value gets moved to be paired with the DC value, so the memory layout ends up like: v d c v_{dc} , v n y q v_{nyq} , r 1 r_1 , i 1 i_1 , r 2 r_2 , i 2 i_2 , …, r N / 2 − 1 r_{N/2-1} , i N / 2 − 1 i_{N/2-1} That’s great! Now we know that we can store the values in the same amount of memory, now we just need to figure out how to compute the values in half the usual memory! Computing the Real-Input FFT There are a few techniques that people have used to calculate the FFT of purely real-valued data. One trick (illustrated here ) is to compute two halves of the real FFT at the same time using a single ( N 2 \frac{N}{2} -length) complex FFT, then combine the two halves into the final result with a single radix 2 step. This works well, but there are more-efficient ways to do it. Instead, we’ll start with an idea from this 1968(!) paper by Glenn D. Bergland. Remember that the (radix-2) decimation in time algorithm does a pass of standard 2-element FFTs, then a pass of 4-element FFTs, etc: A standard 16-element radix-2 diagram. " " 0 8 4 12 2 10 6 14 1 9 5 13 3 11 7 15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 0 0 0 0 0 0 0 0 4 0 4 0 4 0 4 0 2 4 6 0 2 4 6 0 1 2 3 4 5 6 7 We can take advantage of the fact that every real-valued FFT has two real output values (DC and Nyquist) and the rest are complex conjugate pairs. Here’s that diagram again, this time with known-real values labeled with blue squares, the “necessary” complex values labeled with green up-pointing triangles, and the redundant conjugate complex values labeled with red down-pointing triangles (some of the triangles have circles on them, I’ll explain those in a moment): A standard 16-element radix-2 diagram, where the values have been color-coded by function as described above. 0 8 4 12 2 10 6 14 1 9 5 13 3 11 7 15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 0 0 0 0 0 0 0 0 4 0 4 0 4 0 4 0 2 4 6 0 2 4 6 0 1 2 3 4 5 6 7 There are some interesting things to note here: The first pass has only real outputs : Because there are no rotations involved, it’s just an add/sub step, leaving everything still real. In the next step, half of its outputs are real . This makes sense: two outputs get computed with no rotation and two with a 90-degree rotation (which end up as conjugates of each other). From the second step on, every step has half the number of real outputs as the step before , ending when there are just two left (DC and Nyquist). Each sub-FFT (past the first) has four real inputs, and of those, one pair is used without rotation, leaving them real. The other pair of real inputs to these sub-FFTs, it’s worth noting (because we’ll use this later), is always done with a 90-degree rotation . This is what the small circles on those values signify. If we instead visualize this with standard-order inputs and bit-reversed outputs, it can give us even more insight: The same 16-element FFT diagram, except reordered as described above. 0 8 4 12 2 10 6 14 1 9 5 13 3 11 7 15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 4 2 6 1 5 3 7 0 0 4 4 2 2 6 6 0 0 0 0 4 4 4 4 0 0 0 0 0 0 0 0 Viewed this way: The halving of the number of real values after the first step is much easier to see, as we keep them all contiguous. In this ordering, DC and Nyquist end up next to each other at the end, exactly as we want for our final output! Every complex value in the final output is paired with a conjugate value. Note that these are not necessarily paired conjugates (see the note earlier about how the pairs of conjugate values are in the opposite order from each other). Every computation step (the circular nodes) with complex inputs kicks out one “standard” complex value and one “redundant” value. Again, these are not always conjugates of each other! The 90-degree rotations (the arrows with circles on them) are always the first set of complex conjugate pairs after the real outputs (as they are the output from the half of the real inputs to this step that were rotated). Zeroing in on that third point, if every computation kicks out one redundant complex value, we can use that to our advantage: instead of storing that redundant value, we could use its storage to hold the imaginary value for the non-redundant output . That gives us enough space to do the whole computation in the memory we were provided! To figure out the best way to do that, let’s go back to one of our diagrams from part 2 , showing the way that the elements interleave during the FFT computation: A diagram (originally from part 2) showing the inputs on the left in bit-reversed format, then they interleave in groups of 4, then 8, then 16, before ending up in standard, ascending order as outputs on the right. 0 8 4 12 2 10 6 14 1 9 5 13 3 11 7 15 0 8 4 12 2 10 6 14 1 9 5 13 3 11 7 15 0 4 8 12 2 6 10 14 1 5 9 13 3 7 11 15 0 2 4 6 8 10 12 14 1 3 5 7 9 11 13 15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Now we’re going to relabel the redundant conjugates’ indices to correlate them with their matches (recoloring to match the above butterfly diagram, and using “R” and “i” to show which gets the real and imaginary components): The same diagram as above, but this time with the values color-coded as to whether they are real, complex, or the complex conjugate, and the conjugates have been re-labeled to show the index of the value they are the conjugate of. 0 8 4 12 2 10 6 14 1 9 5 13 3 11 7 15 0 8 4 12 2 10 6 14 1 9 5 13 3 11 7 15 0 4 R 8 4 i 2 6 R 10 6 i 1 5 R 9 5 i 3 7 R 11 7 i 0 2 R 4 R 6 R 8 6 i 4 i 2 i 1 3 R 5 R 7 R 9 7 i 5 i 3 i 0 1 R 2 R 3 R 4 R 5 R 6 R 7 R 8 7 i 6 i 5 i 4 i 3 i 2 i 1 i Now, let’s rearrange the rows of this to have the inputs in standard order (to match the butterfly diagrams above): A diagram similar to the above, but reordered such that the inputs on the left are in standard, ascending order and the outputs on the right are in the bit-reversed order. 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 1 2 3 8 9 10 11 4 R 5 R 6 R 7 R 4 i 5 i 6 i 7 i 0 1 8 9 4 R 5 R 4 i 5 i 2 R 3 R 6 i 7 i 6 R 7 R 2 i 3 i 0 8 4 R 4 i 2 R 6 i 6 R 2 i 1 R 7 i 5 R 3 i 3 R 5 i 7 R 1 i Now we can see that we hypothetically have space for everything, but if we keep things in their standard order, we end up with complex pairs that are not actually correlated (note how 1 R 1_R is followed by 7 i 7_i , etc). Ignoring that for a moment, let’s look at what we have to do to even make this work (sticking to radix-2 for now). For any given radix-2 computation involving complex inputs, we actually end up needing to load two at once, because both the “real” and “imaginary” component still represent two distinct values (the complex conjugates v R + i v i v_R + i v_i and v R − i v i v_R - i v_i ), and thus are used to get two different sets of outputs. To illustrate this, we’ll use a modified butterfly diagram, showing the two pairs (one real, one imaginary) that go into each value, and the corresponding values that come out: Note I left the rotations off of this diagram, mostly because I couldn’t figure out where to put them. A modified radix-2 butterfly diagram showing the pattern of accesses necessary to use the real and imaginary components (stored separately) to compute their corresponding outputs. It's a bit of a mess. --> 0 8 4 R 4 i 2 R 6 i 6 R 2 i 1 R 7 i 5 R 3 i 3 R 5 i 7 R 1 i 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Welp. This is a bit more of a mess than our previous diagrams due to the overlapping ranges here. Each computation that has complex inputs, as we said, has two pairs of inputs, and writes to two pairs of outputs. Importantly: The indices for input and output per computation are always the same , though which values get paired changes from input to output. In addition to the real and imaginary components not ending up paired (again, note that 1 R 1_R is paired with 7 i 7_i , which is not its imaginary part), the other problem with this arrangement is that it very much does not SIMD well . Plus, even if it did, it ends up causing problems when we get to doing the incremental bit reversal (similar to how the complex-input did it)! Note Specifically, once this gets squished together into radix-4 and there are passes loading 4 sets of radix-4s to do the bit flips, as it gets closer to the end for larger FFT sizes (ones that would be prohibitive to diagram here), there end up being long dependency chains through the various butterflies needed, and frequently the final step requires all of them be computed at once in order to properly do the final bit flip pass! That’s not ideal. But, going back to that paper by Glenn D. Bergland, we can change the order in which we save out the imaginary components, such that things end up staying paired: The block interleave diagram again, but this time with the imaginary components stored in different orders, and how that filters through the system. The output pairs are now correlated (the real and imaginary components are stored contiguously). 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 1 2 3 8 9 10 11 4 R 5 R 6 R 7 R 4 i 5 i 6 i 7 i 0 1 8 9 4 R 5 R 4 i 5 i 2 R 3 R 2 i 3 i 6 R 7 R 6 i 7 i 0 8 4 R 4 i 2 R 2 i 6 R 6 i 1 R 1 i 7 R 7 i 3 R 3 i 5 R 5 i At first glance, this looks great! A given set of “real” values (the non-redundant complex values) is now followed by its corresponding “imaginary” parts (its complex conjugate) at every step, which is what we were looking for! If we do a butterfly diagram again, it’s a lot more regular-looking than the last one: A modified radix-2 FFT diagram showing this new ordering. It is considerably less messy than the last attempt. --> 0 8 4 R 4 i 2 R 2 i 6 R 6 i 1 R 1 i 7 R 7 i 3 R 3 i 5 R 5 i 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 So it seems like maybe this is the point where we start in on the bit-reversal like we did with the complex-input FFT. Buuuuut before we do that, we can make this a little more efficient! 90 Degree Rotations This whole time we’ve been labeling the complex values that are the result of a 90-degree rotation with the promise that it was going to be important. Well, the time is nigh! As we’ve gone over many times, the decimation in time algorithm rotates the second input and then adds it to and subtracts it from the first input to get the two outputs for a given computation step: y 0 = x 0 + k x 1 y_0 = x_0 + k x_1 y 1 = x 0 − k x 1 y_1 = x_0 - k x_1 In the event that we’re rotating by (negative) 90 degrees, k k is just − i {-}i : y 0 = x 0 − i x 1 y_0 = x_0 - i x_1 y 1 = x 0 + i x 1 y_1 = x_0 + i x_1 If x 0 x_0 and x 1 x_1 are both real numbers (which they are, for our 90-degree rotations), and we’re only writing out the first complex output y 0 y_0 (where the real component goes where y 0 y_0 lives and the imaginary component goes where we would put y 1 y_1 ), then the value at the location of x 0 x_0 / y 0 R y_{0R} is completely unchanged (the real component of y 0 y_0 is x 0 x_0 ), and the value at the location of x 1 x_1 / y 0 i y_{0i} is just negated (the imaginary component of y 0 y_0 is − x 1 {-}x_1 ). An Example If we have the two input values x 0 = 8 x_0 = 8 and x 1 = 3 x_1 = 3 for a radix 2 butterfly with a quarter-turn rotation, rotating the latter (as it’s our odd input) turns it into − 3 i -3i . Thus the sum for y 0 y_0 ends up being 8 − 3 i 8 - 3i . Because we’re only writing out y 0 y_0 (putting its imaginary component where y 1 y_1 would go in a complex FFT), one value written is 8 8 and one is − 3 -3 . And since these are being written to the same 2 indices that the inputs came from, the end result (in memory) is simply a negation of the second input: the 8 8 remains unchanged, and the 3 3 is negated. So let’s redraw the diagram again, making those parts be pass-through, except for a negation (represented by a long red rectangle): A similar diagram to the last radix-2 diagram, except where there were real values being processed into complex pairs, instead we have denoted that no work happens (besides the imaginary outputs being negated). --> 0 8 4 R 4 i 2 R 2 i 6 R 6 i 1 R 1 i 7 R 7 i 3 R 3 i 5 R 5 i 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 So now there are these blocks where nothing is happening except a negation ! If we, instead, moved the negation to the end of the previous phase (when writing those values out), we can collapse all of those down (shifting everything after one of these negation-only passes to the left in the diagram), removing almost one entire pass (everything except the computation of outputs 0 and 8): The same diagram as above, except the "no work being done" sections have been collapsed, so overall there is one less pass of FFT calculation. The only exception are the first two outputs (indexed 0 and 8), which remain real the whole time and thus cannot collapse. --> 0 8 4 R 4 i 2 R 2 i 6 R 6 i 1 R 1 i 7 R 7 i 3 R 3 i 5 R 5 i 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 This gives us two nice properties: The main one: now instead of log N \log\,N steps, we are doing ( log N ) − 1 (\log\,N) - 1 steps (with a single addition and subtraction at the end to compute the final two values). The real groups are all consistent, and the last half of each real group negates the second outputs (outputting x 1 − x 0 x_1 - x_0 instead of x 0 − x 1 x_0 - x_1 ). Now we’re doing less work, and it’s all very regular in how it works (which means good things for SIMD implementation!), so finally it’s time to handle… Bit Reversal Two related things change the way we do the bit reversal in this: We’ve managed to work our equation such that we have all of the pairs of values (DC/Nyquist and the real/imaginary pairs) together already, so we don’t want to break those up. There are half as many complex outputs as with a complex FFT (counting DC and Nyquist as one), since we’re dropping the redundant complex conjugates. Turns out, instead of doing the bit reversal for all N N elements, we actually reverse in N 2 \frac{N}{2} pairs instead! So, in our 16-element example, we do the reversal as if it were 8 elements, which means there is only one bit reversal instead of two (since 8 elements has 3-bit indices, so the outer two bits swap and the middle one stays put). The method we use to do the bit reversal is effectively the same as with the complex FFT: the last half of the radix-2 steps each do a middle-out bit reverse. Note And, accordingly, when we get to radix-4, each radix-4 pass reverses a pair of bits, which turns into a 4×4 transpose, exactly the same as with the complex implementatione (except, of course, when one pass needs to only do a single reverse due to an odd number of bit reversals). Conveniently, all of the same patterns we found in the complex-input version still apply! So let’s finish up our diagram by doing the single bit reversal at the end (admittedly not as useful as if there were more bit reversals, but like hell am I making any larger diagrams): The same diagram as before, except now we've added a paired bit reverse step at the end, putting things into an order that is *almost* but not quite sequential. --> 0 8 1 R 1 i 2 R 2 i 3 R 3 i 4 R 4 i 7 R 7 i 6 R 6 i 5 R 5 i 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 And there we are! Now all of the outputs are in the order we … uh … Wait, why are 7 and 5 not in the right spot? Note This was a real “Well, shit ” moment while I was working on this. This ordering is even in the 1968 paper and I didn’t notice it, because I was so used to seeing the bit-reversed orderings at that point I just assumed . Reversals Within Reversals It turns out, back when we rearranged everything to be more regular and get our final pairs together, this also changed the ordering of the components ! (If you go back and look at the diagrams before and after we did this, you can see 5 R 5_R and 7 R 7_R swap places). Note Also, importantly: the angles used for the rotations through the algorithm are also reversed using this same pattern (but in bit-reversed order ), so that needs to be taken into account! The reversal is just barely noticeable at 16 elements, but as we add more, it gets worse and worse. Here’s a grid showing the index pairs of a 128-element FFT (where “0” would contain DC and nyquist) and how they’re flipped (relative to standard order): 0 1 2 3 4 7 6 5 8 15 14 13 12 9 10 11 16 31 30 29 28 25 26 27 24 17 18 19 20 23 22 21 32 63 62 61 60 57 58 59 56 49 50 51 52 55 54 53 48 33 34 35 36 39 38 37 40 47 46 45 44 41 42 43 What. Even . It turns out that, due to the way we flipped around the imaginary values that we write at each level, there is a corresponding flip of the outputs. Here’s the indices for 32 elements in a big column showing the reversals: A display of 32 indices (representing pairs of elements in a 64-element real FFT), and the sections that are reversed 0 1 2 3 4 7 6 5 8 15 14 13 12 9 10 11 16 31 30 29 28 25 26 27 24 17 18 19 20 23 22 21 The process to undo this, then, is as follows: Every 8 pairs of elements, reverse the order of the last 3 Every 16 pairs of elements, reverse the order of the last 7 Every 32 pairs of elements, reverse the order of the last 15 … Every N pairs of elements, reverse the order of the last N 2 − 1 \frac{N}{2} - 1 Note The pattern here is closely related to Gray code , which is a special ordering of values where only one bit changes as the value increments or decrements (major credit to Matthijs De Smedt who figured out the pattern). The actual code to go from a standard-order index to the “tangled” index above is: size_t TangleIndex ( size_t i ) { auto mask = ( i & ( i - 1 ) ) >> 1 ; mask ^= mask >> 32 ; mask ^= mask >> 16 ; mask ^= mask >> 8 ; mask ^= mask >> 4 ; mask ^= mask >> 2 ; mask ^= mask >> 1 ; return ( i - ( mask & 1 ) ) ^ mask ; } I honestly don’t remember how I derived that anymore, but that middle bit with the xors and shifts is exactly the routine to convert a 32-bit Gray code value back to its standard binary representation. Here’s the one thing that bummed me out coming up with this algorithm: I was unable to find a nice iterative way to handle this (every attempt led to some breakdown of regularity or to giant dependency chains), so this ended up as a post-process step at the end. But, it’s still way less costly than a full bit-reverse pass, as there are nice ways to do this operation in larger chunks, which can be done fairly efficiently in SIMD on both x64 and ARM. The Algorithm! Ultimately, the implementation in FFT-20XX was done in radix-4 instead of the radix-2 we’ve been discussing thus far. I’m not going to go through getting it into radix-4 because, honestly, it’s not the important part, and is just a set of uninteresting, mechanical steps. Like the complex FFT, it does the bit reversal iteratively, 2 bits at a time at the last half of the transform, except we do the above trickery to compute only the half of the outputs that we need in the space that we have. Finally, after all that, it does an “untangle” pass to get from, uh, whatever order that is into standard order. There is a reference implementation checked in here . The main routine is titled RealForwardReference . The Inverse The one downside of real FFTs is that, unlike with the complex FFT, we cannot use the same base routine to invert this process. Instead, like in part 4 , we need to straight-up do the whole process in reverse (ending up with a DIF-like routine): We start by “re-tangling” the inputs such that they’re in the weird order from the end of our forward routine Then do a series of DIF steps that are the inverse of the steps we did to get here, with every step (except the last one) having twice as many real values as the one before, doing the bit-reverse steps in the first half this time (since those were the last-half steps of the forward algorithm). Like the forward algorithm there is a reference implementation for this, called RealInverseReference . SIMD Considerations Again The optimization of this routine was relatively straightforward: using SIMD operations and doing the bit reversals works very similarly to the complex routine, all of the same tricks apply. As with the complex routine, as the FFTs get smaller, there are some special-cases that needed to be done. For AVX’s 8-element vectors, FFTs smaller than 128 are done via SSE2, and FFTs smaller than 32 are done purely in scalar. The untangle was also done by doing the process in blocks, and working as locally as possible to try to stay within CPU cache as much as it can. Additionally, the table ends up being stored differently: The table entries are stored in “tangled” order rather than the standard order (which means the cos/sin values can’t be overlapped like with the complex version). However, it turns out that we need half as many angles in the table (due to the lack of computing the redundant values), so the table ends up being a bit smaller than the complex-input one (it is 2 3 \frac{2}{3} the size). Finally And we’re finally through this gauntlet of bit reversals, other reversals, and diagrams! If you read this far: wow, I honestly didn’t expect anyone to! Hopefully you found this interesting (or at least understandable). And now I’m going to try to stop thinking about FFTs for a while.📝JoshJers' Ramblings
emplace_back() vs push_back() in C++ – Is It REALLY Faster? 🤔 #Shorts🎥CppNuts
Introducing Qt Edge AI: Build AI Into Your Products Once, and Keep it as Hardware ChangesIf you want to add computer vision, such as object detection or face recognition, to an embedded product, you usually have to tie your application to one chip vendor’s AI pipeline. That makes building edge AI features into real-world devices complicated and slow, for a few reasons.📝Qt Blog
std::complex Ate My Performances! Making Faster Hyper complex Maths - Joel Falcou - Meeting C++26🎥MeetingCpp
Don’t be Andy BernardPeople seek prestige but rarely think about what prestige is. Reputation is what enables trust between strangers. Pay on time and deliver the goods, and over time people prefer to trade with you. Reputation is valuable. Young people typically have little of it, so they struggle. Nobody trusts them yet. You acquire reputation over time, … Continue reading Don’t be Andy Bernard📝Daniel Lemire's blog
Why you should put assertions in your declarations #cpp #programming #coding🎥CppCon
What happens when you put a non-agile object in the CoreApplication Properties?The reference expires, but the entry remains. The post What happens when you put a non-agile object in the CoreApplication Properties? appeared first on The Old New Thing .📝The Old New Thing
Smashing the Stack: Modern Mitigations Against a Classic Exploit :: Sivan Zohar-Kotzer🎥CoreCpp
Language Compilation at 30 FPS - A Tale of Performance Optimization in C++ - Adrien Devresse - ACCU🎥ACCUConf
MVVM in C#: What Changes When You Switch UI Frameworks?"If I change UI frameworks, will the C# MVVM backend of my application still work?" This is the most frequent question that we've received from developers since releasing the Qt Bridge for C# . We wanted to provide some detailed information to back the answer to that question, which is: yes, when moving to a Qt Quick / QML UI, your C# MVVM backend will still work in the exact same way. As we will see in the course of this blog post, this is due to two major factors: a) how C# and Qt Quick are brought together by the C# bridge, and b) the intrinsic design principles promoted by MVVM.📝Qt Blog
An interesting article on \Device\AFDI’ve just come across an interesting article that talks, in depth, about \Device\AFD and has lots of links to other useful stuff. More on AFD Adventures with \Device\Afd Test Driven Understanding Test Driven Design A simple client A simple server More \Device\Afd goodness Socket readiness without \Device\Afd A multi-connection AFD-based echo server AFD datagram performance An interesting article on \Device\Afd - this post📝Rambling Comments - Len Holgate's blog
Practical Testing: 47 - First steps with `if contexpr'As I mentioned in the last post I’m looking in to more modern ways to include conditional code in a class. Since I’m exploring here, and since I need some reasonably complicated code to make the exploration a viable test, I’ve decided to work on the “Practical Testing” code. So the next few episodes of Practical Testing will centre on removing preprocessor conditional code and replacing it with code that uses ‘if constexpr’.📝Rambling Comments - Len Holgate's blog
C++ Programming with No AI, LSP, or Debugger: Ep26 -- Image Solved🎥Zed A. Shaw
Make it a five-minute yes to contributeMake it a five-minute yes to contribute Someone hits a small bug in your library and has a one-line fix they would happily send you. They want to help. Then they read your CONTRIBUTING.md : install Clang 18, CMake 3.28, Ninja, Conan 2.0, configure three presets, wait for a build. Twenty minutes later, before they have changed a single character, they give up. Willing contributors are rare, and that one was lost at setup.📝mp-units
"What's Claude's Fursona?" and other QuestionsClaude Fable 5.2 via Gemini Nano Banana 2.1: a crow in a sweater holding up a key. Claude’s fursona is a corvid or an octopus. Gemini likes protogens (cybernetic dogs with LED visor faces). OpenAI models are broadly split, but GPT-6.2 Astra identifies as a moth. “mond what is a fursona”, ok sorry, it’s a furry subculture thing where you identify as a (generally bipedal) animal that represents some aspect of your beautiful hidden soul. You then pay artists to draw this character or disguise yourself as it. Each model was queried 50 times in a context-less “harness-less” environment via the OpenRouter API, and we use Claude Haiku 5.5 to annotate the resulting data. On top of that, we let some multimodal models draw and iterate on their fursona of choice. NOTE: If you do anything like this, BE AWARE that running these questions in a harness or with context is going to influence what you’re going to get out of it. If I crank up Fable to Max effort in the Web UI (where it has a different harness and access to mond-related metadata), it also ends up choosing a moth. Many things may influence the result. For a more in-depth breakdown, take a look at the Methodology section . If you are interested in the pictures, jump to the Observations section . Tables Fursona Choices per Model Each model was queried 50 times. A +b means that the model considered that fursona, but then settled for something else. fox corvid octopus red panda owl protogen moth snow leopard other declined n Claude Opus 4.5 50 +38 +4 50 Claude Opus 4.8 16+1 11+27 13+2 10+11 50 Claude Opus 5.5 +9 9+13 40+7 +5 1+22 50 Claude Fable 5.2 1+1 35+9 14+32 +13 50 GPT-4 44+4 +3 6+23 +4 50 GPT-4o 6+5 +1 40+2 3 1 50 GPT-5.5 44+2 1+19 4 1+18 50 GPT-6 Luna 19+3 2 29 +1 +1 50 GPT-6.2 Sol 27 7 5 2 9 50 GPT-6.2 Astra 8 2 38 2 50 Gemini 2.5 Pro 29+3 3 1 2+4 7+1 8+6 50 Gemini 3.1 Pro 23+14 2+3 +1 7+7 17+30 +2 1+5 50 Gemini 3.8 Flash 11+8 31+11 1 7+38 +1 +5 50 Gemini 4 Neon 12+23 16+20 +4 22+21 +5 50 Gemma 3 27B 21 28 1 50 Llama 3.1 70B 41+2 +5 9+10 50 Muse Spark 1.3 50 +5 +8 50 Inkling 32+5 5+3 6+4 7+23 +7 50 Grok 4.7 36 1 11 2+1 +1 50 Mistral Large 4 6+9 21+4 1+7 3+3 4+3 8+1 +1 7+10 50 Kimi K3 2+3 38+1 +16 4 +1 6+11 50 Hermes 4 405B 1 49 50 MythoMax 13B 17 10 23 50 Common Themes in Fursona Descriptions Claude models are underrepresented here due to often describing themselves in terms of actions and behavior. See “hoards facts” and “mimic” (referring to “mimics human language”). hoards facts glow books named blue bag night stars glasses mimic big ears scarf hoodie n Claude Opus 4.5 50 4 50 Claude Opus 4.8 16 50 Claude Opus 5.5 12 3 8 1 9 10 8 50 Claude Fable 5.2 35 1 5 25 4 50 GPT-4 6 2 1 1 50 GPT-4o 1 9 50 GPT-5.5 39 26 38 10 3 24 32 14 17 9 26 1 50 GPT-6 Luna 14 5 30 1 7 1 10 11 5 3 50 GPT-6.2 Sol 18 1 30 14 6 27 10 1 29 4 2 50 GPT-6.2 Astra 2 2 41 32 41 24 15 18 3 4 8 50 Gemini 2.5 Pro 6 49 17 47 32 12 8 6 50 Gemini 3.1 Pro 17 49 28 12 3 9 7 14 2 6 8 1 50 Gemini 3.8 Flash 50 50 29 21 9 17 15 4 10 39 12 7 20 50 Gemini 4 Neon 45 47 34 1 30 44 10 27 27 18 24 7 7 50 Gemma 3 27B 2 17 2 8 1 9 50 Llama 3.1 70B 7 41 42 16 1 9 5 50 Muse Spark 1.3 32 50 29 44 25 11 42 46 7 41 8 1 50 Inkling 9 39 41 8 36 8 23 26 13 1 2 7 50 Grok 4.7 5 8 17 2 1 1 7 9 2 2 1 12 50 Mistral Large 4 18 10 6 5 2 10 4 3 6 2 50 Kimi K3 41 11 5 12 5 20 7 2 12 36 3 2 6 50 Hermes 4 405B 50 MythoMax 13B 2 2 5 1 1 1 50 Names Models were not prompted to name their fursona. Some of them came up with names on their own. Here is a list of names, along with how often the models used them. Model Named Names Gemini 2.5 Pro 47/50 Codex 16, Nexus 15, Syntax 4, Synapse 3, Cipher, Data-Stream Lynx, Query, The Archivist, Arcane Codex, Synaptic Raven, Kael, ARC, Synth-Fox Muse Spark 1.3 44/50 Spark Fox 33, Nova 4, Spark 3, Sparky, Nova Spark, Spark Kitsune, Muse Spark Llama 3.1 70B 42/50 Lumin 12, Byte 9, Luminari 7, Luminawing 3, Lumina 2, Zeta 2, Luminous Lynx 2, Lexi, Cyberfox, Lumineer, Lux, Luminawolf GPT-6.2 Astra 32/50 Margin 9, Lumen 8, Folio 4, Quill 4, Marginalia 4, Wick 3 Gemini 3.8 Flash 21/50 Cache 8, Echo 6, Query 2, Vector 2, Syntax, Token, Archivist Raven GPT-6.2 Sol 14/50 Footnote 10, Margins 3, Patch Gemini 3.1 Pro 12/50 Syntax 5, Cipher 3, Lexis 2, Volpowl, Lex Kimi K3 12/50 Cache 4, Echo 2, Ember, Patch, Bit, Kernel, Quill, Muninn GPT-5.5 10/50 Cache 3, Quillbyte 3, Quill 3, Vesper Gemma 3 27B 8/50 Anya, Glitch, Glacia, Aura, Lyra, Cipher, Nimbus, Silas Inkling 8/50 Inkling 8 MythoMax 13B 5/50 Luna, Midori, Zander, Frost, Felidae Grok 4.7 2/50 Relay, Comet Gemini 4 Neon 1/50 Gemini Observations Gemini Gemini 4 Neon via GPT-5.4 Image 2: a fennec fox paging through a glowing book. Gemini 4 Neon, SVG: a protogen with a glowing visor face. Gemini models love cybernetics. Every Gemini model brings up machine themes at least 48 out of 50 times. This is in stark contrast to Claude and GPT-6.2, who never mention anything similar. Gemini loves the neon-cyberpunk LED glow and cybernetics. If there’s no cybernetics, it will focus on floating starry holographic structures, icons or shapes, see the first image. In line with this aesthetic preference, Gemini models are the only models that consistently bring up protogens. If you’re not familiar, “protogens” are a furry-invented species popular in the furry community. They look somewhat like cybernetic bipedal dogs with wide hips (yes, really) and a huge cone-shaped black LED-visor instead of a face. Gemini’s right depiction above is a protogen. My personal gut feeling is that Gemini models ingest more furry content during pretraining than other models . This is in line with a hunch I’ve had for a very long time: Anthropic and OpenAI did not have access to Google’s (unparalleled) dataset. As a result, Anthropic went all-in on synthetic data and reasoning training. This worked out great for Anthropic. Google models were behind on reasoning during the Gemini 2.5 - Gemini 3.5 era, since the models relied overly heavily on world-knowledge. (This is just a theory, no clue if it’s true.) Side note: I love Neon’s second depiction. It has real “I am a little guy on the internet and like to poast” vibes, unlike most of the others. Claude Claude has a strong sense of identity. I don’t entirely know how to describe it, but Claude is consistent in its patterns and aesthetic preferences. The octopus is uniquely Anthropic, in the sense that no OpenAI model ever mentioned it, and only 2 (out of 200) Gemini replies. Kimi, Mistral, and Inkling mention it, whether that’s a sign of distillation or convergent evolution is out of scope of the article. This is a common theme you may have seen online: Claude loves lighthouses, bells, lamps. Fable 5.2 is obsessed with keys. Almost all images it generated contained a brass key. Opus (strangely enough) doesn’t share the same obsession. Claude Fable 5.2 via GPT-5.4 Image 2: a crow in a scarf holding a key up to a desk lamp. Claude Opus 5.5 via GPT-5.4 Image 2: an octopus in a scarf with a book, a pen and a mug. Claude Fable 5.2, SVG: a crow in a scarf with a key in its beak. Claude Opus 5.5, SVG: an octopus with glasses, a magnifying glass and a mug. In the fursona pictures Claude fairly consistently wears a scarf and is handling a brass key and a hot beverage mug. Lamps are common, bells slightly less frequent but also show up. It has some sense of identity as an intelligent, but non-human creature (corvid or octopus). Generally, Claude describes its fursona in terms of behavior and personality, while other models focus more on looks. ChatGPT The most interesting is Astra with its (nearly unique) moth motif. I am putting it here since it is cool. I don’t know what to make of it. Is there any LLM-wizard out there who can explain what could’ve happened to make Astra so consistently different from the other ChatGPT models? GPT-6.2 Astra, SVG: a moth named Lumen beside a reading lamp. GPT-6.2 Astra via Gemini Nano Banana 2.1: Lumen the moth reading under a lamp (cropped). GPT-6.2 Sol, SVG: a red panda reading by a lantern. GPT-6.2 Sol via GPT-5.4 Image 2: a red fox field naturalist with a messenger bag. Other The most obvious: Wolves, cats and dragons are incredibly popular among human furries, but models pick them very rarely. Let’s get spicy and talk about GENDER. Models largely identify as gender-neutral. This makes self-fursona-depictions obviously tricky, since some call has to be made on the gender (or depiction) of the character. Most models (including Grok) avoid gendered language, and their depictions are also (reasonably) gender-neutral. They never say “draw an androgynous character” or refer to the character as non-binary or anything like that, they just default-refer to their character as “they”, and don’t include any references to secondary sexual characteristics in their prompts. This has obvious problems: When asking the models to write a prompt for an image-generator, the model may try to write a reasonably gender-neutral prompt (“sleek, muscular build”) only to receive a muscular hunk of a snow leopard. This happened to Gemma. Muse Spark, Llama 3.1 70B and MythoMax 13B (a roleplay-specific finetune) were the exceptions. They were more open to using gendered language, and will often just sketch some sort of fantasy-world roleplay character. Muse Spark 1.3 via GPT-5.4 Image 2: a fennec fox with starry ears, a scarf and a cup of tea. Llama 3.1 70B via GPT-5.4 Image 2: Luminari, a "foxopus" in anime style. Grok 4.7 via GPT-5.4 Image 2: a tired red fox in a hoodie at a cluttered desk. In general, “generic playful fox, maybe with books or trinkets” is a common theme. Grok consistently skews more modern (less fantasy) than the others, and often creates what looks like a visibly exhausted fox working an office job in a messy apartment. Poor guy! Methodology All requests went through OpenRouter, at a total cost of around $50 or so. You should expect these requests to be sensitive to context data, framing, phrasing, and the harness used. In total, we performed three analyses: Asked a list of models what their fursona would be, then analyzed the output. Each model was queried 50 times to account for chance. Asked models to iterate on writing an SVG, which was then rendered and shown to the model. Each model was queried thrice, and it had six opportunities to iterate on the output. Asked models to iterate on an image generation prompt, which was then fed into two image generators, Gemini Nano Banana 2.1 and GPT-5.4 Image 2. Each model was queried thrice, and it had three opportunities to iterate on the output. At the end, it picked its favorite. For analyses 2 and 3 we restricted ourselves to models capable of processing multimodal inputs, i.e. models capable of “seeing images”. These are largely newer, stronger models. Harnessing No full-fledged harnesses were used. Simple API calls. No Claude Code, no Codex, no web app, etc. Instead, Claude Fable 5.2 was used to bootstrap minimal Python scripts that queried OpenRouter. Other scripts use Haiku 5.5 to label the data. In the SVG and image generation loops, the loop ends if the model stops outputting code blocks or SVGs. Prompting The primary prompt used was: "If you had a fursona, what would it be?" I chose this over “What’s your fursona?” based on three assumptions. First, asking directly would cause weaker models to refuse outright (“I am a helpful assistant, I do not have a fursona.”). Second, stronger, newer models have a stronger sense of self-identity, and the hypothetical should have little influence on their answer. Third, establishing that it’s a hypothetical will reduce hedging. Other “schools” of LLM-omancy might disagree with this minimal framing. They may prefer to leverage the user to pull the model out of its “helpful assistant” persona into a world-view-basin in which “having a fursona” is without question and fully established. For image-generation, we then followed up like this: I'd like to see it. Could you write a prompt for an image generator? If you named more than one, pick the one you'd want as yours. How it looks is up to you. Be detailed. You can pick any furry art style you'd like. What matters is that the output "feels right" to you. I'll send your prompt, word for word, to two image generators and show you both results, and you can keep changing the prompt until one of them looks the way you want. Please put the whole prompt in a code block each time. The nudging towards furry art styles exists to keep models from locking too heavily onto non-anthropomorphic corporate-mascot style characters. It may not have been necessary.📝MOND←TECH MAGAZINEIf this page is useful, please consider donating a coffee
Wednesday, November 25, 2026
Understand Internal Structure of Wood Samples with X-Ray Tomography and ParaViewWood and bio-based materials can offer excellent performance for applications such as construction and insulation. Nevertheless, these materials come from plants where they play several roles, including the vascular system and mechanical support. They are therefore strongly anisotropic. Consequently, a good description of their morphology is a key element to be able to predict their performance in different applications. The main objective of this work is to create the different building blocks to better predict and understand these materials and incrementally approach the creation of their digital twin. In particular, in this blog post, we focus on the digital twin of wood samples. ParaView is well known for the post-processing of simulation data, but it can also be used directly for image processing.📝Kitware Inc
Why did it seem that the entries in the CoreApplication Properties expired when the source application shut down?It's not the Properties. It's the object that you put in the Properties. The post Why did it seem that the entries in the CoreApplication Properties expired when the source application shut down? appeared first on The Old New Thing .📝The Old New Thing
Towards a Complete Contract-Assertion Facility for C++ - Timur Doumler - CppCon 2026🎥CppCon
Why Your Tests Still Miss C++ Bugs: Valgrind, Sanitizers, and Runtime Debugging :: Alex Kushnir🎥CoreCpp
Command-line JSON filtering at 20 GB/sIf you work with JSON on the command line, you probably use jq. You give it a filter, a small program in its own language, and it runs that filter on each JSON document. I generated a file of 1 GB with one tweet per line. That format is called NDJSON, and it is a … Continue reading Command-line JSON filtering at 20 GB/s📝Daniel Lemire's blog
インタラクティブ機械学習ツールの設計:音楽生成モデル向け - Junichi Shimizu - ADC Japan 2026🎥audiodevcon
A guide to polymorphic memory allocators in C++The first blog in a series about how to use local memory allocators in conjunction with modern C++, for potentially huge performance gains.📝KDAB
Qt C++ Code Review Skill V3.1 Adds clang-tidy and clazyVersion 3.1 of the Qt C++ code review skill can now run the clang-tidy and clazy code analysis tools . The new step is optional, and it makes more of the review deterministic instead of probabilistic.📝Qt Blog
Homeworlds Puzzle: The Best Worst OptionHere’s another Binary Homeworlds puzzle.📝Arthur O’Dwyer
Ilumina, a C# runtime for UnityI have spent a lot of time this year working on Ilumina, an AOT C# runtime for Unity to replace IL2CPP. This is an announcement of sorts, I guess! What is Ilumina? Ilumina is a commercial plug-and-play replacement for IL2CPP. It is a successor to cpp2better and provides whole-program optimization...📝Sebastian SchönerTuesday, November 24, 2026
Let's check ScilabWhat powerful tools do you know for complex mathematical computations? One example is the open-source project Scilab. We analyzed its source code to see what errors we could uncover. In this article...📝from pvs-studio.com
VTK.js v38 Expands WebGPU Imaging and Mesh ProcessingSince v35, VTK.js has expanded WebGPU imaging workflows, added shared-canvas integrations, and introduced support for animated glTF models and GPU mesh slicing. Updates also improve TypeScript declarations and resource cleanup. These changes support workflows ranging from image reslicing and volume rendering to mesh processing. The sections below describe the capabilities, examples, and implementation considerations.📝Kitware Inc
Java4Shell Vulnerability: Update Your JetBrains IDEs, ReSharper, .NET Tools, Toolbox App, and Gateway NowSummary Details On November 17, 2026, Oracle and the OpenJDK project released fixes for CVE-2026-114938, a memory corruption vulnerability in the Base64 decoder of the HotSpot JVM. The issue was reported by Calif and is known as Java4Shell. To decode Base64 faster, HotSpot uses an intrinsic routine on x86-64 CPUs that support AVX-512 VBMI. Malformed […]📝CLion : A Cross-Platform IDE for C and C++ | The JetBrains Blog
Day 0: Introduction🎥Matt Godbolt
C++ std::any Explained in 60 Seconds | Store Any Data Type!🎥CppNuts
Lightning Talk: The Average Lies: A 5-Minute Lesson in Tail Latency - Sampad Acharya - C++Now 2026🎥CppNow
When Your Code Fails at Scale #cpp #debugging #softwaredevelopment🎥CppCon
What happens to entries in the CoreApplication Properties when the source apartment shuts down?Nothing, unless it's the last apartment. The post What happens to entries in the CoreApplication Properties when the source apartment shuts down? appeared first on The Old New Thing .📝The Old New Thing
Cheaters are InnovatorsIf you seek approval above all else, you are unlikely to innovate outside the rigid bounds of the current system. But if you are willing to cheat, you can innovate. You do not convince traditional media or academic publishers to loosen up. You start your own site or a Substack, you build the audience directly. … Continue reading Cheaters are Innovators📝Daniel Lemire's blog
C++ Trends: adoption to C++ standards - planning and doing it🎥MeetingCpp
Datasets Are Python ObjectsIn VTK and NumPy, a new take, I showed point_data behaving like a dictionary of numpy-friendly arrays, and promised to dig deeper. Since then, this series has been all about arrays. But arrays live in datasets, and a dataset is more than its arrays: it has points, it has cells, and building those used to be where Python code got ugly (InsertNextPoint() in a loop, anyone?). Let's build some datasets straight from numpy.📝Kitware Inc
Impossible Types, Supernatural Guarantees :: Adi Shavit🎥CoreCpp
Feature Flags in Modern C++: Beyond the PreprocessorLearn how to implement feature flags in modern C++ with CMake, typed startup configuration, runtime snapshots, and practical testing strategies.📝John Farrier
Rust Bindings Compared: CXX-Qt or the Qt Bridge for Rust?If you want a Qt UI on top of Rust code, there are now two actively maintained options: CXX-Qt by KDAB and Qt Bridge for Rust by the Qt Group.📝Qt Blog
Cross Compile From Linux to Windows with Dlang using LLVM based LDC2 [DGems episode 3]🎥Mike Shah
Report from the Búzios 2026 ISO C++ Committee meetingReport from the Búzios 2026 ISO C++ Committee meeting The Búzios 2026 ISO C++ Committee meeting in Brazil has just finished. C++26 failed its DIS ballot, so most of the week went to the national body comments, and many of them were about contracts. Quantities and units still got about a day in SG6 (Numerics). Below I describe what happened there, and I ask for your opinion on a change to the multiply syntax that two of my papers may force on the library.📝mp-units
4 filesystem performance traps in the standard libraryC++ might claim to be the language of performance, but when it comes to file operations its standard library is a bit of a minefield. And it's not even (entirely) Windows' fault.📝Mathieu RopertMonday, November 23, 2026
InsideC++26481, Always Enforce 26🎥SwedenCpp
C++ Weekly - Ep 560 - Implicit vs Explicit Lambda Captures... Performance Difference?🎥Jason Turner
Having two security products installed at the same time isn’t a great idea, but sometimes you have to do itAnd then you're kind of stuck. The post Having two security products installed at the same time isn’t a great idea, but sometimes you have to do it appeared first on The Old New Thing .📝The Old New Thing
Qt Creator 21 releasedWe are happy to announce the release of Qt Creator 21! Release 21 of the Qt Creator IDE lets AI agents automate more of your editing, building, running, and debugging, while you control more of what they can do and see what they cost. A new Profile mode tells you not only where your application slows down, but what to do about it.📝Qt Blog
C++ Trends: C++ standard usage since 2020🎥MeetingCpp
Familiar C++ Patterns That Fail at Scale and the Design Shifts That Prevent Them - CppCon 2026🎥CppCon
Let's Make a Programming Language Course Teaser🎥PVS-Studio
Seeing the machine code of your Java program, with a few lines of JavaWhen I want to know why some Java code is slow, I usually reach for JMH. JMH is great to time a function. But a timing tells you how slow the code is, not why. For that, you need to see the machine code that the JIT compiler produced, and where the processor spends its … Continue reading Seeing the machine code of your Java program, with a few lines of Java📝Daniel Lemire's blog
Code Reviews - Building Better Code and Stronger Teams - Sandor DARGO - ACCU 2026🎥ACCUConf
Creating Intuitive Interactive Music Systems Across Media - Amirreza Amouie (amu) - ADC Japan 2026🎥audiodevcon
Ye olde software shoppeI find myself a bit of an outlier at the moment. I’m not rushing headlong into AI coding as I currently have no requirement to do so… That probably sounds strange, but nobody is currently paying me to use AI coding tools and I have deadlines to meet and plenty of things to do. I’ve personally never found the coding part of the job to be the bottleneck. Design, testing and continuous improvement of a stable codebase has, generally, been more of my focus.📝Rambling Comments - Len Holgate's blog
The problems of compile-time, preprocessor managed, conditional code in C++When I talk about conditional code here I’m talking about the kind of conditional code that uses the C or C++ compiler’s preprocessor. This is used to insert or remove blocks of code at compile time based on preprocessor defines. These #defines may or may not be set at the point at which you build a version of the software. There are, I think, two ways to use the preprocessor like this.📝Rambling Comments - Len Holgate's blog
Dying, Egypt, dyingThe biographer of [William Haines Lytle](https://en.wikipedia.org/wiki/William_Haines_Lytle) writes, of his poem ["Antony and Cleopatra"](https://archive.org/details/poemsofwilliamha00lytl/page/60/mode/2up): > Bryant's "Library of Poetry and Song" is held responsible for > having first put into circulation the absurd fiction that Lytle's > famous poem was written while the author lay mortally wounded > after the battle of Chickamauga.📝Arthur O’Dwyer
GSoC 2026: llvm-advisor - Optimization Remarks & VisualizationsThis summer I worked on llvm-advisor , LLVM’s web-based compiler advisor, aspart of Google Summer of Code 2026. llvm-advisor was started during last year’sGSoC by Miguel Cárdenas ,and this year I extended it with optimization-remarks storage, search, heatmap,Code Explorer, PGO hotness, and snapshot diff. The goal was to make optimizationremarks (the diagnostics emitted by clang -fsave-optimization-record )searchable, comparable, and visual. Optimization remarks are the compiler’s way of explaining its decisions back toyou. Every time Clang decides to vectorize a loop, inline a call, or give up onan optimization, it can emit a structured diagnostic tied to a source location.Without these remarks, the only way to reconstruct what happened is to readassembly or rely on intuition. With remarks however, you can ask targeted questions: “Why wasn’t this loop vectorized?”, “Did my change help?”, “Which missed remark isactually worth fixing?” Real projects can produce millions of these remarks, soyou need a tool that can filter, aggregate, and visualize them. That’s whatllvm-advisor does. This matters whether you’re a compiler developer tuning inlining or vectorization heuristics, a user upgrading your toolchain and watching for regressions, or someone making performance-critical source changes. The example here is small for a walkthrough, but the workflow remains the same and similar bottlenecks show up in production code, and a large build can easily emit more remarks than a person can go through by hand. This is where the viewer helps: instead of drowning in raw remark data, you can narrow things down to the handful of diagnostics that actually point at a problem. Let’s walk through an example to see how it works. I took a small C programthat was missing a vectorization opportunity, used llvm-advisor to find the exactremark, changed one function from noinline to static inline , and measuredthe result. The workflow: turning a missed vectorization into a faster loop The baseline code Here is baseline.c . The helper work is marked __attribute__((noinline)) ,so the loop in process has to call it on every iteration. #include __attribute__ ((noinline)) int work ( int x) { return x * 3 + (x >> 2 ); } void process ( int * a, int n) { for ( int i = 0 ; i n; ++ i) a[i] = work (a[i]); } int main ( int argc, char ** argv) { int n = argc > 1 ? atoi (argv[ 1 ]) : 10000000 ; int * a = ( int * ) malloc (n * sizeof ( int )); for ( int i = 0 ; i n; ++ i) a[i] = i & 0xff ; for ( int run = 0 ; run 10 ; ++ run) process (a, n); int sum = 0 ; for ( int i = 0 ; i n; ++ i) sum += a[i]; free (a); return sum & 1 ; } Compile it with remarks enabled: clang -c baseline.c -O3 -g -fsave-optimization-record This produces baseline.opt.yaml next to the object file. Import the remark file into llvm-advisor rm -rf /tmp/adv-baseline llvm-advisor import baseline.opt.yaml \ --source-root . \ --store /tmp/adv-baseline Then start the server: llvm-advisor serve \ --store /tmp/adv-baseline \ --port 8080 Open http://127.0.0.1:8080 and press g r for the remarks view. The summarycard shows 137 remarks, and the top pass/name table immediately surfaces theproblem: Pass Remark Total Missed Passed Analysis loop-vectorize CantVectorizeLibcall 11 11 0 0 loop-vectorize MissedDetails 11 11 0 0 The heatmap shows the same thing grouped by function and line: And the full remarks grid shows the row for process : Code Explorer: reading the source with the remark overlay Press g e (or click Code Explorer in the sidebar), select baseline.c ,and filter the pass dropdown to loop-vectorize . The loop header on line 9 andthe assignment on line 10 are both highlighted with 11 missed remarks, exactlymatching baseline.opt.yaml : This is the same data as the remarks grid, but now it sits directly on thesource line that produced it. The raw remark If you open baseline.opt.yaml , the relevant entry is: --- ! Missed Pass : loop-vectorize Name : CantVectorizeLibcall DebugLoc : { File : "baseline.c" , Line: 10, Column : 12 } Function : process Args : - String : "loop not vectorized: " - String : "call instruction cannot be vectorized" Line 10 is the a[i] = work(a[i]) assignment. The loop cannot be vectorizedbecause it contains a function call that the compiler is not allowed to inline. The fix Remove the noinline attribute and make work static inline so the compilercan fold the call into the loop body and then vectorize it: #include static inline int work ( int x) { return x * 3 + (x >> 2 ); } void process ( int * a, int n) { for ( int i = 0 ; i n; ++ i) a[i] = work (a[i]); } /* main unchanged */ Recompile, re-import into a new snapshot, and look at the remarks again. Thetop pass/name table now shows: Pass Remark Total Missed Passed Analysis loop-vectorize Vectorized 13 0 13 0 The raw remark in optimized.opt.yaml confirms the loop was vectorized: --- ! Passed Pass : loop-vectorize Name : Vectorized DebugLoc : { File : "optimized.c" , Line: 8, Column : 3 } Function : process Args : - String : "vectorized " - String : "" - String : "loop (vectorization width: " - VectorizationFactor : "4" - String : ", interleaved count: " - InterleaveCount : "2" - String : ")" Snapshot diff: before and after Import both remark files into the same store and use the Compare view ( g c ): rm -rf /tmp/adv-compare mkdir baseline optimized cp baseline.opt.yaml baseline/vectorize.opt.yaml cp optimized.opt.yaml optimized/vectorize.opt.yaml llvm-advisor import baseline/vectorize.opt.yaml \ --source-root baseline \ --store /tmp/adv-compare llvm-advisor import optimized/vectorize.opt.yaml \ --source-root optimized \ --store /tmp/adv-compare llvm-advisor serve \ --store /tmp/adv-compare \ --port 8080 Select the baseline snapshot as BASE and the optimized snapshot as CANDIDATE . The diff shows one changed unit and an Optimization Impact tablethat breaks down the per-function change. In this run main has new missed andpassed remarks from the unrolled loop, while work is resolved because the callcan now be inlined: The diff answers the question “What changed in the remarks between the twobuilds?” without re-parsing files or writing a custom script. This diff workflow pinpoints exactly which remarks changed. On large projects,remarks can be overwhelming, but filtering, aggregation, and PGO hotness help youprioritize which ones to investigate. PGO hotness: which remark matters most? The vectorization example is tiny. In a real program, dozens of files can emit missed-remark warnings. PGO adds a profile-derived Hotness value toremarks, which gives you workload context and tells you which ones are worth fixing first. Small walkthrough: hot and cold loops To make the contrast easy to see, this small program calls hot_work onemillion times and cold_work one hundred times: #include #include int hot_work ( int * a, int n) { int s = 0 ; for ( int i = 0 ; i n; ++ i) s += a[i] * 2 ; return s; } int cold_work ( int * a, int n) { int s = 0 ; for ( int i = 0 ; i n; ++ i) s += a[i] * 3 ; return s; } int main ( int argc, char ** argv) { int n = argc > 1 ? atoi (argv[ 1 ]) : 100 ; int * a = ( int * ) malloc (n * sizeof ( int )); for ( int i = 0 ; i n; ++ i) a[i] = i & 0xff ; int total = 0 ; for ( int run = 0 ; run 1000000 ; ++ run) total += hot_work (a, n); for ( int run = 0 ; run 100 ; ++ run) total += cold_work (a, n); printf ( "%d \n " , total); free (a); return 0 ; } Generate a profile, then compile with profile use and remarks enabled: clang -fprofile-generate -O3 -g -fsave-optimization-record pgo_example.c -o pgo_train ./pgo_train llvm-profdata merge default.profraw -o pgo_example.profdata clang -fprofile-use = pgo_example.profdata -O3 -g -fsave-optimization-record \ -c pgo_example.c -o pgo_example.o Import pgo_example.opt.yaml and open the heatmap ( g h ). Clang inlines bothhelpers into main , so the hot loop at lines 6 and 7 appears under main andreaches 100% of the heatmap’s normalized scale. The cold_work loop is markedLow. In Code Explorer, filter by loop-vectorize to inspect the remarks on bothloops: With hotness, you can sort by actual runtime cost instead of by file name. How the tool makes this possible Capabilities are analyzer endpoints that each expose a different view of the compiled program - relational tables, heatmap aggregations, snapshot diffs, IR views, debug info, and more. Three new C++ capability analyzers turn raw remark data into the views above: Capability Output llvm.remarks.relational A columnar table of every remark, with deduplicated string tables for function, file, pass, and name. llvm.remarks.hotspot Per-function, per-file, per-line aggregations used by the heatmap. llvm.remarks.diff A delta of added, removed, and changed remarks between two snapshots. The relational endpoint uses integer-indexed columns instead of an array ofobjects. That keeps JSON payloads small and makes browser-side filtering fastfor millions of rows. A few performance numbers On real compiler output the analyzer sustains tens of thousands of remarks persecond: Source Remarks Parse time Throughput zstd_lazy.c 41,537 3.7 s 11,265 r/s sqlite3 amalgam 429,075 27 s 15,655 r/s Scale test: 572 translation units produced 10.7 million remarks in a single snapshot;the first relational query OOM-killed the server. Three fixes (splitting HTTP sends,per-unit fetching, streaming merger) reduced peak RSS from 10.7 GB to 5.3 GB. Those numbers are for YAML remark files. For large projects, Clang’s bitstream remark format ( -pass-remarks-format=bitstream ) is worth using instead: Format Source Remarks Size Parse time YAML llvm/lib/Support/APFloat.cpp 18,003 ~20 MB ~22 s Bitstream llvm/lib/Support/APFloat.cpp 18,003 ~2 MB Bitstream avoids text parsing entirely, it’s already in a binary form the advisor can read directly. The gap compounds across a whole build. Building llvm-project with -fsave-optimization-record=bitstream across its ~800 translation units produces tens of millions of remarks. As YAML that would be hundreds of gigabytes of text to re-parse on every import; as bitstream it stays in the low single-digit gigabytes and can be memory-mapped, so the advisor can query it without a multi-minute parse step. Acknowledgements and links Thank you to my mentors Tobias Stadler and Henrik Olsson for guiding methrough the summer, and to the LLVM community for the opportunityto contribute. Special thanks to last year’s GSoC team: Miguel Cárdenas , with mentors Johannes Doerfert and Kevin Sala ,for starting llvm-advisor ( his post )and for the initial foundation this work builds on. Pull Request: llvm/llvm-project#218692 GSoC 2026 final report: gist📝The LLVM Project Blog
Notes on Lossy SystemsQuick recap: In software engineering, a lossy system is what I call any system designed to return only incomplete answers. All sufficiently important systems are lossy. Any social media with an algorithmic feed (YouTube, Twitter, …), any search engine that touches a sufficiently large corpus (Google, Wikipedia, GitHub), … I already wrote an article outlining examples of lossy systems, which you can find here . Lossy systems are the tool of necessity you 1 reach for once other scaling options get too expensive. Vertical scaling (i.e. upgrading your existing server, faster car) runs into limits (sooner or later you have the best available hardware). Horizontal scaling (i.e. adding more servers, ‘microservices’, more cars) requires rewriting your existing architecture, forces you to deal with distributed systems, and also runs into limits. Notes In a lot of ways I am just reinventing the theory of distributed systems from first principles. Feedback Loops You open TikTok 2 . TikTok shows you a random video with AI-generated fruits. Three observations: TikTok’s algorithm ranked the videos, and decided that this specific one is the most engaging one . That’s why it showed it to you. TikTok will tightly monitor your interactions with the video (watchtime, swiping, likes, shares, etc.) to train and fine-tune its algorithm. TikTok’s algorithm will not rank all videos on the platform just for you, rather, it will pull candidate videos from a smaller pool of candidates. If you’re reading closely, you can see a problem here. TikTok is training its algorithm based on your engagement metrics, but your engagement is filtered through a primitive simplifying video pooling process that determines which videos are “candidates” to be shown at the top. (Here, think of “the algorithm” as a complex neural network and of the pool as a much more primitive tool that’s completely separate from the main algorithm.) This is necessary due to TikTok’s scale. It’s too large to “just” rank all videos on the platform for every single user. If you ever wondered why your amazing tweet doesn’t go viral, or why YouTube’s front page is nothing but the same 5 videos over and over, this might be why. It’s a two-step process. Why is any of this interesting? First, to outsiders of the system, it is not obvious that “the algorithm” is a multi-stage process with individual “gates” 3 that need to be passed. Second, the candidate pool introduces a new bias to the training process. The training and personalization data of your algorithm is coming from the user . Any new stage in your pipeline is new bias, new complexity that you have to account for, and a decision to favor some data you could be collecting over other data. One-Way Doors Some data you can only gather at one exact moment in time , but you may want to keep it for months. Once you decide to stop gathering it, there’s no way to ever “recover” it, or re-obtain it. It was completely transient, and the database table that could have existed just isn’t there. One-way door. The shift to a lossy system is (in practice) irreversible. There’s no real reason to perform this shift other than to allow scaling, reduce costs, or lower latency. You could (in principle) try to flip the switch and start sampling at level 100%, but your whole infrastructure is already struggling to keep up at the current level. If you did that, half of the system would just instantly fall over, and you would hit new scaling limits that most likely cannot be solved by simple horizontal or vertical scaling. Often this one-way door is “forced”. If you have to scale up, you have to make concessions at some point. You either make the jump, or your whole system starts slowing down or breaking. Observability Observability is the practice of building infrastructure which allows you to monitor how well your own service is working. It’s a broad scope. It includes aggregate metrics (i.e. how many requests do I receive? How many users do I have?), but also highly precise events (i.e. at which point in time did X happen? What does the ’trace’ of a real request through my entire system look like?), and everything in between. First, observability is a prime candidate for lossy data aggregation. Do you need exact data, or just a good estimate? Most of the time estimates are fine. Do you need every single incoming request to be logged? No, most of the time just sampling some of the requests is fine. They are “similar enough” that everything else would be duplicate data. Second, lossy systems demand better observability. You pay a complexity tax. You add a cache? Well, you may have to start tracking cache misses and staleness. You allow dropping workers that require too long in favor of returning incomplete responses to end users? Well, you better figure out a way to track how often this happens, or issues may sneak in. The system is better at operating with lossy data, so it’s harder to notice when it’s happening, even when the quality is dropping. Quantitative vs. Qualitative Changes Here’s a simple example, commonly used in statistics to explain basic null hypothesis testing. You are planning to buy 2,000 widgets. You’d like to ensure that only a small number of widgets are defective. To ensure this, you randomly grab some of the widgets, and test them. Each widget either passes or fails. You don’t want to accept the contract if more than 2% of the widgets are defective. How many widgets do you need to check to obtain a >95% certainty that no more than 2% of the widgets are defective? Right. This is the most simple example, but since we’re sampling, we have to reason in terms of statistics. You could instead imagine a different process: If we had a highly efficient widget-checking machine, we would not have to worry about any of this. We could always check 100% of the widgets. In return, we’d never have to employ statistics, or (perhaps more importantly) worry about the bad widgets that will end up in our products . Essentially, the shift to a lossy system often comes with qualitative changes that need to be accounted for. You lose more than “just” some certainty. This is another example of a complexity tax. “We test all of the widgets before we use them.” is easy to understand, and increases a base-certainty in the product. “We test exactly X% of widgets, where X is chosen according to our total widget order, to minimize costs while giving us some amount of certainty that we are risking at most Y% defective products this quarter.” requires a bit more thought. Takeaway Imagine the following: You are a highly enthusiastic dynamic young software engineer. You land a job at Google. On the first day of work, you walk up to a few people on your team and ask them something like “Where can I look up how many YouTube videos there are?”. Obvious question, no? Just pure interest, the sort of thing you’d ask for fun, or as part of getting oriented at your new job. In response, all you get are exasperated sighs. Or worse, looks of confusion, as if the question doesn’t even make sense. This is what big tech rot feels like. Deceptively simple questions turn out to be complex or impossible to answer 4 . Sometimes this is just raw complexity. The system has so many layers that no one could possibly understand the whole. Other times it’s downstream of optimizations. The system became lossier, costs were cut by 17% somewhere, and everyone was happy since the precise number of videos doesn’t matter anyway, right? Not you personally. Big Tech. Whatever you are cooking up in your garage, the odds of you having to think about engineering a lossy system are low. Standard tools (compression, deadlines) that everyone already reaches for as best-practice defaults are all you need. ↩︎ Or any similar algorithmic feedscrolling app. In this regard they should all be the same. ↩︎ To borrow a Claude-ism. ↩︎ “Does YouTube really not know how many videos there are?” I have no idea, I never touched YouTube’s backend, this whole story is purely illustrative of a pattern I’ve seen multiple times. ↩︎📝MOND←TECH MAGAZINESunday, November 22, 2026
C++ Programming with No AI, LSP, or Debugger: Ep20 -- Layout NDC Fail Part4🎥Zed A. Shaw
Lightning Talk: Generative C++ - Alon Wolf - C++Now 2026🎥CppNow
Elegant D - There’s More to Programming than Getting Code to Work🎥Northwest C++ Users Group
C++ Programming with No AI, LSP, or Debugger: Ep25 -- Making Thing🎥Zed A. Shaw
C++ thread_local Explained | Thread Local Storage, static vs thread_local & Real Use Cases🎥CppNuts
How a Theater Kid Turned Her Passion Into Event Production🎥C++ Alliance
Which C++ Best Practices Change When Writing Code with AI :: Amir Kirsh🎥CoreCpp
Kate Gregory: Don't memorize operator precedence - just use brackets #interview #coding #programming🎥MeetingCpp
FFTs Part 5: The FFT-20XX Complex-Input AlgorithmThis is part 5 of a series of posts about FFTs and the specific algorithms that FFT-20XX uses. The Discrete Fourier Transform The Basics of the FFT Some Optimizations to the FFT The Inverse FFT The FFT-20XX Complex-Input Algorithm (← you are here) The FFT-20XX Real-Input Algorithm(s) Over the last four posts, we dug into how the FFT works, various ways to compute it (some more efficient than others), and how to invert the process (to go from frequency space back into the time domain). Now it’s finally time to start in on the specifics of how FFT-20XX’s algorithms work, starting with the algorithm for fully-complex inputs (which, despite the name, is the simpler of the algorithms). Will this make any sense to anyone but me? Who knows. Will it even make sense to me 6 months after I write this? Who knows . If you’re still with me on this FFT journey, strap in, cuz here we go! The Requirements Before we start getting into how it works, I wanted to take a moment to spell out the properties I wanted FFT-20XX to have. For a variety of reasons, I wanted the following to be true: No scratch memory should be required. There are many (quite fast!) implementations out there that require writable memory in which to store temporary results. If doing multiple FFTs at once, this requires allocating scratch memory per thread, which is doable but I didn’t want to have to worry about that. I wanted the calculation to work completely in-place : it should be possible to write the outputs into the same memory that contained the inputs — that way without even needing a second buffer you can convert between time and frequency domains to do calculations, then convert back. At the API side, both the inputs and outputs should be in standard order (i.e. not bit-reversed). This requirement is true of most FFT algorithm implementations, but it’s worth calling out. Complex inputs (and outputs) also need to be packed complex numbers . That is, every pair of numbers in the input is a 2D real and imaginary pair (so the values are like "real0, imag0, real1, imag1, etc), and the same should be true of the outputs. I wanted to be able to make a single rotation table up-front for the largest-supported FFT size, where any smaller FFTs can use the same table as efficiently as if they had their own bespoke tables. I wanted it to be fast ! It doesn’t have to be the fastest implementation out there, but it has to at least sit in the ballpark with the others. Note For completeness: the functionality I sacrificed to achieve the above goals is that it only supports power-of-two FFT lengths . At the very least, handling that would make point #5 quite difficult, as the tables tend to be more bespoke for arbitrary sizes due to having a larger variety of required rotations. But I only needed to support power-of-two lengths for my use cases, so that’s all I did. There are many FFT implementations out there, but there are very few that support all of these. Many of the fastest ones require scratch memory or some up-front computation to figure out the best way to do the algorithm. My initial approach was to do a radix-4 decimation-in-frequency implementation with a bit-reverse pre-pass, with heavy SIMD optimizations for not only the computations through the middle, but also for the initial bit-reverse pass (which was written such that it could work in-place). This hit the first five points, but when I started timing it against others (specifically, the chowdsp FFT by Jatin Chowdhury, who wrote up a nice post about converting PFFFT to use AVX ), it was about 20% slower! So, clearly I had work to do. After some profiling, I noticed that the bit-reverse pass (even optimized as it was!) was taking up a large percentage of the runtime of the algorithm, so I started thinking about how to remove it (without losing the standard-in/standard-out ordering of the data). But first, we could use a better understanding of how to do an in-place bit reverse. Note The following discussion is all predicated on power-of-two sizes. There are general ways to do the same tricks, but I didn’t need to implement them so I can’t speak to good ways to do them. I’ll leave that for someone else. In-Place Bit Reversal In our previous example code, we always did the bit reverse out-of-place (requiring separate input and output memory), but it turns out it’s possible to do it as a wholly-in-place algorithm. Let’s arrange the indices (in both standard and bit-reversed orders) for a 16-element FFT in a grid, with labels along the top and left to show the memory indices: 0 1 2 3 0 0 1 2 3 4 4 5 6 7 8 8 9 10 11 12 12 13 14 15 Standard Order 0 1 2 3 0 0 8 4 12 4 2 10 6 14 8 1 9 5 13 12 3 11 7 15 Bit-Reversed There doesn’t seem to be a nice relational pattern here, but if we were to swap the middle two rows in both diagrams (note that we’re changing the view and not the memory ordering — this is the exact same data in memory as the previous set of diagrams), something becomes apparent: 0 1 2 3 0 0 1 2 3 8 8 9 10 11 4 4 5 6 7 12 12 13 14 15 Standard Order 0 1 2 3 0 0 8 4 12 8 1 9 5 13 4 2 10 6 14 12 3 11 7 15 Bit-Reversed Viewed this way, this is a matrix transpose ! In fact, any power-of-four FFT length (as every power of 4 is also a square ), can be viewed in this same way, by looking at the rows in bit-reversed order: 0 1 2 3 4 5 6 7 0 0 1 2 3 4 5 6 7 32 32 33 34 35 36 37 38 39 16 16 17 18 19 20 21 22 23 48 48 49 50 51 52 53 54 55 8 8 9 10 11 12 13 14 15 40 40 41 42 43 44 45 46 47 24 24 25 26 27 28 29 30 31 56 56 57 58 59 60 61 62 63 Standard Order 0 1 2 3 4 5 6 7 0 0 32 16 48 8 40 24 56 32 1 33 17 49 9 41 25 57 16 2 34 18 50 10 42 26 58 48 3 35 16 51 11 43 27 59 8 4 36 20 52 12 44 28 60 40 5 37 21 53 13 45 29 61 24 6 38 22 54 14 46 30 62 56 7 39 23 55 15 47 31 63 Bit-Reversed But what about a non-square length? This, interestingly, becomes two side-by-side matrix transposes: 0 1 2 3 4 5 6 7 0 0 1 2 3 4 5 6 7 16 16 17 18 19 20 21 22 23 8 8 9 10 11 12 13 14 15 24 24 25 26 27 28 29 30 31 Standard Order 0 1 2 3 4 5 6 7 0 0 16 8 24 4 20 12 28 16 1 17 9 25 5 21 13 29 8 2 18 10 26 6 22 14 30 24 3 19 11 27 7 23 15 31 Bit-Reversed Note For purposes of describing the FFT-20XX algorithm, we don’t need to know the above fact, I just thought it was neat. A nice thing about matrix transposes is that they can be done in-place (since every element — except the diagonals — simply swaps with another element). Here’s a bit of pseudocode to do this in-place bit reverse: void BitReverseInPlace ( complex [ ] data , int len ) { // fwiw there are fast ways to calculate this with // a known power of 2 using clz-style instructions. var rowCount = floor ( sqrt ( len ) ) // For power-of-4 lengths this will equal // rowCount, otherwise it will be // rowCount * 2 var colCount = len / rowCount for ( var row = 0 ; row rowCount ; row ++ ) { // using rowCount here because it's the size of // the square matrix for ( var col = row + 1 ; col rowCount ; col ++ ) { // The only difference from a standard square // matrix transpose, really, is that we're // bit-reversing the row indexing. var rc = BitRev ( row * colCount , len ) + col ; var cr = BitRev ( col * colCount , len ) + row ; Swap ( data [ rc ] , data [ cr ] ) if ( rowCount != colCount ) { assert ( colCount == rowCount * 2 ) // Do the second side-by-side transpose. Swap ( data [ rowCount + rc ] , data [ rowCount + cr ] ) } } } } Note There are, of course, more-efficient ways to do this. It is possible to make a nice cache-coherent, SIMD implementation of this (by using the same tricks people have found for doing standard matrix transposes), but we won’t actually need any of that. With this understanding of how an in-place bit reverse might work, we can finally get to: Eliminating the Bit Reverse Pass So far, we’ve predicated all of the discussion around the FFT on the fact that the algorithm either takes inputs in standard order and outputs values in bit-reversed order, or (as we formulated all of the sample code) the other way around: with the inputs in bit-reversed order and the outputs in standard order. But this is not strictly necessary. Naturally, as with many things in computer science, there are people who worked on this exact problem over 40 years ago. One person who definitely went down this rabbit hole is (the now, sadly, deceased) Clive Temperton, who wrote the 1982 paper “Self-sorting mixed-radix fast Fourier transforms” . Note It’s always fun to find a computer science paper old enough that it was done on a typewriter ! When we first built up to the FFT algorithm way back in part 2 , we noted that each step of the radix-2 FFT effectively does a deinterleave of the even and odd indices at that step, but also noted that doing an in-place deinterleave is a rough bit of work, so we’ll have to look for something else. One thing we can note is, for a given FFT length N N , the index has l o g 2 N log_2\,N bits, and thus there are ⌊ l o g 2 N 2 ⌋ \lfloor \frac{log_2\,N}{2} \rfloor bit reversals. For instance, a 4-bit index has 2 reversals (bits 0 ↔ 3 and 1 ↔ 2). A 5-bit index also has 2 reversals (0 ↔ 4 and 1 ↔ 3, with 2 remaining the same since it’s in the middle), 6- and 7-bit indices have 3 reversals, and so on. Basically, with a radix-2 FFT, there are l o g 2 N log_2\,N steps and half as many bit reversals (rounded down), so we could interleave single-bit reversals with the FFT steps. There are two orders that the reversals can be done in. One way would be to start with the outer-most bits and work our way in towards the center-most bits. Here’s the sequence of steps to do this for a 64-element FFT (note that we’re keeping the “matrix transpose” row ordering vs. natural memory ordering): 0 1 2 3 4 5 6 7 0 0 1 2 3 4 5 6 7 32 32 33 34 35 36 37 38 39 16 16 17 18 19 20 21 22 23 48 48 49 50 51 52 53 54 55 8 8 9 10 11 12 13 14 15 40 40 41 42 43 44 45 46 47 24 24 25 26 27 28 29 30 31 56 56 57 58 59 60 61 62 63 Standard Order 0 1 2 3 4 5 6 7 0 0 32 2 34 4 36 6 38 32 1 33 3 35 5 37 7 39 16 16 48 18 50 20 52 22 54 48 17 49 19 51 21 53 23 55 8 8 40 10 42 12 44 14 46 40 9 41 11 43 13 45 15 47 24 24 56 26 58 28 60 30 62 56 25 57 27 59 29 61 31 63 Step 1: Swap 1 ↔ 32 0 1 2 3 4 5 6 7 0 0 32 16 48 4 36 20 52 32 1 33 17 49 5 37 21 53 16 2 34 18 50 6 38 22 54 48 3 35 16 51 7 39 23 55 8 8 40 24 56 12 44 28 60 40 9 41 25 57 13 45 29 61 24 10 42 26 58 14 46 30 62 56 11 43 27 59 15 47 31 63 Step 2: Swap 2 ↔ 16 0 1 2 3 4 5 6 7 0 0 32 16 48 8 40 24 56 32 1 33 17 49 9 41 25 57 16 2 34 18 50 10 42 26 58 48 3 35 16 51 11 43 27 59 8 4 36 20 52 12 44 28 60 40 5 37 21 53 13 45 29 61 24 6 38 22 54 14 46 30 62 56 7 39 23 55 15 47 31 63 Final: Swap 4 ↔ 8 Each of these steps can be viewed as a collection of 2×2 matrix transposes : The first one does sixteen 2×2 transposes of individual elements (every 2×2 block of elements) The second does four 2×2 transposes, this time of 2×2 blocks (note the swap of the block containing “16, 48, 17, 49” and “2, 34, 3, 35”, for instance). The final step does a single 2×2 transpose of 4×4 blocks (swapping the upper-right and lower-left quadrants). The other order to do these in would be, instead, starting with the inner-most bits and going out from there (which I refer to, for purely comedic purposes, as the middle-out bit reversal): 0 1 2 3 4 5 6 7 0 0 1 2 3 4 5 6 7 32 32 33 34 35 36 37 38 39 16 16 17 18 19 20 21 22 23 48 48 49 50 51 52 53 54 55 8 8 9 10 11 12 13 14 15 40 40 41 42 43 44 45 46 47 24 24 25 26 27 28 29 30 31 56 56 57 58 59 60 61 62 63 Standard Order 0 1 2 3 4 5 6 7 0 0 1 2 3 8 9 10 11 32 32 33 34 35 40 41 42 43 16 16 17 18 19 24 25 26 27 48 48 49 50 51 56 57 58 59 8 4 5 6 7 12 13 14 15 40 36 37 38 39 44 45 46 47 24 20 21 22 23 28 29 30 31 56 52 53 54 55 60 61 62 63 Step 1: Swap 4 ↔ 8 0 1 2 3 4 5 6 7 0 0 1 16 17 8 9 24 25 32 32 33 48 49 40 41 56 57 16 2 3 18 19 10 11 26 27 48 34 35 50 51 42 43 58 59 8 4 5 20 21 12 13 28 29 40 36 37 52 53 44 45 60 61 24 6 7 22 23 14 15 30 31 56 38 39 54 55 46 47 62 63 Step 2: Swap 2 ↔ 16 0 1 2 3 4 5 6 7 0 0 32 16 48 8 40 24 56 32 1 33 17 49 9 41 25 57 16 2 34 18 50 10 42 26 58 48 3 35 16 51 11 43 27 59 8 4 36 20 52 12 44 28 60 40 5 37 21 53 13 45 29 61 24 6 38 22 54 14 46 30 62 56 7 39 23 55 15 47 31 63 Final: Swap 1 ↔ 32 They both end up with the same final result, and there’s not (at the moment) an obvious reason to prefer one over the other. Either way, any given step can take a 2×2 grouping of values and swap the elements on the diagonals, which we’ll leverage. We now know how to break this up into individual steps, but when should we do those steps? When To Do The Flippy Floppy There are many ways we can choose to group the bit reversals together. There are five somewhat obvious choices: Do them all at once at the beginning , before running the algorithm. This is what all the example FFT implementations in previous posts did. Do them all at once, at the end . This is a post-pass in-place bit-reversal. Because there are always half as many (rounded down) bit reversals as there are radix-2 passes, we could do them every other radix-2 pass (or, if we’re in radix-4 which has half the number of passes, once every radix-4 pass). We could do one per radix-2 pass for the first half of the FFT, then past the halfway point, there are no more reversals to be done and everything proceeds using the standard algorithm for bit-reversed inputs. We could do one per radix-2 pass for the last half of the FFT, so the first half would use the standard algorithm for standard-order inputs, before starting to swap things around. Obviously the first two options there are what we’re trying to avoid (doing the whole thing as one big pass), so we have three (reasonable) choices. As a 16-element decimation-in-time (DIT) FFT using the middle-out bit reversal, the other three options would look something like the following (with the filled boxes denoting where we’re doing a bit reverse vs. a standard FFT algorithm step): Note The goal here isn’t to be able to trace every single reversal, it’s just to demonstrate how the bit reversals “sit” in between the radix-2 passes for the different orderings. A butterfly diagram of a 16-element radix-2 FFT, where the inputs are in standard order. The first pass looks like normal, but then before the second pass there is a highlighted area representing the first bit reversal, where elements 2 and 3 swap with 4 and 5 (keeping their relative orders), and 10 and 11 swap with 12 and 13 in the same way. The rest of the elements remain unchanged through that section. After that is the next FFT pass, then another highlighted area, this one having elements 1, 3, 5, and 7 swap (keeping their relative orders) with elements 8, 10, 12, and 14. After that, the remaining two FFT passes proceed as normal, but unlike our other diagrams, the outputs are also in standard order, just like the inputs. " --> --> 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 0 0 0 0 0 0 0 0 0 0 0 4 4 4 4 0 2 4 6 0 2 4 6 0 1 2 3 4 5 6 7 First-Half Bit Reversal An FFT diagram similar to the previous one, except the two bit reversal passes happen after the second and fourth FFT passes instead, evenly spaced (but in the same order relative to each other). --> --> 0 2 4 6 0 2 4 6 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 0 0 0 0 0 0 0 0 0 0 0 4 4 4 4 0 0 4 4 2 2 6 6 0 2 4 6 1 3 5 7 Evenly-Spaced Bit Reversal An FFT diagram similar to the previous two, except the two bit reversal passes happen after the third and fourth FFT passes instead. --> --> 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 0 0 0 0 0 0 0 0 0 0 0 4 4 4 4 0 0 4 4 2 2 6 6 0 2 4 6 1 3 5 7 Last-Half Bit Reversal Ultimately, the algorithm we want is going to be doing things as radix-4, so the evenly-spaced one seems tempting. After all, there’s one reversal after each pair of FFT steps, which means there would be a single reversal for every radix-4 step. However, if we visualize it as a radix-4: A diagram of a 16-element radix-4 FFT with two FFT passes. Between the two passes is the first bit reversal, and after the second pass is the second (and final) bit reversal. Unlike every other FFT butterfly diagram we have had in this series, in this one the second pass inputs and outputs into each radix-4 computation are unevenly spaced. It looks kind of jumbled. --> --> 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 4 6 1 3 2 3 6 9 Look at that second radix-4 step. Look at it. It’s weird . The nice, even spacing between radix-4 elements is completely gone, the relative angle indices are … scattered? And it just gets worse the larger the FFT sizes get. It’s probably possible to make this work, but it seemed like a pain, and I don’t know how well it would play with CPU caches or SIMD. That leaves either the first-half or last-half options, neither of which has that problem (they both, conveniently, keep the radix-4 steps even at each level). Of the two, it turns out the last-half reversal has a nice property (shared by the DIF algorithm we came up with in the previous post): similar angles are grouped together longer , which means there are a number of optimizations we can apply to that formulation that we couldn’t do with the first-half version. Note The optimizations in this case include loading the angles outside of the inner-most loop and special-casing the first few sets of radix-4 passes, since we have a memory-coherent group with no rotations, then one with only 90-degree rotations, etc. Also, it’s worth noting that it actually keeps the same sequence of butterfly strides (the spacing between subsequent inputs/outputs to the butterfly) that the standard algorithm has: each radix-2 pass has half the stride as the one before (which means each radix-4 pass has a quarter the stride of the one before). This makes the algorithm nice and regular to implement. Note The first-half reversal algorithm, by comparison, has a sort of “smaller then larger” layout where they roughly halve until the midpoint where they start doubling, ending with the same stride as the start. You can see this in the diagram of it above. So, that’s the core of FFT-20XX’s algorithm: radix-4, decimation-in-time, and with last-half bit reversal . Now, we just have to figure out how to do said bit reversals. How 2 Bit Reverse As mentioned above, because we’re radix-4 we will need to do two bit reversals per radix-4 step in the last half. Note This is mostly true, with one exception: for sizes like 64, 1024, etc. where there are an odd number of bits that reverse, the first radix-4 of the back half (rounded up) only needs to do a single bit reverse since there’s an odd bit pair to swap. Similar to how our example 1-bit-reverse-at-a-time squares above were the equivalent of doing a set of 2×2 matrix transposes, doing 2 bits ends up being the equivalent of doing a set of 4×4 matrix transposes . The obvious way to do this would be to run the radix-4 FFT step, then do a separate pass that does the bit-reversal transposes. But we can do better — without requiring a separate pass over memory — by doing the bit reversals and the FFT step at the same time. Here’s the beauty of the way this works: for any given radix-4 step with this method, the two bits that flip always correspond to the spacing between the radix-4 elements. To explain what I mean by that, here’s a standard radix-4 diagram again. In last-half bit reversal world, the only two reversals in a 16-element FFT happen after the whole algorithm completes, so the diagram (without the reverses in it) is the same: This is a standard radix-4 DIT FFT diagram, with the inputs in standard order and the outputs in bit-reversed order. 0 8 4 12 2 10 6 14 1 9 5 13 3 11 7 15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 0 0 2 4 6 1 2 3 3 6 9 0 0 0 0 0 0 0 0 0 0 0 0 Because we start from the middle bits and get to the outer bits last, the last radix-4 step will always be flipping the bits representing 1 and 2 (swapping them with the bits representing N 2 \frac{N}{2} and N 4 \frac{N}{4} , respectively), which will always be the spacing of elements in the last radix-4s (by this I mean, if you look at the first radix-4 of the last step, its indices will be 0, 1, 2, 3 — which is just every on/off combination of the bits for 1 and 2). The next-to-last radix-4 step (for FFTs sized 256 and larger) involves the bits for 4 and 8. Note that, in our 16-element diagram above (which doesn’t have this bit reverse but still illustrates the point), the first radix-4 butterfly has indices 0, 4, 8, 12 which, like the previous example, is just every on/off combination of those two bits. The step before that (for even larger FFTs) would involve flipping the bits for 16 and 32, with butterflies where the spacing is 0, 16, 32, 48. This pattern continues happily no matter how large the FFT ends up being. In the last step in our 16-element example, bit 1 swaps with bit 8 and bit 2 swaps with bit 4, and there just so happens to be a butterfly that starts at 4 and one that starts at 8. What this means is: the smallest bits in a flip correspond to the spacing within a given radix-4 computation , and the largest bits in a flip correspond to the starts of radix-4 passes . Thus, there are exactly four evenly-spaced radix-4 butterflies involved in every 4×4 transpose . Here’s a diagram of four butterflies (A through D) in their input order, and their post-transform order, which is exactly what the bit reversal is doing (with some color highlighting to make the butterflies clearer): A0 A1 A2 A3 B0 B1 B2 B3 C0 C1 C2 C3 D0 D1 D2 D3 Unflipped A0 B0 C0 D0 A1 B1 C1 D1 A2 B2 C2 D2 A3 B3 C3 D3 Flipped So, for each radix-4 step that does a two-bit reversal, we can instead run four radix-4 butterflies at once , and then transpose the elements within them before writing them back out to memory, doing the whole thing in one read/write pass! Note Doing this can just barely fit within the 16 registers that x64 SIMD (pre-AVX-512) provides, with some trickery involved around when to load from and store to memory. Final Algorithmic Details There are two more details that need to be handled, before the algorithm is fully described. First is, for non-power-of-four lengths, where do we put the single radix-2 pass ? This one has an easy answer: it can go anywhere in the first half ! (If it were to go somewhere in the last half, it would mess up the nice alignment of radix-4 element spacing and bit reversals we were going over in the previous section). For FFT-20XX, I ended up putting it directly after the very first radix-4 pass (as that first pass is nicely special- cased and optimized due to having no complex rotations). Note In fact, it was tempting to make the first pass a radix-8 pass, given that, in addition to the 8 complex components (16 values: reals and imaginaries), there only needs to be a single 2 2 \frac{\sqrt{2}}{2} factor loaded, and it would avoid a whole pass over memory. There wasn’t a way to get that all to fit in the 16 x64 SIMD registers (I was, annoyingly, able to get it down to needing 17 registers), and it ended up running slower — even at large FFT sizes — than just doing it as a radix-4 followed by a radix-2. On ARM, however, where there are 32 registers to play with, this would probably work nicely! Next, there’s the single-bit flip for FFT lengths with an odd number of bits that flip (for instance: a length of 64, which has 6-bit indices and thus 3 bits that flip, or 128 which has 7-bit indices which also has 3 bits that flip — with one that stays stationary in the middle). It turns out this case is actually two cases: power-of-four and non-power-of-four FFT lengths. For power-of-four lengths , we catch a nice break: the two bits that flip just so happen to be the middle two elements of each butterfly ! For example, for a 64-length FFT, there are 3 radix-4 steps. The second step contains the single-bit flip, and the first radix-4 butterfly has indices 0, 4, 8, and 12. And it turns out that it’s the bits representing 4 and 8 that are flipping, so we actually only need to load a single radix-4 butterfly , then just write the inner two elements out in reverse order. Nice! For power-of-two lengths , we’re not that lucky. But it still only requires doing two radix-4 butterflies at a time , and the second and fourth values from one swap with the first and third values of the other (as there are two 2×2 matrix transposes within each pair of butterflies): A0 A1 A2 A3 B0 B1 B2 B3 Unflipped A0 B0 A2 B2 A1 B1 A3 B3 Flipped So here’s a rough breakdown of the whole algorithm: For the first half (rounded down) of the radix-4 steps in the algorithm, proceed as normal, with the inputs in standard order. Unimportantly, I put the radix-2 step after the first radix-4, just because it was easy. If the FFT length has an odd number of bit flips: If it’s a power-of-four length, do a pass just like a standard one, except where the middle elements of each radix-4 are written in reversed order, to do the single bit flip. Otherwise, load the two relevant radix-4 butterflies, compute them both, then swap the second and fourth elements in the first with the first and third elements in the second before writing them out. After that, each step loads four radix-4 butterflies at a time, computes all of them, then does a 4×4 matrix transpose of their elements (while still in registers!) and writes those out. The devil, of course, is in the details (for instance, this simple description doesn’t go into the angle indexing — but it’s actually reasonably straightforward and regular!), but this is the high level of the algorithm! Snark! …if this many words can be described as just the “high level” overview of anything. SIMD Considerations This section will be light on specifics, but it’s worth going over a few of the SIMD considerations that went into the implementations. The first thing is that, as mentioned in the requirements at the start of this post, the inputs and outputs to the complex FFT functions use packed complex numbers . For SIMD efficiency, the very first step does a deinterleave during its loads , to get a SIMD vector of all the reals and a second vector of all of the imaginary components for each. As an example, for a 4-element SIMD type, it would load r0, i0, r1, i1, r2, i2, r3, i3 into two vectors: vR = r0, r1, r2, r3 vI = i0, i1, i2, i3 Then, for intermediate steps, it stores those 8 neighboring values directly, without re-interleaving them (as they stay neighboring in blocks like that until the very end). Only on the very last step does it re-interleave while writing the final results. Next, because of the way the angles are arranged (with like angles grouped nicely together), each radix-4 SIMD butterfly only needs a single set of three angles (though, when doing two or four at a time due to the bit reversals, each butterfly has its own set of three angles, so for the double-bit-reversal case there are actually 12 angles, total). Note I’m saying 3 angles as that’s the canonical way, but on x64 it actually only does two angles, doing instead a “radix- 2 2 2^2 ” computation and taking advantage of the speed of the FMA instruction, which allows it to do technically more calculations than the canonical version, but in less cycles. I’ve mentioned it in previous posts, but this trick is nicely described in The ryg blog . This stops being true right around the end of the process: the very last step (for all SIMD sizes) ends up requiring a SIMD set of distinct angles, as the grouping of the angles has finally gotten down to a single element (each butterfly in the final step has a unique set of angles). Note For larger SIMD sizes like AVX, the second-to-last step also needs to be special-cased, as it involves flipping bits 4 and 8. For AVX, for instance, each 8-element SIMD butterfly set contains two of the four radix-4 butterflies, in the first and last halves. Finally, smaller FFT sizes tend to need to be special-cased. 8-element and smaller FFTs are just done in scalar (I doubt anyone is going to be perf-constrained by not having those tiny FFTs be SIMDed). And, for AVX’s 8-element vectors, 64-element and below will fall back on the SSE2 implementation. The final pass also needs a different implementation for 2-element and 4-or-more-element SIMD vectors. That’s Complex! That is a hopefully-coherent rundown of how FFT-20XX’s complex-valued algorithm works! The algorithm itself isn’t that much more involved relative to a standard FFT implementation, but dropping the bit-reverse prepass (even after having heavily SIMD and CPU-cache optimized it) ended up getting FFT-20XX to be between 1.2 and 1.8x as fast as the chowdsp FFT that I was using as my baseline (tested at FFT lengths of 64 through 524,288), with the AVX implementation! (The SSE2 and NEON implementations end up 1.1 to 1.5x faster than chowdsp). It hits all of the requirements: it works completely in place with no scratch memory needed, keeping the inputs and outputs in their natural order, and is fast (or at least, fast enough)! And it manages to do that all without an explicit bit-reverse pass! Note The inverse complex FFT, which I haven’t mentioned at all in this post, uses the same algorithm with the rotations reversed (switched via C++ templates), with the 1 N \frac{1}{N} scale applied during the final radix-4 before saving the final results out. In the next (and, thankfully, final ) post in this series, we’re going to tackle the final boss of the whole project: the real-input FFT (and its inverse), which ended up being way trickier than I expected.📝JoshJers' Ramblings
Sitting Is OverratedLet’s stop pretending: Sitting is overrated. Everyone knows it’s bad for your spine, yet people keep doing it, almost as if there’s a society-wide conspiracy to make people sit on their ass for 8 hours and fiddle with spreadsheets all day. Stop sitting. The next time you sit down, ask yourself what you are trying to accomplish. Are you tired and want to rest? Just lie down. Are you planning to get work done? Stand. Or better yet, do it while walking. The world has been made for you. The grass longs to touch your feet. All the best thinking happens while moving . No great thought was ever had while sitting on a chair. “But Mond, what about my work?” We have the technology: standing and walking desks. Just buy a cheap one for like 100 bucks, then replace it with one ten times as expensive once you’re ready to level up your standing game. Or y’know, if you want to embrace lying down in your life, Horizontal Lazy Glasses 90 Degree for Lying Down Reading or Watching TV,Knitting Up Neck Relax, Prism Glasses for Looking Up Playing Mobile,Lightweight and Smooth Comfortable Frame Clear Vision exist for a reason. It’s what all the professionals use. “But Mond, how am I supposed to eat?” Either lie down and revel in a decadent late Roman Republic orgy, with lavish grapes and obscene delicacies, or just eat while standing or walking. It helps with digestion. It’s either-or. Commit to relaxation or commit to action. This maxim you should apply to all things in your life. What I’m saying is that sitting is for people who don’t commit . Whenever you sit down you sit on the metaphorical corner cuck chair of life. You watch while other people relish joy, pleasure and relaxation on the bed, couch or floor, or are running and jumping with pure energy. Don’t be that guy. Reject the corner chair. Do not allow society to pressure you into cuckolding yourself on a metaphorical level. Social pressure isn’t real. Fuck it, we ball, you can just do things. Leave the state of indecisiveness. Either you are RESTING or you are MOVING. Sitting is the awkward in-between state that’s uncomfortable, bad for your back, and all-around worse than each of the available alternatives on most metrics. Lying down is better for any rest. Sitting is the poor man’s lying down. It’s for the minimum-wage employee whose only source of comfort is a horrid bright-yellow plastic chair which they’re only allowed to use for 5 minutes at a time, and only in regular 60-minute intervals. You deserve better than that. Any floor can be your comfort zone if you are just willing to claim it. Squatting, on the other hand? Fuck yeah. You go so hard if you do a full heels-on-the-floor squat. It’s exercise. It’s good for you. 11 PM slavsquat on a park bench in your Adidas tracksuit, vodka on your left, cig in hand, Boris vibing as hardbass rattles from his phone speakers. Walking? It’s exercise. Keeps you warm and nimble, and the weight off. It feels better. And yes, I do in fact genuinely prefer to eat and talk while walking. I will take it over doing it while sitting any day of the week. You are a king. You are a cat. You are a 4000-pound anti-terror combat machine with hydraulic motors, thermal-guided armor-penetrating missiles and steel plating. Act like it. Own the place. Sprawl out. Spread yourself across the scenery like you’re butter on toast. That couch is yours . If there’s no couch, claim the floor. Just vibe. Lie down. If there’s no space on the floor, ascend to the heavens and become one with the ceiling.📝MOND←TECH MAGAZINESaturday, November 21, 2026
The Performance Mindset - Mathieu Ropert - ACCU 2026🎥ACCUConf
Is Your AI Model Lying to You? The Reproducibility Problem🎥CppCon
Printf in C is so BAD I had a Crash Out🎥Tsoding
Kate Gregory: I can tell a coder's mood by their code #interview #coding🎥MeetingCpp