]> git.gag.com Git - fw/sdcc/commitdiff
* Runs dhrystone. 68.83d/s with terrible code.
authormichaelh <michaelh@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 19 Feb 2000 19:42:56 +0000 (19:42 +0000)
committermichaelh <michaelh@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 19 Feb 2000 19:42:56 +0000 (19:42 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@112 4a8a32a2-be11-0410-ad9d-d568d2c75423

device/lib/gbz80/Makefile
device/lib/gbz80/div.s
device/lib/gbz80/mul.s
src/z80/gbz80.c
src/z80/gen.c
src/z80/gen.h
src/z80/ralloc.c
support/tests/dhrystone/Makefile
support/tests/dhrystone/dhry.c

index 51989aa20aee2d1c7c6b7bfcbd407fff97bf3cd3..01a1cc314008c91545c0490bb85001352405819c 100644 (file)
@@ -5,7 +5,7 @@ TOPDIR = ../../..
 SCC = $(TOPDIR)/bin/sdcc -mgbz80 -v
 SAS = as-gb
 
-OBJ = putchar.o string.o printf.o # asm_strings.o div.o mul.o 
+OBJ = putchar.o string.o printf.o div.o mul.o # asm_strings.o
 LIB = z80.lib
 CC = $(SCC)
 AS = $(SAS)
index 5917c24acb81349e0d86686087b2bc3f257ae9c4..9dd447f3ce6c648de3404c6a66798af8b6296f4b 100644 (file)
        ;; Originally from GBDK by Pascal Felber.
        .area   _CODE
 
-__divschar::   
-       push    de
+__divschar::
        push    bc
-       push    ix
-       ld      ix,#0
-       add     ix,sp
-
-       ld      c,8(ix)
-       ld      e,9(ix)
+       lda     hl,4(sp)
+       
+       ld      c,(hl)
+       inc     hl
+       ld      e,(hl)
        call    .div8
 
-       ld      l,c
-       
-       pop     ix
+       ld      e,c
        pop     bc
-       pop     de
        ret
        
 __modschar::
-       push    de
        push    bc
-       push    ix
-       ld      ix,#0
-       add     ix,sp
-
-       ld      c,8(ix)
-       ld      e,9(ix)
+       lda     hl,4(sp)
+       ld      c,(hl)
+       inc     hl
+       ld      e,(hl)
        call    .div8
 
-       ld      l,e
-       
-       pop     ix
+       ;;  Result in e
        pop     bc
-       pop     de
        ret
 
 __divsint::
-       push    de
        push    bc
-       push    ix
-       ld      ix,#0
-       add     ix,sp
-
-       ld      c,8(ix)
-       ld      b,9(ix)
-       ld      e,10(ix)
-       ld      d,11(ix)
+       lda     hl,4(sp)
+       ld      c,(hl)
+       inc     hl
+       ld      b,(hl)
+       inc     hl
+       ld      e,(hl)
+       inc     hl
+       ld      d,(hl)
        call    .div16
 
-       ld      l,c
-       ld      h,b
-       
-       pop     ix
+       ld      e,c
+       ld      d,b
+
        pop     bc
-       pop     de
        ret
        
 __modsint::
-       push    de
        push    bc
-       push    ix
-       ld      ix,#0
-       add     ix,sp
+       lda     hl,4(sp)
 
-       ld      c,8(ix)
-       ld      b,9(ix)
-       ld      e,10(ix)
-       ld      d,11(ix)
+       ld      c,(hl)
+       inc     hl
+       ld      b,(hl)
+       inc     hl
+       ld      e,(hl)
+       inc     hl
+       ld      d,(hl)
        call    .div16
 
-       ld      l,e
-       ld      h,d
-       
-       pop     ix
+       ;; Result in de
        pop     bc
-       pop     de
        ret
 
        ;; Unsigned
 __divuchar::   
-       push    de
        push    bc
-       push    ix
-       ld      ix,#0
-       add     ix,sp
-
-       ld      c,8(ix)
-       ld      e,9(ix)
+       lda     hl,4(sp)
+       
+       ld      c,(hl)
+       inc     hl
+       ld      e,(hl)
        call    .divu8
 
-       ld      l,c
+       ld      e,c
        
-       pop     ix
        pop     bc
-       pop     de
        ret
        
 __moduchar::
-       push    de
        push    bc
-       push    ix
-       ld      ix,#0
-       add     ix,sp
-
-       ld      c,8(ix)
-       ld      e,9(ix)
+       lda     hl,4(sp)
+       
+       ld      c,(hl)
+       inc     hl
+       ld      e,(hl)
        call    .divu8
 
-       ld      l,e
-       
-       pop     ix
+       ;; Result in e
        pop     bc
-       pop     de
        ret
 
 __divuint::
-       push    de
        push    bc
-       push    ix
-       ld      ix,#0
-       add     ix,sp
-
-       ld      c,8(ix)
-       ld      b,9(ix)
-       ld      e,10(ix)
-       ld      d,11(ix)
+       lda     hl,4(sp)
+       ld      c,(hl)
+       inc     hl
+       ld      b,(hl)
+       inc     hl
+       ld      e,(hl)
+       inc     hl
+       ld      d,(hl)
        call    .divu16
 
-       ld      l,c
-       ld      h,b
+       ld      e,c
+       ld      d,b
        
-       pop     ix
        pop     bc
-       pop     de
        ret
        
 __moduint::
-       push    de
        push    bc
-       push    ix
-       ld      ix,#0
-       add     ix,sp
-
-       ld      c,8(ix)
-       ld      b,9(ix)
-       ld      e,10(ix)
-       ld      d,11(ix)
+       lda     hl,4(sp)
+       ld      c,(hl)
+       inc     hl
+       ld      b,(hl)
+       inc     hl
+       ld      e,(hl)
+       inc     hl
+       ld      d,(hl)
        call    .divu16
 
-       ld      l,e
-       ld      h,d
-       
-       pop     ix
+       ;; Result in de
        pop     bc
-       pop     de
        ret
        
 .div8::
index 57c06a91df7950ea62ba6c7147891aa08b98103d..71edced1b91a96c27557aa26c4b59b3bdb71c97b 100644 (file)
@@ -3,39 +3,34 @@
        .area   _CODE
 __mulschar::   
 __muluchar::
-       push    de
        push    bc
-       push    ix
-       ld      ix,#0
-       add     ix,sp
-
-       ld      c,8(ix)
-       ld      e,9(ix)
+       lda     hl,4(sp)
+       ld      c,(hl)
+       inc     hl
+       ld      e,(hl)
        call    .mulu8
-       
-       pop     ix
+
+       ld      e,l
        pop     bc
-       pop     de
        ret
 
 __mulsint::
 __muluint::
-       push    de
        push    bc
-       push    ix
-       ld      ix,#0
-       add     ix,sp
-
-       ld      c,8(ix)
-       ld      b,9(ix)
-       ld      e,10(ix)
-       ld      d,11(ix)
+       lda     hl,4(sp)
+       ld      c,(hl)
+       inc     hl
+       ld      b,(hl)
+       inc     hl
+       ld      e,(hl)
+       inc     hl
+       ld      d,(hl)
        call    .mulu16
-       
-       pop     ix
+
+       ld      e,l
+       ld      d,h
        pop     bc
-       pop     de
-       ret
+       ret     
                
 .mul8:
 .mulu8:
@@ -53,8 +48,8 @@ __muluint::
        ;;   DE = less significant word of product
        ;;
        ;; Register used: AF,BC,DE,HL
-.mul16:
-.mulu16:
+.mul16::       
+.mulu16::      
        LD      HL,#0x00        ; Product = 0
        LD      A,#15           ; Count = bit length - 1
        ;; Shift-and-add algorithm
index e64785bea72988eec6d37dbea11afe0f9d520843..dea697a354f8595261583fbf501df4e3b18f4453 100644 (file)
@@ -9,7 +9,7 @@
 
 static char _defaultRules[] =
 {
-#include "peeph.rul"
+    ""
 };
 
 static char *_gbz80_keywords[] = { NULL };
index c03c0a22ef6378f851ddcefbfe37a6a23077644e..4ac569f5c854b5975cfc933e590af94d14c4a17d 100644 (file)
@@ -249,6 +249,7 @@ static asmop *aopForSym (iCode *ic,symbol *sym,bool result)
         return aop;
     }
 
