Subject: Re: libc arch/*/gen cleanup
To: Klaus Klein <kleink@reziprozitaet.de>
From: Simon Burge <simonb@wasabisystems.com>
List: tech-userlevel
Date: 10/28/2001 21:12:28
Klaus Klein wrote:

> Simon Burge <simonb@wasabisystems.com> writes:
> 
> > 	/* bytes for quiet NaN (IEEE single precision) */
> > 	const char __nanf[] __attribute__((__aligned__(__alignof__(single)))) =
> 
> Presumably you mean 'float' here. :-) BTW, I've also thought of
> solving this in a more portable way, i.e. making this a union
> consisting of float-type and char.

How does this look then...

in <math.h> have:
 
        union __infinity_u {
                unsigned char val[8];
                double dummy;
        };
        extern __const union __infinity_u __infinity;
        #define HUGE_VAL        (*(__const double *)(__const void *)&__infinity)
 
in lib/libc/gen/ieee754_infinity.c have:
 
        const union __infinity_u __infinity =
        #if BYTE_ORDER == BIG_ENDIAN
                { 0x7f, (char)0xf0, 0, 0, 0, 0, 0, 0 };
        #else
                { 0, 0, 0, 0, 0, 0, (char)0xf0, 0x7f };
        #endif
 
in <machine/math.h> (except vax) have:
 
        union __nanf_u {
                unsigned char val[4];
                float dummy;
        };
        extern __const union __nanf_u __nanf;
        #define NAN             (*(__const float *)(__const void *)&__nanf)
 
in lib/libc/gen/ieee754_nanf.c have:
 
        const union __nanf_u __nanf =
        #if BYTE_ORDER == BIG_ENDIAN
                        { 0x7f, 0xc0,    0,    0 };
        #else
                        {    0,    0, 0xc0, 0x7f };
        #endif


On an alpha, these show up as having the correct alignment constraints
according to objdump:

ieee754_infinity.o:     file format elf64-alpha

Sections:
Idx Name          Size      VMA               LMA               File off  Algn
  ...
  5 .rodata       00000008  0000000000000000  0000000000000000  000001b0  2**3
                  CONTENTS, ALLOC, LOAD, READONLY, DATA

ieee754_nanf.o:     file format elf64-alpha

Sections:
Idx Name          Size      VMA               LMA               File off  Algn
  ...
  5 .rodata       00000004  0000000000000000  0000000000000000  0000019c  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA


It's a pity the union definition in has to be repeated in all non-vax
<machine/math.h> include files.  One idea that comes to mind is to
simply have <machine/math.h> declare __HAVE_NANF in the non-vax case,
and test for this in <math.h>.  Is that acceptable from a standards and
namespace point-of-view?

Simon.
--
Simon Burge                            <simonb@wasabisystems.com>
NetBSD CDs, Support and Service:    http://www.wasabisystems.com/