Skip to content

Instantly share code, notes, and snippets.

@mrspartak
Last active September 23, 2025 04:45
Show Gist options
  • Select an option

  • Save mrspartak/72452c5f72b886f4422c8182190dc5ea to your computer and use it in GitHub Desktop.

Select an option

Save mrspartak/72452c5f72b886f4422c8182190dc5ea to your computer and use it in GitHub Desktop.
Detect GOAMD64 level on linux machine
$script = {
$cpu = Get-WmiObject Win32_Processor
$flags = $cpu.Caption + " " + $cpu.Name + " " + $cpu.Description
function Check-Flag {
param([string]$flag)
return $flags -match $flag
}
if ((Check-Flag "AVX512F") -and (Check-Flag "AVX512BW") -and (Check-Flag "AVX512CD") -and (Check-Flag "AVX512DQ") -and (Check-Flag "AVX512VL")) {
return "v4"
} elseif ((Check-Flag "AVX") -and (Check-Flag "AVX2") -and (Check-Flag "BMI1") -and (Check-Flag "BMI2") -and (Check-Flag "FMA") -and (Check-Flag "MOVBE")) {
return "v3"
} elseif ((Check-Flag "CMPXCHG16B") -and (Check-Flag "POPCNT") -and (Check-Flag "SSE3") -and (Check-Flag "SSE4.1") -and (Check-Flag "SSE4.2") -and (Check-Flag "SSSE3")) {
return "v2"
} else {
return "v1"
}
}
$result = powershell -Command $script
Write-Output "Supported GOAMD64 level: $result"
#!/bin/bash
check_flag() {
grep -q "$1" /proc/cpuinfo
return $?
}
if check_flag "avx512f" && check_flag "avx512bw" && check_flag "avx512cd" && check_flag "avx512dq" && check_flag "avx512vl"; then
echo "v4"
elif check_flag "avx" && check_flag "avx2" && check_flag "bmi1" && check_flag "bmi2" && check_flag "f16c" && check_flag "fma" && check_flag "abm" && check_flag "movbe"; then
echo "v3"
elif check_flag "cx16" && check_flag "lahf_lm" && check_flag "popcnt" && check_flag "sse3" && check_flag "sse4_1" && check_flag "sse4_2" && check_flag "ssse3"; then
echo "v2"
else
echo "v1"
fi
@mrspartak
Copy link
Author

Usage:

GOAMD64=$(curl -sSL https://gist.githubusercontent.com/mrspartak/72452c5f72b886f4422c8182190dc5ea/raw/00f1d358ad9a4d7be765351e4901ab74bd4c2378/detect_goamd64.sh | bash) && echo "Supported GOAMD64 level: $GOAMD64"

@mrspartak
Copy link
Author

For windows:

powershell -Command "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12; iex ((New-Object System.Net.WebClient).DownloadString('https://gist.githubusercontent.com/mrspartak/72452c5f72b886f4422c8182190dc5ea/raw/7690fd129468de418c45ffa32a887e8feaffed95/detect_goamd64.ps1'))"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment