- } else if ((AOP_TYPE(left) == AOP_LIT)) {
- lit = (unsigned long)floatFromVal(AOP(left)->aopu.aop_lit);
- }
-
-
- //if(IC_TRUE(ifx) == NULL)
- /* if left & right are bit variables */
- if (AOP_TYPE(left) == AOP_CRY &&
- AOP_TYPE(right) == AOP_CRY ) {
- assert (0 && "bit variables used in genCmp");
- pic16_emitcode("mov","c,%s",AOP(right)->aopu.aop_dir);
- pic16_emitcode("anl","c,/%s",AOP(left)->aopu.aop_dir);
- } else {
- /* subtract right from left if at the
- end the carry flag is set then we know that
- left is greater than right */
-
- symbol *lbl = newiTempLabel(NULL);
-
-#if 0
- fprintf(stderr, "%s:%s:%d truelbl: %d\tlbl: %d\n",
- __FILE__, __FUNCTION__, __LINE__, truelbl->key+100+pic16_labelOffset, lbl->key+100+pic16_labelOffset);
-#endif
-
-#ifndef _swapp
- if(AOP_TYPE(right) == AOP_LIT) {
-
- //lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);
-
- DEBUGpic16_emitcode(";right lit","%d lit = 0x%x,sign=%d",__LINE__, lit,sign);
-
- /* special cases */
-
- if(lit == 0) {
-
- if(sign != 0)
- genSkipCond(&rFalseIfx,left,size-1,7);
- else
- /* no need to compare to 0...*/
- /* NOTE: this is a de-generate compare that most certainly
- * creates some dead code. */
- pic16_emitpcode(POC_GOTO,pic16_popGetLabel(rFalseIfx.lbl->key));
-
- if(ifx) ifx->generated = 1;
- return;
-
- }
- size--;
-
- if(size == 0) {
- //i = (lit >> (size*8)) & 0xff;
- DEBUGpic16_emitcode(";right lit","line = %d",__LINE__);
-
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left),size));
-
- i = ((0-lit) & 0xff);
- if(sign) {
- if( i == 0x81) {
- /* lit is 0x7f, all signed chars are less than
- * this except for 0x7f itself */
- pic16_emitpcode(POC_XORLW, pic16_popGetLit(0x7f));
- genSkipz2(&rFalseIfx,0);
- } else {
- pic16_emitpcode(POC_ADDLW, pic16_popGetLit(0x80));
- pic16_emitpcode(POC_ADDLW, pic16_popGetLit(i^0x80));
- genSkipc(&rFalseIfx);
- }
-
- } else {
- if(lit == 1) {
- genSkipz2(&rFalseIfx,1);
- } else {
- pic16_emitpcode(POC_ADDLW, pic16_popGetLit(i));
- genSkipc(&rFalseIfx);
- }
- }
-
- if(ifx) ifx->generated = 1;
- return;
- }
-
- /* chars are out of the way. now do ints and longs */
-
-
- DEBUGpic16_emitcode(";right lit","line = %d",__LINE__);
-
- /* special cases */
-
- if(sign) {
-
- if(lit == 0) {
- genSkipCond(&rFalseIfx,left,size,7);
- if(ifx) ifx->generated = 1;
- return;
- }
-
- if(lit <0x100) {
- DEBUGpic16_emitcode(";right lit","line = %d signed compare to 0x%x",__LINE__,lit);
-
- //rFalseIfx.condition ^= 1;
- //genSkipCond(&rFalseIfx,left,size,7);
- //rFalseIfx.condition ^= 1;
-
- pic16_emitpcode(POC_BTFSC, pic16_newpCodeOpBit(pic16_aopGet(AOP(left),size,FALSE,FALSE),7,0, PO_GPR_REGISTER));
- if(rFalseIfx.condition)
- pic16_emitpcode(POC_GOTO, pic16_popGetLabel(rFalseIfx.lbl->key));
- else
- pic16_emitpcode(POC_GOTO, pic16_popGetLabel(truelbl->key));
-
- pic16_emitpcode(POC_MOVLW, pic16_popGetLit(0x100-lit));
- pic16_emitpcode(POC_ADDFW, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left),1));
-
- while(size > 1)
- pic16_emitpcode(POC_IORFW, pic16_popGet(AOP(left),size--));
-
- if(rFalseIfx.condition) {
- emitSKPZ;
- pic16_emitpcode(POC_GOTO, pic16_popGetLabel(truelbl->key));
-
- } else {
- emitSKPNZ;
- }
-
- genSkipc(&rFalseIfx);
- pic16_emitpLabel(truelbl->key);
- if(ifx) ifx->generated = 1;
- return;
-
- }
-
- if(size == 1) {
-
- if( (lit & 0xff) == 0) {
- /* lower byte is zero */
- DEBUGpic16_emitcode(";right lit","line = %d signed compare to 0x%x",__LINE__,lit);
- i = ((lit >> 8) & 0xff) ^0x80;
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left),size));
- pic16_emitpcode(POC_ADDLW, pic16_popGetLit( 0x80));
- pic16_emitpcode(POC_ADDLW, pic16_popGetLit(0x100-i));
- genSkipc(&rFalseIfx);
-
-
- if(ifx) ifx->generated = 1;
- return;
-
- }
- } else {
- /* Special cases for signed longs */
- if( (lit & 0xffffff) == 0) {
- /* lower byte is zero */
- DEBUGpic16_emitcode(";right lit","line = %d signed compare to 0x%x",__LINE__,lit);
- i = ((lit >> 8*3) & 0xff) ^0x80;
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left),size));
- pic16_emitpcode(POC_ADDLW, pic16_popGetLit( 0x80));
- pic16_emitpcode(POC_ADDLW, pic16_popGetLit(0x100-i));
- genSkipc(&rFalseIfx);
-
-
- if(ifx) ifx->generated = 1;
- return;
-
- }
-
- }
-
-
- if(lit & (0x80 << (size*8))) {
- /* lit is negative */
- DEBUGpic16_emitcode(";right lit","line = %d signed compare to 0x%x",__LINE__,lit);
-
- //genSkipCond(&rFalseIfx,left,size,7);
-
- pic16_emitpcode(POC_BTFSS, pic16_newpCodeOpBit(pic16_aopGet(AOP(left),size,FALSE,FALSE),7,0, PO_GPR_REGISTER));
-
- if(rFalseIfx.condition)
- pic16_emitpcode(POC_GOTO, pic16_popGetLabel(truelbl->key));
- else
- pic16_emitpcode(POC_GOTO, pic16_popGetLabel(rFalseIfx.lbl->key));
-
-
- } else {
- /* lit is positive */
- DEBUGpic16_emitcode(";right lit","line = %d signed compare to 0x%x",__LINE__,lit);
- pic16_emitpcode(POC_BTFSC, pic16_newpCodeOpBit(pic16_aopGet(AOP(left),size,FALSE,FALSE),7,0, PO_GPR_REGISTER));
- if(rFalseIfx.condition)
- pic16_emitpcode(POC_GOTO, pic16_popGetLabel(rFalseIfx.lbl->key));
- else
- pic16_emitpcode(POC_GOTO, pic16_popGetLabel(truelbl->key));
-
- }
-
- /*
- This works, but is only good for ints.
- It also requires a "known zero" register.
- pic16_emitpcode(POC_MOVLW, pic16_popGetLit(mlit & 0xff));
- pic16_emitpcode(POC_ADDFW, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_RLCFW, pic16_popCopyReg(&pic16_pc_kzero));
- pic16_emitpcode(POC_ADDLW, pic16_popGetLit( ((mlit>>8) & 0xff)));
- pic16_emitpcode(POC_ADDFW, pic16_popGet(AOP(left),1));
- genSkipc(&rFalseIfx);
-
- pic16_emitpLabel(truelbl->key);
- if(ifx) ifx->generated = 1;
- return;
- **/
-
- /* There are no more special cases, so perform a general compare */
-
- pic16_emitpcode(POC_MOVLW, pic16_popGetLit((lit >> (size*8)) & 0xff));
- pic16_emitpcode(POC_SUBFW, pic16_popGet(AOP(left),size));
-
- while(size--) {
-
- pic16_emitpcode(POC_MOVLW, pic16_popGetLit((lit >> (size*8)) & 0xff));
- emitSKPNZ;
- pic16_emitpcode(POC_SUBFW, pic16_popGet(AOP(left),size));
- }
- //rFalseIfx.condition ^= 1;
- genSkipc(&rFalseIfx);
-
- pic16_emitpLabel(truelbl->key);
-
- if(ifx) ifx->generated = 1;
- return;
-
-
- }
-
-
- /* sign is out of the way. So now do an unsigned compare */
- DEBUGpic16_emitcode(";right lit","line = %d unsigned compare to 0x%x",__LINE__,lit);
-
-
- /* General case - compare to an unsigned literal on the right.*/
-
- i = (lit >> (size*8)) & 0xff;
- pic16_emitpcode(POC_MOVLW, pic16_popGetLit(i));
- pic16_emitpcode(POC_SUBFW, pic16_popGet(AOP(left),size));
- while(size--) {
- i = (lit >> (size*8)) & 0xff;
-
- if(i) {
- pic16_emitpcode(POC_MOVLW, pic16_popGetLit(i));
- emitSKPNZ;
- pic16_emitpcode(POC_SUBFW, pic16_popGet(AOP(left),size));
- } else {
- /* this byte of the lit is zero,
- *if it's not the last then OR in the variable */
- if(size)
- pic16_emitpcode(POC_IORFW, pic16_popGet(AOP(left),size));
- }
- }
-
-
- pic16_emitpLabel(lbl->key);
-// pic16_emitpLabel(truelbl->key);
- //if(emitFinalCheck)
- genSkipc(&rFalseIfx);
- if(sign)
- pic16_emitpLabel(truelbl->key);
-
- if(ifx) ifx->generated = 1;
- return;
-
-
- }
-#endif // _swapp
-
- if(AOP_TYPE(left) == AOP_LIT) {
- //symbol *lbl = newiTempLabel(NULL);
-
- //EXPERIMENTAL lit = (unsigned long)(floatFromVal(AOP(left)->aopu.aop_lit));
-
-
- DEBUGpic16_emitcode(";left lit","lit = 0x%x,sign=%d",lit,sign);
-
- /* Special cases */
- if((lit == 0) && (sign == 0)){
-
- size--;
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right),size));
- while(size)
- pic16_emitpcode(POC_IORFW, pic16_popGet(AOP(right),--size));
-
- genSkipz2(&rFalseIfx,0);
- if(ifx) ifx->generated = 1;
- return;
- }
-
- if(size==1) {
- /* Special cases */
- lit &= 0xff;
- if(((lit == 0xff) && !sign) || ((lit==0x7f) && sign)) {
- /* degenerate compare can never be true */
- if(rFalseIfx.condition == 0)
- pic16_emitpcode(POC_GOTO,pic16_popGetLabel(rFalseIfx.lbl->key));
-
- if(ifx) ifx->generated = 1;
- return;
- }
-
- if(sign) {
- /* signed comparisons to a literal byte */
-
- int lp1 = (lit+1) & 0xff;
-
- DEBUGpic16_emitcode(";left lit","line = %d lit = 0x%x",__LINE__,lit);
- switch (lp1) {
- case 0:
- rFalseIfx.condition ^= 1;
- genSkipCond(&rFalseIfx,right,0,7);
- break;
- case 0x7f:
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right),0));
- pic16_emitpcode(POC_XORLW, pic16_popGetLit(0x7f));
- genSkipz2(&rFalseIfx,1);
- break;
- default:
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right),0));
- pic16_emitpcode(POC_ADDLW, pic16_popGetLit(0x80));
- pic16_emitpcode(POC_ADDLW, pic16_popGetLit(((-(lit+1)) & 0xff) ^ 0x80));
- rFalseIfx.condition ^= 1;
- genSkipc(&rFalseIfx);
- break;
- }
- } else {
- /* unsigned comparisons to a literal byte */
-
- switch(lit & 0xff ) {
- case 0:
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right),0));
- genSkipz2(&rFalseIfx,0);
- break;
- case 0x7f:
- rFalseIfx.condition ^= 1;
- genSkipCond(&rFalseIfx,right,0,7);
- break;
-
- default:
- pic16_emitpcode(POC_MOVLW, pic16_popGetLit((lit+1) & 0xff));
- pic16_emitpcode(POC_SUBFW, pic16_popGet(AOP(right),0));
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- rFalseIfx.condition ^= 1;
- if (AOP_TYPE(result) == AOP_CRY)
- genSkipc(&rFalseIfx);
- else {
- pic16_emitpcode(POC_CLRF, pic16_popGet(AOP(result),0));
- pic16_emitpcode(POC_RLCF, pic16_popGet(AOP(result),0));
- }
- break;
- }
- }
-
- if(ifx) ifx->generated = 1;
- if ((AOP_TYPE(result) != AOP_CRY) && (AOP_SIZE(result)))
- goto check_carry;
- return;
-
- } else {
-
- /* Size is greater than 1 */
-
- if(sign) {
- int lp1 = lit+1;
-
- size--;
-
- if(lp1 == 0) {
- /* this means lit = 0xffffffff, or -1 */
-
-
- DEBUGpic16_emitcode(";left lit = -1","line = %d ",__LINE__);
- rFalseIfx.condition ^= 1;
- genSkipCond(&rFalseIfx,right,size,7);
- if(ifx) ifx->generated = 1;
-
- if ((AOP_TYPE(result) != AOP_CRY) && (AOP_SIZE(result)))
- goto check_carry;
-
- return;
- }
-
- if(lit == 0) {
- int s = size;
-
- if(rFalseIfx.condition) {
- pic16_emitpcode(POC_BTFSC, pic16_newpCodeOpBit(pic16_aopGet(AOP(right),size,FALSE,FALSE),7,0, PO_GPR_REGISTER));
- pic16_emitpcode(POC_GOTO, pic16_popGetLabel(truelbl->key));
- }
-
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right),size));
- while(size--)
- pic16_emitpcode(POC_IORFW, pic16_popGet(AOP(right),size));
-
-
- emitSKPZ;
- if(rFalseIfx.condition) {
- pic16_emitpcode(POC_GOTO, pic16_popGetLabel(rFalseIfx.lbl->key));
- pic16_emitpLabel(truelbl->key);
- }else {
- rFalseIfx.condition ^= 1;
- genSkipCond(&rFalseIfx,right,s,7);
- }
-
- if(ifx) ifx->generated = 1;
-
- if ((AOP_TYPE(result) != AOP_CRY) && (AOP_SIZE(result)))
- goto check_carry;
-
- return;
- }
-
- if((size == 1) && (0 == (lp1&0xff))) {
- /* lower byte of signed word is zero */
- DEBUGpic16_emitcode(";left lit","line = %d 0x%x+1 low byte is zero",__LINE__,lit);
- i = ((lp1 >> 8) & 0xff) ^0x80;
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right),size));
- pic16_emitpcode(POC_ADDLW, pic16_popGetLit( 0x80));
- pic16_emitpcode(POC_ADDLW, pic16_popGetLit(0x100-i));
-
- if ((AOP_TYPE(result) != AOP_CRY) && (AOP_SIZE(result))) {
- emitTOGC;
- if(ifx) ifx->generated = 1;
- goto check_carry;
- } else {
- rFalseIfx.condition ^= 1;
- genSkipc(&rFalseIfx);
- if(ifx) ifx->generated = 1;
- }
-
- return;
- }
-
- if(lit & (0x80 << (size*8))) {
- /* Lit is less than zero */
- DEBUGpic16_emitcode(";left lit","line = %d 0x%x is less than 0",__LINE__,lit);
- //rFalseIfx.condition ^= 1;
- //genSkipCond(&rFalseIfx,left,size,7);
- //rFalseIfx.condition ^= 1;
- pic16_emitpcode(POC_BTFSS, pic16_newpCodeOpBit(pic16_aopGet(AOP(right),size,FALSE,FALSE),7,0, PO_GPR_REGISTER));
- //pic16_emitpcode(POC_GOTO, pic16_popGetLabel(truelbl->key));
-
- if(rFalseIfx.condition)
- pic16_emitpcode(POC_GOTO, pic16_popGetLabel(rFalseIfx.lbl->key));
- else
- pic16_emitpcode(POC_GOTO, pic16_popGetLabel(truelbl->key));
-
-
- } else {
- /* Lit is greater than or equal to zero */
- DEBUGpic16_emitcode(";left lit","line = %d 0x%x is greater than 0",__LINE__,lit);
- //rFalseIfx.condition ^= 1;
- //genSkipCond(&rFalseIfx,right,size,7);
- //rFalseIfx.condition ^= 1;
-
- //pic16_emitpcode(POC_BTFSC, pic16_newpCodeOpBit(pic16_aopGet(AOP(right),size,FALSE,FALSE),7,0));
- //pic16_emitpcode(POC_GOTO, pic16_popGetLabel(rFalseIfx.lbl->key));
-
- pic16_emitpcode(POC_BTFSC, pic16_newpCodeOpBit(pic16_aopGet(AOP(right),size,FALSE,FALSE),7,0, PO_GPR_REGISTER));
- if(rFalseIfx.condition)
- pic16_emitpcode(POC_GOTO, pic16_popGetLabel(truelbl->key));
- else
- pic16_emitpcode(POC_GOTO, pic16_popGetLabel(rFalseIfx.lbl->key));
-
- }
-
- pic16_emitpcode(POC_MOVLW, pic16_popGetLit((lp1 >> (size*8)) & 0xff));
- pic16_emitpcode(POC_SUBFW, pic16_popGet(AOP(right),size));
-
- while(size--) {
-
- pic16_emitpcode(POC_MOVLW, pic16_popGetLit((lp1 >> (size*8)) & 0xff));
- emitSKPNZ;
- pic16_emitpcode(POC_SUBFW, pic16_popGet(AOP(right),size));
- }
- rFalseIfx.condition ^= 1;
- //rFalseIfx.condition = 1;
- genSkipc(&rFalseIfx);
-
- pic16_emitpLabel(truelbl->key);
-
- if(ifx) ifx->generated = 1;
-
-
- if ((AOP_TYPE(result) != AOP_CRY) && (AOP_SIZE(result)))
- goto check_carry;
-
- return;
- // end of if (sign)
- } else {
-
- /* compare word or long to an unsigned literal on the right.*/
-
-
- size--;
- if(lit < 0xff) {
- DEBUGpic16_emitcode ("; ***","%s %d lit =0x%x < 0xff",__FUNCTION__,__LINE__,lit);
- switch (lit) {
- case 0:
- break; /* handled above */
-/*
- case 0xff:
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right),size));
- while(size--)
- pic16_emitpcode(POC_IORFW, pic16_popGet(AOP(right),size));
- genSkipz2(&rFalseIfx,0);
- break;
-*/
- default:
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right),size));
- while(--size)
- pic16_emitpcode(POC_IORFW, pic16_popGet(AOP(right),size));
-
- emitSKPZ;
- if(rFalseIfx.condition)
- pic16_emitpcode(POC_GOTO, pic16_popGetLabel(rFalseIfx.lbl->key));
- else
- pic16_emitpcode(POC_GOTO, pic16_popGetLabel(truelbl->key));
-
-
- pic16_emitpcode(POC_MOVLW, pic16_popGetLit(lit+1));
- pic16_emitpcode(POC_SUBFW, pic16_popGet(AOP(right),0));
-
- rFalseIfx.condition ^= 1;
- genSkipc(&rFalseIfx);
- }
-
- pic16_emitpLabel(truelbl->key);
-
- if(ifx) ifx->generated = 1;
-
- if ((AOP_TYPE(result) != AOP_CRY) && (AOP_SIZE(result)))
- goto check_carry;
-
- return;
- }
-
-
- lit++;
- DEBUGpic16_emitcode ("; ***","%s %d lit =0x%x",__FUNCTION__,__LINE__,lit);
- i = (lit >> (size*8)) & 0xff;
-
- pic16_emitpcode(POC_MOVLW, pic16_popGetLit(i));
- pic16_emitpcode(POC_SUBFW, pic16_popGet(AOP(right),size));
-
- while(size--) {
- i = (lit >> (size*8)) & 0xff;
-
- if(i) {
- pic16_emitpcode(POC_MOVLW, pic16_popGetLit(i));
- emitSKPNZ;
- pic16_emitpcode(POC_SUBFW, pic16_popGet(AOP(right),size));
- } else {
- /* this byte of the lit is zero,
- * if it's not the last then OR in the variable */
- if(size)
- pic16_emitpcode(POC_IORFW, pic16_popGet(AOP(right),size));
- }
- }
-
-
- pic16_emitpLabel(lbl->key);
-
- rFalseIfx.condition ^= 1;
-
- genSkipc(&rFalseIfx);
- }
-
- if(sign)
- pic16_emitpLabel(truelbl->key);
- if(ifx) ifx->generated = 1;
-
- if ((AOP_TYPE(result) != AOP_CRY) && (AOP_SIZE(result)))
- goto check_carry;
-
- return;
- }
- }
- /* Compare two variables */
-
- DEBUGpic16_emitcode(";sign","%d",sign);
-
- size--;
- if(sign) {
- /* Sigh. thus sucks... */
- if(size) {
- pCodeOp *pctemp;
-
- pctemp = pic16_popGetTempReg(1);
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left),size));
- pic16_emitpcode(POC_MOVWF, pctemp); //pic16_popRegFromIdx(pic16_Gstack_base_addr));
- pic16_emitpcode(POC_MOVLW, pic16_popGetLit(0x80));
- pic16_emitpcode(POC_XORWF, pctemp); //pic16_popRegFromIdx(pic16_Gstack_base_addr));
- pic16_emitpcode(POC_XORFW, pic16_popGet(AOP(right),size));
- pic16_emitpcode(POC_SUBFW, pctemp); //pic16_popRegFromIdx(pic16_Gstack_base_addr));
- pic16_popReleaseTempReg(pctemp, 1);
- } else {
- /* Signed char comparison */
- /* Special thanks to Nikolai Golovchenko for this snippet */
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right),0));
- pic16_emitpcode(POC_SUBFW, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_RRCFW, pic16_popGet(AOP(left),0)); /* could be any register */
- pic16_emitpcode(POC_XORFW, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_XORFW, pic16_popGet(AOP(right),0));
- pic16_emitpcode(POC_ADDLW, pic16_popGetLit(0x80));
-
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- genSkipc(&rFalseIfx);
-
- if(ifx) ifx->generated = 1;
-
- if ((AOP_TYPE(result) != AOP_CRY) && (AOP_SIZE(result)))
- goto check_carry;
-
- return;
- }
-
- } else {
-
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right),size));
- pic16_emitpcode(POC_SUBFW, pic16_popGet(AOP(left),size));
- }
-
-
- /* The rest of the bytes of a multi-byte compare */
- while (size) {
-
- emitSKPZ;
- pic16_emitpcode(POC_GOTO, pic16_popGetLabel(lbl->key));
- size--;
-
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right),size));
- pic16_emitpcode(POC_SUBFW, pic16_popGet(AOP(left),size));
-
-
- }
-
- pic16_emitpLabel(lbl->key);
-
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if ((AOP_TYPE(result) == AOP_CRY && AOP_SIZE(result)) ||
- (AOP_TYPE(result) == AOP_REG)) {
- pic16_emitpcode(POC_CLRF, pic16_popGet(AOP(result),0));
- pic16_emitpcode(POC_RLCF, pic16_popGet(AOP(result),0));
- } else {
- genSkipc(&rFalseIfx);
- }
- //genSkipc(&rFalseIfx);
- if(ifx) ifx->generated = 1;
-
-
- if ((AOP_TYPE(result) != AOP_CRY) && (AOP_SIZE(result)))
- goto check_carry;
-
- return;
-
- }
-
-check_carry:
- if ((AOP_TYPE(result) != AOP_CRY)
- && AOP_SIZE(result)) {
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
-
- if(!ifx)pic16_emitpLabel( rFalseIfx.lbl->key );
-
- pic16_outBitC(result);
- } else {
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- /* if the result is used in the next
- ifx conditional branch then generate
- code a little differently */
- if (ifx )
- genIfxJump (ifx,"c");
- else
- pic16_outBitC(result);
- /* leave the result in acc */
- }
-
-}
-
-#elif 0 /* VR version of genCmp() */ /* } else { */
-
-/* check all condition and return appropriate instruction, POC_CPFSGT or POC_CPFFSLT */
-static int selectCompareOp(resolvedIfx *rIfx, iCode *ifx,
- operand *result, int offset, int invert_op)
-{
- /* add code here */
-
- /* check condition, > or < ?? */
- if(rIfx->condition != 0)invert_op ^= 1;
-
- if(ifx && IC_FALSE(ifx))invert_op ^= 1;
-
- if(!ifx)invert_op ^= 1;
-
- DEBUGpic16_emitcode("; +++", "%s:%d %s] rIfx->condition= %d, ifx&&IC_FALSE(ifx)= %d, invert_op = %d",
- __FILE__, __LINE__, __FUNCTION__, rIfx->condition, (ifx && IC_FALSE(ifx)), invert_op);
-
- /* do selection */
- if(!invert_op)return POC_CPFSGT;
- else return POC_CPFSLT;
-}
-
-static int compareAopfirstpass=1;
-
-static void compareAop(resolvedIfx *resIfx, iCode *ifx, symbol *falselbl,
- operand *oper, int offset, operand *result,
- int sign, int invert_op, pCodeOp *pcop, pCodeOp *pcop2,
- symbol *tlbl)
-{
- int op;
- symbol *truelbl;
-
- /* invert if there is a result to be loaded, in order to fit,
- * SETC/CLRC sequence */
- if(AOP_SIZE(result))invert_op ^= 1;
-
-// if(sign && !offset)invert_op ^= 1;
-
-// if(sign)invert_op ^= 1;
-
- op = selectCompareOp(resIfx, ifx, result, offset, invert_op);
-
- if(AOP_SIZE(result) && compareAopfirstpass) {
- if(!ifx) {
- if(pcop2)
- pic16_emitpcode(POC_SETF, pcop2);
- else
- emitSETC;
- } else {
- if(pcop2)
- pic16_emitpcode(POC_CLRF, pcop2);
- else
- emitCLRC;
- }
- }
-
- compareAopfirstpass = 0;
-
- /* there is a bug when comparing operands with size > 1,
- * because higher bytes can be equal and test should be performed
- * to the next lower byte, current algorithm, considers operands
- * inequal in these cases! -- VR 20041107 */
-
-
- if(pcop)
- pic16_emitpcode(op, pcop);
- else
- pic16_emitpcode(op, pic16_popGet(AOP(oper), offset));
-
-
- if((!sign || !offset) && AOP_SIZE(result)) {
- if(!ifx) {
- if(pcop2)
- pic16_emitpcode(POC_CLRF, pcop2);
- else
- emitCLRC;
- } else {
- if(pcop2)
- pic16_emitpcode(POC_SETF, pcop2);
- else
- emitSETC;
- }
-
- /* don't emit final branch (offset == 0) */
- if(offset) {
-
- if(pcop2)
- pic16_emitpcode(POC_RRCF, pcop2);
-
- pic16_emitpcode(POC_BNC, pic16_popGetLabel(falselbl->key));
- }
- } else {
- if((ifx && (IC_TRUE(ifx)!=NULL)) || (sign && !offset)) {
- DEBUGpic16_emitcode ("; +++","%s: %d: ifx = %p, IC_TRUE(ifx) = %d, sign = %d, offset = %d",
- __FUNCTION__, __LINE__, ifx, (ifx&&IC_TRUE(ifx)), sign, offset);
-
- truelbl = newiTempLabel( NULL );
- pic16_emitpcode(POC_BRA, pic16_popGetLabel(truelbl->key));
- if((!ifx || !IC_TRUE(ifx)) && (sign && !offset))
- pic16_emitpcode(POC_GOTO, pic16_popGetLabel(tlbl->key));
- else
- pic16_emitpcode(POC_GOTO, pic16_popGetLabel(resIfx->lbl->key));
- pic16_emitpLabel(truelbl->key);
- } else {
- pic16_emitpcode(POC_GOTO, pic16_popGetLabel(resIfx->lbl->key));
- }
- }
-}
-
-static void genCmp (operand *left, operand *right,
- operand *result, iCode *ifx, int sign)
-{
- int size, cmpop=1;
- long lit = 0L;
- resolvedIfx rFalseIfx;
- symbol *falselbl, *tlbl;
-
- FENTRY;
-
- DEBUGpic16_pic16_AopType(__LINE__,left,right,result);
-
- resolveIfx(&rFalseIfx, ifx);
- size = max(AOP_SIZE(left), AOP_SIZE(right));
-
- /* if left & right are bit variables */
- if(AOP_TYPE(left) == AOP_CRY
- && AOP_TYPE(right) == AOP_CRY ) {
-
- pic16_emitcode("mov","c,%s",AOP(right)->aopu.aop_dir);
- pic16_emitcode("anl","c,/%s",AOP(left)->aopu.aop_dir);
-
- werror(W_POSSBUG2, __FILE__, __LINE__);
- exit(-1);
- }
-
- /* if literal is on the right then swap with left */
- if((AOP_TYPE(right) == AOP_LIT)) {
- operand *tmp = right ;
-// unsigned long mask = (0x100 << (8*(size-1))) - 1;
-
- lit = /*(unsigned long)*/floatFromVal(AOP(right)->aopu.aop_lit);
-
-// lit = (lit - 1) & mask;
- right = left;
- left = tmp;
- rFalseIfx.condition ^= 1; /* reverse compare */
- } else
- if ((AOP_TYPE(left) == AOP_LIT)) {
- /* float compares are handled by support functions */
- lit = /*(unsigned long)*/floatFromVal(AOP(left)->aopu.aop_lit);
- }
-
- /* actual comparing algorithm */
-// size = AOP_SIZE( right );
-
- falselbl = newiTempLabel( NULL );
- if(AOP_TYPE(left) == AOP_LIT) {
- /* compare to literal */
- DEBUGpic16_emitcode ("; ***","%s: %d: compare to literal", __FUNCTION__, __LINE__);
-
- if(sign) {
- pCodeOp *pct, *pct2;
- symbol *tlbl1;
-
- /* signed compare */
- DEBUGpic16_emitcode ("; ***","%s: %d: signed compare", __FUNCTION__, __LINE__);
-
- pct = pic16_popCopyReg(&pic16_pc_prodl);
- pct2 = pic16_popCopyReg(&pic16_pc_prodh);
- tlbl = newiTempLabel( NULL );
-
- /* first compare signs:
- * a. if both are positive, compare just like unsigned
- * b. if both are negative, invert cmpop, compare just like unsigned
- * c. if different signs, determine the result directly */
-
- size--;
-
-#if 1
- /* { */
- tlbl1 = newiTempLabel( NULL );
-// pic16_emitpcode(POC_RLCFW, pic16_popGet( AOP(right), size)); /* move sign to carry */
-
- if(lit > 0) {
-
- /* literal is zero or positive:
- * a. if carry is zero, too, continue compare,
- * b. if carry is set, then continue depending on cmpop ^ condition:
- * 1. '<' return false (literal < variable),
- * 2. '>' return true (literal > variable) */
-// pic16_emitpcode(POC_BNC, pic16_popGetLabel( tlbl1->key ));
- pic16_emitpcode(POC_BTFSC, pic16_popCopyGPR2Bit(pic16_popGet(AOP(right), size), 7));
-
-
- if(cmpop ^ rFalseIfx.condition)pic16_emitpcode(POC_GOTO, pic16_popGetLabel( tlbl->key ));
- else pic16_emitpcode(POC_GOTO, pic16_popGetLabel( rFalseIfx.lbl->key ));
- } else
- if(lit < 0) {
-
- /* literal is negative:
- * a. if carry is set, too, continue compare,
- * b. if carry is zero, then continue depending on cmpop ^ condition:
- * 1. '<' return true (literal < variable),
- * 2. '>' return false (literal > variable) */
-// pic16_emitpcode(POC_BC, pic16_popGetLabel( tlbl1->key ));
- pic16_emitpcode(POC_BTFSS, pic16_popCopyGPR2Bit(pic16_popGet(AOP(right), size), 7));
-
- if(!(cmpop ^ rFalseIfx.condition))pic16_emitpcode(POC_GOTO, pic16_popGetLabel( tlbl->key ));
- else pic16_emitpcode(POC_GOTO, pic16_popGetLabel( rFalseIfx.lbl->key));
- }
-#if 1
- else {
- /* lit == 0 */
- pic16_emitpcode(POC_BTFSC, pic16_popCopyGPR2Bit(pic16_popGet(AOP(right), size), 7));
-
- if(!(cmpop ^ rFalseIfx.condition))pic16_emitpcode(POC_GOTO, pic16_popGetLabel( tlbl->key ));
- else pic16_emitpcode(POC_GOTO, pic16_popGetLabel( rFalseIfx.lbl->key));
- }
-#endif
-
-
- pic16_emitpLabel( tlbl1->key );
-#endif /* } */
-
- compareAopfirstpass=1;
-// pic16_emitpcode(POC_MOVLW, pic16_popGetLit(0x80));
-// pic16_emitpcode(POC_ADDFW, pic16_popGet(AOP(right), size));
-// pic16_emitpcode(POC_MOVWF, pct);
-
-// pic16_emitpcode(POC_MOVLW, pic16_popGetLit(BYTEofLONG(lit, size) + 0x80));
- pic16_emitpcode(POC_MOVLW, pic16_popGetLit(BYTEofLONG(lit, size)));
-// compareAop(&rFalseIfx, ifx, falselbl, right, size, result, sign, 1, pct, pct2, tlbl);
- compareAop(&rFalseIfx, ifx, falselbl, right, size, result, sign, 1, NULL, pct2, tlbl);
-
- /* generic case */
- while( size-- ) {
-// pic16_emitpcode(POC_MOVLW, pic16_popGetLit(0x80));
-// pic16_emitpcode(POC_MOVLW, pic16_popGetLit(0x0));
-// pic16_emitpcode(POC_ADDFW, pic16_popGet(AOP(right), size));
-// pic16_emitpcode(POC_MOVWF, pct);
-
-// pic16_emitpcode(POC_MOVLW, pic16_popGetLit(BYTEofLONG(lit, size) + 0x80));
- pic16_emitpcode(POC_MOVLW, pic16_popGetLit(BYTEofLONG(lit, size) + 0x0));
- compareAop(&rFalseIfx, ifx, falselbl, right, size, result, sign, 1, NULL, pct2, tlbl);
-// compareAop(&rFalseIfx, ifx, falselbl, right, size, result, sign, 1, pct, pct2, tlbl);
-// compareAop(&rFalseIfx, ifx, falselbl, right, size, result, sign, 0, pct, pct2, tlbl);
- }
-
- if(ifx)ifx->generated = 1;
-
- if(AOP_SIZE(result)) {
- pic16_emitpLabel(tlbl->key);
- pic16_emitpLabel(falselbl->key);
- pic16_outBitOp( result, pct2 );
- } else {
- pic16_emitpLabel(tlbl->key);
- }
- } else {
-
- /* unsigned compare */
- DEBUGpic16_emitcode ("; ***","%s: %d: unsigned compare", __FUNCTION__, __LINE__);
-
- compareAopfirstpass=1;
- while(size--) {
-
- pic16_emitpcode(POC_MOVLW, pic16_popGetLit(BYTEofLONG(lit, size)));
- compareAop(&rFalseIfx, ifx, falselbl, right, size, result, sign, 1, NULL, NULL, NULL);
-
- }
- if(ifx)ifx->generated = 1;
-
- if(AOP_SIZE(result)) {
- pic16_emitpLabel(falselbl->key);
- pic16_outBitC( result );
- }
-
- }
- } else {
- /* compare registers */
- DEBUGpic16_emitcode ("; ***","%s: %d: compare registers", __FUNCTION__, __LINE__);
-
-
- if(sign) {
- pCodeOp *pct, *pct2;
-
- /* signed compare */
- DEBUGpic16_emitcode ("; ***","%s: %d: signed compare", __FUNCTION__, __LINE__);
-
- pct = pic16_popCopyReg(&pic16_pc_prodl); /* first temporary register */
- pct2 = pic16_popCopyReg(&pic16_pc_prodh); /* second temporary register */
- tlbl = newiTempLabel( NULL );
-
- compareAopfirstpass=1;
-
- size--;
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right), size));
-// pic16_emitpcode(POC_ADDLW, pic16_popGetLit(0x80));
- pic16_emitpcode(POC_ADDLW, pic16_popGetLit(0x0));
- pic16_emitpcode(POC_MOVWF, pct);
-
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left), size));
-// pic16_emitpcode(POC_ADDLW, pic16_popGetLit(0x80));
- pic16_emitpcode(POC_ADDLW, pic16_popGetLit(0x0));
-
- /* WREG already holds left + 0x80 */
- compareAop(&rFalseIfx, ifx, falselbl, right, size, result, sign, 1, pct, pct2, tlbl);
-
- while( size-- ) {
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right), size));
-// pic16_emitpcode(POC_ADDLW, pic16_popGetLit(0x80));
- pic16_emitpcode(POC_ADDLW, pic16_popGetLit(0x0));
- pic16_emitpcode(POC_MOVWF, pct);
-
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left), size));
-// pic16_emitpcode(POC_ADDLW, pic16_popGetLit(0x80));
- pic16_emitpcode(POC_ADDLW, pic16_popGetLit(0x0));
-
- /* WREG already holds left + 0x80 */
- compareAop(&rFalseIfx, ifx, falselbl, right, size, result, sign, 1, pct, pct2, tlbl);
-// compareAop(&rFalseIfx, ifx, falselbl, right, size, result, sign, 0, pct, pct2, tlbl);
- }
-
- if(ifx)ifx->generated = 1;
-
- if(AOP_SIZE(result)) {
- pic16_emitpLabel(tlbl->key);
- pic16_emitpLabel(falselbl->key);
- pic16_outBitOp( result, pct2 );
- } else {
- pic16_emitpLabel(tlbl->key);
- }
-
- } else {
- /* unsigned compare */
- DEBUGpic16_emitcode ("; ***","%s: %d: unsigned compare", __FUNCTION__, __LINE__);
-
- compareAopfirstpass=1;
- while(size--) {
-
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left), size));
- compareAop(&rFalseIfx, ifx, falselbl, right, size, result, sign, 1, NULL, NULL, NULL);
-
- }
-
- if(ifx)ifx->generated = 1;
- if(AOP_SIZE(result)) {
-
- pic16_emitpLabel(falselbl->key);
- pic16_outBitC( result );
- }
-
- }
- }
-}
-
-#endif /* } */
-
-
-
-/*-----------------------------------------------------------------*/
-/* genCmpGt :- greater than comparison */
-/*-----------------------------------------------------------------*/
-static void genCmpGt (iCode *ic, iCode *ifx)
-{
- operand *left, *right, *result;
- sym_link *letype , *retype;
- int sign ;
-
- FENTRY;
-
- left = IC_LEFT(ic);
- right= IC_RIGHT(ic);
- result = IC_RESULT(ic);
-
- letype = getSpec(operandType(left));
- retype =getSpec(operandType(right));
- sign = !(SPEC_USIGN(letype) | SPEC_USIGN(retype));
- /* assign the amsops */
- pic16_aopOp (left,ic,FALSE);
- pic16_aopOp (right,ic,FALSE);
- pic16_aopOp (result,ic,TRUE);
-
- genCmp(right, left, result, ifx, sign);
-
- pic16_freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- pic16_freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- pic16_freeAsmop(result,NULL,ic,TRUE);
-}