Commit graph

52 commits

Author SHA1 Message Date
Jesús "gsus" Lapastora
149e382735 LibJIT: Integrate GDB JIT Interface with ELF builders
Provide a function to create an ELF image in a format GDB expects.
Outside of ELF platforms this image doesn't make much sense, and in
MacOS a Mach-O memory image is required: see
https://chromium.googlesource.com/v8/v8.git/+/refs/heads/main/src/diagnostics/gdb-jit.cc#1802

Since GDB requires active runtime addresses for the code, copying the
generated code into the image will not help. Instead, `build_gdb_image`
writes the runtime addresses of the code into a NOBITS `.text` section.
2023-12-07 15:34:38 -07:00
Jesús (gsus) Lapastora
bc70144df1 LibJIT: Enable registering JITted objects into GDB
The new JIT::GDB namespace enables registering JITted objects into GDB
dynamically.

Its clients just have to ensure the memory they give to
`register_into_gdb` is in a format that GDB can understand, either by
generating an object file in memory with debug info + symbols or by
registering a custom debug info parser.
None of these are implemented by this API; it only implements the
registering part and lets the client to choose the data format.

GDB JIT Interface:
https://sourceware.org/gdb/current/onlinedocs/gdb.html/JIT-Interface.html#JIT-Interface
Things to take into account from v8's docs, some of which we may
improve: https://v8.dev/docs/gdb-jit#known-limitations
2023-12-07 15:34:38 -07:00
Simon Wanner
6c8ab1ca0d LibJS/JIT: Add a builtin for Math.abs 2023-11-17 19:06:25 +01:00
Stephan Vedder
32352aa729 LibJS/JIT: Add a fast path for floating point comparisons 2023-11-16 11:43:44 +01:00
Bastiaan van der Plaat
d3b3e49e19 LibJS/JIT: Use the x86_64 setcc instruction to remove a branch 2023-11-14 09:54:48 +01:00
Simon Wanner
a3399fa13a LibJS/JIT: Expand Mul fast path to double & i32 combinations
Co-authored-by: Stephan Vedder <vedder@mbits.info>
2023-11-10 11:01:59 +01:00
Simon Wanner
867b8146cf LibJS/JIT: Expand Sub fast path to double & i32 combinations
Co-authored-by: Stephan Vedder <vedder@mbits.info>
2023-11-10 11:01:59 +01:00
Simon Wanner
5edab2679c LibJS/JIT: Expand Add fast path to double & i32 combinations
Co-authored-by: Stephan Vedder <vedder@mbits.info>
2023-11-10 11:01:59 +01:00
Simon Wanner
d91b376393 LibJS/JIT: Add helper for generating combined i32 & double fastpaths
Co-authored-by: Stephan Vedder <vedder@mbits.info>
2023-11-10 11:01:59 +01:00
Simon Wanner
578912aa6c LibJIT: Support unordered double comparison 2023-11-10 11:01:59 +01:00
Simon Wanner
a698c51a5b LibJIT: Add floating-point registers
Co-authored-by: Stephan Vedder <vedder@mbits.info>
2023-11-10 11:01:59 +01:00
Andreas Kling
55e467c359 LibJS/JIT: Add fast path for cached PutById 2023-11-09 16:02:14 +01:00
Stephan Vedder
13726fd3b7 LibJS/JIT: Add fast path for decrement
Generate jitted code for the decrement opcode.
2023-11-08 21:09:44 +01:00
Stephan Vedder
0e69f744df LibJS/JIT: Add increment instruction
Instead of using `Add` with an immediate of 1 use the `Inc` instruction
2023-11-08 21:09:44 +01:00
Simon Wanner
ff63222425 LibJIT: Add mov8/mov16/mov32 with zero- or sign-extension 2023-11-07 14:39:13 +01:00
Andreas Kling
5479bb6ac9 LibJIT/X86_64: Allow mul32() with immediate operand 2023-11-07 11:33:04 +01:00
iliadsh
24d5070520 LibJS/JIT: Add fast path for UnsignedRightShift 2023-11-07 10:17:04 +01:00
iliadsh
c956316c98 LibJS/JIT: Add fast path for RightShift 2023-11-07 10:17:04 +01:00
iliadsh
1244e91481 LibJS/JIT: Add fast path for LeftShift 2023-11-07 10:17:04 +01:00
Simon Wanner
64947506da LibJIT: Only include the Assembler header for the current platform 2023-11-06 10:28:05 +01:00
Nikodem Rabuliński
bacbd830fe LibJIT: Make X86_64Assembler::native_call take u64 instead of void*
Now that x86-specific Assembler will be compiled on every architecture
we can't rely on void* being the right width.
It also fixes compilation on targets which have void*
be different length from u64 (WASM in particular).
2023-11-06 10:05:42 +01:00
Nikodem Rabuliński
8aa35f4fab LibJIT+LibJS: Rename Assembler to X86_64Assembler
This is in preparation for making LibJIT support multiple architectures.
Assembler will now be typedefed to the specific assembler
for a particular architecture.
Additionally, there's now JIT_ARCH_SUPPORTED which is defined on
architectures which LibJIT supports.
2023-11-06 10:05:42 +01:00
Nikodem Rabuliński
9f5450527f LibJS+LibJIT: Make Assembler::native_call accept preserved_registers
This makes JS::JIT::Compiler less architecture-specific
and unifies aligning the stack into a single operation,
where previously we were doing it separately for preserved registers
and for stack arguments.
2023-11-06 10:05:42 +01:00
Andreas Kling
24fb009cf5 LibJS+LibJIT: Add fast path for Int32 * Int32 2023-11-03 10:48:02 +01:00
Andreas Kling
0aeb83b03f LibJS+LibJIT: Add fast path for Int32 ^ Int32 2023-11-03 10:48:02 +01:00
Andreas Kling
17ae6edd8e LibJS+LibJIT: Add fast path for Int32 - Int32 2023-11-03 10:48:02 +01:00
Andreas Kling
56b4586d65 LibJIT: Factor out JO instruction from add32()
Also add a jump_if(Condition, Label) helper. This will make it easier
to add more 32-bit binary ops that branch on overflow.
2023-11-03 10:48:02 +01:00
Simon Wanner
77dc7c4d36 LibJIT: Emit unwindable stack frames
Flip the order from save-registers,enter and leave,restore-registers
to enter,save-register and restore-registers,leave.

