Make puffs_u16be etc functions, not macros.

This commit is contained in:
Nigel Tao committed 2017-09-22 14:41:08 +10:00
1 parent 2fb9972bb9
commit b14bafa717
5 files changed
+85 -52

No files matched your search

+22 -11
View File
@@ -8,17 +8,6 @@
#define PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(x) (void)(x)
// TODO: look for (ifdef) the x86 architecture and cast the pointer? Only do so
// if a benchmark justifies the additional code path.
#define PUFFS_U16BE(p) (((uint16_t)(p[0]) << 8) | ((uint16_t)(p[1]) << 0))
#define PUFFS_U16LE(p) (((uint16_t)(p[0]) << 0) | ((uint16_t)(p[1]) << 8))
#define PUFFS_U32BE(p) \
(((uint32_t)(p[0]) << 24) | ((uint32_t)(p[1]) << 16) | \
((uint32_t)(p[2]) << 8) | ((uint32_t)(p[3]) << 0))
#define PUFFS_U32LE(p) \
(((uint32_t)(p[0]) << 0) | ((uint32_t)(p[1]) << 8) | \
((uint32_t)(p[2]) << 16) | ((uint32_t)(p[3]) << 24))
// Use switch cases for coroutine suspension points, similar to the technique
// in https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
//
@@ -58,6 +47,28 @@ extern int printf(const char* __restrict __format, ...);
// inline attribute to guide optimizations such as inlining, to avoid the
// -Wunused-function warning, and we like to compile with -Wall -Werror.
// TODO: for puffs_u16be and similar functions, look for (ifdef) the x86
// architecture and cast the pointer? Only do so if a benchmark justifies the
// additional code path. Modern compilers might already generate good code.
static inline uint16_t puffs_u16be(uint8_t* p) {
return ((uint16_t)(p[0]) << 8) | ((uint16_t)(p[1]) << 0);
}
static inline uint16_t puffs_u16le(uint8_t* p) {
return ((uint16_t)(p[0]) << 0) | ((uint16_t)(p[1]) << 8);
}
static inline uint32_t puffs_u32be(uint8_t* p) {
return ((uint32_t)(p[0]) << 24) | ((uint32_t)(p[1]) << 16) |
((uint32_t)(p[2]) << 8) | ((uint32_t)(p[3]) << 0);
}
static inline uint32_t puffs_u32le(uint8_t* p) {
return ((uint32_t)(p[0]) << 0) | ((uint32_t)(p[1]) << 8) |
((uint32_t)(p[2]) << 16) | ((uint32_t)(p[3]) << 24);
}
// puffs_base_slice_u8_prefix returns up to the first n bytes of s.
static inline puffs_base_slice_u8 puffs_base_slice_u8_prefix(
puffs_base_slice_u8 s,