Skip to content

Commit

Permalink
[RISC-V] Zvk update to 0.9.7, Zvknc/Zvksc
Browse files Browse the repository at this point in the history
Update the RISC-V Zvk (vector cryptography) extension support from 0.5
to version 0.9.7 (2023-05-31), per
    <https://github.com/riscv/riscv-crypto/releases/download/v20230531/riscv-crypto-spec-vector.pdf>

Differences:
     - Zvbc is dropped from Zvkn and Zvks, and by extension
       from Zvkng and Zvksg;
     - new combo extensions Zvknc and Zvksc are introduced,
      adding Zvbc to Zvkn and Zvks;
     - the experimentatl extensions are tagged as "0.9",
       from the earlier "0.5".

Reviewed By: 4vtomat

Differential Revision: https://reviews.llvm.org/D152117
  • Loading branch information
egouriou-rivos authored and topperc committed Jun 12, 2023
1 parent eae59ae commit c5a88fe
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 114 deletions.
96 changes: 57 additions & 39 deletions clang/test/Preprocessor/riscv-target-features.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@
// CHECK-NOT: __riscv_zvbc {{.*$}}
// CHECK-NOT: __riscv_zvkg {{.*$}}
// CHECK-NOT: __riscv_zvkn {{.*$}}
// CHECK-NOT: __riscv_zvknc {{.*$}}
// CHECK-NOT: __riscv_zvkned {{.*$}}
// CHECK-NOT: __riscv_zvkng {{.*$}}
// CHECK-NOT: __riscv_zvknha {{.*$}}
// CHECK-NOT: __riscv_zvknhb {{.*$}}
// CHECK-NOT: __riscv_zvks {{.*$}}
// CHECK-NOT: __riscv_zvksc {{.*$}}
// CHECK-NOT: __riscv_zvksed {{.*$}}
// CHECK-NOT: __riscv_zvksg {{.*$}}
// CHECK-NOT: __riscv_zvksh {{.*$}}
Expand Down Expand Up @@ -551,108 +553,124 @@
// CHECK-ZFA-EXT: __riscv_zfa 2000{{$}}

// RUN: %clang -target riscv32 -menable-experimental-extensions \
// RUN: -march=rv32i_zve64x_zvbb0p5 -x c -E -dM %s \
// RUN: -march=rv32i_zve64x_zvbb0p9 -x c -E -dM %s \
// RUN: -o - | FileCheck --check-prefix=CHECK-ZVBB-EXT %s
// RUN: %clang -target riscv64 -menable-experimental-extensions \
// RUN: -march=rv64i_zve64x_zvbb0p5 -x c -E -dM %s \
// RUN: -march=rv64i_zve64x_zvbb0p9 -x c -E -dM %s \
// RUN: -o - | FileCheck --check-prefix=CHECK-ZVBB-EXT %s
// CHECK-ZVBB-EXT: __riscv_zvbb 5000{{$}}
// CHECK-ZVBB-EXT: __riscv_zvbb 9000{{$}}

// RUN: %clang -target riscv32 -menable-experimental-extensions \
// RUN: -march=rv32i_zve64x_zvbc0p5 -x c -E -dM %s \
// RUN: -march=rv32i_zve64x_zvbc0p9 -x c -E -dM %s \
// RUN: -o - | FileCheck --check-prefix=CHECK-ZVBC-EXT %s
// RUN: %clang -target riscv64 -menable-experimental-extensions \
// RUN: -march=rv64i_zve64x_zvbc0p5 -x c -E -dM %s \
// RUN: -march=rv64i_zve64x_zvbc0p9 -x c -E -dM %s \
// RUN: -o - | FileCheck --check-prefix=CHECK-ZVBC-EXT %s
// CHECK-ZVBC-EXT: __riscv_zvbc 5000{{$}}
// CHECK-ZVBC-EXT: __riscv_zvbc 9000{{$}}

