summaryrefslogtreecommitdiffhomepage
path: root/Opcode/Ice/IceFPU.h
diff options
context:
space:
mode:
Diffstat (limited to 'Opcode/Ice/IceFPU.h')
-rw-r--r--Opcode/Ice/IceFPU.h96
1 files changed, 8 insertions, 88 deletions
diff --git a/Opcode/Ice/IceFPU.h b/Opcode/Ice/IceFPU.h
index 9e57960..18ad7ae 100644
--- a/Opcode/Ice/IceFPU.h
+++ b/Opcode/Ice/IceFPU.h
@@ -12,6 +12,9 @@
#ifndef __ICEFPU_H__
#define __ICEFPU_H__
+ #include <algorithm>
+ #include <cmath>
+
#define SIGN_BITMASK 0x80000000
//! Integer representation of a floating-point value.
@@ -41,16 +44,7 @@
//! Fast square root for floating-point values.
inline_ float FastSqrt(float square)
{
- float retval;
-
- __asm {
- mov eax, square
- sub eax, 0x3F800000
- sar eax, 1
- add eax, 0x3F800000
- mov [retval], eax
- }
- return retval;
+ return std::sqrt(square);
}
//! Saturates positive to zero.
@@ -178,102 +172,28 @@
return x*x < epsilon;
}
- #define FCOMI_ST0 _asm _emit 0xdb _asm _emit 0xf0
- #define FCOMIP_ST0 _asm _emit 0xdf _asm _emit 0xf0
- #define FCMOVB_ST0 _asm _emit 0xda _asm _emit 0xc0
- #define FCMOVNB_ST0 _asm _emit 0xdb _asm _emit 0xc0
-
- #define FCOMI_ST1 _asm _emit 0xdb _asm _emit 0xf1
- #define FCOMIP_ST1 _asm _emit 0xdf _asm _emit 0xf1
- #define FCMOVB_ST1 _asm _emit 0xda _asm _emit 0xc1
- #define FCMOVNB_ST1 _asm _emit 0xdb _asm _emit 0xc1
-
- #define FCOMI_ST2 _asm _emit 0xdb _asm _emit 0xf2
- #define FCOMIP_ST2 _asm _emit 0xdf _asm _emit 0xf2
- #define FCMOVB_ST2 _asm _emit 0xda _asm _emit 0xc2
- #define FCMOVNB_ST2 _asm _emit 0xdb _asm _emit 0xc2
-
- #define FCOMI_ST3 _asm _emit 0xdb _asm _emit 0xf3
- #define FCOMIP_ST3 _asm _emit 0xdf _asm _emit 0xf3
- #define FCMOVB_ST3 _asm _emit 0xda _asm _emit 0xc3
- #define FCMOVNB_ST3 _asm _emit 0xdb _asm _emit 0xc3
-
- #define FCOMI_ST4 _asm _emit 0xdb _asm _emit 0xf4
- #define FCOMIP_ST4 _asm _emit 0xdf _asm _emit 0xf4
- #define FCMOVB_ST4 _asm _emit 0xda _asm _emit 0xc4
- #define FCMOVNB_ST4 _asm _emit 0xdb _asm _emit 0xc4
-
- #define FCOMI_ST5 _asm _emit 0xdb _asm _emit 0xf5
- #define FCOMIP_ST5 _asm _emit 0xdf _asm _emit 0xf5
- #define FCMOVB_ST5 _asm _emit 0xda _asm _emit 0xc5
- #define FCMOVNB_ST5 _asm _emit 0xdb _asm _emit 0xc5
-
- #define FCOMI_ST6 _asm _emit 0xdb _asm _emit 0xf6
- #define FCOMIP_ST6 _asm _emit 0xdf _asm _emit 0xf6
- #define FCMOVB_ST6 _asm _emit 0xda _asm _emit 0xc6
- #define FCMOVNB_ST6 _asm _emit 0xdb _asm _emit 0xc6
-
- #define FCOMI_ST7 _asm _emit 0xdb _asm _emit 0xf7
- #define FCOMIP_ST7 _asm _emit 0xdf _asm _emit 0xf7
- #define FCMOVB_ST7 _asm _emit 0xda _asm _emit 0xc7
- #define FCMOVNB_ST7 _asm _emit 0xdb _asm _emit 0xc7
-
//! A global function to find MAX(a,b) using FCOMI/FCMOV
inline_ float FCMax2(float a, float b)
{
- float Res;
- _asm fld [a]
- _asm fld [b]
- FCOMI_ST1
- FCMOVB_ST1
- _asm fstp [Res]
- _asm fcomp
- return Res;
+ return std::max(a, b);
}
//! A global function to find MIN(a,b) using FCOMI/FCMOV
inline_ float FCMin2(float a, float b)
{
- float Res;
- _asm fld [a]
- _asm fld [b]
- FCOMI_ST1
- FCMOVNB_ST1
- _asm fstp [Res]
- _asm fcomp
- return Res;
+ return std::min(a, b);
}
//! A global function to find MAX(a,b,c) using FCOMI/FCMOV
inline_ float FCMax3(float a, float b, float c)
{
- float Res;
- _asm fld [a]
- _asm fld [b]
- _asm fld [c]
- FCOMI_ST1
- FCMOVB_ST1
- FCOMI_ST2
- FCMOVB_ST2
- _asm fstp [Res]
- _asm fcompp
- return Res;
+ return std::max(std::max(a, b), c);
}
//! A global function to find MIN(a,b,c) using FCOMI/FCMOV
inline_ float FCMin3(float a, float b, float c)
{
- float Res;
- _asm fld [a]
- _asm fld [b]
- _asm fld [c]
- FCOMI_ST1
- FCMOVNB_ST1
- FCOMI_ST2
- FCMOVNB_ST2
- _asm fstp [Res]
- _asm fcompp
- return Res;
+ return std::min(std::min(a, b), c);
}
inline_ int ConvertToSortable(float f)