Stefan Reinauer (stefan.reinauer@coreboot.org) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/2719
-gerrit
commit b326a2cc514470ca7d5c5ad1abb1b2d01b6b3c4e Author: Gabe Black gabeblack@google.com Date: Fri Mar 8 04:38:13 2013 -0800
libpayload: Turn the endian conversion macros into functions.
In their current macro form, any arguments that are expressions will be evaluated multiple times. That can cause problems if they have side effects, and might not even compile if the overall expression is ambiguous, for instance if you pass in foo++.
Built with code that previously wouldn't compile because the macros expanded to ambiguous expressions.
Change-Id: I378c04d7aff5b4ad40581930ce90e49ba7df1d3e Signed-off-by: Gabe Black gabeblack@google.com --- payloads/libpayload/include/endian.h | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/payloads/libpayload/include/endian.h b/payloads/libpayload/include/endian.h index ee9cf13..cb50443 100644 --- a/payloads/libpayload/include/endian.h +++ b/payloads/libpayload/include/endian.h @@ -26,12 +26,22 @@ #include <arch/types.h> #include <libpayload-config.h>
-#define swap_bytes16(in) ((((in) & 0xFF) << 8) | (((in) & 0xFF00) >> 8)) -#define swap_bytes32(in) ((((in) & 0xFF) << 24) | (((in) & 0xFF00) << 8) | \ - (((in) & 0xFF0000) >> 8) | \ - (((in) & 0xFF000000) >> 24)) -#define swap_bytes64(in) (((uint64_t)swap_bytes32((uint32_t)(in)) << 32) | \ - ((uint64_t)swap_bytes32((uint32_t)((in) >> 32)))) +static inline uint16_t swap_bytes16(uint16_t in) +{ + return ((in & 0xFF) << 8) | ((in & 0xFF00) >> 8); +} + +static inline uint32_t swap_bytes32(uint32_t in) +{ + return ((in & 0xFF) << 24) | ((in & 0xFF00) << 8) | + ((in & 0xFF0000) >> 8) | ((in & 0xFF000000) >> 24); +} + +static inline uint64_t swap_bytes64(uint64_t in) +{ + return ((uint64_t)swap_bytes32((uint32_t)in) << 32) | + ((uint64_t)swap_bytes32((uint32_t)(in >> 32))); +}
/* Endian functions from glibc 2.9 / BSD "endian.h" */