Implemented builtin functions
authorsandeep <sandeep@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 18 Nov 2001 18:58:21 +0000 (18:58 +0000)
committersandeep <sandeep@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 18 Nov 2001 18:58:21 +0000 (18:58 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1617 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/avr/main.c
src/ds390/gen.c
src/ds390/main.c
src/ds390/ralloc.c
src/izt/i186.c
src/izt/tlcs900h.c
src/mcs51/main.c
src/pic/main.c
src/z80/main.c

index 98097a1e6709a632ddb535e78992baa1d3fa0178..ba5a470bc05c3f28a665b0b5bc8526f0e32f7c7b 100644 (file)
@@ -219,5 +219,6 @@ PORT avr_port = {
        0,                      /* leave == */
        FALSE,                  /* No array initializer support. */
        0,                      /* no CSE cost estimation yet */
+       NULL,                   /* no builtin functions */
        PORT_MAGIC
 };
index 40bd4d6321cb9d1a7a6e2815d59e34c4950b0e68..0abcefab80d9667d2727a06e2407dd697df38437 100644 (file)
@@ -473,13 +473,13 @@ aopForSym (iCode * ic, symbol * sym, bool result, bool useDP2)
                                     ((short) sym->stack)) >> 8) & 0xff);
       if (useDP2) {
          if (options.model == MODEL_FLAT24)
-             emitcode ("mov", "dpx1,#0x40");
+             emitcode ("mov", "dpx1,#0x%02x", (options.stack_loc >> 16) & 0xff);
          TR_DPTR("#2");
          emitcode ("mov", "dph1,a");
          emitcode ("mov", "dpl1,b");
       } else {
          if (options.model == MODEL_FLAT24)
-             emitcode ("mov", "dpx,#0x40");
+             emitcode ("mov", "dpx,#0x%02x", (options.stack_loc >> 16) & 0xff);
          emitcode ("mov", "dph,a");
          emitcode ("mov", "dpl,b");
       }
@@ -9928,15 +9928,17 @@ genAddrOf (iCode * ic)
       
       /* if 10 bit stack */
       if (options.stack10bit) {
+         char buff[10];
+         sprintf(buff,"#0x%02x",(options.stack_loc >> 16) & 0xff);
          /* if it has an offset then we need to compute it */
-      emitcode ("subb", "a,#0x%02x",
-               -((sym->stack < 0) ?
-                 ((short) (sym->stack - _G.nRegsSaved)) :
-                 ((short) sym->stack)) & 0xff);
-      emitcode ("mov","b,a");
-      emitcode ("mov","a,#0x%02x",(-((sym->stack < 0) ?
-                                    ((short) (sym->stack - _G.nRegsSaved)) :
-                                    ((short) sym->stack)) >> 8) & 0xff);
+         emitcode ("subb", "a,#0x%02x",
+                   -((sym->stack < 0) ?
+                     ((short) (sym->stack - _G.nRegsSaved)) :
+                     ((short) sym->stack)) & 0xff);
+         emitcode ("mov","b,a");
+         emitcode ("mov","a,#0x%02x",(-((sym->stack < 0) ?
+                                        ((short) (sym->stack - _G.nRegsSaved)) :
+                                        ((short) sym->stack)) >> 8) & 0xff);
          if (sym->stack) {
              emitcode ("mov", "a,_bpx");
              emitcode ("add", "a,#0x%02x", ((sym->stack < 0) ? 
@@ -9949,12 +9951,12 @@ genAddrOf (iCode * ic)
                                              ((short) sym->stack )) >> 8) & 0xff);
              aopPut (AOP (IC_RESULT (ic)), "b", 0);
              aopPut (AOP (IC_RESULT (ic)), "a", 1);
-             aopPut (AOP (IC_RESULT (ic)), "#0x40", 2);
+             aopPut (AOP (IC_RESULT (ic)), buff, 2);
          } else {
              /* we can just move _bp */
              aopPut (AOP (IC_RESULT (ic)), "_bpx", 0);
              aopPut (AOP (IC_RESULT (ic)), "_bpx+1", 1);
-             aopPut (AOP (IC_RESULT (ic)), "#0x40", 2);
+             aopPut (AOP (IC_RESULT (ic)), buff, 2);
          }       
       } else {
          /* if it has an offset then we need to compute it */
@@ -10726,6 +10728,140 @@ genReceive (iCode * ic)
   freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
 }
 
