RISCVInstrInfoZk.td 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. //===- RISCVInstrInfoZk.td - RISC-V 'Zk' instructions ------*- 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 instructions from the standard 'Zk',
  10. // Scalar Cryptography Instructions extension, version 1.0.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //===----------------------------------------------------------------------===//
  14. // Operand and SDNode transformation definitions.
  15. //===----------------------------------------------------------------------===//
  16. def RnumArg : AsmOperandClass {
  17. let Name = "RnumArg";
  18. let RenderMethod = "addImmOperands";
  19. let DiagnosticType = "InvalidRnumArg";
  20. }
  21. def rnum : Operand<i32>, TImmLeaf<i32, [{return (Imm >= 0 && Imm <= 10);}]> {
  22. let ParserMatchClass = RnumArg;
  23. let EncoderMethod = "getImmOpValue";
  24. let DecoderMethod = "decodeUImmOperand<4>";
  25. let OperandType = "OPERAND_RVKRNUM";
  26. let OperandNamespace = "RISCVOp";
  27. }
  28. def byteselect : Operand<i8>, TImmLeaf<i8, [{return isUInt<2>(Imm);}]> {
  29. let ParserMatchClass = UImmAsmOperand<2>;
  30. let DecoderMethod = "decodeUImmOperand<2>";
  31. let OperandType = "OPERAND_UIMM2";
  32. let OperandNamespace = "RISCVOp";
  33. }
  34. //===----------------------------------------------------------------------===//
  35. // Instruction class templates
  36. //===----------------------------------------------------------------------===//
  37. let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
  38. class RVKUnary<bits<12> imm12_in, bits<3> funct3, string opcodestr>
  39. : RVInstI<funct3, OPC_OP_IMM, (outs GPR:$rd), (ins GPR:$rs1),
  40. opcodestr, "$rd, $rs1">{
  41. let imm12 = imm12_in;
  42. }
  43. let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
  44. class RVKByteSelect<bits<5> funct5, string opcodestr>
  45. : RVInstR<{0b00, funct5}, 0b000, OPC_OP, (outs GPR:$rd),
  46. (ins GPR:$rs1, GPR:$rs2, byteselect:$bs),
  47. opcodestr, "$rd, $rs1, $rs2, $bs">{
  48. bits<2> bs;
  49. let Inst{31-30} = bs;
  50. }
  51. let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
  52. class RVKUnary_rnum<bits<7> funct7, bits<3> funct3, string opcodestr>
  53. : RVInstI<funct3, OPC_OP_IMM, (outs GPR:$rd), (ins GPR:$rs1, rnum:$rnum),
  54. opcodestr, "$rd, $rs1, $rnum">{
  55. bits<4> rnum;
  56. let Inst{31-25} = funct7;
  57. let Inst{24} = 1;
  58. let Inst{23-20} = rnum;
  59. }
  60. //===----------------------------------------------------------------------===//
  61. // Instructions
  62. //===----------------------------------------------------------------------===//
  63. let Predicates = [HasStdExtZknd, IsRV32] in {
  64. def AES32DSI : RVKByteSelect<0b10101, "aes32dsi">;
  65. def AES32DSMI : RVKByteSelect<0b10111, "aes32dsmi">;
  66. } // Predicates = [HasStdExtZknd, IsRV32]
  67. let Predicates = [HasStdExtZknd, IsRV64] in {
  68. def AES64DS : ALU_rr<0b0011101, 0b000, "aes64ds">;
  69. def AES64DSM : ALU_rr<0b0011111, 0b000, "aes64dsm">;
  70. def AES64IM : RVKUnary<0b001100000000, 0b001, "aes64im">;
  71. } // Predicates = [HasStdExtZknd, IsRV64]
  72. let Predicates = [HasStdExtZkndOrZkne, IsRV64] in {
  73. def AES64KS2 : ALU_rr<0b0111111, 0b000, "aes64ks2">;
  74. def AES64KS1I : RVKUnary_rnum<0b0011000, 0b001, "aes64ks1i">;
  75. } // Predicates = [HasStdExtZkndOrZkne, IsRV64]
  76. let Predicates = [HasStdExtZkne, IsRV32] in {
  77. def AES32ESI : RVKByteSelect<0b10001, "aes32esi">;
  78. def AES32ESMI : RVKByteSelect<0b10011, "aes32esmi">;
  79. } // Predicates = [HasStdExtZkne, IsRV32]
  80. let Predicates = [HasStdExtZkne, IsRV64] in {
  81. def AES64ES : ALU_rr<0b0011001, 0b000, "aes64es">;
  82. def AES64ESM : ALU_rr<0b0011011, 0b000, "aes64esm">;
  83. } // Predicates = [HasStdExtZkne, IsRV64]
  84. let Predicates = [HasStdExtZknh], IsSignExtendingOpW = 1 in {
  85. def SHA256SIG0 : RVKUnary<0b000100000010, 0b001, "sha256sig0">;
  86. def SHA256SIG1 : RVKUnary<0b000100000011, 0b001, "sha256sig1">;
  87. def SHA256SUM0 : RVKUnary<0b000100000000, 0b001, "sha256sum0">;
  88. def SHA256SUM1 : RVKUnary<0b000100000001, 0b001, "sha256sum1">;
  89. } // Predicates = [HasStdExtZknh]
  90. let Predicates = [HasStdExtZknh, IsRV32] in {
  91. def SHA512SIG0H : ALU_rr<0b0101110, 0b000, "sha512sig0h">;
  92. def SHA512SIG0L : ALU_rr<0b0101010, 0b000, "sha512sig0l">;
  93. def SHA512SIG1H : ALU_rr<0b0101111, 0b000, "sha512sig1h">;
  94. def SHA512SIG1L : ALU_rr<0b0101011, 0b000, "sha512sig1l">;
  95. def SHA512SUM0R : ALU_rr<0b0101000, 0b000, "sha512sum0r">;
  96. def SHA512SUM1R : ALU_rr<0b0101001, 0b000, "sha512sum1r">;
  97. } // [HasStdExtZknh, IsRV32]
  98. let Predicates = [HasStdExtZknh, IsRV64] in {
  99. def SHA512SIG0 : RVKUnary<0b000100000110, 0b001, "sha512sig0">;
  100. def SHA512SIG1 : RVKUnary<0b000100000111, 0b001, "sha512sig1">;
  101. def SHA512SUM0 : RVKUnary<0b000100000100, 0b001, "sha512sum0">;
  102. def SHA512SUM1 : RVKUnary<0b000100000101, 0b001, "sha512sum1">;
  103. } // Predicates = [HasStdExtZknh, IsRV64]
  104. let Predicates = [HasStdExtZksed] in {
  105. def SM4ED : RVKByteSelect<0b11000, "sm4ed">;
  106. def SM4KS : RVKByteSelect<0b11010, "sm4ks">;
  107. } // Predicates = [HasStdExtZksed]
  108. let Predicates = [HasStdExtZksh] in {
  109. def SM3P0 : RVKUnary<0b000100001000, 0b001, "sm3p0">;
  110. def SM3P1 : RVKUnary<0b000100001001, 0b001, "sm3p1">;
  111. } // Predicates = [HasStdExtZksh]
  112. //===----------------------------------------------------------------------===//
  113. // Codegen patterns
  114. //===----------------------------------------------------------------------===//
  115. class PatGprGprByteSelect<SDPatternOperator OpNode, RVInst Inst>
  116. : Pat<(OpNode GPR:$rs1, GPR:$rs2, i8:$imm),
  117. (Inst GPR:$rs1, GPR:$rs2, byteselect:$imm)>;
  118. // Zknd
  119. let Predicates = [HasStdExtZknd, IsRV32] in {
  120. def : PatGprGprByteSelect<int_riscv_aes32dsi, AES32DSI>;
  121. def : PatGprGprByteSelect<int_riscv_aes32dsmi, AES32DSMI>;
  122. } // Predicates = [HasStdExtZknd, IsRV32]
  123. let Predicates = [HasStdExtZknd, IsRV64] in {
  124. def : PatGprGpr<int_riscv_aes64ds, AES64DS>;
  125. def : PatGprGpr<int_riscv_aes64dsm, AES64DSM>;
  126. def : PatGpr<int_riscv_aes64im, AES64IM>;
  127. } // Predicates = [HasStdExtZknd, IsRV64]
  128. let Predicates = [HasStdExtZkndOrZkne, IsRV64] in {
  129. def : PatGprGpr<int_riscv_aes64ks2, AES64KS2>;
  130. def : Pat<(int_riscv_aes64ks1i GPR:$rs1, i32:$rnum),
  131. (AES64KS1I GPR:$rs1, rnum:$rnum)>;
  132. } // Predicates = [HasStdExtZkndOrZkne, IsRV64]
  133. // Zkne
  134. let Predicates = [HasStdExtZkne, IsRV32] in {
  135. def : PatGprGprByteSelect<int_riscv_aes32esi, AES32ESI>;
  136. def : PatGprGprByteSelect<int_riscv_aes32esmi, AES32ESMI>;
  137. } // Predicates = [HasStdExtZkne, IsRV32]
  138. let Predicates = [HasStdExtZkne, IsRV64] in {
  139. def : PatGprGpr<int_riscv_aes64es, AES64ES>;
  140. def : PatGprGpr<int_riscv_aes64esm, AES64ESM>;
  141. } // Predicates = [HasStdExtZkne, IsRV64]
  142. // Zknh
  143. let Predicates = [HasStdExtZknh] in {
  144. def : PatGpr<int_riscv_sha256sig0, SHA256SIG0>;
  145. def : PatGpr<int_riscv_sha256sig1, SHA256SIG1>;
  146. def : PatGpr<int_riscv_sha256sum0, SHA256SUM0>;
  147. def : PatGpr<int_riscv_sha256sum1, SHA256SUM1>;
  148. } // Predicates = [HasStdExtZknh]
  149. let Predicates = [HasStdExtZknh, IsRV32] in {
  150. def : PatGprGpr<int_riscv_sha512sig0l, SHA512SIG0L>;
  151. def : PatGprGpr<int_riscv_sha512sig0h, SHA512SIG0H>;
  152. def : PatGprGpr<int_riscv_sha512sig1l, SHA512SIG1L>;
  153. def : PatGprGpr<int_riscv_sha512sig1h, SHA512SIG1H>;
  154. def : PatGprGpr<int_riscv_sha512sum0r, SHA512SUM0R>;
  155. def : PatGprGpr<int_riscv_sha512sum1r, SHA512SUM1R>;
  156. } // Predicates = [HasStdExtZknh, IsRV32]
  157. let Predicates = [HasStdExtZknh, IsRV64] in {
  158. def : PatGpr<int_riscv_sha512sig0, SHA512SIG0>;
  159. def : PatGpr<int_riscv_sha512sig1, SHA512SIG1>;
  160. def : PatGpr<int_riscv_sha512sum0, SHA512SUM0>;
  161. def : PatGpr<int_riscv_sha512sum1, SHA512SUM1>;
  162. } // Predicates = [HasStdExtZknh, IsRV64]
  163. // Zksed
  164. let Predicates = [HasStdExtZksed] in {
  165. def : PatGprGprByteSelect<int_riscv_sm4ks, SM4KS>;
  166. def : PatGprGprByteSelect<int_riscv_sm4ed, SM4ED>;
  167. } // Predicates = [HasStdExtZksed]
  168. // Zksh
  169. let Predicates = [HasStdExtZksh] in {
  170. def : PatGpr<int_riscv_sm3p0, SM3P0>;
  171. def : PatGpr<int_riscv_sm3p1, SM3P1>;
  172. } // Predicates = [HasStdExtZksh]