Zephyr Project API 3.7.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
math_extras.h File Reference
#include <zephyr/types.h>
#include <stdbool.h>
#include <stddef.h>
#include <zephyr/sys/math_extras_impl.h>

Go to the source code of this file.

Functions

Unsigned integer addition with overflow detection.

These functions compute a + b and store the result in *result, returning true if the operation overflowed.

static bool u16_add_overflow (uint16_t a, uint16_t b, uint16_t *result)
 Add two unsigned 16-bit integers.
 
static bool u32_add_overflow (uint32_t a, uint32_t b, uint32_t *result)
 Add two unsigned 32-bit integers.
 
static bool u64_add_overflow (uint64_t a, uint64_t b, uint64_t *result)
 Add two unsigned 64-bit integers.
 
static bool size_add_overflow (size_t a, size_t b, size_t *result)
 Add two size_t integers.
 
Unsigned integer multiplication with overflow detection.

These functions compute a * b and store the result in *result, returning true if the operation overflowed.

static bool u16_mul_overflow (uint16_t a, uint16_t b, uint16_t *result)
 Multiply two unsigned 16-bit integers.
 
static bool u32_mul_overflow (uint32_t a, uint32_t b, uint32_t *result)
 Multiply two unsigned 32-bit integers.
 
static bool u64_mul_overflow (uint64_t a, uint64_t b, uint64_t *result)
 Multiply two unsigned 64-bit integers.
 
static bool size_mul_overflow (size_t a, size_t b, size_t *result)
 Multiply two size_t integers.
 
Count leading zeros.

Count the number of leading zero bits in the bitwise representation of x.

When x = 0, this is the size of x in bits.

static int u32_count_leading_zeros (uint32_t x)
 Count the number of leading zero bits in a 32-bit integer.
 
static int u64_count_leading_zeros (uint64_t x)
 Count the number of leading zero bits in a 64-bit integer.
 
Count trailing zeros.

Count the number of trailing zero bits in the bitwise representation of x.

When x = 0, this is the size of x in bits.

static int u32_count_trailing_zeros (uint32_t x)
 Count the number of trailing zero bits in a 32-bit integer.
 
static int u64_count_trailing_zeros (uint64_t x)
 Count the number of trailing zero bits in a 64-bit integer.