Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
math_extras.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 Facebook.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
12
24
25#ifndef ZEPHYR_INCLUDE_SYS_MATH_EXTRAS_H_
26#define ZEPHYR_INCLUDE_SYS_MATH_EXTRAS_H_
27
28#include <zephyr/types.h>
29#include <stdbool.h>
30#include <stddef.h>
31
39
47static bool u16_add_overflow(uint16_t a, uint16_t b, uint16_t *result);
48
56
57static bool u32_add_overflow(uint32_t a, uint32_t b, uint32_t *result);
58
66static bool u64_add_overflow(uint64_t a, uint64_t b, uint64_t *result);
67
75static bool size_add_overflow(size_t a, size_t b, size_t *result);
76
78
86
94static bool u16_mul_overflow(uint16_t a, uint16_t b, uint16_t *result);
95
103
104static bool u32_mul_overflow(uint32_t a, uint32_t b, uint32_t *result);
112static bool u64_mul_overflow(uint64_t a, uint64_t b, uint64_t *result);
113
121static bool size_mul_overflow(size_t a, size_t b, size_t *result);
122
124
132
139
146
148
156
163
170
172
181
187typedef struct {
192} int128_t;
193
205
207
209
211
212#endif /* ZEPHYR_INCLUDE_SYS_MATH_EXTRAS_H_ */
static bool u16_mul_overflow(uint16_t a, uint16_t b, uint16_t *result)
Multiply two unsigned 16-bit integers.
static int u64_count_trailing_zeros(uint64_t x)
Count the number of trailing zero bits in a 64-bit integer.
static bool u64_mul_overflow(uint64_t a, uint64_t b, uint64_t *result)
Multiply two unsigned 64-bit integers.
static bool u32_add_overflow(uint32_t a, uint32_t b, uint32_t *result)
Add two unsigned 32-bit integers.
static bool u32_mul_overflow(uint32_t a, uint32_t b, uint32_t *result)
Multiply two unsigned 32-bit integers.
static int u32_count_trailing_zeros(uint32_t x)
Count the number of trailing zero bits in a 32-bit integer.
static bool u16_add_overflow(uint16_t a, uint16_t b, uint16_t *result)
Add two unsigned 16-bit integers.
static bool size_mul_overflow(size_t a, size_t b, size_t *result)
Multiply two size_t integers.
static bool size_add_overflow(size_t a, size_t b, size_t *result)
Add two size_t integers.
static int u32_count_leading_zeros(uint32_t x)
Count the number of leading zero bits in a 32-bit integer.
static void i128_multiply_i64_i64(int64_t a, int64_t b, int128_t *result)
Multiply two signed 64-bit integers and store the result in a 128-bit integer.
static int u64_count_leading_zeros(uint64_t x)
Count the number of leading zero bits in a 64-bit integer.
static bool u64_add_overflow(uint64_t a, uint64_t b, uint64_t *result)
Add two unsigned 64-bit integers.
Inline implementation of functions declared in math_extras.h.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT64_TYPE__ uint64_t
Definition stdint.h:91
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
__INT64_TYPE__ int64_t
Definition stdint.h:75
128-bit integer structure.
Definition math_extras.h:187
uint64_t high
High-order 64 bits (includes sign bit).
Definition math_extras.h:191
uint64_t low
Low-order 64 bits.
Definition math_extras.h:189