Source file src/simd/internal/spec/combinators.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 spec
     6  
     7  // map1 returns the vector z[i] = f(x[i]).
     8  //
     9  // z may have more lanes than x, in which case they will be 0.
    10  func map1[From Elt, FromW Width, To Elt, ToW Width](x Vec[From, FromW], f func(x From) To) (z Vec[To, ToW]) {
    11  	z = makeVec[To, ToW]()
    12  	// Loop over x, not z, because width rounding may have expanded z.
    13  	for i, xi := range x {
    14  		z[i] = f(xi)
    15  	}
    16  	return z
    17  }
    18  
    19  // map2 returns the vector z[i] = f(x[i], y[i]).
    20  //
    21  // z may have more lanes than x, in which case they will be 0.
    22  func map2[From Elt, FromW Width, To Elt, ToW Width](x, y Vec[From, FromW], f func(x, y From) To) (z Vec[To, ToW]) {
    23  	z = makeVec[To, ToW]()
    24  	for i := range x {
    25  		z[i] = f(x[i], y[i])
    26  	}
    27  	return z
    28  }
    29  

View as plain text