| // Copyright 2026 The Go Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| |
| //simdgen:category Numeric conversion |
| |
| package spec |
| |
| // TODO: The note on ConvertToZ applies to anything that does width rounding. |
| // Should we have a quick template for that? Or even just add it automatically? |
| |
| // ConvertToZ converts element values to {{.zE}}. |
| // |
| // {{if lt .xL .zL}} |
| // The low {{.xL}} elements of the result are set. The rest are zero. |
| // {{end}} |
| // |
| //specgen:name ConvertTo{{.zE | title}} |
| //specgen:require z={zB}{zN}x{xL} zE!=xE |
| func ConvertToZ[xE Nums, xW Width, zE Nums, zW Width](x Vec[xE, xW]) (z Vec[zE, zW]) { |
| // Architectures are generally significantly more constrained in what they |
| // will convert between, but this operation describes the full universe of |
| // possible conversions. |
| return map1[xE, xW, zE, zW](x, func(x xE) zE { return zE(x) }) |
| } |
| |
| // TODO: ExtendLo* and ConvertLo* don't work for scalable conversions because we |
| // put a literal zL in the name. We could instead just call them XLoToZ and drop |
| // the number since it's fully implied by the receiver type and the target type. |
| // Note that it's not necessarily the low *half*; for example, |
| // Uint8x16.ExtendLo2ToUint64 is the low eighth, but that's implied by going |
| // from uint8 to uint64 without changing the width. |
| |
| // ExtendLoLToZ extends the lowest {{.zL}} vector elements to {{.zE}}. |
| // |
| //specgen:name ExtendLo{{.zL}}To{{.zE | title}} |
| //specgen:require zB=xB zN>xN |
| func ExtendLoLToZ[E Ints | Uints, W FixedWidth, zE Ints | Uints](x Vec[E, W]) (z Vec[zE, W]) { |
| z = makeVec[zE, W]() |
| for i := range z { |
| z[i] = zE(x[i]) |
| } |
| return z |
| } |
| |
| // ConvertLoLToZ converts the low-indexed {{.zL}} elements of x to {{.zE}}. |
| // |
| //specgen:name ConvertLo{{.zL}}To{{.zE | title}} |
| //specgen:require zL<xL |
| func ConvertLoLToZ[E Nums, W FixedWidth, zE Floats](x Vec[E, W]) (z Vec[zE, W]) { |
| panic("not implemented") |
| } |