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 2 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);
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);
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);
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);
LDxw(x1, x3, fixedaddress);
ed = x1;
wback = x3;
Expand Down
35 changes: 5 additions & 30 deletions src/dynarec/rv64/dynarec_rv64_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,7 @@ uintptr_t geted(dynarec_rv64_t* dyn, uintptr_t addr, int ninst, uint8_t nextop,
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);
}
ADDSL(ret, scratch, xRAX+sib_reg, sib>>6);
} else {
ADD(ret, xRAX+sib_reg, scratch);
}
Expand All @@ -83,12 +78,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);
}
ADDSL(ret, xRAX+sib_reg2, xRAX+sib_reg, sib>>6);
} else {
ADD(ret, xRAX+sib_reg2, xRAX+sib_reg);
}
Expand Down Expand Up @@ -147,12 +137,7 @@ uintptr_t geted(dynarec_rv64_t* dyn, uintptr_t addr, int ninst, uint8_t nextop,
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);
}
ADDSL(ret, xRAX+sib_reg2, xRAX+sib_reg, sib>>6);
} else {
ADD(ret, xRAX+sib_reg2, xRAX+sib_reg);
}
Expand All @@ -166,12 +151,7 @@ uintptr_t geted(dynarec_rv64_t* dyn, uintptr_t addr, int ninst, uint8_t nextop,
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);
}
ADDSL(scratch, xRAX+sib_reg2, xRAX+sib_reg, sib>>6);
} else {
ADD(scratch, xRAX+sib_reg2, xRAX+sib_reg);
}
Expand All @@ -187,12 +167,7 @@ uintptr_t geted(dynarec_rv64_t* dyn, uintptr_t addr, int ninst, uint8_t nextop,
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);
}
ADDSL(ret, scratch, xRAX+sib_reg, sib>>6);
} else {
ADD(ret, scratch, xRAX+sib_reg);
}
Expand Down
10 changes: 10 additions & 0 deletions src/dynarec/rv64/rv64_emitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,16 @@ 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), rs2 might be used as scratch.
#define ADDSL(rd, rs1, rs2, imm2) if (rv64_zba) { \
SHxADD(rd, rs2, imm2, rs1); \
} else if (rv64_xtheadba) { \
TH_ADDSL(rd, rs1, rs2, imm2); \
} else { \
SLLI(rs2, rs2, imm2); \
ptitSeb marked this conversation as resolved.
Show resolved Hide resolved
ADD(rd, rs1, rs2); \
} \

#define SEXT_W(rd, rs1) ADDIW(rd, rs1, 0)

// rd = rs1<<rs2
Expand Down
Loading