| // Copyright 2026 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. |
| |
| //go:build goexperiment.simd && arm64 |
| |
| package simd_test |
| |
| import ( |
| "simd/archsimd" |
| "testing" |
| ) |
| |
| func TestLookupOrZero(t *testing.T) { |
| // Out-of-range indices produce zero lane value. |
| x := []uint8{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16} |
| indices := []uint8{7, 6, 5, 4, 3, 2, 1, 0, 0xff, 8, 16, 9, 128, 10, 20, 11} |
| want := []uint8{8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 0, 10, 0, 11, 0, 12} |
| got := make([]uint8, len(x)) |
| archsimd.LoadUint8x16(x).LookupOrZero(archsimd.LoadUint8x16(indices)).Store(got) |
| checkSlices(t, got, want) |
| } |
| |
| func TestClMul(t *testing.T) { |
| var x = archsimd.LoadUint64x2([]uint64{1, 5}) |
| var y = archsimd.LoadUint64x2([]uint64{3, 9}) |
| |
| foo := func(v archsimd.Uint64x2, s []uint64) { |
| r := make([]uint64, 2, 2) |
| v.Store(r) |
| checkSlices[uint64](t, r, s) |
| } |
| |
| foo(x.CarrylessMultiplyEven(y), []uint64{3, 0}) |
| foo(x.CarrylessMultiplyEvenOdd(y), []uint64{9, 0}) |
| foo(x.CarrylessMultiplyOddEven(y), []uint64{15, 0}) |
| foo(x.CarrylessMultiplyOdd(y), []uint64{45, 0}) |
| foo(y.CarrylessMultiplyEven(y), []uint64{5, 0}) |
| } |