Datasheet

Table Of Contents
26 // return 64 bit value so we can efficiently return both (note quotient must be read
Ê last)
27 ldr r1, [r3, #SIO_DIV_REMAINDER_OFFSET]
28 ldr r0, [r3, #SIO_DIV_QUOTIENT_OFFSET]
29 bx lr
NOTE
Software is free to perform other non divider operations during these 8 cycles.
There are two aliases of the operand registers: writing to the signed alias (DIV_SDIVIDEND and DIV_SDIVISOR) will
initiate a signed calculation, and the other (DIV_UDIVIDEND and DIV_UDIVISOR) will initiate an unsigned calculation.
SDK: https://github.com/raspberrypi/pico-sdk/tree/master/src/rp2_common/hardware_divider/divider.S Lines 36 - 44
36 regular_func_with_section hw_divider_divmod_u32
37 ldr r3, =(SIO_BASE)
38 str r0, [r3, #SIO_DIV_UDIVIDEND_OFFSET]
39 str r1, [r3, #SIO_DIV_UDIVISOR_OFFSET]
40 __divider_delay
41 // return 64 bit value so we can efficiently return both (note quotient must be read
Ê last)
42 ldr r1, [r3, #SIO_DIV_REMAINDER_OFFSET]
43 ldr r0, [r3, #SIO_DIV_QUOTIENT_OFFSET]
44 bx lr
NOTE
A new calculation begins immediately with every write to an operand register, and a new operand write immediately
squashes any calculation currently in progress. For example, when dividing many numbers by the same divisor, only
xDIVIDEND needs to be written, and the signedness of each calculation is determined by whether SDIVIDEND or UDIVIDEND
is written.
To support save and restore on interrupt handler entry/exit (or on e.g. an RTOS context switch), the result registers are
also writable. Writing to a result register will cancel any operation in progress at the time. The DIV_CSR.DIRTY flag can
help make save/restore more efficient: this flag is set when any divider register (operand or result) is written to, and
cleared when the quotient is read.
NOTE
When enabled, the default divider AEABI support maps C level / and % to the hardware divider. When building
software using the SDK and using the divider directly, it is important to read the quotient register last. This ensures
the partial divider state will be correctly saved and restored by any interrupt code that uses the divider. You should
read the quotient register whether you need the value or not.
The SDK module pico_divider https://github.com/raspberrypi/pico-sdk/tree/master/src/common/pico_divider/include/
pico/divider.h provides both the AEABI implementation needed to hook the C / and % operators for both 32-bit and 64-bit
integer division, as well as some additional C functions that return quotients and remainders at the same time. All of
these functions correctly save and restore the hardware divider state (when dirty) so that they can be used in either user
or IRQ handler code.
The SDK module hardware_divider https://github.com/raspberrypi/pico-sdk/tree/master/src/rp2_common/
hardware_divider/include/hardware/divider.h provides lower level macros and helper functions for accessing the
hardware_divider, but these do not save and restore the hardware divider state (although this header does provide
separate functions to do so).
RP2040 Datasheet
2.3. Processor subsystem 32