1 # intparam.m4 serial 4 -*- Autoconf -*-
2 dnl Copyright (C) 1993-2008, 2017, 2020 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 dnl From Bruno Haible, Sam Steingold
9 AC_DEFUN([CL_INTPARAM_CROSS],
11 AC_REQUIRE([AC_C_BIGENDIAN])
14 CL_INTPARAM_BITSIZE([signed char], [char_bitsize])
15 CL_INTPARAM_BITSIZE([short], [short_bitsize])
16 CL_INTPARAM_BITSIZE([int], [int_bitsize])
17 CL_INTPARAM_BITSIZE([long], [long_bitsize])
18 CL_INTPARAM_BITSIZE([long long], [longlong_bitsize])
19 CL_INTPARAM_BITSIZE([unsigned char], [uchar_bitsize])
20 CL_INTPARAM_BITSIZE([unsigned short], [ushort_bitsize])
21 CL_INTPARAM_BITSIZE([unsigned int], [uint_bitsize])
22 CL_INTPARAM_BITSIZE([unsigned long], [ulong_bitsize])
23 CL_INTPARAM_BITSIZE([unsigned long long], [ulonglong_bitsize])
24 if test -n "$char_bitsize"; then
25 echo "/* Integers of type char have $char_bitsize bits. */"
26 echo "#define char_bitsize $char_bitsize"
29 echo "#error \"Integers of type char have no binary representation!!\""
31 if test -n "$short_bitsize"; then
32 echo "/* Integers of type short have $short_bitsize bits. */"
33 echo "#define short_bitsize $short_bitsize"
36 echo "#error \"Integers of type short have no binary representation!!\""
38 if test -n "$int_bitsize"; then
39 echo "/* Integers of type int have $int_bitsize bits. */"
40 echo "#define int_bitsize $int_bitsize"
43 echo "#error \"Integers of type int have no binary representation!!\""
45 if test -n "$long_bitsize"; then
46 echo "/* Integers of type long have $long_bitsize bits. */"
47 echo "#define long_bitsize $long_bitsize"
50 echo "#error \"Integers of type long have no binary representation!!\""
52 if test -n "$longlong_bitsize"; then
53 echo "/* Integers of type long long have $longlong_bitsize bits. */"
54 echo "#define long_long_bitsize $longlong_bitsize"
57 echo "#error \"Integers of type long long have no binary representation!!\""
59 if test -n "$uchar_bitsize"; then
60 echo "/* Integers of type unsigned char have $uchar_bitsize bits. */"
63 echo "#error \"Integers of type unsigned char have no binary representation!!\""
65 if test -n "$ushort_bitsize"; then
66 echo "/* Integers of type unsigned short have $ushort_bitsize bits. */"
69 echo "#error \"Integers of type unsigned short have no binary representation!!\""
71 if test -n "$uint_bitsize"; then
72 echo "/* Integers of type unsigned int have $uint_bitsize bits. */"
75 echo "#error \"Integers of type unsigned int have no binary representation!!\""
77 if test -n "$ulong_bitsize"; then
78 echo "/* Integers of type unsigned long have $ulong_bitsize bits. */"
81 echo "#error \"Integers of type unsigned long have no binary representation!!\""
83 if test -n "$ulonglong_bitsize"; then
84 echo "/* Integers of type unsigned long long have $ulonglong_bitsize bits. */"
87 echo "#error \"Integers of type unsigned long long have no binary representation!!\""
89 if test "$char_bitsize" != "$uchar_bitsize"; then
90 echo "#error \"Integer types char and unsigned char have different sizes!!\""
92 if test "$short_bitsize" != "$ushort_bitsize"; then
93 echo "#error \"Integer types short and unsigned short have different sizes!!\""
95 if test "$int_bitsize" != "$uint_bitsize"; then
96 echo "#error \"Integer types int and unsigned int have different sizes!!\""
98 if test "$long_bitsize" != "$ulong_bitsize"; then
99 echo "#error \"Integer types long and unsigned long have different sizes!!\""
101 if test "$longlong_bitsize" != "$ulonglong_bitsize"; then
102 echo "#error \"Integer types long long and unsigned long long have different sizes!!\""
104 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdint.h>]],
105 [[typedef int verify[2*(sizeof(char*)<=sizeof (intptr_t))-1];]])],
106 [], [echo "#error \"Type char * does not fit into an intptr_t!!\""])
107 _AC_COMPUTE_INT([sizeof (char *)], [pointer_size])
108 pointer_bitsize=`expr $pointer_size '*' $char_bitsize`
109 echo "/* Pointers of type char * have $pointer_bitsize bits. */"
110 echo "#define pointer_bitsize $pointer_bitsize"
112 CL_INTPARAM_SIZEOF([char], [sizeof_char])
113 CL_INTPARAM_ALIGNOF([char], [alignment_char])
114 echo "/* Type char has sizeof = $sizeof_char and alignment = $alignment_char. */"
115 echo "#define sizeof_char $sizeof_char"
116 echo "#define alignment_char $alignment_char"
118 CL_INTPARAM_SIZEOF([unsigned char], [sizeof_uchar])
119 CL_INTPARAM_ALIGNOF([unsigned char], [alignment_uchar])
120 echo "/* Type unsigned char has sizeof = $sizeof_uchar and alignment = $alignment_uchar. */"
122 CL_INTPARAM_SIZEOF([short], [sizeof_short])
123 CL_INTPARAM_ALIGNOF([short], [alignment_short])
124 echo "/* Type short has sizeof = $sizeof_short and alignment = $alignment_short. */"
125 echo "#define sizeof_short $sizeof_short"
126 echo "#define alignment_short $alignment_short"
128 CL_INTPARAM_SIZEOF([unsigned short], [sizeof_ushort])
129 CL_INTPARAM_ALIGNOF([unsigned short], [alignment_ushort])
130 echo "/* Type unsigned short has sizeof = $sizeof_ushort and alignment = $alignment_ushort. */"
132 CL_INTPARAM_SIZEOF([int], [sizeof_int])
133 CL_INTPARAM_ALIGNOF([int], [alignment_int])
134 echo "/* Type int has sizeof = $sizeof_int and alignment = $alignment_int. */"
135 echo "#define sizeof_int $sizeof_int"
136 echo "#define alignment_int $alignment_int"
138 CL_INTPARAM_SIZEOF([unsigned int], [sizeof_uint])
139 CL_INTPARAM_ALIGNOF([unsigned int], [alignment_uint])
140 echo "/* Type unsigned int has sizeof = $sizeof_uint and alignment = $alignment_uint. */"
142 CL_INTPARAM_SIZEOF([long], [sizeof_long])
143 CL_INTPARAM_ALIGNOF([long], [alignment_long])
144 echo "/* Type long has sizeof = $sizeof_long and alignment = $alignment_long. */"
145 echo "#define sizeof_long $sizeof_long"
146 echo "#define alignment_long $alignment_long"
148 CL_INTPARAM_SIZEOF([unsigned long], [sizeof_ulong])
149 CL_INTPARAM_ALIGNOF([unsigned long], [alignment_ulong])
150 echo "/* Type unsigned long has sizeof = $sizeof_ulong and alignment = $alignment_ulong. */"
152 CL_INTPARAM_SIZEOF([long long], [sizeof_longlong])
153 CL_INTPARAM_ALIGNOF([long long], [alignment_longlong])
154 echo "/* Type long long has sizeof = $sizeof_longlong and alignment = $alignment_longlong. */"
155 echo "#define sizeof_long_long $sizeof_longlong"
156 echo "#define alignment_long_long $alignment_longlong"
158 CL_INTPARAM_SIZEOF([unsigned long long], [sizeof_ulonglong])
159 CL_INTPARAM_ALIGNOF([unsigned long long], [alignment_ulonglong])
160 echo "/* Type unsigned long long has sizeof = $sizeof_ulonglong and alignment = $alignment_ulonglong. */"
162 CL_INTPARAM_SIZEOF([float], [sizeof_float])
163 CL_INTPARAM_ALIGNOF([float], [alignment_float])
164 echo "/* Type float has sizeof = $sizeof_float and alignment = $alignment_float. */"
165 echo "#define sizeof_float $sizeof_float"
166 echo "#define alignment_float $alignment_float"
168 CL_INTPARAM_SIZEOF([double], [sizeof_double])
169 CL_INTPARAM_ALIGNOF([double], [alignment_double])
170 echo "/* Type double has sizeof = $sizeof_double and alignment = $alignment_double. */"
171 echo "#define sizeof_double $sizeof_double"
172 echo "#define alignment_double $alignment_double"
174 CL_INTPARAM_SIZEOF([long double], [sizeof_longdouble])
175 CL_INTPARAM_ALIGNOF([long double], [alignment_longdouble])
176 echo "/* Type long double has sizeof = $sizeof_longdouble and alignment = $alignment_longdouble. */"
177 echo "#define sizeof_long_double $sizeof_longdouble"
178 echo "#define alignment_long_double $alignment_longdouble"
180 CL_INTPARAM_SIZEOF([char *], [sizeof_char_ptr])
181 CL_INTPARAM_ALIGNOF([char *], [alignment_char_ptr])
182 echo "/* Type char * has sizeof = $sizeof_char_ptr and alignment = $alignment_char_ptr. */"
184 CL_INTPARAM_SIZEOF([long *], [sizeof_long_ptr])
185 CL_INTPARAM_ALIGNOF([long *], [alignment_long_ptr])
186 echo "/* Type long * has sizeof = $sizeof_long_ptr and alignment = $alignment_long_ptr. */"
188 dnl disabled because:
189 dnl - the results of these are not used anywhere
190 dnl - the results of non-cross are not generated (see src/intparam.h)
191 dnl - the C code fails with "expected identifier or '(' before ')' token"
192 dnl on the line "typedef int verify[2*(alignof(void (*)(void)) == 256) - 1];"
193 dnl CL_INTPARAM_SIZEOF([void (*)(void)], [sizeof_function_ptr])
194 dnl CL_INTPARAM_ALIGNOF([void (*)(void)], [alignment_function_ptr])
195 echo "/* Type function * has sizeof = $sizeof_function_ptr and alignment = $alignment_function_ptr. */"
197 case $ac_cv_c_bigendian in
199 echo "/* Type unsigned short is stored BIG-ENDIAN in memory (i.e. like mc68000 or sparc). */"
200 echo "#define short_big_endian"
201 echo "/* Type unsigned int is stored BIG-ENDIAN in memory (i.e. like mc68000 or sparc). */"
202 echo "#define int_big_endian"
203 echo "/* Type unsigned long is stored BIG-ENDIAN in memory (i.e. like mc68000 or sparc). */"
204 echo "#define long_big_endian"
205 echo "/* Type unsigned long long is stored BIG-ENDIAN in memory (i.e. like mc68000 or sparc). */"
206 echo "#define long_long_big_endian"
209 echo "/* Type unsigned short is stored LITTLE-ENDIAN in memory (i.e. like Z80 or VAX). */"
210 echo "#define short_little_endian"
211 echo "/* Type unsigned int is stored LITTLE-ENDIAN in memory (i.e. like Z80 or VAX). */"
212 echo "#define int_little_endian"
213 echo "/* Type unsigned long is stored LITTLE-ENDIAN in memory (i.e. like Z80 or VAX). */"
214 echo "#define long_little_endian"
215 echo "/* Type unsigned long long is stored LITTLE-ENDIAN in memory (i.e. like Z80 or VAX). */"
216 echo "#define long_long_little_endian"
219 echo "#error \"Type short is stored in memory in an obscure manner!!\""
220 echo "#error \"Type int is stored in memory in an obscure manner!!\""
221 echo "#error \"Type long is stored in memory in an obscure manner!!\""
222 echo "#error \"Type long long is stored in memory in an obscure manner!!\""
228 echo "/* Stack grows up. */"
229 echo "#define stack_grows_up"
232 echo "/* Stack grows down. */"
233 echo "#define stack_grows_down"
236 } > "$cl_machine_file_h"
239 dnl CL_INTPARAM_BITSIZE(type, variable)
240 dnl puts into variable the determined bitsize of the type.
241 AC_DEFUN([CL_INTPARAM_BITSIZE],
245 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
246 [[typedef int verify[2*(($1)($x) == 0) - 1];]])],
248 [if test $n = 1000; then $2=; break; fi;])
249 n=`expr $n + 1`; x="$x * ($1)2"
253 dnl CL_INTPARAM_SIZEOF(type, variable)
254 dnl puts into variable the determined size of the type.
255 AC_DEFUN([CL_INTPARAM_SIZEOF],
257 _AC_COMPUTE_INT([sizeof($1)], [$2])
260 dnl CL_INTPARAM_ALIGNOF(type, variable)
261 dnl puts into variable the determined alignment of the type.
262 AC_DEFUN([CL_INTPARAM_ALIGNOF],[
263 dnl Simplify the guessing by assuming that the alignment is a power of 2.
271 #define alignof(type) __alignof__ (type)
273 template <class type> struct alignof_helper { char slot1; type slot2; };
274 #define alignof(type) offsetof (alignof_helper<type>, slot2)
277 #define alignof(type) offsetof (struct { char slot1; type slot2; }, slot2)
280 [[typedef int verify[2*(alignof($1) == $n) - 1];]])],
282 [if test $n = 0; then $2=; break; fi])