Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
* DEC Alpha- big endian or little endian?
@ 1996-01-29  5:00 Konstantin Olchanski
  1996-02-03  5:00 ` John McNamara
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Konstantin Olchanski @ 1996-01-29  5:00 UTC (permalink / raw)



Folks- what is the endianess of the DEC Alpha machines?

Let me try to describe my problem-

I am looking at all these great new DEC Alpha
	machines coming out with pretty damn good
	price/performance and wish we could use
	them as compute servers.

Unfortunately our applications lives in the big-endian world
	(SGIs, IBM/rs6000 and SUNs) and the Alphas
	seem to be little endian.

This is not a problem for the code itself- it is endian
	independant and was easily ported to the Alpha.

The problem is that all our data sets are written in the
	big-endian format and the little-endian version
	of our code cannot read them.

I understand that it is possible to write a
	"data converter" to covert our data between
	little-endian and big-endian representations.

This approach requires a fair amount of work
	and has some drawbacks, such as slower programs
	(if data is coverted on-the-fly) or increased
	disk space usage (if we have to keep two versions
	of the data- big-endian and little-endian).

So I am asking the DEC gurus this question- is there any
	easier way to make use on the Alphas?

Is there some magic switch that we can flip to have the machine
	run in big-endian mode?

Or maybe some hidden compiler switches to make it produce
	"big-endian" code?

DEC must have provided some kind of solution to this problem,
	since it's hard to believe that they completely locked
	themselves out of the big-endian-workstation market!



Konstantin Olchanski, olchansk@b1.phy.bnl.gov



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

* Re: DEC Alpha- big endian or little endian?
  1996-01-29  5:00 DEC Alpha- big endian or little endian? Konstantin Olchanski
@ 1996-02-03  5:00 ` John McNamara
  1996-02-04  5:00   ` bruce
  1996-02-09  5:00   ` Konstantin Olchanski
  1996-02-04  5:00 ` fairfield
  1996-02-05  5:00 ` Steve Lionel
  2 siblings, 2 replies; 7+ messages in thread
From: John McNamara @ 1996-02-03  5:00 UTC (permalink / raw)


In article <4ejjs1$2pr@sun20.ccd.bnl.gov>,
olchansk@a0.phy.bnl.gov (Konstantin Olchanski) wrote:

>Folks- what is the endianess of the DEC Alpha machines?
>
>Let me try to describe my problem-
>
[snip]
>
>The problem is that all our data sets are written in the
>        big-endian format and the little-endian version
>        of our code cannot read them.
>
>I understand that it is possible to write a
>        "data converter" to covert our data between
>        little-endian and big-endian representations.
>
>This approach requires a fair amount of work
>        and has some drawbacks, such as slower programs
>        (if data is coverted on-the-fly) or increased
>        disk space usage (if we have to keep two versions
>        of the data- big-endian and little-endian).
>
[snip]
>
>
>
>Konstantin Olchanski, olchansk@b1.phy.bnl.gov

Why not just write the few lines of code to swap bytes on
read and write?  If you're really dealing with large files,
the programs are likely memory bound in which case the few
extra logical ops to swap bytes should be essentially free.

John

-- 
John McNamara           "I am not a number, I am a free man"
jfm6@jaguNET.com                              -- No. 6



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

