Created
October 25, 2025 16:24
-
-
Save starius/0a6f84c64de0650ebeaf4381b25c2c42 to your computer and use it in GitHub Desktop.
VAES AVX2 test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module vaes-avx2-test | |
| go 1.25.1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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") | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //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