3 * @brief Implements a terrible and hacky interface to use a virtual FPU to do floating point operations
4 * Updated with even more terror! Whatever floats the boat!
13 extern int Start(const char * vcd_output = NULL); // Starts the VFPU
14 extern int Halt(); // Halts the VFPU
15 typedef enum {ADD=0x0, SUB=0x1, MULT=0x2, DIV=0x3, SQRT=0x4} Opcode;
16 typedef enum {EVEN=0x0, ZERO=0x1, UP=0x2, DOWN=0x3} Rmode; // Rounding mode; to even, towards zero, always up, always down
17 typedef std::bitset<32> Register;
18 extern Register Exec(const Register & a, const Register & b, Opcode op, Rmode rmode = EVEN); // operate with registers
19 extern float Exec(float a, float b, Opcode op, Rmode rmode = EVEN); //converts floats into registers and back
22 * Wrapper class for floats where operations are done on the VFPU
27 VFloat(float f = 0) : m_value(f)
29 static bool init = false;
33 VFPU::Start("flops.vcd");
36 VFloat(const VFloat & cpy) : m_value(cpy.m_value) {}
42 VFloat & operator+=(const VFloat & op)
44 m_value = Exec(m_value, op.m_value, ADD);
47 VFloat & operator-=(const VFloat & op)
49 m_value = Exec(m_value, op.m_value, SUB);
52 VFloat & operator*=(const VFloat & op)
54 m_value = Exec(m_value, op.m_value, MULT);
57 VFloat & operator/=(const VFloat & op)
59 m_value = Exec(m_value, op.m_value, DIV);
63 VFloat operator+(const VFloat & op) const {VFloat f(*this); f+=op; return f;}
64 VFloat operator-(const VFloat & op) const {VFloat f(*this); f-=op; return f;}
65 VFloat operator*(const VFloat & op) const {VFloat f(*this); f*=op; return f;}
66 VFloat operator/(const VFloat & op) const {VFloat f(*this); f/=op; return f;}
68 bool operator==(const VFloat & op) const
72 return (f.m_value == 0);
74 bool operator!=(const VFloat & op) const {return !this->operator==(op);}
75 bool operator<(const VFloat & op) const
79 return (f.m_value > 0);
81 bool operator<=(const VFloat & op) const
85 return (f.m_value >= 0);
87 bool operator>(const VFloat & op) const {return !this->operator<=(op);}
88 bool operator>=(const VFloat & op) const {return !this->operator<(op);}