File tree Expand file tree Collapse file tree 1 file changed +5
-3
lines changed
Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -1417,7 +1417,7 @@ MULH:
14171417
14181418mulh_s_u:
14191419 op mul result rs1 rs2
1420- op shr result result 32
1420+ op idiv result result 0x100000000 # shr 32 - we need to use idiv for this because large negative values cause issues when cast to long
14211421 op and result result 0xffffffff
14221422
14231423 jump end_instruction_with_result always
@@ -1442,8 +1442,10 @@ DIVU:
14421442 # R-type: arg1=rs1, arg2=rs2, arg3=rd
14431443 jump div_by_zero equal rs2 0
14441444
1445- op idiv result rs1 rs2
1446- op and result result 0xffffffff # only necessary for signed
1445+ # use div instead of idiv and then cast to long so that it rounds towards zero
1446+ # https://stackoverflow.com/a/8387377
1447+ op div result rs1 rs2
1448+ op and result result 0xffffffff
14471449
14481450 jump end_instruction_with_result always
14491451
You can’t perform that action at this time.
0 commit comments