Source file src/simd/internal/spec/converts.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 //simdgen:category Numeric conversion 6 7 package spec 8 9 // ConvertToZ converts element values to {zE}. The result has the same number of lanes. 10 // 11 //specgen:name ConvertTo{zE} 12 //specgen:require z={zB}{zN}x{xL} zE!=xE 13 func ConvertToZ[xE Nums, xW Width, zE Nums, zW Width](x Vec[xE, xW]) (z Vec[zE, zW]) { 14 // Architectures are generally significantly more constrained in what they 15 // will convert between, but this operation describes the full universe of 16 // possible conversions. 17 return map1[xE, xW, zE, zW](x, func(x xE) zE { return zE(x) }) 18 } 19 20 // TODO: ExtendLo* and ConvertLo* don't work for scalable conversions because we 21 // put a literal zL in the name. We could instead just call them XLoToZ and drop 22 // the number since it's fully implied by the receiver type and the target type. 23 // Note that it's not necessarily the low *half*; for example, 24 // Uint8x16.ExtendLo2ToUint64 is the low eighth, but that's implied by going 25 // from uint8 to uint64 without changing the width. 26 27 // ExtendLoLToZ extends the lowest {zL} vector elements to {zE}. 28 // 29 //specgen:name ExtendLo{zL}To{zE} 30 //specgen:require zB=xB zN>xN 31 func ExtendLoLToZ[E Ints | Uints, W FixedWidth, zE Ints | Uints](x Vec[E, W]) (z Vec[zE, W]) { 32 z = makeVec[zE, W]() 33 for i := range z { 34 z[i] = zE(x[i]) 35 } 36 return z 37 } 38 39 // ConvertLoLToZ converts the low-indexed {zL} elements of x to {zE}. 40 // 41 //specgen:name ConvertLo{zL}To{zE} 42 //specgen:require zL<xL 43 func ConvertLoLToZ[E Nums, W FixedWidth, zE Floats](x Vec[E, W]) (z Vec[zE, W]) { 44 panic("not implemented") 45 } 46