Skip to content

Instantly share code, notes, and snippets.

@kou1okada
Last active January 11, 2022 11:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kou1okada/b13cc2dd252ea99a87ca to your computer and use it in GitHub Desktop.
Save kou1okada/b13cc2dd252ea99a87ca to your computer and use it in GitHub Desktop.
Show the details of x86 cpu flags found in /proc/cpuinfo.
#!/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