1dnl A function to check for the possibility to control the FPU.
2dnl Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
3dnl Copyright (C) 2010-2016 BUGSENG srl (http://bugseng.com)
4dnl
5dnl This file is part of the Parma Polyhedra Library (PPL).
6dnl
7dnl The PPL is free software; you can redistribute it and/or modify it
8dnl under the terms of the GNU General Public License as published by the
9dnl Free Software Foundation; either version 3 of the License, or (at your
10dnl option) any later version.
11dnl
12dnl The PPL is distributed in the hope that it will be useful, but WITHOUT
13dnl ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14dnl FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15dnl for more details.
16dnl
17dnl You should have received a copy of the GNU General Public License
18dnl along with this program; if not, write to the Free Software Foundation,
19dnl Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
20dnl
21dnl For the most up-to-date information see the Parma Polyhedra Library
22dnl site: http://bugseng.com/products/ppl/ .
23
24AC_DEFUN([AC_CHECK_FPU_CONTROL],
25[
26AC_LANG_PUSH(C++)
27AC_CHECK_HEADERS([fenv.h ieeefp.h])
28AC_MSG_CHECKING([if it is possible to control the FPU])
29AC_RUN_IFELSE([AC_LANG_SOURCE([[
30#if i386
31
32int
33main() {
34  return 0;
35}
36
37#elif defined(HAVE_FENV_H)
38
39# include <fenv.h>
40
41# if !defined(FE_UPWARD) || !defined(FE_DOWNWARD)
42
43  choke me
44
45# elif defined(__arm__) \
46  && (!defined(PPL_ARM_CAN_CONTROL_FPU) || !PPL_ARM_CAN_CONTROL_FPU)
47
48  choke me
49
50#else
51
52     float  nf1 =  -3, pf1 = 3,  f2 =  5;
53     double nd1 =  -7, pd1 = 7,  d2 = 11;
54long double nl1 = -13, pl1 = 13, l2 = 17;
55
56      float nf[2], pf[2];
57     double nd[2], pd[2];
58long double nl[2], pl[2];
59
60int
61ppl_check_function() {
62  int r = 0;
63  if (nf[0] == nf[1] || pf[0] == pf[1] || -nf[0] != pf[1] || -nf[1] != pf[0])
64    r |= 1;
65  if (nd[0] == nd[1] || pd[0] == pd[1] || -nd[0] != pd[1] || -nd[1] != pd[0])
66    r |= 2;
67  if (nl[0] == nl[1] || pl[0] == pl[1] || -nl[0] != pl[1] || -nl[1] != pl[0])
68    r |= 4;
69  return r;
70}
71
72int
73ppl_setround_function(int rounding_mode) {
74  return fesetround(rounding_mode);
75}
76
77int (* volatile ppl_check_function_p)() = ppl_check_function;
78int (* volatile ppl_setround_function_p)(int) = ppl_setround_function;
79
80int
81main() {
82  if ((*ppl_setround_function_p)(FE_DOWNWARD) != 0)
83    return 255;
84
85  nf[0] = nf1 / f2;
86  nd[0] = nd1 / d2;
87  nl[0] = nl1 / l2;
88  pf[0] = pf1 / f2;
89  pd[0] = pd1 / d2;
90  pl[0] = pl1 / l2;
91
92  if ((*ppl_setround_function_p)(FE_UPWARD) != 0)
93    return 255;
94
95  nf[1] = nf1 / f2;
96  nd[1] = nd1 / d2;
97  nl[1] = nl1 / l2;
98  pf[1] = pf1 / f2;
99  pd[1] = pd1 / d2;
100  pl[1] = pl1 / l2;
101
102  return (*ppl_check_function_p)();
103}
104
105# endif
106
107#elif sparc && defined(HAVE_IEEEFP_H)
108
109int
110main() {
111  return 0;
112}
113
114#else
115
116  choke me
117
118#endif
119]])],
120  AC_MSG_RESULT(yes)
121  ac_cv_can_control_fpu=1,
122  AC_MSG_RESULT(no)
123  ac_cv_can_control_fpu=0,
124  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
125#if i386 || (sparc && defined(HAVE_IEEEFP_H))
126
127int
128main() {
129  return 0;
130}
131
132#else
133
134  choke me
135
136#endif
137  ]])],
138    AC_MSG_RESULT(yes)
139    ac_cv_can_control_fpu=1,
140    AC_MSG_RESULT(no)
141    ac_cv_can_control_fpu=0
142  )
143)
144AC_LANG_POP(C++)
145])
146