// RUN: %clang -target riscv32 -menable-experimental-extensions \
// RUN: -march=rv32i_zve32x_zvkg0p5 -x c -E -dM %s \
// RUN: -march=rv32i_zve32x_zvkg0p9 -x c -E -dM %s \
// RUN: -o - | FileCheck --check-prefix=CHECK-ZVKG-EXT %s
// RUN: %clang -target riscv64 -menable-experimental-extensions \
// RUN: -march=rv64i_zve32x_zvkg0p5 -x c -E -dM %s \
// RUN: -march=rv64i_zve32x_zvkg0p9 -x c -E -dM %s \
// RUN: -o - | FileCheck --check-prefix=CHECK-ZVKG-EXT %s
// CHECK-ZVKG-EXT: __riscv_zvkg 5000{{$}}
// CHECK-ZVKG-EXT: __riscv_zvkg 9000{{$}}

// RUN: %clang -target riscv32 -menable-experimental-extensions \
// RUN: -march=rv32i_zve64x_zvkn0p5 -x c -E -dM %s \
// RUN: -march=rv32i_zve64x_zvkn0p9 -x c -E -dM %s \
// RUN: -o - | FileCheck --check-prefix=CHECK-ZVKN-EXT %s
// RUN: %clang -target riscv64 -menable-experimental-extensions \
// RUN: -march=rv64i_zve64x_zvkn0p5 -x c -E -dM %s \
// RUN: -march=rv64i_zve64x_zvkn0p9 -x c -E -dM %s \
// RUN: -o - | FileCheck --check-prefix=CHECK-ZVKN-EXT %s
// CHECK-ZVKN-EXT: __riscv_zvkn 5000{{$}}
// CHECK-ZVKN-EXT: __riscv_zvkn 9000{{$}}

// RUN: %clang -target riscv32 -menable-experimental-extensions \
// RUN: -march=rv32i_zve64x_zvkng0p5 -x c -E -dM %s \
// RUN: -march=rv32i_zve64x_zvknc0p9 -x c -E -dM %s \
// RUN: -o - | FileCheck --check-prefix=CHECK-ZVKNC-EXT %s
// RUN: %clang -target riscv64 -menable-experimental-extensions \
// RUN: -march=rv64i_zve64x_zvknc0p9 -x c -E -dM %s \
// RUN: -o - | FileCheck --check-prefix=CHECK-ZVKNC-EXT %s
// CHECK-ZVKNC-EXT: __riscv_zvknc 9000{{$}}

// RUN: %clang -target riscv32 -menable-experimental-extensions \
// RUN: -march=rv32i_zve64x_zvkng0p9 -x c -E -dM %s \
// RUN: -o - | FileCheck --check-prefix=CHECK-ZVKNG-EXT %s
// RUN: %clang -target riscv64 -menable-experimental-extensions \
// RUN: -march=rv64i_zve64x_zvkng0p5 -x c -E -dM %s \
// RUN: -march=rv64i_zve64x_zvkng0p9 -x c -E -dM %s \
// RUN: -o - | FileCheck --check-prefix=CHECK-ZVKNG-EXT %s
// CHECK-ZVKNG-EXT: __riscv_zvkng 5000{{$}}
// CHECK-ZVKNG-EXT: __riscv_zvkng 9000{{$}}

// RUN: %clang -target riscv32 -menable-experimental-extensions \
// RUN: -march=rv32i_zve32x_zvknha0p5 -x c -E -dM %s \
// RUN: -march=rv32i_zve32x_zvknha0p9 -x c -E -dM %s \
// RUN: -o - | FileCheck --check-prefix=CHECK-ZVKNHA-EXT %s
// RUN: %clang -target riscv64 -menable-experimental-extensions \
// RUN: -march=rv64i_zve32x_zvknha0p5 -x c -E -dM %s \
// RUN: -march=rv64i_zve32x_zvknha0p9 -x c -E -dM %s \
// RUN: -o - | FileCheck --check-prefix=CHECK-ZVKNHA-EXT %s
// CHECK-ZVKNHA-EXT: __riscv_zvknha 5000{{$}}
// CHECK-ZVKNHA-EXT: __riscv_zvknha 9000{{$}}

