// This method is cloned from Operator, just resetting sign and exception bits // (because we don't have any exception support in this toy example) TestCase* FPSumOf3Squares::buildRandomTestCase(int i){ TestCase *tc; /* Generate test cases using random input numbers */ tc = new TestCase(this); // TODO free all this memory when exiting TestBench /* Fill inputs */ for (unsigned int j = 0; j < ioList_.size(); j++) { Signal* s = ioList_[j]; if (s->type() == Signal::in) { // ****** Modification: positive normal numbers with small exponents mpz_class m = getLargeRandom(wF); mpz_class bias = (mpz_class(1)<<(wE-1)) - 1; mpz_class e = getLargeRandom(wE-2) - (mpz_class(1)<<(wE-3)) + bias; // ensure no overflow mpz_class a = (mpz_class(1)<<(wE+wF+1)) // 01 to denote a normal number + (e<<wF) + m; tc->addInput(s->getName(), a); } } /* Get correct outputs */ emulate(tc); // cout << tc->getInputVHDL(); // cout << tc->getExpectedOutputVHDL(); return tc; }
void FixComplexKCM::buildStandardTestCases(TestCaseList * tcl) { TestCase* tc; int one = 1; if(lsb_in < 0 && msb_in >= 0) { //Real one one = one << -lsb_in; } tc = new TestCase(this); tc->addInput("ReIN", 0); tc->addInput("ImIN", 0); emulate(tc); tcl->add(tc); tc = new TestCase(this); tc->addInput("ReIN", one); tc->addInput("ImIN", 0); emulate(tc); tcl->add(tc); tc = new TestCase(this); tc->addInput("ReIN", 0); tc->addInput("ImIN", one); emulate(tc); tcl->add(tc); tc = new TestCase(this); tc->addInput("ReIN", one); tc->addInput("ImIN", one); emulate(tc); tcl->add(tc); if(signedInput) { tc = new TestCase(this); tc->addInput("ReIN", -1 * one); tc->addInput("ImIN", -1 * one); emulate(tc); tcl->add(tc); } tc = new TestCase(this); tc->addInput("ReIN", 2 * one); tc->addInput("ImIN", 0); emulate(tc); tcl->add(tc); }
void FixFunctionBySimplePoly::buildStandardTestCases(TestCaseList* tcl){ TestCase *tc; int lsbIn = f->lsbIn; bool signedIn = f->signedIn; // Testing the extremal cases tc = new TestCase(this); tc->addInput("X", 0); emulate(tc); tcl->add(tc); tc = new TestCase(this); tc->addInput("X", (mpz_class(1)<<(-lsbIn) ) -1); tc -> addComment("largest positive value, corresponding to 1"); emulate(tc); tcl->add(tc); if(signedIn) { tc = new TestCase(this); tc->addInput("X", (mpz_class(1)<<(-lsbIn) )); tc -> addComment("Smallest two's complement value, corresponding to -1"); emulate(tc); tcl->add(tc); } }
void InputIEEE::buildStandardTestCases(TestCaseList* tcl){ TestCase *tc; mpz_class x, r; tc = new TestCase(this); tc->addComment("a typical normal number: 1.0"); x = ((mpz_class(1) << 10)-1) << 52 ; tc->addInput("X", x); emulate(tc); tcl->add(tc); tc = new TestCase(this); tc->addComment("another one: -1.0"); x += (mpz_class(1) << 63); tc->addInput("X", x); emulate(tc); tcl->add(tc); tc = new TestCase(this); tc->addComment("a subnormal that is converted to a normal number"); x = mpz_class(1) << 51; tc->addInput("X", x); emulate(tc); tcl->add(tc); if(wFO==52 && wEO==11) { tc = new TestCase(this); tc->addComment("the same, but defined explicitely (to check emulate())"); x = mpz_class(1) << 51; tc->addInput("X", x); r = mpz_class(1) << 64; // normal number, exp=0, mantissa=1 tc->addExpectedOutput("R", r); tcl->add(tc); } tc = new TestCase(this); tc->addComment("the same, negative"); x += (mpz_class(1) << 63); tc->addInput("X", x); emulate(tc); tcl->add(tc); tc = new TestCase(this); tc->addComment("a subnormal that is flushed to zero"); x = mpz_class(1) << 50; tc->addInput("X", x); emulate(tc); tcl->add(tc); tc = new TestCase(this); tc->addComment("the same, negative"); x += (mpz_class(1) << 63); tc->addInput("X", x); emulate(tc); tcl->add(tc); tc = new TestCase(this); tc->addComment("another subnormal that is flushed to zero"); x = mpz_class(1) << 49; tc->addInput("X", x); emulate(tc); tcl->add(tc); tc = new TestCase(this); tc->addComment("the same, negative"); x += (mpz_class(1) << 63); tc->addInput("X", x); emulate(tc); tcl->add(tc); tc = new TestCase(this); tc->addComment("The largest finite number. "); x = (((mpz_class(1) << 11)-1) << 52) -1 ; tc->addInput("X", x); emulate(tc); tcl->add(tc); if (wEI>wEO && wFI>wFO) { tc = new TestCase(this); tc->addComment("a number whose rounding will trigger an overflow"); x = overflowThreshold << wFI; // maximal exponent x += ((mpz_class(1) << wFI)-1); // largest mantissa tc->addInput("X", x); emulate(tc); tcl->add(tc); tc = new TestCase(this); tc->addComment("just to check: the previous input minus one ulp"); x -= 1; tc->addInput("X", x); emulate(tc); tcl->add(tc); } tc = new TestCase(this); tc->addComment("the same, negative"); x += (mpz_class(1) << 63); tc->addInput("X", x); emulate(tc); tcl->add(tc); tc = new TestCase(this); tc->addComment("Plus infty"); x = ((mpz_class(1) << 11)-1) << 52 ; tc->addInput("X", x); emulate(tc); tcl->add(tc); tc = new TestCase(this); tc->addComment("Minus infty"); x += (mpz_class(1) << 63); tc->addInput("X", x); emulate(tc); tcl->add(tc); tc = new TestCase(this); tc->addComment("NaN"); x = (((mpz_class(1) << 11)-1) << 52 ) + 12; tc->addInput("X", x); emulate(tc); tcl->add(tc); }
TestCase* FPAddDualPath::buildRandomTestCase(int i){ TestCase *tc; mpz_class x,y; mpz_class normalExn = mpz_class(1)<<(wE+wF+1); mpz_class negative = mpz_class(1)<<(wE+wF); tc = new TestCase(this); /* Fill inputs */ if ((i & 7) == 0) {// cancellation, same exponent mpz_class e = getLargeRandom(wE); x = getLargeRandom(wF) + (e << wF) + normalExn; y = getLargeRandom(wF) + (e << wF) + normalExn + negative; } else if ((i & 7) == 1) {// cancellation, exp diff=1 mpz_class e = getLargeRandom(wE); x = getLargeRandom(wF) + (e << wF) + normalExn; e++; // may rarely lead to an overflow, who cares y = getLargeRandom(wF) + (e << wF) + normalExn + negative; } else if ((i & 7) == 2) {// cancellation, exp diff=1 mpz_class e = getLargeRandom(wE); x = getLargeRandom(wF) + (e << wF) + normalExn + negative; e++; // may rarely lead to an overflow, who cares y = getLargeRandom(wF) + (e << wF) + normalExn; } else if ((i & 7) == 3) {// alignment within the mantissa sizes mpz_class e = getLargeRandom(wE); x = getLargeRandom(wF) + (e << wF) + normalExn + negative; e += getLargeRandom(intlog2(wF)); // may lead to an overflow, who cares y = getLargeRandom(wF) + (e << wF) + normalExn; } else if ((i & 7) == 4) {// subtraction, alignment within the mantissa sizes mpz_class e = getLargeRandom(wE); x = getLargeRandom(wF) + (e << wF) + normalExn; e += getLargeRandom(intlog2(wF)); // may lead to an overflow y = getLargeRandom(wF) + (e << wF) + normalExn + negative; } else if ((i & 7) == 5 || (i & 7) == 6) {// addition, alignment within the mantissa sizes mpz_class e = getLargeRandom(wE); x = getLargeRandom(wF) + (e << wF) + normalExn; e += getLargeRandom(intlog2(wF)); // may lead to an overflow y = getLargeRandom(wF) + (e << wF) + normalExn; } else{ //fully random x = getLargeRandom(wE+wF+3); y = getLargeRandom(wE+wF+3); } // Random swap mpz_class swap = getLargeRandom(1); if (swap == mpz_class(0)) { tc->addInput("X", x); tc->addInput("Y", y); } else { tc->addInput("X", y); tc->addInput("Y", x); } /* Get correct outputs */ emulate(tc); return tc; }