diff mc-code-i64.c @ 790:a26d87f93c65

i64 bitfiled
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 21 Nov 2010 23:03:37 +0900
parents 9b1558a9151b
children 75e30aea08cd
line wrap: on
line diff
--- a/mc-code-i64.c	Sun Nov 21 17:28:49 2010 +0900
+++ b/mc-code-i64.c	Sun Nov 21 23:03:37 2010 +0900
@@ -4891,7 +4891,7 @@
     int sign=0,bitsz=1; 
     int align=4,l=0;
     *pbitpos = cadr(caddr(type));
-    *pbitsize = caddr(caddr(type));
+    int bitsize = *pbitsize = caddr(caddr(type));
 
     switch(cadr(type)) { 
     case INT:		sign=1; bitsz=32; align=4;break; 
@@ -4900,8 +4900,8 @@
     case UCHAR: 		bitsz= 8; align=1;break; 
     case SHORT:         sign=1; bitsz=16; align=2;break; 
     case USHORT:        sign=1; bitsz=16; align=2;break; 
-    case LONGLONG:      sign=1; bitsz=64; align=4;l=1; break; 
-    case ULONGLONG:            	bitsz=64; align=4;l=1; break; 
+    case LONGLONG:      sign=1; bitsz=64; align=bitsize>32?8:4;l=1; break; 
+    case ULONGLONG:            	bitsz=64; align=bitsize>32?8:4;l=1; break; 
     default: error(-1);
     }
     *psign = sign;
@@ -5003,37 +5003,37 @@
 /* bit field replacement */
 
 static void
-make_mask_and_or(int mask,int reg)
+make_mask_and_or(int mask,int reg, int dest)
 {
 printf("## mask 0x%08x ~0x%08x\n",mask,~mask);
 	printf("\tpushq %s\n",register_name(reg,0));
 	/* make and-mask  */
 	oprtc(BOR,reg,list2(CONST,~mask));
 	/* do conjunction  */
-	printf("\tandl %s,%s\n",register_name(reg,SIZE_OF_INT),register_name(ireg,SIZE_OF_INT));
+	printf("\tandl %s,%s\n",register_name(reg,SIZE_OF_INT),register_name(dest,SIZE_OF_INT));
 	/* make or-mask  */
 	printf("\tpopq %s\n",register_name(reg,0));
 	oprtc(BAND,reg,list2(CONST,mask));
 	/* do disjunction  */
-	printf("\torl %s,%s\n",register_name(reg,SIZE_OF_INT),register_name(ireg,SIZE_OF_INT));
-	printf("\txchg %s,%s\n",register_name(reg,SIZE_OF_INT),register_name(ireg,SIZE_OF_INT));
+	printf("\torl %s,%s\n",register_name(reg,SIZE_OF_INT),register_name(dest,SIZE_OF_INT));
+	printf("\txchg %s,%s\n",register_name(reg,SIZE_OF_INT),register_name(dest,SIZE_OF_INT));
 }
 
 static void
-make_mask_and_or_l(long mask,int reg)
+make_mask_and_or_l(long mask,int reg, int dest)
 {
         printf("## mask 0x%08lx ~0x%08lx\n",mask,~mask);
 	printf("\tpushq %s\n",register_name(reg,0));
 	/* make and-mask  */
-	loprtc(BOR,reg,llist2(CONST,~mask));
+	loprtc(BOR,reg,llist2(LCONST,~mask));
 	/* do conjunction  */
-	printf("\tandq %s,%s\n",register_name(reg,0),register_name(ireg,0));
+	printf("\tandq %s,%s\n",register_name(reg,0),register_name(dest,0));
 	/* make or-mask  */
 	printf("\tpopq %s\n",register_name(reg,0));
-	oprtc(BAND,reg,list2(CONST,mask));
+	loprtc(BAND,reg,llist2(LCONST,mask));
 	/* do disjunction  */
-	printf("\torq %s,%s\n",register_name(reg,0),register_name(ireg,0));
-	printf("\txchgq %s,%s\n",register_name(reg,0),register_name(ireg,0));
+	printf("\torq %s,%s\n",register_name(reg,0),register_name(dest,0));
+	printf("\txchgq %s,%s\n",register_name(reg,0),register_name(dest,0));
 }
 
 extern void
@@ -5048,23 +5048,24 @@
 // printf("## %d: bitpos=%d bitsize=%d bitsz=%d\n",lineno,bitpos,bitsize,bitsz);
     if (l) {
 #if LONGLONG_CODE
-	use_int(adr);
+	// use_int(adr);
 	use_longlong(value);
 	/* shift left */
 	if (bitpos) 
 	    loprtc(LLSHIFT,value,list2(CONST,bitpos));
 	/* make and-mask */
 	printf("\tpushq %s\n",register_name(adr,0)); 
-	printf("\t%s %d(%s),%s\n",cload(sign,size),4,register_name(adr,0),
+	printf("\t%s (%s),%s\n",cload(sign,size),register_name(adr,0),
 		    register_name(adr,regu(sign,size,0)));
-	mask = make_mask(64-bitpos-bitsize,63-bitpos);
-	make_mask_and_or_l(mask,value);
+	mask = make_mask_64(64-bitpos-bitsize,63-bitpos);
+	make_mask_and_or_l(mask,value, adr);
+	set_lreg(value,0);
 	printf("\tpopq %s\n",register_name(adr,0));
 	printf("\t%s %s,(%s)\n",move(0),
                register_name(value,0), register_name(adr,0));
 #endif
     } else {
-	use_int(adr);
+	// use_int(adr);
 	use_int(value);
 	printf("\tpushq %s\n",register_name(adr,0));
 	printf("\t%s %d(%s),%s\n",cload(sign,size),0,register_name(adr,0),
@@ -5074,7 +5075,8 @@
 	    oprtc(LSHIFT,value,list2(CONST,bitpos));
 	/* make and-mask */
 	mask = make_mask(32-bitpos-bitsize,31-bitpos);
-	make_mask_and_or(mask,value);
+	make_mask_and_or(mask,value, adr);
+	set_ireg(value,0);
 	printf("\tpopq %s\n",register_name(adr,0));
         code_assign(adr,size==4?0:size,value);
     }
@@ -5147,11 +5149,12 @@
 	lc = lcadr(value);
 	lc <<= bitpos;
 	
-	printf("\t%s %d(%s),%s\n",cload(sign,size),4,register_name(adr,regu(sign,size,0)),
+	printf("\t%s (%s),%s\n",cload(sign,size),register_name(adr,regu(sign,size,0)),
 		    register_name(lvalue,0));
 	/* make and-mask upper */
-	mask = make_mask(64-bitpos-bitsize,63-bitpos);
+	mask = make_mask_64(64-bitpos-bitsize,63-bitpos);
 	make_mask_and_or_const(mask,lvalue,lc);
+	set_lreg(lvalue,0);
 	printf("\t%s %s,(%s)\n",move(0),register_name(lvalue,0),
 		    register_name(adr,0));
 	free_register(lvalue);
@@ -5166,6 +5169,7 @@
 	/* make and-mask */
 	mask = make_mask(32-bitpos-bitsize,31-bitpos);
 	make_mask_and_or_const(mask,lvalue,c);
+	set_ireg(lvalue,0);
         code_assign(adr,size,lvalue);
 	free_register(lvalue);
     }