standardize exception-prone x86 behavior to normal C division
This commit is contained in:
parent
9d87703eef
commit
f82699c378
|
@ -87,7 +87,7 @@ static int left_z, left_dzdy;
|
||||||
|
|
||||||
extern "C" int imul16(int x, int y);
|
extern "C" int imul16(int x, int y);
|
||||||
extern "C" int imul14(int x, int y);
|
extern "C" int imul14(int x, int y);
|
||||||
extern "C" int idiv16(int x, int y);
|
extern int idiv16(int x, int y);
|
||||||
|
|
||||||
__inline int iceil(int x)
|
__inline int iceil(int x)
|
||||||
{
|
{
|
||||||
|
|
|
@ -35,6 +35,12 @@
|
||||||
;
|
;
|
||||||
;****************************************************************/
|
;****************************************************************/
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && !defined(_STDINT)
|
||||||
|
typedef signed __int64 int64_t;
|
||||||
|
#else
|
||||||
|
#include <stdint.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
// (x * y) >> 16
|
// (x * y) >> 16
|
||||||
extern "C" int __declspec(naked) imul16(int x, int y)
|
extern "C" int __declspec(naked) imul16(int x, int y)
|
||||||
{
|
{
|
||||||
|
@ -65,19 +71,12 @@ extern "C" int __declspec(naked) imul14(int x, int y)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//(x << 16) / y
|
int idiv16(int x, int y)
|
||||||
extern "C" int __declspec(naked) idiv16(int x, int y)
|
|
||||||
{
|
{
|
||||||
_asm {
|
int64_t result;
|
||||||
push ebp
|
const int64_t m = (int64_t)(x);
|
||||||
mov ebp,esp
|
const int64_t n = (int64_t)(y);
|
||||||
mov eax, [x]
|
|
||||||
mov ebx, [y]
|
result = (m << 16) / n;
|
||||||
mov edx,eax
|
return (int)(result);
|
||||||
sar edx,16
|
}
|
||||||
shl eax,16
|
|
||||||
idiv ebx
|
|
||||||
leave
|
|
||||||
ret
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue