| 1 |
// Copyright 2025 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 archsimd |
| 8 |
|
| 9 |
import ( |
| 10 |
"internal/strconv" |
| 11 |
) |
| 12 |
|
| 13 |
type number interface { |
| 14 |
~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | ~float32 | ~float64 |
| 15 |
} |
| 16 |
|
| 17 |
func sliceToString[T number](x []T) string { |
| 18 |
s := "" |
| 19 |
pfx := "{" |
| 20 |
for _, y := range x { |
| 21 |
s += pfx |
| 22 |
pfx = "," |
| 23 |
switch e := any(y).(type) { |
| 24 |
case int8: |
| 25 |
s += strconv.Itoa(int(e)) |
| 26 |
case int16: |
| 27 |
s += strconv.Itoa(int(e)) |
| 28 |
case int32: |
| 29 |
s += strconv.Itoa(int(e)) |
| 30 |
case int64: |
| 31 |
s += strconv.Itoa(int(e)) |
| 32 |
case uint8: |
| 33 |
s += strconv.FormatUint(uint64(e), 10) |
| 34 |
case uint16: |
| 35 |
s += strconv.FormatUint(uint64(e), 10) |
| 36 |
case uint32: |
| 37 |
s += strconv.FormatUint(uint64(e), 10) |
| 38 |
case uint64: |
| 39 |
s += strconv.FormatUint(uint64(e), 10) |
| 40 |
case float32: |
| 41 |
s += strconv.FormatFloat(float64(e), 'g', -1, 32) |
| 42 |
case float64: |
| 43 |
s += strconv.FormatFloat(e, 'g', -1, 64) |
| 44 |
} |
| 45 |
} |
| 46 |
s += "}" |
| 47 |
return s |
| 48 |
} |