Skip to content

Commit e1e4a59

Browse files
committed
some minor float test changes from testing llvm-libc
1 parent 7632f2a commit e1e4a59

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

test/pico_float_test/CMakeLists.txt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ foreach (FLOAT_TYPE IN LISTS FLOAT_TYPES)
6262
pico_set_float_implementation(custom_float_funcs_test_${FLOAT_TYPE} ${FLOAT_TYPE})
6363
target_link_libraries(custom_float_funcs_test_${FLOAT_TYPE} PRIVATE pico_stdlib)
6464
pico_add_extra_outputs(custom_float_funcs_test_${FLOAT_TYPE})
65-
pico_set_printf_implementation(custom_float_funcs_test_${FLOAT_TYPE} compiler)
65+
if (NOT PICO_CLIB STREQUAL "llvm_libc")
66+
# raw compiler printf on llvm_libc doesn't currently have floating point
67+
pico_set_printf_implementation(custom_float_funcs_test_${FLOAT_TYPE} compiler)
68+
endif()
6669
if (PICO_C_COMPILER_IS_GNU)
6770
target_compile_options(custom_float_funcs_test_${FLOAT_TYPE} PRIVATE -Wno-analyzer-use-of-uninitialized-value)
6871
endif()
@@ -79,7 +82,10 @@ foreach (FLOAT_TYPE IN LISTS FLOAT_TYPES)
7982
target_link_libraries(float_benchmark_${FLOAT_TYPE} PRIVATE pico_stdlib m)
8083
pico_add_extra_outputs(float_benchmark_${FLOAT_TYPE})
8184
target_compile_definitions(float_benchmark_${FLOAT_TYPE} PRIVATE PICO_FLOAT_IN_RAM=1)
82-
pico_set_printf_implementation(float_benchmark_${FLOAT_TYPE} compiler)
85+
if (NOT PICO_CLIB STREQUAL "llvm_libc")
86+
# raw compiler printf on llvm_libc doesn't currently have floating point
87+
pico_set_printf_implementation(float_benchmark_${FLOAT_TYPE} compiler)
88+
endif()
8389
pico_set_binary_type(float_benchmark_${FLOAT_TYPE} copy_to_ram)
8490
endforeach ()
8591

@@ -117,7 +123,10 @@ foreach (DOUBLE_TYPE IN LISTS DOUBLE_TYPES)
117123
pico_set_double_implementation(custom_double_funcs_test_${DOUBLE_TYPE} ${DOUBLE_TYPE})
118124
target_link_libraries(custom_double_funcs_test_${DOUBLE_TYPE} PRIVATE pico_stdlib)
119125
pico_add_extra_outputs(custom_double_funcs_test_${DOUBLE_TYPE})
120-
pico_set_printf_implementation(custom_double_funcs_test_${DOUBLE_TYPE} compiler)
126+
if (NOT PICO_CLIB STREQUAL "llvm_libc")
127+
# raw compiler printf on llvm_libc doesn't currently have floating point
128+
pico_set_printf_implementation(custom_double_funcs_test_${DOUBLE_TYPE} compiler)
129+
endif()
121130

122131
if (PICO_C_COMPILER_IS_CLANG)
123132
# llvm by default will treat our out of range float->int conversions as undefined behavior
@@ -133,7 +142,10 @@ foreach (DOUBLE_TYPE IN LISTS DOUBLE_TYPES)
133142
target_link_libraries(double_benchmark_${DOUBLE_TYPE} PRIVATE pico_stdlib m)
134143
pico_add_extra_outputs(double_benchmark_${DOUBLE_TYPE})
135144
target_compile_definitions(double_benchmark_${DOUBLE_TYPE} PRIVATE PICO_DOUBLE_IN_RAM=1)
136-
pico_set_printf_implementation(double_benchmark_${DOUBLE_TYPE} compiler)
145+
if (NOT PICO_CLIB STREQUAL "llvm_libc")
146+
# raw compiler printf on llvm_libc doesn't currently have floating point
147+
pico_set_printf_implementation(double_benchmark_${DOUBLE_TYPE} compiler)
148+
endif()
137149
pico_set_binary_type(double_benchmark_${DOUBLE_TYPE} copy_to_ram)
138150
endforeach ()
139151

test/pico_float_test/pico_float_test.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,8 @@ float __real_fmodf(float, float);
349349
#ifdef LLVM_LIBC_MATH_H
350350
#define isinff isinf
351351
#endif
352-
#define assert_close(a, b) test_assert((fabsf(a - b) <= allowed_range(a) || ({ printf(" error: %f != %f\n", a, b); 0; })) || (isinff(a) && isinff(b) && (a < 0) == (b < 0)))
353-
#define assert_close_fma(a, b) test_assert((fabsf(a - b) <= allowed_range_fma(a) || ({ printf(" error: %f != %f\n", a, b); 0; })) || (isinff(a) && isinff(b) && (a < 0) == (b < 0)))
352+
#define assert_close(a, b) test_assert((isinf(a) && isinf(b) && signbit(a) == signbit(b)) || fabsf((a) - (b)) <= allowed_range(a) || ({ printf(" error: %f != %f\n", a, b); 0; }) || (isinff(a) && isinff(b) && ((a) < 0) == ((b) < 0)))
353+
#define assert_close_fma(a, b) test_assert((fabsf((a) - (b)) <= allowed_range_fma(a) || ({ printf(" error: %f != %f\n", a, b); 0; })) || (isinff(a) && isinff(b) && ((a) < 0) == ((b) < 0)))
354354
#define check1(func,p0) ({ typeof(p0) r = func(p0), r2 = __CONCAT(__real_, func)(p0); test_assert(r == r2); r; })
355355
#if !LIB_PICO_FLOAT_PICO_VFP
356356
#define check1_vfp_unwrapped(func,p0) ({ typeof(p0) r = func(p0), r2 = __CONCAT(__real_, func)(p0); test_assert(r == r2); r; })
@@ -458,7 +458,7 @@ int main() {
458458
sincosf(x, &s, &c);
459459
printf("SINCOS %10.18f %10.18f\n", s, c);
460460
if (s != sinf(x) || c != cosf(x)) {
461-
printf("SINCOS mismatch\n");
461+
printf("SINCOS mismatch %10.18f %10.18f\n", sinf(x), cosf(x));
462462
fail = true;
463463
}
464464
}

0 commit comments

Comments
 (0)