Skip to content

Commit 78edff2

Browse files
committed
Adding support for Zvkgs's vgmul.vs and vghsh.vs
1 parent 927a086 commit 78edff2

File tree

6 files changed

+112
-0
lines changed

6 files changed

+112
-0
lines changed

disasm/disasm.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2176,6 +2176,13 @@ void disassembler_t::add_instructions(const isa_parser_t* isa)
21762176
DEFINE_VECTOR_VV(vghsh_vv);
21772177
}
21782178

2179+
if (isa->extension_enabled(EXT_ZVKGS)) {
2180+
// Despite its suffix, the vgmul.vv instruction
2181+
// is really ".v", with the form "vgmul.vv vd, vs2".
2182+
DEFINE_VECTOR_V(vgmul_vs);
2183+
DEFINE_VECTOR_VV(vghsh_vs);
2184+
}
2185+
21792186
if (isa->extension_enabled(EXT_ZVKNED)) {
21802187
// Despite their suffixes, the vaes*.{vv,vs} instructions
21812188
// 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
@@ -261,6 +261,8 @@ isa_parser_t::isa_parser_t(const char* str, const char *priv)
261261
extension_table[EXT_ZVFBFWMA] = true;
262262
} else if (ext_str == "zvkg") {
263263
extension_table[EXT_ZVKG] = true;
264+
} else if (ext_str == "zvkgs") {
265+
extension_table[EXT_ZVKGS] = true;
264266
} else if (ext_str == "zvkn") {
265267
extension_table[EXT_ZVBB] = true;
266268
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
@@ -1033,6 +1033,10 @@ riscv_insn_ext_zvkg= \
10331033
vghsh_vv \
10341034
vgmul_vv \
10351035

1036+
riscv_insn_ext_zvkgs= \
1037+
vghsh_vs \
1038+
vgmul_vs \
1039+
10361040
riscv_insn_ext_zvkned = \
10371041
vaesdf_vs \
10381042
vaesdf_vv \
@@ -1091,6 +1095,10 @@ riscv_insn_ext_zvk = \
10911095
$(riscv_insn_ext_zvksed) \
10921096
$(riscv_insn_ext_zvksh) \
10931097

1098+
riscv_insn_ext_zvka = \
1099+
$(riscv_insn_ext_zvbc32e) \
1100+
$(riscv_insn_ext_zvkgs) \
1101+
10941102
riscv_insn_list = \
10951103
$(riscv_insn_ext_i) \
10961104
$(riscv_insn_ext_c) \
@@ -1117,6 +1125,7 @@ riscv_insn_list = \
11171125
$(riscv_insn_ext_zfh_zfa) \
11181126
$(riscv_insn_ext_zicond) \
11191127
$(riscv_insn_ext_zvk) \
1128+
$(riscv_insn_ext_zvka) \
11201129
$(riscv_insn_priv) \
11211130
$(riscv_insn_smrnmi) \
11221131
$(riscv_insn_svinval) \

riscv/zvk_ext_macros.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,13 @@
957957
(DST)[bidx] = (SRC)[bidx]; \
958958
}
959959

960+
// Copies a EGU32x4_t value from 'SRC' into 'DST'.
961+
#define EGU32x4_COPY(DST, SRC) \
962+
for (std::size_t bidx = 0; bidx < 4; ++bidx) { \
963+
(DST)[bidx] = (SRC)[bidx]; \
964+
}
965+
966+
960967
// Performs "MUT_A ^= CONST_B;", i.e., xor of the bytes
961968
// in A (mutated) with the bytes in B (unchanged).
962969
#define EGU8x16_XOREQ(MUT_A, CONST_B) \

0 commit comments

Comments
 (0)