diff --git a/src/codegen/codegen_ops_x86-64.h b/src/codegen/codegen_ops_x86-64.h index 906b07dc6..9f3f844a4 100644 --- a/src/codegen/codegen_ops_x86-64.h +++ b/src/codegen/codegen_ops_x86-64.h @@ -4314,6 +4314,56 @@ static inline void FP_LOAD_REG_D(int reg, int *host_reg1, int *host_reg2) *host_reg1 = REG_EBX; } +static inline int64_t x87_fround16_64(double b) +{ + int16_t a, c; + + switch ((cpu_state.npxc >> 10) & 3) + { + case 0: /*Nearest*/ + a = (int16_t)floor(b); + c = (int16_t)floor(b + 1.0); + if ((b - a) < (c - b)) + return (int64_t) a; + else if ((b - a) > (c - b)) + return (int64_t) c; + else + return (a & 1) ? c : a; + case 1: /*Down*/ + return (int64_t)((int16_t)floor(b)); + case 2: /*Up*/ + return (int64_t)((int16_t)ceil(b)); + case 3: /*Chop*/ + return (int64_t)((int16_t)b); + } + + return 0; +} +static inline int64_t x87_fround32_64(double b) +{ + int32_t a, c; + + switch ((cpu_state.npxc >> 10) & 3) + { + case 0: /*Nearest*/ + a = (int32_t)floor(b); + c = (int32_t)floor(b + 1.0); + if ((b - a) < (c - b)) + return (int64_t) a; + else if ((b - a) > (c - b)) + return (int64_t) c; + else + return (a & 1) ? c : a; + case 1: /*Down*/ + return (int64_t)((int32_t)floor(b)); + case 2: /*Up*/ + return (int64_t)((int32_t)ceil(b)); + case 3: /*Chop*/ + return (int64_t)((int32_t)b); + } + + return 0; +} static inline int64_t x87_fround(double b) { int64_t a, c;