X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fcode.git;a=blobdiff_plain;f=src%2Fvfpu.h;h=cb7fe50592b18f1d4f9da5beb59c39dcdfeae1b1;hp=a2102f93ca5353b038552d71b7a14d2ffc628982;hb=5456793e2aad4235c3db2ca75532c868aaa7c518;hpb=e0cd98bdff7f026b92f2c0e5b08639e08b98874e diff --git a/src/vfpu.h b/src/vfpu.h index a2102f9..cb7fe50 100644 --- a/src/vfpu.h +++ b/src/vfpu.h @@ -1,6 +1,7 @@ /** * @file vfpu.h * @brief Implements a terrible and hacky interface to use a virtual FPU to do floating point operations + * Updated with even more terror! Whatever floats the boat! */ #ifndef _VFPU_H @@ -17,80 +18,78 @@ namespace VFPU extern Register Exec(const Register & a, const Register & b, Opcode op, Rmode rmode = EVEN); // operate with registers extern float Exec(float a, float b, Opcode op, Rmode rmode = EVEN); //converts floats into registers and back - class Float + /** + * Wrapper class for floats where operations are done on the VFPU + */ + class VFloat { public: - Float(float f = 0) : m_value(f) + VFloat(float f = 0) : m_value(f) { static bool init = false; if (!init) { init = true; - VFPU::Start(); + VFPU::Start("flops.vcd"); } } - Float(const Float & cpy) : m_value(cpy.m_value) {} - virtual ~Float() + VFloat(const VFloat & cpy) : m_value(cpy.m_value) {} + virtual ~VFloat() { } - Float & operator+=(const Float & op) + VFloat & operator+=(const VFloat & op) { m_value = Exec(m_value, op.m_value, ADD); return *this; } - Float & operator-=(const Float & op) + VFloat & operator-=(const VFloat & op) { m_value = Exec(m_value, op.m_value, SUB); return *this; } - Float & operator*=(const Float & op) + VFloat & operator*=(const VFloat & op) { m_value = Exec(m_value, op.m_value, MULT); return *this; } - Float & operator/=(const Float & op) + VFloat & operator/=(const VFloat & op) { m_value = Exec(m_value, op.m_value, DIV); return *this; } - Float operator+(const Float & op) const {Float f(*this); f+=op; return f;} - Float operator-(const Float & op) const {Float f(*this); f-=op; return f;} - Float operator*(const Float & op) const {Float f(*this); f*=op; return f;} - Float operator/(const Float & op) const {Float f(*this); f/=op; return f;} + VFloat operator+(const VFloat & op) const {VFloat f(*this); f+=op; return f;} + VFloat operator-(const VFloat & op) const {VFloat f(*this); f-=op; return f;} + VFloat operator*(const VFloat & op) const {VFloat f(*this); f*=op; return f;} + VFloat operator/(const VFloat & op) const {VFloat f(*this); f/=op; return f;} - bool operator==(const Float & op) const + bool operator==(const VFloat & op) const { - Float f(op); + VFloat f(op); f -= *this; return (f.m_value == 0); } - bool operator!=(const Float & op) const {return !this->operator==(op);} - bool operator<(const Float & op) const + bool operator!=(const VFloat & op) const {return !this->operator==(op);} + bool operator<(const VFloat & op) const { - Float f(op); + VFloat f(op); f -= *this; return (f.m_value > 0); } - bool operator<=(const Float & op) const + bool operator<=(const VFloat & op) const { - Float f(op); + VFloat f(op); f -= *this; return (f.m_value >= 0); } - bool operator>(const Float & op) const {return !this->operator<=(op);} - bool operator>=(const Float & op) const {return !this->operator<(op);} + bool operator>(const VFloat & op) const {return !this->operator<=(op);} + bool operator>=(const VFloat & op) const {return !this->operator<(op);} float m_value; }; - - inline Float pow(const Float & a, const Float & b) - { - return Float(pow(a.m_value, b.m_value)); - } } #endif //_VFPU_H