+#if 0
     if (IS_GB) {
        /* if it is in direct space */
        if (IN_DIRSPACE(space)) {
@@ -259,12 +260,16 @@ static asmop *aopForSym (iCode *ic,symbol *sym,bool result)
            return aop;
        }
     }
+#endif
 
     /* only remaining is far space */
     /* in which case DPTR gets the address */
-    sym->aop = aop = newAsmop(AOP_IY);
-    if (!IS_GB)
+    if (IS_GB)
+       sym->aop = aop = newAsmop(AOP_HL);
+    else {
+       sym->aop = aop = newAsmop(AOP_IY);
        emitcode ("ld","iy,#%s ; a", sym->rname);
+    }
     aop->size = getSize(sym->type);
     aop->aopu.aop_dir = sym->rname;
 
@@ -625,6 +630,13 @@ static char *aopGet (asmop *aop, int offset, bool bit16)
     case AOP_REG:
        return aop->aopu.aop_reg[offset]->name;
 
+    case AOP_HL:
+       emitcode("ld", "hl,#%s+%d", aop->aopu.aop_dir, offset);
+       sprintf(s, "(hl)");
+       ALLOC_ATOMIC(rs, strlen(s)+1);
+       strcpy(rs,s);
+       return rs;
+
     case AOP_IY:
        sprintf(s,"%d(iy)", offset);
        ALLOC_ATOMIC(rs,strlen(s)+1);
