Last active
January 11, 2022 11:53
-
-
Save kou1okada/b13cc2dd252ea99a87ca to your computer and use it in GitHub Desktop.
Show the details of x86 cpu flags found in /proc/cpuinfo.
This file contains 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
#!/usr/bin/env bash | |
function have_command () | |
{ | |
type "$1" >& /dev/null | |
} | |
function get_local_features () | |
{ | |
grep ^flags /proc/cpuinfo \ | |
| head -n1 \ | |
| tr [:lower:] [:upper:] \ | |
| awk '{for(i=3;i<=NF;i++)print $i;}' | |
} | |
function get_features_definition () | |
{ | |
local cmd | |
if have_command wget; then | |
cmd=( wget -qO- ) | |
elif have_command curl; then | |
cmd=( curl -o - ) | |
fi | |
"${cmd[@]}" http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/plain/arch/x86/include/asm/cpufeatures.h \ | |
| grep -E "^#define +X86_FEATURE_" \ | |
| sed -r -e 's/\t/ /g' -e 's:.* X86_FEATURE_([^ ]*).*/\* *(.*?) *\*/.*$:\1\t\2:g' | |
} | |
function make_query () | |
{ | |
awk '{printf("%s^%s\t", sep, $0);sep="|"}' | |
} | |
get_features_definition \ | |
| grep -E "$(get_local_features | make_query)" \ | |
| awk -v FS="\t" '{printf("%-18s %s\n", $1, $2);}' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment