1GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
2# Local configure fragment for sysdeps/s390.
3
4AC_CACHE_CHECK(for __builtin_tbegin, libc_cv_gcc_builtin_tbegin, [dnl
5cat > conftest.c <<\EOF
6#include <htmintrin.h>
7void testtransaction ()
8{
9  if (__builtin_tbegin (0) == _HTM_TBEGIN_STARTED)
10    {
11      __builtin_tend ();
12    }
13}
14EOF
15dnl
16dnl test, if the tbegin instruction is used by __builtin_tbegin
17if AC_TRY_COMMAND([${CC-cc} -mhtm -O2 -S conftest.c -o - | grep -w tbegin > /dev/null]) ;
18then
19  libc_cv_gcc_builtin_tbegin=yes
20else
21  libc_cv_gcc_builtin_tbegin=no
22fi
23rm -f conftest* ])
24
25if test "$libc_cv_gcc_builtin_tbegin" = no ; then
26   critic_missing="$critic_missing The used GCC has no support for __builtin_tbegin, which is needed for lock-elision on target S390."
27fi
28
29
30AC_CACHE_CHECK(for S390 vector instruction support, libc_cv_asm_s390_vx, [dnl
31cat > conftest.c <<\EOF
32void testvecinsn ()
33{
34    __asm__ (".machine \"z13\" \n\t"
35	     ".machinemode \"zarch_nohighgprs\" \n\t"
36	     "vistrbs %%v16,%%v17 \n\t"
37	     "locghie %%r1,0" : :);
38}
39EOF
40dnl
41dnl test, if assembler supports S390 vector instructions
42if AC_TRY_COMMAND([${CC-cc} --shared conftest.c -o conftest.o &> /dev/null]) ;
43then
44  libc_cv_asm_s390_vx=yes
45else
46  libc_cv_asm_s390_vx=no
47fi
48rm -f conftest* ])
49
50if test "$libc_cv_asm_s390_vx" = yes ;
51then
52  AC_DEFINE(HAVE_S390_VX_ASM_SUPPORT)
53else
54  AC_MSG_WARN([Use binutils with vector-support in order to use optimized implementations.])
55fi
56
57AC_CACHE_CHECK(for S390 vector support in gcc, libc_cv_gcc_s390_vx, [dnl
58cat > conftest.c <<\EOF
59void testvecclobber ()
60{
61  __asm__ ("" : : : "v16");
62}
63EOF
64dnl
65dnl test, if gcc supports S390 vector registers as clobber in inline assembly
66if AC_TRY_COMMAND([${CC-cc} --shared conftest.c -o conftest.o &> /dev/null]) ;
67then
68  libc_cv_gcc_s390_vx=yes
69else
70  libc_cv_gcc_s390_vx=no
71fi
72rm -f conftest* ])
73
74if test "$libc_cv_gcc_s390_vx" = yes ;
75then
76  AC_DEFINE(HAVE_S390_VX_GCC_SUPPORT)
77fi
78
79AC_CACHE_CHECK(for S390 arch13 zarch instruction support,
80	       libc_cv_asm_s390_arch13, [dnl
81cat > conftest.c <<\EOF
82void testinsn (char *buf)
83{
84    __asm__ (".machine \"arch13\" \n\t"
85	     ".machinemode \"zarch_nohighgprs\" \n\t"
86	     "lghi %%r0,16 \n\t"
87	     "mvcrl 0(%0),32(%0) \n\t"
88	     "vstrs %%v20,%%v20,%%v20,%%v20,0,2"
89	     : : "a" (buf) : "memory", "r0");
90}
91EOF
92dnl test, if assembler supports S390 arch13 instructions
93if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS --shared conftest.c
94			-o conftest.o &> /dev/null]) ;
95then
96  libc_cv_asm_s390_arch13=yes
97else
98  libc_cv_asm_s390_arch13=no
99fi
100rm -f conftest* ])
101if test "$libc_cv_asm_s390_arch13" = yes ;
102then
103  AC_DEFINE(HAVE_S390_ARCH13_ASM_SUPPORT)
104fi
105
106
107AC_CACHE_CHECK(for S390 z10 zarch instruction support as default,
108	       libc_cv_asm_s390_min_z10_zarch, [dnl
109cat > conftest.c <<\EOF
110void testinsn (void *a, void *b, int n)
111{
112    __asm__ ("exrl %2,1f \n\t"
113	     "j 2f \n\t"
114	     "1: mvc 0(1,%0),0(%1) \n\t"
115	     "2:"
116	     : : "a" (a), "a" (b), "d" (n)
117	     : "memory", "cc");
118}
119EOF
120dnl
121dnl test, if assembler supports S390 z10 zarch instructions as default
122if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS --shared conftest.c
123			-o conftest.o &> /dev/null]) ;
124then
125  libc_cv_asm_s390_min_z10_zarch=yes
126else
127  libc_cv_asm_s390_min_z10_zarch=no
128fi
129rm -f conftest* ])
130
131if test "$libc_cv_asm_s390_min_z10_zarch" = yes ;
132then
133  AC_DEFINE(HAVE_S390_MIN_Z10_ZARCH_ASM_SUPPORT)
134fi
135
136AC_CACHE_CHECK(for S390 z196 zarch instruction support as default,
137	       libc_cv_asm_s390_min_z196_zarch, [dnl
138cat > conftest.c <<\EOF
139float testinsn (double e)
140{
141    float d;
142    __asm__ ("ledbra %0,5,%1,4" : "=f" (d) : "f" (e) );
143    return d;
144}
145EOF
146dnl
147dnl test, if assembler supports S390 z196 zarch instructions as default
148if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS --shared conftest.c
149			-o conftest.o &> /dev/null]) ;
150then
151  libc_cv_asm_s390_min_z196_zarch=yes
152else
153  libc_cv_asm_s390_min_z196_zarch=no
154fi
155rm -f conftest* ])
156
157if test "$libc_cv_asm_s390_min_z196_zarch" = yes ;
158then
159  AC_DEFINE(HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT)
160fi
161
162AC_CACHE_CHECK(for S390 z13 zarch instruction support as default,
163	       libc_cv_asm_s390_min_z13_zarch, [dnl
164cat > conftest.c <<\EOF
165int testinsn (void)
166{
167    int i;
168    __asm__ ("vl %%v16,0(%%r15)\n\t"
169	     "vlgvf %0,%%v16,0"
170	     : "=d" (i) : : "memory", "v16");
171    return i;
172}
173EOF
174dnl
175dnl test, if assembler supports S390 z13 zarch instructions as default
176if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS --shared conftest.c
177			-o conftest.o &> /dev/null]) ;
178then
179  libc_cv_asm_s390_min_z13_zarch=yes
180else
181  libc_cv_asm_s390_min_z13_zarch=no
182fi
183rm -f conftest* ])
184
185if test "$libc_cv_asm_s390_min_z13_zarch" = yes ;
186then
187  AC_DEFINE(HAVE_S390_MIN_Z13_ZARCH_ASM_SUPPORT)
188fi
189
190AC_CACHE_CHECK(for S390 arch13 zarch instruction support as default,
191	       libc_cv_asm_s390_min_arch13_zarch, [dnl
192cat > conftest.c <<\EOF
193void testinsn (char *buf)
194{
195    __asm__ ("lghi %%r0,16 \n\t"
196	     "mvcrl 0(%0),32(%0) \n\t"
197	     "vstrs %%v20,%%v20,%%v20,%%v20,0,2"
198	     : : "a" (buf) : "memory", "r0");
199}
200EOF
201dnl test, if assembler supports S390 arch13 zarch instructions as default
202if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS --shared conftest.c
203			-o conftest.o &> /dev/null]) ;
204then
205  libc_cv_asm_s390_min_arch13_zarch=yes
206else
207  libc_cv_asm_s390_min_arch13_zarch=no
208fi
209rm -f conftest* ])
210if test "$libc_cv_asm_s390_min_arch13_zarch" = yes ;
211then
212  AC_DEFINE(HAVE_S390_MIN_ARCH13_ZARCH_ASM_SUPPORT)
213fi
214
215dnl test if GCC is new enough. See gcc "Bug 98269 - gcc 6.5.0
216dnl __builtin_add_overflow() with small uint32_t values incorrectly detects
217dnl overflow
218dnl (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98269)
219AC_CACHE_CHECK([if $CC is sufficient to build libc on s390x],
220libc_cv_compiler_ok_on_s390x, [
221AC_PREPROC_IFELSE([AC_LANG_PROGRAM([[]], [[
222#if !defined __GNUC__ || __GNUC__ < 7 || (__GNUC__ == 7 && __GNUC_MINOR__ < 1)
223#error insufficient compiler for building on s390x
224#endif
225]])],
226	[libc_cv_compiler_ok_on_s390x=yes],
227	[libc_cv_compiler_ok_on_s390x=no])])
228if test "$libc_cv_compiler_ok_on_s390x" != yes; then
229   critic_missing="$critic_missing On s390x, GCC >= 7.1.0 is required."
230fi
231
232test -n "$critic_missing" && AC_MSG_ERROR([
233*** $critic_missing])
234