disable packRegsForOneuse until I can make it safe
[fw/sdcc] / src / ds390 / gen.c
index c01656fe59777d64a0d14a877ae2fb6039d5c9f0..bc8cd0a2b48ce8bdc6f86bfe8642271aab06538a 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
-#include "SDCCglobl.h"
+
+#include <common.h>
+#include "ralloc.h"
+#include "gen.h"
 
 #ifdef HAVE_SYS_ISA_DEFS_H
 #include <sys/isa_defs.h>
 #endif
 #endif
 
-#include "common.h"
-#include "SDCCpeeph.h"
-#include "ralloc.h"
-#include "gen.h"
-
 char *aopLiteral (value *val, int offset);
+#if 0
+//REMOVE ME!!!
 extern int allocInfo;
+#endif
 
 /* this is the down and dirty file with all kinds of 
    kludgy & hacky stuff. This is what it is all about
@@ -82,10 +83,8 @@ static struct {
     set *sendSet;
 } _G;
 
-extern int ds390_ptrRegReq ;
-extern int ds390_nRegs;
-extern FILE *codeOutFile;
 static void saverbank (int, iCode *,bool);
+
 #define RESULTONSTACK(x) \
                          (IC_RESULT(x) && IC_RESULT(x)->aop && \
                          IC_RESULT(x)->aop->type == AOP_STK )
@@ -241,19 +240,28 @@ static asmop *newAsmop (short type)
     return aop;
 }
 
-/* #define DPS_OPT */ /* turn this on after some more testing. */
+/* Turn this off if the world goes to hell. */
+#define LAZY_DPS_OPT
 
-static int _currentDPS;
-static int _desiredDPS;
-static int _lazyDPS = 0;
+static int _currentDPS;          /* Current processor DPS. */
+static int _desiredDPS;          /* DPS value compiler thinks we should be using. */
+static int _lazyDPS = 0;  /* if non-zero, we are doing lazy evaluation of DPS changes. */
 
+/*-----------------------------------------------------------------*/
+/* genSetDPTR: generate code to select which DPTR is in use (zero  */
+/* selects standard DPTR (DPL/DPH/DPX), non-zero selects DS390            */
+/* alternate DPTR (DPL1/DPH1/DPX1).                               */
+/*-----------------------------------------------------------------*/
 static void genSetDPTR(int n)
 {
-#ifdef DPS_OPT
+
+#ifdef LAZY_DPS_OPT
+    /* If we are doing lazy evaluation, simply note the desired
+     * change, but don't emit any code yet.
+     */
     if (_lazyDPS)
     {
         _desiredDPS = n;
-        /* emitcode(";", "_desiredDPS = %d", n); */
         return;
     }
 #endif
@@ -268,30 +276,43 @@ static void genSetDPTR(int n)
     }
 }
 
-static void _startAopGetLoop(void)
+/*-----------------------------------------------------------------*/
+/* _startLazyDPSEvaluation: call to start doing lazy DPS evaluation*/
+/*                                                                */
+/* Any code that operates on DPTR (NB: not on the individual      */
+/* components, like DPH) *must* call _flushLazyDPS() before using  */
+/* DPTR within a lazy DPS evaluation block.                       */
+/*                                                                */
+/* Note that aopPut and aopGet already contain the proper calls to */
+/* _flushLazyDPS, so it is safe to use these calls within a lazy   */
+/* DPS evaluation block.                                          */
+/*                                                                */
+/* Also, _flushLazyDPS must be called before any flow control     */
+/* operations that could potentially branch out of the block.     */
+/*                                                                */
+/* Lazy DPS evaluation is simply an optimization (though an       */
+/* important one), so if in doubt, leave it out.                  */
+/*-----------------------------------------------------------------*/
+static void _startLazyDPSEvaluation(void)
 {
    _currentDPS = 0;
    _desiredDPS = 0;
    _lazyDPS = 1;
 }
 
-static void _endAopGetLoop(void)
-{
-   _lazyDPS = 0;
-   if (_currentDPS)
-   {
-       genSetDPTR(0);
-   }
-   _currentDPS = 0;
-   _desiredDPS = 0;
-}
-
-static void _aopFlushDPS(void)
+/*-----------------------------------------------------------------*/
+/* _flushLazyDPS: emit code to force the actual DPS setting to the */
+/* desired one. Call before using DPTR within a lazy DPS evaluation*/
+/* block.                                                         */
+/*-----------------------------------------------------------------*/
+static void _flushLazyDPS(void)
 {
     if (!_lazyDPS)
     {
+        /* nothing to do. */
         return;
     }
+    
     if (_desiredDPS != _currentDPS)
     {
        if (_desiredDPS)
@@ -303,10 +324,28 @@ static void _aopFlushDPS(void)
            emitcode("dec", "dps");
        }
        _currentDPS = _desiredDPS;
-       /* emitcode(";", "_currentDPS = _desiredDPS = %d", _currentDPS); */
     }
 }
 
+/*-----------------------------------------------------------------*/
+/* _endLazyDPSEvaluation: end lazy DPS evaluation block.          */
+/*                                                                */
+/* Forces us back to the safe state (standard DPTR selected).     */
+/*-----------------------------------------------------------------*/
+static void _endLazyDPSEvaluation(void)
+{
+   if (_currentDPS)
+   {
+       genSetDPTR(0);
+       _flushLazyDPS();
+   }
+   _lazyDPS = 0;
+   _currentDPS = 0;
+   _desiredDPS = 0;
+}
+
+
+
 /*-----------------------------------------------------------------*/
 /* pointerCode - returns the code for a pointer type               */
 /*-----------------------------------------------------------------*/
@@ -433,7 +472,7 @@ static asmop *aopForSym (iCode *ic,symbol *sym,bool result, bool useDP2)
     if (useDP2)
     {        
         genSetDPTR(1);
-        _aopFlushDPS();
+        _flushLazyDPS();
        emitcode ("mov","dptr,#%s", sym->rname);
         genSetDPTR(0);
     }    
@@ -673,6 +712,15 @@ static void aopOp (operand *op, iCode *ic, bool result, bool useDP2)
 
         if (sym->ruonly ) {
             int i;
+            
+            if (useDP2)
+            {
+                /* a AOP_STR uses DPTR, but DPTR is already in use; 
+                 * we're just hosed.
+                 */
+                fprintf(stderr, "*** Internal error: AOP_STR with DPTR in use!\n");
+            }
+            
             aop = op->aop = sym->aop = newAsmop(AOP_STR);
             aop->size = getSize(sym->type);
             for ( i = 0 ; i < fReturnSize_390 ; i++ )
@@ -860,7 +908,7 @@ static char *aopGet (asmop *aop,
             }
        }
     
