Source file src/simd/tofrom_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.simdstable
     6  
     7  package simd_test
     8  
     9  import (
    10  	"simd"
    11  	"testing"
    12  )
    13  
    14  type namedToArch struct {
    15  	name string
    16  	val  any
    17  }
    18  
    19  func allZeroToArch() []namedToArch {
    20  	return []namedToArch{
    21  		{"Int8s", (simd.Int8s{}).ToArch()},
    22  		{"Int16s", (simd.Int16s{}).ToArch()},
    23  		{"Int32s", (simd.Int32s{}).ToArch()},
    24  		{"Int64s", (simd.Int64s{}).ToArch()},
    25  		{"Uint8s", (simd.Uint8s{}).ToArch()},
    26  		{"Uint16s", (simd.Uint16s{}).ToArch()},
    27  		{"Uint32s", (simd.Uint32s{}).ToArch()},
    28  		{"Uint64s", (simd.Uint64s{}).ToArch()},
    29  		{"Float32s", (simd.Float32s{}).ToArch()},
    30  		{"Float64s", (simd.Float64s{}).ToArch()},
    31  		{"Mask8s", (simd.Mask8s{}).ToArch()},
    32  		{"Mask16s", (simd.Mask16s{}).ToArch()},
    33  		{"Mask32s", (simd.Mask32s{}).ToArch()},
    34  		{"Mask64s", (simd.Mask64s{}).ToArch()},
    35  	}
    36  }
    37  
    38  func TestToArchEmulated(t *testing.T) {
    39  	if !simd.Emulated() {
    40  		for _, tc := range allZeroToArch() {
    41  			if tc.val == nil {
    42  				t.Errorf("(%s{}).ToArch() = nil when Emulated() is false", tc.name)
    43  			}
    44  		}
    45  		return
    46  	}
    47  
    48  	for _, tc := range allZeroToArch() {
    49  		if tc.val != nil {
    50  			t.Errorf("(%s{}).ToArch() = %T(%v), want nil when Emulated() is true", tc.name, tc.val, tc.val)
    51  		}
    52  	}
    53  }
    54  

View as plain text