Re:EABitTricks.h
by supermdguy on Monday December 19, 2022 @03:34PM
(#34057280)
Question from a frontend dev: Why can't the compiler apply these tricks automatically? Are there assumptions they're making that don't necessarily hold?
[ Parent
| on HN ]
The compiler cannot always detect all the uses.
Re:EABitTricks.h
by nibbleshifter on Monday December 19, 2022 @04:14PM
(#34057806)
You can't really trust the compiler to emit sensible code ever
Re:EABitTricks.h
by jonstewart on Monday December 19, 2022 @11:12PM
(#34061449)
Clang and GCC can do some amazing optimizations. However, these types of tricks often come into play as a result of clever data representation, i.e., instead of representing data as a bunch of objects in an array, you’ve figured out how to represent it, or a subset, in some cleverly packed bits and/or ints (and then can reap the benefit of these tricks).
It’s trivial for a compiler to see (x / 2) and substitute (x >> 1) but it is much harder for a compiler to go from seeing that you have a bunch of Foo objects and realizing that they could be better represented as clever bit vectors.