From 3fea9aada05567178f0c7b7a33d1f5b157a9625e Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Wed, 4 May 2022 17:58:24 +0100 Subject: [PATCH] Somehow reduce clamp_s8 by 1 instruction --- agb/src/sound/mixer/mixer.s | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/agb/src/sound/mixer/mixer.s b/agb/src/sound/mixer/mixer.s index ba4796b6..667607a1 100644 --- a/agb/src/sound/mixer/mixer.s +++ b/agb/src/sound/mixer/mixer.s @@ -155,19 +155,24 @@ agb_arm_func agb_rs__mixer_collapse @ Arguments: @ r0 = target buffer (i8) @ r1 = input buffer (i16) of fixnums with 4 bits of precision (read in sets of i16 in an i32) - push {r4, r5, r6} + push {r4, r5, r6, r7, r8, r9, r10} + +CONST_0 .req r7 +CONST_FF .req r8 +CONST_127 .req r9 +TEMP .req r10 + + ldr CONST_0, =0 + ldr CONST_FF, =0xff + ldr CONST_127, =127 ldr r2, agb_rs__buffer_size @ loop counter mov r4, r2 .macro clamp_s8 reg:req - cmn \reg, #128 - mvnlt \reg, #128 - - cmp \reg, #127 - movgt \reg, #127 - - and \reg, \reg, #255 + add \reg, \reg, #127 + subs r10, r7, \reg, asr #8 + andne \reg, r8, r10, lsr #24 .endm .macro load_sample left_reg:req right_reg:req @@ -197,12 +202,16 @@ agb_arm_func agb_rs__mixer_collapse orr r3, r3, r5, lsl #24 orr r12, r12, r6, lsl #24 + ldr r5, =0x80808080 + eor r3, r3, r5 + eor r12, r12, r5 + str r3, [r0, r4] @ *(r0 + (r4 = SOUND_BUFFER_SIZE)) = r3 str r12, [r0], #4 @ *r0 = r12; r0 += 4 subs r2, r2, #4 @ r2 -= 4 bne 1b @ loop if not 0 - pop {r4, r5, r6} + pop {r4, r5, r6, r7, r8, r9, r10} bx lr agb_arm_end agb_rs__mixer_collapse