The Lost Art of C Structure Packing

16    17 Dec 2016 23:25 by u/GrislyAtoms

5 comments

4

Is there any compiler that doesn't take care of this? I wrote a C compiler myself (for a compiler class years ago) and one of the specs there was optimized type alignment which is pretty straight forward on a compiler level. I think knowledge of this would be relatively important for somebody writing a low level compiler, but doing this for software in general seems like it's going to be wasting lots of time and best and decreased performance at worst. And of course you need to rethink all your assumptions when you want to deploy on a different architecture. Nasty business.

Something for instance I was surprised to discover is that in some cases esoteric bit hackery for various mathematical operations ends up with a worse performance than doing things 'naively'. I have no clue why or how this is but I assume it's the compiler taking advantage of those 3 and 4 letter acronyms for hardware level optimizations that I've lost track of after SIMD that might do better at optimizing 'normal' code, yet struggle with 'optimized' code.

0

Fun, but basically irrelevant information in 2016 where optimizing compilers are MUCH smarter than people at how to do this stuff.