Skip to content

Commit

Permalink
divide SIMD codes for compiling them with differnt compiler options
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeAkinobu committed Sep 7, 2016
1 parent 7d31ba5 commit 1df3fde
Show file tree
Hide file tree
Showing 11 changed files with 363 additions and 242 deletions.
17 changes: 15 additions & 2 deletions libsent/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ src/phmm/addlog.o \
src/phmm/mkwhmm.o \
src/phmm/vsegment.o \
src/phmm/calc_dnn.o \
src/phmm/calc_dnn_fma.o \
src/phmm/calc_dnn_avx.o \
src/phmm/calc_dnn_sse.o \
src/phmm/calc_dnn_neon.o \
src/util/endian.o \
src/util/jlog.o \
src/util/mymalloc.o \
Expand Down Expand Up @@ -142,8 +146,17 @@ $(TARGET): $(OBJ)
$(AR) $@ $?
$(RANLIB) $@

src/phmm/calc_dnn.o: src/phmm/calc_dnn.c
$(CC) $(CFLAGS) $(CPPFLAGS) @SIMD_CFLAGS@ -o $@ -c $<
src/phmm/calc_dnn_fma.o: src/phmm/calc_dnn_fma.c
$(CC) $(CFLAGS) $(CPPFLAGS) @SIMD_FMA_CFLAGS@ -o $@ -c $<

src/phmm/calc_dnn_avx.o: src/phmm/calc_dnn_avx.c
$(CC) $(CFLAGS) $(CPPFLAGS) @SIMD_AVX_CFLAGS@ -o $@ -c $<

src/phmm/calc_dnn_sse.o: src/phmm/calc_dnn_sse.c
$(CC) $(CFLAGS) $(CPPFLAGS) @SIMD_SSE_CFLAGS@ -o $@ -c $<

src/phmm/calc_dnn_neon.o: src/phmm/calc_dnn_neon.c
$(CC) $(CFLAGS) $(CPPFLAGS) @SIMD_NEON_CFLAGS@ -o $@ -c $<


