Skip to content

Instantly share code, notes, and snippets.

@AlexBaranowski
Created October 4, 2022 08:53
Show Gist options
  • Save AlexBaranowski/dc5fdc0916a568f3edfc71793eb445b8 to your computer and use it in GitHub Desktop.
Save AlexBaranowski/dc5fdc0916a568f3edfc71793eb445b8 to your computer and use it in GitHub Desktop.
Checking the x86_64 microarchitecture
#!/usr/bin/env bash
# Author: Alex Baranowski
# License: MIT
set -e
# we only need first flag line for the cpu
cpu_flags=$(grep '^flags\b' /proc/cpuinfo | head -n 1)
echo -e "supported cpu flags:\n$cpu_flags"
level=0
check_flags(){
current_level=$1
shift
fail_flag=0
for flag in "$@"; do
echo "$cpu_flags" | grep -q "$flag" || {
echo "Flag $flag is missing for $current_level microarchitecture"
fail_flag=1
}
done
[ $fail_flag -eq 1 ] || level=$current_level
}
main () {
echo -e "\n\nChecking micro architecture:\n\n"
check_flags 1 cmov cx8 fpu fxsr lm mmx sse2 syscall && \
check_flags 2 cx16 lahf_lm popcnt sse4_1 sse4_2 ssse3 && \
check_flags 3 abm avx avx2 bmi1 bmi2 f16c fma movbe xsave && \
check_flags 4 avx512bw avx512cd avx512dq avx512f avx512vl check_flags
echo -e "\n\n\nYour cpu support the x86_64 microarchitecture version $level aka x86_64-v${level}"
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment