Mercurial > hg > CbC > old > device
comparison mc-code-powerpc.c @ 527:6b0fd56848e6 inline-asm
inline continue....
asm, lvar free
author | kono |
---|---|
date | Wed, 28 Dec 2005 21:21:57 +0900 |
parents | 9ff5cd7afe2f |
children | d6fff671793a |
comparison
equal
deleted
inserted
replaced
526:9ff5cd7afe2f | 527:6b0fd56848e6 |
---|---|
1240 void | 1240 void |
1241 code_const(int e2,int reg) { | 1241 code_const(int e2,int reg) { |
1242 char *crn; | 1242 char *crn; |
1243 use_int(reg); | 1243 use_int(reg); |
1244 crn = register_name(reg); | 1244 crn = register_name(reg); |
1245 // printf("# 0x%08x\n",e2); | 1245 // printf("## 0x%08x\n",e2); |
1246 if (-32768<e2&&e2<32768) | 1246 if (-32768<e2&&e2<32768) |
1247 printf("\tli %s,%d\n",crn,e2); | 1247 printf("\tli %s,%d\n",crn,e2); |
1248 else { | 1248 else { |
1249 printf("\tlis %s,ha16(%d)\n",crn,e2); | 1249 printf("\tlis %s,ha16(%d)\n",crn,e2); |
1250 printf("\taddi %s,%s,lo16(%d)\n",crn,crn,e2); | 1250 printf("\taddi %s,%s,lo16(%d)\n",crn,crn,e2); |
5162 int r; | 5162 int r; |
5163 int c; | 5163 int c; |
5164 int val; | 5164 int val; |
5165 int clobber = 0; | 5165 int clobber = 0; |
5166 | 5166 |
5167 printf("# constraint %s\n",p); | 5167 printf("## constraint %s\n",p); |
5168 if (*p=='=') { | 5168 retry: |
5169 switch((c=*p)) { | |
5170 case '?': | |
5171 case '!': | |
5172 case '+': | |
5173 case '%': | |
5174 case '#': | |
5175 case '*': | |
5176 case '=': | |
5169 // output register | 5177 // output register |
5170 p++; | 5178 p++; |
5171 } | 5179 goto retry; |
5172 if (*p=='&') { | 5180 case '&': |
5173 // earlyclobber | 5181 // earlyclobber |
5174 p++; | 5182 p++; |
5175 clobber = 1; | 5183 clobber = 1; |
5176 } | 5184 goto retry; |
5177 c = *p; | 5185 case 'b': // address base register (what?) |
5178 if (c=='r') { | 5186 case 'r': |
5179 if (mode==ASM_INPUT) { | 5187 if (mode==ASM_INPUT) { |
5180 for(;repl0;repl0 = cadr(repl0)) { | 5188 for(;repl0;repl0 = cadr(repl0)) { |
5181 if (car(car(repl0))==REGISTER && caddr(repl0)==0) { | 5189 if (car(car(repl0))==REGISTER && caddr(repl0)==0) { |
5182 r = cadr(car(repl0)); | 5190 r = cadr(car(repl0)); |
5183 caddr(repl0) = ASM_USED; | 5191 caddr(repl0) = ASM_USED; |
5187 r = get_register(); | 5195 r = get_register(); |
5188 } else { | 5196 } else { |
5189 r = get_register(); | 5197 r = get_register(); |
5190 } | 5198 } |
5191 repl = list3(list2(REGISTER,r),repl,clobber); | 5199 repl = list3(list2(REGISTER,r),repl,clobber); |
5192 } else if (c=='m') { | 5200 break; |
5201 case 'm': | |
5193 repl = list3(list2(0,0),repl,clobber); | 5202 repl = list3(list2(0,0),repl,clobber); |
5194 } else if (c=='i') { | 5203 break; |
5204 case 'i': | |
5195 if (car(e1)==GVAR) { | 5205 if (car(e1)==GVAR) { |
5196 e1=list3(FNAME,(int)(((NMTBL *)caddr(e1))->nm),0); | 5206 e1=list3(FNAME,(int)(((NMTBL *)caddr(e1))->nm),0); |
5197 } else if (car(e1)==FNAME) { | 5207 } else if (car(e1)==FNAME) { |
5198 e1=list3(FNAME,(int)(((NMTBL *)cadr(e1))->nm),0); | 5208 e1=list3(FNAME,(int)(((NMTBL *)cadr(e1))->nm),0); |
5199 } else if (car(e1)==STRING) { | 5209 } else if (car(e1)==STRING) { |
5201 ascii((char*)cadr(e1)); | 5211 ascii((char*)cadr(e1)); |
5202 e1=list3(STRING,val,0); | 5212 e1=list3(STRING,val,0); |
5203 } else if (car(e1)==CONST) { | 5213 } else if (car(e1)==CONST) { |
5204 } else error(-1); | 5214 } else error(-1); |
5205 repl = list3(e1,repl,clobber); | 5215 repl = list3(e1,repl,clobber); |
5206 } else if (digit(c)) { | 5216 break; |
5217 case '0': case '1': case '2': case '3': case '4': | |
5218 case '5': case '6': case '7': case '8': case '9': | |
5207 val = 0; | 5219 val = 0; |
5208 do { val = val*10 + c-'0'; } while (digit(c=*p++)); | 5220 do { val = val*10 + c-'0'; } while (digit(c=*p++)); |
5209 if (val>MAX_ASM_REG) error(-1); // too large register | 5221 if (val>MAX_ASM_REG) error(-1); // too large register |
5210 if (n-val<0) error(-1); | 5222 if (n-val<0) error(-1); |
5211 repl = list3(car(nth(n-val-1,repl0)),repl,clobber); | 5223 repl = list3(car(nth(n-val-1,repl0)),repl,clobber); |
5212 } else error(-1); | 5224 break; |
5225 default: | |
5226 printf("### unknown asm constraint %c\n",c); | |
5227 } | |
5213 return repl; | 5228 return repl; |
5214 } | 5229 } |
5215 | 5230 |
5216 void | 5231 void |
5217 code_free_asm_operand(int repl) | 5232 code_free_asm_operand(int repl) |
5323 /* alignment is correct and space remains */ | 5338 /* alignment is correct and space remains */ |
5324 *poffset=offset=i; | 5339 *poffset=offset=i; |
5325 i = l+bitsize; | 5340 i = l+bitsize; |
5326 *bfd = (i==bitsz)?0:i; | 5341 *bfd = (i==bitsz)?0:i; |
5327 *sz = (i+7)/8; | 5342 *sz = (i+7)/8; |
5328 // printf("# bitpos=%d bitsize=%d bitsz=%d offset=%d\n",l,bitsize,bitsz,*poffset); | 5343 // printf("## bitpos=%d bitsize=%d bitsz=%d offset=%d\n",l,bitsize,bitsz,*poffset); |
5329 return l; | 5344 return l; |
5330 } | 5345 } |
5331 } | 5346 } |
5332 } | 5347 } |
5333 | 5348 |
5338 } | 5353 } |
5339 bitpos = 0; | 5354 bitpos = 0; |
5340 *bfd = (bitsize==bitsz)?0:bitsize; | 5355 *bfd = (bitsize==bitsz)?0:bitsize; |
5341 *sz = (bitsize+7)/8; | 5356 *sz = (bitsize+7)/8; |
5342 | 5357 |
5343 // printf("# bitpos=%d bitsize=%d bitsz=%d offset=%d\n",bitpos,bitsize,bitsz,*poffset); | 5358 // printf("## bitpos=%d bitsize=%d bitsz=%d offset=%d\n",bitpos,bitsize,bitsz,*poffset); |
5344 return bitpos; | 5359 return bitpos; |
5345 } | 5360 } |
5346 | 5361 |
5347 /* bit field value */ | 5362 /* bit field value */ |
5348 | 5363 |
5352 int sign,bitsz,l,align; | 5367 int sign,bitsz,l,align; |
5353 int bitsize,bitpos; | 5368 int bitsize,bitpos; |
5354 int i,size; | 5369 int i,size; |
5355 set_bitsz(type,&bitpos,&bitsize,&sign,&bitsz,&align,&l); | 5370 set_bitsz(type,&bitpos,&bitsize,&sign,&bitsz,&align,&l); |
5356 size = bitsz/8; | 5371 size = bitsz/8; |
5357 // printf("# %d: bitpos=%d bitsize=%d bitsz=%d\n",lineno,bitpos,bitsize,bitsz); | 5372 // printf("## %d: bitpos=%d bitsize=%d bitsz=%d\n",lineno,bitpos,bitsize,bitsz); |
5358 /* this implementation returns -1 for int i:1; */ | 5373 /* this implementation returns -1 for int i:1; */ |
5359 if (l==1) { | 5374 if (l==1) { |
5360 #if LONGLONG_CODE | 5375 #if LONGLONG_CODE |
5361 // use_int(adr); | 5376 // use_int(adr); |
5362 use_longlong(reg); | 5377 use_longlong(reg); |
5386 /* bit field replacement */ | 5401 /* bit field replacement */ |
5387 | 5402 |
5388 static void | 5403 static void |
5389 make_mask_and_or(int mask,int tmp,char *trn,char *crn,char *lrn) | 5404 make_mask_and_or(int mask,int tmp,char *trn,char *crn,char *lrn) |
5390 { | 5405 { |
5391 // printf("# mask 0x%08x ~0x%08x\n",mask,~mask); | 5406 // printf("## mask 0x%08x ~0x%08x\n",mask,~mask); |
5392 code_const(~mask,tmp); | 5407 code_const(~mask,tmp); |
5393 printf("\tor %s,%s,%s\n",trn,crn,trn); | 5408 printf("\tor %s,%s,%s\n",trn,crn,trn); |
5394 /* do conjunction */ | 5409 /* do conjunction */ |
5395 printf("\tand %s,%s,%s\n",lrn,trn,lrn); | 5410 printf("\tand %s,%s,%s\n",lrn,trn,lrn); |
5396 /* make or-mask */ | 5411 /* make or-mask */ |
5470 static void | 5485 static void |
5471 make_mask_and_or_const(int mask,char *crn,int c) | 5486 make_mask_and_or_const(int mask,char *crn,int c) |
5472 { | 5487 { |
5473 char *trn; | 5488 char *trn; |
5474 int tmp = -1; | 5489 int tmp = -1; |
5475 // printf("# mask 0x%08x ~0x%08x\n",mask,~mask); | 5490 // printf("## mask 0x%08x ~0x%08x\n",mask,~mask); |
5476 if ((~mask|c)!=-1) { | 5491 if ((~mask|c)!=-1) { |
5477 trn = register_name(tmp=get_register()); | 5492 trn = register_name(tmp=get_register()); |
5478 code_const((~mask|c),tmp); | 5493 code_const((~mask|c),tmp); |
5479 /* do conjunction */ | 5494 /* do conjunction */ |
5480 printf("\tand %s,%s,%s\n",crn,trn,crn); | 5495 printf("\tand %s,%s,%s\n",crn,trn,crn); |