Skip to content

Commit 772df1a

Browse files
Gadgetoiddpgeorge
authored andcommitted
rp2: Build with -fno-math-errno to use the hardware sqrt instruction.
Without -fno-math-errno the compiler must keep sqrt()/sqrtf() as library calls so they can set errno on a domain error, even though the Cortex-M33 FPU has a single VSQRT.F32 instruction. MicroPython's math module detects domain errors via isnan/isinf checks on the result rather than errno, so disabling errno here is safe and lets sqrt leverage hardware. Benchmarked on a Pico 2 (RP2350, perfbench N=150 M=100, avg of 3): misc_mandel (complex abs() in its inner loop) improves by ~12%, with no measurable change to non-sqrt benchmarks and a slightly smaller binary. Signed-off-by: Phil Howard <github@gadgetoid.com>
1 parent ca209fd commit 772df1a

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

ports/rp2/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,11 @@ target_compile_options(${MICROPY_TARGET} PRIVATE
532532
-Wall
533533
-Werror
534534
-g # always include debug information in the ELF
535+
536+
# Let the compiler lower sqrt()/sqrtf() to the hardware VSQRT instruction
537+
# instead of a library call. MicroPython's math module detects domain
538+
# errors via isnan/isinf on the result, not errno, so this is safe.
539+
-fno-math-errno
535540
)
536541
537542
target_link_options(${MICROPY_TARGET} PRIVATE

0 commit comments

Comments
 (0)