diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lj_ffrecord.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/lj_ffrecord.c b/src/lj_ffrecord.c index 84957373..a3d18ff9 100644 --- a/src/lj_ffrecord.c +++ b/src/lj_ffrecord.c | |||
@@ -414,9 +414,17 @@ static void LJ_FASTCALL recff_math_abs(jit_State *J, RecordFFData *rd) | |||
414 | /* Record rounding functions math.floor and math.ceil. */ | 414 | /* Record rounding functions math.floor and math.ceil. */ |
415 | static void LJ_FASTCALL recff_math_round(jit_State *J, RecordFFData *rd) | 415 | static void LJ_FASTCALL recff_math_round(jit_State *J, RecordFFData *rd) |
416 | { | 416 | { |
417 | if (!tref_isinteger(J->base[0])) /* Pass through integers unmodified. */ | 417 | TRef tr = J->base[0]; |
418 | J->base[0] = emitir(IRTN(IR_FPMATH), lj_ir_tonum(J, J->base[0]), rd->data); | 418 | if (!tref_isinteger(tr)) { /* Pass through integers unmodified. */ |
419 | /* Note: result is integral (or NaN/Inf), but may not fit into an integer. */ | 419 | tr = emitir(IRTN(IR_FPMATH), lj_ir_tonum(J, tr), rd->data); |
420 | /* Result is integral (or NaN/Inf), but may not fit an int32_t. */ | ||
421 | if (LJ_DUALNUM) { /* Try to narrow using a guarded conversion to int. */ | ||
422 | lua_Number n = lj_vm_foldfpm(numberVnum(&rd->argv[0]), rd->data); | ||
423 | if (n == (lua_Number)lj_num2int(n)) | ||
424 | tr = emitir(IRTGI(IR_CONV), tr, IRCONV_INT_NUM|IRCONV_CHECK); | ||
425 | } | ||
426 | J->base[0] = tr; | ||
427 | } | ||
420 | } | 428 | } |
421 | 429 | ||
422 | /* Record unary math.* functions, mapped to IR_FPMATH opcode. */ | 430 | /* Record unary math.* functions, mapped to IR_FPMATH opcode. */ |