From a0df5f7e9b47a96bef4a94b8c96692f0156acec0 Mon Sep 17 00:00:00 2001 From: bernhardheld Date: Wed, 26 Oct 2005 06:48:27 +0000 Subject: [PATCH] * src/mcs51/gen.c (genMinus): fixed bug 1270906: reverse subtraction, carry must be complemented too * src/mcs51/peeph.def: addded rule 262 to remove double cpl c, which could be emitted by genMinus git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3910 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 7 +++++++ src/mcs51/gen.c | 10 +++++++--- src/mcs51/peeph.def | 7 +++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2c55b617..608a80f4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2005-10-26 Bernhard Held + + * src/mcs51/gen.c (genMinus): fixed bug 1270906: reverse subtraction, + carry must be complemented too + * src/mcs51/peeph.def: addded rule 262 to remove double cpl c, which + could be emitted by genMinus + 2005-10-25 Bernhard Held * src/SDCCast.c (addCast): added promotion for bit variables diff --git a/src/mcs51/gen.c b/src/mcs51/gen.c index 76eb50f8..0757d80d 100644 --- a/src/mcs51/gen.c +++ b/src/mcs51/gen.c @@ -4581,13 +4581,17 @@ genMinus (iCode * ic) emitcode ("subb", "a,b"); popB (pushedB); } else { + /* reverse subtraction with 2's complement */ + if (offset == 0) + emitcode( "setb", "c"); + else + emitcode( "cpl", "c"); wassertl(!aopGetUsesAcc(leftOp, offset), "accumulator clash"); MOVA (aopGet(rightOp, offset, FALSE, TRUE)); - if (offset == 0) { - emitcode( "setb", "c"); - } emitcode("subb", "a,%s", aopGet(leftOp, offset, FALSE, TRUE)); emitcode("cpl", "a"); + if (size) /* skip if last byte */ + emitcode( "cpl", "c"); } } else { MOVA (aopGet (leftOp, offset, FALSE, FALSE)); diff --git a/src/mcs51/peeph.def b/src/mcs51/peeph.def index d93dd22d..77930077 100644 --- a/src/mcs51/peeph.def +++ b/src/mcs51/peeph.def @@ -4468,6 +4468,13 @@ replace { mov %1,a } +replace { + cpl c + cpl c +} by { + ; Peephole 262 removed redundant cpl c +} + // should be one of the last peepholes replace{ %1: -- 2.30.2