18 #include <Bitmask.hpp>
22 BitmaskImpl::getFieldImpl(
const Uint32 src[],
23 unsigned shiftL,
unsigned len, Uint32 dst[])
31 unsigned shiftR = 32 - shiftL;
32 unsigned undefined = shiftL ? ~0 : 0;
35 * dst = shiftL ? * dst : 0;
51 Uint32 mask= ((1 << len) -1);
52 * dst = (* src) & mask;
59 * dst++ |= (* src) << shiftL;
60 * dst = ((* src++) >> shiftR) & undefined;
70 * dst |= ((* src) & ((1 << len) - 1)) << shiftL;
75 * dst++ |= ((* src) << shiftL);
76 * dst = ((* src) >> shiftR) & ((1 << (len - shiftR)) - 1) & undefined;
82 BitmaskImpl::setFieldImpl(Uint32 dst[],
83 unsigned shiftL,
unsigned len,
const Uint32 src[])
91 unsigned shiftR = 32 - shiftL;
92 unsigned undefined = shiftL ? ~0 : 0;
95 * dst = (* src++) >> shiftL;
96 * dst++ |= ((* src) << shiftR) & undefined;
101 Uint32 mask = ((1 << len) -1);
102 * dst = (* dst & ~mask);
106 * dst |= ((* src++) >> shiftL) & mask;
111 * dst |= ((* src++) >> shiftL);
112 * dst |= ((* src) & ((1 << (len - shiftR)) - 1)) << shiftR ;
127 #include <util/NdbTap.hpp>
128 #include <util/BaseString.hpp>
130 #include "parse_mask.hpp"
138 unsigned MAX_BITS = 32 * b.Size;
139 for (i = 0; i < MAX_BITS; i++)
145 case 2:
case 3:
case 5:
case 7:
case 11:
case 13:
case 17:
case 19:
case 23:
146 case 29:
case 31:
case 37:
case 41:
case 43:
152 for (found = i = 0; i < MAX_BITS; i++)
153 found+=(
int)b.
get(i);
154 OK(found == b.
count());
156 printf(
"getText: %s\n", BaseString::getText(b).c_str());
157 OK(BaseString::getText(b) ==
158 "0000000000000000000000000000000000000000000000001ffff5df5f75d753");
159 printf(
"getPrettyText: %s\n", BaseString::getPrettyText(b).c_str());
160 OK(BaseString::getPrettyText(b) ==
161 "0, 1, 4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 22, 24, 25, 26, "
162 "27, 28, 30, 32, 33, 34, 35, 36, 38, 39, 40, 42, 44, 45, 46, 47, "
163 "48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59 and 60");
164 printf(
"getPrettyTextShort: %s\n",
165 BaseString::getPrettyTextShort(b).c_str());
166 OK(BaseString::getPrettyTextShort(b) ==
167 "0,1,4,6,8,9,10,12,14,15,16,18,20,21,22,24,25,26,27,28,30,32,"
168 "33,34,35,36,38,39,40,42,44,45,46,47,48,49,50,51,52,53,54,55,"
175 printf(
"getPrettyTextShort(c 1): %s\n",
176 BaseString::getPrettyTextShort(c).c_str());
181 printf(
"getPrettyTextShort(c 2): %s\n",
182 BaseString::getPrettyTextShort(c).c_str());
188 printf(
"getPrettyTextShort(d 1): %s\n",
189 BaseString::getPrettyTextShort(d).c_str());
193 Uint32 len = d.toArray(tmp,
sizeof(tmp));
194 printf(
"toArray(): ");
195 for (Uint32 i = 0; i < len; i++)
196 printf(
"%u ", (Uint32)tmp[i]);
204 printf(
"getPrettyTextShort(d 2): %s\n",
205 BaseString::getPrettyTextShort(d).c_str());
211 printf(
"getPrettyTextShort(d 3): %s\n",
212 BaseString::getPrettyTextShort(d).c_str());
218 OK(parse_mask(
"1,2,5-7,255", mask) == 6);
222 Uint32 len = mask.toArray(tmp,
sizeof(tmp));
223 printf(
"toArray(): ");
224 for (Uint32 i = 0; i < len; i++)
225 printf(
"%u ", (Uint32)tmp[i]);
253 OK(parse_mask(
"254", mask) == 1);
254 OK(parse_mask(
"255", mask) == 1);
257 OK(parse_mask(
"xx", mask) == -1);
258 OK(parse_mask(
"5-", mask) == -1);
259 OK(parse_mask(
"-5", mask) == -1);
260 OK(parse_mask(
"1,-5", mask) == -1);
263 OK(parse_mask(
"256", mask) == -2);
264 OK(parse_mask(
"1-255,256", mask) == -2);
275 #include <portlib/NdbTick.h>
277 typedef Uint32 (* FUNC)(Uint32
n);
283 return BitmaskImpl::count_bits(n) +
284 BitmaskImpl::count_bits(n*n);
294 double r = d * l * s;
295 double t = r > 0 ? r : r < 0 ? -r : 1;
298 double w = log(d + s + t + v);
299 double x = sqrt(d + s + t + v);
300 return (Uint32)(d * l * s * r * t * u * v * w * x);
305 Result() { sum = 0; elapsed = 0; }
312 test_empty(
Result& res, Uint32 len,
unsigned iter, FUNC func)
315 Uint64 start = NdbTick_CurrentMillisecond();
316 for (Uint32 j = 0; j<iter; j++)
318 for (Uint32 k = 0; k<len; k++)
321 Uint64 stop = NdbTick_CurrentMillisecond();
323 res.elapsed += (stop - start);
326 template<
unsigned sz>
332 Uint64 start = NdbTick_CurrentMillisecond();
333 for (Uint32 j = 0; j<iter; j++)
335 for (Uint32 n = mask.
find(0); n != mask.NotFound;
336 n = mask.
find(n + 1))
341 Uint64 stop = NdbTick_CurrentMillisecond();
343 res.elapsed += (stop - start);
346 template<
unsigned sz>
352 Uint64 start = NdbTick_CurrentMillisecond();
353 for (Uint32 j = 0; j<iter; j++)
363 Uint64 stop = NdbTick_CurrentMillisecond();
365 res.elapsed += (stop - start);
368 template<
unsigned sz>
374 Uint64 start = NdbTick_CurrentMillisecond();
375 for (Uint32 j = 0; j<iter; j++)
378 Uint32 cnt = mask.toArray(tmp,
sizeof(tmp));
379 for (Uint32 n = 0; n<cnt; n++)
380 sum += (* func)(tmp[
n]);
382 Uint64 stop = NdbTick_CurrentMillisecond();
384 res.elapsed += (stop - start);
389 sub0(Uint64 hi, Uint64 lo)
398 x_min(Uint64 a, Uint64 b, Uint64 c)
409 do_test(Uint32 len, FUNC func,
const char *
name,
const char * dist)
415 Result res_find, res_fast, res_toArray, res_empty;
416 for (Uint32 i = 0; i < (10000 / len); i++)
419 if (strcmp(dist,
"ran") == 0)
421 for (Uint32 i = 0; i<len; i++)
423 Uint32 b = rand() % (32 * tmp.Size);
426 b = rand() % (32 * tmp.Size);
431 else if (strcmp(dist,
"low") == 0)
433 for (Uint32 i = 0; i<len; i++)
438 test_find(res_find, tmp, iter, func);
439 test_find_fast(res_fast, tmp, iter, func);
440 test_toArray(res_toArray, tmp, iter, func);
441 test_empty(res_empty, len, iter, func);
444 res_find.elapsed = sub0(res_find.elapsed, res_empty.elapsed);
445 res_toArray.elapsed = sub0(res_toArray.elapsed, res_empty.elapsed);
446 res_fast.elapsed = sub0(res_fast.elapsed, res_empty.elapsed);
447 Uint64 m = x_min(res_find.elapsed, res_toArray.elapsed, res_fast.elapsed);
451 Uint64 div = iter * (10000 / len);
452 printf(
"empty(%s,%s, %u) : %llu ns/iter (elapsed: %llums)\n",
454 (1000000 * res_empty.elapsed / div / len),
456 printf(
"find(%s,%s, %u) : %llu ns/iter (%.3u%%), (sum: %u)\n",
458 (1000000 * res_find.elapsed / div),
459 Uint32((100 * res_find.elapsed) / m),
461 printf(
"fast(%s,%s, %u) : %llu ns/iter (%.3u%%), (sum: %u)\n",
463 (1000000 * res_fast.elapsed / div),
464 Uint32((100 * res_fast.elapsed) / m),
466 printf(
"toArray(%s,%s, %u) : %llu ns/iter (%.3u%%), (sum: %u)\n",
468 (1000000 * res_toArray.elapsed / div),
469 Uint32((100 * res_toArray.elapsed) / m),
478 const int len[] = { 1, 10, 50, 100, 250, 0 };
481 while (len[pos] != 0)
483 Uint32 l = len[pos++];
484 do_test(l, slow,
"slow",
"ran");
488 while (len[pos] != 0)
490 Uint32 l = len[pos++];
491 do_test(l, slow,
"slow",
"low");
495 while (len[pos] != 0)
497 Uint32 l = len[pos++];
498 do_test(l, fast,
"fast",
"ran");
501 while (len[pos] != 0)
503 Uint32 l = len[pos++];
504 do_test(l, fast,
"fast",
"low");