ctr: Encode integers in hex

Replace the custom encoding with a hex encoding.  This makes it a
little easier to inspect the CTR conversions.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2019-08-22 11:08:51 -04:00
parent 69fc1e63b4
commit e59d875256
2 changed files with 11 additions and 8 deletions

View file

@ -14,17 +14,20 @@
static char __PASTE(_DECLS_, __LINE__)[] __attribute__((used)) \
__section(".compile_time_request") = (REQUEST)
#define CTR_INT(V, S) ((((uint32_t)(V) >> S) & 0x3f) + 48)
// Helper macros for encoding an integer
#define CTR_HEX(H) ((H) > 9 ? (H) - 10 + 'A' : (H) + '0')
#define CTR_INT(V, S) CTR_HEX(((uint32_t)(V) >> (S)) & 0x0f)
// Declare a compile time request with an integer expression
#define DECL_CTR_INT(REQUEST, VALUE) \
static struct { char _r[sizeof(REQUEST)]; char _v[8]; } \
static struct { char _r[sizeof(REQUEST)]; char _v[12]; } \
__PASTE(_DECLI_, __LINE__) __attribute__((used)) \
__section(".compile_time_request") = { \
REQUEST " ", { \
(VALUE) < 0 ? '-' : '+', \
CTR_INT((VALUE),0), CTR_INT((VALUE),6), \
CTR_INT((VALUE),12), CTR_INT((VALUE),18), \
CTR_INT((VALUE),24), CTR_INT((VALUE),30), 0 } }
(VALUE) < 0 ? '-' : '+', '0', 'x', \
CTR_INT((VALUE),28), CTR_INT((VALUE),24), \
CTR_INT((VALUE),20), CTR_INT((VALUE),16), \
CTR_INT((VALUE),12), CTR_INT((VALUE),8), \
CTR_INT((VALUE),4), CTR_INT((VALUE),0), 0 } }
#endif // ctr.h