1//=- Mips32r6InstrFormats.td - Mips32r6 Instruction Formats -*- tablegen -*-==// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file describes Mips32r6 instruction formats. 11// 12//===----------------------------------------------------------------------===// 13 14class R6MMR6Rel; 15 16def MipsR62MicroMipsR6 : InstrMapping { 17 let FilterClass = "R6MMR6Rel"; 18 // Instructions with the same BaseOpcode and isNVStore values form a row. 19 let RowFields = ["BaseOpcode"]; 20 // Instructions with the same predicate sense form a column. 21 let ColFields = ["Arch"]; 22 // The key column is the unpredicated instructions. 23 let KeyCol = ["mipsr6"]; 24 // Value columns are PredSense=true and PredSense=false 25 let ValueCols = [["mipsr6"], ["micromipsr6"]]; 26} 27 28class MipsR6Arch<string opstr> { 29 string Arch = "mipsr6"; 30 string BaseOpcode = opstr; 31} 32 33class MipsR6Inst : MipsInst<(outs), (ins), "", [], NoItinerary, FrmOther>, 34 PredicateControl { 35 let DecoderNamespace = "Mips32r6_64r6"; 36 let EncodingPredicates = [HasStdEnc]; 37} 38 39//===----------------------------------------------------------------------===// 40// 41// Field Values 42// 43//===----------------------------------------------------------------------===// 44 45class OPGROUP<bits<6> Val> { 46 bits<6> Value = Val; 47} 48def OPGROUP_COP1 : OPGROUP<0b010001>; 49def OPGROUP_COP2 : OPGROUP<0b010010>; 50def OPGROUP_ADDI : OPGROUP<0b001000>; 51def OPGROUP_AUI : OPGROUP<0b001111>; 52def OPGROUP_BLEZ : OPGROUP<0b000110>; 53def OPGROUP_BGTZ : OPGROUP<0b000111>; 54def OPGROUP_BLEZL : OPGROUP<0b010110>; 55def OPGROUP_BGTZL : OPGROUP<0b010111>; 56def OPGROUP_DADDI : OPGROUP<0b011000>; 57def OPGROUP_DAUI : OPGROUP<0b011101>; 58def OPGROUP_PCREL : OPGROUP<0b111011>; 59def OPGROUP_REGIMM : OPGROUP<0b000001>; 60def OPGROUP_SPECIAL : OPGROUP<0b000000>; 61// The spec occasionally names this value LL, LLD, SC, or SCD. 62def OPGROUP_SPECIAL3 : OPGROUP<0b011111>; 63// The spec names this constant LWC2, LDC2, SWC2, and SDC2 in different places. 64def OPGROUP_COP2LDST : OPGROUP<0b010010>; 65 66class OPCODE2<bits<2> Val> { 67 bits<2> Value = Val; 68} 69def OPCODE2_ADDIUPC : OPCODE2<0b00>; 70def OPCODE2_LWPC : OPCODE2<0b01>; 71def OPCODE2_LWUPC : OPCODE2<0b10>; 72 73class OPCODE3<bits<3> Val> { 74 bits<3> Value = Val; 75} 76def OPCODE3_LDPC : OPCODE3<0b110>; 77 78class OPCODE5<bits<5> Val> { 79 bits<5> Value = Val; 80} 81def OPCODE5_ALUIPC : OPCODE5<0b11111>; 82def OPCODE5_AUIPC : OPCODE5<0b11110>; 83def OPCODE5_DAHI : OPCODE5<0b00110>; 84def OPCODE5_DATI : OPCODE5<0b11110>; 85def OPCODE5_BC1EQZ : OPCODE5<0b01001>; 86def OPCODE5_BC1NEZ : OPCODE5<0b01101>; 87def OPCODE5_BC2EQZ : OPCODE5<0b01001>; 88def OPCODE5_BC2NEZ : OPCODE5<0b01101>; 89def OPCODE5_BGEZAL : OPCODE5<0b10001>; 90// The next four constants are unnamed in the spec. These names are taken from 91// the OPGROUP names they are used with. 92def OPCODE5_LDC2 : OPCODE5<0b01110>; 93def OPCODE5_LWC2 : OPCODE5<0b01010>; 94def OPCODE5_SDC2 : OPCODE5<0b01111>; 95def OPCODE5_SWC2 : OPCODE5<0b01011>; 96 97class OPCODE6<bits<6> Val> { 98 bits<6> Value = Val; 99} 100def OPCODE6_ALIGN : OPCODE6<0b100000>; 101def OPCODE6_DALIGN : OPCODE6<0b100100>; 102def OPCODE6_BITSWAP : OPCODE6<0b100000>; 103def OPCODE6_DBITSWAP : OPCODE6<0b100100>; 104def OPCODE6_JALR : OPCODE6<0b001001>; 105def OPCODE6_CACHE : OPCODE6<0b100101>; 106def OPCODE6_PREF : OPCODE6<0b110101>; 107// The next four constants are unnamed in the spec. These names are taken from 108// the OPGROUP names they are used with. 109def OPCODE6_LL : OPCODE6<0b110110>; 110def OPCODE6_LLD : OPCODE6<0b110111>; 111def OPCODE6_SC : OPCODE6<0b100110>; 112def OPCODE6_SCD : OPCODE6<0b100111>; 113def OPCODE6_CLO : OPCODE6<0b010001>; 114def OPCODE6_CLZ : OPCODE6<0b010000>; 115def OPCODE6_DCLO : OPCODE6<0b010011>; 116def OPCODE6_DCLZ : OPCODE6<0b010010>; 117def OPCODE6_LSA : OPCODE6<0b000101>; 118def OPCODE6_DLSA : OPCODE6<0b010101>; 119def OPCODE6_SDBBP : OPCODE6<0b001110>; 120 121class FIELD_FMT<bits<5> Val> { 122 bits<5> Value = Val; 123} 124def FIELD_FMT_S : FIELD_FMT<0b10000>; 125def FIELD_FMT_D : FIELD_FMT<0b10001>; 126 127class FIELD_CMP_COND<bits<5> Val> { 128 bits<5> Value = Val; 129} 130// Note: The CMP_COND_FMT names differ from the C_COND_FMT names. 131def FIELD_CMP_COND_AF : FIELD_CMP_COND<0b00000>; 132def FIELD_CMP_COND_UN : FIELD_CMP_COND<0b00001>; 133def FIELD_CMP_COND_EQ : FIELD_CMP_COND<0b00010>; 134def FIELD_CMP_COND_UEQ : FIELD_CMP_COND<0b00011>; 135def FIELD_CMP_COND_LT : FIELD_CMP_COND<0b00100>; 136def FIELD_CMP_COND_ULT : FIELD_CMP_COND<0b00101>; 137def FIELD_CMP_COND_LE : FIELD_CMP_COND<0b00110>; 138def FIELD_CMP_COND_ULE : FIELD_CMP_COND<0b00111>; 139def FIELD_CMP_COND_SAF : FIELD_CMP_COND<0b01000>; 140def FIELD_CMP_COND_SUN : FIELD_CMP_COND<0b01001>; 141def FIELD_CMP_COND_SEQ : FIELD_CMP_COND<0b01010>; 142def FIELD_CMP_COND_SUEQ : FIELD_CMP_COND<0b01011>; 143def FIELD_CMP_COND_SLT : FIELD_CMP_COND<0b01100>; 144def FIELD_CMP_COND_SULT : FIELD_CMP_COND<0b01101>; 145def FIELD_CMP_COND_SLE : FIELD_CMP_COND<0b01110>; 146def FIELD_CMP_COND_SULE : FIELD_CMP_COND<0b01111>; 147 148class FIELD_CMP_FORMAT<bits<5> Val> { 149 bits<5> Value = Val; 150} 151def FIELD_CMP_FORMAT_S : FIELD_CMP_FORMAT<0b10100>; 152def FIELD_CMP_FORMAT_D : FIELD_CMP_FORMAT<0b10101>; 153 154//===----------------------------------------------------------------------===// 155// 156// Disambiguators 157// 158//===----------------------------------------------------------------------===// 159// 160// Some encodings are ambiguous except by comparing field values. 161 162class DecodeDisambiguates<string Name> { 163 string DecoderMethod = !strconcat("Decode", Name); 164} 165 166class DecodeDisambiguatedBy<string Name> : DecodeDisambiguates<Name> { 167 string DecoderNamespace = "Mips32r6_64r6_Ambiguous"; 168} 169 170//===----------------------------------------------------------------------===// 171// 172// Encoding Formats 173// 174//===----------------------------------------------------------------------===// 175 176class AUI_FM : MipsR6Inst { 177 bits<5> rs; 178 bits<5> rt; 179 bits<16> imm; 180 181 bits<32> Inst; 182 183 let Inst{31-26} = OPGROUP_AUI.Value; 184 let Inst{25-21} = rs; 185 let Inst{20-16} = rt; 186 let Inst{15-0} = imm; 187} 188 189class DAUI_FM : AUI_FM { 190 let Inst{31-26} = OPGROUP_DAUI.Value; 191} 192 193class BAL_FM : MipsR6Inst { 194 bits<16> offset; 195 196 bits<32> Inst; 197 198 let Inst{31-26} = OPGROUP_REGIMM.Value; 199 let Inst{25-21} = 0b00000; 200 let Inst{20-16} = OPCODE5_BGEZAL.Value; 201 let Inst{15-0} = offset; 202} 203 204class COP1_2R_FM<bits<6> funct, FIELD_FMT Format> : MipsR6Inst { 205 bits<5> fs; 206 bits<5> fd; 207 208 bits<32> Inst; 209 210 let Inst{31-26} = OPGROUP_COP1.Value; 211 let Inst{25-21} = Format.Value; 212 let Inst{20-16} = 0b00000; 213 let Inst{15-11} = fs; 214 let Inst{10-6} = fd; 215 let Inst{5-0} = funct; 216} 217 218class COP1_3R_FM<bits<6> funct, FIELD_FMT Format> : MipsR6Inst { 219 bits<5> ft; 220 bits<5> fs; 221 bits<5> fd; 222 223 bits<32> Inst; 224 225 let Inst{31-26} = OPGROUP_COP1.Value; 226 let Inst{25-21} = Format.Value; 227 let Inst{20-16} = ft; 228 let Inst{15-11} = fs; 229 let Inst{10-6} = fd; 230 let Inst{5-0} = funct; 231} 232 233class COP1_BCCZ_FM<OPCODE5 Operation> : MipsR6Inst { 234 bits<5> ft; 235 bits<16> offset; 236 237 bits<32> Inst; 238 239 let Inst{31-26} = OPGROUP_COP1.Value; 240 let Inst{25-21} = Operation.Value; 241 let Inst{20-16} = ft; 242 let Inst{15-0} = offset; 243} 244 245class COP2_BCCZ_FM<OPCODE5 Operation> : MipsR6Inst { 246 bits<5> ct; 247 bits<16> offset; 248 249 bits<32> Inst; 250 251 let Inst{31-26} = OPGROUP_COP2.Value; 252 let Inst{25-21} = Operation.Value; 253 let Inst{20-16} = ct; 254 let Inst{15-0} = offset; 255} 256 257class PCREL16_FM<OPCODE5 Operation> : MipsR6Inst { 258 bits<5> rs; 259 bits<16> imm; 260 261 bits<32> Inst; 262 263 let Inst{31-26} = OPGROUP_PCREL.Value; 264 let Inst{25-21} = rs; 265 let Inst{20-16} = Operation.Value; 266 let Inst{15-0} = imm; 267} 268 269class PCREL19_FM<OPCODE2 Operation> : MipsR6Inst { 270 bits<5> rs; 271 bits<19> imm; 272 273 bits<32> Inst; 274 275 let Inst{31-26} = OPGROUP_PCREL.Value; 276 let Inst{25-21} = rs; 277 let Inst{20-19} = Operation.Value; 278 let Inst{18-0} = imm; 279} 280 281class PCREL18_FM<OPCODE3 Operation> : MipsR6Inst { 282 bits<5> rs; 283 bits<18> imm; 284 285 bits<32> Inst; 286 287 let Inst{31-26} = OPGROUP_PCREL.Value; 288 let Inst{25-21} = rs; 289 let Inst{20-18} = Operation.Value; 290 let Inst{17-0} = imm; 291} 292 293class SPECIAL3_2R_FM<OPCODE6 Operation> : MipsR6Inst { 294 bits<5> rd; 295 bits<5> rt; 296 297 bits<32> Inst; 298 299 let Inst{31-26} = OPGROUP_SPECIAL3.Value; 300 let Inst{25-21} = 0b00000; 301 let Inst{20-16} = rt; 302 let Inst{15-11} = rd; 303 let Inst{10-6} = 0b00000; 304 let Inst{5-0} = Operation.Value; 305} 306 307class SPECIAL3_MEM_FM<OPCODE6 Operation> : MipsR6Inst { 308 bits<21> addr; 309 bits<5> hint; 310 bits<5> base = addr{20-16}; 311 bits<9> offset = addr{8-0}; 312 313 bits<32> Inst; 314 315 let Inst{31-26} = OPGROUP_SPECIAL3.Value; 316 let Inst{25-21} = base; 317 let Inst{20-16} = hint; 318 let Inst{15-7} = offset; 319 let Inst{6} = 0; 320 let Inst{5-0} = Operation.Value; 321} 322 323class SPECIAL_2R_FM<OPCODE6 Operation> : MipsR6Inst { 324 bits<5> rd; 325 bits<5> rs; 326 327 bits<32> Inst; 328 329 let Inst{31-26} = OPGROUP_SPECIAL.Value; 330 let Inst{25-21} = rs; 331 let Inst{20-16} = 0b00000; 332 let Inst{15-11} = rd; 333 let Inst{10-6} = 0b00001; 334 let Inst{5-0} = Operation.Value; 335} 336 337class SPECIAL_3R_FM<bits<5> mulop, bits<6> funct> : MipsR6Inst { 338 bits<5> rd; 339 bits<5> rs; 340 bits<5> rt; 341 342 bits<32> Inst; 343 344 let Inst{31-26} = OPGROUP_SPECIAL.Value; 345 let Inst{25-21} = rs; 346 let Inst{20-16} = rt; 347 let Inst{15-11} = rd; 348 let Inst{10-6} = mulop; 349 let Inst{5-0} = funct; 350} 351 352class SPECIAL_SDBBP_FM : MipsR6Inst { 353 bits<20> code_; 354 355 bits<32> Inst; 356 357 let Inst{31-26} = OPGROUP_SPECIAL.Value; 358 let Inst{25-6} = code_; 359 let Inst{5-0} = OPCODE6_SDBBP.Value; 360} 361 362// This class is ambiguous with other branches: 363// BEQC/BNEC require that rs < rt && rs != 0 364class CMP_BRANCH_2R_OFF16_FM<OPGROUP funct> : MipsR6Inst { 365 bits<5> rs; 366 bits<5> rt; 367 bits<16> offset; 368 369 bits<32> Inst; 370 371 let Inst{31-26} = funct.Value; 372 let Inst{25-21} = rs; 373 let Inst{20-16} = rt; 374 let Inst{15-0} = offset; 375} 376 377// This class is ambiguous with other branches: 378// BLEZC/BGEZC/BEQZALC/BNEZALC/BGTZALC require that rs == 0 && rt != 0 379// The '1R_RT' in the name means 1 register in the rt field. 380class CMP_BRANCH_1R_RT_OFF16_FM<OPGROUP funct> : MipsR6Inst { 381 bits<5> rt; 382 bits<16> offset; 383 384 bits<32> Inst; 385 386 let Inst{31-26} = funct.Value; 387 let Inst{25-21} = 0b00000; 388 let Inst{20-16} = rt; 389 let Inst{15-0} = offset; 390} 391 392// This class is ambiguous with other branches: 393// BLTZC/BGTZC/BLTZALC/BGEZALC require that rs == rt && rt != 0 394// The '1R_BOTH' in the name means 1 register in both the rs and rt fields. 395class CMP_BRANCH_1R_BOTH_OFF16_FM<OPGROUP funct> : MipsR6Inst { 396 bits<5> rt; 397 bits<16> offset; 398 399 bits<32> Inst; 400 401 let Inst{31-26} = funct.Value; 402 let Inst{25-21} = rt; 403 let Inst{20-16} = rt; 404 let Inst{15-0} = offset; 405} 406 407class CMP_BRANCH_OFF21_FM<bits<6> funct> : MipsR6Inst { 408 bits<5> rs; // rs != 0 409 bits<21> offset; 410 411 bits<32> Inst; 412 413 let Inst{31-26} = funct; 414 let Inst{25-21} = rs; 415 let Inst{20-0} = offset; 416} 417 418class JMP_IDX_COMPACT_FM<bits<6> funct> : MipsR6Inst { 419 bits<5> rt; 420 bits<16> offset; 421 422 bits<32> Inst; 423 424 let Inst{31-26} = funct; 425 let Inst{25-21} = 0b00000; 426 let Inst{20-16} = rt; 427 let Inst{15-0} = offset; 428} 429 430class BRANCH_OFF26_FM<bits<6> funct> : MipsR6Inst { 431 bits<32> Inst; 432 bits<26> offset; 433 434 let Inst{31-26} = funct; 435 let Inst{25-0} = offset; 436} 437 438class SPECIAL3_ALIGN_FM<OPCODE6 Operation> : MipsR6Inst { 439 bits<5> rd; 440 bits<5> rs; 441 bits<5> rt; 442 bits<2> bp; 443 444 bits<32> Inst; 445 446 let Inst{31-26} = OPGROUP_SPECIAL3.Value; 447 let Inst{25-21} = rs; 448 let Inst{20-16} = rt; 449 let Inst{15-11} = rd; 450 let Inst{10-8} = 0b010; 451 let Inst{7-6} = bp; 452 let Inst{5-0} = Operation.Value; 453} 454 455class SPECIAL3_DALIGN_FM<OPCODE6 Operation> : MipsR6Inst { 456 bits<5> rd; 457 bits<5> rs; 458 bits<5> rt; 459 bits<3> bp; 460 461 bits<32> Inst; 462 463 let Inst{31-26} = OPGROUP_SPECIAL3.Value; 464 let Inst{25-21} = rs; 465 let Inst{20-16} = rt; 466 let Inst{15-11} = rd; 467 let Inst{10-9} = 0b01; 468 let Inst{8-6} = bp; 469 let Inst{5-0} = Operation.Value; 470} 471 472class SPECIAL3_LL_SC_FM<OPCODE6 Operation> : MipsR6Inst { 473 bits<5> rt; 474 bits<21> addr; 475 bits<5> base = addr{20-16}; 476 bits<9> offset = addr{8-0}; 477 478 bits<32> Inst; 479 480 let Inst{31-26} = OPGROUP_SPECIAL3.Value; 481 let Inst{25-21} = base; 482 let Inst{20-16} = rt; 483 let Inst{15-7} = offset; 484 let Inst{5-0} = Operation.Value; 485 486 string DecoderMethod = "DecodeSpecial3LlSc"; 487} 488 489class SPECIAL_LSA_FM<OPCODE6 Operation> : MipsR6Inst { 490 bits<5> rd; 491 bits<5> rs; 492 bits<5> rt; 493 bits<2> imm2; 494 495 bits<32> Inst; 496 497 let Inst{31-26} = OPGROUP_SPECIAL.Value; 498 let Inst{25-21} = rs; 499 let Inst{20-16} = rt; 500 let Inst{15-11} = rd; 501 let Inst{10-8} = 0b000; 502 let Inst{7-6} = imm2; 503 let Inst{5-0} = Operation.Value; 504} 505 506class REGIMM_FM<OPCODE5 Operation> : MipsR6Inst { 507 bits<5> rs; 508 bits<16> imm; 509 510 bits<32> Inst; 511 512 let Inst{31-26} = OPGROUP_REGIMM.Value; 513 let Inst{25-21} = rs; 514 let Inst{20-16} = Operation.Value; 515 let Inst{15-0} = imm; 516} 517 518class COP1_CMP_CONDN_FM<FIELD_CMP_FORMAT Format, 519 FIELD_CMP_COND Cond> : MipsR6Inst { 520 bits<5> fd; 521 bits<5> fs; 522 bits<5> ft; 523 524 bits<32> Inst; 525 526 let Inst{31-26} = OPGROUP_COP1.Value; 527 let Inst{25-21} = Format.Value; 528 let Inst{20-16} = ft; 529 let Inst{15-11} = fs; 530 let Inst{10-6} = fd; 531 let Inst{5} = 0; 532 let Inst{4-0} = Cond.Value; 533} 534 535class JR_HB_R6_FM<OPCODE6 Operation> : MipsR6Inst { 536 bits<5> rs; 537 538 bits<32> Inst; 539 540 let Inst{31-26} = OPGROUP_SPECIAL.Value; 541 let Inst{25-21} = rs; 542 let Inst{20-16} = 0; 543 let Inst{15-11} = 0; 544 let Inst{10} = 1; 545 let Inst{9-6} = 0; 546 let Inst{5-0} = Operation.Value; 547} 548 549class COP2LDST_FM<OPCODE5 Operation> : MipsR6Inst { 550 bits<5> rt; 551 bits<21> addr; 552 bits<5> base = addr{20-16}; 553 bits<11> offset = addr{10-0}; 554 555 bits<32> Inst; 556 557 let Inst{31-26} = OPGROUP_COP2LDST.Value; 558 let Inst{25-21} = Operation.Value; 559 let Inst{20-16} = rt; 560 let Inst{15-11} = base; 561 let Inst{10-0} = offset; 562} 563