@web-font-path: "roboto-debian.css";
v2.2.0 (RP2040)
Loading...
Searching...
No Matches
divider.h
Go to the documentation of this file.
/*
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _PICO_DIVIDER_H
#define _PICO_DIVIDER_H
#include "pico.h"
#include "hardware/divider.h"
#ifdef __cplusplus
extern "C" {
#endif
int32_t div_s32s32(int32_t a, int32_t b);
static inline int32_t divmod_s32s32_rem(int32_t a, int32_t b, int32_t *rem) {
divmod_result_t r = hw_divider_divmod_s32(a, b);
*rem = to_remainder_s32(r);
return to_quotient_s32(r);
}
divmod_result_t divmod_s32s32(int32_t a, int32_t b);
uint32_t div_u32u32(uint32_t a, uint32_t b);
static inline uint32_t divmod_u32u32_rem(uint32_t a, uint32_t b, uint32_t *rem) {
divmod_result_t r = hw_divider_divmod_u32(a, b);
*rem = to_remainder_u32(r);
return to_quotient_u32(r);
}
divmod_result_t divmod_u32u32(uint32_t a, uint32_t b);
int64_t div_s64s64(int64_t a, int64_t b);
int64_t divmod_s64s64_rem(int64_t a, int64_t b, int64_t *rem);
int64_t divmod_s64s64(int64_t a, int64_t b);
uint64_t div_u64u64(uint64_t a, uint64_t b);
uint64_t divmod_u64u64_rem(uint64_t a, uint64_t b, uint64_t *rem);
uint64_t divmod_u64u64(uint64_t a, uint64_t b);
// -----------------------------------------------------------------------
// these "unsafe" functions are slightly faster, but do not save the divider state,
// so are not generally safe to be called from interrupts
// -----------------------------------------------------------------------
int32_t div_s32s32_unsafe(int32_t a, int32_t b);
int32_t divmod_s32s32_rem_unsafe(int32_t a, int32_t b, int32_t *rem);
divmod_result_t divmod_s32s32_unsafe(int32_t a, int32_t b);
uint32_t div_u32u32_unsafe(uint32_t a, uint32_t b);
uint32_t divmod_u32u32_rem_unsafe(uint32_t a, uint32_t b, uint32_t *rem);
divmod_result_t divmod_u32u32_unsafe(uint32_t a, uint32_t b);
int64_t div_s64s64_unsafe(int64_t a, int64_t b);
int64_t divmod_s64s64_rem_unsafe(int64_t a, int64_t b, int64_t *rem);
int64_t divmod_s64s64_unsafe(int64_t a, int64_t b);
uint64_t div_u64u64_unsafe(uint64_t a, uint64_t b);
uint64_t divmod_u64u64_rem_unsafe(uint64_t a, uint64_t b, uint64_t *rem);
uint64_t divmod_u64u64_unsafe(uint64_t a, uint64_t b);
#ifdef __cplusplus
}
#endif
#endif
to_quotient_u32
static uint32_t to_quotient_u32(divmod_result_t r)
Efficient extraction of unsigned quotient from 32p32 fixed point.
Definition divider.h:198
to_quotient_s32
static int32_t to_quotient_s32(divmod_result_t r)
Efficient extraction of signed quotient from 32p32 fixed point.
Definition divider.h:208
to_remainder_s32
static int32_t to_remainder_s32(divmod_result_t r)
Efficient extraction of signed remainder from 32p32 fixed point.
Definition divider.h:232
hw_divider_divmod_s32
static divmod_result_t hw_divider_divmod_s32(int32_t a, int32_t b)
Do a signed HW divide and wait for result.
Definition divider.h:74
hw_divider_divmod_u32
static divmod_result_t hw_divider_divmod_u32(uint32_t a, uint32_t b)
Do an unsigned HW divide and wait for result.
Definition divider.h:92
to_remainder_u32
static uint32_t to_remainder_u32(divmod_result_t r)
Efficient extraction of unsigned remainder from 32p32 fixed point.
Definition divider.h:220
divmod_u32u32_rem
static uint32_t divmod_u32u32_rem(uint32_t a, uint32_t b, uint32_t *rem)
Integer divide of two unsigned 32-bit values, with remainder.
Definition divider.h:88
div_s64s64
int64_t div_s64s64(int64_t a, int64_t b)
Integer divide of two signed 64-bit values.
Definition divider_compiler.c:66
divmod_u32u32_rem_unsafe
uint32_t divmod_u32u32_rem_unsafe(uint32_t a, uint32_t b, uint32_t *rem)
Unsafe integer divide of two unsigned 32-bit values, with remainder.
Definition divider_compiler.c:105
divmod_s32s32_rem_unsafe
int32_t divmod_s32s32_rem_unsafe(int32_t a, int32_t b, int32_t *rem)
Unsafe integer divide of two signed 32-bit values, with remainder.
Definition divider_compiler.c:101
divmod_u64u64_unsafe
uint64_t divmod_u64u64_unsafe(uint64_t a, uint64_t b)
Unsafe integer divide of two signed 64-bit values.
div_u64u64
uint64_t div_u64u64(uint64_t a, uint64_t b)
Integer divide of two unsigned 64-bit values.
Definition divider_compiler.c:82
divmod_s64s64_unsafe
int64_t divmod_s64s64_unsafe(int64_t a, int64_t b)
Unsafe integer divide of two signed 64-bit values.
divmod_u64u64
uint64_t divmod_u64u64(uint64_t a, uint64_t b)
Integer divide of two signed 64-bit values.
Definition divider_compiler.c:93
div_u64u64_unsafe
uint64_t div_u64u64_unsafe(uint64_t a, uint64_t b)
Unsafe integer divide of two unsigned 64-bit values.
Definition divider_compiler.c:113
div_s32s32
int32_t div_s32s32(int32_t a, int32_t b)
Integer divide of two signed 32-bit values.
Definition divider_compiler.c:10
divmod_s32s32_unsafe
divmod_result_t divmod_s32s32_unsafe(int32_t a, int32_t b)
Unsafe integer divide of two unsigned 32-bit values.
Definition divider_compiler.c:102
divmod_u32u32
divmod_result_t divmod_u32u32(uint32_t a, uint32_t b)
Integer divide of two unsigned 32-bit values.
Definition divider_compiler.c:22
divmod_s64s64_rem
int64_t divmod_s64s64_rem(int64_t a, int64_t b, int64_t *rem)
Integer divide of two signed 64-bit values, with remainder.
Definition divider_compiler.c:71
div_s32s32_unsafe
int32_t div_s32s32_unsafe(int32_t a, int32_t b)
Unsafe integer divide of two signed 32-bit values.
Definition divider_compiler.c:100
divmod_s64s64
int64_t divmod_s64s64(int64_t a, int64_t b)
Integer divide of two signed 64-bit values.
Definition divider_compiler.c:77
divmod_u64u64_rem_unsafe
uint64_t divmod_u64u64_rem_unsafe(uint64_t a, uint64_t b, uint64_t *rem)
Unsafe integer divide of two unsigned 64-bit values, with remainder.
Definition divider_compiler.c:114
div_u32u32
uint32_t div_u32u32(uint32_t a, uint32_t b)
Integer divide of two unsigned 32-bit values.
Definition divider_compiler.c:18
divmod_s32s32_rem
static int32_t divmod_s32s32_rem(int32_t a, int32_t b, int32_t *rem)
Integer divide of two signed 32-bit values, with remainder.
Definition divider.h:53
divmod_s32s32
divmod_result_t divmod_s32s32(int32_t a, int32_t b)
Integer divide of two signed 32-bit values.
Definition divider_compiler.c:14
divmod_s64s64_rem_unsafe
int64_t divmod_s64s64_rem_unsafe(int64_t a, int64_t b, int64_t *rem)
Unsafe integer divide of two signed 64-bit values, with remainder.
Definition divider_compiler.c:109
divmod_u64u64_rem
uint64_t divmod_u64u64_rem(uint64_t a, uint64_t b, uint64_t *rem)
Integer divide of two unsigned 64-bit values, with remainder.
Definition divider_compiler.c:87
divmod_u32u32_unsafe
divmod_result_t divmod_u32u32_unsafe(uint32_t a, uint32_t b)
Unsafe integer divide of two unsigned 32-bit values.
Definition divider_compiler.c:106
div_u32u32_unsafe
uint32_t div_u32u32_unsafe(uint32_t a, uint32_t b)
Unsafe integer divide of two unsigned 32-bit values.
Definition divider_compiler.c:104
div_s64s64_unsafe
int64_t div_s64s64_unsafe(int64_t a, int64_t b)
Unsafe integer divide of two signed 64-bit values.
Definition divider_compiler.c:108
pico.h
divider.h