Skip to content

Commit c4cf0bf

Browse files
committed
Adding support for Zvkgs's vgmul.vs and vghsh.vs
1 parent 3df0232 commit c4cf0bf

File tree

6 files changed

+110
-0
lines changed

6 files changed

+110
-0
lines changed

disasm/disasm.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2202,6 +2202,11 @@ void disassembler_t::add_instructions(const isa_parser_t* isa, bool strict)
22022202
DEFINE_VECTOR_VV(vghsh_vv);
22032203
}
22042204

2205+
if (ext_enabled(EXT_ZVKGS)) {
2206+
DEFINE_VECTOR_V(vgmul_vs);
2207+
DEFINE_VECTOR_VV(vghsh_vs);
2208+
}
2209+
22052210
if (ext_enabled(EXT_ZVKNED)) {
22062211
// Despite their suffixes, the vaes*.{vv,vs} instructions
22072212
// are really ".v", with the form "<op>.{vv,vs} vd, vs2".

disasm/isa_parser.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ isa_parser_t::isa_parser_t(const char* str, const char *priv)
290290
extension_table[EXT_ZVFBFWMA] = true;
291291
} else if (ext_str == "zvkg") {
292292
extension_table[EXT_ZVKG] = true;
293+
} else if (ext_str == "zvkgs") {
294+
extension_table[EXT_ZVKGS] = true;
293295
} else if (ext_str == "zvkn") {
294296
extension_table[EXT_ZVBB] = true;
295297
extension_table[EXT_ZVKNED] = true;

riscv/insns/vghsh_vs.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// vghsh.vs vd, vs2, vs1
2+
3+
#include "zvk_ext_macros.h"
4+
5+
require_zvkgs;
6+
require(P.VU.vsew == 32);
7+
require_egw_fits(128);
8+
9+
VI_ZVK_VD_VS1_VS2_NOOPERANDS_PRELOOP_EGU32x4_NOVM_LOOP(
10+
{},
11+
// This statement will be executed before the first execution
12+
// of the loop, and only if the loop is going to be entered.
13+
// We cannot use a block ( { ... } ) since we want the variables declared
14+
// here to be visible in the loop block.
15+
// We capture the "scalar", vs2's first element, by copy, even though
16+
// the "no overlap" constraint means that vs2 should remain constant
17+
// during the loop.
18+
EGU32x4_t H = P.VU.elt_group<EGU32x4_t>(vs2_num, 0); EGU32x4_BREV8(H);,
19+
{
20+
EGU32x4_t Y = P.VU.elt_group<EGU32x4_t>(vd_num, idx_eg);; // Current partial hash
21+
EGU32x4_t X = P.VU.elt_group<EGU32x4_t>(vs1_num, idx_eg);; // Block cipher output
22+
23+
EGU32x4_t Z = {};
24+
25+
// S = brev8(Y ^ X)
26+
EGU32x4_t S;
27+
EGU32x4_XOR(S, Y, X);
28+
EGU32x4_BREV8(S);
29+
30+
for (int bit = 0; bit < 128; bit++) {
31+
if (EGU32x4_ISSET(S, bit)) {
32+
EGU32x4_XOREQ(Z, H);
33+
}
34+
35+
const bool reduce = EGU32x4_ISSET(H, 127);
36+
EGU32x4_LSHIFT(H); // Left shift by 1.
37+
if (reduce) {
38+
H[0] ^= 0x87; // Reduce using x^7 + x^2 + x^1 + 1 polynomial
39+
}
40+
}
41+
EGU32x4_BREV8(Z);
42+
// Update the destination register.
43+
EGU32x4_t &vd = P.VU.elt_group<EGU32x4_t>(vd_num, idx_eg, true);
44+
EGU32x4_COPY(vd, Z);
45+
}
46+
);

riscv/insns/vgmul_vs.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// vgmul.vs vd, vs2
2+
3+
#include "zvk_ext_macros.h"
4+
5+
require_zvkgs;
6+
require(P.VU.vsew == 32);
7+
require_egw_fits(128);
8+
9+
VI_ZVK_VD_VS2_NOOPERANDS_PRELOOP_EGU32x4_NOVM_LOOP(
10+
{},
11+
// This statement will be executed before the first execution
12+
// of the loop, and only if the loop is going to be entered.
13+
// We cannot use a block ( { ... } ) since we want the variables declared
14+
// here to be visible in the loop block.
15+
// We capture the "scalar", vs2's first element, by copy, even though
16+
// the "no overlap" constraint means that vs2 should remain constant
17+
// during the loop.
18+
EGU32x4_t H = P.VU.elt_group<EGU32x4_t>(vs2_num, 0); EGU32x4_BREV8(H);
19+
,
20+
{
21+
EGU32x4_t Y = P.VU.elt_group<EGU32x4_t>(vd_num, idx_eg); // Multiplier
22+
EGU32x4_BREV8(Y);
23+
EGU32x4_t Z = {};
24+
25+
for (int bit = 0; bit < 128; bit++) {
26+
if (EGU32x4_ISSET(Y, bit)) {
27+
EGU32x4_XOREQ(Z, H);
28+
}
29+
30+
bool reduce = EGU32x4_ISSET(H, 127);
31+
EGU32x4_LSHIFT(H); // Lef shift by 1
32+
if (reduce) {
33+
H[0] ^= 0x87; // Reduce using x^7 + x^2 + x^1 + 1 polynomial
34+
}
35+
}
36+
EGU32x4_BREV8(Z);
37+
// Update the destination register.
38+
EGU32x4_t &vd = P.VU.elt_group<EGU32x4_t>(vd_num, idx_eg, true);
39+
EGU32x4_COPY(vd, Z);
40+
}
41+
);

riscv/riscv.mk.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,10 @@ riscv_insn_ext_zvkg= \
10461046
vghsh_vv \
10471047
vgmul_vv \
10481048

1049+
riscv_insn_ext_zvkgs= \
1050+
vghsh_vs \
1051+
vgmul_vs \
1052+
10491053
riscv_insn_ext_zvkned = \
10501054
vaesdf_vs \
10511055
vaesdf_vv \
@@ -1123,6 +1127,10 @@ riscv_insn_ext_zvk = \
11231127
$(riscv_insn_ext_zvksed) \
11241128
$(riscv_insn_ext_zvksh) \
11251129

1130+
riscv_insn_ext_zvka = \
1131+
$(riscv_insn_ext_zvbc32e) \
1132+
$(riscv_insn_ext_zvkgs) \
1133+
11261134
riscv_insn_list = \
11271135
$(riscv_insn_ext_i) \
11281136
$(riscv_insn_ext_c) \
@@ -1149,6 +1157,7 @@ riscv_insn_list = \
11491157
$(riscv_insn_ext_zfh_zfa) \
11501158
$(riscv_insn_ext_zicond) \
11511159
$(riscv_insn_ext_zvk) \
1160+
$(riscv_insn_ext_zvka) \
11521161
$(riscv_insn_ext_zvbdot) \
11531162
$(riscv_insn_ext_zvldot) \
11541163
$(riscv_insn_priv) \

riscv/zvk_ext_macros.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,13 @@
983983
(DST)[bidx] = (SRC)[bidx]; \
984984
}
985985

986+
// Copies a EGU32x4_t value from 'SRC' into 'DST'.
987+
#define EGU32x4_COPY(DST, SRC) \
988+
for (std::size_t bidx = 0; bidx < 4; ++bidx) { \
989+
(DST)[bidx] = (SRC)[bidx]; \
990+
}
991+
992+
986993
// Performs "MUT_A ^= CONST_B;", i.e., xor of the bytes
987994
// in A (mutated) with the bytes in B (unchanged).
988995
#define EGU8x16_XOREQ(MUT_A, CONST_B) \

0 commit comments

Comments
 (0)