diff options
author | Craig A. Berry <craigberry@mac.com> | 2005-06-18 13:23:59 -0500 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2005-06-19 15:11:06 +0000 |
commit | f607920a165f3c14b9c61dc74e535bdc6aa1904c (patch) | |
tree | 9036f388507340c1b9d3931c0a9098bc1d7d9be7 | |
parent | dd69047874984d0e0233a4ed2eb67c2fe4ea1617 (diff) | |
download | perl-f607920a165f3c14b9c61dc74e535bdc6aa1904c.tar.gz |
Add a Configure test to see if NV 0.0 is stored as all bits zero, and
#define NV_ZERO_IS_ALLBITS_ZERO if so. This is always true on VMS:
Subject: Re: Configure check for whether 0.0 is stored as all bits zero
From: "Craig A. Berry" <craigberry@mac.com>
Message-Id: <p06210214beda5bf31c4c@[172.16.52.1]>
Date: Sat, 18 Jun 2005 18:23:59 -0500
p4raw-id: //depot/perl@24898
-rwxr-xr-x | Configure | 124 | ||||
-rw-r--r-- | Porting/Glossary | 4 | ||||
-rw-r--r-- | config_h.SH | 5 | ||||
-rw-r--r-- | configure.com | 1 |
4 files changed, 134 insertions, 0 deletions
@@ -1002,6 +1002,7 @@ perl5='' perladmin='' perlpath='' d_nv_preserves_uv='' +d_nv_zero_is_allbits_zero='' i16size='' i16type='' i32size='' @@ -14833,6 +14834,128 @@ esac $rm -f try.* try +$echo "Checking whether NV 0.0 is all bits zero in memory..." >&4 +: volatile so that the compiler has to store it out to memory. +if test X"$d_volatile" = X"$define"; then + volatile=volatile +fi +$cat <<EOP >try.c +#include <stdio.h> +#$i_stdlib I_STDLIB +#ifdef I_STDLIB +#include <stdlib.h> +#endif +#$i_string I_STRING +#ifdef I_STRING +# include <string.h> +#else +# include <strings.h> +#endif +#include <sys/types.h> +#include <signal.h> +#ifdef SIGFPE +$volatile int bletched = 0; +$signal_t blech(s) int s; { bletched = 1; } +#endif + +int checkit($nvtype d, char *where) { + unsigned char *p = (char *)&d; + unsigned char *end = p + sizeof(d); + int fail = 0; + + while (p < end) + fail += *p++; + + if (!fail) + return 0; + + p = (char *)&d; + printf("No - %s: 0x", where); + while (p < end) + printf ("%02X", *p++); + printf("\n"); + return 1; +} + +int main(int argc, char **argv) { + $nvtype d = 0.0; + int fail = 0; + fail += checkit(d, "0.0"); + + /* The compiler shouldn't be assuming that bletched is 0 */ + d = bletched; + + fail += checkit(d, "bleched"); + +#ifdef SIGFPE + signal(SIGFPE, blech); +#endif + + /* Paranoia - the compiler should have no way of knowing that ANSI says + that argv[argc] will always be NULL. Actually, if it did assume this it + would be buggy, as this is C and main() can be called from elsewhere in + the program. */ + d = argv[argc] ? 1 : 0; + + if (d) { + printf("Odd argv[argc]=%p, d=%g\n", argv[argc], d); + } + + fail += checkit(d, "ternary"); + + memset(&d, sizeof(d), argv[argc] ? 1 : 0); + + if (d != 0.0) { + printf("No - memset doesn't give 0.0\n"); + /* This might just blow up: */ + printf("(gives %g)\n", d); + return 1; + } + +#ifdef SIGFPE + if (bletched) { + printf("No - something bleched\n"); + return 1; + } +#endif + if (fail) { + printf("No - %d fail(s)\n", fail); + return 1; + } + printf("Yes\n"); + return 0; +} +EOP +set try + +d_nv_zero_is_allbits_zero="$undef" +if eval $compile; then + xxx="`$run ./try`" + case "$?" in + 0) + case "$xxx" in + Yes) cat >&4 <<EOM +0.0 is represented as all bits zero in memory +EOM + d_nv_zero_is_allbits_zero="$define" + ;; + *) cat >&4 <<EOM +0.0 is not represented as all bits zero in memory +EOM + d_nv_zero_is_allbits_zero="$undef" + ;; + esac + ;; + *) cat >&4 <<EOM +0.0 is not represented as all bits zero in memory +EOM + d_nv_zero_is_allbits_zero="$undef" + ;; + esac +fi + +$rm -f try.* try + : check for off64_t echo " " @@ -21012,6 +21135,7 @@ d_mymalloc='$d_mymalloc' d_nice='$d_nice' d_nl_langinfo='$d_nl_langinfo' d_nv_preserves_uv='$d_nv_preserves_uv' +d_nv_zero_is_allbits_zero='$d_nv_zero_is_allbits_zero' d_off64_t='$d_off64_t' d_old_pthread_create_joinable='$d_old_pthread_create_joinable' d_oldpthreads='$d_oldpthreads' diff --git a/Porting/Glossary b/Porting/Glossary index 99b8e34e7a..ac31fa561e 100644 --- a/Porting/Glossary +++ b/Porting/Glossary @@ -1383,6 +1383,10 @@ d_nv_preserves_uv (perlxv.U): This variable indicates whether a variable of type nvtype can preserve all the bits a variable of type uvtype. +d_nv_zero_is_allbits_zero (perlxv.U): + This variable indicates whether a variable of type nvtype + stores 0.0 in memory as all bits zero. + d_off64_t (d_off64_t.U): This symbol will be defined if the C compiler supports off64_t. diff --git a/config_h.SH b/config_h.SH index 422bd6cce2..7ff827f8d6 100644 --- a/config_h.SH +++ b/config_h.SH @@ -3235,6 +3235,10 @@ sed <<!GROK!THIS! >$CONFIG_H -e 's!^#undef\(.*/\)\*!/\*#define\1 \*!' -e 's!^#un * This symbol contains the number of bits a variable of type NVTYPE * can preserve of a variable of type UVTYPE. */ +/* NV_ZERO_IS_ALLBITS_ZERO + * This symbol, if defined, indicates that a variable of type NVTYPE + * stores 0.0 in memory as all bits zero. + */ #define IVTYPE $ivtype /**/ #define UVTYPE $uvtype /**/ #define I8TYPE $i8type /**/ @@ -3263,6 +3267,7 @@ sed <<!GROK!THIS! >$CONFIG_H -e 's!^#undef\(.*/\)\*!/\*#define\1 \*!' -e 's!^#un #define NVSIZE $nvsize /**/ #$d_nv_preserves_uv NV_PRESERVES_UV #define NV_PRESERVES_UV_BITS $nv_preserves_uv_bits +#$d_nv_zero_is_allbits_zero NV_ZERO_IS_ALLBITS_ZERO #if UVSIZE == 8 # ifdef BYTEORDER # if BYTEORDER == 0x1234 diff --git a/configure.com b/configure.com index 8be30fccb1..0e4cbb0002 100644 --- a/configure.com +++ b/configure.com @@ -5587,6 +5587,7 @@ $ WC "d_nice='define'" $ WC "d_nl_langinfo='" + d_nl_langinfo + "'" $ WC "d_nv_preserves_uv='" + d_nv_preserves_uv + "'" $ WC "nv_preserves_uv_bits='" + nv_preserves_uv_bits + "'" +$ WC "d_nv_zero_is_allbits_zero='define'" $ WC "d_off64_t='" + d_off64_t + "'" $ WC "d_old_pthread_create_joinable='" + d_old_pthread_create_joinable + "'" $ WC "d_oldarchlib='define'" |