Mercurial > hg > truffle
comparison graal/com.oracle.max.asmdis/src/com/sun/max/asm/gen/cisc/amd64/AMD64Template.java @ 3733:e233f5660da4
Added Java files from Maxine project.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Sat, 17 Dec 2011 19:59:18 +0100 |
parents | |
children | bc8527f3071c |
comparison
equal
deleted
inserted
replaced
3732:3e2e8b8abdaf | 3733:e233f5660da4 |
---|---|
1 /* | |
2 * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
23 package com.sun.max.asm.gen.cisc.amd64; | |
24 | |
25 import java.util.*; | |
26 | |
27 import com.sun.max.asm.*; | |
28 import com.sun.max.asm.amd64.*; | |
29 import com.sun.max.asm.gen.*; | |
30 import com.sun.max.asm.gen.cisc.*; | |
31 import com.sun.max.asm.gen.cisc.x86.*; | |
32 import com.sun.max.asm.x86.*; | |
33 import com.sun.max.lang.*; | |
34 import com.sun.max.program.*; | |
35 | |
36 /** | |
37 */ | |
38 public class AMD64Template extends X86Template { | |
39 | |
40 public AMD64Template(X86InstructionDescription instructionDescription, int serial, InstructionAssessment instructionFamily, X86TemplateContext context) { | |
41 super(instructionDescription, serial, instructionFamily, context); | |
42 } | |
43 | |
44 private void addSib(X86Operand.Designation designation) throws TemplateNotNeededException { | |
45 assert context().addressSizeAttribute() != WordWidth.BITS_16; | |
46 haveSibByte(); | |
47 switch (context().sibBaseCase()) { | |
48 case GENERAL_REGISTER: { // base register | |
49 switch (context().addressSizeAttribute()) { | |
50 case BITS_32: | |
51 setExternalCodeSizeAttribute(context().addressSizeAttribute()); | |
52 addEnumerableParameter(designation, ParameterPlace.SIB_BASE, AMD64BaseRegister32.ENUMERATOR); | |
53 break; | |
54 case BITS_64: | |
55 addEnumerableParameter(designation, ParameterPlace.SIB_BASE_REXB, AMD64BaseRegister64.ENUMERATOR); | |
56 break; | |
57 default: | |
58 throw ProgramError.unexpected(); | |
59 } | |
60 break; | |
61 } | |
62 case SPECIAL: { // displacement based specified | |
63 switch (context().modCase()) { | |
64 case MOD_0: { | |
65 setExternalCodeSizeAttribute(context().addressSizeAttribute()); | |
66 /* [disp32 + index] | |
67 * Although this could be a label parameter, we disable it for now due to complications in the assembler and | |
68 * the fact that this instruction may not be very useful. This 32-bit displacement base is an absolute pointer to | |
69 * memory, therefore it cannot address memory above 4GB. However, the assembler currently only supports | |
70 * constraints for user-specified parameters and not constraints on label parameters that need to be checked at | |
71 * assemble time. | |
72 */ | |
73 //setLabelParameterIndex(); | |
74 addParameter(new X86AddressParameter(designation, WordWidth.BITS_32)); | |
75 break; | |
76 } | |
77 default: { | |
78 throw ProgramError.unexpected("no special SIB base for mod != 0"); | |
79 } | |
80 } | |
81 break; | |
82 } | |
83 } | |
84 switch (context().sibIndexCase()) { | |
85 case GENERAL_REGISTER: | |
86 switch (context().addressSizeAttribute()) { | |
87 case BITS_32: | |
88 setExternalCodeSizeAttribute(context().addressSizeAttribute()); | |
89 addEnumerableParameter(designation, ParameterPlace.SIB_INDEX, AMD64IndexRegister32.ENUMERATOR); | |
90 break; | |
91 case BITS_64: | |
92 addEnumerableParameter(designation, ParameterPlace.SIB_INDEX_REXX, AMD64IndexRegister64.ENUMERATOR); | |
93 break; | |
94 default: | |
95 ProgramError.unexpected(); | |
96 } | |
97 break; | |
98 case NONE: | |
99 // Our external assembler (gas) cannot generate these cases and they seem redundant anyway, | |
100 // so for now we do not produce them: | |
101 TemplateNotNeededException.raise(); | |
102 } | |
103 addParameter(new X86EnumerableParameter<Scale>(designation, ParameterPlace.SIB_SCALE, Scale.ENUMERATOR)); | |
104 } | |
105 | |
106 /** | |
107 * Populate templates for ModRM Memory Reference operands. See "Table A-13. ModRM Memory References, 16-Bit Addressing" and | |
108 * "Table A-15. ModRM Memory References, 32-Bit and 64-Bit Addressing". | |
109 */ | |
110 @Override | |
111 protected void organize_M(X86Operand.Designation designation) throws TemplateNotNeededException { | |
112 switch (context().modCase()) { | |
113 case MOD_0: { | |
114 switch (context().rmCase()) { | |
115 case NORMAL: | |
116 switch (context().addressSizeAttribute()) { | |
117 case BITS_32: | |
118 setExternalCodeSizeAttribute(context().addressSizeAttribute()); | |
119 addEnumerableParameter(designation, ParameterPlace.MOD_RM_REXB, AMD64IndirectRegister32.ENUMERATOR); | |
120 break; | |
121 case BITS_64: | |
122 addEnumerableParameter(designation, ParameterPlace.MOD_RM_REXB, AMD64IndirectRegister64.ENUMERATOR); | |
123 break; | |
124 default: | |
125 throw ProgramError.unexpected(); | |
126 } | |
127 break; | |
128 case SWORD: | |
129 switch (context().addressSizeAttribute()) { | |
130 case BITS_16: | |
131 addParameter(new X86AddressParameter(designation, WordWidth.BITS_16)); | |
132 break; | |
133 default: | |
134 TemplateNotNeededException.raise(); | |
135 } | |
136 break; | |
137 case SDWORD: | |
138 switch (context().addressSizeAttribute()) { | |
139 case BITS_64: | |
140 useNamePrefix("rip_"); | |
141 setLabelParameterIndex(); | |
142 addParameter(new X86OffsetParameter(designation, WordWidth.BITS_32)); | |
143 break; | |
144 case BITS_32: | |
145 setExternalCodeSizeAttribute(context().addressSizeAttribute()); | |
146 addParameter(new X86AddressParameter(designation, WordWidth.BITS_32)); | |
147 break; | |
148 default: | |
149 TemplateNotNeededException.raise(); | |
150 } | |
151 break; | |
152 case SIB: | |
153 addSib(designation); | |
154 break; | |
155 } | |
156 break; | |
157 } | |
158 case MOD_1: { | |
159 addParameter(new X86DisplacementParameter(designation, WordWidth.BITS_8)); | |
160 switch (context().rmCase()) { | |
161 case NORMAL: | |
162 switch (context().addressSizeAttribute()) { | |
163 case BITS_32: | |
164 setExternalCodeSizeAttribute(context().addressSizeAttribute()); | |
165 addEnumerableParameter(designation, ParameterPlace.MOD_RM_REXB, AMD64IndirectRegister32.ENUMERATOR); | |
166 break; | |
167 case BITS_64: | |
168 addEnumerableParameter(designation, ParameterPlace.MOD_RM_REXB, AMD64IndirectRegister64.ENUMERATOR); | |
169 break; | |
170 default: | |
171 throw ProgramError.unexpected(); | |
172 } | |
173 break; | |
174 case SIB: | |
175 addSib(designation); | |
176 break; | |
177 default: | |
178 TemplateNotNeededException.raise(); | |
179 } | |
180 break; | |
181 } | |
182 case MOD_2: { | |
183 switch (context().addressSizeAttribute()) { | |
184 case BITS_16: | |
185 addParameter(new X86DisplacementParameter(designation, WordWidth.BITS_16)); | |
186 break; | |
187 case BITS_32: | |
188 case BITS_64: | |
189 addParameter(new X86DisplacementParameter(designation, WordWidth.BITS_32)); | |
190 break; | |
191 default: | |
192 throw ProgramError.unexpected(); | |
193 } | |
194 switch (context().rmCase()) { | |
195 case NORMAL: | |
196 switch (context().addressSizeAttribute()) { | |
197 case BITS_32: | |
198 setExternalCodeSizeAttribute(context().addressSizeAttribute()); | |
199 addEnumerableParameter(designation, ParameterPlace.MOD_RM_REXB, AMD64IndirectRegister32.ENUMERATOR); | |
200 break; | |
201 case BITS_64: | |
202 addEnumerableParameter(designation, ParameterPlace.MOD_RM_REXB, AMD64IndirectRegister64.ENUMERATOR); | |
203 break; | |
204 default: | |
205 throw ProgramError.unexpected(); | |
206 } | |
207 break; | |
208 case SIB: | |
209 addSib(designation); | |
210 break; | |
211 default: | |
212 TemplateNotNeededException.raise(); | |
213 } | |
214 break; | |
215 } | |
216 case MOD_3: { | |
217 TemplateNotNeededException.raise(); | |
218 } | |
219 } | |
220 } | |
221 | |
222 public void visitOperandCode(OperandCode operandCode, X86Operand.Designation designation, ArgumentRange argumentRange, TestArgumentExclusion testArgumentExclusion) | |
223 throws TemplateNotNeededException { | |
224 switch (operandCode) { | |
225 case Cq: { | |
226 addParameter(new X86EnumerableParameter<ControlRegister>(designation, ParameterPlace.MOD_REG, ControlRegister.ENUMERATOR)); | |
227 break; | |
228 } | |
229 case Dq: { | |
230 addParameter(new X86EnumerableParameter<DebugRegister>(designation, ParameterPlace.MOD_REG, DebugRegister.ENUMERATOR)); | |
231 break; | |
232 } | |
233 case Eb: { | |
234 organize_E(designation, ParameterPlace.MOD_RM_REXB, AMD64GeneralRegister8.ENUMERATOR, testArgumentExclusion); | |
235 break; | |
236 } | |
237 case Ed: { | |
238 organize_E(designation, ParameterPlace.MOD_RM_REXB, AMD64GeneralRegister32.ENUMERATOR, testArgumentExclusion); | |
239 break; | |
240 } | |
241 case Ed_q: { | |
242 visitOperandTypeCode(operandCode.operandTypeCode()); | |
243 switch (context().operandSizeAttribute()) { | |
244 case BITS_32: | |
245 organize_E(designation, ParameterPlace.MOD_RM_REXB, AMD64GeneralRegister32.ENUMERATOR, testArgumentExclusion); | |
246 break; | |
247 case BITS_64: | |
248 organize_E(designation, ParameterPlace.MOD_RM_REXB, AMD64GeneralRegister64.ENUMERATOR, testArgumentExclusion); | |
249 break; | |
250 default: | |
251 TemplateNotNeededException.raise(); | |
252 } | |
253 break; | |
254 } | |
255 case Ev: { | |
256 switch (context().operandSizeAttribute()) { | |
257 case BITS_16: | |
258 organize_E(designation, ParameterPlace.MOD_RM_REXB, AMD64GeneralRegister16.ENUMERATOR, testArgumentExclusion); | |
259 break; | |
260 case BITS_32: | |
261 organize_E(designation, ParameterPlace.MOD_RM_REXB, AMD64GeneralRegister32.ENUMERATOR, testArgumentExclusion); | |
262 break; | |
263 case BITS_64: | |
264 organize_E(designation, ParameterPlace.MOD_RM_REXB, AMD64GeneralRegister64.ENUMERATOR, testArgumentExclusion); | |
265 break; | |
266 default: | |
267 throw ProgramError.unexpected(); | |
268 } | |
269 break; | |
270 } | |
271 case Ew: { | |
272 organize_E(designation, ParameterPlace.MOD_RM_REXB, AMD64GeneralRegister16.ENUMERATOR, testArgumentExclusion); | |
273 break; | |
274 } | |
275 case Fv: { | |
276 break; | |
277 } | |
278 case Gb: { | |
279 addEnumerableParameter(designation, ParameterPlace.MOD_REG_REXR, AMD64GeneralRegister8.ENUMERATOR).excludeTestArguments(testArgumentExclusion); | |
280 break; | |
281 } | |
282 case Gd: { | |
283 addEnumerableParameter(designation, ParameterPlace.MOD_REG_REXR, AMD64GeneralRegister32.ENUMERATOR).excludeTestArguments(testArgumentExclusion); | |
284 break; | |
285 } | |
286 case Gd_q: { | |
287 switch (context().operandSizeAttribute()) { | |
288 case BITS_32: | |
289 addEnumerableParameter(designation, ParameterPlace.MOD_REG_REXR, AMD64GeneralRegister32.ENUMERATOR).excludeTestArguments(testArgumentExclusion); | |
290 break; | |
291 case BITS_64: | |
292 addEnumerableParameter(designation, ParameterPlace.MOD_REG_REXR, AMD64GeneralRegister64.ENUMERATOR).excludeTestArguments(testArgumentExclusion); | |
293 break; | |
294 default: | |
295 TemplateNotNeededException.raise(); | |
296 } | |
297 break; | |
298 } | |
299 case Gq: { | |
300 addEnumerableParameter(designation, ParameterPlace.MOD_REG_REXR, AMD64GeneralRegister64.ENUMERATOR).excludeTestArguments(testArgumentExclusion); | |
301 break; | |
302 } | |
303 case Gv: { | |
304 switch (context().operandSizeAttribute()) { | |
305 case BITS_16: | |
306 addEnumerableParameter(designation, ParameterPlace.MOD_REG_REXR, AMD64GeneralRegister16.ENUMERATOR).excludeTestArguments(testArgumentExclusion); | |
307 break; | |
308 case BITS_32: | |
309 addEnumerableParameter(designation, ParameterPlace.MOD_REG_REXR, AMD64GeneralRegister32.ENUMERATOR).excludeTestArguments(testArgumentExclusion); | |
310 break; | |
311 case BITS_64: | |
312 addEnumerableParameter(designation, ParameterPlace.MOD_REG_REXR, AMD64GeneralRegister64.ENUMERATOR).excludeTestArguments(testArgumentExclusion); | |
313 break; | |
314 default: | |
315 ProgramError.unexpected(); | |
316 } | |
317 break; | |
318 } | |
319 case Gw: { | |
320 addEnumerableParameter(designation, ParameterPlace.MOD_REG_REXR, AMD64GeneralRegister16.ENUMERATOR).excludeTestArguments(testArgumentExclusion); | |
321 break; | |
322 } | |
323 case Gz: { | |
324 switch (context().operandSizeAttribute()) { | |
325 case BITS_16: | |
326 addEnumerableParameter(designation, ParameterPlace.MOD_REG_REXR, AMD64GeneralRegister16.ENUMERATOR).excludeTestArguments(testArgumentExclusion); | |
327 break; | |
328 case BITS_32: | |
329 case BITS_64: | |
330 addEnumerableParameter(designation, ParameterPlace.MOD_REG_REXR, AMD64GeneralRegister32.ENUMERATOR).excludeTestArguments(testArgumentExclusion); | |
331 break; | |
332 default: | |
333 ProgramError.unexpected(); | |
334 } | |
335 break; | |
336 } | |
337 case Ib: { | |
338 addParameter(new X86ImmediateParameter(designation, WordWidth.BITS_8), argumentRange, testArgumentExclusion); | |
339 break; | |
340 } | |
341 case ICb: { | |
342 addEnumerableParameter(designation, ParameterPlace.APPEND, AMD64XMMComparison.ENUMERATOR); | |
343 break; | |
344 } | |
345 case Iv: { | |
346 addParameter(new X86ImmediateParameter(designation, context().operandSizeAttribute()), argumentRange, testArgumentExclusion); | |
347 break; | |
348 } | |
349 case Iw: { | |
350 addParameter(new X86ImmediateParameter(designation, WordWidth.BITS_16), argumentRange, testArgumentExclusion); | |
351 break; | |
352 } | |
353 case Iz: { | |
354 WordWidth operandSizeAttribute = context().operandSizeAttribute(); | |
355 if (operandSizeAttribute.greaterThan(WordWidth.BITS_32)) { | |
356 operandSizeAttribute = WordWidth.BITS_32; | |
357 } | |
358 addParameter(new X86ImmediateParameter(designation, operandSizeAttribute), argumentRange, testArgumentExclusion); | |
359 break; | |
360 } | |
361 case Jb: { | |
362 setLabelParameterIndex(); | |
363 addParameter(new X86OffsetParameter(designation, WordWidth.BITS_8)); | |
364 break; | |
365 } | |
366 case Jv: { | |
367 switch (context().operandSizeAttribute()) { | |
368 case BITS_16: | |
369 setLabelParameterIndex(); | |
370 addParameter(new X86OffsetParameter(designation, WordWidth.BITS_16)); | |
371 break; | |
372 case BITS_32: | |
373 setLabelParameterIndex(); | |
374 addParameter(new X86OffsetParameter(designation, WordWidth.BITS_32)); | |
375 break; | |
376 case BITS_64: | |
377 setLabelParameterIndex(); | |
378 addParameter(new X86OffsetParameter(designation, WordWidth.BITS_64)); | |
379 break; | |
380 default: | |
381 ProgramError.unexpected(); | |
382 } | |
383 break; | |
384 } | |
385 case Jz: { | |
386 switch (context().operandSizeAttribute()) { | |
387 case BITS_16: | |
388 setExternalCodeSizeAttribute(context().operandSizeAttribute()); | |
389 setLabelParameterIndex(); | |
390 addParameter(new X86OffsetParameter(designation, WordWidth.BITS_16)); | |
391 break; | |
392 case BITS_32: | |
393 case BITS_64: | |
394 setLabelParameterIndex(); | |
395 addParameter(new X86OffsetParameter(designation, WordWidth.BITS_32)); | |
396 break; | |
397 default: | |
398 ProgramError.unexpected(); | |
399 } | |
400 break; | |
401 } | |
402 case Md_q: { | |
403 if (operandSizeAttribute() == WordWidth.BITS_16) { | |
404 TemplateNotNeededException.raise(); | |
405 } | |
406 organize_M(designation); | |
407 break; | |
408 } | |
409 case Mb: | |
410 case Md: | |
411 case Mq: | |
412 case Mdq: | |
413 case Ms: | |
414 case Mv: | |
415 case Mw: { | |
416 organize_M(designation); | |
417 break; | |
418 } | |
419 case Nb: { | |
420 addEnumerableParameter(designation, ParameterPlace.OPCODE1_REXB, AMD64GeneralRegister8.ENUMERATOR).excludeTestArguments(testArgumentExclusion); | |
421 break; | |
422 } | |
423 case Nd_q: { | |
424 final ParameterPlace place = (opcode2() != null) ? ParameterPlace.OPCODE2_REXB : ParameterPlace.OPCODE1_REXB; | |
425 switch (context().operandSizeAttribute()) { | |
426 case BITS_32: | |
427 addEnumerableParameter(designation, place, AMD64GeneralRegister32.ENUMERATOR).excludeTestArguments(testArgumentExclusion); | |
428 break; | |
429 case BITS_64: | |
430 addEnumerableParameter(designation, place, AMD64GeneralRegister64.ENUMERATOR).excludeTestArguments(testArgumentExclusion); | |
431 break; | |
432 default: | |
433 TemplateNotNeededException.raise(); | |
434 } | |
435 break; | |
436 } | |
437 case Nv: | |
438 final ParameterPlace place = (opcode2() != null) ? ParameterPlace.OPCODE2_REXB : ParameterPlace.OPCODE1_REXB; | |
439 switch (context().operandSizeAttribute()) { | |
440 case BITS_16: | |
441 addEnumerableParameter(designation, place, AMD64GeneralRegister16.ENUMERATOR).excludeTestArguments(testArgumentExclusion); | |
442 break; | |
443 case BITS_32: | |
444 addEnumerableParameter(designation, place, AMD64GeneralRegister32.ENUMERATOR).excludeTestArguments(testArgumentExclusion); | |
445 break; | |
446 case BITS_64: | |
447 addEnumerableParameter(designation, place, AMD64GeneralRegister64.ENUMERATOR).excludeTestArguments(testArgumentExclusion); | |
448 break; | |
449 default: | |
450 ProgramError.unexpected(); | |
451 } | |
452 break; | |
453 case Ob: | |
454 case Ov: { | |
455 switch (context().addressSizeAttribute()) { | |
456 case BITS_32: | |
457 setExternalCodeSizeAttribute(context().addressSizeAttribute()); | |
458 addParameter(new X86AddressParameter(designation, WordWidth.BITS_32), argumentRange); | |
459 break; | |
460 case BITS_64: | |
461 setLabelParameterIndex(); | |
462 addParameter(new X86AddressParameter(designation, WordWidth.BITS_64), argumentRange); | |
463 break; | |
464 default: | |
465 ProgramError.unexpected(); | |
466 } | |
467 break; | |
468 } | |
469 case Pdq: { | |
470 addEnumerableParameter(designation, ParameterPlace.MOD_REG_REXR, AMD64XMMRegister.ENUMERATOR).excludeTestArguments(testArgumentExclusion); | |
471 break; | |
472 } | |
473 case Pq: { | |
474 addEnumerableParameter(designation, ParameterPlace.MOD_REG, MMXRegister.ENUMERATOR).excludeTestArguments(testArgumentExclusion); | |
475 break; | |
476 } | |
477 case PRq: { | |
478 if (context().modCase() != X86TemplateContext.ModCase.MOD_3) { | |
479 TemplateNotNeededException.raise(); | |
480 } | |
481 addEnumerableParameter(designation, ParameterPlace.MOD_RM, MMXRegister.ENUMERATOR).excludeTestArguments(testArgumentExclusion); | |
482 break; | |
483 } | |
484 case Qd: | |
485 case Qq: { | |
486 organize_E(designation, ParameterPlace.MOD_RM, MMXRegister.ENUMERATOR, testArgumentExclusion); | |
487 break; | |
488 } | |
489 case Rq: { | |
490 if (context().modCase() != X86TemplateContext.ModCase.MOD_3) { | |
491 TemplateNotNeededException.raise(); | |
492 } | |
493 addEnumerableParameter(designation, ParameterPlace.MOD_RM_REXB, AMD64GeneralRegister64.ENUMERATOR).excludeTestArguments(testArgumentExclusion); | |
494 break; | |
495 } | |
496 case Rv: | |
497 if (context().modCase() != X86TemplateContext.ModCase.MOD_3) { | |
498 TemplateNotNeededException.raise(); | |
499 } | |
500 switch (context().operandSizeAttribute()) { | |
501 case BITS_16: | |
502 addEnumerableParameter(designation, ParameterPlace.MOD_RM_REXB, AMD64GeneralRegister16.ENUMERATOR).excludeTestArguments(testArgumentExclusion); | |
503 break; | |
504 case BITS_32: | |
505 addEnumerableParameter(designation, ParameterPlace.MOD_RM_REXB, AMD64GeneralRegister32.ENUMERATOR).excludeTestArguments(testArgumentExclusion); | |
506 break; | |
507 case BITS_64: | |
508 addEnumerableParameter(designation, ParameterPlace.MOD_RM_REXB, AMD64GeneralRegister64.ENUMERATOR).excludeTestArguments(testArgumentExclusion); | |
509 break; | |
510 default: | |
511 ProgramError.unexpected(); | |
512 } | |
513 break; | |
514 case Sw: { | |
515 addEnumerableParameter(designation, ParameterPlace.MOD_REG, SegmentRegister.ENUMERATOR).excludeTestArguments(testArgumentExclusion); | |
516 break; | |
517 } | |
518 case Vpd: | |
519 case Vps: | |
520 case Vq: | |
521 case Vdq: | |
522 case Vsd: | |
523 case Vss: { | |
524 addEnumerableParameter(designation, ParameterPlace.MOD_REG_REXR, AMD64XMMRegister.ENUMERATOR).excludeTestArguments(testArgumentExclusion); | |
525 break; | |
526 } | |
527 case VRq: | |
528 case VRdq: | |
529 case VRpd: | |
530 case VRps: { | |
531 if (context().modCase() != X86TemplateContext.ModCase.MOD_3) { | |
532 TemplateNotNeededException.raise(); | |
533 } | |
534 addEnumerableParameter(designation, ParameterPlace.MOD_RM_REXB, AMD64XMMRegister.ENUMERATOR).excludeTestArguments(testArgumentExclusion); | |
535 break; | |
536 } | |
537 case Wdq: | |
538 case Wpd: | |
539 case Wps: | |
540 case Wq: | |
541 case Wsd: | |
542 case Wss: { | |
543 switch (context().operandSizeAttribute()) { | |
544 case BITS_32: | |
545 case BITS_64: | |
546 organize_E(designation, ParameterPlace.MOD_RM_REXB, AMD64XMMRegister.ENUMERATOR, testArgumentExclusion); | |
547 break; | |
548 default: | |
549 TemplateNotNeededException.raise(); | |
550 } | |
551 break; | |
552 } | |
553 case Xz: | |
554 case Yz: { | |
555 switch (operandSizeAttribute()) { | |
556 case BITS_16: | |
557 setOperandTypeSuffix("w"); | |
558 break; | |
559 case BITS_32: | |
560 setOperandTypeSuffix("l"); | |
561 break; | |
562 default: | |
563 TemplateNotNeededException.raise(); | |
564 } | |
565 break; | |
566 } | |
567 case Xb: | |
568 case Xv: | |
569 case Yb: | |
570 case Yv: { | |
571 visitOperandTypeCode(operandCode.operandTypeCode()); | |
572 break; | |
573 } | |
574 default: | |
575 throw ProgramError.unexpected("undefined operand code: " + operandCode); | |
576 } | |
577 } | |
578 | |
579 public void visitRegisterOperandCode(RegisterOperandCode registerOperandCode, X86Operand.Designation designation, ImplicitOperand.ExternalPresence externalPresence) { | |
580 switch (operandSizeAttribute()) { | |
581 case BITS_16: | |
582 addImplicitOperand(new X86ImplicitOperand(designation, externalPresence, AMD64GeneralRegister16.ENUMERATOR.get(registerOperandCode.id()))); | |
583 break; | |
584 case BITS_32: | |
585 addImplicitOperand(new X86ImplicitOperand(designation, externalPresence, AMD64GeneralRegister32.ENUMERATOR.get(registerOperandCode.id()))); | |
586 break; | |
587 case BITS_64: | |
588 addImplicitOperand(new X86ImplicitOperand(designation, externalPresence, AMD64GeneralRegister64.ENUMERATOR.get(registerOperandCode.id()))); | |
589 break; | |
590 default: | |
591 throw ProgramError.unexpected(); | |
592 } | |
593 } | |
594 | |
595 public boolean hasRexPrefix(List<Argument> arguments) { | |
596 if (instructionDescription().defaultOperandSize() == WordWidth.BITS_64) { | |
597 return false; | |
598 } | |
599 if (operandSizeAttribute() == WordWidth.BITS_64) { | |
600 return true; | |
601 } | |
602 for (Argument argument : arguments) { | |
603 if (argument instanceof GeneralRegister) { | |
604 if (argument instanceof AMD64GeneralRegister8) { | |
605 final AMD64GeneralRegister8 generalRegister8 = (AMD64GeneralRegister8) argument; | |
606 if (generalRegister8.requiresRexPrefix()) { | |
607 return true; | |
608 } | |
609 } else { | |
610 final GeneralRegister generalRegister = (GeneralRegister) argument; | |
611 if (generalRegister.value() >= 8) { | |
612 return true; | |
613 } | |
614 } | |
615 } | |
616 } | |
617 return false; | |
618 } | |
619 } |