// RUN: %clang -target riscv32 -menable-experimental-extensions \
// RUN: -march=rv32i_zve64x_zvknhb0p5 -x c -E -dM %s \
// RUN: -march=rv32i_zve64x_zvknhb0p9 -x c -E -dM %s \
// RUN: -o - | FileCheck --check-prefix=CHECK-ZVKNHB-EXT %s
// RUN: %clang -target riscv64 -menable-experimental-extensions \
// RUN: -march=rv64i_zve64x_zvknhb0p5 -x c -E -dM %s \
// RUN: -march=rv64i_zve64x_zvknhb0p9 -x c -E -dM %s \
// RUN: -o - | FileCheck --check-prefix=CHECK-ZVKNHB-EXT %s
// CHECK-ZVKNHB-EXT: __riscv_zvknhb 5000{{$}}
// CHECK-ZVKNHB-EXT: __riscv_zvknhb 9000{{$}}

// RUN: %clang -target riscv32 -menable-experimental-extensions \
// RUN: -march=rv32i_zve32x_zvkned0p5 -x c -E -dM %s \
// RUN: -march=rv32i_zve32x_zvkned0p9 -x c -E -dM %s \
// RUN: -o - | FileCheck --check-prefix=CHECK-ZVKNED-EXT %s
// RUN: %clang -target riscv64 -menable-experimental-extensions \
// RUN: -march=rv64i_zve32x_zvkned0p5 -x c -E -dM %s \
// RUN: -march=rv64i_zve32x_zvkned0p9 -x c -E -dM %s \
// RUN: -o - | FileCheck --check-prefix=CHECK-ZVKNED-EXT %s
// CHECK-ZVKNED-EXT: __riscv_zvkned 5000{{$}}
// CHECK-ZVKNED-EXT: __riscv_zvkned 9000{{$}}

// RUN: %clang -target riscv32 -menable-experimental-extensions \
// RUN: -march=rv32i_zve64x_zvks0p5 -x c -E -dM %s \
// RUN: -march=rv32i_zve64x_zvks0p9 -x c -E -dM %s \
// RUN: -o - | FileCheck --check-prefix=CHECK-ZVKS-EXT %s
// RUN: %clang -target riscv64 -menable-experimental-extensions \
// RUN: -march=rv64i_zve64x_zvks0p5 -x c -E -dM %s \
// RUN: -march=rv64i_zve64x_zvks0p9 -x c -E -dM %s \
// RUN: -o - | FileCheck --check-prefix=CHECK-ZVKS-EXT %s
// CHECK-ZVKS-EXT: __riscv_zvks 5000{{$}}
// CHECK-ZVKS-EXT: __riscv_zvks 9000{{$}}

// RUN: %clang -target riscv32 -menable-experimental-extensions \
// RUN: -march=rv32i_zve64x_zvksc0p9 -x c -E -dM %s \
// RUN: -o - | FileCheck --check-prefix=CHECK-ZVKSC-EXT %s
// RUN: %clang -target riscv64 -menable-experimental-extensions \
// RUN: -march=rv64i_zve64x_zvksc0p9 -x c -E -dM %s \
// RUN: -o - | FileCheck --check-prefix=CHECK-ZVKSC-EXT %s
// CHECK-ZVKSC-EXT: __riscv_zvksc 9000{{$}}

