30 #if V8_TARGET_ARCH_MIPS 32 #include "src/base/platform/platform.h" 33 #include "src/disasm.h" 34 #include "src/macro-assembler.h" 35 #include "src/mips/constants-mips.h" 49 : converter_(converter),
50 out_buffer_(out_buffer),
52 out_buffer_[out_buffer_pos_] =
'\0';
59 int InstructionDecode(byte* instruction);
63 void PrintChar(
const char ch);
64 void Print(
const char* str);
67 void PrintRegister(
int reg);
68 void PrintFPURegister(
int freg);
69 void PrintMSARegister(
int wreg);
70 void PrintFPUStatusRegister(
int freg);
71 void PrintMSAControlRegister(
int creg);
72 void PrintRs(Instruction* instr);
73 void PrintRt(Instruction* instr);
74 void PrintRd(Instruction* instr);
75 void PrintFs(Instruction* instr);
76 void PrintFt(Instruction* instr);
77 void PrintFd(Instruction* instr);
78 void PrintSa(Instruction* instr);
79 void PrintLsaSa(Instruction* instr);
80 void PrintSd(Instruction* instr);
81 void PrintSs1(Instruction* instr);
82 void PrintSs2(Instruction* instr);
83 void PrintBc(Instruction* instr);
84 void PrintCc(Instruction* instr);
85 void PrintBp2(Instruction* instr);
86 void PrintFunction(Instruction* instr);
87 void PrintSecondaryField(Instruction* instr);
88 void PrintUImm9(Instruction* instr);
89 void PrintSImm9(Instruction* instr);
90 void PrintUImm16(Instruction* instr);
91 void PrintSImm16(Instruction* instr);
92 void PrintXImm16(Instruction* instr);
93 void PrintPCImm16(Instruction* instr,
int delta_pc,
int n_bits);
94 void PrintXImm18(Instruction* instr);
95 void PrintSImm18(Instruction* instr);
96 void PrintXImm19(Instruction* instr);
97 void PrintSImm19(Instruction* instr);
98 void PrintXImm21(Instruction* instr);
99 void PrintSImm21(Instruction* instr);
100 void PrintPCImm21(Instruction* instr,
int delta_pc,
int n_bits);
101 void PrintXImm26(Instruction* instr);
102 void PrintSImm26(Instruction* instr);
103 void PrintPCImm26(Instruction* instr,
int delta_pc,
int n_bits);
104 void PrintPCImm26(Instruction* instr);
105 void PrintCode(Instruction* instr);
106 void PrintFormat(Instruction* instr);
107 void PrintMsaDataFormat(Instruction* instr);
108 void PrintMsaXImm8(Instruction* instr);
109 void PrintMsaImm8(Instruction* instr);
110 void PrintMsaImm5(Instruction* instr);
111 void PrintMsaSImm5(Instruction* instr);
112 void PrintMsaSImm10(Instruction* instr,
bool is_mi10 =
false);
113 void PrintMsaImmBit(Instruction* instr);
114 void PrintMsaImmElm(Instruction* instr);
115 void PrintMsaCopy(Instruction* instr);
117 void PrintInstructionName(Instruction* instr);
120 int FormatRegister(Instruction* instr,
const char* option);
121 int FormatFPURegister(Instruction* instr,
const char* option);
122 int FormatMSARegister(Instruction* instr,
const char* option);
123 int FormatOption(Instruction* instr,
const char* option);
124 void Format(Instruction* instr,
const char* format);
125 void Unknown(Instruction* instr);
129 bool DecodeTypeRegisterRsType(Instruction* instr);
130 void DecodeTypeRegisterSRsType(Instruction* instr);
131 void DecodeTypeRegisterDRsType(Instruction* instr);
132 void DecodeTypeRegisterLRsType(Instruction* instr);
133 void DecodeTypeRegisterWRsType(Instruction* instr);
134 void DecodeTypeRegisterSPECIAL(Instruction* instr);
135 void DecodeTypeRegisterSPECIAL2(Instruction* instr);
136 void DecodeTypeRegisterSPECIAL3(Instruction* instr);
137 void DecodeTypeRegister(Instruction* instr);
138 void DecodeTypeImmediate(Instruction* instr);
139 void DecodeTypeImmediateSPECIAL3(Instruction* instr);
140 void DecodeTypeJump(Instruction* instr);
141 void DecodeTypeMsaI8(Instruction* instr);
142 void DecodeTypeMsaI5(Instruction* instr);
143 void DecodeTypeMsaI10(Instruction* instr);
144 void DecodeTypeMsaELM(Instruction* instr);
145 void DecodeTypeMsaBIT(Instruction* instr);
146 void DecodeTypeMsaMI10(Instruction* instr);
147 void DecodeTypeMsa3R(Instruction* instr);
148 void DecodeTypeMsa3RF(Instruction* instr);
149 void DecodeTypeMsaVec(Instruction* instr);
150 void DecodeTypeMsa2R(Instruction* instr);
151 void DecodeTypeMsa2RF(Instruction* instr);
157 DISALLOW_COPY_AND_ASSIGN(Decoder);
162 #define STRING_STARTS_WITH(string, compare_string) \ 163 (strncmp(string, compare_string, strlen(compare_string)) == 0) 167 void Decoder::PrintChar(
const char ch) {
168 out_buffer_[out_buffer_pos_++] = ch;
173 void Decoder::Print(
const char* str) {
175 while (cur !=
'\0' && (out_buffer_pos_ < (out_buffer_.length() - 1))) {
179 out_buffer_[out_buffer_pos_] = 0;
184 void Decoder::PrintRegister(
int reg) {
185 Print(converter_.NameOfCPURegister(reg));
189 void Decoder::PrintRs(Instruction* instr) {
190 int reg = instr->RsValue();
195 void Decoder::PrintRt(Instruction* instr) {
196 int reg = instr->RtValue();
201 void Decoder::PrintRd(Instruction* instr) {
202 int reg = instr->RdValue();
208 void Decoder::PrintFPURegister(
int freg) {
209 Print(converter_.NameOfXMMRegister(freg));
212 void Decoder::PrintMSARegister(
int wreg) { Print(MSARegisters::Name(wreg)); }
214 void Decoder::PrintFPUStatusRegister(
int freg) {
220 Print(converter_.NameOfXMMRegister(freg));
224 void Decoder::PrintMSAControlRegister(
int creg) {
229 case kMSACSRRegister:
237 void Decoder::PrintFs(Instruction* instr) {
238 int freg = instr->RsValue();
239 PrintFPURegister(freg);
243 void Decoder::PrintFt(Instruction* instr) {
244 int freg = instr->RtValue();
245 PrintFPURegister(freg);
249 void Decoder::PrintFd(Instruction* instr) {
250 int freg = instr->RdValue();
251 PrintFPURegister(freg);
256 void Decoder::PrintSa(Instruction* instr) {
257 int sa = instr->SaValue();
258 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
"%d", sa);
263 void Decoder::PrintLsaSa(Instruction* instr) {
264 int sa = instr->LsaSaValue() + 1;
265 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
"%d", sa);
270 void Decoder::PrintSd(Instruction* instr) {
271 int sd = instr->RdValue();
272 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
"%d", sd);
277 void Decoder::PrintSs1(Instruction* instr) {
278 int ss = instr->RdValue();
279 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
"%d", ss + 1);
284 void Decoder::PrintSs2(Instruction* instr) {
285 int ss = instr->RdValue();
286 int pos = instr->SaValue();
288 SNPrintF(out_buffer_ + out_buffer_pos_,
"%d", ss - pos + 1);
293 void Decoder::PrintBc(Instruction* instr) {
294 int cc = instr->FBccValue();
295 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
"%d", cc);
300 void Decoder::PrintCc(Instruction* instr) {
301 int cc = instr->FCccValue();
302 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
"cc(%d)", cc);
306 void Decoder::PrintBp2(Instruction* instr) {
307 int bp2 = instr->Bp2Value();
308 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
"%d", bp2);
312 void Decoder::PrintUImm9(Instruction* instr) {
313 int32_t imm = instr->Imm9Value();
314 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
"%u", imm);
318 void Decoder::PrintSImm9(Instruction* instr) {
319 int32_t imm = ((instr->Imm9Value()) << 23) >> 23;
320 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
"%d", imm);
324 void Decoder::PrintUImm16(Instruction* instr) {
325 int32_t imm = instr->Imm16Value();
326 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
"%u", imm);
331 void Decoder::PrintSImm16(Instruction* instr) {
332 int32_t imm = ((instr->Imm16Value()) << 16) >> 16;
333 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
"%d", imm);
338 void Decoder::PrintXImm16(Instruction* instr) {
339 int32_t imm = instr->Imm16Value();
340 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
"0x%x", imm);
347 void Decoder::PrintPCImm16(Instruction* instr,
int delta_pc,
int n_bits) {
348 int16_t offset = instr->Imm16Value();
350 SNPrintF(out_buffer_ + out_buffer_pos_,
"%s",
351 converter_.NameOfAddress(reinterpret_cast<byte*>(instr) +
352 delta_pc + (offset << n_bits)));
357 void Decoder::PrintSImm18(Instruction* instr) {
359 ((instr->Imm18Value()) << (32 - kImm18Bits)) >> (32 - kImm18Bits);
360 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
"%d", imm);
365 void Decoder::PrintXImm18(Instruction* instr) {
366 int32_t imm = instr->Imm18Value();
367 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
"0x%x", imm);
372 void Decoder::PrintXImm19(Instruction* instr) {
373 int32_t imm = instr->Imm19Value();
374 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
"0x%x", imm);
379 void Decoder::PrintSImm19(Instruction* instr) {
380 int32_t imm19 = instr->Imm19Value();
382 imm19 <<= (32 - kImm19Bits);
383 imm19 >>= (32 - kImm19Bits);
384 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
"%d", imm19);
389 void Decoder::PrintXImm21(Instruction* instr) {
391 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
"0x%x", imm);
396 void Decoder::PrintSImm21(Instruction* instr) {
397 int32_t imm21 = instr->Imm21Value();
399 imm21 <<= (32 - kImm21Bits);
400 imm21 >>= (32 - kImm21Bits);
401 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
"%d", imm21);
408 void Decoder::PrintPCImm21(Instruction* instr,
int delta_pc,
int n_bits) {
409 int32_t imm21 = instr->Imm21Value();
411 imm21 <<= (32 - kImm21Bits);
412 imm21 >>= (32 - kImm21Bits);
414 SNPrintF(out_buffer_ + out_buffer_pos_,
"%s",
415 converter_.NameOfAddress(reinterpret_cast<byte*>(instr) +
416 delta_pc + (imm21 << n_bits)));
421 void Decoder::PrintXImm26(Instruction* instr) {
424 target = (
reinterpret_cast<uint32_t>(instr) & ~0xFFFFFFF) | target;
425 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
"0x%x", target);
430 void Decoder::PrintSImm26(Instruction* instr) {
431 int32_t imm26 = instr->Imm26Value();
433 imm26 <<= (32 - kImm26Bits);
434 imm26 >>= (32 - kImm26Bits);
435 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
"%d", imm26);
442 void Decoder::PrintPCImm26(Instruction* instr,
int delta_pc,
int n_bits) {
443 int32_t imm26 = instr->Imm26Value();
445 imm26 <<= (32 - kImm26Bits);
446 imm26 >>= (32 - kImm26Bits);
448 SNPrintF(out_buffer_ + out_buffer_pos_,
"%s",
449 converter_.NameOfAddress(reinterpret_cast<byte*>(instr) +
450 delta_pc + (imm26 << n_bits)));
457 void Decoder::PrintPCImm26(Instruction* instr) {
458 int32_t imm26 = instr->Imm26Value();
462 SNPrintF(out_buffer_ + out_buffer_pos_,
"%s",
463 converter_.NameOfAddress((reinterpret_cast<byte*>(pc))));
468 void Decoder::PrintCode(Instruction* instr) {
469 if (instr->OpcodeFieldRaw() != SPECIAL)
471 switch (instr->FunctionFieldRaw()) {
473 int32_t code = instr->Bits(25, 6);
474 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
475 "0x%05x (%d)", code, code);
484 int32_t code = instr->Bits(15, 6);
486 SNPrintF(out_buffer_ + out_buffer_pos_,
"0x%03x", code);
494 void Decoder::PrintMsaXImm8(Instruction* instr) {
495 int32_t imm = instr->MsaImm8Value();
496 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
"0x%x", imm);
499 void Decoder::PrintMsaImm8(Instruction* instr) {
500 int32_t imm = instr->MsaImm8Value();
501 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
"%u", imm);
504 void Decoder::PrintMsaImm5(Instruction* instr) {
505 int32_t imm = instr->MsaImm5Value();
506 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
"%u", imm);
509 void Decoder::PrintMsaSImm5(Instruction* instr) {
510 int32_t imm = instr->MsaImm5Value();
511 imm <<= (32 - kMsaImm5Bits);
512 imm >>= (32 - kMsaImm5Bits);
513 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
"%d", imm);
516 void Decoder::PrintMsaSImm10(Instruction* instr,
bool is_mi10) {
517 int32_t imm = is_mi10 ? instr->MsaImmMI10Value() : instr->MsaImm10Value();
518 imm <<= (32 - kMsaImm10Bits);
519 imm >>= (32 - kMsaImm10Bits);
520 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
"%d", imm);
523 void Decoder::PrintMsaImmBit(Instruction* instr) {
524 int32_t m = instr->MsaBitMValue();
525 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
"%u", m);
528 void Decoder::PrintMsaImmElm(Instruction* instr) {
529 int32_t n = instr->MsaElmNValue();
530 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
"%u", n);
533 void Decoder::PrintMsaCopy(Instruction* instr) {
534 int32_t rd = instr->WdValue();
535 int32_t ws = instr->WsValue();
536 int32_t n = instr->MsaElmNValue();
538 SNPrintF(out_buffer_ + out_buffer_pos_,
"%s, %s[%u]",
539 converter_.NameOfCPURegister(rd), MSARegisters::Name(ws), n);
542 void Decoder::PrintFormat(Instruction* instr) {
543 char formatLetter =
' ';
544 switch (instr->RsFieldRaw()) {
561 PrintChar(formatLetter);
564 void Decoder::PrintMsaDataFormat(Instruction* instr) {
565 DCHECK(instr->IsMSAInstr());
567 if (instr->IsMSABranchInstr()) {
568 switch (instr->RsFieldRaw()) {
594 char DF[] = {
'b',
'h',
'w',
'd'};
595 switch (instr->MSAMinorOpcodeField()) {
599 df = DF[instr->Bits(22, 21)];
602 df = DF[instr->Bits(1, 0)];
605 df = DF[instr->MsaBitDf()];
608 df = DF[instr->MsaElmDf()];
611 uint32_t opcode = instr->InstructionBits() & kMsa3RFMask;
621 df = DF[1 + instr->Bit(21)];
624 df = DF[2 + instr->Bit(21)];
629 df = DF[instr->Bits(17, 16)];
632 df = DF[2 + instr->Bit(16)];
644 void Decoder::PrintInstructionName(Instruction* instr) {
650 int Decoder::FormatRegister(Instruction* instr,
const char* format) {
651 DCHECK_EQ(format[0],
'r');
652 if (format[1] ==
's') {
653 int reg = instr->RsValue();
656 }
else if (format[1] ==
't') {
657 int reg = instr->RtValue();
660 }
else if (format[1] ==
'd') {
661 int reg = instr->RdValue();
671 int Decoder::FormatFPURegister(Instruction* instr,
const char* format) {
672 DCHECK_EQ(format[0],
'f');
673 if ((CTC1 == instr->RsFieldRaw()) || (CFC1 == instr->RsFieldRaw())) {
674 if (format[1] ==
's') {
675 int reg = instr->FsValue();
676 PrintFPUStatusRegister(reg);
678 }
else if (format[1] ==
't') {
679 int reg = instr->FtValue();
680 PrintFPUStatusRegister(reg);
682 }
else if (format[1] ==
'd') {
683 int reg = instr->FdValue();
684 PrintFPUStatusRegister(reg);
686 }
else if (format[1] ==
'r') {
687 int reg = instr->FrValue();
688 PrintFPUStatusRegister(reg);
692 if (format[1] ==
's') {
693 int reg = instr->FsValue();
694 PrintFPURegister(reg);
696 }
else if (format[1] ==
't') {
697 int reg = instr->FtValue();
698 PrintFPURegister(reg);
700 }
else if (format[1] ==
'd') {
701 int reg = instr->FdValue();
702 PrintFPURegister(reg);
704 }
else if (format[1] ==
'r') {
705 int reg = instr->FrValue();
706 PrintFPURegister(reg);
715 int Decoder::FormatMSARegister(Instruction* instr,
const char* format) {
716 DCHECK_EQ(format[0],
'w');
717 if (format[1] ==
's') {
718 int reg = instr->WsValue();
719 PrintMSARegister(reg);
721 }
else if (format[1] ==
't') {
722 int reg = instr->WtValue();
723 PrintMSARegister(reg);
725 }
else if (format[1] ==
'd') {
726 int reg = instr->WdValue();
727 PrintMSARegister(reg);
739 int Decoder::FormatOption(Instruction* instr,
const char* format) {
742 DCHECK(STRING_STARTS_WITH(format,
"code"));
747 if (format[3] ==
'1') {
748 if (format[4] ==
'6') {
749 DCHECK(STRING_STARTS_WITH(format,
"imm16"));
752 DCHECK(STRING_STARTS_WITH(format,
"imm16s"));
756 DCHECK(STRING_STARTS_WITH(format,
"imm16u"));
760 DCHECK(STRING_STARTS_WITH(format,
"imm16x"));
764 DCHECK(STRING_STARTS_WITH(format,
"imm16p"));
769 DCHECK(STRING_STARTS_WITH(format,
"imm16p4"));
773 DCHECK(STRING_STARTS_WITH(format,
"imm16p4s2"));
775 PrintPCImm16(instr, delta_pc, n_bits);
783 }
else if (format[4] ==
'8') {
784 DCHECK(STRING_STARTS_WITH(format,
"imm18"));
787 DCHECK(STRING_STARTS_WITH(format,
"imm18s"));
791 DCHECK(STRING_STARTS_WITH(format,
"imm18x"));
796 }
else if (format[4] ==
'9') {
797 DCHECK(STRING_STARTS_WITH(format,
"imm19"));
800 DCHECK(STRING_STARTS_WITH(format,
"imm19s"));
804 DCHECK(STRING_STARTS_WITH(format,
"imm19x"));
809 }
else if (format[4] ==
'0' && format[5] ==
's') {
810 DCHECK(STRING_STARTS_WITH(format,
"imm10s"));
811 if (format[6] ==
'1') {
812 DCHECK(STRING_STARTS_WITH(format,
"imm10s1"));
813 PrintMsaSImm10(instr,
false);
814 }
else if (format[6] ==
'2') {
815 DCHECK(STRING_STARTS_WITH(format,
"imm10s2"));
816 PrintMsaSImm10(instr,
true);
820 }
else if (format[3] ==
'2' && format[4] ==
'1') {
821 DCHECK(STRING_STARTS_WITH(format,
"imm21"));
824 DCHECK(STRING_STARTS_WITH(format,
"imm21s"));
828 DCHECK(STRING_STARTS_WITH(format,
"imm21x"));
832 DCHECK(STRING_STARTS_WITH(format,
"imm21p"));
837 DCHECK(STRING_STARTS_WITH(format,
"imm21p4"));
841 DCHECK(STRING_STARTS_WITH(format,
"imm21p4s2"));
843 PrintPCImm21(instr, delta_pc, n_bits);
851 }
else if (format[3] ==
'2' && format[4] ==
'6') {
852 DCHECK(STRING_STARTS_WITH(format,
"imm26"));
855 DCHECK(STRING_STARTS_WITH(format,
"imm26s"));
859 DCHECK(STRING_STARTS_WITH(format,
"imm26x"));
863 DCHECK(STRING_STARTS_WITH(format,
"imm26p"));
868 DCHECK(STRING_STARTS_WITH(format,
"imm26p4"));
872 DCHECK(STRING_STARTS_WITH(format,
"imm26p4s2"));
874 PrintPCImm26(instr, delta_pc, n_bits);
881 DCHECK(STRING_STARTS_WITH(format,
"imm26j"));
887 }
else if (format[3] ==
'5') {
888 DCHECK(STRING_STARTS_WITH(format,
"imm5"));
889 if (format[4] ==
'u') {
890 DCHECK(STRING_STARTS_WITH(format,
"imm5u"));
892 }
else if (format[4] ==
's') {
893 DCHECK(STRING_STARTS_WITH(format,
"imm5s"));
894 PrintMsaSImm5(instr);
897 }
else if (format[3] ==
'8') {
898 DCHECK(STRING_STARTS_WITH(format,
"imm8"));
901 }
else if (format[3] ==
'9') {
902 DCHECK(STRING_STARTS_WITH(format,
"imm9"));
903 if (format[4] ==
'u') {
904 DCHECK(STRING_STARTS_WITH(format,
"imm9u"));
906 }
else if (format[4] ==
's') {
907 DCHECK(STRING_STARTS_WITH(format,
"imm9s"));
911 }
else if (format[3] ==
'b') {
912 DCHECK(STRING_STARTS_WITH(format,
"immb"));
913 PrintMsaImmBit(instr);
915 }
else if (format[3] ==
'e') {
916 DCHECK(STRING_STARTS_WITH(format,
"imme"));
917 PrintMsaImmElm(instr);
923 return FormatRegister(instr, format);
926 return FormatFPURegister(instr, format);
929 return FormatMSARegister(instr, format);
934 if (format[2] ==
'2') {
935 DCHECK(STRING_STARTS_WITH(format,
"sa2"));
939 DCHECK(STRING_STARTS_WITH(format,
"sa"));
945 DCHECK(STRING_STARTS_WITH(format,
"sd"));
950 if (format[2] ==
'1') {
951 DCHECK(STRING_STARTS_WITH(format,
"ss1"));
955 DCHECK(STRING_STARTS_WITH(format,
"ss2"));
965 DCHECK(STRING_STARTS_WITH(format,
"bc"));
972 DCHECK(STRING_STARTS_WITH(format,
"bp2"));
981 DCHECK(STRING_STARTS_WITH(format,
"Cc"));
986 if (instr->IsMSAInstr()) {
987 PrintMsaDataFormat(instr);
1000 void Decoder::Format(Instruction* instr,
const char* format) {
1001 char cur = *format++;
1002 while ((cur != 0) && (out_buffer_pos_ < (out_buffer_.length() - 1))) {
1004 format += FormatOption(instr, format);
1006 out_buffer_[out_buffer_pos_++] = cur;
1010 out_buffer_[out_buffer_pos_] =
'\0';
1016 void Decoder::Unknown(Instruction* instr) {
1017 Format(instr,
"unknown");
1021 bool Decoder::DecodeTypeRegisterRsType(Instruction* instr) {
1022 switch (instr->FunctionFieldRaw()) {
1024 Format(instr,
"rint.'t 'fd, 'fs");
1027 Format(instr,
"min.'t 'fd, 'fs, 'ft");
1030 Format(instr,
"max.'t 'fd, 'fs, 'ft");
1033 Format(instr,
"mina.'t 'fd, 'fs, 'ft");
1036 Format(instr,
"maxa.'t 'fd, 'fs, 'ft");
1039 Format(instr,
"sel.'t 'fd, 'fs, 'ft");
1042 Format(instr,
"seleqz.'t 'fd, 'fs, 'ft");
1045 Format(instr,
"selnez.'t 'fd, 'fs, 'ft");
1048 Format(instr,
"movz.'t 'fd, 'fs, 'rt");
1051 Format(instr,
"movn.'t 'fd, 'fs, 'rt");
1054 if (instr->Bit(16)) {
1055 Format(instr,
"movt.'t 'fd, 'fs, 'Cc");
1057 Format(instr,
"movf.'t 'fd, 'fs, 'Cc");
1061 Format(instr,
"add.'t 'fd, 'fs, 'ft");
1064 Format(instr,
"sub.'t 'fd, 'fs, 'ft");
1067 Format(instr,
"mul.'t 'fd, 'fs, 'ft");
1070 Format(instr,
"div.'t 'fd, 'fs, 'ft");
1073 Format(instr,
"abs.'t 'fd, 'fs");
1076 Format(instr,
"mov.'t 'fd, 'fs");
1079 Format(instr,
"neg.'t 'fd, 'fs");
1082 Format(instr,
"sqrt.'t 'fd, 'fs");
1085 Format(instr,
"recip.'t 'fd, 'fs");
1088 Format(instr,
"rsqrt.'t 'fd, 'fs");
1091 Format(instr,
"cvt.w.'t 'fd, 'fs");
1094 Format(instr,
"cvt.l.'t 'fd, 'fs");
1097 Format(instr,
"trunc.w.'t 'fd, 'fs");
1100 Format(instr,
"trunc.l.'t 'fd, 'fs");
1103 Format(instr,
"round.w.'t 'fd, 'fs");
1106 Format(instr,
"round.l.'t 'fd, 'fs");
1109 Format(instr,
"floor.w.'t 'fd, 'fs");
1112 Format(instr,
"floor.l.'t 'fd, 'fs");
1115 Format(instr,
"ceil.w.'t 'fd, 'fs");
1118 Format(instr,
"class.'t 'fd, 'fs");
1121 Format(instr,
"ceil.l.'t 'fd, 'fs");
1124 Format(instr,
"cvt.s.'t 'fd, 'fs");
1127 Format(instr,
"c.f.'t 'fs, 'ft, 'Cc");
1130 Format(instr,
"c.un.'t 'fs, 'ft, 'Cc");
1133 Format(instr,
"c.eq.'t 'fs, 'ft, 'Cc");
1136 Format(instr,
"c.ueq.'t 'fs, 'ft, 'Cc");
1139 Format(instr,
"c.olt.'t 'fs, 'ft, 'Cc");
1142 Format(instr,
"c.ult.'t 'fs, 'ft, 'Cc");
1145 Format(instr,
"c.ole.'t 'fs, 'ft, 'Cc");
1148 Format(instr,
"c.ule.'t 'fs, 'ft, 'Cc");
1157 void Decoder::DecodeTypeRegisterSRsType(Instruction* instr) {
1158 if (!DecodeTypeRegisterRsType(instr)) {
1159 switch (instr->FunctionFieldRaw()) {
1161 Format(instr,
"cvt.d.'t 'fd, 'fs");
1164 Format(instr,
"maddf.s 'fd, 'fs, 'ft");
1167 Format(instr,
"msubf.s 'fd, 'fs, 'ft");
1170 Format(instr,
"unknown.cop1.'t");
1177 void Decoder::DecodeTypeRegisterDRsType(Instruction* instr) {
1178 if (!DecodeTypeRegisterRsType(instr)) {
1179 switch (instr->FunctionFieldRaw()) {
1181 Format(instr,
"maddf.d 'fd, 'fs, 'ft");
1184 Format(instr,
"msubf.d 'fd, 'fs, 'ft");
1187 Format(instr,
"unknown.cop1.'t");
1194 void Decoder::DecodeTypeRegisterLRsType(Instruction* instr) {
1195 switch (instr->FunctionFieldRaw()) {
1197 Format(instr,
"cvt.d.l 'fd, 'fs");
1200 Format(instr,
"cvt.s.l 'fd, 'fs");
1203 Format(instr,
"cmp.af.d 'fd, 'fs, 'ft");
1206 Format(instr,
"cmp.un.d 'fd, 'fs, 'ft");
1209 Format(instr,
"cmp.eq.d 'fd, 'fs, 'ft");
1212 Format(instr,
"cmp.ueq.d 'fd, 'fs, 'ft");
1215 Format(instr,
"cmp.lt.d 'fd, 'fs, 'ft");
1218 Format(instr,
"cmp.ult.d 'fd, 'fs, 'ft");
1221 Format(instr,
"cmp.le.d 'fd, 'fs, 'ft");
1224 Format(instr,
"cmp.ule.d 'fd, 'fs, 'ft");
1227 Format(instr,
"cmp.or.d 'fd, 'fs, 'ft");
1230 Format(instr,
"cmp.une.d 'fd, 'fs, 'ft");
1233 Format(instr,
"cmp.ne.d 'fd, 'fs, 'ft");
1241 void Decoder::DecodeTypeRegisterWRsType(Instruction* instr) {
1242 switch (instr->FunctionValue()) {
1244 Format(instr,
"cvt.s.w 'fd, 'fs");
1247 Format(instr,
"cvt.d.w 'fd, 'fs");
1250 Format(instr,
"cmp.af.s 'fd, 'fs, 'ft");
1253 Format(instr,
"cmp.un.s 'fd, 'fs, 'ft");
1256 Format(instr,
"cmp.eq.s 'fd, 'fs, 'ft");
1259 Format(instr,
"cmp.ueq.s 'fd, 'fs, 'ft");
1262 Format(instr,
"cmp.lt.s 'fd, 'fs, 'ft");
1265 Format(instr,
"cmp.ult.s 'fd, 'fs, 'ft");
1268 Format(instr,
"cmp.le.s 'fd, 'fs, 'ft");
1271 Format(instr,
"cmp.ule.s 'fd, 'fs, 'ft");
1274 Format(instr,
"cmp.or.s 'fd, 'fs, 'ft");
1277 Format(instr,
"cmp.une.s 'fd, 'fs, 'ft");
1280 Format(instr,
"cmp.ne.s 'fd, 'fs, 'ft");
1288 void Decoder::DecodeTypeRegisterSPECIAL(Instruction* instr) {
1289 switch (instr->FunctionFieldRaw()) {
1291 Format(instr,
"jr 'rs");
1294 Format(instr,
"jalr 'rs, 'rd");
1297 if (0x0 == static_cast<int>(instr->InstructionBits()))
1298 Format(instr,
"nop");
1300 Format(instr,
"sll 'rd, 'rt, 'sa");
1303 if (instr->RsValue() == 0) {
1304 Format(instr,
"srl 'rd, 'rt, 'sa");
1306 if (IsMipsArchVariant(kMips32r2)) {
1307 Format(instr,
"rotr 'rd, 'rt, 'sa");
1314 Format(instr,
"sra 'rd, 'rt, 'sa");
1317 Format(instr,
"sllv 'rd, 'rt, 'rs");
1320 if (instr->SaValue() == 0) {
1321 Format(instr,
"srlv 'rd, 'rt, 'rs");
1323 if (IsMipsArchVariant(kMips32r2)) {
1324 Format(instr,
"rotrv 'rd, 'rt, 'rs");
1331 Format(instr,
"srav 'rd, 'rt, 'rs");
1334 Format(instr,
"lsa 'rd, 'rt, 'rs, 'sa2");
1337 if (instr->Bits(25, 16) == 0) {
1338 Format(instr,
"mfhi 'rd");
1340 if ((instr->FunctionFieldRaw() == CLZ_R6) && (instr->FdValue() == 1)) {
1341 Format(instr,
"clz 'rd, 'rs");
1342 }
else if ((instr->FunctionFieldRaw() == CLO_R6) &&
1343 (instr->FdValue() == 1)) {
1344 Format(instr,
"clo 'rd, 'rs");
1349 Format(instr,
"mflo 'rd");
1352 if (!IsMipsArchVariant(kMips32r6)) {
1353 Format(instr,
"mult 'rs, 'rt");
1355 if (instr->SaValue() == MUL_OP) {
1356 Format(instr,
"mul 'rd, 'rs, 'rt");
1358 Format(instr,
"muh 'rd, 'rs, 'rt");
1363 if (!IsMipsArchVariant(kMips32r6)) {
1364 Format(instr,
"multu 'rs, 'rt");
1366 if (instr->SaValue() == MUL_OP) {
1367 Format(instr,
"mulu 'rd, 'rs, 'rt");
1369 Format(instr,
"muhu 'rd, 'rs, 'rt");
1374 if (!IsMipsArchVariant(kMips32r6)) {
1375 Format(instr,
"div 'rs, 'rt");
1377 if (instr->SaValue() == DIV_OP) {
1378 Format(instr,
"div 'rd, 'rs, 'rt");
1380 Format(instr,
"mod 'rd, 'rs, 'rt");
1385 if (!IsMipsArchVariant(kMips32r6)) {
1386 Format(instr,
"divu 'rs, 'rt");
1388 if (instr->SaValue() == DIV_OP) {
1389 Format(instr,
"divu 'rd, 'rs, 'rt");
1391 Format(instr,
"modu 'rd, 'rs, 'rt");
1396 Format(instr,
"add 'rd, 'rs, 'rt");
1399 Format(instr,
"addu 'rd, 'rs, 'rt");
1402 Format(instr,
"sub 'rd, 'rs, 'rt");
1405 Format(instr,
"subu 'rd, 'rs, 'rt");
1408 Format(instr,
"and 'rd, 'rs, 'rt");
1411 if (0 == instr->RsValue()) {
1412 Format(instr,
"mov 'rd, 'rt");
1413 }
else if (0 == instr->RtValue()) {
1414 Format(instr,
"mov 'rd, 'rs");
1416 Format(instr,
"or 'rd, 'rs, 'rt");
1420 Format(instr,
"xor 'rd, 'rs, 'rt");
1423 Format(instr,
"nor 'rd, 'rs, 'rt");
1426 Format(instr,
"slt 'rd, 'rs, 'rt");
1429 Format(instr,
"sltu 'rd, 'rs, 'rt");
1432 Format(instr,
"break, code: 'code");
1435 Format(instr,
"tge 'rs, 'rt, code: 'code");
1438 Format(instr,
"tgeu 'rs, 'rt, code: 'code");
1441 Format(instr,
"tlt 'rs, 'rt, code: 'code");
1444 Format(instr,
"tltu 'rs, 'rt, code: 'code");
1447 Format(instr,
"teq 'rs, 'rt, code: 'code");
1450 Format(instr,
"tne 'rs, 'rt, code: 'code");
1453 Format(instr,
"sync");
1456 Format(instr,
"movz 'rd, 'rs, 'rt");
1459 Format(instr,
"movn 'rd, 'rs, 'rt");
1462 if (instr->Bit(16)) {
1463 Format(instr,
"movt 'rd, 'rs, 'bc");
1465 Format(instr,
"movf 'rd, 'rs, 'bc");
1469 Format(instr,
"seleqz 'rd, 'rs, 'rt");
1472 Format(instr,
"selnez 'rd, 'rs, 'rt");
1480 void Decoder::DecodeTypeRegisterSPECIAL2(Instruction* instr) {
1481 switch (instr->FunctionFieldRaw()) {
1483 Format(instr,
"mul 'rd, 'rs, 'rt");
1486 if (!IsMipsArchVariant(kMips32r6)) {
1487 Format(instr,
"clz 'rd, 'rs");
1496 void Decoder::DecodeTypeRegisterSPECIAL3(Instruction* instr) {
1497 switch (instr->FunctionFieldRaw()) {
1499 if (IsMipsArchVariant(kMips32r2) || IsMipsArchVariant(kMips32r6)) {
1500 Format(instr,
"ins 'rt, 'rs, 'sa, 'ss2");
1507 if (IsMipsArchVariant(kMips32r2) || IsMipsArchVariant(kMips32r6)) {
1508 Format(instr,
"ext 'rt, 'rs, 'sa, 'ss1");
1515 int sa = instr->SaFieldRaw() >> kSaShift;
1518 if (IsMipsArchVariant(kMips32r6)) {
1519 Format(instr,
"bitswap 'rd, 'rt");
1526 if (IsMipsArchVariant(kMips32r2) || IsMipsArchVariant(kMips32r6)) {
1527 Format(instr,
"seb 'rd, 'rt");
1534 if (IsMipsArchVariant(kMips32r2) || IsMipsArchVariant(kMips32r6)) {
1535 Format(instr,
"seh 'rd, 'rt");
1542 if (IsMipsArchVariant(kMips32r2) || IsMipsArchVariant(kMips32r6)) {
1543 Format(instr,
"wsbh 'rd, 'rt");
1550 DCHECK(IsMipsArchVariant(kMips32r6));
1551 Format(instr,
"llwp 'rd, 'rt, 0('rs)");
1555 DCHECK(IsMipsArchVariant(kMips32r6));
1556 Format(instr,
"scwp 'rd, 'rt, 0('rs)");
1563 if (IsMipsArchVariant(kMips32r6)) {
1564 Format(instr,
"align 'rd, 'rs, 'rt, 'bp2");
1584 void Decoder::DecodeTypeRegister(Instruction* instr) {
1585 switch (instr->OpcodeFieldRaw()) {
1587 switch (instr->RsFieldRaw()) {
1592 Format(instr,
"mfc1 'rt, 'fs");
1595 Format(instr,
"mfhc1 'rt, 'fs");
1598 Format(instr,
"mtc1 'rt, 'fs");
1602 Format(instr,
"ctc1 'rt, 'fs");
1605 Format(instr,
"cfc1 'rt, 'fs");
1608 Format(instr,
"mthc1 'rt, 'fs");
1611 DecodeTypeRegisterSRsType(instr);
1614 DecodeTypeRegisterDRsType(instr);
1617 DecodeTypeRegisterLRsType(instr);
1620 DecodeTypeRegisterWRsType(instr);
1623 UNIMPLEMENTED_MIPS();
1630 switch (instr->FunctionFieldRaw()) {
1632 Format(instr,
"madd.s 'fd, 'fr, 'fs, 'ft");
1635 Format(instr,
"madd.d 'fd, 'fr, 'fs, 'ft");
1638 Format(instr,
"msub.s 'fd, 'fr, 'fs, 'ft");
1641 Format(instr,
"msub.d 'fd, 'fr, 'fs, 'ft");
1648 DecodeTypeRegisterSPECIAL(instr);
1651 DecodeTypeRegisterSPECIAL2(instr);
1654 DecodeTypeRegisterSPECIAL3(instr);
1657 switch (instr->MSAMinorOpcodeField()) {
1659 DecodeTypeMsa3R(instr);
1662 DecodeTypeMsa3RF(instr);
1665 DecodeTypeMsaVec(instr);
1668 DecodeTypeMsa2R(instr);
1671 DecodeTypeMsa2RF(instr);
1674 DecodeTypeMsaELM(instr);
1685 void Decoder::DecodeTypeImmediateSPECIAL3(Instruction* instr) {
1686 switch (instr->FunctionFieldRaw()) {
1688 if (IsMipsArchVariant(kMips32r6)) {
1689 if (instr->Bit(6)) {
1690 Format(instr,
"llx 'rt, 'imm9s('rs)");
1692 Format(instr,
"ll 'rt, 'imm9s('rs)");
1700 if (IsMipsArchVariant(kMips32r6)) {
1701 if (instr->Bit(6)) {
1702 Format(instr,
"scx 'rt, 'imm9s('rs)");
1704 Format(instr,
"sc 'rt, 'imm9s('rs)");
1716 void Decoder::DecodeTypeImmediate(Instruction* instr) {
1717 switch (instr->OpcodeFieldRaw()) {
1719 switch (instr->RsFieldRaw()) {
1721 if (instr->FBtrueValue()) {
1722 Format(instr,
"bc1t 'bc, 'imm16u -> 'imm16p4s2");
1724 Format(instr,
"bc1f 'bc, 'imm16u -> 'imm16p4s2");
1728 Format(instr,
"bc1eqz 'ft, 'imm16u -> 'imm16p4s2");
1731 Format(instr,
"bc1nez 'ft, 'imm16u -> 'imm16p4s2");
1738 Format(instr,
"bz.'t 'wt, 'imm16s -> 'imm16p4s2");
1745 Format(instr,
"bnz.'t 'wt, 'imm16s -> 'imm16p4s2");
1754 switch (instr->RtFieldRaw()) {
1756 Format(instr,
"bltz 'rs, 'imm16u -> 'imm16p4s2");
1759 if (instr->RsValue() == 0) {
1760 Format(instr,
"nal");
1762 Format(instr,
"bltzal 'rs, 'imm16u -> 'imm16p4s2");
1766 Format(instr,
"bgez 'rs, 'imm16u -> 'imm16p4s2");
1769 if (instr->RsValue() == 0)
1770 Format(instr,
"bal 'imm16s -> 'imm16p4s2");
1772 Format(instr,
"bgezal 'rs, 'imm16u -> 'imm16p4s2");
1776 Format(instr,
"bgezall 'rs, 'imm16u -> 'imm16p4s2");
1784 Format(instr,
"beq 'rs, 'rt, 'imm16u -> 'imm16p4s2");
1787 Format(instr,
"bc 'imm26s -> 'imm26p4s2");
1790 Format(instr,
"balc 'imm26s -> 'imm26p4s2");
1793 Format(instr,
"bne 'rs, 'rt, 'imm16u -> 'imm16p4s2");
1796 if ((instr->RtValue() == 0) && (instr->RsValue() != 0)) {
1797 Format(instr,
"blez 'rs, 'imm16u -> 'imm16p4s2");
1798 }
else if ((instr->RtValue() != instr->RsValue()) &&
1799 (instr->RsValue() != 0) && (instr->RtValue() != 0)) {
1800 Format(instr,
"bgeuc 'rs, 'rt, 'imm16u -> 'imm16p4s2");
1801 }
else if ((instr->RtValue() == instr->RsValue()) &&
1802 (instr->RtValue() != 0)) {
1803 Format(instr,
"bgezalc 'rs, 'imm16u -> 'imm16p4s2");
1804 }
else if ((instr->RsValue() == 0) && (instr->RtValue() != 0)) {
1805 Format(instr,
"blezalc 'rt, 'imm16u -> 'imm16p4s2");
1811 if ((instr->RtValue() == 0) && (instr->RsValue() != 0)) {
1812 Format(instr,
"bgtz 'rs, 'imm16u -> 'imm16p4s2");
1813 }
else if ((instr->RtValue() != instr->RsValue()) &&
1814 (instr->RsValue() != 0) && (instr->RtValue() != 0)) {
1815 Format(instr,
"bltuc 'rs, 'rt, 'imm16u -> 'imm16p4s2");
1816 }
else if ((instr->RtValue() == instr->RsValue()) &&
1817 (instr->RtValue() != 0)) {
1818 Format(instr,
"bltzalc 'rt, 'imm16u -> 'imm16p4s2");
1819 }
else if ((instr->RsValue() == 0) && (instr->RtValue() != 0)) {
1820 Format(instr,
"bgtzalc 'rt, 'imm16u -> 'imm16p4s2");
1826 if ((instr->RtValue() == instr->RsValue()) && (instr->RtValue() != 0)) {
1827 Format(instr,
"bgezc 'rt, 'imm16u -> 'imm16p4s2");
1828 }
else if ((instr->RtValue() != instr->RsValue()) &&
1829 (instr->RsValue() != 0) && (instr->RtValue() != 0)) {
1830 Format(instr,
"bgec 'rs, 'rt, 'imm16u -> 'imm16p4s2");
1831 }
else if ((instr->RsValue() == 0) && (instr->RtValue() != 0)) {
1832 Format(instr,
"blezc 'rt, 'imm16u -> 'imm16p4s2");
1838 if ((instr->RtValue() == instr->RsValue()) && (instr->RtValue() != 0)) {
1839 Format(instr,
"bltzc 'rt, 'imm16u -> 'imm16p4s2");
1840 }
else if ((instr->RtValue() != instr->RsValue()) &&
1841 (instr->RsValue() != 0) && (instr->RtValue() != 0)) {
1842 Format(instr,
"bltc 'rs, 'rt, 'imm16u -> 'imm16p4s2");
1843 }
else if ((instr->RsValue() == 0) && (instr->RtValue() != 0)) {
1844 Format(instr,
"bgtzc 'rt, 'imm16u -> 'imm16p4s2");
1850 if (instr->RsValue() == JIC) {
1851 Format(instr,
"jic 'rt, 'imm16s");
1853 Format(instr,
"beqzc 'rs, 'imm21s -> 'imm21p4s2");
1857 if (instr->RsValue() == JIALC) {
1858 Format(instr,
"jialc 'rt, 'imm16s");
1860 Format(instr,
"bnezc 'rs, 'imm21s -> 'imm21p4s2");
1865 if (!IsMipsArchVariant(kMips32r6)) {
1866 Format(instr,
"addi 'rt, 'rs, 'imm16s");
1868 int rs_reg = instr->RsValue();
1869 int rt_reg = instr->RtValue();
1871 if (rs_reg >= rt_reg) {
1872 Format(instr,
"bovc 'rs, 'rt, 'imm16s -> 'imm16p4s2");
1874 DCHECK_GT(rt_reg, 0);
1876 Format(instr,
"beqzalc 'rt, 'imm16s -> 'imm16p4s2");
1878 Format(instr,
"beqc 'rs, 'rt, 'imm16s -> 'imm16p4s2");
1884 if (IsMipsArchVariant(kMips32r6)) {
1885 int rs_reg = instr->RsValue();
1886 int rt_reg = instr->RtValue();
1888 if (rs_reg >= rt_reg) {
1889 Format(instr,
"bnvc 'rs, 'rt, 'imm16s -> 'imm16p4s2");
1891 DCHECK_GT(rt_reg, 0);
1893 Format(instr,
"bnezalc 'rt, 'imm16s -> 'imm16p4s2");
1895 Format(instr,
"bnec 'rs, 'rt, 'imm16s -> 'imm16p4s2");
1901 Format(instr,
"addiu 'rt, 'rs, 'imm16s");
1904 Format(instr,
"slti 'rt, 'rs, 'imm16s");
1907 Format(instr,
"sltiu 'rt, 'rs, 'imm16u");
1910 Format(instr,
"andi 'rt, 'rs, 'imm16x");
1913 Format(instr,
"ori 'rt, 'rs, 'imm16x");
1916 Format(instr,
"xori 'rt, 'rs, 'imm16x");
1919 if (!IsMipsArchVariant(kMips32r6)) {
1920 Format(instr,
"lui 'rt, 'imm16x");
1922 if (instr->RsValue() != 0) {
1923 Format(instr,
"aui 'rt, 'rs, 'imm16x");
1925 Format(instr,
"lui 'rt, 'imm16x");
1931 Format(instr,
"lb 'rt, 'imm16s('rs)");
1934 Format(instr,
"lh 'rt, 'imm16s('rs)");
1937 Format(instr,
"lwl 'rt, 'imm16s('rs)");
1940 Format(instr,
"lw 'rt, 'imm16s('rs)");
1943 Format(instr,
"lbu 'rt, 'imm16s('rs)");
1946 Format(instr,
"lhu 'rt, 'imm16s('rs)");
1949 Format(instr,
"lwr 'rt, 'imm16s('rs)");
1952 Format(instr,
"pref 'rt, 'imm16s('rs)");
1955 Format(instr,
"sb 'rt, 'imm16s('rs)");
1958 Format(instr,
"sh 'rt, 'imm16s('rs)");
1961 Format(instr,
"swl 'rt, 'imm16s('rs)");
1964 Format(instr,
"sw 'rt, 'imm16s('rs)");
1967 Format(instr,
"swr 'rt, 'imm16s('rs)");
1970 if (IsMipsArchVariant(kMips32r6)) {
1973 Format(instr,
"ll 'rt, 'imm16s('rs)");
1977 if (IsMipsArchVariant(kMips32r6)) {
1980 Format(instr,
"sc 'rt, 'imm16s('rs)");
1984 Format(instr,
"lwc1 'ft, 'imm16s('rs)");
1987 Format(instr,
"ldc1 'ft, 'imm16s('rs)");
1990 Format(instr,
"swc1 'ft, 'imm16s('rs)");
1993 Format(instr,
"sdc1 'ft, 'imm16s('rs)");
1996 int32_t imm21 = instr->Imm21Value();
1998 uint8_t rt = (imm21 >> kImm16Bits);
2001 Format(instr,
"aluipc 'rs, 'imm16s");
2004 Format(instr,
"auipc 'rs, 'imm16s");
2008 rt = (imm21 >> kImm19Bits);
2011 Format(instr,
"lwpc 'rs, 'imm19s");
2014 Format(instr,
"addiupc 'rs, 'imm19s");
2025 DecodeTypeImmediateSPECIAL3(instr);
2028 switch (instr->MSAMinorOpcodeField()) {
2030 DecodeTypeMsaI8(instr);
2033 DecodeTypeMsaI5(instr);
2036 DecodeTypeMsaI10(instr);
2039 DecodeTypeMsaELM(instr);
2042 DecodeTypeMsaBIT(instr);
2045 DecodeTypeMsaMI10(instr);
2053 printf(
"a 0x%x \n", instr->OpcodeFieldRaw());
2060 void Decoder::DecodeTypeJump(Instruction* instr) {
2061 switch (instr->OpcodeFieldRaw()) {
2063 Format(instr,
"j 'imm26x -> 'imm26j");
2066 Format(instr,
"jal 'imm26x -> 'imm26j");
2073 void Decoder::DecodeTypeMsaI8(Instruction* instr) {
2074 uint32_t opcode = instr->InstructionBits() & kMsaI8Mask;
2078 Format(instr,
"andi.b 'wd, 'ws, 'imm8");
2081 Format(instr,
"ori.b 'wd, 'ws, 'imm8");
2084 Format(instr,
"nori.b 'wd, 'ws, 'imm8");
2087 Format(instr,
"xori.b 'wd, 'ws, 'imm8");
2090 Format(instr,
"bmnzi.b 'wd, 'ws, 'imm8");
2093 Format(instr,
"bmzi.b 'wd, 'ws, 'imm8");
2096 Format(instr,
"bseli.b 'wd, 'ws, 'imm8");
2099 Format(instr,
"shf.b 'wd, 'ws, 'imm8");
2102 Format(instr,
"shf.h 'wd, 'ws, 'imm8");
2105 Format(instr,
"shf.w 'wd, 'ws, 'imm8");
2112 void Decoder::DecodeTypeMsaI5(Instruction* instr) {
2113 uint32_t opcode = instr->InstructionBits() & kMsaI5Mask;
2117 Format(instr,
"addvi.'t 'wd, 'ws, 'imm5u");
2120 Format(instr,
"subvi.'t 'wd, 'ws, 'imm5u");
2123 Format(instr,
"maxi_s.'t 'wd, 'ws, 'imm5s");
2126 Format(instr,
"maxi_u.'t 'wd, 'ws, 'imm5u");
2129 Format(instr,
"mini_s.'t 'wd, 'ws, 'imm5s");
2132 Format(instr,
"mini_u.'t 'wd, 'ws, 'imm5u");
2135 Format(instr,
"ceqi.'t 'wd, 'ws, 'imm5s");
2138 Format(instr,
"clti_s.'t 'wd, 'ws, 'imm5s");
2141 Format(instr,
"clti_u.'t 'wd, 'ws, 'imm5u");
2144 Format(instr,
"clei_s.'t 'wd, 'ws, 'imm5s");
2147 Format(instr,
"clei_u.'t 'wd, 'ws, 'imm5u");
2154 void Decoder::DecodeTypeMsaI10(Instruction* instr) {
2155 uint32_t opcode = instr->InstructionBits() & kMsaI5Mask;
2156 if (opcode == LDI) {
2157 Format(instr,
"ldi.'t 'wd, 'imm10s1");
2163 void Decoder::DecodeTypeMsaELM(Instruction* instr) {
2164 uint32_t opcode = instr->InstructionBits() & kMsaELMMask;
2167 if (instr->Bits(21, 16) == 0x3E) {
2168 Format(instr,
"ctcmsa ");
2169 PrintMSAControlRegister(instr->WdValue());
2171 PrintRegister(instr->WsValue());
2173 Format(instr,
"sldi.'t 'wd, 'ws['imme]");
2177 if (instr->Bits(21, 16) == 0x3E) {
2178 Format(instr,
"cfcmsa ");
2179 PrintRegister(instr->WdValue());
2181 PrintMSAControlRegister(instr->WsValue());
2183 Format(instr,
"splati.'t 'wd, 'ws['imme]");
2187 if (instr->Bits(21, 16) == 0x3E) {
2188 Format(instr,
"move.v 'wd, 'ws");
2190 Format(instr,
"copy_s.'t ");
2191 PrintMsaCopy(instr);
2195 Format(instr,
"copy_u.'t ");
2196 PrintMsaCopy(instr);
2199 Format(instr,
"insert.'t 'wd['imme], ");
2200 PrintRegister(instr->WsValue());
2203 Format(instr,
"insve.'t 'wd['imme], 'ws[0]");
2210 void Decoder::DecodeTypeMsaBIT(Instruction* instr) {
2211 uint32_t opcode = instr->InstructionBits() & kMsaBITMask;
2215 Format(instr,
"slli.'t 'wd, 'ws, 'immb");
2218 Format(instr,
"srai.'t 'wd, 'ws, 'immb");
2221 Format(instr,
"srli.'t 'wd, 'ws, 'immb");
2224 Format(instr,
"bclri.'t 'wd, 'ws, 'immb");
2227 Format(instr,
"bseti.'t 'wd, 'ws, 'immb");
2230 Format(instr,
"bnegi.'t 'wd, 'ws, 'immb");
2233 Format(instr,
"binsli.'t 'wd, 'ws, 'immb");
2236 Format(instr,
"binsri.'t 'wd, 'ws, 'immb");
2239 Format(instr,
"sat_s.'t 'wd, 'ws, 'immb");
2242 Format(instr,
"sat_u.'t 'wd, 'ws, 'immb");
2245 Format(instr,
"srari.'t 'wd, 'ws, 'immb");
2248 Format(instr,
"srlri.'t 'wd, 'ws, 'immb");
2255 void Decoder::DecodeTypeMsaMI10(Instruction* instr) {
2256 uint32_t opcode = instr->InstructionBits() & kMsaMI10Mask;
2257 if (opcode == MSA_LD) {
2258 Format(instr,
"ld.'t 'wd, 'imm10s2(");
2259 PrintRegister(instr->WsValue());
2261 }
else if (opcode == MSA_ST) {
2262 Format(instr,
"st.'t 'wd, 'imm10s2(");
2263 PrintRegister(instr->WsValue());
2270 void Decoder::DecodeTypeMsa3R(Instruction* instr) {
2271 uint32_t opcode = instr->InstructionBits() & kMsa3RMask;
2274 Format(instr,
"sll.'t 'wd, 'ws, 'wt");
2277 Format(instr,
"sra.'t 'wd, 'ws, 'wt");
2280 Format(instr,
"srl.'t 'wd, 'ws, 'wt");
2283 Format(instr,
"bclr.'t 'wd, 'ws, 'wt");
2286 Format(instr,
"bset.'t 'wd, 'ws, 'wt");
2289 Format(instr,
"bneg.'t 'wd, 'ws, 'wt");
2292 Format(instr,
"binsl.'t 'wd, 'ws, 'wt");
2295 Format(instr,
"binsr.'t 'wd, 'ws, 'wt");
2298 Format(instr,
"addv.'t 'wd, 'ws, 'wt");
2301 Format(instr,
"subv.'t 'wd, 'ws, 'wt");
2304 Format(instr,
"max_s.'t 'wd, 'ws, 'wt");
2307 Format(instr,
"max_u.'t 'wd, 'ws, 'wt");
2310 Format(instr,
"min_s.'t 'wd, 'ws, 'wt");
2313 Format(instr,
"min_u.'t 'wd, 'ws, 'wt");
2316 Format(instr,
"max_a.'t 'wd, 'ws, 'wt");
2319 Format(instr,
"min_a.'t 'wd, 'ws, 'wt");
2322 Format(instr,
"ceq.'t 'wd, 'ws, 'wt");
2325 Format(instr,
"clt_s.'t 'wd, 'ws, 'wt");
2328 Format(instr,
"clt_u.'t 'wd, 'ws, 'wt");
2331 Format(instr,
"cle_s.'t 'wd, 'ws, 'wt");
2334 Format(instr,
"cle_u.'t 'wd, 'ws, 'wt");
2337 Format(instr,
"add_a.'t 'wd, 'ws, 'wt");
2340 Format(instr,
"adds_a.'t 'wd, 'ws, 'wt");
2343 Format(instr,
"adds_s.'t 'wd, 'ws, 'wt");
2346 Format(instr,
"adds_u.'t 'wd, 'ws, 'wt");
2349 Format(instr,
"ave_s.'t 'wd, 'ws, 'wt");
2352 Format(instr,
"ave_u.'t 'wd, 'ws, 'wt");
2355 Format(instr,
"aver_s.'t 'wd, 'ws, 'wt");
2358 Format(instr,
"aver_u.'t 'wd, 'ws, 'wt");
2361 Format(instr,
"subs_s.'t 'wd, 'ws, 'wt");
2364 Format(instr,
"subs_u.'t 'wd, 'ws, 'wt");
2367 Format(instr,
"subsus_u.'t 'wd, 'ws, 'wt");
2370 Format(instr,
"subsuu_s.'t 'wd, 'ws, 'wt");
2373 Format(instr,
"asub_s.'t 'wd, 'ws, 'wt");
2376 Format(instr,
"asub_u.'t 'wd, 'ws, 'wt");
2379 Format(instr,
"mulv.'t 'wd, 'ws, 'wt");
2382 Format(instr,
"maddv.'t 'wd, 'ws, 'wt");
2385 Format(instr,
"msubv.'t 'wd, 'ws, 'wt");
2388 Format(instr,
"div_s.'t 'wd, 'ws, 'wt");
2391 Format(instr,
"div_u.'t 'wd, 'ws, 'wt");
2394 Format(instr,
"mod_s.'t 'wd, 'ws, 'wt");
2397 Format(instr,
"mod_u.'t 'wd, 'ws, 'wt");
2400 Format(instr,
"dotp_s.'t 'wd, 'ws, 'wt");
2403 Format(instr,
"dotp_u.'t 'wd, 'ws, 'wt");
2406 Format(instr,
"dpadd_s.'t 'wd, 'ws, 'wt");
2409 Format(instr,
"dpadd_u.'t 'wd, 'ws, 'wt");
2412 Format(instr,
"dpsub_s.'t 'wd, 'ws, 'wt");
2415 Format(instr,
"dpsub_u.'t 'wd, 'ws, 'wt");
2418 Format(instr,
"sld.'t 'wd, 'ws['rt]");
2421 Format(instr,
"splat.'t 'wd, 'ws['rt]");
2424 Format(instr,
"pckev.'t 'wd, 'ws, 'wt");
2427 Format(instr,
"pckod.'t 'wd, 'ws, 'wt");
2430 Format(instr,
"ilvl.'t 'wd, 'ws, 'wt");
2433 Format(instr,
"ilvr.'t 'wd, 'ws, 'wt");
2436 Format(instr,
"ilvev.'t 'wd, 'ws, 'wt");
2439 Format(instr,
"ilvod.'t 'wd, 'ws, 'wt");
2442 Format(instr,
"vshf.'t 'wd, 'ws, 'wt");
2445 Format(instr,
"srar.'t 'wd, 'ws, 'wt");
2448 Format(instr,
"srlr.'t 'wd, 'ws, 'wt");
2451 Format(instr,
"hadd_s.'t 'wd, 'ws, 'wt");
2454 Format(instr,
"hadd_u.'t 'wd, 'ws, 'wt");
2457 Format(instr,
"hsub_s.'t 'wd, 'ws, 'wt");
2460 Format(instr,
"hsub_u.'t 'wd, 'ws, 'wt");
2467 void Decoder::DecodeTypeMsa3RF(Instruction* instr) {
2468 uint32_t opcode = instr->InstructionBits() & kMsa3RFMask;
2471 Format(instr,
"fcaf.'t 'wd, 'ws, 'wt");
2474 Format(instr,
"fcun.'t 'wd, 'ws, 'wt");
2477 Format(instr,
"fceq.'t 'wd, 'ws, 'wt");
2480 Format(instr,
"fcueq.'t 'wd, 'ws, 'wt");
2483 Format(instr,
"fclt.'t 'wd, 'ws, 'wt");
2486 Format(instr,
"fcult.'t 'wd, 'ws, 'wt");
2489 Format(instr,
"fcle.'t 'wd, 'ws, 'wt");
2492 Format(instr,
"fcule.'t 'wd, 'ws, 'wt");
2495 Format(instr,
"fsaf.'t 'wd, 'ws, 'wt");
2498 Format(instr,
"fsun.'t 'wd, 'ws, 'wt");
2501 Format(instr,
"fseq.'t 'wd, 'ws, 'wt");
2504 Format(instr,
"fsueq.'t 'wd, 'ws, 'wt");
2507 Format(instr,
"fslt.'t 'wd, 'ws, 'wt");
2510 Format(instr,
"fsult.'t 'wd, 'ws, 'wt");
2513 Format(instr,
"fsle.'t 'wd, 'ws, 'wt");
2516 Format(instr,
"fsule.'t 'wd, 'ws, 'wt");
2519 Format(instr,
"fadd.'t 'wd, 'ws, 'wt");
2522 Format(instr,
"fsub.'t 'wd, 'ws, 'wt");
2525 Format(instr,
"fmul.'t 'wd, 'ws, 'wt");
2528 Format(instr,
"fdiv.'t 'wd, 'ws, 'wt");
2531 Format(instr,
"fmadd.'t 'wd, 'ws, 'wt");
2534 Format(instr,
"fmsub.'t 'wd, 'ws, 'wt");
2537 Format(instr,
"fexp2.'t 'wd, 'ws, 'wt");
2540 Format(instr,
"fexdo.'t 'wd, 'ws, 'wt");
2543 Format(instr,
"ftq.'t 'wd, 'ws, 'wt");
2546 Format(instr,
"fmin.'t 'wd, 'ws, 'wt");
2549 Format(instr,
"fmin_a.'t 'wd, 'ws, 'wt");
2552 Format(instr,
"fmax.'t 'wd, 'ws, 'wt");
2555 Format(instr,
"fmax_a.'t 'wd, 'ws, 'wt");
2558 Format(instr,
"fcor.'t 'wd, 'ws, 'wt");
2561 Format(instr,
"fcune.'t 'wd, 'ws, 'wt");
2564 Format(instr,
"fcne.'t 'wd, 'ws, 'wt");
2567 Format(instr,
"mul_q.'t 'wd, 'ws, 'wt");
2570 Format(instr,
"madd_q.'t 'wd, 'ws, 'wt");
2573 Format(instr,
"msub_q.'t 'wd, 'ws, 'wt");
2576 Format(instr,
"fsor.'t 'wd, 'ws, 'wt");
2579 Format(instr,
"fsune.'t 'wd, 'ws, 'wt");
2582 Format(instr,
"fsne.'t 'wd, 'ws, 'wt");
2585 Format(instr,
"mulr_q.'t 'wd, 'ws, 'wt");
2588 Format(instr,
"maddr_q.'t 'wd, 'ws, 'wt");
2591 Format(instr,
"msubr_q.'t 'wd, 'ws, 'wt");
2598 void Decoder::DecodeTypeMsaVec(Instruction* instr) {
2599 uint32_t opcode = instr->InstructionBits() & kMsaVECMask;
2602 Format(instr,
"and.v 'wd, 'ws, 'wt");
2605 Format(instr,
"or.v 'wd, 'ws, 'wt");
2608 Format(instr,
"nor.v 'wd, 'ws, 'wt");
2611 Format(instr,
"xor.v 'wd, 'ws, 'wt");
2614 Format(instr,
"bmnz.v 'wd, 'ws, 'wt");
2617 Format(instr,
"bmz.v 'wd, 'ws, 'wt");
2620 Format(instr,
"bsel.v 'wd, 'ws, 'wt");
2627 void Decoder::DecodeTypeMsa2R(Instruction* instr) {
2628 uint32_t opcode = instr->InstructionBits() & kMsa2RMask;
2631 Format(instr,
"fill.'t 'wd, ");
2632 PrintRegister(instr->WsValue());
2635 Format(instr,
"pcnt.'t 'wd, 'ws");
2638 Format(instr,
"nloc.'t 'wd, 'ws");
2641 Format(instr,
"nlzc.'t 'wd, 'ws");
2648 void Decoder::DecodeTypeMsa2RF(Instruction* instr) {
2649 uint32_t opcode = instr->InstructionBits() & kMsa2RFMask;
2652 Format(instr,
"fclass.'t 'wd, 'ws");
2655 Format(instr,
"ftrunc_s.'t 'wd, 'ws");
2658 Format(instr,
"ftrunc_u.'t 'wd, 'ws");
2661 Format(instr,
"fsqrt.'t 'wd, 'ws");
2664 Format(instr,
"frsqrt.'t 'wd, 'ws");
2667 Format(instr,
"frcp.'t 'wd, 'ws");
2670 Format(instr,
"frint.'t 'wd, 'ws");
2673 Format(instr,
"flog2.'t 'wd, 'ws");
2676 Format(instr,
"fexupl.'t 'wd, 'ws");
2679 Format(instr,
"fexupr.'t 'wd, 'ws");
2682 Format(instr,
"ffql.'t 'wd, 'ws");
2685 Format(instr,
"ffqr.'t 'wd, 'ws");
2688 Format(instr,
"ftint_s.'t 'wd, 'ws");
2691 Format(instr,
"ftint_u.'t 'wd, 'ws");
2694 Format(instr,
"ffint_s.'t 'wd, 'ws");
2697 Format(instr,
"ffint_u.'t 'wd, 'ws");
2705 int Decoder::InstructionDecode(byte* instr_ptr) {
2706 Instruction* instr = Instruction::At(instr_ptr);
2708 out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_,
2710 instr->InstructionBits());
2711 switch (instr->InstructionType()) {
2712 case Instruction::kRegisterType: {
2713 DecodeTypeRegister(instr);
2716 case Instruction::kImmediateType: {
2717 DecodeTypeImmediate(instr);
2720 case Instruction::kJumpType: {
2721 DecodeTypeJump(instr);
2725 Format(instr,
"UNSUPPORTED");
2741 const char* NameConverter::NameOfAddress(byte* addr)
const {
2742 v8::internal::SNPrintF(tmp_buffer_,
"%p", static_cast<void*>(addr));
2743 return tmp_buffer_.start();
2747 const char* NameConverter::NameOfConstant(byte* addr)
const {
2748 return NameOfAddress(addr);
2752 const char* NameConverter::NameOfCPURegister(
int reg)
const {
2753 return v8::internal::Registers::Name(reg);
2757 const char* NameConverter::NameOfXMMRegister(
int reg)
const {
2758 return v8::internal::FPURegisters::Name(reg);
2762 const char* NameConverter::NameOfByteCPURegister(
int reg)
const {
2768 const char* NameConverter::NameInCode(byte* addr)
const {
2778 byte* instruction) {
2780 return d.InstructionDecode(instruction);
2785 int Disassembler::ConstantPoolSizeAt(byte* instruction) {
2789 void Disassembler::Disassemble(FILE* f, byte* begin, byte* end,
2790 UnimplementedOpcodeAction unimplemented_action) {
2791 NameConverter converter;
2792 Disassembler d(converter, unimplemented_action);
2793 for (byte* pc = begin; pc < end;) {
2797 pc += d.InstructionDecode(buffer, pc);
2798 v8::internal::PrintF(f,
"%p %08x %s\n", static_cast<void*>(prev_pc),
2799 *reinterpret_cast<int32_t*>(prev_pc), buffer.start());
2808 #endif // V8_TARGET_ARCH_MIPS