1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-15 12:24:58 +00:00
Commit graph

85 commits

Author SHA1 Message Date
Simon Wanner
c697ff61f6 LibJS/JIT: Compile the IteratorClose instruction 2023-10-29 17:36:09 +01:00
Simon Wanner
233502a10c LibJS/JIT: Compile the IteratorResultValue instruction 2023-10-29 17:36:09 +01:00
Simon Wanner
e7fdf9c7e5 LibJS/JIT: Compile the ThrowIfNullish instruction 2023-10-29 17:36:09 +01:00
Simon Wanner
9e2edc3085 LibJS/JIT: Compile the ThrowIfNotObject instruction 2023-10-29 17:36:09 +01:00
Simon Wanner
39deb365d2 LibJS/JIT: Compile the IteratorResultDone instruction 2023-10-29 17:36:09 +01:00
Simon Wanner
045a1386d8 LibJS/JIT: Compile the IteratorNext instruction 2023-10-29 17:36:09 +01:00
Simon Wanner
4f8f8b7792 LibJS/JIT: Compile the GetIterator instruction 2023-10-29 17:36:09 +01:00
Simon Wanner
d247744a3e LibJS/JIT: Compile the SuperCallWithArgumentArray instruction 2023-10-29 17:36:09 +01:00
Simon Wanner
09dce5f1bd LibJS/JIT: Compile the BlockDeclarationInstantiation instruction 2023-10-29 17:36:09 +01:00
Simon Wanner
a28d6291ad LibJS/JIT: Generate switch cases using X macro 2023-10-29 17:36:09 +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
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
Simon Wanner
4b23a7dfb4 LibJS/JIT: Compile the NewClass bytecode instruction 2023-10-29 07:44:11 +01:00
Simon Wanner
ddce5e03c2 LibJS/JIT: Clear unwind context handler on usage
This clears the handler pointer of the current unwind context
before jumping to it. This is necessary to not loop infinitely
when an exception is thrown from the handler.
In that case control flow should go to the finalizer instead.

This mirrors how unwind_context.handler_called is used in the
Bytecode::Interpreter.

`try { throw 1 } catch (e) { throw 2 } finally {}` now runs
without looping infinitely in the catch block.
2023-10-29 07:44:11 +01:00
Simon Wanner
224f92f6e4 LibJS/JIT: Compile the CreateVariable bytecode instruction 2023-10-29 07:44:11 +01:00
Simon Wanner
1d3062de9e LibJS/JIT: Compile the ConcatString bytecode instruction 2023-10-29 07:44:11 +01:00
Evgeniy Baskov
9258e253ca LibJS/JIT: Fix crash in CallWithArgumentArray 2023-10-28 22:33:45 +02:00
Andreas Kling
40ecf7689b LibJS/JIT: Run clang-format on Compiler.cpp 2023-10-28 21:02:13 +02:00
Simon Wanner
2cbc9d6970 LibJS/JIT: Consolidate exception handling code
Instead of emitting the lengthy exception checking/handling routine,
we only emit code for checking the presence of an exception and jump
to a common exception handler.

This code size optimization saves 2.08MiB on Kraken/ai-astar.js
2023-10-28 20:44:49 +02:00
Simon Wanner
202a08ecc2 LibJS+LibJIT: Replace make_label() with default constructed label 2023-10-28 20:44:49 +02:00
Idan Horowitz
b2d8d0c270 LibJS: Compile the CallWithArgumentArray bytecode instruction 2023-10-28 20:27:16 +02:00
Idan Horowitz
2b65a80ecb LibJS: Compile the NewBigInt bytecode instruction 2023-10-28 20:27:16 +02:00
Idan Horowitz
d200361620 LibJS: Remove useless indirection in compile_new_{function, regexp}
The cxx_new_* functions have the exact same signature as the underlying
function they redirect to, so there's no need for them. Removing them
saves us a couple of opcodes.
2023-10-28 20:27:16 +02:00
Andreas Kling
87baf140f2 LibJS/JIT: Use PUSH imm when pushing null unwind context pointer(s)
Small code size optimization, saves 252 bytes on Kraken/ai-astar.js :^)
2023-10-28 18:20:07 +02:00
Andreas Kling
fff82c5ffe LibJS/JIT: Only preserve VM& when making native call to C++
Instead of pushing and popping every single caller-saved registers,
we can optimize code size (and speed!) by only pushing the one register
we actually care about: RDI (since it holds our VM&).

This means that native calls may clobber every other caller-saved
register, so this is something that you have to be aware of when
emitting native calls in the JIT.

