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 && wasm
     6  
     7  package simd_test
     8  
     9  import (
    10  	"simd/archsimd"
    11  	"testing"
    12  )
    13  
    14  // This is a subset of the tests in unary_test.go, but notice also
    15  // that amd64 does not support OnesCount for 128-bit vectors except
    16  // on AVX512.
    17  
    18  func TestCeil(t *testing.T) {
    19  	testFloat32x4Unary(t, archsimd.Float32x4.Ceil, ceilSlice[float32])
    20  	testFloat64x2Unary(t, archsimd.Float64x2.Ceil, ceilSlice[float64])
    21  }
    22  
    23  func TestFloor(t *testing.T) {
    24  	testFloat32x4Unary(t, archsimd.Float32x4.Floor, floorSlice[float32])
    25  	testFloat64x2Unary(t, archsimd.Float64x2.Floor, floorSlice[float64])
    26  }
    27  
    28  func TestTrunc(t *testing.T) {
    29  	testFloat32x4Unary(t, archsimd.Float32x4.Trunc, truncSlice[float32])
    30  	testFloat64x2Unary(t, archsimd.Float64x2.Trunc, truncSlice[float64])
    31  }
    32  
    33  func TestRound(t *testing.T) {
    34  	testFloat32x4Unary(t, archsimd.Float32x4.Round, roundSlice[float32])
    35  	testFloat64x2Unary(t, archsimd.Float64x2.Round, roundSlice[float64])
    36  }
    37  
    38  func TestSqrt(t *testing.T) {
    39  	testFloat32x4Unary(t, archsimd.Float32x4.Sqrt, sqrtSlice[float32])
    40  	testFloat64x2Unary(t, archsimd.Float64x2.Sqrt, sqrtSlice[float64])
    41  }
    42  
    43  func TestNot(t *testing.T) {
    44  	testInt8x16Unary(t, archsimd.Int8x16.Not, map1[int8](not))
    45  	testInt32x4Unary(t, archsimd.Int32x4.Not, map1[int32](not))
    46  	testInt64x2Unary(t, archsimd.Int64x2.Not, map1[int64](not))
    47  }
    48  
    49  func TestAbsolute(t *testing.T) {
    50  	testInt8x16Unary(t, archsimd.Int8x16.Abs, map1[int8](abs))
    51  	testInt16x8Unary(t, archsimd.Int16x8.Abs, map1[int16](abs))
    52  	testInt32x4Unary(t, archsimd.Int32x4.Abs, map1[int32](abs))
    53  }
    54  
    55  func TestOnesCount(t *testing.T) {
    56  	testInt8x16Unary(t, archsimd.Int8x16.OnesCount, map1[int8](onesCount))
    57  	testInt16x8Unary(t, archsimd.Int16x8.OnesCount, map1[int16](onesCount))
    58  	testInt32x4Unary(t, archsimd.Int32x4.OnesCount, map1[int32](onesCount))
    59  }
    60  
    61  // func TestConvert(t *testing.T) {
    62  // 	testFloat64x2ConvertToFloat32(t, archsimd.Float64x2.ConvertToFloat32, map1n[float64](toFloat32, 4))
    63  // 	testFloat32x4ConvertToFloat64(t, archsimd.Float32x4.ConvertToFloat64, map1[float32](toFloat64))
    64  
    65  // 	testFloat32x4ConvertToInt32(t, archsimd.Float32x4.ConvertToInt32, map1[float32](floatToInt32_x86))
    66  // 	testFloat64x2ConvertToInt32(t, archsimd.Float64x2.ConvertToInt32, map1n[float64](floatToInt32_x86, 4))
    67  
    68  // 	testInt32x4ConvertToFloat32(t, archsimd.Int32x4.ConvertToFloat32, map1[int32](toFloat32))
    69  // 	testInt32x4ConvertToFloat64(t, archsimd.Int32x4.ConvertToFloat64, map1[int32](toFloat64))
    70  // }
    71  

View as plain text