From be76bfa858937c821630cdcc1c54d12d0059b476 Mon Sep 17 00:00:00 2001 From: Tobias Girstmair Date: Sun, 18 Nov 2018 22:50:43 +0100 Subject: [PATCH] new version bring cycle count down from 425 to 409 --- foo.c | 72 ++++++++++++++++++++--------------------------------------- 1 file changed, 24 insertions(+), 48 deletions(-) diff --git a/foo.c b/foo.c index 29ddee4..9ef065b 100644 --- a/foo.c +++ b/foo.c @@ -86,7 +86,8 @@ static void* mul_jmptable[] = { // replaces data[] section at the top LD Zhi, X IJMP Z */ - mul_58: // 0101 1000 (24cy) + //don't care about top three bits (so don't compute them => _) + mul_58: // ___1 1000 (24cy) LSR (a2) ROR (a1) LSR (a2) @@ -102,14 +103,11 @@ static void* mul_jmptable[] = { // replaces data[] section at the top ADC (a2, i1, carry) LSR (a2) ROR (a1) - LSR (a2) - ROR (a1) + LSR (a1) ADD (a1, i0) - ADC (a2, i1, carry) - LSR (a2) - ROR (a1) + LSR (a1) RJMP (endmul) - mul_69: // 0110 1001 (26cy) + mul_69: // ___0 1001 (26cy) ADD (a1, i0) ADC (a2, i1, carry) LSR (a2) @@ -126,15 +124,11 @@ static void* mul_jmptable[] = { // replaces data[] section at the top LSR (a2) ROR (a1) ADD (a1, i0) - ADC (a2, i1, carry) - LSR (a2) - ROR (a1) + LSR (a1) ADD (a1, i0) - ADC (a2, i1, carry) - LSR (a2) - ROR (a1) + LSR (a1) RJMP (endmul) - mul_75: // 0111 0101 (28cy) + mul_75: // ___1 0101 (28cy) ADD (a1, i0) ADC (a2, i1, carry) LSR (a2) @@ -153,15 +147,11 @@ static void* mul_jmptable[] = { // replaces data[] section at the top LSR (a2) ROR (a1) ADD (a1, i0) - ADC (a2, i1, carry) - LSR (a2) - ROR (a1) + LSR (a1) ADD (a1, i0) - ADC (a2, i1, carry) - LSR (a2) - ROR (a1) + LSR (a1) RJMP (endmul) - mul_84: // 1000 0100 (22cy) + mul_84: // ___0 0100 (22cy) LSR (a2) ROR (a1) LSR (a2) @@ -175,14 +165,11 @@ static void* mul_jmptable[] = { // replaces data[] section at the top LSR (a2) ROR (a1) - LSR (a2) - ROR (a1) - LSR (a2) - ROR (a1) + LSR (a1) + LSR (a1) ADD (a1, i0) - ADC (a2, i1, carry) RJMP (endmul) - mul_8c: // 1000 1100 (24cy) + mul_8c: // ___0 1100 (24cy) LSR (a2) ROR (a1) LSR (a2) @@ -198,14 +185,11 @@ static void* mul_jmptable[] = { // replaces data[] section at the top LSR (a2) ROR (a1) - LSR (a2) - ROR (a1) - LSR (a2) - ROR (a1) + LSR (a1) + LSR (a1) ADD (a1, i0) - ADC (a2, i1, carry) RJMP (endmul) - mul_9d: // 1001 1101 (28cy) + mul_9d: // ___1 1101 (28cy) ADD (a1, i0) ADC (a2, i1, carry) LSR (a2) @@ -225,14 +209,11 @@ static void* mul_jmptable[] = { // replaces data[] section at the top ADC (a2, i1, carry) LSR (a2) ROR (a1) - LSR (a2) - ROR (a1) - LSR (a2) - ROR (a1) + LSR (a1) + LSR (a1) ADD (a1, i0) - ADC (a2, i1, carry) RJMP (endmul) - mul_b0: // 1011 0000 (22cy) + mul_b0: // ___1 0000 (22cy) LSR (a2) ROR (a1) LSR (a2) @@ -247,22 +228,17 @@ static void* mul_jmptable[] = { // replaces data[] section at the top LSR (a2) ROR (a1) ADD (a1, i0) - ADC (a2, i1, carry) - LSR (a2) - ROR (a1) - LSR (a2) - ROR (a1) + LSR (a1) + LSR (a1) ADD (a1, i0) - ADC (a2, i1, carry) endmul: - LSR (a2) //final shift is a common operation for all - ROR (a1) + LSR (a1) //final shift is a common operation for all // end MUL MOV (t, a1) #undef a0 #undef a1 #undef a2 - RET //TODO: replace CALL/RET with IJMP? + RET //TODO: replace CALL/RET with IJMP? (requires undoing goto-mul-hack) }; int main(void) { -- 2.39.3