summaryrefslogtreecommitdiff
path: root/lib9p/internal.h
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2024-09-30 08:05:40 -0600
committerLuke T. Shumaker <lukeshu@lukeshu.com>2024-09-30 11:19:50 -0600
commitd82d7f59f9227a0ea33d13af3c7ed95e16fdd2e3 (patch)
tree0b911ceb5b89642f963faf5f3324eb6eef3d459a /lib9p/internal.h
parent2ec9929e7bab7c87d3851e932baf0c1146981657 (diff)
lib9p: Use __attribute__((always_inline)) and __attribute__((flatten))
Diffstat (limited to 'lib9p/internal.h')
-rw-r--r--lib9p/internal.h20
1 files changed, 11 insertions, 9 deletions
diff --git a/lib9p/internal.h b/lib9p/internal.h
index f67735b..d1da014 100644
--- a/lib9p/internal.h
+++ b/lib9p/internal.h
@@ -22,7 +22,9 @@ static_assert(CONFIG_9P_MAX_ERR_SIZE + CONFIG_9P_MAX_MSG_SIZE + 2*CONFIG_9P_MAX_
/* C language *****************************************************************/
-#define UNUSED(name) /* name __attribute__ ((unused)) */
+#define UNUSED(name) /* name __attribute__((unused)) */
+#define ALWAYS_INLINE inline __attribute__((always_inline))
+#define FLATTEN __attribute__((flatten))
/* types **********************************************************************/
@@ -86,22 +88,22 @@ extern struct _vtable_version _lib9p_vtables[LIB9P_VER_NUM];
/* unmarshal utilities ********************************************************/
-static inline uint8_t decode_u8le(uint8_t *in) {
+static ALWAYS_INLINE uint8_t decode_u8le(uint8_t *in) {
return in[0];
}
-static inline uint16_t decode_u16le(uint8_t *in) {
+static ALWAYS_INLINE uint16_t decode_u16le(uint8_t *in) {
return (((uint16_t)(in[0])) << 0)
| (((uint16_t)(in[1])) << 8)
;
}
-static inline uint32_t decode_u32le(uint8_t *in) {
+static ALWAYS_INLINE uint32_t decode_u32le(uint8_t *in) {
return (((uint32_t)(in[0])) << 0)
| (((uint32_t)(in[1])) << 8)
| (((uint32_t)(in[2])) << 16)
| (((uint32_t)(in[3])) << 24)
;
}
-static inline uint64_t decode_u64le(uint8_t *in) {
+static ALWAYS_INLINE uint64_t decode_u64le(uint8_t *in) {
return (((uint64_t)(in[0])) << 0)
| (((uint64_t)(in[1])) << 8)
| (((uint64_t)(in[2])) << 16)
@@ -139,20 +141,20 @@ static inline bool _is_valid_utf8(uint8_t *str, size_t len, bool forbid_nul) {
/* marshal utilities **********************************************************/
-static inline void encode_u8le(uint8_t in, uint8_t *out) {
+static ALWAYS_INLINE void encode_u8le(uint8_t in, uint8_t *out) {
out[0] = in;
}
-static inline void encode_u16le(uint16_t in, uint8_t *out) {
+static ALWAYS_INLINE void encode_u16le(uint16_t in, uint8_t *out) {
out[0] = (uint8_t)((in >> 0) & 0xFF);
out[1] = (uint8_t)((in >> 8) & 0xFF);
}
-static inline void encode_u32le(uint32_t in, uint8_t *out) {
+static ALWAYS_INLINE void encode_u32le(uint32_t in, uint8_t *out) {
out[0] = (uint8_t)((in >> 0) & 0xFF);
out[1] = (uint8_t)((in >> 8) & 0xFF);
out[2] = (uint8_t)((in >> 16) & 0xFF);
out[3] = (uint8_t)((in >> 24) & 0xFF);
}
-static inline void encode_u64le(uint64_t in, uint8_t *out) {
+static ALWAYS_INLINE void encode_u64le(uint64_t in, uint8_t *out) {
out[0] = (uint8_t)((in >> 0) & 0xFF);
out[1] = (uint8_t)((in >> 8) & 0xFF);
out[2] = (uint8_t)((in >> 16) & 0xFF);