Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
let it work on solaris (test -e does not exist there, but test -x does)
[simgrid.git] / acmacro / gras_arch.m4
1 # BEGIN OF GRAS ARCH CHECK
2 dnl
3 dnl GRAS_DO_CHECK_SIZEOF: Get the size of a datatype (even in cross-compile)
4 dnl  1: type tested
5 dnl  2: extra include lines
6 dnl  3: extra sizes to test
7 dnl ("adapted" from openldap)
8 dnl
9 AC_DEFUN([GRAS_DO_CHECK_SIZEOF],
10 [changequote(<<, >>)dnl 
11  dnl The cache variable name (and of the result). 
12  define(<<GRAS_CHECK_SIZEOF_RES>>, translit(ac_cv_sizeof_$1, [ *()], [_pLR]))dnl
13  changequote([, ])dnl 
14  AC_CACHE_VAL(GRAS_CHECK_SIZEOF_RES, 
15  [for ac_size in 4 8 1 2 16 $3 ; do # List sizes in rough order of prevalence. 
16    AC_COMPILE_IFELSE(AC_LANG_PROGRAM([#include "confdefs.h" 
17    #include <sys/types.h> 
18    $2 
19    ], [switch (0) case 0: case (sizeof ($1) == $ac_size):;]), GRAS_CHECK_SIZEOF_RES=$ac_size) 
20    if test x$GRAS_CHECK_SIZEOF_RES != x ; then break; fi 
21   done 
22  ]) 
23 ])
24
25 dnl
26 dnl GRAS_CHECK_SIZEOF: Get the size of a datatype (even in cross-compile), with msg display, and define the result
27 dnl  1: type tested
28 dnl  2: extra include lines
29 dnl  3: extra sizes to test
30 dnl ("adapted" from openldap)
31 dnl
32 AC_DEFUN([GRAS_CHECK_SIZEOF],
33 [AC_MSG_CHECKING(size of $1) 
34 GRAS_DO_CHECK_SIZEOF($1,$2)
35 if test x$GRAS_CHECK_SIZEOF_RES = x ; then 
36   AC_MSG_ERROR([cannot determine a size for $1]) 
37 fi 
38 AC_MSG_RESULT($GRAS_CHECK_SIZEOF_RES) 
39 ])
40
41 dnl
42 dnl GRAS_TWO_COMPLIMENT([type]): Make sure the type is two-compliment
43 dnl warning, this does not work with char (quite logical)
44 dnl
45 AC_DEFUN([GRAS_TWO_COMPLIMENT],
46 [
47 AC_MSG_CHECKING(whether $1 is two-compliment)
48 AC_RUN_IFELSE([AC_LANG_PROGRAM([[#include "confdefs.h"
49 union {
50    signed $1 testInt;
51    unsigned char bytes[sizeof($1)];
52 } intTester;
53 ]],[[
54    intTester.testInt = -2;
55    return ((unsigned int)intTester.bytes[0] +
56            (unsigned int)intTester.bytes[sizeof($1) - 1]) - 509; /* should be 0 */
57 ]])], dnl end of AC LANG PROGRAM
58 [two_compliment=yes],[two_compliment=no] )dnl end of AC COMPILE IFELSE
59
60 AC_MSG_RESULT($two_compliment)
61 if test x$two_compliment != xyes ; then
62   AC_MSG_ERROR([GRAS works only two-compliment integers (yet)])
63 fi
64 ])
65
66 dnl
67 dnl GRAS_SIGNED_SIZEOF: Get the size of the datatype, and make sure that
68 dnl signed, unsigned and unspecified have the same size
69 dnl
70 AC_DEFUN([GRAS_SIGNED_SIZEOF],
71 [AC_MSG_CHECKING(size of $1)
72 GRAS_DO_CHECK_SIZEOF($1,$2)
73 unspecif=$GRAS_CHECK_SIZEOF_RES
74 if test x$unspecif = x ; then
75   AC_MSG_ERROR([cannot determine a size for $1]) 
76 fi 
77
78 GRAS_DO_CHECK_SIZEOF(signed $1,$2)
79 signed=$GRAS_CHECK_SIZEOF_RES
80 if test x$signed = x ; then
81   AC_MSG_ERROR([cannot determine a size for signed $1]) 
82 fi 
83 if test x$unspecif != x$signed ; then
84   AC_MSG_ERROR(['signed $1' and '$1' have different sizes ! ($signed != $unspecif)]) 
85 fi 
86
87 GRAS_DO_CHECK_SIZEOF(unsigned $1,$2)
88 unsigned=$GRAS_CHECK_SIZEOF_RES
89 if test x$unsigned = x ; then
90   AC_MSG_ERROR([cannot determine a size for unsigned $1]) 
91 fi 
92 if test x$unsigned != x$signed ; then
93   AC_MSG_ERROR(['signed $1' and 'unsigned $1' have different sizes ! ($signed != $unsigned)]) 
94 fi 
95
96 AC_MSG_RESULT($GRAS_CHECK_SIZEOF_RES) 
97 ])
98
99 dnl
100 dnl End of CHECK_SIGNED_SIZEOF
101 dnl
102
103 dnl CHECK_IEEE_FP: determines if floating points are IEEE754 compliant
104 dnl (inspired from NWS code)
105 dnl
106 AC_DEFUN([CHECK_IEEE_FP],
107 [AC_MSG_CHECKING(if floating point datatypes are IEEE 754 compliant) 
108 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include "confdefs.h"
109 union {
110         double testFP;
111         unsigned char bytes[sizeof(double)];
112 } doubleTester;
113 union {
114         float testFP;
115         unsigned char bytes[sizeof(float)];
116 } floatTester;
117 ]],[[
118 if (sizeof(double) != 8 || sizeof(float) != 4)
119    return 1;
120
121 memset(&doubleTester, 0, sizeof(doubleTester));
122 memset(&floatTester, 0, sizeof(floatTester));
123
124 doubleTester.bytes[GRAS_BIGENDIAN ? sizeof(double) - 1 : 0]=192;
125 doubleTester.bytes[GRAS_BIGENDIAN ? sizeof(double) - 2 : 1] =
126   (sizeof(double) == 4)  ? 128 :
127   (sizeof(double) == 8)  ? 16 :
128   (sizeof(double) == 16) ? 1 : 0;
129 if (doubleTester.testFP != -4.0) return 1;
130
131 floatTester.bytes[GRAS_BIGENDIAN ? sizeof(float) - 1 : 0]=192;
132 floatTester.bytes[GRAS_BIGENDIAN ? sizeof(float) - 2 : 1] =
133   (sizeof(float) == 4)  ? 128 :
134   (sizeof(float) == 8)  ? 16 :
135   (sizeof(float) == 16) ? 1 : 0;
136 if (floatTester.testFP != -4.0) return 1;]])],[IEEE_FP=yes],[IEEE_FP=no])
137 AC_MSG_RESULT($IEEE_FP)
138
139 if test x$IEEE_FP != xyes ; then
140    AC_MSG_ERROR([GRAS works only on IEEE754 compliant systems (yet)])
141 else
142    AC_DEFINE(IEEE_FP,1,[defines if this architecture floating point types are IEEE754 compliant])
143 fi
144 ])dnl end of CHECK_IEEE_FP
145
146
147
148 dnl *************************8
149 dnl 
150 AC_DEFUN([GRAS_ARCH],
151 [
152 # Check for the architecture
153 AC_C_BIGENDIAN(endian=1,endian=0,AC_MSG_ERROR([GRAS works only for little or big endian systems (yet)]))
154 dnl Make sure we don't run on a non-two-compliment arch, since we dunno convert them
155 GRAS_TWO_COMPLIMENT(int)
156 AC_DEFINE_UNQUOTED(GRAS_BIGENDIAN,$endian,[define if big endian])
157           
158 GRAS_SIGNED_SIZEOF(char)
159 GRAS_SIGNED_SIZEOF(short int)
160 GRAS_SIGNED_SIZEOF(int)
161 GRAS_SIGNED_SIZEOF(long int)
162 GRAS_SIGNED_SIZEOF(long long int)
163                                                                   
164
165 GRAS_CHECK_SIZEOF(void *)
166 GRAS_CHECK_SIZEOF(void (*) (void))
167                                                                   
168 GRAS_CHECK_SIZEOF(float)
169 GRAS_CHECK_SIZEOF(double)
170 CHECK_IEEE_FP
171
172 AC_MSG_CHECKING(the GRAS signature of this architecture)
173 if test x$endian = x1 ; then
174   trace_endian=B
175 else
176   trace_endian=l
177 fi
178 gras_arch=unknown
179 trace="$trace_endian"
180 trace="${trace}:${ac_cv_sizeof_char}.${ac_cv_sizeof_short_int}.${ac_cv_sizeof_int}.${ac_cv_sizeof_long_int}.${ac_cv_sizeof_long_long_int}"
181 trace="${trace}:${ac_cv_sizeof_void_p}.${ac_cv_sizeof_void_LpR_LvoidR}"
182 trace="${trace}:${ac_cv_sizeof_float}.${ac_cv_sizeof_double}"
183 case $trace in
184   l:1.2.4.4.8:4.4:4.8) gras_arch=0; gras_arch_name=little32;;
185   l:1.2.4.8.8:8.8:4.8) gras_arch=1; gras_arch_name=little64;;
186   B:1.2.4.4.8:4.4:4.8) gras_arch=2; gras_arch_name=big32;;
187   B:1.2.4.8.8:8.8:4.8) gras_arch=3; gras_arch_name=big64;;
188 esac
189 if test x$gras_arch = xunknown ; then
190   AC_MSG_RESULT([damnit ($trace)])
191   AC_MSG_ERROR([Impossible to determine the GRAS architecture signature.
192 Please report this architecture trace ($trace) and what it corresponds to.])
193 fi
194 echo "$as_me:$LINENO: GRAS trace of this machine: $trace" >&AS_MESSAGE_LOG_FD
195 AC_DEFINE_UNQUOTED(GRAS_THISARCH,$gras_arch,[defines the GRAS architecture signature of this machine])
196 AC_MSG_RESULT($gras_arch ($gras_arch_name))
197 ])
198 # END OF GRAS ARCH CHECK
199
200 AC_DEFUN([GRAS_CHECK_STRUCT_COMPACTION],
201 [  AC_MSG_CHECKING(whether the struct gets packed)
202    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include "confdefs.h" 
203         #include <sys/types.h>
204         #include <stddef.h> /* offsetof() */
205         struct s {char c; double d;}; 
206        ]],[[switch (0) 
207         case 0: 
208         case (sizeof(struct s) == sizeof(double)+sizeof(char)):;
209        ]])],[gras_struct_packed=yes],[gras_struct_packed="no (good)"])
210      
211    AC_MSG_RESULT($gras_struct_packed)
212    if test x$gras_struct_packed = xyes ; then
213      AC_MSG_ERROR([GRAS does not support packed structures since it leads to nasty misalignments])
214    fi
215    
216    AC_MSG_CHECKING(whether the struct gets compacted)
217    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include "confdefs.h" 
218         #include <sys/types.h>
219         #include <stddef.h> /* offsetof() */
220         struct s {double d; int i; char c;}; 
221        ]],[[switch (0) 
222         case 0: 
223         case (offsetof(struct s,c) == sizeof(double)+sizeof(int)):;
224        ]])],[gras_struct_compact=yes],[gras_struct_compact=no])
225      
226    AC_MSG_RESULT($gras_struct_compact)
227    
228    if test x$gras_struct_compact = xyes ; then
229      AC_DEFINE_UNQUOTED(GRAS_STRUCT_COMPACT, 1,
230           [Defined if structures are compacted when possible.
231           
232           Consider this structure: struct s {double d; int i; char c;}; 
233           
234           If it is allowed, the char is placed just after the int. If not,
235           it has to be on the 8 bytes boundary imposed by the double.
236           ])
237      AC_MSG_CHECKING(whether arrays in struct can straddle struct alignment boundaries)
238
239      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include "confdefs.h" 
240         #include <sys/types.h>
241         #include <stddef.h> /* offsetof() */
242         struct s { double d; int i; char c[6]; };
243        ]],[[switch (0) 
244         case 0: 
245         case (offsetof(struct s,c) == sizeof(double)+sizeof(int)):;
246        ]])],[gras_array_straddle_struct=yes],[gras_array_straddle_struct=no])
247        
248      AC_MSG_RESULT($gras_array_straddle_struct)
249
250      if test x$gras_array_straddle_struct = xyes ; then
251        AC_DEFINE_UNQUOTED(GRAS_ARRAY_STRADDLE_STRUCT, 1,
252             [Defined if arrays in struct can straddle struct alignment boundaries])
253      else
254        AC_MSG_ERROR([GRAS can only work on either architecture not compacting structures, or allowing array fields to straddle alignment boundaries (yet)])
255      fi
256   fi
257   
258   AC_MSG_CHECKING(for changing alignment boundary structures)
259    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include "confdefs.h" 
260         #include <sys/types.h>
261
262         struct s {int i;double d;};
263        ]],[[switch (0) 
264         case 0: 
265         case (sizeof(struct s) == sizeof(double)+sizeof(int)):;
266        ]])],[gras_struct_changing=yes],[gras_struct_changing=no])
267      
268    AC_MSG_RESULT($gras_struct_changing)
269    
270    if test x$gras_struct_changing = xyes ; then
271      AC_DEFINE_UNQUOTED(GRAS_STRUCT_CHANGING, 1,
272           [Defined if the alignment of structures can vary over fields.
273           
274            Consider the following structure:
275              struct s {
276                int i;
277                double d;
278              };
279              
280            On Solaris, sizeof(struct s)=16, ie all fields get aligned to the
281            biggest boundary (and this will not be defined). On Linux,
282            sizeof(struct s)=12 (and this will be defined).
283           ])
284    fi
285 ])
286 # END OF GRAS CHECK STRUCT COMPACTION
287
288 AC_DEFUN([GRAS_C_COMPACT_STRUCT],
289 [  AC_MSG_CHECKING(whether the struct gets compacted)
290    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include "confdefs.h" 
291         #include <sys/types.h>
292         #include <stddef.h> /* offsetof() */
293         struct s {double d; int a; int b;}; 
294        ]],[[switch (0) 
295         case 0: 
296         case (offsetof(struct s,b) == sizeof(double)+sizeof(int)):;
297        ]])],[gras_compact_struct=yes],[gras_compact_struct=no])
298      
299    AC_MSG_RESULT($gras_compact_struct)
300    
301    if test x$gras_compact_struct = xyes ; then
302      AC_DEFINE_UNQUOTED(GRAS_COMPACT_STRUCT, 1,
303           [Defined if structures are compacted when possible])
304    fi     
305 ])
306 # END OF GRAS COMPACT STRUCT