From da257d2766b333ff3bcf25cd6f460591f7f6f711 Mon Sep 17 00:00:00 2001 From: Alexander Markov Date: Thu, 19 Dec 2024 10:41:40 -0800 Subject: [PATCH] [vm,compiler] Support SIMD constants in IL serialization TEST=vm/dart/isolates/fast_object_copy2_test Change-Id: I934d92f54f9ab51bbdd42edd90588d404bc9be37 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/401920 Reviewed-by: Alexander Aprelev Commit-Queue: Alexander Markov --- .../dart/isolates/fast_object_copy2_test.dart | 1 + runtime/vm/compiler/backend/il_serializer.cc | 45 +++++++++++++++++++ runtime/vm/compiler/backend/il_serializer.h | 1 + 3 files changed, 47 insertions(+) diff --git a/runtime/tests/vm/dart/isolates/fast_object_copy2_test.dart b/runtime/tests/vm/dart/isolates/fast_object_copy2_test.dart index 6cd4ba25f85f..bab4a74d7ce9 100644 --- a/runtime/tests/vm/dart/isolates/fast_object_copy2_test.dart +++ b/runtime/tests/vm/dart/isolates/fast_object_copy2_test.dart @@ -6,6 +6,7 @@ // VMOptions=--enable-fast-object-copy // VMOptions=--no-enable-fast-object-copy --gc-on-foc-slow-path --force-evacuation // VMOptions=--enable-fast-object-copy --gc-on-foc-slow-path --force-evacuation +// VMOptions=--test_il_serialization import 'dart:async'; import 'dart:ffi'; diff --git a/runtime/vm/compiler/backend/il_serializer.cc b/runtime/vm/compiler/backend/il_serializer.cc index 4d124e41d0a7..4138ff9061e8 100644 --- a/runtime/vm/compiler/backend/il_serializer.cc +++ b/runtime/vm/compiler/backend/il_serializer.cc @@ -1600,6 +1600,18 @@ void FlowGraphSerializer::WriteObjectImpl(const Object& x, ASSERT(x.IsCanonical()); Write(Double::Cast(x).value()); break; + case kFloat32x4Cid: + ASSERT(x.IsCanonical()); + Write(Float32x4::Cast(x).value()); + break; + case kFloat64x2Cid: + ASSERT(x.IsCanonical()); + Write(Float64x2::Cast(x).value()); + break; + case kInt32x4Cid: + ASSERT(x.IsCanonical()); + Write(Int32x4::Cast(x).value()); + break; case kFieldCid: { const auto& field = Field::Cast(x); const auto& owner = Class::Handle(Z, field.Owner()); @@ -1877,6 +1889,24 @@ const Object& FlowGraphDeserializer::ReadObjectImpl(intptr_t cid, } case kDoubleCid: return Double::ZoneHandle(Z, Double::NewCanonical(Read())); + case kFloat32x4Cid: { + auto& simd_value = + Float32x4::ZoneHandle(Z, Float32x4::New(Read())); + simd_value ^= simd_value.Canonicalize(thread()); + return simd_value; + } + case kFloat64x2Cid: { + auto& simd_value = + Float64x2::ZoneHandle(Z, Float64x2::New(Read())); + simd_value ^= simd_value.Canonicalize(thread()); + return simd_value; + } + case kInt32x4Cid: { + auto& simd_value = + Int32x4::ZoneHandle(Z, Int32x4::New(Read())); + simd_value ^= simd_value.Canonicalize(thread()); + return simd_value; + } case kFieldCid: { const classid_t owner_class_id = Read(); const intptr_t field_index = Read(); @@ -2290,6 +2320,21 @@ Representation FlowGraphDeserializer::ReadTrait::Read( return static_cast(d->Read()); } +template <> +void FlowGraphSerializer::WriteTrait::Write( + FlowGraphSerializer* s, + simd128_value_t x) { + s->stream()->WriteBytes(&x, sizeof(simd128_value_t)); +} + +template <> +simd128_value_t FlowGraphDeserializer::ReadTrait::Read( + FlowGraphDeserializer* d) { + simd128_value_t value; + d->stream()->ReadBytes(&value, sizeof(simd128_value_t)); + return value; +} + template <> void FlowGraphSerializer::WriteTrait::Write(FlowGraphSerializer* s, const Slot& x) { diff --git a/runtime/vm/compiler/backend/il_serializer.h b/runtime/vm/compiler/backend/il_serializer.h index 33485ff86368..62c3b6a1f972 100644 --- a/runtime/vm/compiler/backend/il_serializer.h +++ b/runtime/vm/compiler/backend/il_serializer.h @@ -109,6 +109,7 @@ class NativeCallingConvention; V(Range*) \ V(RecordShape) \ V(Representation) \ + V(simd128_value_t) \ V(const Slot&) \ V(const Slot*) \ V(const String&) \