- operand *left,*right, *result;
- int size, offset;
- char *l;
- symbol *tlbl , *tlbl1;
- pCodeOp *pctemp;
-
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
-
- right = IC_RIGHT(ic);
- left = IC_LEFT(ic);
- result = IC_RESULT(ic);
-
- aopOp(right,ic,FALSE);
-
- /* if the shift count is known then do it
- as efficiently as possible */
- if (AOP_TYPE(right) == AOP_LIT) {
- genLeftShiftLiteral (left,right,result,ic);
- 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 ) */
-
-
- 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 {
- emitpcode(POC_MOVFW, popGet(AOP(left),offset));
- emitpcode(POC_MOVWF, popGet(AOP(result),offset));
- //aopPut(AOP(result),l,offset);
- }
- offset++;
- }
- }
-
- size = AOP_SIZE(result);
-
- /* if it is only one byte then */
- if (size == 1) {
- if(optimized_for_speed) {
- 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))) {
- emitpcode(POC_MOVFW, popGet(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);
-}
-
-/*-----------------------------------------------------------------*/
-/* genrshOne - right shift a one byte quantity by known count */
-/*-----------------------------------------------------------------*/
-static void genrshOne (operand *result, operand *left,
- int shCount, int sign)
-{
- 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)
-{
- 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)
-{
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if(!sign)
- pic14_emitcode("clr","c");
- MOVA(aopGet(AOP(left),MSB32,FALSE,FALSE));
- if(sign)
- pic14_emitcode("mov","c,acc.7");
- pic14_emitcode("rrc","a");
- aopPut(AOP(result),"a",MSB32-offl);
- if(offl == MSB16)
- /* add sign of "a" */
- addSign(result, MSB32, sign);
-
- MOVA(aopGet(AOP(left),MSB24,FALSE,FALSE));
- pic14_emitcode("rrc","a");
- aopPut(AOP(result),"a",MSB24-offl);
-
- MOVA(aopGet(AOP(left),MSB16,FALSE,FALSE));
- pic14_emitcode("rrc","a");
- aopPut(AOP(result),"a",MSB16-offl);
-
- if(offl == LSB){
- MOVA(aopGet(AOP(left),LSB,FALSE,FALSE));
- pic14_emitcode("rrc","a");
- aopPut(AOP(result),"a",LSB);
- }
-}
-
-/*-----------------------------------------------------------------*/
-/* genrshFour - shift four byte by a known amount != 0 */
-/*-----------------------------------------------------------------*/
-static void genrshFour (operand *result, operand *left,
- int shCount, int sign)
-{
- 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) floatFromVal (AOP(right)->aopu.aop_lit);
- int lsize,res_size;
-
- 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, lsize, 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);
-}
-
-/*-----------------------------------------------------------------*/
-/* 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 */
- 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) {
- 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);