div.h

DIV_H_INV_15625_32

Approximation of (2**l)/d for d=15625, l=12, 32 bits.

1
0x431bde83ul
DIV_H_INV_15625_64

Approximation of (2**l)/d for d=15625, l=12, 64 bits.

1
0x431bde82d7b634dbull
DIV_H_INV_15625_SHIFT

Required shifts for division by 15625, l above.

1
12
uint64_t _div_mulhi64(const uint64_t a, const uint64_t b)
uint64_t div_u64_by_15625(uint64_t val)

Integer divide val by 15625, 64 bit version.

Parameters

val:dividend

Return values

  • (val / 15625)
uint32_t div_u64_by_125(uint64_t val)

Integer divide val by 125.

This function can be used to convert uint64_t microsecond times (or intervals) to miliseconds and store them in uint32_t variables, with up to ~50 days worth of miliseconds ((2**32*1000) -1). Use e.g., ms = div_u64_by_125(microseconds >> 3)

Parameters

val:dividend

Return values

  • (val / 125)
uint64_t div_u64_by_1000000(uint64_t val)

Integer divide val by 1000000.

Parameters

val:dividend

Return values

  • (val / 1000000)
uint32_t div_u32_by_15625div512(uint32_t val)

Divide val by (15625/512)

This is used to quantize a 1MHz value to the closest 32768Hz value, e.g., for timers.

The algorithm uses the modular multiplicative inverse of 15625 to use only multiplication and bit shifts to perform the division.

The result will be equal to the mathematical expression: floor((val * 512) / 15625)

Parameters

val:dividend

Return values

  • (val / (15625/512))
uint64_t div_u64_by_15625div512(uint64_t val)

Divide val by (15625/512)

This is used to quantize a 1MHz value to the closest 32768Hz value, e.g., for timers.

Parameters

val:dividend

Return values

  • (val / (15625/512))
uint32_t div_u32_by_44488(uint32_t val)

Integer divide val by 44488.

Parameters

val:dividend

Return values

  • (val / 44488)
uint32_t div_u32_mod_44488(uint32_t val)

Modulo 44488.

Parameters

val:dividend

Return values

  • (val % 44488)