1#!/bin/sh
2
3# check_simd <srcdir> <builddir> <CXXFLAGS>
4# Read config from $CHECK_SIMD_CONFIG file or $target_list
5
6scriptdir="$(cd "${0%/*}" && pwd)"
7srcdir="$1"
8builddir="$2"
9shift 2
10testdir="$builddir/testsuite"
11
12CXX="$("$builddir/scripts/testsuite_flags" --build-cxx)"
13CXXFLAGS="$("$builddir/scripts/testsuite_flags" --cxxflags) $1 -Wno-psabi"
14shift
15INCLUDES="$("$builddir/scripts/testsuite_flags" --build-includes)"
16
17target_triplet=$($CXX -dumpmachine)
18
19define_target() {
20  name="$1"
21  flags="$2"
22  sim="$3"
23  eval "$name=\"flags=\\\"$flags\\\"
24sim=\\\"$sim\\\"\""
25}
26
27if [ -f "$CHECK_SIMD_CONFIG" ]; then
28  . "$CHECK_SIMD_CONFIG"
29elif [ -z "$CHECK_SIMD_CONFIG" ]; then
30  if [ -z "$target_list" ]; then
31    target_list="unix"
32    case "$target_triplet" in
33      x86_64-*)      target_list="unix/-march=native" ;;
34      i?86-*)        target_list="unix/-march=native" ;;
35      powerpc64le-*) target_list="unix/-mcpu=power8" ;;
36      aarch64-*)     target_list="unix/-mcpu=cortex-a53" ;;
37      arm-*)         target_list="unix/-mcpu=cortex-a7" ;;
38    esac
39  fi
40else
41  echo "Error: File not found: \$CHECK_SIMD_CONFIG='$CHECK_SIMD_CONFIG'" 1>&2
42  exit 1
43fi
44
45# define unix with no flags and no simulator:
46define_target unix
47
48list="$target_list"
49
50# expand a{b,c} to a/b a/c
51while [ "${list#*\{}" != "${list}" ]; do
52  list="$(echo "$list" | \
53    sed -e 's#\([^ ]\+\){\([^{},]*\),\([^{}]*\)}\(/[^ ]*\)\?#\1/\2\4 \1{\3}\4#g' \
54        -e 's#{\([^{},]*\)}#/\1#g' \
55        -e 's#/ # #g' -e 's#/$##')"
56done
57
58# per a/b/c block extract flags and simulator, then make check-simd
59while [ ${#list} -gt 0 ]; do
60  a="${list%% *}"
61  if [ "$a" = "$list" ]; then
62    list=""
63  else
64    list="${list#${a} }"
65  fi
66  b="${a%%/*}"
67  eval "eval \"\$$b\""
68  flags="${flags}$(echo "${a#${b}}"|sed 's#/# #g')"
69  subdir="simd/$(echo "$flags" | sed 's#[= /-]##g')"
70  rm -f "${subdir}/Makefile"
71  $srcdir/testsuite/experimental/simd/generate_makefile.sh \
72    --destination="$testdir/$subdir" --sim="$sim" --testflags="$flags" \
73    $CXX $INCLUDES $CXXFLAGS -static-libgcc -static-libstdc++
74  echo "$subdir"
75done
76