diff options
| author | Junyang Shao <shaojunyang@google.com> | 2025-09-09 16:29:38 +0000 |
|---|---|---|
| committer | Junyang Shao <shaojunyang@google.com> | 2025-09-18 11:07:18 -0700 |
| commit | f1e3651c3324c905b71ca333987650ccf2d1d5d9 (patch) | |
| tree | d795693d819f8a339a74e4ba24515ae0b3da5a61 /src/simd | |
| parent | d9751166a6872e05afee5087cee2f360344bd2f9 (diff) | |
| download | go-f1e3651c3324c905b71ca333987650ccf2d1d5d9.tar.xz | |
[dev.simd] cmd/compile, simd: add VPTEST
Change-Id: Ia5103100eca2747fd10917ee2f32e3403e68e844
Reviewed-on: https://go-review.googlesource.com/c/go/+/702175
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Junyang Shao <shaojunyang@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Rob Lee <leerob7691@gmail.com>
Diffstat (limited to 'src/simd')
| -rw-r--r-- | src/simd/extra_amd64.go | 128 | ||||
| -rw-r--r-- | src/simd/internal/simd_test/simd_test.go | 23 |
2 files changed, 151 insertions, 0 deletions
diff --git a/src/simd/extra_amd64.go b/src/simd/extra_amd64.go index 6d09f04bbb..a7832e6a57 100644 --- a/src/simd/extra_amd64.go +++ b/src/simd/extra_amd64.go @@ -15,3 +15,131 @@ package simd // // Asm: VZEROUPPER, CPU Feature: AVX func ClearAVXUpperBits() + +// IsZero returns true if all elements of x are zeros. +// +// This method compiles to VPTEST x, x. +// x.And(y).IsZero() and x.AndNot(y).IsZero() will be optimized to VPTEST x, y +// +// Asm: VPTEST, CPU Feature: AVX +func (x Int8x16) IsZero() bool + +// IsZero returns true if all elements of x are zeros. +// +// This method compiles to VPTEST x, x. +// x.And(y).IsZero() and x.AndNot(y).IsZero() will be optimized to VPTEST x, y +// +// Asm: VPTEST, CPU Feature: AVX +func (x Int8x32) IsZero() bool + +// IsZero returns true if all elements of x are zeros. +// +// This method compiles to VPTEST x, x. +// x.And(y).IsZero() and x.AndNot(y).IsZero() will be optimized to VPTEST x, y +// +// Asm: VPTEST, CPU Feature: AVX +func (x Int16x8) IsZero() bool + +// IsZero returns true if all elements of x are zeros. +// +// This method compiles to VPTEST x, x. +// x.And(y).IsZero() and x.AndNot(y).IsZero() will be optimized to VPTEST x, y +// +// Asm: VPTEST, CPU Feature: AVX +func (x Int16x16) IsZero() bool + +// IsZero returns true if all elements of x are zeros. +// +// This method compiles to VPTEST x, x. +// x.And(y).IsZero() and x.AndNot(y).IsZero() will be optimized to VPTEST x, y +// +// Asm: VPTEST, CPU Feature: AVX +func (x Int32x4) IsZero() bool + +// IsZero returns true if all elements of x are zeros. +// +// This method compiles to VPTEST x, x. +// x.And(y).IsZero() and x.AndNot(y).IsZero() will be optimized to VPTEST x, y +// +// Asm: VPTEST, CPU Feature: AVX +func (x Int32x8) IsZero() bool + +// IsZero returns true if all elements of x are zeros. +// +// This method compiles to VPTEST x, x. +// x.And(y).IsZero() and x.AndNot(y).IsZero() will be optimized to VPTEST x, y +// +// Asm: VPTEST, CPU Feature: AVX +func (x Int64x2) IsZero() bool + +// IsZero returns true if all elements of x are zeros. +// +// This method compiles to VPTEST x, x. +// x.And(y).IsZero() and x.AndNot(y).IsZero() will be optimized to VPTEST x, y +// +// Asm: VPTEST, CPU Feature: AVX +func (x Int64x4) IsZero() bool + +// IsZero returns true if all elements of x are zeros. +// +// This method compiles to VPTEST x, x. +// x.And(y).IsZero() and x.AndNot(y).IsZero() will be optimized to VPTEST x, y +// +// Asm: VPTEST, CPU Feature: AVX +func (x Uint8x16) IsZero() bool + +// IsZero returns true if all elements of x are zeros. +// +// This method compiles to VPTEST x, x. +// x.And(y).IsZero() and x.AndNot(y).IsZero() will be optimized to VPTEST x, y +// +// Asm: VPTEST, CPU Feature: AVX +func (x Uint8x32) IsZero() bool + +// IsZero returns true if all elements of x are zeros. +// +// This method compiles to VPTEST x, x. +// x.And(y).IsZero() and x.AndNot(y).IsZero() will be optimized to VPTEST x, y +// +// Asm: VPTEST, CPU Feature: AVX +func (x Uint16x8) IsZero() bool + +// IsZero returns true if all elements of x are zeros. +// +// This method compiles to VPTEST x, x. +// x.And(y).IsZero() and x.AndNot(y).IsZero() will be optimized to VPTEST x, y +// +// Asm: VPTEST, CPU Feature: AVX +func (x Uint16x16) IsZero() bool + +// IsZero returns true if all elements of x are zeros. +// +// This method compiles to VPTEST x, x. +// x.And(y).IsZero() and x.AndNot(y).IsZero() will be optimized to VPTEST x, y +// +// Asm: VPTEST, CPU Feature: AVX +func (x Uint32x4) IsZero() bool + +// IsZero returns true if all elements of x are zeros. +// +// This method compiles to VPTEST x, x. +// x.And(y).IsZero() and x.AndNot(y).IsZero() will be optimized to VPTEST x, y +// +// Asm: VPTEST, CPU Feature: AVX +func (x Uint32x8) IsZero() bool + +// IsZero returns true if all elements of x are zeros. +// +// This method compiles to VPTEST x, x. +// x.And(y).IsZero() and x.AndNot(y).IsZero() will be optimized to VPTEST x, y +// +// Asm: VPTEST, CPU Feature: AVX +func (x Uint64x2) IsZero() bool + +// IsZero returns true if all elements of x are zeros. +// +// This method compiles to VPTEST x, x. +// x.And(y).IsZero() and x.AndNot(y).IsZero() will be optimized to VPTEST x, y +// +// Asm: VPTEST, CPU Feature: AVX +func (x Uint64x4) IsZero() bool diff --git a/src/simd/internal/simd_test/simd_test.go b/src/simd/internal/simd_test/simd_test.go index 0ebd10d147..e43bea1e12 100644 --- a/src/simd/internal/simd_test/simd_test.go +++ b/src/simd/internal/simd_test/simd_test.go @@ -557,3 +557,26 @@ func TestLeadingZeros(t *testing.T) { } } } + +func TestIsZero(t *testing.T) { + v1 := simd.LoadUint64x2Slice([]uint64{0, 1}) + v2 := simd.LoadUint64x2Slice([]uint64{0, 0}) + if v1.IsZero() { + t.Errorf("Result incorrect, want false, got true") + } + if !v2.IsZero() { + t.Errorf("Result incorrect, want true, got false") + } + if !v1.And(v2).IsZero() { + t.Errorf("Result incorrect, want true, got false") + } + if v1.AndNot(v2).IsZero() { + t.Errorf("Result incorrect, want false, got true") + } + if !v2.And(v1).IsZero() { + t.Errorf("Result incorrect, want true, got false") + } + if !v2.AndNot(v1).IsZero() { + t.Errorf("Result incorrect, want true, got false") + } +} |
