-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Assuming big-endian relative jumptables for PPC
- Loading branch information
Alexandro Sanchez Bach
committed
Jun 29, 2017
1 parent
f0dd31d
commit 8d7f1e6
Showing
4 changed files
with
115 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#include "endian.h" | ||
|
||
/* Detect host endianness */ | ||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ | ||
#define NUCLEUS_HOST_LE | ||
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ | ||
#define NUCLEUS_HOST_BE | ||
#endif | ||
|
||
/* Endian swap */ | ||
#define SWAP_16(x) ( \ | ||
(((x) >> 8) & 0x00FF) | (((x) << 8) & 0xFF00) \ | ||
) | ||
#define SWAP_32(x) ( \ | ||
(((x) >> 24) & 0x000000FF) | (((x) >> 8) & 0x0000FF00) | \ | ||
(((x) << 8) & 0x00FF0000) | (((x) << 24) & 0xFF000000) \ | ||
) | ||
#define SWAP_64(x) ( \ | ||
(((x) >> 56) & 0x00000000000000FF) | (((x) >> 40) & 0x000000000000FF00) | \ | ||
(((x) >> 24) & 0x0000000000FF0000) | (((x) >> 8) & 0x00000000FF000000) | \ | ||
(((x) << 8) & 0x000000FF00000000) | (((x) << 24) & 0x0000FF0000000000) | \ | ||
(((x) << 40) & 0x00FF000000000000) | (((x) << 56) & 0xFF00000000000000) \ | ||
) | ||
|
||
|
||
/* Little-Endian reads */ | ||
uint16_t read_le_i16(const uint16_t* data) | ||
{ | ||
uint16_t value = *data; | ||
#if defined(NUCLEUS_HOST_LE) | ||
return value; | ||
#elif defined(NUCLEUS_HOST_BE) | ||
return SWAP_16(value); | ||
#endif | ||
} | ||
|
||
uint32_t read_le_i32(const uint32_t* data) | ||
{ | ||
uint32_t value = *data; | ||
#if defined(NUCLEUS_HOST_LE) | ||
return value; | ||
#elif defined(NUCLEUS_HOST_BE) | ||
return SWAP_32(value); | ||
#endif | ||
} | ||
|
||
uint64_t read_le_i64(const uint64_t* data) | ||
{ | ||
uint64_t value = *data; | ||
#if defined(NUCLEUS_HOST_LE) | ||
return value; | ||
#elif defined(NUCLEUS_HOST_BE) | ||
return SWAP_64(value); | ||
#endif | ||
} | ||
|
||
|
||
/* Big-Endian reads */ | ||
uint16_t read_be_i16(const uint16_t* data) | ||
{ | ||
uint16_t value = *data; | ||
#if defined(NUCLEUS_HOST_BE) | ||
return value; | ||
#elif defined(NUCLEUS_HOST_LE) | ||
return SWAP_16(value); | ||
#endif | ||
} | ||
|
||
uint32_t read_be_i32(const uint32_t* data) | ||
{ | ||
uint32_t value = *data; | ||
#if defined(NUCLEUS_HOST_BE) | ||
return value; | ||
#elif defined(NUCLEUS_HOST_LE) | ||
return SWAP_32(value); | ||
#endif | ||
} | ||
|
||
uint64_t read_be_i64(const uint64_t* data) | ||
{ | ||
uint64_t value = *data; | ||
#if defined(NUCLEUS_HOST_BE) | ||
return value; | ||
#elif defined(NUCLEUS_HOST_LE) | ||
return SWAP_64(value); | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#ifndef NUCLEUS_ENDIAN_H | ||
#define NUCLEUS_ENDIAN_H | ||
|
||
#include <stdint.h> | ||
|
||
uint16_t read_le_i16(const uint16_t* data); | ||
uint32_t read_le_i32(const uint32_t* data); | ||
uint64_t read_le_i64(const uint64_t* data); | ||
|
||
uint16_t read_be_i16(const uint16_t* data); | ||
uint32_t read_be_i32(const uint32_t* data); | ||
uint64_t read_be_i64(const uint64_t* data); | ||
|
||
#endif /* NUCLEUS_ENDIAN_H */ |