changeset 127:eb4d8975926c

Intel float fix
author kono
date Tue, 01 Apr 2003 10:31:40 +0900
parents 1d1612fe705a
children d497c39add36
files .gdbinit Changes Makefile mc-code-ia32.c mc-code-powerpc.c mc-codegen.c mc-parse.c test/int.c
diffstat 8 files changed, 197 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/.gdbinit	Wed Mar 26 16:50:12 2003 +0900
+++ b/.gdbinit	Tue Apr 01 10:31:40 2003 +0900
@@ -1,5 +1,5 @@
 tb main
-r -s test/fact-a.c
+r -s test/arg.c
 define regs 
 printf "pc =%08x lr =%08x r0 =%08x r1 =%08x r3= %08x r4= %08x\n",$pc,$lr,$r0,$r1,$r3,$r4
 printf "r10=%08x r11=%08x r12=%08x r13=%08x r14=%08x r15=%08x\n",$r10,$r11,$r12,$r13,$r14,$r15
--- a/Changes	Wed Mar 26 16:50:12 2003 +0900
+++ b/Changes	Tue Apr 01 10:31:40 2003 +0900
@@ -2596,3 +2596,95 @@
 そうねぇ。return-continuation 側が普通でしょう。あぁ、
 でも返し先は元の関数呼び出しの引数上だから壊れちゃって
 いるかもね。だから、とっておく実装の方が良いわけね。
+
+(なんか -O3 にすると、mc1 が落ちるな...)
+
+Sat Mar 29 16:35:18 JST 2003
+
+     r30               <------r1_offset------------------------------> r1
+     #                *               <------------lvar_offset------->
+ r+  +------------+---+---------------+----------+--------------+----+    -
+  xx  callee arg   zz   register save ! local      caller arg     zz
+                          reg_save      disp       max_func_args*size_of_int
+        lvar>0                         lvar<0       lvar>0x1000 0000
+
+このままだと、* が previous r1/r30 になるので、function から
+goto する時に戻り番地やzzにあるはずのsaved r31/r30が破壊されて
+しまう。それは、ちょっと困るということは、一旦、dummy subroutine
+(普通はstub っていうか)を呼び出す方が良い? 戻り番地とprevious r1/r30
+は持ち歩いているわけだけど... また、r20-r29はつぶされてしまう
+ので、前もってsaveする必要もある。f31-f20も。(結構多いな...)
+
+   #  *          r30 <--------------r1_offset-----------> r1
+r+ +--+----------+----------+-----------+----------+----+
+xx  zz  reg save !callee arg!code local  caller arg  xx
+         r20-r29 
+
+これだと environment は持ち運ぶ必要はない? いや、ある?
+逆に戻り番地を持ち運ぶ必要はなくなるわけね。そっちの
+方がきれいかな。goto-cotinuation みたいな感じか。
+
+返り側は、
+
+  lwz r1,continuation
+  lwz r1,0(r1)
+  lwz r0,8(r1)
+  mtlr r0
+  lmw r30,-8(r1)
+  blr
+
+程度で良い? このr30ってのはgoto先では知り得ない。いや、待てよ、
+この場合は、r20-r29って決まっているわけか。
+
+  lwz r1,continuation
+  set r3/f1 as a return value
+  lwz r1,0(r1)
+  lwz r0,8(r1)
+  mtlr r0
+  lmw r20,-148(r1) (?!)
+  blr
+
+で良いわけか。構文は同じでreturn addressは無視することにするか。
+呼出側は、
+
+  通常の関数呼び出し (引数0) (は、手間0だから..)
+  bl L_stub_NN
+L_return:        (普通のretrunもあるから、必要な場合がある)
+  lwz r1,0(r1)
+  lwz r0,8(r1)
+  mtlr r0
+  lmw r20,-8(r1)
+  blr
+L_stub_NN:
+  mflr r0
+  bl L_61
+L_65:
+  lwz r1,0(r1)
+  lmw r23,-108(r1)
+  b restFP+36 ; restore f23-f31
+L_61:
+  stmw r23,-108(r1)
+  stw r0,8(r1)
+  b saveFP+36 ; save f23-f31
+
+ちょっと複雑すぎるかな。特に gcc では、こういう操作は難しいかも。
+
+あ、そうか。register saveは、このy関数が呼び出された時点で
+やってしまえば良い。そうすれば必要ない。戻り番地も既に xx
+に入っている。だよね。
+
+                 * gotoを呼び出した関数のr1 ! r1(goto前のr1)
+   #             *          r30 <---------------r1_offset---------------> r1
+r+ +----------+--+----------+----------------+-----------+----------+----+
+    cousin arg xx  reg save !callee arg      !code local  caller arg  xx
+                   r20-r29     lvar>0         lvar<0      lvar>0x1000 000
+                   f20-f31  <-my_func_args--><--disp-----><-max_func_arg->
+                              *size_of_int                  *size_of_int
+
+とすれば stub は必要ない。cousin arg も保存されている。goto の
+引数のみがlocal変数を上書きする形で格納される。これで、original
+のIA32実装と一致することになる。(引数の保存を除いて。いや、
+元のも保存されているんじゃないの?)
+
+それで、code segment から関数呼出しするときは? (ってことは、
+それようのテストも必要なわけか...)
--- a/Makefile	Wed Mar 26 16:50:12 2003 +0900
+++ b/Makefile	Tue Apr 01 10:31:40 2003 +0900
@@ -1,4 +1,5 @@
-CC = gcc
+CC = gcc 
+# -O3
 CFLAGS = -g -Wall -I.
 BASE=0
 STAGE=1