// RUN: %clang -target riscv32 -menable-experimental-extensions \
// RUN: -march=rv32i_zve32x_zvksed0p5 -x c -E -dM %s \
// RUN: -march=rv32i_zve32x_zvksed0p9 -x c -E -dM %s \
// RUN: -o - | FileCheck --check-prefix=CHECK-ZVKSED-EXT %s
// RUN: %clang -target riscv64 -menable-experimental-extensions \
// RUN: -march=rv64i_zve32x_zvksed0p5 -x c -E -dM %s \
// RUN: -march=rv64i_zve32x_zvksed0p9 -x c -E -dM %s \
// RUN: -o - | FileCheck --check-prefix=CHECK-ZVKSED-EXT %s
// CHECK-ZVKSED-EXT: __riscv_zvksed 5000{{$}}
// CHECK-ZVKSED-EXT: __riscv_zvksed 9000{{$}}

// RUN: %clang -target riscv32 -menable-experimental-extensions \
// RUN: -march=rv32i_zve64x_zvksg0p5 -x c -E -dM %s \
// RUN: -march=rv32i_zve64x_zvksg0p9 -x c -E -dM %s \
// RUN: -o - | FileCheck --check-prefix=CHECK-ZVKSG-EXT %s
// RUN: %clang -target riscv64 -menable-experimental-extensions \
// RUN: -march=rv64i_zve64x_zvksg0p5 -x c -E -dM %s \
// RUN: -march=rv64i_zve64x_zvksg0p9 -x c -E -dM %s \
// RUN: -o - | FileCheck --check-prefix=CHECK-ZVKSG-EXT %s
// CHECK-ZVKSG-EXT: __riscv_zvksg 5000{{$}}
// CHECK-ZVKSG-EXT: __riscv_zvksg 9000{{$}}

// RUN: %clang -target riscv32 -menable-experimental-extensions \
// RUN: -march=rv32i_zve32x_zvksh0p5 -x c -E -dM %s \
// RUN: -march=rv32i_zve32x_zvksh0p9 -x c -E -dM %s \
// RUN: -o - | FileCheck --check-prefix=CHECK-ZVKSH-EXT %s
// RUN: %clang -target riscv64 -menable-experimental-extensions \
// RUN: -march=rv64i_zve32x_zvksh0p5 -x c -E -dM %s \
// RUN: -march=rv64i_zve32x_zvksh0p9 -x c -E -dM %s \
// RUN: -o - | FileCheck --check-prefix=CHECK-ZVKSH-EXT %s
// CHECK-ZVKSH-EXT: __riscv_zvksh 5000{{$}}
// CHECK-ZVKSH-EXT: __riscv_zvksh 9000{{$}}

// RUN: %clang -target riscv32 -menable-experimental-extensions \
// RUN: -march=rv32i_zve32x_zvkt0p5 -x c -E -dM %s \
// RUN: -march=rv32i_zve32x_zvkt0p9 -x c -E -dM %s \
// RUN: -o - | FileCheck --check-prefix=CHECK-ZVKT-EXT %s
// RUN: %clang -target riscv64 -menable-experimental-extensions \
// RUN: -march=rv64i_zve32x_zvkt0p5 -x c -E -dM %s \
// RUN: -march=rv64i_zve32x_zvkt0p9 -x c -E -dM %s \
// RUN: -o - | FileCheck --check-prefix=CHECK-ZVKT-EXT %s
// CHECK-ZVKT-EXT: __riscv_zvkt 5000{{$}}
// CHECK-ZVKT-EXT: __riscv_zvkt 9000{{$}}

// RUN: %clang -target riscv32 -menable-experimental-extensions \
// RUN: -march=rv32i_zicond1p0 -x c -E -dM %s \
Expand Down
4 changes: 2 additions & 2 deletions llvm/docs/RISCVUsage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ The primary goal of experimental support is to assist in the process of ratifica
``experimental-zvfh``
LLVM implements `this draft text <https://github.com/riscv/riscv-v-spec/pull/780>`__.

