mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[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>
This commit is contained in:
parent
bf00f5dfd6
commit
5a78e1a4a1
4 changed files with 19 additions and 5 deletions
|
|
@ -465,7 +465,7 @@ func CalcSize(t *Type) {
|
|||
// by the compiler except for the space that they reserve.
|
||||
func simdify(st *Type, isTag bool) {
|
||||
st.align = 8
|
||||
st.alg = AMEM
|
||||
st.alg = ANOALG // not comparable with ==
|
||||
st.intRegs = 0
|
||||
st.isSIMD = true
|
||||
if isTag {
|
||||
|
|
|
|||
|
|
@ -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}}
|
||||
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue