mirror of
https://github.com/harfbuzz/harfbuzz.git
synced 2025-04-15 01:18:13 +00:00
[algs] 64bit popcount
This commit is contained in:
parent
5b0d818128
commit
bd62a91d03
1 changed files with 6 additions and 4 deletions
|
@ -618,16 +618,18 @@ hb_popcount (T v)
|
|||
if (sizeof (T) <= 4)
|
||||
{
|
||||
/* "HACKMEM 169" */
|
||||
uint32_t y;
|
||||
y = (v >> 1) &033333333333;
|
||||
uint32_t y = (uint32_t) v;
|
||||
y = (y >> 1) &033333333333;
|
||||
y = v - y - ((y >>1) & 033333333333);
|
||||
return (((y + (y >> 3)) & 030707070707) % 077);
|
||||
}
|
||||
|
||||
if (sizeof (T) == 8)
|
||||
{
|
||||
unsigned int shift = 32;
|
||||
return hb_popcount<uint32_t> ((uint32_t) v) + hb_popcount ((uint32_t) (v >> shift));
|
||||
uint64_t y = (uint64_t) v;
|
||||
y -= ((y >> 1) & 0x5555555555555555ull);
|
||||
y = (y & 0x3333333333333333ull) + (y >> 2 & 0x3333333333333333ull);
|
||||
return ((y + (y >> 4)) & 0xf0f0f0f0f0f0f0full) * 0x101010101010101ull >> 56;
|
||||
}
|
||||
|
||||
if (sizeof (T) == 16)
|
||||
|
|
Loading…
Add table
Reference in a new issue