3 ms·
Whenever I see C code like this: #define CHUNK(multiplier, z) \ {
by Groxx 15y ago
Whenever I see C code like this:
#define CHUNK(multiplier, z) \
{ \
uint64 old_a = a; \
a = Rotate(b, 41 ^ z) * multiplier + Fetch64(s); \
b = Rotate(c, 27 ^ z) * multiplier + Fetch64(s + 8); \
c = Rotate(d, 41 ^ z) * multiplier + Fetch64(s + 16); \
... etc
I wonder: isn't this the kind of thing that's better handled by creating a function, and maybe explicitly telling the compiler to inline it? I mean, you can do this (from here: http://gcc.gnu.org/onlinedocs/gcc/Inline.html http://gcc.gnu.org/onlinedocs/gcc/Inline.html ):
inline void foo (const char) __attribute__((always_inline));
or you could simply let your optimizer take care of it. It may be faster to not inline it in some circumstances, but you've gone out of your way to prevent it from being able to make that decision, and to make your code harder to read and more prone to problems due to macro expansion.
Why? Is it habit? Or is there a good reason? (currently. historical reasons are not good reasons to continue doing things.)
- saurik 15y agoPeople who write hash functions are both exceedingly anal about performance concerns and generally interested in having their work compile with any and all reasonable C compilers (yes, even those that aren't gcc) and still have at least good performance. They also tend to be things that are not designed in code: they are designed in math and then translated to code as the last step, preferably in a way that is able to remain static forever (they should not need maintenance by an engineer, even/especially to update to support random new C compiler builds). (Some of my friends entered the recent SHA3 NIST hash competition and lasted long enough to have random other mathematicians scrutinize, improve, and finally defeat their math. http://en.wikipedia.org/wiki/Spectral_Hash http://en.wikipedia.org/wiki/Spectral_Hash)