Ignore:
Timestamp:
Jul 31, 2007, 4:30:31 AM (17 years ago)
Author:
dai_9181
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/abdev/BasicCompiler64/CodeGenerator.cpp

    r243 r254  
    7979#define INDEX_NON   0x04
    8080
    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 ){
     81const 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
    8285    if(mod==MOD_DISP32){
    8386        //ModR/Mバイト
     
    9497
    9598    //レジスタモードの場合は、ここで終了
    96     if(mod==MOD_REG) return;
     99    if(mod==MOD_REG) return pPertialSchedule;
    97100
    98101
     
    106109
    107110    //ディスプレースメントを必要としない場合は、ここで終了
    108     if(mod==MOD_BASE) return;
     111    if(mod==MOD_BASE) return pPertialSchedule;
    109112
    110113
     
    113116    //////////////////////////
    114117
    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
    117130        pNativeCode->Put( disp, scheduleType );
    118131    }
    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
     138const 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 ){
    124139    //命令プリフィックス
    125140    if(op_prefix) pNativeCode->Put( op_prefix );
     
    133148
    134149    //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 );
    136151}
    137152
     
    175190    pNativeCode->Put( i64data );
    176191}
    177 void CodeGenerator::op_mov_RM(int op_size,int reg,int base_reg,long offset,char mod, Schedule::Type scheduleType ){
     192const PertialSchedule *CodeGenerator::op_mov_RM(int op_size,int reg,int base_reg,long offset,char mod, Schedule::Type scheduleType, bool isPertialSchedule ){
    178193    //mov reg64,qword ptr[base_reg+offset]
    179194    //mov reg32,dword ptr[base_reg+offset]
     
    190205    else opcode=(char)0x8B;
    191206
    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}
     209const 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 ){
    195210    //mov reg64,qword ptr[base_reg1+base_reg2+offset]
    196211    //mov reg32,dword ptr[base_reg1+base_reg2+offset]
    197212    //mov reg16,word ptr[base_reg1+base_reg2+offset]
    198213    //mov reg8,byte ptr[base_reg1+base_reg2+offset]
     214    const PertialSchedule *pPertialSchedule = NULL;
    199215
    200216    if(base_reg1==REG_RSP){
     
    226242
    227243        //オフセット値
     244        if( isPertialSchedule )
     245        {
     246            pertialSchedules.push_back( new PertialSchedule( pNativeCode->GetSize(), sizeof(long) ) );
     247            pPertialSchedule = pertialSchedules.back();
     248        }
    228249        pNativeCode->Put( offset, scheduleType );
    229250    }
     
    239260        pNativeCode->Put( (char)(REGISTER_OPERAND(base_reg1)<<3 | REGISTER_OPERAND(base_reg2)) );
    240261    }
    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}
     265const PertialSchedule *CodeGenerator::op_mov_MR(int op_size,int reg,int base_reg,long offset,char mod, Schedule::Type scheduleType, bool isPertialSchedule ){
    243266    //mov qword ptr[base_reg+offset],reg64
    244267    //mov dword ptr[base_reg+offset],reg32
     
    255278    else opcode=(char)0x89;
    256279
    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}
     282const 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 ){
    260283    //mov qword ptr[base_reg1+base_reg2+offset],reg64
    261284    //mov dword ptr[base_reg1+base_reg2+offset],reg32
    262285    //mov word ptr[base_reg1+base_reg2+offset],reg16
    263286    //mov byte ptr[base_reg1+base_reg2+offset],reg8
     287    const PertialSchedule *pPertialSchedule = NULL;
    264288
    265289    if(base_reg1==REG_RSP){
     
    291315
    292316        //オフセット値
     317        if( isPertialSchedule )
     318        {
     319            pertialSchedules.push_back( new PertialSchedule( pNativeCode->GetSize(), sizeof(long) ) );
     320            pPertialSchedule = pertialSchedules.back();
     321        }
    293322        pNativeCode->Put( offset, scheduleType );
    294323    }
     
    304333        pNativeCode->Put( (char)(REGISTER_OPERAND(base_reg1)<<3 | REGISTER_OPERAND(base_reg2)) );
    305334    }
    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
     339const PertialSchedule *CodeGenerator::op_mov_MV(int op_size,int base_reg,int offset, Schedule::Type offsetScheduleType, bool isPertialSchedule, BOOL bUseOffset,long i32data){
    309340    //mov ptr[base_reg+offset],i32data
    310341    //mov ptr[base_reg       ],i32data
     342    const PertialSchedule *pPertialSchedule = NULL;
    311343
    312344    //16ビット演算のプリフィックス
     
    326358
    327359        //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 );
    329361    }
    330362    else{
     
    346378        pNativeCode->Put( (char)i32data );
    347379    }
     380
     381    return pPertialSchedule;
    348382}
    349383
     
    561595/////////////////////
    562596
    563 void CodeGenerator::op_add_RM(int op_size,int reg,int base_reg,int offset,char mod, Schedule::Type scheduleType ){
     597const PertialSchedule *CodeGenerator::op_add_RM(int op_size,int reg,int base_reg,int offset,char mod, Schedule::Type scheduleType, bool isPertialSchedule ){
    564598    //add reg64,qword ptr[base_reg+offset]
    565599    //add reg32,dword ptr[base_reg+offset]
     
    576610    else opcode=(char)0x03;
    577611
    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
     615const PertialSchedule *CodeGenerator::op_add_RV(int reg,long offset, Schedule::Type scheduleType, bool isPertialSchedule ){
    582616    //add reg,offset
     617    const PertialSchedule *pPertialSchedule = NULL;
     618
    583619    char RexByte=-1;
    584620
     
    594630        pNativeCode->Put( (char)RexByte );
    595631        pNativeCode->Put( (char)0x05 );
    596         pNativeCode->Put( offset, scheduleType );
    597632    }
    598633    else{
     
    603638        pNativeCode->Put( (char)0x81 );
    604639        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;
    607650}
    608651void CodeGenerator::op_add_RR(int reg1,int reg2){
     
    13031346////////////////////
    13041347
    1305 void CodeGenerator::op_movlpd_MR(int xmm_reg,int base_reg,int offset,char mod, Schedule::Type scheduleType ){
     1348const PertialSchedule *CodeGenerator::op_movlpd_MR(int xmm_reg,int base_reg,int offset,char mod, Schedule::Type scheduleType, bool isPertialSchedule ){
    13061349    //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}
     1352const PertialSchedule *CodeGenerator::op_movlpd_RM(int xmm_reg,int base_reg,int offset,char mod, Schedule::Type scheduleType, bool isPertialSchedule ){
    13101353    //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 );
    13121355}
    13131356void CodeGenerator::op_movsd_RR(int xmm_reg1,int xmm_reg2){
     
    13171360    __op_format(0,(char)0xF2,(char)0x0F,(char)0x10,xmm_reg1,xmm_reg2,0,MOD_REG);
    13181361}
    1319 void CodeGenerator::op_movsd_MR(int xmm_reg,int base_reg,int offset,char mod, Schedule::Type scheduleType ){
     1362const PertialSchedule *CodeGenerator::op_movsd_MR(int xmm_reg,int base_reg,int offset,char mod, Schedule::Type scheduleType, bool isPertialSchedule ){
    13201363    //movsd qword ptr[reg+offset],xmm_reg
    13211364    //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 );
    13231366}
    13241367void CodeGenerator::op_movss_RR(int xmm_reg1,int xmm_reg2){
     
    13281371    __op_format(0,(char)0xF3,(char)0x0F,(char)0x10,xmm_reg1,xmm_reg2,0,MOD_REG);
    13291372}
    1330 void CodeGenerator::op_movss_RM(int xmm_reg,int base_reg,int offset,char mod, Schedule::Type scheduleType ){
     1373const PertialSchedule *CodeGenerator::op_movss_RM(int xmm_reg,int base_reg,int offset,char mod, Schedule::Type scheduleType, bool isPertialSchedule ){
    13311374    //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}
     1377const PertialSchedule *CodeGenerator::op_movss_MR(int xmm_reg,int base_reg,int offset,char mod, Schedule::Type scheduleType, bool isPertialSchedule ){
    13351378    //movss dword ptr[reg+offset],xmm_reg
    13361379    //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 );
    13381381}
    13391382
Note: See TracChangeset for help on using the changeset viewer.