comparison mc-code-powerpc.c @ 231:f5efe15629d4

*** empty log message ***
author kono
date Wed, 28 Apr 2004 21:33:45 +0900
parents d60c6c31f63a
children 8a23c20ac92d
comparison
equal deleted inserted replaced
230:d60c6c31f63a 231:f5efe15629d4
1140 } 1140 }
1141 1141
1142 void 1142 void
1143 code_preinc(int e1,int e2,int dir,int sign,int sz,int reg) { 1143 code_preinc(int e1,int e2,int dir,int sign,int sz,int reg) {
1144 char *xrn,*drn; 1144 char *xrn,*drn;
1145 int dreg;
1146 if (car(e2)==REGISTER) { 1145 if (car(e2)==REGISTER) {
1147 use_int(reg); 1146 use_int(reg);
1148 printf("\taddi %s,%s,%d\n", 1147 printf("\taddi %s,%s,%d\n",
1149 register_name(cadr(e2)),register_name(cadr(e2)), dir); 1148 register_name(cadr(e2)),register_name(cadr(e2)), dir);
1150 if (cadr(reg)!=e2) 1149 if (cadr(reg)!=e2)
1153 } 1152 }
1154 g_expr(e2); 1153 g_expr(e2);
1155 if (!is_int_reg(creg)) error(-1); 1154 if (!is_int_reg(creg)) error(-1);
1156 xrn = register_name(creg); 1155 xrn = register_name(creg);
1157 if (reg==USE_CREG) { 1156 if (reg==USE_CREG) {
1158 dreg=get_register(); if (!dreg) error(-1); 1157 reg=get_register(); if (!reg) error(-1);
1159 drn = register_name(dreg); 1158 drn = register_name(reg);
1160 set_ireg(dreg,0); 1159 set_ireg(reg,0);
1161 } else { 1160 } else {
1162 drn = register_name(reg); 1161 drn = register_name(reg);
1163 } 1162 }
1164 printf("\t%s %s,0(%s)\n",cload(sz),drn,xrn); 1163 printf("\t%s %s,0(%s)\n",cload(sz),drn,xrn);
1165 if (use) cext(sign,sz,dreg); 1164 if (use) cext(sign,sz,reg);
1166 printf("\taddi %s,%s,%d\n",drn,drn,dir); 1165 printf("\taddi %s,%s,%d\n",drn,drn,dir);
1167 printf("\t%s %s,0(%s)\n",cstore(sz),drn,xrn); 1166 printf("\t%s %s,0(%s)\n",cstore(sz),drn,xrn);
1168 } 1167 }
1169 1168
1170 1169
1171 void 1170 void
1172 code_postinc(int e1,int e2,int dir,int sign,int sz,int reg) { 1171 code_postinc(int e1,int e2,int dir,int sign,int sz,int reg) {
1173 char *xrn,*crn,*nrn; 1172 char *xrn,*crn,*nrn;
1174 int dreg,nreg; 1173 int nreg;
1175 if (car(e2)==REGISTER) { 1174 if (car(e2)==REGISTER) {
1176 use_int(reg); 1175 use_int(reg);
1177 printf("\tmr %s,%s\n",register_name(reg),register_name(cadr(e2))); 1176 printf("\tmr %s,%s\n",register_name(reg),register_name(cadr(e2)));
1178 printf("\taddi %s,%s,%d\n", 1177 printf("\taddi %s,%s,%d\n",
1179 register_name(cadr(e2)),register_name(cadr(e2)),dir); 1178 register_name(cadr(e2)),register_name(cadr(e2)),dir);
1183 if (!is_int_reg(creg)) error(-1); 1182 if (!is_int_reg(creg)) error(-1);
1184 crn = register_name(creg); 1183 crn = register_name(creg);
1185 nreg=get_register(); if (!nreg) error(-1); 1184 nreg=get_register(); if (!nreg) error(-1);
1186 nrn = register_name(nreg); 1185 nrn = register_name(nreg);
1187 if (reg==USE_CREG) { 1186 if (reg==USE_CREG) {
1188 dreg=get_register(); if (!dreg) error(-1); 1187 reg=get_register(); if (!reg) error(-1);
1189 xrn = register_name(dreg); 1188 xrn = register_name(reg);
1190 set_ireg(dreg,0); 1189 set_ireg(reg,0);
1191 } else { 1190 } else {
1192 xrn = register_name(reg); 1191 xrn = register_name(reg);
1193 } 1192 }
1194 printf("\t%s %s,0(%s)\n",cload(sz),xrn,crn); 1193 printf("\t%s %s,0(%s)\n",cload(sz),xrn,crn);
1195 if (use) cext(sign,sz,reg); 1194 if (use) cext(sign,sz,reg);
3203 } 3202 }
3204 3203
3205 void 3204 void
3206 drexpr(int e1, int e2,int l1, int op,int cond) 3205 drexpr(int e1, int e2,int l1, int op,int cond)
3207 { 3206 {
3208 if (cond) { 3207 if (!cond) {
3209 switch(op) { 3208 switch(op) {
3210 case FOP+GT: 3209 case FOP+GT:
3211 drexpr(e2,e1,l1,FOP+GE,0); break; 3210 drexpr(e2,e1,l1,FOP+GE,1); break;
3212 case FOP+GE: 3211 case FOP+GE:
3213 drexpr(e2,e1,l1,FOP+GT,0); break; 3212 drexpr(e2,e1,l1,FOP+GT,1); break;
3214 case FOP+EQ: 3213 case FOP+EQ:
3215 op=FOP+NEQ; break; 3214 op=FOP+NEQ; break;
3216 case FOP+NEQ: 3215 case FOP+NEQ:
3217 op=FOP+EQ; break; 3216 op=FOP+EQ; break;
3218 case DOP+GT: 3217 case DOP+GT:
3219 drexpr(e2,e1,l1,DOP+GE,0); break; 3218 drexpr(e2,e1,l1,DOP+GE,1); break;
3220 case DOP+GE: 3219 case DOP+GE:
3221 drexpr(e2,e1,l1,DOP+GT,0); break; 3220 drexpr(e2,e1,l1,DOP+GT,1); break;
3222 case DOP+EQ: 3221 case DOP+EQ:
3223 op=DOP+NEQ; break; 3222 op=DOP+NEQ; break;
3224 case DOP+NEQ: 3223 case DOP+NEQ:
3225 op=DOP+EQ; break; 3224 op=DOP+EQ; break;
3226 } 3225 }
3238 case FOP+GE: 3237 case FOP+GE:
3239 printf("\tble\tcr0,L_%d\n",l1); 3238 printf("\tble\tcr0,L_%d\n",l1);
3240 break; 3239 break;
3241 case DOP+EQ: 3240 case DOP+EQ:
3242 case FOP+EQ: 3241 case FOP+EQ:
3243 printf("\tbne\tcr0,L_%d\n",l1); 3242 printf("\tbeq\tcr0,L_%d\n",l1);
3244 break; 3243 break;
3245 case DOP+NEQ: 3244 case DOP+NEQ:
3246 case FOP+NEQ: 3245 case FOP+NEQ:
3247 printf("\tbeq\tcr0,L_%d\n",l1); 3246 printf("\tbne\tcr0,L_%d\n",l1);
3248 break; 3247 break;
3249 } 3248 }
3250 } 3249 }
3251 3250
3252 int emit_dpop(int d) 3251 int emit_dpop(int d)
3335 case LOP+LT: 3334 case LOP+LT:
3336 pcond(code_ge(!cond),l1); break; 3335 pcond(code_ge(!cond),l1); break;
3337 case LOP+LE: 3336 case LOP+LE:
3338 pcond(code_gt(!cond),l1); break; 3337 pcond(code_gt(!cond),l1); break;
3339 case LOP+UGT: 3338 case LOP+UGT:
3340 pcond(code_ugt(!cond),l1); break; 3339 pcond(code_ugt(cond),l1); break;
3341 case LOP+UGE: 3340 case LOP+UGE:
3342 pcond(code_uge(!cond),l1); break; 3341 pcond(code_uge(cond),l1); break;
3343 default: 3342 default:
3344 error(-1); 3343 error(-1);
3345 } 3344 }
3346 tosop(CMP,regv_l(reg),regv_l(e3)); 3345 tosop(CMP,regv_l(reg),regv_l(e3));
3347 switch(op) { 3346 switch(op) {
3356 case LOP+LT: 3355 case LOP+LT:
3357 pcond(code_ge(!cond),l1); break; 3356 pcond(code_ge(!cond),l1); break;
3358 case LOP+LE: 3357 case LOP+LE:
3359 pcond(code_gt(!cond),l1); break; 3358 pcond(code_gt(!cond),l1); break;
3360 case LOP+UGT: 3359 case LOP+UGT:
3361 pcond(code_ugt(!cond),l1); break; 3360 pcond(code_ugt(cond),l1); break;
3362 case LOP+UGE: 3361 case LOP+UGE:
3363 pcond(code_uge(!cond),l1); break; 3362 pcond(code_uge(cond),l1); break;
3364 default: 3363 default:
3365 error(-1); 3364 error(-1);
3366 } 3365 }
3367 emit_lpop_free(e3); 3366 emit_lpop_free(e3);
3368 } 3367 }
3717 { 3716 {
3718 code_save_stacks(); 3717 code_save_stacks();
3719 clear_ptr_cache(); 3718 clear_ptr_cache();
3720 lsrd_lib_used = 1; 3719 lsrd_lib_used = 1;
3721 set_lreg(RET_LREGISTER,1); 3720 set_lreg(RET_LREGISTER,1);
3722 set_lreg_operand(oreg,1); 3721 if (regv_l(oreg)!=5) {
3722 printf("\tmr r5,%s\n", lregister_name_low(oreg));
3723 }
3723 printf("\tbl lsrd__\n"); 3724 printf("\tbl lsrd__\n");
3724 } 3725 }
3725 3726
3726 static void 3727 static void
3727 code_ldiv_lib(int oreg) // ___divdi3$stub 3728 code_ldiv_lib(int oreg) // ___divdi3$stub
3884 if (!(-32766<cadr(e)&&cadr(e)<32767)) return 0; 3885 if (!(-32766<cadr(e)&&cadr(e)<32767)) return 0;
3885 v = caddr(e); 3886 v = caddr(e);
3886 } else return 0; 3887 } else return 0;
3887 3888
3888 switch(op) { 3889 switch(op) {
3889 case LSHIFT: 3890 case LLSHIFT:
3890 case ULSHIFT: 3891 case LULSHIFT:
3891 case RSHIFT: 3892 case LRSHIFT:
3892 case URSHIFT: 3893 case LURSHIFT:
3893 return (0<v&&v<31); 3894 return (0<v&&v<31);
3894 case LADD: 3895 case LADD:
3895 case LSUB: 3896 case LSUB:
3896 return 1; 3897 return 1;
3897 case LBOR: 3898 case LBOR:
3921 case LLSHIFT: 3922 case LLSHIFT:
3922 case LULSHIFT: 3923 case LULSHIFT:
3923 greg = get_register(); 3924 greg = get_register();
3924 use_reg(greg); 3925 use_reg(greg);
3925 grn = register_name(greg); 3926 grn = register_name(greg);
3926 printf("\tsrwi %s,%s,%d\n",grn,crn_h,32-v); 3927 printf("\tsrwi %s,%s,%d\n",grn,crn_l,32-v);
3928 printf("\tslwi %s,%s,%d\n",crn_h,crn_h,v);
3929 printf("\tor %s,%s,%s\n",crn_h,grn,crn_h);
3927 printf("\tslwi %s,%s,%d\n",crn_l,crn_l,v); 3930 printf("\tslwi %s,%s,%d\n",crn_l,crn_l,v);
3928 printf("\tor %s,%s,%s\n",crn_l,grn,crn_l);
3929 printf("\tslwi %s,%s,%d\n",crn_h,crn_h,v);
3930 free_register(greg); 3931 free_register(greg);
3931 return; 3932 return;
3932 case LRSHIFT: 3933 case LRSHIFT:
3933 greg = get_register(); 3934 greg = get_register();
3934 use_reg(greg); 3935 use_reg(greg);
3935 grn = register_name(greg); 3936 grn = register_name(greg);
3936 printf("\tsrwi %s,%s,%d\n",grn,crn_l,v); 3937 printf("\tsrwi %s,%s,%d\n",grn,crn_l,v);
3937 printf("\tinsrwi %s,%s,%d\n",grn,crn_h,v); 3938 printf("\tinsrwi %s,%s,%d,0\n",grn,crn_h,v);
3938 printf("\tsrawi %s,%s,%d\n",crn_h,crn_h,v); 3939 printf("\tsrawi %s,%s,%d\n",crn_h,crn_h,v);
3939 printf("\tmr %s,%s\n",crn_l,grn); 3940 printf("\tmr %s,%s\n",crn_l,grn);
3940 free_register(greg); 3941 free_register(greg);
3941 return; 3942 return;
3942 case LURSHIFT: 3943 case LURSHIFT:
3943 greg = get_register(); 3944 greg = get_register();
3944 use_reg(greg); 3945 use_reg(greg);
3945 grn = register_name(greg); 3946 grn = register_name(greg);
3946 printf("\tslwi %s,%s,%d\n",grn,crn_l,32-v); 3947 printf("\tslwi %s,%s,%d\n",grn,crn_h,32-v);
3947 printf("\tsrwi %s,%s,%d\n",crn_l,crn_h,v);
3948 printf("\tor %s,%s,%s\n",crn_h,grn,crn_h);
3949 printf("\tsrwi %s,%s,%d\n",crn_l,crn_l,v); 3948 printf("\tsrwi %s,%s,%d\n",crn_l,crn_l,v);
3949 printf("\tor %s,%s,%s\n",crn_l,grn,crn_l);
3950 printf("\tsrwi %s,%s,%d\n",crn_h,crn_h,v);
3950 free_register(greg); 3951 free_register(greg);
3951 return; 3952 return;
3953 case LSUB:
3954 v = -v;
3952 case LADD: 3955 case LADD:
3953 printf("\taddic %s,%s,lo16(%d)\n",crn_l,crn_l,v); 3956 printf("\taddic %s,%s,%d\n",crn_l,crn_l,v);
3954 printf("\taddze %s,%s\n",crn_h,crn_h); 3957 if (v<0)
3955 break; 3958 printf("\taddme %s,%s\n",crn_h,crn_h);
3956 case LSUB: 3959 else
3957 printf("\taddic %s,%s,lo16(-%d)\n",crn_l,crn_l,v); 3960 printf("\taddze %s,%s\n",crn_h,crn_h);
3958 printf("\taddme %s,%s\n",crn_h,crn_h);
3959 break; 3961 break;
3960 case LBOR: 3962 case LBOR:
3961 printf("\tori %s,%s,lo16(%d)\n",crn_l,crn_l,v); 3963 printf("\tori %s,%s,lo16(%d)\n",crn_l,crn_l,v);
3962 break; 3964 break;
3963 default: 3965 default: