]> git.ipfire.org Git - thirdparty/LuaJIT.git/commitdiff
MIPS: Fix emitted code for U32 to float conversion.
authorMike Pall <mike>
Mon, 20 Feb 2017 01:35:00 +0000 (02:35 +0100)
committerMike Pall <mike>
Mon, 20 Feb 2017 01:35:00 +0000 (02:35 +0100)
src/lj_asm_mips.h

index 8044037bc87e66cb0b8c380c0adaeb1e19ca9ec5..03270ccaa69c5504d584e6370af4e882802d69b3 100644 (file)
@@ -443,18 +443,14 @@ static void asm_conv(ASMState *as, IRIns *ir)
       /* y = (x ^ 0x8000000) + 2147483648.0 */
       Reg left = ra_alloc1(as, lref, RSET_GPR);
       Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, dest));
-      emit_fgh(as, irt_isfloat(ir->t) ? MIPSI_ADD_S : MIPSI_ADD_D,
-              dest, dest, tmp);
-      emit_fg(as, irt_isfloat(ir->t) ? MIPSI_CVT_S_W : MIPSI_CVT_D_W,
-             dest, dest);
       if (irt_isfloat(ir->t))
-       emit_lsptr(as, MIPSI_LWC1, (tmp & 31),
-                  (void *)lj_ir_k64_find(as->J, U64x(4f000000,4f000000)),
-                  RSET_GPR);
-      else
-       emit_lsptr(as, MIPSI_LDC1, (tmp & 31),
-                  (void *)lj_ir_k64_find(as->J, U64x(41e00000,00000000)),
-                  RSET_GPR);
+       emit_fg(as, MIPSI_CVT_S_D, dest, dest);
+      /* Must perform arithmetic with doubles to keep the precision. */
+      emit_fgh(as, MIPSI_ADD_D, dest, dest, tmp);
+      emit_fg(as, MIPSI_CVT_D_W, dest, dest);
+      emit_lsptr(as, MIPSI_LDC1, (tmp & 31),
+                (void *)lj_ir_k64_find(as->J, U64x(41e00000,00000000)),
+                RSET_GPR);
       emit_tg(as, MIPSI_MTC1, RID_TMP, dest);
       emit_dst(as, MIPSI_XOR, RID_TMP, RID_TMP, left);
       emit_ti(as, MIPSI_LUI, RID_TMP, 0x8000);