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

[WRAPPED] Fixed Android long double handling #2096

Merged
merged 3 commits into from
Nov 30, 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
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ endif()
if(NOGIT)
add_definitions(-DNOGIT)
endif()
if(CI)
add_definitions(-Wno-pointer-type-mismatch)
endif()

if(HAVE_TRACE)
set(BOX64 box64)
Expand Down
88 changes: 78 additions & 10 deletions rebuild_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1095,15 +1095,15 @@ def generate_typedefs(arr: Iterable[FunctionType], file) -> None:
file.write("typedef " + td_types[v.get_convention().ident][v.get_convention().values.index(v[0])] + " (*" + name + ")"
+ "(" + ', '.join(td_types[v.get_convention().ident][v.get_convention().values.index(t)] for t in v[2:]) + ");\n")
if any_depends_on_ld:
file.write("\n#ifdef HAVE_LD80BITS\n")
file.write("\n#if defined(HAVE_LD80BITS) || defined(ANDROID)\n")
for v in arr:
if all(c not in v for c in depends_on_ld):
continue
name = v + "_t"
v = v[:-1] if v.endswith('NN') else v # FIXME
file.write("typedef " + td_types[v.get_convention().ident][v.get_convention().values.index(v[0])] + " (*" + name + ")"
+ "(" + ', '.join(td_types[v.get_convention().ident][v.get_convention().values.index(t)] for t in v[2:]) + ");\n")
file.write("#else // HAVE_LD80BITS\n")
file.write("#else // !HAVE_LD80BITS && !ANDROID\n")
for k in td_types_nold:
for t in td_types_nold[k]:
td_types[k][conventions[k].values.index(t)] = td_types_nold[k][t]
Expand Down Expand Up @@ -1197,6 +1197,13 @@ def generate_typedefs(arr: Iterable[FunctionType], file) -> None:
},
conventions['W']: {}
}
vals_android = {
conventions['F']: {
"D": "long double ld=fn({0}); emu->xmm[0].u128=*(__uint128_t*)&ld;",
"Y": "from_complexl(emu, fn({0}));",
},
conventions['W']: {}
}
vals_ld = {
k: {t: vals[k][k.values.index(t)] for t in vals_nold[k]} for k in vals_nold
}
Expand Down Expand Up @@ -1333,9 +1340,24 @@ def generate_typedefs(arr: Iterable[FunctionType], file) -> None:
'D': "FromLD((void*)(R_RSP + {p})), ", # K
'Y': "to_complexk(emu, R_RSP + {p}), ", # y
}
arg_s_android = {
'D': "*(long double*)(R_RSP + {p})], ",
'Y': "to_complexl(emu, R_RSP + {p}), ",
}
arg_s_ld = {
t: arg_s[conventions['F'].values.index(t)] for t in arg_s_nold
}
vxmm_noandroid = vxmm[:]
vxmm_android = vxmm[:]
vxmm_android[conventions['F'].values.index('D')] = 1
vxmm_android[conventions['F'].values.index('Y')] = 1
arg_x_android = {
'D': "*(long double*)&emu->xmm[{p}], ",
'Y': "to_complexl(emu, (uintptr_t)&emu->xmm[{p}]), ",
}
arg_x_ld = {
t: arg_x[conventions['F'].values.index(t)] for t in arg_x_android
}

