1 | #include "stdafx.h"
|
---|
2 |
|
---|
3 | #include <Compiler.h>
|
---|
4 |
|
---|
5 | #include "../BasicCompiler_Common/common.h"
|
---|
6 | #include "Opcode.h"
|
---|
7 |
|
---|
8 |
|
---|
9 | void SetXmmReg_DoubleVariable(RELATIVE_VAR *pRelativeVar,int xmm_reg){
|
---|
10 | if(pRelativeVar->dwKind==VAR_GLOBAL){
|
---|
11 | if(pRelativeVar->bOffsetOffset){
|
---|
12 | //movlpd xmm_reg,qword ptr[r11+offset]
|
---|
13 | OpBuffer[obp++]=(char)0x66;
|
---|
14 | OpBuffer[obp++]=(char)0x41;
|
---|
15 | OpBuffer[obp++]=(char)0x0F;
|
---|
16 | OpBuffer[obp++]=(char)0x12;
|
---|
17 | OpBuffer[obp++]=(char)(0x83 | REGISTER_OPERAND(xmm_reg)<<3);
|
---|
18 | *((long *)(OpBuffer+obp))=(int)pRelativeVar->offset;
|
---|
19 | pobj_GlobalVarSchedule->add();
|
---|
20 | obp+=sizeof(long);
|
---|
21 | }
|
---|
22 | else{
|
---|
23 | //movlpd xmm_reg,qword ptr[offset]
|
---|
24 | OpBuffer[obp++]=(char)0x66;
|
---|
25 | OpBuffer[obp++]=(char)0x0F;
|
---|
26 | OpBuffer[obp++]=(char)0x12;
|
---|
27 | OpBuffer[obp++]=(char)(0x04 | REGISTER_OPERAND(xmm_reg)<<3);
|
---|
28 | OpBuffer[obp++]=(char)0x25;
|
---|
29 | *((long *)(OpBuffer+obp))=(int)pRelativeVar->offset;
|
---|
30 | pobj_GlobalVarSchedule->add();
|
---|
31 | obp+=sizeof(long);
|
---|
32 | }
|
---|
33 | }
|
---|
34 | else if( pRelativeVar->dwKind == VAR_REFGLOBAL ){
|
---|
35 | SetError(300,NULL,cp);
|
---|
36 | }
|
---|
37 | else if(pRelativeVar->dwKind==VAR_LOCAL){
|
---|
38 | if(pRelativeVar->bOffsetOffset){
|
---|
39 | //movlpd xmm_reg,qword ptr[rsp+r11+offset]
|
---|
40 | OpBuffer[obp++]=(char)0x66;
|
---|
41 | OpBuffer[obp++]=(char)0x42;
|
---|
42 | OpBuffer[obp++]=(char)0x0F;
|
---|
43 | OpBuffer[obp++]=(char)0x12;
|
---|
44 | OpBuffer[obp++]=(char)(0x84 | REGISTER_OPERAND(xmm_reg)<<3);
|
---|
45 | OpBuffer[obp++]=(char)0x1C;
|
---|
46 | *((long *)(OpBuffer+obp))=(int)pRelativeVar->offset;
|
---|
47 | AddLocalVarAddrSchedule();
|
---|
48 | obp+=sizeof(long);
|
---|
49 | }
|
---|
50 | else{
|
---|
51 | //movlpd xmm_reg,qword ptr[rsp+offset]
|
---|
52 | OpBuffer[obp++]=(char)0x66;
|
---|
53 | OpBuffer[obp++]=(char)0x0F;
|
---|
54 | OpBuffer[obp++]=(char)0x12;
|
---|
55 | OpBuffer[obp++]=(char)(0x84 | REGISTER_OPERAND(xmm_reg)<<3);
|
---|
56 | OpBuffer[obp++]=(char)0x24;
|
---|
57 | *((long *)(OpBuffer+obp))=(int)pRelativeVar->offset;
|
---|
58 | AddLocalVarAddrSchedule();
|
---|
59 | obp+=sizeof(long);
|
---|
60 | }
|
---|
61 | }
|
---|
62 | else if( pRelativeVar->dwKind == VAR_REFLOCAL ){
|
---|
63 | if(pRelativeVar->bOffsetOffset){
|
---|
64 | //add r11,qword ptr[rsp+offset]
|
---|
65 | OpBuffer[obp++]=(char)0x4C;
|
---|
66 | OpBuffer[obp++]=(char)0x03;
|
---|
67 | OpBuffer[obp++]=(char)0x9C;
|
---|
68 | OpBuffer[obp++]=(char)0x24;
|
---|
69 | *((long *)(OpBuffer+obp))=(int)pRelativeVar->offset;
|
---|
70 | AddLocalVarAddrSchedule();
|
---|
71 | obp+=sizeof(long);
|
---|
72 | }
|
---|
73 | else{
|
---|
74 | //mov r11,qword ptr[rsp+offset]
|
---|
75 | compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelativeVar->offset,MOD_BASE_DISP32);
|
---|
76 | obp-=sizeof(long);
|
---|
77 | AddLocalVarAddrSchedule();
|
---|
78 | obp+=sizeof(long);
|
---|
79 | }
|
---|
80 |
|
---|
81 | goto directmem;
|
---|
82 | }
|
---|
83 | else if(pRelativeVar->dwKind==VAR_DIRECTMEM){
|
---|
84 | directmem:
|
---|
85 | //movlpd xmm_reg,qword ptr[r11]
|
---|
86 | OpBuffer[obp++]=(char)0x66;
|
---|
87 | OpBuffer[obp++]=(char)0x41;
|
---|
88 | OpBuffer[obp++]=(char)0x0F;
|
---|
89 | OpBuffer[obp++]=(char)0x12;
|
---|
90 | OpBuffer[obp++]=(char)(0x03 | REGISTER_OPERAND(xmm_reg)<<3);
|
---|
91 | }
|
---|
92 | }
|
---|
93 | void SetXmmReg_SingleVariable(RELATIVE_VAR *pRelativeVar,int xmm_reg){
|
---|
94 | if(pRelativeVar->dwKind==VAR_GLOBAL){
|
---|
95 | if(pRelativeVar->bOffsetOffset){
|
---|
96 | //movss xmm_reg,dword ptr[r11+offset]
|
---|
97 | OpBuffer[obp++]=(char)0xF3;
|
---|
98 | OpBuffer[obp++]=(char)0x41;
|
---|
99 | OpBuffer[obp++]=(char)0x0F;
|
---|
100 | OpBuffer[obp++]=(char)0x10;
|
---|
101 | OpBuffer[obp++]=(char)(0x83 | REGISTER_OPERAND(xmm_reg)<<3);
|
---|
102 | *((long *)(OpBuffer+obp))=(int)pRelativeVar->offset;
|
---|
103 | pobj_GlobalVarSchedule->add();
|
---|
104 | obp+=sizeof(long);
|
---|
105 | }
|
---|
106 | else{
|
---|
107 | //movss xmm_reg,dword ptr[offset]
|
---|
108 | OpBuffer[obp++]=(char)0xF3;
|
---|
109 | OpBuffer[obp++]=(char)0x0F;
|
---|
110 | OpBuffer[obp++]=(char)0x10;
|
---|
111 | OpBuffer[obp++]=(char)(0x04 | REGISTER_OPERAND(xmm_reg)<<3);
|
---|
112 | OpBuffer[obp++]=(char)0x25;
|
---|
113 | *((long *)(OpBuffer+obp))=(int)pRelativeVar->offset;
|
---|
114 | pobj_GlobalVarSchedule->add();
|
---|
115 | obp+=sizeof(long);
|
---|
116 | }
|
---|
117 | }
|
---|
118 | else if( pRelativeVar->dwKind == VAR_REFGLOBAL ){
|
---|
119 | SetError(300,NULL,cp);
|
---|
120 | }
|
---|
121 | else if(pRelativeVar->dwKind==VAR_LOCAL){
|
---|
122 | if(pRelativeVar->bOffsetOffset){
|
---|
123 | //movss xmm_reg,dword ptr[rsp+r11+offset]
|
---|
124 | OpBuffer[obp++]=(char)0xF3;
|
---|
125 | OpBuffer[obp++]=(char)0x42;
|
---|
126 | OpBuffer[obp++]=(char)0x0F;
|
---|
127 | OpBuffer[obp++]=(char)0x10;
|
---|
128 | OpBuffer[obp++]=(char)(0x84 | REGISTER_OPERAND(xmm_reg)<<3);
|
---|
129 | OpBuffer[obp++]=(char)0x1C;
|
---|
130 | *((long *)(OpBuffer+obp))=(int)pRelativeVar->offset;
|
---|
131 | AddLocalVarAddrSchedule();
|
---|
132 | obp+=sizeof(long);
|
---|
133 | }
|
---|
134 | else{
|
---|
135 | //movss xmm_reg,dword ptr[rsp+offset]
|
---|
136 | OpBuffer[obp++]=(char)0xF3;
|
---|
137 | OpBuffer[obp++]=(char)0x0F;
|
---|
138 | OpBuffer[obp++]=(char)0x10;
|
---|
139 | OpBuffer[obp++]=(char)(0x84 | REGISTER_OPERAND(xmm_reg)<<3);
|
---|
140 | OpBuffer[obp++]=(char)0x24;
|
---|
141 | *((long *)(OpBuffer+obp))=(int)pRelativeVar->offset;
|
---|
142 | AddLocalVarAddrSchedule();
|
---|
143 | obp+=sizeof(long);
|
---|
144 | }
|
---|
145 | }
|
---|
146 | else if( pRelativeVar->dwKind == VAR_REFLOCAL ){
|
---|
147 | if(pRelativeVar->bOffsetOffset){
|
---|
148 | //add r11,qword ptr[rsp+offset]
|
---|
149 | OpBuffer[obp++]=(char)0x4C;
|
---|
150 | OpBuffer[obp++]=(char)0x03;
|
---|
151 | OpBuffer[obp++]=(char)0x9C;
|
---|
152 | OpBuffer[obp++]=(char)0x24;
|
---|
153 | *((long *)(OpBuffer+obp))=(int)pRelativeVar->offset;
|
---|
154 | AddLocalVarAddrSchedule();
|
---|
155 | obp+=sizeof(long);
|
---|
156 | }
|
---|
157 | else{
|
---|
158 | //mov r11,qword ptr[rsp+offset]
|
---|
159 | compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelativeVar->offset,MOD_BASE_DISP32);
|
---|
160 | obp-=sizeof(long);
|
---|
161 | AddLocalVarAddrSchedule();
|
---|
162 | obp+=sizeof(long);
|
---|
163 | }
|
---|
164 |
|
---|
165 | goto directmem;
|
---|
166 | }
|
---|
167 | else if(pRelativeVar->dwKind==VAR_DIRECTMEM){
|
---|
168 | directmem:
|
---|
169 | //movss xmm_reg,dword ptr[r11]
|
---|
170 | OpBuffer[obp++]=(char)0xF3;
|
---|
171 | OpBuffer[obp++]=(char)0x41;
|
---|
172 | OpBuffer[obp++]=(char)0x0F;
|
---|
173 | OpBuffer[obp++]=(char)0x10;
|
---|
174 | OpBuffer[obp++]=(char)(0x03 | REGISTER_OPERAND(xmm_reg)<<3);
|
---|
175 | }
|
---|
176 | }
|
---|
177 |
|
---|
178 |
|
---|
179 | void SetReg_WholeVariable(int type,RELATIVE_VAR *pRelativeVar,int reg){
|
---|
180 | int varSize;
|
---|
181 |
|
---|
182 | varSize=GetTypeSize(type,-1);
|
---|
183 |
|
---|
184 | if(pRelativeVar->dwKind==VAR_GLOBAL){
|
---|
185 | if(pRelativeVar->bOffsetOffset){
|
---|
186 | //mov reg, ptr[r11+offset]
|
---|
187 | compiler.codeGenerator.op_mov_RM(varSize,reg,REG_R11,(int)pRelativeVar->offset,MOD_BASE_DISP32);
|
---|
188 | obp-=sizeof(long);
|
---|
189 | pobj_GlobalVarSchedule->add();
|
---|
190 | obp+=sizeof(long);
|
---|
191 | }
|
---|
192 | else{
|
---|
193 | //mov reg, ptr[offset]
|
---|
194 | compiler.codeGenerator.op_mov_RM(varSize,reg,0,(int)pRelativeVar->offset,MOD_DISP32);
|
---|
195 | obp-=sizeof(long);
|
---|
196 | pobj_GlobalVarSchedule->add();
|
---|
197 | obp+=sizeof(long);
|
---|
198 | }
|
---|
199 | }
|
---|
200 | else if( pRelativeVar->dwKind == VAR_REFGLOBAL ){
|
---|
201 | if(pRelativeVar->bOffsetOffset){
|
---|
202 | //add r11,qword ptr[offset]
|
---|
203 | compiler.codeGenerator.op_add_RM(sizeof(_int64),REG_R11,REG_NON,(int)pRelativeVar->offset,MOD_DISP32);
|
---|
204 | obp-=sizeof(long);
|
---|
205 | pobj_GlobalVarSchedule->add();
|
---|
206 | obp+=sizeof(long);
|
---|
207 | }
|
---|
208 | else{
|
---|
209 | //mov r11,qword ptr[offset]
|
---|
210 | compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_NON,(int)pRelativeVar->offset,MOD_DISP32);
|
---|
211 | obp-=sizeof(long);
|
---|
212 | pobj_GlobalVarSchedule->add();
|
---|
213 | obp+=sizeof(long);
|
---|
214 | }
|
---|
215 |
|
---|
216 | goto directmem;
|
---|
217 | }
|
---|
218 | else if(pRelativeVar->dwKind==VAR_LOCAL){
|
---|
219 | if(pRelativeVar->bOffsetOffset){
|
---|
220 | //mov reg, ptr[rsp+r11+offset]
|
---|
221 | compiler.codeGenerator.op_mov_RM_ex(varSize,reg,REG_RSP,REG_R11,(int)pRelativeVar->offset,USE_OFFSET);
|
---|
222 | obp-=sizeof(long);
|
---|
223 | AddLocalVarAddrSchedule();
|
---|
224 | obp+=sizeof(long);
|
---|
225 | }
|
---|
226 | else{
|
---|
227 | //mov reg, ptr[rsp+offset]
|
---|
228 | compiler.codeGenerator.op_mov_RM(varSize,reg,REG_RSP,(int)pRelativeVar->offset,MOD_BASE_DISP32);
|
---|
229 | obp-=sizeof(long);
|
---|
230 | AddLocalVarAddrSchedule();
|
---|
231 | obp+=sizeof(long);
|
---|
232 | }
|
---|
233 | }
|
---|
234 | else if( pRelativeVar->dwKind == VAR_REFLOCAL ){
|
---|
235 | if(pRelativeVar->bOffsetOffset){
|
---|
236 | //add r11,qword ptr[rsp+offset]
|
---|
237 | compiler.codeGenerator.op_add_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelativeVar->offset,MOD_BASE_DISP32);
|
---|
238 | obp-=sizeof(long);
|
---|
239 | AddLocalVarAddrSchedule();
|
---|
240 | obp+=sizeof(long);
|
---|
241 | }
|
---|
242 | else{
|
---|
243 | //mov r11,qword ptr[rsp+offset]
|
---|
244 | compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelativeVar->offset,MOD_BASE_DISP32);
|
---|
245 | obp-=sizeof(long);
|
---|
246 | AddLocalVarAddrSchedule();
|
---|
247 | obp+=sizeof(long);
|
---|
248 | }
|
---|
249 |
|
---|
250 | goto directmem;
|
---|
251 | }
|
---|
252 | else if(pRelativeVar->dwKind==VAR_DIRECTMEM){
|
---|
253 | directmem:
|
---|
254 | //mov reg, ptr[r11]
|
---|
255 | compiler.codeGenerator.op_mov_RM(varSize,reg,REG_R11,0,MOD_BASE);
|
---|
256 | }
|
---|
257 | }
|
---|