1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-15 17:34:59 +00:00
Commit graph

43 commits

Author SHA1 Message Date
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
Andreas Kling
5bd93f34af LibJS/JIT: Sign-extend integers before comparing in LessThan fast path 2023-10-27 19:07:22 +02:00
Andreas Kling
4b7f5f4ae7 LibJS/JIT: Allow multiple jumps to the same Assembler::Label 2023-10-27 19:07:22 +02:00
Andreas Kling
1fb95c7df9 LibJS/JIT: Add fast path for LessThan Int32 < Int32
This uses a new branch_if_both_int32() helper.

It's interesting to note that we can compare encoded Int32 values
without stripping the INT32_TAG, since it doesn't affect signedness
of values.
2023-10-27 19:07:22 +02:00
Andreas Kling
ea65214c57 LibJS/JIT: Add fast path for Increment with Int32 value
This uses a new branch_if_int32() mechanism that takes a code generating
lambda whose code will run if the input register is an Int32 JS::Value.
2023-10-27 19:07:22 +02:00
Andreas Kling
e4c4fb09f9 LibJS/JIT: Add fast path for the ResolveThisBinding codegen
We now generate a fast path for cached `this` values. The first time
`this` is resolved within a function, we call out to C++, but then
all subsequent accesses will hit the cache in Register::this_value().
2023-10-27 19:07:22 +02:00
Andreas Kling
7097169967 LibJS/JIT: Compile the PutByValue bytecode instruction 2023-10-27 19:07:22 +02:00
Andreas Kling
9c93d100d1 LibJS/JIT: Compile the NewFunction bytecode instruction 2023-10-27 19:07:22 +02:00
Andreas Kling
a913ac5799 LibJS/JIT: Compile the NewArray bytecode instruction 2023-10-27 19:07:22 +02:00
Andreas Kling
6a16783c66 LibJS/JIT: Compile the SetVariable bytecode instruction 2023-10-27 19:07:22 +02:00
Andreas Kling
e946440ed3 LibJS/JIT: Compile the TypeofVariable bytecode instruction 2023-10-27 19:07:22 +02:00
Andreas Kling
c65aecd878 LibJS/JIT: Compile all the unary bytecode instructions 2023-10-27 19:07:22 +02:00
Andreas Kling
640455b1d2 LibJS/JIT: Compile the Call bytecode instruction
I've left a FIXME about dealing with some throwsy cases.
2023-10-27 19:07:22 +02:00
Andreas Kling
d866780235 LibJS/JIT: Compile the NewObject bytecode instruction 2023-10-27 19:07:22 +02:00
Andreas Kling
580249d650 LibJS/JIT: Compile the PutById bytecode instruction 2023-10-27 19:07:22 +02:00
Andreas Kling
3974ce2069 LibJS/JIT: Compile the GetGlobal bytecode instruction 2023-10-27 19:07:22 +02:00
Andreas Kling
12898f5aef LibJS/JIT: Compile the Decrement bytecode instruction 2023-10-27 19:07:22 +02:00
Andreas Kling
966b6f78a6 LibJS/JIT: Compile the GetByValue bytecode instruction 2023-10-27 19:07:22 +02:00
Andreas Kling
1c0efbec6b LibJS/JIT: Compile the ResolveThisBinding bytecode instruction 2023-10-27 19:07:22 +02:00
Andreas Kling
b2602a4bae LibJS/JIT: Compile the ToNumeric bytecode instruction 2023-10-27 19:07:22 +02:00
Andreas Kling
0f735b3502 LibJS/JIT: Log both success and failure from the JIT compiler
These logs will eventually go away, once the JIT compiler can always
compile everything. :^)
2023-10-27 19:07:22 +02:00
Andreas Kling
6a6ef6670c LibJS/JIT: Support the GetById bytecode op
We can now do basic property (get) access in jitted code! :^)
2023-10-27 19:07:22 +02:00
Andreas Kling
b923ca392d LibJS/JIT: Support all the binary bytecode ops :^)
(And use the X macro to avoid repeating ourselves!)
2023-10-27 19:07:22 +02:00
Andreas Kling
c2fe7af095 LibJS/JIT: Support the NewString bytecode op
This necessitated making the JIT::Compiler aware of the current
Bytecode::Executable, since that's where all the string literals are
held, but that seems like a good thing.
2023-10-27 19:07:22 +02:00
Andreas Kling
efe58ebf2f LibJS/JIT: Support the Return bytecode op 2023-10-27 19:07:22 +02:00
Andreas Kling
45be2a8f72 LibJS/JIT: Add support for Add/Sub/Mul/Div bytecode ops 2023-10-27 19:07:22 +02:00
Geo25rey
891b071654 LibJS/JIT: Add support for "throw" keyword 2023-10-27 19:07:22 +02:00
Andreas Kling
ed0d2bce83 LibJS/JIT: Handle exceptions in LessThan :^) 2023-10-27 19:07:22 +02:00
Andreas Kling
9dd5be0186 LibJS/JIT: Compile the EnterUnwindContext and LeaveUnwindContext ops
These push a "valid" unwind context on the stack and check_exception()
now knows how to jump to the (catch) handler if present.

(finally) finalizers will require some more work, but with this change,
we now have basic support for try...catch. :^)
2023-10-27 19:07:22 +02:00
Andreas Kling
e3560c2545 LibJS/JIT: Propagate exceptions in the simplest case :^)
We now establish a stack of "unwind contexts" similar to what the
bytecode interpreter does, but here, it's a stack of structs with
addresses to the catch and finally blocks.

Unwind contexts also have a "valid" flag, and the root unwind context
(always present, pushed on JIT code entry) has valid=false, which we
interpret in check_exception() as "return and let our caller deal with
the exception".

Anything in Compiler that may generate an exception should now also
call check_exception() ASAP to emit the code for handling this.
2023-10-27 19:07:22 +02:00
Andreas Kling
3523f9f722 LibJS/JIT: Add patchable absolute references to basic blocks 2023-10-27 19:07:22 +02:00
Andreas Kling
71e41418f6 LibJS/JIT: Do "enter & leave" sequence in x86_64 machine code
This ensures that the stack pointer is restored before we return from
the jitted code.
2023-10-27 19:07:22 +02:00
Andreas Kling
a7bad26b63 LibJS/JIT: Add missing unistd.h include (fixes Clang build) 2023-10-27 19:07:22 +02:00
Andreas Kling
acece9057e LibJS/JIT: Make Assembler::Reg represent X86 registers
And move the generic register aliases to JIT::Compiler.
2023-10-27 19:07:22 +02:00
Andreas Kling
f9041c7b31 LibJS/JIT: Fast path for boolean JS::Value in compile_to_boolean() 2023-10-27 19:07:22 +02:00
Andreas Kling
babdc0a25b LibJS: Work-in-progress JIT compiler :^) 2023-10-27 19:07:22 +02:00