-       _aopFlushDPS();
+       _flushLazyDPS();
     
        while (offset > aop->coff) {
            emitcode ("inc","dptr");
@@ -1012,7 +1060,7 @@ static void aopPut (asmop *aop, char *s, int offset)
        {
             genSetDPTR(1);
        }
-       _aopFlushDPS();
+       _flushLazyDPS();
     
        if (aop->code) {
            werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
@@ -1142,32 +1190,6 @@ static void aopPut (asmop *aop, char *s, int offset)
 }
 
 
-#if 0
-/*-----------------------------------------------------------------*/
-/* pointToEnd :- points to the last byte of the operand            */
-/*-----------------------------------------------------------------*/
-static void pointToEnd (asmop *aop)
-{
-    int count ;
-    if (!aop)
-        return ;
-
-    aop->coff = count = (aop->size - 1);
-    switch (aop->type) {
-        case AOP_R0 :
-        case AOP_R1 :
-            while (count--)
-                emitcode("inc","%s",aop->aopu.aop_ptr->name);
-            break;
-        case AOP_DPTR :
-            while (count--)
-                emitcode("inc","dptr");
-            break;
-    }
-
-}
-#endif
-
 /*-----------------------------------------------------------------*/
 /* reAdjustPreg - points a register back to where it should        */
 /*-----------------------------------------------------------------*/
@@ -1190,7 +1212,7 @@ static void reAdjustPreg (asmop *aop)
             if (aop->type == AOP_DPTR2)
            {
                 genSetDPTR(1);
-                _aopFlushDPS();
+                _flushLazyDPS();
            } 
             while (size--)
             {
@@ -1265,7 +1287,7 @@ static void genNotFloat (operand *op, operand *res)
     size = AOP_SIZE(op) - 1;
     offset = 1;
 
-    _startAopGetLoop();
+    _startLazyDPSEvaluation();
     l = aopGet(op->aop,offset++,FALSE,FALSE,TRUE);
     MOVA(l);    
 
@@ -1274,7 +1296,7 @@ static void genNotFloat (operand *op, operand *res)
                  aopGet(op->aop,
                         offset++,FALSE,FALSE,FALSE));
     }
-    _endAopGetLoop();
+    _endLazyDPSEvaluation();
     tlbl = newiTempLabel(NULL);
 
     tlbl = newiTempLabel(NULL);
@@ -1378,7 +1400,7 @@ static void toBoolean(operand *oper)
                size--;
     }
 
-    _startAopGetLoop();
+    _startLazyDPSEvaluation();
     if (AOP_NEEDSACC(oper))
     {
         emitcode("push", "b");
@@ -1399,7 +1421,7 @@ static void toBoolean(operand *oper)
             emitcode("orl","a,%s",aopGet(AOP(oper),offset++,FALSE,FALSE,FALSE));
        }
     }
-    _endAopGetLoop();
+    _endLazyDPSEvaluation();
     
     if (AOP_NEEDSACC(oper))
     {
@@ -1478,14 +1500,14 @@ static void genCpl (iCode *ic)
     } 
 
     size = AOP_SIZE(IC_RESULT(ic));
-    _startAopGetLoop();
+    _startLazyDPSEvaluation();
     while (size--) {
         char *l = aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE,TRUE);
         MOVA(l);       
         emitcode("cpl","a");
         aopPut(AOP(IC_RESULT(ic)),"a",offset++);
     }
-    _endAopGetLoop();
+    _endLazyDPSEvaluation();
 
 
 release:
@@ -1505,7 +1527,7 @@ static void genUminusFloat(operand *op,operand *result)
     first it then copy the rest in place */
     D(emitcode(";", "genUminusFloat"););
     
-    _startAopGetLoop();
+    _startLazyDPSEvaluation();
     size = AOP_SIZE(op) - 1;
     l = aopGet(AOP(op),3,FALSE,FALSE,TRUE);
     MOVA(l);    
@@ -1519,7 +1541,7 @@ static void genUminusFloat(operand *op,operand *result)
                offset);
         offset++;
     }
-    _endAopGetLoop();
+    _endLazyDPSEvaluation();
 }
 
 /*-----------------------------------------------------------------*/
@@ -1560,8 +1582,7 @@ static void genUminus (iCode *ic)
     /* otherwise subtract from zero */
     size = AOP_SIZE(IC_LEFT(ic));
     offset = 0 ;
-    //CLRC ;
-    _startAopGetLoop();
+    _startLazyDPSEvaluation();
     while(size--) {
         char *l = aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE,TRUE);
         if (!strcmp(l,"a")) {
@@ -1577,7 +1598,7 @@ static void genUminus (iCode *ic)
         }       
         aopPut(AOP(IC_RESULT(ic)),"a",offset++);
     }
-    _endAopGetLoop();
+    _endLazyDPSEvaluation();
 
     /* if any remaining bytes in the result */
     /* we just need to propagate the sign   */
@@ -1700,7 +1721,7 @@ static void unsaveRegisters (iCode *ic)
 static void pushSide(operand * oper, int size)
 {
        int offset = 0;
-       _startAopGetLoop();
+       _startLazyDPSEvaluation();
        while (size--) {
                char *l = aopGet(AOP(oper),offset++,FALSE,TRUE,FALSE);
                if (AOP_TYPE(oper) != AOP_REG &&
@@ -1711,7 +1732,7 @@ static void pushSide(operand * oper, int size)
                } else
                        emitcode("push","%s",l);
        }
-       _endAopGetLoop();
+       _endLazyDPSEvaluation();
 }
 
 /*-----------------------------------------------------------------*/
@@ -1721,10 +1742,13 @@ static void assignResultValue(operand * oper)
 {
        int offset = 0;
        int size = AOP_SIZE(oper);
+       
+       _startLazyDPSEvaluation();
        while (size--) {
                aopPut(AOP(oper),fReturn[offset],offset);
                offset++;
        }
+       _endLazyDPSEvaluation();
 }
 
 
@@ -1746,7 +1770,7 @@ static void genXpush (iCode *ic)
     emitcode("mov","%s,_spx",r->name);
 
     size = AOP_SIZE(IC_LEFT(ic));
-    _startAopGetLoop();
+    _startLazyDPSEvaluation();
     while(size--) {
 
        char *l = aopGet(AOP(IC_LEFT(ic)),
@@ -1756,7 +1780,7 @@ static void genXpush (iCode *ic)
        emitcode("inc","%s",r->name);
 
     }
-    _endAopGetLoop();
+    _endLazyDPSEvaluation();
 
        
     emitcode("mov","_spx,%s",r->name);
@@ -1787,7 +1811,7 @@ static void genIpush (iCode *ic)
         aopOp(IC_LEFT(ic),ic,FALSE, FALSE);
         size = AOP_SIZE(IC_LEFT(ic));
         /* push it on the stack */
-        _startAopGetLoop();
+        _startLazyDPSEvaluation();
         while(size--) {
             l = aopGet(AOP(IC_LEFT(ic)),offset++,FALSE,TRUE,TRUE);
             if (*l == '#') {
@@ -1796,7 +1820,7 @@ static void genIpush (iCode *ic)
             }
             emitcode("push","%s",l);
         }
-        _endAopGetLoop();
+        _endLazyDPSEvaluation();
         return ;        
     }
 
