[206] | 1 | #include "stdafx.h"
|
---|
| 2 |
|
---|
[226] | 3 | #include <Compiler.h>
|
---|
| 4 |
|
---|
[3] | 5 | #include "../BasicCompiler_Common/common.h"
|
---|
| 6 | #include "Opcode.h"
|
---|
| 7 |
|
---|
| 8 | BOOL CalcTwoTerm_Relational(int idCalc,int *type,LONG_PTR *index_stack,int *pStackPointer){
|
---|
| 9 | int reg1,reg2;
|
---|
| 10 | int AnswerType;
|
---|
| 11 |
|
---|
| 12 | int sp;
|
---|
| 13 | sp=*pStackPointer;
|
---|
| 14 |
|
---|
| 15 | AnswerType=NeutralizationType(type[sp-2],index_stack[sp-2],type[sp-1],index_stack[sp-1]);
|
---|
| 16 |
|
---|
| 17 | if(IsRealNumberType(AnswerType)){
|
---|
| 18 | ////////////////
|
---|
| 19 | // 実数演算
|
---|
| 20 | ////////////////
|
---|
| 21 | int xmm_reg1,xmm_reg2;
|
---|
| 22 |
|
---|
| 23 | //2つの項を適切なレジスタにセット
|
---|
| 24 | SetTowTermToReg_RealCalc(AnswerType,type,sp,&xmm_reg1,&xmm_reg2);
|
---|
| 25 |
|
---|
| 26 | if(AnswerType==DEF_DOUBLE){
|
---|
| 27 | //comisd xmm_reg1,xmm_reg2
|
---|
[226] | 28 | compiler.codeGenerator.op_comisd(xmm_reg1,xmm_reg2);
|
---|
[3] | 29 | }
|
---|
| 30 | else if(AnswerType==DEF_SINGLE){
|
---|
| 31 | //comiss xmm_reg1,xmm_reg2
|
---|
[226] | 32 | compiler.codeGenerator.op_comiss(xmm_reg1,xmm_reg2);
|
---|
[3] | 33 | }
|
---|
| 34 |
|
---|
| 35 | //Xmmレジスタを解放
|
---|
| 36 | pobj_reg->UnlockXmmReg();
|
---|
| 37 |
|
---|
| 38 | //汎用レジスタを確保
|
---|
| 39 | reg1=pobj_reg->LockReg();
|
---|
| 40 | }
|
---|
| 41 | else if(Is64Type(AnswerType)){
|
---|
| 42 | //////////////////////
|
---|
| 43 | // 64ビット整数演算
|
---|
| 44 | //////////////////////
|
---|
| 45 |
|
---|
| 46 | //2つの項を適切なレジスタにセット
|
---|
| 47 | SetTowTermToReg_Whole64Calc(type,sp,®1,®2);
|
---|
| 48 |
|
---|
| 49 | //cmp reg1,reg2
|
---|
[226] | 50 | compiler.codeGenerator.op_cmp_reg(sizeof(_int64),reg1,reg2);
|
---|
[3] | 51 | }
|
---|
| 52 | else{
|
---|
| 53 | //////////////////////
|
---|
| 54 | // 32ビット整数演算
|
---|
| 55 | //////////////////////
|
---|
| 56 |
|
---|
| 57 | //2つの項を適切なレジスタにセット
|
---|
| 58 | SetTowTermToReg_Whole32Calc(type,sp,®1,®2);
|
---|
| 59 |
|
---|
| 60 | //cmp reg1,reg2
|
---|
[226] | 61 | compiler.codeGenerator.op_cmp_reg(sizeof(long),reg1,reg2);
|
---|
[3] | 62 | }
|
---|
| 63 |
|
---|
| 64 |
|
---|
| 65 | ////////////////////
|
---|
| 66 | // 条件分岐
|
---|
| 67 | ////////////////////
|
---|
| 68 |
|
---|
| 69 | if(idCalc==CALC_PE){
|
---|
| 70 | // reg1 <= reg2
|
---|
| 71 | if(IsSignedType(AnswerType)&&IsWholeNumberType(AnswerType)){
|
---|
| 72 | //符号あり演算
|
---|
| 73 | //jle
|
---|
| 74 | OpBuffer[obp++]=(char)0x7E;
|
---|
| 75 | }
|
---|
| 76 | else{
|
---|
| 77 | //符号なし演算
|
---|
| 78 | //jbe
|
---|
| 79 | OpBuffer[obp++]=(char)0x76;
|
---|
| 80 | }
|
---|
| 81 | }
|
---|
| 82 | else if(idCalc==CALC_QE){
|
---|
| 83 | // reg1 >= reg2
|
---|
| 84 | if(IsSignedType(AnswerType)&&IsWholeNumberType(AnswerType)){
|
---|
| 85 | //符号あり演算
|
---|
| 86 | //jge
|
---|
| 87 | OpBuffer[obp++]=(char)0x7D;
|
---|
| 88 | }
|
---|
| 89 | else{
|
---|
| 90 | //符号なし演算
|
---|
| 91 | //jae
|
---|
| 92 | OpBuffer[obp++]=(char)0x73;
|
---|
| 93 | }
|
---|
| 94 | }
|
---|
| 95 | else if(idCalc==CALC_P){
|
---|
| 96 | // reg1 < reg2
|
---|
| 97 | if(IsSignedType(AnswerType)&&IsWholeNumberType(AnswerType)){
|
---|
| 98 | //符号あり演算
|
---|
| 99 | //jl
|
---|
| 100 | OpBuffer[obp++]=(char)0x7C;
|
---|
| 101 | }
|
---|
| 102 | else{
|
---|
| 103 | //符号なし演算
|
---|
| 104 | //jb
|
---|
| 105 | OpBuffer[obp++]=(char)0x72;
|
---|
| 106 | }
|
---|
| 107 | }
|
---|
| 108 | else if(idCalc==CALC_Q){
|
---|
| 109 | // reg1 > reg2
|
---|
| 110 | if(IsSignedType(AnswerType)&&IsWholeNumberType(AnswerType)){
|
---|
| 111 | //符号あり演算
|
---|
| 112 | //jg
|
---|
| 113 | OpBuffer[obp++]=(char)0x7F;
|
---|
| 114 | }
|
---|
| 115 | else{
|
---|
| 116 | //符号なし演算
|
---|
| 117 | //ja
|
---|
| 118 | OpBuffer[obp++]=(char)0x77;
|
---|
| 119 | }
|
---|
| 120 | }
|
---|
| 121 | else if(idCalc==CALC_NOTEQUAL){
|
---|
| 122 | // reg1 <> reg2
|
---|
| 123 |
|
---|
| 124 | //jne
|
---|
| 125 | OpBuffer[obp++]=(char)0x75;
|
---|
| 126 | }
|
---|
| 127 | else if(idCalc==CALC_EQUAL){
|
---|
| 128 | // reg1 = reg2
|
---|
| 129 |
|
---|
| 130 | //je
|
---|
| 131 | OpBuffer[obp++]=(char)0x74;
|
---|
| 132 | }
|
---|
| 133 | OpBuffer[obp++]=(char)0x05;
|
---|
| 134 |
|
---|
| 135 |
|
---|
| 136 | //////////////////////
|
---|
| 137 | // FALSEをセット
|
---|
| 138 | //////////////////////
|
---|
| 139 |
|
---|
| 140 | //xor reg1,reg1
|
---|
[226] | 141 | compiler.codeGenerator.op_zero_reg(reg1);
|
---|
[3] | 142 |
|
---|
[36] | 143 | //jmp 7(次のmovを飛び越す)
|
---|
[3] | 144 | OpBuffer[obp++]=(char)0xEB;
|
---|
| 145 | OpBuffer[obp++]=(char)0x07;
|
---|
| 146 |
|
---|
| 147 |
|
---|
| 148 | ///////////////////
|
---|
[36] | 149 | // Trueをセット
|
---|
[3] | 150 | ///////////////////
|
---|
| 151 |
|
---|
[36] | 152 | //mov reg1,1
|
---|
[226] | 153 | compiler.codeGenerator.op_mov_RV(sizeof(_int64),reg1,1);
|
---|
[3] | 154 |
|
---|
| 155 |
|
---|
| 156 | if(reg1==REG_R14){
|
---|
| 157 | //mov qword ptr[rsp+offset],r14 ※スタックフレームを利用
|
---|
| 158 | pobj_sf->push(REG_R14);
|
---|
| 159 | }
|
---|
| 160 |
|
---|
| 161 | sp--;
|
---|
| 162 |
|
---|
| 163 | *pStackPointer=sp;
|
---|
| 164 |
|
---|
[36] | 165 | type[sp-1]=DEF_BOOLEAN;
|
---|
[3] | 166 |
|
---|
| 167 | return 1;
|
---|
| 168 | }
|
---|