commit b6e5a65e0d89e3ba01e81b557974d4ca98934363
parent 073220cd7e2b75e1cf3123d5dea196caa1bf9937
Author: anon <anon@example.com>
Date: Thu, 15 Oct 2026 15:28:34 +0000
Round guest ceiling values through the portable CRT
Diffstat:
2 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/decompiled/runtime/guest_crt.c b/decompiled/runtime/guest_crt.c
@@ -425,6 +425,12 @@ static void crt_floor(void)
g_esp += 4;
}
+static void crt_ceil(void)
+{
+ fp_push_impl(g_st, &g_fp_top, ceil(MEMD(g_esp + 4)));
+ g_esp += 4;
+}
+
static void crt_ciacos(void)
{
double input = fp_pop_impl(g_st, &g_fp_top);
@@ -916,6 +922,7 @@ recomp_func_t guest_crt_lookup(const char *name)
{"??2@YAPAXI@Z", crt_new}, {"??3@YAXPAX@Z", crt_free},
{"_ftol", crt_ftol},
{"floor", crt_floor},
+ {"ceil", crt_ceil},
{"_CIfmod", crt_cifmod},
{"_CIacos", crt_ciacos},
{"atof", crt_atof},
diff --git a/decompiled/tests/guest_crt.c b/decompiled/tests/guest_crt.c
@@ -132,19 +132,24 @@ static void eh_prolog_installs_guest_frame(void)
assert(g_eax == RECOMP_RETADDR);
}
-static void floor_returns_on_guest_fpu_stack(void)
+static void rounding_returns_on_guest_fpu_stack(void)
{
- const double inputs[] = {1.75, -1.25, 0.0, -0.0, 0x1p52};
- const double expected[] = {1.0, -2.0, 0.0, -0.0, 0x1p52};
- for (unsigned i = 0; i < 5; ++i) {
+ const char *functions[] = {"floor", "ceil"};
+ const double inputs[] = {1.75, -1.25, 0.0, -0.0, 0x1p52, 0x1p-1074, -0x1p-1074, INFINITY, -INFINITY};
+ const double expected[][9] = {
+ {1.0, -2.0, 0.0, -0.0, 0x1p52, 0, -1, INFINITY, -INFINITY},
+ {2.0, -1.0, 0.0, -0.0, 0x1p52, 1, -0.0, INFINITY, -INFINITY},
+ };
+ for (unsigned function = 0; function < 2; ++function)
+ for (unsigned i = 0; i < 9; ++i) {
g_esp = 0x5000ff00u;
MEMD(g_esp + 4) = inputs[i];
g_fp_top = 1;
g_st[0] = 123.5;
- guest_crt_lookup("floor")();
+ guest_crt_lookup(functions[function])();
- assert(g_st[0] == expected[i] && signbit(g_st[0]) == signbit(expected[i]));
+ assert(g_st[0] == expected[function][i] && signbit(g_st[0]) == signbit(expected[function][i]));
assert(g_fp_top == 2 && g_st[1] == 123.5);
assert(g_esp == 0x5000ff04u);
assert(MEMD(0x5000ff04u) == inputs[i]);
@@ -441,7 +446,7 @@ int main(void)
dllonexit_preserves_callbacks_when_growing();
eh_prolog_installs_guest_frame();
standard_stream_data_preserves_32_bit_layout();
- floor_returns_on_guest_fpu_stack();
+ rounding_returns_on_guest_fpu_stack();
startup_copies_arguments_and_environment();
startup_exposes_writable_crt_modes();
startup_selects_53_bit_floating_point();
@@ -454,6 +459,6 @@ int main(void)
time_writes_only_a_32_bit_guest_value();
substring_search_returns_guest_addresses();
assert(MEM32(guest_crt_data("_adjust_fdiv")) == 0);
- puts("guest CRT: constructors, heap, EH frame, FILE data, floor and startup state passed");
+ puts("guest CRT: constructors, heap, EH frame, FILE data, rounding and startup state passed");
return 0;
}