* Re: DEC Alpha- big endian or little endian?
  1996-01-29  5:00 DEC Alpha- big endian or little endian? Konstantin Olchanski
  1996-02-03  5:00 ` John McNamara
@ 1996-02-04  5:00 ` fairfield
  1996-02-05  5:00 ` Steve Lionel
  2 siblings, 0 replies; 7+ messages in thread
From: fairfield @ 1996-02-04  5:00 UTC (permalink / raw)


In article <4ejjs1$2pr@sun20.ccd.bnl.gov>, 
    			olchansk@a0.phy.bnl.gov (Konstantin Olchanski) writes:
> 
> Folks- what is the endianess of the DEC Alpha machines?

        Little-endian...but you knew  that  or  you  wouldn't be asking,
    right?  :-)
 
[...]
> The problem is that all our data sets are written in the
> 	big-endian format and the little-endian version
> 	of our code cannot read them.
> 
> I understand that it is possible to write a
> 	"data converter" to covert our data between
> 	little-endian and big-endian representations.

        I'm more familiar with VMS than DEC  UNUIX, but I know that what
    follows  w.r.t. VMS has its analog in DEC UNIX.  Under VMS,  Digital
    Fortran   supports   a   command   line   qualifier,   or    switch,
    /CONVERT=BIG_ENDIAN,  that  allows  you  to  tell  the  compiler  to
    automatically  convert   external   big-endian   data   to  internal
    little-endian   format   on   READ,  and  to  WRITE   the   internal
    little-endian  data  to  external  files   as   big-endian   format.
    Additionally,  there  is  an  optional keyword to the OPEN statement
    that allows  you  to  do  the  same  thing  within  your  code  on a
    file-by-file  basis.   You'll need to check the fortran man page  to
    get the syntax for UNIX, but I'd wager it's something like -convert.

        This  applies  to  Fortran,  I  don't  think  the  I/O subsystem
    functionallity   exists  for  DEC  C.   Also,  there  may  be   some
    restrictions if the data in the external file are not all  the  same
    size  (i.e.,  mixed 4- and 8-byte items).  Someone from Digital will
    have to answer that (Steve Lionel?).

        Since IEEE is the  native  Alpha floating-point format on Alpha,
    you only need to byte swap, no other conversion is required.

[...]
> Is there some magic switch that we can flip to have the machine
> 	run in big-endian mode?

        No, but the Fortran language support does...

> Or maybe some hidden compiler switches to make it produce
> 	"big-endian" code?

        ...yes, as noted above for Fortran.

        Note also that even  if  you  must  use  C,  there  is a runtime
    library  conversion  routine  (CVT$CONVERT_FLOAT on  VMS,  something
    similarly named...but shorter and lowercase on UNIX :-) which, while
    doing  floating-point  conversion,  also  supports   big-endian   to
    little-endian  conversion.  Since it's in the rtl, it will have been
    optimized for speed on the  Alpha.   Whether it would be faster than
    your  own  byte-swapping code I can't say (haven't tested  it).   It
    will definitely be slower than using the Fortrna I/O subsystem since
    you need to call it for each data item, no arrays allowed.  :-(
 
> DEC must have provided some kind of solution to this problem,
> 	since it's hard to believe that they completely locked
> 	themselves out of the big-endian-workstation market!

        Nope. :-)

            -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] 7+ messages in thread

* Re: DEC Alpha- big endian or little endian?
  1996-02-03  5:00 ` John McNamara
@ 1996-02-04  5:00   ` bruce
  1996-02-09  5:00   ` Konstantin Olchanski
  1 sibling, 0 replies; 7+ messages in thread
From: bruce @ 1996-02-04  5:00 UTC (permalink / raw)


In article <jfm6-0302962341500001@dlup-j.jagunet.com>, jfm6@jagunet.com (John McNamara) writes:
> In article <4ejjs1$2pr@sun20.ccd.bnl.gov>,
> olchansk@a0.phy.bnl.gov (Konstantin Olchanski) wrote:
> 
>>Folks- what is the endianess of the DEC Alpha machines?

Little endien, like almost all DEC machines.

>>The problem is that all our data sets are written in the
>>        big-endian format and the little-endian version
>>        of our code cannot read them.
>>
>>I understand that it is possible to write a
>>        "data converter" to covert our data between
>>        little-endian and big-endian representations.
>>
>>This approach requires a fair amount of work
>>        and has some drawbacks, such as slower programs
>>        (if data is coverted on-the-fly) or increased
>>        disk space usage (if we have to keep two versions
>>        of the data- big-endian and little-endian).
> 
> Why not just write the few lines of code to swap bytes on
> read and write?  If you're really dealing with large files,
> the programs are likely memory bound in which case the few
> extra logical ops to swap bytes should be essentially free.

