3 * @brief Implements a terrible and hacky interface to use a virtual FPU to do floating point operations
12 extern int Start(const char * vcd_output = NULL); // Starts the VFPU
13 extern int Halt(); // Halts the VFPU
14 typedef enum {ADD=0x0, SUB=0x1, MULT=0x2, DIV=0x3, SQRT=0x4} Opcode;
15 typedef enum {EVEN=0x0, ZERO=0x1, UP=0x2, DOWN=0x3} Rmode; // Rounding mode; to even, towards zero, always up, always down
16 typedef std::bitset<32> Register;
17 extern Register Exec(const Register & a, const Register & b, Opcode op, Rmode rmode = EVEN); // operate with registers
18 extern float Exec(float a, float b, Opcode op, Rmode rmode = EVEN); //converts floats into registers and back
23 Float(float f = 0) : m_value(f)
25 static bool init = false;
32 Float(const Float & cpy) : m_value(cpy.m_value) {}
38 Float & operator+=(const Float & op)
40 m_value = Exec(m_value, op.m_value, ADD);
43 Float & operator-=(const Float & op)
45 m_value = Exec(m_value, op.m_value, SUB);
48 Float & operator*=(const Float & op)
50 m_value = Exec(m_value, op.m_value, MULT);
53 Float & operator/=(const Float & op)
55 m_value = Exec(m_value, op.m_value, DIV);
59 Float operator+(const Float & op) const {Float f(*this); f+=op; return f;}
60 Float operator-(const Float & op) const {Float f(*this); f-=op; return f;}
61 Float operator*(const Float & op) const {Float f(*this); f*=op; return f;}
62 Float operator/(const Float & op) const {Float f(*this); f/=op; return f;}
64 bool operator==(const Float & op) const
68 return (f.m_value == 0);
70 bool operator!=(const Float & op) const {return !this->operator==(op);}
71 bool operator<(const Float & op) const
75 return (f.m_value > 0);
77 bool operator<=(const Float & op) const
81 return (f.m_value >= 0);
83 bool operator>(const Float & op) const {return !this->operator<=(op);}
84 bool operator>=(const Float & op) const {return !this->operator<(op);}
90 inline Float pow(const Float & a, const Float & b)
92 return Float(pow(a.m_value, b.m_value));