changeset 756:e333c95586bd

i64 continue...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 16 Nov 2010 19:36:40 +0900
parents d7393378b352
children 7cb7dd01507f
files mc-code-i64.c mc-code-ia32.c mc-codegen.c mc-parse.c test/code-gen-all.c test/code-gen.c
diffstat 6 files changed, 73 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/mc-code-i64.c	Mon Nov 15 12:17:59 2010 +0900
+++ b/mc-code-i64.c	Tue Nov 16 19:36:40 2010 +0900
@@ -365,8 +365,8 @@
 #define REG_EBP   1
 #define REG_EDI   2    // first argument register
 #define REG_ESI   3
-#define REG_ECX   4    // for strange reason (code_assop)
-#define REG_EDX   5
+#define REG_EDX   4
+#define REG_ECX   5    // for strange reason (code_assop)
 #define REG_EAX   8
 #define REG_EBX   11
 #define REG_R15   15
@@ -388,8 +388,8 @@
     0,
     0,
     0,
+    "%dl",
     "%cl",
-    "%dl",
     "%r8b",
     "%r9b",
     "%al",
@@ -406,8 +406,8 @@
     "%bp",
     "%di",
     "%si",
+    "%dx",
     "%cx",
-    "%dx",
     "%r8w",
     "%r9w",
     "%ax",
@@ -425,8 +425,8 @@
     "%ebp",
     "%edi",
     "%esi",
+    "%edx",
     "%ecx",
-    "%edx",
     "%r8d",
     "%r9d",
     "%eax",
@@ -450,8 +450,8 @@
     "%rbp",
     "%rdi",
     "%rsi",
+    "%rdx",
     "%rcx",
-    "%rdx",
     "%r8",
     "%r9",
     "%rax",
@@ -652,7 +652,7 @@
 
     char *move_op;
     code_clear_stack_reg(reg1); 
-    move_op = (regs[reg1]||regs[reg1])?"\txchg %s,%s\n":"\tmovq %s,%s\n";
+    move_op = (regs[reg1])?"\txchg %s,%s\n":"\tmovq %s,%s\n";
     if (move && reg0!=reg1) {
 	printf(move_op,reg_name_q[reg0],reg_name_q[reg1]);
 	if (!regs[reg1]) regs[reg1]=USING_REG;
@@ -1397,7 +1397,7 @@
 cload(int sign,int sz) {
     return sz==1?(sign?"movsbq":"movzbq"):
 	    sz==SIZE_OF_SHORT?(sign?"movswq":"movzwq"):
-	    sz==SIZE_OF_INT?(sign?"movslq":"movzlq"):"movq";
+	    sz==SIZE_OF_INT?(sign?"movslq":"movl"):"movq";
 }
 
 void
@@ -2283,6 +2283,10 @@
     code_call(e2,fn,jmp);
     free_register_var(reg_arg_list);
     if (ret_type==DOUBLE||ret_type==FLOAT) {
+        if (use)
+            set_freg(RET_DREGISTER,0);
+        else
+            set_freg(CREG_REGISTER,0);
     } else if (ret_type==VOID) {
     } else {
         if (use)
@@ -3528,10 +3532,13 @@
     printf("\t%s %s,",fstore(d),fregister_name(freg)); lvar(e2); printf("\n");
 }
 
+/*
+      e = d
+ */
 void code_dassign_dregister(int e,int d,int f)
 {
     use_float(d,f);
-    printf("\tmovapd %s,%s\n",fregister_name(e),fregister_name(f)); 
+    printf("\tmovapd %s,%s\n",fregister_name(f),fregister_name(e)); 
 }
 
 void code_dassign(int e2,int freg,int d)
@@ -3671,16 +3678,16 @@
     char *dbs = d?"d":"s";
     printf("        cmpq    $0, %s\n",u);
     printf("        js      f1\n");
-    printf("        cvtsi2%sdq       %s,%s\n",dbs,u,dn);
+    printf("        cvtsi2s%sq       %s,%s\n",dbs,u,dn);
     printf("        jmp     f2\n");
     printf("1:\n");
     printf("        movq    %s, %s\n",u,t);
     printf("        shrq    %s\n",t);
     printf("        andl    $1, %s\n",register_name(i,SIZE_OF_INT));
     printf("        orq     %s, %s\n",t,u);
-    printf("        cvtsi2%sdq       %s, %s\n",dbs,u,dn);
-    printf("        movap%s  %s, %s\n",dbs,dn,register_name(td,0));
-    printf("        adds%s   %s, %s\n",dbs,dn,register_name(td,0));
+    printf("        cvtsi2s%sq       %s, %s\n",dbs,u,dn);
+    printf("        movap%s  %s, %s\n",dbs,dn,fregister_name(td));
+    printf("        adds%s   %s, %s\n",dbs,dn,fregister_name(td));
     printf("2:\n");
     free_register(tmp);
     free_register(td);
@@ -3690,8 +3697,18 @@
     code_u2d1(reg,1);
 }
 
