1 ?RCS: $Id: perlxv.U,v 1.1 2000/08/31 17:53:56 jhi Exp jhi $
3 ?RCS: Copyright (c) 1999 Jarkko Hietaniemi
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.
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 nv_overflows_integers_at \
12 d_nv_zero_is_allbits_zero: \
13 echo rm_try use64bitint d_quad quadtype uquadtype usequadmath \
14 d_longdbl uselongdouble longdblsize doublesize i_quadmath \
15 shortsize intsize longsize i_stdlib i_string libs gccversion \
16 cat Compile i_inttypes test d_volatile signal_t run
17 ?MAKE: -pick add $@ %<
19 ?S: This variable contains the C type used for Perl's IV.
22 ?S: This variable contains the C type used for Perl's UV.
25 ?S: This variable contains the C type used for Perl's NV.
28 ?S: This variable contains the C type used for Perl's I8.
31 ?S: This variable contains the C type used for Perl's U8.
34 ?S: This variable contains the C type used for Perl's I16.
37 ?S: This variable contains the C type used for Perl's U16.
40 ?S: This variable contains the C type used for Perl's I32.
43 ?S: This variable contains the C type used for Perl's U32.
46 ?S: This variable contains the C type used for Perl's I64.
49 ?S: This variable contains the C type used for Perl's U64.
52 ?S: This variable is the size of an IV in bytes.
55 ?S: This variable is the size of a UV in bytes.
58 ?S: This variable is the size of an I8 in bytes.
61 ?S: This variable is the size of an U8 in bytes.
64 ?S: This variable is the size of an I16 in bytes.
67 ?S: This variable is the size of an U16 in bytes.
70 ?S: This variable is the size of an I32 in bytes.
73 ?S: This variable is the size of an U32 in bytes.
76 ?S: This variable is the size of an I64 in bytes.
79 ?S: This variable is the size of an U64 in bytes.
82 ?S: This variable is the size of a Perl NV in bytes.
83 ?S: Note that some floating point formats have unused bytes.
86 ?S: This variable indicates whether a variable of type nvtype
87 ?S: can preserve all the bits a variable of type uvtype.
89 ?S:nv_preserves_uv_bits:
90 ?S: This variable indicates how many of bits type uvtype
91 ?S: a variable nvtype can preserve.
93 ?S:nv_overflows_integers_at:
94 ?S: This variable gives the largest integer value that NVs can hold
95 ?S: as a constant floating point expression.
96 ?S: If it could not be determined, it holds the value 0.
98 ?S:d_nv_zero_is_allbits_zero:
99 ?S: This variable indicates whether a variable of type nvtype
100 ?S: stores 0.0 in memory as all bits zero.
103 ?C: This symbol defines the C type used for Perl's IV.
106 ?C: This symbol defines the C type used for Perl's UV.
109 ?C: This symbol defines the C type used for Perl's I8.
112 ?C: This symbol defines the C type used for Perl's U8.
115 ?C: This symbol defines the C type used for Perl's I16.
118 ?C: This symbol defines the C type used for Perl's U16.
121 ?C: This symbol defines the C type used for Perl's I32.
124 ?C: This symbol defines the C type used for Perl's U32.
127 ?C: This symbol defines the C type used for Perl's I64.
130 ?C: This symbol defines the C type used for Perl's U64.
133 ?C: This symbol defines the C type used for Perl's NV.
136 ?C: This symbol contains the sizeof(IV).
139 ?C: This symbol contains the sizeof(UV).
142 ?C: This symbol contains the sizeof(I8).
145 ?C: This symbol contains the sizeof(U8).
148 ?C: This symbol contains the sizeof(I16).
151 ?C: This symbol contains the sizeof(U16).
154 ?C: This symbol contains the sizeof(I32).
157 ?C: This symbol contains the sizeof(U32).
160 ?C: This symbol contains the sizeof(I64).
163 ?C: This symbol contains the sizeof(U64).
166 ?C: This symbol contains the sizeof(NV).
167 ?C: Note that some floating point formats have unused bytes.
168 ?C: The most notable example is the x86* 80-bit extended precision
169 ?C: which comes in byte sizes of 12 and 16 (for 32 and 64 bit
170 ?C: platforms, respectively), but which only uses 10 bytes.
171 ?C: Perl compiled with -Duselongdouble on x86* is like this.
174 ?C: This symbol, if defined, indicates that a variable of type NVTYPE
175 ?C: can preserve all the bits of a variable of type UVTYPE.
177 ?C:NV_PRESERVES_UV_BITS:
178 ?C: This symbol contains the number of bits a variable of type NVTYPE
179 ?C: can preserve of a variable of type UVTYPE.
181 ?C:NV_OVERFLOWS_INTEGERS_AT:
182 ?C: This symbol gives the largest integer value that NVs can hold. This
183 ?C: value + 1.0 cannot be stored accurately. It is expressed as constant
184 ?C: floating point expression to reduce the chance of decimal/binary
185 ?C: conversion issues. If it can not be determined, the value 0 is given.
187 ?C:NV_ZERO_IS_ALLBITS_ZERO:
188 ?C: This symbol, if defined, indicates that a variable of type NVTYPE
189 ?C: stores 0.0 in memory as all bits zero.
191 ?H:#define IVTYPE $ivtype /**/
192 ?H:#define UVTYPE $uvtype /**/
193 ?H:#define I8TYPE $i8type /**/
194 ?H:#define U8TYPE $u8type /**/
195 ?H:#define I16TYPE $i16type /**/
196 ?H:#define U16TYPE $u16type /**/
197 ?H:#define I32TYPE $i32type /**/
198 ?H:#define U32TYPE $u32type /**/
199 ?H:?%<:#ifdef HAS_QUAD
200 ?H:?%<:#define I64TYPE $i64type /**/
201 ?H:?%<:#define U64TYPE $u64type /**/
203 ?H:#define NVTYPE $nvtype /**/
204 ?H:#define IVSIZE $ivsize /**/
205 ?H:#define UVSIZE $uvsize /**/
206 ?H:#define I8SIZE $i8size /**/
207 ?H:#define U8SIZE $u8size /**/
208 ?H:#define I16SIZE $i16size /**/
209 ?H:#define U16SIZE $u16size /**/
210 ?H:#define I32SIZE $i32size /**/
211 ?H:#define U32SIZE $u32size /**/
212 ?H:?%<:#ifdef HAS_QUAD
213 ?H:?%<:#define I64SIZE $i64size /**/
214 ?H:?%<:#define U64SIZE $u64size /**/
216 ?H:#define NVSIZE $nvsize /**/
217 ?H:#$d_nv_preserves_uv NV_PRESERVES_UV
218 ?H:#define NV_PRESERVES_UV_BITS $nv_preserves_uv_bits
219 ?H:#define NV_OVERFLOWS_INTEGERS_AT ($nv_overflows_integers_at)
220 ?H:#$d_nv_zero_is_allbits_zero NV_ZERO_IS_ALLBITS_ZERO
221 ?H:?%<:#if UVSIZE == 8
222 ?H:?%<:# ifdef BYTEORDER
223 ?H:?%<:# if BYTEORDER == 0x1234
224 ?H:?%<:# undef BYTEORDER
225 ?H:?%<:# define BYTEORDER 0x12345678
227 ?H:?%<:# if BYTEORDER == 0x4321
228 ?H:?%<:# undef BYTEORDER
229 ?H:?%<:# define BYTEORDER 0x87654321
241 $echo "Choosing the C types to be used for Perl's internal types..." >&4
243 case "$use64bitint:$d_quad:$quadtype" in
251 uvtype="unsigned long"
257 case "$uselongdouble:$d_longdbl" in
267 case "$usequadmath:$i_quadmath" in
275 *** You requested the use of the quadmath library, but you
276 *** do not seem to have the quadmath library installed.
277 *** Cannot continue, aborting.
283 define:*) $cat <<EOM >&4
285 *** You requested the use of the quadmath library, but you
286 *** do not seem to have the required header, <quadmath.h>.
288 case "$gccversion" in
291 *** Your gcc looks a bit old:
297 *** You are not running a gcc.
302 *** For the quadmath library you need at least gcc 4.6.
303 *** Cannot continue, aborting.
309 $echo "(IV will be "$ivtype", $ivsize bytes)"
310 $echo "(UV will be "$uvtype", $uvsize bytes)"
311 $echo "(NV will be "$nvtype", $nvsize bytes)"
314 #$i_inttypes I_INTTYPES
316 #include <inttypes.h>
322 uint8_t u = UINT8_MAX;
326 int16_t i = INT16_MAX;
327 uint16_t u = UINT16_MAX;
331 int32_t i = INT32_MAX;
332 uint32_t u = UINT32_MAX;
339 u8type="unsigned char"
344 '') case "$shortsize" in
346 u16type="unsigned short"
355 if eval $compile; then
356 case "`$run ./try`" in
368 '') if $test $shortsize -ge 2; then
370 u16type="unsigned short"
378 '') case "$longsize" in
380 u32type="unsigned long"
384 *) case "$intsize" in
386 u32type="unsigned int"
397 if eval $compile; then
398 case "`$run ./try`" in
410 '') if $test $intsize -ge 4; then
412 u32type="unsigned int"
420 '') case "$d_quad:$quadtype" in
431 $echo "Checking how many bits of your UVs your NVs can preserve..." >&4
432 : volatile so that the compiler has to store it out to memory.
433 if test X"$d_volatile" = X"$define"; then
442 #include <sys/types.h>
445 $volatile int bletched = 0;
446 $signal_t blech(int s) { bletched = 1; }
454 signal(SIGFPE, blech);
457 for (i = 0; i < n; i++) {
458 u = u << 1 | ($uvtype)1;
464 d = ($nvtype)(u - 1);
465 if (($uvtype)d != (u - 1))
472 printf("%d\n", ((i == n) ? -n : i));
478 d_nv_preserves_uv="$undef"
479 if eval $compile; then
480 nv_preserves_uv_bits="`$run ./try`"
482 case "$nv_preserves_uv_bits" in
484 nv_preserves_uv_bits=`expr 0 - $nv_preserves_uv_bits`
485 $echo "Your NVs can preserve all $nv_preserves_uv_bits bits of your UVs." 2>&1
486 d_nv_preserves_uv="$define"
488 [1-9]*) $echo "Your NVs can preserve only $nv_preserves_uv_bits bits of your UVs." 2>&1
489 d_nv_preserves_uv="$undef" ;;
490 *) $echo "Can't figure out how many bits your NVs preserve." 2>&1
491 nv_preserves_uv_bits="0" ;;
495 $echo "Checking to find the largest integer value your NVs can hold..." >&4
496 : volatile so that the compiler has to store it out to memory.
497 if test X"$d_volatile" = X"$define"; then
511 $volatile NV up = value + 1.0;
512 $volatile NV negated = -value;
513 $volatile NV down = negated - 1.0;
514 $volatile NV got_up = up - value;
515 int up_good = got_up == 1.0;
516 int got_down = down - negated;
517 int down_good = got_down == -1.0;
519 if (down_good != up_good) {
521 "Inconsistency - up %d %f; down %d %f; for 2**%d (%.20f)\n",
522 up_good, (double) got_up, down_good, (double) got_down,
523 count, (double) value);
530 fputs("256.0", stdout);
533 fputs("2.0", stdout);
545 fprintf(stderr, "Cannot overflow integer range, even at 2**%d (%.20f)\n",
546 count, (double) value);
552 nv_overflows_integers_at='0'
553 if eval $compile; then
559 The largest integer your NVs can preserve is equal to $xxx
561 nv_overflows_integers_at="$xxx"
564 Cannot determine the largest integer value your NVs can hold, unexpected output
571 Cannot determine the largest integer value your NVs can hold
578 $echo "Checking whether NV 0.0 is all bits zero in memory..." >&4
579 : volatile so that the compiler has to store it out to memory.
580 if test X"$d_volatile" = X"$define"; then
593 # include <strings.h>
595 #include <sys/types.h>
598 $volatile int bletched = 0;
599 $signal_t blech(int s) { bletched = 1; }
602 int checkit($nvtype d, const char *where) {
604 unsigned char *p = (unsigned char *)v;
605 unsigned char *end = p + sizeof(d);
614 p = (unsigned char *)v;
615 printf("No - %s: 0x", where);
617 printf ("%02X", *p++);
622 int main(int argc, char **argv) {
625 fail += checkit(d, "0.0");
627 /* The compiler shouldn't be assuming that bletched is 0 */
630 fail += checkit(d, "bleched");
633 signal(SIGFPE, blech);
636 /* Paranoia - the compiler should have no way of knowing that ANSI says
637 that argv[argc] will always be NULL. Actually, if it did assume this it
638 would be buggy, as this is C and main() can be called from elsewhere in
640 d = argv[argc] ? 1 : 0;
643 printf("Odd argv[argc]=%p, d=%g\n", argv[argc], d);
646 fail += checkit(d, "ternary");
648 memset(&d, sizeof(d), argv[argc] ? 1 : 0);
651 printf("No - memset doesn't give 0.0\n");
652 /* This might just blow up: */
653 printf("(gives %g)\n", d);
659 printf("No - something bleched\n");
664 printf("No - %d fail(s)\n", fail);
673 d_nv_zero_is_allbits_zero="$undef"
674 if eval $compile; then
680 0.0 is represented as all bits zero in memory
682 d_nv_zero_is_allbits_zero="$define"
685 0.0 is not represented as all bits zero in memory
687 d_nv_zero_is_allbits_zero="$undef"
692 0.0 is not represented as all bits zero in memory
694 d_nv_zero_is_allbits_zero="$undef"