Saturday, August 2, 2014

Bitcount, 8-bit precomputed

/*Bloody C99 keywords, I deny!*/
#include<stdint.h>
typedef uint8_t t1u;
typedef int8_t t1s;
typedef uint16_t t2u;
typedef int16_t t2s;
typedef uint32_t t4u;
typedef int32_t t4s;typedef float t4f;
typedef uint64_t t8u;
typedef int64_t t8s;typedef double t8f;

static t1u const nlA[0x100]={
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,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,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,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,
1,2,2,3,2,3,3,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};


static t1u fs(t1u p)noexcept{

return nlA[p];}
static t2u fs(t2u p)noexcept{

return nlA[p&0xFF]+nlA[(p>>0x08)&0xFF];}
static t4u fs(t4u p)noexcept{

return nlA[p&0xFF]+nlA[(p>>0x08)&0xFF]+nlA[(p>>0x10)&0xFF]+nlA[(p>>0x18)&0xFF];}
static t8u fs(t8u p)noexcept{return nlA[p&0xFF]+nlA[(p>>0x08)&0xFF]+nlA[(p>>0x10)&0xFF]+nlA[(p>>0x18)&0xFF]+

nlA[(p>>0x20)&0xFF]+nlA[(p>>0x28)&0xFF]+nlA[(p>>0x30)&0xFF]+nlA[(p>>0x38)&0xFF];}

No comments:

Post a Comment