HOTBM::HOTBM(Target* target, string func, string namebase, int wI, int wO, int n, double xmin, double xmax, double scale) : Operator(target), inst(0), f(*new Function(func, xmin, xmax, scale)), wI(wI), wO(wO) { try { Param p(wI, wO, n); Exhaustive ex(f, p); inst = 0; inst = ex.getInstance(); inst->roundTables(); } catch (const char *s) { throw std::string(s); } if (!inst) throw std::string("HOTBM cound not be generated."); { std::ostringstream o; if(namebase != "") o << namebase << "_"; o << "hotbm_" << vhdlize(func) << wI << "_" << wO << "_" << n; o << "_" << vhdlize(xmin) << "_" << vhdlize(xmax) << "_" << vhdlize(scale); uniqueName_ = o.str(); } setCombinatorial(); addInput("X", wI); addOutput("R", wO+1, 2); // faithful rounding genVHDL(); }
void FixComplexKCM::init() { if(lsb_in>msb_in) { throw string("FixComplexKCM: Error, lsbIn>msbIn"); } // definition of the source file name, used for info and error reporting // using REPORT srcFileName="FixComplexKCM"; // definition of the name of the operator ostringstream name; name << "FixComplexKCM_" << vhdlize(msb_in) <<"_" << vhdlize(lsb_in) << "_" << vhdlize(lsb_out) << "_" << vhdlize(constant_re) << "_" << vhdlize(constant_im) << "_" << ((signedInput) ? "" : "un") << "signed" ; setName(name.str()); // Copyright setCopyrightString("3IF 2015 dev team (2015)"); input_width = 1 + msb_in - lsb_in; // declaring inputs addInput ("ReIN" , input_width); addInput ("ImIN" , input_width); //Computing constants for testBench and in order to know constant width sollya_obj_t nodeIm, nodeRe; nodeRe = sollya_lib_parse_string(constant_re.c_str()); if(sollya_lib_obj_is_error(nodeRe)) { ostringstream error; error << srcFileName <<" : Unable to parse string \"" << constant_re << "\" as a numeric constant" << endl; throw error.str(); } nodeIm = sollya_lib_parse_string(constant_im.c_str()); if(sollya_lib_obj_is_error(nodeIm)) { ostringstream error; error << srcFileName <<" : Unable to parse string \"" << constant_im << "\" as a numeric constant" << endl; throw error.str(); } mpfr_inits2(10000, mpfr_constant_re, mpfr_constant_im, NULL); sollya_lib_get_constant(mpfr_constant_re, nodeRe); sollya_lib_get_constant(mpfr_constant_im, nodeIm); constantReNeg = (mpfr_sgn(mpfr_constant_re) < 0); constantImNeg = (mpfr_sgn(mpfr_constant_im) < 0); mpfr_t log2C; mpfr_init2(log2C, 100); //Constant real part width mpfr_log2(log2C, mpfr_constant_re, GMP_RNDN); constantReMsb = mpfr_get_si(log2C, GMP_RNDU); //Constant imaginary part width mpfr_log2(log2C, mpfr_constant_im, GMP_RNDN); constantImMsb = mpfr_get_si(log2C, GMP_RNDU); //Free mpfr_clear(log2C); int constantMaxMSB = max(constantReMsb, constantImMsb); //Do we need an extra sign bit ? bool extraSignBitRe = !signedInput && (constantReNeg || !constantImNeg); bool extraSignBitIm = !signedInput && (constantReNeg || constantImNeg); int msbout_re, msbout_im; msbout_re = msbout_im = msb_in + constantMaxMSB +1; if(extraSignBitRe) { msbout_re++; } if(extraSignBitIm) { msbout_im++; } outputre_width = msbout_re - lsb_out + 1; outputim_width = msbout_im - lsb_out + 1; if(outputre_width < 0 || outputim_width < 0) { THROWERROR("Computed msb will be lower than asked lsb." " Result would always be zero "); } }