7 #ifndef _HARDWARE_DIVIDER_H 8 #define _HARDWARE_DIVIDER_H 11 #include "hardware/structs/sio.h" 43 typedef uint64_t divmod_result_t;
55 check_hw_layout(
sio_hw_t, div_sdividend, SIO_DIV_SDIVIDEND_OFFSET);
56 sio_hw->div_sdividend = (uint32_t)a;
57 sio_hw->div_sdivisor = (uint32_t)b;
71 sio_hw_t, div_udividend, SIO_DIV_UDIVIDEND_OFFSET);
72 sio_hw->div_udividend = a;
73 sio_hw->div_udivisor = b;
83 static_assert(SIO_DIV_CSR_READY_BITS == 1,
"");
89 "hw_divider_result_loop_%=:" 90 "ldr %0, [%1, %2]\n\t" 92 "bcc hw_divider_result_loop_%=\n\t" 94 :
"l" (sio_hw),
"I" (SIO_DIV_CSR_OFFSET)
108 divmod_result_t rc = (((divmod_result_t) sio_hw->div_remainder) << 32u) | sio_hw->div_quotient;
133 return sio_hw->div_quotient;
145 return (int32_t)sio_hw->div_quotient;
157 uint32_t rc = sio_hw->div_remainder;
158 sio_hw->div_quotient;
171 int32_t rc = (int32_t)sio_hw->div_remainder;
172 sio_hw->div_quotient;
215 return (int32_t)(uint32_t)r;
227 return (uint32_t)(r >> 32u);
239 return (int32_t)(r >> 32u);
322 return sio_hw->div_quotient;
337 uint32_t rc = sio_hw->div_remainder;
338 sio_hw->div_quotient;
354 return (int32_t)sio_hw->div_quotient;
369 int32_t rc = (int32_t)sio_hw->div_remainder;
370 sio_hw->div_quotient;
403 #endif // _HARDWARE_DIVIDER_H divmod_result_t hw_divider_divmod_s32(int32_t a, int32_t b)
Do a signed HW divide and wait for resultDivide a by b, wait for calculation to complete, return result as a fixed point 32p32 value.
static int32_t hw_divider_quotient_s32(int32_t a, int32_t b)
Do a signed HW divide, wait for result, return quotientDivide a by b, wait for calculation to complet...
Definition: divider.h:277
static uint32_t to_quotient_u32(divmod_result_t r)
Efficient extraction of unsigned quotient from 32p32 fixed point.
Definition: divider.h:204
static int32_t hw_divider_s32_remainder_wait(void)
Return result of last asynchronous HW divide, signed remainder onlyThis function waits for the result...
Definition: divider.h:169
static uint32_t hw_divider_u32_remainder_inlined(uint32_t a, uint32_t b)
Do a hardware unsigned HW divide, wait for result, return remainderDivide a by b, wait for calculatio...
Definition: divider.h:334
static uint32_t hw_divider_u32_remainder(uint32_t a, uint32_t b)
Do an unsigned HW divide, wait for result, return remainderDivide a by b, wait for calculation to com...
Definition: divider.h:264
static int32_t hw_divider_s32_quotient_wait(void)
Return result of last asynchronous HW divide, signed quotient onlyThis function waits for the result ...
Definition: divider.h:143
static uint32_t hw_divider_u32_remainder_wait(void)
Return result of last asynchronous HW divide, unsigned remainder onlyThis function waits for the resu...
Definition: divider.h:155
static uint32_t to_remainder_u32(divmod_result_t r)
Efficient extraction of unsigned remainder from 32p32 fixed point.
Definition: divider.h:226
static divmod_result_t hw_divider_result_nowait(void)
Return result of HW divide, nowait.
Definition: divider.h:106
static int32_t hw_divider_remainder_s32(int32_t a, int32_t b)
Do a signed HW divide, wait for result, return remainderDivide a by b, wait for calculation to comple...
Definition: divider.h:290
void hw_divider_save_state(hw_divider_state_t *dest)
Save the calling cores hardware divider stateCopy the current core's hardware divider state into the ...
static int32_t to_quotient_s32(divmod_result_t r)
Efficient extraction of signed quotient from 32p32 fixed point.
Definition: divider.h:214
static uint32_t hw_divider_u32_quotient_wait(void)
Return result of last asynchronous HW divide, unsigned quotient onlyThis function waits for the resul...
Definition: divider.h:131
static void hw_divider_pause(void)
Pause for exact amount of time needed for a asynchronous divide to complete.
Definition: divider.h:297
Definition: divider.h:374
static void hw_divider_wait_ready(void)
Wait for a divide to completeWait for a divide to complete.
Definition: divider.h:81
static int32_t to_remainder_s32(divmod_result_t r)
Efficient extraction of signed remainder from 32p32 fixed point.
Definition: divider.h:238
static void hw_divider_divmod_s32_start(int32_t a, int32_t b)
Start a signed asynchronous divideStart a divide of the specified signed parameters. You should wait for 8 cycles (__div_pause()) or wait for the ready bit to be set (hw_divider_wait_ready()) prior to reading the results.
Definition: divider.h:54
static divmod_result_t hw_divider_result_wait(void)
Return result of last asynchronous HW divideThis function waits for the result to be ready by calling...
Definition: divider.h:119
static uint32_t hw_divider_u32_quotient_inlined(uint32_t a, uint32_t b)
Do a hardware unsigned HW divide, wait for result, return quotientDivide a by b, wait for calculation...
Definition: divider.h:319
static int32_t hw_divider_s32_quotient_inlined(int32_t a, int32_t b)
Do a hardware signed HW divide, wait for result, return quotientDivide a by b, wait for calculation t...
Definition: divider.h:351
static uint32_t hw_divider_u32_quotient(uint32_t a, uint32_t b)
Do an unsigned HW divide, wait for result, return quotientDivide a by b, wait for calculation to comp...
Definition: divider.h:251
static void hw_divider_divmod_u32_start(uint32_t a, uint32_t b)
Start an unsigned asynchronous divideStart a divide of the specified unsigned parameters. You should wait for 8 cycles (__div_pause()) or wait for the ready bit to be set (hw_divider_wait_ready()) prior to reading the results.
Definition: divider.h:69
divmod_result_t hw_divider_divmod_u32(uint32_t a, uint32_t b)
Do an unsigned HW divide and wait for resultDivide a by b, wait for calculation to complete...
void hw_divider_restore_state(hw_divider_state_t *src)
Load a saved hardware divider state into the current core's hardware dividerCopy the passed hardware ...
static int32_t hw_divider_s32_remainder_inlined(int32_t a, int32_t b)
Do a hardware signed HW divide, wait for result, return remainderDivide a by b, wait for calculation ...
Definition: divider.h:366