@@ -1815,11 +1839,10 @@ static void genIpush (iCode *ic)
     /* then do the push */
     aopOp(IC_LEFT(ic),ic,FALSE, FALSE);
 
-
-       // pushSide(IC_LEFT(ic), AOP_SIZE(IC_LEFT(ic)));
+    // pushSide(IC_LEFT(ic), AOP_SIZE(IC_LEFT(ic)));
     size = AOP_SIZE(IC_LEFT(ic));
 
-    _startAopGetLoop();
+    _startLazyDPSEvaluation();
     while (size--) {
         l = aopGet(AOP(IC_LEFT(ic)),offset++,FALSE,TRUE,FALSE);
         if (AOP_TYPE(IC_LEFT(ic)) != AOP_REG && 
@@ -1830,7 +1853,7 @@ static void genIpush (iCode *ic)
         } else
             emitcode("push","%s",l);
     }
-    _endAopGetLoop();
+    _endLazyDPSEvaluation();
 
     freeAsmop(IC_LEFT(ic),NULL,ic,TRUE);
 }
@@ -1852,13 +1875,13 @@ static void genIpop (iCode *ic)
     aopOp(IC_LEFT(ic),ic,FALSE, FALSE);
     size = AOP_SIZE(IC_LEFT(ic));
     offset = (size-1);
-    _startAopGetLoop();
+    _startLazyDPSEvaluation();
     while (size--)
     {
         emitcode("pop","%s",aopGet(AOP(IC_LEFT(ic)),offset--,
                                    FALSE,TRUE,TRUE));
     }
-    _endAopGetLoop();
+    _endLazyDPSEvaluation();
 
     freeAsmop(IC_LEFT(ic),NULL,ic,TRUE);
 }
@@ -1988,7 +2011,7 @@ static void genCall (iCode *ic)
             aopOp(IC_LEFT(sic),sic,FALSE, TRUE);
            size = AOP_SIZE(IC_LEFT(sic));
            
-           _startAopGetLoop();
+           _startLazyDPSEvaluation();
            while (size--) {
                char *l = aopGet(AOP(IC_LEFT(sic)),offset,
                                FALSE, FALSE, TRUE);
@@ -1998,7 +2021,7 @@ static void genCall (iCode *ic)
                             l);
                offset++;
            }
-           _endAopGetLoop();
+           _endLazyDPSEvaluation();
            freeAsmop (IC_LEFT(sic),NULL,sic,TRUE);
        }
        _G.sendSet = NULL;
@@ -2014,16 +2037,57 @@ static void genCall (iCode *ic)
           OP_SYMBOL(IC_RESULT(ic))->spildir )) ||
         IS_TRUE_SYMOP(IC_RESULT(ic)) ) {
 
+#ifdef LAZY_DPS_OPT
+       /* Not really related to LAZY_DPS_OPT, but don't want
+        * another testing flag right now...
+        */
+#define FAR_RETURN_OPT
+#ifdef FAR_RETURN_OPT   
+       if (isOperandInFarSpace(IC_RESULT(ic))
+        && getSize(operandType(IC_RESULT(ic))) <= 2)
+       {
+           int size =  getSize(operandType(IC_RESULT(ic)));
+           
+            /* Special case for 1 or 2 byte return in far space. */
+           emitcode(";", "Kevin function call abuse #1");
+
+           MOVA(fReturn[0]);
+           if (size > 1)
+           {
+               emitcode("mov", "b,%s", fReturn[1]);
+           }
+    
+           aopOp(IC_RESULT(ic),ic,FALSE, FALSE);
+           aopPut(AOP(IC_RESULT(ic)),"a",0);
+           
+           if (size > 1)
+           {
+               aopPut(AOP(IC_RESULT(ic)),"b",1);
+           }
+           freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);           
+       }
+       else
+#endif 
+       {
+            _G.accInUse++;
+            aopOp(IC_RESULT(ic),ic,FALSE, TRUE);
+            _G.accInUse--;
+                                     
+            assignResultValue(IC_RESULT(ic));
+                                                  
+            freeAsmop(IC_RESULT(ic),NULL, ic,TRUE);
+        }
+#else
        if (!isOperandInFarSpace(IC_RESULT(ic)))
        {
-        _G.accInUse++;
+            _G.accInUse++;
             aopOp(IC_RESULT(ic),ic,FALSE, FALSE);
-        _G.accInUse--;
+            _G.accInUse--;
 
-       assignResultValue(IC_RESULT(ic));
+           assignResultValue(IC_RESULT(ic));
                
-        freeAsmop(IC_RESULT(ic),NULL, ic,TRUE);
-    }
+            freeAsmop(IC_RESULT(ic),NULL, ic,TRUE);
+       }
         else
         {
             /* Result is in far space, and requires DPTR to access
@@ -2056,7 +2120,8 @@ static void genCall (iCode *ic)
                aopPut(AOP(IC_RESULT(ic)),"a",++offset);
            }
            freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
-        }
+       }
+#endif 
     }
 
     /* adjust the stack for parameters if 
@@ -2139,7 +2204,7 @@ static void genPcall (iCode *ic)
            
                aopOp(IC_LEFT(sic),sic,FALSE, FALSE);
                size = AOP_SIZE(IC_LEFT(sic));
-               _startAopGetLoop();
+               _startLazyDPSEvaluation();
                while (size--) 
                {
                        char *l = aopGet(AOP(IC_LEFT(sic)),offset,
@@ -2152,7 +2217,7 @@ static void genPcall (iCode *ic)
                        }
                        offset++;
                }
-               _endAopGetLoop();
+               _endLazyDPSEvaluation();
                freeAsmop (IC_LEFT(sic),NULL,sic,TRUE);
            }
            _G.sendSet = NULL;
@@ -2582,7 +2647,7 @@ static void genRet (iCode *ic)
     aopOp(IC_LEFT(ic),ic,FALSE, TRUE);
     size = AOP_SIZE(IC_LEFT(ic));
     
-    _startAopGetLoop();
+    _startLazyDPSEvaluation();
     while (size--) {
            char *l ;
            if (AOP_TYPE(IC_LEFT(ic)) == AOP_DPTR) {
@@ -2597,7 +2662,7 @@ static void genRet (iCode *ic)
                            emitcode("mov","%s,%s",fReturn[offset++],l);
            }
     }
-    _endAopGetLoop();    
+    _endLazyDPSEvaluation();    
 
     if (pushed) {
        while(pushed) {
@@ -2784,12 +2849,12 @@ static bool genPlusIncr (iCode *ic)
             aopPut(AOP(IC_RESULT(ic)),"a",0);
         } else {
            
-           _startAopGetLoop();
+           _startLazyDPSEvaluation();
             while (icount--) 
             {
                 emitcode ("inc","%s",aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE,FALSE));
             }
-            _endAopGetLoop();
+            _endLazyDPSEvaluation();
         }
        
         return TRUE ;
@@ -2901,8 +2966,14 @@ static void genPlus (iCode *ic)
 
     /* special cases :- */
 
+#ifdef LAZY_DPS_OPT
+    aopOp (IC_RIGHT(ic),ic,FALSE, FALSE);
+    aopOp (IC_LEFT(ic),ic,FALSE, 
+          (AOP_TYPE(IC_RIGHT(ic)) == AOP_DPTR));
+#else    
     aopOp (IC_LEFT(ic),ic,FALSE, TRUE);
     aopOp (IC_RIGHT(ic),ic,FALSE, FALSE);
+#endif    
     if ((AOP_TYPE(IC_LEFT(ic)) == AOP_DPTR2) &&
         (AOP_TYPE(IC_RIGHT(ic)) == AOP_DPTR))
     {
@@ -2910,7 +2981,9 @@ static void genPlus (iCode *ic)
     }
     else
     {
-        aopOp (IC_RESULT(ic),ic,TRUE, AOP_TYPE(IC_RIGHT(ic)) == AOP_DPTR);
+        aopOp (IC_RESULT(ic),ic,TRUE, 
+               ((AOP_TYPE(IC_RIGHT(ic)) == AOP_DPTR)
+             || (AOP_TYPE(IC_LEFT(ic)) == AOP_DPTR)));
 
     /* if literal, literal on the right or
        if left requires ACC or right is already
@@ -2942,13 +3015,13 @@ static void genPlus (iCode *ic)
             outBitC(IC_RESULT(ic));
         } else {
             size = getDataSize(IC_RESULT(ic));
-            _startAopGetLoop();
+            _startLazyDPSEvaluation();
             while (size--) {
                 MOVA(aopGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE,TRUE));
                 emitcode("addc","a,#00");
                 aopPut(AOP(IC_RESULT(ic)),"a",offset++);
             }
-            _endAopGetLoop();
+            _endLazyDPSEvaluation();
         }
         goto release ;
     }
@@ -2961,7 +3034,7 @@ static void genPlus (iCode *ic)
     }
     size = getDataSize(pushResult ? IC_LEFT(ic) : IC_RESULT(ic));
 
-    _startAopGetLoop();
+    _startLazyDPSEvaluation();
     while(size--)
     {
        if (AOP_TYPE(IC_LEFT(ic)) == AOP_ACC) 
@@ -2992,7 +3065,7 @@ static void genPlus (iCode *ic)
         }
         offset++;
     }
-    _endAopGetLoop();
+    _endLazyDPSEvaluation();
    
     if (pushResult)
     {
@@ -3027,11 +3100,13 @@ static void genPlus (iCode *ic)
            }
        }
 
+       _startLazyDPSEvaluation();
         while(size--)
         {
             emitcode("pop", "acc");
             aopPut(AOP(IC_RESULT(ic)), "a", --offset);
         }
+        _endLazyDPSEvaluation();
     }
 
     adjustArithmeticResult(ic);
@@ -3153,12 +3228,12 @@ static bool genMinusDec (iCode *ic)
         AOP_TYPE(IC_RESULT(ic)) == AOP_REG &&
         sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic)))) {
 
-       _startAopGetLoop();
+       _startLazyDPSEvaluation();
         while (icount--) 
         {
             emitcode ("dec","%s",aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE,FALSE));
         }
-        _endAopGetLoop();
+        _endLazyDPSEvaluation();
 
         return TRUE ;
     }
@@ -3261,7 +3336,7 @@ static void genMinus (iCode *ic)
 
 
     /* if literal, add a,#-lit, else normal subb */
-    _startAopGetLoop();
+    _startLazyDPSEvaluation();
     while (size--) {
         MOVA(aopGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE,TRUE));
         if (AOP_TYPE(IC_RIGHT(ic)) != AOP_LIT)  
@@ -3287,7 +3362,7 @@ static void genMinus (iCode *ic)
         }
         offset++;
     }
