diff options
| author | Junyang Shao <shaojunyang@google.com> | 2025-09-08 19:38:56 +0000 |
|---|---|---|
| committer | Junyang Shao <shaojunyang@google.com> | 2025-09-08 13:53:52 -0700 |
| commit | c39b2fdd1ec86f68668141a0901d5f3fc634854e (patch) | |
| tree | 104830fc4a0bfe2f1f7dd419bbd36a2c1621a55f /src/simd | |
| parent | 832c1f76dc665f0e211eec12dd77c17fa2ceedd7 (diff) | |
| download | go-c39b2fdd1ec86f68668141a0901d5f3fc634854e.tar.xz | |
[dev.simd] cmd/compile, simd: add VPLZCNT[DQ]
Change-Id: Ifd6d8c12deac9c41722fdf2511d860a334e83438
Reviewed-on: https://go-review.googlesource.com/c/go/+/701915
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Bypass: Junyang Shao <shaojunyang@google.com>
Diffstat (limited to 'src/simd')
| -rw-r--r-- | src/simd/_gen/simdgen/ops/Others/categories.yaml | 5 | ||||
| -rw-r--r-- | src/simd/_gen/simdgen/ops/Others/go.yaml | 8 | ||||
| -rw-r--r-- | src/simd/internal/simd_test/simd_test.go | 17 | ||||
| -rw-r--r-- | src/simd/ops_amd64.go | 62 |
4 files changed, 92 insertions, 0 deletions
diff --git a/src/simd/_gen/simdgen/ops/Others/categories.yaml b/src/simd/_gen/simdgen/ops/Others/categories.yaml new file mode 100644 index 0000000000..4489f4f403 --- /dev/null +++ b/src/simd/_gen/simdgen/ops/Others/categories.yaml @@ -0,0 +1,5 @@ +!sum +- go: LeadingZeros + commutative: false + documentation: !string |- + // NAME counts the leading zeros of each element in x. diff --git a/src/simd/_gen/simdgen/ops/Others/go.yaml b/src/simd/_gen/simdgen/ops/Others/go.yaml new file mode 100644 index 0000000000..a4fd87407b --- /dev/null +++ b/src/simd/_gen/simdgen/ops/Others/go.yaml @@ -0,0 +1,8 @@ +!sum +- go: LeadingZeros + asm: "VPLZCNT[DQ]" + in: + - &any + go: $t + out: + - *any diff --git a/src/simd/internal/simd_test/simd_test.go b/src/simd/internal/simd_test/simd_test.go index 1d4311d75c..0ebd10d147 100644 --- a/src/simd/internal/simd_test/simd_test.go +++ b/src/simd/internal/simd_test/simd_test.go @@ -540,3 +540,20 @@ func TestClearAVXUpperBits(t *testing.T) { checkSlices[int64](t, r, []int64{11, 22, 33, 44}) checkSlices[int64](t, s, []int64{9, 18, 27, 36}) } + +func TestLeadingZeros(t *testing.T) { + if !simd.HasAVX512() { + t.Skip("Test requires HasAVX512, not available on this hardware") + return + } + + src := []uint64{0b1111, 0} + want := []uint64{60, 64} + got := make([]uint64, 2) + simd.LoadUint64x2Slice(src).LeadingZeros().StoreSlice(got) + for i := range 2 { + if want[i] != got[i] { + t.Errorf("Result incorrect at %d: want %d, got %d", i, want[i], got[i]) + } + } +} diff --git a/src/simd/ops_amd64.go b/src/simd/ops_amd64.go index 39552131bf..c1d0e8338a 100644 --- a/src/simd/ops_amd64.go +++ b/src/simd/ops_amd64.go @@ -3298,6 +3298,68 @@ func (x Float64x4) IsNan(y Float64x4) Mask64x4 // Asm: VCMPPD, CPU Feature: AVX512 func (x Float64x8) IsNan(y Float64x8) Mask64x8 +/* LeadingZeros */ + +// LeadingZeros counts the leading zeros of each element in x. +// +// Asm: VPLZCNTD, CPU Feature: AVX512 +func (x Int32x4) LeadingZeros() Int32x4 + +// LeadingZeros counts the leading zeros of each element in x. +// +// Asm: VPLZCNTD, CPU Feature: AVX512 +func (x Int32x8) LeadingZeros() Int32x8 + +// LeadingZeros counts the leading zeros of each element in x. +// +// Asm: VPLZCNTD, CPU Feature: AVX512 +func (x Int32x16) LeadingZeros() Int32x16 + +// LeadingZeros counts the leading zeros of each element in x. +// +// Asm: VPLZCNTQ, CPU Feature: AVX512 +func (x Int64x2) LeadingZeros() Int64x2 + +// LeadingZeros counts the leading zeros of each element in x. +// +// Asm: VPLZCNTQ, CPU Feature: AVX512 +func (x Int64x4) LeadingZeros() Int64x4 + +// LeadingZeros counts the leading zeros of each element in x. +// +// Asm: VPLZCNTQ, CPU Feature: AVX512 +func (x Int64x8) LeadingZeros() Int64x8 + +// LeadingZeros counts the leading zeros of each element in x. +// +// Asm: VPLZCNTD, CPU Feature: AVX512 +func (x Uint32x4) LeadingZeros() Uint32x4 + +// LeadingZeros counts the leading zeros of each element in x. +// +// Asm: VPLZCNTD, CPU Feature: AVX512 +func (x Uint32x8) LeadingZeros() Uint32x8 + +// LeadingZeros counts the leading zeros of each element in x. +// +// Asm: VPLZCNTD, CPU Feature: AVX512 +func (x Uint32x16) LeadingZeros() Uint32x16 + +// LeadingZeros counts the leading zeros of each element in x. +// +// Asm: VPLZCNTQ, CPU Feature: AVX512 +func (x Uint64x2) LeadingZeros() Uint64x2 + +// LeadingZeros counts the leading zeros of each element in x. +// +// Asm: VPLZCNTQ, CPU Feature: AVX512 +func (x Uint64x4) LeadingZeros() Uint64x4 + +// LeadingZeros counts the leading zeros of each element in x. +// +// Asm: VPLZCNTQ, CPU Feature: AVX512 +func (x Uint64x8) LeadingZeros() Uint64x8 + /* Less */ // Less compares for less than. |
