From e4a8d6eefc267c3a38d5237205421cbbe6eaebe8 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Sun, 10 Oct 2021 20:19:19 -0400 Subject: [PATCH] optimized samplebuffer copying --- Makefile | 8 +++---- source/handlers.cpp | 16 +++++++------- source/samplebuffer.cpp | 48 ++++++++++++++++++++--------------------- 3 files changed, 36 insertions(+), 36 deletions(-) diff --git a/Makefile b/Makefile index 3dcfd94..9e98828 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ TARGET_PLATFORM = L4 # Compiler options here. ifeq ($(USE_OPT),) - USE_OPT = -Os -g3 -ggdb -fomit-frame-pointer -falign-functions=16 --specs=nosys.specs + USE_OPT = -O0 -g3 -ggdb -fomit-frame-pointer -falign-functions=16 --specs=nosys.specs endif # C specific options here (added to USE_OPT). @@ -177,9 +177,9 @@ CPPWARN = -Wall -Wextra -Wundef -pedantic -Wno-volatile # List all user C define here, like -D_DEBUG=1 UDEFS = -DCORTEX_ENABLE_WFI_IDLE=TRUE \ - -DPORT_USE_SYSCALL=TRUE \ - -DPORT_USE_GUARD_MPU_REGION=MPU_REGION_0 \ - -DTARGET_PLATFORM_$(TARGET_PLATFORM) + -DPORT_USE_SYSCALL=TRUE \ + -DPORT_USE_GUARD_MPU_REGION=MPU_REGION_0 \ + -DTARGET_PLATFORM_$(TARGET_PLATFORM) # Define ASM defines here UADEFS = diff --git a/source/handlers.cpp b/source/handlers.cpp index 07f6ed3..2ff948d 100644 --- a/source/handlers.cpp +++ b/source/handlers.cpp @@ -105,7 +105,7 @@ void MemManage_Handler() { // 1. Get the stack pointer. uint32_t lr; - asm("mov %0, lr" : "=r" (lr)); + asm("mov %0, lr" : "=r" (lr)); // 2. Recover from the fault. ConversionManager::abort(); @@ -120,14 +120,14 @@ void HardFault_Handler() // Get the stack pointer. //uint32_t *stack; uint32_t lr; - asm("mov %0, lr" : "=r" (lr)); - /*asm("\ - tst lr, #4; \ - ite eq; \ - mrseq %0, msp; \ - mrsne %0, psp; \ + asm("mov %0, lr" : "=r" (lr)); + /*asm("\ + tst lr, #4; \ + ite eq; \ + mrseq %0, msp; \ + mrsne %0, psp; \ mov %1, lr; \ - " : "=r" (stack), "=r" (lr));*/ + " : "=r" (stack), "=r" (lr));*/ // If coming from the algorithm, attempt to recover; otherwise, give up. if (run_status != RunStatus::Running && (lr & 4) != 0) diff --git a/source/samplebuffer.cpp b/source/samplebuffer.cpp index 6f588b1..74c6778 100644 --- a/source/samplebuffer.cpp +++ b/source/samplebuffer.cpp @@ -19,8 +19,8 @@ void SampleBuffer::clear() { } __attribute__((section(".convcode"))) void SampleBuffer::modify(Sample *data, unsigned int srcsize) { - auto size = std::min(srcsize, m_size); - size = (size + 15) & 0xFF0; + auto size = srcsize < m_size ? srcsize : m_size; + size = (size + 15) & (~15); m_modified = m_buffer; const int *src = reinterpret_cast(data); @@ -35,22 +35,22 @@ void SampleBuffer::modify(Sample *data, unsigned int srcsize) { int f = src[5]; int g = src[6]; int h = src[7]; - dst[0] = a; - dst[1] = b; - dst[2] = c; - dst[3] = d; - dst[4] = e; - dst[5] = f; - dst[6] = g; - dst[7] = h; - src += 8; - dst += 8; + dst[0] = a; + dst[1] = b; + dst[2] = c; + dst[3] = d; + dst[4] = e; + dst[5] = f; + dst[6] = g; + dst[7] = h; + src += 8; + dst += 8; } while (src < srcend); } __attribute__((section(".convcode"))) void SampleBuffer::midmodify(Sample *data, unsigned int srcsize) { - auto size = std::min(srcsize, m_size / 2); - size = (size + 15) & 0xFF0; + auto size = srcsize < m_size / 2 ? srcsize : m_size / 2; + size = (size + 15) & (~15); m_modified = middata(); const int *src = reinterpret_cast(data); @@ -65,16 +65,16 @@ void SampleBuffer::midmodify(Sample *data, unsigned int srcsize) { int f = src[5]; int g = src[6]; int h = src[7]; - dst[0] = a; - dst[1] = b; - dst[2] = c; - dst[3] = d; - dst[4] = e; - dst[5] = f; - dst[6] = g; - dst[7] = h; - src += 8; - dst += 8; + dst[0] = a; + dst[1] = b; + dst[2] = c; + dst[3] = d; + dst[4] = e; + dst[5] = f; + dst[6] = g; + dst[7] = h; + src += 8; + dst += 8; } while (src < srcend); }