Home | History | Annotate | Line # | Download | only in druntime
      1 #
      2 # Contains macros to detect CPU features.
      3 #
      4 
      5 
      6 # DRUNTIME_CPU_SOURCES
      7 # -------------------
      8 # Detect target CPU and add DRUNTIME_CPU_XXX conditionals.
      9 AC_DEFUN([DRUNTIME_CPU_SOURCES],
     10 [
     11   druntime_target_cpu_parsed=""
     12   case "$target_cpu" in
     13       aarch64*)
     14                druntime_target_cpu_parsed="aarch64"
     15                ;;
     16       arm*)    druntime_target_cpu_parsed="arm"
     17                ;;
     18       mips*)   druntime_target_cpu_parsed="mips"
     19                ;;
     20       powerpc*)
     21                druntime_target_cpu_parsed="powerpc"
     22                ;;
     23       i[[34567]]86|x86_64)
     24                druntime_target_cpu_parsed="x86"
     25                ;;
     26       s390x)
     27                druntime_target_cpu_parsed="s390x"
     28                ;;
     29       s390)
     30                druntime_target_cpu_parsed="s390"
     31                ;;
     32   esac
     33   AM_CONDITIONAL([DRUNTIME_CPU_AARCH64],
     34                  [test "$druntime_target_cpu_parsed" = "aarch64"])
     35   AM_CONDITIONAL([DRUNTIME_CPU_ARM],
     36                  [test "$druntime_target_cpu_parsed" = "arm"])
     37   AM_CONDITIONAL([DRUNTIME_CPU_MIPS],
     38                  [test "$druntime_target_cpu_parsed" = "mips"])
     39   AM_CONDITIONAL([DRUNTIME_CPU_POWERPC],
     40                  [test "$druntime_target_cpu_parsed" = "powerpc"])
     41   AM_CONDITIONAL([DRUNTIME_CPU_X86],
     42                  [test "$druntime_target_cpu_parsed" = "x86"])
     43   AM_CONDITIONAL([DRUNTIME_CPU_SYSTEMZ],
     44                  [test "$druntime_target_cpu_parsed" = "s390x"])
     45   AM_CONDITIONAL([DRUNTIME_CPU_S390],
     46                  [test "$druntime_target_cpu_parsed" = "s390"])
     47 ])
     48 
     49 
     50 # DRUNTIME_ENABLE_ATOMIC_BUILTINS
     51 # -------------------------
     52 # Check support for atomic builtins up to 64 bit.
     53 AC_DEFUN([DRUNTIME_ENABLE_ATOMIC_BUILTINS],
     54 [
     55   # This checks to see if the host supports the compiler-generated builtins
     56   # for atomic operations for various integral sizes. Note, this is intended
     57   # to be an all-or-nothing switch, so all the atomic operations that are
     58   # used should be checked.
     59   AC_MSG_CHECKING([for atomic builtins for byte])
     60   AC_CACHE_VAL(druntime_cv_atomic_byte, [
     61     AC_TRY_LINK(
     62       [import gcc.builtins;], [
     63       shared(byte) c1;
     64        byte c2, c3;
     65        __atomic_compare_exchange_1(&c1, &c2, c3, false, 5, 5);
     66        __atomic_load_1(&c1, 5);
     67        __atomic_store_1(&c1, c2, 5);
     68        return 0;
     69       ],
     70       [druntime_cv_atomic_byte=yes],
     71       [druntime_cv_atomic_byte=no])
     72   ])
     73   AC_MSG_RESULT($druntime_cv_atomic_byte)
     74 
     75   AC_MSG_CHECKING([for atomic builtins for short])
     76   AC_CACHE_VAL(druntime_cv_atomic_short, [
     77     AC_TRY_LINK(
     78       [import gcc.builtins;], [
     79       shared(short) c1;
     80        short c2, c3;
     81        __atomic_compare_exchange_2(&c1, &c2, c3, false, 5, 5);
     82        __atomic_load_2(&c1, 5);
     83        __atomic_store_2(&c1, c2, 5);
     84        return 0;
     85       ],
     86       [druntime_cv_atomic_short=yes],
     87       [druntime_cv_atomic_short=no])
     88   ])
     89   AC_MSG_RESULT($druntime_cv_atomic_short)
     90 
     91   AC_MSG_CHECKING([for atomic builtins for int])
     92   AC_CACHE_VAL(druntime_cv_atomic_int, [
     93     AC_TRY_LINK(
     94       [import gcc.builtins;], [
     95       shared(int) c1;
     96        int c2, c3;
     97        __atomic_compare_exchange_4(&c1, &c2, c3, false, 5, 5);
     98        __atomic_load_4(&c1, 5);
     99        __atomic_store_4(&c1, c2, 5);
    100        return 0;
    101       ],
    102       [druntime_cv_atomic_int=yes],
    103       [druntime_cv_atomic_int=no])
    104   ])
    105   AC_MSG_RESULT($druntime_cv_atomic_int)
    106 
    107   AC_MSG_CHECKING([for atomic builtins for long])
    108   AC_CACHE_VAL(druntime_cv_atomic_long, [
    109     AC_TRY_LINK(
    110       [import gcc.builtins;], [
    111        shared(long) c1;
    112        long c2, c3;
    113        __atomic_compare_exchange_8(&c1, &c2, c3, false, 5, 5);
    114        __atomic_load_8(&c1, 5);
    115        __atomic_store_8(&c1, c2, 5);
    116        return 0;
    117       ],
    118       [druntime_cv_atomic_long=yes],
    119       [druntime_cv_atomic_long=no])
    120   ])
    121   AC_MSG_RESULT($druntime_cv_atomic_long)
    122 
    123   # Have atomic builtin support if all but the long test above passes.
    124   DCFG_HAVE_ATOMIC_BUILTINS=false
    125   if test "$druntime_cv_atomic_byte" = yes \
    126      && test "$druntime_cv_atomic_short" = yes \
    127      && test "$druntime_cv_atomic_int" = yes; then \
    128     DCFG_HAVE_ATOMIC_BUILTINS=true
    129   fi
    130 
    131   # Have 64-bit atomic support if the long test above passes.
    132   DCFG_HAVE_64BIT_ATOMICS=false
    133   if test "$druntime_cv_atomic_long" = yes; then
    134     DCFG_HAVE_64BIT_ATOMICS=true
    135   fi
    136 
    137   AC_SUBST(DCFG_HAVE_ATOMIC_BUILTINS)
    138   AC_SUBST(DCFG_HAVE_64BIT_ATOMICS)
    139 ])
    140