mirror of
https://github.com/overte-org/overte.git
synced 2025-07-23 09:03:53 +02:00
#2386 trying a new static lookup table for numberOfOnes()
This commit is contained in:
parent
07742f54a7
commit
5f94e44cde
1 changed files with 16 additions and 8 deletions
|
@ -130,14 +130,22 @@ void outputBits(unsigned char byte, QDebug* continuedDebug) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int numberOfOnes(unsigned char byte) {
|
int numberOfOnes(unsigned char byte) {
|
||||||
return (byte >> 7)
|
|
||||||
+ ((byte >> 6) & 1)
|
static const unsigned char nbits[256] = {
|
||||||
+ ((byte >> 5) & 1)
|
0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,
|
||||||
+ ((byte >> 4) & 1)
|
4,3,4,4,5,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,
|
||||||
+ ((byte >> 3) & 1)
|
4,5,3,4,4,5,4,5,5,6,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,
|
||||||
+ ((byte >> 2) & 1)
|
3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,2,3,3,4,3,4,4,5,3,4,4,5,
|
||||||
+ ((byte >> 1) & 1)
|
4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,1,2,2,3,2,3,3,
|
||||||
+ (byte & 1);
|
4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,2,3,
|
||||||
|
3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,
|
||||||
|
6,6,7,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,
|
||||||
|
4,5,5,6,5,6,6,7,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,
|
||||||
|
6,5,6,6,7,5,6,6,7,6,7,7,8
|
||||||
|
};
|
||||||
|
|
||||||
|
return nbits[(unsigned char) byte];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool oneAtBit(unsigned char byte, int bitIndex) {
|
bool oneAtBit(unsigned char byte, int bitIndex) {
|
||||||
|
|
Loading…
Reference in a new issue