|
| 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 | +); |
0 commit comments