Source file src/simd/madd_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
     6  
     7  package simd_test
     8  
     9  import (
    10  	"simd"
    11  	"testing"
    12  )
    13  
    14  //go:noinline
    15  func mulAdd(A, B, C simd.Float32s) simd.Float32s {
    16  	return A.MulAdd(B, C)
    17  }
    18  
    19  func TestMulAdd(t *testing.T) {
    20  	a := []float32{2, 3, 5, 7}
    21  	b := []float32{11, 13, 17, 19}
    22  	c := []float32{23, 29, 31, 37}
    23  
    24  	A, _ := simd.LoadFloat32sPart(a)
    25  	B, _ := simd.LoadFloat32sPart(b)
    26  	C, _ := simd.LoadFloat32sPart(c)
    27  
    28  	D := mulAdd(A, B, C)
    29  	d := make([]float32, 4)
    30  
    31  	D.StorePart(d)
    32  
    33  	if d[0] != a[0]*b[0]+c[0] {
    34  		t.Errorf("MulAdd test failed, expected %f, got %f", a[0]*b[0]+c[0], d[0])
    35  	}
    36  }
    37  

View as plain text