[XL] Change in dart/sdk[main]: Share SIMD value operations via a dart._simd part

0 views
Skip to first unread message

Modestas Valauskas (Gerrit)

unread,
Jul 14, 2026, 2:21:34 PM (yesterday) Jul 14
to Stephen Adams, dart-...@luci-project-accounts.iam.gserviceaccount.com, Kevin Moore, Martin Kustermann, dart-dc-te...@google.com, dart2js-te...@google.com, dart2wasm-t...@google.com, rev...@dartlang.org
Attention needed from Kevin Moore, Martin Kustermann and Stephen Adams

Modestas Valauskas voted and added 4 comments

Votes added by Modestas Valauskas

Auto-Submit+1

4 comments

Patchset-level comments
File-level comment, Patchset 2:
Modestas Valauskas . resolved

PTAL. PS3 attempts to fix the remaining failures and address Stephen's feedback. It changed the approach from using mixins-from-another-library to using a shared library + part so we don't have to make private members public.

File sdk/lib/_internal/js_runtime/lib/native_typed_data.dart
Line 168, Patchset 2: NativeFloat32x4List._externalStorage(this.storage);
Stephen Adams . resolved

Historically it was important to keep this private.

Even nowadays, public names shared between private libraries can still leak to user code:

`(myF32x4List as dynamic).storage`.

Modestas Valauskas

Thank you, that's a very good point that I missed. I switched to parts in PS3.

