aboutsummaryrefslogtreecommitdiff
path: root/src/simd
diff options
context:
space:
mode:
authorCherry Mui <cherryyz@google.com>2025-09-22 11:57:19 -0400
committerCherry Mui <cherryyz@google.com>2025-09-25 10:32:03 -0700
commit5a78e1a4a1c79185e86b5c18efffba2a9b9d3739 (patch)
treed09db312dec703a5ca96ea75df0b95250d65d591 /src/simd
parentbf00f5dfd6152c00881ce10275ed006e0b991c11 (diff)
downloadgo-5a78e1a4a1c79185e86b5c18efffba2a9b9d3739.tar.xz
[dev.simd] simd, cmd/compile: mark simd vectors uncomparable
SIMD vector types are opqaue, and are expected to be operated with methods. It is not always possible to compare the two vectors efficiently. Instead of adding more magic to the compiler to handle the == operator, mark the vector types uncomparable. Change-Id: I4ca5d5e80ca7d8992dffa7b3c0386b75eb19cfa8 Reviewed-on: https://go-review.googlesource.com/c/go/+/705855 Reviewed-by: Junyang Shao <shaojunyang@google.com> TryBot-Bypass: Cherry Mui <cherryyz@google.com> Reviewed-by: David Chase <drchase@google.com>
Diffstat (limited to 'src/simd')
-rw-r--r--src/simd/_gen/simdgen/gen_simdTypes.go2
-rw-r--r--src/simd/internal/simd_test/simd_test.go14
-rw-r--r--src/simd/types_amd64.go6
3 files changed, 18 insertions, 4 deletions
diff --git a/src/simd/_gen/simdgen/gen_simdTypes.go b/src/simd/_gen/simdgen/gen_simdTypes.go
index 22d19be0e2..0d5d08b7ed 100644
--- a/src/simd/_gen/simdgen/gen_simdTypes.go
+++ b/src/simd/_gen/simdgen/gen_simdTypes.go
@@ -129,7 +129,7 @@ const simdTypesTemplates = `
{{define "sizeTmpl"}}
// v{{.}} is a tag type that tells the compiler that this is really {{.}}-bit SIMD
type v{{.}} struct {
- _{{.}} struct{}
+ _{{.}} [0]func() // uncomparable
}
{{end}}
diff --git a/src/simd/internal/simd_test/simd_test.go b/src/simd/internal/simd_test/simd_test.go
index e43bea1e12..f05c6d6f66 100644
--- a/src/simd/internal/simd_test/simd_test.go
+++ b/src/simd/internal/simd_test/simd_test.go
@@ -54,6 +54,20 @@ func TestType(t *testing.T) {
}
}
+func TestUncomparable(t *testing.T) {
+ // Test that simd vectors are not comparable
+ var x, y any = simd.LoadUint32x4(&[4]uint32{1, 2, 3, 4}), simd.LoadUint32x4(&[4]uint32{5, 6, 7, 8})
+ shouldPanic := func(fn func()) {
+ defer func() {
+ if recover() == nil {
+ panic("did not panic")
+ }
+ }()
+ fn()
+ }
+ shouldPanic(func() { _ = x == y })
+}
+
func TestFuncValue(t *testing.T) {
// Test that simd intrinsic can be used as a function value.
xv := [4]int32{1, 2, 3, 4}
diff --git a/src/simd/types_amd64.go b/src/simd/types_amd64.go
index f70a6a214b..72547c7602 100644
--- a/src/simd/types_amd64.go
+++ b/src/simd/types_amd64.go
@@ -6,7 +6,7 @@ package simd
// v128 is a tag type that tells the compiler that this is really 128-bit SIMD
type v128 struct {
- _128 struct{}
+ _128 [0]func() // uncomparable
}
// Float32x4 is a 128-bit SIMD vector of 4 float32
@@ -433,7 +433,7 @@ func (x Mask64x2) ToBits() uint8
// v256 is a tag type that tells the compiler that this is really 256-bit SIMD
type v256 struct {
- _256 struct{}
+ _256 [0]func() // uncomparable
}
// Float32x8 is a 256-bit SIMD vector of 8 float32
@@ -860,7 +860,7 @@ func (x Mask64x4) ToBits() uint8
// v512 is a tag type that tells the compiler that this is really 512-bit SIMD
type v512 struct {
- _512 struct{}
+ _512 [0]func() // uncomparable
}
// Float32x16 is a 512-bit SIMD vector of 16 float32