Make popcount bit-masks stricter

Each bit run is upto the right shift count, so the each mask does not
need more upper bits.
This commit is contained in:
Nobuyoshi Nakada 2023-09-19 11:07:20 +09:00
Родитель f087f2c74c
Коммит 54f1d398d9
1 изменённых файлов: 6 добавлений и 6 удалений

Просмотреть файл

@ -398,9 +398,9 @@ rb_popcount32(uint32_t x)
#else
x = (x & 0x55555555) + (x >> 1 & 0x55555555);
x = (x & 0x33333333) + (x >> 2 & 0x33333333);
x = (x & 0x0f0f0f0f) + (x >> 4 & 0x0f0f0f0f);
x = (x & 0x001f001f) + (x >> 8 & 0x001f001f);
x = (x & 0x0000003f) + (x >>16 & 0x0000003f);
x = (x & 0x07070707) + (x >> 4 & 0x07070707);
x = (x & 0x000f000f) + (x >> 8 & 0x000f000f);
x = (x & 0x0000001f) + (x >>16 & 0x0000001f);
return (unsigned int)x;
#endif
@ -428,9 +428,9 @@ rb_popcount64(uint64_t x)
x = (x & 0x5555555555555555) + (x >> 1 & 0x5555555555555555);
x = (x & 0x3333333333333333) + (x >> 2 & 0x3333333333333333);
x = (x & 0x0707070707070707) + (x >> 4 & 0x0707070707070707);
x = (x & 0x001f001f001f001f) + (x >> 8 & 0x001f001f001f001f);
x = (x & 0x0000003f0000003f) + (x >>16 & 0x0000003f0000003f);
x = (x & 0x000000000000007f) + (x >>32 & 0x000000000000007f);
x = (x & 0x000f000f000f000f) + (x >> 8 & 0x000f000f000f000f);
x = (x & 0x0000001f0000001f) + (x >>16 & 0x0000001f0000001f);
x = (x & 0x000000000000003f) + (x >>32 & 0x000000000000003f);
return (unsigned int)x;
#endif