• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# AC_PROG_NASM
2# --------------------------
3# Check that NASM exists and determine flags
4AC_DEFUN([AC_PROG_NASM],[
5
6AC_ARG_VAR(NASM, [NASM command (used to build the x86/x86-64 SIMD code)])
7if test "x$NASM" = "x"; then
8  AC_CHECK_PROGS(NASM, [nasm nasmw yasm])
9  test -z "$NASM" && AC_MSG_ERROR([no nasm (Netwide Assembler) found])
10fi
11
12AC_MSG_CHECKING([for object file format of host system])
13case "$host_os" in
14  cygwin* | mingw* | pw32* | interix*)
15    case "$host_cpu" in
16      x86_64)
17        objfmt='Win64-COFF'
18        ;;
19      *)
20        objfmt='Win32-COFF'
21        ;;
22    esac
23  ;;
24  msdosdjgpp* | go32*)
25    objfmt='COFF'
26  ;;
27  os2-emx*)			# not tested
28    objfmt='MSOMF'		# obj
29  ;;
30  linux*coff* | linux*oldld*)
31    objfmt='COFF'		# ???
32  ;;
33  linux*aout*)
34    objfmt='a.out'
35  ;;
36  linux*)
37    case "$host_cpu" in
38      x86_64)
39        objfmt='ELF64'
40        ;;
41      *)
42        objfmt='ELF'
43        ;;
44    esac
45  ;;
46  kfreebsd* | freebsd* | netbsd* | openbsd*)
47    if echo __ELF__ | $CC -E - | grep __ELF__ > /dev/null; then
48      objfmt='BSD-a.out'
49    else
50      case "$host_cpu" in
51        x86_64 | amd64)
52          objfmt='ELF64'
53          ;;
54        *)
55          objfmt='ELF'
56          ;;
57      esac
58    fi
59  ;;
60  solaris* | sunos* | sysv* | sco*)
61    case "$host_cpu" in
62      x86_64)
63        objfmt='ELF64'
64        ;;
65      *)
66        objfmt='ELF'
67        ;;
68    esac
69  ;;
70  darwin* | rhapsody* | nextstep* | openstep* | macos*)
71    case "$host_cpu" in
72      x86_64)
73        objfmt='Mach-O64'
74        ;;
75      *)
76        objfmt='Mach-O'
77        ;;
78    esac
79  ;;
80  *)
81    objfmt='ELF ?'
82  ;;
83esac
84
85AC_MSG_RESULT([$objfmt])
86if test "$objfmt" = 'ELF ?'; then
87  objfmt='ELF'
88  AC_MSG_WARN([unexpected host system. assumed that the format is $objfmt.])
89fi
90
91AC_MSG_CHECKING([for object file format specifier (NAFLAGS) ])
92case "$objfmt" in
93  MSOMF)      NAFLAGS='-fobj -DOBJ32';;
94  Win32-COFF) NAFLAGS='-fwin32 -DWIN32';;
95  Win64-COFF) NAFLAGS='-fwin64 -DWIN64 -D__x86_64__';;
96  COFF)       NAFLAGS='-fcoff -DCOFF';;
97  a.out)      NAFLAGS='-faout -DAOUT';;
98  BSD-a.out)  NAFLAGS='-faoutb -DAOUT';;
99  ELF)        NAFLAGS='-felf -DELF';;
100  ELF64)      NAFLAGS='-felf64 -DELF -D__x86_64__';;
101  RDF)        NAFLAGS='-frdf -DRDF';;
102  Mach-O)     NAFLAGS='-fmacho -DMACHO';;
103  Mach-O64)   NAFLAGS='-fmacho64 -DMACHO -D__x86_64__';;
104esac
105AC_MSG_RESULT([$NAFLAGS])
106AC_SUBST([NAFLAGS])
107
108AC_MSG_CHECKING([whether the assembler ($NASM $NAFLAGS) works])
109cat > conftest.asm <<EOF
110[%line __oline__ "configure"
111        section .text
112        global  _main,main
113_main:
114main:   xor     eax,eax
115        ret
116]EOF
117try_nasm='$NASM $NAFLAGS -o conftest.o conftest.asm'
118if AC_TRY_EVAL(try_nasm) && test -s conftest.o; then
119  AC_MSG_RESULT(yes)
120else
121  echo "configure: failed program was:" >&AC_FD_CC
122  cat conftest.asm >&AC_FD_CC
123  rm -rf conftest*
124  AC_MSG_RESULT(no)
125  AC_MSG_ERROR([installation or configuration problem: assembler cannot create object files.])
126fi
127
128AC_MSG_CHECKING([whether the linker accepts assembler output])
129try_nasm='${CC-cc} -o conftest${ac_exeext} $LDFLAGS conftest.o $LIBS 1>&AC_FD_CC'
130if AC_TRY_EVAL(try_nasm) && test -s conftest${ac_exeext}; then
131  rm -rf conftest*
132  AC_MSG_RESULT(yes)
133else
134  rm -rf conftest*
135  AC_MSG_RESULT(no)
136  AC_MSG_ERROR([configuration problem: maybe object file format mismatch.])
137fi
138
139])
140
141# AC_CHECK_COMPATIBLE_ARM_ASSEMBLER_IFELSE
142# --------------------------
143# Test whether the assembler is suitable and supports NEON instructions
144AC_DEFUN([AC_CHECK_COMPATIBLE_ARM_ASSEMBLER_IFELSE],[
145  ac_good_gnu_arm_assembler=no
146  ac_save_CC="$CC"
147  ac_save_CFLAGS="$CFLAGS"
148  CFLAGS="$CCASFLAGS -x assembler-with-cpp"
149  CC="$CCAS"
150  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
151    .text
152    .fpu neon
153    .arch armv7a
154    .object_arch armv4
155    .arm
156    pld [r0]
157    vmovn.u16 d0, q0]])], ac_good_gnu_arm_assembler=yes)
158
159  ac_use_gas_preprocessor=no
160  if test "x$ac_good_gnu_arm_assembler" = "xno" ; then
161    CC="gas-preprocessor.pl $CCAS"
162    AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
163      .text
164      .fpu neon
165      .arch armv7a
166      .object_arch armv4
167      .arm
168      pld [r0]
169      vmovn.u16 d0, q0]])], ac_use_gas_preprocessor=yes)
170  fi
171  CFLAGS="$ac_save_CFLAGS"
172  CC="$ac_save_CC"
173
174  if test "x$ac_use_gas_preprocessor" = "xyes" ; then
175    CCAS="gas-preprocessor.pl $CCAS"
176    AC_SUBST([CCAS])
177    ac_good_gnu_arm_assembler=yes
178  fi
179
180  if test "x$ac_good_gnu_arm_assembler" = "xyes" ; then
181    $1
182  else
183    $2
184  fi
185])
186
187# AC_CHECK_COMPATIBLE_MIPSEL_ASSEMBLER_IFELSE
188# --------------------------
189# Test whether the assembler is suitable and supports MIPS instructions
190AC_DEFUN([AC_CHECK_COMPATIBLE_MIPS_ASSEMBLER_IFELSE],[
191  have_mips_dspr2=no
192  ac_save_CFLAGS="$CFLAGS"
193  CFLAGS="$CCASFLAGS -mdspr2"
194
195  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
196
197  int main ()
198  {
199    int c = 0, a = 0, b = 0;
200    __asm__ __volatile__ (
201        "precr.qb.ph %[c], %[a], %[b]          \n\t"
202        : [c] "=r" (c)
203        : [a] "r" (a), [b] "r" (b)
204    );
205    return c;
206  }
207  ]])], have_mips_dspr2=yes)
208  CFLAGS=$ac_save_CFLAGS
209
210  if test "x$have_mips_dspr2" = "xyes" ; then
211    $1
212  else
213    $2
214  fi
215])
216
217AC_DEFUN([AC_CHECK_COMPATIBLE_ARM64_ASSEMBLER_IFELSE],[
218  ac_good_gnu_arm_assembler=no
219  ac_save_CC="$CC"
220  ac_save_CFLAGS="$CFLAGS"
221  CFLAGS="$CCASFLAGS -x assembler-with-cpp"
222  CC="$CCAS"
223  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
224    .text
225    MYVAR .req x0
226    movi v0.16b, #100
227    mov MYVAR, #100
228    .unreq MYVAR]])], ac_good_gnu_arm_assembler=yes)
229
230  ac_use_gas_preprocessor=no
231  if test "x$ac_good_gnu_arm_assembler" = "xno" ; then
232    CC="gas-preprocessor.pl $CCAS"
233    AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
234      .text
235      MYVAR .req x0
236      movi v0.16b, #100
237      mov MYVAR, #100
238      .unreq MYVAR]])], ac_use_gas_preprocessor=yes)
239  fi
240  CFLAGS="$ac_save_CFLAGS"
241  CC="$ac_save_CC"
242
243  if test "x$ac_use_gas_preprocessor" = "xyes" ; then
244    CCAS="gas-preprocessor.pl $CCAS"
245    AC_SUBST([CCAS])
246    ac_good_gnu_arm_assembler=yes
247  fi
248
249  if test "x$ac_good_gnu_arm_assembler" = "xyes" ; then
250    $1
251  else
252    $2
253  fi
254])
255