From 34c14d4e6dabf91a61c2ff20bedb646f88615e42 Mon Sep 17 00:00:00 2001 From: R-Goc Date: Tue, 13 May 2025 14:12:50 +0200 Subject: [PATCH] LibJS: Add fast path for float to int put This commit adds a fast path for putting values into a TypedArray of an integer type, when the value being put in is a double. This leads to a 6% speedup on JetStream/gcc-loops.js. --- Libraries/LibJS/Bytecode/Interpreter.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Libraries/LibJS/Bytecode/Interpreter.cpp b/Libraries/LibJS/Bytecode/Interpreter.cpp index 904b1b4a204..ef07d9c2523 100644 --- a/Libraries/LibJS/Bytecode/Interpreter.cpp +++ b/Libraries/LibJS/Bytecode/Interpreter.cpp @@ -1431,6 +1431,24 @@ inline ThrowCompletionOr put_by_value(VM& vm, Value base, Optional(typed_array, index, value.as_double()); return {}; + case TypedArrayBase::Kind::Int8Array: + fast_typed_array_set_element(typed_array, index, MUST(value.to_i8(vm))); + return {}; + case TypedArrayBase::Kind::Int16Array: + fast_typed_array_set_element(typed_array, index, MUST(value.to_i16(vm))); + return {}; + case TypedArrayBase::Kind::Int32Array: + fast_typed_array_set_element(typed_array, index, MUST(value.to_i32(vm))); + return {}; + case TypedArrayBase::Kind::Uint8Array: + fast_typed_array_set_element(typed_array, index, MUST(value.to_u8(vm))); + return {}; + case TypedArrayBase::Kind::Uint16Array: + fast_typed_array_set_element(typed_array, index, MUST(value.to_u16(vm))); + return {}; + case TypedArrayBase::Kind::Uint32Array: + fast_typed_array_set_element(typed_array, index, MUST(value.to_u32(vm))); + return {}; default: break; }