aboutsummaryrefslogtreecommitdiff
path: root/src/simd/string.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/simd/string.go')
-rw-r--r--src/simd/string.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/simd/string.go b/src/simd/string.go
new file mode 100644
index 0000000000..a692653aa0
--- /dev/null
+++ b/src/simd/string.go
@@ -0,0 +1,48 @@
+// Copyright 2025 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.
+
+//go:build goexperiment.simd && amd64
+
+package simd
+
+import (
+ "internal/strconv"
+)
+
+type number interface {
+ ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | ~float32 | ~float64
+}
+
+func sliceToString[T number](x []T) string {
+ s := ""
+ pfx := "{"
+ for _, y := range x {
+ s += pfx
+ pfx = ","
+ switch e := any(y).(type) {
+ case int8:
+ s += strconv.Itoa(int(e))
+ case int16:
+ s += strconv.Itoa(int(e))
+ case int32:
+ s += strconv.Itoa(int(e))
+ case int64:
+ s += strconv.Itoa(int(e))
+ case uint8:
+ s += strconv.FormatUint(uint64(e), 10)
+ case uint16:
+ s += strconv.FormatUint(uint64(e), 10)
+ case uint32:
+ s += strconv.FormatUint(uint64(e), 10)
+ case uint64:
+ s += strconv.FormatUint(uint64(e), 10)
+ case float32:
+ s += strconv.FormatFloat(float64(e), 'g', -1, 32)
+ case float64:
+ s += strconv.FormatFloat(e, 'g', -1, 64)
+ }
+ }
+ s += "}"
+ return s
+}