Mercurial > hg > CbC > old > device
comparison mc-code-powerpc.c @ 331:f25aa4f03198
bit-field continue...
author | kono |
---|---|
date | Wed, 23 Jun 2004 22:37:32 +0900 |
parents | fa4c7b15d7ed |
children | ce85d6106119 |
comparison
equal
deleted
inserted
replaced
330:fa4c7b15d7ed | 331:f25aa4f03198 |
---|---|
1856 | 1856 |
1857 static void | 1857 static void |
1858 increment_function_arg(int e3,int *pnargs,int *preg_arg,int *pfreg_arg) { | 1858 increment_function_arg(int e3,int *pnargs,int *preg_arg,int *pfreg_arg) { |
1859 int nargs=0,reg_arg=0,freg_arg=0; | 1859 int nargs=0,reg_arg=0,freg_arg=0; |
1860 int t=caddr(e3); | 1860 int t=caddr(e3); |
1861 if (t>=0&&(car(t)==BIT_FIELD)) { | |
1862 t = cadr(t); | |
1863 } | |
1861 if(scalar(t)) { | 1864 if(scalar(t)) { |
1862 nargs ++ ; reg_arg++; | 1865 nargs ++ ; reg_arg++; |
1863 } else if (t==LONGLONG||t==ULONGLONG) { | 1866 } else if (t==LONGLONG||t==ULONGLONG) { |
1864 nargs ++ ; reg_arg++; | 1867 nargs ++ ; reg_arg++; |
1865 nargs ++ ; reg_arg++; | 1868 nargs ++ ; reg_arg++; |
1884 #define AS_ARG 0 | 1887 #define AS_ARG 0 |
1885 | 1888 |
1886 static int | 1889 static int |
1887 get_input_arg(int t,int mode,int nargs,int reg_arg,int freg_arg) | 1890 get_input_arg(int t,int mode,int nargs,int reg_arg,int freg_arg) |
1888 { | 1891 { |
1892 if (t>=0&&(car(t)==BIT_FIELD)) { | |
1893 t = cadr(t); | |
1894 } | |
1889 if(scalar(t)) { | 1895 if(scalar(t)) { |
1890 if (mode==AS_SAVE) { | 1896 if (mode==AS_SAVE) { |
1891 return get_register_var(0); | 1897 return get_register_var(0); |
1892 } else if (reg_arg>=MAX_INPUT_REGISTER_VAR) { | 1898 } else if (reg_arg>=MAX_INPUT_REGISTER_VAR) { |
1893 return list2(LVAR,caller_arg_offset_v(nargs)); | 1899 return list2(LVAR,caller_arg_offset_v(nargs)); |
5078 | 5084 |
5079 static void | 5085 static void |
5080 set_bitsz(int type,int *psign,int *pbitsz,int *palign,int *pl) | 5086 set_bitsz(int type,int *psign,int *pbitsz,int *palign,int *pl) |
5081 { | 5087 { |
5082 int sign=0,bitsz; | 5088 int sign=0,bitsz; |
5089 int align,l=0; | |
5083 switch(cadr(type)) { | 5090 switch(cadr(type)) { |
5084 case INT: sign=1; bitsz=32; align=4;break; | 5091 case INT: sign=1; bitsz=32; align=4;break; |
5085 case UNSIGNED: bitsz=32; align=4;break; | 5092 case UNSIGNED: bitsz=32; align=4;break; |
5086 case CHAR: sign=1; bitsz=24; align=1;break; | 5093 case CHAR: sign=1; bitsz=24; align=1;break; |
5087 case UCHAR: bitsz=24; align=1;break; | 5094 case UCHAR: bitsz=24; align=1;break; |
5103 */ | 5110 */ |
5104 | 5111 |
5105 extern int | 5112 extern int |
5106 code_bit_field_disp(int type,int *poffset,int *bfd,int *sz) | 5113 code_bit_field_disp(int type,int *poffset,int *bfd,int *sz) |
5107 { | 5114 { |
5108 int sign,bitsz; | 5115 int sign,bitsz,align; |
5109 int i; | 5116 int i; |
5110 int bitpos = *bfd; | 5117 int bitpos = *bfd; |
5111 int offset = *poffset; | 5118 int offset = *poffset; |
5112 int l; | 5119 int l; |
5113 int bitsize = cadddr(type); | 5120 int bitsize = cadddr(type); |
5114 set_bitsz(type,&sign,&bitsz,&l); | 5121 set_bitsz(type,&sign,&bitsz,&align,&l); |
5115 | 5122 |
5116 if (bitsize>bitsz) { error(BTERR); bitsize = i; } | 5123 if (bitsize>bitsz) { error(BTERR); bitsize = i; } |
5117 | 5124 |
5118 /* bfd means previous bit field bit offset */ | 5125 /* bfd means previous bit field bit offset */ |
5119 if (bitpos) { | 5126 if (bitpos) { |
5148 | 5155 |
5149 /* bit field value */ | 5156 /* bit field value */ |
5150 | 5157 |
5151 /* reg contains container value, result should be in reg */ | 5158 /* reg contains container value, result should be in reg */ |
5152 extern void | 5159 extern void |
5153 code_bit_field(int type,int bit_offset,int bit_size,int reg) | 5160 code_bit_field(int type,int bitpos,int reg) |
5154 { | 5161 { |
5155 int sign,bitsz,l; | 5162 int sign,bitsz,l,align; |
5156 int bitsize = cadddr(type); | 5163 int bitsize = cadddr(type); |
5157 int i; | 5164 int i; |
5158 set_bitsz(type,&sign,&bitsz,&l); | 5165 set_bitsz(type,&sign,&bitsz,&align,&l); |
5159 /* this implementation returns -1 for int i:1; */ | 5166 /* this implementation returns -1 for int i:1; */ |
5160 if (l==1) { | 5167 if (l==1) { |
5161 use_longlong(reg); | 5168 use_longlong(reg); |
5162 /* shift left */ | 5169 /* shift left */ |
5163 if (bit_offset) | 5170 if (bitpos) |
5164 loprtc(LLSHIFT,reg,bit_offset); | 5171 loprtc(LLSHIFT,reg,bitpos); |
5165 /* shift right */ | 5172 /* shift right */ |
5166 if ((i=bitsz-bitsize)) | 5173 if ((i=bitsz-bitsize)) |
5167 loprtc(sign?LRSHIFT:LRUSHIFT,reg,i); | 5174 loprtc(sign?LRSHIFT:LURSHIFT,reg,i); |
5168 } else { | 5175 } else { |
5169 use_int(reg); | 5176 use_int(reg); |
5170 /* shift left */ | 5177 /* shift left */ |
5171 if (bit_offset) | 5178 if (bitpos) |
5172 oprtc(LSHIFT,reg,bit_offset); | 5179 oprtc(LSHIFT,reg,bitpos); |
5173 /* shift right */ | 5180 /* shift right */ |
5174 if ((i=bitsz-bitsize)) | 5181 if ((i=bitsz-bitsize)) |
5175 oprtc(sign?RSHIFT:RUSHIFT,reg,i); | 5182 oprtc(sign?RSHIFT:URSHIFT,reg,i); |
5176 } | 5183 } |
5177 } | 5184 } |
5178 | 5185 |
5179 /* bit field replacement */ | 5186 /* bit field replacement */ |
5180 | 5187 |
5183 { | 5190 { |
5184 int mask = 0; | 5191 int mask = 0; |
5185 int bit = 1; | 5192 int bit = 1; |
5186 int i; | 5193 int i; |
5187 if (from<0||from>32) error(-1); | 5194 if (from<0||from>32) error(-1); |
5188 for (i=31;from<=i;i--,bit<<1) { | 5195 for (i=31;from<=i;i--,bit<<=1) { |
5189 if (i<=to) { | 5196 if (i<=to) { |
5190 mask |= bit; | 5197 mask |= bit; |
5191 } | 5198 } |
5192 } | 5199 } |
5200 return mask; | |
5193 } | 5201 } |
5194 | 5202 |
5195 static void | 5203 static void |
5196 make_mask_and_or(int mask,int tmp,char *trn,*crn,*lrn) | 5204 make_mask_and_or(int mask,int tmp,char *trn,char *crn,char *lrn) |
5197 { | 5205 { |
5198 code_const(~mask,tmp); | 5206 code_const(~mask,tmp); |
5199 printf("\tor %s,%s,%s\n",trn,crn,trn); | 5207 printf("\tor %s,%s,%s\n",trn,crn,trn); |
5200 /* do conjunction */ | 5208 /* do conjunction */ |
5201 printf("\tand %s,%s,%s\n",lrn,trn,lrn); | 5209 printf("\tand %s,%s,%s\n",lrn,trn,lrn); |
5205 /* do disjunction */ | 5213 /* do disjunction */ |
5206 printf("\tor %s,%s,%s\n",lrn,trn,lrn); | 5214 printf("\tor %s,%s,%s\n",lrn,trn,lrn); |
5207 } | 5215 } |
5208 | 5216 |
5209 extern void | 5217 extern void |
5210 code_bit_replace(int value,int lvalue,int type,int bit_offset) | 5218 code_bit_replace(int value,int lvalue,int type,int bitpos) |
5211 { | 5219 { |
5212 int sign,bitsz,l; | 5220 int sign,bitsz,l,align; |
5213 int bitsize = cadddr(type); | 5221 int bitsize = cadddr(type); |
5214 int mask = 0; | 5222 int mask = 0; |
5215 int tmp = -1; | 5223 int tmp = -1; |
5224 int i; | |
5216 char *crn,*lrn,*trn; | 5225 char *crn,*lrn,*trn; |
5217 set_bitsz(type,&sign,&bitsz,&l); | 5226 set_bitsz(type,&sign,&bitsz,&align,&l); |
5218 if (l) { | 5227 if (l) { |
5219 use_longlong(value); | 5228 use_longlong(value); |
5220 crn = lregister_name_low(value); | 5229 crn = lregister_name_low(value); |
5221 lrn = lregister_name_low(lvalue); | 5230 lrn = lregister_name_low(lvalue); |
5222 /* shift left */ | 5231 /* shift left */ |
5223 if ((i=bitsz-bitsize-bitpos)) | 5232 if ((i=bitsz-bitsize-bitpos)) |
5224 loprtc(LLSHIFT,reg,i); | 5233 loprtc(LLSHIFT,value,i); |
5225 trn = register_name(tmp = get_register()); | 5234 trn = register_name(tmp = get_register()); |
5226 if (bitpos+bitsize>32) { | 5235 if (bitpos+bitsize>32) { |
5227 /* make and-mask lower */ | 5236 /* make and-mask lower */ |
5228 mask = make_mask(bitpos>32?bitpos-32:0,bitpos+bitsize-32); | 5237 mask = make_mask(bitpos>32?bitpos-32:0,bitpos+bitsize-32); |
5229 make_mask_and_or(mask,tmp,trn,crn,lrn); | 5238 make_mask_and_or(mask,tmp,trn,crn,lrn); |
5239 use_int(value); | 5248 use_int(value); |
5240 crn = register_name(value); | 5249 crn = register_name(value); |
5241 lrn = register_name(lvalue); | 5250 lrn = register_name(lvalue); |
5242 /* shift left */ | 5251 /* shift left */ |
5243 if ((i=bitsz-bitsize-bitpos)) | 5252 if ((i=bitsz-bitsize-bitpos)) |
5244 oprtc(LSHIFT,reg,i); | 5253 oprtc(LSHIFT,value,i); |
5245 trn = register_name(tmp = get_register()); | 5254 trn = register_name(tmp = get_register()); |
5246 /* make and-mask */ | 5255 /* make and-mask */ |
5247 mask = make_mask(bitpos+(32-bitsz),bitpos+bitsize); | 5256 mask = make_mask(bitpos+(32-bitsz),bitpos+bitsize); |
5248 make_mask_and_or(mask,tmp,trn,crn,lrn); | 5257 make_mask_and_or(mask,tmp,trn,crn,lrn); |
5249 } | 5258 } |