8000 [RV64_DYNAREC] Extended simple wrapper for more int types by xctan · Pull Request #2160 · ptitSeb/box64 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[RV64_DYNAREC] Extended simple wrapper for more int types #2160

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

Merged
merged 1 commit into from
Dec 17, 2024
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
14 changes: 10 additions & 4 deletions rebuild_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,24 +842,25 @@ def main(root: str, files: Iterable[Filename], ver: str):

# H could be allowed maybe?
allowed_simply: Dict[str, str] = {"ARM64": "v", "RV64": "v"}
allowed_regs : Dict[str, str] = {"ARM64": "cCwWiuIUlLp", "RV64": "CWuIUlLp"}
allowed_regs : Dict[str, str] = {"ARM64": "cCwWiuIUlLp", "RV64": "CWIUlLp"}
allowed_fpr : Dict[str, str] = {"ARM64": "fd", "RV64": "fd"}
allowed_sextw : Dict[str, str] = {"ARM64": "", "RV64": "cwiu"}

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

# Sanity checks
forbidden_simple: Dict[str, str] = {"ARM64": "EDVOSNHPAxXYb", "RV64": "EcwiDVOSNHPAxXYb"}
forbidden_simple: Dict[str, str] = {"ARM64": "EDVOSNHPAxXYb", "RV64": "EDVOSNHPAxXYb"}
assert(all(k in allowed_simply for k in forbidden_simple))
assert(all(k in allowed_regs for k in forbidden_simple))
assert(all(k in allowed_fpr for k in forbidden_simple))
for k1 in forbidden_simple:
assert(len(allowed_simply[k1]) + len(allowed_regs[k1]) + len(allowed_fpr[k1]) + len(forbidden_simple[k1]) == len(allowed_conv.values))
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))
assert(all(c not in allowed_regs[k1] for c in allowed_simply[k1]))
assert(all(c not in allowed_simply[k1] + allowed_regs[k1] for c in allowed_fpr[k1]))
assert(all(c not in allowed_simply[k1] + allowed_regs[k1] + allowed_fpr[k1] for c in forbidden_simple[k1]))
assert(all(c in allowed_simply[k1] + allowed_regs[k1] + allowed_fpr[k1] + forbidden_simple[k1] for c in allowed_conv.values))
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))
assert(all(c in allowed_conv.values for c in return_x87))
assert(all(c in forbidden_simple[k] for c in depends_on_ld for k in forbidden_simple))

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

if v.get_convention() is not allowed_conv:
continue
Expand All @@ -884,13 +886,17 @@ def check_simple(v: FunctionType) -> Dict[str, int]:
fpr_count = fpr_count + 1
elif c in allowed_simply[k]:
continue
elif c in allowed_sextw[k]:
sextw_mask |= 1 << regs_count
regs_count += 1
else:
break
else:
# No character in forbidden_simply
if (regs_count <= 6) and (fpr_count <= 8):
# All checks passed!
ret_val = 1 + fpr_count
ret_val |= sextw_mask << 4
if v[0] in allowed_fpr[k]:
ret_val = -ret_val
ret[k] = ret_val
Expand Down
4 changes: 2 additions & 2 deletions src/dynarec/rv64/dynarec_rv64_00_3.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
if (isRetX87Wrapper(*(wrapper_t*)(addr)))
// return value will be on the stack, so the stack depth needs to be updated
x87_purgecache(dyn, ninst, 0, x3, x1, x4);
if (tmp < 0 || tmp > 1)
if (tmp < 0 || (tmp & 15) > 1)
tmp = 0; // TODO: removed when FP is in place
if ((box64_log < 2 && !cycle_log) && tmp) {
// GETIP(ip+3+8+8); // read the 0xCC
Expand Down Expand Up @@ -932,7 +932,7 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
tmp = isSimpleWrapper(*(wrapper_t*)(dyn->insts[ninst].natcall + 2));
} else
tmp = 0;
if (tmp < 0 || tmp > 1)
if (tmp < 0 || (tmp & 15) > 1)
tmp = 0; // TODO: removed when FP is in place
if (dyn->insts[ninst].natcall && isRetX87Wrapper(*(wrapper_t*)(dyn->insts[ninst].natcall + 2)))
// return value will be on the stack, so the stack depth needs to be updated
Expand Down
7 changes: 7 additions & 0 deletions src/dynarec/rv64/dynarec_rv64_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,13 @@ void call_n(dynarec_rv64_t* dyn, int ninst, void* fnc, int w)
{
MAYUSE(fnc);
fpu_pushcache(dyn, ninst, x3, 1);
// check if additional sextw needed
int sextw_mask = ((w > 0 ? w : -w) >> 4) & 0b111111;
for (int i = 0; i < 6; i++) {
if (sextw_mask & (1 << i)) {
SEXT_W(A0+i, A0+i);
}
}
// native call
TABLE64(x3, (uintptr_t)fnc);
JALR(xRA, x3);
Expand Down
Loading
Loading
0