23 ms·
Seeing the project name EAStdC I thought for a moment this would be the C counterpart to EASTL (e.g. a modern replacement for the C standard library), but alas,
by flohofwoe 4y ago
Seeing the project name EAStdC I thought for a moment this would be the C counterpart to EASTL (e.g. a modern replacement for the C standard library), but alas, it's all written in C++ and intended to be used from C++ (e.g. no C interfaces).
For anyone interested in this sort of stuff and isn't yet aware of the 'bit twiddling hacks' collection:
https://graphics.stanford.edu/~seander/bithacks.html https://graphics.stanford.edu/~seander/bithacks.html
Also regarding the bit counting function:
inline int CountBits(uint32_t x) // Branchless version
{
#if defined(EASTDC_SSE_POPCNT)
return _mm_popcnt_u32(x);
#else
x = x - ((x >> 1) & 0x55555555);
x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
x = (x + (x >> 4)) & 0x0F0F0F0F;
return (int)((x * 0x01010101) >> 24);
#endif
}
Some compilers go as far as detecting the 'bit twiddling' version and replace that with a popcnt instruction:
https://www.godbolt.org/z/bExMvfzEx https://www.godbolt.org/z/bExMvfzEx
- sreekotay 4y agoMy contribution: http://sree.kotay.com/2007/04/shift-registers-and-de-bruijn-sequences_10.html?m=1 http://sree.kotay.com/2007/04/shift-registers-and-de-bruijn-...
- maximilianburke 4y ago(disclaimer: I used to work on these EA* libraries) The intention of EAStdC wasn't really to replace the platform libc but to augment it with portable implementations that had consistent behavior across the different platforms, as well as have some opt-in performance improvements (like a memcpy that used VMX), while also not polluting the global (C) namespace.
- djmips 4y agoWow! That's quite surprising to me (the godbolt link). Very cool!