From 1c54bc5674a54d84112da5191c28a745d448c816 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Mon, 2 Jan 2017 23:02:48 -0800 Subject: Add NNI_GET32, NNI_PUT32 macros. --- src/core/defs.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/core') diff --git a/src/core/defs.h b/src/core/defs.h index e44be1ec..1114704d 100644 --- a/src/core/defs.h +++ b/src/core/defs.h @@ -44,4 +44,18 @@ typedef int64_t nni_duration; // Relative time (usec). #define NNI_ALLOC_STRUCT(s) nni_alloc(sizeof (*s)) #define NNI_FREE_STRUCT(s) nni_free((s), sizeof (*s)) +#define NNI_PUT32(ptr, u) \ + do { \ + ptr[0] = (uint8_t)(((uint32_t)u) >> 24); \ + ptr[1] = (uint8_t)(((uint32_t)u) >> 16); \ + ptr[2] = (uint8_t)(((uint32_t)u) >> 8); \ + ptr[3] = (uint8_t)((uint32_t)u); \ + } while (0) + +#define NNI_GET32(ptr, v) \ + v = (((uint32_t)((uint8_t)ptr[0])) << 24) + \ + (((uint32_t)((uint8_t)ptr[1])) << 16) + \ + (((uint32_t)((uint8_t)ptr[2])) << 8) + \ + (((uint32_t)(uint8_t)ptr[3])) + #endif // CORE_DEFS_H -- cgit v1.2.3-70-g09d2