This way the return address is next to the saved frame pointer like
unwinding routines expect.
2023-11-02 07:37:41 +01:00
Hendiadyoin1
a42d849ec1 LibJIT: Widen allowed argument range for add32 and use REX if necessary
The REX prefix is elided when it is not needed, so no change in code
size is to be expected
2023-10-29 20:28:04 +01:00
Hendiadyoin1
248782461c LibJIT: Introduce and use REX prefix helper
This makes the code a bit more readable and in conjunction with the
ModRM helper should prevent some operand ordering bugs.
This also includes one incidental bugfix:
`sign_extend_32_to_64_bits`, was not setting the `REX.R` bit when
appropriate,
And one size obvious optimization:
We may now elide the REX prefix on `xor eax, eax` as storing to a 32 bit
register clears the upper 32 bit of said register, which is wanted here.
2023-10-29 20:28:04 +01:00
Hendiadyoin1
540963fbe3 LibJIT: Use ModRM helpers where applicable
This also widens the argument coverage of some helpers, to allow
memory offsets, this also consolidates the displacement size choosing.
This also stops us from some out argument ordering bugs, as we now just
need to look up the correct calling convention and call the correct
function.
2023-10-29 20:28:04 +01:00
Hendiadyoin1
b46c5545f1 LibJIT: Add ModRM helpers for argument encoding 2023-10-29 20:28:04 +01:00
Zaggy1024
56e8f52cb3 LibJIT/LibJS: Remove jump_if_***() in favor of jump_if()
The `jump_if()` function implements all the conditions already in use
and more, so let's avoid encouraging more wrapper functions.
2023-10-29 17:11:04 +01:00
Zaggy1024
288aff01cd LibJIT: Emit all Jcc jump instructions from one function
Since all conditional instructions use a certain number of bits to
encode the condition type (from my observation of `Jcc`, `SETcc` and
`CMOVcc`), let's abuse that to deduplicate some code!