This is some trouble if the data file format is anything but a simple
array of binary numbers.  For example, if the file has a long integer,
then two shorts, then another long, etc, you can't just blindly swap
bytes as if you were converting an array of long integers.  If there
are multiple record types that have to be converted in different ways
then things can get even messier.

If the code is at all reasonably organized, the read and write routines
should be isolated and the conversion can be done in them, as you said.
I've seen a lot of code that isn't, however :-).

If your compiler is decent, it should be able to generate code to
convert the data with no noticeable speed impact, unless all you're
doing is copying the data from one file to another and not actually
doing any real processing on it;  then you _might_ be able to detect
a slight slowdown, but your dominant time is almost certainly going 
to be disk I/O time.  If the original author is expecting to use the
DEC compilers, then he should have little problem in that area.

Most of the people I know about who buy workstations are not very
interested in the "endienness" of the workstation, so I'm not sure
you're talking about a very big "big-endien workstation marketplace."
But then, perhaps they have organized their code better than this code
sounds like it is organized.

Bruce C. Wright



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

* Re: DEC Alpha- big endian or little endian?
  1996-01-29  5:00 DEC Alpha- big endian or little endian? Konstantin Olchanski
  1996-02-03  5:00 ` John McNamara
  1996-02-04  5:00 ` fairfield
@ 1996-02-05  5:00 ` Steve Lionel
  2 siblings, 0 replies; 7+ messages in thread
From: Steve Lionel @ 1996-02-05  5:00 UTC (permalink / raw)



In article <4ejjs1$2pr@sun20.ccd.bnl.gov>, olchansk@a0.phy.bnl.gov 
(Konstantin Olchanski) writes:
|>
|>Folks- what is the endianess of the DEC Alpha machines?

Digital's Alpha systems are little-endian.  (The Alpha processor can be
used in either little-endian or big-endian modes, but as far as I know, the
big-endian mode has been used only in certain Cray products using Alpha
chips.)

DEC Fortran has a -convert big_endian compile switch which will cause data
to be converted automatically during unformatted I/O.  
-- 

Steve Lionel                      Mail: lionel@quark.enet.dec.com
Fortran Development               WWW:  http://www.digital.com/info/slionel.html
Digital Equipment Corporation     CompuServe: 75263,3001
110 Spit Brook Road, ZKO2-3/N30
Nashua, NH 03062-2698             "Free advice is worth every cent"

For information on Digital Fortran 90, see http://www.digital.com/info/hpc/f90/



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

* Re: DEC Alpha- big endian or little endian?
  1996-02-03  5:00 ` John McNamara
  1996-02-04  5:00   ` bruce
@ 1996-02-09  5:00   ` Konstantin Olchanski
  1996-02-16  5:00     ` bruce
  1 sibling, 1 reply; 7+ messages in thread
From: Konstantin Olchanski @ 1996-02-09  5:00 UTC (permalink / raw)


In article <jfm6-0302962341500001@dlup-j.jagunet.com>, jfm6@jagunet.com (John McNamara) writes:
> In article <4ejjs1$2pr@sun20.ccd.bnl.gov>,
> olchansk@a0.phy.bnl.gov (Konstantin Olchanski) wrote:
> >
> >The problem is that all our data sets are written in the
> >        big-endian format and the little-endian version
> >        of our code cannot read them.
> 
> Why not just write the few lines of code to swap bytes on
> read and write?  If you're really dealing with large files,
> the programs are likely memory bound in which case the few
> extra logical ops to swap bytes should be essentially free.


"just swapping bytes" gets somewhat complicated if the data
	is a horrible mix of ints, shorts and chars...


but, I guess there is no other way... 

I am considering writing
	a program in perl to read the C header files
	and automatically produce endian-changing routines.
	Maybe somebody already did this? Any suggestions?


C.O.



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

* Re: DEC Alpha- big endian or little endian?
  1996-02-09  5:00   ` Konstantin Olchanski
