This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Part 2 of a big cleanup action based on the upcoming dist-4.0
[metaconfig.git] / U / perl / perlxv.U
CommitLineData
6cadf241 1?RCS: $Id: perlxv.U,v 1.1 2000/08/31 17:53:56 jhi Exp jhi $
b4d5f732
JH
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 \
d7ef793b 10 i8size u8size i16size u16size i32size u32size i64size u64size \
913e5e82 11 d_nv_preserves_uv nv_preserves_uv_bits d_nv_zero_is_allbits_zero: \
2cb64bf6 12 echo rm_try use64bitint d_quad quadtype uquadtype \
b4d5f732 13 d_longdbl uselongdouble longdblsize doublesize \
5107cfb0 14 shortsize intsize longsize i_stdlib i_string \
0f00356b 15 cat Compile i_inttypes test d_volatile signal_t run
b4d5f732
JH
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:.
ebebf7f4 83?S:d_nv_preserves_uv:
d7ef793b
JH
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:.
2c06d0fa 87?S:nv_preserves_uv_bits:
31ebece7
JH
88?S: This variable indicates how many of bits type uvtype
89?S: a variable nvtype can preserve.
90?S:.
913e5e82
MB
91?S:d_nv_zero_is_allbits_zero:
92?S: This variable indicates whether a variable of type nvtype
93?S: stores 0.0 in memory as all bits zero.
94?S:.
b4d5f732
JH
95?C:IVTYPE:
96?C: This symbol defines the C type used for Perl's IV.
97?C:.
98?C:UVTYPE:
99?C: This symbol defines the C type used for Perl's UV.
100?C:.
101?C:I8TYPE:
102?C: This symbol defines the C type used for Perl's I8.
103?C:.
104?C:U8TYPE:
105?C: This symbol defines the C type used for Perl's U8.
106?C:.
107?C:I16TYPE:
108?C: This symbol defines the C type used for Perl's I16.
109?C:.
110?C:U16TYPE:
111?C: This symbol defines the C type used for Perl's U16.
112?C:.
113?C:I32TYPE:
114?C: This symbol defines the C type used for Perl's I32.
115?C:.
116?C:U32TYPE:
117?C: This symbol defines the C type used for Perl's U32.
118?C:.
119?C:I64TYPE:
120?C: This symbol defines the C type used for Perl's I64.
121?C:.
122?C:U64TYPE:
123?C: This symbol defines the C type used for Perl's U64.
124?C:.
125?C:NVTYPE:
126?C: This symbol defines the C type used for Perl's NV.
127?C:.
128?C:IVSIZE:
129?C: This symbol contains the sizeof(IV).
130?C:.
131?C:UVSIZE:
132?C: This symbol contains the sizeof(UV).
133?C:.
134?C:I8SIZE:
135?C: This symbol contains the sizeof(I8).
136?C:.
137?C:U8SIZE:
138?C: This symbol contains the sizeof(U8).
139?C:.
140?C:I16SIZE:
141?C: This symbol contains the sizeof(I16).
142?C:.
143?C:U16SIZE:
144?C: This symbol contains the sizeof(U16).
145?C:.
146?C:I32SIZE:
147?C: This symbol contains the sizeof(I32).
148?C:.
149?C:U32SIZE:
150?C: This symbol contains the sizeof(U32).
151?C:.
152?C:I64SIZE:
153?C: This symbol contains the sizeof(I64).
154?C:.
155?C:U64SIZE:
156?C: This symbol contains the sizeof(U64).
157?C:.
158?C:NVSIZE:
159?C: This symbol contains the sizeof(NV).
160?C:.
d7ef793b
JH
161?C:NV_PRESERVES_UV:
162?C: This symbol, if defined, indicates that a variable of type NVTYPE
31ebece7
JH
163?C: can preserve all the bits of a variable of type UVTYPE.
164?C:.
846df602 165?C:NV_PRESERVES_UV_BITS:
31ebece7
JH
166?C: This symbol contains the number of bits a variable of type NVTYPE
167?C: can preserve of a variable of type UVTYPE.
d7ef793b 168?C:.
913e5e82
MB
169?C:NV_ZERO_IS_ALLBITS_ZERO:
170?C: This symbol, if defined, indicates that a variable of type NVTYPE
171?C: stores 0.0 in memory as all bits zero.
172?C:.
b4d5f732
JH
173?H:#define IVTYPE $ivtype /**/
174?H:#define UVTYPE $uvtype /**/
175?H:#define I8TYPE $i8type /**/
176?H:#define U8TYPE $u8type /**/
177?H:#define I16TYPE $i16type /**/
178?H:#define U16TYPE $u16type /**/
179?H:#define I32TYPE $i32type /**/
180?H:#define U32TYPE $u32type /**/
500277eb 181?H:?%<:#ifdef HAS_QUAD
b4d5f732
JH
182?H:?%<:#define I64TYPE $i64type /**/
183?H:?%<:#define U64TYPE $u64type /**/
184?H:?%<:#endif
185?H:#define NVTYPE $nvtype /**/
186?H:#define IVSIZE $ivsize /**/
187?H:#define UVSIZE $uvsize /**/
188?H:#define I8SIZE $i8size /**/
189?H:#define U8SIZE $u8size /**/
190?H:#define I16SIZE $i16size /**/
191?H:#define U16SIZE $u16size /**/
192?H:#define I32SIZE $i32size /**/
193?H:#define U32SIZE $u32size /**/
500277eb 194?H:?%<:#ifdef HAS_QUAD
b4d5f732
JH
195?H:?%<:#define I64SIZE $i64size /**/
196?H:?%<:#define U64SIZE $u64size /**/
197?H:?%<:#endif
198?H:#define NVSIZE $nvsize /**/
ebebf7f4 199?H:#$d_nv_preserves_uv NV_PRESERVES_UV
2c06d0fa 200?H:#define NV_PRESERVES_UV_BITS $nv_preserves_uv_bits
913e5e82 201?H:#$d_nv_zero_is_allbits_zero NV_ZERO_IS_ALLBITS_ZERO
6b4048d7
JH
202?H:?%<:#if UVSIZE == 8
203?H:?%<:# ifdef BYTEORDER
204?H:?%<:# if BYTEORDER == 0x1234
205?H:?%<:# undef BYTEORDER
206?H:?%<:# define BYTEORDER 0x12345678
207?H:?%<:# else
208?H:?%<:# if BYTEORDER == 0x4321
209?H:?%<:# undef BYTEORDER
210?H:?%<:# define BYTEORDER 0x87654321
211?H:?%<:# endif
212?H:?%<:# endif
213?H:?%<:# endif
214?H:?%<:#endif
b4d5f732 215?H:.
8c100f95 216?T:volatile
913e5e82
MB
217?T:xxx
218?T:d
0065f4af
MB
219?F:!try
220: Check basic sizes
b4d5f732
JH
221echo " "
222$echo "Choosing the C types to be used for Perl's internal types..." >&4
223
33b2427b 224case "$use64bitint:$d_quad:$quadtype" in
500277eb 225define:define:?*)
b4d5f732
JH
226 ivtype="$quadtype"
227 uvtype="$uquadtype"
228 ivsize=8
229 uvsize=8
230 ;;
231*) ivtype="long"
232 uvtype="unsigned long"
233 ivsize=$longsize
234 uvsize=$longsize
235 ;;
236esac
237
238case "$uselongdouble:$d_longdbl" in
239define:define)
240 nvtype="long double"
241 nvsize=$longdblsize
242 ;;
243*) nvtype=double
244 nvsize=$doublesize
245 ;;
246esac
247
d7ef793b
JH
248$echo "(IV will be "$ivtype", $ivsize bytes)"
249$echo "(UV will be "$uvtype", $uvsize bytes)"
250$echo "(NV will be "$nvtype", $nvsize bytes)"
b4d5f732
JH
251
252$cat >try.c <<EOCP
253#$i_inttypes I_INTTYPES
254#ifdef I_INTTYPES
255#include <inttypes.h>
256#endif
257#include <stdio.h>
258int main() {
259#ifdef INT8
260 int8_t i = INT8_MAX;
261 uint8_t u = UINT8_MAX;
262 printf("int8_t\n");
263#endif
264#ifdef INT16
265 int16_t i = INT16_MAX;
266 uint16_t i = UINT16_MAX;
267 printf("int16_t\n");
268#endif
269#ifdef INT32
270 int32_t i = INT32_MAX;
271 uint32_t u = UINT32_MAX;
272 printf("int32_t\n");
273#endif
b4d5f732
JH
274}
275EOCP
c9f0ccae 276
a12a5d34 277i8type="signed char"
5107cfb0
MB
278u8type="unsigned char"
279i8size=1
280u8size=1
c9f0ccae
JH
281
282case "$i16type" in
283'') case "$shortsize" in
284 2) i16type=short
285 u16type="unsigned short"
286 i16size=$shortsize
287 u16size=$shortsize
b4d5f732
JH
288 ;;
289 esac
c9f0ccae
JH
290 ;;
291esac
b4d5f732 292case "$i16type" in
c9f0ccae
JH
293'') set try -DINT16
294 if eval $compile; then
0f00356b 295 case "`$run ./try`" in
c9f0ccae
JH
296 int16_t)
297 i16type=int16_t
298 u16type=uint16_t
299 i16size=2
300 u16size=2
301 ;;
302 esac
303 fi
b4d5f732
JH
304 ;;
305esac
c9f0ccae
JH
306case "$i16type" in
307'') if $test $shortsize -ge 2; then
308 i16type=short
309 u16type="unsigned short"
310 i16size=$shortsize
311 u16size=$shortsize
312 fi
313 ;;
314esac
315
b4d5f732
JH
316case "$i32type" in
317'') case "$longsize" in
318 4) i32type=long
319 u32type="unsigned long"
c9f0ccae 320 i32size=$longsize
b4d5f732
JH
321 u32size=$longsize
322 ;;
323 *) case "$intsize" in
324 4) i32type=int
325 u32type="unsigned int"
326 i32size=$intsize
327 u32size=$intsize
328 ;;
329 esac
330 ;;
331 esac
332 ;;
333esac
c9f0ccae
JH
334case "$i32type" in
335'') set try -DINT32
336 if eval $compile; then
0f00356b 337 case "`$run ./try`" in
c9f0ccae
JH
338 int32_t)
339 i32type=int32_t
340 u32type=uint32_t
341 i32size=4
342 u32size=4
343 ;;
344 esac
345 fi
346 ;;
347esac
348case "$i32type" in
349'') if $test $intsize -ge 4; then
350 i32type=int
351 u32type="unsigned int"
352 i32size=$intsize
353 u32size=$intsize
354 fi
355 ;;
356esac
357
b4d5f732 358case "$i64type" in
500277eb
JH
359'') case "$d_quad:$quadtype" in
360 define:?*)
361 i64type="$quadtype"
b4d5f732
JH
362 u64type="$uquadtype"
363 i64size=8
364 u64size=8
365 ;;
366 esac
367 ;;
368esac
369
8c100f95
NC
370$echo "Checking how many bits of your UVs your NVs can preserve..." >&4
371: volatile so that the compiler has to store it out to memory.
372if test X"$d_volatile" = X"$define"; then
373 volatile=volatile
374fi
d7ef793b
JH
375$cat <<EOP >try.c
376#include <stdio.h>
1273bb5e
JH
377#$i_stdlib I_STDLIB
378#ifdef I_STDLIB
379#include <stdlib.h>
380#endif
8c100f95
NC
381#include <sys/types.h>
382#include <signal.h>
383#ifdef SIGFPE
384$volatile int bletched = 0;
dc952a08 385$signal_t blech(int s) { bletched = 1; }
8c100f95 386#endif
31ebece7
JH
387int main() {
388 $uvtype u = 0;
8c100f95 389 $nvtype d;
31ebece7
JH
390 int n = 8 * $uvsize;
391 int i;
8c100f95
NC
392#ifdef SIGFPE
393 signal(SIGFPE, blech);
394#endif
395
31ebece7
JH
396 for (i = 0; i < n; i++) {
397 u = u << 1 | ($uvtype)1;
8c100f95
NC
398 d = ($nvtype)u;
399 if (($uvtype)d != u)
400 break;
401 if (d <= 0)
402 break;
403 d = ($nvtype)(u - 1);
404 if (($uvtype)d != (u - 1))
31ebece7 405 break;
8c100f95 406#ifdef SIGFPE
a0115d2f 407 if (bletched)
8c100f95
NC
408 break;
409#endif
31ebece7 410 }
74b7c8a4 411 printf("%d\n", ((i == n) ? -n : i));
31ebece7
JH
412 exit(0);
413}
414EOP
8c100f95
NC
415set try
416
417d_nv_preserves_uv="$undef"
418if eval $compile; then
2c06d0fa 419 nv_preserves_uv_bits="`$run ./try`"
8c100f95 420fi
2c06d0fa 421case "$nv_preserves_uv_bits" in
2cb64bf6 422\-[1-9]*)
2c06d0fa
JH
423 nv_preserves_uv_bits=`expr 0 - $nv_preserves_uv_bits`
424 $echo "Your NVs can preserve all $nv_preserves_uv_bits bits of your UVs." 2>&1
8c100f95 425 d_nv_preserves_uv="$define"
31ebece7 426 ;;
2c06d0fa 427[1-9]*) $echo "Your NVs can preserve only $nv_preserves_uv_bits bits of your UVs." 2>&1
8c100f95
NC
428 d_nv_preserves_uv="$undef" ;;
429*) $echo "Can't figure out how many bits your NVs preserve." 2>&1
cfa76520 430 nv_preserves_uv_bits="0" ;;
31ebece7 431esac
2cb64bf6 432$rm_try
8c100f95 433
913e5e82
MB
434$echo "Checking whether NV 0.0 is all bits zero in memory..." >&4
435: volatile so that the compiler has to store it out to memory.
436if test X"$d_volatile" = X"$define"; then
437 volatile=volatile
438fi
439$cat <<EOP >try.c
440#include <stdio.h>
441#$i_stdlib I_STDLIB
442#ifdef I_STDLIB
443#include <stdlib.h>
444#endif
445#$i_string I_STRING
446#ifdef I_STRING
447# include <string.h>
448#else
449# include <strings.h>
450#endif
451#include <sys/types.h>
452#include <signal.h>
453#ifdef SIGFPE
454$volatile int bletched = 0;
dc952a08 455$signal_t blech(int s) { bletched = 1; }
913e5e82
MB
456#endif
457
458int checkit($nvtype d, char *where) {
459 unsigned char *p = (char *)&d;
460 unsigned char *end = p + sizeof(d);
461 int fail = 0;
462
463 while (p < end)
464 fail += *p++;
465
466 if (!fail)
467 return 0;
468
469 p = (char *)&d;
470 printf("No - %s: 0x", where);
471 while (p < end)
472 printf ("%02X", *p++);
473 printf("\n");
474 return 1;
475}
476
477int main(int argc, char **argv) {
478 $nvtype d = 0.0;
479 int fail = 0;
480 fail += checkit(d, "0.0");
481
482 /* The compiler shouldn't be assuming that bletched is 0 */
483 d = bletched;
484
485 fail += checkit(d, "bleched");
486
487#ifdef SIGFPE
488 signal(SIGFPE, blech);
489#endif
490
491 /* Paranoia - the compiler should have no way of knowing that ANSI says
492 that argv[argc] will always be NULL. Actually, if it did assume this it
493 would be buggy, as this is C and main() can be called from elsewhere in
494 the program. */
495 d = argv[argc] ? 1 : 0;
496
497 if (d) {
498 printf("Odd argv[argc]=%p, d=%g\n", argv[argc], d);
499 }
500
501 fail += checkit(d, "ternary");
502
503 memset(&d, sizeof(d), argv[argc] ? 1 : 0);
504
505 if (d != 0.0) {
506 printf("No - memset doesn't give 0.0\n");
507 /* This might just blow up: */
508 printf("(gives %g)\n", d);
509 return 1;
510 }
2cb64bf6 511
913e5e82
MB
512#ifdef SIGFPE
513 if (bletched) {
514 printf("No - something bleched\n");
515 return 1;
516 }
517#endif
518 if (fail) {
519 printf("No - %d fail(s)\n", fail);
520 return 1;
521 }
522 printf("Yes\n");
523 return 0;
524}
525EOP
526set try
527
528d_nv_zero_is_allbits_zero="$undef"
529if eval $compile; then
530 xxx="`$run ./try`"
531 case "$?" in
532 0)
533 case "$xxx" in
534 Yes) cat >&4 <<EOM
5350.0 is represented as all bits zero in memory
536EOM
537 d_nv_zero_is_allbits_zero="$define"
538 ;;
539 *) cat >&4 <<EOM
5400.0 is not represented as all bits zero in memory
541EOM
542 d_nv_zero_is_allbits_zero="$undef"
543 ;;
544 esac
545 ;;
546 *) cat >&4 <<EOM
5470.0 is not represented as all bits zero in memory
548EOM
549 d_nv_zero_is_allbits_zero="$undef"
550 ;;
551 esac
552fi
2cb64bf6 553$rm_try
913e5e82 554