-    _endAopGetLoop();
+    _endLazyDPSEvaluation();
 
     if (pushResult)
     {
@@ -4679,11 +4754,11 @@ static void genOr (iCode *ic, iCode *ifx)
 
     AOP_OP_3(ic);
     AOP_SET_LOCALS(ic);
-    #if 0
+#if 0
     aopOp((left = IC_LEFT(ic)),ic,FALSE, FALSE);
     aopOp((right= IC_RIGHT(ic)),ic,FALSE, TRUE);
     aopOp((result=IC_RESULT(ic)),ic,TRUE, FALSE);
-    #endif
+#endif
 
 #ifdef DEBUG_TYPE
     emitcode("","; Type res[%d] = l[%d]&r[%d]",
@@ -5162,7 +5237,7 @@ static void genRRC (iCode *ic)
     offset = size - 1 ;
     CLRC;
     
-    _startAopGetLoop();
+    _startLazyDPSEvaluation();
     while (size--) {
         l = aopGet(AOP(left),offset,FALSE,FALSE,TRUE);
         MOVA(l);
@@ -5170,7 +5245,7 @@ static void genRRC (iCode *ic)
         if (AOP_SIZE(result) > 1)
             aopPut(AOP(result),"a",offset--);
     }
-    _endAopGetLoop();
+    _endLazyDPSEvaluation();
     
     /* now we need to put the carry into the
     highest order byte of the result */
@@ -5213,7 +5288,7 @@ static void genRLC (iCode *ic)
             aopPut(AOP(result),"a",offset++);
         }
             
-        _startAopGetLoop();
+        _startLazyDPSEvaluation();
         while (size--) {
             l = aopGet(AOP(left),offset,FALSE,FALSE,TRUE);
             MOVA(l);
@@ -5221,7 +5296,7 @@ static void genRLC (iCode *ic)
             if (AOP_SIZE(result) > 1)
                 aopPut(AOP(result),"a",offset++);
         }
-        _endAopGetLoop();
+        _endLazyDPSEvaluation();
     }
     /* now we need to put the carry into the
     highest order byte of the result */
@@ -5341,6 +5416,8 @@ static void AccRsh (int shCount)
     }
 }
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* AccSRsh - signed right shift accumulator by known count                 */
 /*-----------------------------------------------------------------*/
@@ -5369,7 +5446,10 @@ static void AccSRsh (int shCount)
         }
     }
 }
+#endif
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* shiftR1Left2Result - shift right one byte from left to result   */
 /*-----------------------------------------------------------------*/
@@ -5385,7 +5465,10 @@ static void shiftR1Left2Result (operand *left, int offl,
         AccRsh(shCount);
     aopPut(AOP(result),"a",offr);
 }
+#endif
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* shiftL1Left2Result - shift left one byte from left to result    */
 /*-----------------------------------------------------------------*/
@@ -5399,7 +5482,10 @@ static void shiftL1Left2Result (operand *left, int offl,
     AccLsh(shCount);
     aopPut(AOP(result),"a",offr);
 }
