test/codegen: add code generation test for subtle.ConstantTimeSelect

The subtle.ConstantTimeSelect function is now intrinsified on a number of
architectures. Add test coverage for code generation.

Change-Id: Iff97510838b39ec2137d64a62d2f516c94710c68
Reviewed-on: https://go-review.googlesource.com/c/go/+/748400
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Xueqi Luo <1824368278@qq.com>
Reviewed-by: Meng Zhuo <mengzhuo1203@gmail.com>
Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
Joel Sing
2026-02-21 02:14:06 +11:00
parent 5cd4b35d73
commit ff023a3341

View File

@@ -6,6 +6,8 @@
package codegen
import "crypto/subtle"
func cmovint(c int) int {
x := c + 4
if x < 0 {
@@ -527,3 +529,11 @@ func cmovFromMulFromFlags64sext(x int64, b bool) int64 {
// amd64:"CMOV",-"MOVB.ZX",-"MUL"
return x * r
}
func constantTimeSelect(v, x, y int) int {
// amd64:"CMOVQ"
// arm64:"CSEL"
// riscv64/rva20u64,riscv64/rva22u64:"SNEZ" "NEG" "AND" "OR"
// riscv64/rva23u64:"NEG" "CZERONEZ" "CZEROEQZ" "OR" -"SNEZ" -"AND"
return subtle.ConstantTimeSelect(v, x, y)
}