* lightening/aarch64-cpu.c (SWPAL, CASAL): New instructions.
(swap_atomic, cas_atomic): Use better instructions if we have LSE.
* lightening/aarch64.c (get_hwcap, jit_get_cpu): Arrange to detect LSE
availability on GNU/Linux and Darwin.
Based on a patch by Tony Garnock-Jones. Thanks!
* lightening/x86.c (jit_try_shorten): If the address is within the
last instruction, don't shorten. If the intstruction is a jump, we
could elide it entirely in some cases, but we don't know if the user
captured the PC before calling jit_patch_here. Better to leave this
to the user.
Thanks to Helmut Eller for the bug report and test case in
https://gitlab.com/wingo/lightening/-/issues/17.
* lightening/lightening.c (abi_gpr_to_mem): Write whole words when
spilling GPRs to the stack. Always correct given that all Lightening
operations that write GPRs write the whole register, and the current
ABI targets allow writing the extra words. Closes#15.
Prevents useless over-alignment for ARM.
* lightening/lightening.c (struct jit_literal_pool_entry): Value is a
uintptr_t.
(emit_uintptr): New helper.
(emit_abs_reloc): Use new helper.
(patch_pending_literal): Value is a uintptr_t.
(emit_literal_pool): Adapt to literal entry being uintptr_t.
* lightening.h:
* lightening/lightening.c (jit_begin_data): Add max data size
parameter. If nonzero, can allow the JIT to avoid prematurely
emitting a constant pool.
(jit_end_data): Allow pending literals.
* tests/jmp_table.c (run_test): Use new API.
* lightening.h:
* lightening/lightening.c (jit_begin_data, jit_end_data)
(jit_emit_u8, jit_emit_u16, jit_emit_u32, jit_emit_u64): Add new raw
data-emitting primitives, bracketed by begin/end so that we can flush
constant pools first, if needed.
* lightening/lightening.c (struct jit_state): Add new emitting_data
flag.
(jit_begin, jit_reset, jit_end): Handle the new flag.
(emit_abs_reloc): Move here, from x86.c.
* lightening/x86.c (emit_abs_reloc): Remove.
(jit_try_shorten): Don't shorten if loc == start; could be raw data.
* tests/jmp_table.c: New test.
This is a followup to 1bb909a44d. It
reproduces the bug that 1bb909a44d fixes
on ARMv7.
* tests/movi.c: New file.
Co-authored-by: Ludovic Courtès <ludo@gnu.org>
* lightening/arm-cpu.c (rotate_left): Fix the case of rotating by zero,
which produced undefined behavior. Many thanks to Andrew
Gierth (andrew at tao11 riddles org uk) for the debugging and the
fix.
It is unlikely for any ARM code to be close enough to not have needed
a veneer, but it is possible, especially if running in a program with
another JIT library.
* lightening/x86.c (reset_abi_arg_iterator): Reserve 32 stack bytes on
64-bit Windows systems, in accordance with ABI. Thanks a million to
Charles Stanhope for the patch and to Mike Gran for testing!
The existing calli / callr interface is for ABI calls. Sometimes though
you want to call some of your own code, just to get the current return
address. ARM's branch-and-link instructions are ideal for this but they
don't exist on x86; there we emulate them by adding corresponding
pop_link_register / push_link_register instructions that are no-ops on
ARM.
* lightening.h (FOR_EACH_INSTRUCTION): Add jit_jmpi_with_link,
pop_link_register, push_link_register.
* lightening/arm-cpu.c:
* lightening/x86-cpu.c:
* lightening/aarch64-cpu.c (jmpi_with_link, push_link_register)
(pop_link_register): Add implementations.
* lightening/arm.h:
* lightening/aarch64.h:
* lightening/x86.h (JIT_LR): New definition.
* tests/link-register.c: New test.
These operations emit the same code that GCC does for corresponding
operations under the sequential consistency memory model. It would be
possible to relax to acquire/release or something in the future.