Skip to content

Commit 72cbb14

Browse files
authored
[RV64_DYNAREC] Use ADDSL to replace SLLI+ADD pattern (#4551)
* [RV64_DYNAREC] Use ADDSL to replace shxadd pattern * [RV64_DYNAREC] Use ADDSL to replace SLLI+ADD pattern
1 parent a489cfe commit 72cbb14

4 files changed

Lines changed: 22 additions & 88 deletions

File tree

‎src/dynarec/rv64/dynarec_rv64_66f0.c‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,8 @@ uintptr_t dynarec64_66F0(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
113113
u8 &= 0x0f;
114114
ADDI(x3, wback, u8 >> 3);
115115
ANDI(x4, x3, 3);
116-
SLLI(x4, x4, 3);
117116
ADDI(x5, xZR, u8 & 7);
118-
ADD(x5, x4, x5);
117+
ADDSL(x5, x5, x4, 3, x4);
119118
ANDI(x3, x3, ~3);
120119
ADDI(x6, xZR, 1);
121120
SLL(x6, x6, x5);
@@ -143,9 +142,8 @@ uintptr_t dynarec64_66F0(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
143142
u8 &= 0x0f;
144143
ADDI(x3, wback, u8 >> 3);
145144
ANDI(x4, x3, 3);
146-
SLLI(x4, x4, 3);
147145
ADDI(x5, xZR, u8 & 7);
148-
ADD(x5, x4, x5);
146+
ADDSL(x5, x5, x4, 3, x4);
149147
ANDI(x3, x3, ~3);
150148
ADDI(x6, xZR, 1);
151149
SLL(x6, x6, x5);
@@ -174,9 +172,8 @@ uintptr_t dynarec64_66F0(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
174172
u8 &= 0x0f;
175173
ADDI(x3, wback, u8 >> 3);
176174
ANDI(x4, x3, 3);
177-
SLLI(x4, x4, 3);
178175
ADDI(x5, xZR, u8 & 7);
179-
ADD(x5, x4, x5);
176+
ADDSL(x5, x5, x4, 3, x4);
180177
ANDI(x3, x3, ~3);
181178
ADDI(x6, xZR, 1);
182179
SLL(x6, x6, x5);

‎src/dynarec/rv64/dynarec_rv64_avx_66_0f38.c‎

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -585,8 +585,7 @@ uintptr_t dynarec64_AVX_66_0F38(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t i
585585
for (int i = 0; i < 4; ++i) {
586586
LWU(x4, xEmu, offsetof(x64emu_t, scratch) + 16 + 4 * i);
587587
ANDI(x4, x4, 3);
588-
SLLI(x4, x4, 2);
589-
ADD(x4, x4, xEmu);
588+
ADDSL(x4, xEmu, x4, 2, x4);
590589
LWU(x5, x4, offsetof(x64emu_t, scratch) + 0);
591590
SW(x5, gback, gdoffset + 4 * i);
592591
}
@@ -604,8 +603,7 @@ uintptr_t dynarec64_AVX_66_0F38(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t i
604603
for (int i = 0; i < 4; ++i) {
605604
LWU(x4, xEmu, offsetof(x64emu_t, scratch) + 16 + 4 * i);
606605
ANDI(x4, x4, 3);
607-
SLLI(x4, x4, 2);
608-
ADD(x4, x4, xEmu);
606+
ADDSL(x4, xEmu, x4, 2, x4);
609607
LWU(x5, x4, offsetof(x64emu_t, scratch) + 0);
610608
SW(x5, gback, gyoffset + 4 * i);
611609
}
@@ -631,8 +629,7 @@ uintptr_t dynarec64_AVX_66_0F38(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t i
631629
LD(x4, xEmu, offsetof(x64emu_t, scratch) + 16 + 8 * i);
632630
SRLI(x4, x4, 1);
633631
ANDI(x4, x4, 1);
634-
SLLI(x4, x4, 3);
635-
ADD(x4, x4, xEmu);
632+
ADDSL(x4, xEmu, x4, 3, x4);
636633
LD(x5, x4, offsetof(x64emu_t, scratch) + 0);
637634
SD(x5, gback, gdoffset + 8 * i);
638635
}
@@ -651,8 +648,7 @@ uintptr_t dynarec64_AVX_66_0F38(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t i
651648
LD(x4, xEmu, offsetof(x64emu_t, scratch) + 16 + 8 * i);
652649
SRLI(x4, x4, 1);
653650
ANDI(x4, x4, 1);
654-
SLLI(x4, x4, 3);
655-
ADD(x4, x4, xEmu);
651+
ADDSL(x4, xEmu, x4, 3, x4);
656652
LD(x5, x4, offsetof(x64emu_t, scratch) + 0);
657653
SD(x5, gback, gyoffset + 8 * i);
658654
}
@@ -727,16 +723,14 @@ uintptr_t dynarec64_AVX_66_0F38(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t i
727723
for (int i = 0; i < 4; ++i) {
728724
LWU(x3, vback, vxoffset + 4 * i);
729725
ANDI(x3, x3, 7);
730-
SLLI(x3, x3, 2);
731-
ADD(x4, wback, x3);
726+
ADDSL(x4, wback, x3, 2, x3);
732727
LWU(x5, x4, fixedaddress);
733728
SW(x5, gback, gdoffset + 4 * i);
734729
}
735730
for (int i = 0; i < 4; ++i) {
736731
LWU(x3, vback, vyoffset + 4 * i);
737732
ANDI(x3, x3, 7);
738-
SLLI(x3, x3, 2);
739-
ADD(x4, wback, x3);
733+
ADDSL(x4, wback, x3, 2, x3);
740734
LWU(x5, x4, fixedaddress);
741735
SW(x5, gback, gyoffset + 4 * i);
742736
}
@@ -1474,16 +1468,14 @@ uintptr_t dynarec64_AVX_66_0F38(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t i
14741468
for (int i = 0; i < 4; ++i) {
14751469
LWU(x3, vback, vxoffset + 4 * i);
14761470
ANDI(x3, x3, 7);
1477-
SLLI(x3, x3, 2);
1478-
ADD(x4, wback, x3);
1471+
ADDSL(x4, wback, x3, 2, x3);
14791472
LWU(x5, x4, fixedaddress);
14801473
SW(x5, gback, gdoffset + 4 * i);
14811474
}
14821475
for (int i = 0; i < 4; ++i) {
14831476
LWU(x3, vback, vyoffset + 4 * i);
14841477
ANDI(x3, x3, 7);
1485-
SLLI(x3, x3, 2);
1486-
ADD(x4, wback, x3);
1478+
ADDSL(x4, wback, x3, 2, x3);
14871479
LWU(x5, x4, fixedaddress);
14881480
SW(x5, gback, gyoffset + 4 * i);
14891481
}

‎src/dynarec/rv64/dynarec_rv64_d9.c‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,7 @@ uintptr_t dynarec64_D9(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int ni
142142
ANDI(x5, x5, 7); // (emu->top + i)&7
143143
}
144144
// load x2 with ST0 anyway, for sign extraction
145-
if (cpuext.zba)
146-
SH3ADD(x1, x5, xEmu);
147-
else {
148-
SLLI(x5, x5, 3);
149-
ADD(x1, xEmu, x5);
150-
}
145+
ADDSL(x1, xEmu, x5, 3, x5);
151146
LD(x2, x1, offsetof(x64emu_t, x87));
152147
// load tag
153148
if (i2 >= 0) {

‎src/dynarec/rv64/dynarec_rv64_helper.c‎

Lines changed: 10 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -942,12 +942,7 @@ void x87_purgecache(dynarec_rv64_t* dyn, int ninst, int next, int s1, int s2, in
942942
#endif
943943
ADDI(s3, s2, dyn->e.x87cache[i]); // unadjusted count, as it's relative to real top
944944
ANDI(s3, s3, 7); // (emu->top + st)&7
945-
if (cpuext.zba)
946-
SH3ADD(s1, s3, xEmu);
947-
else {
948-
SLLI(s1, s3, 3);
949-
ADD(s1, xEmu, s1);
950-
}
945+
ADDSL(s1, xEmu, s3, 3, s1);
951946
switch (extcache_get_current_st(dyn, ninst, st)) {
952947
case EXT_CACHE_ST_D:
953948
FSD(dyn->e.x87reg[i], s1, offsetof(x64emu_t, x87)); // save the value
@@ -1054,12 +1049,7 @@ static void x87_reflectcache(dynarec_rv64_t* dyn, int ninst, int s1, int s2, int
10541049
if (dyn->e.x87cache[i] != -1) {
10551050
ADDI(s3, s2, dyn->e.x87cache[i]);
10561051
ANDI(s3, s3, 7); // (emu->top + i)&7
1057-
if (cpuext.zba)
1058-
SH3ADD(s1, s3, xEmu);
1059-
else {
1060-
SLLI(s1, s3, 3);
1061-
ADD(s1, xEmu, s1);
1062-
}
1052+
ADDSL(s1, xEmu, s3, 3, s1);
10631053
if (extcache_get_current_st_f(dyn, dyn->e.x87cache[i]) >= 0) {
10641054
FCVTDS(SCRATCH0, dyn->e.x87reg[i]);
10651055
FSD(SCRATCH0, s1, offsetof(x64emu_t, x87));
@@ -1136,12 +1126,7 @@ int x87_get_cache(dynarec_rv64_t* dyn, int ninst, int populate, int s1, int s2,
11361126
ADDI(s2, s2, a);
11371127
ANDI(s2, s2, 7);
11381128
}
1139-
if (cpuext.zba)
1140-
SH3ADD(s1, s2, xEmu);
1141-
else {
1142-
SLLI(s2, s2, 3);
1143-
ADD(s1, xEmu, s2);
1144-
}
1129+
ADDSL(s1, xEmu, s2, 3, s2);
11451130
FLD(dyn->e.x87reg[ret], s1, offsetof(x64emu_t, x87));
11461131
}
11471132
MESSAGE(LOG_DUMP, "\t-------x87 Cache for ST%d\n", st);
@@ -1188,12 +1173,7 @@ void x87_refresh(dynarec_rv64_t* dyn, int ninst, int s1, int s2, int st)
11881173
ADDI(s2, s2, a);
11891174
ANDI(s2, s2, 7); // (emu->top + i)&7
11901175
}
1191-
if (cpuext.zba)
1192-
SH3ADD(s1, s2, xEmu);
1193-
else {
1194-
SLLI(s2, s2, 3);
1195-
ADD(s1, xEmu, s2);
1196-
}
1176+
ADDSL(s1, xEmu, s2, 3, s2);
11971177
if (dyn->e.extcache[EXTIDX(reg)].t == EXT_CACHE_ST_F) {
11981178
FCVTDS(SCRATCH0, reg);
11991179
FSD(SCRATCH0, s1, offsetof(x64emu_t, x87));
@@ -1231,12 +1211,7 @@ void x87_forget(dynarec_rv64_t* dyn, int ninst, int s1, int s2, int st)
12311211
ADDI(s2, s2, a);
12321212
ANDI(s2, s2, 7); // (emu->top + i)&7
12331213
}
1234-
if (cpuext.zba)
1235-
SH3ADD(s1, s2, xEmu);
1236-
else {
1237-
SLLI(s2, s2, 3);
1238-
ADD(s1, xEmu, s2);
1239-
}
1214+
ADDSL(s1, xEmu, s2, 3, s2);
12401215
if (dyn->e.extcache[EXTIDX(reg)].t == EXT_CACHE_ST_F) {
12411216
FCVTDS(SCRATCH0, reg);
12421217
FSD(SCRATCH0, s1, offsetof(x64emu_t, x87));
@@ -1275,12 +1250,7 @@ void x87_reget_st(dynarec_rv64_t* dyn, int ninst, int s1, int s2, int st)
12751250
ADDI(s2, s2, a);
12761251
AND(s2, s2, 7);
12771252
}
1278-
if (cpuext.zba)
1279-
SH3ADD(s1, s2, xEmu);
1280-
else {
1281-
SLLI(s2, s2, 3);
1282-
ADD(s1, xEmu, s2);
1283-
}
1253+
ADDSL(s1, xEmu, s2, 3, s2);
12841254
FLD(dyn->e.x87reg[i], s1, offsetof(x64emu_t, x87));
12851255
MESSAGE(LOG_DUMP, "\t-------x87 Cache for ST%d\n", st);
12861256
// ok
@@ -1300,12 +1270,7 @@ void x87_reget_st(dynarec_rv64_t* dyn, int ninst, int s1, int s2, int st)
13001270
int a = st - dyn->e.x87stack;
13011271
ADDI(s2, s2, a);
13021272
ANDI(s2, s2, 7); // (emu->top + i)&7
1303-
if (cpuext.zba)
1304-
SH3ADD(s1, s2, xEmu);
1305-
else {
1306-
SLLI(s2, s2, 3);
1307-
ADD(s1, xEmu, s2);
1308-
}
1273+
ADDSL(s1, xEmu, s2, 3, s2);
13091274
FLD(dyn->e.x87reg[ret], s1, offsetof(x64emu_t, x87));
13101275
MESSAGE(LOG_DUMP, "\t-------x87 Cache for ST%d\n", st);
13111276
}
@@ -1335,12 +1300,7 @@ void x87_free(dynarec_rv64_t* dyn, int ninst, int s1, int s2, int s3, int st)
13351300
}
13361301
ANDI(s2, s2, 7); // (emu->top + i)&7
13371302
}
1338-
if (cpuext.zba)
1339-
SH3ADD(s1, s2, xEmu);
1340-
else {
1341-
SLLI(s2, s2, 3);
1342-
ADD(s1, xEmu, s2);
1343-
}
1303+
ADDSL(s1, xEmu, s2, 3, s2);
13441304
if (dyn->e.extcache[EXTIDX(reg)].t == EXT_CACHE_ST_F) {
13451305
FCVTDS(SCRATCH0, reg);
13461306
FSD(SCRATCH0, s1, offsetof(x64emu_t, x87));
@@ -2356,12 +2316,7 @@ static void loadCache(dynarec_rv64_t* dyn, int ninst, int stack_cnt, int s1, int
23562316
}
23572317
*s3_top += a;
23582318
*s2_val = 0;
2359-
if (cpuext.zba)
2360-
SH3ADD(s2, s3, xEmu);
2361-
else {
2362-
SLLI(s2, s3, 3);
2363-
ADD(s2, xEmu, s2);
2364-
}
2319+
ADDSL(s2, xEmu, s3, 3, s2);
23652320
FLD(reg, s2, offsetof(x64emu_t, x87));
23662321
if (t == EXT_CACHE_ST_F) {
23672322
FCVTSD(reg, reg);
@@ -2433,12 +2388,7 @@ static void unloadCache(dynarec_rv64_t* dyn, int ninst, int stack_cnt, int s1, i
24332388
ANDI(s3, s3, 7);
24342389
}
24352390
*s3_top += a;
2436-
if (cpuext.zba)
2437-
SH3ADD(s2, s3, xEmu);
2438-
else {
2439-
SLLI(s2, s3, 3);
2440-
ADD(s2, xEmu, s2);
2441-
}
2391+
ADDSL(s2, xEmu, s3, 3, s2);
24422392
*s2_val = 0;
24432393
if (t == EXT_CACHE_ST_F) {
24442394
FCVTDS(reg, reg);

0 commit comments

Comments
 (0)