BitVector.c

filter: Statementstmt 89.9% 1712 / 1904 Branchbran 72.8% 900 / 1236 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 83.1% 2612 / 3140 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« Vector.xs ↑ Summary blib/lib/Bit/Vector.pm »
1 #ifndef MODULE_BIT_VECTOR
2 #define MODULE_BIT_VECTOR
3 /*****************************************************************************/
4 /* MODULE NAME: BitVector.c MODULE TYPE: (adt) */
5 /*****************************************************************************/
6 /* MODULE IMPORTS: */
7 /*****************************************************************************/
8 #include <stdlib.h> /* MODULE TYPE: (sys) */
9 #include <limits.h> /* MODULE TYPE: (sys) */
10 #include <string.h> /* MODULE TYPE: (sys) */
11 #include <ctype.h> /* MODULE TYPE: (sys) */
12 #include "ToolBox.h" /* MODULE TYPE: (dat) */
13 /*****************************************************************************/
14 /* MODULE INTERFACE: */
15 /*****************************************************************************/
16  
17 typedef enum
18 {
19 BV_ErrCode_Ok = 0, /* everything went allright */
20  
21 BV_ErrCode_Type, /* types word and size_t have incompatible sizes */
22 BV_ErrCode_Bits, /* bits of word and sizeof(word) are inconsistent */
23 BV_ErrCode_Word, /* size of word is less than 16 bits */
24 BV_ErrCode_Powr, /* number of bits of word is not a power of two */
25 BV_ErrCode_Loga, /* error in calculation of logarithm */
26 BV_ErrCode_Lpwr, /* number of bits of long is not a power of two */
27 BV_ErrCode_WgtL, /* size of word is greater than size of long */
28  
29 BV_ErrCode_Null, /* unable to allocate memory */
30  
31 BV_ErrCode_Indx, /* index out of range */
32 BV_ErrCode_Ordr, /* minimum > maximum index */
33 BV_ErrCode_Size, /* bit vector size mismatch */
34 BV_ErrCode_Pars, /* input string syntax error */
35 BV_ErrCode_Ovfl, /* numeric overflow error */
36 BV_ErrCode_Same, /* operands must be distinct */
37 BV_ErrCode_Expo, /* exponent must be positive */
38 BV_ErrCode_Zero, /* division by zero error */
39 BV_ErrCode_Oops /* unexpected error (contact author) */
40 }
41 BV_ErrCode;
42  
43 typedef
44 wordptr *bv_listptr;
45  
46 /* ===> MISCELLANEOUS BASIC FUNCTIONS: <=== */
47  
48 charptr BitVector_Error (BV_ErrCode error); /* map errcode to string */
49  
50 BV_ErrCode BitVector_Boot (void); /* 0 = ok, 1..17 = error */
51  
52 N_word BitVector_Size (N_int bits); /* bit vec. size (# of words) */
53 N_word BitVector_Mask (N_int bits); /* bit vec. mask (unused bits) */
54  
55 /* ===> CLASS METHODS: <=== */
56  
57 charptr BitVector_Version (void); /* return version string */
58  
59 N_int BitVector_Word_Bits (void); /* return # of bits in machine word */
60 N_int BitVector_Long_Bits (void); /* return # of bits in unsigned long */
61  
62 /* ===> CONSTRUCTOR METHODS: <=== */
63  
64 wordptr BitVector_Create (N_int bits, boolean clear); /* malloc */
65 bv_listptr BitVector_Create_List(N_int bits, boolean clear, N_int count);
66  
67 wordptr BitVector_Resize (wordptr oldaddr, N_int bits); /* realloc */
68  
69 wordptr BitVector_Shadow (wordptr addr); /* make same size but empty */
70 wordptr BitVector_Clone (wordptr addr); /* make exact duplicate */
71  
72 wordptr BitVector_Concat (wordptr X, wordptr Y); /* return concat'd */
73  
74 /* ===> DESTRUCTOR METHODS: <=== */
75  
76 void BitVector_Dispose (charptr string); /* string */
77 void BitVector_Destroy (wordptr addr); /* bitvec */
78 void BitVector_Destroy_List (bv_listptr list, N_int count); /* list */
79  
80 /* ===> OBJECT METHODS: <=== */
81  
82 /* ===> bit vector copy function: */
83  
84 void BitVector_Copy (wordptr X, wordptr Y); /* X = Y */
85  
86 /* ===> bit vector initialization: */
87  
88 void BitVector_Empty (wordptr addr); /* X = {} */
89 void BitVector_Fill (wordptr addr); /* X = ~{} */
90 void BitVector_Flip (wordptr addr); /* X = ~X */
91  
92 void BitVector_Primes (wordptr addr);
93  
94 /* ===> miscellaneous functions: */
95  
96 void BitVector_Reverse (wordptr X, wordptr Y);
97  
98 /* ===> bit vector interval operations and functions: */
99  
100 void BitVector_Interval_Empty (wordptr addr, N_int lower, N_int upper);
101 void BitVector_Interval_Fill (wordptr addr, N_int lower, N_int upper);
102 void BitVector_Interval_Flip (wordptr addr, N_int lower, N_int upper);
103 void BitVector_Interval_Reverse (wordptr addr, N_int lower, N_int upper);
104  
105 boolean BitVector_interval_scan_inc (wordptr addr, N_int start,
106 N_intptr min, N_intptr max);
107 boolean BitVector_interval_scan_dec (wordptr addr, N_int start,
108 N_intptr min, N_intptr max);
109  
110 void BitVector_Interval_Copy (wordptr X, wordptr Y, N_int Xoffset,
111 N_int Yoffset, N_int length);
112  
113 wordptr BitVector_Interval_Substitute(wordptr X, wordptr Y,
114 N_int Xoffset, N_int Xlength,
115 N_int Yoffset, N_int Ylength);
116  
117 /* ===> bit vector test functions: */
118  
119 boolean BitVector_is_empty (wordptr addr); /* X == {} ? */
120 boolean BitVector_is_full (wordptr addr); /* X == ~{} ? */
121  
122 boolean BitVector_equal (wordptr X, wordptr Y); /* X == Y ? */
123 Z_int BitVector_Lexicompare(wordptr X, wordptr Y); /* X <,=,> Y ? */
124 Z_int BitVector_Compare (wordptr X, wordptr Y); /* X <,=,> Y ? */
125  
126 /* ===> bit vector string conversion functions: */
127  
128 charptr BitVector_to_Hex (wordptr addr);
129 BV_ErrCode BitVector_from_Hex (wordptr addr, charptr string);
130  
131 charptr BitVector_to_Bin (wordptr addr);
132 BV_ErrCode BitVector_from_Bin (wordptr addr, charptr string);
133  
134 charptr BitVector_to_Dec (wordptr addr);
135 BV_ErrCode BitVector_from_Dec (wordptr addr, charptr string);
136  
137 charptr BitVector_to_Enum (wordptr addr);
138 BV_ErrCode BitVector_from_Enum (wordptr addr, charptr string);
139  
140 /* ===> bit vector bit operations, functions & tests: */
141  
142 void BitVector_Bit_Off (wordptr addr, N_int index); /* X = X \ {x} */
143 void BitVector_Bit_On (wordptr addr, N_int index); /* X = X + {x} */
144 boolean BitVector_bit_flip (wordptr addr, N_int index); /* (X+{x})\(X*{x}) */
145  
146 boolean BitVector_bit_test (wordptr addr, N_int index); /* {x} in X ? */
147  
148 void BitVector_Bit_Copy (wordptr addr, N_int index, boolean bit);
149  
150 /* ===> bit vector bit shift & rotate functions: */
151  
152 void BitVector_LSB (wordptr addr, boolean bit);
153 void BitVector_MSB (wordptr addr, boolean bit);
154 boolean BitVector_lsb_ (wordptr addr);
155 boolean BitVector_msb_ (wordptr addr);
156 boolean BitVector_rotate_left (wordptr addr);
157 boolean BitVector_rotate_right (wordptr addr);
158 boolean BitVector_shift_left (wordptr addr, boolean carry_in);
159 boolean BitVector_shift_right (wordptr addr, boolean carry_in);
160 void BitVector_Move_Left (wordptr addr, N_int bits);
161 void BitVector_Move_Right (wordptr addr, N_int bits);
162  
163 /* ===> bit vector insert/delete bits: */
164  
165 void BitVector_Insert (wordptr addr, N_int offset, N_int count,
166 boolean clear);
167 void BitVector_Delete (wordptr addr, N_int offset, N_int count,
168 boolean clear);
169  
170 /* ===> bit vector arithmetic: */
171  
172 boolean BitVector_increment (wordptr addr); /* X++ */
173 boolean BitVector_decrement (wordptr addr); /* X-- */
174  
175 boolean BitVector_compute (wordptr X, wordptr Y, wordptr Z, boolean minus,
176 boolean *carry);
177 boolean BitVector_add (wordptr X, wordptr Y, wordptr Z, boolean *carry);
178 boolean BitVector_sub (wordptr X, wordptr Y, wordptr Z, boolean *carry);
179 boolean BitVector_inc (wordptr X, wordptr Y);
180 boolean BitVector_dec (wordptr X, wordptr Y);
181  
182 void BitVector_Negate (wordptr X, wordptr Y);
183 void BitVector_Absolute (wordptr X, wordptr Y);
184 Z_int BitVector_Sign (wordptr addr);
185 BV_ErrCode BitVector_Mul_Pos (wordptr X, wordptr Y, wordptr Z, boolean strict);
186 BV_ErrCode BitVector_Multiply (wordptr X, wordptr Y, wordptr Z);
187 BV_ErrCode BitVector_Div_Pos (wordptr Q, wordptr X, wordptr Y, wordptr R);
188 BV_ErrCode BitVector_Divide (wordptr Q, wordptr X, wordptr Y, wordptr R);
189 BV_ErrCode BitVector_GCD (wordptr X, wordptr Y, wordptr Z);
190 BV_ErrCode BitVector_GCD2 (wordptr U, wordptr V, wordptr W, /* O */
191 wordptr X, wordptr Y); /* I */
192 BV_ErrCode BitVector_Power (wordptr X, wordptr Y, wordptr Z);
193  
194 /* ===> direct memory access functions: */
195  
196 void BitVector_Block_Store(wordptr addr, charptr buffer, N_int length);
197 charptr BitVector_Block_Read (wordptr addr, N_intptr length);
198  
199 /* ===> word array functions: */
200  
201 void BitVector_Word_Store (wordptr addr, N_int offset, N_int value);
202 N_int BitVector_Word_Read (wordptr addr, N_int offset);
203  
204 void BitVector_Word_Insert(wordptr addr, N_int offset, N_int count,
205 boolean clear);
206 void BitVector_Word_Delete(wordptr addr, N_int offset, N_int count,
207 boolean clear);
208  
209 /* ===> arbitrary size chunk functions: */
210  
211 void BitVector_Chunk_Store(wordptr addr, N_int chunksize,
212 N_int offset, N_long value);
213 N_long BitVector_Chunk_Read (wordptr addr, N_int chunksize,
214 N_int offset);
215  
216 /* ===> set operations: */
217  
218 void Set_Union (wordptr X, wordptr Y, wordptr Z); /* X = Y + Z */
219 void Set_Intersection (wordptr X, wordptr Y, wordptr Z); /* X = Y * Z */
220 void Set_Difference (wordptr X, wordptr Y, wordptr Z); /* X = Y \ Z */
221 void Set_ExclusiveOr (wordptr X, wordptr Y, wordptr Z); /*(Y+Z)\(Y*Z)*/
222 void Set_Complement (wordptr X, wordptr Y); /* X = ~Y */
223  
224 /* ===> set functions: */
225  
226 boolean Set_subset (wordptr X, wordptr Y); /* X in Y */
227  
228 N_int Set_Norm (wordptr addr); /* = |X| */
229 N_int Set_Norm2 (wordptr addr); /* = |X| */
230 N_int Set_Norm3 (wordptr addr); /* = |X| */
231 Z_long Set_Min (wordptr addr); /* = min(X) */
232 Z_long Set_Max (wordptr addr); /* = max(X) */
233  
234 /* ===> matrix-of-booleans operations: */
235  
236 void Matrix_Multiplication(wordptr X, N_int rowsX, N_int colsX,
237 wordptr Y, N_int rowsY, N_int colsY,
238 wordptr Z, N_int rowsZ, N_int colsZ);
239  
240 void Matrix_Product (wordptr X, N_int rowsX, N_int colsX,
241 wordptr Y, N_int rowsY, N_int colsY,
242 wordptr Z, N_int rowsZ, N_int colsZ);
243  
244 void Matrix_Closure (wordptr addr, N_int rows, N_int cols);
245  
246 void Matrix_Transpose (wordptr X, N_int rowsX, N_int colsX,
247 wordptr Y, N_int rowsY, N_int colsY);
248  
249 /*****************************************************************************/
250 /* MODULE RESOURCES: */
251 /*****************************************************************************/
252  
253 #define BV_BITS_(BitVector) *(BitVector-3)
254 #define BV_SIZE_(BitVector) *(BitVector-2)
255 #define BV_MASK_(BitVector) *(BitVector-1)
256  
257 #define BV_ERRCODE_TYPE "sizeof(word) > sizeof(size_t)"
258 #define BV_ERRCODE_BITS "bits(word) != sizeof(word)*8"
259 #define BV_ERRCODE_WORD "bits(word) < 16"
260 #define BV_ERRCODE_POWR "bits(word) is not a power of two"
261 #define BV_ERRCODE_LOGA "bits(word) != 2^ld(bits(word))"
262 #define BV_ERRCODE_LPWR "bits(long) is not a power of two"
263 #define BV_ERRCODE_WGTL "bits(word) > bits(long)"
264 #define BV_ERRCODE_NULL "unable to allocate memory"
265 #define BV_ERRCODE_INDX "index out of range"
266 #define BV_ERRCODE_ORDR "minimum > maximum index"
267 #define BV_ERRCODE_SIZE "bit vector size mismatch"
268 #define BV_ERRCODE_PARS "input string syntax error"
269 #define BV_ERRCODE_OVFL "numeric overflow error"
270 #define BV_ERRCODE_SAME "result vector(s) must be distinct"
271 #define BV_ERRCODE_EXPO "exponent must be positive"
272 #define BV_ERRCODE_ZERO "division by zero error"
273 #define BV_ERRCODE_OOPS "unexpected internal error - please contact author"
274  
275 const N_int BV_ByteNorm[256] =
276 {
277 0x00, 0x01, 0x01, 0x02, 0x01, 0x02, 0x02, 0x03,
278 0x01, 0x02, 0x02, 0x03, 0x02, 0x03, 0x03, 0x04, /* 0x00 */
279 0x01, 0x02, 0x02, 0x03, 0x02, 0x03, 0x03, 0x04,
280 0x02, 0x03, 0x03, 0x04, 0x03, 0x04, 0x04, 0x05, /* 0x10 */
281 0x01, 0x02, 0x02, 0x03, 0x02, 0x03, 0x03, 0x04,
282 0x02, 0x03, 0x03, 0x04, 0x03, 0x04, 0x04, 0x05, /* 0x20 */
283 0x02, 0x03, 0x03, 0x04, 0x03, 0x04, 0x04, 0x05,
284 0x03, 0x04, 0x04, 0x05, 0x04, 0x05, 0x05, 0x06, /* 0x30 */
285 0x01, 0x02, 0x02, 0x03, 0x02, 0x03, 0x03, 0x04,
286 0x02, 0x03, 0x03, 0x04, 0x03, 0x04, 0x04, 0x05, /* 0x40 */
287 0x02, 0x03, 0x03, 0x04, 0x03, 0x04, 0x04, 0x05,
288 0x03, 0x04, 0x04, 0x05, 0x04, 0x05, 0x05, 0x06, /* 0x50 */
289 0x02, 0x03, 0x03, 0x04, 0x03, 0x04, 0x04, 0x05,
290 0x03, 0x04, 0x04, 0x05, 0x04, 0x05, 0x05, 0x06, /* 0x60 */
291 0x03, 0x04, 0x04, 0x05, 0x04, 0x05, 0x05, 0x06,
292 0x04, 0x05, 0x05, 0x06, 0x05, 0x06, 0x06, 0x07, /* 0x70 */
293 0x01, 0x02, 0x02, 0x03, 0x02, 0x03, 0x03, 0x04,
294 0x02, 0x03, 0x03, 0x04, 0x03, 0x04, 0x04, 0x05, /* 0x80 */
295 0x02, 0x03, 0x03, 0x04, 0x03, 0x04, 0x04, 0x05,
296 0x03, 0x04, 0x04, 0x05, 0x04, 0x05, 0x05, 0x06, /* 0x90 */
297 0x02, 0x03, 0x03, 0x04, 0x03, 0x04, 0x04, 0x05,
298 0x03, 0x04, 0x04, 0x05, 0x04, 0x05, 0x05, 0x06, /* 0xA0 */
299 0x03, 0x04, 0x04, 0x05, 0x04, 0x05, 0x05, 0x06,
300 0x04, 0x05, 0x05, 0x06, 0x05, 0x06, 0x06, 0x07, /* 0xB0 */
301 0x02, 0x03, 0x03, 0x04, 0x03, 0x04, 0x04, 0x05,
302 0x03, 0x04, 0x04, 0x05, 0x04, 0x05, 0x05, 0x06, /* 0xC0 */
303 0x03, 0x04, 0x04, 0x05, 0x04, 0x05, 0x05, 0x06,
304 0x04, 0x05, 0x05, 0x06, 0x05, 0x06, 0x06, 0x07, /* 0xD0 */
305 0x03, 0x04, 0x04, 0x05, 0x04, 0x05, 0x05, 0x06,
306 0x04, 0x05, 0x05, 0x06, 0x05, 0x06, 0x06, 0x07, /* 0xE0 */
307 0x04, 0x05, 0x05, 0x06, 0x05, 0x06, 0x06, 0x07,
308 0x05, 0x06, 0x06, 0x07, 0x06, 0x07, 0x07, 0x08 /* 0xF0 */
309 };
310  
311 /*****************************************************************************/
312 /* MODULE IMPLEMENTATION: */
313 /*****************************************************************************/
314  
315 /**********************************************/
316 /* global implementation-intrinsic constants: */
317 /**********************************************/
318  
319 #define BV_HIDDENWORDS 3
320  
321 /*****************************************************************/
322 /* global machine-dependent constants (set by "BitVector_Boot"): */
323 /*****************************************************************/
324  
325 static N_word BV_WordBits; /* = # of bits in a machine word (power of 2) */
326 static N_word BV_ModMask; /* = BV_WordBits-1 (for "modulo BV_WordBits") */
327 static N_word BV_LogBits; /* = ld(BV_WordBits) (logarithmus dualis) */
328 static N_word BV_Factor; /* = ld(BV_WordBits / 8) (ld of # of bytes) */
329  
330 static N_word BV_LSB = 1; /* = mask for least significant bit */
331 static N_word BV_MSB; /* = mask for most significant bit */
332  
333 static N_word BV_LongBits; /* = # of bits in unsigned long */
334  
335 static N_word BV_Log10; /* = logarithm to base 10 of BV_WordBits - 1 */
336 static N_word BV_Exp10; /* = largest possible power of 10 in signed int */
337  
338 /********************************************************************/
339 /* global bit mask table for fast access (set by "BitVector_Boot"): */
340 /********************************************************************/
341  
342 #define BV_MASKTABSIZE (sizeof(N_word) << 3)
343  
344 static N_word BV_BitMaskTab[BV_MASKTABSIZE];
345  
346 /*****************************/
347 /* global macro definitions: */
348 /*****************************/
349  
350 #define BIT_VECTOR_ZERO_WORDS(target,count) \
351 while (count-- > 0) *target++ = 0;
352  
353 #define BIT_VECTOR_FILL_WORDS(target,fill,count) \
354 while (count-- > 0) *target++ = fill;
355  
356 #define BIT_VECTOR_FLIP_WORDS(target,flip,count) \
357 while (count-- > 0) *target++ ^= flip;
358  
359 #define BIT_VECTOR_COPY_WORDS(target,source,count) \
360 while (count-- > 0) *target++ = *source++;
361  
362 #define BIT_VECTOR_BACK_WORDS(target,source,count) \
363 { target += count; source += count; while (count-- > 0) *--target = *--source; }
364  
365 #define BIT_VECTOR_CLR_BIT(address,index) \
366 *(address+(index>>BV_LogBits)) &= NOT BV_BitMaskTab[index AND BV_ModMask];
367  
368 #define BIT_VECTOR_SET_BIT(address,index) \
369 *(address+(index>>BV_LogBits)) |= BV_BitMaskTab[index AND BV_ModMask];
370  
371 #define BIT_VECTOR_TST_BIT(address,index) \
372 ((*(address+(index>>BV_LogBits)) AND BV_BitMaskTab[index AND BV_ModMask]) != 0)
373  
374 #define BIT_VECTOR_FLP_BIT(address,index,mask) \
375 (mask = BV_BitMaskTab[index AND BV_ModMask]), \
376 (((*(addr+(index>>BV_LogBits)) ^= mask) AND mask) != 0)
377  
378 #define BIT_VECTOR_DIGITIZE(type,value,digit) \
379 value = (type) ((digit = value) / 10); \
380 digit -= value * 10; \
381 digit += (type) '0';
382  
383 /*********************************************************/
384 /* private low-level functions (potentially dangerous!): */
385 /*********************************************************/
386  
387 23 static N_word BIT_VECTOR_power10(N_word x)
388 {
389 23 N_word y = 1;
390  
391 437 ▶ while (x-- > 0) y *= 10;
Branch: 1 branch
BranchTrueFalseTotal
while (x-- > 0) y *= 10; 414 23 437
392 23 return(y);
393 }
394  
395 4094 static void BIT_VECTOR_zro_words(wordptr addr, N_word count)
396 {
397 35040 ▶ BIT_VECTOR_ZERO_WORDS(addr,count)
Branch: 1 branch
BranchTrueFalseTotal
BIT_VECTOR_ZERO_WORDS(addr,count) 30946 4094 35040
398 4094 }
399  
400 5307 static void BIT_VECTOR_cpy_words(wordptr target, wordptr source, N_word count)
401 {
402 77221 ▶ BIT_VECTOR_COPY_WORDS(target,source,count)
Branch: 1 branch
BranchTrueFalseTotal
BIT_VECTOR_COPY_WORDS(target,source,count) 71914 5307 77221
403 5307 }
404  
405 4092 static void BIT_VECTOR_mov_words(wordptr target, wordptr source, N_word count)
406 {
407 4092 ▶ if (target != source)
Branch: 1 branch
BranchTrueFalseTotal
if (target != source) 4092 0 4092
408 {
409 19578 ▶ if (target < source) BIT_VECTOR_COPY_WORDS(target,source,count)
Branch: 2 branches
BranchTrueFalseTotal
if (target < source) BIT_VECTOR_COPY_WORDS(target,source,count) 2046 2046 4092
if (target < source) BIT_VECTOR_COPY_WORDS(target,source,count) 15486 2046 17532
410 17532 ▶ else BIT_VECTOR_BACK_WORDS(target,source,count)
Branch: 1 branch
BranchTrueFalseTotal
else BIT_VECTOR_BACK_WORDS(target,source,count) 15486 2046 17532
411 }
412 4092 }
413  
414 2514 static void BIT_VECTOR_ins_words(wordptr addr, N_word total, N_word count,
415 boolean clear)
416 {
417 N_word length;
418  
419 2514 ▶ if ((total > 0) and (count > 0))
Branch: 2 branches
BranchTrueFalseTotal
if ((total > 0) and (count > 0)) 2514 0 2514
if ((total > 0) and (count > 0)) 2047 467 2514
420 {
421 2047 ▶ if (count > total) count = total;
Branch: 1 branch
BranchTrueFalseTotal
if (count > total) count = total; 1 2046 2047
422 2047 length = total - count;
423 2047 ▶ if (length > 0) BIT_VECTOR_mov_words(addr+count,addr,length);
Branch: 1 branch
BranchTrueFalseTotal
if (length > 0) BIT_VECTOR_mov_words(addr+count,addr,length); 2046 1 2047
424 2047 ▶ if (clear) BIT_VECTOR_zro_words(addr,count);
Branch: 1 branch
BranchTrueFalseTotal
if (clear) BIT_VECTOR_zro_words(addr,count); 2047 0 2047
425 }
426 2514 }
427  
428 2514 static void BIT_VECTOR_del_words(wordptr addr, N_word total, N_word count,
429 boolean clear)
430 {
431 N_word length;
432  
433 2514 ▶ if ((total > 0) and (count > 0))
Branch: 2 branches
BranchTrueFalseTotal
if ((total > 0) and (count > 0)) 2514 0 2514
if ((total > 0) and (count > 0)) 2047 467 2514
434 {
435 2047 ▶ if (count > total) count = total;
Branch: 1 branch
BranchTrueFalseTotal
if (count > total) count = total; 1 2046 2047
436 2047 length = total - count;
437 2047 ▶ if (length > 0) BIT_VECTOR_mov_words(addr,addr+count,length);
Branch: 1 branch
BranchTrueFalseTotal
if (length > 0) BIT_VECTOR_mov_words(addr,addr+count,length); 2046 1 2047
438 2047 ▶ if (clear) BIT_VECTOR_zro_words(addr+length,count);
Branch: 1 branch
BranchTrueFalseTotal
if (clear) BIT_VECTOR_zro_words(addr+length,count); 2047 0 2047
439 }
440 2514 }
441  
442 4616 static void BIT_VECTOR_reverse(charptr string, N_word length)
443 {
444 charptr last;
445 N_char temp;
446  
447 4616 ▶ if (length > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (length > 1) 4110 506 4616
448 {
449 4110 last = string + length - 1;
450 12571 ▶ while (string < last)
Branch: 1 branch
BranchTrueFalseTotal
while (string < last) 8461 4110 12571
451 {
452 8461 temp = *string;
453 8461 *string = *last;
454 8461 *last = temp;
455 8461 string++;
456 8461 last--;
457 }
458 }
459 4616 }
460  
461 3888 static N_word BIT_VECTOR_int2str(charptr string, N_word value)
462 {
463 N_word length;
464 N_word digit;
465 charptr work;
466  
467 3888 work = string;
468 3888 ▶ if (value > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (value > 0) 3814 74 3888
469 {
470 3814 length = 0;
471 14174 ▶ while (value > 0)
Branch: 1 branch
BranchTrueFalseTotal
while (value > 0) 10360 3814 14174
472 {
473 10360 BIT_VECTOR_DIGITIZE(N_word,value,digit)
474 10360 *work++ = (N_char) digit;
475 10360 length++;
476 }
477 3814 BIT_VECTOR_reverse(string,length);
478 }
479 else
480 {
481 74 length = 1;
482 74 *work++ = (N_char) '0';
483 }
484 3888 return(length);
485 }
486  
487 3899 static N_word BIT_VECTOR_str2int(charptr string, N_word *value)
488 {
489 N_word length;
490 N_word digit;
491  
492 3899 *value = 0;
493 3899 length = 0;
494 3899 digit = (N_word) *string++;
495 /* separate because isdigit() is likely a macro! */
496 14369 ▶ while (isdigit((int)digit) != 0)
Branch: 1 branch
BranchTrueFalseTotal
while (isdigit((int)digit) != 0) 10470 3899 14369
497 {
498 10470 length++;
499 10470 digit -= (N_word) '0';
500 10470 ▶ if (*value) *value *= 10;
Branch: 1 branch
BranchTrueFalseTotal
if (*value) *value *= 10; 6571 3899 10470
501 10470 *value += digit;
502 10470 digit = (N_word) *string++;
503 }
504 3899 return(length);
505 }
506  
507 /********************************************/
508 /* routine to convert error code to string: */
509 /********************************************/
510  
511 23 charptr BitVector_Error(BV_ErrCode error)
512 {
513 23 switch (error)
514 {
515 0 case BV_ErrCode_Ok: return( (charptr) NULL ); break;
516 0 case BV_ErrCode_Type: return( (charptr) BV_ERRCODE_TYPE ); break;
517 0 case BV_ErrCode_Bits: return( (charptr) BV_ERRCODE_BITS ); break;
518 0 case BV_ErrCode_Word: return( (charptr) BV_ERRCODE_WORD ); break;
519 0 case BV_ErrCode_Powr: return( (charptr) BV_ERRCODE_POWR ); break;
520 0 case BV_ErrCode_Loga: return( (charptr) BV_ERRCODE_LOGA ); break;
521 0 case BV_ErrCode_Lpwr: return( (charptr) BV_ERRCODE_LPWR ); break;
522 0 case BV_ErrCode_WgtL: return( (charptr) BV_ERRCODE_WGTL ); break;
523 0 case BV_ErrCode_Null: return( (charptr) BV_ERRCODE_NULL ); break;
524 4 case BV_ErrCode_Indx: return( (charptr) BV_ERRCODE_INDX ); break;
525 1 case BV_ErrCode_Ordr: return( (charptr) BV_ERRCODE_ORDR ); break;
526 8 case BV_ErrCode_Size: return( (charptr) BV_ERRCODE_SIZE ); break;
527 8 case BV_ErrCode_Pars: return( (charptr) BV_ERRCODE_PARS ); break;
528 0 case BV_ErrCode_Ovfl: return( (charptr) BV_ERRCODE_OVFL ); break;
529 2 case BV_ErrCode_Same: return( (charptr) BV_ERRCODE_SAME ); break;
530 0 case BV_ErrCode_Expo: return( (charptr) BV_ERRCODE_EXPO ); break;
531 0 case BV_ErrCode_Zero: return( (charptr) BV_ERRCODE_ZERO ); break;
532 0 default: return( (charptr) BV_ERRCODE_OOPS ); break;
533 }
534 }
535  
536 /*****************************************/
537 /* automatic self-configuration routine: */
538 /*****************************************/
539  
540 /*******************************************************/
541 /* */
542 /* MUST be called once prior to any other function */
543 /* to initialize the machine dependent constants */
544 /* of this package! */
545 /* */
546 /*******************************************************/
547  
548 23 BV_ErrCode BitVector_Boot(void)
549 {
550 N_word sample;
551 N_long longsample;
552  
553 if (sizeof(N_word) > sizeof(size_t)) return(BV_ErrCode_Type);
554  
555 23 BV_WordBits = 0;
556 23 sample = ~0;
557 1495 ▶ while (sample) /* determine # of bits in a machine word */
Branch: 1 branch
BranchTrueFalseTotal
while (sample) /* determine # of bits in a machine word */ 1472 23 1495
558 {
559 1472 sample &= sample - 1;
560 1472 BV_WordBits++;
561 }
562  
563 23 ▶ if (BV_WordBits != (sizeof(N_word) << 3)) return(BV_ErrCode_Bits);
Branch: 1 branch
BranchTrueFalseTotal
if (BV_WordBits != (sizeof(N_word) << 3)) return(BV_ErrCode_Bits); 0 23 23
564  
565 23 ▶ if (BV_WordBits < 16) return(BV_ErrCode_Word);
Branch: 1 branch
BranchTrueFalseTotal
if (BV_WordBits < 16) return(BV_ErrCode_Word); 0 23 23
566  
567 23 BV_LongBits = 0;
568 23 longsample = ~0L;
569 1495 ▶ while (longsample) /* determine # of bits in an unsigned long */
Branch: 1 branch
BranchTrueFalseTotal
while (longsample) /* determine # of bits in an unsigned long */ 1472 23 1495
570 {
571 1472 longsample &= longsample - 1L;
572 1472 BV_LongBits++;
573 }
574  
575 23 BV_LogBits = 0;
576 23 sample = BV_ModMask = BV_WordBits - 1;
577 23 ▶ if (sample AND BV_WordBits) return(BV_ErrCode_Powr); /* not a power of 2 */
Branch: 1 branch
BranchTrueFalseTotal
if (sample AND BV_WordBits) return(BV_ErrCode_Powr); /* not a power of 2 */ 0 23 23
578 161 ▶ while (sample)
Branch: 1 branch
BranchTrueFalseTotal
while (sample) 138 23 161
579 {
580 138 sample &= sample - 1;
581 138 BV_LogBits++;
582 }
583 23 ▶ if (BV_WordBits != (BV_LSB << BV_LogBits)) return(BV_ErrCode_Loga); /* ld wrong */
Branch: 1 branch
BranchTrueFalseTotal
if (BV_WordBits != (BV_LSB << BV_LogBits)) return(BV_ErrCode_Loga); /* ld wrong */ 0 23 23
584  
585 23 longsample = BV_LongBits - 1;
586 23 ▶ if ((longsample AND BV_LongBits) or (BV_LongBits != (sizeof(N_long) << 3)))
Branch: 2 branches
BranchTrueFalseTotal
if ((longsample AND BV_LongBits) or (BV_LongBits != (sizeof(N_long) << 3))) 23 0 23
if ((longsample AND BV_LongBits) or (BV_LongBits != (sizeof(N_long) << 3))) 0 23 23
587 {
588 0 BV_LongBits = (sizeof(N_long) << 3);
589 0 longsample = BV_LongBits - 1;
590 0 ▶ if (longsample AND BV_LongBits) return(BV_ErrCode_Lpwr);
Branch: 1 branch
BranchTrueFalseTotal
if (longsample AND BV_LongBits) return(BV_ErrCode_Lpwr); 0 0 0
591 }
592  
593 23 ▶ if (BV_WordBits > BV_LongBits) return(BV_ErrCode_WgtL);
Branch: 1 branch
BranchTrueFalseTotal
if (BV_WordBits > BV_LongBits) return(BV_ErrCode_WgtL); 0 23 23
594  
595 23 ▶ if (BV_WordBits > BV_MASKTABSIZE) return(BV_ErrCode_Oops);
Branch: 1 branch
BranchTrueFalseTotal
if (BV_WordBits > BV_MASKTABSIZE) return(BV_ErrCode_Oops); 0 23 23
596  
597 1495 ▶ for ( sample = 0; sample < BV_WordBits; sample++ )
Branch: 1 branch
BranchTrueFalseTotal
for ( sample = 0; sample < BV_WordBits; sample++ ) 1472 23 1495
598 {
599 1472 BV_BitMaskTab[sample] = (BV_LSB << sample);
600 }
601  
602 23 BV_Factor = BV_LogBits - 3; /* ld(Bits/8) = ld(Bits)-ld(8) = ld(Bits)-3 */
603  
604 23 BV_MSB = (BV_LSB << BV_ModMask);
605  
606 23 BV_Log10 = (N_word) (BV_ModMask * 0.30103); /* (Bits-1) * ln(2) / ln(10) */
607 23 BV_Exp10 = BIT_VECTOR_power10(BV_Log10);
608  
609 23 return(BV_ErrCode_Ok);
610 }
611  
612 22818 N_word BitVector_Size(N_int bits) /* bit vector size (# of words) */
613 {
614 N_word size;
615  
616 22818 size = bits >> BV_LogBits;
617 22818 ▶ if (bits AND BV_ModMask) size++;
Branch: 1 branch
BranchTrueFalseTotal
if (bits AND BV_ModMask) size++; 14332 8486 22818
618 22818 return(size);
619 }
620  
621 22818 N_word BitVector_Mask(N_int bits) /* bit vector mask (unused bits) */
622 {
623 N_word mask;
624  
625 22818 mask = bits AND BV_ModMask;
626 22818 ▶ if (mask) mask = (N_word) ~(~0L << mask); else mask = (N_word) ~0L;
Branch: 1 branch
BranchTrueFalseTotal
if (mask) mask = (N_word) ~(~0L << mask); else mask = (N_word) ~0L; 14332 8486 22818
627 22818 return(mask);
628 }
629  
630 4 charptr BitVector_Version(void)
631 {
632 4 return((charptr)"7.5");
633 }
634  
635 911 N_int BitVector_Word_Bits(void)
636 {
637 911 return(BV_WordBits);
638 }
639  
640 39710 N_int BitVector_Long_Bits(void)
641 {
642 39710 return(BV_LongBits);
643 }
644  
645 /********************************************************************/
646 /* */
647 /* WARNING: Do not "free()" constant character strings, i.e., */
648 /* don't call "BitVector_Dispose()" for strings returned */
649 /* by "BitVector_Error()" or "BitVector_Version()"! */
650 /* */
651 /* ONLY call this function for strings allocated with "malloc()", */
652 /* i.e., the strings returned by the functions "BitVector_to_*()" */
653 /* and "BitVector_Block_Read()"! */
654 /* */
655 /********************************************************************/
656  
657 5041 void BitVector_Dispose(charptr string) /* free string */
658 {
659 5041 ▶ if (string != NULL) free((voidptr) string);
Branch: 1 branch
BranchTrueFalseTotal
if (string != NULL) free((voidptr) string); 5041 0 5041
660 5041 }
661  
662 22735 void BitVector_Destroy(wordptr addr) /* free bitvec */
663 {
664 22735 ▶ if (addr != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (addr != NULL) 22735 0 22735
665 {
666 22735 addr -= BV_HIDDENWORDS;
667 22735 free((voidptr) addr);
668 }
669 22735 }
670  
671 61 void BitVector_Destroy_List(bv_listptr list, N_int count) /* free list */
672 {
673 bv_listptr slot;
674  
675 61 ▶ if (list != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (list != NULL) 61 0 61
676 {
677 61 slot = list;
678 721 ▶ while (count-- > 0)
Branch: 1 branch
BranchTrueFalseTotal
while (count-- > 0) 660 61 721
679 {
680 660 BitVector_Destroy(*slot++);
681 }
682 61 free((voidptr) list);
683 }
684 61 }
685  
686 22723 wordptr BitVector_Create(N_int bits, boolean clear) /* malloc */
687 {
688 N_word size;
689 N_word mask;
690 N_word bytes;
691 wordptr addr;
692 wordptr zero;
693  
694 22723 size = BitVector_Size(bits);
695 22723 mask = BitVector_Mask(bits);
696 22723 bytes = (size + BV_HIDDENWORDS) << BV_Factor;
697 22723 addr = (wordptr) malloc((size_t) bytes);
698 22723 ▶ if (addr != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (addr != NULL) 22723 0 22723
699 {
700 22723 *addr++ = bits;
701 22723 *addr++ = size;
702 22723 *addr++ = mask;
703 22723 ▶ if (clear)
Branch: 1 branch
BranchTrueFalseTotal
if (clear) 12993 9730 22723
704 {
705 12993 zero = addr;
706 479787 ▶ BIT_VECTOR_ZERO_WORDS(zero,size)
Branch: 1 branch
BranchTrueFalseTotal
BIT_VECTOR_ZERO_WORDS(zero,size) 466794 12993 479787
707 }
708 }
709 22723 return(addr);
710 }
711  
712 61 bv_listptr BitVector_Create_List(N_int bits, boolean clear, N_int count)
713 {
714 61 bv_listptr list = NULL;
715 bv_listptr slot;
716 wordptr addr;
717 N_int i;
718  
719 61 ▶ if (count > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (count > 0) 61 0 61
720 {
721 61 list = (bv_listptr) malloc(sizeof(wordptr) * count);
722 61 ▶ if (list != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (list != NULL) 61 0 61
723 {
724 61 slot = list;
725 726 ▶ for ( i = 0; i < count; i++ )
Branch: 1 branch
BranchTrueFalseTotal
for ( i = 0; i < count; i++ ) 665 61 726
726 {
727 665 addr = BitVector_Create(bits,clear);
728 665 ▶ if (addr == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (addr == NULL) 0 665 665
729 {
730 0 BitVector_Destroy_List(list,i);
731 0 return(NULL);
732 }
733 665 *slot++ = addr;
734 }
735 }
736 }
737 61 return(list);
738 }
739  
740 95 wordptr BitVector_Resize(wordptr oldaddr, N_int bits) /* realloc */
741 {
742 N_word bytes;
743 N_word oldsize;
744 N_word oldmask;
745 N_word newsize;
746 N_word newmask;
747 wordptr newaddr;
748 wordptr source;
749 wordptr target;
750  
751 95 oldsize = BV_SIZE_(oldaddr);
752 95 oldmask = BV_MASK_(oldaddr);
753 95 newsize = BitVector_Size(bits);
754 95 newmask = BitVector_Mask(bits);
755 95 ▶ if (oldsize > 0) *(oldaddr+oldsize-1) &= oldmask;
Branch: 1 branch
BranchTrueFalseTotal
if (oldsize > 0) *(oldaddr+oldsize-1) &= oldmask; 95 0 95
756 95 ▶ if (newsize <= oldsize)
Branch: 1 branch
BranchTrueFalseTotal
if (newsize <= oldsize) 83 12 95
757 {
758 83 newaddr = oldaddr;
759 83 BV_BITS_(newaddr) = bits;
760 83 BV_SIZE_(newaddr) = newsize;
761 83 BV_MASK_(newaddr) = newmask;
762 83 ▶ if (newsize > 0) *(newaddr+newsize-1) &= newmask;
Branch: 1 branch
BranchTrueFalseTotal
if (newsize > 0) *(newaddr+newsize-1) &= newmask; 82 1 83
763 }
764 else
765 {
766 12 bytes = (newsize + BV_HIDDENWORDS) << BV_Factor;
767 12 newaddr = (wordptr) malloc((size_t) bytes);
768 12 ▶ if (newaddr != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (newaddr != NULL) 12 0 12
769 {
770 12 *newaddr++ = bits;
771 12 *newaddr++ = newsize;
772 12 *newaddr++ = newmask;
773 12 target = newaddr;
774 12 source = oldaddr;
775 12 newsize -= oldsize;
776 2211 ▶ BIT_VECTOR_COPY_WORDS(target,source,oldsize)
Branch: 1 branch
BranchTrueFalseTotal
BIT_VECTOR_COPY_WORDS(target,source,oldsize) 2199 12 2211
777 221541 ▶ BIT_VECTOR_ZERO_WORDS(target,newsize)
Branch: 1 branch
BranchTrueFalseTotal
BIT_VECTOR_ZERO_WORDS(target,newsize) 221529 12 221541
778 }
779 12 BitVector_Destroy(oldaddr);
780 }
781 95 return(newaddr);
782 }
783  
784 2732 wordptr BitVector_Shadow(wordptr addr) /* makes new, same size but empty */
785 {
786 2732 return( BitVector_Create(BV_BITS_(addr),true) );
787 }
788  
789 5305 wordptr BitVector_Clone(wordptr addr) /* makes exact duplicate */
790 {
791 N_word bits;
792 wordptr twin;
793  
794 5305 bits = BV_BITS_(addr);
795 5305 twin = BitVector_Create(bits,false);
796 5305 ▶ if ((twin != NULL) and (bits > 0))
Branch: 2 branches
BranchTrueFalseTotal
if ((twin != NULL) and (bits > 0)) 5305 0 5305
if ((twin != NULL) and (bits > 0)) 5305 0 5305
797 5305 BIT_VECTOR_cpy_words(twin,addr,BV_SIZE_(addr));
798 5305 return(twin);
799 }
800  
801 2 wordptr BitVector_Concat(wordptr X, wordptr Y) /* returns concatenation */
802 {
803 /* BEWARE that X = most significant part, Y = least significant part! */
804  
805 N_word bitsX;
806 N_word bitsY;
807 N_word bitsZ;
808 wordptr Z;
809  
810 2 bitsX = BV_BITS_(X);
811 2 bitsY = BV_BITS_(Y);
812 2 bitsZ = bitsX + bitsY;
813 2 Z = BitVector_Create(bitsZ,false);
814 2 ▶ if ((Z != NULL) and (bitsZ > 0))
Branch: 2 branches
BranchTrueFalseTotal
if ((Z != NULL) and (bitsZ > 0)) 2 0 2
if ((Z != NULL) and (bitsZ > 0)) 2 0 2
815 {
816 2 BIT_VECTOR_cpy_words(Z,Y,BV_SIZE_(Y));
817 2 BitVector_Interval_Copy(Z,X,bitsY,0,bitsX);
818 2 *(Z+BV_SIZE_(Z)-1) &= BV_MASK_(Z);
819 }
820 2 return(Z);
821 }
822  
823 5280 void BitVector_Copy(wordptr X, wordptr Y) /* X = Y */
824 {
825 5280 N_word sizeX = BV_SIZE_(X);
826 5280 N_word sizeY = BV_SIZE_(Y);
827 5280 N_word maskX = BV_MASK_(X);
828 5280 N_word maskY = BV_MASK_(Y);
829 5280 N_word fill = 0;
830 wordptr lastX;
831 wordptr lastY;
832  
833 5280 ▶ if ((X != Y) and (sizeX > 0))
Branch: 2 branches
BranchTrueFalseTotal
if ((X != Y) and (sizeX > 0)) 5274 6 5280
if ((X != Y) and (sizeX > 0)) 5274 0 5274
834 {
835 5274 lastX = X + sizeX - 1;
836 5274 ▶ if (sizeY > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (sizeY > 0) 5274 0 5274
837 {
838 5274 lastY = Y + sizeY - 1;
839 5274 ▶ if ( (*lastY AND (maskY AND NOT (maskY >> 1))) == 0 ) *lastY &= maskY;
Branch: 1 branch
BranchTrueFalseTotal
if ( (*lastY AND (maskY AND NOT (maskY >> 1))) == 0 ) *lastY &= maskY; 5208 66 5274
840 else
841 {
842 66 fill = (N_word) ~0L;
843 66 *lastY |= NOT maskY;
844 }
845 44171 ▶ while ((sizeX > 0) and (sizeY > 0))
Branch: 2 branches
BranchTrueFalseTotal
while ((sizeX > 0) and (sizeY > 0)) 38903 5268 44171
while ((sizeX > 0) and (sizeY > 0)) 38897 6 38903
846 {
847 38897 *X++ = *Y++;
848 38897 sizeX--;
849 38897 sizeY--;
850 }
851 5274 *lastY &= maskY;
852 }
853 5324 ▶ while (sizeX-- > 0) *X++ = fill;
Branch: 1 branch
BranchTrueFalseTotal
while (sizeX-- > 0) *X++ = fill; 50 5274 5324
854 5274 *lastX &= maskX;
855 }
856 5280 }
857  
858 4120 void BitVector_Empty(wordptr addr) /* X = {} clr all */
859 {
860 4120 N_word size = BV_SIZE_(addr);
861  
862 39275 ▶ BIT_VECTOR_ZERO_WORDS(addr,size)
Branch: 1 branch
BranchTrueFalseTotal
BIT_VECTOR_ZERO_WORDS(addr,size) 35155 4120 39275
863 4120 }
864  
865 10723 void BitVector_Fill(wordptr addr) /* X = ~{} set all */
866 {
867 10723 N_word size = BV_SIZE_(addr);
868 10723 N_word mask = BV_MASK_(addr);
869 10723 N_word fill = (N_word) ~0L;
870  
871 10723 ▶ if (size > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (size > 0) 10722 1 10723
872 {
873 159053 ▶ BIT_VECTOR_FILL_WORDS(addr,fill,size)
Branch: 1 branch
BranchTrueFalseTotal
BIT_VECTOR_FILL_WORDS(addr,fill,size) 148331 10722 159053
874 10722 *(--addr) &= mask;
875 }
876 10723 }
877  
878 2971 void BitVector_Flip(wordptr addr) /* X = ~X flip all */
879 {
880 2971 N_word size = BV_SIZE_(addr);
881 2971 N_word mask = BV_MASK_(addr);
882 2971 N_word flip = (N_word) ~0L;
883  
884 2971 ▶ if (size > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (size > 0) 2971 0 2971
885 {
886 91202 ▶ BIT_VECTOR_FLIP_WORDS(addr,flip,size)
Branch: 1 branch
BranchTrueFalseTotal
BIT_VECTOR_FLIP_WORDS(addr,flip,size) 88231 2971 91202
887 2971 *(--addr) &= mask;
888 }
889 2971 }
890  
891 1238 void BitVector_Primes(wordptr addr)
892 {
893 1238 N_word bits = BV_BITS_(addr);
894 1238 N_word size = BV_SIZE_(addr);
895 wordptr work;
896 N_word temp;
897 N_word i,j;
898  
899 1238 ▶ if (size > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (size > 0) 1236 2 1238
900 {
901 1236 temp = 0xAAAA;
902 1236 i = BV_WordBits >> 4;
903 4944 ▶ while (--i > 0)
Branch: 1 branch
BranchTrueFalseTotal
while (--i > 0) 3708 1236 4944
904 {
905 3708 temp <<= 16;
906 3708 temp |= 0xAAAA;
907 }
908 1236 i = size;
909 1236 work = addr;
910 1236 *work++ = temp XOR 0x0006;
911 37933 ▶ while (--i > 0) *work++ = temp;
Branch: 1 branch
BranchTrueFalseTotal
while (--i > 0) *work++ = temp; 36697 1236 37933
912 24893 ▶ for ( i = 3; (j = i * i) < bits; i += 2 )
Branch: 1 branch
BranchTrueFalseTotal
for ( i = 3; (j = i * i) < bits; i += 2 ) 23657 1236 24893
913 {
914 3256085 ▶ for ( ; j < bits; j += i ) BIT_VECTOR_CLR_BIT(addr,j)
Branch: 1 branch
BranchTrueFalseTotal
for ( ; j < bits; j += i ) BIT_VECTOR_CLR_BIT(addr,j) 3232428 23657 3256085
915 }
916 1236 *(addr+size-1) &= BV_MASK_(addr);
917 }
918 1238 }
919  
920 2 void BitVector_Reverse(wordptr X, wordptr Y)
921 {
922 2 N_word bits = BV_BITS_(X);
923 N_word mask;
924 N_word bit;
925 N_word value;
926  
927 2 ▶ if (bits > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (bits > 0) 2 0 2
928 {
929 2 ▶ if (X == Y) BitVector_Interval_Reverse(X,0,bits-1);
Branch: 1 branch
BranchTrueFalseTotal
if (X == Y) BitVector_Interval_Reverse(X,0,bits-1); 1 1 2
930 1 ▶ else if (bits == BV_BITS_(Y))
Branch: 1 branch
BranchTrueFalseTotal
else if (bits == BV_BITS_(Y)) 1 0 1
931 {
932 /* mask = BV_MASK_(Y); */
933 /* mask &= NOT (mask >> 1); */
934 1 mask = BV_BitMaskTab[(bits-1) AND BV_ModMask];
935 1 Y += BV_SIZE_(Y) - 1;
936 1 value = 0;
937 1 bit = BV_LSB;
938 1025 ▶ while (bits-- > 0)
Branch: 1 branch
BranchTrueFalseTotal
while (bits-- > 0) 1024 1 1025
939 {
940 1024 ▶ if ((*Y AND mask) != 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((*Y AND mask) != 0) 1 1023 1024
941 {
942 1 value |= bit;
943 }
944 1024 ▶ if (not (mask >>= 1))
Branch: 1 branch
BranchTrueFalseTotal
if (not (mask >>= 1)) 16 1008 1024
945 {
946 16 Y--;
947 16 mask = BV_MSB;
948 }
949 1024 ▶ if (not (bit <<= 1))
Branch: 1 branch
BranchTrueFalseTotal
if (not (bit <<= 1)) 16 1008 1024
950 {
951 16 *X++ = value;
952 16 value = 0;
953 16 bit = BV_LSB;
954 }
955 }
956 1 ▶ if (bit > BV_LSB) *X = value;
Branch: 1 branch
BranchTrueFalseTotal
if (bit > BV_LSB) *X = value; 0 1 1
957 }
958 }
959 2 }
960  
961 10543 void BitVector_Interval_Empty(wordptr addr, N_int lower, N_int upper)
962 { /* X = X \ [lower..upper] */
963 10543 N_word bits = BV_BITS_(addr);
964 10543 N_word size = BV_SIZE_(addr);
965 wordptr loaddr;
966 wordptr hiaddr;
967 N_word lobase;
968 N_word hibase;
969 N_word lomask;
970 N_word himask;
971 N_word diff;
972  
973 10543 ▶ if ((size > 0) and (lower < bits) and (upper < bits) and (lower <= upper))
Branch: 4 branches
BranchTrueFalseTotal
if ((size > 0) and (lower < bits) and (upper < bits) and (lower <= upper)) 10543 0 10543
if ((size > 0) and (lower < bits) and (upper < bits) and (lower <= upper)) 10543 0 10543
if ((size > 0) and (lower < bits) and (upper < bits) and (lower <= upper)) 10543 0 10543
if ((size > 0) and (lower < bits) and (upper < bits) and (lower <= upper)) 10543 0 10543
974 {
975 10543 lobase = lower >> BV_LogBits;
976 10543 hibase = upper >> BV_LogBits;
977 10543 diff = hibase - lobase;
978 10543 loaddr = addr + lobase;
979 10543 hiaddr = addr + hibase;
980  
981 10543 lomask = (N_word) (~0L << (lower AND BV_ModMask));
982 10543 himask = (N_word) ~((~0L << (upper AND BV_ModMask)) << 1);
983  
984 10543 ▶ if (diff == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (diff == 0) 2273 8270 10543
985 {
986 2273 *loaddr &= NOT (lomask AND himask);
987 }
988 else
989 {
990 8270 *loaddr++ &= NOT lomask;
991 64460 ▶ while (--diff > 0)
Branch: 1 branch
BranchTrueFalseTotal
while (--diff > 0) 56190 8270 64460
992 {
993 56190 *loaddr++ = 0;
994 }
995 8270 *hiaddr &= NOT himask;
996 }
997 }
998 10543 }
999  
1000 323 void BitVector_Interval_Fill(wordptr addr, N_int lower, N_int upper)
1001 { /* X = X + [lower..upper] */
1002 323 N_word bits = BV_BITS_(addr);
1003 323 N_word size = BV_SIZE_(addr);
1004 323 N_word fill = (N_word) ~0L;
1005 wordptr loaddr;
1006 wordptr hiaddr;
1007 N_word lobase;
1008 N_word hibase;
1009 N_word lomask;
1010 N_word himask;
1011 N_word diff;
1012  
1013 323 ▶ if ((size > 0) and (lower < bits) and (upper < bits) and (lower <= upper))
Branch: 4 branches
BranchTrueFalseTotal
if ((size > 0) and (lower < bits) and (upper < bits) and (lower <= upper)) 323 0 323
if ((size > 0) and (lower < bits) and (upper < bits) and (lower <= upper)) 323 0 323
if ((size > 0) and (lower < bits) and (upper < bits) and (lower <= upper)) 323 0 323
if ((size > 0) and (lower < bits) and (upper < bits) and (lower <= upper)) 323 0 323
1014 {
1015 323 lobase = lower >> BV_LogBits;
1016 323 hibase = upper >> BV_LogBits;
1017 323 diff = hibase - lobase;
1018 323 loaddr = addr + lobase;
1019 323 hiaddr = addr + hibase;
1020  
1021 323 lomask = (N_word) (~0L << (lower AND BV_ModMask));
1022 323 himask = (N_word) ~((~0L << (upper AND BV_ModMask)) << 1);
1023  
1024 323 ▶ if (diff == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (diff == 0) 286 37 323
1025 {
1026 286 *loaddr |= (lomask AND himask);
1027 }
1028 else
1029 {
1030 37 *loaddr++ |= lomask;
1031 2261 ▶ while (--diff > 0)
Branch: 1 branch
BranchTrueFalseTotal
while (--diff > 0) 2224 37 2261
1032 {
1033 2224 *loaddr++ = fill;
1034 }
1035 37 *hiaddr |= himask;
1036 }
1037 323 *(addr+size-1) &= BV_MASK_(addr);
1038 }
1039 323 }
1040  
1041 561 void BitVector_Interval_Flip(wordptr addr, N_int lower, N_int upper)
1042 { /* X = X ^ [lower..upper] */
1043 561 N_word bits = BV_BITS_(addr);
1044 561 N_word size = BV_SIZE_(addr);
1045 561 N_word flip = (N_word) ~0L;
1046 wordptr loaddr;
1047 wordptr hiaddr;
1048 N_word lobase;
1049 N_word hibase;
1050 N_word lomask;
1051 N_word himask;
1052 N_word diff;
1053  
1054 561 ▶ if ((size > 0) and (lower < bits) and (upper < bits) and (lower <= upper))
Branch: 4 branches
BranchTrueFalseTotal
if ((size > 0) and (lower < bits) and (upper < bits) and (lower <= upper)) 561 0 561
if ((size > 0) and (lower < bits) and (upper < bits) and (lower <= upper)) 561 0 561
if ((size > 0) and (lower < bits) and (upper < bits) and (lower <= upper)) 561 0 561
if ((size > 0) and (lower < bits) and (upper < bits) and (lower <= upper)) 561 0 561
1055 {
1056 561 lobase = lower >> BV_LogBits;
1057 561 hibase = upper >> BV_LogBits;
1058 561 diff = hibase - lobase;
1059 561 loaddr = addr + lobase;
1060 561 hiaddr = addr + hibase;
1061  
1062 561 lomask = (N_word) (~0L << (lower AND BV_ModMask));
1063 561 himask = (N_word) ~((~0L << (upper AND BV_ModMask)) << 1);
1064  
1065 561 ▶ if (diff == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (diff == 0) 537 24 561
1066 {
1067 537 *loaddr ^= (lomask AND himask);
1068 }
1069 else
1070 {
1071 24 *loaddr++ ^= lomask;
1072 4120 ▶ while (--diff > 0)
Branch: 1 branch
BranchTrueFalseTotal
while (--diff > 0) 4096 24 4120
1073 {
1074 4096 *loaddr++ ^= flip;
1075 }
1076 24 *hiaddr ^= himask;
1077 }
1078 561 *(addr+size-1) &= BV_MASK_(addr);
1079 }
1080 561 }
1081  
1082 50 void BitVector_Interval_Reverse(wordptr addr, N_int lower, N_int upper)
1083 {
1084 50 N_word bits = BV_BITS_(addr);
1085 wordptr loaddr;
1086 wordptr hiaddr;
1087 N_word lomask;
1088 N_word himask;
1089  
1090 50 ▶ if ((bits > 0) and (lower < bits) and (upper < bits) and (lower < upper))
Branch: 4 branches
BranchTrueFalseTotal
if ((bits > 0) and (lower < bits) and (upper < bits) and (lower < upper)) 50 0 50
if ((bits > 0) and (lower < bits) and (upper < bits) and (lower < upper)) 50 0 50
if ((bits > 0) and (lower < bits) and (upper < bits) and (lower < upper)) 50 0 50
if ((bits > 0) and (lower < bits) and (upper < bits) and (lower < upper)) 49 1 50
1091 {
1092 49 loaddr = addr + (lower >> BV_LogBits);
1093 49 hiaddr = addr + (upper >> BV_LogBits);
1094 49 lomask = BV_BitMaskTab[lower AND BV_ModMask];
1095 49 himask = BV_BitMaskTab[upper AND BV_ModMask];
1096 133581 ▶ for ( bits = upper - lower + 1; bits > 1; bits -= 2 )
Branch: 1 branch
BranchTrueFalseTotal
for ( bits = upper - lower + 1; bits > 1; bits -= 2 ) 133532 49 133581
1097 {
1098 133532 ▶ if (((*loaddr AND lomask) != 0) XOR ((*hiaddr AND himask) != 0))
Branch: 1 branch
BranchTrueFalseTotal
if (((*loaddr AND lomask) != 0) XOR ((*hiaddr AND himask) != 0)) 25795 107737 133532
1099 {
1100 25795 *loaddr ^= lomask; /* swap bits only if they differ! */
1101 25795 *hiaddr ^= himask;
1102 }
1103 133532 ▶ if (not (lomask <<= 1))
Branch: 1 branch
BranchTrueFalseTotal
if (not (lomask <<= 1)) 2074 131458 133532
1104 {
1105 2074 lomask = BV_LSB;
1106 2074 loaddr++;
1107 }
1108 133532 ▶ if (not (himask >>= 1))
Branch: 1 branch
BranchTrueFalseTotal
if (not (himask >>= 1)) 2074 131458 133532
1109 {
1110 2074 himask = BV_MSB;
1111 2074 hiaddr--;
1112 }
1113 }
1114 }
1115 50 }
1116  
1117 10398 boolean BitVector_interval_scan_inc(wordptr addr, N_int start,
1118 N_intptr min, N_intptr max)
1119 {
1120 10398 N_word size = BV_SIZE_(addr);
1121 10398 N_word mask = BV_MASK_(addr);
1122 N_word offset;
1123 N_word bitmask;
1124 N_word value;
1125 boolean empty;
1126  
1127 10398 ▶ if ((size == 0) or (start >= BV_BITS_(addr))) return(false);
Branch: 2 branches
BranchTrueFalseTotal
if ((size == 0) or (start >= BV_BITS_(addr))) return(false); 10398 0 10398
if ((size == 0) or (start >= BV_BITS_(addr))) return(false); 0 10398 10398
1128  
1129 10398 *min = start;
1130 10398 *max = start;
1131  
1132 10398 offset = start >> BV_LogBits;
1133  
1134 10398 *(addr+size-1) &= mask;
1135  
1136 10398 addr += offset;
1137 10398 size -= offset;
1138  
1139 10398 bitmask = BV_BitMaskTab[start AND BV_ModMask];
1140 10398 mask = NOT (bitmask OR (bitmask - 1));
1141  
1142 10398 value = *addr++;
1143 10398 ▶ if ((value AND bitmask) == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((value AND bitmask) == 0) 6923 3475 10398
1144 {
1145 6923 value &= mask;
1146 6923 ▶ if (value == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (value == 0) 2807 4116 6923
1147 {
1148 2807 offset++;
1149 2807 empty = true;
1150 19383 ▶ while (empty and (--size > 0))
Branch: 2 branches
BranchTrueFalseTotal
while (empty and (--size > 0)) 16709 2674 19383
while (empty and (--size > 0)) 16576 133 16709
1151 {
1152 16576 ▶ if ((value = *addr++)) empty = false; else offset++;
Branch: 1 branch
BranchTrueFalseTotal
if ((value = *addr++)) empty = false; else offset++; 2674 13902 16576
1153 }
1154 2807 ▶ if (empty) return(false);
Branch: 1 branch
BranchTrueFalseTotal
if (empty) return(false); 133 2674 2807
1155 }
1156 6790 start = offset << BV_LogBits;
1157 6790 bitmask = BV_LSB;
1158 6790 mask = value;
1159 218083 ▶ while (not (mask AND BV_LSB))
Branch: 1 branch
BranchTrueFalseTotal
while (not (mask AND BV_LSB)) 211293 6790 218083
1160 {
1161 211293 bitmask <<= 1;
1162 211293 mask >>= 1;
1163 211293 start++;
1164 }
1165 6790 mask = NOT (bitmask OR (bitmask - 1));
1166 6790 *min = start;
1167 6790 *max = start;
1168 }
1169 10265 value = NOT value;
1170 10265 value &= mask;
1171 10265 ▶ if (value == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (value == 0) 4419 5846 10265
1172 {
1173 4419 offset++;
1174 4419 empty = true;
1175 37761 ▶ while (empty and (--size > 0))
Branch: 2 branches
BranchTrueFalseTotal
while (empty and (--size > 0)) 34577 3184 37761
while (empty and (--size > 0)) 33342 1235 34577
1176 {
1177 33342 ▶ if ((value = NOT *addr++)) empty = false; else offset++;
Branch: 1 branch
BranchTrueFalseTotal
if ((value = NOT *addr++)) empty = false; else offset++; 3184 30158 33342
1178 }
1179 4419 ▶ if (empty) value = BV_LSB;
Branch: 1 branch
BranchTrueFalseTotal
if (empty) value = BV_LSB; 1235 3184 4419
1180 }
1181 10265 start = offset << BV_LogBits;
1182 327168 ▶ while (not (value AND BV_LSB))
Branch: 1 branch
BranchTrueFalseTotal
while (not (value AND BV_LSB)) 316903 10265 327168
1183 {
1184 316903 value >>= 1;
1185 316903 start++;
1186 }
1187 10265 *max = --start;
1188 10265 return(true);
1189 }
1190  
1191 5447 boolean BitVector_interval_scan_dec(wordptr addr, N_int start,
1192 N_intptr min, N_intptr max)
1193 {
1194 5447 N_word size = BV_SIZE_(addr);
1195 5447 N_word mask = BV_MASK_(addr);
1196 N_word offset;
1197 N_word bitmask;
1198 N_word value;
1199 boolean empty;
1200  
1201 5447 ▶ if ((size == 0) or (start >= BV_BITS_(addr))) return(false);
Branch: 2 branches
BranchTrueFalseTotal
if ((size == 0) or (start >= BV_BITS_(addr))) return(false); 5447 0 5447
if ((size == 0) or (start >= BV_BITS_(addr))) return(false); 0 5447 5447
1202  
1203 5447 *min = start;
1204 5447 *max = start;
1205  
1206 5447 offset = start >> BV_LogBits;
1207  
1208 5447 ▶ if (offset >= size) return(false);
Branch: 1 branch
BranchTrueFalseTotal
if (offset >= size) return(false); 0 5447 5447
1209  
1210 5447 *(addr+size-1) &= mask;
1211  
1212 5447 addr += offset;
1213 5447 size = ++offset;
1214  
1215 5447 bitmask = BV_BitMaskTab[start AND BV_ModMask];
1216 5447 mask = (bitmask - 1);
1217  
1218 5447 value = *addr--;
1219 5447 ▶ if ((value AND bitmask) == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((value AND bitmask) == 0) 2902 2545 5447
1220 {
1221 2902 value &= mask;
1222 2902 ▶ if (value == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (value == 0) 2409 493 2902
1223 {
1224 2409 offset--;
1225 2409 empty = true;
1226 158808 ▶ while (empty and (--size > 0))
Branch: 2 branches
BranchTrueFalseTotal
while (empty and (--size > 0)) 156479 2329 158808
while (empty and (--size > 0)) 156399 80 156479
1227 {
1228 156399 ▶ if ((value = *addr--)) empty = false; else offset--;
Branch: 1 branch
BranchTrueFalseTotal
if ((value = *addr--)) empty = false; else offset--; 2329 154070 156399
1229 }
1230 2409 ▶ if (empty) return(false);
Branch: 1 branch
BranchTrueFalseTotal
if (empty) return(false); 80 2329 2409
1231 }
1232 2822 start = offset << BV_LogBits;
1233 2822 bitmask = BV_MSB;
1234 2822 mask = value;
1235 93116 ▶ while (not (mask AND BV_MSB))
Branch: 1 branch
BranchTrueFalseTotal
while (not (mask AND BV_MSB)) 90294 2822 93116
1236 {
1237 90294 bitmask >>= 1;
1238 90294 mask <<= 1;
1239 90294 start--;
1240 }
1241 2822 mask = (bitmask - 1);
1242 2822 *max = --start;
1243 2822 *min = start;
1244 }
1245 5367 value = NOT value;
1246 5367 value &= mask;
1247 5367 ▶ if (value == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (value == 0) 4604 763 5367
1248 {
1249 4604 offset--;
1250 4604 empty = true;
1251 37659 ▶ while (empty and (--size > 0))
Branch: 2 branches
BranchTrueFalseTotal
while (empty and (--size > 0)) 35602 2057 37659
while (empty and (--size > 0)) 33055 2547 35602
1252 {
1253 33055 ▶ if ((value = NOT *addr--)) empty = false; else offset--;
Branch: 1 branch
BranchTrueFalseTotal
if ((value = NOT *addr--)) empty = false; else offset--; 2057 30998 33055
1254 }
1255 4604 ▶ if (empty) value = BV_MSB;
Branch: 1 branch
BranchTrueFalseTotal
if (empty) value = BV_MSB; 2547 2057 4604
1256 }
1257 5367 start = offset << BV_LogBits;
1258 96322 ▶ while (not (value AND BV_MSB))
Branch: 1 branch
BranchTrueFalseTotal
while (not (value AND BV_MSB)) 90955 5367 96322
1259 {
1260 90955 value <<= 1;
1261 90955 start--;
1262 }
1263 5367 *min = start;
1264 5367 return(true);
1265 }
1266  
1267 10114 void BitVector_Interval_Copy(wordptr X, wordptr Y, N_int Xoffset,
1268 N_int Yoffset, N_int length)
1269 {
1270 10114 N_word bitsX = BV_BITS_(X);
1271 10114 N_word bitsY = BV_BITS_(Y);
1272 10114 N_word source = 0; /* silence compiler warning */
1273 10114 N_word target = 0; /* silence compiler warning */
1274 N_word s_lo_base;
1275 N_word s_hi_base;
1276 N_word s_lo_bit;
1277 N_word s_hi_bit;
1278 N_word s_base;
1279 10114 N_word s_lower = 0; /* silence compiler warning */
1280 10114 N_word s_upper = 0; /* silence compiler warning */
1281 N_word s_bits;
1282 N_word s_min;
1283 N_word s_max;
1284 N_word t_lo_base;
1285 N_word t_hi_base;
1286 N_word t_lo_bit;
1287 N_word t_hi_bit;
1288 N_word t_base;
1289 10114 N_word t_lower = 0; /* silence compiler warning */
1290 10114 N_word t_upper = 0; /* silence compiler warning */
1291 N_word t_bits;
1292 N_word t_min;
1293 N_word mask;
1294 N_word bits;
1295 N_word select;
1296 boolean ascending;
1297 boolean notfirst;
1298 10114 wordptr Z = X;
1299  
1300 10114 ▶ if ((length > 0) and (Xoffset < bitsX) and (Yoffset < bitsY))
Branch: 3 branches
BranchTrueFalseTotal
if ((length > 0) and (Xoffset < bitsX) and (Yoffset < bitsY)) 10114 0 10114
if ((length > 0) and (Xoffset < bitsX) and (Yoffset < bitsY)) 10114 0 10114
if ((length > 0) and (Xoffset < bitsX) and (Yoffset < bitsY)) 10114 0 10114
1301 {
1302 10114 ▶ if ((Xoffset + length) > bitsX) length = bitsX - Xoffset;
Branch: 1 branch
BranchTrueFalseTotal
if ((Xoffset + length) > bitsX) length = bitsX - Xoffset; 2 10112 10114
1303 10114 ▶ if ((Yoffset + length) > bitsY) length = bitsY - Yoffset;
Branch: 1 branch
BranchTrueFalseTotal
if ((Yoffset + length) > bitsY) length = bitsY - Yoffset; 0 10114 10114
1304  
1305 10114 ascending = (Xoffset <= Yoffset);
1306  
1307 10114 s_lo_base = Yoffset >> BV_LogBits;
1308 10114 s_lo_bit = Yoffset AND BV_ModMask;
1309 10114 Yoffset += --length;
1310 10114 s_hi_base = Yoffset >> BV_LogBits;
1311 10114 s_hi_bit = Yoffset AND BV_ModMask;
1312  
1313 10114 t_lo_base = Xoffset >> BV_LogBits;
1314 10114 t_lo_bit = Xoffset AND BV_ModMask;
1315 10114 Xoffset += length;
1316 10114 t_hi_base = Xoffset >> BV_LogBits;
1317 10114 t_hi_bit = Xoffset AND BV_ModMask;
1318  
1319 10114 ▶ if (ascending)
Branch: 1 branch
BranchTrueFalseTotal
if (ascending) 5054 5060 10114
1320 {
1321 5054 s_base = s_lo_base;
1322 5054 t_base = t_lo_base;
1323 }
1324 else
1325 {
1326 5060 s_base = s_hi_base;
1327 5060 t_base = t_hi_base;
1328 }
1329 10114 s_bits = 0;
1330 10114 t_bits = 0;
1331 10114 Y += s_base;
1332 10114 X += t_base;
1333 10114 notfirst = false;
1334 while (true)
1335 {
1336 144320 ▶ if (t_bits == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (t_bits == 0) 82820 61500 144320
1337 {
1338 82820 ▶ if (notfirst)
Branch: 1 branch
BranchTrueFalseTotal
if (notfirst) 72706 10114 82820
1339 {
1340 72706 *X = target;
1341 72706 ▶ if (ascending)
Branch: 1 branch
BranchTrueFalseTotal
if (ascending) 36272 36434 72706
1342 {
1343 36272 ▶ if (t_base == t_hi_base) break;
Branch: 1 branch
BranchTrueFalseTotal
if (t_base == t_hi_base) break; 5054 31218 36272
1344 31218 t_base++;
1345 31218 X++;
1346 }
1347 else
1348 {
1349 36434 ▶ if (t_base == t_lo_base) break;
Branch: 1 branch
BranchTrueFalseTotal
if (t_base == t_lo_base) break; 5060 31374 36434
1350 31374 t_base--;
1351 31374 X--;
1352 }
1353 }
1354 72706 ▶ select = ((t_base == t_hi_base) << 1) OR (t_base == t_lo_base);
Branch: 1 branch
BranchTrueFalseTotal
select = ((t_base == t_hi_base) << 1) OR (t_base == t_lo_base); 10114 62592 72706
1355 72706 switch (select)
1356 {
1357 54360 case 0:
1358 54360 t_lower = 0;
1359 54360 t_upper = BV_WordBits - 1;
1360 54360 t_bits = BV_WordBits;
1361 54360 target = 0;
1362 54360 break;
1363 8232 case 1:
1364 8232 t_lower = t_lo_bit;
1365 8232 t_upper = BV_WordBits - 1;
1366 8232 t_bits = BV_WordBits - t_lo_bit;
1367 8232 mask = (N_word) (~0L << t_lower);
1368 8232 target = *X AND NOT mask;
1369 8232 break;
1370 8232 case 2:
1371 8232 t_lower = 0;
1372 8232 t_upper = t_hi_bit;
1373 8232 t_bits = t_hi_bit + 1;
1374 8232 mask = (N_word) ((~0L << t_upper) << 1);
1375 8232 target = *X AND mask;
1376 8232 break;
1377 1882 case 3:
1378 1882 t_lower = t_lo_bit;
1379 1882 t_upper = t_hi_bit;
1380 1882 t_bits = t_hi_bit - t_lo_bit + 1;
1381 1882 mask = (N_word) (~0L << t_lower);
1382 1882 mask &= (N_word) ~((~0L << t_upper) << 1);
1383 1882 target = *X AND NOT mask;
1384 1882 break;
1385 }
1386 }
1387 134206 ▶ if (s_bits == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (s_bits == 0) 72706 61500 134206
1388 {
1389 72706 ▶ if (notfirst)
Branch: 1 branch
BranchTrueFalseTotal
if (notfirst) 62592 10114 72706
1390 {
1391 62592 ▶ if (ascending)
Branch: 1 branch
BranchTrueFalseTotal
if (ascending) 31254 31338 62592
1392 {
1393 31254 ▶ if (s_base == s_hi_base) break;
Branch: 1 branch
BranchTrueFalseTotal
if (s_base == s_hi_base) break; 0 31254 31254
1394 31254 s_base++;
1395 31254 Y++;
1396 }
1397 else
1398 {
1399 31338 ▶ if (s_base == s_lo_base) break;
Branch: 1 branch
BranchTrueFalseTotal
if (s_base == s_lo_base) break; 0 31338 31338
1400 31338 s_base--;
1401 31338 Y--;
1402 }
1403 }
1404 72706 source = *Y;
1405 72706 ▶ select = ((s_base == s_hi_base) << 1) OR (s_base == s_lo_base);
Branch: 1 branch
BranchTrueFalseTotal
select = ((s_base == s_hi_base) << 1) OR (s_base == s_lo_base); 10114 62592 72706
1406 72706 switch (select)
1407 {
1408 54360 case 0:
1409 54360 s_lower = 0;
1410 54360 s_upper = BV_WordBits - 1;
1411 54360 s_bits = BV_WordBits;
1412 54360 break;
1413 8232 case 1:
1414 8232 s_lower = s_lo_bit;
1415 8232 s_upper = BV_WordBits - 1;
1416 8232 s_bits = BV_WordBits - s_lo_bit;
1417 8232 break;
1418 8232 case 2:
1419 8232 s_lower = 0;
1420 8232 s_upper = s_hi_bit;
1421 8232 s_bits = s_hi_bit + 1;
1422 8232 break;
1423 1882 case 3:
1424 1882 s_lower = s_lo_bit;
1425 1882 s_upper = s_hi_bit;
1426 1882 s_bits = s_hi_bit - s_lo_bit + 1;
1427 1882 break;
1428 }
1429 }
1430 134206 notfirst = true;
1431 134206 ▶ if (s_bits > t_bits)
Branch: 1 branch
BranchTrueFalseTotal
if (s_bits > t_bits) 61500 72706 134206
1432 {
1433 61500 bits = t_bits - 1;
1434 61500 ▶ if (ascending)
Branch: 1 branch
BranchTrueFalseTotal
if (ascending) 30732 30768 61500
1435 {
1436 30732 s_min = s_lower;
1437 30732 s_max = s_lower + bits;
1438 }
1439 else
1440 {
1441 30768 s_max = s_upper;
1442 30768 s_min = s_upper - bits;
1443 }
1444 61500 t_min = t_lower;
1445 }
1446 else
1447 {
1448 72706 bits = s_bits - 1;
1449 72706 ▶ if (ascending) t_min = t_lower;
Branch: 1 branch
BranchTrueFalseTotal
if (ascending) t_min = t_lower; 36308 36398 72706
1450 36398 else t_min = t_upper - bits;
1451 72706 s_min = s_lower;
1452 72706 s_max = s_upper;
1453 }
1454 134206 bits++;
1455 134206 mask = (N_word) (~0L << s_min);
1456 134206 mask &= (N_word) ~((~0L << s_max) << 1);
1457 134206 ▶ if (s_min == t_min) target |= (source AND mask);
Branch: 1 branch
BranchTrueFalseTotal
if (s_min == t_min) target |= (source AND mask); 1242 132964 134206
1458 else
1459 {
1460 132964 ▶ if (s_min < t_min) target |= (source AND mask) << (t_min-s_min);
Branch: 1 branch
BranchTrueFalseTotal
if (s_min < t_min) target |= (source AND mask) << (t_min-s_min); 66482 66482 132964
1461 66482 else target |= (source AND mask) >> (s_min-t_min);
1462 }
1463 134206 ▶ if (ascending)
Branch: 1 branch
BranchTrueFalseTotal
if (ascending) 67040 67166 134206
1464 {
1465 67040 s_lower += bits;
1466 67040 t_lower += bits;
1467 }
1468 else
1469 {
1470 67166 s_upper -= bits;
1471 67166 t_upper -= bits;
1472 }
1473 134206 s_bits -= bits;
1474 134206 t_bits -= bits;
1475 }
1476 10114 *(Z+BV_SIZE_(Z)-1) &= BV_MASK_(Z);
1477 }
1478 10114 }
1479  
1480  
1481 2 wordptr BitVector_Interval_Substitute(wordptr X, wordptr Y,
1482 N_int Xoffset, N_int Xlength,
1483 N_int Yoffset, N_int Ylength)
1484 {
1485 2 N_word Xbits = BV_BITS_(X);
1486 2 N_word Ybits = BV_BITS_(Y);
1487 N_word limit;
1488 N_word diff;
1489  
1490 2 ▶ if ((Xoffset <= Xbits) and (Yoffset <= Ybits))
Branch: 2 branches
BranchTrueFalseTotal
if ((Xoffset <= Xbits) and (Yoffset <= Ybits)) 2 0 2
if ((Xoffset <= Xbits) and (Yoffset <= Ybits)) 2 0 2
1491 {
1492 2 limit = Xoffset + Xlength;
1493 2 ▶ if (limit > Xbits)
Branch: 1 branch
BranchTrueFalseTotal
if (limit > Xbits) 2 0 2
1494 {
1495 2 limit = Xbits;
1496 2 Xlength = Xbits - Xoffset;
1497 }
1498 2 ▶ if ((Yoffset + Ylength) > Ybits)
Branch: 1 branch
BranchTrueFalseTotal
if ((Yoffset + Ylength) > Ybits) 2 0 2
1499 {
1500 2 Ylength = Ybits - Yoffset;
1501 }
1502 2 ▶ if (Xlength == Ylength)
Branch: 1 branch
BranchTrueFalseTotal
if (Xlength == Ylength) 2 0 2
1503 {
1504 2 ▶ if ((Ylength > 0) and ((X != Y) or (Xoffset != Yoffset)))
Branch: 3 branches
BranchTrueFalseTotal
if ((Ylength > 0) and ((X != Y) or (Xoffset != Yoffset))) 0 2 2
if ((Ylength > 0) and ((X != Y) or (Xoffset != Yoffset))) 0 0 0
if ((Ylength > 0) and ((X != Y) or (Xoffset != Yoffset))) 0 0 0
1505 {
1506 0 BitVector_Interval_Copy(X,Y,Xoffset,Yoffset,Ylength);
1507 }
1508 }
1509 else /* Xlength != Ylength */
1510 {
1511 0 ▶ if (Xlength > Ylength)
Branch: 1 branch
BranchTrueFalseTotal
if (Xlength > Ylength) 0 0 0
1512 {
1513 0 diff = Xlength - Ylength;
1514 0 ▶ if (Ylength > 0) BitVector_Interval_Copy(X,Y,Xoffset,Yoffset,Ylength);
Branch: 1 branch
BranchTrueFalseTotal
if (Ylength > 0) BitVector_Interval_Copy(X,Y,Xoffset,Yoffset,Ylength); 0 0 0
1515 0 ▶ if (limit < Xbits) BitVector_Delete(X,Xoffset+Ylength,diff,false);
Branch: 1 branch
BranchTrueFalseTotal
if (limit < Xbits) BitVector_Delete(X,Xoffset+Ylength,diff,false); 0 0 0
1516 0 ▶ if ((X = BitVector_Resize(X,Xbits-diff)) == NULL) return(NULL);
Branch: 1 branch
BranchTrueFalseTotal
if ((X = BitVector_Resize(X,Xbits-diff)) == NULL) return(NULL); 0 0 0
1517 }
1518 else /* Ylength > Xlength ==> Ylength > 0 */
1519 {
1520 0 diff = Ylength - Xlength;
1521 0 ▶ if (X != Y)
Branch: 1 branch
BranchTrueFalseTotal
if (X != Y) 0 0 0
1522 {
1523 0 ▶ if ((X = BitVector_Resize(X,Xbits+diff)) == NULL) return(NULL);
Branch: 1 branch
BranchTrueFalseTotal
if ((X = BitVector_Resize(X,Xbits+diff)) == NULL) return(NULL); 0 0 0
1524 0 ▶ if (limit < Xbits) BitVector_Insert(X,limit,diff,false);
Branch: 1 branch
BranchTrueFalseTotal
if (limit < Xbits) BitVector_Insert(X,limit,diff,false); 0 0 0
1525 0 BitVector_Interval_Copy(X,Y,Xoffset,Yoffset,Ylength);
1526 }
1527 else /* in-place */
1528 {
1529 0 ▶ if ((Y = X = BitVector_Resize(X,Xbits+diff)) == NULL) return(NULL);
Branch: 1 branch
BranchTrueFalseTotal
if ((Y = X = BitVector_Resize(X,Xbits+diff)) == NULL) return(NULL); 0 0 0
1530 0 ▶ if (limit >= Xbits)
Branch: 1 branch
BranchTrueFalseTotal
if (limit >= Xbits) 0 0 0
1531 {
1532 0 BitVector_Interval_Copy(X,Y,Xoffset,Yoffset,Ylength);
1533 }
1534 else /* limit < Xbits */
1535 {
1536 0 BitVector_Insert(X,limit,diff,false);
1537 0 ▶ if ((Yoffset+Ylength) <= limit)
Branch: 1 branch
BranchTrueFalseTotal
if ((Yoffset+Ylength) <= limit) 0 0 0
1538 {
1539 0 BitVector_Interval_Copy(X,Y,Xoffset,Yoffset,Ylength);
1540 }
1541 else /* overlaps or lies above critical area */
1542 {
1543 0 ▶ if (limit <= Yoffset)
Branch: 1 branch
BranchTrueFalseTotal
if (limit <= Yoffset) 0 0 0
1544 {
1545 0 Yoffset += diff;
1546 0 BitVector_Interval_Copy(X,Y,Xoffset,Yoffset,Ylength);
1547 }
1548 else /* Yoffset < limit */
1549 {
1550 0 Xlength = limit - Yoffset;
1551 0 BitVector_Interval_Copy(X,Y,Xoffset,Yoffset,Xlength);
1552 0 Yoffset = Xoffset + Ylength; /* = limit + diff */
1553 0 Xoffset += Xlength;
1554 0 Ylength -= Xlength;
1555 0 BitVector_Interval_Copy(X,Y,Xoffset,Yoffset,Ylength);
1556 }
1557 }
1558 }
1559 }
1560 }
1561 }
1562 }
1563 2 return(X);
1564 }
1565  
1566 4974 boolean BitVector_is_empty(wordptr addr) /* X == {} ? */
1567 {
1568 4974 N_word size = BV_SIZE_(addr);
1569 4974 boolean r = true;
1570  
1571 4974 ▶ if (size > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (size > 0) 4974 0 4974
1572 {
1573 4974 *(addr+size-1) &= BV_MASK_(addr);
1574 13775 ▶ while (r and (size-- > 0)) r = ( *addr++ == 0 );
Branch: 2 branches
BranchTrueFalseTotal
while (r and (size-- > 0)) r = ( *addr++ == 0 ); 9774 4001 13775
while (r and (size-- > 0)) r = ( *addr++ == 0 ); 8801 973 9774
1575 }
1576 4974 return(r);
1577 }
1578  
1579 22 boolean BitVector_is_full(wordptr addr) /* X == ~{} ? */
1580 {
1581 22 N_word size = BV_SIZE_(addr);
1582 22 N_word mask = BV_MASK_(addr);
1583 22 boolean r = false;
1584 wordptr last;
1585  
1586 22 ▶ if (size > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (size > 0) 22 0 22
1587 {
1588 22 r = true;
1589 22 last = addr + size - 1;
1590 22 *last |= NOT mask;
1591 683 ▶ while (r and (size-- > 0)) r = ( NOT *addr++ == 0 );
Branch: 2 branches
BranchTrueFalseTotal
while (r and (size-- > 0)) r = ( NOT *addr++ == 0 ); 668 15 683
while (r and (size-- > 0)) r = ( NOT *addr++ == 0 ); 661 7 668
1592 22 *last &= mask;
1593 }
1594 22 return(r);
1595 }
1596  
1597 23992 boolean BitVector_equal(wordptr X, wordptr Y) /* X == Y ? */
1598 {
1599 23992 N_word size = BV_SIZE_(X);
1600 23992 N_word mask = BV_MASK_(X);
1601 23992 boolean r = false;
1602  
1603 23992 ▶ if (BV_BITS_(X) == BV_BITS_(Y))
Branch: 1 branch
BranchTrueFalseTotal
if (BV_BITS_(X) == BV_BITS_(Y)) 23992 0 23992
1604 {
1605 23992 r = true;
1606 23992 ▶ if (size > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (size > 0) 23988 4 23992
1607 {
1608 23988 *(X+size-1) &= mask;
1609 23988 *(Y+size-1) &= mask;
1610 410372 ▶ while (r and (size-- > 0)) r = (*X++ == *Y++);
Branch: 2 branches
BranchTrueFalseTotal
while (r and (size-- > 0)) r = (*X++ == *Y++); 408175 2197 410372
while (r and (size-- > 0)) r = (*X++ == *Y++); 386384 21791 408175
1611 }
1612 }
1613 23992 return(r);
1614 }
1615  
1616 48 Z_int BitVector_Lexicompare(wordptr X, wordptr Y) /* X <,=,> Y ? */
1617 { /* unsigned */
1618 48 N_word bitsX = BV_BITS_(X);
1619 48 N_word bitsY = BV_BITS_(Y);
1620 48 N_word size = BV_SIZE_(X);
1621 48 boolean r = true;
1622  
1623 48 ▶ if (bitsX == bitsY)
Branch: 1 branch
BranchTrueFalseTotal
if (bitsX == bitsY) 48 0 48
1624 {
1625 48 ▶ if (size > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (size > 0) 48 0 48
1626 {
1627 48 X += size;
1628 48 Y += size;
1629 13530 ▶ while (r and (size-- > 0)) r = (*(--X) == *(--Y));
Branch: 2 branches
BranchTrueFalseTotal
while (r and (size-- > 0)) r = (*(--X) == *(--Y)); 13496 34 13530
while (r and (size-- > 0)) r = (*(--X) == *(--Y)); 13482 14 13496
1630 }
1631 48 ▶ if (r) return((Z_int) 0);
Branch: 1 branch
BranchTrueFalseTotal
if (r) return((Z_int) 0); 14 34 48
1632 else
1633 {
1634 34 ▶ if (*X < *Y) return((Z_int) -1); else return((Z_int) 1);
Branch: 1 branch
BranchTrueFalseTotal
if (*X < *Y) return((Z_int) -1); else return((Z_int) 1); 18 16 34
1635 }
1636 }
1637 else
1638 {
1639 0 ▶ if (bitsX < bitsY) return((Z_int) -1); else return((Z_int) 1);
Branch: 1 branch
BranchTrueFalseTotal
if (bitsX < bitsY) return((Z_int) -1); else return((Z_int) 1); 0 0 0
1640 }
1641 }
1642  
1643 27 Z_int BitVector_Compare(wordptr X, wordptr Y) /* X <,=,> Y ? */
1644 { /* signed */
1645 27 N_word bitsX = BV_BITS_(X);
1646 27 N_word bitsY = BV_BITS_(Y);
1647 27 N_word size = BV_SIZE_(X);
1648 27 N_word mask = BV_MASK_(X);
1649 N_word sign;
1650 27 boolean r = true;
1651  
1652 27 ▶ if (bitsX == bitsY)
Branch: 1 branch
BranchTrueFalseTotal
if (bitsX == bitsY) 27 0 27
1653 {
1654 27 ▶ if (size > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (size > 0) 27 0 27
1655 {
1656 27 X += size;
1657 27 Y += size;
1658 27 mask &= NOT (mask >> 1);
1659 27 ▶ if ((sign = (*(X-1) AND mask)) != (*(Y-1) AND mask))
Branch: 1 branch
BranchTrueFalseTotal
if ((sign = (*(X-1) AND mask)) != (*(Y-1) AND mask)) 12 15 27
1660 {
1661 12 ▶ if (sign) return((Z_int) -1); else return((Z_int) 1);
Branch: 1 branch
BranchTrueFalseTotal
if (sign) return((Z_int) -1); else return((Z_int) 1); 6 6 12
1662 }
1663 13359 ▶ while (r and (size-- > 0)) r = (*(--X) == *(--Y));
Branch: 2 branches
BranchTrueFalseTotal
while (r and (size-- > 0)) r = (*(--X) == *(--Y)); 13351 8 13359
while (r and (size-- > 0)) r = (*(--X) == *(--Y)); 13344 7 13351
1664 }
1665 15 ▶ if (r) return((Z_int) 0);
Branch: 1 branch
BranchTrueFalseTotal
if (r) return((Z_int) 0); 7 8 15
1666 else
1667 {
1668 8 ▶ if (*X < *Y) return((Z_int) -1); else return((Z_int) 1);
Branch: 1 branch
BranchTrueFalseTotal
if (*X < *Y) return((Z_int) -1); else return((Z_int) 1); 4 4 8
1669 }
1670 }
1671 else
1672 {
1673 0 ▶ if (bitsX < bitsY) return((Z_int) -1); else return((Z_int) 1);
Branch: 1 branch
BranchTrueFalseTotal
if (bitsX < bitsY) return((Z_int) -1); else return((Z_int) 1); 0 0 0
1674 }
1675 }
1676  
1677 252 charptr BitVector_to_Hex(wordptr addr)
1678 {
1679 252 N_word bits = BV_BITS_(addr);
1680 252 N_word size = BV_SIZE_(addr);
1681 N_word value;
1682 N_word count;
1683 N_word digit;
1684 N_word length;
1685 charptr string;
1686  
1687 252 length = bits >> 2;
1688 252 ▶ if (bits AND 0x0003) length++;
Branch: 1 branch
BranchTrueFalseTotal
if (bits AND 0x0003) length++; 178 74 252
1689 252 string = (charptr) malloc((size_t) (length+1));
1690 252 ▶ if (string == NULL) return(NULL);
Branch: 1 branch
BranchTrueFalseTotal
if (string == NULL) return(NULL); 0 252 252
1691 252 string += length;
1692 252 *string = (N_char) '\0';
1693 252 ▶ if (size > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (size > 0) 251 1 252
1694 {
1695 251 *(addr+size-1) &= BV_MASK_(addr);
1696 1192 ▶ while ((size-- > 0) and (length > 0))
Branch: 2 branches
BranchTrueFalseTotal
while ((size-- > 0) and (length > 0)) 941 251 1192
while ((size-- > 0) and (length > 0)) 941 0 941
1697 {
1698 941 value = *addr++;
1699 941 count = BV_WordBits >> 2;
1700 14317 ▶ while ((count-- > 0) and (length > 0))
Branch: 2 branches
BranchTrueFalseTotal
while ((count-- > 0) and (length > 0)) 13568 749 14317
while ((count-- > 0) and (length > 0)) 13376 192 13568
1701 {
1702 13376 digit = value AND 0x000F;
1703 13376 ▶ if (digit > 9) digit += (N_word) 'A' - 10;
Branch: 1 branch
BranchTrueFalseTotal
if (digit > 9) digit += (N_word) 'A' - 10; 6035 7341 13376
1704 7341 else digit += (N_word) '0';
1705 13376 *(--string) = (N_char) digit; length--;
1706 13376 ▶ if ((count > 0) and (length > 0)) value >>= 4;
Branch: 2 branches
BranchTrueFalseTotal
if ((count > 0) and (length > 0)) value >>= 4; 12627 749 13376
if ((count > 0) and (length > 0)) value >>= 4; 12435 192 12627
1707 }
1708 }
1709 }
1710 252 return(string);
1711 }
1712  
1713 3122 BV_ErrCode BitVector_from_Hex(wordptr addr, charptr string)
1714 {
1715 3122 N_word size = BV_SIZE_(addr);
1716 3122 N_word mask = BV_MASK_(addr);
1717 3122 boolean ok = true;
1718 N_word length;
1719 N_word value;
1720 N_word count;
1721 int digit;
1722  
1723 3122 ▶ if (size > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (size > 0) 3122 0 3122
1724 {
1725 3122 length = strlen((char *) string);
1726 3122 string += length;
1727 12855 ▶ while (size-- > 0)
Branch: 1 branch
BranchTrueFalseTotal
while (size-- > 0) 9733 3122 12855
1728 {
1729 9733 value = 0;
1730 146069 ▶ for ( count = 0; (ok and (length > 0) and (count < BV_WordBits)); count += 4 )
Branch: 3 branches
BranchTrueFalseTotal
for ( count = 0; (ok and (length > 0) and (count < BV_WordBits)); count += 4 ) 146061 8 146069
for ( count = 0; (ok and (length > 0) and (count < BV_WordBits)); count += 4 ) 142889 3172 146061
for ( count = 0; (ok and (length > 0) and (count < BV_WordBits)); count += 4 ) 136336 6553 142889
1731 {
1732 136336 digit = (int) *(--string); length--;
1733 /* separate because toupper() is likely a macro! */
1734 136336 digit = toupper(digit);
1735 136336 ▶ if ((ok = (isxdigit(digit) != 0)))
Branch: 1 branch
BranchTrueFalseTotal
if ((ok = (isxdigit(digit) != 0))) 136331 5 136336
1736 {
1737 136331 ▶ if (digit >= (int) 'A') digit -= (int) 'A' - 10;
Branch: 1 branch
BranchTrueFalseTotal
if (digit >= (int) 'A') digit -= (int) 'A' - 10; 54926 81405 136331
1738 81405 else digit -= (int) '0';
1739 136331 value |= (((N_word) digit) << count);
1740 }
1741 }
1742 9733 *addr++ = value;
1743 }
1744 3122 *(--addr) &= mask;
1745 }
1746 3122 ▶ if (ok) return(BV_ErrCode_Ok);
Branch: 1 branch
BranchTrueFalseTotal
if (ok) return(BV_ErrCode_Ok); 3117 5 3122
1747 5 else return(BV_ErrCode_Pars);
1748 }
1749  
1750 109 charptr BitVector_to_Bin(wordptr addr)
1751 {
1752 109 N_word size = BV_SIZE_(addr);
1753 N_word value;
1754 N_word count;
1755 N_word digit;
1756 N_word length;
1757 charptr string;
1758  
1759 109 length = BV_BITS_(addr);
1760 109 string = (charptr) malloc((size_t) (length+1));
1761 109 ▶ if (string == NULL) return(NULL);
Branch: 1 branch
BranchTrueFalseTotal
if (string == NULL) return(NULL); 0 109 109
1762 109 string += length;
1763 109 *string = (N_char) '\0';
1764 109 ▶ if (size > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (size > 0) 109 0 109
1765 {
1766 109 *(addr+size-1) &= BV_MASK_(addr);
1767 833 ▶ while (size-- > 0)
Branch: 1 branch
BranchTrueFalseTotal
while (size-- > 0) 724 109 833
1768 {
1769 724 value = *addr++;
1770 724 count = BV_WordBits;
1771 724 ▶ if (count > length) count = length;
Branch: 1 branch
BranchTrueFalseTotal
if (count > length) count = length; 84 640 724
1772 44372 ▶ while (count-- > 0)
Branch: 1 branch
BranchTrueFalseTotal
while (count-- > 0) 43648 724 44372
1773 {
1774 43648 digit = value AND 0x0001;
1775 43648 digit += (N_word) '0';
1776 43648 *(--string) = (N_char) digit; length--;
1777 43648 ▶ if (count > 0) value >>= 1;
Branch: 1 branch
BranchTrueFalseTotal
if (count > 0) value >>= 1; 42924 724 43648
1778 }
1779 }
1780 }
1781 109 return(string);
1782 }
1783  
1784 110 BV_ErrCode BitVector_from_Bin(wordptr addr, charptr string)
1785 {
1786 110 N_word size = BV_SIZE_(addr);
1787 110 N_word mask = BV_MASK_(addr);
1788 110 boolean ok = true;
1789 N_word length;
1790 N_word value;
1791 N_word count;
1792 int digit;
1793  
1794 110 ▶ if (size > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (size > 0) 110 0 110
1795 {
1796 110 length = strlen((char *) string);
1797 110 string += length;
1798 867 ▶ while (size-- > 0)
Branch: 1 branch
BranchTrueFalseTotal
while (size-- > 0) 757 110 867
1799 {
1800 757 value = 0;
1801 43389 ▶ for ( count = 0; (ok and (length > 0) and (count < BV_WordBits)); count++ )
Branch: 3 branches
BranchTrueFalseTotal
for ( count = 0; (ok and (length > 0) and (count < BV_WordBits)); count++ ) 43389 0 43389
for ( count = 0; (ok and (length > 0) and (count < BV_WordBits)); count++ ) 43232 157 43389
for ( count = 0; (ok and (length > 0) and (count < BV_WordBits)); count++ ) 42632 600 43232
1802 {
1803 42632 digit = (int) *(--string); length--;
1804 42632 switch (digit)
1805 {
1806 24658 case (int) '0':
1807 24658 break;
1808 17974 case (int) '1':
1809 17974 value |= BV_BitMaskTab[count];
1810 17974 break;
1811 0 default:
1812 0 ok = false;
1813 0 break;
1814 }
1815 }
1816 757 *addr++ = value;
1817 }
1818 110 *(--addr) &= mask;
1819 }
1820 110 ▶ if (ok) return(BV_ErrCode_Ok);
Branch: 1 branch
BranchTrueFalseTotal
if (ok) return(BV_ErrCode_Ok); 110 0 110
1821 0 else return(BV_ErrCode_Pars);
1822 }
1823  
1824 802 charptr BitVector_to_Dec(wordptr addr)
1825 {
1826 802 N_word bits = BV_BITS_(addr);
1827 N_word length;
1828 N_word digits;
1829 N_word count;
1830 N_word q;
1831 N_word r;
1832 boolean loop;
1833 charptr result;
1834 charptr string;
1835 wordptr quot;
1836 wordptr rest;
1837 wordptr temp;
1838 wordptr base;
1839 Z_int sign;
1840  
1841 802 length = (N_word) (bits / 3.3); /* digits = bits * ln(2) / ln(10) */
1842 802 length += 2; /* compensate for truncating & provide space for minus sign */
1843 802 result = (charptr) malloc((size_t) (length+1)); /* remember the '\0'! */
1844 802 ▶ if (result == NULL) return(NULL);
Branch: 1 branch
BranchTrueFalseTotal
if (result == NULL) return(NULL); 0 802 802
1845 802 string = result;
1846 802 sign = BitVector_Sign(addr);
1847 802 ▶ if ((bits < 4) or (sign == 0))
Branch: 2 branches
BranchTrueFalseTotal
if ((bits < 4) or (sign == 0)) 802 0 802
if ((bits < 4) or (sign == 0)) 76 726 802
1848 {
1849 76 ▶ if (bits > 0) digits = *addr; else digits = (N_word) 0;
Branch: 1 branch
BranchTrueFalseTotal
if (bits > 0) digits = *addr; else digits = (N_word) 0; 76 0 76
1850 76 ▶ if (sign < 0) digits = ((N_word)(-((Z_word)digits))) AND BV_MASK_(addr);
Branch: 1 branch
BranchTrueFalseTotal
if (sign < 0) digits = ((N_word)(-((Z_word)digits))) AND BV_MASK_(addr); 0 76 76
1851 76 *string++ = (N_char) digits + (N_char) '0';
1852 76 digits = 1;
1853 }
1854 else
1855 {
1856 726 quot = BitVector_Create(bits,false);
1857 726 ▶ if (quot == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (quot == NULL) 0 726 726
1858 {
1859 0 BitVector_Dispose(result);
1860 0 return(NULL);
1861 }
1862 726 rest = BitVector_Create(bits,false);
1863 726 ▶ if (rest == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (rest == NULL) 0 726 726
1864 {
1865 0 BitVector_Dispose(result);
1866 0 BitVector_Destroy(quot);
1867 0 return(NULL);
1868 }
1869 726 temp = BitVector_Create(bits,false);
1870 726 ▶ if (temp == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (temp == NULL) 0 726 726
1871 {
1872 0 BitVector_Dispose(result);
1873 0 BitVector_Destroy(quot);
1874 0 BitVector_Destroy(rest);
1875 0 return(NULL);
1876 }
1877 726 base = BitVector_Create(bits,true);
1878 726 ▶ if (base == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (base == NULL) 0 726 726
1879 {
1880 0 BitVector_Dispose(result);
1881 0 BitVector_Destroy(quot);
1882 0 BitVector_Destroy(rest);
1883 0 BitVector_Destroy(temp);
1884 0 return(NULL);
1885 }
1886 726 ▶ if (sign < 0) BitVector_Negate(quot,addr);
Branch: 1 branch
BranchTrueFalseTotal
if (sign < 0) BitVector_Negate(quot,addr); 314 412 726
1887 412 else BitVector_Copy(quot,addr);
1888 726 digits = 0;
1889 726 *base = BV_Exp10;
1890 726 loop = (bits >= BV_WordBits);
1891 do
1892 {
1893 1178 ▶ if (loop)
Branch: 1 branch
BranchTrueFalseTotal
if (loop) 1142 36 1178
1894 {
1895 1142 BitVector_Copy(temp,quot);
1896 1142 ▶ if (BitVector_Div_Pos(quot,temp,base,rest))
Branch: 1 branch
BranchTrueFalseTotal
if (BitVector_Div_Pos(quot,temp,base,rest)) 0 1142 1142
1897 {
1898 0 BitVector_Dispose(result); /* emergency exit */
1899 0 BitVector_Destroy(quot);
1900 0 BitVector_Destroy(rest); /* should never occur */
1901 0 BitVector_Destroy(temp); /* under normal operation */
1902 0 BitVector_Destroy(base);
1903 0 return(NULL);
1904 }
1905 1142 loop = not BitVector_is_empty(quot);
1906 1142 q = *rest;
1907 }
1908 36 else q = *quot;
1909 1178 count = BV_Log10;
1910 10662 ▶ while (((loop and (count-- > 0)) or ((not loop) and (q != 0))) and
Branch: 5 branches
BranchTrueFalseTotal
while (((loop and (count-- > 0)) or ((not loop) and (q != 0))) and 8588 2074 10662
while (((loop and (count-- > 0)) or ((not loop) and (q != 0))) and 452 8136 8588
while (((loop and (count-- > 0)) or ((not loop) and (q != 0))) and 2074 452 2526
while (((loop and (count-- > 0)) or ((not loop) and (q != 0))) and 1348 726 2074
while (((loop and (count-- > 0)) or ((not loop) and (q != 0))) and 9484 0 9484
1911 (digits < length))
1912 {
1913 9484 ▶ if (q != 0)
Branch: 1 branch
BranchTrueFalseTotal
if (q != 0) 9456 28 9484
1914 {
1915 9456 BIT_VECTOR_DIGITIZE(N_word,q,r)
1916 }
1917 28 else r = (N_word) '0';
1918 9484 *string++ = (N_char) r;
1919 9484 digits++;
1920 }
1921 }
1922 1178 ▶ while (loop and (digits < length));
Branch: 2 branches
BranchTrueFalseTotal
while (loop and (digits < length)); 452 726 1178
while (loop and (digits < length)); 452 0 452
1923 726 BitVector_Destroy(quot);
1924 726 BitVector_Destroy(rest);
1925 726 BitVector_Destroy(temp);
1926 726 BitVector_Destroy(base);
1927 }
1928 802 ▶ if ((sign < 0) and (digits < length))
Branch: 2 branches
BranchTrueFalseTotal
if ((sign < 0) and (digits < length)) 314 488 802
if ((sign < 0) and (digits < length)) 314 0 314
1929 {
1930 314 *string++ = (N_char) '-';
1931 314 digits++;
1932 }
1933 802 *string = (N_char) '\0';
1934 802 BIT_VECTOR_reverse(result,digits);
1935 802 return(result);
1936 }
1937  
1938 264 BV_ErrCode BitVector_from_Dec(wordptr addr, charptr string)
1939 {
1940 264 BV_ErrCode error = BV_ErrCode_Ok;
1941 264 N_word bits = BV_BITS_(addr);
1942 264 N_word mask = BV_MASK_(addr);
1943 264 boolean init = (bits > BV_WordBits);
1944 boolean minus;
1945 boolean shift;
1946 boolean carry;
1947 wordptr term;
1948 wordptr base;
1949 wordptr prod;
1950 wordptr rank;
1951 wordptr temp;
1952 N_word accu;
1953 N_word powr;
1954 N_word count;
1955 N_word length;
1956 int digit;
1957  
1958 264 ▶ if (bits > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (bits > 0) 264 0 264
1959 {
1960 264 length = strlen((char *) string);
1961 264 ▶ if (length == 0) return(BV_ErrCode_Pars);
Branch: 1 branch
BranchTrueFalseTotal
if (length == 0) return(BV_ErrCode_Pars); 0 264 264
1962 264 digit = (int) *string;
1963 264 ▶ if ((minus = (digit == (int) '-')) or
Branch: 2 branches
BranchTrueFalseTotal
if ((minus = (digit == (int) '-')) or 152 112 264
if ((minus = (digit == (int) '-')) or 0 152 152
1964 (digit == (int) '+'))
1965 {
1966 112 string++;
1967 112 ▶ if (--length == 0) return(BV_ErrCode_Pars);
Branch: 1 branch
BranchTrueFalseTotal
if (--length == 0) return(BV_ErrCode_Pars); 0 112 112
1968 }
1969 264 string += length;
1970 264 term = BitVector_Create(BV_WordBits,false);
1971 264 ▶ if (term == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (term == NULL) 0 264 264
1972 {
1973 0 return(BV_ErrCode_Null);
1974 }
1975 264 base = BitVector_Create(BV_WordBits,false);
1976 264 ▶ if (base == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (base == NULL) 0 264 264
1977 {
1978 0 BitVector_Destroy(term);
1979 0 return(BV_ErrCode_Null);
1980 }
1981 264 prod = BitVector_Create(bits,init);
1982 264 ▶ if (prod == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (prod == NULL) 0 264 264
1983 {
1984 0 BitVector_Destroy(term);
1985 0 BitVector_Destroy(base);
1986 0 return(BV_ErrCode_Null);
1987 }
1988 264 rank = BitVector_Create(bits,init);
1989 264 ▶ if (rank == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (rank == NULL) 0 264 264
1990 {
1991 0 BitVector_Destroy(term);
1992 0 BitVector_Destroy(base);
1993 0 BitVector_Destroy(prod);
1994 0 return(BV_ErrCode_Null);
1995 }
1996 264 temp = BitVector_Create(bits,false);
1997 264 ▶ if (temp == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (temp == NULL) 0 264 264
1998 {
1999 0 BitVector_Destroy(term);
2000 0 BitVector_Destroy(base);
2001 0 BitVector_Destroy(prod);
2002 0 BitVector_Destroy(rank);
2003 0 return(BV_ErrCode_Null);
2004 }
2005 264 BitVector_Empty(addr);
2006 264 *base = BV_Exp10;
2007 264 shift = false;
2008 980 ▶ while ((not error) and (length > 0))
Branch: 2 branches
BranchTrueFalseTotal
while ((not error) and (length > 0)) 980 0 980
while ((not error) and (length > 0)) 716 264 980
2009 {
2010 716 accu = 0;
2011 716 powr = 1;
2012 716 count = BV_Log10;
2013 9536 ▶ while ((not error) and (length > 0) and (count-- > 0))
Branch: 3 branches
BranchTrueFalseTotal
while ((not error) and (length > 0) and (count-- > 0)) 9536 0 9536
while ((not error) and (length > 0) and (count-- > 0)) 9272 264 9536
while ((not error) and (length > 0) and (count-- > 0)) 8820 452 9272
2014 {
2015 8820 digit = (int) *(--string); length--;
2016 /* separate because isdigit() is likely a macro! */
2017 8820 ▶ if (isdigit(digit) != 0)
Branch: 1 branch
BranchTrueFalseTotal
if (isdigit(digit) != 0) 8820 0 8820
2018 {
2019 8820 accu += ((N_word) digit - (N_word) '0') * powr;
2020 8820 powr *= 10;
2021 }
2022 0 else error = BV_ErrCode_Pars;
2023 }
2024 716 ▶ if (not error)
Branch: 1 branch
BranchTrueFalseTotal
if (not error) 716 0 716
2025 {
2026 716 ▶ if (shift)
Branch: 1 branch
BranchTrueFalseTotal
if (shift) 452 264 716
2027 {
2028 452 *term = accu;
2029 452 BitVector_Copy(temp,rank);
2030 452 error = BitVector_Mul_Pos(prod,temp,term,false);
2031 }
2032 else
2033 {
2034 264 *prod = accu;
2035 264 ▶ if ((not init) and ((accu AND NOT mask) != 0)) error = BV_ErrCode_Ovfl;
Branch: 2 branches
BranchTrueFalseTotal
if ((not init) and ((accu AND NOT mask) != 0)) error = BV_ErrCode_Ovfl; 42 222 264
if ((not init) and ((accu AND NOT mask) != 0)) error = BV_ErrCode_Ovfl; 0 42 42
2036 }
2037 716 ▶ if (not error)
Branch: 1 branch
BranchTrueFalseTotal
if (not error) 716 0 716
2038 {
2039 716 carry = false;
2040 716 BitVector_compute(addr,addr,prod,false,&carry);
2041 /* ignores sign change (= overflow) but not */
2042 /* numbers too large (= carry) for resulting bit vector */
2043 716 ▶ if (carry) error = BV_ErrCode_Ovfl;
Branch: 1 branch
BranchTrueFalseTotal
if (carry) error = BV_ErrCode_Ovfl; 0 716 716
2044 else
2045 {
2046 716 ▶ if (length > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (length > 0) 452 264 716
2047 {
2048 452 ▶ if (shift)
Branch: 1 branch
BranchTrueFalseTotal
if (shift) 404 48 452
2049 {
2050 404 BitVector_Copy(temp,rank);
2051 404 error = BitVector_Mul_Pos(rank,temp,base,false);
2052 }
2053 else
2054 {
2055 48 *rank = *base;
2056 48 shift = true;
2057 }
2058 }
2059 }
2060 }
2061 }
2062 }
2063 264 BitVector_Destroy(term);
2064 264 BitVector_Destroy(base);
2065 264 BitVector_Destroy(prod);
2066 264 BitVector_Destroy(rank);
2067 264 BitVector_Destroy(temp);
2068 264 ▶ if (not error and minus)
Branch: 2 branches
BranchTrueFalseTotal
if (not error and minus) 264 0 264
if (not error and minus) 112 152 264
2069 {
2070 112 BitVector_Negate(addr,addr);
2071 112 ▶ if ((*(addr + BV_SIZE_(addr) - 1) AND mask AND NOT (mask >> 1)) == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((*(addr + BV_SIZE_(addr) - 1) AND mask AND NOT (mask >> 1)) == 0) 0 112 112
2072 0 error = BV_ErrCode_Ovfl;
2073 }
2074 }
2075 264 return(error);
2076 }
2077  
2078 112 charptr BitVector_to_Enum(wordptr addr)
2079 {
2080 112 N_word bits = BV_BITS_(addr);
2081 N_word sample;
2082 N_word length;
2083 N_word digits;
2084 N_word factor;
2085 N_word power;
2086 N_word start;
2087 N_word min;
2088 N_word max;
2089 charptr string;
2090 charptr target;
2091 boolean comma;
2092  
2093 112 ▶ if (bits > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (bits > 0) 112 0 112
2094 {
2095 112 sample = bits - 1; /* greatest possible index */
2096 112 length = 2; /* account for index 0 and terminating '\0' */
2097 112 digits = 1; /* account for intervening dashes and commas */
2098 112 factor = 1;
2099 112 power = 10;
2100 337 ▶ while (sample >= (power-1))
Branch: 1 branch
BranchTrueFalseTotal
while (sample >= (power-1)) 225 112 337
2101 {
2102 225 length += ++digits * factor * 6; /* 9,90,900,9000,... (9*2/3 = 6) */
2103 225 factor = power;
2104 225 power *= 10;
2105 }
2106 112 ▶ if (sample > --factor)
Branch: 1 branch
BranchTrueFalseTotal
if (sample > --factor) 112 0 112
2107 {
2108 112 sample -= factor;
2109 112 factor = (N_word) ( sample / 3 );
2110 112 factor = (factor << 1) + (sample - (factor * 3));
2111 112 length += ++digits * factor;
2112 }
2113 }
2114 0 else length = 1;
2115 112 string = (charptr) malloc((size_t) length);
2116 112 ▶ if (string == NULL) return(NULL);
Branch: 1 branch
BranchTrueFalseTotal
if (string == NULL) return(NULL); 0 112 112
2117 112 start = 0;
2118 112 comma = false;
2119 112 target = string;
2120 3917 ▶ while ((start < bits) and BitVector_interval_scan_inc(addr,start,&min,&max))
Branch: 2 branches
BranchTrueFalseTotal
while ((start < bits) and BitVector_interval_scan_inc(addr,start,&min,&max)) 3857 60 3917
while ((start < bits) and BitVector_interval_scan_inc(addr,start,&min,&max)) 3805 52 3857
2121 {
2122 3805 start = max + 2;
2123 3805 ▶ if (comma) *target++ = (N_char) ',';
Branch: 1 branch
BranchTrueFalseTotal
if (comma) *target++ = (N_char) ','; 3693 112 3805
2124 3805 ▶ if (min == max)
Branch: 1 branch
BranchTrueFalseTotal
if (min == max) 3722 83 3805
2125 {
2126 3722 target += BIT_VECTOR_int2str(target,min);
2127 }
2128 else
2129 {
2130 83 ▶ if (min+1 == max)
Branch: 1 branch
BranchTrueFalseTotal
if (min+1 == max) 38 45 83
2131 {
2132 38 target += BIT_VECTOR_int2str(target,min);
2133 38 *target++ = (N_char) ',';
2134 38 target += BIT_VECTOR_int2str(target,max);
2135 }
2136 else
2137 {
2138 45 target += BIT_VECTOR_int2str(target,min);
2139 45 *target++ = (N_char) '-';
2140 45 target += BIT_VECTOR_int2str(target,max);
2141 }
2142 }
2143 3805 comma = true;
2144 }
2145 112 *target = (N_char) '\0';
2146 112 return(string);
2147 }
2148  
2149 122 BV_ErrCode BitVector_from_Enum(wordptr addr, charptr string)
2150 {
2151 122 BV_ErrCode error = BV_ErrCode_Ok;
2152 122 N_word bits = BV_BITS_(addr);
2153 122 N_word state = 1;
2154 122 N_word start = 0; /* silence compiler warning */
2155 N_word token;
2156 N_word index;
2157  
2158 122 ▶ if (bits > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (bits > 0) 122 0 122
2159 {
2160 122 BitVector_Empty(addr);
2161 7917 ▶ while ((not error) and (state != 0))
Branch: 2 branches
BranchTrueFalseTotal
while ((not error) and (state != 0)) 7909 8 7917
while ((not error) and (state != 0)) 7795 114 7909
2162 {
2163 7795 token = (N_word) *string;
2164 /* separate because isdigit() is likely a macro! */
2165 7795 ▶ if (isdigit((int)token) != 0)
Branch: 1 branch
BranchTrueFalseTotal
if (isdigit((int)token) != 0) 3899 3896 7795
2166 {
2167 3899 string += BIT_VECTOR_str2int(string,&index);
2168 3899 ▶ if (index < bits) token = (N_word) '0';
Branch: 1 branch
BranchTrueFalseTotal
if (index < bits) token = (N_word) '0'; 3895 4 3899
2169 4 else error = BV_ErrCode_Indx;
2170 }
2171 3896 else string++;
2172 7795 ▶ if (not error)
Branch: 1 branch
BranchTrueFalseTotal
if (not error) 7791 4 7795
2173 7791 switch (state)
2174 {
2175 120 case 1:
2176 120 switch (token)
2177 {
2178 120 case (N_word) '0':
2179 120 state = 2;
2180 120 break;
2181 0 case (N_word) '\0':
2182 0 state = 0;
2183 0 break;
2184 0 default:
2185 0 error = BV_ErrCode_Pars;
2186 0 break;
2187 }
2188 120 break;
2189 3852 case 2:
2190 3852 switch (token)
2191 {
2192 44 case (N_word) '-':
2193 44 start = index;
2194 44 state = 3;
2195 44 break;
2196 3730 case (N_word) ',':
2197 3730 BIT_VECTOR_SET_BIT(addr,index)
2198 3730 state = 5;
2199 3730 break;
2200 77 case (N_word) '\0':
2201 77 BIT_VECTOR_SET_BIT(addr,index)
2202 77 state = 0;
2203 77 break;
2204 1 default:
2205 1 error = BV_ErrCode_Pars;
2206 1 break;
2207 }
2208 3852 break;
2209 43 case 3:
2210 43 ▶ switch (token)
Branch: 1 branch
BranchTrueFalseTotal
switch (token) 43 0 43
2211 {
2212 43 case (N_word) '0':
2213 43 ▶ if (start < index)
Branch: 1 branch
BranchTrueFalseTotal
if (start < index) 42 1 43
2214 42 BitVector_Interval_Fill(addr,start,index);
2215 1 ▶ else if (start == index)
Branch: 1 branch
BranchTrueFalseTotal
else if (start == index) 0 1 1
2216 0 BIT_VECTOR_SET_BIT(addr,index)
2217 1 else error = BV_ErrCode_Ordr;
2218 43 state = 4;
2219 43 break;
2220 0 default:
2221 0 error = BV_ErrCode_Pars;
2222 0 break;
2223 }
2224 43 break;
2225 42 case 4:
2226 42 switch (token)
2227 {
2228 5 case (N_word) ',':
2229 5 state = 5;
2230 5 break;
2231 37 case (N_word) '\0':
2232 37 state = 0;
2233 37 break;
2234 0 default:
2235 0 error = BV_ErrCode_Pars;
2236 0 break;
2237 }
2238 42 break;
2239 3734 case 5:
2240 3734 ▶ switch (token)
Branch: 1 branch
BranchTrueFalseTotal
switch (token) 3732 2 3734
2241 {
2242 3732 case (N_word) '0':
2243 3732 state = 2;
2244 3732 break;
2245 2 default:
2246 2 error = BV_ErrCode_Pars;
2247 2 break;
2248 }
2249 3734 break;
2250 }
2251 }
2252 }
2253 122 return(error);
2254 }
2255  
2256 25057 void BitVector_Bit_Off(wordptr addr, N_int index) /* X = X \ {x} */
2257 {
2258 25057 ▶ if (index < BV_BITS_(addr)) BIT_VECTOR_CLR_BIT(addr,index)
Branch: 1 branch
BranchTrueFalseTotal
if (index < BV_BITS_(addr)) BIT_VECTOR_CLR_BIT(addr,index) 25057 0 25057
2259 25057 }
2260  
2261 22927 void BitVector_Bit_On(wordptr addr, N_int index) /* X = X + {x} */
2262 {
2263 22927 ▶ if (index < BV_BITS_(addr)) BIT_VECTOR_SET_BIT(addr,index)
Branch: 1 branch
BranchTrueFalseTotal
if (index < BV_BITS_(addr)) BIT_VECTOR_SET_BIT(addr,index) 22927 0 22927
2264 22927 }
2265  
2266 13337 boolean BitVector_bit_flip(wordptr addr, N_int index) /* X=(X+{x})\(X*{x}) */
2267 {
2268 N_word mask;
2269  
2270 13337 ▶ if (index < BV_BITS_(addr)) return( BIT_VECTOR_FLP_BIT(addr,index,mask) );
Branch: 1 branch
BranchTrueFalseTotal
if (index < BV_BITS_(addr)) return( BIT_VECTOR_FLP_BIT(addr,index,mask) ); 13337 0 13337
2271 0 else return( false );
2272 }
2273  
2274 128249 boolean BitVector_bit_test(wordptr addr, N_int index) /* {x} in X ? */
2275 {
2276 128249 ▶ if (index < BV_BITS_(addr)) return( BIT_VECTOR_TST_BIT(addr,index) );
Branch: 1 branch
BranchTrueFalseTotal
if (index < BV_BITS_(addr)) return( BIT_VECTOR_TST_BIT(addr,index) ); 128249 0 128249
2277 0 else return( false );
2278 }
2279  
2280 1 void BitVector_Bit_Copy(wordptr addr, N_int index, boolean bit)
2281 {
2282 1 ▶ if (index < BV_BITS_(addr))
Branch: 1 branch
BranchTrueFalseTotal
if (index < BV_BITS_(addr)) 1 0 1
2283 {
2284 1 ▶ if (bit) BIT_VECTOR_SET_BIT(addr,index)
Branch: 1 branch
BranchTrueFalseTotal
if (bit) BIT_VECTOR_SET_BIT(addr,index) 1 0 1
2285 0 else BIT_VECTOR_CLR_BIT(addr,index)
2286 }
2287 1 }
2288  
2289 1 void BitVector_LSB(wordptr addr, boolean bit)
2290 {
2291 1 ▶ if (BV_BITS_(addr) > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (BV_BITS_(addr) > 0) 1 0 1
2292 {
2293 1 ▶ if (bit) *addr |= BV_LSB;
Branch: 1 branch
BranchTrueFalseTotal
if (bit) *addr |= BV_LSB; 1 0 1
2294 0 else *addr &= NOT BV_LSB;
2295 }
2296 1 }
2297  
2298 1 void BitVector_MSB(wordptr addr, boolean bit)
2299 {
2300 1 N_word size = BV_SIZE_(addr);
2301 1 N_word mask = BV_MASK_(addr);
2302  
2303 1 ▶ if (size-- > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (size-- > 0) 1 0 1
2304 {
2305 1 ▶ if (bit) *(addr+size) |= mask AND NOT (mask >> 1);
Branch: 1 branch
BranchTrueFalseTotal
if (bit) *(addr+size) |= mask AND NOT (mask >> 1); 1 0 1
2306 0 else *(addr+size) &= NOT mask OR (mask >> 1);
2307 }
2308 1 }
2309  
2310 1 boolean BitVector_lsb_(wordptr addr)
2311 {
2312 1 ▶ if (BV_SIZE_(addr) > 0) return( (*addr AND BV_LSB) != 0 );
Branch: 1 branch
BranchTrueFalseTotal
if (BV_SIZE_(addr) > 0) return( (*addr AND BV_LSB) != 0 ); 1 0 1
2313 0 else return( false );
2314 }
2315  
2316 29 boolean BitVector_msb_(wordptr addr)
2317 {
2318 29 N_word size = BV_SIZE_(addr);
2319 29 N_word mask = BV_MASK_(addr);
2320  
2321 29 ▶ if (size-- > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (size-- > 0) 29 0 29
2322 29 return( (*(addr+size) AND (mask AND NOT (mask >> 1))) != 0 );
2323 else
2324 0 return( false );
2325 }
2326  
2327 4058 boolean BitVector_rotate_left(wordptr addr)
2328 {
2329 4058 N_word size = BV_SIZE_(addr);
2330 4058 N_word mask = BV_MASK_(addr);
2331 N_word msb;
2332 boolean carry_in;
2333 4058 boolean carry_out = false;
2334  
2335 4058 ▶ if (size > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (size > 0) 4058 0 4058
2336 {
2337 4058 msb = mask AND NOT (mask >> 1);
2338 4058 carry_in = ((*(addr+size-1) AND msb) != 0);
2339 43727 ▶ while (size-- > 1)
Branch: 1 branch
BranchTrueFalseTotal
while (size-- > 1) 39669 4058 43727
2340 {
2341 39669 carry_out = ((*addr AND BV_MSB) != 0);
2342 39669 *addr <<= 1;
2343 39669 ▶ if (carry_in) *addr |= BV_LSB;
Branch: 1 branch
BranchTrueFalseTotal
if (carry_in) *addr |= BV_LSB; 6903 32766 39669
2344 39669 carry_in = carry_out;
2345 39669 addr++;
2346 }
2347 4058 carry_out = ((*addr AND msb) != 0);
2348 4058 *addr <<= 1;
2349 4058 ▶ if (carry_in) *addr |= BV_LSB;
Branch: 1 branch
BranchTrueFalseTotal
if (carry_in) *addr |= BV_LSB; 776 3282 4058
2350 4058 *addr &= mask;
2351 }
2352 4058 return(carry_out);
2353 }
2354  
2355 4058 boolean BitVector_rotate_right(wordptr addr)
2356 {
2357 4058 N_word size = BV_SIZE_(addr);
2358 4058 N_word mask = BV_MASK_(addr);
2359 N_word msb;
2360 boolean carry_in;
2361 4058 boolean carry_out = false;
2362  
2363 4058 ▶ if (size > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (size > 0) 4058 0 4058
2364 {
2365 4058 msb = mask AND NOT (mask >> 1);
2366 4058 carry_in = ((*addr AND BV_LSB) != 0);
2367 4058 addr += size-1;
2368 4058 *addr &= mask;
2369 4058 carry_out = ((*addr AND BV_LSB) != 0);
2370 4058 *addr >>= 1;
2371 4058 ▶ if (carry_in) *addr |= msb;
Branch: 1 branch
BranchTrueFalseTotal
if (carry_in) *addr |= msb; 777 3281 4058
2372 4058 carry_in = carry_out;
2373 4058 addr--;
2374 4058 size--;
2375 43727 ▶ while (size-- > 0)
Branch: 1 branch
BranchTrueFalseTotal
while (size-- > 0) 39669 4058 43727
2376 {
2377 39669 carry_out = ((*addr AND BV_LSB) != 0);
2378 39669 *addr >>= 1;
2379 39669 ▶ if (carry_in) *addr |= BV_MSB;
Branch: 1 branch
BranchTrueFalseTotal
if (carry_in) *addr |= BV_MSB; 6903 32766 39669
2380 39669 carry_in = carry_out;
2381 39669 addr--;
2382 }
2383 }
2384 4058 return(carry_out);
2385 }
2386  
2387 368682 boolean BitVector_shift_left(wordptr addr, boolean carry_in)
2388 {
2389 368682 N_word size = BV_SIZE_(addr);
2390 368682 N_word mask = BV_MASK_(addr);
2391 N_word msb;
2392 368682 boolean carry_out = carry_in;
2393  
2394 368682 ▶ if (size > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (size > 0) 368682 0 368682
2395 {
2396 368682 msb = mask AND NOT (mask >> 1);
2397 5560762 ▶ while (size-- > 1)
Branch: 1 branch
BranchTrueFalseTotal
while (size-- > 1) 5192080 368682 5560762
2398 {
2399 5192080 carry_out = ((*addr AND BV_MSB) != 0);
2400 5192080 *addr <<= 1;
2401 5192080 ▶ if (carry_in) *addr |= BV_LSB;
Branch: 1 branch
BranchTrueFalseTotal
if (carry_in) *addr |= BV_LSB; 1147228 4044852 5192080
2402 5192080 carry_in = carry_out;
2403 5192080 addr++;
2404 }
2405 368682 carry_out = ((*addr AND msb) != 0);
2406 368682 *addr <<= 1;
2407 368682 ▶ if (carry_in) *addr |= BV_LSB;
Branch: 1 branch
BranchTrueFalseTotal
if (carry_in) *addr |= BV_LSB; 75261 293421 368682
2408 368682 *addr &= mask;
2409 }
2410 368682 return(carry_out);
2411 }
2412  
2413 89777 boolean BitVector_shift_right(wordptr addr, boolean carry_in)
2414 {
2415 89777 N_word size = BV_SIZE_(addr);
2416 89777 N_word mask = BV_MASK_(addr);
2417 N_word msb;
2418 89777 boolean carry_out = carry_in;
2419  
2420 89777 ▶ if (size > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (size > 0) 89777 0 89777
2421 {
2422 89777 msb = mask AND NOT (mask >> 1);
2423 89777 addr += size-1;
2424 89777 *addr &= mask;
2425 89777 carry_out = ((*addr AND BV_LSB) != 0);
2426 89777 *addr >>= 1;
2427 89777 ▶ if (carry_in) *addr |= msb;
Branch: 1 branch
BranchTrueFalseTotal
if (carry_in) *addr |= msb; 2329 87448 89777
2428 89777 carry_in = carry_out;
2429 89777 addr--;
2430 89777 size--;
2431 1183490 ▶ while (size-- > 0)
Branch: 1 branch
BranchTrueFalseTotal
while (size-- > 0) 1093713 89777 1183490
2432 {
2433 1093713 carry_out = ((*addr AND BV_LSB) != 0);
2434 1093713 *addr >>= 1;
2435 1093713 ▶ if (carry_in) *addr |= BV_MSB;
Branch: 1 branch
BranchTrueFalseTotal
if (carry_in) *addr |= BV_MSB; 989227 104486 1093713
2436 1093713 carry_in = carry_out;
2437 1093713 addr--;
2438 }
2439 }
2440 89777 return(carry_out);
2441 }
2442  
2443 2564 void BitVector_Move_Left(wordptr addr, N_int bits)
2444 {
2445 N_word count;
2446 N_word words;
2447  
2448 2564 ▶ if (bits > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (bits > 0) 2554 10 2564
2449 {
2450 2554 count = bits AND BV_ModMask;
2451 2554 words = bits >> BV_LogBits;
2452 2554 ▶ if (bits >= BV_BITS_(addr)) BitVector_Empty(addr);
Branch: 1 branch
BranchTrueFalseTotal
if (bits >= BV_BITS_(addr)) BitVector_Empty(addr); 41 2513 2554
2453 else
2454 {
2455 80118 ▶ while (count-- > 0) BitVector_shift_left(addr,0);
Branch: 1 branch
BranchTrueFalseTotal
while (count-- > 0) BitVector_shift_left(addr,0); 77605 2513 80118
2456 2513 BitVector_Word_Insert(addr,0,words,true);
2457 }
2458 }
2459 2564 }
2460  
2461 2564 void BitVector_Move_Right(wordptr addr, N_int bits)
2462 {
2463 N_word count;
2464 N_word words;
2465  
2466 2564 ▶ if (bits > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (bits > 0) 2554 10 2564
2467 {
2468 2554 count = bits AND BV_ModMask;
2469 2554 words = bits >> BV_LogBits;
2470 2554 ▶ if (bits >= BV_BITS_(addr)) BitVector_Empty(addr);
Branch: 1 branch
BranchTrueFalseTotal
if (bits >= BV_BITS_(addr)) BitVector_Empty(addr); 41 2513 2554
2471 else
2472 {
2473 80118 ▶ while (count-- > 0) BitVector_shift_right(addr,0);
Branch: 1 branch
BranchTrueFalseTotal
while (count-- > 0) BitVector_shift_right(addr,0); 77605 2513 80118
2474 2513 BitVector_Word_Delete(addr,0,words,true);
2475 }
2476 }
2477 2564 }
2478  
2479 5153 void BitVector_Insert(wordptr addr, N_int offset, N_int count, boolean clear)
2480 {
2481 5153 N_word bits = BV_BITS_(addr);
2482 N_word last;
2483  
2484 5153 ▶ if ((count > 0) and (offset < bits))
Branch: 2 branches
BranchTrueFalseTotal
if ((count > 0) and (offset < bits)) 5131 22 5153
if ((count > 0) and (offset < bits)) 5131 0 5131
2485 {
2486 5131 last = offset + count;
2487 5131 ▶ if (last < bits)
Branch: 1 branch
BranchTrueFalseTotal
if (last < bits) 5050 81 5131
2488 {
2489 5050 BitVector_Interval_Copy(addr,addr,last,offset,(bits-last));
2490 }
2491 81 else last = bits;
2492 5131 ▶ if (clear) BitVector_Interval_Empty(addr,offset,(last-1));
Branch: 1 branch
BranchTrueFalseTotal
if (clear) BitVector_Interval_Empty(addr,offset,(last-1)); 5131 0 5131
2493 }
2494 5153 }
2495  
2496 5153 void BitVector_Delete(wordptr addr, N_int offset, N_int count, boolean clear)
2497 {
2498 5153 N_word bits = BV_BITS_(addr);
2499 N_word last;
2500  
2501 5153 ▶ if ((count > 0) and (offset < bits))
Branch: 2 branches
BranchTrueFalseTotal
if ((count > 0) and (offset < bits)) 5131 22 5153
if ((count > 0) and (offset < bits)) 5131 0 5131
2502 {
2503 5131 last = offset + count;
2504 5131 ▶ if (last < bits)
Branch: 1 branch
BranchTrueFalseTotal
if (last < bits) 5050 81 5131
2505 {
2506 5050 BitVector_Interval_Copy(addr,addr,offset,last,(bits-last));
2507 }
2508 81 else count = bits - offset;
2509 5131 ▶ if (clear) BitVector_Interval_Empty(addr,(bits-count),(bits-1));
Branch: 1 branch
BranchTrueFalseTotal
if (clear) BitVector_Interval_Empty(addr,(bits-count),(bits-1)); 5131 0 5131
2510 }
2511 5153 }
2512  
2513 1333 boolean BitVector_increment(wordptr addr) /* X++ */
2514 {
2515 1333 N_word size = BV_SIZE_(addr);
2516 1333 N_word mask = BV_MASK_(addr);
2517 1333 wordptr last = addr + size - 1;
2518 1333 boolean carry = true;
2519  
2520 1333 ▶ if (size > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (size > 0) 1333 0 1333
2521 {
2522 1333 *last |= NOT mask;
2523 2704 ▶ while (carry and (size-- > 0))
Branch: 2 branches
BranchTrueFalseTotal
while (carry and (size-- > 0)) 1374 1330 2704
while (carry and (size-- > 0)) 1371 3 1374
2524 {
2525 1371 carry = (++(*addr++) == 0);
2526 }
2527 1333 *last &= mask;
2528 }
2529 1333 return(carry);
2530 }
2531  
2532 1333 boolean BitVector_decrement(wordptr addr) /* X-- */
2533 {
2534 1333 N_word size = BV_SIZE_(addr);
2535 1333 N_word mask = BV_MASK_(addr);
2536 1333 wordptr last = addr + size - 1;
2537 1333 boolean carry = true;
2538  
2539 1333 ▶ if (size > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (size > 0) 1333 0 1333
2540 {
2541 1333 *last &= mask;
2542 2732 ▶ while (carry and (size-- > 0))
Branch: 2 branches
BranchTrueFalseTotal
while (carry and (size-- > 0)) 1406 1326 2732
while (carry and (size-- > 0)) 1399 7 1406
2543 {
2544 1399 carry = (*addr == 0);
2545 1399 --(*addr++);
2546 }
2547 1333 *last &= mask;
2548 }
2549 1333 return(carry);
2550 }
2551  
2552 255146 boolean BitVector_compute(wordptr X, wordptr Y, wordptr Z, boolean minus, boolean *carry)
2553 {
2554 255146 N_word size = BV_SIZE_(X);
2555 255146 N_word mask = BV_MASK_(X);
2556 255146 N_word vv = 0;
2557 N_word cc;
2558 N_word mm;
2559 N_word yy;
2560 N_word zz;
2561 N_word lo;
2562 N_word hi;
2563  
2564 255146 ▶ if (size > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (size > 0) 255146 0 255146
2565 {
2566 255146 ▶ if (minus) cc = (*carry == 0);
Branch: 1 branch
BranchTrueFalseTotal
if (minus) cc = (*carry == 0); 231456 23690 255146
2567 23690 else cc = (*carry != 0);
2568 /* deal with (size-1) least significant full words first: */
2569 3987683 ▶ while (--size > 0)
Branch: 1 branch
BranchTrueFalseTotal
while (--size > 0) 3732537 255146 3987683
2570 {
2571 3732537 yy = *Y++;
2572 3732537 ▶ if (minus) zz = (N_word) NOT ( Z ? *Z++ : 0 );
Branch: 2 branches
BranchTrueFalseTotal
if (minus) zz = (N_word) NOT ( Z ? *Z++ : 0 ); 3409758 322779 3732537
if (minus) zz = (N_word) NOT ( Z ? *Z++ : 0 ); 3409758 0 3409758
2573 322779 ▶ else zz = (N_word) ( Z ? *Z++ : 0 );
Branch: 1 branch
BranchTrueFalseTotal
else zz = (N_word) ( Z ? *Z++ : 0 ); 322779 0 322779
2574 3732537 lo = (yy AND BV_LSB) + (zz AND BV_LSB) + cc;
2575 3732537 hi = (yy >> 1) + (zz >> 1) + (lo >> 1);
2576 3732537 cc = ((hi AND BV_MSB) != 0);
2577 3732537 *X++ = (hi << 1) OR (lo AND BV_LSB);
2578 }
2579 /* deal with most significant word (may be used only partially): */
2580 255146 yy = *Y AND mask;
2581 255146 ▶ if (minus) zz = (N_word) NOT ( Z ? *Z : 0 );
Branch: 2 branches
BranchTrueFalseTotal
if (minus) zz = (N_word) NOT ( Z ? *Z : 0 ); 231456 23690 255146
if (minus) zz = (N_word) NOT ( Z ? *Z : 0 ); 231456 0 231456
2582 23690 ▶ else zz = (N_word) ( Z ? *Z : 0 );
Branch: 1 branch
BranchTrueFalseTotal
else zz = (N_word) ( Z ? *Z : 0 ); 23690 0 23690
2583 255146 zz &= mask;
2584 255146 ▶ if (mask == BV_LSB) /* special case, only one bit used */
Branch: 1 branch
BranchTrueFalseTotal
if (mask == BV_LSB) /* special case, only one bit used */ 81227 173919 255146
2585 {
2586 81227 vv = cc;
2587 81227 lo = yy + zz + cc;
2588 81227 cc = (lo >> 1);
2589 81227 vv ^= cc;
2590 81227 *X = lo AND BV_LSB;
2591 }
2592 else
2593 {
2594 173919 ▶ if (NOT mask) /* not all bits are used, but more than one */
Branch: 1 branch
BranchTrueFalseTotal
if (NOT mask) /* not all bits are used, but more than one */ 81768 92151 173919
2595 {
2596 81768 mm = (mask >> 1);
2597 81768 vv = (yy AND mm) + (zz AND mm) + cc;
2598 81768 mm = mask AND NOT mm;
2599 81768 lo = yy + zz + cc;
2600 81768 cc = (lo >> 1);
2601 81768 vv ^= cc;
2602 81768 vv &= mm;
2603 81768 cc &= mm;
2604 81768 *X = lo AND mask;
2605 }
2606 else /* other special case, all bits are used */
2607 {
2608 92151 mm = NOT BV_MSB;
2609 92151 lo = (yy AND mm) + (zz AND mm) + cc;
2610 92151 vv = lo AND BV_MSB;
2611 92151 hi = ((yy AND BV_MSB) >> 1) + ((zz AND BV_MSB) >> 1) + (vv >> 1);
2612 92151 cc = hi AND BV_MSB;
2613 92151 vv ^= cc;
2614 92151 *X = (hi << 1) OR (lo AND mm);
2615 }
2616 }
2617 255146 ▶ if (minus) *carry = (cc == 0);
Branch: 1 branch
BranchTrueFalseTotal
if (minus) *carry = (cc == 0); 231456 23690 255146
2618 23690 else *carry = (cc != 0);
2619 }
2620 255146 return(vv != 0);
2621 }
2622  
2623 0 boolean BitVector_add(wordptr X, wordptr Y, wordptr Z, boolean *carry)
2624 {
2625 0 return(BitVector_compute(X,Y,Z,false,carry));
2626 }
2627  
2628 0 boolean BitVector_sub(wordptr X, wordptr Y, wordptr Z, boolean *carry)
2629 {
2630 0 return(BitVector_compute(X,Y,Z,true,carry));
2631 }
2632  
2633 0 boolean BitVector_inc(wordptr X, wordptr Y)
2634 {
2635 0 boolean carry = true;
2636  
2637 0 return(BitVector_compute(X,Y,NULL,false,&carry));
2638 }
2639  
2640 0 boolean BitVector_dec(wordptr X, wordptr Y)
2641 {
2642 0 boolean carry = true;
2643  
2644 0 return(BitVector_compute(X,Y,NULL,true,&carry));
2645 }
2646  
2647 780 void BitVector_Negate(wordptr X, wordptr Y)
2648 {
2649 780 N_word size = BV_SIZE_(X);
2650 780 N_word mask = BV_MASK_(X);
2651 780 boolean carry = true;
2652  
2653 780 ▶ if (size > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (size > 0) 780 0 780
2654 {
2655 2639 ▶ while (size-- > 0)
Branch: 1 branch
BranchTrueFalseTotal
while (size-- > 0) 1859 780 2639
2656 {
2657 1859 *X = NOT *Y++;
2658 1859 ▶ if (carry)
Branch: 1 branch
BranchTrueFalseTotal
if (carry) 780 1079 1859
2659 {
2660 780 carry = (++(*X) == 0);
2661 }
2662 1859 X++;
2663 }
2664 780 *(--X) &= mask;
2665 }
2666 780 }
2667  
2668 2 void BitVector_Absolute(wordptr X, wordptr Y)
2669 {
2670 2 N_word size = BV_SIZE_(Y);
2671 2 N_word mask = BV_MASK_(Y);
2672  
2673 2 ▶ if (size > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (size > 0) 2 0 2
2674 {
2675 2 ▶ if (*(Y+size-1) AND (mask AND NOT (mask >> 1))) BitVector_Negate(X,Y);
Branch: 1 branch
BranchTrueFalseTotal
if (*(Y+size-1) AND (mask AND NOT (mask >> 1))) BitVector_Negate(X,Y); 0 2 2
2676 2 else BitVector_Copy(X,Y);
2677 }
2678 2 }
2679  
2680 803 Z_int BitVector_Sign(wordptr addr)
2681 {
2682 803 N_word size = BV_SIZE_(addr);
2683 803 N_word mask = BV_MASK_(addr);
2684 803 wordptr last = addr + size - 1;
2685 803 boolean r = true;
2686  
2687 803 ▶ if (size > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (size > 0) 803 0 803
2688 {
2689 803 *last &= mask;
2690 1682 ▶ while (r and (size-- > 0)) r = ( *addr++ == 0 );
Branch: 2 branches
BranchTrueFalseTotal
while (r and (size-- > 0)) r = ( *addr++ == 0 ); 955 727 1682
while (r and (size-- > 0)) r = ( *addr++ == 0 ); 879 76 955
2691 }
2692 803 ▶ if (r) return((Z_int) 0);
Branch: 1 branch
BranchTrueFalseTotal
if (r) return((Z_int) 0); 76 727 803
2693 else
2694 {
2695 727 ▶ if (*last AND (mask AND NOT (mask >> 1))) return((Z_int) -1);
Branch: 1 branch
BranchTrueFalseTotal
if (*last AND (mask AND NOT (mask >> 1))) return((Z_int) -1); 314 413 727
2696 413 else return((Z_int) 1);
2697 }
2698 }
2699  
2700 1254 BV_ErrCode BitVector_Mul_Pos(wordptr X, wordptr Y, wordptr Z, boolean strict)
2701 {
2702 N_word mask;
2703 N_word limit;
2704 N_word count;
2705 Z_long last;
2706 wordptr sign;
2707 boolean carry;
2708 boolean overflow;
2709 1254 boolean ok = true;
2710  
2711 /*
2712 Requirements:
2713 - X, Y and Z must be distinct
2714 - X and Y must have equal sizes (whereas Z may be any size!)
2715 - Z should always contain the SMALLER of the two factors Y and Z
2716 Constraints:
2717 - The contents of Y (and of X, of course) are destroyed
2718 (only Z is preserved!)
2719 */
2720  
2721 1254 ▶ if ((X == Y) or (X == Z) or (Y == Z)) return(BV_ErrCode_Same);
Branch: 3 branches
BranchTrueFalseTotal
if ((X == Y) or (X == Z) or (Y == Z)) return(BV_ErrCode_Same); 1254 0 1254
if ((X == Y) or (X == Z) or (Y == Z)) return(BV_ErrCode_Same); 1254 0 1254
if ((X == Y) or (X == Z) or (Y == Z)) return(BV_ErrCode_Same); 0 1254 1254
2722 1254 ▶ if (BV_BITS_(X) != BV_BITS_(Y)) return(BV_ErrCode_Size);
Branch: 1 branch
BranchTrueFalseTotal
if (BV_BITS_(X) != BV_BITS_(Y)) return(BV_ErrCode_Size); 0 1254 1254
2723 1254 BitVector_Empty(X);
2724 1254 ▶ if (BitVector_is_empty(Y)) return(BV_ErrCode_Ok); /* also if BV_BITS_(Y)==0 */
Branch: 1 branch
BranchTrueFalseTotal
if (BitVector_is_empty(Y)) return(BV_ErrCode_Ok); /* also if BV_BITS_(Y)==0 */ 68 1186 1254
2725 1186 ▶ if ((last = Set_Max(Z)) < 0L) return(BV_ErrCode_Ok);
Branch: 1 branch
BranchTrueFalseTotal
if ((last = Set_Max(Z)) < 0L) return(BV_ErrCode_Ok); 28 1158 1186
2726 1158 limit = (N_word) last;
2727 1158 sign = Y + BV_SIZE_(Y) - 1;
2728 1158 mask = BV_MASK_(Y);
2729 1158 *sign &= mask;
2730 1158 mask &= NOT (mask >> 1);
2731 50372 ▶ for ( count = 0; (ok and (count <= limit)); count++ )
Branch: 2 branches
BranchTrueFalseTotal
for ( count = 0; (ok and (count <= limit)); count++ ) 50372 0 50372
for ( count = 0; (ok and (count <= limit)); count++ ) 49214 1158 50372
2732 {
2733 49214 ▶ if ( BIT_VECTOR_TST_BIT(Z,count) )
Branch: 1 branch
BranchTrueFalseTotal
if ( BIT_VECTOR_TST_BIT(Z,count) ) 22218 26996 49214
2734 {
2735 22218 carry = false;
2736 22218 overflow = BitVector_compute(X,X,Y,false,&carry);
2737 22218 ▶ if (strict) ok = not (carry or overflow);
Branch: 3 branches
BranchTrueFalseTotal
if (strict) ok = not (carry or overflow); 454 21764 22218
if (strict) ok = not (carry or overflow); 454 0 454
if (strict) ok = not (carry or overflow); 454 0 454
2738 21764 else ok = not carry;
2739 }
2740 49214 ▶ if (ok and (count < limit))
Branch: 2 branches
BranchTrueFalseTotal
if (ok and (count < limit)) 49214 0 49214
if (ok and (count < limit)) 48056 1158 49214
2741 {
2742 48056 carry = BitVector_shift_left(Y,0);
2743 48056 ▶ if (strict)
Branch: 1 branch
BranchTrueFalseTotal
if (strict) 496 47560 48056
2744 {
2745 496 overflow = ((*sign AND mask) != 0);
2746 496 ▶ ok = not (carry or overflow);
Branch: 2 branches
BranchTrueFalseTotal
ok = not (carry or overflow); 496 0 496
ok = not (carry or overflow); 496 0 496
2747 }
2748 47560 else ok = not carry;
2749 }
2750 }
2751 1158 ▶ if (ok) return(BV_ErrCode_Ok); else return(BV_ErrCode_Ovfl);
Branch: 1 branch
BranchTrueFalseTotal
if (ok) return(BV_ErrCode_Ok); else return(BV_ErrCode_Ovfl); 1158 0 1158
2752 }
2753  
2754 156 BV_ErrCode BitVector_Multiply(wordptr X, wordptr Y, wordptr Z)
2755 {
2756 156 BV_ErrCode error = BV_ErrCode_Ok;
2757 156 N_word bit_x = BV_BITS_(X);
2758 156 N_word bit_y = BV_BITS_(Y);
2759 156 N_word bit_z = BV_BITS_(Z);
2760 N_word size;
2761 N_word mask;
2762 N_word msb;
2763 wordptr ptr_y;
2764 wordptr ptr_z;
2765 boolean sgn_x;
2766 boolean sgn_y;
2767 boolean sgn_z;
2768 boolean zero;
2769 wordptr A;
2770 wordptr B;
2771  
2772 /*
2773 Requirements:
2774 - Y and Z must have equal sizes
2775 - X must have at least the same size as Y and Z but may be larger (!)
2776 Features:
2777 - The contents of Y and Z are preserved
2778 - X may be identical with Y or Z (or both!)
2779 (in-place multiplication is possible!)
2780 */
2781  
2782 156 ▶ if ((bit_y != bit_z) or (bit_x < bit_y)) return(BV_ErrCode_Size);
Branch: 2 branches
BranchTrueFalseTotal
if ((bit_y != bit_z) or (bit_x < bit_y)) return(BV_ErrCode_Size); 156 0 156
if ((bit_y != bit_z) or (bit_x < bit_y)) return(BV_ErrCode_Size); 0 156 156
2783 156 ▶ if (BitVector_is_empty(Y) or BitVector_is_empty(Z))
Branch: 2 branches
BranchTrueFalseTotal
if (BitVector_is_empty(Y) or BitVector_is_empty(Z)) 119 37 156
if (BitVector_is_empty(Y) or BitVector_is_empty(Z)) 1 118 119
2784 {
2785 38 BitVector_Empty(X);
2786 }
2787 else
2788 {
2789 118 A = BitVector_Create(bit_y,false);
2790 118 ▶ if (A == NULL) return(BV_ErrCode_Null);
Branch: 1 branch
BranchTrueFalseTotal
if (A == NULL) return(BV_ErrCode_Null); 0 118 118
2791 118 B = BitVector_Create(bit_z,false);
2792 118 ▶ if (B == NULL) { BitVector_Destroy(A); return(BV_ErrCode_Null); }
Branch: 1 branch
BranchTrueFalseTotal
if (B == NULL) { BitVector_Destroy(A); return(BV_ErrCode_Null); } 0 118 118
2793 118 size = BV_SIZE_(Y);
2794 118 mask = BV_MASK_(Y);
2795 118 msb = (mask AND NOT (mask >> 1));
2796 118 sgn_y = (((*(Y+size-1) &= mask) AND msb) != 0);
2797 118 sgn_z = (((*(Z+size-1) &= mask) AND msb) != 0);
2798 118 sgn_x = sgn_y XOR sgn_z;
2799 118 ▶ if (sgn_y) BitVector_Negate(A,Y); else BitVector_Copy(A,Y);
Branch: 1 branch
BranchTrueFalseTotal
if (sgn_y) BitVector_Negate(A,Y); else BitVector_Copy(A,Y); 20 98 118
2800 118 ▶ if (sgn_z) BitVector_Negate(B,Z); else BitVector_Copy(B,Z);
Branch: 1 branch
BranchTrueFalseTotal
if (sgn_z) BitVector_Negate(B,Z); else BitVector_Copy(B,Z); 58 60 118
2801 118 ptr_y = A + size;
2802 118 ptr_z = B + size;
2803 118 zero = true;
2804 382 ▶ while (zero and (size-- > 0))
Branch: 2 branches
BranchTrueFalseTotal
while (zero and (size-- > 0)) 264 118 382
while (zero and (size-- > 0)) 264 0 264
2805 {
2806 264 zero &= (*(--ptr_y) == 0);
2807 264 zero &= (*(--ptr_z) == 0);
2808 }
2809 118 ▶ if (*ptr_y > *ptr_z)
Branch: 1 branch
BranchTrueFalseTotal
if (*ptr_y > *ptr_z) 0 118 118
2810 {
2811 0 ▶ if (bit_x > bit_y)
Branch: 1 branch
BranchTrueFalseTotal
if (bit_x > bit_y) 0 0 0
2812 {
2813 0 A = BitVector_Resize(A,bit_x);
2814 0 ▶ if (A == NULL) { BitVector_Destroy(B); return(BV_ErrCode_Null); }
Branch: 1 branch
BranchTrueFalseTotal
if (A == NULL) { BitVector_Destroy(B); return(BV_ErrCode_Null); } 0 0 0
2815 }
2816 0 error = BitVector_Mul_Pos(X,A,B,true);
2817 }
2818 else
2819 {
2820 118 ▶ if (bit_x > bit_z)
Branch: 1 branch
BranchTrueFalseTotal
if (bit_x > bit_z) 0 118 118
2821 {
2822 0 B = BitVector_Resize(B,bit_x);
2823 0 ▶ if (B == NULL) { BitVector_Destroy(A); return(BV_ErrCode_Null); }
Branch: 1 branch
BranchTrueFalseTotal
if (B == NULL) { BitVector_Destroy(A); return(BV_ErrCode_Null); } 0 0 0
2824 }
2825 118 error = BitVector_Mul_Pos(X,B,A,true);
2826 }
2827 118 ▶ if ((not error) and sgn_x) BitVector_Negate(X,X);
Branch: 2 branches
BranchTrueFalseTotal
if ((not error) and sgn_x) BitVector_Negate(X,X); 118 0 118
if ((not error) and sgn_x) BitVector_Negate(X,X); 58 60 118
2828 118 BitVector_Destroy(A);
2829 118 BitVector_Destroy(B);
2830 }
2831 156 return(error);
2832 }
2833  
2834 1545 BV_ErrCode BitVector_Div_Pos(wordptr Q, wordptr X, wordptr Y, wordptr R)
2835 {
2836 1545 N_word bits = BV_BITS_(Q);
2837 N_word mask;
2838 wordptr addr;
2839 Z_long last;
2840 boolean flag;
2841 1545 boolean copy = false; /* flags whether valid rest is in R (0) or X (1) */
2842  
2843 /*
2844 Requirements:
2845 - All bit vectors must have equal sizes
2846 - Q, X, Y and R must all be distinct bit vectors
2847 - Y must be non-zero (of course!)
2848 Constraints:
2849 - The contents of X (and Q and R, of course) are destroyed
2850 (only Y is preserved!)
2851 */
2852  
2853 1545 ▶ if ((bits != BV_BITS_(X)) or (bits != BV_BITS_(Y)) or (bits != BV_BITS_(R)))
Branch: 3 branches
BranchTrueFalseTotal
if ((bits != BV_BITS_(X)) or (bits != BV_BITS_(Y)) or (bits != BV_BITS_(R))) 1545 0 1545
if ((bits != BV_BITS_(X)) or (bits != BV_BITS_(Y)) or (bits != BV_BITS_(R))) 1545 0 1545
if ((bits != BV_BITS_(X)) or (bits != BV_BITS_(Y)) or (bits != BV_BITS_(R))) 0 1545 1545
2854 0 return(BV_ErrCode_Size);
2855 1545 ▶ if ((Q == X) or (Q == Y) or (Q == R) or (X == Y) or (X == R) or (Y == R))
Branch: 6 branches
BranchTrueFalseTotal
if ((Q == X) or (Q == Y) or (Q == R) or (X == Y) or (X == R) or (Y == R)) 1545 0 1545
if ((Q == X) or (Q == Y) or (Q == R) or (X == Y) or (X == R) or (Y == R)) 1545 0 1545
if ((Q == X) or (Q == Y) or (Q == R) or (X == Y) or (X == R) or (Y == R)) 1545 0 1545
if ((Q == X) or (Q == Y) or (Q == R) or (X == Y) or (X == R) or (Y == R)) 1545 0 1545
if ((Q == X) or (Q == Y) or (Q == R) or (X == Y) or (X == R) or (Y == R)) 1545 0 1545
if ((Q == X) or (Q == Y) or (Q == R) or (X == Y) or (X == R) or (Y == R)) 0 1545 1545
2856 0 return(BV_ErrCode_Same);
2857 1545 ▶ if (BitVector_is_empty(Y))
Branch: 1 branch
BranchTrueFalseTotal
if (BitVector_is_empty(Y)) 0 1545 1545
2858 0 return(BV_ErrCode_Zero);
2859  
2860 1545 BitVector_Empty(R);
2861 1545 BitVector_Copy(Q,X);
2862 1545 ▶ if ((last = Set_Max(Q)) < 0L) return(BV_ErrCode_Ok);
Branch: 1 branch
BranchTrueFalseTotal
if ((last = Set_Max(Q)) < 0L) return(BV_ErrCode_Ok); 0 1545 1545
2863 1545 bits = (N_word) ++last;
2864 232394 ▶ while (bits-- > 0)
Branch: 1 branch
BranchTrueFalseTotal
while (bits-- > 0) 230849 1545 232394
2865 {
2866 230849 addr = Q + (bits >> BV_LogBits);
2867 230849 mask = BV_BitMaskTab[bits AND BV_ModMask];
2868 230849 flag = ((*addr AND mask) != 0);
2869 230849 ▶ if (copy)
Branch: 1 branch
BranchTrueFalseTotal
if (copy) 100508 130341 230849
2870 {
2871 100508 BitVector_shift_left(X,flag);
2872 100508 flag = false;
2873 100508 BitVector_compute(R,X,Y,true,&flag);
2874 }
2875 else
2876 {
2877 130341 BitVector_shift_left(R,flag);
2878 130341 flag = false;
2879 130341 BitVector_compute(X,R,Y,true,&flag);
2880 }
2881 230849 ▶ if (flag) *addr &= NOT mask;
Branch: 1 branch
BranchTrueFalseTotal
if (flag) *addr &= NOT mask; 131254 99595 230849
2882 else
2883 {
2884 99595 *addr |= mask;
2885 99595 copy = not copy;
2886 }
2887 }
2888 1545 ▶ if (copy) BitVector_Copy(R,X);
Branch: 1 branch
BranchTrueFalseTotal
if (copy) BitVector_Copy(R,X); 515 1030 1545
2889 1545 return(BV_ErrCode_Ok);
2890 }
2891  
2892 6 BV_ErrCode BitVector_Divide(wordptr Q, wordptr X, wordptr Y, wordptr R)
2893 {
2894 6 BV_ErrCode error = BV_ErrCode_Ok;
2895 6 N_word bits = BV_BITS_(Q);
2896 6 N_word size = BV_SIZE_(Q);
2897 6 N_word mask = BV_MASK_(Q);
2898 6 N_word msb = (mask AND NOT (mask >> 1));
2899 boolean sgn_q;
2900 boolean sgn_x;
2901 boolean sgn_y;
2902 wordptr A;
2903 wordptr B;
2904  
2905 /*
2906 Requirements:
2907 - All bit vectors must have equal sizes
2908 - Q and R must be two distinct bit vectors
2909 - Y must be non-zero (of course!)
2910 Features:
2911 - The contents of X and Y are preserved
2912 - Q may be identical with X or Y (or both)
2913 (in-place division is possible!)
2914 - R may be identical with X or Y (or both)
2915 (but not identical with Q!)
2916 */
2917  
2918 6 ▶ if ((bits != BV_BITS_(X)) or (bits != BV_BITS_(Y)) or (bits != BV_BITS_(R)))
Branch: 3 branches
BranchTrueFalseTotal
if ((bits != BV_BITS_(X)) or (bits != BV_BITS_(Y)) or (bits != BV_BITS_(R))) 4 2 6
if ((bits != BV_BITS_(X)) or (bits != BV_BITS_(Y)) or (bits != BV_BITS_(R))) 3 1 4
if ((bits != BV_BITS_(X)) or (bits != BV_BITS_(Y)) or (bits != BV_BITS_(R))) 1 2 3
2919 4 return(BV_ErrCode_Size);
2920 2 ▶ if (Q == R)
Branch: 1 branch
BranchTrueFalseTotal
if (Q == R) 1 1 2
2921 1 return(BV_ErrCode_Same);
2922 1 ▶ if (BitVector_is_empty(Y))
Branch: 1 branch
BranchTrueFalseTotal
if (BitVector_is_empty(Y)) 0 1 1
2923 0 return(BV_ErrCode_Zero);
2924  
2925 1 ▶ if (BitVector_is_empty(X))
Branch: 1 branch
BranchTrueFalseTotal
if (BitVector_is_empty(X)) 0 1 1
2926 {
2927 0 BitVector_Empty(Q);
2928 0 BitVector_Empty(R);
2929 }
2930 else
2931 {
2932 1 A = BitVector_Create(bits,false);
2933 1 ▶ if (A == NULL) return(BV_ErrCode_Null);
Branch: 1 branch
BranchTrueFalseTotal
if (A == NULL) return(BV_ErrCode_Null); 0 1 1
2934 1 B = BitVector_Create(bits,false);
2935 1 ▶ if (B == NULL) { BitVector_Destroy(A); return(BV_ErrCode_Null); }
Branch: 1 branch
BranchTrueFalseTotal
if (B == NULL) { BitVector_Destroy(A); return(BV_ErrCode_Null); } 0 1 1
2936 1 size--;
2937 1 sgn_x = (((*(X+size) &= mask) AND msb) != 0);
2938 1 sgn_y = (((*(Y+size) &= mask) AND msb) != 0);
2939 1 sgn_q = sgn_x XOR sgn_y;
2940 1 ▶ if (sgn_x) BitVector_Negate(A,X); else BitVector_Copy(A,X);
Branch: 1 branch
BranchTrueFalseTotal
if (sgn_x) BitVector_Negate(A,X); else BitVector_Copy(A,X); 0 1 1
2941 1 ▶ if (sgn_y) BitVector_Negate(B,Y); else BitVector_Copy(B,Y);
Branch: 1 branch
BranchTrueFalseTotal
if (sgn_y) BitVector_Negate(B,Y); else BitVector_Copy(B,Y); 0 1 1
2942 1 ▶ if (not (error = BitVector_Div_Pos(Q,A,B,R)))
Branch: 1 branch
BranchTrueFalseTotal
if (not (error = BitVector_Div_Pos(Q,A,B,R))) 1 0 1
2943 {
2944 1 ▶ if (sgn_q) BitVector_Negate(Q,Q);
Branch: 1 branch
BranchTrueFalseTotal
if (sgn_q) BitVector_Negate(Q,Q); 0 1 1
2945 1 ▶ if (sgn_x) BitVector_Negate(R,R);
Branch: 1 branch
BranchTrueFalseTotal
if (sgn_x) BitVector_Negate(R,R); 0 1 1
2946 }
2947 1 BitVector_Destroy(A);
2948 1 BitVector_Destroy(B);
2949 }
2950 1 return(error);
2951 }
2952  
2953 82 BV_ErrCode BitVector_GCD(wordptr X, wordptr Y, wordptr Z)
2954 {
2955 82 BV_ErrCode error = BV_ErrCode_Ok;
2956 82 N_word bits = BV_BITS_(X);
2957 82 N_word size = BV_SIZE_(X);
2958 82 N_word mask = BV_MASK_(X);
2959 82 N_word msb = (mask AND NOT (mask >> 1));
2960 boolean sgn_a;
2961 boolean sgn_b;
2962 boolean sgn_r;
2963 wordptr Q;
2964 wordptr R;
2965 wordptr A;
2966 wordptr B;
2967 wordptr T;
2968  
2969 /*
2970 Requirements:
2971 - All bit vectors must have equal sizes
2972 Features:
2973 - The contents of Y and Z are preserved
2974 - X may be identical with Y or Z (or both)
2975 (in-place is possible!)
2976 - GCD(0,z) == GCD(z,0) == z
2977 - negative values are handled correctly
2978 */
2979  
2980 82 ▶ if ((bits != BV_BITS_(Y)) or (bits != BV_BITS_(Z))) return(BV_ErrCode_Size);
Branch: 2 branches
BranchTrueFalseTotal
if ((bits != BV_BITS_(Y)) or (bits != BV_BITS_(Z))) return(BV_ErrCode_Size); 80 2 82
if ((bits != BV_BITS_(Y)) or (bits != BV_BITS_(Z))) return(BV_ErrCode_Size); 1 79 80
2981 79 ▶ if (BitVector_is_empty(Y))
Branch: 1 branch
BranchTrueFalseTotal
if (BitVector_is_empty(Y)) 9 70 79
2982 {
2983 9 ▶ if (X != Z) BitVector_Copy(X,Z);
Branch: 1 branch
BranchTrueFalseTotal
if (X != Z) BitVector_Copy(X,Z); 9 0 9
2984 9 return(BV_ErrCode_Ok);
2985 }
2986 70 ▶ if (BitVector_is_empty(Z))
Branch: 1 branch
BranchTrueFalseTotal
if (BitVector_is_empty(Z)) 8 62 70
2987 {
2988 8 ▶ if (X != Y) BitVector_Copy(X,Y);
Branch: 1 branch
BranchTrueFalseTotal
if (X != Y) BitVector_Copy(X,Y); 8 0 8
2989 8 return(BV_ErrCode_Ok);
2990 }
2991 62 Q = BitVector_Create(bits,false);
2992 62 ▶ if (Q == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (Q == NULL) 0 62 62
2993 {
2994 0 return(BV_ErrCode_Null);
2995 }
2996 62 R = BitVector_Create(bits,false);
2997 62 ▶ if (R == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (R == NULL) 0 62 62
2998 {
2999 0 BitVector_Destroy(Q);
3000 0 return(BV_ErrCode_Null);
3001 }
3002 62 A = BitVector_Create(bits,false);
3003 62 ▶ if (A == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (A == NULL) 0 62 62
3004 {
3005 0 BitVector_Destroy(Q);
3006 0 BitVector_Destroy(R);
3007 0 return(BV_ErrCode_Null);
3008 }
3009 62 B = BitVector_Create(bits,false);
3010 62 ▶ if (B == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (B == NULL) 0 62 62
3011 {
3012 0 BitVector_Destroy(Q);
3013 0 BitVector_Destroy(R);
3014 0 BitVector_Destroy(A);
3015 0 return(BV_ErrCode_Null);
3016 }
3017 62 size--;
3018 62 sgn_a = (((*(Y+size) &= mask) AND msb) != 0);
3019 62 sgn_b = (((*(Z+size) &= mask) AND msb) != 0);
3020 62 ▶ if (sgn_a) BitVector_Negate(A,Y); else BitVector_Copy(A,Y);
Branch: 1 branch
BranchTrueFalseTotal
if (sgn_a) BitVector_Negate(A,Y); else BitVector_Copy(A,Y); 30 32 62
3021 62 ▶ if (sgn_b) BitVector_Negate(B,Z); else BitVector_Copy(B,Z);
Branch: 1 branch
BranchTrueFalseTotal
if (sgn_b) BitVector_Negate(B,Z); else BitVector_Copy(B,Z); 30 32 62
3022 202 ▶ while (not error)
Branch: 1 branch
BranchTrueFalseTotal
while (not error) 202 0 202
3023 {
3024 202 ▶ if (not (error = BitVector_Div_Pos(Q,A,B,R)))
Branch: 1 branch
BranchTrueFalseTotal
if (not (error = BitVector_Div_Pos(Q,A,B,R))) 202 0 202
3025 {
3026 202 ▶ if (BitVector_is_empty(R)) break;
Branch: 1 branch
BranchTrueFalseTotal
if (BitVector_is_empty(R)) break; 62 140 202
3027 140 T = A; sgn_r = sgn_a;
3028 140 A = B; sgn_a = sgn_b;
3029 140 B = R; sgn_b = sgn_r;
3030 140 R = T;
3031 }
3032 }
3033 62 ▶ if (not error)
Branch: 1 branch
BranchTrueFalseTotal
if (not error) 62 0 62
3034 {
3035 62 ▶ if (sgn_b) BitVector_Negate(X,B); else BitVector_Copy(X,B);
Branch: 1 branch
BranchTrueFalseTotal
if (sgn_b) BitVector_Negate(X,B); else BitVector_Copy(X,B); 30 32 62
3036 }
3037 62 BitVector_Destroy(Q);
3038 62 BitVector_Destroy(R);
3039 62 BitVector_Destroy(A);
3040 62 BitVector_Destroy(B);
3041 62 return(error);
3042 }
3043  
3044 77 BV_ErrCode BitVector_GCD2(wordptr U, wordptr V, wordptr W, wordptr X, wordptr Y)
3045 {
3046 77 BV_ErrCode error = BV_ErrCode_Ok;
3047 77 N_word bits = BV_BITS_(U);
3048 77 N_word size = BV_SIZE_(U);
3049 77 N_word mask = BV_MASK_(U);
3050 77 N_word msb = (mask AND NOT (mask >> 1));
3051 bv_listptr L;
3052 boolean minus;
3053 boolean carry;
3054 boolean sgn_q;
3055 boolean sgn_r;
3056 boolean sgn_a;
3057 boolean sgn_b;
3058 boolean sgn_x;
3059 boolean sgn_y;
3060 wordptr Q;
3061 wordptr R;
3062 wordptr A;
3063 wordptr B;
3064 wordptr T;
3065 wordptr X1;
3066 wordptr X2;
3067 wordptr X3;
3068 wordptr Y1;
3069 wordptr Y2;
3070 wordptr Y3;
3071 wordptr Z;
3072  
3073 /*
3074 Requirements:
3075 - All bit vectors must have equal sizes
3076 - U, V, and W must all be distinct bit vectors
3077 Features:
3078 - The contents of X and Y are preserved
3079 - U, V and W may be identical with X or Y (or both,
3080 provided that U, V and W are mutually distinct)
3081 (i.e., in-place is possible!)
3082 - GCD(0,z) == GCD(z,0) == z
3083 - negative values are handled correctly
3084 */
3085  
3086 77 ▶ if ((bits != BV_BITS_(V)) or
Branch: 1 branch
BranchTrueFalseTotal
if ((bits != BV_BITS_(V)) or 77 0 77
3087 77 ▶ (bits != BV_BITS_(W)) or
Branch: 1 branch
BranchTrueFalseTotal
(bits != BV_BITS_(W)) or 77 0 77
3088 77 ▶ (bits != BV_BITS_(X)) or
Branch: 1 branch
BranchTrueFalseTotal
(bits != BV_BITS_(X)) or 77 0 77
3089 77 ▶ (bits != BV_BITS_(Y)))
Branch: 1 branch
BranchTrueFalseTotal
(bits != BV_BITS_(Y))) 0 77 77
3090 {
3091 0 return(BV_ErrCode_Size);
3092 }
3093 77 ▶ if ((U == V) or (U == W) or (V == W))
Branch: 3 branches
BranchTrueFalseTotal
if ((U == V) or (U == W) or (V == W)) 77 0 77
if ((U == V) or (U == W) or (V == W)) 77 0 77
if ((U == V) or (U == W) or (V == W)) 0 77 77
3094 {
3095 0 return(BV_ErrCode_Same);
3096 }
3097 77 ▶ if ((bits == 0) or (size == 0))
Branch: 2 branches
BranchTrueFalseTotal
if ((bits == 0) or (size == 0)) 77 0 77
if ((bits == 0) or (size == 0)) 0 77 77
3098 {
3099 0 return(BV_ErrCode_Ok);
3100 }
3101 77 ▶ if (BitVector_is_empty(X))
Branch: 1 branch
BranchTrueFalseTotal
if (BitVector_is_empty(X)) 9 68 77
3102 {
3103 9 ▶ if (U != Y) BitVector_Copy(U,Y);
Branch: 1 branch
BranchTrueFalseTotal
if (U != Y) BitVector_Copy(U,Y); 9 0 9
3104 9 BitVector_Empty(V);
3105 9 BitVector_Empty(W);
3106 9 ▶ if (BV_SIZE_(W)) *W = 1;
Branch: 1 branch
BranchTrueFalseTotal
if (BV_SIZE_(W)) *W = 1; 9 0 9
3107 9 return(BV_ErrCode_Ok);
3108 }
3109 68 ▶ if (BitVector_is_empty(Y))
Branch: 1 branch
BranchTrueFalseTotal
if (BitVector_is_empty(Y)) 8 60 68
3110 {
3111 8 ▶ if (U != X) BitVector_Copy(U,X);
Branch: 1 branch
BranchTrueFalseTotal
if (U != X) BitVector_Copy(U,X); 8 0 8
3112 8 BitVector_Empty(V);
3113 8 BitVector_Empty(W);
3114 8 ▶ if (BV_SIZE_(V)) *V = 1;
Branch: 1 branch
BranchTrueFalseTotal
if (BV_SIZE_(V)) *V = 1; 8 0 8
3115 8 return(BV_ErrCode_Ok);
3116 }
3117 60 ▶ if ((L = BitVector_Create_List(bits,false,11)) == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if ((L = BitVector_Create_List(bits,false,11)) == NULL) 0 60 60
3118 {
3119 0 return(BV_ErrCode_Null);
3120 }
3121 60 Q = L[0];
3122 60 R = L[1];
3123 60 A = L[2];
3124 60 B = L[3];
3125 60 X1 = L[4];
3126 60 X2 = L[5];
3127 60 X3 = L[6];
3128 60 Y1 = L[7];
3129 60 Y2 = L[8];
3130 60 Y3 = L[9];
3131 60 Z = L[10];
3132 60 size--;
3133 60 sgn_a = (((*(X+size) &= mask) AND msb) != 0);
3134 60 sgn_b = (((*(Y+size) &= mask) AND msb) != 0);
3135 60 ▶ if (sgn_a) BitVector_Negate(A,X); else BitVector_Copy(A,X);
Branch: 1 branch
BranchTrueFalseTotal
if (sgn_a) BitVector_Negate(A,X); else BitVector_Copy(A,X); 30 30 60
3136 60 ▶ if (sgn_b) BitVector_Negate(B,Y); else BitVector_Copy(B,Y);
Branch: 1 branch
BranchTrueFalseTotal
if (sgn_b) BitVector_Negate(B,Y); else BitVector_Copy(B,Y); 30 30 60
3137 60 BitVector_Empty(X1);
3138 60 BitVector_Empty(X2);
3139 60 *X1 = 1;
3140 60 BitVector_Empty(Y1);
3141 60 BitVector_Empty(Y2);
3142 60 *Y2 = 1;
3143 60 sgn_x = false;
3144 60 sgn_y = false;
3145 200 ▶ while (not error)
Branch: 1 branch
BranchTrueFalseTotal
while (not error) 200 0 200
3146 {
3147 200 ▶ if ((error = BitVector_Div_Pos(Q,A,B,R)))
Branch: 1 branch
BranchTrueFalseTotal
if ((error = BitVector_Div_Pos(Q,A,B,R))) 0 200 200
3148 {
3149 0 break;
3150 }
3151 200 ▶ if (BitVector_is_empty(R))
Branch: 1 branch
BranchTrueFalseTotal
if (BitVector_is_empty(R)) 60 140 200
3152 {
3153 60 break;
3154 }
3155 140 sgn_q = sgn_a XOR sgn_b;
3156  
3157 140 ▶ if (sgn_x) BitVector_Negate(Z,X2); else BitVector_Copy(Z,X2);
Branch: 1 branch
BranchTrueFalseTotal
if (sgn_x) BitVector_Negate(Z,X2); else BitVector_Copy(Z,X2); 18 122 140
3158 140 ▶ if ((error = BitVector_Mul_Pos(X3,Z,Q,true)))
Branch: 1 branch
BranchTrueFalseTotal
if ((error = BitVector_Mul_Pos(X3,Z,Q,true))) 0 140 140
3159 {
3160 0 break;
3161 }
3162 140 minus = not (sgn_x XOR sgn_q);
3163 140 carry = 0;
3164 140 ▶ if (BitVector_compute(X3,X1,X3,minus,&carry))
Branch: 1 branch
BranchTrueFalseTotal
if (BitVector_compute(X3,X1,X3,minus,&carry)) 0 140 140
3165 {
3166 0 error = BV_ErrCode_Ovfl;
3167 0 break;
3168 }
3169 140 sgn_x = (((*(X3+size) &= mask) AND msb) != 0);
3170  
3171 140 ▶ if (sgn_y) BitVector_Negate(Z,Y2); else BitVector_Copy(Z,Y2);
Branch: 1 branch
BranchTrueFalseTotal
if (sgn_y) BitVector_Negate(Z,Y2); else BitVector_Copy(Z,Y2); 18 122 140
3172 140 ▶ if ((error = BitVector_Mul_Pos(Y3,Z,Q,true)))
Branch: 1 branch
BranchTrueFalseTotal
if ((error = BitVector_Mul_Pos(Y3,Z,Q,true))) 0 140 140
3173 {
3174 0 break;
3175 }
3176 140 minus = not (sgn_y XOR sgn_q);
3177 140 carry = 0;
3178 140 ▶ if (BitVector_compute(Y3,Y1,Y3,minus,&carry))
Branch: 1 branch
BranchTrueFalseTotal
if (BitVector_compute(Y3,Y1,Y3,minus,&carry)) 0 140 140
3179 {
3180 0 error = BV_ErrCode_Ovfl;
3181 0 break;
3182 }
3183 140 sgn_y = (((*(Y3+size) &= mask) AND msb) != 0);
3184  
3185 140 T = A; sgn_r = sgn_a;
3186 140 A = B; sgn_a = sgn_b;
3187 140 B = R; sgn_b = sgn_r;
3188 140 R = T;
3189  
3190 140 T = X1;
3191 140 X1 = X2;
3192 140 X2 = X3;
3193 140 X3 = T;
3194  
3195 140 T = Y1;
3196 140 Y1 = Y2;
3197 140 Y2 = Y3;
3198 140 Y3 = T;
3199 }
3200 60 ▶ if (not error)
Branch: 1 branch
BranchTrueFalseTotal
if (not error) 60 0 60
3201 {
3202 60 ▶ if (sgn_b) BitVector_Negate(U,B); else BitVector_Copy(U,B);
Branch: 1 branch
BranchTrueFalseTotal
if (sgn_b) BitVector_Negate(U,B); else BitVector_Copy(U,B); 30 30 60
3203 60 BitVector_Copy(V,X2);
3204 60 BitVector_Copy(W,Y2);
3205 }
3206 60 BitVector_Destroy_List(L,11);
3207 60 return(error);
3208 }
3209  
3210 5 BV_ErrCode BitVector_Power(wordptr X, wordptr Y, wordptr Z)
3211 {
3212 5 BV_ErrCode error = BV_ErrCode_Ok;
3213 5 N_word bits = BV_BITS_(X);
3214 5 boolean first = true;
3215 Z_long last;
3216 N_word limit;
3217 N_word count;
3218 wordptr T;
3219  
3220 /*
3221 Requirements:
3222 - X must have at least the same size as Y but may be larger (!)
3223 - X may not be identical with Z
3224 - Z must be positive
3225 Features:
3226 - The contents of Y and Z are preserved
3227 */
3228  
3229 5 ▶ if (X == Z) return(BV_ErrCode_Same);
Branch: 1 branch
BranchTrueFalseTotal
if (X == Z) return(BV_ErrCode_Same); 1 4 5
3230 4 ▶ if (bits < BV_BITS_(Y)) return(BV_ErrCode_Size);
Branch: 1 branch
BranchTrueFalseTotal
if (bits < BV_BITS_(Y)) return(BV_ErrCode_Size); 1 3 4
3231 3 ▶ if (BitVector_msb_(Z)) return(BV_ErrCode_Expo);
Branch: 1 branch
BranchTrueFalseTotal
if (BitVector_msb_(Z)) return(BV_ErrCode_Expo); 0 3 3
3232 3 ▶ if ((last = Set_Max(Z)) < 0L)
Branch: 1 branch
BranchTrueFalseTotal
if ((last = Set_Max(Z)) < 0L) 1 2 3
3233 {
3234 1 ▶ if (bits < 2) return(BV_ErrCode_Ovfl);
Branch: 1 branch
BranchTrueFalseTotal
if (bits < 2) return(BV_ErrCode_Ovfl); 0 1 1
3235 1 BitVector_Empty(X);
3236 1 *X |= BV_LSB;
3237 1 return(BV_ErrCode_Ok); /* anything ^ 0 == 1 */
3238 }
3239 2 ▶ if (BitVector_is_empty(Y))
Branch: 1 branch
BranchTrueFalseTotal
if (BitVector_is_empty(Y)) 1 1 2
3240 {
3241 1 ▶ if (X != Y) BitVector_Empty(X);
Branch: 1 branch
BranchTrueFalseTotal
if (X != Y) BitVector_Empty(X); 1 0 1
3242 1 return(BV_ErrCode_Ok); /* 0 ^ anything not zero == 0 */
3243 }
3244 1 T = BitVector_Create(bits,false);
3245 1 ▶ if (T == NULL) return(BV_ErrCode_Null);
Branch: 1 branch
BranchTrueFalseTotal
if (T == NULL) return(BV_ErrCode_Null); 0 1 1
3246 1 limit = (N_word) last;
3247 2 ▶ for ( count = 0; ((!error) and (count <= limit)); count++ )
Branch: 2 branches
BranchTrueFalseTotal
for ( count = 0; ((!error) and (count <= limit)); count++ ) 2 0 2
for ( count = 0; ((!error) and (count <= limit)); count++ ) 1 1 2
3248 {
3249 1 ▶ if ( BIT_VECTOR_TST_BIT(Z,count) )
Branch: 1 branch
BranchTrueFalseTotal
if ( BIT_VECTOR_TST_BIT(Z,count) ) 1 0 1
3250 {
3251 1 ▶ if (first)
Branch: 1 branch
BranchTrueFalseTotal
if (first) 1 0 1
3252 {
3253 1 first = false;
3254 1 ▶ if (count) { BitVector_Copy(X,T); }
Branch: 1 branch
BranchTrueFalseTotal
if (count) { BitVector_Copy(X,T); } 0 1 1
3255 1 ▶ else { if (X != Y) BitVector_Copy(X,Y); }
Branch: 1 branch
BranchTrueFalseTotal
else { if (X != Y) BitVector_Copy(X,Y); } 1 0 1
3256 }
3257 0 else error = BitVector_Multiply(X,T,X); /* order important because T > X */
3258 }
3259 1 ▶ if ((!error) and (count < limit))
Branch: 2 branches
BranchTrueFalseTotal
if ((!error) and (count < limit)) 1 0 1
if ((!error) and (count < limit)) 0 1 1
3260 {
3261 0 ▶ if (count) error = BitVector_Multiply(T,T,T);
Branch: 1 branch
BranchTrueFalseTotal
if (count) error = BitVector_Multiply(T,T,T); 0 0 0
3262 0 else error = BitVector_Multiply(T,Y,Y);
3263 }
3264 }
3265 1 BitVector_Destroy(T);
3266 1 return(error);
3267 }
3268  
3269 3766 void BitVector_Block_Store(wordptr addr, charptr buffer, N_int length)
3270 {
3271 3766 N_word size = BV_SIZE_(addr);
3272 3766 N_word mask = BV_MASK_(addr);
3273 N_word value;
3274 N_word count;
3275  
3276 /* provide translation for independence of endian-ness: */
3277 3766 ▶ if (size > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (size > 0) 3763 3 3766
3278 {
3279 115655 ▶ while (size-- > 0)
Branch: 1 branch
BranchTrueFalseTotal
while (size-- > 0) 111892 3763 115655
3280 {
3281 111892 value = 0;
3282 1006904 ▶ for ( count = 0; (length > 0) and (count < BV_WordBits); count += 8 )
Branch: 2 branches
BranchTrueFalseTotal
for ( count = 0; (length > 0) and (count < BV_WordBits); count += 8 ) 1003126 3778 1006904
for ( count = 0; (length > 0) and (count < BV_WordBits); count += 8 ) 895012 108114 1003126
3283 {
3284 895012 value |= (((N_word) *buffer++) << count); length--;
3285 }
3286 111892 *addr++ = value;
3287 }
3288 3763 *(--addr) &= mask;
3289 }
3290 3766 }
3291  
3292 3766 charptr BitVector_Block_Read(wordptr addr, N_intptr length)
3293 {
3294 3766 N_word size = BV_SIZE_(addr);
3295 N_word value;
3296 N_word count;
3297 charptr buffer;
3298 charptr target;
3299  
3300 /* provide translation for independence of endian-ness: */
3301 3766 *length = size << BV_Factor;
3302 3766 buffer = (charptr) malloc((size_t) ((*length)+1));
3303 3766 ▶ if (buffer == NULL) return(NULL);
Branch: 1 branch
BranchTrueFalseTotal
if (buffer == NULL) return(NULL); 0 3766 3766
3304 3766 target = buffer;
3305 3766 ▶ if (size > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (size > 0) 3763 3 3766
3306 {
3307 3763 *(addr+size-1) &= BV_MASK_(addr);
3308 115655 ▶ while (size-- > 0)
Branch: 1 branch
BranchTrueFalseTotal
while (size-- > 0) 111892 3763 115655
3309 {
3310 111892 value = *addr++;
3311 111892 count = BV_WordBits >> 3;
3312 1007028 ▶ while (count-- > 0)
Branch: 1 branch
BranchTrueFalseTotal
while (count-- > 0) 895136 111892 1007028
3313 {
3314 895136 *target++ = (N_char) (value AND 0x00FF);
3315 895136 ▶ if (count > 0) value >>= 8;
Branch: 1 branch
BranchTrueFalseTotal
if (count > 0) value >>= 8; 783244 111892 895136
3316 }
3317 }
3318 }
3319 3766 *target = (N_char) '\0';
3320 3766 return(buffer);
3321 }
3322  
3323 5347 void BitVector_Word_Store(wordptr addr, N_int offset, N_int value)
3324 {
3325 5347 N_word size = BV_SIZE_(addr);
3326  
3327 5347 ▶ if (size > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (size > 0) 5347 0 5347
3328 {
3329 5347 ▶ if (offset < size) *(addr+offset) = value;
Branch: 1 branch
BranchTrueFalseTotal
if (offset < size) *(addr+offset) = value; 5347 0 5347
3330 5347 *(addr+size-1) &= BV_MASK_(addr);
3331 }
3332 5347 }
3333  
3334 5384 N_int BitVector_Word_Read(wordptr addr, N_int offset)
3335 {
3336 5384 N_word size = BV_SIZE_(addr);
3337  
3338 5384 ▶ if (size > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (size > 0) 5384 0 5384
3339 {
3340 5384 *(addr+size-1) &= BV_MASK_(addr);
3341 5384 ▶ if (offset < size) return( *(addr+offset) );
Branch: 1 branch
BranchTrueFalseTotal
if (offset < size) return( *(addr+offset) ); 5384 0 5384
3342 }
3343 0 return( (N_int) 0 );
3344 }
3345  
3346 2514 void BitVector_Word_Insert(wordptr addr, N_int offset, N_int count,
3347 boolean clear)
3348 {
3349 2514 N_word size = BV_SIZE_(addr);
3350 2514 N_word mask = BV_MASK_(addr);
3351 2514 wordptr last = addr+size-1;
3352  
3353 2514 ▶ if (size > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (size > 0) 2514 0 2514
3354 {
3355 2514 *last &= mask;
3356 2514 ▶ if (offset > size) offset = size;
Branch: 1 branch
BranchTrueFalseTotal
if (offset > size) offset = size; 0 2514 2514
3357 2514 BIT_VECTOR_ins_words(addr+offset,size-offset,count,clear);
3358 2514 *last &= mask;
3359 }
3360 2514 }
3361  
3362 2514 void BitVector_Word_Delete(wordptr addr, N_int offset, N_int count,
3363 boolean clear)
3364 {
3365 2514 N_word size = BV_SIZE_(addr);
3366 2514 N_word mask = BV_MASK_(addr);
3367 2514 wordptr last = addr+size-1;
3368  
3369 2514 ▶ if (size > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (size > 0) 2514 0 2514
3370 {
3371 2514 *last &= mask;
3372 2514 ▶ if (offset > size) offset = size;
Branch: 1 branch
BranchTrueFalseTotal
if (offset > size) offset = size; 0 2514 2514
3373 2514 BIT_VECTOR_del_words(addr+offset,size-offset,count,clear);
3374 2514 *last &= mask;
3375 }
3376 2514 }
3377  
3378 19353 void BitVector_Chunk_Store(wordptr addr, N_int chunksize, N_int offset,
3379 N_long value)
3380 {
3381 19353 N_word bits = BV_BITS_(addr);
3382 N_word mask;
3383 N_word temp;
3384  
3385 19353 ▶ if ((chunksize > 0) and (offset < bits))
Branch: 2 branches
BranchTrueFalseTotal
if ((chunksize > 0) and (offset < bits)) 19353 0 19353
if ((chunksize > 0) and (offset < bits)) 19353 0 19353
3386 {
3387 19353 ▶ if (chunksize > BV_LongBits) chunksize = BV_LongBits;
Branch: 1 branch
BranchTrueFalseTotal
if (chunksize > BV_LongBits) chunksize = BV_LongBits; 0 19353 19353
3388 19353 ▶ if ((offset + chunksize) > bits) chunksize = bits - offset;
Branch: 1 branch
BranchTrueFalseTotal
if ((offset + chunksize) > bits) chunksize = bits - offset; 253 19100 19353
3389 19353 addr += offset >> BV_LogBits;
3390 19353 offset &= BV_ModMask;
3391 41898 ▶ while (chunksize > 0)
Branch: 1 branch
BranchTrueFalseTotal
while (chunksize > 0) 22545 19353 41898
3392 {
3393 22545 mask = (N_word) (~0L << offset);
3394 22545 bits = offset + chunksize;
3395 22545 ▶ if (bits < BV_WordBits)
Branch: 1 branch
BranchTrueFalseTotal
if (bits < BV_WordBits) 18704 3841 22545
3396 {
3397 18704 mask &= (N_word) ~(~0L << bits);
3398 18704 bits = chunksize;
3399 }
3400 3841 else bits = BV_WordBits - offset;
3401 22545 temp = (N_word) (value << offset);
3402 22545 temp &= mask;
3403 22545 *addr &= NOT mask;
3404 22545 *addr++ |= temp;
3405 22545 value >>= bits;
3406 22545 chunksize -= bits;
3407 22545 offset = 0;
3408 }
3409 }
3410 19353 }
3411  
3412 19353 N_long BitVector_Chunk_Read(wordptr addr, N_int chunksize, N_int offset)
3413 {
3414 19353 N_word bits = BV_BITS_(addr);
3415 19353 N_word chunkbits = 0;
3416 19353 N_long value = 0L;
3417 N_long temp;
3418 N_word mask;
3419  
3420 19353 ▶ if ((chunksize > 0) and (offset < bits))
Branch: 2 branches
BranchTrueFalseTotal
if ((chunksize > 0) and (offset < bits)) 19353 0 19353
if ((chunksize > 0) and (offset < bits)) 19353 0 19353
3421 {
3422 19353 ▶ if (chunksize > BV_LongBits) chunksize = BV_LongBits;
Branch: 1 branch
BranchTrueFalseTotal
if (chunksize > BV_LongBits) chunksize = BV_LongBits; 0 19353 19353
3423 19353 ▶ if ((offset + chunksize) > bits) chunksize = bits - offset;
Branch: 1 branch
BranchTrueFalseTotal
if ((offset + chunksize) > bits) chunksize = bits - offset; 253 19100 19353
3424 19353 addr += offset >> BV_LogBits;
3425 19353 offset &= BV_ModMask;
3426 41898 ▶ while (chunksize > 0)
Branch: 1 branch
BranchTrueFalseTotal
while (chunksize > 0) 22545 19353 41898
3427 {
3428 22545 bits = offset + chunksize;
3429 22545 ▶ if (bits < BV_WordBits)
Branch: 1 branch
BranchTrueFalseTotal
if (bits < BV_WordBits) 18704 3841 22545
3430 {
3431 18704 mask = (N_word) ~(~0L << bits);
3432 18704 bits = chunksize;
3433 }
3434 else
3435 {
3436 3841 mask = (N_word) ~0L;
3437 3841 bits = BV_WordBits - offset;
3438 }
3439 22545 temp = (N_long) ((*addr++ AND mask) >> offset);
3440 22545 value |= temp << chunkbits;
3441 22545 chunkbits += bits;
3442 22545 chunksize -= bits;
3443 22545 offset = 0;
3444 }
3445 }
3446 19353 return(value);
3447 }
3448  
3449 /*******************/
3450 /* set operations: */
3451 /*******************/
3452  
3453 1059 void Set_Union(wordptr X, wordptr Y, wordptr Z) /* X = Y + Z */
3454 {
3455 1059 N_word bits = BV_BITS_(X);
3456 1059 N_word size = BV_SIZE_(X);
3457 1059 N_word mask = BV_MASK_(X);
3458  
3459 1059 ▶ if ((size > 0) and (bits == BV_BITS_(Y)) and (bits == BV_BITS_(Z)))
Branch: 3 branches
BranchTrueFalseTotal
if ((size > 0) and (bits == BV_BITS_(Y)) and (bits == BV_BITS_(Z))) 1059 0 1059
if ((size > 0) and (bits == BV_BITS_(Y)) and (bits == BV_BITS_(Z))) 1059 0 1059
if ((size > 0) and (bits == BV_BITS_(Y)) and (bits == BV_BITS_(Z))) 1059 0 1059
3460 {
3461 17963 ▶ while (size-- > 0) *X++ = *Y++ OR *Z++;
Branch: 1 branch
BranchTrueFalseTotal
while (size-- > 0) *X++ = *Y++ OR *Z++; 16904 1059 17963
3462 1059 *(--X) &= mask;
3463 }
3464 1059 }
3465  
3466 53 void Set_Intersection(wordptr X, wordptr Y, wordptr Z) /* X = Y * Z */
3467 {
3468 53 N_word bits = BV_BITS_(X);
3469 53 N_word size = BV_SIZE_(X);
3470 53 N_word mask = BV_MASK_(X);
3471  
3472 53 ▶ if ((size > 0) and (bits == BV_BITS_(Y)) and (bits == BV_BITS_(Z)))
Branch: 3 branches
BranchTrueFalseTotal
if ((size > 0) and (bits == BV_BITS_(Y)) and (bits == BV_BITS_(Z))) 53 0 53
if ((size > 0) and (bits == BV_BITS_(Y)) and (bits == BV_BITS_(Z))) 53 0 53
if ((size > 0) and (bits == BV_BITS_(Y)) and (bits == BV_BITS_(Z))) 53 0 53
3473 {
3474 901 ▶ while (size-- > 0) *X++ = *Y++ AND *Z++;
Branch: 1 branch
BranchTrueFalseTotal
while (size-- > 0) *X++ = *Y++ AND *Z++; 848 53 901
3475 53 *(--X) &= mask;
3476 }
3477 53 }
3478  
3479 1672 void Set_Difference(wordptr X, wordptr Y, wordptr Z) /* X = Y \ Z */
3480 {
3481 1672 N_word bits = BV_BITS_(X);
3482 1672 N_word size = BV_SIZE_(X);
3483 1672 N_word mask = BV_MASK_(X);
3484  
3485 1672 ▶ if ((size > 0) and (bits == BV_BITS_(Y)) and (bits == BV_BITS_(Z)))
Branch: 3 branches
BranchTrueFalseTotal
if ((size > 0) and (bits == BV_BITS_(Y)) and (bits == BV_BITS_(Z))) 1672 0 1672
if ((size > 0) and (bits == BV_BITS_(Y)) and (bits == BV_BITS_(Z))) 1672 0 1672
if ((size > 0) and (bits == BV_BITS_(Y)) and (bits == BV_BITS_(Z))) 1672 0 1672
3486 {
3487 28392 ▶ while (size-- > 0) *X++ = *Y++ AND NOT *Z++;
Branch: 1 branch
BranchTrueFalseTotal
while (size-- > 0) *X++ = *Y++ AND NOT *Z++; 26720 1672 28392
3488 1672 *(--X) &= mask;
3489 }
3490 1672 }
3491  
3492 49 void Set_ExclusiveOr(wordptr X, wordptr Y, wordptr Z) /* X=(Y+Z)\(Y*Z) */
3493 {
3494 49 N_word bits = BV_BITS_(X);
3495 49 N_word size = BV_SIZE_(X);
3496 49 N_word mask = BV_MASK_(X);
3497  
3498 49 ▶ if ((size > 0) and (bits == BV_BITS_(Y)) and (bits == BV_BITS_(Z)))
Branch: 3 branches
BranchTrueFalseTotal
if ((size > 0) and (bits == BV_BITS_(Y)) and (bits == BV_BITS_(Z))) 49 0 49
if ((size > 0) and (bits == BV_BITS_(Y)) and (bits == BV_BITS_(Z))) 49 0 49
if ((size > 0) and (bits == BV_BITS_(Y)) and (bits == BV_BITS_(Z))) 49 0 49
3499 {
3500 2849 ▶ while (size-- > 0) *X++ = *Y++ XOR *Z++;
Branch: 1 branch
BranchTrueFalseTotal
while (size-- > 0) *X++ = *Y++ XOR *Z++; 2800 49 2849
3501 49 *(--X) &= mask;
3502 }
3503 49 }
3504  
3505 20 void Set_Complement(wordptr X, wordptr Y) /* X = ~Y */
3506 {
3507 20 N_word size = BV_SIZE_(X);
3508 20 N_word mask = BV_MASK_(X);
3509  
3510 20 ▶ if ((size > 0) and (BV_BITS_(X) == BV_BITS_(Y)))
Branch: 2 branches
BranchTrueFalseTotal
if ((size > 0) and (BV_BITS_(X) == BV_BITS_(Y))) 20 0 20
if ((size > 0) and (BV_BITS_(X) == BV_BITS_(Y))) 20 0 20
3511 {
3512 2931 ▶ while (size-- > 0) *X++ = NOT *Y++;
Branch: 1 branch
BranchTrueFalseTotal
while (size-- > 0) *X++ = NOT *Y++; 2911 20 2931
3513 20 *(--X) &= mask;
3514 }
3515 20 }
3516  
3517 /******************/
3518 /* set functions: */
3519 /******************/
3520  
3521 5519 boolean Set_subset(wordptr X, wordptr Y) /* X subset Y ? */
3522 {
3523 5519 N_word size = BV_SIZE_(X);
3524 5519 boolean r = false;
3525  
3526 5519 ▶ if ((size > 0) and (BV_BITS_(X) == BV_BITS_(Y)))
Branch: 2 branches
BranchTrueFalseTotal
if ((size > 0) and (BV_BITS_(X) == BV_BITS_(Y))) 5519 0 5519
if ((size > 0) and (BV_BITS_(X) == BV_BITS_(Y))) 5519 0 5519
3527 {
3528 5519 r = true;
3529 13533 ▶ while (r and (size-- > 0)) r = ((*X++ AND NOT *Y++) == 0);
Branch: 2 branches
BranchTrueFalseTotal
while (r and (size-- > 0)) r = ((*X++ AND NOT *Y++) == 0); 9139 4394 13533
while (r and (size-- > 0)) r = ((*X++ AND NOT *Y++) == 0); 8014 1125 9139
3530 }
3531 5519 return(r);
3532 }
3533  
3534 8998 N_int Set_Norm(wordptr addr) /* = | X | */
3535 {
3536 byteptr byte;
3537 N_word bytes;
3538 N_int n;
3539  
3540 8998 byte = (byteptr) addr;
3541 8998 bytes = BV_SIZE_(addr) << BV_Factor;
3542 8998 n = 0;
3543 5516670 ▶ while (bytes-- > 0)
Branch: 1 branch
BranchTrueFalseTotal
while (bytes-- > 0) 5507672 8998 5516670
3544 {
3545 5507672 n += BV_ByteNorm[*byte++];
3546 }
3547 8998 return(n);
3548 }
3549  
3550 0 N_int Set_Norm2(wordptr addr) /* = | X | */
3551 {
3552 0 N_word size = BV_SIZE_(addr);
3553 N_word w0,w1;
3554 N_int n,k;
3555  
3556 0 n = 0;
3557 0 ▶ while (size-- > 0)
Branch: 1 branch
BranchTrueFalseTotal
while (size-- > 0) 0 0 0
3558 {
3559 0 k = 0;
3560 0 w1 = NOT (w0 = *addr++);
3561 0 ▶ while (w0 and w1)
Branch: 2 branches
BranchTrueFalseTotal
while (w0 and w1) 0 0 0
while (w0 and w1) 0 0 0
3562 {
3563 0 w0 &= w0 - 1;
3564 0 w1 &= w1 - 1;
3565 0 k++;
3566 }
3567 0 ▶ if (w0 == 0) n += k;
Branch: 1 branch
BranchTrueFalseTotal
if (w0 == 0) n += k; 0 0 0
3568 0 else n += BV_WordBits - k;
3569 }
3570 0 return(n);
3571 }
3572  
3573 0 N_int Set_Norm3(wordptr addr) /* = | X | */
3574 {
3575 0 N_word size = BV_SIZE_(addr);
3576 0 N_int count = 0;
3577 N_word c;
3578  
3579 0 ▶ while (size-- > 0)
Branch: 1 branch
BranchTrueFalseTotal
while (size-- > 0) 0 0 0
3580 {
3581 0 c = *addr++;
3582 0 ▶ while (c)
Branch: 1 branch
BranchTrueFalseTotal
while (c) 0 0 0
3583 {
3584 0 c &= c - 1;
3585 0 count++;
3586 }
3587 }
3588 0 return(count);
3589 }
3590  
3591 760 Z_long Set_Min(wordptr addr) /* = min(X) */
3592 {
3593 760 boolean empty = true;
3594 760 N_word size = BV_SIZE_(addr);
3595 760 N_word i = 0;
3596 760 N_word c = 0; /* silence compiler warning */
3597  
3598 290821 ▶ while (empty and (size-- > 0))
Branch: 2 branches
BranchTrueFalseTotal
while (empty and (size-- > 0)) 290791 30 290821
while (empty and (size-- > 0)) 290061 730 290791
3599 {
3600 290061 ▶ if ((c = *addr++)) empty = false; else i++;
Branch: 1 branch
BranchTrueFalseTotal
if ((c = *addr++)) empty = false; else i++; 30 290031 290061
3601 }
3602 760 ▶ if (empty) return((Z_long) LONG_MAX); /* plus infinity */
Branch: 1 branch
BranchTrueFalseTotal
if (empty) return((Z_long) LONG_MAX); /* plus infinity */ 730 30 760
3603 30 i <<= BV_LogBits;
3604 127 ▶ while (not (c AND BV_LSB))
Branch: 1 branch
BranchTrueFalseTotal
while (not (c AND BV_LSB)) 97 30 127
3605 {
3606 97 c >>= 1;
3607 97 i++;
3608 }
3609 30 return((Z_long) i);
3610 }
3611  
3612 3494 Z_long Set_Max(wordptr addr) /* = max(X) */
3613 {
3614 3494 boolean empty = true;
3615 3494 N_word size = BV_SIZE_(addr);
3616 3494 N_word i = size;
3617 3494 N_word c = 0; /* silence compiler warning */
3618  
3619 3494 addr += size-1;
3620 300459 ▶ while (empty and (size-- > 0))
Branch: 2 branches
BranchTrueFalseTotal
while (empty and (size-- > 0)) 297724 2735 300459
while (empty and (size-- > 0)) 296965 759 297724
3621 {
3622 296965 ▶ if ((c = *addr--)) empty = false; else i--;
Branch: 1 branch
BranchTrueFalseTotal
if ((c = *addr--)) empty = false; else i--; 2735 294230 296965
3623 }
3624 3494 ▶ if (empty) return((Z_long) LONG_MIN); /* minus infinity */
Branch: 1 branch
BranchTrueFalseTotal
if (empty) return((Z_long) LONG_MIN); /* minus infinity */ 759 2735 3494
3625 2735 i <<= BV_LogBits;
3626 107061 ▶ while (not (c AND BV_MSB))
Branch: 1 branch
BranchTrueFalseTotal
while (not (c AND BV_MSB)) 104326 2735 107061
3627 {
3628 104326 c <<= 1;
3629 104326 i--;
3630 }
3631 2735 return((Z_long) --i);
3632 }
3633  
3634 /**********************************/
3635 /* matrix-of-booleans operations: */
3636 /**********************************/
3637  
3638 2 void Matrix_Multiplication(wordptr X, N_int rowsX, N_int colsX,
3639 wordptr Y, N_int rowsY, N_int colsY,
3640 wordptr Z, N_int rowsZ, N_int colsZ)
3641 {
3642 N_word i;
3643 N_word j;
3644 N_word k;
3645 N_word indxX;
3646 N_word indxY;
3647 N_word indxZ;
3648 N_word termX;
3649 N_word termY;
3650 N_word sum;
3651  
3652 2 ▶ if ((colsY == rowsZ) and (rowsX == rowsY) and (colsX == colsZ) and
Branch: 3 branches
BranchTrueFalseTotal
if ((colsY == rowsZ) and (rowsX == rowsY) and (colsX == colsZ) and 2 0 2
if ((colsY == rowsZ) and (rowsX == rowsY) and (colsX == colsZ) and 2 0 2
if ((colsY == rowsZ) and (rowsX == rowsY) and (colsX == colsZ) and 2 0 2
3653 2 ▶ (BV_BITS_(X) == rowsX*colsX) and
Branch: 1 branch
BranchTrueFalseTotal
(BV_BITS_(X) == rowsX*colsX) and 2 0 2
3654 2 ▶ (BV_BITS_(Y) == rowsY*colsY) and
Branch: 1 branch
BranchTrueFalseTotal
(BV_BITS_(Y) == rowsY*colsY) and 2 0 2
3655 2 ▶ (BV_BITS_(Z) == rowsZ*colsZ))
Branch: 1 branch
BranchTrueFalseTotal
(BV_BITS_(Z) == rowsZ*colsZ)) 2 0 2
3656 {
3657 66 ▶ for ( i = 0; i < rowsY; i++ )
Branch: 1 branch
BranchTrueFalseTotal
for ( i = 0; i < rowsY; i++ ) 64 2 66
3658 {
3659 64 termX = i * colsX;
3660 64 termY = i * colsY;
3661 2112 ▶ for ( j = 0; j < colsZ; j++ )
Branch: 1 branch
BranchTrueFalseTotal
for ( j = 0; j < colsZ; j++ ) 2048 64 2112
3662 {
3663 2048 indxX = termX + j;
3664 2048 sum = 0;
3665 67584 ▶ for ( k = 0; k < colsY; k++ )
Branch: 1 branch
BranchTrueFalseTotal
for ( k = 0; k < colsY; k++ ) 65536 2048 67584
3666 {
3667 65536 indxY = termY + k;
3668 65536 indxZ = k * colsZ + j;
3669 65536 ▶ if ( BIT_VECTOR_TST_BIT(Y,indxY) &&
Branch: 1 branch
BranchTrueFalseTotal
if ( BIT_VECTOR_TST_BIT(Y,indxY) && 64 65472 65536
3670 64 ▶ BIT_VECTOR_TST_BIT(Z,indxZ) ) sum ^= 1;
Branch: 1 branch
BranchTrueFalseTotal
BIT_VECTOR_TST_BIT(Z,indxZ) ) sum ^= 1; 2 62 64
3671 }
3672 2048 ▶ if (sum) BIT_VECTOR_SET_BIT(X,indxX)
Branch: 1 branch
BranchTrueFalseTotal
if (sum) BIT_VECTOR_SET_BIT(X,indxX) 2 2046 2048
3673 2046 else BIT_VECTOR_CLR_BIT(X,indxX)
3674 }
3675 }
3676 }
3677 2 }
3678  
3679 2 void Matrix_Product(wordptr X, N_int rowsX, N_int colsX,
3680 wordptr Y, N_int rowsY, N_int colsY,
3681 wordptr Z, N_int rowsZ, N_int colsZ)
3682 {
3683 N_word i;
3684 N_word j;
3685 N_word k;
3686 N_word indxX;
3687 N_word indxY;
3688 N_word indxZ;
3689 N_word termX;
3690 N_word termY;
3691 N_word sum;
3692  
3693 2 ▶ if ((colsY == rowsZ) and (rowsX == rowsY) and (colsX == colsZ) and
Branch: 3 branches
BranchTrueFalseTotal
if ((colsY == rowsZ) and (rowsX == rowsY) and (colsX == colsZ) and 2 0 2
if ((colsY == rowsZ) and (rowsX == rowsY) and (colsX == colsZ) and 2 0 2
if ((colsY == rowsZ) and (rowsX == rowsY) and (colsX == colsZ) and 2 0 2
3694 2 ▶ (BV_BITS_(X) == rowsX*colsX) and
Branch: 1 branch
BranchTrueFalseTotal
(BV_BITS_(X) == rowsX*colsX) and 2 0 2
3695 2 ▶ (BV_BITS_(Y) == rowsY*colsY) and
Branch: 1 branch
BranchTrueFalseTotal
(BV_BITS_(Y) == rowsY*colsY) and 2 0 2
3696 2 ▶ (BV_BITS_(Z) == rowsZ*colsZ))
Branch: 1 branch
BranchTrueFalseTotal
(BV_BITS_(Z) == rowsZ*colsZ)) 2 0 2
3697 {
3698 66 ▶ for ( i = 0; i < rowsY; i++ )
Branch: 1 branch
BranchTrueFalseTotal
for ( i = 0; i < rowsY; i++ ) 64 2 66
3699 {
3700 64 termX = i * colsX;
3701 64 termY = i * colsY;
3702 2112 ▶ for ( j = 0; j < colsZ; j++ )
Branch: 1 branch
BranchTrueFalseTotal
for ( j = 0; j < colsZ; j++ ) 2048 64 2112
3703 {
3704 2048 indxX = termX + j;
3705 2048 sum = 0;
3706 67584 ▶ for ( k = 0; k < colsY; k++ )
Branch: 1 branch
BranchTrueFalseTotal
for ( k = 0; k < colsY; k++ ) 65536 2048 67584
3707 {
3708 65536 indxY = termY + k;
3709 65536 indxZ = k * colsZ + j;
3710 65536 ▶ if ( BIT_VECTOR_TST_BIT(Y,indxY) &&
Branch: 1 branch
BranchTrueFalseTotal
if ( BIT_VECTOR_TST_BIT(Y,indxY) && 64 65472 65536
3711 64 ▶ BIT_VECTOR_TST_BIT(Z,indxZ) ) sum |= 1;
Branch: 1 branch
BranchTrueFalseTotal
BIT_VECTOR_TST_BIT(Z,indxZ) ) sum |= 1; 2 62 64
3712 }
3713 2048 ▶ if (sum) BIT_VECTOR_SET_BIT(X,indxX)
Branch: 1 branch
BranchTrueFalseTotal
if (sum) BIT_VECTOR_SET_BIT(X,indxX) 2 2046 2048
3714 2046 else BIT_VECTOR_CLR_BIT(X,indxX)
3715 }
3716 }
3717 }
3718 2 }
3719  
3720 1 void Matrix_Closure(wordptr addr, N_int rows, N_int cols)
3721 {
3722 N_word i;
3723 N_word j;
3724 N_word k;
3725 N_word ii;
3726 N_word ij;
3727 N_word ik;
3728 N_word kj;
3729 N_word termi;
3730 N_word termk;
3731  
3732 1 ▶ if ((rows == cols) and (BV_BITS_(addr) == rows*cols))
Branch: 2 branches
BranchTrueFalseTotal
if ((rows == cols) and (BV_BITS_(addr) == rows*cols)) 1 0 1
if ((rows == cols) and (BV_BITS_(addr) == rows*cols)) 1 0 1
3733 {
3734 33 ▶ for ( i = 0; i < rows; i++ )
Branch: 1 branch
BranchTrueFalseTotal
for ( i = 0; i < rows; i++ ) 32 1 33
3735 {
3736 32 ii = i * cols + i;
3737 32 BIT_VECTOR_SET_BIT(addr,ii)
3738 }
3739 33 ▶ for ( k = 0; k < rows; k++ )
Branch: 1 branch
BranchTrueFalseTotal
for ( k = 0; k < rows; k++ ) 32 1 33
3740 {
3741 32 termk = k * cols;
3742 1056 ▶ for ( i = 0; i < rows; i++ )
Branch: 1 branch
BranchTrueFalseTotal
for ( i = 0; i < rows; i++ ) 1024 32 1056
3743 {
3744 1024 termi = i * cols;
3745 1024 ik = termi + k;
3746 33792 ▶ for ( j = 0; j < rows; j++ )
Branch: 1 branch
BranchTrueFalseTotal
for ( j = 0; j < rows; j++ ) 32768 1024 33792
3747 {
3748 32768 ij = termi + j;
3749 32768 kj = termk + j;
3750 32768 ▶ if ( BIT_VECTOR_TST_BIT(addr,ik) &&
Branch: 1 branch
BranchTrueFalseTotal
if ( BIT_VECTOR_TST_BIT(addr,ik) && 1024 31744 32768
3751 1024 ▶ BIT_VECTOR_TST_BIT(addr,kj) )
Branch: 1 branch
BranchTrueFalseTotal
BIT_VECTOR_TST_BIT(addr,kj) ) 32 992 1024
3752 32 BIT_VECTOR_SET_BIT(addr,ij)
3753 }
3754 }
3755 }
3756 }
3757 1 }
3758  
3759 2 void Matrix_Transpose(wordptr X, N_int rowsX, N_int colsX,
3760 wordptr Y, N_int rowsY, N_int colsY)
3761 {
3762 N_word i;
3763 N_word j;
3764 N_word ii;
3765 N_word ij;
3766 N_word ji;
3767 N_word addii;
3768 N_word addij;
3769 N_word addji;
3770 N_word bitii;
3771 N_word bitij;
3772 N_word bitji;
3773 N_word termi;
3774 N_word termj;
3775 boolean swap;
3776  
3777 /* BEWARE that "in-place" is ONLY possible if the matrix is quadratic!! */
3778  
3779 2 ▶ if ((rowsX == colsY) and (colsX == rowsY) and
Branch: 2 branches
BranchTrueFalseTotal
if ((rowsX == colsY) and (colsX == rowsY) and 2 0 2
if ((rowsX == colsY) and (colsX == rowsY) and 2 0 2
3780 2 ▶ (BV_BITS_(X) == rowsX*colsX) and
Branch: 1 branch
BranchTrueFalseTotal
(BV_BITS_(X) == rowsX*colsX) and 2 0 2
3781 2 ▶ (BV_BITS_(Y) == rowsY*colsY))
Branch: 1 branch
BranchTrueFalseTotal
(BV_BITS_(Y) == rowsY*colsY)) 2 0 2
3782 {
3783 2 ▶ if (rowsY == colsY) /* in-place is possible! */
Branch: 1 branch
BranchTrueFalseTotal
if (rowsY == colsY) /* in-place is possible! */ 2 0 2
3784 {
3785 66 ▶ for ( i = 0; i < rowsY; i++ )
Branch: 1 branch
BranchTrueFalseTotal
for ( i = 0; i < rowsY; i++ ) 64 2 66
3786 {
3787 64 termi = i * colsY;
3788 1056 ▶ for ( j = 0; j < i; j++ )
Branch: 1 branch
BranchTrueFalseTotal
for ( j = 0; j < i; j++ ) 992 64 1056
3789 {
3790 992 termj = j * colsX;
3791 992 ij = termi + j;
3792 992 ji = termj + i;
3793 992 addij = ij >> BV_LogBits;
3794 992 addji = ji >> BV_LogBits;
3795 992 bitij = BV_BitMaskTab[ij AND BV_ModMask];
3796 992 bitji = BV_BitMaskTab[ji AND BV_ModMask];
3797 992 swap = ((*(Y+addij) AND bitij) != 0);
3798 992 ▶ if ((*(Y+addji) AND bitji) != 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((*(Y+addji) AND bitji) != 0) 0 992 992
3799 0 *(X+addij) |= bitij;
3800 else
3801 992 *(X+addij) &= NOT bitij;
3802 992 ▶ if (swap)
Branch: 1 branch
BranchTrueFalseTotal
if (swap) 0 992 992
3803 0 *(X+addji) |= bitji;
3804 else
3805 992 *(X+addji) &= NOT bitji;
3806 }
3807 64 ii = termi + i;
3808 64 addii = ii >> BV_LogBits;
3809 64 bitii = BV_BitMaskTab[ii AND BV_ModMask];
3810 64 ▶ if ((*(Y+addii) AND bitii) != 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((*(Y+addii) AND bitii) != 0) 2 62 64
3811 2 *(X+addii) |= bitii;
3812 else
3813 62 *(X+addii) &= NOT bitii;
3814 }
3815 }
3816 else /* rowsX != colsX, in-place is NOT possible! */
3817 {
3818 0 ▶ for ( i = 0; i < rowsY; i++ )
Branch: 1 branch
BranchTrueFalseTotal
for ( i = 0; i < rowsY; i++ ) 0 0 0
3819 {
3820 0 termi = i * colsY;
3821 0 ▶ for ( j = 0; j < colsY; j++ )
Branch: 1 branch
BranchTrueFalseTotal
for ( j = 0; j < colsY; j++ ) 0 0 0
3822 {
3823 0 termj = j * colsX;
3824 0 ij = termi + j;
3825 0 ji = termj + i;
3826 0 addij = ij >> BV_LogBits;
3827 0 addji = ji >> BV_LogBits;
3828 0 bitij = BV_BitMaskTab[ij AND BV_ModMask];
3829 0 bitji = BV_BitMaskTab[ji AND BV_ModMask];
3830 0 ▶ if ((*(Y+addij) AND bitij) != 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((*(Y+addij) AND bitij) != 0) 0 0 0
3831 0 *(X+addji) |= bitji;
3832 else
3833 0 *(X+addji) &= NOT bitji;
3834 }
3835 }
3836 }
3837 }
3838 2 }
3839  
3840 /*****************************************************************************/
3841 /* VERSION: 7.5 */
3842 /*****************************************************************************/
3843 /* VERSION HISTORY: */
3844 /*****************************************************************************/
3845 /* */
3846 /* Version 7.5 21 11 26 No changes. */
3847 /* Version 7.4 03.09.13 No changes. */
3848 /* Version 7.3 01.06.13 No changes. */
3849 /* Version 7.2 17.05.12 No changes. */
3850 /* Version 7.1 29.09.09 Added prefix "BV_" to all global identifiers. */
3851 /* Version 7.0 22.08.09 Fixed bugs in "GCD2()" and "Boot()". */
3852 /* Version 6.9 12.08.09 Removed an obsolete warning (memory leak). */
3853 /* Version 6.8 10.08.09 Fixed hard-coded table size BV_MASKTABSIZE. */
3854 /* Version 6.7 08.08.09 No changes. */
3855 /* Version 6.6 27.07.09 Made it thread-safe and MacOS X compatible. */
3856 /* Version 6.5 27.07.09 Added automatic support for module "Storable". */
3857 /* Version 6.4 03.10.04 Added C++ comp. directives. Improved "Norm()". */
3858 /* Version 6.3 28.09.02 Added "Create_List()" and "GCD2()". */
3859 /* Version 6.2 15.09.02 Overhauled error handling. Fixed "GCD()". */
3860 /* Version 6.1 08.10.01 Make VMS linker happy: _lsb,_msb => _lsb_,_msb_ */
3861 /* Version 6.0 08.10.00 Corrected overflow handling. */
3862 /* Version 5.8 14.07.00 Added "Power()". Changed "Copy()". */
3863 /* Version 5.7 19.05.99 Quickened "Div_Pos()". Added "Product()". */
3864 /* Version 5.6 02.11.98 Leading zeros eliminated in "to_Hex()". */
3865 /* Version 5.5 21.09.98 Fixed bug of uninitialized "error" in Multiply. */
3866 /* Version 5.4 07.09.98 Fixed bug of uninitialized "error" in Divide. */
3867 /* Version 5.3 12.05.98 Improved Norm. Completed history. */
3868 /* Version 5.2 31.03.98 Improved Norm. */
3869 /* Version 5.1 09.03.98 No changes. */
3870 /* Version 5.0 01.03.98 Major additions and rewrite. */
3871 /* Version 4.2 16.07.97 Added is_empty, is_full. */
3872 /* Version 4.1 30.06.97 Added word-ins/del, move-left/right, inc/dec. */
3873 /* Version 4.0 23.04.97 Rewrite. Added bit shift and bool. matrix ops. */
3874 /* Version 3.2 04.02.97 Added interval methods. */
3875 /* Version 3.1 21.01.97 Fixed bug on 64 bit machines. */
3876 /* Version 3.0 12.01.97 Added flip. */
3877 /* Version 2.0 14.12.96 Efficiency and consistency improvements. */
3878 /* Version 1.1 08.01.96 Added Resize and ExclusiveOr. */
3879 /* Version 1.0 14.12.95 First version under UNIX (with Perl module). */
3880 /* Version 0.9 01.11.93 First version of C library under MS-DOS. */
3881 /* Version 0.1 ??.??.89 First version in Turbo Pascal under CP/M. */
3882 /* */
3883 /*****************************************************************************/
3884 /* AUTHOR: */
3885 /*****************************************************************************/
3886 /* */
3887 /* Steffen Beyer */
3888 /* mailto:STBEY@cpan.org */
3889 /* http://www.engelschall.com/u/sb/download/ */
3890 /* */
3891 /*****************************************************************************/
3892 /* COPYRIGHT: */
3893 /*****************************************************************************/
3894 /* */
3895 /* Copyright (c) 1995 - 2013 by Steffen Beyer. */
3896 /* All rights reserved. */
3897 /* */
3898 /*****************************************************************************/
3899 /* LICENSE: */
3900 /*****************************************************************************/
3901 /* */
3902 /* This library is free software; you can redistribute it and/or */
3903 /* modify it under the terms of the GNU Library General Public */
3904 /* License as published by the Free Software Foundation; either */
3905 /* version 2 of the License, or (at your option) any later version. */
3906 /* */
3907 /* This library is distributed in the hope that it will be useful, */
3908 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
3909 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
3910 /* Library General Public License for more details. */
3911 /* */
3912 /* You should have received a copy of the GNU Library General Public */
3913 /* License along with this library; if not, write to the */
3914 /* Free Software Foundation, Inc., */
3915 /* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
3916 /* */
3917 /* or download a copy from ftp://ftp.gnu.org/pub/gnu/COPYING.LIB-2.0 */
3918 /* */
3919 /*****************************************************************************/
3920 #endif
« Vector.xs ↑ Summary blib/lib/Bit/Vector.pm »