Source file src/simd/sum_amd64_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 && amd64
     6  
     7  package simd_test
     8  
     9  import (
    10  	"simd"
    11  	"simd/archsimd"
    12  )
    13  
    14  func sum(x simd.Float32s) float32 {
    15  	switch a := x.ToArch().(type) {
    16  	case archsimd.Float32x8:
    17  		a = a.ConcatAddPairsGrouped(a)
    18  		a = a.ConcatAddPairsGrouped(a)
    19  		return a.GetLo().GetElem(0) + a.GetHi().GetElem(0)
    20  	case archsimd.Float32x16:
    21  		b := a.GetLo().Add(a.GetHi())
    22  		b = b.ConcatAddPairsGrouped(b)
    23  		b = b.ConcatAddPairsGrouped(b)
    24  		return b.GetLo().GetElem(0) + b.GetHi().GetElem(0)
    25  	case archsimd.Float32x4:
    26  		return boringSum(simd.Float32sFromArch(a))
    27  	default:
    28  		return boringSum(x)
    29  	}
    30  	panic("nope")
    31  }
    32  

View as plain text