+/*-----------------------------------------------------------------*/
+/* genMemcpyX2X - gen code for memcpy xdata to xdata               */
+/*-----------------------------------------------------------------*/
+static void genMemcpyX2X( iCode *ic, int nparms, operand **parms, int fromc)
+{
+    operand *from , *to , *count;
+    symbol *lbl;
+
+    /* we know it has to be 3 parameters */
+    assert (nparms == 3);
+    
+    to = parms[0];
+    from = parms[1];
+    count = parms[2];
+
+    aopOp (from, ic->next, FALSE, FALSE);
+
+    /* get from into DPTR1 */
+    emitcode ("mov", "dpl1,%s", aopGet (AOP (from), 0, FALSE, FALSE, TRUE));
+    emitcode ("mov", "dph1,%s", aopGet (AOP (from), 1, FALSE, FALSE, TRUE));
+    if (options.model == MODEL_FLAT24) {
+       emitcode ("mov", "dpx1,%s", aopGet (AOP (from), 2, FALSE, FALSE, TRUE));
+    }
+
+    freeAsmop (from, NULL, ic, FALSE);
+    aopOp (to, ic, FALSE, FALSE);
+    /* get "to" into DPTR */
+    /* if the operand is already in dptr
+       then we do nothing else we move the value to dptr */
+    if (AOP_TYPE (to) != AOP_STR) {
+       /* if already in DPTR then we need to push */
+       if (AOP_TYPE(to) == AOP_DPTR) {
+           emitcode ("push", "%s", aopGet (AOP (to), 0, FALSE, TRUE, TRUE));
+           emitcode ("push", "%s", aopGet (AOP (to), 1, FALSE, TRUE, TRUE));
+           if (options.model == MODEL_FLAT24)
+               emitcode ("mov", "dpx,%s", aopGet (AOP (to), 2, FALSE, FALSE, TRUE));
+           emitcode ("pop", "dph");
+           emitcode ("pop", "dpl");        
+       } else {
+           _startLazyDPSEvaluation ();
+           /* if this is remateriazable */
+           if (AOP_TYPE (to) == AOP_IMMD) {
+               emitcode ("mov", "dptr,%s", aopGet (AOP (to), 0, TRUE, FALSE, FALSE));
+           } else {                    /* we need to get it byte by byte */
+               emitcode ("mov", "dpl,%s", aopGet (AOP (to), 0, FALSE, FALSE, TRUE));
+               emitcode ("mov", "dph,%s", aopGet (AOP (to), 1, FALSE, FALSE, TRUE));
+               if (options.model == MODEL_FLAT24) {
+                   emitcode ("mov", "dpx,%s", aopGet (AOP (to), 2, FALSE, FALSE, TRUE));
+               }
+           }
+           _endLazyDPSEvaluation ();
+       }
+    }
+    freeAsmop (to, NULL, ic, FALSE);
+
+    aopOp (count, ic->next->next, FALSE,FALSE);
+    lbl =newiTempLabel(NULL);
+
+    /* now for the actual copy */
+    if (AOP_TYPE(count) == AOP_LIT && 
+       (int)floatFromVal (AOP(count)->aopu.aop_lit) <= 256) {
+       emitcode (";","OH! JOY auto increment with djnz (very fast)");
+       emitcode ("mov", "dps, #0x21");         /* Select DPTR2 & auto-toggle. */
+       emitcode ("mov", "b,%s",aopGet(AOP(count),0,FALSE,FALSE,FALSE));
+       emitcode ("","%05d$:",lbl->key+100);
+       if (fromc) {
+           emitcode ("clr","a");
+           emitcode ("movc", "a,@a+dptr");
+       } else 
+           emitcode ("movx", "a,@dptr");
+       emitcode ("movx", "@dptr,a");
+       emitcode ("inc", "dptr");
+       emitcode ("inc", "dptr");
+       emitcode ("djnz","b,%05d$",lbl->key+100);
+    } else {
+       symbol *lbl1 = newiTempLabel(NULL);
+       
+       emitcode (";"," Auto increment but no djnz");
+       emitcode ("mov","ap,%s",aopGet (AOP (count), 0, FALSE, TRUE, TRUE));
+       emitcode ("mov","b,%s",aopGet (AOP (count), 1, FALSE, TRUE, TRUE));
+       emitcode ("mov", "dps, #0x21");         /* Select DPTR2 & auto-toggle. */
+       emitcode ("","%05d$:",lbl->key+100);
+       if (fromc) {
+           emitcode ("clr","a");
+           emitcode ("movc", "a,@a+dptr");
+       } else 
+           emitcode ("movx", "a,@dptr");
+       emitcode ("movx", "@dptr,a");
+       emitcode ("inc", "dptr");
+       emitcode ("inc", "dptr");
+       emitcode ("mov","a,b");
+       emitcode ("orl","a,ap");
+       emitcode ("jz","%05d$",lbl1->key+100);
+       emitcode ("mov","a,ap");
+       emitcode ("add","a,#0xFF");
+       emitcode ("mov","ap,a");
+       emitcode ("mov","a,b");
+       emitcode ("addc","a,#0xFF");
+       emitcode ("mov","b,a");
+       emitcode ("sjmp","%05d$",lbl->key+100);
+       emitcode ("","%05d$:",lbl1->key+100);
+    }
+    emitcode ("mov", "dps, #0"); 
+    freeAsmop (count, NULL, ic, FALSE);
+
+}
+
+/*-----------------------------------------------------------------*/
+/* genBuiltIn - calls the appropriate function to  generating code */
+/* for a built in function                                        */
+/*-----------------------------------------------------------------*/
+static void genBuiltIn (iCode *ic)
+{
+    operand *bi_parms[MAX_BUILTIN_ARGS];
+    int nbi_parms;
+    iCode *bi_iCode;
+    symbol *bif;
+
+    /* get all the arguments for a built in function */
+    bi_iCode = getBuiltinParms(ic,&nbi_parms,bi_parms);
+
+    /* which function is it */
+    bif = OP_SYMBOL(IC_LEFT(bi_iCode));
+    if (strcmp(bif->name,"__builtin_memcpy_x2x")==0) {
+       genMemcpyX2X(bi_iCode,nbi_parms,bi_parms,0);
+    } else if (strcmp(bif->name,"__builtin_memcpy_c2x")==0) {
+       genMemcpyX2X(bi_iCode,nbi_parms,bi_parms,1);
+    } else {
+       werror(E_INTERNAL_ERROR,"unknown builtin function encountered\n");
+       return ;
+    }
+    return ;    
+}
+
 /*-----------------------------------------------------------------*/
 /* gen390Code - generate code for Dallas 390 based controllers     */
 /*-----------------------------------------------------------------*/
