Skip to content

Commit f65c22d

Browse files
authored
[RV64_DYNAREC] Extended simple wrapper for more int types (ptitSeb#2160)
1 parent 4859591 commit f65c22d

File tree

4 files changed

+1679
-346
lines changed

4 files changed

+1679
-346
lines changed

Diff for: rebuild_wrappers.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -842,24 +842,25 @@ def main(root: str, files: Iterable[Filename], ver: str):
842842

843843
# H could be allowed maybe?
844844
allowed_simply: Dict[str, str] = {"ARM64": "v", "RV64": "v"}
845-
allowed_regs : Dict[str, str] = {"ARM64": "cCwWiuIUlLp", "RV64": "CWuIUlLp"}
845+
allowed_regs : Dict[str, str] = {"ARM64": "cCwWiuIUlLp", "RV64": "CWIUlLp"}
846846
allowed_fpr : Dict[str, str] = {"ARM64": "fd", "RV64": "fd"}
847+
allowed_sextw : Dict[str, str] = {"ARM64": "", "RV64": "cwiu"}
847848

848849
# Detect functions which return in an x87 register
849850
retx87_wraps: Dict[ClausesStr, List[FunctionType]] = {}
850851
return_x87: str = "D"
851852

852853
# Sanity checks
853-
forbidden_simple: Dict[str, str] = {"ARM64": "EDVOSNHPAxXYb", "RV64": "EcwiDVOSNHPAxXYb"}
854+
forbidden_simple: Dict[str, str] = {"ARM64": "EDVOSNHPAxXYb", "RV64": "EDVOSNHPAxXYb"}
854855
assert(all(k in allowed_simply for k in forbidden_simple))
855856
assert(all(k in allowed_regs for k in forbidden_simple))
856857
assert(all(k in allowed_fpr for k in forbidden_simple))
857858
for k1 in forbidden_simple:
858-
assert(len(allowed_simply[k1]) + len(allowed_regs[k1]) + len(allowed_fpr[k1]) + len(forbidden_simple[k1]) == len(allowed_conv.values))
859+
assert(len(allowed_simply[k1]) + len(allowed_regs[k1]) + len(allowed_fpr[k1]) + len(allowed_sextw[k1]) + len(forbidden_simple[k1]) == len(allowed_conv.values))
859860
assert(all(c not in allowed_regs[k1] for c in allowed_simply[k1]))
860861
assert(all(c not in allowed_simply[k1] + allowed_regs[k1] for c in allowed_fpr[k1]))
861862
assert(all(c not in allowed_simply[k1] + allowed_regs[k1] + allowed_fpr[k1] for c in forbidden_simple[k1]))
862-
assert(all(c in allowed_simply[k1] + allowed_regs[k1] + allowed_fpr[k1] + forbidden_simple[k1] for c in allowed_conv.values))
863+
assert(all(c in allowed_simply[k1] + allowed_regs[k1] + allowed_fpr[k1] + allowed_sextw[k1] + forbidden_simple[k1] for c in allowed_conv.values))
863864
assert(all(c in allowed_conv.values for c in return_x87))
864865
assert(all(c in forbidden_simple[k] for c in depends_on_ld for k in forbidden_simple))
865866

@@ -872,6 +873,7 @@ def check_simple(v: FunctionType) -> Dict[str, int]:
872873
for k in forbidden_simple:
873874
regs_count: int = 0
874875
fpr_count : int = 0
876+
sextw_mask: int = 0
875877

876878
if v.get_convention() is not allowed_conv:
877879
continue
@@ -884,13 +886,17 @@ def check_simple(v: FunctionType) -> Dict[str, int]:
884886
fpr_count = fpr_count + 1
885887
elif c in allowed_simply[k]:
886888
continue
889+
elif c in allowed_sextw[k]:
890+
sextw_mask |= 1 << regs_count
891+
regs_count += 1
887892
else:
888893
break
889894
else:
890895
# No character in forbidden_simply
891896
if (regs_count <= 6) and (fpr_count <= 8):
892897
# All checks passed!
893898
ret_val = 1 + fpr_count
899+
ret_val |= sextw_mask << 4
894900
if v[0] in allowed_fpr[k]:
895901
ret_val = -ret_val
896902
ret[k] = ret_val

Diff for: src/dynarec/rv64/dynarec_rv64_00_3.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
436436
if (isRetX87Wrapper(*(wrapper_t*)(addr)))
437437
// return value will be on the stack, so the stack depth needs to be updated
438438
x87_purgecache(dyn, ninst, 0, x3, x1, x4);
439-
if (tmp < 0 || tmp > 1)
439+
if (tmp < 0 || (tmp & 15) > 1)
440440
tmp = 0; // TODO: removed when FP is in place
441441
if ((box64_log < 2 && !cycle_log) && tmp) {
442442
// GETIP(ip+3+8+8); // read the 0xCC
@@ -932,7 +932,7 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
932932
tmp = isSimpleWrapper(*(wrapper_t*)(dyn->insts[ninst].natcall + 2));
933933
} else
934934
tmp = 0;
935-
if (tmp < 0 || tmp > 1)
935+
if (tmp < 0 || (tmp & 15) > 1)
936936
tmp = 0; // TODO: removed when FP is in place
937937
if (dyn->insts[ninst].natcall && isRetX87Wrapper(*(wrapper_t*)(dyn->insts[ninst].natcall + 2)))
938938
// return value will be on the stack, so the stack depth needs to be updated

Diff for: src/dynarec/rv64/dynarec_rv64_helper.c

+7
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,13 @@ void call_n(dynarec_rv64_t* dyn, int ninst, void* fnc, int w)
844844
{
845845
MAYUSE(fnc);
846846
fpu_pushcache(dyn, ninst, x3, 1);
847+
// check if additional sextw needed
848+
int sextw_mask = ((w > 0 ? w : -w) >> 4) & 0b111111;
849+
for (int i = 0; i < 6; i++) {
850+
if (sextw_mask & (1 << i)) {
851+
SEXT_W(A0+i, A0+i);
852+
}
853+
}
847854
// native call
848855
TABLE64(x3, (uintptr_t)fnc);
849856
JALR(xRA, x3);

0 commit comments

Comments
 (0)