-
- right = IC_RIGHT(ic);
- left = IC_LEFT(ic);
- result = IC_RESULT(ic);
-
- aopOp(right,ic,FALSE);
- aopOp(left,ic,FALSE);
- aopOp(result,ic,FALSE);
-
-
- /* if the shift count is known then do it
- as efficiently as possible */
- if (AOP_TYPE(right) == AOP_LIT) {
- shiftLeft_Left2ResultLit (left, result, (int) ulFromVal (AOP(right)->aopu.aop_lit));
- return ;
- }
-
- /* shift count is unknown then we have to form
- a loop get the loop count in B : Note: we take
- only the lower order byte since shifting
- more that 32 bits make no sense anyway, ( the
- largest size of an object can be only 32 bits ) */
-
- /* this code fails for RIGHT == RESULT */
- assert (!pic14_sameRegs (AOP(right), AOP(result)));
-
- /* now move the left to the result if they are not the
- same */
- if (!pic14_sameRegs(AOP(left),AOP(result)) &&
- AOP_SIZE(result) > 1) {
-
- size = AOP_SIZE(result);
- offset=0;
- while (size--) {
- l = aopGet(AOP(left),offset,FALSE,TRUE);
- if (*l == '@' && (IS_AOP_PREG(result))) {
-
- pic14_emitcode("mov","a,%s",l);
- aopPut(AOP(result),"a",offset);
- } else {
- emitpcode(POC_MOVFW, popGet(AOP(left),offset));
- emitpcode(POC_MOVWF, popGet(AOP(result),offset));
- //aopPut(AOP(result),l,offset);
- }
- offset++;
- }
- }
-
- if(AOP_TYPE(left) == AOP_LIT)
- lit = ulFromVal (AOP(left)->aopu.aop_lit);
-
- size = AOP_SIZE(result);
-
- /* if it is only one byte then */
- if (size == 1) {
- if(optimized_for_speed && AOP_TYPE(left)!=AOP_LIT) {
- emitpcode(POC_SWAPFW, popGet(AOP(left),0));
- emitpcode(POC_ANDLW, popGetLit(0xf0));
- emitpcode(POC_BTFSS, newpCodeOpBit(aopGet(AOP(right),0,FALSE,FALSE),2,0));
- emitpcode(POC_MOVFW, popGet(AOP(left),0));
- emitpcode(POC_MOVWF, popGet(AOP(result),0));
- emitpcode(POC_BTFSS, newpCodeOpBit(aopGet(AOP(right),0,FALSE,FALSE),0,0));
- emitpcode(POC_ADDWF, popGet(AOP(result),0));
- emitpcode(POC_RLFW, popGet(AOP(result),0));
- emitpcode(POC_ANDLW, popGetLit(0xfe));
- emitpcode(POC_ADDFW, popGet(AOP(result),0));
- emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(right),0,FALSE,FALSE),1,0));
- emitpcode(POC_ADDWF, popGet(AOP(result),0));
- } else {
-
- tlbl = newiTempLabel(NULL);
- if (!pic14_sameRegs(AOP(left),AOP(result))) {
- mov2w (AOP(left), 0);
- emitpcode(POC_MOVWF, popGet(AOP(result),0));
- }
-
- emitpcode(POC_COMFW, popGet(AOP(right),0));
- emitpcode(POC_RRF, popGet(AOP(result),0));
- emitpLabel(tlbl->key);
- emitpcode(POC_RLF, popGet(AOP(result),0));
- emitpcode(POC_ADDLW, popGetLit(1));
- emitSKPC;
- emitpcode(POC_GOTO,popGetLabel(tlbl->key));
- }
- goto release ;
- }
-
- if (pic14_sameRegs(AOP(left),AOP(result))) {
-
- tlbl = newiTempLabel(NULL);
- emitpcode(POC_COMFW, popGet(AOP(right),0));
- genMultiAsm(POC_RRF, result, size,1);
- emitpLabel(tlbl->key);
- genMultiAsm(POC_RLF, result, size,0);
- emitpcode(POC_ADDLW, popGetLit(1));
- emitSKPC;
- emitpcode(POC_GOTO,popGetLabel(tlbl->key));
- goto release;
- }
-
- //tlbl = newiTempLabel(NULL);
- //offset = 0 ;
- //tlbl1 = newiTempLabel(NULL);
-
- //reAdjustPreg(AOP(result));
-
- //pic14_emitcode("sjmp","%05d_DS_",tlbl1->key+100);
- //pic14_emitcode("","%05d_DS_:",tlbl->key+100);
- //l = aopGet(AOP(result),offset,FALSE,FALSE);
- //MOVA(l);
- //pic14_emitcode("add","a,acc");
- //aopPut(AOP(result),"a",offset++);
- //while (--size) {
- // l = aopGet(AOP(result),offset,FALSE,FALSE);
- // MOVA(l);
- // pic14_emitcode("rlc","a");
- // aopPut(AOP(result),"a",offset++);
- //}
- //reAdjustPreg(AOP(result));
-
- //pic14_emitcode("","%05d_DS_:",tlbl1->key+100);
- //pic14_emitcode("djnz","b,%05d_DS_",tlbl->key+100);
-
-
- tlbl = newiTempLabel(NULL);
- tlbl1= newiTempLabel(NULL);
-
- size = AOP_SIZE(result);
- offset = 1;
-
- pctemp = popGetTempReg(); /* grab a temporary working register. */
-
- emitpcode(POC_MOVFW, popGet(AOP(right),0));
-
- /* offset should be 0, 1 or 3 */
- emitpcode(POC_ANDLW, popGetLit(0x07 + ((offset&3) << 3)));
- emitSKPNZ;
- emitpcode(POC_GOTO, popGetLabel(tlbl1->key));
-
- emitpcode(POC_MOVWF, pctemp);
-
-
- emitpLabel(tlbl->key);
-
- emitCLRC;
- emitpcode(POC_RLF, popGet(AOP(result),0));
- while(--size)
- emitpcode(POC_RLF, popGet(AOP(result),offset++));
-
- emitpcode(POC_DECFSZ, pctemp);
- emitpcode(POC_GOTO,popGetLabel(tlbl->key));
- emitpLabel(tlbl1->key);
-
- popReleaseTempReg(pctemp);
-
-
-release:
- freeAsmop (right,NULL,ic,TRUE);
- freeAsmop(left,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
-}
-#endif
-
-#if 0
-/*-----------------------------------------------------------------*/
-/* genrshOne - right shift a one byte quantity by known count */
-/*-----------------------------------------------------------------*/
-static void genrshOne (operand *result, operand *left,
- int shCount, int sign)
-{
- FENTRY;
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- shiftR1Left2Result(left, LSB, result, LSB, shCount, sign);
-}
-
-/*-----------------------------------------------------------------*/
-/* genrshTwo - right shift two bytes by known amount != 0 */
-/*-----------------------------------------------------------------*/
-static void genrshTwo (operand *result,operand *left,
- int shCount, int sign)
-{
- FENTRY;
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- /* if shCount >= 8 */
- if (shCount >= 8) {
- shCount -= 8 ;
- if (shCount)
- shiftR1Left2Result(left, MSB16, result, LSB,
- shCount, sign);
- else
- movLeft2Result(left, MSB16, result, LSB);
-
- emitpcode(POC_CLRF,popGet(AOP(result),MSB16));
-
- if(sign) {
- emitpcode(POC_BTFSC,newpCodeOpBit(aopGet(AOP(left),LSB,FALSE,FALSE),7,0));
- emitpcode(POC_DECF, popGet(AOP(result),MSB16));
- }
- }
-
- /* 1 <= shCount <= 7 */
- else
- shiftR2Left2Result(left, LSB, result, LSB, shCount, sign);
-}
-
-/*-----------------------------------------------------------------*/
-/* shiftRLong - shift right one long from left to result */
-/* offl = LSB or MSB16 */
-/*-----------------------------------------------------------------*/
-static void shiftRLong (operand *left, int offl,
- operand *result, int sign)
-{
- int size, same;
-
- FENTRY;
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
-
- size = AOP_SIZE(left);
- if (AOP_SIZE(result) < size) size = AOP_SIZE(result);
-
- if (sign)
- emitpcode (POC_RLFW, popGet (AOP(left), AOP_SIZE(left)-1));
- else
- emitCLRC;
-
- assert (offl >= 0 && offl < size);
-
- same = pic14_sameRegs (AOP(left), AOP(result));
-
- /* perform the shift */
- while (size--)
- {
- if (same && !offl) {
- emitpcode (POC_RRF, popGet (AOP(result), size));
- } else {
- emitpcode (POC_RRFW, popGet (AOP(left), size));
- emitpcode (POC_MOVWF, popGet (AOP(result), size-offl));
- }
- } // while
-
- addSign (result, AOP_SIZE(left) - offl, sign);
-}
-
-/*-----------------------------------------------------------------*/
-/* genrshFour - shift four byte by a known amount != 0 */
-/*-----------------------------------------------------------------*/
-static void genrshFour (operand *result, operand *left,
- int shCount, int sign)
-{
- FENTRY;
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- /* if shifting more that 3 bytes */
- if(shCount >= 24 ) {
- shCount -= 24;
- if(shCount)
- shiftR1Left2Result(left, MSB32, result, LSB, shCount, sign);
- else
- movLeft2Result(left, MSB32, result, LSB);
-
- addSign(result, MSB16, sign);
- }
- else if(shCount >= 16){
- shCount -= 16;
- if(shCount)
- shiftR2Left2Result(left, MSB24, result, LSB, shCount, sign);
- else{
- movLeft2Result(left, MSB24, result, LSB);
- movLeft2Result(left, MSB32, result, MSB16);
- }
- addSign(result, MSB24, sign);
- }
- else if(shCount >= 8){
- shCount -= 8;
- if(shCount == 1)
- shiftRLong(left, MSB16, result, sign);
- else if(shCount == 0){
- movLeft2Result(left, MSB16, result, LSB);
- movLeft2Result(left, MSB24, result, MSB16);
- movLeft2Result(left, MSB32, result, MSB24);
- addSign(result, MSB32, sign);
- }
- else{
- shiftR2Left2Result(left, MSB16, result, LSB, shCount, 0);
- shiftLLeftOrResult(left, MSB32, result, MSB16, 8 - shCount);
- /* the last shift is signed */
- shiftR1Left2Result(left, MSB32, result, MSB24, shCount, sign);
- addSign(result, MSB32, sign);
- }
- }
- else{ /* 1 <= shCount <= 7 */
- if(shCount <= 2){
- shiftRLong(left, LSB, result, sign);
- if(shCount == 2)
- shiftRLong(result, LSB, result, sign);
- }
- else{
- shiftR2Left2Result(left, LSB, result, LSB, shCount, 0);
- shiftLLeftOrResult(left, MSB24, result, MSB16, 8 - shCount);
- shiftR2Left2Result(left, MSB24, result, MSB24, shCount, sign);
- }
- }
-}
-
-/*-----------------------------------------------------------------*/
-/* genRightShiftLiteral - right shifting by known count */
-/*-----------------------------------------------------------------*/
-static void genRightShiftLiteral (operand *left,
- operand *right,
- operand *result,
- iCode *ic,
- int sign)
-{
- int shCount = (int) ulFromVal (AOP(right)->aopu.aop_lit);
- int lsize,res_size;
-
- FENTRY;
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- freeAsmop(right,NULL,ic,TRUE);
-
- aopOp(left,ic,FALSE);
- aopOp(result,ic,FALSE);
-
-#if VIEW_SIZE
- pic14_emitcode("; shift right ","result %d, left %d",AOP_SIZE(result),
- AOP_SIZE(left));
-#endif
-
- lsize = pic14_getDataSize(left);
- res_size = pic14_getDataSize(result);
- /* test the LEFT size !!! */
-
- /* I suppose that the left size >= result size */
- if(shCount == 0){
- while(res_size--)
- movLeft2Result(left, res_size, result, res_size);
- }
-
- else if(shCount >= (lsize * 8)){
-
- if(res_size == 1) {
- emitpcode(POC_CLRF, popGet(AOP(result),LSB));
- if(sign) {
- emitpcode(POC_BTFSC,newpCodeOpBit(aopGet(AOP(left),lsize-1,FALSE,FALSE),7,0));
- emitpcode(POC_DECF, popGet(AOP(result),LSB));
- }
- } else {
-
- if(sign) {
- emitpcode(POC_MOVLW, popGetLit(0));
- emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(left),lsize-1,FALSE,FALSE),7,0));
- emitpcode(POC_MOVLW, popGetLit(0xff));
- while(res_size--)
- emitpcode(POC_MOVWF, popGet(AOP(result),res_size));
-
- } else {
-
- while(res_size--)
- emitpcode(POC_CLRF, popGet(AOP(result),res_size));
- }
- }
- } else {
-
- switch (res_size) {
- case 1:
- genrshOne (result,left,shCount,sign);
- break;
-
- case 2:
- genrshTwo (result,left,shCount,sign);
- break;
-
- case 4:
- genrshFour (result,left,shCount,sign);
- break;
- default :
- break;
- }
-
- }
-
- freeAsmop(left,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
-}
-#endif
-
-#if 0
-/*-----------------------------------------------------------------*/
-/* genSignedRightShift - right shift of signed number */
-/*-----------------------------------------------------------------*/
-static void genSignedRightShift (iCode *ic)
-{
- operand *right, *left, *result;
- int size, offset;
- // char *l;
- symbol *tlbl, *tlbl1 ;
- pCodeOp *pctemp;
-
- //same = ((left == result) || (AOP(left) == AOP(result))) && (offl == offr);
-
- /* we do it the hard way put the shift count in b
- and loop thru preserving the sign */
- FENTRY;
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
-
- right = IC_RIGHT(ic);
- left = IC_LEFT(ic);
- result = IC_RESULT(ic);
-
- aopOp(right,ic,FALSE);
- aopOp(left,ic,FALSE);
- aopOp(result,ic,FALSE);
-
-
- if ( AOP_TYPE(right) == AOP_LIT) {
- shiftRight_Left2ResultLit (left, result, (int) ulFromVal (AOP(right)->aopu.aop_lit), 1);
- //genRightShiftLiteral (left,right,result,ic,1);
- return ;
- }
- /* shift count is unknown then we have to form
- a loop get the loop count in B : Note: we take
- only the lower order byte since shifting
- more that 32 bits make no sense anyway, ( the
- largest size of an object can be only 32 bits ) */
-
- //pic14_emitcode("mov","b,%s",aopGet(AOP(right),0,FALSE,FALSE));
- //pic14_emitcode("inc","b");
- //freeAsmop (right,NULL,ic,TRUE);
- //aopOp(left,ic,FALSE);
- //aopOp(result,ic,FALSE);
-
- /* now move the left to the result if they are not the
- same */
- if (!pic14_sameRegs(AOP(left),AOP(result)) &&
- AOP_SIZE(result) > 1) {
-
- size = AOP_SIZE(result);
- offset=0;
- while (size--) {
- /*
- l = aopGet(AOP(left),offset,FALSE,TRUE);
- if (*l == '@' && IS_AOP_PREG(result)) {
- pic14_emitcode("mov","a,%s",l);
- aopPut(AOP(result),"a",offset);
- } else
- aopPut(AOP(result),l,offset);
- */
- emitpcode(POC_MOVFW, popGet(AOP(left),offset));
- emitpcode(POC_MOVWF, popGet(AOP(result),offset));
-
- offset++;
- }
- }
-
- /* mov the highest order bit to OVR */
- tlbl = newiTempLabel(NULL);
- tlbl1= newiTempLabel(NULL);
-
- size = AOP_SIZE(result);
- offset = size - 1;
-
- pctemp = popGetTempReg(); /* grab a temporary working register. */
-
- emitpcode(POC_MOVFW, popGet(AOP(right),0));
-
- /* offset should be 0, 1 or 3 */
- emitpcode(POC_ANDLW, popGetLit(0x07 + ((offset&3) << 3)));
- emitSKPNZ;
- emitpcode(POC_GOTO, popGetLabel(tlbl1->key));
-
- emitpcode(POC_MOVWF, pctemp);
-
-
- emitpLabel(tlbl->key);
-
- emitpcode(POC_RLFW, popGet(AOP(result),offset));
- emitpcode(POC_RRF, popGet(AOP(result),offset));
-
- while(--size) {
- emitpcode(POC_RRF, popGet(AOP(result),--offset));
- }
-
- emitpcode(POC_DECFSZ, pctemp);
- emitpcode(POC_GOTO,popGetLabel(tlbl->key));
- emitpLabel(tlbl1->key);
-
- popReleaseTempReg(pctemp);
-#if 0
- size = AOP_SIZE(result);
- offset = size - 1;
- pic14_emitcode("mov","a,%s",aopGet(AOP(left),offset,FALSE,FALSE));
- pic14_emitcode("rlc","a");
- pic14_emitcode("mov","ov,c");
- /* if it is only one byte then */
- if (size == 1) {
- l = aopGet(AOP(left),0,FALSE,FALSE);
- MOVA(l);
- pic14_emitcode("sjmp","%05d_DS_",tlbl1->key+100);
- pic14_emitcode("","%05d_DS_:",tlbl->key+100);
- pic14_emitcode("mov","c,ov");
- pic14_emitcode("rrc","a");
- pic14_emitcode("","%05d_DS_:",tlbl1->key+100);
- pic14_emitcode("djnz","b,%05d_DS_",tlbl->key+100);
- aopPut(AOP(result),"a",0);
- goto release ;
- }
-
- reAdjustPreg(AOP(result));
- pic14_emitcode("sjmp","%05d_DS_",tlbl1->key+100);
- pic14_emitcode("","%05d_DS_:",tlbl->key+100);
- pic14_emitcode("mov","c,ov");
- while (size--) {
- l = aopGet(AOP(result),offset,FALSE,FALSE);
- MOVA(l);
- pic14_emitcode("rrc","a");
- aopPut(AOP(result),"a",offset--);
- }
- reAdjustPreg(AOP(result));
- pic14_emitcode("","%05d_DS_:",tlbl1->key+100);
- pic14_emitcode("djnz","b,%05d_DS_",tlbl->key+100);
-
-release:
-#endif
-
- freeAsmop(left,NULL,ic,TRUE);
- freeAsmop(result,NULL,ic,TRUE);
- freeAsmop(right,NULL,ic,TRUE);
-}
-#endif
-
-/*-----------------------------------------------------------------*/
-/* loadSignToC - load the operand's sign bit into CARRY */
-/*-----------------------------------------------------------------*/
-
-static void loadSignToC (operand *op)
-{
- FENTRY;
- assert (op && AOP(op) && AOP_SIZE(op));
-
- emitCLRC;
- emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(op),AOP_SIZE(op)-1,FALSE,FALSE),7,0));
- emitSETC;
-}
-
-/*-----------------------------------------------------------------*/
-/* genRightShift - generate code for right shifting */
-/*-----------------------------------------------------------------*/
-static void genGenericShift (iCode *ic, int shiftRight)
-{
- operand *right, *left, *result;
- sym_link *retype ;
- int size;
- symbol *tlbl, *tlbl1, *inverselbl;
-
- FENTRY;
- /* if signed then we do it the hard way preserve the
- sign bit moving it inwards */
- retype = getSpec(operandType(IC_RESULT(ic)));
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
-
- /* signed & unsigned types are treated the same : i.e. the
- signed is NOT propagated inwards : quoting from the
- ANSI - standard : "for E1 >> E2, is equivalent to division
- by 2**E2 if unsigned or if it has a non-negative value,
- otherwise the result is implementation defined ", MY definition
- is that the sign does not get propagated */