@@ -53,7 +54,7 @@
 	-gcc $(TARGET).c -o b.out $(MLIB)
 	-./b.out > $(TARGET).gcc.out
 	-./$(MC) -s $(TARGET).c
-	-gcc $(TARGET).s -$(MLIB)
+	-gcc $(TARGET).s $(MLIB)
 	-./a.out > $(TARGET).$(MC).out
 	-diff  $(TARGET).gcc.out $(TARGET).$(MC).out
 
@@ -88,3 +89,62 @@
 
 # DO NOT DELETE
 
+mc-code-ia32.o: mc.h /usr/include/stdio.h /usr/include/sys/types.h
+mc-code-ia32.o: /usr/include/sys/appleapiopts.h /usr/include/sys/cdefs.h
+mc-code-ia32.o: /usr/include/machine/types.h /usr/include/ppc/types.h
+mc-code-ia32.o: /usr/include/machine/ansi.h /usr/include/ppc/ansi.h
+mc-code-ia32.o: /usr/include/machine/endian.h /usr/include/ppc/endian.h
+mc-code-ia32.o: conv/conv.h mc-codegen.h mc-code.h
+mc-codegen.o: mc.h /usr/include/stdio.h /usr/include/sys/types.h
+mc-codegen.o: /usr/include/sys/appleapiopts.h /usr/include/sys/cdefs.h
+mc-codegen.o: /usr/include/machine/types.h /usr/include/ppc/types.h
+mc-codegen.o: /usr/include/machine/ansi.h /usr/include/ppc/ansi.h
+mc-codegen.o: /usr/include/machine/endian.h /usr/include/ppc/endian.h
+mc-codegen.o: conv/conv.h mc-codegen.h mc-code.h
+mc-parse.o: mc.h /usr/include/stdio.h /usr/include/sys/types.h
+mc-parse.o: /usr/include/sys/appleapiopts.h /usr/include/sys/cdefs.h
+mc-parse.o: /usr/include/machine/types.h /usr/include/ppc/types.h
+mc-parse.o: /usr/include/machine/ansi.h /usr/include/ppc/ansi.h
+mc-parse.o: /usr/include/machine/endian.h /usr/include/ppc/endian.h
+mc-parse.o: conv/conv.h mc-codegen.h
+mc-tree.o: mc.h /usr/include/stdio.h /usr/include/sys/types.h
+mc-tree.o: /usr/include/sys/appleapiopts.h /usr/include/sys/cdefs.h
+mc-tree.o: /usr/include/machine/types.h /usr/include/ppc/types.h
+mc-tree.o: /usr/include/machine/ansi.h /usr/include/ppc/ansi.h
+mc-tree.o: /usr/include/machine/endian.h /usr/include/ppc/endian.h
+mc-tree.o: conv/conv.h
+mc.o: /usr/include/stdio.h /usr/include/sys/types.h
+mc.o: /usr/include/sys/appleapiopts.h /usr/include/sys/cdefs.h
+mc.o: /usr/include/machine/types.h /usr/include/ppc/types.h
+mc.o: /usr/include/machine/ansi.h /usr/include/ppc/ansi.h
+mc.o: /usr/include/machine/endian.h /usr/include/ppc/endian.h conv/conv.h
+conv/c.o: mc.h /usr/include/stdio.h /usr/include/sys/types.h
+conv/c.o: /usr/include/sys/appleapiopts.h /usr/include/sys/cdefs.h
+conv/c.o: /usr/include/machine/types.h /usr/include/ppc/types.h
+conv/c.o: /usr/include/machine/ansi.h /usr/include/ppc/ansi.h
+conv/c.o: /usr/include/machine/endian.h /usr/include/ppc/endian.h conv/conv.h
+conv/c.o: conv/convdef.h conv/c.h
+conv/c2cbc.o: mc.h /usr/include/stdio.h /usr/include/sys/types.h
+conv/c2cbc.o: /usr/include/sys/appleapiopts.h /usr/include/sys/cdefs.h
+conv/c2cbc.o: /usr/include/machine/types.h /usr/include/ppc/types.h
+conv/c2cbc.o: /usr/include/machine/ansi.h /usr/include/ppc/ansi.h
+conv/c2cbc.o: /usr/include/machine/endian.h /usr/include/ppc/endian.h
+conv/c2cbc.o: conv/conv.h
+conv/cbc2c.o: mc.h /usr/include/stdio.h /usr/include/sys/types.h
+conv/cbc2c.o: /usr/include/sys/appleapiopts.h /usr/include/sys/cdefs.h
+conv/cbc2c.o: /usr/include/machine/types.h /usr/include/ppc/types.h
+conv/cbc2c.o: /usr/include/machine/ansi.h /usr/include/ppc/ansi.h
+conv/cbc2c.o: /usr/include/machine/endian.h /usr/include/ppc/endian.h
+conv/cbc2c.o: conv/conv.h
+conv/null.o: mc.h /usr/include/stdio.h /usr/include/sys/types.h
+conv/null.o: /usr/include/sys/appleapiopts.h /usr/include/sys/cdefs.h
+conv/null.o: /usr/include/machine/types.h /usr/include/ppc/types.h
+conv/null.o: /usr/include/machine/ansi.h /usr/include/ppc/ansi.h
+conv/null.o: /usr/include/machine/endian.h /usr/include/ppc/endian.h
+conv/null.o: conv/conv.h conv/convdef.h conv/null.h
+mc-code-powerpc.o: mc.h /usr/include/stdio.h /usr/include/sys/types.h
+mc-code-powerpc.o: /usr/include/sys/appleapiopts.h /usr/include/sys/cdefs.h
+mc-code-powerpc.o: /usr/include/machine/types.h /usr/include/ppc/types.h
+mc-code-powerpc.o: /usr/include/machine/ansi.h /usr/include/ppc/ansi.h
+mc-code-powerpc.o: /usr/include/machine/endian.h /usr/include/ppc/endian.h
+mc-code-powerpc.o: conv/conv.h mc-code.h mc-codegen.h
--- a/mc-code-ia32.c	Wed Mar 26 16:50:12 2003 +0900
+++ b/mc-code-ia32.c	Tue Apr 01 10:31:40 2003 +0900
@@ -934,8 +934,8 @@
 int
 function(int e1)
 {
-    int e2,e3,e4,e5,nargs,t,ret_type;
-    NMTBL *n;
+    int e2,e3,e4,nargs,t,ret_type;
+    NMTBL *n=0;
     int save,saved;
     ret_type = cadddr(e1);
 #ifdef SAVE_STACKS
@@ -954,7 +954,7 @@
     nargs = 0;
     for (e3 = caddr(e1); e3; e3 = cadr(e3)) {	
 	t=caddr(e3);
-	n=(NMTBL *)(e5=(cadr(e4 = car(e3))));
+	e4 = car(e3);
 	if(scalar(t)) {
 	    g_expr(e4);
 	    printf("\tpushl %s\n",register_name(creg,0));
@@ -1052,7 +1052,7 @@
     printf("\t%s (%s)\n",fload(car(e1)==DRINDIRECT),register_name(creg,0));
     t=DOUBLE;
     break;
-    case CRINDIRECT: case RINDIRECT:
+    case CRINDIRECT: case RINDIRECT: default:
     op = ((byte = (car(e1) == CRINDIRECT)) ? "movsbl" : "movl");
     printf("\t%s (%s),%s\n",op,register_name(creg,0),register_name(creg,0));
     t=byte?CHAR:INT;
@@ -1175,9 +1175,9 @@
 	edx_setup();
 	orn = register_name(oreg,0);
 	if (op==DIV)
-	    printf("\tcltd\n\tdivl %s\n",orn);
+	    printf("\tcltd\n\tidivl %s\n",orn);
 	else 
-	    printf("\txor %%edx,%%edx\n\tidivl %s\n",orn);
+	    printf("\txor %%edx,%%edx\n\tdivl %s\n",orn);
 	edx_cleanup();
 	break;
     case MOD:
@@ -1186,9 +1186,9 @@
 	edx_setup();
 	orn = register_name(oreg,0);
 	if (op==DIV)
-	    printf("\tcltd\n\tdivl %s\n",orn);
+	    printf("\tcltd\n\tidivl %s\n",orn);
 	else 
-	    printf("\txor %%edx,%%edx\n\tidivl %s\n",orn);
+	    printf("\txor %%edx,%%edx\n\tdivl %s\n",orn);
         dx = virtual(REG_EDX);	
 	if (dx!=creg) {
 	    rname[dx]=rname[creg];
@@ -1685,8 +1685,8 @@
     printf("\tmovl    (%%esp), %s\n",register_name(creg,0));
     printf("\tmovb    $12, 1(%%esp)\n");
     printf("\tfldcw   (%%esp)\n");
-    printf("\tmovl    %s, (%%ebp)\n",register_name(creg,0));
     printf("\tfistpl  %d(%%esp)\n",size_of_int);
+    printf("\tmovl    %s, (%%esp)\n",register_name(creg,0));
     printf("\tfldcw   (%%esp)\n");
     printf("\tpopl    %s\n",register_name(creg,0));
     printf("\tpopl    %s\n",register_name(creg,0));
@@ -1706,7 +1706,7 @@
     printf("\tmovl    (%%esp), %s\n",register_name(creg,0));
     printf("\tmovb    $12, 1(%%esp)\n");
     printf("\tfldcw   (%%esp)\n");
-    printf("\tmovl    %s, (%%ebp)\n",register_name(creg,0));
+    printf("\tmovl    %s, (%%esp)\n",register_name(creg,0));
     printf("\tfistpll %d(%%esp)\n",size_of_int);
     printf("\tfldcw   (%%esp)\n");
     printf("\tmovl    %d(%%esp),%s\n",size_of_int,register_name(creg,0));
@@ -1891,7 +1891,8 @@
 void
 code_save_fstacks()
 {
-    int xreg,sp;
+    int xreg,sp,uses;
+    uses = use; use = 0;
     sp=freg_sp;
     while(sp-->0) {
 	if ((xreg=freg_stack[sp])==-1) {
@@ -1900,6 +1901,7 @@
 	    freg_stack[sp]= freg_stack[sp]-REG_LVAR_OFFSET;
 	}
     }
+    use = uses;
 }
 
 /* end */
--- a/mc-code-powerpc.c	Wed Mar 26 16:50:12 2003 +0900
+++ b/mc-code-powerpc.c	Tue Apr 01 10:31:40 2003 +0900
@@ -129,12 +129,24 @@
      f1-r8  input register
      f24-f31 saved register variable
 
+function call stack frame
                        <------r1_offset------------------------------>
                                       <------------lvar_offset------->
  r+  +------------+---+---------------+----------+--------------+----+    -
       callee arg   xx   register save   local      caller arg     xx
                           reg_save      disp       max_func_args*size_of_int
         lvar>0                         lvar<0       lvar>0x1000 0000
+
+code segment stack frame
+
+                 * gotoを呼び出した関数のr1 ! r1(goto前のr1)
+   #             *          r30 <---------------r1_offset---------------> r1
+r+ +----------+--+----------+----------------+-----------+----------+----+
+    cousin arg xx  reg save !callee arg      !code local  caller arg  xx
+                   r20-r29     lvar>0         lvar<0      lvar>0x1000 000
+                   f20-f31  <-my_func_args--><--disp-----><-max_func_arg->
+                              *size_of_int                  *size_of_int
+
  */
 int arg_offset = 24; int arg_offset1 = 24; int disp_offset = -12;
 #define func_disp_offset 60
@@ -593,6 +605,7 @@
     int p,p1;
     char *rrn;
 
+    p1 = ptcptr; p = cadr(p1); /* unnecesary, if ptcptr is initialized */
     while(ptcptr) {
 	if(car(ptcptr)==g) return caddr(ptcptr);
 	p1=p; p=ptcptr;
@@ -604,9 +617,13 @@
     if (!caddr(p)) {
 	if((r=get_register())) {
 	    caddr(p)=r; regs[r]=PTRC_REG;
-	} else
+	} else {
+	    error(-1);
 	    r=creg; /* this can't happen */
+	}
 	car(p)=g;
+    } else {
+	r = caddr(p);
     }
     rrn = register_name(r);
     if (nptr->sc==STATIC) {
@@ -1293,7 +1310,7 @@
     int e2,e3,e4,e5,nargs,t,r0,r1;
     int arg,reg_arg,freg_arg,arg_assign;
     int reg_arg_list=0,ret_type,special_lvar;
-    NMTBL *fn;
+    NMTBL *fn = 0;
     int jmp = 0;
     char *jrn;
 
@@ -2450,7 +2467,7 @@
 
 void dtosop(int op,int e1)
 { 
-    char *opn;
+    char *opn="";
     char *frn=fregister_name(freg);
     char *grn=fregister_name(e1);
     fregv[freg]=1;
--- a/mc-codegen.c	Wed Mar 26 16:50:12 2003 +0900
+++ b/mc-codegen.c	Tue Apr 01 10:31:40 2003 +0900
@@ -324,6 +324,7 @@
 b_expr(int e1, char cond, int l1,int err)
 {
     int e2,l2,t;
+    l2 = 0;
     e2=cadr(e1);
     switch(car(e1)) {
     case LNOT:
@@ -731,7 +732,7 @@
 {
     int e2,e3,e4,sz,arg_size,ty,regs,fregs;
     int t0,s0;
-    NMTBL *code0;
+    NMTBL *code0 = 0;
     int target = 0;
     int source = 0;
     int processing = 0;
--- a/mc-parse.c	Wed Mar 26 16:50:12 2003 +0900
+++ b/mc-parse.c	Tue Apr 01 10:31:40 2003 +0900
@@ -446,7 +446,7 @@
 static int
 typespec(void)
 {
-    int t;
+    int t = INT;
     stypedecl = 0;
 
     while (sym==KONST) {
@@ -1036,7 +1036,7 @@
 static int
 sdecl(int s)
 {
-    int smode,sdisp,type0;
+    int smode,sdisp,type0=0;
     NMTBL *nptr0,*gnptr0;
     int tags;
 
@@ -2220,7 +2220,7 @@
 static int
 expr14(void)
 {
-    int e1,t;
+    int e1=0,t;
 
     switch(sym) {
     case IDENT:
@@ -2523,7 +2523,7 @@
 dbinop(int op, int e1, int e2, int t1, int t2)
 {
     double d1,d2,d;
-    int b;
+    int b=0;
 
     type= DOUBLE;
     if (integral(t1)) { e1=float_value(e1,t1); t1=DOUBLE; }
@@ -2593,7 +2593,7 @@
 static int
 binop(int op, int e1, int e2, int t1, int t2)
 {
-    int e;
+    int e=0;
 
     if(t1==DOUBLE||t2==DOUBLE||t1==FLOAT||t2==FLOAT)
 	return dbinop(op,e1,e2,t1,t2);
--- a/test/int.c	Wed Mar 26 16:50:12 2003 +0900
+++ b/test/int.c	Tue Apr 01 10:31:40 2003 +0900
@@ -303,6 +303,7 @@
     g += 2*g;
     printf("%d:%d\t",n++,g);
 
+    g = -3;
     f *= 2*g;
     printf("%d:%d\t",n++,f);
     f /= 2*g;
@@ -327,6 +328,7 @@
     *pg += 2**pg;
     printf("%d:%d\t",n++,*pg);
 
+    *pg = -3;
     *pf *= 2**pg;
     printf("%d:%d\t",n++,*pf);
     *pf /= 2**pg;