Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
* DEC Unix 4.0 IEEE floating point on Alpha
@ 1997-07-23  4:00 James Nau
  1997-07-23  4:00 ` Paul DeMone
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: James Nau @ 1997-07-23  4:00 UTC (permalink / raw)



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

james@engrs.unl.edu



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: DEC Unix 4.0 IEEE floating point on Alpha
  1997-07-23  4:00 DEC Unix 4.0 IEEE floating point on Alpha James Nau
@ 1997-07-23  4:00 ` Paul DeMone
  1997-07-24  4:00   ` Emmanuel Choquet
  1997-07-24  4:00 ` Jim Griffin
  1997-07-24  4:00 ` A.Arnold
  2 siblings, 1 reply; 9+ messages in thread
From: Paul DeMone @ 1997-07-23  4:00 UTC (permalink / raw)



James Nau wrote:
> 
> 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
> 
> james@engrs.unl.edu

--
Paul W. DeMone                 The 801 experiment SPARCed an ARMs race
Kanata, Ontario                to put more PRECISION and POWER into
demone@mosaid.com              architectures with MIPSed results but
PaulDeMone@EasyInternet.net    ALPHA's well that ends well.




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: DEC Unix 4.0 IEEE floating point on Alpha
  1997-07-23  4:00 ` Paul DeMone
@ 1997-07-24  4:00   ` Emmanuel Choquet
  0 siblings, 0 replies; 9+ messages in thread
From: Emmanuel Choquet @ 1997-07-24  4:00 UTC (permalink / raw)



Paul DeMone wrote:
> 
> James Nau wrote:
> >
> > 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
                _/
                            _/
              _/   _/_/_/  _/   _/_/_/
             _/   _/      _/   _/
            _/   _/      _/   _/_/_/
           _/   _/      _/       _/
          _/   _/_/_/  _/   _/_/_/

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



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: DEC Unix 4.0 IEEE floating point on Alpha
  1997-07-23  4:00 DEC Unix 4.0 IEEE floating point on Alpha James Nau
  1997-07-23  4:00 ` Paul DeMone
  1997-07-24  4:00 ` Jim Griffin
@ 1997-07-24  4:00 ` A.Arnold
  1997-07-24  4:00   ` fairfield
  2 siblings, 1 reply; 9+ messages in thread
From: A.Arnold @ 1997-07-24  4:00 UTC (permalink / raw)




>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;
    }
}

Alfred Arnold

--
--------------------------------------------------------------------------------
Alfred Arnold                                 Phone: +49 (2461) 61-2434
Zentralinstitut fuer Angewandte Mathematik    Fax  : +49 (2461) 61-6656
Forschungszentrum Juelich                     E-Mail: a.arnold@kfa-juelich.de
D-52425 Juelich, Germany  http://www.kfa-juelich.de/zam/ZAMPeople/arnold.html

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



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: DEC Unix 4.0 IEEE floating point on Alpha
  1997-07-24  4:00 ` A.Arnold
@ 1997-07-24  4:00   ` fairfield
  1997-07-25  4:00     ` Steve Lionel
  0 siblings, 1 reply; 9+ messages in thread
From: fairfield @ 1997-07-24  4:00 UTC (permalink / raw)



In article <5r732p$9n@zam201.zam.kfa-juelich.de>,
    	arnold@zam331.kfa-juelich.de (A.Arnold) writes:
>
>>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
--
 Kenneth H. Fairfield       |  Internet: Fairfield@Slac.Stanford.Edu
 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...



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: DEC Unix 4.0 IEEE floating point on Alpha
  1997-07-23  4:00 DEC Unix 4.0 IEEE floating point on Alpha James Nau
  1997-07-23  4:00 ` Paul DeMone
@ 1997-07-24  4:00 ` Jim Griffin
  1997-07-26  4:00   ` John Hascall
  1997-08-05  4:00   ` Eugene Y C Chu
  1997-07-24  4:00 ` A.Arnold
  2 siblings, 2 replies; 9+ messages in thread
From: Jim Griffin @ 1997-07-24  4:00 UTC (permalink / raw)



In article <5r5qt6$gd8@crcnis3.unl.edu>, james@engrs.unl.edu (James Nau) wrote:

> 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
griffin@voy.net
"You can fool all of the people some of the time ---
               and that's sufficient.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: DEC Unix 4.0 IEEE floating point on Alpha
  1997-07-24  4:00   ` fairfield
@ 1997-07-25  4:00     ` Steve Lionel
  0 siblings, 0 replies; 9+ messages in thread
From: Steve Lionel @ 1997-07-25  4:00 UTC (permalink / raw)




In article <1997Jul24.122022.1@sldb4.slac.stanford.edu>, 
fairfield@sldb4.slac.stanford.edu writes:
|>        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!)
-- 
Steve Lionel                      mailto:lionel@mail.dec.com
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



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: DEC Unix 4.0 IEEE floating point on Alpha
  1997-07-24  4:00 ` Jim Griffin
@ 1997-07-26  4:00   ` John Hascall
  1997-08-05  4:00   ` Eugene Y C Chu
  1 sibling, 0 replies; 9+ messages in thread
From: John Hascall @ 1997-07-26  4:00 UTC (permalink / raw)



Jim Griffin <griffin@voyageronline.net> wrote:
}> 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
mailto:john@iastate.edu
http://www.cc.iastate.edu/staff/systems/john/welcome.html  <-- the usual crud



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: DEC Unix 4.0 IEEE floating point on Alpha
  1997-07-24  4:00 ` Jim Griffin
  1997-07-26  4:00   ` John Hascall
@ 1997-08-05  4:00   ` Eugene Y C Chu
  1 sibling, 0 replies; 9+ messages in thread
From: Eugene Y C Chu @ 1997-08-05  4:00 UTC (permalink / raw)



In article <griffin-2407971002590001@ts-2-61.chatt.voyageronline.net>,
Jim Griffin <griffin@voyageronline.net> wrote:
>In article <5r5qt6$gd8@crcnis3.unl.edu>, james@engrs.unl.edu (James Nau) wrote:

>> 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

-- 
>|< >|< >|< >|< >|< >|< >|< >|< >|< >|< >|< >|< >|< >|< >|< >|< >|< >|< >|<
>|<	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...	>|<



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~1997-08-05  4:00 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1997-07-23  4:00 DEC Unix 4.0 IEEE floating point on Alpha James Nau
1997-07-23  4:00 ` Paul DeMone
1997-07-24  4:00   ` Emmanuel Choquet
1997-07-24  4:00 ` Jim Griffin
1997-07-26  4:00   ` John Hascall
1997-08-05  4:00   ` Eugene Y C Chu
1997-07-24  4:00 ` A.Arnold
1997-07-24  4:00   ` fairfield
1997-07-25  4:00     ` Steve Lionel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox