]> git.gag.com Git - fw/sdcc/commitdiff
- And'ing with a constant works (again).
authorsdattalo <sdattalo@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 17 Oct 2001 05:33:44 +0000 (05:33 +0000)
committersdattalo <sdattalo@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 17 Oct 2001 05:33:44 +0000 (05:33 +0000)
  - Added and1.c to test anding unsigned chars, ints, and longs with lits.
  - Change PIC regression testing so that simulations are run only on the
C files that have changed

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1412 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/pic/gen.c
src/regression/Makefile
src/regression/and1.c [new file with mode: 0644]

index 78b27bfbc3e98e48d71e88b06cb1e86c23bb3d1b..8f52b8a0a8e1229d75f24aab1c640d72b137c10e 100644 (file)
@@ -1536,7 +1536,7 @@ int pic14_getDataSize(operand *op)
 /*-----------------------------------------------------------------*/
 void pic14_outAcc(operand *result)
 {
-    int size, offset;
+
     DEBUGpic14_emitcode ("; ***","%s  %d - Warning no code will be generated here",__FUNCTION__,__LINE__);
 
 #if 0
@@ -3625,15 +3625,26 @@ static void genc16bit2lit(operand *op, int lit, int offset)
     emitpcode(POC_MOVFW,popGet(AOP(op),offset+i,FALSE,FALSE));
     emitpcode(POC_XORLW,popGetLit(BYTEofLONG(lit,i)));
   }
+
   i ^= 1;
 
-  if(BYTEofLONG(lit,i)) {
+  switch( BYTEofLONG(lit,i)) { 
+  case 0:
+    emitpcode(POC_IORFW,popGet(AOP(op),offset+i,FALSE,FALSE));
+    break;
+  case 1:
+    emitSKPNZ;
+    emitpcode(POC_DECFW,popGet(AOP(op),offset+i,FALSE,FALSE));
+    break;
+  case 0xff:
+    emitSKPNZ;
+    emitpcode(POC_INCFW,popGet(AOP(op),offset+i,FALSE,FALSE));
+    break;
+  default:
     emitpcode(POC_MOVLW,popGetLit(BYTEofLONG(lit,i)));
     emitSKPNZ;
     emitpcode(POC_XORFW,popGet(AOP(op),offset+i,FALSE,FALSE));
 
-  }else {
-    emitpcode(POC_IORFW,popGet(AOP(op),offset+i,FALSE,FALSE));
   }
 
 }
