Changeset 1578
 Timestamp:
 Oct 23, 2011, 5:58:11 AM (8 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/lib/bitblock128.hpp
r1574 r1578 90 90 union {bitblock128_t bitblock; unsigned long elems[sizeof(bitblock128_t)/sizeof(long)];} u; 91 91 u.bitblock = v; 92 93 #if LONG_BIT == 64 94 if (u.elems[0] != 0) {return cfzll(u.elems[0]);} 95 else if (u.elems[1] != 0) {return 64 + cfzll(u.elems[1]);} 96 else {return 128;} 97 #endif 98 99 #if LONG_BIT < 64 100 if (u.elems[0] != 0) {return cfzl(u.elems[0]);} 101 else if (u.elems[1] != 0) {return 32 + cfzl(u.elems[1]);} 102 else if (u.elems[2] != 0) {return 64 + cfzl(u.elems[2]);} 103 else if (u.elems[3] != 0) {return 96 + cfzl(u.elems[3]);} 104 else {return 128;} 105 #endif 92 uint32_t so_far = 0; 93 for (int i = 0; i < sizeof(bitblock128_t)/sizeof(long); i++) { 94 if (u.elems[i] != 0) return so_far + cfzl(u.elems[i]); 95 so_far += 8 * sizeof(long); 96 } 97 return so_far; 106 98 } 107 99 … … 109 101 union {bitblock128_t bitblock; unsigned long elems[sizeof(bitblock128_t)/sizeof(long)];} u; 110 102 u.bitblock = v; 111 112 #if LONG_BIT == 64 113 if (u.elems[1] != 0) return cbzll(u.elems[1]); 114 else if (u.elems[0] != 0) return LONG_BIT + cbzll(u.elems[0]); 115 #endif 116 #if LONG_BIT < 64 117 if (u.elems[3] != 0) return cbzl(u.elems[3]); 118 else if (u.elems[2] != 0) return 32 + cbzl(u.elems[2]); 119 else if (u.elems[1] != 0) return 64 + cbzl(u.elems[1]); 120 else if (u.elems[0] != 0) return 96 + cbzl(u.elems[0]); 121 #endif 122 else {return 128;} 103 uint32_t so_far = 0; 104 for (int i = sizeof(bitblock128_t)/sizeof(long)  1; i >= 0; i) { 105 if (u.elems[i] != 0) return so_far + cbzl(u.elems[i]); 106 so_far += 8 * sizeof(long); 107 } 108 return so_far; 123 109 } 124 110
Note: See TracChangeset
for help on using the changeset viewer.