Skip to content

fixed ldexpf, and reduced GDB1 autotest errors #607

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 2 commits into from
May 20, 2025
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
12 changes: 8 additions & 4 deletions src/libc/ldexpf.src
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ _scalbn:
bit 7, (iy + 11) ; scale sign
jr z, .scale_up
.scale_down:
; test signbit
; HL is not INT_MIN here
dec hl
add hl, hl
jr nc, .finish
jr nc, .finish ; expon > 0
; expon <= 0 or subnormal
.underflow_to_zero:
ld hl, ___fe_cur_env
set 5, (hl) ; FE_INEXACT
Expand Down Expand Up @@ -99,7 +101,6 @@ end if
ld e, (iy + 6)
ret


else

; normal inputs are handled correctly, unless the output is subnormal
Expand Down Expand Up @@ -132,9 +133,12 @@ _scalbn:
.scale_down:
; test signbit
push hl
; HL is not INT_MIN here
dec hl
add hl, hl
pop hl
jr nc, .finish
jr nc, .finish ; expon > 0
; expon <= 0 or subnormal
; jr .underflow_to_zero
.underflow_to_zero:
ld hl, ___fe_cur_env
Expand Down
7 changes: 5 additions & 2 deletions test/floating_point/complex/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <ti/screen.h>
#include <ti/getcsc.h>
#include <sys/util.h>
#include <ti/sprintf.h>

#include <complex.h>

