py: Add AArch64 native emitter and inline assembler. - #19697
Open
StrideZhou wants to merge 1 commit into
Open
StrideZhou wants to merge 1 commit into
StrideZhou wants to merge 1 commit into
Conversation
|
Code size report: |
StrideZhou
force-pushed
the
aarch64-pr
branch
from
September 13, 2026 03:47
a5a9dba to
3903c47
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #19697 +/- ##
==========================================
+ Coverage 98.55% 98.59% +0.03%
==========================================
Files 182 182
Lines 23335 23335
Branches 5 5
==========================================
+ Hits 22998 23006 +8
+ Misses 336 328 -8
Partials 1 1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
StrideZhou
force-pushed
the
aarch64-pr
branch
3 times, most recently
from
September 13, 2026 15:12
2316851 to
7d3d35b
Compare
StrideZhou
marked this pull request as ready for review
September 13, 2026 16:38
StrideZhou
marked this pull request as draft
September 14, 2026 06:27
StrideZhou
force-pushed
the
aarch64-pr
branch
4 times, most recently
from
September 16, 2026 15:56
b402048 to
d48085c
Compare
StrideZhou
marked this pull request as ready for review
September 20, 2026 10:02
StrideZhou
force-pushed
the
aarch64-pr
branch
from
September 20, 2026 12:37
d48085c to
873554b
Compare
Add a complete AArch64 (ARMv8-A) assembler and native/Viper emitter to the MicroPython compiler. This enables runtime native code generation and an inline assembler for 64-bit ARM targets. Key additions include: - Core AArch64 assembler, native/Viper emitters, and instruction encoders in py/. - QEMU port support: VIRT_AARCH64 and VIRT_AARCH64_FLOAT boards, including startup, exception handling, timer, PL011 UART, and semihosting. Hardware-accelerated sqrt/sqrtf in libm. - Unix port support for AArch64 native/inline emitters. - Comprehensive test suite covering 64-bit constants, large stack frames, and large pointer offsets. - CI jobs for QEMU bare-metal and Unix AArch64 emulation. Note that persistent native .mpy loading is deliberately disabled for AArch64 because the current .mpy format has no available architecture IDs. This is deferred to the .mpy v7 toolchain work (see micropython#19386). This change does not increase the code size for any other architecture, as the new emitters are only compiled when targeting AArch64. Signed-off-by: Stride Zhou <stride_anderson@qq.com>
StrideZhou
force-pushed
the
aarch64-pr
branch
from
September 20, 2026 12:39
873554b to
a1f9857
Compare
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.
1. Motivation & Problem Statement
Currently, MicroPython lacks runtime native code generation (Native/Viper) and inline assembler support for the 64-bit ARM (AArch64/ARMv8-A) architecture. This limits performance optimization opportunities on modern 64-bit ARM platforms, such as native Unix hosts or QEMU-emulated environments. This PR aims to bridge this gap by providing a complete, robust AArch64 instruction emission and inline assembly framework.
2. Summary of Changes
This PR introduces ~5,400+ lines of code, structured across the following areas:
py/): Added the AArch64 assembler, Native/Viper code emitters, and inline assembler instruction encoders.ports/qemu/):VIRT_AARCH64andVIRT_AARCH64_FLOATboard configurations.shared/runtime/semihosting_aarch64.c).sqrtandsqrtfimplementations using the AArch64fsqrtinstruction (lib/libm/andlib/libm_dbl/).qemu-aarch64user-mode emulation.docs/reference/asm_aarch64.rst, detailing register calling conventions, supported instruction subsets (including Python keyword workarounds likeand_), and known limitations.tests/):native_const64.py,viper_const64.py), large stack frame locals (viper_many_locals.py), and large pointer offsets (viper_ptr_large_offset.py).asm_test.py,native_test.py,viper_test.py) to gracefullySKIPif the target lacks a.mpyarchitecture ID, preventing false CI failures..github/workflows/andtools/ci.sh, including automated ARM GNU toolchain download/verification, QEMU bare-metal build/test, Unix user-mode emulation test, and dedicatedgcovcoverage collection for the new emitter files.3. Testing & Verification
Strictly adhering to project CI standards, the following verifications have been completed:
mpy-crossand the Unix port with AArch64 emitters enabled. Feature detection correctly reportsaarch64.VIRT_AARCH64test suite, inline-assembler tests, and Unix AArch64 bytecode/native test suites, generating accurategcovreports forasmaarch64.c,emitnaarch64.c, andemitinlineaarch64.c.4. Trade-offs, Limitations & Alternatives
(Addressing MicroPython's core concerns regarding code size and architectural compatibility)
+0 +0.000%)..mpyArchitecture ID (Critical Limitation): The current.mpyfile format has exhausted its available architecture IDs. Consequently, persistent native.mpyloading is deliberately disabled for AArch64. Inline assembler and Native/Viper code are compiled at runtime only. This is a pragmatic trade-off; architecture-ID allocation is deferred until the.mpyv7 format and native toolchain design are updated (see Issue mpy-cross/mpy-ld/natmod Please add target for aarch64 #19386).pushandpopoperations automatically pad an odd number of registers with a dummy slot (using the zero register) to maintain strict 16-byte stack pointer (sp) alignment.5. Compliance & Generative AI Declaration