From 91f350aa51390a3f86d733d7e714ca9a0554de4f Mon Sep 17 00:00:00 2001 From: viciious Date: Sun, 23 Jul 2023 10:40:39 +0000 Subject: [PATCH] Use pre-clamped LUT for IMA indices --- sh2_mixer.s | 138 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 101 insertions(+), 37 deletions(-) diff --git a/sh2_mixer.s b/sh2_mixer.s index 143a20f11..617df69a7 100644 --- a/sh2_mixer.s +++ b/sh2_mixer.s @@ -253,16 +253,11 @@ mix4_loop: 5: /* step_index += index_table[nibble] */ mov.l _index_table,r1 - mov.b @(r0,r1),r1 + add r2,r2 /* index *= 2 */ + shll2 r2 /* index *= 4 */ + add r2,r0 + mov.b @(r0,r1),r2 extu.w r12,r12 /* clear upper word for step_index */ - add r1,r2 /* step_index += index_table[nibble] */ - - /* clamp to 0:88 */ - cmp/pz r2 - bf/s 6f - mov #88,r1 - cmp/gt r1,r2 - bt/s 7f shll16 r2 or r2,r12 /* r12 is step_index : predictor again */ @@ -326,14 +321,8 @@ mix4_exit: 3: bra 5b mov r1,r12 /* clamp sample to 32767 */ -6: bra mix4_gets - mov #0,r2 /* clamp step_index to 0 */ -7: - mov #88,r2 /* clamp step_index to 88 */ - shll16 r2 - bra mix4_gets - or r2,r12 /* r12 is step_index : predictor again */ + nop ! void S_PaintChannel4IMA2x(void *channel, int16_t *buffer, int32_t cnt, int32_t scale); ! On entry: r4 = channel pointer @@ -447,16 +436,11 @@ mix4_loop2x: 5: /* step_index += index_table[nibble] */ mov.l _index_table,r1 - mov.b @(r0,r1),r1 + add r2,r2 /* index *= 2 */ + shll2 r2 /* index *= 4 */ + add r2,r0 + mov.b @(r0,r1),r2 extu.w r12,r12 /* clear upper word for step_index */ - add r1,r2 /* step_index += index_table[nibble] */ - - /* clamp to 0:88 */ - cmp/pz r2 - bf/s 6f - mov #88,r1 - cmp/gt r1,r2 - bt/s 7f shll16 r2 or r2,r12 /* r12 is step_index : predictor again */ @@ -527,15 +511,8 @@ mix4_exit2x: 3: bra 5b mov r1,r12 /* clamp sample to 32767 */ -6: - bra mix4_gets2x - mov #0,r2 /* clamp step_index to 0 */ -7: - mov #88,r2 /* clamp step_index to 88 */ - shll16 r2 bra mix4_gets2x - or r2,r12 /* r12 is step_index : predictor again */ - + nop .align 4 @@ -557,8 +534,95 @@ step_table: .word 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899 .word 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794 .word 32767 - + +.global index_table index_table: - .byte -1, -1, -1, -1, 2, 4, 6, 8 - .byte -1, -1, -1, -1, 2, 4, 6, 8 - + .byte 0, 0, 0, 0, 2, 4, 6, 8 + .byte 0, 0, 0, 0, 3, 5, 7, 9 + .byte 1, 1, 1, 1, 4, 6, 8, 10 + .byte 2, 2, 2, 2, 5, 7, 9, 11 + .byte 3, 3, 3, 3, 6, 8, 10, 12 + .byte 4, 4, 4, 4, 7, 9, 11, 13 + .byte 5, 5, 5, 5, 8, 10, 12, 14 + .byte 6, 6, 6, 6, 9, 11, 13, 15 + .byte 7, 7, 7, 7, 10, 12, 14, 16 + .byte 8, 8, 8, 8, 11, 13, 15, 17 + .byte 9, 9, 9, 9, 12, 14, 16, 18 + .byte 10, 10, 10, 10, 13, 15, 17, 19 + .byte 11, 11, 11, 11, 14, 16, 18, 20 + .byte 12, 12, 12, 12, 15, 17, 19, 21 + .byte 13, 13, 13, 13, 16, 18, 20, 22 + .byte 14, 14, 14, 14, 17, 19, 21, 23 + .byte 15, 15, 15, 15, 18, 20, 22, 24 + .byte 16, 16, 16, 16, 19, 21, 23, 25 + .byte 17, 17, 17, 17, 20, 22, 24, 26 + .byte 18, 18, 18, 18, 21, 23, 25, 27 + .byte 19, 19, 19, 19, 22, 24, 26, 28 + .byte 20, 20, 20, 20, 23, 25, 27, 29 + .byte 21, 21, 21, 21, 24, 26, 28, 30 + .byte 22, 22, 22, 22, 25, 27, 29, 31 + .byte 23, 23, 23, 23, 26, 28, 30, 32 + .byte 24, 24, 24, 24, 27, 29, 31, 33 + .byte 25, 25, 25, 25, 28, 30, 32, 34 + .byte 26, 26, 26, 26, 29, 31, 33, 35 + .byte 27, 27, 27, 27, 30, 32, 34, 36 + .byte 28, 28, 28, 28, 31, 33, 35, 37 + .byte 29, 29, 29, 29, 32, 34, 36, 38 + .byte 30, 30, 30, 30, 33, 35, 37, 39 + .byte 31, 31, 31, 31, 34, 36, 38, 40 + .byte 32, 32, 32, 32, 35, 37, 39, 41 + .byte 33, 33, 33, 33, 36, 38, 40, 42 + .byte 34, 34, 34, 34, 37, 39, 41, 43 + .byte 35, 35, 35, 35, 38, 40, 42, 44 + .byte 36, 36, 36, 36, 39, 41, 43, 45 + .byte 37, 37, 37, 37, 40, 42, 44, 46 + .byte 38, 38, 38, 38, 41, 43, 45, 47 + .byte 39, 39, 39, 39, 42, 44, 46, 48 + .byte 40, 40, 40, 40, 43, 45, 47, 49 + .byte 41, 41, 41, 41, 44, 46, 48, 50 + .byte 42, 42, 42, 42, 45, 47, 49, 51 + .byte 43, 43, 43, 43, 46, 48, 50, 52 + .byte 44, 44, 44, 44, 47, 49, 51, 53 + .byte 45, 45, 45, 45, 48, 50, 52, 54 + .byte 46, 46, 46, 46, 49, 51, 53, 55 + .byte 47, 47, 47, 47, 50, 52, 54, 56 + .byte 48, 48, 48, 48, 51, 53, 55, 57 + .byte 49, 49, 49, 49, 52, 54, 56, 58 + .byte 50, 50, 50, 50, 53, 55, 57, 59 + .byte 51, 51, 51, 51, 54, 56, 58, 60 + .byte 52, 52, 52, 52, 55, 57, 59, 61 + .byte 53, 53, 53, 53, 56, 58, 60, 62 + .byte 54, 54, 54, 54, 57, 59, 61, 63 + .byte 55, 55, 55, 55, 58, 60, 62, 64 + .byte 56, 56, 56, 56, 59, 61, 63, 65 + .byte 57, 57, 57, 57, 60, 62, 64, 66 + .byte 58, 58, 58, 58, 61, 63, 65, 67 + .byte 59, 59, 59, 59, 62, 64, 66, 68 + .byte 60, 60, 60, 60, 63, 65, 67, 69 + .byte 61, 61, 61, 61, 64, 66, 68, 70 + .byte 62, 62, 62, 62, 65, 67, 69, 71 + .byte 63, 63, 63, 63, 66, 68, 70, 72 + .byte 64, 64, 64, 64, 67, 69, 71, 73 + .byte 65, 65, 65, 65, 68, 70, 72, 74 + .byte 66, 66, 66, 66, 69, 71, 73, 75 + .byte 67, 67, 67, 67, 70, 72, 74, 76 + .byte 68, 68, 68, 68, 71, 73, 75, 77 + .byte 69, 69, 69, 69, 72, 74, 76, 78 + .byte 70, 70, 70, 70, 73, 75, 77, 79 + .byte 71, 71, 71, 71, 74, 76, 78, 80 + .byte 72, 72, 72, 72, 75, 77, 79, 81 + .byte 73, 73, 73, 73, 76, 78, 80, 82 + .byte 74, 74, 74, 74, 77, 79, 81, 83 + .byte 75, 75, 75, 75, 78, 80, 82, 84 + .byte 76, 76, 76, 76, 79, 81, 83, 85 + .byte 77, 77, 77, 77, 80, 82, 84, 86 + .byte 78, 78, 78, 78, 81, 83, 85, 87 + .byte 79, 79, 79, 79, 82, 84, 86, 88 + .byte 80, 80, 80, 80, 83, 85, 87, 88 + .byte 81, 81, 81, 81, 84, 86, 88, 88 + .byte 82, 82, 82, 82, 85, 87, 88, 88 + .byte 83, 83, 83, 83, 86, 88, 88, 88 + .byte 84, 84, 84, 84, 87, 88, 88, 88 + .byte 85, 85, 85, 85, 88, 88, 88, 88 + .byte 86, 86, 86, 86, 88, 88, 88, 88 + .byte 87, 87, 87, 87, 88, 88, 88, 88