MCPcopy Create free account
hub / github.com/AliveToolkit/alive2 / randomInt

Method randomInt

tools/quick-fuzz.cpp:441–481  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

439 }
440
441 Constant *randomInt(Type *Ty) {
442 const auto Width = Ty->getIntegerBitWidth();
443 auto &P = Pool.at(Width);
444
445 if (P.size() > 0 && C.flip()) {
446 auto I = P.at(C.choose(P.size()));
447 switch (C.choose(3)) {
448 case 0: {
449 APInt Delta(Width, limit(C.choose(8) + 1, Width));
450 I += C.flip() ? Delta : -Delta;
451 break;
452 }
453 case 1:
454 I ^= APInt(Width, limit(1 << C.choose(Width), Width));
455 break;
456 case 2:
457 I = ~I;
458 break;
459 default:
460 assert(false);
461 }
462 return ConstantInt::get(Ty, I);
463 } else {
464 auto I = randomIntHelper(Width);
465 switch (C.choose(5)) {
466 case 0:
467 I = ~I;
468 break;
469 case 1:
470 I = I + 1;
471 break;
472 case 2:
473 I = I - 1;
474 break;
475 default:
476 break;
477 }
478 P.push_back(I);
479 return ConstantInt::get(Ty, I);
480 }
481 }
482
483 Value *getRandomVal(unsigned Upto, Type *Ty) {
484 const auto Width = Ty->getIntegerBitWidth();

Callers

nothing calls this directly

Calls 5

APIntClass · 0.85
atMethod · 0.80
flipMethod · 0.80
chooseMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected