RISCVInstrFormatsC.td 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. //===-- RISCVInstrFormatsC.td - RISCV C Instruction Formats --*- tablegen -*-=//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file describes the RISC-V C extension instruction formats.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. class RVInst16<dag outs, dag ins, string opcodestr, string argstr,
  13. list<dag> pattern, InstFormat format>
  14. : Instruction {
  15. field bits<16> Inst;
  16. // SoftFail is a field the disassembler can use to provide a way for
  17. // instructions to not match without killing the whole decode process. It is
  18. // mainly used for ARM, but Tablegen expects this field to exist or it fails
  19. // to build the decode table.
  20. field bits<16> SoftFail = 0;
  21. let Size = 2;
  22. bits<2> Opcode = 0;
  23. let Namespace = "RISCV";
  24. dag OutOperandList = outs;
  25. dag InOperandList = ins;
  26. let AsmString = opcodestr # "\t" # argstr;
  27. let Pattern = pattern;
  28. let TSFlags{4-0} = format.Value;
  29. }
  30. class RVInst16CR<bits<4> funct4, bits<2> opcode, dag outs, dag ins,
  31. string opcodestr, string argstr>
  32. : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCR> {
  33. bits<5> rs1;
  34. bits<5> rs2;
  35. let Inst{15-12} = funct4;
  36. let Inst{11-7} = rs1;
  37. let Inst{6-2} = rs2;
  38. let Inst{1-0} = opcode;
  39. }
  40. // The immediate value encoding differs for each instruction, so each subclass
  41. // is responsible for setting the appropriate bits in the Inst field.
  42. // The bits Inst{6-2} must be set for each instruction.
  43. class RVInst16CI<bits<3> funct3, bits<2> opcode, dag outs, dag ins,
  44. string opcodestr, string argstr>
  45. : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCI> {
  46. bits<10> imm;
  47. bits<5> rd;
  48. bits<5> rs1;
  49. let Inst{15-13} = funct3;
  50. let Inst{12} = imm{5};
  51. let Inst{11-7} = rd;
  52. let Inst{1-0} = opcode;
  53. }
  54. // The immediate value encoding differs for each instruction, so each subclass
  55. // is responsible for setting the appropriate bits in the Inst field.
  56. // The bits Inst{12-7} must be set for each instruction.
  57. class RVInst16CSS<bits<3> funct3, bits<2> opcode, dag outs, dag ins,
  58. string opcodestr, string argstr>
  59. : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCSS> {
  60. bits<10> imm;
  61. bits<5> rs2;
  62. bits<5> rs1;
  63. let Inst{15-13} = funct3;
  64. let Inst{6-2} = rs2;
  65. let Inst{1-0} = opcode;
  66. }
  67. class RVInst16CIW<bits<3> funct3, bits<2> opcode, dag outs, dag ins,
  68. string opcodestr, string argstr>
  69. : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCIW> {
  70. bits<10> imm;
  71. bits<3> rd;
  72. let Inst{15-13} = funct3;
  73. let Inst{4-2} = rd;
  74. let Inst{1-0} = opcode;
  75. }
  76. // The immediate value encoding differs for each instruction, so each subclass
  77. // is responsible for setting the appropriate bits in the Inst field.
  78. // The bits Inst{12-10} and Inst{6-5} must be set for each instruction.
  79. class RVInst16CL<bits<3> funct3, bits<2> opcode, dag outs, dag ins,
  80. string opcodestr, string argstr>
  81. : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCL> {
  82. bits<3> rd;
  83. bits<3> rs1;
  84. let Inst{15-13} = funct3;
  85. let Inst{9-7} = rs1;
  86. let Inst{4-2} = rd;
  87. let Inst{1-0} = opcode;
  88. }
  89. // The immediate value encoding differs for each instruction, so each subclass
  90. // is responsible for setting the appropriate bits in the Inst field.
  91. // The bits Inst{12-10} and Inst{6-5} must be set for each instruction.
  92. class RVInst16CS<bits<3> funct3, bits<2> opcode, dag outs, dag ins,
  93. string opcodestr, string argstr>
  94. : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCS> {
  95. bits<3> rs2;
  96. bits<3> rs1;
  97. let Inst{15-13} = funct3;
  98. let Inst{9-7} = rs1;
  99. let Inst{4-2} = rs2;
  100. let Inst{1-0} = opcode;
  101. }
  102. class RVInst16CA<bits<6> funct6, bits<2> funct2, bits<2> opcode, dag outs,
  103. dag ins, string opcodestr, string argstr>
  104. : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCA> {
  105. bits<3> rs2;
  106. bits<3> rs1;
  107. let Inst{15-10} = funct6;
  108. let Inst{9-7} = rs1;
  109. let Inst{6-5} = funct2;
  110. let Inst{4-2} = rs2;
  111. let Inst{1-0} = opcode;
  112. }
  113. class RVInst16CB<bits<3> funct3, bits<2> opcode, dag outs, dag ins,
  114. string opcodestr, string argstr>
  115. : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCB> {
  116. bits<9> imm;
  117. bits<3> rs1;
  118. let Inst{15-13} = funct3;
  119. let Inst{9-7} = rs1;
  120. let Inst{1-0} = opcode;
  121. }
  122. class RVInst16CJ<bits<3> funct3, bits<2> opcode, dag outs, dag ins,
  123. string opcodestr, string argstr>
  124. : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCJ> {
  125. bits<11> offset;
  126. let Inst{15-13} = funct3;
  127. let Inst{12} = offset{10};
  128. let Inst{11} = offset{3};
  129. let Inst{10-9} = offset{8-7};
  130. let Inst{8} = offset{9};
  131. let Inst{7} = offset{5};
  132. let Inst{6} = offset{6};
  133. let Inst{5-3} = offset{2-0};
  134. let Inst{2} = offset{4};
  135. let Inst{1-0} = opcode;
  136. }