aboutsummaryrefslogtreecommitdiff
path: root/riscv/zvksh_ext_macros.h
diff options
context:
space:
mode:
authorEric Gouriou <ego@rivosinc.com>2023-06-01 18:09:07 -0700
committerEric Gouriou <ego@rivosinc.com>2023-06-19 14:30:35 -0700
commita55f96ae9380d5cc9bef05e8b9e82e54d5d6ec35 (patch)
tree43f28cdc046246deb9275b71ecaaacdce45ecaa9 /riscv/zvksh_ext_macros.h
parentcbb2b1a224d8922c6d3146da56f5087a3858ced5 (diff)
downloadriscv-isa-sim-a55f96ae9380d5cc9bef05e8b9e82e54d5d6ec35.zip
riscv-isa-sim-a55f96ae9380d5cc9bef05e8b9e82e54d5d6ec35.tar.gz
riscv-isa-sim-a55f96ae9380d5cc9bef05e8b9e82e54d5d6ec35.tar.bz2
Zvk: Implement Zvksh, vector SM3 Hash Function
Implement the Zvksh sub-extension, "ShangMi Suite: SM3 Hash Function Instructions": - vsm3me.vv, message expansion, - vsm3c.vi, compression rounds. This also introduces a SM3 specific header for common logic. Co-authored-by: Raghav Gupta <rgupta@rivosinc.com> Co-authored-by: Albert Jakieła <aja@semihalf.com> Co-authored-by: Kornel Dulęba <mindal@semihalf.com> Signed-off-by: Eric Gouriou <ego@rivosinc.com>
Diffstat (limited to 'riscv/zvksh_ext_macros.h')
-rw-r--r--riscv/zvksh_ext_macros.h47
1 files changed, 47 insertions, 0 deletions
diff --git a/riscv/zvksh_ext_macros.h b/riscv/zvksh_ext_macros.h
new file mode 100644
index 0000000..71c5a09
--- /dev/null
+++ b/riscv/zvksh_ext_macros.h
@@ -0,0 +1,47 @@
+// Helper macros and functions to help implement instructions defined as part of
+// the RISC-V Zvksh extension (vectorized SM3).
+
+#include "zvk_ext_macros.h"
+
+#ifndef RISCV_INSNS_ZVKSH_COMMON_H_
+#define RISCV_INSNS_ZVKSH_COMMON_H_
+
+// Constraints common to all vsm3* instructions:
+// - Zvksh is enabled
+// - VSEW == 32
+// - EGW (256) <= LMUL * VLEN
+// - No overlap of vd and vs2.
+//
+// The constraint that vstart and vl are both EGS (8) aligned
+// is checked in the VI_ZVK_..._EGU32x8_..._LOOP macros.
+#define require_vsm3_constraints \
+ do { \
+ require_zvksh; \
+ require(P.VU.vsew == 32); \
+ require_egw_fits(256); \
+ require(insn.rd() != insn.rs2()); \
+ } while (false)
+
+#define FF1(X, Y, Z) ((X) ^ (Y) ^ (Z))
+#define FF2(X, Y, Z) (((X) & (Y)) | ((X) & (Z)) | ((Y) & (Z)))
+
+// Boolean function FF_j - section 4.3. of the IETF draft.
+#define ZVKSH_FF(X, Y, Z, J) (((J) <= 15) ? FF1(X, Y, Z) : FF2(X, Y, Z))
+
+#define GG1(X, Y, Z) ((X) ^ (Y) ^ (Z))
+#define GG2(X, Y, Z) (((X) & (Y)) | ((~(X)) & (Z)))
+
+// Boolean function GG_j - section 4.3. of the IETF draft.
+#define ZVKSH_GG(X, Y, Z, J) (((J) <= 15) ? GG1(X, Y, Z) : GG2(X, Y, Z))
+
+#define T1 0x79CC4519
+#define T2 0x7A879D8A
+
+// T_j constant - section 4.2. of the IETF draft.
+#define ZVKSH_T(J) (((J) <= 15) ? (T1) : (T2))
+
+// Permutation functions P_0 and P_1 - section 4.4 of the IETF draft.
+#define ZVKSH_P0(X) ((X) ^ ZVK_ROL32((X), 9) ^ ZVK_ROL32((X), 17))
+#define ZVKSH_P1(X) ((X) ^ ZVK_ROL32((X), 15) ^ ZVK_ROL32((X), 23))
+
+#endif // RISCV_INSNS_ZVKSH_COMMON_H