turbo: add CIRCUITPY_LOAD_NATIVE to load host-compiled native .mpy - #11332
Open
mikeysklar wants to merge 2 commits into
Open
turbo: add CIRCUITPY_LOAD_NATIVE to load host-compiled native .mpy#11332mikeysklar wants to merge 2 commits into
mikeysklar wants to merge 2 commits into
Conversation
Expose MICROPY_PERSISTENT_CODE_LOAD_NATIVE as a CIRCUITPY_ make flag, the same way CIRCUITPY_ENABLE_MPY_NATIVE exposes MICROPY_EMIT_THUMB. A board that sets CIRCUITPY_LOAD_NATIVE = 1 loads and runs native and viper .mpy files that mpy-cross compiled on the host, without carrying the on-board emitter: @micropython.native and @micropython.viper from source still raise SyntaxError, a .mpy for another architecture still raises ValueError. Boards that already enable the emitter keep loading native .mpy, since the macro is also true when CIRCUITPY_ENABLE_MPY_NATIVE is set. Default is off; no board changes in this commit. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Turn on CIRCUITPY_LOAD_NATIVE for the Metro M4 AirLift Lite, Metro RP2040, Metro RP2350, Feather nRF52840 Express and Feather STM32F405 Express. Flash cost over the same build without the flag, and the time for a host-compiled viper mandelbrot (160x120, 64 iterations) against the float bytecode a user would write: Metro M4 AirLift Lite +1,904 B 431 ms (11,221 ms bytecode) Metro RP2040 +3,036 B 384 ms (13,942 ms bytecode) Metro RP2350 +2,876 B 261 ms (6,371 ms bytecode) Feather nRF52840 Express +2,432 B 781 ms (20,788 ms bytecode) Feather STM32F405 Express +2,444 B 416 ms (8,121 ms bytecode) The SAMD51 board is the reason for the flag: the on-board emitter overflows its flash by 12,804 B, the loader alone fits with 6,876 B free. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Second of five PRs for turbo. #11331 backported the native
.mpyloader but left it compiled out. This one adds theCIRCUITPY_LOAD_NATIVEbuild flag that turns it on, and enables it on five boards. Depends on #11331.What
CIRCUITPY_LOAD_NATIVE=1loads native and viper.mpybuilt on the host bympy-cross, without compiling in the on-board emitter. On-board compiling of@nativeand@viperis untouched and still lives behindCIRCUITPY_ENABLE_MPY_NATIVE.Why
The emitter costs 20 to 50 KB. On the Metro M4 AirLift Lite it does not fit at all:
CIRCUITPY_ENABLE_MPY_NATIVE=1fails to link,region FLASH_FIRMWARE overflowed by 13104 bytes(12.8 KB). The loader alone:Tested on hardware
All five flashed with
10.3.0-52-gcee7c17c08built from this branch, then driven over the serial REPL._mpyarch.mpyBoth variants returned checksum 3264000 on every board, so the compiled module computes what the source does. On all five, a wrong-arch (
xtensawin).mpyraisesValueError: incompatible .mpy arch, and@micropython.viperin source raisesSyntaxError: invalid micropython decorator.Not tested: Cortex-M7, non-English translations.
How I tested it
Scope
Metro M0 Express is left out, and it is closer than it looks. Stock leaves 1,660 bytes free and the loader needs about 1,868, so
CIRCUITPY_LOAD_NATIVE=1fails to link by 208 bytes:Dropping
safemode.pyclears it, but that is a poor trade for a shipping board and not something I want to propose. One maintainer thinks roughly 700 bytes could be recovered on the SAMD21, which would cover it three times over. Suggestions for where those 208 bytes should come from are very welcome, and I am happy to build and measure any candidate. If a way is found, the board is a one-line addition to this PR.AI assistance
Claude Code wrote the config lines and test script. I chose the boards, ran each one, checked the numbers.