``experimental-zvbb``, ``experimental-zvbc``, ``experimental-zvkg``, ``experimental-zvkn``, ``experimental-zvkng``, ``experimental-zvknha``, ``experimental-zvknhb``, ``experimental-zvkns``, ``experimental-zvks``, ``experimental-zvksed``, ``experimental-zvksg``, ``experimental-zvksh``, ``experimental-zvkt``
LLVM implements the `0.5 draft specification <https://github.com/riscv/riscv-crypto/releases/download/v20230407/riscv-crypto-spec-vector.pdf>`__. Note that current vector crypto extension version can be found in: <https://github.com/riscv/riscv-crypto>.
``experimental-zvbb``, ``experimental-zvbc``, ``experimental-zvkg``, ``experimental-zvkn``, ``experimental-zvknc``, ``experimental-zvkned``, ``experimental-zvkng``, ``experimental-zvknha``, ``experimental-zvknhb``, ``experimental-zvks``, ``experimental-zvksc``, ``experimental-zvksed``, ``experimental-zvksg``, ``experimental-zvksh``, ``experimental-zvkt``
LLVM implements the `0.9.7 draft specification <https://github.com/riscv/riscv-crypto/releases/download/v20230531/riscv-crypto-spec-vector.pdf>`__. Note that current vector crypto extension version can be found in: <https://github.com/riscv/riscv-crypto>.

To use an experimental extension from `clang`, you must add `-menable-experimental-extensions` to the command line, and specify the exact version of the experimental extension you are using. To use an experimental extension with LLVM's internal developer tools (e.g. `llc`, `llvm-objdump`, `llvm-mc`), you must prefix the extension name with `experimental-`. Note that you don't need to specify the version with internal tools, and shouldn't include the `experimental-` prefix with `clang`.

Expand Down
40 changes: 22 additions & 18 deletions llvm/lib/Support/RISCVISAInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,19 +155,21 @@ static const RISCVSupportedExtension SupportedExperimentalExtensions[] = {
{"ztso", RISCVExtensionVersion{0, 1}},

// vector crypto
{"zvbb", RISCVExtensionVersion{0, 5}},
{"zvbc", RISCVExtensionVersion{0, 5}},
{"zvkg", RISCVExtensionVersion{0, 5}},
{"zvkn", RISCVExtensionVersion{0, 5}},
{"zvkned", RISCVExtensionVersion{0, 5}},
{"zvkng", RISCVExtensionVersion{0, 5}},
{"zvknha", RISCVExtensionVersion{0, 5}},
{"zvknhb", RISCVExtensionVersion{0, 5}},
{"zvks", RISCVExtensionVersion{0, 5}},
{"zvksed", RISCVExtensionVersion{0, 5}},
{"zvksg", RISCVExtensionVersion{0, 5}},
{"zvksh", RISCVExtensionVersion{0, 5}},
{"zvkt", RISCVExtensionVersion{0, 5}},
{"zvbb", RISCVExtensionVersion{0, 9}},
{"zvbc", RISCVExtensionVersion{0, 9}},
{"zvkg", RISCVExtensionVersion{0, 9}},
{"zvkn", RISCVExtensionVersion{0, 9}},
{"zvknc", RISCVExtensionVersion{0, 9}},
{"zvkned", RISCVExtensionVersion{0, 9}},
{"zvkng", RISCVExtensionVersion{0, 9}},
{"zvknha", RISCVExtensionVersion{0, 9}},
{"zvknhb", RISCVExtensionVersion{0, 9}},
{"zvks", RISCVExtensionVersion{0, 9}},
{"zvksc", RISCVExtensionVersion{0, 9}},
{"zvksed", RISCVExtensionVersion{0, 9}},
{"zvksg", RISCVExtensionVersion{0, 9}},
{"zvksh", RISCVExtensionVersion{0, 9}},
{"zvkt", RISCVExtensionVersion{0, 9}},
};