@ 1996-02-16  5:00     ` bruce
  0 siblings, 0 replies; 7+ messages in thread
From: bruce @ 1996-02-16  5:00 UTC (permalink / raw)


In article <4ffml4$fb2@sun20.ccd.bnl.gov>, olchansk@a0.phy.bnl.gov (Konstantin Olchanski) writes:
> In article <jfm6-0302962341500001@dlup-j.jagunet.com>, jfm6@jagunet.com (John McNamara) writes:
>> In article <4ejjs1$2pr@sun20.ccd.bnl.gov>,
>> olchansk@a0.phy.bnl.gov (Konstantin Olchanski) wrote:
>> >
>> >The problem is that all our data sets are written in the
>> >        big-endian format and the little-endian version
>> >        of our code cannot read them.
>> 
>> Why not just write the few lines of code to swap bytes on
>> read and write?  If you're really dealing with large files,
>> the programs are likely memory bound in which case the few
>> extra logical ops to swap bytes should be essentially free.
> 
> "just swapping bytes" gets somewhat complicated if the data
> 	is a horrible mix of ints, shorts and chars...
> 
> but, I guess there is no other way... 
> 
> I am considering writing
> 	a program in perl to read the C header files
> 	and automatically produce endian-changing routines.
> 	Maybe somebody already did this? Any suggestions?

I don't have anything to read the .h files and produce code to extract
data from the structs, though I doubt that such a thing would be very
difficult to produce.  I do have some macros that make converting
between the two representations a bit less painful.  The following is
cut with a few modifications from a header file used by a fairly large
project that runs on a variety of architectures of varying word sizes
and on big and little endien machines.  Note that this does NOT deal
with IEEE or VAX-format floating point issues;  that program does not
use floats in its binary files.  You will also notice that the macros
are rather "little-endien-centric" in that they assume that the data
require no conversion on little endien machines;  your definitions of
the EXTRACT_* macros would have to have the opposite #ifdef.  Beware also
that the macros are "fragile" in the sense that you cannot use arguments
with side effects, e.g., EXTRACT_WORD(*p++) is a no-no;  in this way
they are similar to the usual macro definitions of max and min which are
also fragile.

#ifdef _ALPHA
#define	WORD16	short
#define	LONG32	int
#else
#define	WORD16	short
#define LONG32	long
#endif

typedef unsigned char	BYTE;
typedef unsigned WORD16	WORD;
typedef unsigned LONG32	DWORD;

#define LOBYTE(w)	((BYTE)(w))
#define HIBYTE(w)	((BYTE)(((UINT)(w) >> 8) & 0xff))
#define LOWORD(l)	((WORD)(DWORD)(l))
#define HIWORD(l)	((WORD)((((DWORD)(l)) >> 16) & 0xffff))

#ifdef LITTLE_ENDIEN
#define EXTRACT_WORD(w)	(w)
#define EXTRACT_LONG(l)	(l)
#else
#define EXTRACT_WORD(w)	((LOBYTE(w)<<8) | HIBYTE(w))
#define EXTRACT_LONG(l)	((EXTRACT_WORD(LOWORD(l))<<16)|EXTRACT_WORD(HIWORD(l)))
#endif

You can also swap bytes by extracting the high and low bytes and moving
them into an array of bytes, then reading it out as a word or long word
as appropriate, but on most architectures that's probably not as efficient
unless the compiler is smart enough to spot what you're doing.

Good luck,

Bruce C. Wright



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

end of thread, other threads:[~1996-02-16  5:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1996-01-29  5:00 DEC Alpha- big endian or little endian? Konstantin Olchanski
1996-02-03  5:00 ` John McNamara
1996-02-04  5:00   ` bruce
1996-02-09  5:00   ` Konstantin Olchanski
1996-02-16  5:00     ` bruce
1996-02-04  5:00 ` fairfield
1996-02-05  5: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