35 typedef uint32_t Uint32;
36 #define MEMCOPY_NO_WORDS(to, from, no_of_words) \
37 memcpy((to), (void*)(from), (size_t)(no_of_words << 2));
41 getbits(
const Uint32 *src, Uint32 bit_pos, Uint32 *dst, Uint32 count)
55 MEMCOPY_NO_WORDS(dst, src, count>>5);
71 #ifdef WORDS_BIGENDIAN
72 Uint32 firstpart_len= 32-bit_pos;
73 val= *src++ & (((Uint32)1<<firstpart_len)-1);
74 val|= *src & ((Uint32)0xffffffff << firstpart_len);
76 val= *src++ >> bit_pos;
77 val|= *src << (32-bit_pos);
87 if (bit_pos+count <= 32)
90 #ifdef WORDS_BIGENDIAN
91 val= *src >> (32-(bit_pos+count));
99 #ifdef WORDS_BIGENDIAN
100 Uint32 firstpart_len= 32-bit_pos;
101 val= *src++ & (((Uint32)1<<firstpart_len)-1);
102 val|= (*src >> (32-count)) & ((Uint32)0xffffffff << firstpart_len);
104 val= *src++ >> bit_pos;
105 val|= *src << (32-bit_pos);
109 *dst= val & (((Uint32)1<<count)-1);
114 setbits(
const Uint32 *src, Uint32 *dst, Uint32 bit_pos, Uint32 count)
123 #ifdef WORDS_BIGENDIAN
124 Uint32 low_mask= ((Uint32)0xffffffff)<<(32-bit_pos);
125 Uint32 high_mask= ~low_mask;
127 Uint32 low_mask= (((Uint32)1)<<bit_pos) - 1;
128 Uint32 high_mask= ~low_mask;
133 MEMCOPY_NO_WORDS(dst, src, count>>5);
143 #ifdef WORDS_BIGENDIAN
144 *dst= (*dst&low_mask) | (val&high_mask);
146 *dst= (*dst&high_mask) | (val&low_mask);
148 *dst= (*dst&low_mask) | (val<<bit_pos);
150 *dst= (*dst&high_mask) | (val>>(32-bit_pos));
160 if (bit_pos+count <= 32)
163 Uint32 end_mask= (((Uint32)1)<<count) - 1;
164 #ifdef WORDS_BIGENDIAN
165 Uint32 shift= (32-(bit_pos+count));
166 *dst= (*dst&~(end_mask<<shift)) | ((val&end_mask)<<shift);
168 *dst= (*dst&~(end_mask<<bit_pos)) | ((val&end_mask)<<bit_pos);
174 #ifdef WORDS_BIGENDIAN
175 *dst= (*dst&low_mask) | (val&high_mask);
177 Uint32 shift= 32-count;
178 Uint32 end_mask= ((((Uint32)1)<<(bit_pos+count-32)) - 1) << (32-bit_pos);
179 *dst= (*dst&~(end_mask<<shift)) | ((val&end_mask)<<shift);
181 *dst= (*dst&low_mask) | (val<<bit_pos);
183 Uint32 end_mask= (((Uint32)1)<<(count+bit_pos-32)) - 1;
184 *dst= (*dst&~end_mask) | ((val>>(32-bit_pos))&end_mask);
199 memset(bms[i], 0,
sizeof(bms[i]));
205 for(j= 0; j<len[
i]; j++)
207 bms[
i][j>>5]|= (((uint32_t)1)<<(j&31));
215 for(i=0, idx=0; i<N; i++, idx+= S)
219 setbits(&(bms[idx][0]), &(bm[0]), pos[idx], len[idx]);
230 getbits(&(bm[0]), pos[i], &(buf[0]), len[i]);
231 assert(0==memcmp(buf, bms[i], ((len[i]+31)>>5)<<2));
235 int main(
int argc,
char *argv[])