DEC Unix 4.0 IEEE floating point on Alpha

DEC Unix 4.0 IEEE floating point on Alpha

Post by James N » Thu, 24 Jul 1997 04:00:00



Hi all,

I've come across a problem with the floating point format on
DEC alphas.  It happens under both VMS and Digital Unix.  It
appears to me that Alphas store IEEE floating point numbers
backwards.  On an Alpha, for value 511.0, I get:

00 80 FF 43

as the binary representation [written by
fwrite( &x, sizeof(float), 1, outfile);]

while on every other Unix workstation I've been able to get my fingers
on yields:

43 FF 80 00

which all the tools and info I find say this is 511.0 in IEEE format.

Can someone tell me if it's possible to get the Alpha to read/write
IEEE in the right order?  I've tried cc with the -ieee switch, but
that didn't do anything useful, and I tried gcc, and under VMS, I
tried cc/float=ieee ..., all of which yielded the 'backwards' IEEE format.

[my immediate need is for reading IEEE binary format generated
elsewhere, into a canned program, without wanting to write a byte
re-ordering program...]

Thanks for any help

james


 
 
 

DEC Unix 4.0 IEEE floating point on Alpha

Post by Paul DeMon » Thu, 24 Jul 1997 04:00:00



> Hi all,

> I've come across a problem with the floating point format on
> DEC alphas.  It happens under both VMS and Digital Unix.  It
> appears to me that Alphas store IEEE floating point numbers
> backwards.  On an Alpha, for value 511.0, I get:

> 00 80 FF 43

> as the binary representation [written by
> fwrite( &x, sizeof(float), 1, outfile);]

> while on every other Unix workstation I've been able to get my fingers
> on yields:

> 43 FF 80 00

> which all the tools and info I find say this is 511.0 in IEEE format.[snip]

  It looks like a byte endianess problem to me.  The Alpha runs in little
  endian mode (like VAX and x86) while 68K, SPARC, and non-DEC MIPS based
  workstations run in big endian mode.

  You could write FP values to a file in big endian order on your Alpha
  if you alias a char array over the FP value in memory and pick up the
  bytes in reverse order and write them individually to your file  There
  are probably more elegent ways of doing this...

> james



--
Paul W. DeMone                 The 801 experiment SPARCed an ARMs race
Kanata, Ontario                to put more PRECISION and POWER into



 
 
 

DEC Unix 4.0 IEEE floating point on Alpha

Post by Emmanuel Choque » Fri, 25 Jul 1997 04:00:00




> > Hi all,

>   It looks like a byte endianess problem to me.  The Alpha runs in little
>   endian mode (like VAX and x86) while 68K, SPARC, and non-DEC MIPS based
>   workstations run in big endian mode.

>   You could write FP values to a file in big endian order on your Alpha
>   if you alias a char array over the FP value in memory and pick up the
>   bytes in reverse order and write them individually to your file  There
>   are probably more elegent ways of doing this...

if you use FORTRAN from Digital, there are options to automatically
convert
the endianism while reading on the fly from a file.

--
Emmanuel Choquet
Informatique Client/Serveur
& Communication
                _/
                            _/
              _/   _/_/_/  _/   _/_/_/
             _/   _/      _/   _/
            _/   _/      _/   _/_/_/
           _/   _/      _/       _/
          _/   _/_/_/  _/   _/_/_/


c/o Cica      Tel: (33) 4 92.94.23.50
2229, route des cretes  fax: (33) 4 92.94.23.54
06560 Sophia-Antipolis

 
 
 

DEC Unix 4.0 IEEE floating point on Alpha

Post by A.Arno » Fri, 25 Jul 1997 04:00:00


Quote:>Can someone tell me if it's possible to get the Alpha to read/write
>IEEE in the right order?  I've tried cc with the -ieee switch, but
>that didn't do anything useful, and I tried gcc, and under VMS, I
>tried cc/float=ieee ..., all of which yielded the 'backwards' IEEE format.

There's no right and no wrong, there's only little-endian and big-endian!
DEC Alpha with Digital Unix or VMS is a little-endian architecture, i.e.
for all multibyte variables, the LSB is stored at the first address.  You
will see just the same on an Intel-based machine.  In contrast, a big endian
architecture (what you call 'right') stores the MSB at the first memory lo-
cation.  68000, CRAY, Sparc, and PowerPC are for example big endian archi-
tectures.

From time to time, discussions break up in newsgroups about which represen-
tation is the better one.  IMHO, they are just as pointless as discussions
about the better processor or OS.  Both have their pros and cons, and both
work if consistently used in a single environment.

