Mercurial > hg > CbC > old > device
comparison mc-code-ia32.c @ 365:5ac17fa9d7e0
bit-field constant assignment
author | kono |
---|---|
date | Wed, 07 Jul 2004 14:34:25 +0900 |
parents | c29eebf3eaf4 |
children | 2d510935c37d |
comparison
equal
deleted
inserted
replaced
364:c29eebf3eaf4 | 365:5ac17fa9d7e0 |
---|---|
1284 use_longlong0(USE_CREG); | 1284 use_longlong0(USE_CREG); |
1285 regv[creg]=1; | 1285 regv[creg]=1; |
1286 } else if (ret_type==VOID) { | 1286 } else if (ret_type==VOID) { |
1287 regv[freg]=0; regv[creg]=0; | 1287 regv[freg]=0; regv[creg]=0; |
1288 } else { | 1288 } else { |
1289 if (!is_int_reg(creg)) { | |
1290 lreg=0; creg=virtual(REG_EAX); | |
1291 } | |
1289 use_register(creg,REG_EAX,0); | 1292 use_register(creg,REG_EAX,0); |
1290 fregv[freg]=0; regv[creg]=1; | 1293 fregv[freg]=0; regv[creg]=1; |
1291 } | 1294 } |
1292 stack_depth = stack_depth_save; | 1295 stack_depth = stack_depth_save; |
1293 return ret_type; | 1296 return ret_type; |
3458 mask = make_mask(32-bitpos-bitsize,31-bitpos); | 3461 mask = make_mask(32-bitpos-bitsize,31-bitpos); |
3459 make_mask_and_or(mask,value,lvalue); | 3462 make_mask_and_or(mask,value,lvalue); |
3460 } | 3463 } |
3461 } | 3464 } |
3462 | 3465 |
3466 | |
3467 static void | |
3468 make_mask_and_or_const(int mask,int reg,int c) | |
3469 { | |
3470 int a; | |
3471 // printf("# mask 0x%08x ~0x%08x\n",mask,~mask); | |
3472 a = ~mask|c; | |
3473 if (a!=-1) { | |
3474 /* do conjunction */ | |
3475 if (rname[reg]<MAX_DATA_REG && ((a& ~0xffff)==~0xffff)) { | |
3476 if ((a& ~0xff)==~0xff) | |
3477 printf("\tandb $%d,%s\n",a&0xff,register_name(reg,1)); | |
3478 else | |
3479 printf("\tandw $%d,%s\n",a&0xffff,register_name(reg,2)); | |
3480 } else | |
3481 printf("\tandl $%d,%s\n",a,register_name(reg,0)); | |
3482 } | |
3483 /* make or-mask */ | |
3484 c = mask&c; | |
3485 if (c!=0) { | |
3486 /* do disjunction */ | |
3487 if (rname[reg]<MAX_DATA_REG && (!(c& ~0xffff))) { | |
3488 if (!(c& ~0xff)) | |
3489 printf("\torb $%d,%s\n",c&0xff,register_name(reg,1)); | |
3490 else | |
3491 printf("\torw $%d,%s\n",c&0xffff,register_name(reg,2)); | |
3492 } else | |
3493 printf("\torl $%d,%s\n",c,register_name(reg,0)); | |
3494 } | |
3495 } | |
3496 | |
3497 extern void | |
3498 code_bit_replace_const(int value,int lvalue,int type,int bitpos) | |
3499 { | |
3500 int sign,bitsz,l,align; | |
3501 int bitsize = cadddr(type); | |
3502 int mask = 0; | |
3503 int c; | |
3504 #if LONGLONG_CODE | |
3505 long long lc; | |
3463 #endif | 3506 #endif |
3507 set_bitsz(type,&sign,&bitsz,&align,&l); | |
3508 // printf("# %d: bitpos=%d bitsize=%d bitsz=%d\n",lineno,bitpos,bitsize,bitsz); | |
3509 if (l) { | |
3510 #if LONGLONG_CODE | |
3511 use_longlong(lvalue); | |
3512 /* shift left */ | |
3513 lc = lcadr(value); | |
3514 lc <<= bitpos; | |
3515 if (bitpos+bitsize>=32) { | |
3516 /* make and-mask upper */ | |
3517 mask = make_mask(64-bitpos-bitsize,bitpos>=32?63-bitpos:31); | |
3518 make_mask_and_or_const(mask, | |
3519 virtual(lvalue==REG_L?REG_EDI:REG_EDX),(int)(lc>>32)); | |
3520 } | |
3521 if (bitpos<32) { | |
3522 /* make and-mask lower */ | |
3523 mask = make_mask(bitpos+bitsize>=32?0:32-bitpos-bitsize,31-bitpos); | |
3524 make_mask_and_or_const(mask, | |
3525 virtual(lvalue==REG_L?REG_ESI:REG_EAX),(int)(lc)); | |
3526 } | |
3527 #endif | |
3528 } else { | |
3529 use_int(lvalue); | |
3530 /* shift left */ | |
3531 c = cadr(value); | |
3532 c <<= bitpos; | |
3533 /* make and-mask */ | |
3534 mask = make_mask(32-bitpos-bitsize,31-bitpos); | |
3535 make_mask_and_or_const(mask,lvalue,c); | |
3536 } | |
3537 } | |
3538 | |
3539 | |
3540 #endif | |
3464 | 3541 |
3465 /* end */ | 3542 /* end */ |