changeset 631:76242dc0bbc9

Intel Mac continue....
author kono
date Wed, 11 Oct 2006 01:20:21 +0900
parents 557b2a266f75
children 704b483c3122
files Changes mc-code-ia32.c
diffstat 2 files changed, 61 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/Changes	Tue Oct 10 23:26:06 2006 +0900
+++ b/Changes	Wed Oct 11 01:20:21 2006 +0900
@@ -8921,5 +8921,6 @@
 関数呼び出し時にスタックを調整するようなことはしない」
 なのか。
 
-
-
+おっと、stack は 16byte alignment でなければならないわけね。
+
+
--- a/mc-code-ia32.c	Tue Oct 10 23:26:06 2006 +0900
+++ b/mc-code-ia32.c	Wed Oct 11 01:20:21 2006 +0900
@@ -271,6 +271,7 @@
             see enter/enter1/leave           see code_enter
  */
 static int arg_offset;
+
 int disp_offset = -12;
 #define func_disp_offset (-12)
 #define code_disp_offset (-12)
@@ -671,7 +672,7 @@
 #ifdef __APPLE__
     char *rrn = register_name(r,0);
     if (nptr->sc==STATIC && !(is_code(nptr)||is_function(nptr))) {
-        printf("\tmovl _%s-_%d(%%ebx),%s\n",nptr->nm,
+        printf("\tleal _%s-_%d(%%ebx),%s\n",nptr->nm,
             goffset_label,rrn);
     } else {
         printf("\tmovl L_%s$non_lazy_ptr-_%d(%%ebx),%s\n",
@@ -1356,7 +1357,7 @@
 	text_mode(0);
     }
 #ifdef __APPLE__
-    printf("\tmovl _%d-_%d(%%ebx),%s\n",lb,
+    printf("\tleal _%d-_%d(%%ebx),%s\n",lb,
 	    goffset_label,
 	    register_name(creg,0));
 #else
@@ -1513,6 +1514,37 @@
 #endif
 
     e2 = cadr(e1);
+#ifdef __APPLE__
+    //   esp must align 16byte for mmx operation
+    nargs = 0;
+    int length;
+    for (e3 = caddr(e1); e3; e3 = cadr(e3)) {	
+	t=caddr(e3);
+	if(scalar(t)) {
+	} else if (t==LONGLONG||t==ULONGLONG) {
+	    ++nargs;
+	} else if (t==DOUBLE) {
+	    nargs += SIZE_OF_DOUBLE/SIZE_OF_INT;
+	    continue;
+	} else if (t==FLOAT) {
+	    nargs += SIZE_OF_FLOAT/SIZE_OF_INT;
+	    continue;
+	} else if (car(t)==STRUCT||car(t)==UNION) {
+	    length = size(t);
+	    length += SIZE_OF_INT - (length%SIZE_OF_INT);
+	    nargs += length/SIZE_OF_INT ;
+	    continue;
+	} else {
+	    error(TYERR);
+	}
+	++nargs;
+    }
+    if (nargs%4) {
+	length = (4-(nargs%4))*4;
+	stack_depth += length;
+	printf("\tleal %d(%%esp),%%esp\n",-length);
+    }
+#endif
     nargs = 0;
     for (e3 = caddr(e1); e3; e3 = cadr(e3)) {	
 	t=caddr(e3);
@@ -1581,7 +1613,7 @@
     } else {
 	printf("\tcall\t*%s\n",register_name(REG_EAX,0));
     }
-    if (nargs) printf("\taddl $%d,%%esp\n",SIZE_OF_INT*nargs);
+    if (nargs) printf("\taddl $%d,%%esp\n",stack_depth-stack_depth_save);
     if (ret_type==DOUBLE||ret_type==FLOAT) {
     } else if (ret_type==LONGLONG||ret_type==ULONGLONG) {
 	use_longlong0(USE_CREG);
@@ -1854,6 +1886,10 @@
     case UDIV:
     case MOD:
     case UMOD:
+#ifdef __APPLE__
+	if (regs[REG_EDX]==PTRC_REG)
+	    clear_ptr_cache_reg(REG_EDX);
+#endif
 	use_register(reg,REG_EAX,1);
 	if (oreg==REG_EAX) oreg=reg;
 	if (oreg==REG_EDX) {
@@ -2095,7 +2131,12 @@
 void
 code_leave(char *name)
 {
+#ifdef __APPLE__
+    disp &= -(SIZE_OF_INT*4); // 16byte alignment
+    disp -= code_disp_offset-8;
+#else
     disp &= -SIZE_OF_INT;
+#endif
     printf("\t.set _%d,%d\n",code_disp_label,disp+code_disp_offset-8);
 #ifndef __APPLE__
     printf("_%d:\n",labelno);
@@ -2166,7 +2207,12 @@
 {
     int sz;
 
+#ifdef __APPLE__
+    disp &= -(SIZE_OF_INT*4); // 16byte alignment
+    disp -= 12;
+#else
     disp &= -SIZE_OF_INT;
+#endif
     if (control)
         code_set_return_register(1);
     if (retcont) {
@@ -3055,6 +3101,9 @@
     /* specified registers stacks are saved in local variable */
     /* temporal registers are saved in local variable */
     int i,reg;
+    if (regs[reg1]==PTRC_REG)
+        clear_ptr_cache_reg(reg1);
+
     for(i=0;i<reg_sp;i++) {
         if ((reg=reg_stack[i])>=0 && reg==reg1) {
             code_assign_lvar(
@@ -3105,10 +3154,11 @@
     g_expr(e1);
     emit_lpush();
     g_expr(e2);
-    // we are sure %ecx,%ebx is free
+    // we are sure %ecx is free
+    // %ebx is used in Intel Mac
     printf("\tpopl %%ecx\n");   // LSW
-    printf("\tpopl %%ebx\n");   // MSW
-    printf("\tsubl %%edx,%%ebx\n");
+    printf("\tcmpl %%edx,(%%esp)\n");  // MSW
+    printf("\tpopl %%edx\n"); 
     l2 = fwdlabel();
     // cond==0 jump on false condtion   ( if(x) => rexpr(..  cond=0 ...) )
     switch(op) {
@@ -3873,13 +3923,13 @@
     } else if (car(rstr)==CONST) {
 	printf("%d",cadr(rstr));
     } else if (car(rstr)==FNAME) {
-#ifdef __APPLE
+#ifdef __APPLE__
 	printf("_%s-_%d",(char*)cadr(rstr),goffset_label);
 #else
 	printf("%s",(char*)cadr(rstr));
 #endif
     } else if (car(rstr)==STRING) {
-#ifdef __APPLE
+#ifdef __APPLE__
 	printf("_%d-_%d",cadr(rstr),goffset_label);
 #else
 	printf("_%d",cadr(rstr));