Skip to content

[Arm32-JIT] Elixir fixes#25

Open
ziopio wants to merge 4 commits into
arm32-jitfrom
ziopio/elixir
Open

[Arm32-JIT] Elixir fixes#25
ziopio wants to merge 4 commits into
arm32-jitfrom
ziopio/elixir

Conversation

@ziopio

@ziopio ziopio commented Jul 2, 2026

Copy link
Copy Markdown

This PR is inspired by #23

Co-authored-by: Frank Hunleth <fhunleth@troodon-software.com>
ziopio and others added 3 commits July 2, 2026 14:12
This binary OP might generate too much code. We cannot wait the next check. We need to act within this emitter.

Co-authored-by: Frank Hunleth <fhunleth@troodon-software.com>
Co-authored-by: Frank Hunleth <fhunleth@troodon-software.com>
a.asr(TMP, TMP, imm(_TAG_IMMED1_SIZE));

if (Base.get() != 0) {
if (Support::isUInt12((Sint)Base.get())) {

@ziopio ziopio Jul 2, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change fixes a bug while loading Elixir.String.Tokenizer.
This caused the next line to emit sub r12 r12 257 which is illegal.

// This emitter may introduce more code then expected.
// This may overshoot the 4KB displacement limit of few constants.
// To avoid it we check the pending stubs between every segment.
check_pending_stubs();

@ziopio ziopio Jul 2, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

During loading of module Elixir.Exceptions this emitter was producing more then 2KB of assembly.

This was breaking asmjit code generation as the next stub creation was forced to handle a displacement value that was over 4KB.

The displacement happened to be over 4KB by 100~200 bytes

@ziopio ziopio Jul 3, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fhunleth while rebasing on maint-27 I realized that the OTP team fixed THIS same BUG in 27.2, they basically did the same fix for arm64, but added the check_pending_stubs at the end of the loops, which sligthly makes more sense.

@ziopio

ziopio commented Jul 2, 2026

Copy link
Copy Markdown
Author

@fhunleth please let me know if these fixes are also working on your hardware.

I tested with qemu and I think I pinpointed the issues you experienced.

@fhunleth

fhunleth commented Jul 2, 2026

Copy link
Copy Markdown

@ziopio This is great! Thank you for digging through all of that AI code I shared. I'll should be able to try it out tomorrow!

@ziopio

ziopio commented Jul 3, 2026

Copy link
Copy Markdown
Author

@fhunleth these commits are already on the branch arm32-jit-maint-27 I suggest you to try this new branch that uses latest OTP-27 and can run elixir 1.20.2

@fhunleth

fhunleth commented Jul 7, 2026

Copy link
Copy Markdown

@ziopio This branch didn't work, but it is really close. To make it work, I only had to add this change:

https://github.com/fhunleth/otp/blob/41142ef00fb14d6567cd5d314e033e4d6baf8eaf/erts/emulator/beam/jit/arm/32/beam_asm_module.cpp#L574-L577

$ diff erlang-27.0/erts/emulator/beam/jit/arm/32/beam_asm_module.cpp erlang-27.0-works-2/erts/emulator/beam/jit/arm/32/beam_asm_module.cpp 
574c574,577
<                                  Constant{.latestOffset = maxOffset,
---
>                                  Constant{.latestOffset = std::max<ssize_t>(
>                                                    currOffset,
>                                                    maxOffset -
>                                                            STUB_CHECK_INTERVAL),

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