Skip to content

Instantly share code, notes, and snippets.

@mr-c
Created April 20, 2020 11:11
Show Gist options
  • Save mr-c/90dbca3383037914dbdd5abf935231d9 to your computer and use it in GitHub Desktop.
Save mr-c/90dbca3383037914dbdd5abf935231d9 to your computer and use it in GitHub Desktop.
#!/bin/bash
for SIMD in mmx sse sse2 sse3 ssse3 sse4.1 sse4.2 avx fma avx2 avx512bw avx512f avx512vl; do
echo ${SIMD}
gcc -DSIMDE_NO_NATIVE -DSIMDE_ENABLE_NATIVE_ALIASES -I. -fdump-tree-original ./test/build/CMakeFiles/munit.dir/munit/munit.c.o test/x86/${SIMD}.c -lm -o ${SIMD}.o || true # 2> /dev/null || true
grep Function ${SIMD}.c.004t.original | awk '{ print $3}' >> simde.functions
while read -r line ; do
if [[ "${line}" == "simde"* ]] ; then
if grep -q " ${line##simde}" simde/x86/${SIMD}.h ; then
echo ${line##simde}
fi
fi
done < simde.functions >> simde.native.functions
done
sort -u < simde.native.functions > simde.sorted.native.functions
echo Found $(wc -l < simde.sorted.native.functions) native functions implemented
skips="_mm256_extract_epi8 _mm256_extract_epi16 _mm256_extract_epi32 _mm256_extract_epi64 _mm256_insert_epi8 _mm256_insert_epi16 _mm256_insert_epi32 _mm256_insert_epi64"
# These need to be skipped, or the loops manually unrolled.
for skip in ${skips} ; do sed -i "/${skip}/d" simde.sorted.native.functions ; done
for SIMD in mmx sse sse2 sse3 ssse3 sse4.1 sse4.2 avx fma avx2 avx512bw avx512f avx512vl; do
while read -r line ; do
sed -i -E "s/([^_])simde${line}/\1${line}/g" test/x86/${SIMD}.c
done < simde.sorted.native.functions
done
@nemequ
Copy link

nemequ commented Apr 22, 2020

For the first part, is there a reason not to just add -fdump-tree-original to the CFLAGS, then just compile normally?

Instead of hardcoding the ISA extensions, maybe something like for header in simde/x86/*.h; SIMD="$(basename "$header" .h)"; ...; done?

For generating the list of candidate functions, you could get rid of awk with something like grep -hoP '(?<=;; Function )simde_[^ ]+' "${SIMD}.c.004t.original". That wolud also let you get rid of the outer if.

Maybe it would be better to parse the function list from the XML data backing the Intel Intrinsics Guide? If you want, I can generate a list of native functions that we could just keep in the repo somewhere.

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