+#endif
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* movLeft2Result - move byte from left to result                  */
 /*-----------------------------------------------------------------*/
@@ -5426,7 +5512,10 @@ static void movLeft2Result (operand *left, int offl,
         }
     }
 }
+#endif
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* AccAXRrl1 - right rotate c->a:x->c by 1                         */
 /*-----------------------------------------------------------------*/
@@ -5437,7 +5526,10 @@ static void AccAXRrl1 (char *x)
     emitcode("rrc","a");
     emitcode("xch","a,%s", x);
 }
+#endif
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* AccAXLrl1 - left rotate c<-a:x<-c by 1                          */
 /*-----------------------------------------------------------------*/
@@ -5448,7 +5540,10 @@ static void AccAXLrl1 (char *x)
     emitcode("xch","a,%s",x);
     emitcode("rlc","a");
 }
+#endif
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* AccAXLsh1 - left shift a:x<-0 by 1                              */
 /*-----------------------------------------------------------------*/
@@ -5459,7 +5554,10 @@ static void AccAXLsh1 (char *x)
     emitcode("xch","a,%s",x);
     emitcode("rlc","a");
 }
+#endif
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* AccAXLsh - left shift a:x by known count (0..7)                 */
 /*-----------------------------------------------------------------*/
@@ -5510,7 +5608,10 @@ static void AccAXLsh (char *x, int shCount)
             break;
     }
 }
+#endif
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* AccAXRsh - right shift a:x known count (0..7)                   */
 /*-----------------------------------------------------------------*/
@@ -5564,7 +5665,10 @@ static void AccAXRsh (char *x, int shCount)
             break;
     }
 }
+#endif
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* AccAXRshS - right shift signed a:x known count (0..7)           */
 /*-----------------------------------------------------------------*/
@@ -5634,7 +5738,10 @@ static void AccAXRshS (char *x, int shCount)
             break;
     }
 }
+#endif
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* shiftL2Left2Result - shift left two bytes from left to result   */
 /*-----------------------------------------------------------------*/
@@ -5654,8 +5761,10 @@ static void shiftL2Left2Result (operand *left, int offl,
     AccAXLsh( aopGet(AOP(result),offr,FALSE,FALSE,FALSE), shCount);
     aopPut(AOP(result),"a",offr+MSB16);
 }
+#endif
 
-
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* shiftR2Left2Result - shift right two bytes from left to result  */
 /*-----------------------------------------------------------------*/
@@ -5680,7 +5789,10 @@ static void shiftR2Left2Result (operand *left, int offl,
     if(getDataSize(result) > 1)
         aopPut(AOP(result),"a",offr+MSB16);
 }
+#endif
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* shiftLLeftOrResult - shift left one byte from left, or to result*/
 /*-----------------------------------------------------------------*/
@@ -5695,7 +5807,10 @@ static void shiftLLeftOrResult (operand *left, int offl,
     /* back to result */
     aopPut(AOP(result),"a",offr);
 }
+#endif
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* shiftRLeftOrResult - shift right one byte from left,or to result*/
 /*-----------------------------------------------------------------*/
@@ -5710,7 +5825,10 @@ static void shiftRLeftOrResult (operand *left, int offl,
     /* back to result */
     aopPut(AOP(result),"a",offr);
 }
+#endif
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* genlshOne - left shift a one byte quantity by known count       */
 /*-----------------------------------------------------------------*/
@@ -5719,7 +5837,10 @@ static void genlshOne (operand *result, operand *left, int shCount)
     D(emitcode(";", "genlshOne "););
     shiftL1Left2Result(left, LSB, result, LSB, shCount);
 }
+#endif
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* genlshTwo - left shift two bytes by known amount != 0           */
 /*-----------------------------------------------------------------*/
@@ -5752,7 +5873,10 @@ static void genlshTwo (operand *result,operand *left, int shCount)
             shiftL2Left2Result(left, LSB, result, LSB, shCount);
     }
 }
+#endif
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* shiftLLong - shift left one long from left to result            */
 /* offl = LSB or MSB16                                             */
@@ -5813,7 +5937,10 @@ static void shiftLLong (operand *left, operand *result, int offr )
     if(offr != LSB)
         aopPut(AOP(result),zero,LSB);       
 }
+#endif
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* genlshFour - shift four byte by a known amount != 0             */
 /*-----------------------------------------------------------------*/
@@ -5897,7 +6024,10 @@ static void genlshFour (operand *result, operand *left, int shCount)
         shiftL2Left2Result(left, LSB, result, LSB, shCount);
     }
 }
+#endif
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* genLeftShiftLiteral - left shifting by known count              */
 /*-----------------------------------------------------------------*/
@@ -5952,6 +6082,7 @@ static void genLeftShiftLiteral (operand *left,
     freeAsmop(left,NULL,ic,TRUE);
     freeAsmop(result,NULL,ic,TRUE);
 }
+#endif
 
 /*-----------------------------------------------------------------*/
 /* genLeftShift - generates code for left shifting                 */
@@ -5971,14 +6102,14 @@ static void genLeftShift (iCode *ic)
 
     aopOp(right,ic,FALSE, FALSE);
 
-    #if 0
+#if 0
     /* 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 ;
     }
-    #endif
+#endif
 
     /* shift count is unknown then we have to form 
     a loop get the loop count in B : Note: we take
@@ -5999,7 +6130,7 @@ static void genLeftShift (iCode *ic)
 
         size = AOP_SIZE(result);
         offset=0;
-        _startAopGetLoop();
+        _startLazyDPSEvaluation();
         while (size--) {
             l = aopGet(AOP(left),offset,FALSE,TRUE,FALSE);
             if (*l == '@' && (IS_AOP_PREG(result))) {
@@ -6010,7 +6141,7 @@ static void genLeftShift (iCode *ic)
                 aopPut(AOP(result),l,offset);
             offset++;
         }
-        _endAopGetLoop();
+        _endLazyDPSEvaluation();
     }
 
     tlbl = newiTempLabel(NULL);
@@ -6041,14 +6172,14 @@ static void genLeftShift (iCode *ic)
     MOVA(l);
     emitcode("add","a,acc");         
     aopPut(AOP(result),"a",offset++);
-    _startAopGetLoop();
+    _startLazyDPSEvaluation();
     while (--size) {
         l = aopGet(AOP(result),offset,FALSE,FALSE,TRUE);
         MOVA(l);
         emitcode("rlc","a");         
         aopPut(AOP(result),"a",offset++);
     }
-    _endAopGetLoop();
+    _endLazyDPSEvaluation();
     reAdjustPreg(AOP(result));
 
     emitcode("","%05d$:",tlbl1->key+100);
@@ -6058,6 +6189,8 @@ release:
     freeAsmop(result,NULL,ic,TRUE);
 }
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* genrshOne - right shift a one byte quantity by known count      */
 /*-----------------------------------------------------------------*/
