UI: __popcnt is not supported by old CPU

This commit is contained in:
Nodir Temirkhodjaev 2023-02-12 21:56:03 +03:00
parent 3c626ec675
commit 4301045d82
2 changed files with 5 additions and 18 deletions

View File

@ -266,24 +266,11 @@ bool isTimeInPeriod(quint8 hour, quint8 minute, quint8 fromHour, quint8 fromMinu
return is_time_in_period(time, period);
}
int bitCount(quint32 mask)
int bitCount(quint32 v)
{
#if defined(_M_IX86) || defined(_M_X64)
return __popcnt(mask);
#elif defined(_M_ARM64)
__n64 num;
num.n64_u64[0] = mask;
num = neon_cnt(num);
return num.n64_u32[0];
#else
int n = 0;
while (mask != 0) {
n += (mask & 1) != 0 ? 1 : 0;
mask >>= 1;
}
return n;
#endif
v = v - ((v >> 1) & 0x55555555);
v = (v & 0x33333333) + ((v >> 2) & 0x33333333);
return ((v + (v >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
}
int bitScanForward(quint32 mask)

View File

@ -77,7 +77,7 @@ quint16 confAppPeriodBits(const void *drvConf, quint8 hour, quint8 minute);
bool isTimeInPeriod(quint8 hour, quint8 minute, quint8 fromHour, quint8 fromMinute, quint8 toHour,
quint8 toMinute);
int bitCount(quint32 mask);
int bitCount(quint32 v);
int bitScanForward(quint32 mask);
void provUnregister();