aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Sing <joel@sing.id.au>2026-02-21 02:14:06 +1100
committerJoel Sing <joel@sing.id.au>2026-02-28 03:17:49 -0800
commitff023a334125bb4edb43db352d2c6a5eb414d2e4 (patch)
treedd36dea57a51a6ab40cf8edb0f6c321aad878f9c
parent5cd4b35d73c1822b03ea5624fd48cc1c294254c9 (diff)
downloadgo-ff023a334125bb4edb43db352d2c6a5eb414d2e4.tar.xz
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>
-rw-r--r--test/codegen/condmove.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/test/codegen/condmove.go b/test/codegen/condmove.go
index 54e5f361fe..bd2d1540b4 100644
--- a/test/codegen/condmove.go
+++ b/test/codegen/condmove.go
@@ -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)
+}