From e812347e2ade88a5922c9cd9eebda93ef9c3fd07 Mon Sep 17 00:00:00 2001 From: michaelh Date: Mon, 19 Nov 2001 05:38:44 +0000 Subject: [PATCH] * src/z80/gen.c (genCmp): Fixed compare on unsigned. git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1621 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 2 ++ src/z80/gen.c | 23 +++++++++++++++-------- support/regression/tests/compare.c | 13 +++++++++++++ 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 966497fd..32f70621 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2001-11-18 Michael Hope + * src/z80/gen.c (genCmp): Fixed compare on unsigned. + * src/z80/ralloc.c (packRegsForHLUse3): Created and optimised. (packRegsForIYUse): Created and optimised. diff --git a/src/z80/gen.c b/src/z80/gen.c index 5652ea6b..4572471a 100644 --- a/src/z80/gen.c +++ b/src/z80/gen.c @@ -3272,13 +3272,13 @@ genPlus (iCode * ic) emit2 ("add hl,%s", _pairs[left].name); goto release; } - else if (right != PAIR_INVALID) + else if (right != PAIR_INVALID && right != PAIR_HL) { fetchPair (PAIR_HL, AOP (IC_LEFT (ic))); emit2 ("add hl,%s", getPairName (AOP (IC_RIGHT (ic)))); goto release; } - else if (left != PAIR_INVALID) + else if (left != PAIR_INVALID && left != PAIR_HL) { fetchPair (PAIR_HL, AOP (IC_RIGHT (ic))); emit2 ("add hl,%s", getPairName (AOP (IC_LEFT (ic)))); @@ -3290,10 +3290,10 @@ genPlus (iCode * ic) } } - if (isPair (AOP (IC_RIGHT (ic))) && AOP_TYPE (IC_LEFT (ic)) == AOP_IMMD) + if (isPair (AOP (IC_RIGHT (ic))) && AOP_TYPE (IC_LEFT (ic)) == AOP_IMMD && getPairId (AOP (IC_RIGHT (ic))) != PAIR_HL) { fetchPair (PAIR_HL, AOP (IC_LEFT (ic))); - emit2 ("add hl,%s", getPairName (AOP (IC_RIGHT (ic)))); + emit2 ("add hl,%s ; 2", getPairName (AOP (IC_RIGHT (ic)))); spillCached(); commitPair ( AOP (IC_RESULT (ic)), PAIR_HL); goto release; @@ -4112,14 +4112,21 @@ release: code a little differently */ if (ifx) { - if (IS_GB) + if (sign) { - emit2 ("rlca"); - genIfxJump (ifx, swap_sense ? "nc" : "c"); + if (IS_GB) + { + emit2 ("rlca"); + genIfxJump (ifx, swap_sense ? "nc" : "c"); + } + else + { + genIfxJump (ifx, swap_sense ? "p" : "m"); + } } else { - genIfxJump (ifx, swap_sense ? "p" : "m"); + genIfxJump (ifx, swap_sense ? "nc" : "c"); } } else diff --git a/support/regression/tests/compare.c b/support/regression/tests/compare.c index f6e9ee6c..f058c3a6 100644 --- a/support/regression/tests/compare.c +++ b/support/regression/tests/compare.c @@ -88,6 +88,19 @@ testCompareVariables(void) ASSERT(left >= right); } +static void +testUnsignedCompare(void) +{ + {attr} {storage} unsigned {type} left, right; + + left = 0; + right = (unsigned {type})-1; + + ASSERT(left < right); + ASSERT(left <= right); + ASSERT(right > left); + ASSERT(right >= left); +} /* Common cases: Around zero -- 2.47.2