Skip to content

Instantly share code, notes, and snippets.

@starius
Created October 25, 2025 16:24
Show Gist options
  • Select an option

  • Save starius/0a6f84c64de0650ebeaf4381b25c2c42 to your computer and use it in GitHub Desktop.

Select an option

Save starius/0a6f84c64de0650ebeaf4381b25c2c42 to your computer and use it in GitHub Desktop.
VAES AVX2 test
module vaes-avx2-test
go 1.25.1
package main
import "fmt"
// VAESProbeYMM executes one VAESENC with YMM regs.
// It will SIGILL if VAES (256-bit) isn't supported by the CPU/OS.
func VAESProbeYMM()
func main() {
// If the instruction is unsupported, the process will crash before this prints.
VAESProbeYMM()
fmt.Println("ok: VAES YMM instruction executed")
}
//go:build amd64
#include "textflag.h"
// VAESProbeYMM executes a single VAESENC on YMM registers.
// If the CPU/OS doesn't support VAES (256-bit), this will SIGILL.
TEXT ·VAESProbeYMM(SB), NOSPLIT, $0-0
// Make sure upper lanes are in a known state.
VZEROUPPER
// Zero two YMM registers to use as state and round key.
// (We use VXORPS just to create valid YMM values.)
VXORPS Y0, Y0, Y0
VXORPS Y1, Y1, Y1
// Perform one AES encryption round:
// Intel syntax would be: VAESENC ymm0, ymm0, ymm1
// Go Plan 9 syntax is src1, src2, dst — so:
// dst = AESENC(src2, src1)
VAESENC Y1, Y0, Y0
// Clean up upper lanes for friendliness with legacy code.
VZEROUPPER
RET
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment