go/test/simd_inline.go
David Chase d7b3da6e25 [dev.simd] simd: improve arm64 and amd64 rotateAll
replace difficult-to-use AVX512-only rotateAll
with an emulation from shifts.  We can revisit this
in the future or else just peephole the shifts
into rotates, later.

this adds plain emulation on arm64 and also for
16-bit rotation on amd64

includes tests, needs additional tests to exercise all
the weird paths through the emulation because it recognizes
constants etc.

the inlining threshold for simd-mentioning closures
was bumped up even higher because the rotate emulation
has a higher inlining cost, and the test that this mattered
for was taken from actual crypto code.

Change-Id: I26c92db2551d2f44a8cd03ac21571491fea436d6
Reviewed-on: https://go-review.googlesource.com/c/go/+/781262
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2026-05-29 12:30:10 -07:00

51 lines
4 KiB
Go

// errorcheck -0 -m
//go:build goexperiment.simd && amd64
// 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.
package foo
import "simd/archsimd"
func hasClosure(a, b, c, d archsimd.Int64x4) (w, x, y, z archsimd.Int64x4) {
shuf := func() { // ERROR "can inline hasClosure.func1"
w = z.RotateAllLeft(1).Xor(a) // ERROR "inlining call to archsimd.Int64x4.RotateAllLeft"
x = w.RotateAllLeft(3).Xor(b) // ERROR "inlining call to archsimd.Int64x4.RotateAllLeft"
y = x.RotateAllLeft(5).Xor(c) // ERROR "inlining call to archsimd.Int64x4.RotateAllLeft"
z = y.RotateAllLeft(7).Xor(d) // ERROR "inlining call to archsimd.Int64x4.RotateAllLeft"
a, b, c, d = b.RotateAllLeft(1).Xor(a.RotateAllLeft(23)), // ERROR "inlining call to archsimd.Int64x4.RotateAllLeft"
c.RotateAllLeft(1).Xor(b.RotateAllLeft(23)), // ERROR "inlining call to archsimd.Int64x4.RotateAllLeft"
d.RotateAllLeft(1).Xor(c.RotateAllLeft(23)), // ERROR "inlining call to archsimd.Int64x4.RotateAllLeft"
a.RotateAllLeft(1).Xor(d.RotateAllLeft(23)) // ERROR "inlining call to archsimd.Int64x4.RotateAllLeft"
w = z.RotateAllLeft(1).Xor(a) // ERROR "inlining call to archsimd.Int64x4.RotateAllLeft"
x = w.RotateAllLeft(3).Xor(b) // ERROR "inlining call to archsimd.Int64x4.RotateAllLeft"
y = x.RotateAllLeft(5).Xor(c) // ERROR "inlining call to archsimd.Int64x4.RotateAllLeft"
z = y.RotateAllLeft(7).Xor(d) // ERROR "inlining call to archsimd.Int64x4.RotateAllLeft"
a, b, c, d = b.RotateAllLeft(1).Xor(a.RotateAllLeft(23)), // ERROR "inlining call to archsimd.Int64x4.RotateAllLeft"
c.RotateAllLeft(1).Xor(b.RotateAllLeft(23)), // ERROR "inlining call to archsimd.Int64x4.RotateAllLeft"
d.RotateAllLeft(1).Xor(c.RotateAllLeft(23)), // ERROR "inlining call to archsimd.Int64x4.RotateAllLeft"
a.RotateAllLeft(1).Xor(d.RotateAllLeft(23)) // ERROR "inlining call to archsimd.Int64x4.RotateAllLeft"
w = z.RotateAllLeft(1).Xor(a) // ERROR "inlining call to archsimd.Int64x4.RotateAllLeft"
x = w.RotateAllLeft(3).Xor(b) // ERROR "inlining call to archsimd.Int64x4.RotateAllLeft"
y = x.RotateAllLeft(5).Xor(c) // ERROR "inlining call to archsimd.Int64x4.RotateAllLeft"
z = y.RotateAllLeft(7).Xor(d) // ERROR "inlining call to archsimd.Int64x4.RotateAllLeft"
a, b, c, d = b.RotateAllLeft(1).Xor(a.RotateAllLeft(23)), // ERROR "inlining call to archsimd.Int64x4.RotateAllLeft"
c.RotateAllLeft(1).Xor(b.RotateAllLeft(23)), // ERROR "inlining call to archsimd.Int64x4.RotateAllLeft"
d.RotateAllLeft(1).Xor(c.RotateAllLeft(23)), // ERROR "inlining call to archsimd.Int64x4.RotateAllLeft"
a.RotateAllLeft(1).Xor(d.RotateAllLeft(23)) // ERROR "inlining call to archsimd.Int64x4.RotateAllLeft"
}
shuf() // ERROR "inlining call to hasClosure.func1" "inlining call to archsimd.Int64x4.RotateAllLeft"
shuf() // ERROR "inlining call to hasClosure.func1" "inlining call to archsimd.Int64x4.RotateAllLeft"
shuf() // ERROR "inlining call to hasClosure.func1" "inlining call to archsimd.Int64x4.RotateAllLeft"
shuf() // ERROR "inlining call to hasClosure.func1" "inlining call to archsimd.Int64x4.RotateAllLeft"
shuf() // ERROR "inlining call to hasClosure.func1" "inlining call to archsimd.Int64x4.RotateAllLeft"
shuf() // ERROR "inlining call to hasClosure.func1" "inlining call to archsimd.Int64x4.RotateAllLeft"
shuf() // ERROR "inlining call to hasClosure.func1" "inlining call to archsimd.Int64x4.RotateAllLeft"
shuf() // ERROR "inlining call to hasClosure.func1" "inlining call to archsimd.Int64x4.RotateAllLeft"
shuf() // ERROR "inlining call to hasClosure.func1" "inlining call to archsimd.Int64x4.RotateAllLeft"
return
}