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 libs gccversion \
16 cat Compile i_inttypes test 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
240 $echo "Choosing the C types to be used for Perl's internal types..." >&4
242 case "$use64bitint:$d_quad:$quadtype" in
250 uvtype="unsigned long"
256 case "$uselongdouble:$d_longdbl" in
266 case "$usequadmath:$i_quadmath" in
270 : libquadmath is not in the usual places, and the place
271 : changes if the compiler is upgraded. So ask the compiler if it
273 : We do not need to save this, if it fails we abort.
274 libs="$libs -lquadmath"
277 #include <quadmath.h>
279 int main(int argc, char *argv[]) {
281 if (fabsq(logq(x)) > 1e-6) {
282 fputs("quadmath is broken\n", stderr);
290 if eval $compile_ok; then
296 *** You requested the use of the quadmath library, but
297 *** it appears to be nonfunctional.
298 *** Cannot continue, aborting.
307 *** You requested the use of the quadmath library, but you
308 *** do not seem to have the quadmath library installed.
309 *** Cannot continue, aborting.
314 define:*) $cat <<EOM >&4
316 *** You requested the use of the quadmath library, but you
317 *** do not seem to have the required header, <quadmath.h>.
319 case "$gccversion" in
322 *** Your gcc looks a bit old:
328 *** You are not running a gcc.
333 *** For the quadmath library you need at least gcc 4.6.
334 *** Cannot continue, aborting.
340 $echo "(IV will be "$ivtype", $ivsize bytes)"
341 $echo "(UV will be "$uvtype", $uvsize bytes)"
342 $echo "(NV will be "$nvtype", $nvsize bytes)"
345 #$i_inttypes I_INTTYPES
347 #include <inttypes.h>
353 uint8_t u = UINT8_MAX;
357 int16_t i = INT16_MAX;
358 uint16_t u = UINT16_MAX;
362 int32_t i = INT32_MAX;
363 uint32_t u = UINT32_MAX;
370 u8type="unsigned char"
375 '') case "$shortsize" in
377 u16type="unsigned short"
386 if eval $compile; then
387 case "`$run ./try`" in
399 '') if $test $shortsize -ge 2; then
401 u16type="unsigned short"
409 '') case "$longsize" in
411 u32type="unsigned long"
415 *) case "$intsize" in
417 u32type="unsigned int"
428 if eval $compile; then
429 case "`$run ./try`" in
441 '') if $test $intsize -ge 4; then
443 u32type="unsigned int"
451 '') case "$d_quad:$quadtype" in
462 $echo "Checking how many bits of your UVs your NVs can preserve..." >&4
469 #$i_inttypes I_INTTYPES
471 #include <inttypes.h>
473 #include <sys/types.h>
476 /* volatile so that the compiler has to store it out to memory */
477 volatile int bletched = 0;
478 $signal_t blech(int s) { bletched = 1; }
486 signal(SIGFPE, blech);
489 for (i = 0; i < n; i++) {
490 u = u << 1 | ($uvtype)1;
496 d = ($nvtype)(u - 1);
497 if (($uvtype)d != (u - 1))
504 printf("%d\n", ((i == n) ? -n : i));
510 d_nv_preserves_uv="$undef"
511 if eval $compile; then
512 nv_preserves_uv_bits="`$run ./try`"
514 case "$nv_preserves_uv_bits" in
516 nv_preserves_uv_bits=`expr 0 - $nv_preserves_uv_bits`
517 $echo "Your NVs can preserve all $nv_preserves_uv_bits bits of your UVs." >&4
518 d_nv_preserves_uv="$define"
520 [1-9]*) $echo "Your NVs can preserve only $nv_preserves_uv_bits bits of your UVs." >&4
521 d_nv_preserves_uv="$undef" ;;
522 *) $echo "Can't figure out how many bits your NVs preserve." >&4
523 nv_preserves_uv_bits="0" ;;
527 $echo "Checking to find the largest integer value your NVs can hold..." >&4
539 /* volatile so that the compiler has to store it out to memory */
540 volatile NV up = value + 1.0;
541 volatile NV negated = -value;
542 volatile NV down = negated - 1.0;
543 volatile NV got_up = up - value;
544 int up_good = got_up == 1.0;
545 int got_down = down - negated;
546 int down_good = got_down == -1.0;
548 if (down_good != up_good) {
550 "Inconsistency - up %d %f; down %d %f; for 2**%d (%.20f)\n",
551 up_good, (double) got_up, down_good, (double) got_down,
552 count, (double) value);
559 fputs("256.0", stdout);
562 fputs("2.0", stdout);
574 fprintf(stderr, "Cannot overflow integer range, even at 2**%d (%.20f)\n",
575 count, (double) value);
581 nv_overflows_integers_at='0'
582 if eval $compile; then
588 The largest integer your NVs can preserve is equal to $xxx
590 nv_overflows_integers_at="$xxx"
593 Cannot determine the largest integer value your NVs can hold, unexpected output
600 Cannot determine the largest integer value your NVs can hold
607 $echo "Checking whether NV 0.0 is all bits zero in memory..." >&4
615 #include <sys/types.h>
618 /* volatile so that the compiler has to store it out to memory */
619 volatile int bletched = 0;
620 $signal_t blech(int s) { bletched = 1; }
623 int checkit($nvtype d, const char *where) {
625 unsigned char *p = (unsigned char *)v;
626 unsigned char *end = p + sizeof(d);
635 p = (unsigned char *)v;
636 printf("No - %s: 0x", where);
638 printf ("%02X", *p++);
643 int main(int argc, char **argv) {
646 fail += checkit(d, "0.0");
648 /* The compiler shouldn't be assuming that bletched is 0 */
651 fail += checkit(d, "bleched");
654 signal(SIGFPE, blech);
657 /* Paranoia - the compiler should have no way of knowing that ANSI says
658 that argv[argc] will always be NULL. Actually, if it did assume this it
659 would be buggy, as this is C and main() can be called from elsewhere in
661 d = argv[argc] ? 1 : 0;
664 printf("Odd argv[argc]=%p, d=%g\n", argv[argc], d);
667 fail += checkit(d, "ternary");
669 memset(&d, sizeof(d), argv[argc] ? 1 : 0);
672 printf("No - memset doesn't give 0.0\n");
673 /* This might just blow up: */
674 printf("(gives %g)\n", d);
680 printf("No - something bleched\n");
685 printf("No - %d fail(s)\n", fail);
694 d_nv_zero_is_allbits_zero="$undef"
695 if eval $compile; then
701 0.0 is represented as all bits zero in memory
703 d_nv_zero_is_allbits_zero="$define"
706 0.0 is not represented as all bits zero in memory
708 d_nv_zero_is_allbits_zero="$undef"
713 0.0 is not represented as all bits zero in memory
715 d_nv_zero_is_allbits_zero="$undef"