@@ -10973,7 +11109,8 @@ gen390Code (iCode * lic)
          break;
 
        case SEND:
-         addSet (&_G.sendSet, ic);
+         if (ic->builtinSEND) genBuiltIn(ic);
+         else addSet (&_G.sendSet, ic);
          break;
 
        case ARRAYINIT:
index 6e62d6e391303f5c33c365a16a31c19cdd387ab2..d3215509b982ed6a2c16c6f277e1da480108204e 100644 (file)
@@ -43,7 +43,11 @@ static char *_ds390_keywords[] =
   NULL
 };
 
-
+static builtins __ds390_builtins[] = {
+    { "__builtin_memcpy_x2x","v",3,{"cx*","cx*","i"}}, /* void __builtin_memcpy_x2x (xdata char *,xdata char *,int) */
+    { "__builtin_memcpy_c2x","v",3,{"cx*","cp*","i"}}, /* void __builtin_memcpy_c2x (xdata char *,code  char *,int) */
+    { NULL , NULL,0, {NULL}}                      /* mark end of table */
+};    
 void ds390_assignRegisters (eBBlock ** ebbs, int count);
 
 static int regParmFlg = 0;     /* determine if we can register a parameter */
@@ -120,6 +124,8 @@ _ds390_finaliseOptions (void)
     {
     fprintf (stderr,
             "*** error: ds390 port only supports the 10 bit stack mode.\n");
+    } else {
+       if (!options.stack_loc) options.stack_loc = 0x400000;
     }
     
     /* generate native code 16*16 mul/div */