Line 2061, Patchset 1 (Parent): Int32x4 withW(int w) {
Stephen Adams . resolved

This was more efficient that the new code since it truncates only one element.

Modestas Valauskas

Done

File sdk/lib/_internal/shared_typed_data/shared_typed_data.dart
Line 42, Patchset 1: final l = _i32Scratch;
Stephen Adams . resolved

`list` would be better - `l` is an abbreviation _and_ looks too much like `1`.

Modestas Valauskas

Done

Open in Gerrit

Related details

Attention is currently required from:
  • Kevin Moore
  • Martin Kustermann
  • Stephen Adams
Submit Requirements:
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I235b2e292e899a21d2f02d5314d0892575a6d0fd
Gerrit-Change-Number: 523460
Gerrit-PatchSet: 3
Gerrit-Owner: Modestas Valauskas <valauska...@gmail.com>
Gerrit-Reviewer: Kevin Moore <kev...@google.com>
Gerrit-Reviewer: Martin Kustermann <kuste...@google.com>
Gerrit-Reviewer: Modestas Valauskas <valauska...@gmail.com>
Gerrit-Reviewer: Stephen Adams <s...@google.com>
Gerrit-Attention: Stephen Adams <s...@google.com>
Gerrit-Attention: Martin Kustermann <kuste...@google.com>
Gerrit-Attention: Kevin Moore <kev...@google.com>
Gerrit-Comment-Date: Tue, 14 Jul 2026 18:21:27 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: Stephen Adams <s...@google.com>
unsatisfied_requirement
open
diffy

Modestas Valauskas (Gerrit)

unread,
Jul 14, 2026, 4:44:42 PM (yesterday) Jul 14
to Stephen Adams, dart-...@luci-project-accounts.iam.gserviceaccount.com, Kevin Moore, Martin Kustermann, dart-dc-te...@google.com, dart2js-te...@google.com, dart2wasm-t...@google.com, rev...@dartlang.org
Attention needed from Kevin Moore, Martin Kustermann and Stephen Adams

Modestas Valauskas voted and added 1 comment

Votes added by Modestas Valauskas

Auto-Submit+1

1 comment

Patchset-level comments
File-level comment, Patchset 5 (Latest):
Modestas Valauskas . resolved

PS5 regenerates wasm goldens and adds missing references to the new _simd library. PTAL

Open in Gerrit

Related details

Attention is currently required from:
  • Kevin Moore
  • Martin Kustermann
  • Stephen Adams
Submit Requirements:
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I235b2e292e899a21d2f02d5314d0892575a6d0fd
Gerrit-Change-Number: 523460
Gerrit-PatchSet: 5
Gerrit-Owner: Modestas Valauskas <valauska...@gmail.com>
Gerrit-Reviewer: Kevin Moore <kev...@google.com>
Gerrit-Reviewer: Martin Kustermann <kuste...@google.com>
Gerrit-Reviewer: Modestas Valauskas <valauska...@gmail.com>
Gerrit-Reviewer: Stephen Adams <s...@google.com>
Gerrit-Attention: Stephen Adams <s...@google.com>
Gerrit-Attention: Martin Kustermann <kuste...@google.com>
Gerrit-Attention: Kevin Moore <kev...@google.com>
Gerrit-Comment-Date: Tue, 14 Jul 2026 20:44:37 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
unsatisfied_requirement
open
diffy

Stephen Adams (Gerrit)

unread,
6:14 PM (5 hours ago) 6:14 PM
to Modestas Valauskas, Johnni Winther, Slava Egorov, Kevin Moore, dart-...@luci-project-accounts.iam.gserviceaccount.com, Martin Kustermann, dart-dc-te...@google.com, dart2js-te...@google.com, dart2wasm-t...@google.com, rev...@dartlang.org
Attention needed from Johnni Winther, Martin Kustermann and Modestas Valauskas

Stephen Adams added 3 comments

Patchset-level comments
Stephen Adams . unresolved

I would like @kuste...@google.com and perhaps @veg...@google.com to comment before I revisit this issue.

File sdk/lib/_internal/shared_typed_data/simd_shared.dart
Line 7, Patchset 5 (Latest):part of dart._simd;
Stephen Adams . unresolved

/cc @johnni...@google.com

We have been moving away from this syntax to enforce that a part file can only be a part of one library, and usually in the same directory.

See https://github.com/dart-lang/language/issues/2358 for details.


A different approach: export shim code from the platform version that can be used by the common code. The shim would be a class with static methods, or an extension type to give some of those methods instance-method syntax. Something like this:

```
--- platform_simd.dart

extension Int32x4ListShim on Int32x4list {
Int32List get storage => _storage;
}
extension Int32x4Shim on Int32x4 {
static Int32x4 newTruncated(int x, int y, int z, int w) =>
NativeInt32x4._truncated(x, y, z, w);
static int truncate(int x) => x.toSigned(32);
}
```

```dart
--- simd_shared.dart

  Int32x4 withX(int x) => NativeInt32x4._truncated(
NativeInt32x4._truncate(x),
y,
z,
w,
);
---->
Int32x4 withX(int x) => Int32x4Shim.newTruncated(
Int32x4Shim.truncate(x),
y,
z,
w
);

```

With the shims, the dependency between the common code and the platform version is explicit and contained, rather than the entire library's private namespace. For consistency, the platform code could use the same shim methods.

I still have misgivings about this whole approach. It is nice to have shared code, but only to the degree that the common code is easily maintained, and does not interfere with the evolution of the runtime. By coupling the runtimes together like this, it makes it harder to do something 'outside the pattern' in just one library.

I also worry is that at least one of the compilers will generate worse code because of the layer of abstraction or dispatch to mixin methods or failure to tree-shake unused declarations (either by open-world assumptions, or weaknesses in the algorithm).

Line 16, Patchset 5 (Latest): Int32x4 operator |(Int32x4 other) => NativeInt32x4._truncated(
Stephen Adams . unresolved

This is incorrect for the _Dart_ bitwise operations on the web.
See https://dart.dev/resources/language/number-representation#bitwise-operations

The original code in the DDC ans dart2js runtimes has `JS` fragments to handle this. The `JS` fragments are not available on all platforms, and incompatible where they are available.

Open in Gerrit

Related details

Attention is currently required from:
  • Johnni Winther
  • Martin Kustermann
  • Modestas Valauskas
Submit Requirements:
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I235b2e292e899a21d2f02d5314d0892575a6d0fd
Gerrit-Change-Number: 523460
Gerrit-PatchSet: 5
Gerrit-Owner: Modestas Valauskas <valauska...@gmail.com>
Gerrit-Reviewer: Kevin Moore <kev...@google.com>
Gerrit-Reviewer: Martin Kustermann <kuste...@google.com>
Gerrit-Reviewer: Modestas Valauskas <valauska...@gmail.com>
Gerrit-Reviewer: Stephen Adams <s...@google.com>
Gerrit-CC: Johnni Winther <johnni...@google.com>
Gerrit-CC: Slava Egorov <veg...@google.com>
Gerrit-Attention: Modestas Valauskas <valauska...@gmail.com>
Gerrit-Attention: Martin Kustermann <kuste...@google.com>
Gerrit-Attention: Johnni Winther <johnni...@google.com>
Gerrit-Comment-Date: Wed, 15 Jul 2026 22:14:06 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
unsatisfied_requirement
open
diffy

Modestas Valauskas (Gerrit)

unread,
7:43 PM (4 hours ago) 7:43 PM
to Lasse Nielsen, Johnni Winther, Slava Egorov, Kevin Moore, Stephen Adams, dart-...@luci-project-accounts.iam.gserviceaccount.com, Martin Kustermann, dart-dc-te...@google.com, dart2js-te...@google.com, dart2wasm-t...@google.com, rev...@dartlang.org
Attention needed from Johnni Winther, Lasse Nielsen, Martin Kustermann and Stephen Adams

Modestas Valauskas added 3 comments

Patchset-level comments
Modestas Valauskas . resolved

Thank you Stephen for your feedback and I agree, let's wait for some other perspectives.

File sdk/lib/_internal/shared_typed_data/simd_shared.dart
Modestas Valauskas
I do prefer the part feature for sharing code in this case:
- Publishing the private storage and constructors is only safe as long as we are careful.
- It introduces indirection in performance critical parts of our sdk (we can't guarantee that it will be inlined with a prefer inline pragma on all platforms, so the performance question applies here, too, I ran into one just yesterday https://dart-review.googlesource.com/c/sdk/+/523380).
- Since we have a feature for this issue, I think we should use it.

But I understand your concerns and I will not insist on us using parts when alternative approaches like yours are available and preferred. (Let's wait for a few other perspectives @l...@google.com I'd love to hear your thoughts here as well since https://github.com/dart-lang/language/issues/2358 is your issue)

Line 16, Patchset 5 (Latest): Int32x4 operator |(Int32x4 other) => NativeInt32x4._truncated(
Stephen Adams . unresolved

This is incorrect for the _Dart_ bitwise operations on the web.
See https://dart.dev/resources/language/number-representation#bitwise-operations

The original code in the DDC ans dart2js runtimes has `JS` fragments to handle this. The `JS` fragments are not available on all platforms, and incompatible where they are available.

Modestas Valauskas

I should probably give these a `SharedNaive...` prefix. My intent behind them is that the implementations that use these mixins can and should specialize the operations that they can implement more efficiently. I just checked again and the specializations do override these naive implementations on js and ddc side. (Or did you mean something else and I missed something?)

Open in Gerrit

Related details

Attention is currently required from:
  • Johnni Winther
  • Lasse Nielsen
  • Martin Kustermann
  • Stephen Adams
Submit Requirements:
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I235b2e292e899a21d2f02d5314d0892575a6d0fd
Gerrit-Change-Number: 523460
Gerrit-PatchSet: 5
Gerrit-Owner: Modestas Valauskas <valauska...@gmail.com>
Gerrit-Reviewer: Kevin Moore <kev...@google.com>
Gerrit-Reviewer: Martin Kustermann <kuste...@google.com>
Gerrit-Reviewer: Modestas Valauskas <valauska...@gmail.com>
Gerrit-Reviewer: Stephen Adams <s...@google.com>
Gerrit-CC: Johnni Winther <johnni...@google.com>
Gerrit-CC: Lasse Nielsen <l...@google.com>
Gerrit-Attention: Stephen Adams <s...@google.com>
Gerrit-Attention: Martin Kustermann <kuste...@google.com>
Gerrit-Attention: Johnni Winther <johnni...@google.com>
Gerrit-Attention: Lasse Nielsen <l...@google.com>
Gerrit-Comment-Date: Wed, 15 Jul 2026 23:43:50 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Stephen Adams <s...@google.com>
unsatisfied_requirement
open
diffy
Reply all
Reply to author
Forward
0 new messages