Skip to content

Conversation

@k0kubun
Copy link
Member

@k0kubun k0kubun commented Aug 27, 2025

This PR addresses Max's suggestion at #14357 (comment).

Adding SCRATCH2 allows arm64_emit to emit IncrCounter without relying on arm64_split, which lets compile_side_exits remove the cfg!(target_arch = "aarch64") branch. I don't think taking Opnd::const_ptr in IncrCounter as Max suggested isn't worth it, which will duplicate more code in arm64_emit, so it still takes Opnd::Mem.

It generally doesn't seem like a good idea to waste a register when you can save it with no run-time overhead, especially when it's for --zjit-stats. But at the same time, it seems useful to remove an extra register pressure that the other architecture doesn't have for the same LIR instruction.

x18 is a platform register. Since we control the use of every register in JIT code, it seems safe to use it as an extra caller-saved register. We don't seem to have any more caller-saved registers.

@k0kubun k0kubun marked this pull request as ready for review August 27, 2025 17:32
@matzbot matzbot requested a review from a team August 27, 2025 17:32
Copy link
Member

@XrXr XrXr left a comment

Choose a reason for hiding this comment

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

x18 is a platform register. Since we control the use of every register in JIT code, it seems safe to use it as an extra caller-saved register. We don't seem to have any more caller-saved registers.

It's not a great idea to run afoul macOS's platform rules for this https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms#Respect-the-purpose-of-specific-CPU-registers

It's hard to predict what can go wrong. Maybe they use it in the kernel for something in which case we actually don't have full control over that register because we could be preempted in the region of code that uses the register.

@k0kubun
Copy link
Member Author

k0kubun commented Aug 27, 2025

https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms#Respect-the-purpose-of-specific-CPU-registers
The platforms reserve register x18. Don’t use this register.

Heh, interesting. Thanks for pointing that out.

If we don't have an additional caller-saved register, I'd rather leave the cfg!(target_arch = "aarch64") branch in compile_side_exits as is. Assembler is not designed to hide abstraction leaks after split/alloc_regs in the first place. We should treat compile_side_exits like part of the emit pass, which happens to have slightly richer API.

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