summaryrefslogtreecommitdiff
path: root/deps/v8/src
diff options
context:
space:
mode:
authorYagiz Nizipli <yagiz@nizipli.com>2022-12-10 09:23:50 -0500
committerGitHub <noreply@github.com>2022-12-10 14:23:50 +0000
commit894aff75be5cc5e0f4d151038913ce83d39643e7 (patch)
treeabe29e2b1fc67041baf77820b003ffed9ed09c7f /deps/v8/src
parent265ea1e74ef429f7c27f05ac4cc9136adf2e8d9b (diff)
downloadnode-new-894aff75be5cc5e0f4d151038913ce83d39643e7.tar.gz
deps: V8: cherry-pick bc831f8ba33b
Original commit message: [fastcall] Implement support for onebyte string arguments This CL adds one byte string specialization support for fast API call arguments. It introduces a kOneByteString variant to CTypeInfo. We see a ~6x improvement in Deno's TextEncoder#encode microbenchmark. Rendered results: https://divy-v8-patches.deno.dev/ Bug: chromium:1052746 Change-Id: I47c3a9e101cd18ddc6ad58f627db3a34231b60f7 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4036884 Reviewed-by: Toon Verwaest <verwaest@chromium.org> Reviewed-by: Maya Lekova <mslekova@chromium.org> Commit-Queue: Maya Lekova <mslekova@chromium.org> Cr-Commit-Position: refs/heads/main@{#84552} Refs: https://github.com/v8/v8/commit/bc831f8ba33b79e2eb670faf1f84c4e39aeb0f9f PR-URL: https://github.com/nodejs/node/pull/45788 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
Diffstat (limited to 'deps/v8/src')
-rw-r--r--deps/v8/src/codegen/machine-type.h1
-rw-r--r--deps/v8/src/compiler/effect-control-linearizer.cc45
-rw-r--r--deps/v8/src/compiler/fast-api-calls.cc1
-rw-r--r--deps/v8/src/compiler/simplified-lowering.cc1
-rw-r--r--deps/v8/src/d8/d8-test.cc47
5 files changed, 95 insertions, 0 deletions
diff --git a/deps/v8/src/codegen/machine-type.h b/deps/v8/src/codegen/machine-type.h
index 29d7de7583..38834d2394 100644
--- a/deps/v8/src/codegen/machine-type.h
+++ b/deps/v8/src/codegen/machine-type.h
@@ -315,6 +315,7 @@ class MachineType {
case CTypeInfo::Type::kFloat64:
return MachineType::Float64();
case CTypeInfo::Type::kV8Value:
+ case CTypeInfo::Type::kSeqOneByteString:
case CTypeInfo::Type::kApiObject:
return MachineType::AnyTagged();
}
diff --git a/deps/v8/src/compiler/effect-control-linearizer.cc b/deps/v8/src/compiler/effect-control-linearizer.cc
index 055e3484e7..66973abcbc 100644
--- a/deps/v8/src/compiler/effect-control-linearizer.cc
+++ b/deps/v8/src/compiler/effect-control-linearizer.cc
@@ -5395,6 +5395,50 @@ Node* EffectControlLinearizer::AdaptFastCallArgument(
case CTypeInfo::Type::kFloat32: {
return __ TruncateFloat64ToFloat32(node);
}
+ case CTypeInfo::Type::kSeqOneByteString: {
+ // Check that the value is a HeapObject.
+ Node* value_is_smi = ObjectIsSmi(node);
+ __ GotoIf(value_is_smi, if_error);
+
+ Node* map = __ LoadField(AccessBuilder::ForMap(), node);
+ Node* instance_type =
+ __ LoadField(AccessBuilder::ForMapInstanceType(), map);
+
+ Node* encoding = __ Word32And(
+ instance_type,
+ __ Int32Constant(kStringRepresentationAndEncodingMask));
+
+ Node* is_onebytestring = __ Word32Equal(
+ encoding, __ Int32Constant(kSeqOneByteStringTag));
+ __ GotoIfNot(is_onebytestring, if_error);
+
+ Node* length_in_bytes =
+ __ LoadField(AccessBuilder::ForStringLength(), node);
+ Node* data_ptr = __ IntPtrAdd(
+ node, __ IntPtrConstant(SeqOneByteString::kHeaderSize -
+ kHeapObjectTag));
+
+ constexpr int kAlign = alignof(FastOneByteString);
+ constexpr int kSize = sizeof(FastOneByteString);
+ static_assert(kSize == sizeof(uintptr_t) + sizeof(size_t),
+ "The size of "
+ "FastOneByteString isn't equal to the sum of its "
+ "expected members.");
+ Node* stack_slot = __ StackSlot(kSize, kAlign);
+
+ __ Store(StoreRepresentation(MachineType::PointerRepresentation(),
+ kNoWriteBarrier),
+ stack_slot, 0, data_ptr);
+ __ Store(StoreRepresentation(MachineRepresentation::kWord32,
+ kNoWriteBarrier),
+ stack_slot, sizeof(size_t), length_in_bytes);
+
+ static_assert(sizeof(uintptr_t) == sizeof(size_t),
+ "The string length can't "
+ "fit the PointerRepresentation used to store it.");
+
+ return stack_slot;
+ }
default: {
return node;
}
@@ -5600,6 +5644,7 @@ Node* EffectControlLinearizer::LowerFastApiCall(Node* node) {
case CTypeInfo::Type::kFloat64:
return ChangeFloat64ToTagged(
c_call_result, CheckForMinusZeroMode::kCheckForMinusZero);
+ case CTypeInfo::Type::kSeqOneByteString:
case CTypeInfo::Type::kV8Value:
case CTypeInfo::Type::kApiObject:
case CTypeInfo::Type::kUint8:
diff --git a/deps/v8/src/compiler/fast-api-calls.cc b/deps/v8/src/compiler/fast-api-calls.cc
index 4e3f92a99e..4279048ee1 100644
--- a/deps/v8/src/compiler/fast-api-calls.cc
+++ b/deps/v8/src/compiler/fast-api-calls.cc
@@ -29,6 +29,7 @@ ElementsKind GetTypedArrayElementsKind(CTypeInfo::Type type) {
case CTypeInfo::Type::kFloat64:
return FLOAT64_ELEMENTS;
case CTypeInfo::Type::kVoid:
+ case CTypeInfo::Type::kSeqOneByteString:
case CTypeInfo::Type::kBool:
case CTypeInfo::Type::kV8Value:
case CTypeInfo::Type::kApiObject:
diff --git a/deps/v8/src/compiler/simplified-lowering.cc b/deps/v8/src/compiler/simplified-lowering.cc
index 17200099ca..2d47663809 100644
--- a/deps/v8/src/compiler/simplified-lowering.cc
+++ b/deps/v8/src/compiler/simplified-lowering.cc
@@ -1961,6 +1961,7 @@ class RepresentationSelector {
case CTypeInfo::Type::kFloat64:
return UseInfo::CheckedNumberAsFloat64(kDistinguishZeros, feedback);
case CTypeInfo::Type::kV8Value:
+ case CTypeInfo::Type::kSeqOneByteString:
case CTypeInfo::Type::kApiObject:
return UseInfo::AnyTagged();
}
diff --git a/deps/v8/src/d8/d8-test.cc b/deps/v8/src/d8/d8-test.cc
index 068a2b2329..a4d5abdc44 100644
--- a/deps/v8/src/d8/d8-test.cc
+++ b/deps/v8/src/d8/d8-test.cc
@@ -43,6 +43,43 @@ class FastCApiObject {
static FastCApiObject& instance();
#ifdef V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
+ static AnyCType CopyStringFastCallbackPatch(AnyCType receiver,
+ AnyCType should_fallback,
+ AnyCType source, AnyCType out,
+ AnyCType options) {
+ AnyCType ret;
+ CopyStringFastCallback(receiver.object_value, should_fallback.bool_value,
+ *source.string_value, *out.uint8_ta_value,
+ *options.options_value);
+ return ret;
+ }
+
+#endif // V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
+ static void CopyStringFastCallback(Local<Object> receiver,
+ bool should_fallback,
+ const FastOneByteString& source,
+ const FastApiTypedArray<uint8_t>& out,
+ FastApiCallbackOptions& options) {
+ FastCApiObject* self = UnwrapObject(receiver);
+ self->fast_call_count_++;
+
+ if (should_fallback) {
+ options.fallback = true;
+ } else {
+ options.fallback = false;
+ }
+
+ uint8_t* memory = nullptr;
+ CHECK(out.getStorageIfAligned(&memory));
+ memcpy(memory, source.data, source.length);
+ }
+
+ static void CopyStringSlowCallback(const FunctionCallbackInfo<Value>& args) {
+ FastCApiObject* self = UnwrapObject(args.This());
+ CHECK_SELF_OR_THROW();
+ self->slow_call_count_++;
+ }
+#ifdef V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
static AnyCType AddAllFastCallbackPatch(AnyCType receiver,
AnyCType should_fallback,
AnyCType arg_i32, AnyCType arg_u32,
@@ -1084,6 +1121,16 @@ Local<FunctionTemplate> Shell::CreateTestFastCApiTemplate(Isolate* isolate) {
PerIsolateData::Get(isolate)->SetTestApiObjectCtor(api_obj_ctor);
Local<Signature> signature = Signature::New(isolate, api_obj_ctor);
{
+ CFunction copy_str_func = CFunction::Make(
+ FastCApiObject::CopyStringFastCallback V8_IF_USE_SIMULATOR(
+ FastCApiObject::CopyStringFastCallbackPatch));
+ api_obj_ctor->PrototypeTemplate()->Set(
+ isolate, "copy_string",
+ FunctionTemplate::New(isolate, FastCApiObject::CopyStringSlowCallback,
+ Local<Value>(), signature, 1,
+ ConstructorBehavior::kThrow,
+ SideEffectType::kHasSideEffect, &copy_str_func));
+
CFunction add_all_c_func =
CFunction::Make(FastCApiObject::AddAllFastCallback V8_IF_USE_SIMULATOR(
FastCApiObject::AddAllFastCallbackPatch));