GLAST / LAT > DAQ and FSW > FSW > Doxygen Index> PBI / dev > doc_gather / linux-gcc


Interface   Data Structures   File List   Data Fields   Globals  

Unions.h File Reference

Defines a set of useful unions between long long, ints, shorts and chars (bytes) which allow one to access subfields in a consistent fashion across big and little endian machines. More...

#include <PBI/Endianness.h>
#include <UNIONS_BIG_LITTLE>

Classes

union  _U_byte
 Accesses an 8 bit quantity as both a signed and unsigned byte. More...
struct  _U_short_as_bytes
 Internal structure which sets the ordering for assessing the bytes within a short. More...
struct  _U_int_as_shorts
 Internal structure which sets the ordering for assessing the shorts within an int. More...
struct  _U_longlong_as_ints
 Internal structure which sets the ordering for assessing the ints within a long long int. More...
union  _U_short
 Accesses a 16 bit quantity as narrower integer types (chars). More...
union  _U_int
 Accesses a 32 bit quantity as narrower integer types (shorts and chars). More...
union  _U_longlong
 Accesses a 64 bit quantity as narrower integer types (ints, shorts and chars). More...

Defines

#define _UNIONS_SHORT_AS_BYTES
 Internal use only.
#define U_PACK_SHORT_WITH_BYTES(_hi, _lo)   ((((_hi)&0xff) << 8) | (((_lo)&0xff) << 0))
 Packs a short with the numerically high and low bytes.
#define U_UNPACK_SHORT_LO_BYTE(_us)   ((unsigned char)(_us))
 Extracts the numerically least significant byte from a short.
#define U_UNPACK_SHORT_HI_BYTE(_us)   ((unsigned char)((_us) >> 8))
 Extracts the numerically most significant byte from a short.
#define _UNIONS_INT_AS_SHORTS
 Internal use only.
#define U_PACK_INT_WITH_SHORTS(_hi, _lo)   ((((_hi)&0xffff) << 16) | (((_lo)&0xffff) << 0))
 Packs an int with the numerically high and low shorts.
#define U_PACK_INT_WITH_BYTES(_3, _2, _1, _0)
 Packs an int with the 4 bytes, specified in order from the numerically most significant byte (_3) to the numerically least signicant byte (_0).
#define U_UNPACK_INT_LO_SHORT(_ui)   ((unsigned short)(_ui))
 Extracts the numerically least significant short from an int.
#define U_UNPACK_INT_HI_SHORT(_ui)   ((unsigned short)((_ui) >> 16))
 Extracts the numerically most significant short from an int.
#define _UNIONS_LONGLONG_AS_INTS
 Internal use only.
#define U_PACK_LL_WITH_INTS(_hi, _lo)
 Packs a long long int with the numerically high and low ints.
#define U_UNPACK_LL_HI_INT(_ull)   ((unsigned int)((_ull) >> 32))
 Extracts the numerically most significant int from a long long int.
#define U_PACK_LL_WITH_SHORTS(_3, _2, _1, _0)
 Packs a long long int with 4 shorts, specified in order from the numerically most significant short (_3) to the numerically least signicant short (_0).
#define U_PACK_LL_WITH_BYTES(_7, _6, _5, _4, _3, _2, _1, _0)
 Packs a long long int with 8 bytes, specified in order from the numerically most significant byte (_7) to the numerically least signicant byte (_0).
#define U_UNPACK_LL_LO_INT(_ull)   ((unsigned int)(_ull))
 Extracts the numerically least significant int from a long long.

Typedefs

typedef union _U_byte U_byte
 Typedef for union _U_byte.
typedef struct _U_short_as_bytes U_short_as_bytes
 Typedef for union _U_short_as_bytes.
typedef struct _U_int_as_shorts U_int_as_shorts
 Typedef for union _U_int_as_shorts.
typedef struct _U_longlong_as_ints U_longlong_as_ints
 Typedef for union _U_longlong_as_ints.
typedef union _U_short U_short
 Typedef for union _U_short.
typedef union _U_int U_int
 Typedef for union _U_int.
typedef union _U_longlong U_longlong
 Typedef for union _U_longlong.


Detailed Description

Defines a set of useful unions between long long, ints, shorts and chars (bytes) which allow one to access subfields in a consistent fashion across big and little endian machines.

Author:
JJRussell - russell@slac.stanford.edu
  CVS $Id: Unions.h,v 1.5 2011/03/24 20:50:58 apw Exp $

DESCRIPTION
Many times one needs to access a subfield of large value. For example, extracting the most significant 32 bits of a 64 bit number. Unfortunately, this extraction is dependent of the endianness of the machine. The unions and macros defined in here allow one t uniformly do this extraction.
USAGE
The user has two choices in the packing and unpacking. The first is to use a set of unions to load the wider type or assess narrower types. The unions are completely general, allowing assess to any narrower type contained within the wider type. This generality comes at the expense of verbosity, which some would interpret as overly complex. In the simple and often needed case of assessing only the hi or lo halves, for example the hi or lo 32 bits of a long long int, a series of less general purpose, but easier to use macros are provided. These are of the form:
One of the big problems here is one of language. There are two concepts of ordering; one by where the bits representing the least signficant digits (in a numerical sense) live and the other relating to their layout in memory. On little endian machines, these are the same. On big endian machines, the bits containing the least significant digits live in the highest addresses. Indeed, this is the problem these unions are trying to solve.
TARGET PLATFORMS
All FSW supported platforms.

