From ab28697c185f3f2b06362f223eca27e560f7c042 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 2 Nov 2019 10:45:41 +0100 Subject: [PATCH] - undid the very pointless pow2char (de)optimization by substituting the real array with an empty struct containing an inlined [] operator. I think this shows a fundamental misunderstanding of what constexpr means, even when declared as such it requires a constant argument to be treated as a constant. But since nearly all uses of this were not using constants, the compiler was emitting actual memory accesses to the array each time this was used. --- source/build/include/compat.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/source/build/include/compat.h b/source/build/include/compat.h index e7dbe4d23..f8aef3de2 100644 --- a/source/build/include/compat.h +++ b/source/build/include/compat.h @@ -1134,7 +1134,18 @@ CONSTEXPR size_t logbasenegative(T n) ////////// Bitfield manipulation ////////// +#if 0 +// Behold the probably most useless (de)optimization I ever discovered. +// Replacing a simple bit shift with a memory access through a global pointer is surely going to improve matters... >( +// Constexpr means shit here if the index is not a constant! static CONSTEXPR const char pow2char[8] = {1,2,4,8,16,32,64,128u}; +#else +// Revert the above to a real bit shift through some C++ operator magic. That saves me from reverting all the code that uses this construct. +struct +{ + constexpr uint8_t operator[](int index) const { return 1 << index; }; +} pow2char; +#endif static FORCE_INLINE void bitmap_set(uint8_t *const ptr, int const n) { ptr[n>>3] |= pow2char[n&7]; } static FORCE_INLINE void bitmap_clear(uint8_t *const ptr, int const n) { ptr[n>>3] &= ~pow2char[n&7]; }