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