source: dev/trunk/abdev/BasicCompiler64/NumOpe_Logical.cpp@ 419

Last change on this file since 419 was 419, checked in by dai_9181, 16 years ago

64bitコンパイラで32bit値のxor演算が正常に行われないバグを修正。

File size: 3.7 KB
Line 
1#include "stdafx.h"
2
3#include <Compiler.h>
4
5#include "../BasicCompiler_Common/common.h"
6#include "Opcode.h"
7
8BOOL CalcTwoTerm_Logical(int idCalc,int *type,LONG_PTR *index_stack,int *pStackPointer){
9 //value[sp-2] xor= value[sp-1]
10 //xor演算
11
12 int sp;
13 sp=*pStackPointer;
14
15 if(IsRealNumberType(type[sp-2])||IsRealNumberType(type[sp-1])){
16 //いずれかの項が実数のとき
17 SetError(45,"xor",cp);
18 return 0;
19 }
20
21 int reg1,reg2;
22
23 if(Is64Type(type[sp-2])||Is64Type(type[sp-1])){
24 //////////////////////
25 // 64ビット整数演算
26 //////////////////////
27
28 SetTowTermToReg_Whole64Calc(type,sp,&reg1,&reg2);
29
30 if(idCalc==CALC_XOR){
31 //xor reg1,reg2
32 compiler.codeGenerator.op_xor_reg(sizeof(_int64),reg1,reg2);
33 }
34 else if(idCalc==CALC_OR){
35 //or reg1,reg2
36 compiler.codeGenerator.op_or_reg(sizeof(_int64),reg1,reg2);
37 }
38 else if(idCalc==CALC_AND){
39 //and reg1,reg2
40 compiler.codeGenerator.op_and_reg(sizeof(_int64),reg1,reg2);
41 }
42 else
43 {
44 throw;
45 }
46
47 if(reg1==REG_R14){
48 //mov qword ptr[rsp+offset],r14 ※スタックフレームを利用
49 pobj_sf->push(REG_R14);
50 }
51
52 sp--;
53 type[sp-1]=NeutralizationType(type[sp-1],index_stack[sp-1],type[sp],index_stack[sp]);
54 }
55 else{
56 //32ビット以下の整数演算
57
58 SetTowTermToReg_Whole32Calc(type,sp,&reg1,&reg2);
59
60 if(idCalc==CALC_XOR){
61 //add reg1,reg2
62 compiler.codeGenerator.op_xor_reg(sizeof(long),reg1,reg2);
63 }
64 else if(idCalc==CALC_OR){
65 //or reg1,reg2
66 compiler.codeGenerator.op_or_reg(sizeof(long),reg1,reg2);
67 }
68 else if(idCalc==CALC_AND){
69 //and reg1,reg2
70 compiler.codeGenerator.op_and_reg(sizeof(long),reg1,reg2);
71 }
72 else
73 {
74 throw;
75 }
76
77 if(reg1==REG_R14){
78 //mov qword ptr[rsp+offset],r14 ※スタックフレームを利用
79 pobj_sf->push(REG_R14);
80 }
81
82 sp--;
83 type[sp-1]=NeutralizationType(type[sp-1],index_stack[sp-1],type[sp],index_stack[sp]);
84 }
85
86 *pStackPointer=sp;
87 return 1;
88}
89
90BOOL Calc_Not(int *type,int sp){
91 //value[sp-1]=Not value[sp-1]
92 //NOT演算子
93
94 if(IsRealNumberType(type[sp-1])){
95 //実数のとき
96 SetError(45,"Not",cp);
97 return 0;
98 }
99
100 int reg;
101
102 if( type[sp - 1] == DEF_BOOLEAN ){
103 SetOneTermToReg_Whole32Calc(type[sp-1],&reg);
104
105 if( reg != REG_RAX ){
106 //mov rax,qword ptr[rsp+offset] ※スタックフレームを利用
107 pobj_sf->pop(REG_RAX);
108 }
109
110 //cmp reg,0
111 compiler.codeGenerator.op_cmp_value(Type(type[sp-1]).GetSize(),reg,0);
112
113 //setne al
114 compiler.codeGenerator.op_setne( REG_RAX );
115
116 //and rax,000000FFh
117 compiler.codeGenerator.op_and64_value(REG_RAX,(int)0xFF);
118
119 //neg
120 compiler.codeGenerator.op_neg( REG_RAX );
121
122 //sbb rax, rax
123 compiler.codeGenerator.op_sbb_RR( sizeof(_int64), REG_RAX, REG_RAX );
124
125 //add rax, 1
126 compiler.codeGenerator.op_add_RV( REG_RAX, 1 );
127
128 if( reg != REG_RAX ){
129 //mov reg,rax
130 compiler.codeGenerator.op_mov_RR( reg, REG_RAX );
131
132 //mov qword ptr[rsp+offset],rax ※スタックフレームを利用
133 pobj_sf->push(REG_RAX);
134 }
135
136 if(reg==REG_R14){
137 //mov qword ptr[rsp+offset],r14 ※スタックフレームを利用
138 pobj_sf->push(REG_R14);
139 }
140 }
141 else if(type[sp-1]==DEF_INT64||type[sp-1]==DEF_QWORD){
142 SetOneTermToReg_Whole64Calc(type[sp-1],&reg);
143
144 //not reg
145 compiler.codeGenerator.op_not_reg(sizeof(_int64),reg);
146
147 if(reg==REG_R14){
148 //mov qword ptr[rsp+offset],r14 ※スタックフレームを利用
149 pobj_sf->push(REG_R14);
150 }
151 }
152 else if(IsWholeNumberType(type[sp-1])){
153 SetOneTermToReg_Whole32Calc(type[sp-1],&reg);
154
155 //not reg
156 compiler.codeGenerator.op_not_reg(sizeof(long),reg);
157
158 if(reg==REG_R14){
159 //mov qword ptr[rsp+offset],r14 ※スタックフレームを利用
160 pobj_sf->push(REG_R14);
161 }
162 }
163
164 return 1;
165}
Note: See TracBrowser for help on using the repository browser.