This adds a `Condition` enum that defines the type of condition we are
jumping based on, whose underlying values are the values that must be
encoded to trigger each condition.
2023-10-29 17:11:04 +01:00
Zaggy1024
e717961000 LibJIT: Use test x, x instead of cmp x, 0 in all cases
The `test` instruction will have the same result as `cmp` when
comparing to zero, so let's always emit that code. This has no effect
until the following commit.
2023-10-29 17:11:04 +01:00
iliadsh
4f3945024a LibJS/JIT: Add fast path for Add Int32, Int32
This uses the 32-bit registers to perform the addition and bail if the
overflow flag (OF) is set.
2023-10-29 08:02:00 +01:00
Fabian Meyer
4afd782477 LibJIT: Fix Assembler::add(reg, reg) and sub(reg, reg) encoding 2023-10-28 23:13:22 +02:00
Simon Wanner
202a08ecc2 LibJS+LibJIT: Replace make_label() with default constructed label 2023-10-28 20:44:49 +02:00
Simon Wanner
ff265d1900 LibJIT: Support jumps to already linked labels 2023-10-28 20:44:49 +02:00
Andreas Kling
32d3a47058 LibJIT: Generate MOV ModR/M without displacement when possible
For non-extended register bases and 0x0 offset, we can emit a ModR/M
byte without displacement.
2023-10-28 20:26:35 +02:00
Andreas Kling
bbde64e0b6 LibJIT: Emit 8-bit PUSH imm when possible 2023-10-28 18:20:07 +02:00
Andreas Kling
926786e8d1 LibJS+LibJIT: Let users of JIT::Assembler handle caller-saved registers
Instead of JIT::Assembler making the decision for everyone and forcing
out every caller-saved register in the ABI onto the stack, we now leave
that decision to users of JIT::Assembler.
2023-10-28 18:20:07 +02:00
Idan Horowitz
863314ff10 LibJIT: Support passing stack arguments to native_call()s
The x86-64 SystemV ABI specifies that additional arguments after the
first 6 register-passed ones should be passed on the stack.
2023-10-28 14:44:45 +02:00
Andreas Kling
e63423554f LibJIT: Keep the stack pointer aligned for making native calls
Instead of adjusting the stack pointer before/after making native calls,
just make sure we come out of enter() with the stack pointer aligned
for making calls.

This is strictly a code size reduction. :^)
2023-10-28 09:10:38 +02:00
Idan Horowitz
538a570852 LibJIT+LibJS: Consolidate sized immediate assembler operands
This replaces the existing sized immediate operands with a unified
immediate operand that leaves the size handling to the assembler,
instead of the user.

This has 2 benefits:
1. The user doesn't need to know which specific operand size the
instruction expects when using it
2. The assembler automatically chooses the minimal operand size that
fits the given value, resulting in smaller code size without any
additional effort from the user. While the change is small, it still
has a noticeable effect on performance (since it increases the I$ hit
rate), resulting in 5% speedup on kraken a-star.
2023-10-28 07:04:14 +02:00
Andreas Kling
230aa1404c LibJIT: Only compile Assembler on x86_64 for now 2023-10-27 19:07:22 +02:00
Andreas Kling
8c745ca223 LibJS+LibJIT: Fix GCC build 2023-10-27 19:07:22 +02:00
Andreas Kling
5b198ccf32 LibJS+LibJIT: Don't turn patchable movs into xors with self
If a mov instruction is meant to be patchable, we don't want to rewrite
it as a xor, since that removes the slot where we'd patch in the right
value later.

Also, make sure to set both size bits in the REX prefix for xoring a
register with itself.
2023-10-27 19:07:22 +02:00
Andreas Kling
6f0baea594 LibJIT: Add jump_if_zero() and jump_if_not_zero() to Assembler
These can use test reg,reg on x86 which gives us a shorter encoding.
2023-10-27 19:07:22 +02:00
Andreas Kling
fb483f1950 LibJIT: Emit 8-bit displacement variants for mov when possible 2023-10-27 19:07:22 +02:00