This reduces code size on Kraken/ai-astar.js by 553 KiB and makes
execution time ~6% faster as well! :^)
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
Andreas Kling
9afd12a8ba LibJS/JIT: Consolidate exits from the jitted code
Instead of emitting the "restore callee-saved registers and return"
sequence again and again, just emit it once at the end of the generated
code, and have everyone jump to it.

This is a code size optimization that saves 207KiB on Kraken/ai-astar.js
2023-10-28 18:20:07 +02:00
Idan Horowitz
0768bf2623 LibJS: Execute the finalizer when returning from a try block in the JIT
This fixes 1 of the 2 remaining failing test-js tests.
2023-10-28 17:11:47 +02:00
Idan Horowitz
78cac671b6 LibJS: Pass the expression string to cxx_call as a stack argument
This restores the bytecode interpreter's original call exception
throwing behaviour to the JIT.
This also fixes 8 of the 10 failing test-js tests when running with the
JIT enabled.
2023-10-28 14:44:45 +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
Simon Wanner
ec8330b647 LibJS/JIT: Dump disassembly of generated code using LibX86
This avoids the need for redirecting stdout to a file and using
ndisasm, which can lead to problems if other things are printed.
2023-10-27 21:49:55 +02:00
Andreas Kling
c1551a64dc LibJS/JIT: Compile the NewRegExp bytecode instruction 2023-10-27 19:07:22 +02:00
Andreas Kling
d6756decb9 LibJS/JIT: Compile the JumpNullish bytecode instruction 2023-10-27 19:07:22 +02:00
Andreas Kling
17b2c7d965 LibJS/JIT: Compile the TypeofLocal bytecode instruction 2023-10-27 19:07:22 +02:00
Andreas Kling
a645b9c6c3 LibJS/JIT: Stub out the JIT compiler on everything but ARCH(X86_64)
We don't support other architectures yet!
2023-10-27 19:07:22 +02:00
Andreas Kling
d1c701f79f LibJS/JIT: Compile the Create/LeaveLexicalEnvironment instructions 2023-10-27 19:07:22 +02:00
Andreas Kling
935d67cfcf LibJS/JIT: Compile the GetCalleeAndThisFromEnvironment instruction 2023-10-27 19:07:22 +02:00
Andreas Kling
dabaaabfc0 LibJS/JIT: Support the GetVariable bytecode instruction 2023-10-27 19:07:22 +02:00
Andreas Kling
17657d012f LibJS/JIT: Consider compilation failed if mprotect(PROT_EXEC) fails 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
8eba60d015 LibJS/JIT: Only try JIT compilation when LIBJS_JIT is set in environment
Instead of adding a flag to everything everywhere, let's try using an
environment variable this time.
2023-10-27 19:07:22 +02:00
Andreas Kling
ae273e8e20 LibJS/JIT: Add simple compile-time flags for logging & dumping code 2023-10-27 19:07:22 +02:00
Andreas Kling
3b239b64ff LibJS/JIT: Remove debug spam in cxx_increment() 2023-10-27 19:07:22 +02:00
Andreas Kling
e2f5bfb4c4 LibJS/JIT: Always mask everything but LSB in ToBoolean
As it turns out, cxx_to_boolean() may return "bool" as other values
than just 0 or 1. This happens when the C++ compiler decides to only
update the AL portion of the RAX return value register instead of
the whole thing.
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
8b32e98f3f LibJS/JIT: Simplify Increment Int32 fast path
When we know the value is a positive Int32 less than 0x7fffffff,
it's safe to just add 1 to it and use that as the final result.
This avoids the work of re-adding the INT32_TAG.
2023-10-27 19:07:22 +02:00
Andreas Kling
b43e38112c LibJS/JIT: Use JIT::Assembler::jump_if_zero() to improve code size 2023-10-27 19:07:22 +02:00
Andreas Kling
bfb527e614 LibJS/JIT: Call throw_if_needed_for_call() in cxx_call()
This allows test-js to run to completion (although we do still have
some bugs to track down.)
2023-10-27 19:07:22 +02:00
Andreas Kling
022974a43a LibJS/JIT: Let Compiler keep per-BasicBlock state internally
Compiler now has a BasicBlockData struct for each BasicBlock. The struct
contains all the stuff that we previously stored with the
Bytecode::BasicBlock.
2023-10-27 19:07:22 +02:00
Andreas Kling
8a24d00b1a LibJS/JIT: Preserve the accumulator across PutByFoo
This ensures that we don't clobber the accumulator when putting a value
to a setter.
2023-10-27 19:07:22 +02:00