2021-10-25 13:43:19 +00:00
|
|
|
|
|
|
|
#include "byte_order.h"
|
|
|
|
|
2019-03-29 14:44:55 +00:00
|
|
|
static inline uint32_t load32(const void *src) {
|
|
|
|
uint32_t w;
|
|
|
|
memcpy(&w, src, sizeof w);
|
2021-10-25 13:43:19 +00:00
|
|
|
#if BYTE_ORDER == BIG_ENDIAN
|
|
|
|
REVERSE32(w, w);
|
|
|
|
#endif
|
2019-03-29 14:44:55 +00:00
|
|
|
return w;
|
2017-02-28 17:14:54 +00:00
|
|
|
}
|
|
|
|
|
2019-03-29 14:44:55 +00:00
|
|
|
static inline uint64_t load64(const void *src) {
|
2017-02-28 17:14:54 +00:00
|
|
|
uint64_t w;
|
|
|
|
memcpy(&w, src, sizeof w);
|
2021-10-25 13:43:19 +00:00
|
|
|
#if BYTE_ORDER == BIG_ENDIAN
|
|
|
|
REVERSE64(w, w);
|
|
|
|
#endif
|
2017-02-28 17:14:54 +00:00
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
2019-03-29 14:44:55 +00:00
|
|
|
static inline void store16(void *dst, uint16_t w) { memcpy(dst, &w, sizeof w); }
|
2017-02-28 17:14:54 +00:00
|
|
|
|
2021-10-25 13:43:19 +00:00
|
|
|
static inline void store32(void *dst, uint32_t w) {
|
|
|
|
#if BYTE_ORDER == BIG_ENDIAN
|
|
|
|
REVERSE32(w, w);
|
|
|
|
#endif
|
|
|
|
memcpy(dst, &w, sizeof w);
|
|
|
|
}
|
2017-02-28 17:14:54 +00:00
|
|
|
|
2021-10-25 13:43:19 +00:00
|
|
|
static inline void store64(void *dst, uint64_t w) {
|
|
|
|
#if BYTE_ORDER == BIG_ENDIAN
|
|
|
|
REVERSE64(w, w);
|
|
|
|
#endif
|
|
|
|
memcpy(dst, &w, sizeof w);
|
|
|
|
}
|
2017-02-28 17:14:54 +00:00
|
|
|
|
2019-03-29 14:44:55 +00:00
|
|
|
static inline uint32_t rotr32(const uint32_t w, const unsigned c) {
|
|
|
|
return (w >> c) | (w << (32 - c));
|
2017-02-28 17:14:54 +00:00
|
|
|
}
|
|
|
|
|
2019-03-29 14:44:55 +00:00
|
|
|
static inline uint64_t rotr64(const uint64_t w, const unsigned c) {
|
|
|
|
return (w >> c) | (w << (64 - c));
|
2017-02-28 17:14:54 +00:00
|
|
|
}
|