@@ -6067,7 +6200,10 @@ static void genrshOne (operand *result, operand *left,
     D(emitcode(";", "genrshOne"););
     shiftR1Left2Result(left, LSB, result, LSB, shCount, sign);
 }
+#endif
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* genrshTwo - right shift two bytes by known amount != 0          */
 /*-----------------------------------------------------------------*/
@@ -6091,7 +6227,10 @@ static void genrshTwo (operand *result,operand *left,
     else
         shiftR2Left2Result(left, LSB, result, LSB, shCount, sign); 
 }
+#endif
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* shiftRLong - shift right one long from left to result           */
 /* offl = LSB or MSB16                                             */
@@ -6124,7 +6263,10 @@ static void shiftRLong (operand *left, int offl,
         aopPut(AOP(result),"a",LSB);
     }
 }
+#endif
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* genrshFour - shift four byte by a known amount != 0             */
 /*-----------------------------------------------------------------*/
@@ -6183,7 +6325,10 @@ static void genrshFour (operand *result, operand *left,
         }
     }
 }
+#endif
 
+#if 0
+//REMOVE ME!!!
 /*-----------------------------------------------------------------*/
 /* genRightShiftLiteral - right shifting by known count            */
 /*-----------------------------------------------------------------*/
@@ -6244,6 +6389,7 @@ static void genRightShiftLiteral (operand *left,
         freeAsmop(result,NULL,ic,TRUE);
     }
 }
+#endif
 
 /*-----------------------------------------------------------------*/
 /* genSignedRightShift - right shift of signed number              */
@@ -6266,13 +6412,13 @@ static void genSignedRightShift (iCode *ic)
 
     aopOp(right,ic,FALSE, FALSE);
 
-    #if 0
+#if 0
     if ( AOP_TYPE(right) == AOP_LIT) {
        genRightShiftLiteral (left,right,result,ic,1);
        return ;
     }
-    #endif
-        /* shift count is unknown then we have to form 
+#endif
+    /* 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
@@ -6291,7 +6437,7 @@ static void genSignedRightShift (iCode *ic)
 
         size = AOP_SIZE(result);
         offset=0;
-        _startAopGetLoop();
+        _startLazyDPSEvaluation();
         while (size--) {
             l = aopGet(AOP(left),offset,FALSE,TRUE,FALSE);
             if (*l == '@' && IS_AOP_PREG(result)) {
@@ -6302,7 +6448,7 @@ static void genSignedRightShift (iCode *ic)
                 aopPut(AOP(result),l,offset);
             offset++;
         }
-        _endAopGetLoop();
+        _endLazyDPSEvaluation();
     }
 
     /* mov the highest order bit to OVR */    
@@ -6332,14 +6478,14 @@ static void genSignedRightShift (iCode *ic)
     emitcode("sjmp","%05d$",tlbl1->key+100);
     emitcode("","%05d$:",tlbl->key+100);    
     emitcode("mov","c,ov");
-    _startAopGetLoop();
+    _startLazyDPSEvaluation();
     while (size--) {
         l = aopGet(AOP(result),offset,FALSE,FALSE,TRUE);
         MOVA(l);
         emitcode("rrc","a");         
         aopPut(AOP(result),"a",offset--);
     }
-    _endAopGetLoop();
+    _endLazyDPSEvaluation();
     reAdjustPreg(AOP(result));
     emitcode("","%05d$:",tlbl1->key+100);
     emitcode("djnz","b,%05d$",tlbl->key+100);
@@ -6384,14 +6530,14 @@ static void genRightShift (iCode *ic)
 
     aopOp(right,ic,FALSE, FALSE);
 
-    #if 0
+#if 0
     /* if the shift count is known then do it 
     as efficiently as possible */
     if (AOP_TYPE(right) == AOP_LIT) {
         genRightShiftLiteral (left,right,result,ic, 0);
         return ;
     }
-    #endif
+#endif
 
     /* shift count is unknown then we have to form 
     a loop get the loop count in B : Note: we take
@@ -6412,7 +6558,7 @@ static void genRightShift (iCode *ic)
 
         size = AOP_SIZE(result);
         offset=0;
-        _startAopGetLoop();
+        _startLazyDPSEvaluation();
         while (size--) {
             l = aopGet(AOP(left),offset,FALSE,TRUE,FALSE);
             if (*l == '@' && IS_AOP_PREG(result)) {
@@ -6423,7 +6569,7 @@ static void genRightShift (iCode *ic)
                 aopPut(AOP(result),l,offset);
             offset++;
         }
-        _endAopGetLoop();
+        _endLazyDPSEvaluation();
     }
 
     tlbl = newiTempLabel(NULL);
@@ -6449,14 +6595,14 @@ static void genRightShift (iCode *ic)
     emitcode("sjmp","%05d$",tlbl1->key+100);
     emitcode("","%05d$:",tlbl->key+100);    
     CLRC;
-    _startAopGetLoop();
+    _startLazyDPSEvaluation();
     while (size--) {
         l = aopGet(AOP(result),offset,FALSE,FALSE,TRUE);
         MOVA(l);
         emitcode("rrc","a");         
         aopPut(AOP(result),"a",offset--);
     }
-    _endAopGetLoop();
+    _endLazyDPSEvaluation();
     reAdjustPreg(AOP(result));
 
     emitcode("","%05d$:",tlbl1->key+100);
@@ -6590,7 +6736,7 @@ static void genDataPointerGet (operand *left,
     /* get the string representation of the name */
     l = aopGet(AOP(left),0,FALSE,TRUE,FALSE);
     size = AOP_SIZE(result);
