Skip to content

Make AVM_MINIMAL_OPCODES default on MCUs - #2465

Merged
bettio merged 3 commits into
atomvm:release-0.7from
bettio:minimal-opcodes-on-mcus
Nov 3, 2026
Merged

bettio merged 3 commits into
atomvm:release-0.7from
bettio:minimal-opcodes-on-mcus

Conversation

@bettio

@bettio bettio commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

AVM_MINIMAL_OPCODES leaves out opcodes that the compiler emits only
with legacy options, saving flash on microcontrollers. It also left
out bs_test_tail2, which OTP 27+ still emits with no_ssa_opt and
beam_debug_info (OTP 28+), so such modules aborted with "Undecoded
opcode: 121". With bs_test_tail2 always compiled in, code compiled
with default options on OTP 27+ (Erlang, Elixir and Gleam) never
needs the left-out opcodes, so the option is now on by default for
ESP32, STM32 and RP2. Generic UNIX and emscripten keep it off.

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

AVM_MINIMAL_OPCODES compiled out bs_test_tail2 together with
bs_test_unit, assuming that only the no_bs_match and
no_ssa_opt_bs_ensure compiler options emit it. Since OTP 27, no_ssa_opt
also makes the compiler fall back to bs_test_tail2, and so does
beam_debug_info on OTP 28 and later, which Elixir 1.21 suggests as an
erlc_options value. Such modules loaded fine, then aborted with
"Undecoded opcode: 121".

Always compile bs_test_tail2 in, and add a test compiled with
no_ssa_opt, so the opcode is covered on every OTP version, including
OTP 29 where no_bs_match is gone.

Signed-off-by: Davide Bettio <davide@uninstall.it>
AVM_MINIMAL_OPCODES is about to become the default on microcontrollers,
but CI never builds or tests it. Add a generic UNIX job with it.

On such builds, skip the three tests that force the no_bs_create_bin or
no_bs_match compiler options on OTP 27 and 28: their modules use the
opcodes the option leaves out, and the VM would abort the whole run.

Signed-off-by: Davide Bettio <davide@uninstall.it>
@bettio bettio changed the title Minimal opcodes on mcus Make AVM_MINIMAL_OPCODES default on MCUs Nov 2, 2026
Flash space is tight on microcontrollers, and the opcodes that
AVM_MINIMAL_OPCODES leaves out are emitted only by the legacy
no_bs_create_bin, no_bs_match and no_ssa_opt_bs_ensure compiler
options. No OTP release from 27 to 29 emits them with its default
options, and neither the Elixir nor the Gleam compiler passes those
options.

Enable it by default on ESP32 and RP2 too, like STM32 already does.
This also covers ESP32-C5, which had its own special case. Generic
UNIX and emscripten keep the full opcode set. Document the option and
describe what it leaves out more precisely.

Signed-off-by: Davide Bettio <davide@uninstall.it>
@bettio
bettio force-pushed the minimal-opcodes-on-mcus branch from ffca1f9 to 0faafa7 Compare November 3, 2026 22:47
@bettio
bettio merged commit d4d541f into atomvm:release-0.7 Nov 3, 2026
170 of 171 checks passed
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.

2 participants