Skip to content

Commit 7347f43

Browse files
committed
vector: crypto: fix EMUL alignment check for .vs operations
1 parent 789068f commit 7347f43

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

riscv/insns/vsm4r_vs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const uint32_t EGS = 4;
66

77
require_vsm4_constraints;
88
require_align(insn.rd(), P.VU.vflmul);
9+
require_vs2_align_eglmul(128);
910
// No overlap of vd and vs2.
1011
require_noover_eglmul(insn.rd(), insn.rs2());
1112

riscv/zvk_ext_macros.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,20 @@
8686
// (LMUL * VLEN) <= EGW
8787
#define require_egw_fits(EGW) require((EGW) <= (P.VU.VLEN * P.VU.vflmul))
8888

89+
// Ensures that a register index is aligned to EMUL
90+
// evaluated as EGW / VLEN.
91+
// The check is only enabled if this value is greater
92+
// than one (no index alignment check required for fractional EMUL)
93+
#define require_vreg_align_eglmul(EGW, VREG_NUM) \
94+
do { \
95+
float vfeglmul = EGW / P.VU.VLEN; \
96+
if (vfeglmul > 1) { \
97+
require_align(VREG_NUM, vfeglmul); \
98+
}\
99+
} while (0)
100+
101+
#define require_vs2_align_eglmul(EGW) require_vreg_align_eglmul(EGW, insn.rs2())
102+
89103
// ensure that rs2 and rd do not overlap, assuming rd encodes an LMUL wide
90104
// vector register group and rs2 encodes an vs2_EMUL=ceil(EGW / VLEN) vector register
91105
// group.

riscv/zvkned_ext_macros.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
// vaes*.vs instruction constraints:
1111
// - Zvkned is enabled
1212
// - EGW (128) <= LMUL * VLEN
13+
// - vd is LMUL aligned
14+
// - vs2 is ceil(EGW / VLEN) aligned
1315
// - vd and vs2 cannot overlap
1416
//
1517
// The constraint that vstart and vl are both EGS (4) aligned
@@ -22,6 +24,7 @@
2224
require(P.VU.vsew == 32); \
2325
require_egw_fits(128); \
2426
require_align(insn.rd(), P.VU.vflmul); \
27+
require_vs2_align_eglmul(128); \
2528
require_noover_eglmul(insn.rd(), insn.rs2()); \
2629
} while (false)
2730

0 commit comments

Comments
 (0)