Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DYNAREC_RV64] Added support for xtheadba #970

Merged
merged 3 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions src/dynarec/rv64/dynarec_rv64_0f.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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:
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
55 changes: 5 additions & 50 deletions src/dynarec/rv64/dynarec_rv64_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions src/dynarec/rv64/rv64_emitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<<rs2
Expand Down