1. No. 2. No. 3. No. Those things are true most of the time, but not all of the time. Profiling and benchmarks are the tools I use to find out whether it's me or the compiler being stupid.
-
-
-O2 _is_ the way you tell the compiler "try to produce the correct ASM for this C". Sometimes it can't figure it out (and it's frustrating). But if you write the C carefully enough, sometimes it can. -O0 _never_ figures out the correct ASM for the C code, pretty much ever.
-
So in the godbolt I showed a -O0 and a -O2 of an inner product, and hopefully you can see that -O0 is _not at all_ similar to the C code - it's not even usable. -O2 produces the _actual_ closest translation to the input C code!
End of conversation
New conversation -
-
-
There is no direct mapping from C to ASM, correct. I feel though like some C programmers are convinced that there is, being "close to the metal" and all.
-
These are in practice two things though. Telling the computer what to do with the code you write (or use from a lib) and what the compiler does as a following pass to translate it so your machine can run it (and how good of a job it does at that translation).
- Show replies
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.