Skip to content

Conversation

@pguyot
Copy link
Collaborator

@pguyot pguyot commented Oct 18, 2025

Continuation of:

Add the ability to perform just in time compilation directly on Raspberry Pi Pico. Erlang bytecode is compiled to armv6m on the first run and directly executed on subsequent runs. In this PR, the native code compilation does not take advantage of being done on the device, it still generates position independent code.

If Erlang modules include Type chunk, the same optimizations that happen on the desktop with precompilation could be done on the Pico, however current release (0.7.5) of packbeam prunes the Type chunk.

Just in time compilation on the Pico is achieved by:

  • Adding a flush call after JIT is performed, which is noop on all platforms except on armv6m where we flush the literal pool (normally a noop, though, as the pool should have been flushed earlier).
  • Updating avm API to fetch the last section named end.
  • Adding a jit_stream_flash for RP2 platform and adding a cache native code mechanism that rely on the avm end section on RP2 to find out where to flash jit code (after the last end) and detect if avm were updated.

These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).

SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later

@pguyot pguyot force-pushed the w42/pico-embedded-jit branch 2 times, most recently from fea5189 to 1563eeb Compare October 24, 2025 06:05
@pguyot pguyot force-pushed the w42/pico-embedded-jit branch 2 times, most recently from 0630183 to 2e4f0df Compare October 25, 2025 08:35
Use a cache to remember tail calls that were already implemented and
replace further implementations of the same tail call with a jump to the
previous implementation.

Coverage shows that all cases are covered in libs/estdlib/src and libs/jit/src:

OP_RETURN: 50 misses, 1735 hits (97%)
OP_JUMP/OP_CALL_LAST/OP_CALL_ONLY: 656 misses, 389 hits (37%)
OP_CALL_LAST: 220 misses, 206 hits (48%)
OP_FUNC_INFO: 58 misses, 1619 hits (97%)

Signed-off-by: Paul Guyot <[email protected]>
This is required as flash chips are programmed by setting bits from 1 to 0,
and erased by setting all bits to 0, so placeholders set to FF can be
replaced without erasing a whole block.

Signed-off-by: Paul Guyot <[email protected]>
Introduce jit_stream_flash.c common implementation that leverages
(common) flash behavior that can be written from 1 to 0.

Signed-off-by: Paul Guyot <[email protected]>
@pguyot pguyot force-pushed the w42/pico-embedded-jit branch from 2e4f0df to 49d6693 Compare October 25, 2025 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant