From 41b26fc450b60830ad3a9ed65941e51193d65e99 Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 2 Oct 2021 15:55:07 +0200 Subject: Removed inline assembly from fixed point number class --- Stars45/Fix.h | 103 +++++++++++++--------------------------------------------- 1 file changed, 22 insertions(+), 81 deletions(-) (limited to 'Stars45') diff --git a/Stars45/Fix.h b/Stars45/Fix.h index d3aade0..4369812 100644 --- a/Stars45/Fix.h +++ b/Stars45/Fix.h @@ -49,14 +49,7 @@ const double fix_sixty_five=65536.0; inline int fast_f2i(double d) { - int i; - - _asm { - fld d - fistp i - } - - return i; + return static_cast(d); } // +--------------------------------------------------------------------+ @@ -73,18 +66,9 @@ public: static const fix five; static const fix ten; - fix() { } - fix(int n) : val(n<(d * fix_sixty_five)) { } fix(const fix& f) : val(f.val) { } // conversion operators: @@ -95,12 +79,7 @@ public: // assignment operators: fix& operator=(const fix& f) { val=f.val; return *this; } fix& operator=(int n) { val=(n<(d * fix_sixty_five); return *this; } // comparison operators: int operator==(const fix& f) const { return val==f.val; } @@ -113,48 +92,22 @@ public: // arithmetic operators: fix operator+(const fix& f) const { fix r; r.val = val+f.val; return r; } fix operator-(const fix& f) const { fix r; r.val = val-f.val; return r; } - fix operator*(const fix& f) const { long a=val; long b=f.val; - _asm { - mov eax, a - mov edx, b - imul edx - shrd eax, edx, 16 - mov a, eax - } - fix r; r.val = a; return r; } - fix operator/(const fix& f) const { long a=val; long b=f.val; - _asm { - mov eax, a - mov ebx, b - mov edx, eax - sar edx, 16 - shl eax, 16 - idiv ebx - mov a, eax - } - fix r; r.val = a; return r; } + fix operator*(const fix& f) const { + fix r; + r.val = (val * f.val) >> Precision; + return r; } + fix operator/(const fix& f) const { + fix r; + r.val = (val << Precision) / f.val; + return r; } fix& operator+=(const fix& f) { val+=f.val; return *this; } fix& operator-=(const fix& f) { val-=f.val; return *this; } - fix& operator*=(const fix& f) { long a=val; long b=f.val; - _asm { - mov eax, a - mov edx, b - imul edx - shrd eax, edx, 16 - mov a, eax - } - val=a; return *this; } - fix& operator/=(const fix& f) { long a=val; long b=f.val; - _asm { - mov eax, a - mov ebx, b - mov edx, eax - sar edx, 16 - shl eax, 16 - idiv ebx - mov a, eax - } - val=a; return *this; } + fix& operator*=(const fix& f) { + val = (val * f.val) >> Precision; + return *this; } + fix& operator/=(const fix& f) { + val = (val << Precision) / f.val; + return *this; } fix operator+(int n) const { fix r; r.val = val+(n<(d); return *this; } + fix& operator/=(double d) { val/=static_cast(d); return *this; } // misc. functions: fix truncate() const { fix r; r.val = val&IntMask; return r; } @@ -184,17 +135,7 @@ public: fix adjust_up() const { fix r; r.val = val+FractMask; return r; } fix adjust_down() const { fix r; r.val = val-FractMask; return r; } - fix muldiv(const fix& num, const fix& den) const - { long a=val, b=num.val, c=den.val; - _asm { - mov eax, a - mov edx, b - mov ebx, c - imul edx - idiv ebx - mov a, eax - } - fix r; r.val = a; return r; } + fix muldiv(const fix& num, const fix& den) const { return (*this) * num / den; } // data: long val; -- cgit v1.1