aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Pall <mike>2011-03-15 18:15:42 +0100
committerMike Pall <mike>2011-03-15 18:15:42 +0100
commit6299485000cfc96c92352501182e228c8e143005 (patch)
tree7319a2bce51556463da74a2716b51f3c8e8ef17a /src
parentdcbae09b1d462cc4ed7c11b0ff10d5c1f74eebd7 (diff)
downloadluajit-6299485000cfc96c92352501182e228c8e143005.tar.gz
luajit-6299485000cfc96c92352501182e228c8e143005.tar.bz2
luajit-6299485000cfc96c92352501182e228c8e143005.zip
DUALNUM: Narrow result of math.floor() and math.ceil().
Diffstat (limited to 'src')
-rw-r--r--src/lj_ffrecord.c14
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. */
415static void LJ_FASTCALL recff_math_round(jit_State *J, RecordFFData *rd) 415static 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. */