-void code_d2f(int reg) { }
-void code_f2d(int reg) { }
+void code_d2f(int reg) { 
+    use_float(0,reg);
+    int f = reg;
+    set_freg(get_dregister(0),0);
+    printf("\tcvtsd2ss    %s,%s\n",fregister_name(f),fregister_name(freg));
+}
+void code_f2d(int reg) { 
+    use_float(0,reg);
+    int f = reg;
+    set_freg(get_dregister(1),0);
+    printf("\tcvtss2sd    %s,%s\n",fregister_name(f),fregister_name(freg));
+}
 void code_f2i(int reg) { 
     use_float(0,reg);
     int f = reg;
@@ -4098,8 +4115,8 @@
     int i,reg;
     for(i=0;i<reg_sp;i++) {
         if ((reg=reg_stack[i])>=0) {
-            code_assign_lvar(
-                (reg_stack[i]=new_lvar(SIZE_OF_INT)),reg,0); 
+            code_lassign_lvar(
+                (reg_stack[i]=new_lvar(SIZE_OF_LONGLONG)),reg); 
             reg_stack[i]= reg_stack[i]-REG_LVAR_OFFSET;
             if (regs[reg]!=REG_VAR) free_register(reg);
         }
@@ -4108,7 +4125,7 @@
     for(i=0;i<freg_sp;i++) {
         if ((reg=freg_stack[i])>=0) {
             code_dassign_lvar(
-                (freg_stack[i]=new_lvar(SIZE_OF_FLOAT)),reg,0); 
+                (freg_stack[i]=new_lvar(SIZE_OF_DOUBLE)),reg,1); 
             freg_stack[i]= freg_stack[i]-REG_LVAR_OFFSET;
             free_register(reg);
         }
@@ -4127,8 +4144,8 @@
 
     for(i=0;i<reg_sp;i++) {
         if ((reg=reg_stack[i])>=0 && reg==reg1) {
-            code_assign_lvar(
-                (reg_stack[i]=new_lvar(SIZE_OF_INT)),reg,0); 
+            code_lassign_lvar(
+                (reg_stack[i]=new_lvar(SIZE_OF_LONGLONG)),reg); 
             reg_stack[i]= reg_stack[i]-REG_LVAR_OFFSET;
             if (regs[reg]!=REG_VAR) free_register(reg);
         }
@@ -4196,7 +4213,7 @@
 void code_lassign(int e1,int e2)
 {
     use_longlong(e2);
-    printf("\tmovq %s,(%s)\n",register_name(e1,0),register_name(e2,0));
+    printf("\tmovq %s,(%s)\n",register_name(e2,0),register_name(e1,0));
 }
 
 void code_lassign_gvar(int e1,int e2)
@@ -4287,13 +4304,13 @@
 void code_i2ll(int reg)
 {
     int reg0 = USE_CREG;
-    int creg0 = creg;
+    // int creg0 = creg;
 
     use_longlong(reg0);
-    use_register(creg0,REG_EAX,1);
-
-    printf("\tcltq\n");
-    lreg = creg = reg0;
+    use_register(reg0,REG_EAX,1);
+
+    printf("\tcltq\n"); // printf("\tmovslq %s,%s\n", reg, reg);
+    lreg = creg = REG_EAX;
 }
 
 void code_i2ull(int reg)
--- a/mc-code-ia32.c	Mon Nov 15 12:17:59 2010 +0900
+++ b/mc-code-ia32.c	Tue Nov 16 19:36:40 2010 +0900
@@ -549,7 +549,7 @@
 
     char *move_op;
     code_clear_stack_reg(reg1); 
-    move_op = (regs[reg1]||regs[reg1])?"\txchg %s,%s\n":"\tmovl %s,%s\n";
+    move_op = (regs[reg1])?"\txchg %s,%s\n":"\tmovl %s,%s\n";
     if (move && reg0!=reg1) {
 	printf(move_op,reg_name[reg0],reg_name[reg1]);
 	if (!regs[reg1]) regs[reg1]=USING_REG;
--- a/mc-codegen.c	Mon Nov 15 12:17:59 2010 +0900
+++ b/mc-codegen.c	Tue Nov 16 19:36:40 2010 +0900
@@ -2755,7 +2755,7 @@
     }
 
     g_expr(e3);
-    if (car(e2)==LREGISTER) {
+    if (car(e2)==LREGISTER||car(e2)==REGISTER) {
         emit_lpush();
         code_register_lassop(cadr(e2),op);
         if (use)
--- a/mc-parse.c	Mon Nov 15 12:17:59 2010 +0900
+++ b/mc-parse.c	Tue Nov 16 19:36:40 2010 +0900
@@ -1099,7 +1099,7 @@
     case UNSIGNED:
 	t = UNSIGNED;
 	if(getsym(0)==INT) {
-            t = lp64?ULONGLONG:UNSIGNED;
+            t = UNSIGNED;         // unsigend int
             getsym(0);
 	} else if (sym==CHAR) { getsym(0); t = UCHAR; }
 	else if (sym==SHORT) { 
--- a/test/code-gen-all.c	Mon Nov 15 12:17:59 2010 +0900
+++ b/test/code-gen-all.c	Tue Nov 16 19:36:40 2010 +0900
@@ -184,6 +184,8 @@
 	code_cond_fff();
 	code_cond_ddd();
 	code_cond_float();
+	code_d2f();
+	code_f2d();
 #endif
 #if LONGLONG_CODE 
 	code_cond_lll();
--- a/test/code-gen.c	Mon Nov 15 12:17:59 2010 +0900
+++ b/test/code-gen.c	Tue Nov 16 19:36:40 2010 +0900
@@ -3518,6 +3518,31 @@
      printf("#3517:%f\n",f);
 }
 
+INLINE static float
+ d2f(double d) {
+    return (float)d;
+}
+
+INLINE static float
+ f2d(float d) {
+    return (double)d;
+}
+
+INLINE void
+code_d2f()
+{
+    double d = 0.1;
+    printf("code_d2f %g\n",d2f(d));
+}
+
+INLINE void
+code_f2d()
+{
+    double f = 0.1;
+    printf("code_f2d %g\n",f2d(f));
+}
+
+
 #endif
 
 #if LONGLONG_CODE