Skip to content

Instantly share code, notes, and snippets.

@hvrsim
Created August 10, 2024 19:50
Show Gist options
  • Save hvrsim/a4bc4a92d1ce61c8debc193139c409d9 to your computer and use it in GitHub Desktop.
Save hvrsim/a4bc4a92d1ce61c8debc193139c409d9 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Code from StackOverflow answer, link here:
# https://stackoverflow.com/questions/43128698/inlining-failed-in-call-to-always-inline-mm-mullo-epi32-target-specific-opti
get_instruction ()
{
[ -z "$1" ] && exit
func_name="$1[^1-9a-zA-Z_]"
header_file=`grep --include=\*intrin.h -Rl "$func_name" /usr/lib/gcc | head -n1`
[ -z "$header_file" ] && exit
>&2 echo "function located in: $header_file"
target_directive=`grep "#pragma GCC target(\|$func_name" $header_file | grep -B 1 "$func_name" | head -n1`
echo $target_directive | grep -o '"[^,]*[,"]' | sed 's/"//g' | sed 's/,//g'
}
instruction=`get_instruction $1`
if [ -z "$instruction" ]; then
echo "error: function not found: $1"
else
echo "add \"-m$instruction\" to the gcc invocation"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment