Mercurial > hg > index.cgi
changeset 201:4503199d56ba
Short circuit unneeded loops in pass4
Added debugging messages to deduce why pass4.c ran so slow. Short circuit
unneeded looping yields approx. 70% reduction in execution time.
author | William Astle <lost@l-w.ca> |
---|---|
date | Fri, 16 Mar 2012 22:22:14 -0600 |
parents | 348e2816ce32 |
children | 47a055c57d4a |
files | lwasm/pass4.c |
diffstat | 1 files changed, 17 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/lwasm/pass4.c Fri Mar 16 19:44:12 2012 -0600 +++ b/lwasm/pass4.c Fri Mar 16 22:22:14 2012 -0600 @@ -56,6 +56,7 @@ // find an unresolved instruction for ( ; sl && sl -> len != -1; sl = sl -> next) { + debug_message(as, 200, "Search line %p", sl); as -> cl = sl; lwasm_reduce_expr(as, sl -> addr); lwasm_reduce_expr(as, sl -> daddr); @@ -64,7 +65,8 @@ for (le = sl -> exprs; le; le = le -> next) lwasm_reduce_expr(as, le -> expr); } - + + debug_message(as, 200, "Found line %p", sl); // simplify address as -> cl = sl; lwasm_reduce_expr(as, sl -> addr); @@ -78,21 +80,31 @@ if (sl -> len == -1 && sl -> insn >= 0 && instab[sl -> insn].resolve) { (instab[sl -> insn].resolve)(as, sl, 1); + debug_message(as, 200, "Try resolve = %d/%d", sl -> len, sl -> dlen); if (force && sl -> len == -1 && sl -> dlen == -1) { lwasm_register_error(as, sl, "Instruction failed to resolve."); return; } } - cnt--; - if (cnt == 0) - return; + if (sl -> len != -1 && sl -> dlen != -1) + { + cnt--; + if (cnt == 0) + return; + + // this one resolved - try looking for the next one instead + // of wasting time running through the rest of the lines + continue; + } do { + debug_message(as, 200, "Flatten after..."); rc = 0; for (cl = sl; cl; cl = cl -> next) { + debug_message(as, 200, "Flatten line %p", cl); as -> cl = cl; // simplify address @@ -116,6 +128,7 @@ else cl -> dlen = cl -> len; } + debug_message(as, 200, "Flatten resolve returns %d", cl -> len); if (cl -> len != -1 && cl -> dlen != -1) { rc++;