1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef V8_ARM64_DECODER_ARM64_INL_H_
6 #define V8_ARM64_DECODER_ARM64_INL_H_
8 #include "arm64/decoder-arm64.h"
17 // Top-level instruction decode function.
19 void Decoder<V>::Decode(Instruction *instr) {
20 if (instr->Bits(28, 27) == 0) {
21 V::VisitUnallocated(instr);
23 switch (instr->Bits(27, 24)) {
24 // 0: PC relative addressing.
25 case 0x0: DecodePCRelAddressing(instr); break;
27 // 1: Add/sub immediate.
28 case 0x1: DecodeAddSubImmediate(instr); break;
30 // A: Logical shifted register.
31 // Add/sub with carry.
32 // Conditional compare register.
33 // Conditional compare immediate.
34 // Conditional select.
35 // Data processing 1 source.
36 // Data processing 2 source.
37 // B: Add/sub shifted register.
38 // Add/sub extended register.
39 // Data processing 3 source.
41 case 0xB: DecodeDataProcessing(instr); break;
43 // 2: Logical immediate.
44 // Move wide immediate.
45 case 0x2: DecodeLogical(instr); break;
49 case 0x3: DecodeBitfieldExtract(instr); break;
51 // 4: Unconditional branch immediate.
52 // Exception generation.
53 // Compare and branch immediate.
54 // 5: Compare and branch immediate.
55 // Conditional branch.
57 // 6,7: Unconditional branch.
58 // Test and branch immediate.
62 case 0x7: DecodeBranchSystemException(instr); break;
64 // 8,9: Load/store register pair post-index.
65 // Load register literal.
66 // Load/store register unscaled immediate.
67 // Load/store register immediate post-index.
68 // Load/store register immediate pre-index.
69 // Load/store register offset.
70 // C,D: Load/store register pair offset.
71 // Load/store register pair pre-index.
72 // Load/store register unsigned immediate.
77 case 0xD: DecodeLoadStore(instr); break;
79 // E: FP fixed point conversion.
80 // FP integer conversion.
81 // FP data processing 1 source.
84 // FP data processing 2 source.
85 // FP conditional compare.
86 // FP conditional select.
88 // F: FP data processing 3 source.
91 case 0xF: DecodeFP(instr); break;
98 void Decoder<V>::DecodePCRelAddressing(Instruction* instr) {
99 ASSERT(instr->Bits(27, 24) == 0x0);
100 // We know bit 28 is set, as <b28:b27> = 0 is filtered out at the top level
102 ASSERT(instr->Bit(28) == 0x1);
103 V::VisitPCRelAddressing(instr);
108 void Decoder<V>::DecodeBranchSystemException(Instruction* instr) {
109 ASSERT((instr->Bits(27, 24) == 0x4) ||
110 (instr->Bits(27, 24) == 0x5) ||
111 (instr->Bits(27, 24) == 0x6) ||
112 (instr->Bits(27, 24) == 0x7) );
114 switch (instr->Bits(31, 29)) {
117 V::VisitUnconditionalBranch(instr);
122 if (instr->Bit(25) == 0) {
123 V::VisitCompareBranch(instr);
125 V::VisitTestBranch(instr);
130 if (instr->Bit(25) == 0) {
131 if ((instr->Bit(24) == 0x1) ||
132 (instr->Mask(0x01000010) == 0x00000010)) {
133 V::VisitUnallocated(instr);
135 V::VisitConditionalBranch(instr);
138 V::VisitUnallocated(instr);
143 if (instr->Bit(25) == 0) {
144 if (instr->Bit(24) == 0) {
145 if ((instr->Bits(4, 2) != 0) ||
146 (instr->Mask(0x00E0001D) == 0x00200001) ||
147 (instr->Mask(0x00E0001D) == 0x00400001) ||
148 (instr->Mask(0x00E0001E) == 0x00200002) ||
149 (instr->Mask(0x00E0001E) == 0x00400002) ||
150 (instr->Mask(0x00E0001C) == 0x00600000) ||
151 (instr->Mask(0x00E0001C) == 0x00800000) ||
152 (instr->Mask(0x00E0001F) == 0x00A00000) ||
153 (instr->Mask(0x00C0001C) == 0x00C00000)) {
154 V::VisitUnallocated(instr);
156 V::VisitException(instr);
159 if (instr->Bits(23, 22) == 0) {
160 const Instr masked_003FF0E0 = instr->Mask(0x003FF0E0);
161 if ((instr->Bits(21, 19) == 0x4) ||
162 (masked_003FF0E0 == 0x00033000) ||
163 (masked_003FF0E0 == 0x003FF020) ||
164 (masked_003FF0E0 == 0x003FF060) ||
165 (masked_003FF0E0 == 0x003FF0E0) ||
166 (instr->Mask(0x00388000) == 0x00008000) ||
167 (instr->Mask(0x0038E000) == 0x00000000) ||
168 (instr->Mask(0x0039E000) == 0x00002000) ||
169 (instr->Mask(0x003AE000) == 0x00002000) ||
170 (instr->Mask(0x003CE000) == 0x00042000) ||
171 (instr->Mask(0x003FFFC0) == 0x000320C0) ||
172 (instr->Mask(0x003FF100) == 0x00032100) ||
173 (instr->Mask(0x003FF200) == 0x00032200) ||
174 (instr->Mask(0x003FF400) == 0x00032400) ||
175 (instr->Mask(0x003FF800) == 0x00032800) ||
176 (instr->Mask(0x0038F000) == 0x00005000) ||
177 (instr->Mask(0x0038E000) == 0x00006000)) {
178 V::VisitUnallocated(instr);
180 V::VisitSystem(instr);
183 V::VisitUnallocated(instr);
187 if ((instr->Bit(24) == 0x1) ||
188 (instr->Bits(20, 16) != 0x1F) ||
189 (instr->Bits(15, 10) != 0) ||
190 (instr->Bits(4, 0) != 0) ||
191 (instr->Bits(24, 21) == 0x3) ||
192 (instr->Bits(24, 22) == 0x3)) {
193 V::VisitUnallocated(instr);
195 V::VisitUnconditionalBranchToRegister(instr);
202 V::VisitUnallocated(instr);
210 void Decoder<V>::DecodeLoadStore(Instruction* instr) {
211 ASSERT((instr->Bits(27, 24) == 0x8) ||
212 (instr->Bits(27, 24) == 0x9) ||
213 (instr->Bits(27, 24) == 0xC) ||
214 (instr->Bits(27, 24) == 0xD) );
216 if (instr->Bit(24) == 0) {
217 if (instr->Bit(28) == 0) {
218 if (instr->Bit(29) == 0) {
219 if (instr->Bit(26) == 0) {
220 // TODO(all): VisitLoadStoreExclusive.
221 V::VisitUnimplemented(instr);
223 DecodeAdvSIMDLoadStore(instr);
226 if ((instr->Bits(31, 30) == 0x3) ||
227 (instr->Mask(0xC4400000) == 0x40000000)) {
228 V::VisitUnallocated(instr);
230 if (instr->Bit(23) == 0) {
231 if (instr->Mask(0xC4400000) == 0xC0400000) {
232 V::VisitUnallocated(instr);
234 V::VisitLoadStorePairNonTemporal(instr);
237 V::VisitLoadStorePairPostIndex(instr);
242 if (instr->Bit(29) == 0) {
243 if (instr->Mask(0xC4000000) == 0xC4000000) {
244 V::VisitUnallocated(instr);
246 V::VisitLoadLiteral(instr);
249 if ((instr->Mask(0x84C00000) == 0x80C00000) ||
250 (instr->Mask(0x44800000) == 0x44800000) ||
251 (instr->Mask(0x84800000) == 0x84800000)) {
252 V::VisitUnallocated(instr);
254 if (instr->Bit(21) == 0) {
255 switch (instr->Bits(11, 10)) {
257 V::VisitLoadStoreUnscaledOffset(instr);
261 if (instr->Mask(0xC4C00000) == 0xC0800000) {
262 V::VisitUnallocated(instr);
264 V::VisitLoadStorePostIndex(instr);
269 // TODO(all): VisitLoadStoreRegisterOffsetUnpriv.
270 V::VisitUnimplemented(instr);
274 if (instr->Mask(0xC4C00000) == 0xC0800000) {
275 V::VisitUnallocated(instr);
277 V::VisitLoadStorePreIndex(instr);
283 if (instr->Bits(11, 10) == 0x2) {
284 if (instr->Bit(14) == 0) {
285 V::VisitUnallocated(instr);
287 V::VisitLoadStoreRegisterOffset(instr);
290 V::VisitUnallocated(instr);
297 if (instr->Bit(28) == 0) {
298 if (instr->Bit(29) == 0) {
299 V::VisitUnallocated(instr);
301 if ((instr->Bits(31, 30) == 0x3) ||
302 (instr->Mask(0xC4400000) == 0x40000000)) {
303 V::VisitUnallocated(instr);
305 if (instr->Bit(23) == 0) {
306 V::VisitLoadStorePairOffset(instr);
308 V::VisitLoadStorePairPreIndex(instr);
313 if (instr->Bit(29) == 0) {
314 V::VisitUnallocated(instr);
316 if ((instr->Mask(0x84C00000) == 0x80C00000) ||
317 (instr->Mask(0x44800000) == 0x44800000) ||
318 (instr->Mask(0x84800000) == 0x84800000)) {
319 V::VisitUnallocated(instr);
321 V::VisitLoadStoreUnsignedOffset(instr);
330 void Decoder<V>::DecodeLogical(Instruction* instr) {
331 ASSERT(instr->Bits(27, 24) == 0x2);
333 if (instr->Mask(0x80400000) == 0x00400000) {
334 V::VisitUnallocated(instr);
336 if (instr->Bit(23) == 0) {
337 V::VisitLogicalImmediate(instr);
339 if (instr->Bits(30, 29) == 0x1) {
340 V::VisitUnallocated(instr);
342 V::VisitMoveWideImmediate(instr);
350 void Decoder<V>::DecodeBitfieldExtract(Instruction* instr) {
351 ASSERT(instr->Bits(27, 24) == 0x3);
353 if ((instr->Mask(0x80400000) == 0x80000000) ||
354 (instr->Mask(0x80400000) == 0x00400000) ||
355 (instr->Mask(0x80008000) == 0x00008000)) {
356 V::VisitUnallocated(instr);
357 } else if (instr->Bit(23) == 0) {
358 if ((instr->Mask(0x80200000) == 0x00200000) ||
359 (instr->Mask(0x60000000) == 0x60000000)) {
360 V::VisitUnallocated(instr);
362 V::VisitBitfield(instr);
365 if ((instr->Mask(0x60200000) == 0x00200000) ||
366 (instr->Mask(0x60000000) != 0x00000000)) {
367 V::VisitUnallocated(instr);
369 V::VisitExtract(instr);
376 void Decoder<V>::DecodeAddSubImmediate(Instruction* instr) {
377 ASSERT(instr->Bits(27, 24) == 0x1);
378 if (instr->Bit(23) == 1) {
379 V::VisitUnallocated(instr);
381 V::VisitAddSubImmediate(instr);
387 void Decoder<V>::DecodeDataProcessing(Instruction* instr) {
388 ASSERT((instr->Bits(27, 24) == 0xA) ||
389 (instr->Bits(27, 24) == 0xB) );
391 if (instr->Bit(24) == 0) {
392 if (instr->Bit(28) == 0) {
393 if (instr->Mask(0x80008000) == 0x00008000) {
394 V::VisitUnallocated(instr);
396 V::VisitLogicalShifted(instr);
399 switch (instr->Bits(23, 21)) {
401 if (instr->Mask(0x0000FC00) != 0) {
402 V::VisitUnallocated(instr);
404 V::VisitAddSubWithCarry(instr);
409 if ((instr->Bit(29) == 0) ||
410 (instr->Mask(0x00000410) != 0)) {
411 V::VisitUnallocated(instr);
413 if (instr->Bit(11) == 0) {
414 V::VisitConditionalCompareRegister(instr);
416 V::VisitConditionalCompareImmediate(instr);
422 if (instr->Mask(0x20000800) != 0x00000000) {
423 V::VisitUnallocated(instr);
425 V::VisitConditionalSelect(instr);
430 if (instr->Bit(29) == 0x1) {
431 V::VisitUnallocated(instr);
433 if (instr->Bit(30) == 0) {
434 if ((instr->Bit(15) == 0x1) ||
435 (instr->Bits(15, 11) == 0) ||
436 (instr->Bits(15, 12) == 0x1) ||
437 (instr->Bits(15, 12) == 0x3) ||
438 (instr->Bits(15, 13) == 0x3) ||
439 (instr->Mask(0x8000EC00) == 0x00004C00) ||
440 (instr->Mask(0x8000E800) == 0x80004000) ||
441 (instr->Mask(0x8000E400) == 0x80004000)) {
442 V::VisitUnallocated(instr);
444 V::VisitDataProcessing2Source(instr);
447 if ((instr->Bit(13) == 1) ||
448 (instr->Bits(20, 16) != 0) ||
449 (instr->Bits(15, 14) != 0) ||
450 (instr->Mask(0xA01FFC00) == 0x00000C00) ||
451 (instr->Mask(0x201FF800) == 0x00001800)) {
452 V::VisitUnallocated(instr);
454 V::VisitDataProcessing1Source(instr);
463 case 7: V::VisitUnallocated(instr); break;
467 if (instr->Bit(28) == 0) {
468 if (instr->Bit(21) == 0) {
469 if ((instr->Bits(23, 22) == 0x3) ||
470 (instr->Mask(0x80008000) == 0x00008000)) {
471 V::VisitUnallocated(instr);
473 V::VisitAddSubShifted(instr);
476 if ((instr->Mask(0x00C00000) != 0x00000000) ||
477 (instr->Mask(0x00001400) == 0x00001400) ||
478 (instr->Mask(0x00001800) == 0x00001800)) {
479 V::VisitUnallocated(instr);
481 V::VisitAddSubExtended(instr);
485 if ((instr->Bit(30) == 0x1) ||
486 (instr->Bits(30, 29) == 0x1) ||
487 (instr->Mask(0xE0600000) == 0x00200000) ||
488 (instr->Mask(0xE0608000) == 0x00400000) ||
489 (instr->Mask(0x60608000) == 0x00408000) ||
490 (instr->Mask(0x60E00000) == 0x00E00000) ||
491 (instr->Mask(0x60E00000) == 0x00800000) ||
492 (instr->Mask(0x60E00000) == 0x00600000)) {
493 V::VisitUnallocated(instr);
495 V::VisitDataProcessing3Source(instr);
503 void Decoder<V>::DecodeFP(Instruction* instr) {
504 ASSERT((instr->Bits(27, 24) == 0xE) ||
505 (instr->Bits(27, 24) == 0xF) );
507 if (instr->Bit(28) == 0) {
508 DecodeAdvSIMDDataProcessing(instr);
510 if (instr->Bit(29) == 1) {
511 V::VisitUnallocated(instr);
513 if (instr->Bits(31, 30) == 0x3) {
514 V::VisitUnallocated(instr);
515 } else if (instr->Bits(31, 30) == 0x1) {
516 DecodeAdvSIMDDataProcessing(instr);
518 if (instr->Bit(24) == 0) {
519 if (instr->Bit(21) == 0) {
520 if ((instr->Bit(23) == 1) ||
521 (instr->Bit(18) == 1) ||
522 (instr->Mask(0x80008000) == 0x00000000) ||
523 (instr->Mask(0x000E0000) == 0x00000000) ||
524 (instr->Mask(0x000E0000) == 0x000A0000) ||
525 (instr->Mask(0x00160000) == 0x00000000) ||
526 (instr->Mask(0x00160000) == 0x00120000)) {
527 V::VisitUnallocated(instr);
529 V::VisitFPFixedPointConvert(instr);
532 if (instr->Bits(15, 10) == 32) {
533 V::VisitUnallocated(instr);
534 } else if (instr->Bits(15, 10) == 0) {
535 if ((instr->Bits(23, 22) == 0x3) ||
536 (instr->Mask(0x000E0000) == 0x000A0000) ||
537 (instr->Mask(0x000E0000) == 0x000C0000) ||
538 (instr->Mask(0x00160000) == 0x00120000) ||
539 (instr->Mask(0x00160000) == 0x00140000) ||
540 (instr->Mask(0x20C40000) == 0x00800000) ||
541 (instr->Mask(0x20C60000) == 0x00840000) ||
542 (instr->Mask(0xA0C60000) == 0x80060000) ||
543 (instr->Mask(0xA0C60000) == 0x00860000) ||
544 (instr->Mask(0xA0C60000) == 0x00460000) ||
545 (instr->Mask(0xA0CE0000) == 0x80860000) ||
546 (instr->Mask(0xA0CE0000) == 0x804E0000) ||
547 (instr->Mask(0xA0CE0000) == 0x000E0000) ||
548 (instr->Mask(0xA0D60000) == 0x00160000) ||
549 (instr->Mask(0xA0D60000) == 0x80560000) ||
550 (instr->Mask(0xA0D60000) == 0x80960000)) {
551 V::VisitUnallocated(instr);
553 V::VisitFPIntegerConvert(instr);
555 } else if (instr->Bits(14, 10) == 16) {
556 const Instr masked_A0DF8000 = instr->Mask(0xA0DF8000);
557 if ((instr->Mask(0x80180000) != 0) ||
558 (masked_A0DF8000 == 0x00020000) ||
559 (masked_A0DF8000 == 0x00030000) ||
560 (masked_A0DF8000 == 0x00068000) ||
561 (masked_A0DF8000 == 0x00428000) ||
562 (masked_A0DF8000 == 0x00430000) ||
563 (masked_A0DF8000 == 0x00468000) ||
564 (instr->Mask(0xA0D80000) == 0x00800000) ||
565 (instr->Mask(0xA0DE0000) == 0x00C00000) ||
566 (instr->Mask(0xA0DF0000) == 0x00C30000) ||
567 (instr->Mask(0xA0DC0000) == 0x00C40000)) {
568 V::VisitUnallocated(instr);
570 V::VisitFPDataProcessing1Source(instr);
572 } else if (instr->Bits(13, 10) == 8) {
573 if ((instr->Bits(15, 14) != 0) ||
574 (instr->Bits(2, 0) != 0) ||
575 (instr->Mask(0x80800000) != 0x00000000)) {
576 V::VisitUnallocated(instr);
578 V::VisitFPCompare(instr);
580 } else if (instr->Bits(12, 10) == 4) {
581 if ((instr->Bits(9, 5) != 0) ||
582 (instr->Mask(0x80800000) != 0x00000000)) {
583 V::VisitUnallocated(instr);
585 V::VisitFPImmediate(instr);
588 if (instr->Mask(0x80800000) != 0x00000000) {
589 V::VisitUnallocated(instr);
591 switch (instr->Bits(11, 10)) {
593 V::VisitFPConditionalCompare(instr);
597 if ((instr->Bits(15, 14) == 0x3) ||
598 (instr->Mask(0x00009000) == 0x00009000) ||
599 (instr->Mask(0x0000A000) == 0x0000A000)) {
600 V::VisitUnallocated(instr);
602 V::VisitFPDataProcessing2Source(instr);
607 V::VisitFPConditionalSelect(instr);
610 default: UNREACHABLE();
616 // Bit 30 == 1 has been handled earlier.
617 ASSERT(instr->Bit(30) == 0);
618 if (instr->Mask(0xA0800000) != 0) {
619 V::VisitUnallocated(instr);
621 V::VisitFPDataProcessing3Source(instr);
631 void Decoder<V>::DecodeAdvSIMDLoadStore(Instruction* instr) {
632 // TODO(all): Implement Advanced SIMD load/store instruction decode.
633 ASSERT(instr->Bits(29, 25) == 0x6);
634 V::VisitUnimplemented(instr);
639 void Decoder<V>::DecodeAdvSIMDDataProcessing(Instruction* instr) {
640 // TODO(all): Implement Advanced SIMD data processing instruction decode.
641 ASSERT(instr->Bits(27, 25) == 0x7);
642 V::VisitUnimplemented(instr);
646 } } // namespace v8::internal
648 #endif // V8_ARM64_DECODER_ARM64_INL_H_