From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,ee23f835fc0eaa1c,start X-Google-Attributes: gidfee84,public From: berkley@siesta.cs.wustl.edu (Berkley Shands) Subject: SGI / DEC binary files Date: 1997/11/05 Message-ID: <63ptsl$nq4@siesta.cs.wustl.edu> X-Deja-AN: 287190561 Organization: Washington University, St. Louis MO Newsgroups: comp.unix.osf.osf1 There are two varieties of SGI, the 32 bit and the 64 bit. I will use "long" as being 64 bits wide (long long on SGI 32 or long on SGI 64). Inside the registers, int, long and double are exactly the same between the two machines. When written out to disk, or into memory, the SGI has a reversed byte order from the Alpha. If you swap the bytes around, you can read and write without problems. This is assuming you are using BINARY files. Either the SGI will have to swap or the Alpha will have to swap the byte order. If you tag the data with a byte saying who wrote it last, then only the "other" machine will have to re-order the bytes (caveat reader :-). You can avoid the issue altogether by allowing the programs to talk to each other directly (assuming that is available). See the work by Dr. Goldman et. al. http://www.cs.wustl.edu/cs/playground - Windows-NT, NetBSD, Linux, Solaris, IRIX64, OSF1 it doesn't matter. The NT software also talks to Corba and other PC interfaces with a little help. Here is the main header file we use to define machine types and "long" - /* +========================================================================+ */ /* | Playground, Copyright 1996 Washington University All Rights Reserved. | */ /* |------------------------------------------------------------------------| */ /* | FILE: CompilerDefs.hh */ /* |------------------------------------------------------------------------| */ /* | Who | Date | Implementation Modification */ /* |------------------------------------------------------------------------| */ /* | jyp | Feb 01, 97 | Initial Code Generation */ /* +========================================================================+ */ #ifndef CompilerDefs_h_ #define CompilerDefs_h_ /* */ /* list of weird definitions and other tricks needed to work around */ /* various compilers' idiosyncrasies */ /* */ /* The following pre-defined symbols are provided by the compiler */ /* _MSC_VER - Visual C++ version ID 4.2E */ /* __BCPLUSPLUS__ - Borland C++ V5.0 */ /* __SUNPRO_CC - Sun Sparcworks Pro V3.1 */ /* __DECCXX - Digital CXX V5.6 */ /* __DECCXX_VER = 50660098 (V5.6-098) */ /* __UNIX All flavors of real unix */ /* WIN32 Both flavors of Intel/MS NT4.0 */ /* __GNUG__ GNU G++ */ /* __NetBSD__ NetBSD unix */ /* __i386 used with NetBSD for Intel platforms */ /* __mips64 SGI 7.x Compilers (not pre-defined) */ /* __mips SGI systems (GNU) */ /* __linux__ Linux running on an Intel Platform */ /* Microsft C++ doesn't like throw() in template declarations! */ /* gcc is still not too good at dealing with exception signatures */ #if defined (_MSC_VER) || defined (__GNUG__) || defined (__BCPLUSPLUS__) # define NOTHROW #else # define NOTHROW throw() #endif /* */ /* dealing with naming conventions for include files */ /* */ #if defined (__cplusplus) #include #else #include #endif /* after iostream, all hell breaks loose with g++ otherwise! */ #include "bool.h" /* dealing with various representations of 64 bit longs */ /* and 32 bit integers to make sure all use the same amount of storage */ #if defined (__alpha) || defined (__LP64) || defined (__mips64) # define PGLONG64 long # define PGINT32 int # define PGUINT32 unsigned int #elif defined (__sparc) || defined (__mips) # define PGLONG64 long long # define PGINT32 long # define PGUINT32 unsigned long #elif defined (__i386) && (defined (__NetBSD__) || defined(__linux__)) # define PGLONG64 long long # define PGINT32 long # define PGUINT32 unsigned long /* defined in veneer/MissingTmpl.cxx */ ostream & operator << (ostream &, const PGLONG64 &); #elif defined (_M_IX86) # if defined (_MSC_VER) # define PGLONG64 __int64 # else # define PGLONG64 long # endif # define PGINT32 long # define PGUINT32 unsigned long /* defined in veneer/MissingTmpl.cxx */ ostream & operator << (ostream &, const PGLONG64 &); #else # error "CompilerDefs.hh; unknown compilation machine" #endif /* for gcc on Ix86 boxes, the << operator can't get the cast from */ /* PGint to PGINT64 right, so we must explicitly cast it. */ #if defined(__NetBSD__) || defined(__linux__) #define INT64FIX (PGLONG64) #else #define INT64FIX #endif #endif /* CompilerDefs_h_ */ Here is the code to swap bytes around... //+========================================================================+ //| Playground, Copyright 1996 Washington University All Rights Reserved. | //|------------------------------------------------------------------------| //| FILE: ByteSwapper.cxx //|------------------------------------------------------------------------| //| Who | Date | Implementation Modification //|------------------------------------------------------------------------| //| joeh| Apr 23, 96 | Initial Code Generation //+========================================================================+ #include #include "PGsockets.hh" #include #include #include "PGdefs.hh" #include "ByteSwapper.hh" #include "MachineTypes.hh" ByteSwapper::ByteSwapper() { } ByteSwapper::~ByteSwapper() NOTHROW { } // obtain an integer value from the stream PGLONG64 ByteSwapper::getHostOrderedData(const char machineType, const char* buffer) const { bool sameEndian_ = true; PGLONG64 number = 0; ::memcpy(&number, buffer, sizeof(PGLONG64)); switch (MachineType::getMachineType()) { case MachineType::ALPHA: case MachineType::INTEL64: case MachineType::INTEL32: switch (machineType) { case MachineType::MIPS64: case MachineType::MIPS32: case MachineType::SUN64: case MachineType::SUN32: sameEndian_ = false; break; } // switch break; case MachineType::MIPS64: case MachineType::MIPS32: case MachineType::SUN64: case MachineType::SUN32: switch (machineType) { case MachineType::ALPHA: case MachineType::INTEL64: case MachineType::INTEL32: sameEndian_ = false; break; } // switch break; } // switch if (sameEndian_) return number; // not the same flavor of machine, we must swap the bytes char* numo = (char*) &number; // destination const char* numi = buffer + 7; // source *numo++ = *numi--; // reverse byte order *numo++ = *numi--; // reverse byte order *numo++ = *numi--; // reverse byte order *numo++ = *numi--; // reverse byte order *numo++ = *numi--; // reverse byte order *numo++ = *numi--; // reverse byte order *numo++ = *numi--; // reverse byte order *numo++ = *numi--; // reverse byte order return number; } Berkley Shands