summaryrefslogtreecommitdiffhomepage
path: root/Stars45
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2021-10-02 15:55:07 +0200
committerAki <please@ignore.pl>2021-10-02 15:55:07 +0200
commit41b26fc450b60830ad3a9ed65941e51193d65e99 (patch)
treec9cad088b82c16f07a188311d76a0ba721a46f34 /Stars45
parentdb03f429fd1dd171e4b4c78b7db92717a04be8c4 (diff)
downloadstarshatter-41b26fc450b60830ad3a9ed65941e51193d65e99.zip
starshatter-41b26fc450b60830ad3a9ed65941e51193d65e99.tar.gz
starshatter-41b26fc450b60830ad3a9ed65941e51193d65e99.tar.bz2
Removed inline assembly from fixed point number class
Diffstat (limited to 'Stars45')
-rw-r--r--Stars45/Fix.h103
1 files changed, 22 insertions, 81 deletions
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<int>(d);
}
// +--------------------------------------------------------------------+
@@ -73,18 +66,9 @@ public:
static const fix five;
static const fix ten;
- fix() { }
- fix(int n) : val(n<<Precision) { }
- fix(double d)
- {
- long ival;
- _asm {
- fld fix_sixty_five
- fmul d
- fistp ival
- }
- val=ival;
- }
+ fix() : val(0) { }
+ fix(int n) : val(n<<Precision) { }
+ fix(double d) : val(static_cast<long>(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<<Precision); return *this; }
- fix& operator=(double d) { long ival;
- _asm { fld fix_sixty_five
- fmul d
- fistp ival }
- val = ival;
- return *this; }
+ fix& operator=(double d) { val = static_cast<long>(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<<Precision); return r; }
fix operator-(int n) const { fix r; r.val = val-(n<<Precision); return r; }
@@ -171,10 +124,8 @@ public:
fix operator/(double d) const { fix f(d); return (*this)/f; }
fix& operator+=(double d) { fix f(d); val+=f.val; return *this; }
fix& operator-=(double d) { fix f(d); val-=f.val; return *this; }
- fix& operator*=(double d) { int n; _asm { fld d
- fistp n } val*=n; return *this; }
- fix& operator/=(double d) { int n; _asm { fld d
- fistp n } val/=n; return *this; }
+ fix& operator*=(double d) { val*=static_cast<long>(d); return *this; }
+ fix& operator/=(double d) { val/=static_cast<long>(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;