LoongArchInstrFormats.td 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. //===- LoongArchInstrFormats.td - LoongArch Instr. 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. // Describe LoongArch instructions format
  10. //
  11. // opcode - operation code.
  12. // rd - destination register operand.
  13. // r{j/k} - source register operand.
  14. // immN - immediate data operand.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. class LAInst<dag outs, dag ins, string opcstr, string opnstr,
  18. list<dag> pattern = []>
  19. : Instruction {
  20. field bits<32> Inst;
  21. // SoftFail is a field the disassembler can use to provide a way for
  22. // instructions to not match without killing the whole decode process. It is
  23. // mainly used for ARM, but Tablegen expects this field to exist or it fails
  24. // to build the decode table.
  25. field bits<32> SoftFail = 0;
  26. let Namespace = "LoongArch";
  27. let Size = 4;
  28. let OutOperandList = outs;
  29. let InOperandList = ins;
  30. let AsmString = opcstr # "\t" # opnstr;
  31. let Pattern = pattern;
  32. }
  33. // Pseudo instructions
  34. class Pseudo<dag outs, dag ins, list<dag> pattern = [], string opcstr = "",
  35. string opnstr = "">
  36. : LAInst<outs, ins, opcstr, opnstr, pattern> {
  37. let isPseudo = 1;
  38. let isCodeGenOnly = 1;
  39. }
  40. // 2R-type
  41. // <opcode | rj | rd>
  42. class Fmt2R<bits<22> op, dag outs, dag ins, string opcstr, string opnstr,
  43. list<dag> pattern = []>
  44. : LAInst<outs, ins, opcstr, opnstr, pattern> {
  45. bits<5> rj;
  46. bits<5> rd;
  47. let Inst{31-10} = op;
  48. let Inst{9-5} = rj;
  49. let Inst{4-0} = rd;
  50. }
  51. // 3R-type
  52. // <opcode | rk | rj | rd>
  53. class Fmt3R<bits<17> op, dag outs, dag ins, string opcstr, string opnstr,
  54. list<dag> pattern = []>
  55. : LAInst<outs, ins, opcstr, opnstr, pattern> {
  56. bits<5> rk;
  57. bits<5> rj;
  58. bits<5> rd;
  59. let Inst{31-15} = op;
  60. let Inst{14-10} = rk;
  61. let Inst{9-5} = rj;
  62. let Inst{4-0} = rd;
  63. }
  64. // 3RI2-type
  65. // <opcode | I2 | rk | rj | rd>
  66. class Fmt3RI2<bits<15> op, dag outs, dag ins, string opcstr, string opnstr,
  67. list<dag> pattern = []>
  68. : LAInst<outs, ins, opcstr, opnstr, pattern> {
  69. bits<2> imm2;
  70. bits<5> rk;
  71. bits<5> rj;
  72. bits<5> rd;
  73. let Inst{31-17} = op;
  74. let Inst{16-15} = imm2;
  75. let Inst{14-10} = rk;
  76. let Inst{9-5} = rj;
  77. let Inst{4-0} = rd;
  78. }
  79. // 3RI3-type
  80. // <opcode | I3 | rk | rj | rd>
  81. class Fmt3RI3<bits<14> op, dag outs, dag ins, string opcstr, string opnstr,
  82. list<dag> pattern = []>
  83. : LAInst<outs, ins, opcstr, opnstr, pattern> {
  84. bits<3> imm3;
  85. bits<5> rk;
  86. bits<5> rj;
  87. bits<5> rd;
  88. let Inst{31-18} = op;
  89. let Inst{17-15} = imm3;
  90. let Inst{14-10} = rk;
  91. let Inst{9-5} = rj;
  92. let Inst{4-0} = rd;
  93. }
  94. // 2RI5-type
  95. // <opcode | I5 | rj | rd>
  96. class Fmt2RI5<bits<17> op, dag outs, dag ins, string opcstr, string opnstr,
  97. list<dag> pattern = []>
  98. : LAInst<outs, ins, opcstr, opnstr, pattern> {
  99. bits<5> imm5;
  100. bits<5> rj;
  101. bits<5> rd;
  102. let Inst{31-15} = op;
  103. let Inst{14-10} = imm5;
  104. let Inst{9-5} = rj;
  105. let Inst{4-0} = rd;
  106. }
  107. // 2RI6-type
  108. // <opcode | I6 | rj | rd>
  109. class Fmt2RI6<bits<16> op, dag outs, dag ins, string opcstr, string opnstr,
  110. list<dag> pattern = []>
  111. : LAInst<outs, ins, opcstr, opnstr, pattern> {
  112. bits<6> imm6;
  113. bits<5> rj;
  114. bits<5> rd;
  115. let Inst{31-16} = op;
  116. let Inst{15-10} = imm6;
  117. let Inst{9-5} = rj;
  118. let Inst{4-0} = rd;
  119. }
  120. // 2RI8-type
  121. // <opcode | I8 | rj | rd>
  122. class Fmt2RI8<bits<14> op, dag outs, dag ins, string opcstr, string opnstr,
  123. list<dag> pattern = []>
  124. : LAInst<outs, ins, opcstr, opnstr, pattern> {
  125. bits<8> imm8;
  126. bits<5> rj;
  127. bits<5> rd;
  128. let Inst{31-18} = op;
  129. let Inst{17-10} = imm8;
  130. let Inst{9-5} = rj;
  131. let Inst{4-0} = rd;
  132. }
  133. // 2RI12-type
  134. // <opcode | I12 | rj | rd>
  135. class Fmt2RI12<bits<10> op, dag outs, dag ins, string opcstr, string opnstr,
  136. list<dag> pattern = []>
  137. : LAInst<outs, ins, opcstr, opnstr, pattern> {
  138. bits<12> imm12;
  139. bits<5> rj;
  140. bits<5> rd;
  141. let Inst{31-22} = op;
  142. let Inst{21-10} = imm12;
  143. let Inst{9-5} = rj;
  144. let Inst{4-0} = rd;
  145. }
  146. // 2RI14-type
  147. // <opcode | I14 | rj | rd>
  148. class Fmt2RI14<bits<8> op, dag outs, dag ins, string opcstr, string opnstr,
  149. list<dag> pattern = []>
  150. : LAInst<outs, ins, opcstr, opnstr, pattern> {
  151. bits<14> imm14;
  152. bits<5> rj;
  153. bits<5> rd;
  154. let Inst{31-24} = op;
  155. let Inst{23-10} = imm14;
  156. let Inst{9-5} = rj;
  157. let Inst{4-0} = rd;
  158. }
  159. // 2RI16-type
  160. // <opcode | I16 | rj | rd>
  161. class Fmt2RI16<bits<6> op, dag outs, dag ins, string opcstr, string opnstr,
  162. list<dag> pattern = []>
  163. : LAInst<outs, ins, opcstr, opnstr, pattern> {
  164. bits<16> imm16;
  165. bits<5> rj;
  166. bits<5> rd;
  167. let Inst{31-26} = op;
  168. let Inst{25-10} = imm16;
  169. let Inst{9-5} = rj;
  170. let Inst{4-0} = rd;
  171. }
  172. // 1RI20-type
  173. // <opcode | I20 | rd>
  174. class Fmt1RI20<bits<7> op, dag outs, dag ins, string opcstr, string opnstr,
  175. list<dag> pattern = []>
  176. : LAInst<outs, ins, opcstr, opnstr, pattern> {
  177. bits<20> imm20;
  178. bits<5> rd;
  179. let Inst{31-25} = op;
  180. let Inst{24-5} = imm20;
  181. let Inst{4-0} = rd;
  182. }
  183. // 1RI21-type
  184. // <opcode | I21[15:0] | rj | I21[20:16]>
  185. class Fmt1RI21<bits<6> op, dag outs, dag ins, string opcstr, string opnstr,
  186. list<dag> pattern = []>
  187. : LAInst<outs, ins, opcstr, opnstr, pattern> {
  188. bits<21> imm21;
  189. bits<5> rj;
  190. let Inst{31-26} = op;
  191. let Inst{25-10} = imm21{15-0};
  192. let Inst{9-5} = rj;
  193. let Inst{4-0} = imm21{20-16};
  194. }
  195. // I15-type
  196. // <opcode | I15>
  197. class FmtI15<bits<17> op, dag outs, dag ins, string opcstr, string opnstr,
  198. list<dag> pattern = []>
  199. : LAInst<outs, ins, opcstr, opnstr, pattern> {
  200. bits<15> imm15;
  201. let Inst{31-15} = op;
  202. let Inst{14-0} = imm15;
  203. }
  204. // I26-type
  205. // <opcode | I26[15:0] | I26[25:16]>
  206. class FmtI26<bits<6> op, dag outs, dag ins, string opcstr, string opnstr,
  207. list<dag> pattern = []>
  208. : LAInst<outs, ins, opcstr, opnstr, pattern> {
  209. bits<26> imm26;
  210. let Inst{31-26} = op;
  211. let Inst{25-10} = imm26{15-0};
  212. let Inst{9-0} = imm26{25-16};
  213. }
  214. // FmtBSTR_W
  215. // <opcode[11:1] | msbw | opcode[0] | lsbw | rj | rd>
  216. class FmtBSTR_W<bits<12> op, dag outs, dag ins, string opcstr, string opnstr,
  217. list<dag> pattern = []>
  218. : LAInst<outs, ins, opcstr, opnstr, pattern> {
  219. bits<5> msbw;
  220. bits<5> lsbw;
  221. bits<5> rj;
  222. bits<5> rd;
  223. let Inst{31-21} = op{11-1};
  224. let Inst{20-16} = msbw;
  225. let Inst{15} = op{0};
  226. let Inst{14-10} = lsbw;
  227. let Inst{9-5} = rj;
  228. let Inst{4-0} = rd;
  229. }
  230. // FmtBSTR_D
  231. // <opcode | msbd | lsbd | rj | rd>
  232. class FmtBSTR_D<bits<10> op, dag outs, dag ins, string opcstr, string opnstr,
  233. list<dag> pattern = []>
  234. : LAInst<outs, ins, opcstr, opnstr, pattern> {
  235. bits<6> msbd;
  236. bits<6> lsbd;
  237. bits<5> rj;
  238. bits<5> rd;
  239. let Inst{31-22} = op;
  240. let Inst{21-16} = msbd;
  241. let Inst{15-10} = lsbd;
  242. let Inst{9-5} = rj;
  243. let Inst{4-0} = rd;
  244. }
  245. // FmtASRT
  246. // <opcode | rk | rj | 0x0>
  247. class FmtASRT<bits<17> op, dag outs, dag ins, string opcstr, string opnstr,
  248. list<dag> pattern = []>
  249. : LAInst<outs, ins, opcstr, opnstr, pattern> {
  250. bits<5> rk;
  251. bits<5> rj;
  252. let Inst{31-15} = op;
  253. let Inst{14-10} = rk;
  254. let Inst{9-5} = rj;
  255. let Inst{4-0} = 0x0;
  256. }
  257. // FmtPRELD
  258. // < 0b0010101011 | I12 | rj | I5>
  259. class FmtPRELD<dag outs, dag ins, string opcstr, string opnstr,
  260. list<dag> pattern = []>
  261. : LAInst<outs, ins, opcstr, opnstr, pattern> {
  262. bits<12> imm12;
  263. bits<5> rj;
  264. bits<5> imm5;
  265. let Inst{31-22} = 0b0010101011;
  266. let Inst{21-10} = imm12;
  267. let Inst{9-5} = rj;
  268. let Inst{4-0} = imm5;
  269. }
  270. // FmtPRELDX
  271. // < 0b00111000001011000 | rk | rj | I5>
  272. class FmtPRELDX<dag outs, dag ins, string opcstr, string opnstr,
  273. list<dag> pattern = []>
  274. : LAInst<outs, ins, opcstr, opnstr, pattern> {
  275. bits<5> rk;
  276. bits<5> rj;
  277. bits<5> imm5;
  278. let Inst{31-15} = 0b00111000001011000;
  279. let Inst{14-10} = rk;
  280. let Inst{9-5} = rj;
  281. let Inst{4-0} = imm5;
  282. }
  283. // FmtCSR
  284. // <opcode[12:5] | csr_num | opcode[4:0] | rd>
  285. class FmtCSR<bits<13> op, dag outs, dag ins, string opcstr, string opnstr,
  286. list<dag> pattern = []>
  287. : LAInst<outs, ins, opcstr, opnstr, pattern> {
  288. bits<14> csr_num;
  289. bits<5> rd;
  290. let Inst{31-24} = op{12-5};
  291. let Inst{23-10} = csr_num;
  292. let Inst{9-5} = op{4-0};
  293. let Inst{4-0} = rd;
  294. }
  295. // FmtCSRXCHG
  296. // <opcode | csr_num | rj | rd>
  297. class FmtCSRXCHG<bits<8> op, dag outs, dag ins, string opcstr, string opnstr,
  298. list<dag> pattern = []>
  299. : LAInst<outs, ins, opcstr, opnstr, pattern> {
  300. bits<14> csr_num;
  301. bits<5> rj;
  302. bits<5> rd;
  303. let Inst{31-24} = op;
  304. let Inst{23-10} = csr_num;
  305. let Inst{9-5} = rj;
  306. let Inst{4-0} = rd;
  307. }
  308. // FmtCACOP
  309. // <0b0000011000 | I12 | rj | I5>
  310. class FmtCACOP<dag outs, dag ins, string opcstr, string opnstr,
  311. list<dag> pattern = []>
  312. : LAInst<outs, ins, opcstr, opnstr, pattern> {
  313. bits<12> imm12;
  314. bits<5> rj;
  315. bits<5> op;
  316. let Inst{31-22} = 0b0000011000;
  317. let Inst{21-10} = imm12;
  318. let Inst{9-5} = rj;
  319. let Inst{4-0} = op;
  320. }
  321. // FmtIMM32
  322. // <I32>
  323. class FmtI32<bits<32> op, string opstr, list<dag> pattern = []>
  324. : LAInst<(outs), (ins), opstr, "", pattern> {
  325. let Inst{31-0} = op;
  326. }
  327. // FmtINVTLB
  328. // <0b00000110010010011 | rk | rj | I5>
  329. class FmtINVTLB<dag outs, dag ins, string opcstr, string opnstr,
  330. list<dag> pattern = []>
  331. : LAInst<outs, ins, opcstr, opnstr, pattern> {
  332. bits<5> rk;
  333. bits<5> rj;
  334. bits<5> op;
  335. let Inst{31-15} = 0b00000110010010011;
  336. let Inst{14-10} = rk;
  337. let Inst{9-5} = rj;
  338. let Inst{4-0} = op;
  339. }
  340. // FmtLDPTE
  341. // <0b00000110010001 | seq | rj | 00000>
  342. class FmtLDPTE<dag outs, dag ins, string opcstr, string opnstr,
  343. list<dag> pattern = []>
  344. : LAInst<outs, ins, opcstr, opnstr, pattern> {
  345. bits<8> seq;
  346. bits<5> rj;
  347. let Inst{31-18} = 0b00000110010001;
  348. let Inst{17-10} = seq;
  349. let Inst{9-5} = rj;
  350. let Inst{4-0} = 0b00000;
  351. }