4 ms·
I like the highlighting – I finally understand why people say compilers generate faster code than a human could write. Pasted in a pretty straightforward and al
by smitherfield 10y ago
I like the highlighting – I finally understand why people say compilers generate faster code than a human could write. Pasted in a pretty straightforward and already fairly optimized function I'd written and of course got back something also pretty straightforward, then I put in "-Ofast -march=native" and, wow. Completely rearranged everything in a totally non-linear way and generated all sorts of bizarre (to me) instructions. I think I'd need to study it for months if not years to understand what the compiler did.
- MichaelBurge 10y agoIf you've never done it before, try stepping through a Haskell program compiled with a recent GHC. The control flow is pretty weird.
- astrange 10y agoYou can follow ghc's compilation with '-v5'. Alas, I've never liked the way it compiles - full of unpredictable jumps, makes no sense at asm level, and just doesn't look a good modern CPU citizen. Of course I am only a minor Haskell learner but jhc could do whole-program compilation with readable assembly. As for gcc, try 'gcc -fdump-tree-all -fdump-rtl-all-slim' and read the 50 files it prints.
- AstralStorm 10y agoOn the other hand, try -Os as in size optimization. You will get readable code that is not slow. I think most people internally optimise readability and thus size, those who don't generally make unmaintainable mush.
- dom0 10y agoDo realize that no Linux distribution ships such binaries. They do the equivalent of -march=$worstSupportedProcessor (eg x86_64). To actually get any benefits from the smart compiler on these you'll need to use FMV and proprietary compiler extensions (eg. GCC per function options), write runtime dispatch code etc. (GCC also has proprietary extensions for that).
- smitherfield 10y agoIn this particular case it just replaced a few of the x86 instructions with AMD64 ones.
- arthur2e5 10y agoSolus Linux builds some libraries into /usr/$LIB/avx and modified glibc's ld loader to load these libraries if the CPU happens to have avx2. https://github.com/AOSC-Dev/aosc-os-abbs/issues/522#issuecomment-266824590 https://github.com/AOSC-Dev/aosc-os-abbs/issues/522#issuecom... (In that issue I am trying to figure out some FMV stuff.)
- geocar 10y ago> I think I'd need to study it for months if not years to understand what the compiler did. Yes, but once you did you might see how you might improve it. Your brain, while slower at code translation than gcc, can think of things that gcc never will, and yet things that can beat your brain[1] are still slower. [1]: https://en.wikipedia.org/wiki/Superoptimization https://en.wikipedia.org/wiki/Superoptimization