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

     1  // Copyright 2025 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 && (amd64 || wasm || arm64)
     6  
     7  package simd_test
     8  
     9  import (
    10  	"runtime"
    11  	"simd/archsimd"
    12  	"testing"
    13  )
    14  
    15  // This is a subset of the tests in unary_test.go, but notice also
    16  // that amd64 does not support OnesCount for 128-bit vectors except
    17  // on AVX512.
    18  
    19  func TestCeil(t *testing.T) {
    20  	testFloat32x4Unary(t, archsimd.Float32x4.Ceil, ceilSlice[float32])
    21  	testFloat64x2Unary(t, archsimd.Float64x2.Ceil, ceilSlice[float64])
    22  }
    23  
    24  func TestFloor(t *testing.T) {
    25  	testFloat32x4Unary(t, archsimd.Float32x4.Floor, floorSlice[float32])
    26  	testFloat64x2Unary(t, archsimd.Float64x2.Floor, floorSlice[float64])
    27  }
    28  
    29  func TestTrunc(t *testing.T) {
    30  	testFloat32x4Unary(t, archsimd.Float32x4.Trunc, truncSlice[float32])
    31  	testFloat64x2Unary(t, archsimd.Float64x2.Trunc, truncSlice[float64])
    32  }
    33  
    34  func TestRound(t *testing.T) {
    35  	testFloat32x4Unary(t, archsimd.Float32x4.Round, roundSlice[float32])
    36  	testFloat64x2Unary(t, archsimd.Float64x2.Round, roundSlice[float64])
    37  }
    38  
    39  func TestSqrt(t *testing.T) {
    40  	testFloat32x4Unary(t, archsimd.Float32x4.Sqrt, sqrtSlice[float32])
    41  	testFloat64x2Unary(t, archsimd.Float64x2.Sqrt, sqrtSlice[float64])
    42  }
    43  
    44  func TestNot(t *testing.T) {
    45  	testInt8x16Unary(t, archsimd.Int8x16.Not, map1[int8](not))
    46  	testInt32x4Unary(t, archsimd.Int32x4.Not, map1[int32](not))
    47  	testInt64x2Unary(t, archsimd.Int64x2.Not, map1[int64](not))
    48  }
    49  
    50  func TestAbs(t *testing.T) {
    51  	testFloat32x4Unary(t, archsimd.Float32x4.Abs, map1[float32](abs))
    52  	testFloat64x2Unary(t, archsimd.Float64x2.Abs, map1[float64](abs))
    53  	testInt8x16Unary(t, archsimd.Int8x16.Abs, map1[int8](abs))
    54  	testInt16x8Unary(t, archsimd.Int16x8.Abs, map1[int16](abs))
    55  	testInt32x4Unary(t, archsimd.Int32x4.Abs, map1[int32](abs))
    56  	if runtime.GOARCH != "amd64" || archsimd.X86.AVX512() {
    57  		testInt64x2Unary(t, archsimd.Int64x2.Abs, map1[int64](abs))
    58  	}
    59  }
    60  
    61  func TestNeg(t *testing.T) {
    62  	testFloat32x4Unary(t, archsimd.Float32x4.Neg, map1[float32](neg))
    63  	testFloat64x2Unary(t, archsimd.Float64x2.Neg, map1[float64](neg))
    64  	testInt8x16Unary(t, archsimd.Int8x16.Neg, map1[int8](neg))
    65  	testInt16x8Unary(t, archsimd.Int16x8.Neg, map1[int16](neg))
    66  	testInt32x4Unary(t, archsimd.Int32x4.Neg, map1[int32](neg))
    67  	testInt64x2Unary(t, archsimd.Int64x2.Neg, map1[int64](neg))
    68  }
    69  
    70  func TestOnesCount(t *testing.T) {
    71  	if runtime.GOARCH == "amd64" && !archsimd.X86.AVX512BITALG() {
    72  		t.Skip("OnesCount on 128-bit 8-bit vectors on amd64 requires AVX512BITALG")
    73  	}
    74  	testInt8x16Unary(t, archsimd.Int8x16.OnesCount, map1[int8](onesCount))
    75  	testUint8x16Unary(t, archsimd.Uint8x16.OnesCount, map1[uint8](onesCount))
    76  }
    77  

View as plain text