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