2025-09-16 17:27:36 +00:00
|
|
|
// asmcheck
|
|
|
|
|
|
|
|
|
|
// Copyright 2025 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.
|
|
|
|
|
|
|
|
|
|
// These tests check code generation of simd peephole optimizations.
|
|
|
|
|
|
|
|
|
|
//go:build goexperiment.simd
|
|
|
|
|
|
|
|
|
|
package codegen
|
|
|
|
|
|
|
|
|
|
import "simd"
|
|
|
|
|
|
|
|
|
|
func vptest1() bool {
|
|
|
|
|
v1 := simd.LoadUint64x2Slice([]uint64{0, 1})
|
|
|
|
|
v2 := simd.LoadUint64x2Slice([]uint64{0, 0})
|
|
|
|
|
// amd64:`VPTEST\s(.*)(.*)$`
|
|
|
|
|
// amd64:`SETCS\s(.*)$`
|
|
|
|
|
return v1.AndNot(v2).IsZero()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func vptest2() bool {
|
|
|
|
|
v1 := simd.LoadUint64x2Slice([]uint64{0, 1})
|
|
|
|
|
v2 := simd.LoadUint64x2Slice([]uint64{0, 0})
|
|
|
|
|
// amd64:`VPTEST\s(.*)(.*)$`
|
|
|
|
|
// amd64:`SETEQ\s(.*)$`
|
|
|
|
|
return v1.And(v2).IsZero()
|
|
|
|
|
}
|
2025-09-19 04:38:19 +00:00
|
|
|
|
|
|
|
|
type Args2 struct {
|
|
|
|
|
V0 simd.Uint8x32
|
|
|
|
|
V1 simd.Uint8x32
|
|
|
|
|
x string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//go:noinline
|
|
|
|
|
func simdStructNoSpill(a Args2) simd.Uint8x32 {
|
|
|
|
|
// amd64:-`VMOVDQU\s.*$`
|
|
|
|
|
return a.V0.Xor(a.V1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func simdStructWrapperNoSpill(a Args2) simd.Uint8x32 {
|
|
|
|
|
// amd64:-`VMOVDQU\s.*$`
|
|
|
|
|
a.x = "test"
|
|
|
|
|
return simdStructNoSpill(a)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//go:noinline
|
|
|
|
|
func simdArrayNoSpill(a [1]Args2) simd.Uint8x32 {
|
|
|
|
|
// amd64:-`VMOVDQU\s.*$`
|
|
|
|
|
return a[0].V0.Xor(a[0].V1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func simdArrayWrapperNoSpill(a [1]Args2) simd.Uint8x32 {
|
|
|
|
|
// amd64:-`VMOVDQU\s.*$`
|
|
|
|
|
a[0].x = "test"
|
|
|
|
|
return simdArrayNoSpill(a)
|
|
|
|
|
}
|
2025-11-04 21:46:06 +00:00
|
|
|
|
|
|
|
|
func simdFeatureGuardedMaskOpt() simd.Int16x16 {
|
|
|
|
|
var x, y simd.Int16x16
|
2025-11-12 19:56:09 +00:00
|
|
|
if simd.X86.AVX512() {
|
2025-11-04 21:46:06 +00:00
|
|
|
mask := simd.Mask16x16FromBits(5)
|
|
|
|
|
return x.Add(y).Masked(mask) // amd64:`VPADDW.Z\s.*$`
|
|
|
|
|
}
|
|
|
|
|
mask := simd.Mask16x16FromBits(5)
|
|
|
|
|
return x.Add(y).Masked(mask) // amd64:`VPAND\s.*$`
|
|
|
|
|
}
|
2025-11-05 19:25:00 +00:00
|
|
|
|
|
|
|
|
func simdMaskedMerge() simd.Int16x16 {
|
|
|
|
|
var x, y simd.Int16x16
|
2025-11-12 19:56:09 +00:00
|
|
|
if simd.X86.AVX512() {
|
2025-11-05 19:25:00 +00:00
|
|
|
mask := simd.Mask16x16FromBits(5)
|
|
|
|
|
return x.Add(y).Merge(x, mask) // amd64:-`VPBLENDVB\s.*$`
|
|
|
|
|
}
|
|
|
|
|
mask := simd.Mask16x16FromBits(5)
|
|
|
|
|
return x.Add(y).Merge(x, mask) // amd64:`VPBLENDVB\s.*$`
|
|
|
|
|
}
|