diff --git a/src/dynarec/rv64/dynarec_rv64_0f.c b/src/dynarec/rv64/dynarec_rv64_0f.c index 9e225bd21..8e85cc8e4 100644 --- a/src/dynarec/rv64/dynarec_rv64_0f.c +++ b/src/dynarec/rv64/dynarec_rv64_0f.c @@ -418,7 +418,7 @@ uintptr_t dynarec64_0F(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int ni SRLI(x3, gd, 8); SLLI(x4, x2, 16); AND(x3, x3, x4); - OR(x1, x1, x3); + OR(x1, x1, x3); SLLI(x3, gd, 8); SLLI(x4, x2, 24); AND(x3, x3, x4); @@ -436,7 +436,7 @@ uintptr_t dynarec64_0F(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int ni LUI(x2, 0xff0); AND(gd, gd, x2); OR(gd, gd, x1); - } + } } break; case 0xF1: @@ -477,7 +477,7 @@ uintptr_t dynarec64_0F(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int ni SRLI(x3, gd, 8); SLLI(x4, x2, 16); AND(x3, x3, x4); - OR(x1, x1, x3); + OR(x1, x1, x3); SLLI(x3, gd, 8); SLLI(x4, x2, 24); AND(x3, x3, x4); @@ -1097,8 +1097,7 @@ uintptr_t dynarec64_0F(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int ni SMREAD(); addr = geted(dyn, addr, ninst, nextop, &wback, x3, x1, &fixedaddress, rex, NULL, 1, 0); SRAIxw(x1, gd, 5+rex.w); // r1 = (gd>>5) - SLLI(x1, x1, 2+rex.w); - ADD(x3, wback, x1); //(&ed)+=r1*4; + ADDSL(x3, wback, x1, 2+rex.w, x1); LDxw(x1, x3, fixedaddress); ed = x1; } @@ -1131,8 +1130,7 @@ uintptr_t dynarec64_0F(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int ni SMREAD(); addr = geted(dyn, addr, ninst, nextop, &wback, x3, x1, &fixedaddress, rex, NULL, 1, 0); SRAI(x1, gd, 5+rex.w); - SLLI(x1, x1, 2+rex.w); - ADD(x3, wback, x1); + ADDSL(x3, wback, x1, 2+rex.w, x1); LDxw(x1, x3, fixedaddress); ed = x1; wback = x3; @@ -1279,8 +1277,7 @@ uintptr_t dynarec64_0F(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int ni SMREAD(); addr = geted(dyn, addr, ninst, nextop, &wback, x2, x1, &fixedaddress, rex, NULL, 1, 0); SRAI(x1, gd, 5+rex.w); - SLLI(x1, x1, 2+rex.w); - ADD(x3, wback, x1); + ADDSL(x3, wback, x1, 2+rex.w, x1); LDxw(x1, x3, fixedaddress); ed = x1; wback = x3; @@ -1449,8 +1446,7 @@ uintptr_t dynarec64_0F(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int ni SMREAD(); addr = geted(dyn, addr, ninst, nextop, &wback, x3, x1, &fixedaddress, rex, NULL, 1, 0); SRAI(x1, gd, 5+rex.w); - SLLI(x1, x1, 2+rex.w); - ADD(x3, wback, x1); + ADDSL(x3, wback, x1, 2+rex.w, x1); LDxw(x1, x3, fixedaddress); ed = x1; wback = x3; diff --git a/src/dynarec/rv64/dynarec_rv64_helper.c b/src/dynarec/rv64/dynarec_rv64_helper.c index a005c3b9e..1b89b08b0 100644 --- a/src/dynarec/rv64/dynarec_rv64_helper.c +++ b/src/dynarec/rv64/dynarec_rv64_helper.c @@ -56,16 +56,7 @@ uintptr_t geted(dynarec_rv64_t* dyn, uintptr_t addr, int ninst, uint8_t nextop, if (sib_reg!=4) { if(tmp && ((tmp<-2048) || (tmp>maxval) || !i12)) { MOV64x(scratch, tmp); - if((sib>>6)) { - if(rv64_zba) { - SHxADD(ret, xRAX+sib_reg, sib>>6, scratch); - } else { - SLLI(ret, xRAX+sib_reg, (sib>>6)); - ADD(ret, ret, scratch); - } - } else { - ADD(ret, xRAX+sib_reg, scratch); - } + ADDSL(ret, scratch, xRAX+sib_reg, sib>>6, ret); } else { if(sib>>6) { SLLI(ret, xRAX+sib_reg, (sib>>6)); @@ -82,16 +73,7 @@ uintptr_t geted(dynarec_rv64_t* dyn, uintptr_t addr, int ninst, uint8_t nextop, } } else { if (sib_reg!=4) { - if(sib>>6) { - if(rv64_zba) { - SHxADD(ret, xRAX+sib_reg, sib>>6, xRAX+sib_reg2); - } else { - SLLI(scratch, xRAX+sib_reg, (sib>>6)); - ADD(ret, xRAX+sib_reg2, scratch); - } - } else { - ADD(ret, xRAX+sib_reg2, xRAX+sib_reg); - } + ADDSL(ret, xRAX+sib_reg2, xRAX+sib_reg, sib>>6, scratch); } else { ret = xRAX+sib_reg2; } @@ -146,16 +128,7 @@ uintptr_t geted(dynarec_rv64_t* dyn, uintptr_t addr, int ninst, uint8_t nextop, *fixaddress = i64; if((nextop&7)==4) { if (sib_reg!=4) { - if(sib>>6) { - if(rv64_zba) { - SHxADD(ret, xRAX+sib_reg, sib>>6, xRAX+sib_reg2); - } else { - SLLI(scratch, xRAX+sib_reg, (sib>>6)); - ADD(ret, xRAX+sib_reg2, scratch); - } - } else { - ADD(ret, xRAX+sib_reg2, xRAX+sib_reg); - } + ADDSL(ret, xRAX+sib_reg2, xRAX+sib_reg, sib>>6, scratch); } else { ret = xRAX+sib_reg2; } @@ -165,16 +138,7 @@ uintptr_t geted(dynarec_rv64_t* dyn, uintptr_t addr, int ninst, uint8_t nextop, if(i64>=-2048 && i64<=2047) { if((nextop&7)==4) { if (sib_reg!=4) { - if(sib>>6) { - if(rv64_zba) { - SHxADD(scratch, xRAX+sib_reg, sib>>6, xRAX+sib_reg2); - } else { - SLLI(scratch, xRAX+sib_reg, (sib>>6)); - ADD(scratch, xRAX+sib_reg2, scratch); - } - } else { - ADD(scratch, xRAX+sib_reg2, xRAX+sib_reg); - } + ADDSL(scratch, xRAX+sib_reg2, xRAX+sib_reg, sib>>6, scratch); } else { scratch = xRAX+sib_reg2; } @@ -186,16 +150,7 @@ uintptr_t geted(dynarec_rv64_t* dyn, uintptr_t addr, int ninst, uint8_t nextop, if((nextop&7)==4) { if (sib_reg!=4) { ADD(scratch, scratch, xRAX+sib_reg2); - if(sib>>6) { - if(rv64_zba) { - SHxADD(ret, xRAX+sib_reg, sib>>6, scratch); - } else { - SLLI(ret, xRAX+sib_reg, (sib>>6)); - ADD(ret, scratch, ret); - } - } else { - ADD(ret, scratch, xRAX+sib_reg); - } + ADDSL(ret, scratch, xRAX+sib_reg, sib>>6, ret); } else { PASS3(int tmp = xRAX+sib_reg2); ADD(ret, tmp, scratch); diff --git a/src/dynarec/rv64/rv64_emitter.h b/src/dynarec/rv64/rv64_emitter.h index 6457ad592..23f4f73df 100644 --- a/src/dynarec/rv64/rv64_emitter.h +++ b/src/dynarec/rv64/rv64_emitter.h @@ -310,6 +310,18 @@ f28–31 ft8–11 FP temporaries Caller // rd = rs1 + imm12 #define ADDIz(rd, rs1, imm12) EMIT(I_type((imm12)&0b111111111111, rs1, 0b000, rd, rex.is32bits?0b0011011:0b0010011)) +// rd = rs1 + (rs2 << imm2) +#define ADDSL(rd, rs1, rs2, imm2, scratch) if (!imm2) { \ + ADD(rd, rs1, rs2); \ + } else if (rv64_zba) { \ + SHxADD(rd, rs2, imm2, rs1); \ + } else if (rv64_xtheadba) { \ + TH_ADDSL(rd, rs1, rs2, imm2); \ + } else { \ + SLLI(scratch, rs2, imm2); \ + ADD(rd, rs1, scratch); \ + } \ + #define SEXT_W(rd, rs1) ADDIW(rd, rs1, 0) // rd = rs1<