Source file src/simd/archsimd/internal/simd_test/broadcast_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 broadcast tests, in the shape of the binary/unary drivers in
     8  // binary_sve_arm64_test.go: broadcast each scalar drawn from the pool and
     9  // check that every lane the hardware actually populated equals the scalar.
    10  
    11  package simd_test
    12  
    13  import (
    14  	"simd/archsimd"
    15  	"testing"
    16  )
    17  
    18  // testSVEBroadcast drives a scalable broadcast constructor. active is the
    19  // runtime number of live lanes (from the vector's Len()).
    20  func testSVEBroadcast[T number, V any](t *testing.T, pool []T, elemBytes, active int,
    21  	f func(T) V, store func(V, []T)) {
    22  	t.Helper()
    23  	count := sveMaxBytes / elemBytes // lanes in the fixed backing array
    24  	for _, x := range pool {
    25  		g := make([]T, count)
    26  		store(f(x), g)
    27  		w := make([]T, count)
    28  		for i := range w {
    29  			w[i] = x
    30  		}
    31  		if !checkSlicesLogInput(t, g[:active], w[:active], 0.0, func() {
    32  			t.Helper()
    33  			t.Logf("x=%v", x)
    34  		}) {
    35  			return
    36  		}
    37  	}
    38  }
    39  
    40  func TestBroadcastSVE(t *testing.T) {
    41  	if !archsimd.ARM64.SVE() {
    42  		t.Skip("no SVE")
    43  	}
    44  	testSVEBroadcast(t, int8s, 1, archsimd.Int8s{}.Len(), archsimd.BroadcastInt8s, archsimd.Int8s.Store)
    45  	testSVEBroadcast(t, int16s, 2, archsimd.Int16s{}.Len(), archsimd.BroadcastInt16s, archsimd.Int16s.Store)
    46  	testSVEBroadcast(t, int32s, 4, archsimd.Int32s{}.Len(), archsimd.BroadcastInt32s, archsimd.Int32s.Store)
    47  	testSVEBroadcast(t, int64s, 8, archsimd.Int64s{}.Len(), archsimd.BroadcastInt64s, archsimd.Int64s.Store)
    48  	testSVEBroadcast(t, uint8s, 1, archsimd.Uint8s{}.Len(), archsimd.BroadcastUint8s, archsimd.Uint8s.Store)
    49  	testSVEBroadcast(t, uint16s, 2, archsimd.Uint16s{}.Len(), archsimd.BroadcastUint16s, archsimd.Uint16s.Store)
    50  	testSVEBroadcast(t, uint32s, 4, archsimd.Uint32s{}.Len(), archsimd.BroadcastUint32s, archsimd.Uint32s.Store)
    51  	testSVEBroadcast(t, uint64s, 8, archsimd.Uint64s{}.Len(), archsimd.BroadcastUint64s, archsimd.Uint64s.Store)
    52  	testSVEBroadcast(t, float32s, 4, archsimd.Float32s{}.Len(), archsimd.BroadcastFloat32s, archsimd.Float32s.Store)
    53  	testSVEBroadcast(t, float64s, 8, archsimd.Float64s{}.Len(), archsimd.BroadcastFloat64s, archsimd.Float64s.Store)
    54  }
    55  

View as plain text