Expand Down Expand Up @@ -191,9 +192,11 @@ int main(void) {
os_ClrHome();
size_t fail_index = run_test();
if (fail_index == SIZE_MAX) {
printf("All tests passed");
fputs("All tests passed", stdout);
} else {
printf("Failed test: L%zu\n", fail_index);
char buf[sizeof("Failed test: 16777215\n")];
boot_sprintf(buf, "Failed test: %u\n", fail_index);
fputs(buf, stdout);
}

while (!os_GetCSC());
Expand Down
4 changes: 2 additions & 2 deletions test/floating_point/float32_classification/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ static test_result fpclassify_test(void) {

int main(void) {
os_ClrHome();
printf("Testing 2^" NUM_TO_STR(test_count) " inputs");
fputs("Testing 2^" NUM_TO_STR(test_count) " inputs", stdout);
test_result ret = fpclassify_test();
os_ClrHome();
if (ret.passed) {
printf("All tests passed");
fputs("All tests passed", stdout);
} else {
printf(
"Failed test:\n0x%08lX\nTruth: %06o_%d\nGuess: %06o_%d",
Expand Down
7 changes: 5 additions & 2 deletions test/floating_point/float32_frexp/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <ti/screen.h>
#include <ti/getcsc.h>
#include <sys/util.h>
#include <ti/sprintf.h>

#include "f32_frexp_LUT.h"

Expand Down Expand Up @@ -48,9 +49,11 @@ int main(void) {
os_ClrHome();
size_t fail_index = run_test();
if (fail_index == SIZE_MAX) {
printf("All tests passed");
fputs("All tests passed", stdout);
} else {
printf("Failed test: %zu", fail_index);
char buf[sizeof("Failed test: 16777215\n")];
boot_sprintf(buf, "Failed test: %u\n", fail_index);
fputs(buf, stdout);
}

while (!os_GetCSC());
Expand Down
13 changes: 8 additions & 5 deletions test/floating_point/float32_ilogb/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <ti/screen.h>
#include <ti/getcsc.h>
#include <sys/util.h>
#include <ti/sprintf.h>

#include "f32_ilogb_LUT.h"

Expand All @@ -23,8 +24,9 @@ size_t run_test(void) {
for (size_t i = 0; i < length; i++) {
int result = ilogbf(input[i]);
if (result != output[i]) {
// printf("%3zu: %08lX\n\t%d != %d\n", i, input[i], result, output[i]);
// while (!os_GetCSC());
#if 0
printf("%3zu: %08lX\n\t%d != %d\n", i, input[i], result, output[i]);
#endif
return i;
}
}
Expand All @@ -34,13 +36,14 @@ size_t run_test(void) {
}

int main(void) {

os_ClrHome();
size_t fail_index = run_test();
if (fail_index == SIZE_MAX) {
printf("All tests passed");
fputs("All tests passed", stdout);
} else {
printf("Failed test: %zu", fail_index);
char buf[sizeof("Failed test: 16777215\n")];
boot_sprintf(buf, "Failed test: %u\n", fail_index);
fputs(buf, stdout);
}

while (!os_GetCSC());
Expand Down
12 changes: 4 additions & 8 deletions test/floating_point/float32_ldexp/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,16 @@ size_t run_test(void) {
for (size_t i = 0; i < length; i++) {
F32_pun result;
result.flt = ldexpf(input[i].value, input[i].expon);
// ignoring subnormal inputs for now
if (issubnormal(input[i].value) || issubnormal(output[i].flt)) {
continue;
}
if (result.bin != output[i].bin) {
// ignore NaN's with differing payloads
// treat signed zeros as equal for now
if (
(!(isnan(result.flt) && isnan(output[i].flt))) &&
(!(iszero(result.flt) && iszero(output[i].flt)))
(!(result.bin == 0 && iszero(output[i].flt)))
) {
/* Float multiplication does not handle subnormals yet */
if (!(iszero(result.flt) && issubnormal(output[i].flt))) {
#if 0
if (!(iszero(result.flt) && (issubnormal(output[i].flt) || issubnormal(input[i].value)))) {
#if 1
printf(
"%zu:\nI: %08lX %+d\nG: %08lX\nT: %08lX\n",
i, *(uint32_t*)(void*)&(input[i].value), input[i].expon,
Expand All @@ -65,7 +61,7 @@ int main(void) {
if (fail_index == SIZE_MAX) {
fputs("All tests passed", stdout);
} else {
char buf[sizeof("Failed test: -8388608\n")];
char buf[sizeof("Failed test: 16777215\n")];
boot_sprintf(buf, "Failed test: %u\n", fail_index);
fputs(buf, stdout);
}
Expand Down
19 changes: 13 additions & 6 deletions test/floating_point/float32_math/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <ti/screen.h>
#include <ti/getcsc.h>
#include <sys/util.h>
#include <ti/sprintf.h>

#include <bit>
#include <cmath>
Expand Down Expand Up @@ -38,7 +39,7 @@ static bool test_result(float guess, float truth) {

#define TEST(guess, truth) if (test_result(guess, truth)) { return __LINE__; }

static size_t run_test(void) {
static int run_test(void) {

TEST(std::exp ( 6.3f), 544.5719101259290330593886677332f);
TEST(std::exp ( -4.2f), 0.014995576820477706211984360229f);
Expand Down Expand Up @@ -91,16 +92,22 @@ static size_t run_test(void) {
TEST(std::hypot(1.23f, 4.56f, 7.89f), 9.195575022803087326242198470012610630662f);

/* passed all */
return SIZE_MAX;
return 0;
}

int main(void) {
os_ClrHome();
size_t fail_index = run_test();
if (fail_index == SIZE_MAX) {
printf("All tests passed");
int failed_test = run_test();
if (failed_test != 0) {
char buf[sizeof("Failed test L-8388608\n")];
boot_sprintf(buf, "Failed test L%d\n", failed_test);
fputs(buf, stdout);
#if 0
/* debugging */
printf("ULP: %ld\n", fail_ulp);
#endif
} else {
printf("Failed test: L%zu\nULP: %ld", fail_index, fail_ulp);
fputs("All tests passed", stdout);
}

while (!os_GetCSC());
Expand Down
21 changes: 13 additions & 8 deletions test/floating_point/float32_modf/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <ti/screen.h>
#include <ti/getcsc.h>
#include <sys/util.h>
#include <ti/sprintf.h>

#include "f32_modf_LUT.h"

Expand Down Expand Up @@ -36,12 +37,14 @@ size_t run_test(void) {
isnan(frac_part.flt) && isnan(output[i].frac_part.flt) &&
isnan(trunc_part.flt) && isnan(output[i].trunc_part.flt)
)) {
printf(
"I: %08lX T: %zu\nG: %08lX %08lX\nT: %08lX %08lX\n",
input[i].bin, i,
frac_part.bin, trunc_part.bin,
output[i].frac_part.bin, output[i].trunc_part.bin
);
#if 0
printf(
"I: %08lX T: %zu\nG: %08lX %08lX\nT: %08lX %08lX\n",
input[i].bin, i,
frac_part.bin, trunc_part.bin,
output[i].frac_part.bin, output[i].trunc_part.bin
);
#endif
return i;
}
}
Expand All @@ -55,9 +58,11 @@ int main(void) {
os_ClrHome();
size_t fail_index = run_test();
if (fail_index == SIZE_MAX) {
printf("All tests passed");
fputs("All tests passed", stdout);
} else {
printf("Failed test: %zu", fail_index);
char buf[sizeof("Failed test: 16777215\n")];
boot_sprintf(buf, "Failed test: %u\n", fail_index);
fputs(buf, stdout);
}

while (!os_GetCSC());
Expand Down
17 changes: 11 additions & 6 deletions test/floating_point/float32_to_float64/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <ti/screen.h>
#include <ti/getcsc.h>
#include <sys/util.h>
#include <ti/sprintf.h>

#include "f32_to_f64_LUT.h"

Expand All @@ -30,10 +31,12 @@ size_t run_test(void) {
result.flt = (long double)input[i];
if (result.bin != output[i].bin) {
if (!(isnan(result.flt) && isnan(output[i].flt))) {
printf(
"I: %08lX\nG: %016llX\nT: %016llX\n",
*((const uint32_t*)input + i), result.bin, output[i].bin
);
#if 0
printf(
"I: %08lX\nG: %016llX\nT: %016llX\n",
*((const uint32_t*)input + i), result.bin, output[i].bin
);
#endif
return i;
}
}
Expand All @@ -47,9 +50,11 @@ int main(void) {
os_ClrHome();
size_t fail_index = run_test();
if (fail_index == SIZE_MAX) {
printf("All tests passed");
fputs("All tests passed", stdout);
} else {
printf("Failed test: %zu", fail_index);
char buf[sizeof("Failed test: 16777215\n")];
boot_sprintf(buf, "Failed test: %u\n", fail_index);
fputs(buf, stdout);
}

while (!os_GetCSC());
Expand Down
21 changes: 13 additions & 8 deletions test/floating_point/float32_trunc/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <ti/screen.h>
#include <ti/getcsc.h>
#include <sys/util.h>
#include <ti/sprintf.h>

#include "f32_trunc_LUT.h"

Expand All @@ -29,12 +30,14 @@ size_t run_test(void) {
F32_pun result;
result.flt = truncf(input[i].flt);
if (result.bin != output[i].bin && !(isnan(result.flt) || isnan(output[i].flt))) {
printf(
"I: %08lX T: %zu\nG: %08lX\nT: %08lX\n",
input[i].bin, i,
result.bin,
output[i].bin
);
#if 0
printf(
"I: %08lX T: %zu\nG: %08lX\nT: %08lX\n",
input[i].bin, i,
result.bin,
output[i].bin
);
#endif
return i;
}
}
Expand All @@ -47,9 +50,11 @@ int main(void) {
os_ClrHome();
size_t fail_index = run_test();
if (fail_index == SIZE_MAX) {
printf("All tests passed");
fputs("All tests passed", stdout);
} else {
printf("Failed test: %zu", fail_index);
char buf[sizeof("Failed test: 16777215\n")];
boot_sprintf(buf, "Failed test: %u\n", fail_index);
fputs(buf, stdout);
}

while (!os_GetCSC());
Expand Down
15 changes: 12 additions & 3 deletions test/floating_point/float64_arithmetic/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <ti/screen.h>
#include <ti/getcsc.h>
#include <sys/util.h>
#include <ti/sprintf.h>

#include <bit>
#include <cmath>
Expand Down Expand Up @@ -124,14 +125,22 @@ int main(void) {
os_ClrHome();
int comparison_result = comparison_test();
if (comparison_result != 0) {
printf("Failed test L%d\n", comparison_result);
char buf[sizeof("Failed test L-8388608\n")];
boot_sprintf(buf, "Failed test L%d\n", comparison_result);
fputs(buf, stdout);
} else {
int64_t fail_ulp = 0;
size_t fail_index = run_test(&fail_ulp);
if (fail_index == SIZE_MAX) {
printf("All tests passed");
fputs("All tests passed", stdout);
} else {
printf("Failed test: %zu\nULP: %lld", fail_index, fail_ulp);
char buf[sizeof("Failed test: 16777215\n")];
boot_sprintf(buf, "Failed test: %u\n", fail_index);
fputs(buf, stdout);
#if 0
/* debugging */
printf("ULP: %lld\n", fail_ulp);
#endif
}
}
while (!os_GetCSC());
Expand Down
10 changes: 4 additions & 6 deletions test/floating_point/float64_classification/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,15 @@ static test_result fpclassify_test(void) {

int main(void) {
os_ClrHome();
printf("Testing 2^" NUM_TO_STR(test_count) " inputs");
fputs("Testing 2^" NUM_TO_STR(test_count) " inputs", stdout);
test_result ret = fpclassify_test();
os_ClrHome();
if (ret.passed) {
printf("All tests passed");
fputs("All tests passed", stdout);
} else {
// just in-case printf does not support long long or uint64_t
const uint32_t* failed_index_split = (const uint32_t*)((const void*)&(ret.failed_index));
printf(
"Failed test:\n0x%08lX%08lX\nTruth: %06o_%d\nGuess: %06o_%d",
failed_index_split[1], failed_index_split[0], ret.truth, ret.truth_fp, ret.guess, ret.guess_fp
"Failed test:\n0x%016llX\nTruth: %06o_%d\nGuess: %06o_%d",
ret.failed_index, ret.truth, ret.truth_fp, ret.guess, ret.guess_fp
);
}

Expand Down
Loading
Loading