From 21885795bac4791a8e3c8a5dcee76d165c282d09 Mon Sep 17 00:00:00 2001 From: sdattalo Date: Tue, 2 Oct 2001 03:45:23 +0000 Subject: [PATCH] Operators <<, >>, are now fully working for constant shifts on unsigned char and unsigned int. git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1342 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- src/pic/gen.c | 122 +++++++++++++++++++++++++---- src/regression/rotate3.c | 163 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 266 insertions(+), 19 deletions(-) diff --git a/src/pic/gen.c b/src/pic/gen.c index 265e9fc0..f1bf622a 100644 --- a/src/pic/gen.c +++ b/src/pic/gen.c @@ -5291,7 +5291,7 @@ static void shiftR1Left2Result (operand *left, int offl, DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__); - same = (left == result) || (AOP(left) == AOP(result)); + same = ((left == result) || (AOP(left) == AOP(result))) && (offl == offr); /* Copy the msb into the carry if signed. */ if(sign) { @@ -5339,13 +5339,13 @@ static void shiftR1Left2Result (operand *left, int offl, case 4: emitpcode(POC_SWAPFW, popGet(AOP(left),offl,FALSE,FALSE)); - emitpcode(POC_ANDLW, popGetLit(0x1f)); + emitpcode(POC_ANDLW, popGetLit(0x0f)); emitpcode(POC_MOVWF, popGet(AOP(result),offr,FALSE,FALSE)); break; case 5: emitpcode(POC_SWAPFW, popGet(AOP(left),offl,FALSE,FALSE)); - emitpcode(POC_ANDLW, popGetLit(0x1f)); + emitpcode(POC_ANDLW, popGetLit(0x0f)); emitpcode(POC_MOVWF, popGet(AOP(result),offr,FALSE,FALSE)); emitCLRC; emitpcode(POC_RRF, popGet(AOP(result),offr,FALSE,FALSE)); @@ -5353,7 +5353,7 @@ static void shiftR1Left2Result (operand *left, int offl, break; case 6: - emitpcode(POC_RLFW, popGet(AOP(left),offr,FALSE,FALSE)); + emitpcode(POC_RLFW, popGet(AOP(left),offl,FALSE,FALSE)); emitpcode(POC_ANDLW, popGetLit(0x80)); emitpcode(POC_MOVWF, popGet(AOP(result),offr,FALSE,FALSE)); emitpcode(POC_RLF, popGet(AOP(result),offr,FALSE,FALSE)); @@ -5774,6 +5774,7 @@ static void shiftL2Left2Result (operand *left, int offl, break; case 1: case 2: + case 3: /* note, use a mov/add for the shift since the mov has a chance of getting optimized out */ emitpcode(POC_MOVFW, popGet(AOP(left),offl,FALSE,FALSE)); @@ -5788,7 +5789,7 @@ static void shiftL2Left2Result (operand *left, int offl, emitpcode(POC_RLF, popGet(AOP(result),offr+MSB16,FALSE,FALSE)); } break; - case 3: + case 4: case 5: emitpcode(POC_SWAPFW,popGet(AOP(left),offl+MSB16,FALSE,FALSE)); @@ -5800,10 +5801,7 @@ static void shiftL2Left2Result (operand *left, int offl, emitpcode(POC_XORWF, popGet(AOP(result),offr,FALSE,FALSE)); emitpcode(POC_ADDWF, popGet(AOP(result),offr+MSB16,FALSE,FALSE)); - if(shCount == 3) { - emitpcode(POC_RRF, popGet(AOP(result),offr+MSB16,FALSE,FALSE)); - emitpcode(POC_RRF, popGet(AOP(result),offr,FALSE,FALSE)); - } + if(shCount == 5) { emitpcode(POC_RLF, popGet(AOP(result),offr,FALSE,FALSE)); emitpcode(POC_RLF, popGet(AOP(result),offr+MSB16,FALSE,FALSE)); @@ -5844,8 +5842,9 @@ static void shiftR2Left2Result (operand *left, int offl, int same=0; DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__); - if(pic14_sameRegs(AOP(result), AOP(left)) && - ((offl + MSB16) == offr)){ + same = pic14_sameRegs(AOP(result), AOP(left)); + + if(same && ((offl + MSB16) == offr)){ same=1; /* don't crash result[offr] */ MOVA(aopGet(AOP(left),offl,FALSE,FALSE)); @@ -5858,12 +5857,97 @@ static void shiftR2Left2Result (operand *left, int offl, if(sign) AccAXRshS( aopGet(AOP(result),offr,FALSE,FALSE) , shCount); else { - //AccAXRsh( aopGet(AOP(result),offr,FALSE,FALSE) , shCount); + //AccAXRsh( aopGet(AOP(result),offr,FALSE,FALSE) , shCount); - // switch() { - //} - if(pic14_getDataSize(result) > 1) - aopPut(AOP(result),"a",offr+MSB16); + switch(shCount) { + case 0: + break; + case 1: + case 2: + case 3: + emitCLRC; + if(same) { + emitpcode(POC_RRF,popGet(AOP(result),offr+MSB16,FALSE,FALSE)); + emitpcode(POC_RRF,popGet(AOP(result),offr,FALSE,FALSE)); + } else { + + emitpcode(POC_RRFW, popGet(AOP(left),offl+MSB16,FALSE,FALSE)); + emitpcode(POC_MOVWF,popGet(AOP(result),offr+MSB16,FALSE,FALSE)); + emitpcode(POC_RRFW, popGet(AOP(left),offl,FALSE,FALSE)); + emitpcode(POC_MOVWF,popGet(AOP(result),offr,FALSE,FALSE)); + } + + while(--shCount) { + emitCLRC; + emitpcode(POC_RRF,popGet(AOP(result),offr+MSB16,FALSE,FALSE)); + emitpcode(POC_RRF,popGet(AOP(result),offr,FALSE,FALSE)); + } + break; + case 4: + case 5: + if(same) { + + emitpcode(POC_MOVLW, popGetLit(0xf0)); + emitpcode(POC_ANDWF, popGet(AOP(result),offr,FALSE,FALSE)); + emitpcode(POC_SWAPF, popGet(AOP(result),offr,FALSE,FALSE)); + + emitpcode(POC_SWAPF, popGet(AOP(result),offr+MSB16,FALSE,FALSE)); + emitpcode(POC_ANDFW, popGet(AOP(result),offr+MSB16,FALSE,FALSE)); + emitpcode(POC_XORWF, popGet(AOP(result),offr+MSB16,FALSE,FALSE)); + emitpcode(POC_ADDWF, popGet(AOP(result),offr,FALSE,FALSE)); + } else { + emitpcode(POC_SWAPF, popGet(AOP(left),offl,FALSE,FALSE)); + emitpcode(POC_ANDLW, popGetLit(0x0f)); + emitpcode(POC_MOVWF, popGet(AOP(result),offr,FALSE,FALSE)); + + emitpcode(POC_SWAPF, popGet(AOP(left),offl+MSB16,FALSE,FALSE)); + emitpcode(POC_MOVWF, popGet(AOP(result),offr+MSB16,FALSE,FALSE)); + emitpcode(POC_ANDLW, popGetLit(0xf0)); + emitpcode(POC_XORWF, popGet(AOP(result),offr+MSB16,FALSE,FALSE)); + emitpcode(POC_ADDWF, popGet(AOP(result),offr,FALSE,FALSE)); + } + + if(shCount >=5) { + emitpcode(POC_RRF, popGet(AOP(result),offr+MSB16,FALSE,FALSE)); + emitpcode(POC_RRF, popGet(AOP(result),offr,FALSE,FALSE)); + } + + break; + + case 6: + if(same) { + + emitpcode(POC_RLF, popGet(AOP(result),offr,FALSE,FALSE)); + emitpcode(POC_RLF, popGet(AOP(result),offr+MSB16,FALSE,FALSE)); + + emitpcode(POC_RLF, popGet(AOP(result),offr,FALSE,FALSE)); + emitpcode(POC_RLF, popGet(AOP(result),offr+MSB16,FALSE,FALSE)); + emitpcode(POC_RLFW, popGet(AOP(result),offr,FALSE,FALSE)); + emitpcode(POC_ANDLW,popGetLit(0x03)); + emitpcode(POC_XORFW,popGet(AOP(result),offr+MSB16,FALSE,FALSE)); + emitpcode(POC_XORWF,popGet(AOP(result),offr+MSB16,FALSE,FALSE)); + emitpcode(POC_XORFW,popGet(AOP(result),offr+MSB16,FALSE,FALSE)); + emitpcode(POC_MOVWF,popGet(AOP(result),offr,FALSE,FALSE)); + } else { + emitpcode(POC_RLFW, popGet(AOP(left),offl,FALSE,FALSE)); + emitpcode(POC_MOVWF,popGet(AOP(result),offr+MSB16,FALSE,FALSE)); + emitpcode(POC_RLFW, popGet(AOP(result),offl+MSB16,FALSE,FALSE)); + emitpcode(POC_MOVWF,popGet(AOP(result),offr,FALSE,FALSE)); + emitpcode(POC_RLF, popGet(AOP(result),offr+MSB16,FALSE,FALSE)); + emitpcode(POC_RLF, popGet(AOP(result),offr,FALSE,FALSE)); + emitpcode(POC_RLFW, popGet(AOP(result),offr,FALSE,FALSE)); + emitpcode(POC_ANDLW,popGetLit(0x03)); + emitpcode(POC_MOVWF,popGet(AOP(result),offr,FALSE,FALSE)); + } + + break; + case 7: + emitpcode(POC_RLFW, popGet(AOP(left),offl,FALSE,FALSE)); + emitpcode(POC_RLFW, popGet(AOP(left),offl+MSB16,FALSE,FALSE)); + emitpcode(POC_MOVWF,popGet(AOP(result),offr,FALSE,FALSE)); + emitpcode(POC_CLRF, popGet(AOP(result),offr+MSB16,FALSE,FALSE)); + emitpcode(POC_RLF, popGet(AOP(result),offr+MSB16,FALSE,FALSE)); + } } } @@ -6283,7 +6367,11 @@ static void genrshTwo (operand *result,operand *left, shCount, sign); else movLeft2Result(left, MSB16, result, LSB, sign); - addSign(result, MSB16, sign); + if(sign) + addSign(result, MSB16, sign); + else + emitpcode(POC_CLRF,popGet(AOP(result),MSB16,FALSE,FALSE)); + } /* 1 <= shCount <= 7 */ diff --git a/src/regression/rotate3.c b/src/regression/rotate3.c index f0f5330f..ee594481 100644 --- a/src/regression/rotate3.c +++ b/src/regression/rotate3.c @@ -127,15 +127,83 @@ void shift_int_left_15(void) /*****************************************************/ void shift_int_right_1(void) { - aint0 >>= 1; +} + +void shift_int_right_2(void) +{ + aint0 >>= 2; +} + +void shift_int_right_3(void) +{ + aint0 >>= 3; +} + +void shift_int_right_4(void) +{ + aint0 >>= 4; +} + +void shift_int_right_5(void) +{ + aint0 >>= 5; +} +void shift_int_right_6(void) +{ + aint0 >>= 6; +} + +void shift_int_right_7(void) +{ + aint0 >>= 7; +} + +void shift_int_right_8(void) +{ + aint0 >>= 8; +} + +void shift_int_right_9(void) +{ + aint0 >>= 9; +} + +void shift_int_right_10(void) +{ + aint0 >>= 10; +} + +void shift_int_right_11(void) +{ + aint0 >>= 11; +} + +void shift_int_right_12(void) +{ + aint0 >>= 12; +} + +void shift_int_right_13(void) +{ + aint0 >>= 13; +} + +void shift_int_right_14(void) +{ + aint0 >>= 14; +} + +void shift_int_right_15(void) +{ + aint0 >>= 15; } /*****************************************************/ void main(void) { - char i; + //char i; aint0 = 0xabcd; @@ -227,6 +295,97 @@ void main(void) if(aint0 != 0x8000) failures++; + /***********************/ + aint0 = 0xabcd; + + shift_int_right_1(); + if(aint0 != 0x55e6) + failures++; + + aint0 = 0xabcd; + + shift_int_right_2(); + if(aint0 != 0x2af3) + failures++; + + aint0 = 0xabcd; + + shift_int_right_3(); + if(aint0 != 0x1579) + failures++; + + aint0 = 0xabcd; + + shift_int_right_4(); + if(aint0 != 0x0abc) + failures++; + + aint0 = 0xabcd; + + shift_int_right_5(); + if(aint0 != 0x055e) + failures++; + + aint0 = 0xabcd; + + shift_int_right_6(); + if(aint0 != 0x02af) + failures++; + + aint0 = 0xabcd; + + shift_int_right_7(); + if(aint0 != 0x0157) + failures++; + + aint0 = 0xabcd; + + shift_int_right_8(); + if(aint0 != 0x00ab) + failures++; + + aint0 = 0xabcd; + + shift_int_right_9(); + if(aint0 != 0x0055) + failures++; + + aint0 = 0xabcd; + + shift_int_right_10(); + if(aint0 != 0x002a) + failures++; + + aint0 = 0xabcd; + + shift_int_right_11(); + if(aint0 != 0x0015) + failures++; + + aint0 = 0xabcd; + + shift_int_right_12(); + if(aint0 != 0x000a) + failures++; + + aint0 = 0xabcd; + + shift_int_right_13(); + if(aint0 != 0x0005) + failures++; + + aint0 = 0xabcd; + + shift_int_right_14(); + if(aint0 != 0x0002) + failures++; + + aint0 = 0xabcd; + + shift_int_right_15(); + if(aint0 != 0x0001) + failures++; + success=failures; done(); } -- 2.30.2