Source file src/simd/internal/simdref/simdref_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  package simdref_test
     6  
     7  import (
     8  	"fmt"
     9  	"simd/internal/simdref"
    10  	"simd/internal/spec"
    11  	"testing"
    12  )
    13  
    14  func TestScalableExecution(t *testing.T) {
    15  	// Calling scalable operation before setting width must panic
    16  	func() {
    17  		defer func() {
    18  			if r := recover(); r == nil {
    19  				t.Fatalf("expected panic on LoadInt8s when scalable width unset, but did not panic")
    20  			}
    21  		}()
    22  		sUnset := make([]int8, 16)
    23  		simdref.LoadInt8s(sUnset)
    24  	}()
    25  
    26  	// Test at two different scalable widths
    27  	for _, width := range []int{128, 256} {
    28  		t.Run(fmt.Sprint(width), func(t *testing.T) {
    29  			s1 := make([]int8, width/8)
    30  			s2 := make([]int8, width/8)
    31  			for i := range s1 {
    32  				s1[i] = int8(i)
    33  				s2[i] = 10
    34  			}
    35  			out := make([]int8, width/8)
    36  
    37  			defer spec.SetScalableWidth(width)()
    38  			x := simdref.LoadInt8s(s1)
    39  			y := simdref.LoadInt8s(s2)
    40  			z := x.Add(y)
    41  			z.Store(out)
    42  			for i := range out {
    43  				if out[i] != int8(i)+10 {
    44  					t.Fatalf("out[%d] = %d, want %d", i, out[i], int8(i)+10)
    45  				}
    46  			}
    47  		})
    48  	}
    49  }
    50  

View as plain text