@@ -323,5 +329,6 @@ PORT ds390_port =
   0,                           /* leave == */
   TRUE,                         /* we support array initializers. */
   cseCostEstimation,
+  __ds390_builtins,             /* table of builtin functions */
   PORT_MAGIC
 };
index 48e73e173edad8294bce5beab624fccc85f7cb6c..9adf61c4fa77af30a5e2c5889ea96bd57f669177 100644 (file)
@@ -2067,6 +2067,8 @@ packRegsDPTRuse (iCode * lic, operand * op, eBBlock * ebp)
     for (; ic && ic->seq <= OP_SYMBOL(op)->liveTo;
         ic = hTabNextItem(iCodeSeqhTab,&key)) {
 
+       if (SKIP_IC3(ic)) continue;
+
        /* if PCALL cannot be sure give up */
        if (ic->op == PCALL) return NULL;
 
index 301807e2f22dab988b6cd0fca2990fb31b49632d..c9e19639228c7cd08ec2921fcf1813d972051e04 100644 (file)
@@ -210,5 +210,6 @@ PORT i186_port = {
     0,  /* leave == */
     FALSE,                        /* No array initializer support. */
     0,                            /* no CSE cost estimation yet */
+    NULL,                      /* no builtin functions */
     PORT_MAGIC
 };
index 2c9cfe0045167652dd67ef252f58fce64bac20cc..3be389c1d29e85608076a1859f6916ac6e8641e6 100644 (file)
@@ -209,5 +209,6 @@ PORT tlcs900h_port =
   0,                           /* leave == */
   FALSE,                        /* No array initializer support. */    
   0,                            /* no CSE cost estimation yet */
+  NULL,                        /* no builtin functions */
   PORT_MAGIC
 };
index f4f5ba706afc4e60e2d569de521d28e1a587ca5c..c21bbd4439cd7e46f2010ac7f9c822fd27e1abb8 100644 (file)
@@ -243,5 +243,6 @@ PORT mcs51_port =
   0,                           /* leave == */
   FALSE,                        /* No array initializer support. */
   cseCostEstimation,
+  NULL,                        /* no builtin functions */
   PORT_MAGIC
 };
index 596f5cb25e8effa3016ddac723ce97f68329aac0..d0cd1a33f00c2e1ad9e36b93b721743caf9a7aee 100644 (file)
@@ -300,5 +300,6 @@ PORT pic_port =
   0,                           /* leave == */
   FALSE,                        /* No array initializer support. */
   0,                            /* no CSE cost estimation yet */
+  NULL,                        /* no builtin functions */
   PORT_MAGIC
 };
index 99abb8db1a54803de3cb15b2c7f505750117bf2d..8622ae90a9291e367df25aa93484fb954b4009c9 100644 (file)
@@ -513,6 +513,7 @@ PORT z80_port =
   0,                           /* leave == */
   TRUE,                         /* Array initializer support. */       
   0,                            /* no CSE cost estimation yet */
+  NULL,                        /* no builtin functions */
   PORT_MAGIC
 };
 
@@ -596,5 +597,6 @@ PORT gbz80_port =
   0,                           /* leave == */
   TRUE,                         /* Array initializer support. */
   0,                            /* no CSE cost estimation yet */
+  NULL,                        /* no builtin functions */
   PORT_MAGIC
 };