Return to Index  

replacement bit.cpp which does not use __int8 etc.

June 14 2008 at 1:27 PM
qbguy  (Login dean.menezes)
R

 

//bit-array access inline functions
static long boff;
static int64_t bmask;
static uint64_t *bptr64;
static int64_t bval64;
inline uint64_t getubits(unsigned long bsize, unsigned char *base,
unsigned long i)
{
bmask = ~(-(1 << bsize));
i *= bsize;
boff = i & bmask;
return ((*(uint64_t *) (base + (i >> 3))) & (bmask << boff)) >> boff;
}
inline int64_t getbits(unsigned long bsize, unsigned char *base,
unsigned long i)
{
bmask = ~(-(1 << bsize));
i *= bsize;
boff = i & bmask;
bval64 = ((*(uint64_t *) (base + (i >> 3))) & (bmask << boff)) >> boff;
if (bval64 & (1 << (bsize - 1)))
return (bval64 | (~bmask));
return bval64;
}
inline void setbits(unsigned long bsize, unsigned char *base,
unsigned long i, long val)
{
bmask = ~(-(1 << bsize));
i *= bsize;
boff = i & bmask;
val = (val & bmask) << boff;
bptr64 = (uint64_t *) (base + (i >> 3));
*bptr64 = (*bptr64 & (~(bmask << boff))) + val;
}

/*
#define bmask 7
#define bsize 3
inline unsigned long getubits_3(unsigned char *base,unsigned long i){
i*=bsize; boff=i&bmask;
return ((*(unsigned long*)(base+(i>>3)))&(bmask<<boff))>>boff;
}
inline long getbits_3(unsigned char *base,unsigned long i){
i*=bsize; boff=i&bmask;
bval=((*(unsigned long*)(base+(i>>3)))&(bmask<<boff))>>boff;
if (bval&4) return (bval|(~bmask));
return bval;
}
inline void setbits_3(unsigned char *base,unsigned long i,long val){
i*=bsize; boff=i&bmask; val=(val&bmask)<<boff; bptr=(unsigned long*)(base+(i>>3));
*bptr=(*bptr&(~(bmask<<boff)))+val;
}
#undef bmask
#undef bsize
*/



    
This message has been edited by dean.menezes on Jun 15, 2008 10:04 AM


 
 Respond to this message   
 Copyright © 1999-2014 Network54. All rights reserved.   Terms of Use   Privacy Statement