utils.h
Include dependency graph for utils.h:
This graph shows which files directly or indirectly include utils.h:
Misc functions and macros.
Miscellaneous functions and macros useful for different tasks, like endian byteswap, unaligned reads, marking unused vars, etc…
Defines
-
READ_32_ALIGNED(ptr) ( (((uint8_t *)(ptr))[0] << 24) | (((uint8_t *) (ptr))[1] << 16) | (((uint8_t *)(ptr))[2] << 8) | ((uint8_t *)(ptr))[3] )
-
READ_64_UNALIGNED(ptr)
( (((uint64_t) ((uint8_t *)(ptr))[0]) << 56) | (((uint64_t) ((uint8_t *) (ptr))[1]) << 48) | \
(((uint64_t) ((uint8_t *)(ptr))[2]) << 40) | (((uint64_t) ((uint8_t *) (ptr))[3]) << 32) | \
(((uint64_t) ((uint8_t *)(ptr))[4]) << 24) | (((uint64_t) ((uint8_t *) (ptr))[5]) << 16) | \
(((uint64_t) ((uint8_t *)(ptr))[6]) << 8) | (((uint64_t) ((uint8_t *) (ptr))[7])) )
-
WRITE_64_UNALIGNED(ptr, val)
{ \
((uint8_t *)(ptr))[0] = (((uint64_t) val) >> 56) & 0xff; \
((uint8_t *)(ptr))[1] = (((uint64_t) val) >> 48) & 0xff; \
((uint8_t *)(ptr))[2] = (((uint64_t) val) >> 40) & 0xff; \
((uint8_t *)(ptr))[3] = (((uint64_t) val) >> 32) & 0xff; \
((uint8_t *)(ptr))[4] = (((uint64_t) val) >> 24) & 0xff; \
((uint8_t *)(ptr))[5] = (((uint64_t) val) >> 16) & 0xff; \
((uint8_t *)(ptr))[6] = (((uint64_t) val) >> 8) & 0xff; \
((uint8_t *)(ptr))[7] = ((uint64_t) val) & 0xff; \
}
-
READ_32_UNALIGNED(ptr) ( (((uint8_t *)(ptr))[0] << 24) | (((uint8_t *) (ptr))[1] << 16) | (((uint8_t *)(ptr))[2] << 8) | ((uint8_t *)(ptr))[3] )
-
WRITE_32_UNALIGNED(ptr, val)
{ \
((uint8_t *)(ptr))[0] = (((uint32_t) val) >> 24) & 0xff; \
((uint8_t *)(ptr))[1] = (((uint32_t) val) >> 16) & 0xff; \
((uint8_t *)(ptr))[2] = (((uint32_t) val) >> 8) & 0xff; \
((uint8_t *)(ptr))[3] = ((uint32_t) val) & 0xff; \
}
-
READ_16_UNALIGNED(ptr) ( (((uint8_t *)(ptr))[0] << 8) | ((uint8_t *)(ptr))[1] )
-
WRITE_16_UNALIGNED(ptr, val)
{ \
((uint8_t *)(ptr))[0] = (((uint16_t) val) >> 8) & 0xff; \
((uint8_t *)(ptr))[1] = ((uint16_t) val) & 0xff; \
}
-
ENDIAN_SWAP_32(value) ((((value) & 0xFF) << 24) | (((value) & 0xFF00) << 8) | (((value) & 0xFF0000) >> 8) | (((value) & 0xFF000000) >> 24))
-
UNUSED(x) (void) (x);
-
IS_NULL_PTR(x) ((x) == NULL)
-
LIKELY(x) (x)
-
UNLIKELY(x) (x)
-
HOT_FUNC
-
COLD_FUNC
-
MALLOC_LIKE
-
MUST_CHECK
-
AVM_ABORT() abort()
-
CAST_FUNC_TO_VOID_PTR(f) ((void *) (f))
-
CAST_VOID_TO_FUNC_PTR(f) ((func_ptr_t) (f))
-
CONTAINER_OF(ptr, type, member) ((type *) (((char *) (ptr)) - offsetof(type, member)))
-
PRINTF_FORMAT_ARGS(...)
-
NO_DISCARD(...)
-
UNREACHABLE(...)
Typedefs
-
typedef void (*func_ptr_t)(void)