diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp --- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp +++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp @@ -503,6 +503,7 @@ return false; return (isRV64() && isUInt<5>(Imm)) || isUInt<4>(Imm); } + bool isUImm2() const { int64_t Imm; RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None; @@ -520,6 +521,7 @@ bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK); return IsConstantImm && isUInt<4>(Imm) && VK == RISCVMCExpr::VK_RISCV_None; } + bool isUImm5() const { int64_t Imm; RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None; @@ -1062,7 +1064,7 @@ return generateImmOutOfRangeError(Operands, ErrorInfo, 0, (1 << 4) - 1); case Match_InvalidUImm2: return generateImmOutOfRangeError(Operands, ErrorInfo, 0, (1 << 2) - 1); - case Match_InvalidUImm4: + case Match_InvalidUImm4: return generateImmOutOfRangeError(Operands, ErrorInfo, 0, (1 << 4) - 1); case Match_InvalidUImm5: return generateImmOutOfRangeError(Operands, ErrorInfo, 0, (1 << 5) - 1); diff --git a/llvm/lib/Target/RISCV/RISCV.td b/llvm/lib/Target/RISCV/RISCV.td --- a/llvm/lib/Target/RISCV/RISCV.td +++ b/llvm/lib/Target/RISCV/RISCV.td @@ -193,7 +193,6 @@ def HasStdExtK : Predicate<"Subtarget->hasStdExtK()">, AssemblerPredicate<(all_of FeatureStdExtK), "'K' (Scalar Cryptography Instructions)">; - def Feature64Bit : SubtargetFeature<"64bit", "HasRV64", "true", "Implements RV64">; def IsRV64 : Predicate<"Subtarget->is64Bit()">, diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.td b/llvm/lib/Target/RISCV/RISCVInstrInfo.td --- a/llvm/lib/Target/RISCV/RISCVInstrInfo.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.td @@ -128,6 +128,21 @@ let OperandNamespace = "RISCVOp"; } +def uimm2 : Operand, ImmLeaf(Imm);}]> { + let ParserMatchClass = UImmAsmOperand<2>; + let DecoderMethod = "decodeUImmOperand<2>"; + let OperandType = "OPERAND_UIMM2"; + let OperandNamespace = "RISCVOp"; +} + +def uimm4 : Operand, ImmLeaf(Imm);}]> { + let ParserMatchClass = UImmAsmOperand<4>; + let EncoderMethod = "getImmOpValue"; + let DecoderMethod = "decodeUImmOperand<4>"; + let OperandType = "OPERAND_UIMM4"; + let OperandNamespace = "RISCVOp"; +} + def uimm5 : Operand, ImmLeaf(Imm);}]> { let ParserMatchClass = UImmAsmOperand<5>; let DecoderMethod = "decodeUImmOperand<5>"; diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoK.td b/llvm/lib/Target/RISCV/RISCVInstrInfoK.td --- a/llvm/lib/Target/RISCV/RISCVInstrInfoK.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoK.td @@ -6,30 +6,11 @@ // //===----------------------------------------------------------------------===// /// -/// This file describes the RISC-K instructions from the standard 'K' +/// This file describes the RISC-V instructions from the standard 'K' /// scalar cryptography extension, version 0.8.1. /// //===----------------------------------------------------------------------===// - -//===----------------------------------------------------------------------===// -// Operand and SDNode transformation definitions. -//===----------------------------------------------------------------------===// -def uimm2 : Operand, ImmLeaf(Imm);}]> { - let ParserMatchClass = UImmAsmOperand<2>; - let DecoderMethod = "decodeUImmOperand<2>"; - let OperandType = "OPERAND_UIMM2"; - let OperandNamespace = "RISCVOp"; -} - -def rcon : Operand, ImmLeaf(Imm);}]> { - let ParserMatchClass = UImmAsmOperand<4>; - let EncoderMethod = "getImmOpValue"; - let DecoderMethod = "decodeUImmOperand<4>"; - let OperandType = "OPERAND_UIMM4"; - let OperandNamespace = "RISCVOp"; -} - //===----------------------------------------------------------------------===// // Instruction class templates //===----------------------------------------------------------------------===// @@ -60,7 +41,7 @@ } // op rd rs1 rcon class RVKUnary_rcon funct7, bits<3> funct3, string opcodestr> - : RVInstI { bits<4> rcon; @@ -72,7 +53,6 @@ } // hasSideEffects = 0, mayLoad = 0, mayStore = 0 let Predicates = [HasStdExtK] in { - // RVKUnary def SHA256SUM0 : RVKUnary<0b0001000, 0b00000, 0b001, "sha256sum0">, Sched<[]>; def SHA256SUM1 : RVKUnary<0b0001000, 0b00001, 0b001, "sha256sum1">, @@ -85,20 +65,19 @@ Sched<[]>; def SM3P1 : RVKUnary<0b0001000, 0b01001, 0b001, "sm3p1">, Sched<[]>; - //RVKByteSelect + def SM4ED : RVKByteSelect<0b11000, "sm4ed">, Sched<[]>; def SM4KS : RVKByteSelect<0b11010, "sm4ks">, Sched<[]>; - // Pseudo Instructions - def GETNOISE : InstAlias<"getnoise $rd", (CSRRS GPR:$rd, MNOISE.Encoding, X0)>, + // Assembler Pseudo Instructions + def : InstAlias<"getnoise $rd", (CSRRS GPR:$rd, MNOISE.Encoding, X0)>, Sched<[]>; - def POLLENTROPY: InstAlias<"pollentropy $rd", (CSRRS GPR:$rd, MENTROPY.Encoding, X0)>, + def : InstAlias<"pollentropy $rd", (CSRRS GPR:$rd, MENTROPY.Encoding, X0)>, Sched<[]>; } // Predicates = [HasStdExtK] let Predicates = [HasStdExtK, IsRV32] in { - // RVKBinary def SHA512SUM0R : RVKBinary<0b0101000, 0b000, "sha512sum0r">, Sched<[]>; def SHA512SUM1R : RVKBinary<0b0101001, 0b000, "sha512sum1r">, @@ -111,7 +90,7 @@ Sched<[]>; def SHA512SIG1H : RVKBinary<0b0101111, 0b000, "sha512sig1h">, Sched<[]>; - // RVKByteSelect + def AES32ESMI : RVKByteSelect<0b11011, "aes32esmi">, Sched<[]>; def AES32ESI : RVKByteSelect<0b11001, "aes32esi">, @@ -123,7 +102,6 @@ } // Predicates = [HasStdExtK, IsRV32] let Predicates = [HasStdExtK, IsRV64] in { - // RVK Unary def SHA512SUM0 : RVKUnary<0b0001000, 0b00100, 0b001, "sha512sum0">, Sched<[]>; def SHA512SUM1 : RVKUnary<0b0001000, 0b00101, 0b001, "sha512sum1">, @@ -134,7 +112,7 @@ Sched<[]>; def AES64IM : RVKUnary<0b0011000, 0b00000, 0b001, "aes64im">, Sched<[]>; - // RVK Binary + def AES64KS2 : RVKBinary<0b0111111, 0b000, "aes64ks2">, Sched<[]>; def AES64ESM : RVKBinary<0b0011011, 0b000, "aes64esm">, @@ -145,7 +123,7 @@ Sched<[]>; def AES64DS : RVKBinary<0b0011101, 0b000, "aes64ds">, Sched<[]>; - // RVKUnary_rcon + def AES64KS1I : RVKUnary_rcon<0b0011000, 0b001, "aes64ks1i">, Sched<[]>; -} // Predicates = [HasStdExtK, IsRV64] \ No newline at end of file +} // Predicates = [HasStdExtK, IsRV64] diff --git a/llvm/lib/Target/RISCV/RISCVSubtarget.h b/llvm/lib/Target/RISCV/RISCVSubtarget.h --- a/llvm/lib/Target/RISCV/RISCVSubtarget.h +++ b/llvm/lib/Target/RISCV/RISCVSubtarget.h @@ -52,10 +52,10 @@ bool HasStdExtZbt = false; bool HasStdExtZbproposedc = false; bool HasStdExtV = false; - bool HasStdExtK = false; bool HasStdExtZvlsseg = false; bool HasStdExtZvamo = false; bool HasStdExtZfh = false; + bool HasStdExtK = false; bool HasRV64 = false; bool IsRV32E = false; bool EnableLinkerRelax = false; @@ -120,10 +120,10 @@ bool hasStdExtZbt() const { return HasStdExtZbt; } bool hasStdExtZbproposedc() const { return HasStdExtZbproposedc; } bool hasStdExtV() const { return HasStdExtV; } - bool hasStdExtK() const { return HasStdExtK; } bool hasStdExtZvlsseg() const { return HasStdExtZvlsseg; } bool hasStdExtZvamo() const { return HasStdExtZvamo; } bool hasStdExtZfh() const { return HasStdExtZfh; } + bool hasStdExtK() const { return HasStdExtK; } bool is64Bit() const { return HasRV64; } bool isRV32E() const { return IsRV32E; } bool enableLinkerRelax() const { return EnableLinkerRelax; } diff --git a/llvm/lib/Target/RISCV/RISCVSystemOperands.td b/llvm/lib/Target/RISCV/RISCVSystemOperands.td --- a/llvm/lib/Target/RISCV/RISCVSystemOperands.td +++ b/llvm/lib/Target/RISCV/RISCVSystemOperands.td @@ -374,7 +374,7 @@ def : SysReg<"vlenb", 0xC22>; //===----------------------------------------------- -// K ext CSRs +// Machine Scalar Cryptography CSRs //===----------------------------------------------- def MENTROPY : SysReg<"mentropy", 0xF15>; def MNOISE : SysReg<"mnoise", 0x7A9>; diff --git a/llvm/test/MC/RISCV/rvk/rv32k.s b/llvm/test/MC/RISCV/rvk/rv32k.s --- a/llvm/test/MC/RISCV/rvk/rv32k.s +++ b/llvm/test/MC/RISCV/rvk/rv32k.s @@ -1,13 +1,10 @@ # RUN: llvm-mc -triple=riscv32 -show-encoding --mattr=+experimental-k %s \ # RUN: | FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST - # RUN: not llvm-mc -triple=riscv32 -show-encoding %s 2>&1 \ # RUN: | FileCheck %s --check-prefix=CHECK-ERROR - # RUN: llvm-mc -triple=riscv32 -filetype=obj --mattr=+experimental-k %s \ # RUN: | llvm-objdump -d --mattr=+experimental-k - \ # RUN: | FileCheck %s --check-prefix=CHECK-INST - # RUN: llvm-mc -triple=riscv32 -filetype=obj --mattr=+experimental-k %s \ # RUN: | llvm-objdump -d - | FileCheck %s --check-prefix=CHECK-UNKNOWN @@ -143,4 +140,4 @@ # CHECK-INST: aes32dsi t0, a2, 3 # CHECK-ENCODING: [0x33,0x80,0xc2,0xfa] # CHECK-ERROR: instruction requires the following: 'K' (Scalar Cryptography Instructions) -# CHECK-UNKNOWN: 33 80 c2 fa \ No newline at end of file +# CHECK-UNKNOWN: 33 80 c2 fa diff --git a/llvm/test/MC/RISCV/rvk/rv64k.s b/llvm/test/MC/RISCV/rvk/rv64k.s --- a/llvm/test/MC/RISCV/rvk/rv64k.s +++ b/llvm/test/MC/RISCV/rvk/rv64k.s @@ -1,13 +1,10 @@ # RUN: llvm-mc -triple=riscv64 -show-encoding --mattr=+experimental-k %s \ # RUN: | FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST - # RUN: not llvm-mc -triple=riscv64 -show-encoding %s 2>&1 \ # RUN: | FileCheck %s --check-prefix=CHECK-ERROR - # RUN: llvm-mc -triple=riscv64 -filetype=obj --mattr=+experimental-k %s \ # RUN: | llvm-objdump -d --mattr=+experimental-k - \ # RUN: | FileCheck %s --check-prefix=CHECK-INST - # RUN: llvm-mc -triple=riscv64 -filetype=obj --mattr=+experimental-k %s \ # RUN: | llvm-objdump -d - | FileCheck %s --check-prefix=CHECK-UNKNOWN @@ -125,4 +122,4 @@ # CHECK-INST: aes64ks1i a0, a1, 5 # CHECK-ENCODING: [0x13,0x95,0x55,0x31] # CHECK-ERROR: instruction requires the following: 'K' (Scalar Cryptography Instructions) -# CHECK-UNKNOWN: 13 95 55 31 \ No newline at end of file +# CHECK-UNKNOWN: 13 95 55 31