From ff023a334125bb4edb43db352d2c6a5eb414d2e4 Mon Sep 17 00:00:00 2001 From: Joel Sing Date: Sat, 21 Feb 2026 02:14:06 +1100 Subject: 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 Reviewed-by: David Chase Reviewed-by: Xueqi Luo <1824368278@qq.com> Reviewed-by: Meng Zhuo Reviewed-by: Russ Cox --- test/codegen/condmove.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test/codegen') 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) +} -- cgit v1.3