RetroArch/rarchdb/rarchdb_endian.h

35 lines
1.0 KiB
C
Raw Normal View History

2014-12-30 21:02:15 +01:00
#ifndef __RARCHDB_MSGPACK_ENDIAN_H
#define __RARCHDB_MSGPACK_ENDIAN_H
#include <stdint.h>
#include <retro_endianness.h>
2014-12-30 21:02:15 +01:00
2014-12-30 21:17:34 +01:00
#ifndef swap16
2014-12-30 21:02:15 +01:00
#define swap16(val) \
((((uint16_t)(val) & 0x00ff) << 8) \
| (((uint16_t)(val) & 0xff00) >> 8))
2014-12-30 21:17:34 +01:00
#endif
2014-12-30 21:02:15 +01:00
2014-12-30 21:17:34 +01:00
#ifndef swap64
2014-12-30 21:02:15 +01:00
#define swap64(val) \
((((uint64_t)(val) & 0x00000000000000ffULL) << 56) \
| (((uint64_t)(val) & 0x000000000000ff00ULL) << 40) \
| (((uint64_t)(val) & 0x0000000000ff0000ULL) << 24) \
| (((uint64_t)(val) & 0x00000000ff000000ULL) << 8) \
| (((uint64_t)(val) & 0x000000ff00000000ULL) >> 8) \
| (((uint64_t)(val) & 0x0000ff0000000000ULL) >> 24) \
| (((uint64_t)(val) & 0x00ff000000000000ULL) >> 40) \
| (((uint64_t)(val) & 0xff00000000000000ULL) >> 56))
2014-12-30 21:17:34 +01:00
#endif
2014-12-30 21:02:15 +01:00
#define httobe64(x) (is_little_endian() ? swap64(x) : (x))
2014-12-30 21:45:03 +01:00
#define httobe32(x) (is_little_endian() ? SWAP32(x) : (x))
2014-12-30 21:02:15 +01:00
#define httobe16(x) (is_little_endian() ? swap16(x) : (x))
#define betoht16(x) httobe16(x)
#define betoht32(x) httobe32(x)
#define betoht64(x) httobe64(x)
#endif