diff mc-code-powerpc.c @ 779:a0f84a0a990a

float value sharing
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Fri, 19 Nov 2010 14:09:56 +0900
parents a177c65f3e37
children c5315f472912
line wrap: on
line diff
--- a/mc-code-powerpc.c	Fri Nov 19 04:39:47 2010 +0900
+++ b/mc-code-powerpc.c	Fri Nov 19 14:09:56 2010 +0900
@@ -4242,49 +4242,68 @@
     return *j;
 }
 
+static void emit_dconst0(ValuePtr value, int lb, void *arg)
+{
+    long d = (long) arg;
+    printf(" \t.data\n\t.align 3\n");
+    lb=fwdlabel();
+    printf("%s%d:\n",lpfx,lb);
+    if (d) {
+#if ENDIAN_D==0
+	printf("\t.long\t0x%x,0x%x\n",code_d1(value->d),code_d2(value->d));
+#else
+	printf("\t.long\t0x%x,0x%x\n",code_d2(value->d),code_d1(value->d));
+#endif
+    } else {
+	printf("\t.long\t0x%x\n",code_f(value->i));
+    }
+    if (output_mode==TEXT_EMIT_MODE) {
+	printf(".text\n");
+    } else {
+	text_mode(0);
+    }
+}
+
+/* load double / float const
+   we should keep what constant we have create
+ */
+
 void
 code_dconst(int e2,int freg,int d)
 { 
     int lb;
-    double value = dcadr(e2);
+    Value value;
+    value.d = dcadr(e2);
     int r;
     char *rrn,*frn;
-
     use_float(d,freg);
     frn = fregister_name(freg);
-    if (value==0.0) {
+    if (value.d==0.0) {
 	float_zero_lib_used=1;
 	r = get_ptr_cache(&float_zero);
 	rrn = register_name(r);
 	printf("\tlfs %s,0(%s)\n",frn,rrn);
 	return;
     }
-    if (value==1.0) {
+    if (value.d==1.0) {
 	float_one_lib_used=1;
 	r = get_ptr_cache(&float_one);
 	rrn = register_name(r);
 	printf("\tlfs %s,0(%s)\n",frn,rrn);
 	return;
     }
+    if (d) {
+       sz = sizeof(double);
+    } else {
+       sz = sizeof(float);
+       value.f = (float) value.d;
+    }
+
+    long d_mode = d;
+    int lb = get_data_label(&value,sz,emit_dconst0, (void*) d_mode);
+
     rrn = register_name((r=get_register()));
     use_reg(r); // to clear ptr cache
-    printf(" \t.data\n\t.align 3\n");
-    lb=fwdlabel();
-    printf("%s%d:\n",lpfx,lb);
-    if (d) {
-#if ENDIAN_D==0
-	printf("\t.long\t0x%x,0x%x\n",code_d1(value),code_d2(value));
-#else
-	printf("\t.long\t0x%x,0x%x\n",code_d2(value),code_d1(value));
-#endif
-    } else {
-	printf("\t.long\t0x%x\n",code_f(value));
-    }
-    if (output_mode==TEXT_EMIT_MODE) {
-	printf(".text\n");
-    } else {
-	text_mode(0);
-    }
     code_label_value(lb,r);
     if (d) {
 	printf("\tlfd %s,0(%s)\n",frn,rrn);