Define Documentation

#define U_PACK_INT_WITH_BYTES ( _3,
_2,
_1,
_0   ) 

Value:

Packs an int with the 4 bytes, specified in order from the numerically most significant byte (_3) to the numerically least signicant byte (_0).

Parameters:
_3 The numerically most significant byte
_2 The numericallly second most significant byte
_1 The numericallly third most significant byte
_0 The numerically least significant byte
Returns:
The packed integer

#define U_PACK_INT_WITH_SHORTS ( _hi,
_lo   )     ((((_hi)&0xffff) << 16) | (((_lo)&0xffff) << 0))

Packs an int with the numerically high and low shorts.

Parameters:
_hi The numerically most significant short
_lo The numerically least significant short
Returns:
The packed integer

#define U_PACK_LL_WITH_BYTES ( _7,
_6,
_5,
_4,
_3,
_2,
_1,
_0   ) 

Value:

Packs a long long int with 8 bytes, specified in order from the numerically most significant byte (_7) to the numerically least signicant byte (_0).

Parameters:
_7 The numerically most significant byte
_6 The numericallly second most significant byte
_5 The numericallly third most significant byte
_4 The numerically fourth most significant byte
_3 The numerically fifth most significant byte
_2 The numericallly sixth most significant byte
_1 The numericallly seventh most significant byte
_0 The numerically least significant byte
Returns:
The packed long long integer

#define U_PACK_LL_WITH_INTS ( _hi,
_lo   ) 

Value:

((((((unsigned long long)(_hi))&0xffffffff)) << 32) |          \
                              ((((_lo) &0xffffffff) <<  0)))
Packs a long long int with the numerically high and low ints.

Parameters:
_hi The numerically most significant int
_lo The numerically least significant int
Returns:
The packed long long integer

#define U_PACK_LL_WITH_SHORTS ( _3,
_2,
_1,
_0   ) 

Value:

Packs a long long int with 4 shorts, specified in order from the numerically most significant short (_3) to the numerically least signicant short (_0).

Parameters:
_3 The numerically most significant short
_2 The numericallly second most significant short
_1 The numericallly third most significant short
_0 The numerically least significant short
Returns:
The packed long long integer

#define U_PACK_SHORT_WITH_BYTES ( _hi,
_lo   )     ((((_hi)&0xff) << 8) | (((_lo)&0xff) << 0))

Packs a short with the numerically high and low bytes.

Parameters:
_hi The numerically most significant byte
_lo The numerically least significant byte
Returns:
The packed short integer

#define U_UNPACK_INT_HI_SHORT ( _ui   )     ((unsigned short)((_ui) >> 16))

Extracts the numerically most significant short from an int.

Parameters:
_ui The int to extract the short from
Returns:
The numerically most significant short.

#define U_UNPACK_INT_LO_SHORT ( _ui   )     ((unsigned short)(_ui))

Extracts the numerically least significant short from an int.

Parameters:
_ui The int to extract the short from
Returns:
The numerically least significant short.

#define U_UNPACK_LL_HI_INT ( _ull   )     ((unsigned int)((_ull) >> 32))

Extracts the numerically most significant int from a long long int.

Parameters:
_ull The long long to extract the int from
Returns:
The numerically most significant int.

#define U_UNPACK_LL_LO_INT ( _ull   )     ((unsigned int)(_ull))

Extracts the numerically least significant int from a long long.

Parameters:
_ull The long long to extract the int from
Returns:
The numerically least significant int.

#define U_UNPACK_SHORT_HI_BYTE ( _us   )     ((unsigned char)((_us) >> 8))

Extracts the numerically most significant byte from a short.

Parameters:
_us The short to extract the byte from
Returns:
The numerically most significant byte.

#define U_UNPACK_SHORT_LO_BYTE ( _us   )     ((unsigned char)(_us))

Extracts the numerically least significant byte from a short.

Parameters:
_us The short to extract the byte from
Returns:
The numerically least significant byte.


Typedef Documentation

Typedef for union _U_int.

The 32 bits can be assessed as

  1. signed and unsigned ints
  2. hi and lo signed and unsigned 16 bit integers
  3. hi and lo signed and unsigned 8 bit chars within each of the hi and lo 16 bit shorts.

Typedef for union _U_longlong.

The 64 bits can be assessed as

  1. signed and unsigned long longs
  2. hi and lo signed and unsigned 32 bit integers
  3. hi and lo signed and unsigned 16 bit shorts within each of the hi and lo 32 bit integers
  4. hi and lo signed and unsigned 8 bit chars within each of the hi and lo 16 bit shorts.

Typedef for union _U_short.

The 16 bits can be assessed as

  1. signed and unsigned shorts
  2. hi and lo signed and unsigned 8 bit chars within each of the hi and lo 16 bit shorts.


Generated on Thu Aug 4 14:20:46 2011 by  doxygen 1.5.8