Source file src/simd/archsimd/internal/simd_test/ternary_sve_arm64_test.go

     1  // Copyright 2026 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build goexperiment.simd && arm64
     6  
     7  // SVE ternary-op tests, the three-input counterpart of the drivers in
     8  // binary_sve_arm64_test.go. flakiness absorbs the float32 double rounding of
     9  // the math.FMA-based emulation, as in the NEON MulAdd tests.
    10  
    11  package simd_test
    12  
    13  import (
    14  	"simd/archsimd"
    15  	"testing"
    16  )
    17  
    18  // testSVETernary drives a scalable ternary op like testSVEBinary. active is the
    19  // runtime number of live lanes (from the vector's Len()).
    20  func testSVETernary[T number, V any](t *testing.T, pool []T, elemBytes, active int, flakiness float64,
    21  	load func([]T) V, f func(V, V, V) V, store func(V, []T), want func(_, _, _ []T) []T) {
    22  	t.Helper()
    23  	count := sveMaxBytes / elemBytes // lanes in the fixed backing array
    24  	forSliceTriple(t, pool, count, func(x, y, z []T) bool {
    25  		t.Helper()
    26  		g := make([]T, count)
    27  		store(f(load(x), load(y), load(z)), g)
    28  		w := want(x, y, z)
    29  		return checkSlicesLogInput(t, g[:active], w[:active], flakiness, func() {
    30  			t.Helper()
    31  			t.Logf("x=%v", x)
    32  			t.Logf("y=%v", y)
    33  			t.Logf("z=%v", z)
    34  		})
    35  	})
    36  }
    37  
    38  func TestMulAddSVE(t *testing.T) {
    39  	if !archsimd.ARM64.SVE() {
    40  		t.Skip("no SVE")
    41  	}
    42  	testSVETernary(t, int8s, 1, archsimd.Int8s{}.Len(), 0, archsimd.LoadInt8s, archsimd.Int8s.MulAdd, archsimd.Int8s.Store, imaSlice[int8])
    43  	testSVETernary(t, int16s, 2, archsimd.Int16s{}.Len(), 0, archsimd.LoadInt16s, archsimd.Int16s.MulAdd, archsimd.Int16s.Store, imaSlice[int16])
    44  	testSVETernary(t, int32s, 4, archsimd.Int32s{}.Len(), 0, archsimd.LoadInt32s, archsimd.Int32s.MulAdd, archsimd.Int32s.Store, imaSlice[int32])
    45  	testSVETernary(t, int64s, 8, archsimd.Int64s{}.Len(), 0, archsimd.LoadInt64s, archsimd.Int64s.MulAdd, archsimd.Int64s.Store, imaSlice[int64])
    46  	testSVETernary(t, uint8s, 1, archsimd.Uint8s{}.Len(), 0, archsimd.LoadUint8s, archsimd.Uint8s.MulAdd, archsimd.Uint8s.Store, imaSlice[uint8])
    47  	testSVETernary(t, uint16s, 2, archsimd.Uint16s{}.Len(), 0, archsimd.LoadUint16s, archsimd.Uint16s.MulAdd, archsimd.Uint16s.Store, imaSlice[uint16])
    48  	testSVETernary(t, uint32s, 4, archsimd.Uint32s{}.Len(), 0, archsimd.LoadUint32s, archsimd.Uint32s.MulAdd, archsimd.Uint32s.Store, imaSlice[uint32])
    49  	testSVETernary(t, uint64s, 8, archsimd.Uint64s{}.Len(), 0, archsimd.LoadUint64s, archsimd.Uint64s.MulAdd, archsimd.Uint64s.Store, imaSlice[uint64])
    50  	testSVETernary(t, float32s, 4, archsimd.Float32s{}.Len(), 0.001, archsimd.LoadFloat32s, archsimd.Float32s.MulAdd, archsimd.Float32s.Store, fmaSlice[float32])
    51  	testSVETernary(t, float64s, 8, archsimd.Float64s{}.Len(), 0.001, archsimd.LoadFloat64s, archsimd.Float64s.MulAdd, archsimd.Float64s.Store, fmaSlice[float64])
    52  }
    53  

View as plain text