From c65aecd878f539156fc6d1cfd4a6477c2c78f95e Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 20 Oct 2023 13:37:48 +0200 Subject: [PATCH] LibJS/JIT: Compile all the unary bytecode instructions --- Userland/Libraries/LibJS/JIT/Compiler.cpp | 34 +++++++++++++++++++++++ Userland/Libraries/LibJS/JIT/Compiler.h | 6 ++++ 2 files changed, 40 insertions(+) diff --git a/Userland/Libraries/LibJS/JIT/Compiler.cpp b/Userland/Libraries/LibJS/JIT/Compiler.cpp index b0ce4e5ac9..1f8d50e714 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.cpp +++ b/Userland/Libraries/LibJS/JIT/Compiler.cpp @@ -361,6 +361,33 @@ static ThrowCompletionOr typed_equals(VM&, Value src1, Value src2) JS_ENUMERATE_COMMON_BINARY_OPS(DO_COMPILE_COMMON_BINARY_OP) #undef DO_COMPILE_COMMON_BINARY_OP +static ThrowCompletionOr not_(VM&, Value value) +{ + return Value(!value.to_boolean()); +} + +static ThrowCompletionOr typeof_(VM& vm, Value value) +{ + return PrimitiveString::create(vm, value.typeof()); +} + +#define DO_COMPILE_COMMON_UNARY_OP(TitleCaseName, snake_case_name) \ + static Value cxx_##snake_case_name(VM& vm, Value value) \ + { \ + return TRY_OR_SET_EXCEPTION(snake_case_name(vm, value)); \ + } \ + \ + void Compiler::compile_##snake_case_name(Bytecode::Op::TitleCaseName const&) \ + { \ + load_vm_register(ARG1, Bytecode::Register::accumulator()); \ + m_assembler.native_call((void*)cxx_##snake_case_name); \ + store_vm_register(Bytecode::Register::accumulator(), RET); \ + check_exception(); \ + } + +JS_ENUMERATE_COMMON_UNARY_OPS(DO_COMPILE_COMMON_UNARY_OP) +#undef DO_COMPILE_COMMON_UNARY_OP + void Compiler::compile_return(Bytecode::Op::Return const&) { load_vm_register(GPR0, Bytecode::Register::accumulator()); @@ -622,6 +649,13 @@ OwnPtr Compiler::compile(Bytecode::Executable& bytecode_execut JS_ENUMERATE_COMMON_BINARY_OPS(DO_COMPILE_COMMON_BINARY_OP) #undef DO_COMPILE_COMMON_BINARY_OP +#define DO_COMPILE_COMMON_UNARY_OP(TitleCaseName, snake_case_name) \ + case Bytecode::Instruction::Type::TitleCaseName: \ + compiler.compile_##snake_case_name(static_cast(op)); \ + break; + JS_ENUMERATE_COMMON_UNARY_OPS(DO_COMPILE_COMMON_UNARY_OP) +#undef DO_COMPILE_COMMON_UNARY_OP + default: dbgln("\033[31;1mJIT compilation failed\033[0m: {}", bytecode_executable.name); dbgln("Unsupported bytecode op: {}", op.to_deprecated_string(bytecode_executable)); diff --git a/Userland/Libraries/LibJS/JIT/Compiler.h b/Userland/Libraries/LibJS/JIT/Compiler.h index 2c1ebce484..7aa1eb2c9b 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.h +++ b/Userland/Libraries/LibJS/JIT/Compiler.h @@ -53,6 +53,12 @@ private: JS_ENUMERATE_COMMON_BINARY_OPS(DO_COMPILE_COMMON_BINARY_OP) #undef DO_COMPILE_COMMON_BINARY_OP +#define DO_COMPILE_COMMON_UNARY_OP(OpTitleCase, op_snake_case) \ + void compile_##op_snake_case(Bytecode::Op::OpTitleCase const&); + + JS_ENUMERATE_COMMON_UNARY_OPS(DO_COMPILE_COMMON_UNARY_OP) +#undef DO_COMPILE_COMMON_UNARY_OP + void compile_return(Bytecode::Op::Return const&); void compile_new_string(Bytecode::Op::NewString const&); void compile_new_object(Bytecode::Op::NewObject const&);