endian.h 1.23 KB
Newer Older
lwc-tester committed
1 2 3 4 5
#ifndef ENDIAN_H_
#define ENDIAN_H_

#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__

Martin Schläffer committed
6 7 8 9
/* macros for big endian machines */
#ifndef NDEBUG
#pragma message("Using macros for big endian machines")
#endif
lwc-tester committed
10 11 12 13 14
#define U64BIG(x) (x)
#define U32BIG(x) (x)
#define U16BIG(x) (x)

#elif defined(_MSC_VER) || \
Martin Schläffer committed
15
    (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
lwc-tester committed
16

Martin Schläffer committed
17 18 19 20 21 22 23 24 25 26 27 28 29
/* macros for little endian machines */
#ifndef NDEBUG
#pragma message("Using macros for little endian machines")
#endif
#define U64BIG(x)                          \
  (((0x00000000000000FFULL & (x)) << 56) | \
   ((0x000000000000FF00ULL & (x)) << 40) | \
   ((0x0000000000FF0000ULL & (x)) << 24) | \
   ((0x00000000FF000000ULL & (x)) << 8) |  \
   ((0x000000FF00000000ULL & (x)) >> 8) |  \
   ((0x0000FF0000000000ULL & (x)) >> 24) | \
   ((0x00FF000000000000ULL & (x)) >> 40) | \
   ((0xFF00000000000000ULL & (x)) >> 56))
lwc-tester committed
30
#define U32BIG(x)                                           \
Martin Schläffer committed
31 32 33
  (((0x000000FF & (x)) << 24) | ((0x0000FF00 & (x)) << 8) | \
   ((0x00FF0000 & (x)) >> 8) | ((0xFF000000 & (x)) >> 24))
#define U16BIG(x) (((0x00FF & (x)) << 8) | ((0xFF00 & (x)) >> 8))
lwc-tester committed
34 35

#else
Martin Schläffer committed
36
#error "Ascon byte order macros not defined in endian.h"
lwc-tester committed
37 38
#endif

Martin Schläffer committed
39
#endif /* ENDIAN_H_ */