@@ -735,7 +747,17 @@ static void aopPut (asmop *aop, char *s, int offset)
        else
            emitcode("ld", "%d(iy),%s", offset, s);
        break;
-       
+    
+    case AOP_HL:
+       assert(IS_GB);
+       if (!strcmp(s, "(hl)")) {
+           emitcode("ld", "a,(hl)");
+           s = "a";
+       }
+       emitcode("ld", "hl,#%s+%d", aop->aopu.aop_dir, offset);
+       emitcode("ld", "(hl),%s", s);
+       break;
+
     case AOP_STK:
        if (IS_GB) {
            if (!strcmp("(hl)", s)) {
@@ -1018,6 +1040,8 @@ release:
 static bool requiresHL(asmop *aop)
 {
     switch (aop->type) {
+    case AOP_DIR:
+    case AOP_HL:
     case AOP_STK:
        return TRUE;
     default:
@@ -1044,8 +1068,9 @@ void assignResultValue(operand * oper)
 static void fetchHL(asmop *aop)
 {
     if (IS_GB && requiresHL(aop)) {
-       emitcode("ld", "a,%s", aopGet(aop, 0, FALSE));
-       emitcode("ld", "h,%s", aopGet(aop, 1, FALSE));
+       aopGet(aop, 0, FALSE);
+       emitcode("ld", "a,(hl+)");
+       emitcode("ld", "h,(hl)");
        emitcode("ld", "l,a");
     }
     else {
@@ -1402,7 +1427,12 @@ static void genRet (iCode *ic)
     size = AOP_SIZE(IC_LEFT(ic));
     
     if ((size == 2) && ((l = aopGetWord(AOP(IC_LEFT(ic)), 0)))) {
+       if (IS_GB) {
+           emitcode("ld", "de,%s", l);
+       }
+       else {
            emitcode("ld", "hl,%s", l);
+       }
     }
     else {
        while (size--) {
@@ -2571,7 +2601,7 @@ static void genOr (iCode *ic, iCode *ifx)
                    MOVA(aopGet(AOP(right),offset,FALSE));
                    emitcode("or","a,%s ; 7",
                             aopGet(AOP(left),offset,FALSE));
-                   aopPut(AOP(result),"a ; 8",0);
+                   aopPut(AOP(result),"a ; 8", offset);
                }
             }
         }
@@ -3376,10 +3406,14 @@ static void genGenPointerSet (operand *right,
 {    
     int size, offset ;
     link *retype = getSpec(operandType(right));
+    const char *ptr = "hl";
 
     aopOp(result,ic,FALSE);
     aopOp(right,ic,FALSE);
 
+    if (IS_GB)
+       ptr = "de";
+
     /* Handle the exceptions first */
     if (isPair(AOP(result)) && (AOP_SIZE(right)==1)) {
        /* Just do it */
@@ -3396,11 +3430,17 @@ static void genGenPointerSet (operand *right,
         /* if this is remateriazable */
         if (AOP_TYPE(result) == AOP_IMMD) {
            emitcode("", "; Error 2");
-           emitcode("ld", "hl,%s", aopGet(AOP(result), 0, TRUE));
+           emitcode("ld", "%s,%s", ptr, aopGet(AOP(result), 0, TRUE));
         }
         else { /* we need to get it byte by byte */
-           /* PENDING: do this better */
-           fetchHL(AOP(result));
+           if (IS_GB) {
+               emitcode("ld", "e,%s", aopGet(AOP(result), 0, TRUE));
+               emitcode("ld", "d,%s", aopGet(AOP(result), 1, TRUE));
+           }
+           else {
+               /* PENDING: do this better */
+               fetchHL(AOP(result));
+           }
         }
     }
     /* so hl know contains the address */
@@ -3416,16 +3456,15 @@ static void genGenPointerSet (operand *right,
 
         while (size--) {
             char *l = aopGet(AOP(right),offset,FALSE);
-
-           if (isRegOrLit(AOP(right))) {
-               emitcode("ld", "(hl),%s", l);
+           if (isRegOrLit(AOP(right)) && !IS_GB) {
+               emitcode("ld", "(%s),%s", l);
            }
            else {
                MOVA(l);
-               emitcode("ld", "(hl),a", offset);
+               emitcode("ld", "(%s),a", ptr, offset);
            }
            if (size) {
-               emitcode("inc", "hl");
+               emitcode("inc", ptr);
            }
            offset++;
         }
@@ -3503,7 +3542,7 @@ static void genAddrOf (iCode *ic)
     if (sym->onStack) {
         /* if it has an offset  then we need to compute it */
        if (IS_GB) {
-           emitcode("lda", "hl,%d+%d(sp)", sym->stack, _spoffset);
+           emitcode("lda", "hl,%d+%d+%d(sp)", sym->stack, _pushed, _spoffset);
            emitcode("ld", "d,h");
            emitcode("ld", "e,l");
            aopPut(AOP(IC_RESULT(ic)), "e", 0);
index 9af52073ce89442ca807a2f87344ea57d038e89d..8052526e70417e7308559a961ab5fc81c1539f70 100644 (file)
@@ -41,7 +41,9 @@ enum {
     /* Is in the carry register */
     AOP_CRY, 
     /* Is pointed to by IY */
-    AOP_IY, 
+    AOP_IY,
+    /* Is pointed to by HL */
+    AOP_HL,
     /* Is in A */
     AOP_ACC };
 
index 2a758fde3128f85b4fa1222fd1e910ce34c30656..330de6b4c1a24116aa9fa0afb18f19f660d91d3e 100644 (file)
@@ -2076,15 +2076,17 @@ static void packRegisters (eBBlock *ebp)
            getSize(operandType(IC_RESULT(ic))) <= 2)
            packRegsForAccUse (ic);
 #else
-       if ((POINTER_GET(ic) ||
-            IS_ARITHMETIC_OP(ic) ||
-            IS_BITWISE_OP(ic) ||
-            ic->op == LEFT_OP ||
-            ic->op == RIGHT_OP
-            ) &&
-           IS_ITEMP(IC_RESULT(ic)) &&
-           getSize(operandType(IC_RESULT(ic))) == 1)
-           packRegsForAccUse2(ic);
+       if (!IS_GB) {
+           if ((POINTER_GET(ic) ||
+                IS_ARITHMETIC_OP(ic) ||
+                IS_BITWISE_OP(ic) ||
+                ic->op == LEFT_OP ||
+                ic->op == RIGHT_OP
+                ) &&
+               IS_ITEMP(IC_RESULT(ic)) &&
+               getSize(operandType(IC_RESULT(ic))) == 1)
+               packRegsForAccUse2(ic);
+       }
 #endif
     }
 }
index f5090adf339523d89702fbf5a5f41afd163c1565..da2343ef14164d6ab196163510718a1cf0969993 100644 (file)
@@ -1,20 +1,23 @@
 # Simple Makefile for dhrystone and sdcc
 
-CC = /home/michaelh/projects/sdcc/bin/sdcc
+#CC = /home/michaelh/projects/sdcc/bin/sdcc
 # -DNOENUM is here to make the results more predictable
-CFLAGS = -mgbz80 -v --dumpall
+#CFLAGS = -mgbz80 -v --dumpall
+CC = lcc-gb
+CFLAGS = -int16 -DSDCC=1 -v
 CFLAGS += -DREG= -DNOSTRUCTASSIGN -DNOENUM -DBROKEN_SDCC=0 -DHZ=100
-LIBDIR = /home/michaelh/projects/sdcc/device/lib/z80/
-LD = link-z80
+LIBDIR = /home/michaelh/projects/sdcc/device/lib/gbz80/
+LD = link-gb
+AS = as-gb
 
 OBJ = dhry.o
 
 all: dhry
 
 dhry: $(OBJ)
-       $(LD) -n -- -i -m -k$(LIBDIR) -lz80.lib \
-       -b_CODE=0x200 dhry.ihx $(LIBDIR)crt0.o $(OBJ)
-       cat dhry.ihx | ../../makebin/makebin > dhry.rom
+       $(LD) -n -- -z -m -k$(LIBDIR) -lz80.lib \
+       -b_CODE=0x200 dhry.gb $(LIBDIR)crt0.o $(OBJ)
+#      cat dhry.ihx | ../../makebin/makebin > dhry.rom
 
 native:
        gcc -g -O2 -DREG= -DNOSTRUCTASSIGN -DNOENUM -o dhry dhry.c
@@ -22,8 +25,12 @@ native:
 .c.o:
        $(CC) $(CFLAGS) $<
 
-dhry.c: $(CC)
+dhry.c:
 
 clean:
        rm -r *~ dhry
 
+dhry.o: dhry.c
+       /usr/lib/SDK/gbz80-gb/2.1.0/bin/cpp -DINT_16_BITS -D__STDC__=1 -DZ80 -DGB -DGAMEBOY -D__LCC__ -DSDCC=1 -DREG= -DNOSTRUCTASSIGN -DNOENUM -DBROKEN_SDCC=0 -DHZ=100 -I/usr/lib/sdcc/include dhry.c dhry.i
+       /usr/lib/SDK/gbz80-gb/2.1.0/bin/rcc -target=gbz80/int16 -optimize -v dhry.i dhry.asm
+       $(AS) -plosff dhry.o dhry.asm
\ No newline at end of file
index 4c02ebea3093d32055dcd624333cca1728be1622..02da21bb68e897f1788c27a5e3a4075339e81fc1 100644 (file)
@@ -72,6 +72,7 @@ char            Ch_1_Glob,
                 Ch_2_Glob;
 int             Arr_1_Glob [50];
 int             Arr_2_Glob [50] [50];
+char           silly;
 
 /* Used instead of malloc() */
 static Rec_Type _r[2];
@@ -164,7 +165,7 @@ int main(void)
               Int_1_Loc, Int_2_Loc, Int_3_Loc));
 
        DPRINTF(("Proc_8\n"));
-       Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
+       Proc_8 (Arr_1_Glob, (int *)Arr_2_Glob, Int_1_Loc, Int_3_Loc);
        /* Int_Glob == 5 */
        DPRINTF(("Int_Glob %d == 5\n", Int_Glob));
        DPRINTF(("Proc_1\n"));
@@ -293,6 +294,7 @@ void Proc_1 (REG Rec_Pointer Ptr_Val_Par)
        }
     else /* not executed */
        structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp);
+    silly = 1;
 } /* Proc_1 */