-    _startAopGetLoop();
+    _startLazyDPSEvaluation();
     while (size--) {
        if (offset)
            sprintf(buffer,"(%s + %d)",l+1,offset);
@@ -6598,7 +6744,7 @@ static void genDataPointerGet (operand *left,
            sprintf(buffer,"%s",l+1);
        aopPut(AOP(result),buffer,offset++);
     }
-    _endAopGetLoop();
+    _endLazyDPSEvaluation();
 
     freeAsmop(left,NULL,ic,TRUE);
     freeAsmop(result,NULL,ic,TRUE);
@@ -6801,7 +6947,7 @@ static void genFarPointerGet (operand *left,
         else 
         { 
             /* we need to get it byte by byte */
-            _startAopGetLoop();
+            _startLazyDPSEvaluation();
            if (AOP_TYPE(left) != AOP_DPTR)
            {
                emitcode("mov","dpl,%s",aopGet(AOP(left),0,FALSE,FALSE,TRUE));
@@ -6818,7 +6964,7 @@ static void genFarPointerGet (operand *left,
                  emitcode("pop", "dph");
                  emitcode("pop", "dpl");
             }
-            _endAopGetLoop();
+            _endLazyDPSEvaluation();
         }
     }
     /* so dptr know contains the address */
@@ -6832,12 +6978,19 @@ static void genFarPointerGet (operand *left,
         size = AOP_SIZE(result);
         offset = 0 ;
 
+       _startLazyDPSEvaluation();
         while (size--) {
+            
+            genSetDPTR(0);
+            _flushLazyDPS();
+            
             emitcode("movx","a,@dptr");
-            aopPut(AOP(result),"a",offset++);
             if (size)
-                emitcode("inc","dptr");
+                emitcode("inc","dptr");            
+
+            aopPut(AOP(result),"a",offset++);
         }
+        _endLazyDPSEvaluation();
     }
 
     freeAsmop(result,NULL,ic,TRUE);
@@ -6861,16 +7014,16 @@ static void emitcodePointerGet (operand *left,
         if (AOP_TYPE(left) == AOP_IMMD)
             emitcode("mov","dptr,%s",aopGet(AOP(left),0,TRUE,FALSE,FALSE));
         else { /* we need to get it byte by byte */
-            _startAopGetLoop();
+            _startLazyDPSEvaluation();
             emitcode("mov","dpl,%s",aopGet(AOP(left),0,FALSE,FALSE,TRUE));
             emitcode("mov","dph,%s",aopGet(AOP(left),1,FALSE,FALSE,TRUE));
             emitcode("mov","dpx,%s",aopGet(AOP(left),2,FALSE,FALSE,TRUE));
-            _endAopGetLoop();
+            _endLazyDPSEvaluation();
         }
     }
     /* so dptr know contains the address */
     freeAsmop(left,NULL,ic,TRUE);
-    aopOp(result,ic,FALSE, FALSE);
+    aopOp(result,ic,FALSE, TRUE);
 
     /* if bit then unpack */
     if (IS_BITVAR(retype)) 
@@ -6879,13 +7032,19 @@ static void emitcodePointerGet (operand *left,
         size = AOP_SIZE(result);
         offset = 0 ;
 
-        while (size--) {
+       _startLazyDPSEvaluation();
+        while (size--) 
+        {
+            genSetDPTR(0);
+            _flushLazyDPS();
+                              
             emitcode("clr","a");
             emitcode("movc","a,@a+dptr");
-            aopPut(AOP(result),"a",offset++);
             if (size)
-                emitcode("inc","dptr");
+                emitcode("inc","dptr");            
+            aopPut(AOP(result),"a",offset++);
         }
+        _endLazyDPSEvaluation();
     }
 
     freeAsmop(result,NULL,ic,TRUE);
@@ -6911,7 +7070,7 @@ static void genGenPointerGet (operand *left,
            emitcode("mov","b,#%d",pointerCode(retype));
        }
         else { /* we need to get it byte by byte */
-            _startAopGetLoop();
+            _startLazyDPSEvaluation();
             emitcode("mov","dpl,%s",aopGet(AOP(left),0,FALSE,FALSE,TRUE));
             emitcode("mov","dph,%s",aopGet(AOP(left),1,FALSE,FALSE,TRUE));
             if (options.model == MODEL_FLAT24)
@@ -6923,7 +7082,7 @@ static void genGenPointerGet (operand *left,
             {
                emitcode("mov","b,%s",aopGet(AOP(left),2,FALSE,FALSE,TRUE));
             }
-            _endAopGetLoop();
+            _endLazyDPSEvaluation();
         }
     }
     /* so dptr know contains the address */
@@ -7388,7 +7547,7 @@ static void genFarPointerSet (operand *right,
         else 
         {
             /* we need to get it byte by byte */
-            _startAopGetLoop();
+            _startLazyDPSEvaluation();
            if (AOP_TYPE(result) != AOP_DPTR)
            {
                emitcode("mov","dpl,%s",aopGet(AOP(result),0,FALSE,FALSE,TRUE));
@@ -7405,7 +7564,7 @@ static void genFarPointerSet (operand *right,
                  emitcode("pop", "dph");
                  emitcode("pop", "dpl");
             }
-            _endAopGetLoop();
+            _endLazyDPSEvaluation();
         }
     }
     /* so dptr know contains the address */
@@ -7419,15 +7578,19 @@ static void genFarPointerSet (operand *right,
         size = AOP_SIZE(right);
         offset = 0 ;
 
-       _startAopGetLoop();
+       _startLazyDPSEvaluation();
         while (size--) {
             char *l = aopGet(AOP(right),offset++,FALSE,FALSE,TRUE);
             MOVA(l);
+            
+            genSetDPTR(0);
+            _flushLazyDPS();
+            
             emitcode("movx","@dptr,a");
             if (size)
                 emitcode("inc","dptr");
         }
-        _endAopGetLoop();
+        _endLazyDPSEvaluation();
     }
 
     freeAsmop(right,NULL,ic,TRUE);
@@ -7447,7 +7610,7 @@ static void genGenPointerSet (operand *right,
     /* if the operand is already in dptr 
     then we do nothing else we move the value to dptr */
     if (AOP_TYPE(result) != AOP_STR) {
-       _startAopGetLoop();
+       _startLazyDPSEvaluation();
         /* if this is remateriazable */
         if (AOP_TYPE(result) == AOP_IMMD) {
             emitcode("mov","dptr,%s",aopGet(AOP(result),0,TRUE,FALSE,FALSE));
@@ -7459,7 +7622,7 @@ static void genGenPointerSet (operand *right,
             emitcode("mov","dpx,%s",aopGet(AOP(result),2,FALSE,FALSE,TRUE));
             emitcode("mov","b,%s",aopGet(AOP(result),3,FALSE,FALSE,TRUE));
         }
-        _endAopGetLoop();
+        _endLazyDPSEvaluation();
     }
     /* so dptr know contains the address */
     freeAsmop(result,NULL,ic,TRUE);
@@ -7472,13 +7635,19 @@ static void genGenPointerSet (operand *right,
         size = AOP_SIZE(right);
         offset = 0 ;
 
+       _startLazyDPSEvaluation();
         while (size--) {
             char *l = aopGet(AOP(right),offset++,FALSE,FALSE,TRUE);
             MOVA(l);
+            
+            genSetDPTR(0);
+            _flushLazyDPS();
+            
             emitcode("lcall","__gptrput");
             if (size)
                 emitcode("inc","dptr");
         }
+        _endLazyDPSEvaluation();
     }
 
     freeAsmop(right,NULL,ic,TRUE);
@@ -7667,12 +7836,37 @@ static void genFarFarAssign (operand *result, operand *right, iCode *ic)
 {
     int size = AOP_SIZE(right);
     int offset = 0;
-    char *l ;
+    char *l;
+
+#ifdef LAZY_DPS_OPT
+    if (size > 1)
+    {
+       /* This is a net loss for size == 1, but a big gain
+        * otherwise.
+        */
+       D(emitcode(";", "genFarFarAssign (improved)"););
 
+       aopOp(result,ic,TRUE, TRUE);
+
+       _startLazyDPSEvaluation();
+       while (size--) 
+       {
+           aopPut(AOP(result),
+                  aopGet(AOP(right),offset,FALSE,FALSE,FALSE),
+                  offset);
+           offset++;
+       }
+       _endLazyDPSEvaluation();    
+       freeAsmop(result,NULL,ic,FALSE);
+       freeAsmop(right,NULL,ic,FALSE);
+    }
+    else
+#endif
+    {
     D(emitcode(";", "genFarFarAssign "););
 
     /* first push the right side on to the stack */
-    _startAopGetLoop();
+    _startLazyDPSEvaluation();
     while (size--) {
        l = aopGet(AOP(right),offset++,FALSE,FALSE,TRUE);
        MOVA(l);
@@ -7688,8 +7882,8 @@ static void genFarFarAssign (operand *result, operand *right, iCode *ic)
        aopPut(AOP(result),"a",--offset);
     }
     freeAsmop(result,NULL,ic,FALSE);
-    _endAopGetLoop();
-       
+    _endLazyDPSEvaluation();
+    }
 }
 
 /*-----------------------------------------------------------------*/
@@ -7764,14 +7958,41 @@ static void genAssign (iCode *ic)
     offset = 0 ;
     if(AOP_TYPE(right) == AOP_LIT)
        lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);
+    
     if((size > 1) &&
        (AOP_TYPE(result) != AOP_REG) &&
        (AOP_TYPE(right) == AOP_LIT) &&
-       !IS_FLOAT(operandType(right)) &&
-       (lit < 256L)){
+       !IS_FLOAT(operandType(right)) 
+#ifndef LAZY_DPS_OPT
+       && (lit < 256L)
+#endif       
+       )
+    {
+#ifdef LAZY_DPS_OPT
+       D(emitcode(";", "Kevin's better literal load code"););
+       _startLazyDPSEvaluation();
+    while (size && ((unsigned int)(lit >> (offset*8)) != 0))
+       {
+           aopPut(AOP(result),
+                  aopGet(AOP(right),offset,FALSE,FALSE,TRUE),
+                  offset);
+           offset++;
+           size--;
+       }
+       /* And now fill the rest with zeros. */
+       if (size)
+       {
+           emitcode("clr","a");
+       }
+       while (size--)
+       {
+           aopPut(AOP(result), "a", offset++);
+       }
+       _endLazyDPSEvaluation();
+#else
        emitcode("clr","a");
        
-       _startAopGetLoop();
+       _startLazyDPSEvaluation();
        while (size--) 
        {
            if((unsigned int)((lit >> (size*8)) & 0x0FFL)== 0)
@@ -7781,9 +8002,12 @@ static void genAssign (iCode *ic)
                       aopGet(AOP(right),size,FALSE,FALSE,FALSE),
                       size);
        }
-       _endAopGetLoop();
-    } else {
-       _startAopGetLoop();
+       _endLazyDPSEvaluation();
+#endif 
+    } 
+    else 
+    {
+       _startLazyDPSEvaluation();
        while (size--) 
        {
            aopPut(AOP(result),
@@ -7791,7 +8015,7 @@ static void genAssign (iCode *ic)
                   offset);
            offset++;
        }
-       _endAopGetLoop();
+       _endLazyDPSEvaluation();
     }
     
 release:
@@ -7885,14 +8109,14 @@ static void genCast (iCode *ic)
         /* if they in different places then copy */
         size = AOP_SIZE(result);
         offset = 0 ;
-        _startAopGetLoop();
+        _startLazyDPSEvaluation();
         while (size--) {
             aopPut(AOP(result),
                    aopGet(AOP(right),offset,FALSE,FALSE,FALSE),
                    offset);
             offset++;
         }
-        _endAopGetLoop();
+        _endLazyDPSEvaluation();
         goto release;
     }
 
@@ -7955,14 +8179,14 @@ static void genCast (iCode *ic)
            /* the first two bytes are known */
            size = GPTRSIZE - 1; 
            offset = 0 ;
-           _startAopGetLoop();
+           _startLazyDPSEvaluation();
            while (size--) {
                aopPut(AOP(result),
                       aopGet(AOP(right),offset,FALSE,FALSE,FALSE),
                       offset);
                offset++;
            }
-           _endAopGetLoop();
+           _endLazyDPSEvaluation();
            
            /* the last byte depending on type */
            switch (p_type) {
@@ -7993,14 +8217,14 @@ static void genCast (iCode *ic)
        /* just copy the pointers */
        size = AOP_SIZE(result);
        offset = 0 ;
-       _startAopGetLoop();
+       _startLazyDPSEvaluation();
        while (size--) {
            aopPut(AOP(result),
                   aopGet(AOP(right),offset,FALSE,FALSE,FALSE),
                   offset);
            offset++;
        }
-       _endAopGetLoop();
+       _endLazyDPSEvaluation();
        goto release ;
     }
     
@@ -8009,22 +8233,30 @@ static void genCast (iCode *ic)
     /* we move to result for the size of source */
     size = AOP_SIZE(right);
     offset = 0 ;
-    _startAopGetLoop();
+    _startLazyDPSEvaluation();
     while (size--) {
         aopPut(AOP(result),
                aopGet(AOP(right),offset,FALSE,FALSE,FALSE),
                offset);
         offset++;
     }
-    _endAopGetLoop();
+    _endLazyDPSEvaluation();
 
     /* now depending on the sign of the source && destination */
     size = AOP_SIZE(result) - AOP_SIZE(right);
     /* if unsigned or not an integral type */
-    if (SPEC_USIGN(rtype) || !IS_SPEC(rtype)) {
+    /* also, if the source is a bit, we don't need to sign extend, because
+     * it can't possibly have set the sign bit.
+     */
+    if (SPEC_USIGN(rtype) || !IS_SPEC(rtype) || AOP_TYPE(right) == AOP_CRY) 
+    {
         while (size--)
+        {
             aopPut(AOP(result),zero,offset++);
-    } else {
+        }
+    } 
+    else 
+    {
         /* we need to extend the sign :{ */
         char *l = aopGet(AOP(right),AOP_SIZE(right) - 1,
                          FALSE,FALSE,TRUE);
@@ -8133,7 +8365,7 @@ static void genReceive (iCode *ic)
 }
 
 /*-----------------------------------------------------------------*/
-/* gen390Code - generate code for 8051 based controllers            */
+/* gen390Code - generate code for Dallas 390 based controllers     */
 /*-----------------------------------------------------------------*/
 void gen390Code (iCode *lic)
 {
@@ -8142,12 +8374,15 @@ void gen390Code (iCode *lic)
 
     lineHead = lineCurr = NULL;
 
+#if 0
+    //REMOVE ME!!!
     /* print the allocation information */
     if (allocInfo)
        printAllocInfo( currFunc, codeOutFile);
+#endif
     /* if debug information required */
-/*     if (options.debug && currFunc) { */
-    if (currFunc) {
+    if (options.debug && currFunc) {
+    //jwk if (currFunc) {
        cdbSymbol(currFunc,cdbFile,FALSE,TRUE);
        _G.debugLine = 1;
        if (IS_STATIC(currFunc->etype))