If you want to portably read and write binary data over different platforms,
you have to do the 'byte mirroring' yourself on architectures that do not
use the endianess you use in your files (I personally work on Alphas and Intels
most of the time, so my binary files are 'little endian' and I have to convert
on a big-endian machine...).  For example, the following routine converts
an array of 4-byte values (doesn't matter if they are floats or ints):

        void DSwap(void *Field, int Cnt)
{
   register unsigned char *Run=(unsigned char *) Field,Swap;
   register int z;

   for (z=0; z<Cnt/4; z++,Run+=4)
    {
     Swap=Run[0]; Run[0]=Run[3]; Run[3]=Swap;
     Swap=Run[1]; Run[1]=Run[2]; Run[2]=Swap;
    }

Quote:}

Alfred Arnold

--
--------------------------------------------------------------------------------
Alfred Arnold                                 Phone: +49 (2461) 61-2434
Zentralinstitut fuer Angewandte Mathematik    Fax  : +49 (2461) 61-6656

D-52425 Juelich, Germany  http://www.kfa-juelich.de/zam/ZAMPeople/arnold.html

God is an atheist.
--------------------------------------------------------------------------------

 
 
 

DEC Unix 4.0 IEEE floating point on Alpha

Post by fairfi.. » Fri, 25 Jul 1997 04:00:00




Quote:

>>Can someone tell me if it's possible to get the Alpha to read/write
>>IEEE in the right order?  I've tried cc with the -ieee switch, but
>>that didn't do anything useful, and I tried gcc, and under VMS, I
>>tried cc/float=ieee ..., all of which yielded the 'backwards' IEEE format.
[...]
> If you want to portably read and write binary data over different platforms,
> you have to do the 'byte mirroring' yourself on architectures that do not
> use the endianess you use in your files (I personally work on Alphas and
> Intels most of the time, so my binary files are 'little endian' and I have
> to convert on a big-endian machine...).  For example, the following routine
> converts an array of 4-byte values (doesn't matter if they are floats or
> ints):

        Perhaps a better solution is to use the "convert float" routines
    available on DU (and OpenVMS).  Sorry  that I can't recall the exact
    name  on DU; its a run-time library routine called CVT$CONVERT_FLOAT
    on OVMS.  By using this routine for all input and output  of  binary
    data,  you  can  maintain  a  single  external  source  form,  e.g.,
    big-endian  &  IEEE  floats,  etc.    The  routine  does  many  more
    conversions than these, but for the problem at hand...

        -Ken
--

 SLAC, P.O.Box 4349, MS 46  |  DECnet:   45537::FAIRFIELD (45537=SLACVX)
 Stanford, CA   94309       |  Voice:    415-926-2924    FAX: 415-926-3515
 -------------------------------------------------------------------------
 These opinions are mine, not SLAC's, Stanford's, nor the DOE's...

 
 
 

DEC Unix 4.0 IEEE floating point on Alpha

Post by Jim Griff » Fri, 25 Jul 1997 04:00:00



> Hi all,

> I've come across a problem with the floating point format on
> DEC alphas.  It happens under both VMS and Digital Unix.  It
> appears to me that Alphas store IEEE floating point numbers
> backwards.  On an Alpha, for value 511.0, I get:

> 00 80 FF 43

> as the binary representation [written by
> fwrite( &x, sizeof(float), 1, outfile);]

> while on every other Unix workstation I've been able to get my fingers
> on yields:

> 43 FF 80 00

> which all the tools and info I find say this is 511.0 in IEEE format.

> Can someone tell me if it's possible to get the Alpha to read/write
> IEEE in the right order?  I've tried cc with the -ieee switch, but
> that didn't do anything useful, and I tried gcc, and under VMS, I
> tried cc/float=ieee ..., all of which yielded the 'backwards' IEEE format.

> [my immediate need is for reading IEEE binary format generated
> elsewhere, into a canned program, without wanting to write a byte
> re-ordering program...]

> Thanks for any help

> james

It's not the wrong order.  DECs are little-endian machines, whereas most
other Unix workstations, PCs and Macs are big-endian.  Little-endian
machines store data into memory in a different order than big-endian
machines.

One work-around is to use the htonl call before storing the data in a
file, but that may not be a good solution for your application.

--
Jim Griffin - TNS/AANR

"You can fool all of the people some of the time ---
               and that's sufficient.

 
 
 

DEC Unix 4.0 IEEE floating point on Alpha

Post by Steve Lion » Sat, 26 Jul 1997 04:00:00



|>        Perhaps a better solution is to use the "convert float" routines
|>    available on DU (and OpenVMS).  Sorry  that I can't recall the exact
|>    name  on DU; its a run-time library routine called CVT$CONVERT_FLOAT
|>    on OVMS.  By using this routine for all input and output  of  binary
|>    data,  you  can  maintain  a  single  external  source  form,  e.g.,
|>    big-endian  &  IEEE  floats,  etc.    The  routine  does  many  more
|>    conversions than these, but for the problem at hand...

The DIGITAL UNIX routine is cvt_ftof.  There's a man page for it.  Unlike
CVT$CONVERT_FLOAT, it will convert between little-endian and big-endian
IEEE.  (CVT$CONVERT_FLOAT will convert between any OTHER of the supported
datatypes and big-endian IEEE, but won't do the simple byte-swapping!)
--

Fortran Development               http://www.digital.com/info/slionel.html
Digital Equipment Corporation    
110 Spit Brook Road, ZKO2-3/N30    
Nashua, NH 03062-2698             "Free advice is worth every cent"

For information on DIGITAL Fortran, see http://www.digital.com/fortran

 
 
 

DEC Unix 4.0 IEEE floating point on Alpha

Post by John Hasca » Sun, 27 Jul 1997 04:00:00



}> DEC alphas.  It happens under both VMS and Digital Unix.  It
}> appears to me that Alphas store IEEE floating point numbers
}> backwards.  On an Alpha, for value 511.0, I get:
}> 00 80 FF 43
}> while on every other Unix workstation I've been able to get my fingers
}> on yields:
}> 43 FF 80 00
}> which all the tools and info I find say this is 511.0 in IEEE format.
}It's not the wrong order.  DECs are little-endian machines, whereas most
}other Unix workstations, PCs and Macs are big-endian.  Little-endian
}machines store data into memory in a different order than big-endian
}machines.

    No, PCs are little-endian too.

