11fd87a68SDimitry Andric//===- RISCVInstrInfoZk.td - RISC-V 'Zk' instructions ------*- tablegen -*-===// 204eeddc0SDimitry Andric// 304eeddc0SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 404eeddc0SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 504eeddc0SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 604eeddc0SDimitry Andric// 704eeddc0SDimitry Andric//===----------------------------------------------------------------------===// 804eeddc0SDimitry Andric// 904eeddc0SDimitry Andric// This file describes the RISC-V instructions from the standard 'Zk', 1004eeddc0SDimitry Andric// Scalar Cryptography Instructions extension, version 1.0. 1104eeddc0SDimitry Andric// 1204eeddc0SDimitry Andric//===----------------------------------------------------------------------===// 1304eeddc0SDimitry Andric 1404eeddc0SDimitry Andric//===----------------------------------------------------------------------===// 1504eeddc0SDimitry Andric// Operand and SDNode transformation definitions. 1604eeddc0SDimitry Andric//===----------------------------------------------------------------------===// 1704eeddc0SDimitry Andric 1806c3fb27SDimitry Andricdef riscv_sha256sig0 : SDNode<"RISCVISD::SHA256SIG0", SDTIntUnaryOp>; 1906c3fb27SDimitry Andricdef riscv_sha256sig1 : SDNode<"RISCVISD::SHA256SIG1", SDTIntUnaryOp>; 2006c3fb27SDimitry Andricdef riscv_sha256sum0 : SDNode<"RISCVISD::SHA256SUM0", SDTIntUnaryOp>; 2106c3fb27SDimitry Andricdef riscv_sha256sum1 : SDNode<"RISCVISD::SHA256SUM1", SDTIntUnaryOp>; 2206c3fb27SDimitry Andric 2306c3fb27SDimitry Andricdef SDT_RISCVZkByteSelect : SDTypeProfile<1, 3, [SDTCisVT<0, XLenVT>, 2406c3fb27SDimitry Andric SDTCisVT<1, XLenVT>, 2506c3fb27SDimitry Andric SDTCisVT<2, XLenVT>, 2606c3fb27SDimitry Andric SDTCisVT<3, i32>]>; 2706c3fb27SDimitry Andricdef riscv_sm4ks : SDNode<"RISCVISD::SM4KS", SDT_RISCVZkByteSelect>; 2806c3fb27SDimitry Andricdef riscv_sm4ed : SDNode<"RISCVISD::SM4ED", SDT_RISCVZkByteSelect>; 2906c3fb27SDimitry Andric 3006c3fb27SDimitry Andricdef riscv_sm3p0 : SDNode<"RISCVISD::SM3P0", SDTIntUnaryOp>; 3106c3fb27SDimitry Andricdef riscv_sm3p1 : SDNode<"RISCVISD::SM3P1", SDTIntUnaryOp>; 3206c3fb27SDimitry Andric 3304eeddc0SDimitry Andricdef RnumArg : AsmOperandClass { 3404eeddc0SDimitry Andric let Name = "RnumArg"; 3504eeddc0SDimitry Andric let RenderMethod = "addImmOperands"; 3604eeddc0SDimitry Andric let DiagnosticType = "InvalidRnumArg"; 3704eeddc0SDimitry Andric} 3804eeddc0SDimitry Andric 39*5f757f3fSDimitry Andricdef rnum : RISCVOp<i32>, TImmLeaf<i32, [{return (Imm >= 0 && Imm <= 10);}]> { 4004eeddc0SDimitry Andric let ParserMatchClass = RnumArg; 4104eeddc0SDimitry Andric let EncoderMethod = "getImmOpValue"; 4204eeddc0SDimitry Andric let DecoderMethod = "decodeUImmOperand<4>"; 4304eeddc0SDimitry Andric let OperandType = "OPERAND_RVKRNUM"; 4404eeddc0SDimitry Andric} 4504eeddc0SDimitry Andric 46*5f757f3fSDimitry Andricdef byteselect : RISCVOp<i32>, TImmLeaf<i32, [{return isUInt<2>(Imm);}]> { 4704eeddc0SDimitry Andric let ParserMatchClass = UImmAsmOperand<2>; 4804eeddc0SDimitry Andric let DecoderMethod = "decodeUImmOperand<2>"; 4904eeddc0SDimitry Andric let OperandType = "OPERAND_UIMM2"; 5004eeddc0SDimitry Andric} 5104eeddc0SDimitry Andric 5204eeddc0SDimitry Andric//===----------------------------------------------------------------------===// 5304eeddc0SDimitry Andric// Instruction class templates 5404eeddc0SDimitry Andric//===----------------------------------------------------------------------===// 5504eeddc0SDimitry Andriclet hasSideEffects = 0, mayLoad = 0, mayStore = 0 in 56*5f757f3fSDimitry Andricclass RVKUnary<bits<12> imm12, bits<3> funct3, string opcodestr> 57*5f757f3fSDimitry Andric : RVInstIUnary<imm12, funct3, OPC_OP_IMM, (outs GPR:$rd), (ins GPR:$rs1), 58*5f757f3fSDimitry Andric opcodestr, "$rd, $rs1">; 5904eeddc0SDimitry Andric 6004eeddc0SDimitry Andriclet hasSideEffects = 0, mayLoad = 0, mayStore = 0 in 6104eeddc0SDimitry Andricclass RVKByteSelect<bits<5> funct5, string opcodestr> 6204eeddc0SDimitry Andric : RVInstR<{0b00, funct5}, 0b000, OPC_OP, (outs GPR:$rd), 6304eeddc0SDimitry Andric (ins GPR:$rs1, GPR:$rs2, byteselect:$bs), 6404eeddc0SDimitry Andric opcodestr, "$rd, $rs1, $rs2, $bs">{ 6504eeddc0SDimitry Andric bits<2> bs; 6604eeddc0SDimitry Andric let Inst{31-30} = bs; 6704eeddc0SDimitry Andric} 6804eeddc0SDimitry Andric 6904eeddc0SDimitry Andriclet hasSideEffects = 0, mayLoad = 0, mayStore = 0 in 7004eeddc0SDimitry Andricclass RVKUnary_rnum<bits<7> funct7, bits<3> funct3, string opcodestr> 71*5f757f3fSDimitry Andric : RVInstIBase<funct3, OPC_OP_IMM, (outs GPR:$rd), 72*5f757f3fSDimitry Andric (ins GPR:$rs1, rnum:$rnum), opcodestr, "$rd, $rs1, $rnum"> { 7304eeddc0SDimitry Andric bits<4> rnum; 7404eeddc0SDimitry Andric let Inst{31-25} = funct7; 75*5f757f3fSDimitry Andric let Inst{24} = 0b1; 7604eeddc0SDimitry Andric let Inst{23-20} = rnum; 7704eeddc0SDimitry Andric} 7804eeddc0SDimitry Andric 7904eeddc0SDimitry Andric//===----------------------------------------------------------------------===// 8004eeddc0SDimitry Andric// Instructions 8104eeddc0SDimitry Andric//===----------------------------------------------------------------------===// 8204eeddc0SDimitry Andriclet Predicates = [HasStdExtZknd, IsRV32] in { 8304eeddc0SDimitry Andricdef AES32DSI : RVKByteSelect<0b10101, "aes32dsi">; 8404eeddc0SDimitry Andricdef AES32DSMI : RVKByteSelect<0b10111, "aes32dsmi">; 8504eeddc0SDimitry Andric} // Predicates = [HasStdExtZknd, IsRV32] 8604eeddc0SDimitry Andric 8704eeddc0SDimitry Andriclet Predicates = [HasStdExtZknd, IsRV64] in { 8804eeddc0SDimitry Andricdef AES64DS : ALU_rr<0b0011101, 0b000, "aes64ds">; 8904eeddc0SDimitry Andricdef AES64DSM : ALU_rr<0b0011111, 0b000, "aes64dsm">; 9004eeddc0SDimitry Andric 9104eeddc0SDimitry Andricdef AES64IM : RVKUnary<0b001100000000, 0b001, "aes64im">; 9204eeddc0SDimitry Andric} // Predicates = [HasStdExtZknd, IsRV64] 9304eeddc0SDimitry Andric 9404eeddc0SDimitry Andriclet Predicates = [HasStdExtZkndOrZkne, IsRV64] in { 9504eeddc0SDimitry Andricdef AES64KS2 : ALU_rr<0b0111111, 0b000, "aes64ks2">; 9604eeddc0SDimitry Andric 9704eeddc0SDimitry Andricdef AES64KS1I : RVKUnary_rnum<0b0011000, 0b001, "aes64ks1i">; 9804eeddc0SDimitry Andric} // Predicates = [HasStdExtZkndOrZkne, IsRV64] 9904eeddc0SDimitry Andric 10004eeddc0SDimitry Andriclet Predicates = [HasStdExtZkne, IsRV32] in { 10104eeddc0SDimitry Andricdef AES32ESI : RVKByteSelect<0b10001, "aes32esi">; 10204eeddc0SDimitry Andricdef AES32ESMI : RVKByteSelect<0b10011, "aes32esmi">; 10304eeddc0SDimitry Andric} // Predicates = [HasStdExtZkne, IsRV32] 10404eeddc0SDimitry Andric 10504eeddc0SDimitry Andriclet Predicates = [HasStdExtZkne, IsRV64] in { 10604eeddc0SDimitry Andricdef AES64ES : ALU_rr<0b0011001, 0b000, "aes64es">; 10704eeddc0SDimitry Andricdef AES64ESM : ALU_rr<0b0011011, 0b000, "aes64esm">; 10804eeddc0SDimitry Andric} // Predicates = [HasStdExtZkne, IsRV64] 10904eeddc0SDimitry Andric 110bdd1243dSDimitry Andriclet Predicates = [HasStdExtZknh], IsSignExtendingOpW = 1 in { 11104eeddc0SDimitry Andricdef SHA256SIG0 : RVKUnary<0b000100000010, 0b001, "sha256sig0">; 11204eeddc0SDimitry Andricdef SHA256SIG1 : RVKUnary<0b000100000011, 0b001, "sha256sig1">; 11304eeddc0SDimitry Andricdef SHA256SUM0 : RVKUnary<0b000100000000, 0b001, "sha256sum0">; 11404eeddc0SDimitry Andricdef SHA256SUM1 : RVKUnary<0b000100000001, 0b001, "sha256sum1">; 11504eeddc0SDimitry Andric} // Predicates = [HasStdExtZknh] 11604eeddc0SDimitry Andric 11704eeddc0SDimitry Andriclet Predicates = [HasStdExtZknh, IsRV32] in { 11804eeddc0SDimitry Andricdef SHA512SIG0H : ALU_rr<0b0101110, 0b000, "sha512sig0h">; 11904eeddc0SDimitry Andricdef SHA512SIG0L : ALU_rr<0b0101010, 0b000, "sha512sig0l">; 12004eeddc0SDimitry Andricdef SHA512SIG1H : ALU_rr<0b0101111, 0b000, "sha512sig1h">; 12104eeddc0SDimitry Andricdef SHA512SIG1L : ALU_rr<0b0101011, 0b000, "sha512sig1l">; 12204eeddc0SDimitry Andricdef SHA512SUM0R : ALU_rr<0b0101000, 0b000, "sha512sum0r">; 12304eeddc0SDimitry Andricdef SHA512SUM1R : ALU_rr<0b0101001, 0b000, "sha512sum1r">; 12404eeddc0SDimitry Andric} // [HasStdExtZknh, IsRV32] 12504eeddc0SDimitry Andric 12604eeddc0SDimitry Andriclet Predicates = [HasStdExtZknh, IsRV64] in { 12704eeddc0SDimitry Andricdef SHA512SIG0 : RVKUnary<0b000100000110, 0b001, "sha512sig0">; 12804eeddc0SDimitry Andricdef SHA512SIG1 : RVKUnary<0b000100000111, 0b001, "sha512sig1">; 12904eeddc0SDimitry Andricdef SHA512SUM0 : RVKUnary<0b000100000100, 0b001, "sha512sum0">; 13004eeddc0SDimitry Andricdef SHA512SUM1 : RVKUnary<0b000100000101, 0b001, "sha512sum1">; 13104eeddc0SDimitry Andric} // Predicates = [HasStdExtZknh, IsRV64] 13204eeddc0SDimitry Andric 13306c3fb27SDimitry Andriclet Predicates = [HasStdExtZksed], IsSignExtendingOpW = 1 in { 13404eeddc0SDimitry Andricdef SM4ED : RVKByteSelect<0b11000, "sm4ed">; 13504eeddc0SDimitry Andricdef SM4KS : RVKByteSelect<0b11010, "sm4ks">; 13604eeddc0SDimitry Andric} // Predicates = [HasStdExtZksed] 13704eeddc0SDimitry Andric 13806c3fb27SDimitry Andriclet Predicates = [HasStdExtZksh], IsSignExtendingOpW = 1 in { 13904eeddc0SDimitry Andricdef SM3P0 : RVKUnary<0b000100001000, 0b001, "sm3p0">; 14004eeddc0SDimitry Andricdef SM3P1 : RVKUnary<0b000100001001, 0b001, "sm3p1">; 14104eeddc0SDimitry Andric} // Predicates = [HasStdExtZksh] 14204eeddc0SDimitry Andric 14304eeddc0SDimitry Andric//===----------------------------------------------------------------------===// 14404eeddc0SDimitry Andric// Codegen patterns 14504eeddc0SDimitry Andric//===----------------------------------------------------------------------===// 14604eeddc0SDimitry Andric 14704eeddc0SDimitry Andricclass PatGprGprByteSelect<SDPatternOperator OpNode, RVInst Inst> 14806c3fb27SDimitry Andric : Pat<(XLenVT (OpNode (XLenVT GPR:$rs1), (XLenVT GPR:$rs2), byteselect:$imm)), 14904eeddc0SDimitry Andric (Inst GPR:$rs1, GPR:$rs2, byteselect:$imm)>; 15004eeddc0SDimitry Andric 15104eeddc0SDimitry Andric// Zknd 15204eeddc0SDimitry Andriclet Predicates = [HasStdExtZknd, IsRV32] in { 15304eeddc0SDimitry Andricdef : PatGprGprByteSelect<int_riscv_aes32dsi, AES32DSI>; 15404eeddc0SDimitry Andricdef : PatGprGprByteSelect<int_riscv_aes32dsmi, AES32DSMI>; 15504eeddc0SDimitry Andric} // Predicates = [HasStdExtZknd, IsRV32] 15604eeddc0SDimitry Andric 15704eeddc0SDimitry Andriclet Predicates = [HasStdExtZknd, IsRV64] in { 15804eeddc0SDimitry Andricdef : PatGprGpr<int_riscv_aes64ds, AES64DS>; 15904eeddc0SDimitry Andricdef : PatGprGpr<int_riscv_aes64dsm, AES64DSM>; 16004eeddc0SDimitry Andricdef : PatGpr<int_riscv_aes64im, AES64IM>; 16104eeddc0SDimitry Andric} // Predicates = [HasStdExtZknd, IsRV64] 16204eeddc0SDimitry Andric 16304eeddc0SDimitry Andriclet Predicates = [HasStdExtZkndOrZkne, IsRV64] in { 16404eeddc0SDimitry Andricdef : PatGprGpr<int_riscv_aes64ks2, AES64KS2>; 16506c3fb27SDimitry Andricdef : Pat<(int_riscv_aes64ks1i GPR:$rs1, rnum:$rnum), 16604eeddc0SDimitry Andric (AES64KS1I GPR:$rs1, rnum:$rnum)>; 16704eeddc0SDimitry Andric} // Predicates = [HasStdExtZkndOrZkne, IsRV64] 16804eeddc0SDimitry Andric 16904eeddc0SDimitry Andric// Zkne 17004eeddc0SDimitry Andriclet Predicates = [HasStdExtZkne, IsRV32] in { 17104eeddc0SDimitry Andricdef : PatGprGprByteSelect<int_riscv_aes32esi, AES32ESI>; 17204eeddc0SDimitry Andricdef : PatGprGprByteSelect<int_riscv_aes32esmi, AES32ESMI>; 17304eeddc0SDimitry Andric} // Predicates = [HasStdExtZkne, IsRV32] 17404eeddc0SDimitry Andric 17504eeddc0SDimitry Andriclet Predicates = [HasStdExtZkne, IsRV64] in { 17604eeddc0SDimitry Andricdef : PatGprGpr<int_riscv_aes64es, AES64ES>; 17704eeddc0SDimitry Andricdef : PatGprGpr<int_riscv_aes64esm, AES64ESM>; 17804eeddc0SDimitry Andric} // Predicates = [HasStdExtZkne, IsRV64] 17904eeddc0SDimitry Andric 18004eeddc0SDimitry Andric// Zknh 18104eeddc0SDimitry Andriclet Predicates = [HasStdExtZknh] in { 18206c3fb27SDimitry Andricdef : PatGpr<riscv_sha256sig0, SHA256SIG0>; 18306c3fb27SDimitry Andricdef : PatGpr<riscv_sha256sig1, SHA256SIG1>; 18406c3fb27SDimitry Andricdef : PatGpr<riscv_sha256sum0, SHA256SUM0>; 18506c3fb27SDimitry Andricdef : PatGpr<riscv_sha256sum1, SHA256SUM1>; 18604eeddc0SDimitry Andric} // Predicates = [HasStdExtZknh] 18704eeddc0SDimitry Andric 18804eeddc0SDimitry Andriclet Predicates = [HasStdExtZknh, IsRV32] in { 18904eeddc0SDimitry Andricdef : PatGprGpr<int_riscv_sha512sig0l, SHA512SIG0L>; 19004eeddc0SDimitry Andricdef : PatGprGpr<int_riscv_sha512sig0h, SHA512SIG0H>; 19104eeddc0SDimitry Andricdef : PatGprGpr<int_riscv_sha512sig1l, SHA512SIG1L>; 19204eeddc0SDimitry Andricdef : PatGprGpr<int_riscv_sha512sig1h, SHA512SIG1H>; 19304eeddc0SDimitry Andricdef : PatGprGpr<int_riscv_sha512sum0r, SHA512SUM0R>; 19404eeddc0SDimitry Andricdef : PatGprGpr<int_riscv_sha512sum1r, SHA512SUM1R>; 19504eeddc0SDimitry Andric} // Predicates = [HasStdExtZknh, IsRV32] 19604eeddc0SDimitry Andric 19704eeddc0SDimitry Andriclet Predicates = [HasStdExtZknh, IsRV64] in { 19804eeddc0SDimitry Andricdef : PatGpr<int_riscv_sha512sig0, SHA512SIG0>; 19904eeddc0SDimitry Andricdef : PatGpr<int_riscv_sha512sig1, SHA512SIG1>; 20004eeddc0SDimitry Andricdef : PatGpr<int_riscv_sha512sum0, SHA512SUM0>; 20104eeddc0SDimitry Andricdef : PatGpr<int_riscv_sha512sum1, SHA512SUM1>; 20204eeddc0SDimitry Andric} // Predicates = [HasStdExtZknh, IsRV64] 20304eeddc0SDimitry Andric 20404eeddc0SDimitry Andric// Zksed 20504eeddc0SDimitry Andriclet Predicates = [HasStdExtZksed] in { 20606c3fb27SDimitry Andricdef : PatGprGprByteSelect<riscv_sm4ks, SM4KS>; 20706c3fb27SDimitry Andricdef : PatGprGprByteSelect<riscv_sm4ed, SM4ED>; 20804eeddc0SDimitry Andric} // Predicates = [HasStdExtZksed] 20904eeddc0SDimitry Andric 21004eeddc0SDimitry Andric// Zksh 21104eeddc0SDimitry Andriclet Predicates = [HasStdExtZksh] in { 21206c3fb27SDimitry Andricdef : PatGpr<riscv_sm3p0, SM3P0>; 21306c3fb27SDimitry Andricdef : PatGpr<riscv_sm3p1, SM3P1>; 21404eeddc0SDimitry Andric} // Predicates = [HasStdExtZksh] 215