|
Zephyr API Documentation 4.5.99
A Scalable Open Source RTOS
|
64-bit by 32-bit division More...
Files | |
| file | div64.h |
| 64-bit by 32-bit division without a 64-bit divide instruction. | |
Data Structures | |
| struct | sys_div64_recip |
| Reciprocal of a 32-bit divisor known only at run time. More... | |
Macros | |
| #define | sys_div64_u32_const(n, d) |
| Divide a 64-bit value by a 32-bit constant. | |
| #define | sys_div64_u32_const_inline(n, d) |
| Divide a 64-bit value by a 32-bit constant, inline. | |
| #define | sys_mod64_u32_const(n, d) |
| Remainder of a 64-bit value divided by a 32-bit constant. | |
| #define | sys_sdiv64_u32_const(n, d) |
| Divide a signed 64-bit value by a 32-bit constant. | |
| #define | SYS_DIV64_RECIP_INIT(d) |
| Static initializer for a reciprocal of a constant divisor. | |
Functions | |
| static void | sys_div64_recip_init (struct sys_div64_recip *r, uint32_t d) |
| Set up the reciprocal of a divisor. | |
| static uint64_t | sys_div64_recip_div (uint64_t n, const struct sys_div64_recip *r) |
| Divide a 64-bit value by a reciprocal's divisor. | |
| static uint32_t | sys_div64_recip_mod (uint64_t n, const struct sys_div64_recip *r) |
| Remainder of a 64-bit value divided by a reciprocal's divisor. | |
64-bit by 32-bit division
On a 32-bit target, n / d with a 64-bit n is a libgcc call that divides bit by bit, even for a constant d. These helpers multiply by a reciprocal of d instead. 64-bit targets divide in hardware.
| #define SYS_DIV64_RECIP_INIT | ( | d | ) |
#include <zephyr/sys/div64.h>
Static initializer for a reciprocal of a constant divisor.
| d | Divisor, an integer constant expression from 1 to UINT32_MAX. |
| #define sys_div64_u32_const | ( | n, | |
| d ) |
#include <zephyr/sys/div64.h>
Divide a 64-bit value by a 32-bit constant.
On a 32-bit target this multiplies by a reciprocal of d worked out at build time, in a shared out-of-line helper, or inline when optimizing for speed. Without the optimizer, or for a non-constant d, it divides plainly. A constant n folds to a constant, so the result may initialize a static object.
| n | Dividend (uint64_t). |
| d | Divisor, a constant from 1 to UINT32_MAX. |
n / d (uint64_t). | #define sys_div64_u32_const_inline | ( | n, | |
| d ) |
#include <zephyr/sys/div64.h>
Divide a 64-bit value by a 32-bit constant, inline.
Same as sys_div64_u32_const(), but the multiplication is always inline, for hot paths that are worth a few dozen bytes per call site.
| n | Dividend (uint64_t). |
| d | Divisor, a constant from 1 to UINT32_MAX. |
n / d (uint64_t). | #define sys_mod64_u32_const | ( | n, | |
| d ) |
#include <zephyr/sys/div64.h>
Remainder of a 64-bit value divided by a 32-bit constant.
Paired with sys_div64_u32_const() on the same operands, the compiler computes the quotient once.
| n | Dividend (uint64_t). |
| d | Divisor, a constant from 1 to UINT32_MAX. |
n % d (uint32_t). | #define sys_sdiv64_u32_const | ( | n, | |
| d ) |
#include <zephyr/sys/div64.h>
Divide a signed 64-bit value by a 32-bit constant.
Rounds toward zero, like the C division operator.
| n | Dividend (int64_t). |
| d | Divisor, a constant from 1 to UINT32_MAX. |
n / d (int64_t).
|
inlinestatic |
#include <zephyr/sys/div64.h>
Divide a 64-bit value by a reciprocal's divisor.
| n | Dividend. |
| r | Reciprocal of the divisor. |
n divided by the divisor of r.
|
inlinestatic |
#include <zephyr/sys/div64.h>
Set up the reciprocal of a divisor.
Takes four 32-bit divisions on a 32-bit target, so do it where the divisor changes, not before each division.
| r | Reciprocal to set up. |
| d | Divisor, from 1 to UINT32_MAX. |
|
inlinestatic |
#include <zephyr/sys/div64.h>
Remainder of a 64-bit value divided by a reciprocal's divisor.
| n | Dividend. |
| r | Reciprocal of the divisor. |
n modulo the divisor of r.