John
--
John Hascall, Software Engr.        Shut up, be happy.  The conveniences you
ISU Computation Center              demanded are now mandatory. -Jello Biafra

http://www.cc.iastate.edu/staff/systems/john/welcome.html  <-- the usual crud

 
 
 

DEC Unix 4.0 IEEE floating point on Alpha

Post by Eugene Y C C » Wed, 06 Aug 1997 04:00:00





>> I've come across a problem with the floating point format on
>> DEC alphas.  It happens under both VMS and Digital Unix.  It
>> appears to me that Alphas store IEEE floating point numbers
>> backwards.  On an Alpha, for value 511.0, I get:
>> 00 80 FF 43
>> as the binary representation [written by
>> fwrite( &x, sizeof(float), 1, outfile);]
>> while on every other Unix workstation I've been able to get my fingers
>> on yields:
>> 43 FF 80 00
>It's not the wrong order.  DECs are little-endian machines, whereas most
>other Unix workstations, PCs and Macs are big-endian.  Little-endian
>machines store data into memory in a different order than big-endian
>machines.
>One work-around is to use the htonl call before storing the data in a
>file, but that may not be a good solution for your application.

One additional note:  the htonl, ntohl, htons, and ntohs routines are
typically coded by the native systems more efficiently than what you can
do writing even a tight loop.  Also, it seems that by some sort of
agreement in the industry, the network byte order is now Bigendian, so
these conversion routines do nothing on Bigendian systems.  This means
that you can include calls to these routines in your source code, and it
will be portable between the two types of machines.

Personal opinion:

I think it's more logical to store higher order bytes into higher
addressed memories, like Little Endian.  When I perform mathematical
operations, I (along with everyone else I know of) work in Little
Endian; least significant digits to most significant digits from right
to left.  But the od utility in UNIX displays Big Endian more clearly
(from left to right), while the VMS dump utility displays Little Endian
more clearly (from right to left).

eyc

--

- Show quoted text -

Quote:>|< >|< >|< >|< >|< >|< >|< >|< >|< >|< >|< >|< >|< >|< >|< >|< >|< >|< >|<
>|<       Me:  Eugene Chu (email to chu at gt40 in domain jpl nasa gov)   >|<
>|<            Related topics only...no spammers or unsolicited e-mail    >|<
>|<       Motto:  I'm Mr. Butterfly...One's roots can be so complex...    >|<

 
 
 

1. Floating point format on DEC Unix Alpha

What 32 bits floating point format is used on Digital Alpha machines running
DEC Unix?
Is the the IEEE floating format with 1 sign bit, 8 exponent bits and 23
mantissa bits, with mantissa in binary scientific notation (same as on Intel
PCs)?

-Morten-

2. Regular Expression Validator...

3. IEEE Floating-point exceptions and traps on OSF/1.3 and Alpha

4. sound enhancements...

5. C code to convert DEC floating pt to IEEE floating pt

6. netscape 6 is driving me mad!

7. floating point representation in Alpha, Unix

8. possibility theory

9. IEEE Standard for Floating Point

10. IEEE floating-point question

11. IEEE floating point conversion needed

12. Vax <-> IEEE Floating Point Conversions?

13. VAX Floating Point to IEEE?