static bool stripExperimentalPrefix(StringRef &Ext) {
Expand Down Expand Up @@ -944,13 +946,13 @@ static const char *ImpliedExtsZve64x[] = {"zve32x", "zvl64b"};
static const char *ImpliedExtsZvfbfmin[] = {"zve32f"};
static const char *ImpliedExtsZvfbfwma[] = {"zve32f"};
static const char *ImpliedExtsZvfh[] = {"zve32f", "zfhmin"};
static const char *ImpliedExtsZvkn[] = {"zvbb", "zvbc", "zvkned", "zvknhb",
"zvkt"};
static const char *ImpliedExtsZvkn[] = {"zvbb", "zvkned", "zvknhb", "zvkt"};
static const char *ImpliedExtsZvknc[] = {"zvbc", "zvkn"};
static const char *ImpliedExtsZvkng[] = {"zvkg", "zvkn"};
static const char *ImpliedExtsZvknhb[] = {"zvknha"};
static const char *ImpliedExtsZvks[] = {"zvbb", "zvbc", "zvksed", "zvksh",
"zvkt"};
static const char *ImpliedExtsZvksg[] = {"zvks", "zvkg"};
static const char *ImpliedExtsZvks[] = {"zvbb", "zvksed", "zvksh", "zvkt"};
static const char *ImpliedExtsZvksc[] = {"zvbc", "zvks"};
static const char *ImpliedExtsZvksg[] = {"zvkg", "zvks"};
static const char *ImpliedExtsZvl1024b[] = {"zvl512b"};
static const char *ImpliedExtsZvl128b[] = {"zvl64b"};
static const char *ImpliedExtsZvl16384b[] = {"zvl8192b"};
Expand Down Expand Up @@ -1006,9 +1008,11 @@ static constexpr ImpliedExtsEntry ImpliedExts[] = {
{{"zvfbfwma"}, {ImpliedExtsZvfbfwma}},
{{"zvfh"}, {ImpliedExtsZvfh}},
{{"zvkn"}, {ImpliedExtsZvkn}},
{{"zvknc"}, {ImpliedExtsZvknc}},
{{"zvkng"}, {ImpliedExtsZvkng}},
{{"zvknhb"}, {ImpliedExtsZvknhb}},
{{"zvks"}, {ImpliedExtsZvks}},
{{"zvksc"}, {ImpliedExtsZvksc}},
{{"zvksg"}, {ImpliedExtsZvksg}},
{{"zvl1024b"}, {ImpliedExtsZvl1024b}},
{{"zvl128b"}, {ImpliedExtsZvl128b}},
Expand Down
10 changes: 10 additions & 0 deletions llvm/lib/Target/RISCV/RISCVFeatures.td
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,11 @@ def FeatureStdExtZvkn
"This extension is shorthand for the following set of "
"other extensions: Zvkned, Zvknhb, Zvbb, Zvbc, and Zvkt.">;

def FeatureStdExtZvknc
: SubtargetFeature<"experimental-zvknc", "HasStdExtZvknc", "true",
"This extension is shorthand for the following set of "
"other extensions: Zvkn and Zvbc.">;

def FeatureStdExtZvkned
: SubtargetFeature<"experimental-zvkned", "HasStdExtZvkned", "true",
"'Zvkned' (Vector AES Encryption & Decryption (Single Round))">;
Expand Down Expand Up @@ -584,6 +589,11 @@ def FeatureStdExtZvks
"This extension is shorthand for the following set of "
"other extensions: Zvksed, Zvksh, Zvbb, Zvbc, and Zvkt.">;

def FeatureStdExtZvksc
: SubtargetFeature<"experimental-zvksc", "HasStdExtZvksc", "true",
"This extension is shorthand for the following set of "
"other extensions: Zvks and Zvbc.">;

def FeatureStdExtZvksed
: SubtargetFeature<"experimental-zvksed", "HasStdExtZvksed", "true",
"'Zvksed' (SM4 Block Cipher Instructions)">;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/RISCV/RISCVInstrInfoZvk.td
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
//
// This file describes the RISC-V instructions from the standard 'Zvk',
// Vector Cryptography Instructions extension, version 0.5.1.
// Vector Cryptography Instructions extension, version 0.9.7.
//
//===----------------------------------------------------------------------===//

Expand Down

0 comments on commit c5a88fe

Please sign in to comment.