source: dev/trunk/abdev/BasicCompiler64/Compile_Calc_PushVar.cpp@ 228

Last change on this file since 228 was 228, checked in by dai_9181, 17 years ago
File size: 7.4 KB
Line 
1#include "stdafx.h"
2
3#include <Compiler.h>
4
5#include "../BasicCompiler_Common/common.h"
6#include "Opcode.h"
7
8
9void 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){
84directmem:
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}
93void 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){
168directmem:
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
179void 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, Schedule::GlobalVar );
188 }
189 else{
190 //mov reg, ptr[offset]
191 compiler.codeGenerator.op_mov_RM(varSize,reg,0,(int)pRelativeVar->offset,MOD_DISP32, Schedule::GlobalVar );
192 }
193 }
194 else if( pRelativeVar->dwKind == VAR_REFGLOBAL ){
195 if(pRelativeVar->bOffsetOffset){
196 //add r11,qword ptr[offset]
197 compiler.codeGenerator.op_add_RM(sizeof(_int64),REG_R11,REG_NON,(int)pRelativeVar->offset,MOD_DISP32, Schedule::GlobalVar );
198 }
199 else{
200 //mov r11,qword ptr[offset]
201 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_NON,(int)pRelativeVar->offset,MOD_DISP32, Schedule::GlobalVar );
202 }
203
204 goto directmem;
205 }
206 else if(pRelativeVar->dwKind==VAR_LOCAL){
207 if(pRelativeVar->bOffsetOffset){
208 //mov reg, ptr[rsp+r11+offset]
209 compiler.codeGenerator.op_mov_RM_ex(varSize,reg,REG_RSP,REG_R11,(int)pRelativeVar->offset,USE_OFFSET, Schedule::LocalVar );
210 }
211 else{
212 //mov reg, ptr[rsp+offset]
213 compiler.codeGenerator.op_mov_RM(varSize,reg,REG_RSP,(int)pRelativeVar->offset,MOD_BASE_DISP32, Schedule::LocalVar );
214 }
215 }
216 else if( pRelativeVar->dwKind == VAR_REFLOCAL ){
217 if(pRelativeVar->bOffsetOffset){
218 //add r11,qword ptr[rsp+offset]
219 compiler.codeGenerator.op_add_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelativeVar->offset,MOD_BASE_DISP32, Schedule::LocalVar );
220 }
221 else{
222 //mov r11,qword ptr[rsp+offset]
223 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelativeVar->offset,MOD_BASE_DISP32, Schedule::LocalVar );
224 }
225
226 goto directmem;
227 }
228 else if(pRelativeVar->dwKind==VAR_DIRECTMEM){
229directmem:
230 //mov reg, ptr[r11]
231 compiler.codeGenerator.op_mov_RM(varSize,reg,REG_R11,0,MOD_BASE);
232 }
233}
Note: See TracBrowser for help on using the repository browser.