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 @@ -504,6 +504,24 @@ return (isRV64() && isUInt<5>(Imm)) || isUInt<4>(Imm); } + bool isUImm2() const { + int64_t Imm; + RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None; + if (!isImm()) + return false; + bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK); + return IsConstantImm && isUInt<2>(Imm) && VK == RISCVMCExpr::VK_RISCV_None; + } + + bool isUImm4() const { + int64_t Imm; + RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None; + if (!isImm()) + return false; + 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; @@ -1044,6 +1062,10 @@ if (isRV64()) return generateImmOutOfRangeError(Operands, ErrorInfo, 0, (1 << 5) - 1); return generateImmOutOfRangeError(Operands, ErrorInfo, 0, (1 << 4) - 1); + case Match_InvalidUImm2: + return generateImmOutOfRangeError(Operands, ErrorInfo, 0, (1 << 2) - 1); + case Match_InvalidUImm4: + return generateImmOutOfRangeError(Operands, ErrorInfo, 0, (1 << 4) - 1); case Match_InvalidUImm5: return generateImmOutOfRangeError(Operands, ErrorInfo, 0, (1 << 5) - 1); case Match_InvalidSImm5: diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h @@ -111,7 +111,8 @@ namespace RISCVOp { enum OperandType : unsigned { OPERAND_FIRST_RISCV_IMM = MCOI::OPERAND_FIRST_TARGET, - OPERAND_UIMM4 = OPERAND_FIRST_RISCV_IMM, + OPERAND_UIMM2 = OPERAND_FIRST_RISCV_IMM, + OPERAND_UIMM4, OPERAND_UIMM5, OPERAND_UIMM12, OPERAND_SIMM12, 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 @@ -187,7 +187,12 @@ def HasStdExtZvamo : Predicate<"Subtarget->hasStdExtZvamo()">, AssemblerPredicate<(all_of FeatureExtZvamo), "'Zvamo'(Vector AMO Operations)">; - +def FeatureStdExtK + : SubtargetFeature<"experimental-k", "HasStdExtK", "true", + "'K' (Scalar Cryptography Instructions)">; +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>"; @@ -1260,4 +1275,5 @@ include "RISCVInstrInfoC.td" include "RISCVInstrInfoB.td" include "RISCVInstrInfoV.td" +include "RISCVInstrInfoK.td" include "RISCVInstrInfoZfh.td" diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoK.td b/llvm/lib/Target/RISCV/RISCVInstrInfoK.td new file mode 100644 --- /dev/null +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoK.td @@ -0,0 +1,102 @@ +//===-- RISCVInstrInfoK.td - RISC-V 'K' instructions -------*- tablegen -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +/// +/// This file describes the RISC-V instructions from the standard 'K' +/// scalar cryptography extension, version 0.8.1. +/// +//===----------------------------------------------------------------------===// + +//===----------------------------------------------------------------------===// +// Instruction class templates +//===----------------------------------------------------------------------===// + +let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in + class RVKUnary funct7, bits<5> funct5, bits<3> funct3, string opcodestr> + : RVInstR{ + let Inst{24-20} = funct5; + } + +let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in + class RVKBinary funct7, bits<3> funct3, string opcodestr> + : RVInstR; + +let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in + class RVKByteSelect funct5, string opcodestr> + : RVInstS<0b000, OPC_OP, (outs GPR:$rt), (ins GPR:$rs2, uimm2:$bs), + opcodestr, "$rt, $rs2, $bs">{ + bits<2> bs; + bits<5> rt; + + let Inst{31-30}=bs; + let Inst{29-25}=funct5; + let Inst{19-15}=rt; + let Inst{11-7}=0b00000; + } + +let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in + class RVKUnary_rcon funct7, bits<3> funct3, string opcodestr> + : RVInstI { + bits<4> rcon; + + let Inst{31-25} = funct7; + let Inst{24} = 1; + let Inst{23-20} = rcon; + } + +//===----------------------------------------------------------------------===// +// Instructions +//===----------------------------------------------------------------------===// + +let Predicates = [HasStdExtK] in { + def SHA256SUM0 : RVKUnary<0b0001000, 0b00000, 0b001, "sha256sum0">; + def SHA256SUM1 : RVKUnary<0b0001000, 0b00001, 0b001, "sha256sum1">; + def SHA256SIG0 : RVKUnary<0b0001000, 0b00010, 0b001, "sha256sig0">; + def SHA256SIG1 : RVKUnary<0b0001000, 0b00011, 0b001, "sha256sig1">; + + def SM3P0 : RVKUnary<0b0001000, 0b01000, 0b001, "sm3p0">; + def SM3P1 : RVKUnary<0b0001000, 0b01001, 0b001, "sm3p1">; + def SM4ED : RVKByteSelect<0b11000, "sm4ed">; + def SM4KS : RVKByteSelect<0b11010, "sm4ks">; + + // Assembler Pseudo Instructions + def : InstAlias<"getnoise $rd", (CSRRS GPR:$rd, MNOISE.Encoding, X0)>; + def : InstAlias<"pollentropy $rd", (CSRRS GPR:$rd, MENTROPY.Encoding, X0)>; +} // Predicates = [HasStdExtK] + +let Predicates = [HasStdExtK, IsRV32] in { + def SHA512SUM0R : RVKBinary<0b0101000, 0b000, "sha512sum0r">; + def SHA512SUM1R : RVKBinary<0b0101001, 0b000, "sha512sum1r">; + def SHA512SIG0L : RVKBinary<0b0101010, 0b000, "sha512sig0l">; + def SHA512SIG0H : RVKBinary<0b0101110, 0b000, "sha512sig0h">; + def SHA512SIG1L : RVKBinary<0b0101011, 0b000, "sha512sig1l">; + def SHA512SIG1H : RVKBinary<0b0101111, 0b000, "sha512sig1h">; + + def AES32ESMI : RVKByteSelect<0b11011, "aes32esmi">; + def AES32DSMI : RVKByteSelect<0b11111, "aes32dsmi">; + def AES32ESI : RVKByteSelect<0b11001, "aes32esi">; + def AES32DSI : RVKByteSelect<0b11101, "aes32dsi">; +} // Predicates = [HasStdExtK, IsRV32] + +let Predicates = [HasStdExtK, IsRV64] in { + def SHA512SUM0 : RVKUnary<0b0001000, 0b00100, 0b001, "sha512sum0">; + def SHA512SUM1 : RVKUnary<0b0001000, 0b00101, 0b001, "sha512sum1">; + def SHA512SIG0 : RVKUnary<0b0001000, 0b00110, 0b001, "sha512sig0">; + def SHA512SIG1 : RVKUnary<0b0001000, 0b00111, 0b001, "sha512sig1">; + + def AES64IM : RVKUnary<0b0011000, 0b00000, 0b001, "aes64im">; + def AES64KS2 : RVKBinary<0b0111111, 0b000, "aes64ks2">; + def AES64ESM : RVKBinary<0b0011011, 0b000, "aes64esm">; + def AES64DSM : RVKBinary<0b0011111, 0b000, "aes64dsm">; + + def AES64ES : RVKBinary<0b0011001, 0b000, "aes64es">; + def AES64DS : RVKBinary<0b0011101, 0b000, "aes64ds">; + + def AES64KS1I : RVKUnary_rcon<0b0011000, 0b001, "aes64ks1i">; +} // Predicates = [HasStdExtK, IsRV64] diff --git a/llvm/lib/Target/RISCV/RISCVSchedRocket.td b/llvm/lib/Target/RISCV/RISCVSchedRocket.td --- a/llvm/lib/Target/RISCV/RISCVSchedRocket.td +++ b/llvm/lib/Target/RISCV/RISCVSchedRocket.td @@ -16,7 +16,7 @@ let IssueWidth = 1; // 1 micro-op is dispatched per cycle. let LoadLatency = 3; let MispredictPenalty = 3; - let UnsupportedFeatures = [HasStdExtV, HasStdExtZvamo, HasStdExtZvlsseg]; + let UnsupportedFeatures = [HasStdExtV, HasStdExtZvamo, HasStdExtZvlsseg, HasStdExtK]; } //===----------------------------------------------------------------------===// diff --git a/llvm/lib/Target/RISCV/RISCVSchedSiFive7.td b/llvm/lib/Target/RISCV/RISCVSchedSiFive7.td --- a/llvm/lib/Target/RISCV/RISCVSchedSiFive7.td +++ b/llvm/lib/Target/RISCV/RISCVSchedSiFive7.td @@ -15,7 +15,7 @@ let LoadLatency = 3; let MispredictPenalty = 3; let CompleteModel = 0; - let UnsupportedFeatures = [HasStdExtV, HasStdExtZvamo, HasStdExtZvlsseg]; + let UnsupportedFeatures = [HasStdExtV, HasStdExtZvamo, HasStdExtZvlsseg, HasStdExtK]; } // The SiFive7 microarchitecure has two pipelines: A and B. 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 @@ -55,6 +55,7 @@ bool HasStdExtZvlsseg = false; bool HasStdExtZvamo = false; bool HasStdExtZfh = false; + bool HasStdExtK = false; bool HasRV64 = false; bool IsRV32E = false; bool EnableLinkerRelax = false; @@ -122,6 +123,7 @@ 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 @@ -372,3 +372,9 @@ def : SysReg<"vl", 0xC20>; def : SysReg<"vtype", 0xC21>; def : SysReg<"vlenb", 0xC22>; + +//===----------------------------------------------- +// Machine Scalar Cryptography CSRs +//===----------------------------------------------- +def MENTROPY : SysReg<"mentropy", 0xF15>; +def MNOISE : SysReg<"mnoise", 0x7A9>; diff --git a/llvm/test/MC/RISCV/rvk/rv32k-only-valid.s b/llvm/test/MC/RISCV/rvk/rv32k-only-valid.s new file mode 100644 --- /dev/null +++ b/llvm/test/MC/RISCV/rvk/rv32k-only-valid.s @@ -0,0 +1,93 @@ +# 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 + +# CHECK-INST: sha512sum0r a0, a1, a2 +# CHECK-ENCODING: [0x33,0x85,0xc5,0x50] +# CHECK-ERROR: instruction requires the following: 'K' (Scalar Cryptography Instructions) +# CHECK-UNKNOWN: 33 85 c5 50 +sha512sum0r a0, a1, a2 + +# CHECK-INST: sha512sum1r a0, a1, a2 +# CHECK-ENCODING: [0x33,0x85,0xc5,0x52] +# CHECK-ERROR: instruction requires the following: 'K' (Scalar Cryptography Instructions) +# CHECK-UNKNOWN: 33 85 c5 52 +sha512sum1r a0, a1, a2 + +# CHECK-INST: sha512sig0l a0, a1, a2 +# CHECK-ENCODING: [0x33,0x85,0xc5,0x54] +# CHECK-ERROR: instruction requires the following: 'K' (Scalar Cryptography Instructions) +# CHECK-UNKNOWN: 33 85 c5 54 +sha512sig0l a0, a1, a2 + +# CHECK-INST: sha512sig0h a0, a1, a2 +# CHECK-ENCODING: [0x33,0x85,0xc5,0x5c] +# CHECK-ERROR: instruction requires the following: 'K' (Scalar Cryptography Instructions) +# CHECK-UNKNOWN: 33 85 c5 5c +sha512sig0h a0, a1, a2 + +# CHECK-INST: sha512sig1l a0, a1, a2 +# CHECK-ENCODING: [0x33,0x85,0xc5,0x56] +# CHECK-ERROR: instruction requires the following: 'K' (Scalar Cryptography Instructions) +# CHECK-UNKNOWN: 33 85 c5 56 +sha512sig1l a0, a1, a2 + +# CHECK-INST: sha512sig1h a0, a1, a2 +# CHECK-ENCODING: [0x33,0x85,0xc5,0x5e] +# CHECK-ERROR: instruction requires the following: 'K' (Scalar Cryptography Instructions) +# CHECK-UNKNOWN: 33 85 c5 5e +sha512sig1h a0, a1, a2 + +# CHECK-INST: csrr a0, mnoise +# CHECK-ENCODING: [0x73,0x25,0x90,0x7a] +# CHECK-ERROR: instruction requires the following: 'K' (Scalar Cryptography Instructions) +# CHECK-UNKNOWN: 73 25 90 7a csrr a0, mnoise +getnoise a0 + +# CHECK-INST: csrr a0, mentropy +# CHECK-ENCODING: [0x73,0x25,0x50,0xf1] +# CHECK-ERROR: instruction requires the following: 'K' (Scalar Cryptography Instructions) +# CHECK-UNKNOWN: 73 25 50 f1 csrr a0, mentropy +pollentropy a0 + +# CHECK-INST: sm4ed t0, a2, 3 +# CHECK-ENCODING: [0x33,0x80,0xc2,0xf0] +# CHECK-ERROR: instruction requires the following: 'K' (Scalar Cryptography Instructions) +# CHECK-UNKNOWN: 33 80 c2 f0 +sm4ed t0, a2, 3 + +# CHECK-INST: sm4ks t0, a2, 3 +# CHECK-ENCODING: [0x33,0x80,0xc2,0xf4] +# CHECK-ERROR: instruction requires the following: 'K' (Scalar Cryptography Instructions) +# CHECK-UNKNOWN: 33 80 c2 f4 +sm4ks t0, a2, 3 + +# CHECK-INST: aes32esmi t0, a2, 3 +# CHECK-ENCODING: [0x33,0x80,0xc2,0xf6] +# CHECK-ERROR: instruction requires the following: 'K' (Scalar Cryptography Instructions) +# CHECK-UNKNOWN: 33 80 c2 f6 +aes32esmi t0, a2, 3 + +# CHECK-INST: aes32esi t0, a2, 3 +# CHECK-ENCODING: [0x33,0x80,0xc2,0xf2] +# CHECK-ERROR: instruction requires the following: 'K' (Scalar Cryptography Instructions) +# CHECK-UNKNOWN: 33 80 c2 f2 +aes32esi t0, a2, 3 + +# CHECK-INST: aes32dsmi t0, a2, 3 +# CHECK-ENCODING: [0x33,0x80,0xc2,0xfe] +# CHECK-ERROR: instruction requires the following: 'K' (Scalar Cryptography Instructions) +# CHECK-UNKNOWN: 33 80 c2 fe +aes32dsmi t0, a2, 3 + +# 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 +aes32dsi t0, a2, 3 diff --git a/llvm/test/MC/RISCV/rvk/rv32k-valid.s b/llvm/test/MC/RISCV/rvk/rv32k-valid.s new file mode 100644 --- /dev/null +++ b/llvm/test/MC/RISCV/rvk/rv32k-valid.s @@ -0,0 +1,66 @@ +# 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 +# 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 + +# CHECK-INST: sha256sum0 a0, a1 +# CHECK-ENCODING: [0x13,0x95,0x05,0x10] +# CHECK-ERROR: instruction requires the following: 'K' (Scalar Cryptography Instructions) +# CHECK-UNKNOWN: 13 95 05 10 +sha256sum0 a0, a1 + +# CHECK-INST: sha256sum1 a0, a1 +# CHECK-ENCODING: [0x13,0x95,0x15,0x10] +# CHECK-ERROR: instruction requires the following: 'K' (Scalar Cryptography Instructions) +# CHECK-UNKNOWN: 13 95 15 10 +sha256sum1 a0, a1 + +# CHECK-INST: sha256sig0 a0, a1 +# CHECK-ENCODING: [0x13,0x95,0x25,0x10] +# CHECK-ERROR: instruction requires the following: 'K' (Scalar Cryptography Instructions) +# CHECK-UNKNOWN: 13 95 25 10 +sha256sig0 a0, a1 + +# CHECK-INST: sha256sig1 a0, a1 +# CHECK-ENCODING: [0x13,0x95,0x35,0x10] +# CHECK-ERROR: instruction requires the following: 'K' (Scalar Cryptography Instructions) +# CHECK-UNKNOWN: 13 95 35 10 +sha256sig1 a0, a1 + +# CHECK-INST: sm3p0 a0, a1 +# CHECK-ENCODING: [0x13,0x95,0x85,0x10] +# CHECK-ERROR: instruction requires the following: 'K' (Scalar Cryptography Instructions) +# CHECK-UNKNOWN: 13 95 85 10 +sm3p0 a0, a1 + +# CHECK-INST: sm3p1 a0, a1 +# CHECK-ENCODING: [0x13,0x95,0x95,0x10] +# CHECK-ERROR: instruction requires the following: 'K' (Scalar Cryptography Instructions) +# CHECK-UNKNOWN: 13 95 95 10 +sm3p1 a0, a1 + +# CHECK-INST: csrr a0, mnoise +# CHECK-ENCODING: [0x73,0x25,0x90,0x7a] +# CHECK-ERROR: instruction requires the following: 'K' (Scalar Cryptography Instructions) +# CHECK-UNKNOWN: 73 25 90 7a +getnoise a0 + +# CHECK-INST: csrr a0, mentropy +# CHECK-ENCODING: [0x73,0x25,0x50,0xf1] +# CHECK-ERROR: instruction requires the following: 'K' (Scalar Cryptography Instructions) +# CHECK-UNKNOWN: 73 25 50 f1 +pollentropy a0 \ No newline at end of file diff --git a/llvm/test/MC/RISCV/rvk/rv64k-valid.s b/llvm/test/MC/RISCV/rvk/rv64k-valid.s new file mode 100644 --- /dev/null +++ b/llvm/test/MC/RISCV/rvk/rv64k-valid.s @@ -0,0 +1,75 @@ +# 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 + +# CHECK-INST: sha512sum0 a0, a1 +# CHECK-ENCODING: [0x13,0x95,0x45,0x10] +# CHECK-ERROR: instruction requires the following: 'K' (Scalar Cryptography Instructions) +# CHECK-UNKNOWN: 13 95 45 10 +sha512sum0 a0, a1 + +# CHECK-INST: sha512sum1 a0, a1 +# CHECK-ENCODING: [0x13,0x95,0x55,0x10] +# CHECK-ERROR: instruction requires the following: 'K' (Scalar Cryptography Instructions) +# CHECK-UNKNOWN: 13 95 55 10 +sha512sum1 a0, a1 + +# CHECK-INST: sha512sig0 a0, a1 +# CHECK-ENCODING: [0x13,0x95,0x65,0x10] +# CHECK-ERROR: instruction requires the following: 'K' (Scalar Cryptography Instructions) +# CHECK-UNKNOWN: 13 95 65 10 +sha512sig0 a0, a1 + +# CHECK-INST: sha512sig1 a0, a1 +# CHECK-ENCODING: [0x13,0x95,0x75,0x10] +# CHECK-ERROR: instruction requires the following: 'K' (Scalar Cryptography Instructions) +# CHECK-UNKNOWN: 13 95 75 10 +sha512sig1 a0, a1 + +# CHECK-INST: aes64im a0, a1 +# CHECK-ENCODING: [0x13,0x95,0x05,0x30] +# CHECK-ERROR: instruction requires the following: 'K' (Scalar Cryptography Instructions) +# CHECK-UNKNOWN: 13 95 05 30 +aes64im a0, a1 + +# CHECK-INST: aes64ks2 a0, a1, a2 +# CHECK-ENCODING: [0x33,0x85,0xc5,0x7e] +# CHECK-ERROR: instruction requires the following: 'K' (Scalar Cryptography Instructions) +# CHECK-UNKNOWN: 33 85 c5 7e +aes64ks2 a0, a1, a2 + +# CHECK-INST: aes64esm a0, a1, a2 +# CHECK-ENCODING: [0x33,0x85,0xc5,0x36] +# CHECK-ERROR: instruction requires the following: 'K' (Scalar Cryptography Instructions) +# CHECK-UNKNOWN: 33 85 c5 36 +aes64esm a0, a1, a2 + +# CHECK-INST: aes64es a0, a1, a2 +# CHECK-ENCODING: [0x33,0x85,0xc5,0x32] +# CHECK-ERROR: instruction requires the following: 'K' (Scalar Cryptography Instructions) +# CHECK-UNKNOWN: 33 85 c5 32 +aes64es a0, a1, a2 + +# CHECK-INST: aes64dsm a0, a1, a2 +# CHECK-ENCODING: [0x33,0x85,0xc5,0x3e] +# CHECK-ERROR: instruction requires the following: 'K' (Scalar Cryptography Instructions) +# CHECK-UNKNOWN: 33 85 c5 3e +aes64dsm a0, a1, a2 + +# CHECK-INST: aes64es a0, a1, a2 +# CHECK-ENCODING: [0x33,0x85,0xc5,0x32] +# CHECK-ERROR: instruction requires the following: 'K' (Scalar Cryptography Instructions) +# CHECK-UNKNOWN: 33 85 c5 32 +aes64es a0, a1, a2 + +# 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 +aes64ks1i a0, a1, 5 diff --git a/llvm/test/MC/RISCV/rvk/rvk32-invalid.s b/llvm/test/MC/RISCV/rvk/rvk32-invalid.s new file mode 100644 --- /dev/null +++ b/llvm/test/MC/RISCV/rvk/rvk32-invalid.s @@ -0,0 +1,8 @@ +# RUN: not llvm-mc -triple=riscv32 -mattr=+experimental-k < %s 2>&1 \ +# RUN: | FileCheck %s --check-prefix=CHECK-ERROR + +sm4ed t0, a2, 8 +# CHECK-ERROR: immediate must be an integer in the range [0, 3] + +sm4ks t0, a2, 8 +# CHECK-ERROR: immediate must be an integer in the range [0, 3] diff --git a/llvm/test/MC/RISCV/rvk/rvk32-only-invalid.s b/llvm/test/MC/RISCV/rvk/rvk32-only-invalid.s new file mode 100644 --- /dev/null +++ b/llvm/test/MC/RISCV/rvk/rvk32-only-invalid.s @@ -0,0 +1,14 @@ +# RUN: not llvm-mc -triple=riscv32 -mattr=+experimental-k < %s 2>&1 \ +# RUN: | FileCheck %s --check-prefix=CHECK-ERROR + +aes32esmi t0, a2, 8 +# CHECK-ERROR: immediate must be an integer in the range [0, 3] + +aes32esi t0, a2, 8 +# CHECK-ERROR: immediate must be an integer in the range [0, 3] + +aes32dsmi t0, a2, 8 +# CHECK-ERROR: immediate must be an integer in the range [0, 3] + +aes32dsi t0, a2, 8 +# CHECK-ERROR: immediate must be an integer in the range [0, 3]