# HG changeset patch # User William Astle # Date 1457066301 25200 # Node ID 0af33282b5184d45314126f3dc4774a172be8ad3 # Parent c501b3ce39c828cdef208b443a02b0bf9e1fb5f1 Fix cycle counting for relative branches. The original creator of the cycle counting code appears to have mangled two different approaches to counting the cycles for relative branches into the final product which led to counting too many cycles for the branch instructions. The comments in the cycle table were correct but the code was doing some incorrect things. Also add the missing LBRN entry to the cycle table. The one labelled LBRN was not, in fact, LBRN, but one of the actual useful branch instructions. diff -r c501b3ce39c8 -r 0af33282b518 lwasm/cycle.c --- a/lwasm/cycle.c Thu Mar 03 21:17:48 2016 -0700 +++ b/lwasm/cycle.c Thu Mar 03 21:38:21 2016 -0700 @@ -305,20 +305,21 @@ { 0x16, 5, 4, 0 }, // LBRA { 0x17, 9, 7, 0 }, // LBSR - { 0x1022, 5, 5, 0 }, // LBRN - { 0x1023, 5, 6, 0 }, // remaining long branches are estimated on 6809 only: - { 0x1024, 5, 6, 0 }, // 6809: 5 cycles, +1 cycle if the branch is taken - { 0x1025, 5, 6, 0 }, // 6309 native: always 5 cycles - { 0x1026, 5, 6, 0 }, - { 0x1027, 5, 6, 0 }, - { 0x1028, 5, 6, 0 }, - { 0x1029, 5, 6, 0 }, - { 0x102a, 5, 6, 0 }, - { 0x102b, 5, 6, 0 }, - { 0x102c, 5, 6, 0 }, - { 0x102d, 5, 6, 0 }, - { 0x102e, 5, 6, 0 }, - { 0x102f, 5, 6, 0 }, + { 0x1021, 5, 5, 0 }, // LBRN + { 0x1022, 5, 5, 0 }, // remaining long branches are estimated on 6809 only: + { 0x1023, 5, 5, 0 }, // + { 0x1024, 5, 5, 0 }, // 6809: 5 cycles, +1 cycle if the branch is taken + { 0x1025, 5, 5, 0 }, // 6309 native: always 5 cycles + { 0x1026, 5, 5, 0 }, // + { 0x1027, 5, 5, 0 }, // this is handled as a special case elsewhere + { 0x1028, 5, 5, 0 }, + { 0x1029, 5, 5, 0 }, + { 0x102a, 5, 5, 0 }, + { 0x102b, 5, 5, 0 }, + { 0x102c, 5, 5, 0 }, + { 0x102d, 5, 5, 0 }, + { 0x102e, 5, 5, 0 }, + { 0x102f, 5, 5, 0 }, { 0x86, 2, 2, 0 }, // LDA { 0x96, 4, 3, 0 }, diff -r c501b3ce39c8 -r 0af33282b518 lwasm/insn_rel.c --- a/lwasm/insn_rel.c Thu Mar 03 21:17:48 2016 -0700 +++ b/lwasm/insn_rel.c Thu Mar 03 21:38:21 2016 -0700 @@ -308,7 +308,6 @@ { lwasm_emitop(l, instab[l->insn].ops[2]); lwasm_emit(l, offs); - l->cycle_adj = 2; } } else @@ -316,6 +315,5 @@ lwasm_emitop(l, instab[l -> insn].ops[3]); lwasm_emitexpr(l, e, 2); - l->cycle_adj = 4; } }