[go] cmd/compile: "simd" types have non-constant sizeof

2 views
Skip to first unread message

David Chase (Gerrit)

unread,
Jun 9, 2026, 5:23:11 PM (13 hours ago) Jun 9
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

David Chase has uploaded the change for review

Commit message

cmd/compile: "simd" types have non-constant sizeof

This is for the simd aka "midway" types whose size is
determined at run time.
Change-Id: I7666ccd8090b066c5b4d434f196ac6c8b8b468f5

Change diff

diff --git a/src/cmd/compile/internal/types2/builtins.go b/src/cmd/compile/internal/types2/builtins.go
index 82c6e9c..f130020 100644
--- a/src/cmd/compile/internal/types2/builtins.go
+++ b/src/cmd/compile/internal/types2/builtins.go
@@ -1034,6 +1034,11 @@
t.unpack()
varSize := check.hasVarSize(t.rhs())

+ // Special case for portable simd types that rewrite to unknown sizes.
+ if o := t.Obj(); o != nil && o.Pkg() != nil && o.Pkg().Name() == "simd" && o.Name() == "_simd" {
+ varSize = true
+ }
+
t.mu.Lock()
defer t.mu.Unlock()

diff --git a/src/simd/sizeof_test.go b/src/simd/sizeof_test.go
new file mode 100644
index 0000000..497d715
--- /dev/null
+++ b/src/simd/sizeof_test.go
@@ -0,0 +1,33 @@
+// Copyright 2026 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:build goexperiment.simd
+
+package simd_test
+
+import (
+ "simd"
+ "simd/testdata"
+ "testing"
+ "unsafe"
+)
+
+var v simd.Float32s
+
+func TestSizeof(t *testing.T) {
+ var f float32
+ sv0 := int(unsafe.Sizeof(v))
+ sv1 := v.Len() * int(unsafe.Sizeof(f))
+ sV := int(unsafe.Sizeof(testdata.V))
+ sF := int(unsafe.Sizeof(testdata.F()))
+ if sv0 != sv1 {
+ t.Errorf("Expected sv0=%d and sv1=%d are equal, but not", sv0, sv1)
+ }
+ if sF != sv1 {
+ t.Errorf("Expected sF=%d and sv1=%d are equal, but not", sF, sv1)
+ }
+ if sV != sv1 {
+ t.Errorf("Expected sV=%d and sv1=%d are equal, but not", sV, sv1)
+ }
+}
diff --git a/src/simd/testdata/v.go b/src/simd/testdata/v.go
new file mode 100644
index 0000000..4f1710fa
--- /dev/null
+++ b/src/simd/testdata/v.go
@@ -0,0 +1,18 @@
+// Copyright 2026 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:build goexperiment.simd
+
+package testdata
+
+import (
+ "simd"
+)
+
+var V simd.Float32s
+
+func F() simd.Float32s {
+ var x simd.Float32s
+ return x
+}

Change information

Files:
  • M src/cmd/compile/internal/types2/builtins.go
  • A src/simd/sizeof_test.go
  • A src/simd/testdata/v.go
Change size: M
Delta: 3 files changed, 56 insertions(+), 0 deletions(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I7666ccd8090b066c5b4d434f196ac6c8b8b468f5
Gerrit-Change-Number: 788961
Gerrit-PatchSet: 1
Gerrit-Owner: David Chase <drc...@google.com>
Gerrit-Reviewer: David Chase <drc...@google.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Robert Griesemer (Gerrit)

unread,
Jun 9, 2026, 6:23:56 PM (12 hours ago) Jun 9
to David Chase, goph...@pubsubhelper.golang.org, Robert Griesemer, Robert Findley, Gopher Robot, golang...@luci-project-accounts.iam.gserviceaccount.com, golang-co...@googlegroups.com
Attention needed from David Chase, Robert Findley and Robert Griesemer

Robert Griesemer added 3 comments

Patchset-level comments
File-level comment, Patchset 1 (Latest):
Robert Griesemer . unresolved

Seems ok but you need to also fix go/types by calling go generate in that directory.

File src/cmd/compile/internal/types2/builtins.go
Line 1030, Patchset 1 (Latest): check.push(t.obj)
Robert Griesemer . unresolved

maybe here:
```
obj := t.obj
check.push(obj)
```
and then below (line 1038):
```
if pkg := obj.pkg; pkg != nil && ...
```

Line 1038, Patchset 1 (Latest): if o := t.Obj(); o != nil && o.Pkg() != nil && o.Pkg().Name() == "simd" && o.Name() == "_simd" {
Robert Griesemer . unresolved

You should be able to leave away o != nil. All *Named types must have an object (which is where their name is).

Open in Gerrit

Related details

Attention is currently required from:
  • David Chase
  • Robert Findley
  • Robert Griesemer
Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I7666ccd8090b066c5b4d434f196ac6c8b8b468f5
    Gerrit-Change-Number: 788961
    Gerrit-PatchSet: 1
    Gerrit-Owner: David Chase <drc...@google.com>
    Gerrit-Reviewer: David Chase <drc...@google.com>
    Gerrit-Reviewer: Robert Findley <rfin...@golang.org>
    Gerrit-Reviewer: Robert Griesemer <g...@golang.org>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-CC: Robert Griesemer <g...@google.com>
    Gerrit-Attention: David Chase <drc...@google.com>
    Gerrit-Attention: Robert Griesemer <g...@golang.org>
    Gerrit-Attention: Robert Findley <rfin...@golang.org>
    Gerrit-Comment-Date: Tue, 09 Jun 2026 22:23:49 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    unsatisfied_requirement
    open
    diffy
    Reply all
    Reply to author
    Forward
    0 new messages