From b68de0bae973fa412a8d4646cb5033200e5dba6e Mon Sep 17 00:00:00 2001 From: MaartenBrock Date: Fri, 3 Nov 2006 09:11:47 +0000 Subject: [PATCH] * device/include/mcs51/c8051f020.h, * device/include/mcs51/c8051f040.h, * device/include/mcs51/c8051f060.h, * device/include/mcs51/c8051f120.h: added PS0, fixed bug 1589279 * src/z80/gen.c (gencjneshort), * src/z80/peeph.def: applied patch 1571373, thanks Philipp Krause git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4459 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 9 + device/include/mcs51/c8051f020.h | 3 +- device/include/mcs51/c8051f040.h | 4 + device/include/mcs51/c8051f060.h | 1 + device/include/mcs51/c8051f120.h | 1 + src/z80/gen.c | 19 ++- src/z80/peeph.def | 271 +++++++++++++++++++++++++++++-- 7 files changed, 287 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index 05a9532e..f5d7807b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2006-11-03 Maarten Brock + + * device/include/mcs51/c8051f020.h, + * device/include/mcs51/c8051f040.h, + * device/include/mcs51/c8051f060.h, + * device/include/mcs51/c8051f120.h: added PS0, fixed bug 1589279 + * src/z80/gen.c (gencjneshort), + * src/z80/peeph.def: applied patch 1571373, thanks Philipp Krause + 2006-10-31 Borut Razem * debugger/mcs51/acinclude.m4, debugger/mcs51/aclocal.m4, diff --git a/device/include/mcs51/c8051f020.h b/device/include/mcs51/c8051f020.h index cec6e9b3..58326c15 100644 --- a/device/include/mcs51/c8051f020.h +++ b/device/include/mcs51/c8051f020.h @@ -244,8 +244,8 @@ __sbit __at (0xA8) EX0 ; /* EXTERNAL INTERRUPT 0 ENABLE __sbit __at (0xA9) ET0 ; /* TIMER 0 INTERRUPT ENABLE */ __sbit __at (0xAA) EX1 ; /* EXTERNAL INTERRUPT 1 ENABLE */ __sbit __at (0xAB) ET1 ; /* TIMER 1 INTERRUPT ENABLE */ -__sbit __at (0xAC) ES ; /* SERIAL PORT 0 INTERRUPT ENABLE */ __sbit __at (0xAC) ES0 ; /* SERIAL PORT 0 INTERRUPT ENABLE */ +__sbit __at (0xAC) ES ; /* SERIAL PORT 0 INTERRUPT ENABLE */ __sbit __at (0xAD) ET2 ; /* TIMER 2 INTERRUPT ENABLE */ __sbit __at (0xAF) EA ; /* GLOBAL INTERRUPT ENABLE */ @@ -264,6 +264,7 @@ __sbit __at (0xB8) PX0 ; /* EXTERNAL INTERRUPT 0 PRIORITY __sbit __at (0xB9) PT0 ; /* TIMER 0 PRIORITY */ __sbit __at (0xBA) PX1 ; /* EXTERNAL INTERRUPT 1 PRIORITY */ __sbit __at (0xBB) PT1 ; /* TIMER 1 PRIORITY */ +__sbit __at (0xBC) PS0 ; /* SERIAL PORT PRIORITY */ __sbit __at (0xBC) PS ; /* SERIAL PORT PRIORITY */ __sbit __at (0xBD) PT2 ; /* TIMER 2 PRIORITY */ diff --git a/device/include/mcs51/c8051f040.h b/device/include/mcs51/c8051f040.h index 67388dac..2885a006 100644 --- a/device/include/mcs51/c8051f040.h +++ b/device/include/mcs51/c8051f040.h @@ -194,6 +194,9 @@ __sfr __at 0xE4 XBR3 ; /* CROSSBAR CONFIGURATION REGISTER 3 */ __sfr __at 0xE8 P6 ; /* PORT 6 */ __sfr __at 0xF8 P7 ; /* PORT 7 */ +/* +Do NOT use sfr16 for CAN0DAT ! +*/ /* BIT Registers */ @@ -314,6 +317,7 @@ __sbit __at 0xB8 PX0 ; /* EXTERNAL INTERRUPT 0 PRIORITY */ __sbit __at 0xB9 PT0 ; /* TIMER 0 PRIORITY */ __sbit __at 0xBA PX1 ; /* EXTERNAL INTERRUPT 1 PRIORITY */ __sbit __at 0xBB PT1 ; /* TIMER 1 PRIORITY */ +__sbit __at 0xBC PS0 ; /* SERIAL PORT PRIORITY */ __sbit __at 0xBC PS ; /* SERIAL PORT PRIORITY */ __sbit __at 0xBD PT2 ; /* TIMER 2 PRIORITY */ diff --git a/device/include/mcs51/c8051f060.h b/device/include/mcs51/c8051f060.h index 0835a6c3..a366e94f 100644 --- a/device/include/mcs51/c8051f060.h +++ b/device/include/mcs51/c8051f060.h @@ -335,6 +335,7 @@ __sbit __at 0xB8 PX0 ; /* EXTERNAL INTERRUPT 0 PRIORITY */ __sbit __at 0xB9 PT0 ; /* TIMER 0 PRIORITY */ __sbit __at 0xBA PX1 ; /* EXTERNAL INTERRUPT 1 PRIORITY */ __sbit __at 0xBB PT1 ; /* TIMER 1 PRIORITY */ +__sbit __at 0xBC PS0 ; /* SERIAL PORT PRIORITY */ __sbit __at 0xBC PS ; /* SERIAL PORT PRIORITY */ __sbit __at 0xBD PT2 ; /* TIMER 2 PRIORITY */ diff --git a/device/include/mcs51/c8051f120.h b/device/include/mcs51/c8051f120.h index 661ac954..dc53b8bb 100644 --- a/device/include/mcs51/c8051f120.h +++ b/device/include/mcs51/c8051f120.h @@ -352,6 +352,7 @@ __sbit __at (0xB8) PX0 ; /* EXTERNAL INTERRUPT 0 PRIORITY __sbit __at (0xB9) PT0 ; /* TIMER 0 PRIORITY */ __sbit __at (0xBA) PX1 ; /* EXTERNAL INTERRUPT 1 PRIORITY */ __sbit __at (0xBB) PT1 ; /* TIMER 1 PRIORITY */ +__sbit __at (0xBC) PS0 ; /* SERIAL PORT PRIORITY */ __sbit __at (0xBC) PS ; /* SERIAL PORT PRIORITY */ __sbit __at (0xBD) PT2 ; /* TIMER 2 PRIORITY */ diff --git a/src/z80/gen.c b/src/z80/gen.c index 527f3c1e..d2d02ba7 100644 --- a/src/z80/gen.c +++ b/src/z80/gen.c @@ -4779,11 +4779,11 @@ gencjneshort (operand * left, operand * right, symbol * lbl) { while (size--) { - emit2 ("ld a,%s", aopGet (AOP (left), offset, FALSE)); - if ((AOP_TYPE (right) == AOP_LIT) && lit == 0) + _moveA (aopGet (AOP (left), offset, FALSE)); + if ((unsigned int) ((lit >> (offset * 8)) & 0x0FFL) == 0) emit2 ("or a,a"); else - emit2 ("cp a,%s", aopGet (AOP (right), offset, FALSE)); + emit2 ("sub a,%s", aopGet (AOP (right), offset, FALSE)); emit2 ("jp NZ,!tlabel", lbl->key + 100); offset++; } @@ -4798,13 +4798,18 @@ gencjneshort (operand * left, operand * right, symbol * lbl) while (size--) { _moveA (aopGet (AOP (left), offset, FALSE)); - if ((AOP_TYPE (left) == AOP_DIR && AOP_TYPE (right) == AOP_LIT) && + if (/*AOP_TYPE (left) == AOP_DIR &&*/ AOP_TYPE (right) == AOP_LIT && ((unsigned int) ((lit >> (offset * 8)) & 0x0FFL) == 0)) - /* PENDING */ - emit2 ("jp NZ,!tlabel", lbl->key + 100); + { + /* PENDING */ + /* MB: pending what? doesn't this need "or a,a"? */ + /* and I don't think AOP_TYPE(left) has anything to do with this */ + emit2 ("or a,a"); + emit2 ("jp NZ,!tlabel", lbl->key + 100); + } else { - emit2 ("cp %s", aopGet (AOP (right), offset, FALSE)); + emit2 ("sub %s", aopGet (AOP (right), offset, FALSE)); emit2 ("jp NZ,!tlabel", lbl->key + 100); } offset++; diff --git a/src/z80/peeph.def b/src/z80/peeph.def index d94ffdd2..2fb852b6 100644 --- a/src/z80/peeph.def +++ b/src/z80/peeph.def @@ -3,11 +3,13 @@ replace { } by { ERROR - peephole - caught (hl),(hl) } + replace restart { ld %1,%1 } by { - ; Removed redundent load + ; peephole removed redundant load. } + replace restart { xor a,a or a,%1 @@ -18,13 +20,7 @@ replace restart { or a,%1 jp %2,%3 } -replace restart { - cp a,#0x00 - jp NZ,%1 -} by { - or a,a - jp NZ,%1 -} + replace restart { jp NZ,%1 jp %2 @@ -36,7 +32,8 @@ replace restart { %1: jp %3 %2: -} +} if labelRefCountChange(%1 -1) + replace restart { jp NZ,%1 jp %2 @@ -44,7 +41,8 @@ replace restart { } by { jp Z,%2 %1: -} +} if labelRefCountChange(%1 -1) + replace restart { jp Z,%1 jp %2 @@ -52,19 +50,22 @@ replace restart { } by { jp NZ,%2 %1: -} +} if labelRefCountChange(%1 -1) + replace restart { or a,%1 or a,a } by { or a,%1 } + replace restart { or a,%1) or a,a } by { or a,%1) } + replace restart { xor a,a or a,%1 @@ -79,6 +80,7 @@ replace restart { or a,%3 jp Z,%2 } + replace restart { jp NZ,%1 inc %3) @@ -89,37 +91,43 @@ replace restart { inc %3) %1: jp %2 -} +} if labelRefCountChange(%1 -1), labelRefCountChange(%2 1) + replace restart { xor a,a ld a,#0x00 } by { xor a,a } + replace { ld e,#0x00 ld d,#0x00 } by { ld de,#0x0000 } + replace { ld l,#0x00 ld h,#0x00 } by { ld hl,#0x0000 } + replace { ld c,#0x00 ld b,#0x00 } by { ld bc,#0x0000 } + replace restart { ld %1,a ld a,%1 } by { ld %1,a } if notVolatile %1 + replace restart { jp %1,%2 jr %3 @@ -130,7 +138,8 @@ replace restart { jr %3 %2: jp %4 -} +} if labelRefCountChange(%2 -1), labelRefCountChange(%4 1) + replace { ld l,e ld h,d @@ -142,12 +151,14 @@ replace { push de push bc } + replace { and a,#%1 or a,a } by { and a,#%1 } + replace { ld b,l ld a,b @@ -158,6 +169,7 @@ replace { pop bc ld b,a } + replace { ld d,l ld a,d @@ -168,6 +180,7 @@ replace { pop de ld d,a } + replace { ld a,b push af @@ -176,6 +189,7 @@ replace { push bc inc sp } + replace { ld a,d push af @@ -184,6 +198,7 @@ replace { push de inc sp } + replace { ld a,%1 sub a,#%2 @@ -198,6 +213,7 @@ replace { cp a,#%4 jp P,%5 } + replace { ld e,l ld d,h @@ -207,6 +223,7 @@ replace { ld e,l ld d,h } + replace { ld %1,%2 ld %3,%4 @@ -217,3 +234,231 @@ replace { ld %3,%4 } +// From: Philipp Klaus Krause +replace restart { + ld %1,a + ld a,%2 + add a,%1 + ld %1,a +} by { + ; peephole removed loads by exploiting commutativity of addition. + add a,%2 + ld %1,a +} + +// From: Philipp Klaus Krause +replace restart { + ld %1,a + ld a,%2 + add a,%1 +} by { + ld %1, a + ; peephole removed load by exploiting commutativity of addition. + add a, %2 +} + +// From: Philipp Klaus Krause +replace { + or a,%1 + jp NZ,%2 + ld %3,#0x00 +} by { + or a,%1 + jp NZ,%2 + ld %3,a + ; peephole replaced constant #0x00 by a (which has just been tested to be #0x00). +} + +// From: Philipp Klaus Krause +replace { + and a,%1 + jp NZ,%2 + ld %3,#0x00 +} by { + and a,%1 + jp NZ,%2 + ld %3,a + ; peephole replaced constant #0x00 by a (which has just been tested to be #0x00). +} + +// From: Philipp Klaus Krause +replace { + sub a,%1 + jp NZ,%2 + ld %3,#0x00 +} by { + sub a,%1 + jp NZ,%2 + ld %3,a + ; peephole replaced constant #0x00 by a (which has just been tested to be #0x00). +} + +// From: Philipp Klaus Krause +replace { + dec a + jp NZ,%1 + ld %2,#0x00 +} by { + dec a + jp NZ,%1 + ld %2,a + ; peephole replaced constant #0x00 by a (which has just been tested to be #0x00). +} + +// From: Philipp Klaus Krause +replace { + or a,%1 + jp NZ,%2 + ld a,%3 + or a,a +} by { + or a,%1 + jp NZ,%2 + or a,%3 + ; peephole shortened or using a (which has just been tested to be #0x00). +} + +// From: Philipp Klaus Krause +replace { + and a,%1 + jp NZ,%2 + ld a,%3 + or a,a +} by { + and a,%1 + jp NZ,%2 + or a,%3 + ; peephole shortened or using a (which has just been tested to be #0x00). +} + +// From: Philipp Klaus Krause +replace { + sub a,%1 + jp NZ,%2 + ld a,%3 + or a,a +} by { + sub a,%1 + jp NZ,%2 + or a,%3 + ; peephole shortened or using a (which has just been tested to be #0x00). +} + +// From: Philipp Klaus Krause +replace { + dec a + jp NZ,%1 + ld a,%2 + or a,a +} by { + dec a + jp NZ,%1 + or a,%2 + ; peephole shortened or using a (which has just been tested to be #0x00). +} + +// From: Philipp Klaus Krause +replace restart { + or a,%1 + jp NZ,%2 + push %3 + ld %4,#0x00 +} by { + or a,%1 + jp NZ,%2 + push %3 + ld %4,a + ; peephole replaced constant #0x00 by a (which has just been tested to be #0x00). +} + +// From: Philipp Klaus Krause +replace restart { + and a,%1 + jp NZ,%2 + push %3 + ld %4,#0x00 +} by { + sub a,%1 + jp NZ,%2 + push %3 + ld %4,a + ; peephole replaced constant #0x00 by a (which has just been tested to be #0x00). +} + +// From: Philipp Klaus Krause +replace restart { + sub a,%1 + jp NZ,%2 + push %3 + ld %4,#0x00 +} by { + sub a,%1 + jp NZ,%2 + push %3 + ld %4,a + ; peephole replaced constant #0x00 by a (which has just been tested to be #0x00). +} + +// From: Philipp Klaus Krause +replace restart { + dec a + jp NZ,%1 + push %2 + ld %3,#0x00 +} by { + dec a + jp NZ,%1 + push %2 + ld %3,a + ; peephole replaced constant #0x00 by a (which has just been tested to be #0x00). +} + +// From: Philipp Klaus Krause +replace restart{ + jp NZ,%1 + or a,%2 + jp Z,%3 +%1: + jp %4 +%3: +} by { + jp NZ,%4 + ; peephole redirected jump + or a,%2 + jp NZ,%4 + ; peephole redirected jump +%3: +} if labelRefCount(%1 1), labelRefCountChange(%1 -1), labelRefCountChange(%3 -1), labelRefCountChange(%4 1) + +// Should be one of the last ones. Opens the code to further peephole optimization. +// From: Philipp Klaus Krause +replace restart { +%1: +} by { + ; peephole removed unused label %1. +} if labelRefCount(%1 0) + +// From: Philipp Klaus Krause +replace { + jp Z,%5 +} by { + jr Z,%5 +} if labelInRange() + +replace { + jp NZ,%5 +} by { + jr NZ,%5 +} if labelInRange() + +replace { + jp C,%5 +} by { + jr C,%5 +} if labelInRange() + +replace { + jp NC,%5 +} by { + jr NC,%5 +} if labelInRange() -- 2.30.2