simd: correct two errors in formatting code, standardize emulation Ingo Oeser caught two errors in CL 795760 post submit. Other changes bring the two versions of the emulation file into much closer alignment, so that there are only two different lines. Change-Id: I2e4493bd7423aefddddaa30021b97f44a9c035fb Reviewed-on: https://go-review.googlesource.com/c/go/+/796180 Reviewed-by: Junyang Shao <shaojunyang@google.com> LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
diff --git a/src/simd/internal/bridge/simd_emulated.go b/src/simd/internal/bridge/simd_emulated.go index dea8c4d..b6d0d72 100644 --- a/src/simd/internal/bridge/simd_emulated.go +++ b/src/simd/internal/bridge/simd_emulated.go
@@ -33,7 +33,7 @@ } type number interface { - ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | ~float32 | ~float64 + ~int8 | ~int16 | ~int32 | ~int64 | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64 } func sliceToString[T number](x []T) string { @@ -50,7 +50,7 @@ case int32: s += strconv.Itoa(int(e)) case int64: - s += strconv.Itoa(int(e)) + s += strconv.FormatInt(int64(e), 10) case uint8: s += strconv.FormatUint(uint64(e), 10) case uint16: @@ -69,16 +69,6 @@ return s } -type _simd struct { - _ [0]func(*_simd) *_simd -} - -// Int8s represents a 128-bit vector of 16 int8 elements. -type Int8s struct { - _ _simd - a, b uint64 -} - // LoadInt8s loads a slice of int8 into an Int8s vector. func LoadInt8s(s []int8) Int8s { var a, b uint64 @@ -393,12 +383,6 @@ return Uint8s{a: x.a, b: x.b} } -// Int16s represents a 128-bit vector of 8 int16 elements. -type Int16s struct { - _ _simd - a, b uint64 -} - // LoadInt16s loads a slice of int16 into an Int16s vector. func LoadInt16s(s []int16) Int16s { var a, b uint64 @@ -755,12 +739,6 @@ return Uint16s{a: x.a, b: x.b} } -// Int32s represents a 128-bit vector of 4 int32 elements. -type Int32s struct { - _ _simd - a, b uint64 -} - // LoadInt32s loads a slice of int32 into an Int32s vector. func LoadInt32s(s []int32) Int32s { var a, b uint64 @@ -1094,12 +1072,6 @@ return Uint32s{a: x.a, b: x.b} } -// Int64s represents a 128-bit vector of 2 int64 elements. -type Int64s struct { - _ _simd - a, b uint64 -} - // LoadInt64s loads a slice of int64 into an Int64s vector. func LoadInt64s(s []int64) Int64s { var a, b uint64 @@ -1331,12 +1303,6 @@ return Uint64s{a: x.a, b: x.b} } -// Uint8s represents a 128-bit vector of 16 uint8 elements. -type Uint8s struct { - _ _simd - a, b uint64 -} - // LoadUint8s loads a slice of uint8 into an Uint8s vector. func LoadUint8s(s []uint8) Uint8s { var a, b uint64 @@ -1594,12 +1560,6 @@ return Uint64s{a: x.a, b: x.b} } -// Uint16s represents a 128-bit vector of 8 uint16 elements. -type Uint16s struct { - _ _simd - a, b uint64 -} - // LoadUint16s loads a slice of uint16 into an Uint16s vector. func LoadUint16s(s []uint16) Uint16s { var a, b uint64 @@ -1943,12 +1903,6 @@ return Uint8s{a: x.a, b: x.b} } -// Uint32s represents a 128-bit vector of 4 uint32 elements. -type Uint32s struct { - _ _simd - a, b uint64 -} - // LoadUint32s loads a slice of uint32 into an Uint32s vector. func LoadUint32s(s []uint32) Uint32s { var a, b uint64 @@ -2259,12 +2213,6 @@ return Uint8s{a: x.a, b: x.b} } -// Uint64s represents a 128-bit vector of 2 uint64 elements. -type Uint64s struct { - _ _simd - a, b uint64 -} - // LoadUint64s loads a slice of uint64 into an Uint64s vector. func LoadUint64s(s []uint64) Uint64s { var a, b uint64 @@ -2501,12 +2449,6 @@ return Uint8s{a: x.a, b: x.b} } -// Float32s represents a 128-bit vector of 4 float32 elements. -type Float32s struct { - _ _simd - a, b uint64 -} - // LoadFloat32s loads a slice of float32 into an Float32s vector. func LoadFloat32s(s []float32) Float32s { var a, b uint64 @@ -2709,7 +2651,6 @@ res.set(1, x.get(1)*y.get(1)) res.set(2, x.get(2)*y.get(2)) res.set(3, x.get(3)*y.get(3)) - return res } @@ -2721,7 +2662,6 @@ res.set(1, x.get(1)*y.get(1)+z.get(1)) res.set(2, x.get(2)*y.get(2)+z.get(2)) res.set(3, x.get(3)*y.get(3)+z.get(3)) - return res } @@ -2790,12 +2730,6 @@ return Uint32s{a: x.a, b: x.b} } -// Float64s represents a 128-bit vector of 2 float64 elements. -type Float64s struct { - _ _simd - a, b uint64 -} - // LoadFloat64s loads a slice of float64 into an Float64s vector. func LoadFloat64s(s []float64) Float64s { var a, b uint64 @@ -3059,12 +2993,6 @@ return Uint64s{a: x.a, b: x.b} } -// Mask8s represents a 128-bit mask vector for 16 int8/uint8 elements. -type Mask8s struct { - _ _simd - a, b uint64 -} - func (x *Mask8s) set(i int, v bool) { if v { if i < 8 { @@ -3099,12 +3027,6 @@ return Int8s{a: x.a, b: x.b} } -// Mask16s represents a 128-bit mask vector for 8 int16/uint16 elements. -type Mask16s struct { - _ _simd - a, b uint64 -} - func (x *Mask16s) set(i int, v bool) { if v { if i < 4 { @@ -3139,12 +3061,6 @@ return Int16s{a: x.a, b: x.b} } -// Mask32s represents a 128-bit mask vector for 4 int32/uint32/float32 elements. -type Mask32s struct { - _ _simd - a, b uint64 -} - func (x *Mask32s) set(i int, v bool) { if v { if i < 2 { @@ -3179,12 +3095,6 @@ return Int32s{a: x.a, b: x.b} } -// Mask64s represents a 128-bit mask vector for 2 int64/uint64/float64 elements. -type Mask64s struct { - _ _simd - a, b uint64 -} - func (x *Mask64s) set(i int, v bool) { if v { if i == 0 {
diff --git a/src/simd/internal/bridge/simd_types_emulated.go b/src/simd/internal/bridge/simd_types_emulated.go new file mode 100644 index 0000000..d7aa0be --- /dev/null +++ b/src/simd/internal/bridge/simd_types_emulated.go
@@ -0,0 +1,95 @@ +// 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. + +//go:build goexperiment.simd && (amd64 || wasm || arm64) + +package bridge + +type _simd struct { + _ [0]func(*_simd) *_simd +} + +// Int8s represents a 128-bit vector of 16 int8 elements. +type Int8s struct { + _ _simd + a, b uint64 +} + +// Int16s represents a 128-bit vector of 8 int16 elements. +type Int16s struct { + _ _simd + a, b uint64 +} + +// Int32s represents a 128-bit vector of 4 int32 elements. +type Int32s struct { + _ _simd + a, b uint64 +} + +// Int64s represents a 128-bit vector of 2 int64 elements. +type Int64s struct { + _ _simd + a, b uint64 +} + +// Uint8s represents a 128-bit vector of 16 uint8 elements. +type Uint8s struct { + _ _simd + a, b uint64 +} + +// Uint16s represents a 128-bit vector of 8 uint16 elements. +type Uint16s struct { + _ _simd + a, b uint64 +} + +// Uint32s represents a 128-bit vector of 4 uint32 elements. +type Uint32s struct { + _ _simd + a, b uint64 +} + +// Uint64s represents a 128-bit vector of 2 uint64 elements. +type Uint64s struct { + _ _simd + a, b uint64 +} + +// Float32s represents a 128-bit vector of 4 float32 elements. +type Float32s struct { + _ _simd + a, b uint64 +} + +// Float64s represents a 128-bit vector of 2 float64 elements. +type Float64s struct { + _ _simd + a, b uint64 +} + +// Mask8s represents a 128-bit mask vector for 16 int8/uint8 elements. +type Mask8s struct { + _ _simd + a, b uint64 +} + +// Mask16s represents a 128-bit mask vector for 8 int16/uint16 elements. +type Mask16s struct { + _ _simd + a, b uint64 +} + +// Mask32s represents a 128-bit mask vector for 4 int32/uint32/float32 elements. +type Mask32s struct { + _ _simd + a, b uint64 +} + +// Mask64s represents a 128-bit mask vector for 2 int64/uint64/float64 elements. +type Mask64s struct { + _ _simd + a, b uint64 +}
diff --git a/src/simd/simd_emulated.go b/src/simd/simd_emulated.go index ba87733..3737297 100644 --- a/src/simd/simd_emulated.go +++ b/src/simd/simd_emulated.go
@@ -33,7 +33,7 @@ } type number interface { - ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | ~float32 | ~float64 + ~int8 | ~int16 | ~int32 | ~int64 | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64 } func sliceToString[T number](x []T) string { @@ -50,7 +50,7 @@ case int32: s += strconv.Itoa(int(e)) case int64: - s += strconv.Itoa(int(e)) + s += strconv.FormatInt(int64(e), 10) case uint8: s += strconv.FormatUint(uint64(e), 10) case uint16: @@ -2651,7 +2651,6 @@ res.set(1, x.get(1)*y.get(1)) res.set(2, x.get(2)*y.get(2)) res.set(3, x.get(3)*y.get(3)) - return res }