From: MaartenBrock Date: Sun, 6 Aug 2006 18:26:33 +0000 (+0000) Subject: * device/lib/Makefile.in (Z80SOURCES): enabled float support X-Git-Url: https://git.gag.com/?p=fw%2Fsdcc;a=commitdiff_plain;h=16ac8b47e19e2fde58a59fab8b53be041be8efe6 * device/lib/Makefile.in (Z80SOURCES): enabled float support * sim/ucsim/z80.src/inst.cc (inst_rst): generate breakpoint on RST8,ACC==0 * src/ds390/gen.c (shiftRLong), * src/hc08/gen.c (shiftLLong, shiftRLong): fixed bug 1533966 * src/mcs51/gen.c (sameReg): changed to sameByte, (xch_a_aopGet): new, (shiftL2Left2Result, shiftR2Left2Result, shiftRLeftOrResult, shiftLLong, shiftRLong): fixed bug 1533966 * src/z80/gen.c (shiftR2Left2Result, shiftL2Left2Result, genlshTwo, genLeftShiftLiteral, genrshTwo, genRightShiftLiteral): fixed bug 1533966 * support/regression/Makefile.in: disabled z80, enabled ucz80 * support/regression/tests/float_trans.c: enabled test for z80 and host * support/regression/tests/shifts2.c: new, for testing bug 1533966 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4322 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index a367e2b9..55798d62 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2006-08-06 Maarten Brock + + * device/lib/Makefile.in (Z80SOURCES): enabled float support + * sim/ucsim/z80.src/inst.cc (inst_rst): generate breakpoint on RST8,ACC==0 + * src/ds390/gen.c (shiftRLong), + * src/hc08/gen.c (shiftLLong, shiftRLong): fixed bug 1533966 + * src/mcs51/gen.c (sameReg): changed to sameByte, + (xch_a_aopGet): new, + (shiftL2Left2Result, shiftR2Left2Result, shiftRLeftOrResult, shiftLLong, + shiftRLong): fixed bug 1533966 + * src/z80/gen.c (shiftR2Left2Result, shiftL2Left2Result, genlshTwo, + genLeftShiftLiteral, genrshTwo, genRightShiftLiteral): fixed bug 1533966 + * support/regression/Makefile.in: disabled z80, enabled ucz80 + * support/regression/tests/float_trans.c: enabled test for z80 and host + * support/regression/tests/shifts2.c: new, for testing bug 1533966 + 2006-08-01 Borut Razem * src/mcs51/gen.c, src/dc390/gen.c: fixed warning: diff --git a/device/lib/Makefile.in b/device/lib/Makefile.in index b3aa8b28..50522964 100644 --- a/device/lib/Makefile.in +++ b/device/lib/Makefile.in @@ -66,65 +66,71 @@ OPT_DISABLE_PIC16 = @OPT_DISABLE_PIC16@ OPT_DISABLE_XA51 = @OPT_DISABLE_XA51@ OPT_DISABLE_Z80 = @OPT_DISABLE_Z80@ -SOURCES = _atof.c _atoi.c _atol.c _autobaud.c _bp.c _schar2fs.c \ - _decdptr.c _divsint.c _divslong.c _divuint.c \ - _divulong.c _fs2schar.c _fs2sint.c _fs2slong.c \ - _fs2uchar.c _fs2uint.c _fs2ulong.c _fsadd.c \ - _fsdiv.c _fseq.c _fsgt.c _fslt.c _fscmp.c _fsmul.c \ - _fsneq.c _fssub.c _gptrget.c _gptrgetc.c _gptrput.c \ - _sint2fs.c _iscntrl.c _isdigit.c _isgraph.c \ - _islower.c _isprint.c _ispunct.c _isspace.c \ - _isupper.c _isxdigit.c _itoa.c _ltoa.c \ - _slong2fs.c \ - _memcmp.c _memcpy.c _memmove.c _memset.c \ - _modsint.c _modslong.c _moduint.c _modulong.c \ - _mulint.c _mullong.c \ - abs.c labs.c \ - _ser.c _setjmp.c \ - _spx.c _startup.c \ - _strcat.c _strchr.c _strcmp.c _strcpy.c \ - _strcspn.c _strlen.c _strncat.c _strncmp.c \ - _strncpy.c _strpbrk.c _strrchr.c _strspn.c \ - _strstr.c _strtok.c \ - _uchar2fs.c _uint2fs.c _ulong2fs.c \ - calloc.c malloc.c realloc.c free.c \ - serial.c ser_ir.c printfl.c \ - printf_large.c sprintf.c vprintf.c puts.c gets.c \ - printf_fast.c printf_fast_f.c printf_tiny.c \ - assert.c time.c bpx.c \ - _fsget1arg.c _fsget2args.c _fsnormalize.c \ - _fsreturnval.c _fsrshift.c _fsswapargs.c _logexpf.c \ - fabsf.c frexpf.c ldexpf.c expf.c powf.c sincosf.c sinf.c \ - cosf.c logf.c log10f.c sqrtf.c tancotf.c tanf.c cotf.c \ - asincosf.c asinf.c acosf.c atanf.c atan2f.c sincoshf.c \ - sinhf.c coshf.c tanhf.c floorf.c ceilf.c modff.c errno.c +SOURCES = _autobaud.c _bp.c _decdptr.c \ + _gptrget.c _gptrgetc.c _gptrput.c \ + _ser.c _setjmp.c \ + serial.c ser_ir.c \ + _atof.c _atoi.c _atol.c _itoa.c _ltoa.c \ + _schar2fs.c _sint2fs.c _slong2fs.c \ + _uchar2fs.c _uint2fs.c _ulong2fs.c \ + _fs2schar.c _fs2sint.c _fs2slong.c \ + _fs2uchar.c _fs2uint.c _fs2ulong.c \ + _fsadd.c _fsdiv.c _fsmul.c _fssub.c \ + _fseq.c _fsgt.c _fslt.c _fsneq.c \ + _divsint.c _divslong.c _divuint.c _divulong.c \ + _modsint.c _modslong.c _moduint.c _modulong.c \ + _mulint.c _mullong.c \ + abs.c labs.c \ + _iscntrl.c _isdigit.c _isgraph.c \ + _isprint.c _ispunct.c _isspace.c \ + _islower.c _isupper.c _isxdigit.c \ + _spx.c _startup.c \ + _strcat.c _strchr.c _strcmp.c _strcpy.c \ + _strcspn.c _strlen.c _strncat.c _strncmp.c \ + _strncpy.c _strpbrk.c _strrchr.c _strspn.c \ + _strstr.c _strtok.c \ + _memcmp.c _memcpy.c _memmove.c _memset.c \ + calloc.c malloc.c realloc.c free.c \ + printf_large.c sprintf.c vprintf.c puts.c gets.c \ + printf_fast.c printf_fast_f.c printf_tiny.c printfl.c \ + assert.c time.c bpx.c \ + _fscmp.c _fsget1arg.c _fsget2args.c _fsnormalize.c \ + _fsreturnval.c _fsrshift.c _fsswapargs.c _logexpf.c \ + fabsf.c frexpf.c ldexpf.c expf.c powf.c sincosf.c sinf.c \ + cosf.c logf.c log10f.c sqrtf.c tancotf.c tanf.c cotf.c \ + asincosf.c asinf.c acosf.c atanf.c atan2f.c sincoshf.c \ + sinhf.c coshf.c tanhf.c floorf.c ceilf.c modff.c errno.c OBJECTS = $(patsubst %.c,$(PORTDIR)/%.rel,$(SOURCES)) -Z80SOURCES = _atof.c _atoi.c \ - _iscntrl.c _isdigit.c _isgraph.c \ - _islower.c _isprint.c _ispunct.c _isspace.c \ - _isupper.c _isxdigit.c \ - _memcmp.c _memcpy.c _memmove.c _memset.c \ - _startup.c \ - _strcat.c _strchr.c _strcmp.c _strcpy.c \ - _strcspn.c _strlen.c _strncat.c _strncmp.c \ - _strncpy.c _strpbrk.c _strrchr.c _strspn.c \ - _strstr.c _strtok.c \ - assert.c \ - _modslong.c _modulong.c \ - _mullong.c \ - abs.c labs.c \ - _divslong.c _divulong.c \ - calloc.c malloc.c realloc.c free.c \ - printf_large.c sprintf.c vprintf.c puts.c gets.c \ - _fs2schar.c _fs2sint.c _fs2slong.c \ - _fs2uchar.c _fs2uint.c _fs2ulong.c _fsadd.c \ - _fsdiv.c _fseq.c _fsgt.c _fslt.c _fsmul.c \ - _fsneq.c _fssub.c \ - _uchar2fs.c _uint2fs.c \ - _ulong2fs.c \ - _slong2fs.c _sint2fs.c _schar2fs.c +Z80SOURCES = \ + _atof.c _atoi.c _atol.c _itoa.c _ltoa.c \ + _schar2fs.c _sint2fs.c _slong2fs.c \ + _uchar2fs.c _uint2fs.c _ulong2fs.c \ + _fs2schar.c _fs2sint.c _fs2slong.c \ + _fs2uchar.c _fs2uint.c _fs2ulong.c \ + _fsadd.c _fsdiv.c _fsmul.c _fssub.c \ + _fseq.c _fsgt.c _fslt.c _fsneq.c \ + _divslong.c _divulong.c \ + _modslong.c _modulong.c \ + _mullong.c \ + abs.c labs.c \ + _iscntrl.c _isdigit.c _isgraph.c \ + _isprint.c _ispunct.c _isspace.c \ + _islower.c _isupper.c _isxdigit.c \ + _startup.c \ + _strcat.c _strchr.c _strcmp.c _strcpy.c \ + _strcspn.c _strlen.c _strncat.c _strncmp.c \ + _strncpy.c _strpbrk.c _strrchr.c _strspn.c \ + _strstr.c _strtok.c \ + _memcmp.c _memcpy.c _memmove.c _memset.c \ + calloc.c malloc.c realloc.c free.c \ + printf_large.c sprintf.c vprintf.c puts.c gets.c \ + assert.c time.c \ + fabsf.c frexpf.c ldexpf.c expf.c powf.c sincosf.c sinf.c \ + cosf.c logf.c log10f.c sqrtf.c tancotf.c tanf.c cotf.c \ + asincosf.c asinf.c acosf.c atanf.c atan2f.c sincoshf.c \ + sinhf.c coshf.c tanhf.c floorf.c ceilf.c modff.c errno.c Z80OBJECTS = $(Z80SOURCES:%.c=$(PORTDIR)/%.o) @@ -156,32 +162,33 @@ XA51SOURCES = _atof.c _atoi.c _atol.c _schar2fs.c \ XA51OBJECTS = $(XA51SOURCES:%.c=$(PORTDIR)/%.rel) -HC08SOURCES = _atof.c _atoi.c _atol.c _schar2fs.c \ - _divsint.c _divslong.c \ - _fs2schar.c _fs2sint.c _fs2slong.c \ - _fs2uchar.c _fs2uint.c _fs2ulong.c _fsadd.c \ - _fsdiv.c _fseq.c _fsgt.c _fslt.c _fsmul.c \ - _fsneq.c _fssub.c \ - _sint2fs.c _iscntrl.c _isdigit.c _isgraph.c \ - _islower.c _isprint.c _ispunct.c _isspace.c \ - _isupper.c _isxdigit.c _itoa.c _ltoa.c \ - _slong2fs.c \ - _memcmp.c _memcpy.c _memmove.c _memset.c \ - _modsint.c _modslong.c _moduint.c _modulong.c \ - abs.c labs.c \ - _spx.c _startup.c \ - _strcat.c _strchr.c _strcmp.c _strcpy.c \ - _strcspn.c _strlen.c _strncat.c _strncmp.c \ - _strncpy.c _strpbrk.c _strrchr.c _strspn.c \ - _strstr.c _strtok.c \ - _uchar2fs.c _uint2fs.c _ulong2fs.c \ - calloc.c malloc.c realloc.c free.c \ - printf_large.c sprintf.c vprintf.c \ - assert.c time.c \ - fabsf.c frexpf.c ldexpf.c expf.c powf.c sincosf.c sinf.c \ - cosf.c logf.c log10f.c sqrtf.c tancotf.c tanf.c cotf.c \ - asincosf.c asinf.c acosf.c atanf.c atan2f.c sincoshf.c \ - sinhf.c coshf.c tanhf.c floorf.c ceilf.c modff.c errno.c +HC08SOURCES = \ + _atof.c _atoi.c _atol.c _itoa.c _ltoa.c \ + _schar2fs.c _sint2fs.c _slong2fs.c \ + _uchar2fs.c _uint2fs.c _ulong2fs.c \ + _fs2schar.c _fs2sint.c _fs2slong.c \ + _fs2uchar.c _fs2uint.c _fs2ulong.c \ + _fsadd.c _fsdiv.c _fsmul.c _fssub.c \ + _fseq.c _fsgt.c _fslt.c _fsneq.c \ + _divsint.c _divslong.c \ + _modsint.c _modslong.c _moduint.c _modulong.c \ + abs.c labs.c \ + _iscntrl.c _isdigit.c _isgraph.c \ + _isprint.c _ispunct.c _isspace.c \ + _islower.c _isupper.c _isxdigit.c \ + _spx.c _startup.c \ + _strcat.c _strchr.c _strcmp.c _strcpy.c \ + _strcspn.c _strlen.c _strncat.c _strncmp.c \ + _strncpy.c _strpbrk.c _strrchr.c _strspn.c \ + _strstr.c _strtok.c \ + _memcmp.c _memcpy.c _memmove.c _memset.c \ + calloc.c malloc.c realloc.c free.c \ + printf_large.c sprintf.c vprintf.c puts.c gets.c \ + assert.c time.c \ + fabsf.c frexpf.c ldexpf.c expf.c powf.c sincosf.c sinf.c \ + cosf.c logf.c log10f.c sqrtf.c tancotf.c tanf.c cotf.c \ + asincosf.c asinf.c acosf.c atanf.c atan2f.c sincoshf.c \ + sinhf.c coshf.c tanhf.c floorf.c ceilf.c modff.c errno.c HC08OBJECTS = $(patsubst %.c,$(PORTDIR)/%.rel,$(HC08SOURCES)) diff --git a/sim/ucsim/z80.src/inst.cc b/sim/ucsim/z80.src/inst.cc index 69be604f..3cb181df 100644 --- a/sim/ucsim/z80.src/inst.cc +++ b/sim/ucsim/z80.src/inst.cc @@ -955,7 +955,8 @@ cl_z80::inst_rst(t_mem code) //PC = 0x08; switch (regs.A) { case 0: - ::exit(0); + return(resBREAKPOINT); +// ::exit(0); break; case 1: diff --git a/src/ds390/gen.c b/src/ds390/gen.c index 12fd0218..337f3cff 100644 --- a/src/ds390/gen.c +++ b/src/ds390/gen.c @@ -9626,12 +9626,13 @@ static void shiftRLong (operand * left, int offl, operand * result, int sign) { - int isSameRegs=sameRegs(AOP(left),AOP(result)); + bool overlapping = regsInCommon (left, result) || operandsEqu(left, result); - if (isSameRegs && offl>1) { - // we are in big trouble, but this shouldn't happen - werror(E_INTERNAL_ERROR, __FILE__, __LINE__); - } + if (overlapping && offl>1) + { + // we are in big trouble, but this shouldn't happen + werror(E_INTERNAL_ERROR, __FILE__, __LINE__); + } MOVA (aopGet (left, MSB32, FALSE, FALSE, NULL)); @@ -9662,28 +9663,44 @@ shiftRLong (operand * left, int offl, emitcode ("rrc", "a"); - if (isSameRegs && offl==MSB16) { - emitcode ("xch", - "a,%s",aopGet (left, MSB24, FALSE, FALSE, DP2_RESULT_REG)); - } else { - aopPut (result, "a", MSB32); - MOVA (aopGet (left, MSB24, FALSE, FALSE, NULL)); - } + if (overlapping && offl==MSB16) + { + emitcode ("xch", "a,%s", aopGet (left, MSB24, FALSE, FALSE, DP2_RESULT_REG)); + } + else + { + aopPut (result, "a", MSB32 - offl); + MOVA (aopGet (left, MSB24, FALSE, FALSE, NULL)); + } emitcode ("rrc", "a"); - if (isSameRegs && offl==1) { - emitcode ("xch", "a,%s", - aopGet (left, MSB16, FALSE, FALSE, DP2_RESULT_REG)); - } else { - aopPut (result, "a", MSB24); - MOVA (aopGet (left, MSB16, FALSE, FALSE, NULL)); - } - emitcode ("rrc", "a"); - aopPut (result, "a", MSB16 - offl); - if (offl == LSB) + if (overlapping && offl==MSB16) + { + emitcode ("xch", "a,%s", aopGet (left, MSB16, FALSE, FALSE, DP2_RESULT_REG)); + } + else + { + aopPut (result, "a", MSB24 - offl); + MOVA (aopGet (left, MSB16, FALSE, FALSE, NULL)); + } + + emitcode ("rrc", "a"); + if (offl != LSB) + { + aopPut (result, "a", MSB16 - offl); + } + else { - MOVA (aopGet (left, LSB, FALSE, FALSE, NULL)); + if (overlapping && offl==MSB16) + { + emitcode ("xch", "a,%s", aopGet (left, LSB, FALSE, FALSE, DP2_RESULT_REG)); + } + else + { + aopPut (result, "a", MSB16 - offl); + MOVA (aopGet (left, LSB, FALSE, FALSE, NULL)); + } emitcode ("rrc", "a"); aopPut (result, "a", LSB); } diff --git a/src/hc08/gen.c b/src/hc08/gen.c index d1fdc98d..2897a995 100644 --- a/src/hc08/gen.c +++ b/src/hc08/gen.c @@ -27,8 +27,8 @@ -------------------------------------------------------------------------*/ -#define D(x) -//#define D(x) x +//#define D(x) +#define D(x) x #include #include @@ -6309,7 +6309,7 @@ genlshTwo (operand * result, operand * left, int shCount) /*-----------------------------------------------------------------*/ /* shiftLLong - shift left one long from left to result */ -/* offl = LSB or MSB16 */ +/* offr = LSB or MSB16 */ /*-----------------------------------------------------------------*/ static void shiftLLong (operand * left, operand * result, int offr) @@ -6326,10 +6326,10 @@ shiftLLong (operand * left, operand * result, int offr) loadRegFromAop (hc08_reg_xa, AOP (left), LSB); rmwWithReg ("lsl", hc08_reg_a); rmwWithReg ("rol", hc08_reg_x); - storeRegToAop (hc08_reg_xa, AOP (result), offr); if (offr==LSB) { + storeRegToAop (hc08_reg_xa, AOP (result), offr); loadRegFromAop (hc08_reg_xa, AOP (left), MSB24); rmwWithReg ("rol", hc08_reg_a); rmwWithReg ("rol", hc08_reg_x); @@ -6337,7 +6337,9 @@ shiftLLong (operand * left, operand * result, int offr) } else if (offr==MSB16) { + storeRegToAop (hc08_reg_a, AOP (result), offr); loadRegFromAop (hc08_reg_a, AOP (left), MSB24); + storeRegToAop (hc08_reg_x, AOP (result), offr+1); rmwWithReg ("rol", hc08_reg_a); storeRegToAop (hc08_reg_a, AOP (result), offr+2); storeConstToAop (zero, AOP (result), 0); @@ -6658,6 +6660,7 @@ shiftRLong (operand * left, int offl, rmwWithReg ("lsr", hc08_reg_x); rmwWithReg ("ror", hc08_reg_a); storeRegToAop (hc08_reg_xa, AOP (result), MSB24); + loadRegFromAop (hc08_reg_xa, AOP (left), LSB); } else if (offl==MSB16) { @@ -6666,15 +6669,27 @@ shiftRLong (operand * left, int offl, rmwWithReg ("asr", hc08_reg_a); else rmwWithReg ("lsr", hc08_reg_a); + loadRegFromAop (hc08_reg_x, AOP (left), MSB24); storeRegToAop (hc08_reg_a, AOP (result), MSB24); - storeRegSignToUpperAop (hc08_reg_a, AOP (result), MSB32, sign); + loadRegFromAop (hc08_reg_a, AOP (left), MSB16); } - loadRegFromAop (hc08_reg_xa, AOP (left), offl); rmwWithReg ("ror", hc08_reg_x); rmwWithReg ("ror", hc08_reg_a); storeRegToAop (hc08_reg_xa, AOP (result), LSB); + if (offl==MSB16) + { + if (sign) + { + loadRegFromAop (hc08_reg_a, AOP (left), MSB24); + storeRegSignToUpperAop (hc08_reg_a, AOP (result), MSB32, sign); + } + else + { + storeConstToAop (zero, AOP (result), MSB32); + } + } pullOrFreeReg (hc08_reg_x, needpulx); pullOrFreeReg (hc08_reg_a, needpula); diff --git a/src/mcs51/gen.c b/src/mcs51/gen.c index f2b156b4..53b528ee 100644 --- a/src/mcs51/gen.c +++ b/src/mcs51/gen.c @@ -849,11 +849,14 @@ operandsEqu (operand * op1, operand * op2) } /*-----------------------------------------------------------------*/ -/* sameReg - two asmops have the same register at given offsets */ +/* sameByte - two asmops have the same address at given offsets */ /*-----------------------------------------------------------------*/ static bool -sameReg (asmop * aop1, int off1, asmop * aop2, int off2) +sameByte (asmop * aop1, int off1, asmop * aop2, int off2) { + if (aop1 == aop2 && off1 == off2) + return TRUE; + if (aop1->type != AOP_REG && aop1->type != AOP_CRY) return FALSE; @@ -1874,6 +1877,32 @@ toBoolean (operand * oper) } +/*-------------------------------------------------------------------*/ +/* xch_a_aopGet - for exchanging acc with value of the aop */ +/*-------------------------------------------------------------------*/ +static char * +xch_a_aopGet (operand * oper, int offset, bool bit16, bool dname) +{ + char * l; + + if (aopGetUsesAcc (oper, offset)) + { + emitcode("mov", "b,a"); + MOVA (aopGet (oper, offset, bit16, dname)); + emitcode("xch", "a,b"); + aopPut (oper, "a", offset); + emitcode("xch", "a,b"); + l = "b"; + } + else + { + l = aopGet (oper, offset, bit16, dname); + emitcode("xch", "a,%s", l); + } + return l; +} + + /*-----------------------------------------------------------------*/ /* genNot - generate code for ! operation */ /*-----------------------------------------------------------------*/ @@ -3439,7 +3468,6 @@ genFunction (iCode * ic) } } - if (fReentrant) { if (options.useXstack) @@ -8323,8 +8351,8 @@ shiftL2Left2Result (operand * left, int offl, { /* don't crash result[offr] */ MOVA (aopGet (left, offl, FALSE, FALSE)); - emitcode ("xch", "a,%s", aopGet (left, offl + MSB16, FALSE, FALSE)); - x = aopGet (result, offr, FALSE, FALSE); + x = xch_a_aopGet (left, offl + MSB16, FALSE, FALSE); + usedB = !strncmp(x, "b", 1); } else if (aopGetUsesAcc (result, offr)) { @@ -8375,8 +8403,8 @@ shiftR2Left2Result (operand * left, int offl, { /* don't crash result[offr] */ MOVA (aopGet (left, offl, FALSE, FALSE)); - emitcode ("xch", "a,%s", aopGet (left, offl + MSB16, FALSE, FALSE)); - x = aopGet (result, offr, FALSE, FALSE); + x = xch_a_aopGet (left, offl + MSB16, FALSE, FALSE); + usedB = !strncmp(x, "b", 1); } else if (aopGetUsesAcc (result, offr)) { @@ -8445,7 +8473,16 @@ shiftRLeftOrResult (operand * left, int offl, /* shift right accumulator */ AccRsh (shCount); /* or with result */ - emitcode ("orl", "a,%s", aopGet (result, offr, FALSE, FALSE)); + if (aopGetUsesAcc(result, offr)) + { + emitcode ("xch", "a,b"); + MOVA (aopGet (result, offr, FALSE, FALSE)); + emitcode ("orl", "a,b"); + } + else + { + emitcode ("orl", "a,%s", aopGet (result, offr, FALSE, FALSE)); + } /* back to result */ aopPut (result, "a", offr); } @@ -8515,8 +8552,7 @@ shiftLLong (operand * left, operand * result, int offr) emitcode ("add", "a,acc"); if (sameRegs (AOP (left), AOP (result)) && size >= MSB16 + offr && offr != LSB) - emitcode ("xch", "a,%s", - aopGet (left, LSB + offr, FALSE, FALSE)); + xch_a_aopGet (left, LSB + offr, FALSE, FALSE); else aopPut (result, "a", LSB + offr); } @@ -8531,8 +8567,7 @@ shiftLLong (operand * left, operand * result, int offr) emitcode ("rlc", "a"); if (sameRegs (AOP (left), AOP (result)) && size >= MSB24 + offr && offr != LSB) - emitcode ("xch", "a,%s", - aopGet (left, MSB16 + offr, FALSE, FALSE)); + xch_a_aopGet (left, MSB16 + offr, FALSE, FALSE); else aopPut (result, "a", MSB16 + offr); } @@ -8547,8 +8582,7 @@ shiftLLong (operand * left, operand * result, int offr) emitcode ("rlc", "a"); if (sameRegs (AOP (left), AOP (result)) && size >= MSB32 + offr && offr != LSB) - emitcode ("xch", "a,%s", - aopGet (left, MSB24 + offr, FALSE, FALSE)); + xch_a_aopGet (left, MSB24 + offr, FALSE, FALSE); else aopPut (result, "a", MSB24 + offr); } @@ -8883,9 +8917,9 @@ static void shiftRLong (operand * left, int offl, operand * result, int sign) { - bool useSameRegs = regsInCommon (left, result); + bool overlapping = regsInCommon (left, result) || operandsEqu(left, result); - if (useSameRegs && offl>1) + if (overlapping && offl>1) { // we are in big trouble, but this shouldn't happen werror(E_INTERNAL_ERROR, __FILE__, __LINE__); @@ -8900,9 +8934,9 @@ shiftRLong (operand * left, int offl, { emitcode ("rlc", "a"); emitcode ("subb", "a,acc"); - if (useSameRegs && sameReg (AOP (left), MSB32, AOP (result), MSB32)) + if (overlapping && sameByte (AOP (left), MSB32, AOP (result), MSB32)) { - emitcode ("xch", "a,%s", aopGet (left, MSB32, FALSE, FALSE)); + xch_a_aopGet (left, MSB32, FALSE, FALSE); } else { @@ -8912,7 +8946,16 @@ shiftRLong (operand * left, int offl, } else { - aopPut (result, zero, MSB32); + if (aopPutUsesAcc (result, zero, MSB32)) + { + emitcode("xch", "a,b"); + aopPut (result, zero, MSB32); + emitcode("xch", "a,b"); + } + else + { + aopPut (result, zero, MSB32); + } } } @@ -8927,28 +8970,29 @@ shiftRLong (operand * left, int offl, emitcode ("rrc", "a"); - if (useSameRegs && offl==MSB16 && - sameReg (AOP (left), MSB24, AOP (result), MSB32-offl)) + if (overlapping && offl==MSB16 && + sameByte (AOP (left), MSB24, AOP (result), MSB32-offl)) { - emitcode ("xch", "a,%s",aopGet (left, MSB24, FALSE, FALSE)); + xch_a_aopGet (left, MSB24, FALSE, FALSE); } else { - aopPut (result, "a", MSB32-offl); + aopPut (result, "a", MSB32 - offl); MOVA (aopGet (left, MSB24, FALSE, FALSE)); } emitcode ("rrc", "a"); - if (useSameRegs && offl==1 && - sameReg (AOP (left), MSB16, AOP (result), MSB24-offl)) + if (overlapping && offl==MSB16 && + sameByte (AOP (left), MSB16, AOP (result), MSB24-offl)) { - emitcode ("xch", "a,%s",aopGet (left, MSB16, FALSE, FALSE)); + xch_a_aopGet (left, MSB16, FALSE, FALSE); } else { - aopPut (result, "a", MSB24-offl); + aopPut (result, "a", MSB24 - offl); MOVA (aopGet (left, MSB16, FALSE, FALSE)); } + emitcode ("rrc", "a"); if (offl != LSB) { @@ -8956,10 +9000,10 @@ shiftRLong (operand * left, int offl, } else { - if (useSameRegs && - sameReg (AOP (left), LSB, AOP (result), MSB16-offl)) + if (overlapping && + sameByte (AOP (left), LSB, AOP (result), MSB16-offl)) { - emitcode ("xch", "a,%s",aopGet (left, LSB, FALSE, FALSE)); + xch_a_aopGet (left, LSB, FALSE, FALSE); } else { diff --git a/src/z80/gen.c b/src/z80/gen.c index 30d500eb..fa56bcc9 100644 --- a/src/z80/gen.c +++ b/src/z80/gen.c @@ -5707,6 +5707,9 @@ shiftR2Left2Result (operand * left, int offl, movLeft2Result (left, offl, result, offr, 0); movLeft2Result (left, offl + 1, result, offr + 1, 0); + if (shCount == 0) + return; + /* if (AOP(result)->type == AOP_REG) { */ tlbl = newiTempLabel (NULL); @@ -5753,6 +5756,9 @@ shiftL2Left2Result (operand * left, int offl, movLeft2Result (left, offl + 1, result, offr + 1, 0); } + if (shCount == 0) + return; + if (getPairId (AOP (result)) == PAIR_HL) { while (shCount--) @@ -5956,7 +5962,7 @@ shiftL1Left2Result (operand * left, int offl, /*-----------------------------------------------------------------*/ -/* genlshTwo - left shift two bytes by known amount != 0 */ +/* genlshTwo - left shift two bytes by known amount */ /*-----------------------------------------------------------------*/ static void genlshTwo (operand * result, operand * left, int shCount) @@ -5974,8 +5980,8 @@ genlshTwo (operand * result, operand * left, int shCount) if (shCount) { movLeft2Result (left, LSB, result, MSB16, 0); - aopPut (AOP (result), "!zero", 0); shiftL1Left2Result (left, LSB, result, MSB16, shCount); + aopPut (AOP (result), "!zero", LSB); } else { @@ -5988,7 +5994,7 @@ genlshTwo (operand * result, operand * left, int shCount) aopPut (AOP (result), "!zero", LSB); } } - /* 1 <= shCount <= 7 */ + /* 0 <= shCount <= 7 */ else { if (size == 1) @@ -6031,12 +6037,8 @@ genLeftShiftLiteral (operand * left, size = getSize (operandType (result)); /* I suppose that the left size >= result size */ - if (shCount == 0) - { - wassert (0); - } - else if (shCount >= (size * 8)) + if (shCount >= (size * 8)) { while (size--) { @@ -6231,7 +6233,7 @@ shiftR1Left2Result (operand * left, int offl, } /*-----------------------------------------------------------------*/ -/* genrshTwo - right shift two bytes by known amount != 0 */ +/* genrshTwo - right shift two bytes by known amount */ /*-----------------------------------------------------------------*/ static void genrshTwo (operand * result, operand * left, @@ -6264,7 +6266,7 @@ genrshTwo (operand * result, operand * left, aopPut (AOP (result), "!zero", 1); } } - /* 1 <= shCount <= 7 */ + /* 0 <= shCount <= 7 */ else { shiftR2Left2Result (left, LSB, result, LSB, shCount, sign); @@ -6292,12 +6294,8 @@ genRightShiftLiteral (operand * left, size = getSize (operandType (result)); /* I suppose that the left size >= result size */ - if (shCount == 0) - { - wassert (0); - } - else if (shCount >= (size * 8)) { + if (shCount >= (size * 8)) { const char *s; if (!SPEC_USIGN(getSpec(operandType(left)))) { _moveA(aopGet (AOP (left), 0, FALSE)); diff --git a/support/regression/Makefile.in b/support/regression/Makefile.in index ab3c6f5f..3378a7b0 100644 --- a/support/regression/Makefile.in +++ b/support/regression/Makefile.in @@ -69,7 +69,7 @@ GENERATE_CASES = $(srcdir)/generate-cases.py # Each directory under ports/ is used as a port name. Each port is tested. # Each port must have a spec.mk which describes how to build the object # files and how to run the emulator. -ALL_PORTS = $(filter-out .svn xa51 ucz80 gbz80 pic16,$(notdir $(wildcard $(PORTS_DIR)/*))) +ALL_PORTS = $(filter-out .svn xa51 z80 gbz80 pic16,$(notdir $(wildcard $(PORTS_DIR)/*))) # These ports will be cleaned with 'make clean' CLEAN_PORTS = $(filter-out .svn,$(notdir $(wildcard $(PORTS_DIR)/*))) diff --git a/support/regression/tests/float_trans.c b/support/regression/tests/float_trans.c index 6431baf6..c068b142 100644 --- a/support/regression/tests/float_trans.c +++ b/support/regression/tests/float_trans.c @@ -11,22 +11,20 @@ void testTrans(void) { -#if !defined(SDCC_z80) && !PORT_HOST -# ifdef SQRTF - ASSERT(fabsf (sqrtf (5.0) - 2.23606801) < 0.00001); -# endif -# ifdef LOGF +#ifdef SQRTF + ASSERT(fabsf (sqrtf (5.0) - 2.23606801) < 0.00001); +#endif +#ifdef LOGF ASSERT(fabsf (logf (124.0) - 4.82028150) < 0.00001); ASSERT(fabsf (log10f (124.0) - 2.09342169) < 0.00001); +#endif +#ifdef POWF + /* too big for small model */ +# ifndef SDCC_MODEL_SMALL + ASSERT(fabsf (powf (1.5, 2.0) - 2.24999976) < 0.00001); # endif -# ifdef POWF - /* too big for small modell */ -# ifndef SDCC_MODEL_SMALL - ASSERT(fabsf (powf (1.5, 2.0) - 2.24999976) < 0.00001); -# endif -# endif -# ifdef TANF +#endif +#ifdef TANF ASSERT(fabsf (tanf (1.6) - -34.23250579) < 0.00001); -# endif #endif } diff --git a/support/regression/tests/shifts2.c b/support/regression/tests/shifts2.c new file mode 100644 index 00000000..3708e575 --- /dev/null +++ b/support/regression/tests/shifts2.c @@ -0,0 +1,92 @@ +/** extended tests for shift operations, added by + Frieder Ferlemann to check for bugs related to bug 1533966 + + size: 8,16,32 + right: 0,1 + vol: 0,1 + sign: u, +*/ +#include +#ifdef __sun__ +# include +#else +# include +#endif + +#define SIZE ({size}) +#define RIGHT ({right}) +#define VOL ({vol}) + +#if SIZE == 8 +# define TYPE {sign}int8_t +# define TEST_VECT 0xa4 +#endif + +#if SIZE == 16 +# define TYPE {sign}int16_t +# define TEST_VECT 0xa8ce +#endif + +#if SIZE == 32 +# define TYPE {sign}int32_t +# define TEST_VECT 0xa8b5c4d6 +#endif + +#if RIGHT == 0 +# define SHIFT(x,y) (TYPE)((TYPE)(x)<<(y)) +#else +# define SHIFT(x,y) (TYPE)((TYPE)(x)>>(y)) +#endif + +#if VOL == 0 + volatile TYPE s = TEST_VECT; + TYPE t; + #define TESTSHIFT(x) t=s; t = SHIFT (t,(x)); ASSERT( t == SHIFT (TEST_VECT, (x))); +#else + volatile TYPE t = TEST_VECT; + #define TESTSHIFT(x) t=TEST_VECT; t = SHIFT (t,(x)); ASSERT( t == SHIFT (TEST_VECT, (x))); +#endif + +static void +testShift(void) +{ + TESTSHIFT(0); + TESTSHIFT(1); + TESTSHIFT(2); + TESTSHIFT(3); + TESTSHIFT(4); + TESTSHIFT(5); + TESTSHIFT(6); + TESTSHIFT(7); + +#if SIZE >= 16 + TESTSHIFT(8); + TESTSHIFT(9); + TESTSHIFT(10); + TESTSHIFT(11); + TESTSHIFT(12); + TESTSHIFT(13); + TESTSHIFT(14); + TESTSHIFT(15); +#endif + +#if SIZE >= 32 + TESTSHIFT(16); + TESTSHIFT(17); + TESTSHIFT(18); + TESTSHIFT(19); + TESTSHIFT(20); + TESTSHIFT(21); + TESTSHIFT(22); + TESTSHIFT(23); + + TESTSHIFT(24); + TESTSHIFT(25); + TESTSHIFT(26); + TESTSHIFT(27); + TESTSHIFT(28); + TESTSHIFT(29); + TESTSHIFT(30); + TESTSHIFT(31); +#endif +}