/*
- * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
#define _OS_OSBYTEORDER_H
#include <stdint.h>
+#include <libkern/_OSByteOrder.h>
/* Macros for swapping constant values in the preprocessing stage. */
-#define OSSwapConstInt16(x) \
- ((uint16_t)((((uint16_t)(x) & 0xff00) >> 8) | \
- (((uint16_t)(x) & 0x00ff) << 8)))
-
-#define OSSwapConstInt32(x) \
- ((uint32_t)((((uint32_t)(x) & 0xff000000) >> 24) | \
- (((uint32_t)(x) & 0x00ff0000) >> 8) | \
- (((uint32_t)(x) & 0x0000ff00) << 8) | \
- (((uint32_t)(x) & 0x000000ff) << 24)))
-
-#define OSSwapConstInt64(x) \
- ((uint64_t)((((uint64_t)(x) & 0xff00000000000000ULL) >> 56) | \
- (((uint64_t)(x) & 0x00ff000000000000ULL) >> 40) | \
- (((uint64_t)(x) & 0x0000ff0000000000ULL) >> 24) | \
- (((uint64_t)(x) & 0x000000ff00000000ULL) >> 8) | \
- (((uint64_t)(x) & 0x00000000ff000000ULL) << 8) | \
- (((uint64_t)(x) & 0x0000000000ff0000ULL) << 24) | \
- (((uint64_t)(x) & 0x000000000000ff00ULL) << 40) | \
- (((uint64_t)(x) & 0x00000000000000ffULL) << 56)))
+#define OSSwapConstInt16(x) __DARWIN_OSSwapConstInt16(x)
+#define OSSwapConstInt32(x) __DARWIN_OSSwapConstInt32(x)
+#define OSSwapConstInt64(x) __DARWIN_OSSwapConstInt64(x)
#if defined(__GNUC__)
#include <libkern/machine/OSByteOrder.h>
#endif
-#define OSSwapInt16(x) \
- (__builtin_constant_p(x) ? OSSwapConstInt16(x) : _OSSwapInt16(x))
-
-#define OSSwapInt32(x) \
- (__builtin_constant_p(x) ? OSSwapConstInt32(x) : _OSSwapInt32(x))
-
-#define OSSwapInt64(x) \
- (__builtin_constant_p(x) ? OSSwapConstInt64(x) : _OSSwapInt64(x))
-
#else /* ! __GNUC__ */
#include <libkern/machine/OSByteOrder.h>
-#define OSSwapInt16(x) OSSwapConstInt16(x)
-
-#define OSSwapInt32(x) OSSwapConstInt32(x)
-
-#define OSSwapInt64(x) OSSwapConstInt64(x)
-
#endif /* __GNUC__ */
+#define OSSwapInt16(x) __DARWIN_OSSwapInt16(x)
+#define OSSwapInt32(x) __DARWIN_OSSwapInt32(x)
+#define OSSwapInt64(x) __DARWIN_OSSwapInt64(x)
+
enum {
OSUnknownByteOrder,
OSLittleEndian,
/* Host endianess to big endian byte swapping macros for constants. */
-#define OSSwapHostToBigConstInt16(x) (x)
-#define OSSwapHostToBigConstInt32(x) (x)
-#define OSSwapHostToBigConstInt64(x) (x)
+#define OSSwapHostToBigConstInt16(x) ((uint16_t)(x))
+#define OSSwapHostToBigConstInt32(x) ((uint32_t)(x))
+#define OSSwapHostToBigConstInt64(x) ((uint64_t)(x))
/* Generic host endianess to big endian byte swapping functions. */
/* Big endian to host endianess byte swapping macros for constants. */
-#define OSSwapBigToHostConstInt16(x) (x)
-#define OSSwapBigToHostConstInt32(x) (x)
-#define OSSwapBigToHostConstInt64(x) (x)
+#define OSSwapBigToHostConstInt16(x) ((uint16_t)(x))
+#define OSSwapBigToHostConstInt32(x) ((uint32_t)(x))
+#define OSSwapBigToHostConstInt64(x) ((uint64_t)(x))
/* Generic big endian to host endianess byte swapping functions. */
/* Host endianess to little endian byte swapping macros for constants. */
-#define OSSwapHostToLittleConstInt16(x) (x)
-#define OSSwapHostToLittleConstInt32(x) (x)
-#define OSSwapHostToLittleConstInt64(x) (x)
+#define OSSwapHostToLittleConstInt16(x) ((uint16_t)(x))
+#define OSSwapHostToLittleConstInt32(x) ((uint32_t)(x))
+#define OSSwapHostToLittleConstInt64(x) ((uint64_t)(x))
/* Generic host endianess to little endian byte swapping functions. */
/* Little endian to host endianess byte swapping macros for constants. */
-#define OSSwapLittleToHostConstInt16(x) (x)
-#define OSSwapLittleToHostConstInt32(x) (x)
-#define OSSwapLittleToHostConstInt64(x) (x)
+#define OSSwapLittleToHostConstInt16(x) ((uint16_t)(x))
+#define OSSwapLittleToHostConstInt32(x) ((uint32_t)(x))
+#define OSSwapLittleToHostConstInt64(x) ((uint64_t)(x))
/* Generic little endian to host endianess byte swapping functions. */