Skip to content

Commit 378fd60

Browse files
committed
Merge pull request #1829 from pguyot/w34/jit-arm
Just in time compilation with armv6m target Continuation of: - #1770 - #1773 - #1833 - #1834 - #1835 - #1890 - #1878 - #1881 - #1887 The target is suitable for Pico, Pico2 and STM32. Benchmark test on a Pico with SMP disabled shows a speed increase from 14% to 62%.   | native (w34/jit-arm) | emulated (main) -- d8ecc02 | % -- | -- | -- | -- pingpong_speed_test | 17437587 | 27590085 | 37 % prime_speed_test | 13257293 | 35212412 | 62 % prng_test | 1128949 | 1500967 | 25 % pi_test | 26759537 | 58693061 | 54 % sudoku_solution_test | 6420801 | 7471461 | 14 % sudoku_puzzle_test | 254335968 | 333834045 | 24 % Remark: the current backend requires 64 bits floats. 32 bits floats would need a specific variant. 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
2 parents 20be95c + 45e22e8 commit 378fd60

29 files changed

+7932
-41
lines changed

.github/workflows/build-and-test.yaml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ jobs:
321321
cmake_opts_other: "-DAVM_DISABLE_JIT=OFF"
322322
jit_target_arch: "aarch64"
323323

324-
# armhf build
324+
# armhf builds
325325
- os: "ubuntu-24.04"
326326
cc: "arm-linux-gnueabihf-gcc"
327327
cxx: "arm-linux-gnueabihf-g++"
@@ -336,6 +336,21 @@ jobs:
336336
arch: "armhf"
337337
library-arch: arm-linux-gnueabihf
338338

339+
- os: "ubuntu-24.04"
340+
cc: "arm-linux-gnueabihf-gcc"
341+
cxx: "arm-linux-gnueabihf-g++"
342+
# -D_FILE_OFFSET_BITS=64 is required for making atomvm:posix_readdir/1 test work
343+
# otherwise readdir will fail due to 64 bits inode numbers with 32 bit ino_t
344+
cflags: "-mcpu=cortex-a7 -mfloat-abi=hard -O2 -mthumb -mthumb-interwork -D_FILE_OFFSET_BITS=64"
345+
otp: "28"
346+
elixir_version: "1.17"
347+
rebar3_version: "3.24.0"
348+
cmake_opts_other: "-DAVM_DISABLE_JIT=OFF -DAVM_JIT_TARGET_ARCH=armv6m -DCMAKE_TOOLCHAIN_FILE=${RUNNER_TEMP}/armhf_toolchain.cmake"
349+
compiler_pkgs: "crossbuild-essential-armhf libc6-dbg:armhf zlib1g-dev:armhf libmbedtls-dev:armhf qemu-user qemu-user-binfmt binfmt-support"
350+
arch: "armhf"
351+
library-arch: arm-linux-gnueabihf
352+
jit_target_arch: "armv6m"
353+
339354
# s390x build
340355
- os: "ubuntu-24.04"
341356
cc: "s390x-linux-gnu-gcc"
@@ -586,7 +601,7 @@ jobs:
586601
587602
- name: "Test: test_jit.avm with valgrind"
588603
if: matrix.library-arch == '' && matrix.otp != '21' && matrix.otp != '22'
589-
timeout-minutes: 30
604+
timeout-minutes: 60
590605
working-directory: build
591606
run: |
592607
ulimit -c unlimited

CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,14 @@ if (NOT AVM_DISABLE_JIT AND NOT DEFINED AVM_JIT_TARGET_ARCH)
5757
set(AVM_JIT_TARGET_ARCH ${CMAKE_SYSTEM_PROCESSOR})
5858
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm64|aarch64$")
5959
set(AVM_JIT_TARGET_ARCH "aarch64")
60+
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^cortex-m.+$")
61+
set(AVM_JIT_TARGET_ARCH "armv6m")
6062
else()
61-
message(FATAL "JIT is not supported on ${CMAKE_SYSTEM_PROCESSOR}")
63+
message(FATAL_ERROR "JIT is not supported on ${CMAKE_SYSTEM_PROCESSOR}")
6264
endif()
6365
endif()
6466

65-
set(AVM_PRECOMPILED_TARGETS "x86_64;aarch64" CACHE STRING "Targets to precompile code to if AVM_DISABLE_JIT is OFF or AVM_ENABLE_PRECOMPILED is ON")
67+
set(AVM_PRECOMPILED_TARGETS "x86_64;aarch64;armv6m" CACHE STRING "Targets to precompile code to if AVM_DISABLE_JIT is OFF or AVM_ENABLE_PRECOMPILED is ON")
6668

6769
if((${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") OR
6870
(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") OR

CMakeModules/BuildErlang.cmake

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,24 @@ macro(pack_lib avm_name)
194194
)
195195
set(target_deps ${target_deps} ${avm_name}-pico.uf2 ${avm_name}-pico2.uf2)
196196

197+
if(NOT AVM_DISABLE_JIT OR AVM_ENABLE_PRECOMPILED)
198+
add_custom_command(
199+
OUTPUT ${avm_name}-armv6m-pico.uf2
200+
DEPENDS ${avm_name}-armv6m.avm UF2Tool
201+
COMMAND ${CMAKE_BINARY_DIR}/tools/uf2tool/uf2tool create -o ${avm_name}-armv6m-pico.uf2 -s 0x10100000 ${avm_name}-armv6m.avm
202+
COMMENT "Creating UF2 file ${avm_name}-armv6m.uf2"
203+
VERBATIM
204+
)
205+
add_custom_command(
206+
OUTPUT ${avm_name}-armv6m-pico2.uf2
207+
DEPENDS ${avm_name}-armv6m.avm UF2Tool
208+
COMMAND ${CMAKE_BINARY_DIR}/tools/uf2tool/uf2tool create -o ${avm_name}-armv6m-pico2.uf2 -f data -s 0x10100000 ${avm_name}-armv6m.avm
209+
COMMENT "Creating UF2 file ${avm_name}-armv6m.uf2"
210+
VERBATIM
211+
)
212+
set(target_deps ${target_deps} ${avm_name}-armv6m-pico.uf2 ${avm_name}-armv6m-pico2.uf2)
213+
endif()
214+
197215
add_custom_target(
198216
${avm_name} ALL
199217
DEPENDS ${target_deps}

libs/jit/include/jit.hrl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
-define(JIT_ARCH_X86_64, 1).
2424
-define(JIT_ARCH_AARCH64, 2).
25+
-define(JIT_ARCH_ARMV6M, 3).
2526

2627
-define(JIT_VARIANT_PIC, 1).
2728

libs/jit/src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ set(ERLANG_MODULES
2929
jit_stream_mmap
3030
jit_aarch64
3131
jit_aarch64_asm
32+
jit_armv6m
33+
jit_armv6m_asm
3234
jit_x86_64
3335
jit_x86_64_asm
3436
)

0 commit comments

Comments
 (0)