# Asserts
for k in conventions:
Expand Down Expand Up @@ -1539,7 +1561,15 @@ def function_writer(f, N: FunctionType, W: str) -> None:
else:
function_writer(file, v, v + "_t")
if any_depends_on_ld:
file.write("\n#ifdef HAVE_LD80BITS\n")
file.write("\n#if defined(ANDROID)\n")
for c in vals_android:
for t in vals_android[c]:
vals[c][c.values.index(t)] = vals_android[c][t]
for t in arg_s_android:
arg_s[conventions['F'].values.index(t)] = arg_s_android[t]
for t in arg_x_android:
arg_x[conventions['F'].values.index(t)] = arg_x_android[t]
vxmm = vxmm_android
for v in gbls[k]:
if all(c not in v for c in depends_on_ld):
continue
Expand All @@ -1548,12 +1578,20 @@ def function_writer(f, N: FunctionType, W: str) -> None:
file.write("void vFv(x64emu_t *emu, uintptr_t fcn) { vFv_t fn = (vFv_t)fcn; fn(); (void)emu; }\n")
else:
function_writer(file, v, v + "_t")
file.write("#else // HAVE_LD80BITS\n")
file.write("#elif !defined(HAVE_LD80BITS)\n")
for c in vals_android:
for t in vals_ld[c]:
vals[c][c.values.index(t)] = vals_ld[c][t]
for c in vals_nold:
for t in vals_nold[c]:
vals[c][c.values.index(t)] = vals_nold[c][t]
for t in arg_s_android:
arg_s[conventions['F'].values.index(t)] = arg_s_ld[t]
for t in arg_s_nold:
arg_s[conventions['F'].values.index(t)] = arg_s_nold[t]
for t in arg_x_android:
arg_x[conventions['F'].values.index(t)] = arg_x_ld[t]
vxmm = vxmm_noandroid
for v in gbls[k]:
if all(c not in v for c in depends_on_ld):
continue
Expand All @@ -1563,10 +1601,19 @@ def function_writer(f, N: FunctionType, W: str) -> None:
else:
function_writer(file, v, v + "_t")
for c in vals_nold:
for t in vals_ld[c]:
for t in vals_nold[c]:
vals[c][c.values.index(t)] = vals_ld[c][t]
for t in arg_s_nold:
arg_s[conventions['F'].values.index(t)] = arg_s_nold[t]
arg_s[conventions['F'].values.index(t)] = arg_s_ld[t]
file.write("#else // defined(HAVE_LD80BITS) && !defined(ANDROID)\n")
for v in gbls[k]:
if all(c not in v for c in depends_on_ld):
continue
if v == FunctionType("vFv"):
# Suppress all warnings...
file.write("void vFv(x64emu_t *emu, uintptr_t fcn) { vFv_t fn = (vFv_t)fcn; fn(); (void)emu; }\n")
else:
function_writer(file, v, v + "_t")
file.write("#endif\n")
if k != str(Clauses()):
file.write("#endif\n")
Expand All @@ -1581,26 +1628,47 @@ def function_writer(f, N: FunctionType, W: str) -> None:
continue
function_writer(file, vr, vf + "_t")
if any_depends_on_ld:
file.write("\n#ifdef HAVE_LD80BITS\n")
file.write("\n#if defined(ANDROID)\n")
for c in vals_android:
for t in vals_android[c]:
vals[c][c.values.index(t)] = vals_android[c][t]
for t in arg_s_android:
arg_s[conventions['F'].values.index(t)] = arg_s_android[t]
for t in arg_x_android:
arg_x[conventions['F'].values.index(t)] = arg_x_android[t]
vxmm = vxmm_android
for vr, vf in redirects[k]:
if all(c not in vr for c in depends_on_ld):
continue
function_writer(file, vr, vf + "_t")
file.write("#else // HAVE_LD80BITS\n")
file.write("#elif !defined(HAVE_LD80BITS)\n")
for c in vals_android:
for t in vals_ld[c]:
vals[c][c.values.index(t)] = vals_ld[c][t]
for c in vals_nold:
for t in vals_nold[c]:
vals[c][c.values.index(t)] = vals_nold[c][t]
for t in arg_s_android:
arg_s[conventions['F'].values.index(t)] = arg_s_ld[t]
for t in arg_s_nold:
arg_s[conventions['F'].values.index(t)] = arg_s_nold[t]
for t in arg_x_android:
arg_x[conventions['F'].values.index(t)] = arg_x_ld[t]
vxmm = vxmm_noandroid
for vr, vf in redirects[k]:
if all(c not in vr for c in depends_on_ld):
continue
function_writer(file, vr, vf + "_t")
for c in vals_nold:
for t in vals_ld[c]:
for t in vals_nold[c]:
vals[c][c.values.index(t)] = vals_ld[c][t]
for t in arg_s_nold:
arg_s[conventions['F'].values.index(t)] = arg_s_nold[t]
arg_s[conventions['F'].values.index(t)] = arg_s_ld[t]
file.write("#else // defined(HAVE_LD80BITS) && !defined(ANDROID)\n")
for vr, vf in redirects[k]:
if all(c not in vr for c in depends_on_ld):
continue
function_writer(file, vr, vf + "_t")
file.write("#endif\n")
if k != str(Clauses()):
file.write("#endif\n")
Expand Down
6 changes: 6 additions & 0 deletions src/include/complext.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,18 @@ static inline void from_complex(x64emu_t* emu, complex_t v) {
emu->xmm[0].d[0]=v.r;
emu->xmm[1].d[0]=v.i;
}
#ifdef ANDROID
static inline void from_complexl(x64emu_t* emu, complexl_t v) {
memcpy(&emu->xmm[0], &v, 16*2); // what if AVX is present?
}
#else
static inline void from_complexl(x64emu_t* emu, complexl_t v) {
fpu_do_push(emu);
fpu_do_push(emu);
ST0.d=FromLD(&v.r);
ST(1).d=FromLD(&v.i);
}
#endif
static inline void from_complexk(x64emu_t* emu, complex_t v) {
fpu_do_push(emu);
fpu_do_push(emu);
Expand Down
Loading