############################################################
Expand Down
91 changes: 53 additions & 38 deletions libsent/configure
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,10 @@ RM
INSTALL_DATA
INSTALL_SCRIPT
INSTALL_PROGRAM
SIMD_CFLAGS
SIMD_NEON_CFLAGS
SIMD_SSE_CFLAGS
SIMD_AVX_CFLAGS
SIMD_FMA_CFLAGS
CPP
OBJEXT
EXEEXT
Expand Down Expand Up @@ -3310,6 +3313,7 @@ _ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
SIMD_FMA_CFLAGS=""
xxxxFMA=yes
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
Expand Down Expand Up @@ -3337,7 +3341,7 @@ _ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
SIMD_CFLAGS="-mfma"
SIMD_FMA_CFLAGS="-mfma"
xxxxFMA=yes
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
Expand All @@ -3346,14 +3350,15 @@ fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
CFLAGS="$xxxCFLAGS"
fi
if test "$xxxxFMA" = yes; then
xxxxAVX=yes
else
xxxxAVX=no
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for SIMD AVX instruction" >&5
$as_echo "#define HAS_SIMD_FMA 1" >>confdefs.h
fi
xxxxAVX=no
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for SIMD AVX instruction" >&5
$as_echo_n "checking for SIMD AVX instruction... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <immintrin.h>
Expand All @@ -3368,19 +3373,20 @@ _ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
xxxxAVX=yes
SIMD_AVX_CFLAGS=""
xxxxAVX=yes
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
if test "$xxxxAVX" = no; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for SIMD AVX instruction with -mavx" >&5
if test "$xxxxAVX" = no; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for SIMD AVX instruction with -mavx" >&5
$as_echo_n "checking for SIMD AVX instruction with -mavx... " >&6; }
xxxCFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -mavx"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
xxxCFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -mavx"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <immintrin.h>
Expand All @@ -3395,24 +3401,24 @@ _ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
SIMD_CFLAGS="-mavx"
xxxxAVX=yes
SIMD_AVX_CFLAGS="-mavx"
xxxxAVX=yes
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
CFLAGS="$xxxCFLAGS"
fi
CFLAGS="$xxxCFLAGS"
fi
if test "$xxxxAVX" = yes; then
xxxxSSE=yes
else
xxxxSSE=no
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for SIMD SSE instruction" >&5
$as_echo "#define HAS_SIMD_AVX 1" >>confdefs.h
fi
xxxxSSE=no
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for SIMD SSE instruction" >&5
$as_echo_n "checking for SIMD SSE instruction... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <immintrin.h>
Expand All @@ -3427,19 +3433,20 @@ _ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
xxxxSSE=yes
SIMD_SSE_CFLAGS=""
xxxxSSE=yes
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
if test "$xxxxSSE" = no; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for SIMD SSE instruction with -msse" >&5
if test "$xxxxSSE" = no; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for SIMD SSE instruction with -msse" >&5
$as_echo_n "checking for SIMD SSE instruction with -msse... " >&6; }
xxxCFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -msse"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
xxxCFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -msse"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <immintrin.h>
Expand All @@ -3454,19 +3461,22 @@ _ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
SIMD_CFLAGS="-msse"
xxxxSSE=yes
SIMD_SSE_CFLAGS="-msse"
xxxxSSE=yes
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
CFLAGS="$xxxCFLAGS"
fi
CFLAGS="$xxxCFLAGS"
fi
if test "$xxxxSSE" = yes; then
$as_echo "#define HAS_SIMD_SSE 1" >>confdefs.h
fi
if test "$use_neon" = yes; then
xxxxNEON=yes
xxxxNEON=no
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for NEON SIMD instruction for ARM" >&5
$as_echo_n "checking for NEON SIMD instruction for ARM... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
Expand All @@ -3484,10 +3494,11 @@ _ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
SIMD_NEON_CFLAGS=""
xxxxNEON=yes
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
xxxxNEON=no
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
Expand All @@ -3511,22 +3522,26 @@ _ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
SIMD_CFLAGS="-mfpu=neon"
SIMD_NEON_CFLAGS="-mfpu=neon"
xxxxNEON=yes
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
CFLAGS="$xxxCFLAGS"
fi
if test "$xxxxNEON" = yes; then
$as_echo "#define USE_ARM_NEON 1" >>confdefs.h
$as_echo "#define HAS_SIMD_NEON 1" >>confdefs.h
fi
fi
# Find a good install program. We prefer a C program (faster),
# so one script is as good as another. But avoid the broken or
# incompatible versions:
Expand Down
105 changes: 57 additions & 48 deletions libsent/configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ AC_MSG_CHECKING([for SIMD FMA instruction])
AC_TRY_COMPILE([#include <immintrin.h>
],[__m256 v1, v2; __m256 x = _mm256_fmadd_ps(v1, v2, x);],
AC_MSG_RESULT([yes])
SIMD_FMA_CFLAGS=""
xxxxFMA=yes,
AC_MSG_RESULT([no])
)
Expand All @@ -150,72 +151,76 @@ if test "$xxxxFMA" = no; then
AC_TRY_COMPILE([#include <immintrin.h>
],[__m256 v1, v2; __m256 x = _mm256_fmadd_ps(v1, v2, x);],
AC_MSG_RESULT([yes])
SIMD_CFLAGS="-mfma"
SIMD_FMA_CFLAGS="-mfma"
xxxxFMA=yes,
AC_MSG_RESULT([no]))
CFLAGS="$xxxCFLAGS"
fi

if test "$xxxxFMA" = yes; then
xxxxAVX=yes
else
xxxxAVX=no
AC_MSG_CHECKING([for SIMD AVX instruction])
AC_DEFINE(HAS_SIMD_FMA)
fi

xxxxAVX=no
AC_MSG_CHECKING([for SIMD AVX instruction])
AC_TRY_COMPILE([#include <immintrin.h>
],[__m256 v = _mm256_setzero_ps();],
AC_MSG_RESULT([yes])
SIMD_AVX_CFLAGS=""
xxxxAVX=yes,
AC_MSG_RESULT([no])
)
if test "$xxxxAVX" = no; then
dnl retry with "-mavx" option
AC_MSG_CHECKING([for SIMD AVX instruction with -mavx])
xxxCFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -mavx"
AC_TRY_COMPILE([#include <immintrin.h>
],[__m256 v = _mm256_setzero_ps();],
AC_MSG_RESULT([yes])
SIMD_AVX_CFLAGS="-mavx"
xxxxAVX=yes,
AC_MSG_RESULT([no])
)
if test "$xxxxAVX" = no; then
dnl retry with "-mavx" option
AC_MSG_CHECKING([for SIMD AVX instruction with -mavx])
xxxCFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -mavx"
AC_TRY_COMPILE([#include <immintrin.h>
],[__m256 v = _mm256_setzero_ps();],
AC_MSG_RESULT([yes])
SIMD_CFLAGS="-mavx"
xxxxAVX=yes,
AC_MSG_RESULT([no]))
CFLAGS="$xxxCFLAGS"
fi
AC_MSG_RESULT([no]))
CFLAGS="$xxxCFLAGS"
fi

