Use faster way to calculate buffer pointer.

One of the few instructions that can use the high registers (r8-r14) is
the add instruction, which can add any two registers, as long as one of
them is also used as the destination register.

By using this form of add , we can add buf_base (in a high register) to
the offset within the buffer (in a low register), to get the desired
pointer value (buf_ptr) which we want to access.

This saves one cycle by eliminating the need to move buf_base to a low
register first.
This commit is contained in:
Martin Ling
2021-12-20 13:26:57 +00:00
parent c1c665d5b8
commit e531fb507b

View File

@ -66,8 +66,8 @@ shadow registers.
There are two key code paths, with the following worst-case timings: There are two key code paths, with the following worst-case timings:
RX: 141 cycles RX: 140 cycles
TX: 126 cycles TX: 125 cycles
Design Design
====== ======
@ -178,9 +178,8 @@ loop:
str r0, [sgpio_int, #INT_CLEAR] // 8 str r0, [sgpio_int, #INT_CLEAR] // 8
// ... and grab the address of the buffer segment we want to write to / read from. // ... and grab the address of the buffer segment we want to write to / read from.
mov r0, buf_base // r0 = &buffer // 1 ldr buf_ptr, [state, #OFFSET] // buf_ptr = position_in_buffer // 2
ldr r2, [state, #OFFSET] // r2 = position_in_buffer // 2 add buf_ptr, buf_base // buf_ptr = &buffer + position_in_buffer // 1
add buf_ptr, r0, r2 // buf_ptr = &buffer + position_in_buffer // 1
// Load direction (TX or RX) // Load direction (TX or RX)
ldr r0, [state, #TX] // 2 ldr r0, [state, #TX] // 2