3 ms·
> If you haven’t been living under a rock quarantined against COVID-19, you’ve probably heard about C becoming assembly 2.0, or the new assembly, or YES THIS.
by chrisseaton 6y ago
> If you haven’t been living under a rock quarantined against COVID-19, you’ve probably heard about C becoming assembly 2.0, or the new assembly, or YES THIS.
What's this referring to? Has something been proposed recently?
> Now, many compilers have done some work with this using what are known as intrinsics. However, these do not allow us to fully exploit what we can in assembly. Most of the intrinsic instructions follow the C calling conventions, so they are required to load from RAM, do something with it, then store back into RAM.
> Since we store the intermediate values, we’re exercising the memory controller for every intrinsic. For our assembly, we load at the beginning and store at the very end. Nothing is in between.
I don't understand this claim. It seems demonstrably false to me. Intrinsics don't have to follow the C calling convention. And they in practice don't follow it. You can try it for yourself. It definitely doesn't store intermediate results to memory for his example code.
In fact, isn't what clang generates roughly the same assembly as the hand-written assembly in the article?
https://godbolt.org/z/rfmFB5 https://godbolt.org/z/rfmFB5
The author looks like an expert so I guess I'm missing something.
- vardump 6y agoYou're absolutely correct.
- pavehawk2007 6y agoHello, The introduction was meant to be tongue-and-cheek. There was a talk back in January which made headlines due to its claims. https://www.youtube.com/watch?v=8SoJR3sCaR4 https://www.youtube.com/watch?v=8SoJR3sCaR4 When I started learning the Nim programming language, the claims were that what you can do in C is what you can do in assembly... In other words, there was no more reason to learn or write assembly, unless you were making a C compiler yourself. I don't think they were ever taken seriously, but neither was my introduction supposed to be taken seriously. The point being that instead of having your brand new language compile to assembly, why not compile to C? Regarding the intrinsics, you are correct if you optimize. Using your same link, you can turn off the optimizer and see that it follows C ABI conventions--mainly so the debugger can follow each step. The point here is that we're still writing assembly, with a C marinade on top. _mm_haddps is wrapping an assembly instruction directly. However, to see what this is actually doing, we need to know a bit of assembly. In other words, we're writing C in syntax only. Perhaps I can reword that part better. Thanks for the comment!
- tom_mellior 6y ago> There was a talk back in January which made headlines due to its claims. https://www.youtube.com/watch?v=8SoJR3sCaR4 https://www.youtube.com/watch?v=8SoJR3sCaR4 That talk has 3194 views at the moment. That's pretty obscure. > Using your same link, you can turn off the optimizer and see that it follows C calling conventions--mainly so the debugger can follow each step. If you change -O0 to -O3 you will see a lot of stack traffic, that's true. This has nothing to do with calling conventions -- there are no calls generated for the intrinsics. Rather, you just see stack traffic because GCC doesn't try to do proper register allocation at -O0. Nothing to do with intrinsics.
- kbenson 6y ago> That talk has 3194 views at the moment. That's pretty obscure. I guess it depends on the intended audience of this post? I might also find it hard to understand some of the context of a post poking fun as some trend in some knitting mailing list, if I wasn't a member of that list. I think by "made headlines" they might mean "made a stir in some of the communities I frequent". Given the idea of bloggers as news people, a "headline" is a blog post that gains traction in circles you care about...
- tom_mellior 6y agoYes, the video was probably passed around in a the Nim community. The featured article isn't directed at the Nim community, though. The author just misjudged the video's reach outside of their knitting mailing list.