changed to use osdWireConfig.h def of EPICS_BYTE_ORDER and EPICS_FLOAT_WORD_ORDER

This commit is contained in:
Jeff Hill
2007-08-27 22:13:39 +00:00
parent 0154bf5388
commit c9722c3061
+44 -72
View File
@@ -31,6 +31,8 @@
# include <cstring>
#endif
#include "osdWireConfig.h"
//
// The default assumption is that the local floating point format is
// IEEE and that these routines only need to perform byte swapping
@@ -39,55 +41,25 @@
// for this file if that assumption is wrong.
//
//
// Here are the definitions for architecture dependent byte ordering
// and floating point format.
//
// Perhaps the definition of EPICS_BIG_ENDIAN, EPICS_LITTLE_ENDIAN,
// and EPICS_32107654_FP_ENDIAN should be left to the build system
// so that this file need not be modified when adding support for a
// new architecture?
//
#if defined (_M_IX86) || defined (_X86_) || defined (__i386__) || defined (_X86_64_) || defined (_M_AMD64)
# define EPICS_LITTLE_ENDIAN
#elif ( defined (__ALPHA) || defined (__alpha) )
# define EPICS_LITTLE_ENDIAN
#elif defined (__arm__)
# define EPICS_LITTLE_ENDIAN
#else
# define EPICS_BIG_ENDIAN
#ifndef EPICS_BYTE_ORDER
#error osdWireConfig.h didnt define EPICS_BYTE_ORDER
#endif
#ifndef EPICS_FLOAT_WORD_ORDER
#error osdWireConfig.h didnt define EPICS_FLOAT_WORD_ORDER
#endif
//
// EPICS_CONVERSION_REQUIRED is set if either the byte order
// or the floating point are not exactly big endian and ieee fp.
// or the floating point word order are not exactly big endian.
// This can be set by hand above for a specific architecture
// should there be an architecture that is a weird middle endian
// ieee floating point format that is also big endian integer.
//
#if ! defined ( EPICS_BIG_ENDIAN ) && ! defined ( EPICS_CONVERSION_REQUIRED )
# define EPICS_CONVERSION_REQUIRED
#endif
//
// some architecture sanity checks
//
#if defined(EPICS_BIG_ENDIAN) && defined(EPICS_LITTLE_ENDIAN)
# error defined(EPICS_BIG_ENDIAN) && defined(EPICS_LITTLE_ENDIAN)
#endif
#if !defined(EPICS_BIG_ENDIAN) && !defined(EPICS_LITTLE_ENDIAN)
# error !defined(EPICS_BIG_ENDIAN) && !defined(EPICS_LITTLE_ENDIAN)
#endif
//
// The ARM supports two different floating point architectures, the
// original and a more recent "vector" format. The original FPU is
// emulated by the Netwinder library and, in little endian mode, has
// the two words in the opposite order to that which would otherwise
// be expected! The vector format is identical to IEEE.
//
#if defined (_ARM_NWFP_)
# define EPICS_32107654_FP_ENDIAN
#if EPICS_BYTE_ORDER != EPICS_ENDIAN_BIG || EPICS_FLOAT_WORD_ORDER != EPICS_BYTE_ORDER
# if ! defined ( EPICS_CONVERSION_REQUIRED )
# define EPICS_CONVERSION_REQUIRED
# endif
#endif
//
@@ -106,14 +78,14 @@ inline void WireGet < epicsFloat64 > (
epicsFloat64 _f;
epicsUInt32 _u[2];
} tmp;
# if defined ( EPICS_BIG_ENDIAN ) || defined ( EPICS_32107654_FP_ENDIAN )
WireGet ( pWireSrc, tmp._u[0] );
WireGet ( pWireSrc + 4, tmp._u[1] );
# elif defined ( EPICS_LITTLE_ENDIAN )
# if EPICS_FLOAT_WORD_ORDER == EPICS_ENDIAN_LITTLE
WireGet ( pWireSrc, tmp._u[1] );
WireGet ( pWireSrc + 4, tmp._u[0] );
# elif EPICS_FLOAT_WORD_ORDER == EPICS_ENDIAN_BIG
WireGet ( pWireSrc, tmp._u[0] );
WireGet ( pWireSrc + 4, tmp._u[1] );
# else
# error undefined endian type
# error unsupported floating point word order
# endif
dst = tmp._f;
}
@@ -145,14 +117,14 @@ inline void WireSet < epicsFloat64 > (
epicsUInt32 _u[2];
} tmp;
tmp._f = src;
# if defined ( EPICS_BIG_ENDIAN ) || defined ( EPICS_32107654_FP_ENDIAN )
WireSet ( tmp._u[0], pWireDst );
WireSet ( tmp._u[1], pWireDst + 4 );
# elif defined ( EPICS_LITTLE_ENDIAN )
# if EPICS_FLOAT_WORD_ORDER == EPICS_ENDIAN_LITTLE
WireSet ( tmp._u[1], pWireDst );
WireSet ( tmp._u[0], pWireDst + 4 );
# elif EPICS_FLOAT_WORD_ORDER == EPICS_ENDIAN_BIG
WireSet ( tmp._u[0], pWireDst );
WireSet ( tmp._u[1], pWireDst + 4 );
# else
# error undefined endian type
# error unsupported floating point word order
# endif
}
@@ -175,12 +147,12 @@ template <>
inline void AlignedWireGet < epicsUInt16 > (
const epicsUInt16 & src, epicsUInt16 & dst )
{
# if defined ( EPICS_LITTLE_ENDIAN )
# if EPICS_BYTE_ORDER == EPICS_ENDIAN_LITTLE
dst = byteSwap ( src );
# elif defined ( EPICS_BIG_ENDIAN )
# elif EPICS_BYTE_ORDER == EPICS_ENDIAN_BIG
dst = src;
# else
# error undefined endian type
# error unsupported endian type
# endif
}
@@ -188,12 +160,12 @@ template <>
inline void AlignedWireGet < epicsUInt32 > (
const epicsUInt32 & src, epicsUInt32 & dst )
{
# if defined ( EPICS_LITTLE_ENDIAN )
# if EPICS_BYTE_ORDER == EPICS_ENDIAN_LITTLE
dst = byteSwap ( src );
# elif defined ( EPICS_BIG_ENDIAN )
# elif EPICS_BYTE_ORDER == EPICS_ENDIAN_BIG
dst = src;
# else
# error undefined endian type
# error unsupported endian type
# endif
}
@@ -201,29 +173,29 @@ template <>
inline void AlignedWireGet < epicsFloat64 > (
const epicsFloat64 & src, epicsFloat64 & dst )
{
// copy through union here
// copy through union here
// a) prevents over-aggressive optimization under strict aliasing rules
// b) doesnt preclude extra copy operation being optimized away
union Swapper {
epicsUInt32 _u[2];
epicsFloat64 _f;
};
# if defined ( EPICS_32107654_FP_ENDIAN )
# if EPICS_BYTE_ORDER == EPICS_ENDIAN_BIG && EPICS_FLOAT_WORD_ORDER == EPICS_BYTE_ORDER
dst = src;
# elif EPICS_FLOAT_WORD_ORDER == EPICS_ENDIAN_BIG
Swapper tmp;
tmp._f = src;
AlignedWireGet ( tmp._u[0], tmp._u[0] );
AlignedWireGet ( tmp._u[1], tmp._u[1] );
dst = tmp._f;
# elif defined ( EPICS_LITTLE_ENDIAN )
# elif EPICS_FLOAT_WORD_ORDER == EPICS_ENDIAN_LITTLE
Swapper srcu, dstu;
srcu._f = src;
AlignedWireGet ( srcu._u[1], dstu._u[0] );
AlignedWireGet ( srcu._u[0], dstu._u[1] );
dst = dstu._f;
# elif defined ( EPICS_BIG_ENDIAN )
dst = src;
# else
# error undefined endian type
# error unsupported floating point word order
# endif
}
@@ -231,9 +203,9 @@ template <>
inline void AlignedWireSet < epicsUInt16 >
( const epicsUInt16 & src, epicsUInt16 & dst )
{
# if defined ( EPICS_LITTLE_ENDIAN )
# if EPICS_BYTE_ORDER == EPICS_ENDIAN_LITTLE
dst = byteSwap ( src );
# elif defined ( EPICS_BIG_ENDIAN )
# elif EPICS_BYTE_ORDER == EPICS_ENDIAN_BIG
dst = src;
# else
# error undefined endian type
@@ -244,9 +216,9 @@ template <>
inline void AlignedWireSet < epicsUInt32 > (
const epicsUInt32 & src, epicsUInt32 & dst )
{
# if defined ( EPICS_LITTLE_ENDIAN )
# if EPICS_BYTE_ORDER == EPICS_ENDIAN_LITTLE
dst = byteSwap ( src );
# elif defined ( EPICS_BIG_ENDIAN )
# elif EPICS_BYTE_ORDER == EPICS_ENDIAN_BIG
dst = src;
# else
# error undefined endian type
@@ -264,22 +236,22 @@ inline void AlignedWireSet < epicsFloat64 > (
epicsUInt32 _u[2];
epicsFloat64 _f;
};
# if defined ( EPICS_32107654_FP_ENDIAN )
# if EPICS_BYTE_ORDER == EPICS_ENDIAN_BIG && EPICS_FLOAT_WORD_ORDER == EPICS_BYTE_ORDER
dst = src;
# elif EPICS_FLOAT_WORD_ORDER == EPICS_ENDIAN_BIG
Swapper tmp;
tmp._f = src;
AlignedWireSet ( tmp._u[0], tmp._u[0] );
AlignedWireSet ( tmp._u[1], tmp._u[1] );
dst = tmp._f;
# elif defined ( EPICS_LITTLE_ENDIAN )
# elif EPICS_FLOAT_WORD_ORDER == EPICS_ENDIAN_LITTLE
Swapper srcu, dstu;
srcu._f = src;
AlignedWireSet ( srcu._u[1], dstu._u[0] );
AlignedWireSet ( srcu._u[0], dstu._u[1] );
dst = dstu._f;
# elif defined ( EPICS_BIG_ENDIAN )
dst = src;
# else
# error undefined endian type
# error unsupported floating point word order
# endif
}