From 2de700b122dce0d7968986f45250760e5d656381 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Thu, 30 Jun 2016 18:00:07 +0100 Subject: [PATCH] copt: improvements and new rules work --- Applications/SmallC/copt.c | 13 +++ Applications/SmallC/rules.6809 | 167 ++++++++++++++++++++++++++------- 2 files changed, 145 insertions(+), 35 deletions(-) diff --git a/Applications/SmallC/copt.c b/Applications/SmallC/copt.c index b899c641..b3c4546a 100644 --- a/Applications/SmallC/copt.c +++ b/Applications/SmallC/copt.c @@ -583,6 +583,19 @@ static char *subst(char *pat) } i += sprintf(&buf[i], "%s$%lx", num < 0 ? "-" : "", labs(num)); pat++; + } else if (pat[0] == '%' && pat[1] == '{') { + /* Substitute with expression decimal */ + cp = pat + 2; + if ((pat = strchr(cp, '}')) == NULL || pat - cp <= 0) + num = 0; + else + num = eval(cp, pat - cp); + if (i >= MAXLINE - 20) { + fprintf(stderr, "%s: line too long\n", progname); + exit(1); + } + i += sprintf(&buf[i], "%d", num); + pat++; } else if (pat[0] == '%' && pat[1] == '=') { /* Substitute with converted variable */ /* First seperate all parts of the pattern string */ diff --git a/Applications/SmallC/rules.6809 b/Applications/SmallC/rules.6809 index c9cc8491..2f543e9e 100644 --- a/Applications/SmallC/rules.6809 +++ b/Applications/SmallC/rules.6809 @@ -1,8 +1,14 @@ +# +# Eliminate pointless branches +# lbra %1 %1: = %1: +# +# Reverse branches to optimize +# lbeq %1 lbra %2 %1: @@ -10,54 +16,145 @@ lbra %2 lbne %2 %1: -tfr u,d -pshs d -tfr d,u -ldd %1 +lbne %1 +lbra %2 +%1: = -pshs u -ldd %1 +lbeq %2 +%1: -tfr u,d +# +# Fix up the stack based add and subtraction +# generated by scc +# +ldd %1 pshs d -ldd #%1 -puls x -std ,x +ldd %2 +addd ,s++ = -tfr u,x -ldd #%1 -std ,x - -leau %1,s -pshs u -ldd ,u +ldd %1 addd %2 -puls x -std ,x -subd %2 + +ldd %1 +pshs d +ldd %2 +subd ,s++ +coma +comb +addd #1 = -leax %1,s -ldd ,x -addd %2 -std ,x +ldd %1 subd %2 -tfr u,d +# +# Post increment load into d or b via u. Relies on the fact that +# the base compiler won't generate an std ,u in this pattern +# +ldd %1 +addd #2 +std %1 +subd #2 tfr d,u ldd ,u = -ldd ,u +ldu %1 +ldd ,u++ +stu %1 -tfr u,d +ldd %1 +addd #1 +std %1 +subd #1 tfr d,u +ldb ,u = -tfr u,d +ldu %1 +ldb ,u++ +stu %1 -leau %d,s -tfr u,x -ldd %1 -std ,x +# +# FIXME: make sure the assembler can cope with a+b+c,s +# +ldd %1,s +addd #1 +std %1,s +subd #1 +pshs d = -leax %d,s -ldd %1 -std ,x +ldd %1,s +pshs d +addd #1 +std %{%1+2},s + +# +# Commonly occuring string case +# Could do for all values in -128 to +127 but not nice way +# I can see to specify that in copt until I hack copt 8) +# Should do ne cases FIXME +# + +ldb %1 +sex +cmpd #0 +lbeq %2 +ldd %3 += +ldb %1 +cmpb #0 +lbeq %2 +ldd %3 + + +# +# Commonly occuring string case +# Could do for all values in 0 to 255 but not nice way +# I can see to specify that in copt until I hack copt 8) +# + +ldb %1 +clr a +cmpd #0 +lbeq %2 +ldd %3 += +ldb %1 +cmpb #0 +lbeq %2 +ldd %3 + +# +# Ditto but after the ,u++ optimization +# + +ldb %1 +stu %2 +sex +cmpd #0 +lbeq %3 +ldd %4 += +ldb %1 +stu %2 +cmpb #0 +lbeq %3 +ldd %4 + + +# +# Commonly occuring string case +# Could do for all values in 0 to 255 but not nice way +# I can see to specify that in copt until I hack copt 8) +# + +ldb %1 +stu %2 +clr a +cmpd #0 +lbeq %3 +ldd %4 += +ldb %1 +stu %2 +cmpb #0 +lbeq %3 +ldd %4 -- 2.34.1