From e531fb507bb65d437d4267f78656c7abb0a7498a Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Mon, 20 Dec 2021 13:26:57 +0000 Subject: [PATCH] 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. --- firmware/hackrf_usb/sgpio_m0.s | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/firmware/hackrf_usb/sgpio_m0.s b/firmware/hackrf_usb/sgpio_m0.s index a6e9589c..2fd87695 100644 --- a/firmware/hackrf_usb/sgpio_m0.s +++ b/firmware/hackrf_usb/sgpio_m0.s @@ -66,8 +66,8 @@ shadow registers. There are two key code paths, with the following worst-case timings: -RX: 141 cycles -TX: 126 cycles +RX: 140 cycles +TX: 125 cycles Design ====== @@ -178,9 +178,8 @@ loop: str r0, [sgpio_int, #INT_CLEAR] // 8 // ... and grab the address of the buffer segment we want to write to / read from. - mov r0, buf_base // r0 = &buffer // 1 - ldr r2, [state, #OFFSET] // r2 = position_in_buffer // 2 - add buf_ptr, r0, r2 // buf_ptr = &buffer + position_in_buffer // 1 + ldr buf_ptr, [state, #OFFSET] // buf_ptr = position_in_buffer // 2 + add buf_ptr, buf_base // buf_ptr = &buffer + position_in_buffer // 1 // Load direction (TX or RX) ldr r0, [state, #TX] // 2