Changeset 254 in dev for trunk/abdev/BasicCompiler64/CodeGenerator.cpp
- Timestamp:
- Jul 31, 2007, 4:30:31 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abdev/BasicCompiler64/CodeGenerator.cpp
r243 r254 79 79 #define INDEX_NON 0x04 80 80 81 void CodeGenerator::set_mod_rm_sib_disp(char mod,int reg,int scale,int index_reg,int base_reg,long disp, Schedule::Type scheduleType ){ 81 const PertialSchedule *CodeGenerator::set_mod_rm_sib_disp(char mod,int reg,int scale,int index_reg,int base_reg,long disp, Schedule::Type scheduleType, bool isPertialSchedule ) 82 { 83 const PertialSchedule *pPertialSchedule = NULL; 84 82 85 if(mod==MOD_DISP32){ 83 86 //ModR/Mバイト … … 94 97 95 98 //レジスタモードの場合は、ここで終了 96 if(mod==MOD_REG) return ;99 if(mod==MOD_REG) return pPertialSchedule; 97 100 98 101 … … 106 109 107 110 //ディスプレースメントを必要としない場合は、ここで終了 108 if(mod==MOD_BASE) return ;111 if(mod==MOD_BASE) return pPertialSchedule; 109 112 110 113 … … 113 116 ////////////////////////// 114 117 115 if(mod==MOD_BASE_DISP8) pNativeCode->Put( (char)disp ); 116 else{ 118 if(mod==MOD_BASE_DISP8) 119 { 120 pNativeCode->Put( (char)disp ); 121 } 122 else 123 { 124 if( isPertialSchedule ) 125 { 126 pertialSchedules.push_back( new PertialSchedule( pNativeCode->GetSize(), sizeof(long) ) ); 127 pPertialSchedule = pertialSchedules.back(); 128 } 129 117 130 pNativeCode->Put( disp, scheduleType ); 118 131 } 119 } 120 121 122 123 void CodeGenerator::__op_format(int op_size,char op_prefix,char opcode1,char opcode2,int reg,int base_reg,long offset,char mod, Schedule::Type scheduleType ){ 132 133 return pPertialSchedule; 134 } 135 136 137 138 const PertialSchedule *CodeGenerator::__op_format(int op_size,char op_prefix,char opcode1,char opcode2,int reg,int base_reg,long offset,char mod, Schedule::Type scheduleType, bool isPertialSchedule ){ 124 139 //命令プリフィックス 125 140 if(op_prefix) pNativeCode->Put( op_prefix ); … … 133 148 134 149 //ModR/M, SIB, disp 135 set_mod_rm_sib_disp(mod,reg,SCALE_NON,INDEX_NON,base_reg,offset, scheduleType );150 return set_mod_rm_sib_disp(mod,reg,SCALE_NON,INDEX_NON,base_reg,offset, scheduleType, isPertialSchedule ); 136 151 } 137 152 … … 175 190 pNativeCode->Put( i64data ); 176 191 } 177 void CodeGenerator::op_mov_RM(int op_size,int reg,int base_reg,long offset,char mod, Schedule::Type scheduleType ){192 const PertialSchedule *CodeGenerator::op_mov_RM(int op_size,int reg,int base_reg,long offset,char mod, Schedule::Type scheduleType, bool isPertialSchedule ){ 178 193 //mov reg64,qword ptr[base_reg+offset] 179 194 //mov reg32,dword ptr[base_reg+offset] … … 190 205 else opcode=(char)0x8B; 191 206 192 __op_format(op_size,op_prefix,opcode,0,reg,base_reg,offset,mod, scheduleType);193 } 194 void CodeGenerator::op_mov_RM_ex(int op_size,int reg,int base_reg1,int base_reg2,long offset,BOOL bUseOffset, Schedule::Type scheduleType ){207 return __op_format(op_size,op_prefix,opcode,0,reg,base_reg,offset,mod, scheduleType, isPertialSchedule ); 208 } 209 const PertialSchedule *CodeGenerator::op_mov_RM_ex(int op_size,int reg,int base_reg1,int base_reg2,long offset,BOOL bUseOffset, Schedule::Type scheduleType, bool isPertialSchedule ){ 195 210 //mov reg64,qword ptr[base_reg1+base_reg2+offset] 196 211 //mov reg32,dword ptr[base_reg1+base_reg2+offset] 197 212 //mov reg16,word ptr[base_reg1+base_reg2+offset] 198 213 //mov reg8,byte ptr[base_reg1+base_reg2+offset] 214 const PertialSchedule *pPertialSchedule = NULL; 199 215 200 216 if(base_reg1==REG_RSP){ … … 226 242 227 243 //オフセット値 244 if( isPertialSchedule ) 245 { 246 pertialSchedules.push_back( new PertialSchedule( pNativeCode->GetSize(), sizeof(long) ) ); 247 pPertialSchedule = pertialSchedules.back(); 248 } 228 249 pNativeCode->Put( offset, scheduleType ); 229 250 } … … 239 260 pNativeCode->Put( (char)(REGISTER_OPERAND(base_reg1)<<3 | REGISTER_OPERAND(base_reg2)) ); 240 261 } 241 } 242 void CodeGenerator::op_mov_MR(int op_size,int reg,int base_reg,long offset,char mod, Schedule::Type scheduleType ){ 262 263 return pPertialSchedule; 264 } 265 const PertialSchedule *CodeGenerator::op_mov_MR(int op_size,int reg,int base_reg,long offset,char mod, Schedule::Type scheduleType, bool isPertialSchedule ){ 243 266 //mov qword ptr[base_reg+offset],reg64 244 267 //mov dword ptr[base_reg+offset],reg32 … … 255 278 else opcode=(char)0x89; 256 279 257 __op_format(op_size,op_prefix,opcode,0,reg,base_reg,offset,mod, scheduleType );258 } 259 void CodeGenerator::op_mov_MR_ex(int op_size,int reg,int base_reg1,int base_reg2,long offset,BOOL bUseOffset, Schedule::Type scheduleType ){280 return __op_format(op_size,op_prefix,opcode,0,reg,base_reg,offset,mod, scheduleType, isPertialSchedule ); 281 } 282 const PertialSchedule *CodeGenerator::op_mov_MR_ex(int op_size,int reg,int base_reg1,int base_reg2,long offset,BOOL bUseOffset, Schedule::Type scheduleType, bool isPertialSchedule ){ 260 283 //mov qword ptr[base_reg1+base_reg2+offset],reg64 261 284 //mov dword ptr[base_reg1+base_reg2+offset],reg32 262 285 //mov word ptr[base_reg1+base_reg2+offset],reg16 263 286 //mov byte ptr[base_reg1+base_reg2+offset],reg8 287 const PertialSchedule *pPertialSchedule = NULL; 264 288 265 289 if(base_reg1==REG_RSP){ … … 291 315 292 316 //オフセット値 317 if( isPertialSchedule ) 318 { 319 pertialSchedules.push_back( new PertialSchedule( pNativeCode->GetSize(), sizeof(long) ) ); 320 pPertialSchedule = pertialSchedules.back(); 321 } 293 322 pNativeCode->Put( offset, scheduleType ); 294 323 } … … 304 333 pNativeCode->Put( (char)(REGISTER_OPERAND(base_reg1)<<3 | REGISTER_OPERAND(base_reg2)) ); 305 334 } 306 } 307 308 void CodeGenerator::op_mov_MV(int op_size,int base_reg,int offset, Schedule::Type offsetScheduleType, BOOL bUseOffset,long i32data){ 335 336 return pPertialSchedule; 337 } 338 339 const PertialSchedule *CodeGenerator::op_mov_MV(int op_size,int base_reg,int offset, Schedule::Type offsetScheduleType, bool isPertialSchedule, BOOL bUseOffset,long i32data){ 309 340 //mov ptr[base_reg+offset],i32data 310 341 //mov ptr[base_reg ],i32data 342 const PertialSchedule *pPertialSchedule = NULL; 311 343 312 344 //16ビット演算のプリフィックス … … 326 358 327 359 //ModR/M, SIB, disp 328 set_mod_rm_sib_disp(MOD_BASE_DISP32,0,SCALE_NON,INDEX_NON,base_reg,offset, offsetScheduleType );360 pPertialSchedule = set_mod_rm_sib_disp(MOD_BASE_DISP32,0,SCALE_NON,INDEX_NON,base_reg,offset, offsetScheduleType, isPertialSchedule ); 329 361 } 330 362 else{ … … 346 378 pNativeCode->Put( (char)i32data ); 347 379 } 380 381 return pPertialSchedule; 348 382 } 349 383 … … 561 595 ///////////////////// 562 596 563 void CodeGenerator::op_add_RM(int op_size,int reg,int base_reg,int offset,char mod, Schedule::Type scheduleType ){597 const PertialSchedule *CodeGenerator::op_add_RM(int op_size,int reg,int base_reg,int offset,char mod, Schedule::Type scheduleType, bool isPertialSchedule ){ 564 598 //add reg64,qword ptr[base_reg+offset] 565 599 //add reg32,dword ptr[base_reg+offset] … … 576 610 else opcode=(char)0x03; 577 611 578 __op_format(op_size,op_prefix,opcode,0,reg,base_reg,offset,mod, scheduleType );579 } 580 581 void CodeGenerator::op_add_RV(int reg,long offset, Schedule::Type scheduleType ){612 return __op_format(op_size,op_prefix,opcode,0,reg,base_reg,offset,mod, scheduleType, isPertialSchedule ); 613 } 614 615 const PertialSchedule *CodeGenerator::op_add_RV(int reg,long offset, Schedule::Type scheduleType, bool isPertialSchedule ){ 582 616 //add reg,offset 617 const PertialSchedule *pPertialSchedule = NULL; 618 583 619 char RexByte=-1; 584 620 … … 594 630 pNativeCode->Put( (char)RexByte ); 595 631 pNativeCode->Put( (char)0x05 ); 596 pNativeCode->Put( offset, scheduleType );597 632 } 598 633 else{ … … 603 638 pNativeCode->Put( (char)0x81 ); 604 639 pNativeCode->Put( (char)(0xC0| REGISTER_OPERAND(reg)) ); 605 pNativeCode->Put( offset, scheduleType ); 606 } 640 } 641 642 if( isPertialSchedule ) 643 { 644 pertialSchedules.push_back( new PertialSchedule( pNativeCode->GetSize(), sizeof(long) ) ); 645 pPertialSchedule = pertialSchedules.back(); 646 } 647 pNativeCode->Put( offset, scheduleType ); 648 649 return pPertialSchedule; 607 650 } 608 651 void CodeGenerator::op_add_RR(int reg1,int reg2){ … … 1303 1346 //////////////////// 1304 1347 1305 void CodeGenerator::op_movlpd_MR(int xmm_reg,int base_reg,int offset,char mod, Schedule::Type scheduleType ){1348 const PertialSchedule *CodeGenerator::op_movlpd_MR(int xmm_reg,int base_reg,int offset,char mod, Schedule::Type scheduleType, bool isPertialSchedule ){ 1306 1349 //movlpd qword ptr[base_reg+offset],xmm_reg 1307 __op_format(0,(char)0x66,(char)0x0F,(char)0x13,xmm_reg,base_reg,offset,mod, scheduleType );1308 } 1309 void CodeGenerator::op_movlpd_RM(int xmm_reg,int base_reg,int offset,char mod, Schedule::Type scheduleType ){1350 return __op_format(0,(char)0x66,(char)0x0F,(char)0x13,xmm_reg,base_reg,offset,mod, scheduleType, isPertialSchedule ); 1351 } 1352 const PertialSchedule *CodeGenerator::op_movlpd_RM(int xmm_reg,int base_reg,int offset,char mod, Schedule::Type scheduleType, bool isPertialSchedule ){ 1310 1353 //movlpd xmm_reg,qword ptr[base_reg+offset] 1311 __op_format(0,(char)0x66,(char)0x0F,(char)0x12,xmm_reg,base_reg,offset,mod, scheduleType );1354 return __op_format(0,(char)0x66,(char)0x0F,(char)0x12,xmm_reg,base_reg,offset,mod, scheduleType, isPertialSchedule ); 1312 1355 } 1313 1356 void CodeGenerator::op_movsd_RR(int xmm_reg1,int xmm_reg2){ … … 1317 1360 __op_format(0,(char)0xF2,(char)0x0F,(char)0x10,xmm_reg1,xmm_reg2,0,MOD_REG); 1318 1361 } 1319 void CodeGenerator::op_movsd_MR(int xmm_reg,int base_reg,int offset,char mod, Schedule::Type scheduleType ){1362 const PertialSchedule *CodeGenerator::op_movsd_MR(int xmm_reg,int base_reg,int offset,char mod, Schedule::Type scheduleType, bool isPertialSchedule ){ 1320 1363 //movsd qword ptr[reg+offset],xmm_reg 1321 1364 //movsd qword ptr[reg],xmm_reg 1322 __op_format(0,(char)0xF2,(char)0x0F,(char)0x11,xmm_reg,base_reg,offset,mod, scheduleType );1365 return __op_format(0,(char)0xF2,(char)0x0F,(char)0x11,xmm_reg,base_reg,offset,mod, scheduleType, isPertialSchedule ); 1323 1366 } 1324 1367 void CodeGenerator::op_movss_RR(int xmm_reg1,int xmm_reg2){ … … 1328 1371 __op_format(0,(char)0xF3,(char)0x0F,(char)0x10,xmm_reg1,xmm_reg2,0,MOD_REG); 1329 1372 } 1330 void CodeGenerator::op_movss_RM(int xmm_reg,int base_reg,int offset,char mod, Schedule::Type scheduleType ){1373 const PertialSchedule *CodeGenerator::op_movss_RM(int xmm_reg,int base_reg,int offset,char mod, Schedule::Type scheduleType, bool isPertialSchedule ){ 1331 1374 //movss xmm_reg,dword ptr[base_reg+offset] 1332 __op_format(0,(char)0xF3,(char)0x0F,(char)0x10,xmm_reg,base_reg,offset,mod, scheduleType );1333 } 1334 void CodeGenerator::op_movss_MR(int xmm_reg,int base_reg,int offset,char mod, Schedule::Type scheduleType ){1375 return __op_format(0,(char)0xF3,(char)0x0F,(char)0x10,xmm_reg,base_reg,offset,mod, scheduleType, isPertialSchedule ); 1376 } 1377 const PertialSchedule *CodeGenerator::op_movss_MR(int xmm_reg,int base_reg,int offset,char mod, Schedule::Type scheduleType, bool isPertialSchedule ){ 1335 1378 //movss dword ptr[reg+offset],xmm_reg 1336 1379 //movss dword ptr[reg],xmm_reg 1337 __op_format(0,(char)0xF3,(char)0x0F,(char)0x11,xmm_reg,base_reg,offset,mod, scheduleType );1380 return __op_format(0,(char)0xF3,(char)0x0F,(char)0x11,xmm_reg,base_reg,offset,mod, scheduleType, isPertialSchedule ); 1338 1381 } 1339 1382
Note:
See TracChangeset
for help on using the changeset viewer.