@@ -4333,15 +4344,11 @@ static void genAnd (iCode *ic, iCode *ifx)
             // if(left &  2^n)
          else{
            if(ifx){
-             pCodeOp *pcorb = popGet(AOP(left),0,TRUE,FALSE);
-             PCORB(pcorb)->subtype = PCOP(pcorb)->type;
-             PCOP(pcorb)->type = PO_GPR_BIT;
-             PCORB(pcorb)->bit = posbit;
              if(IC_TRUE(ifx)) {
-               emitpcode(POC_BTFSC, pcorb); 
+               emitpcode(POC_BTFSC,newpCodeOpBit(aopGet(AOP(left),0,FALSE,FALSE),posbit,0));
                emitpcode(POC_GOTO,popGetLabel(IC_TRUE(ic)->key));
              } else {
-               emitpcode(POC_BTFSS, pcorb); 
+               emitpcode(POC_BTFSS,newpCodeOpBit(aopGet(AOP(left),0,FALSE,FALSE),posbit,0));
                emitpcode(POC_GOTO,popGetLabel(IC_FALSE(ic)->key));
              }
              ifx->generated = 1;
@@ -4386,6 +4393,7 @@ static void genAnd (iCode *ic, iCode *ifx)
 
     /* if left is same as result */
     if(pic14_sameRegs(AOP(result),AOP(left))){
+      int know_W = -1;
       for(;size--; offset++,lit>>=8) {
        if(AOP_TYPE(right) == AOP_LIT){
          switch(lit & 0xff) {
@@ -4395,8 +4403,7 @@ static void genAnd (iCode *ic, iCode *ifx)
            emitpcode(POC_CLRF,popGet(AOP(result),offset,FALSE,FALSE));
            break;
          case 0xff:
-           pic14_emitcode("movf","%s,w",aopGet(AOP(right),offset,FALSE,FALSE));
-           emitpcode(POC_MOVWF,popGet(AOP(right),offset,FALSE,FALSE));
+           /* and'ing with 0xff is a nop when the result and left are the same */
            break;
 
          default:
@@ -4405,11 +4412,15 @@ static void genAnd (iCode *ic, iCode *ifx)
              if(p>=0) {
                /* only one bit is set in the literal, so use a bcf instruction */
                pic14_emitcode("bcf","%s,%d",aopGet(AOP(left),offset,FALSE,TRUE),p);
-               emitpcode(POC_BCF,popGet(AOP(left),offset,FALSE,TRUE));
+               //emitpcode(POC_BCF,popGet(AOP(left),offset,FALSE,TRUE));
+               emitpcode(POC_BCF,newpCodeOpBit(aopGet(AOP(left),offset,FALSE,FALSE),p,0));
+
              } else {
                pic14_emitcode("movlw","0x%x", (lit & 0xff));
                pic14_emitcode("andwf","%s,f",aopGet(AOP(left),offset,FALSE,TRUE));
-               emitpcode(POC_MOVLW, popGetLit(lit & 0xff));
+               if(know_W != (lit&0xff))
+                 emitpcode(POC_MOVLW, popGetLit(lit & 0xff));
+               know_W = lit &0xff;
                emitpcode(POC_ANDWF,popGet(AOP(left),offset,FALSE,TRUE));
              }
            }    
index fd8001aabd4f7dfa188e324ac7c1435cb8d7f0a5..3b740b23f3776ab2692403ce38d600b8399b4e55 100644 (file)
@@ -1,5 +1,10 @@
 # Regression testing Makefile for Pic Port of SDCC
 #
+# note that this regression suite was started before
+# the one in sdcc/regression. The regression suite in
+# sdcc/regression is better suited for testing mature
+# ports.
+#
 # GPL'd
 #
 # T. Scott Dattalo scott@dattalo.com
@@ -58,6 +63,7 @@ SRC = b.c \
        add.c \
        add2.c \
        add3.c \
+       and1.c \
        bool1.c \
        call1.c \
        compare.c \
@@ -96,6 +102,8 @@ all: test
 # The .stc files are script files for gpsim
 .cod.stc:
        ./$(CREATESTC) $*.cod $*.stc
+       echo "Created $*.stc"
+       ./$(SIMULATE) $*.stc $(LOGFILE)
 
 # this will also make .stc files
 #%.stc : %.cod
@@ -111,12 +119,6 @@ asm : $(ASM)
 stc : $(STC)
 
 test:  $(STC)
-       if [ -n "$(STC)" ]; then \
-       stcfiles="$(STC)" ; \
-       for f in $$stcfiles ; do \
-         ./$(SIMULATE) $$f $(LOGFILE); \
-       done ; \
-       fi
        echo "Done - Results are in $(LOGFILE)"
 
 cleancod:
diff --git a/src/regression/and1.c b/src/regression/and1.c
new file mode 100644 (file)
index 0000000..c566bd9
--- /dev/null
@@ -0,0 +1,121 @@
+
+unsigned char success=0;
+unsigned char failures=0;
+unsigned char dummy=0;
+
+
+unsigned int uint0 = 0;
+unsigned int uint1 = 0;
+unsigned char uchar0 = 0;
+unsigned char uchar1 = 0;
+unsigned long ulong0 = 0;
+
+void done()
+{
+
+  dummy++;
+
+}
+
+// uchar0 = 0xff;
+void and_lit2uchar(void)
+{
+
+  if(uchar0 != 0xff)
+    failures++;
+
+  uchar0 &= 0x7f;
+
+  if(uchar0 != 0x7f)
+    failures++;
+
+  uchar0 &= 0x3f;
+
+  if(uchar0 != 0x3f)
+    failures++;
+
+  uchar0 &= 0xdf;
+
+  if(uchar0 != 0x1f)
+    failures++;
+}
+
+void and_lit2uint(void)
+{
+  if(uint0 != 0xffff)
+    failures++;
+
+  uint0 &= 0x7fff;
+
+  if(uint0 != 0x7fff)
+    failures++;
+
+  uint0 &= 0x3fff;
+
+  if(uint0 != 0x3fff)
+    failures++;
+
+  uint0 &= 0xdfff;
+
+  if(uint0 != 0x1fff)
+    failures++;
+
+
+  uint0 &= 0xff7f;
+
+  if(uint0 != 0x1f7f)
+    failures++;
+
+  uint0 &= 0x0f0f;
+
+  if(uint0 != 0x0f0f)
+    failures++;
+
+  uint0 &= 0xfefe;
+
+  if(uint0 != 0x0e0e)
+    failures++;
+
+  uint0 &= 0xf0f0;
+
+  if(uint0 != 0)
+    failures++;
+}
+
+void and_lit2ulong(void)
+{
+
+  if(ulong0 != 0xffffffff)
+    failures++;
+
+  ulong0 &= 0x7fffffff;
+
+  if(ulong0 != 0x7fffffff)
+    failures++;
+
+  ulong0 &= 0xff00ffff;
+
+  if(ulong0 != 0x7f00ffff)
+    failures++;
+
+  ulong0 &= 0xfeff00ff;
+
+  if(ulong0 != 0x7e0000ff)
+    failures++;
+}
+
+void main(void)
+{
+
+  uchar0 = 0xff;
+  and_lit2uchar();
+
+  uint0 = 0xffff;
+  and_lit2uint();
+
+  ulong0 = 0xffffffff;
+  and_lit2ulong();
+
+  success = failures;
+  done();
+}