From 79edaddf501f30b44c544fd9dbef8b073c63cd0f Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 26 Mar 2024 18:57:18 +1100 Subject: [PATCH] rp2/CMakeLists: Apply O2 optimisation to map, mpz and vm source code. Enabling this optimisation increases the RPI_PICO firmware by +3344 bytes. Performace change is: diff of scores (higher is better) N=100 M=100 rpi-base -> rpi-opt diff diff% (error%) bm_chaos.py 196.56 -> 215.26 : +18.70 = +9.514% (+/-0.05%) bm_fannkuch.py 52.47 -> 54.37 : +1.90 = +3.621% (+/-0.05%) bm_fft.py 1476.74 -> 1530.06 : +53.32 = +3.611% (+/-0.01%) bm_float.py 2305.65 -> 2444.11 : +138.46 = +6.005% (+/-0.08%) bm_hexiom.py 32.83 -> 35.09 : +2.26 = +6.884% (+/-0.05%) bm_nqueens.py 2335.85 -> 2259.78 : -76.07 = -3.257% (+/-0.06%) bm_pidigits.py 366.23 -> 465.81 : +99.58 = +27.191% (+/-0.04%) bm_wordcount.py 41.20 -> 41.87 : +0.67 = +1.626% (+/-0.01%) core_import_mpy_multi.py 327.44 -> 335.24 : +7.80 = +2.382% (+/-0.08%) core_import_mpy_single.py 63.41 -> 64.98 : +1.57 = +2.476% (+/-0.21%) core_locals.py 27.24 -> 29.19 : +1.95 = +7.159% (+/-0.01%) core_qstr.py 137.31 -> 140.84 : +3.53 = +2.571% (+/-0.03%) core_str.py 18.44 -> 18.10 : -0.34 = -1.844% (+/-0.03%) core_yield_from.py 221.69 -> 211.72 : -9.97 = -4.497% (+/-0.01%) misc_aes.py 303.38 -> 308.72 : +5.34 = +1.760% (+/-0.02%) misc_mandel.py 1501.00 -> 1746.60 : +245.60 = +16.362% (+/-0.04%) misc_pystone.py 1348.22 -> 1456.75 : +108.53 = +8.050% (+/-0.07%) misc_raytrace.py 223.81 -> 246.16 : +22.35 = +9.986% (+/-0.07%) viper_call0.py 331.05 -> 331.10 : +0.05 = +0.015% (+/-0.00%) viper_call1a.py 323.34 -> 323.39 : +0.05 = +0.015% (+/-0.00%) viper_call1b.py 241.01 -> 241.04 : +0.03 = +0.012% (+/-0.00%) viper_call1c.py 242.88 -> 242.92 : +0.04 = +0.016% (+/-0.00%) viper_call2a.py 318.41 -> 318.46 : +0.05 = +0.016% (+/-0.00%) viper_call2b.py 211.27 -> 211.30 : +0.03 = +0.014% (+/-0.00%) And the test `tests/basics/builtin_pow3_intbig.py` now passes (it uses a lot of mpz code and previously took longer than 10 seconds to run on RPI_PICO, which would lead to a timeout in the test runner). Signed-off-by: Damien George --- ports/rp2/CMakeLists.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ports/rp2/CMakeLists.txt b/ports/rp2/CMakeLists.txt index b605faaf21..fcc435b7b9 100644 --- a/ports/rp2/CMakeLists.txt +++ b/ports/rp2/CMakeLists.txt @@ -455,6 +455,15 @@ target_link_options(${MICROPY_TARGET} PRIVATE -Wl,--wrap=dcd_event_handler ) +# Apply optimisations to performance-critical source code. +set_source_files_properties( + ${MICROPY_PY_DIR}/map.c + ${MICROPY_PY_DIR}/mpz.c + ${MICROPY_PY_DIR}/vm.c + PROPERTIES + COMPILE_OPTIONS "-O2" +) + set_source_files_properties( ${PICO_SDK_PATH}/src/rp2_common/pico_double/double_math.c ${PICO_SDK_PATH}/src/rp2_common/pico_float/float_math.c