]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
[mips] fix CmpLE32U and Max32U ops
authorPetar Jovanovic <mips32r2@gmail.com>
Sat, 9 May 2026 13:46:27 +0000 (13:46 +0000)
committerPetar Jovanovic <mips32r2@gmail.com>
Sat, 9 May 2026 13:46:27 +0000 (13:46 +0000)
CmpLE32U operation was incorrectly implemented as a signed comparaison,
use less-or-same for unsigned.

Max32U operation was incorrectly implemented using the SLT instruction,
use the unsigned variant SLTU.

This partially fixes none/tests/iropt-test.

Patch by:
Dimitrije Dzunic <dimitrije.dzunic@htecgroup.com>
Aleksandar Rikalo <aleksandar.rikalo@htecgroup.com>

VEX/priv/host_mips_defs.c
VEX/priv/host_mips_defs.h
VEX/priv/host_mips_isel.c

index d018aac8417743be0361f9d2bbad71cd0a2c6876..c14782ffde59fb227f8764238731db45d8bd4759 100644 (file)
@@ -795,6 +795,9 @@ const HChar *showMIPSAluOp(MIPSAluOp op, Bool immR)
       case Malu_SLT:
          ret = immR ? "slti" : "slt";
          break;
+      case Malu_SLTU:
+         ret = immR ? "sltui" : "sltu";
+         break;
       default:
          vpanic("showMIPSAluOp");
          break;
@@ -3885,6 +3888,13 @@ Int emit_MIPSInstr ( /*MB_MOD*/Bool* is_profInc,
                   p = mkFormR(p, 0, r_srcL, r_srcR, r_dst, 0, 42);
                }
                break;
+            case Malu_SLTU:
+               if (immR) {
+                  goto bad;
+               } else {
+                  p = mkFormR(p, 0, r_srcL, r_srcR, r_dst, 0, 43);
+               }
+               break;
 
             default:
                goto bad;
index 838368b85c115b34b73fed76abb24d39cf5b2902..4aaec89002437436c0da529fde8e5b690ac5daa4 100644 (file)
@@ -268,7 +268,7 @@ typedef enum {
    Malu_ADD, Malu_SUB,
    Malu_AND, Malu_OR, Malu_NOR, Malu_XOR,
    Malu_DADD, Malu_DSUB,
-   Malu_SLT
+   Malu_SLT, Malu_SLTU
 } MIPSAluOp;
 
 extern const HChar *showMIPSAluOp(MIPSAluOp,
index 19c761b00b993788b045ddbd404cd4efb6834083..1260e0b7d1514fd64f09527caeb1e8ebf6a56620 100644 (file)
@@ -1139,7 +1139,7 @@ static HReg iselWordExpr_R_wrk(ISelEnv * env, IRExpr * e)
                   size32 = False;
                   break;
                case Iop_CmpLE32U:
-                  cc = MIPScc_LE;
+                  cc = MIPScc_LS;
                   size32 = True;
                   break;
                case Iop_CmpLE32S:
@@ -1175,10 +1175,10 @@ static HReg iselWordExpr_R_wrk(ISelEnv * env, IRExpr * e)
             MIPSRH *argRH = MIPSRH_Reg(argR);
             /* max (v0, s0)
                ------------
-               slt v1, v0, s0
+               sltu v1, v0, s0
                movn v0, s0, v1 */
 
-            addInstr(env, MIPSInstr_Alu(Malu_SLT, tmp, argL, argRH));
+            addInstr(env, MIPSInstr_Alu(Malu_SLTU, tmp, argL, argRH));
 #if (__mips_isa_rev >= 6)
             {
               HReg r_temp  = newVRegI(env);