From d186412cedf50326312fcb1b4c417d6eeca260f6 Mon Sep 17 00:00:00 2001 From: frief Date: Fri, 25 Jun 2004 15:14:24 +0000 Subject: [PATCH] added peepholes 182.d (return 0.0), 256 (range check), 257 (do while), 258.a-f (bit banging f.e. on 3-wire SPI bus) git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3366 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- src/mcs51/peeph.def | 167 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 165 insertions(+), 2 deletions(-) diff --git a/src/mcs51/peeph.def b/src/mcs51/peeph.def index 98a65b9e..6225543d 100644 --- a/src/mcs51/peeph.def +++ b/src/mcs51/peeph.def @@ -1120,6 +1120,17 @@ replace { mov dptr,#(((%2)<<8) + %1) } +// applies to return 0.0; in f.e. sincosf.c +replace { + mov dpl,#%1 + clr a + mov dph,a +} by { + ; Peephole 182.d used 16 bit load of dptr + mov dptr,#(%1&0x00ff) + clr a +} + replace { anl %1,#%2 anl %1,#%3 @@ -3095,14 +3106,14 @@ replace { jnz %1 %1: } by { - ; Peephole 249a jump optimization + ; Peephole 249.a jump optimization } if labelRefCount %1 1 replace { jz %1 %1: } by { - ; Peephole 249b jump optimization + ; Peephole 249.b jump optimization } if labelRefCount %1 1 @@ -3204,6 +3215,7 @@ replace { ret } + // applies to f.e. funptrs.c // saves one byte if %1 is a register or @register replace { @@ -3238,3 +3250,154 @@ replace { mov dptr,%5 jmp @a+dptr } + +// applies to f.e. jump tables and scott-bool1.c. +// similar peepholes can be constructed for other instructions +// after which a flag or a register is known (like: djnz, cjne, jnc) +replace { + jc %1 +%2: + clr c +} by { + ; Peephole 256.a removed redundant clr c + jc %1 +%2: +} if labelRefCount %2 0 + +// applies to f.e. logf.c +replace { + jnz %1 +%2: + clr a +} by { + ; Peephole 256.b removed redundant clr a + jnz %1 +%2: +} if labelRefCount %2 0 + + +// unsigned char i=8; do{ } while(--i != 0); +// this currently only applies if i is kept in a register +replace { + dec %1 + cjne %1,#0x00,%2 +} by { + ; Peephole 257 optimized decrement with compare + djnz %1,%2 +} if notVolatile %1 + + +// in_byte<<=1; if(in_bit) in_byte|=1; +// helps f.e. reading data on a 3-wire (SPI) bus +replace { + mov a,%1 + add a,%1 + mov %1,a + jnb %2,%3 +%4: + orl %1,#0x01 +%3: +} by { + ; Peephole 258.a optimized bitbanging + mov a,%1 + mov c,%2 + addc a,%1 + mov %1,a +%4: +%3: +} if notVolatile %1 + +// in_byte<<=1; if(in_bit) in_byte|=1; +replace { + mov a,r%1 + add a,r%1 + mov r%1,a + jnb %2,%3 +%4: + orl ar%1,#0x01 +%3: +} by { + ; Peephole 258.b optimized bitbanging + mov a,r%1 + mov c,%2 + addc a,r%1 + mov r%1,a +%4: +%3: +} + +// in_byte>>=1; if(in_bit) in_byte|=0x80; +replace { + mov a,%1 + clr c + rrc a + mov %1,a + jnb %2,%3 +%4: + orl %1,#0x80 +%3: +} by { + ; Peephole 258.c optimized bitbanging + mov a,%1 + mov c,%2 + rrc a + mov %1,a +%4: +%3: +} if notVolatile %1 + +// in_byte>>=1; if(in_bit) in_byte|=0x80; +replace { + mov a,r%1 + clr c + rrc a + mov r%1,a + jnb %2,%3 +%4: + orl ar%1,#0x80 +%3: +} by { + ; Peephole 258.d optimized bitbanging + mov a,r%1 + mov c,%2 + rrc a + mov r%1,a +%4: +%3: +} + +// out_bit=out_byte&0x80; out_byte<<=1; +// helps f.e. writing data on a 3-wire (SPI) bus +replace { + mov a,%1 + mov c,acc.7 + mov %2,c + mov a,%1 + add a,%1 + mov %1,a +} by { + ; Peephole 258.e optimized bitbanging + mov a,%1 + add a,%1 + mov %2,c + mov %1,a +} if notVolatile %1 + +// out_bit=out_byte&0x01; out_byte>>=1; +replace { + mov a,%1 + mov c,acc.0 + mov %2,c + mov a,%1 + clr c + rrc a + mov %1,a +} by { + ; Peephole 258.f optimized bitbanging + mov a,%1 + clr c + rrc a + mov %2,c + mov %1,a +} if notVolatile %1 + -- 2.47.2