This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
metaconfig changes for #20881.
[metaconfig.git] / U / perl / perlxv.U
1 ?RCS: $Id: perlxv.U,v 1.1 2000/08/31 17:53:56 jhi Exp jhi $
2 ?RCS:
3 ?RCS: Copyright (c) 1999 Jarkko Hietaniemi
4 ?RCS:
5 ?RCS: You may distribute under the terms of either the GNU General Public
6 ?RCS: License or the Artistic License, as specified in the README file.
7 ?RCS:
8 ?MAKE:ivtype uvtype nvtype ivsize uvsize nvsize \
9         i8type u8type i16type u16type i32type u32type i64type u64type \
10         i8size u8size i16size u16size i32size u32size i64size u64size \
11         d_nv_preserves_uv nv_preserves_uv_bits: \
12         echo rm use64bitint d_quad quadtype uquadtype \
13         d_longdbl uselongdouble longdblsize doublesize \
14         charsize shortsize intsize longsize i_stdlib \
15         cat Compile i_inttypes test d_volatile signal_t run
16 ?MAKE:  -pick add $@ %<
17 ?S:ivtype:
18 ?S:     This variable contains the C type used for Perl's IV.
19 ?S:.
20 ?S:uvtype:
21 ?S:     This variable contains the C type used for Perl's UV.
22 ?S:.
23 ?S:nvtype:
24 ?S:     This variable contains the C type used for Perl's NV.
25 ?S:.
26 ?S:i8type:
27 ?S:     This variable contains the C type used for Perl's I8.
28 ?S:.
29 ?S:u8type:
30 ?S:     This variable contains the C type used for Perl's U8.
31 ?S:.
32 ?S:i16type:
33 ?S:     This variable contains the C type used for Perl's I16.
34 ?S:.
35 ?S:u16type:
36 ?S:     This variable contains the C type used for Perl's U16.
37 ?S:.
38 ?S:i32type:
39 ?S:     This variable contains the C type used for Perl's I32.
40 ?S:.
41 ?S:u32type:
42 ?S:     This variable contains the C type used for Perl's U32.
43 ?S:.
44 ?S:i64type:
45 ?S:     This variable contains the C type used for Perl's I64.
46 ?S:.
47 ?S:u64type:
48 ?S:     This variable contains the C type used for Perl's U64.
49 ?S:.
50 ?S:ivsize:
51 ?S:     This variable is the size of an IV in bytes.
52 ?S:.
53 ?S:uvsize:
54 ?S:     This variable is the size of a UV in bytes.
55 ?S:.
56 ?S:i8size:
57 ?S:     This variable is the size of an I8 in bytes.
58 ?S:.
59 ?S:u8size:
60 ?S:     This variable is the size of an U8 in bytes.
61 ?S:.
62 ?S:i16size:
63 ?S:     This variable is the size of an I16 in bytes.
64 ?S:.
65 ?S:u16size:
66 ?S:     This variable is the size of an U16 in bytes.
67 ?S:.
68 ?S:i32size:
69 ?S:     This variable is the size of an I32 in bytes.
70 ?S:.
71 ?S:u32size:
72 ?S:     This variable is the size of an U32 in bytes.
73 ?S:.
74 ?S:i64size:
75 ?S:     This variable is the size of an I64 in bytes.
76 ?S:.
77 ?S:u64size:
78 ?S:     This variable is the size of an U64 in bytes.
79 ?S:.
80 ?S:nvsize:
81 ?S:     This variable is the size of an NV in bytes.
82 ?S:.
83 ?S:d_nv_preserves_uv:
84 ?S:     This variable indicates whether a variable of type nvtype
85 ?S:     can preserve all the bits a variable of type uvtype.
86 ?S:.
87 ?S:nv_preserves_uv_bits:
88 ?S:     This variable indicates how many of bits type uvtype
89 ?S:     a variable nvtype can preserve.
90 ?S:.
91 ?C:IVTYPE:
92 ?C:     This symbol defines the C type used for Perl's IV.
93 ?C:.
94 ?C:UVTYPE:
95 ?C:     This symbol defines the C type used for Perl's UV.
96 ?C:.
97 ?C:I8TYPE:
98 ?C:     This symbol defines the C type used for Perl's I8.
99 ?C:.
100 ?C:U8TYPE:
101 ?C:     This symbol defines the C type used for Perl's U8.
102 ?C:.
103 ?C:I16TYPE:
104 ?C:     This symbol defines the C type used for Perl's I16.
105 ?C:.
106 ?C:U16TYPE:
107 ?C:     This symbol defines the C type used for Perl's U16.
108 ?C:.
109 ?C:I32TYPE:
110 ?C:     This symbol defines the C type used for Perl's I32.
111 ?C:.
112 ?C:U32TYPE:
113 ?C:     This symbol defines the C type used for Perl's U32.
114 ?C:.
115 ?C:I64TYPE:
116 ?C:     This symbol defines the C type used for Perl's I64.
117 ?C:.
118 ?C:U64TYPE:
119 ?C:     This symbol defines the C type used for Perl's U64.
120 ?C:.
121 ?C:NVTYPE:
122 ?C:     This symbol defines the C type used for Perl's NV.
123 ?C:.
124 ?C:IVSIZE:
125 ?C:     This symbol contains the sizeof(IV).
126 ?C:.
127 ?C:UVSIZE:
128 ?C:     This symbol contains the sizeof(UV).
129 ?C:.
130 ?C:I8SIZE:
131 ?C:     This symbol contains the sizeof(I8).
132 ?C:.
133 ?C:U8SIZE:
134 ?C:     This symbol contains the sizeof(U8).
135 ?C:.
136 ?C:I16SIZE:
137 ?C:     This symbol contains the sizeof(I16).
138 ?C:.
139 ?C:U16SIZE:
140 ?C:     This symbol contains the sizeof(U16).
141 ?C:.
142 ?C:I32SIZE:
143 ?C:     This symbol contains the sizeof(I32).
144 ?C:.
145 ?C:U32SIZE:
146 ?C:     This symbol contains the sizeof(U32).
147 ?C:.
148 ?C:I64SIZE:
149 ?C:     This symbol contains the sizeof(I64).
150 ?C:.
151 ?C:U64SIZE:
152 ?C:     This symbol contains the sizeof(U64).
153 ?C:.
154 ?C:NVSIZE:
155 ?C:     This symbol contains the sizeof(NV).
156 ?C:.
157 ?C:NV_PRESERVES_UV:
158 ?C:     This symbol, if defined, indicates that a variable of type NVTYPE
159 ?C:     can preserve all the bits of a variable of type UVTYPE.
160 ?C:.
161 ?C:NV_PRESERVES_UV_BITS:
162 ?C:     This symbol contains the number of bits a variable of type NVTYPE
163 ?C:     can preserve of a variable of type UVTYPE.
164 ?C:.
165 ?H:#define      IVTYPE          $ivtype         /**/
166 ?H:#define      UVTYPE          $uvtype         /**/
167 ?H:#define      I8TYPE          $i8type         /**/
168 ?H:#define      U8TYPE          $u8type         /**/
169 ?H:#define      I16TYPE         $i16type        /**/
170 ?H:#define      U16TYPE         $u16type        /**/
171 ?H:#define      I32TYPE         $i32type        /**/
172 ?H:#define      U32TYPE         $u32type        /**/
173 ?H:?%<:#ifdef HAS_QUAD
174 ?H:?%<:#define  I64TYPE         $i64type        /**/
175 ?H:?%<:#define  U64TYPE         $u64type        /**/
176 ?H:?%<:#endif
177 ?H:#define      NVTYPE          $nvtype         /**/
178 ?H:#define      IVSIZE          $ivsize         /**/
179 ?H:#define      UVSIZE          $uvsize         /**/
180 ?H:#define      I8SIZE          $i8size         /**/
181 ?H:#define      U8SIZE          $u8size         /**/
182 ?H:#define      I16SIZE         $i16size        /**/
183 ?H:#define      U16SIZE         $u16size        /**/
184 ?H:#define      I32SIZE         $i32size        /**/
185 ?H:#define      U32SIZE         $u32size        /**/
186 ?H:?%<:#ifdef HAS_QUAD
187 ?H:?%<:#define  I64SIZE         $i64size        /**/
188 ?H:?%<:#define  U64SIZE         $u64size        /**/
189 ?H:?%<:#endif
190 ?H:#define      NVSIZE          $nvsize         /**/
191 ?H:#$d_nv_preserves_uv  NV_PRESERVES_UV
192 ?H:#define      NV_PRESERVES_UV_BITS    $nv_preserves_uv_bits
193 ?H:?%<:#if UVSIZE == 8
194 ?H:?%<:#   ifdef BYTEORDER
195 ?H:?%<:#       if BYTEORDER == 0x1234
196 ?H:?%<:#           undef BYTEORDER
197 ?H:?%<:#           define BYTEORDER 0x12345678
198 ?H:?%<:#       else
199 ?H:?%<:#           if BYTEORDER == 0x4321
200 ?H:?%<:#               undef BYTEORDER
201 ?H:?%<:#               define BYTEORDER 0x87654321
202 ?H:?%<:#           endif
203 ?H:?%<:#       endif
204 ?H:?%<:#   endif
205 ?H:?%<:#endif
206 ?H:.
207 ?T:volatile
208
209 echo " "
210 $echo "Choosing the C types to be used for Perl's internal types..." >&4
211
212 case "$use64bitint:$d_quad:$quadtype" in
213 define:define:?*)
214         ivtype="$quadtype"
215         uvtype="$uquadtype"
216         ivsize=8
217         uvsize=8
218         ;;
219 *)      ivtype="long"
220         uvtype="unsigned long"
221         ivsize=$longsize
222         uvsize=$longsize
223         ;;
224 esac
225
226 case "$uselongdouble:$d_longdbl" in
227 define:define)
228         nvtype="long double"
229         nvsize=$longdblsize
230         ;;
231 *)      nvtype=double
232         nvsize=$doublesize
233         ;;
234 esac
235
236 $echo "(IV will be "$ivtype", $ivsize bytes)"
237 $echo "(UV will be "$uvtype", $uvsize bytes)"
238 $echo "(NV will be "$nvtype", $nvsize bytes)"
239
240 $cat >try.c <<EOCP
241 #$i_inttypes I_INTTYPES
242 #ifdef I_INTTYPES
243 #include <inttypes.h>
244 #endif
245 #include <stdio.h>
246 int main() {
247 #ifdef INT8
248    int8_t i =  INT8_MAX;
249   uint8_t u = UINT8_MAX;
250   printf("int8_t\n");
251 #endif
252 #ifdef INT16
253    int16_t i =  INT16_MAX;
254   uint16_t i = UINT16_MAX;
255   printf("int16_t\n");
256 #endif
257 #ifdef INT32
258    int32_t i =  INT32_MAX;
259   uint32_t u = UINT32_MAX;
260   printf("int32_t\n");
261 #endif
262 }
263 EOCP
264
265 case "$i8type" in
266 '')     case "$charsize" in
267         1)      i8type=char
268                 u8type="unsigned char"
269                 i8size=$charsize
270                 u8size=$charsize
271                 ;;
272         esac
273         ;;
274 esac
275 case "$i8type" in
276 '')     set try -DINT8
277         if eval $compile; then
278                 case "`$run ./try`" in
279                 int8_t) i8type=int8_t
280                         u8type=uint8_t
281                         i8size=1
282                         u8size=1
283                         ;;
284                 esac
285         fi
286         ;;
287 esac
288 case "$i8type" in
289 '')     if $test $charsize -ge 1; then
290                 i8type=char
291                 u8type="unsigned char"
292                 i8size=$charsize
293                 u8size=$charsize
294         fi
295         ;;
296 esac
297
298 case "$i16type" in
299 '')     case "$shortsize" in
300         2)      i16type=short
301                 u16type="unsigned short"
302                 i16size=$shortsize
303                 u16size=$shortsize
304                 ;;
305         esac
306         ;;
307 esac
308 case "$i16type" in
309 '')     set try -DINT16
310         if eval $compile; then
311                 case "`$run ./try`" in
312                 int16_t)
313                         i16type=int16_t
314                         u16type=uint16_t
315                         i16size=2
316                         u16size=2
317                         ;;
318                 esac
319         fi
320         ;;
321 esac
322 case "$i16type" in
323 '')     if $test $shortsize -ge 2; then
324                 i16type=short
325                 u16type="unsigned short"
326                 i16size=$shortsize
327                 u16size=$shortsize
328         fi
329         ;;
330 esac
331
332 case "$i32type" in
333 '')     case "$longsize" in
334         4)      i32type=long
335                 u32type="unsigned long"
336                 i32size=$longsize
337                 u32size=$longsize
338                 ;;
339         *)      case "$intsize" in
340                 4)      i32type=int
341                         u32type="unsigned int"
342                         i32size=$intsize
343                         u32size=$intsize
344                         ;;
345                 esac
346                 ;;
347         esac
348         ;;
349 esac
350 case "$i32type" in
351 '')     set try -DINT32
352         if eval $compile; then
353                 case "`$run ./try`" in
354                 int32_t)
355                         i32type=int32_t
356                         u32type=uint32_t
357                         i32size=4
358                         u32size=4
359                         ;;
360                 esac
361         fi
362         ;;
363 esac
364 case "$i32type" in
365 '')     if $test $intsize -ge 4; then
366                 i32type=int
367                 u32type="unsigned int"
368                 i32size=$intsize
369                 u32size=$intsize
370         fi
371         ;;
372 esac
373
374 case "$i64type" in
375 '')     case "$d_quad:$quadtype" in
376         define:?*)
377                 i64type="$quadtype"
378                 u64type="$uquadtype"
379                 i64size=8
380                 u64size=8
381                 ;;
382         esac
383         ;;
384 esac
385
386 $echo "Checking how many bits of your UVs your NVs can preserve..." >&4
387 : volatile so that the compiler has to store it out to memory.
388 if test X"$d_volatile" = X"$define"; then
389         volatile=volatile
390 fi
391 $cat <<EOP >try.c
392 #include <stdio.h>
393 #$i_stdlib I_STDLIB
394 #ifdef I_STDLIB
395 #include <stdlib.h>
396 #endif
397 #include <sys/types.h>
398 #include <signal.h>
399 #ifdef SIGFPE
400 $volatile int bletched = 0;
401 $signal_t blech(s) int s; { bletched = 1; }
402 #endif
403 int main() {
404     $uvtype u = 0;
405     $nvtype d;
406     int     n = 8 * $uvsize;
407     int     i;
408 #ifdef SIGFPE
409     signal(SIGFPE, blech);
410 #endif
411
412     for (i = 0; i < n; i++) {
413       u = u << 1 | ($uvtype)1;
414       d = ($nvtype)u;
415       if (($uvtype)d != u)
416         break;
417       if (d <= 0)
418         break;
419       d = ($nvtype)(u - 1);
420       if (($uvtype)d != (u - 1))
421         break;
422 #ifdef SIGFPE
423       if (bletched) {
424         break;
425 #endif
426       } 
427     }
428     printf("%d\n", ((i == n) ? -n : i));
429     exit(0);
430 }
431 EOP
432 set try
433
434 d_nv_preserves_uv="$undef"
435 if eval $compile; then
436         nv_preserves_uv_bits="`$run ./try`"
437 fi
438 case "$nv_preserves_uv_bits" in
439 \-[1-9]*)       
440         nv_preserves_uv_bits=`expr 0 - $nv_preserves_uv_bits`
441         $echo "Your NVs can preserve all $nv_preserves_uv_bits bits of your UVs."  2>&1
442         d_nv_preserves_uv="$define"
443         ;;
444 [1-9]*) $echo "Your NVs can preserve only $nv_preserves_uv_bits bits of your UVs."  2>&1
445         d_nv_preserves_uv="$undef" ;;
446 *)      $echo "Can't figure out how many bits your NVs preserve." 2>&1
447         nv_preserves_uv_bits="$undef" ;;
448 esac
449
450 $rm -f try.* try
451