Commit graph

32 commits

Author SHA1 Message Date
Simon Wanner
64947506da LibJIT: Only include the Assembler header for the current platform 2023-11-06 10:28:05 +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
Andreas Kling
d09bc54586 LibJIT: Encode mov(reg, 0) as xor(reg, reg)
This uses less space for the same result. :^)
2023-10-27 19:07:22 +02:00
Andreas Kling
5b87d26027 LibJIT+LibJS: Move JIT::Assembler into a new LibJIT library
This will allow other parts of the system to generate machine code
at runtime. :^)
2023-10-27 19:07:22 +02:00
Renamed from Userland/Libraries/LibJS/JIT/Assembler.h (Browse further)