if test "$xxxxAVX" = yes; then
xxxxSSE=yes
else
xxxxSSE=no
AC_MSG_CHECKING([for SIMD SSE instruction])
AC_DEFINE(HAS_SIMD_AVX)
fi

xxxxSSE=no
AC_MSG_CHECKING([for SIMD SSE instruction])
AC_TRY_COMPILE([#include <immintrin.h>
],[__m128 x = _mm_setzero_ps();],
AC_MSG_RESULT([yes])
SIMD_SSE_CFLAGS=""
xxxxSSE=yes,
AC_MSG_RESULT([no])
)
if test "$xxxxSSE" = no; then
dnl retry with "-msse" option
AC_MSG_CHECKING([for SIMD SSE instruction with -msse])
xxxCFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -msse"
AC_TRY_COMPILE([#include <immintrin.h>
],[__m128 x = _mm_setzero_ps();],
AC_MSG_RESULT([yes])
SIMD_SSE_CFLAGS="-msse"
xxxxSSE=yes,
AC_MSG_RESULT([no])
)
if test "$xxxxSSE" = no; then
dnl retry with "-msse" option
AC_MSG_CHECKING([for SIMD SSE instruction with -msse])
xxxCFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -msse"
AC_TRY_COMPILE([#include <immintrin.h>
],[__m128 x = _mm_setzero_ps();],
AC_MSG_RESULT([yes])
SIMD_CFLAGS="-msse"
xxxxSSE=yes,
AC_MSG_RESULT([no]))
CFLAGS="$xxxCFLAGS"
fi
AC_MSG_RESULT([no]))
CFLAGS="$xxxCFLAGS"
fi
if test "$xxxxSSE" = yes; then
AC_DEFINE(HAS_SIMD_SSE)
fi

if test "$use_neon" = yes; then
xxxxNEON=yes
xxxxNEON=no
AC_MSG_CHECKING([for NEON SIMD instruction for ARM])
AC_TRY_COMPILE([#include <arm_neon.h>
],[float32x4_t x = vdupq_n_f32(0);],
AC_MSG_RESULT([yes]),
AC_MSG_RESULT([yes])
SIMD_NEON_CFLAGS=""
xxxxNEON=yes,
AC_MSG_RESULT([no])
xxxxNEON=no
)
if test "$xxxxNEON" = no; then
dnl retry with "-mfpu=neon" option
Expand All @@ -225,16 +230,20 @@ if test "$use_neon" = yes; then
AC_TRY_COMPILE([#include <arm_neon.h>
],[float32x4_t x = vdupq_n_f32(0);],
AC_MSG_RESULT([yes])
SIMD_CFLAGS="-mfpu=neon"
SIMD_NEON_CFLAGS="-mfpu=neon"
xxxxNEON=yes,
AC_MSG_RESULT([no]))
AC_MSG_RESULT([no])
)
CFLAGS="$xxxCFLAGS"
fi
if test "$xxxxNEON" = yes; then
AC_DEFINE(USE_ARM_NEON)
AC_DEFINE(HAS_SIMD_NEON)
fi
fi
AC_SUBST(SIMD_CFLAGS)
AC_SUBST(SIMD_FMA_CFLAGS)
AC_SUBST(SIMD_AVX_CFLAGS)
AC_SUBST(SIMD_SSE_CFLAGS)
AC_SUBST(SIMD_NEON_CFLAGS)

dnl Checks for programs.
AC_PROG_INSTALL
Expand Down
Loading

0 comments on commit 1df3fde

Please sign in to comment.