From d06539f5b941cd7fce59d80870b0191c2996bac9 Mon Sep 17 00:00:00 2001 From: michaelh Date: Sat, 19 Feb 2000 19:42:56 +0000 Subject: [PATCH] * Runs dhrystone. 68.83d/s with terrible code. git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@112 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- device/lib/gbz80/Makefile | 2 +- device/lib/gbz80/div.s | 161 ++++++++++++------------------- device/lib/gbz80/mul.s | 45 ++++----- src/z80/gbz80.c | 2 +- src/z80/gen.c | 69 ++++++++++--- src/z80/gen.h | 4 +- src/z80/ralloc.c | 20 ++-- support/tests/dhrystone/Makefile | 23 +++-- support/tests/dhrystone/dhry.c | 4 +- 9 files changed, 171 insertions(+), 159 deletions(-) diff --git a/device/lib/gbz80/Makefile b/device/lib/gbz80/Makefile index 51989aa2..01a1cc31 100644 --- a/device/lib/gbz80/Makefile +++ b/device/lib/gbz80/Makefile @@ -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) diff --git a/device/lib/gbz80/div.s b/device/lib/gbz80/div.s index 5917c24a..9dd447f3 100644 --- a/device/lib/gbz80/div.s +++ b/device/lib/gbz80/div.s @@ -1,161 +1,126 @@ ;; 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:: diff --git a/device/lib/gbz80/mul.s b/device/lib/gbz80/mul.s index 57c06a91..71edced1 100644 --- a/device/lib/gbz80/mul.s +++ b/device/lib/gbz80/mul.s @@ -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 diff --git a/src/z80/gbz80.c b/src/z80/gbz80.c index e64785be..dea697a3 100644 --- a/src/z80/gbz80.c +++ b/src/z80/gbz80.c @@ -9,7 +9,7 @@ static char _defaultRules[] = { -#include "peeph.rul" + "" }; static char *_gbz80_keywords[] = { NULL }; diff --git a/src/z80/gen.c b/src/z80/gen.c index c03c0a22..4ac569f5 100644 --- a/src/z80/gen.c +++ b/src/z80/gen.c @@ -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); diff --git a/src/z80/gen.h b/src/z80/gen.h index 9af52073..8052526e 100644 --- a/src/z80/gen.h +++ b/src/z80/gen.h @@ -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 }; diff --git a/src/z80/ralloc.c b/src/z80/ralloc.c index 2a758fde..330de6b4 100644 --- a/src/z80/ralloc.c +++ b/src/z80/ralloc.c @@ -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 } } diff --git a/support/tests/dhrystone/Makefile b/support/tests/dhrystone/Makefile index f5090adf..da2343ef 100644 --- a/support/tests/dhrystone/Makefile +++ b/support/tests/dhrystone/Makefile @@ -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 diff --git a/support/tests/dhrystone/dhry.c b/support/tests/dhrystone/dhry.c index 4c02ebea..02da21bb 100644 --- a/support/tests/dhrystone/dhry.c +++ b/support/tests/dhrystone/dhry.c @@ -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 */ -- 2.30.2