|
| 1 | +/*=======================================================================================*/ |
| 2 | +/* This Sail RISC-V architecture model, comprising all files and */ |
| 3 | +/* directories except where otherwise noted is subject the BSD */ |
| 4 | +/* two-clause license in the LICENSE file. */ |
| 5 | +/* */ |
| 6 | +/* SPDX-License-Identifier: BSD-2-Clause */ |
| 7 | +/*=======================================================================================*/ |
| 8 | + |
| 9 | +function clause currentlyEnabled(Ext_Zvkg) = hartSupports(Ext_Zvkg) & currentlyEnabled(Ext_V) |
| 10 | + |
| 11 | +union clause ast = VGHSH_VV : (vregidx, vregidx, vregidx) |
| 12 | + |
| 13 | +mapping clause encdec = VGHSH_VV(vs2, vs1, vd) |
| 14 | + <-> 0b1011001 @ encdec_vreg(vs2) @ encdec_vreg(vs1) @ 0b010 @ encdec_vreg(vd) @ 0b1110111 |
| 15 | + when currentlyEnabled(Ext_Zvkg) & get_sew() == 32 & zvk_check_encdec(128, 4) |
| 16 | + |
| 17 | +mapping clause assembly = VGHSH_VV(vs2, vs1, vd) |
| 18 | + <-> "vghsh.vv" ^ spc() ^ vreg_name(vd) ^ sep() ^ vreg_name(vs2) ^ sep() ^ vreg_name(vs1) |
| 19 | + |
| 20 | +function clause execute (VGHSH_VV(vs2, vs1, vd)) = { |
| 21 | + let SEW = get_sew(); |
| 22 | + let LMUL_pow = get_lmul_pow(); |
| 23 | + let num_elem = get_num_elem(LMUL_pow, SEW); |
| 24 | + |
| 25 | + assert(SEW == 32); |
| 26 | + |
| 27 | + let vs2_val = read_vreg(num_elem, SEW, LMUL_pow, vs2); |
| 28 | + let vs1_val = read_vreg(num_elem, SEW, LMUL_pow, vs1); |
| 29 | + let vd_val = read_vreg(num_elem, SEW, LMUL_pow, vd); |
| 30 | + |
| 31 | + let eg_len = (unsigned(vl) / 4); |
| 32 | + let eg_start = (unsigned(vstart) / 4); |
| 33 | + |
| 34 | + foreach (i from eg_start to (eg_len - 1)) { |
| 35 | + assert(i * 4 + 3 < num_elem); |
| 36 | + |
| 37 | + let Y : bits(128) = get_velem_quad(vd_val, i); |
| 38 | + let X : bits(128) = get_velem_quad(vs1_val, i); |
| 39 | + var H : bits(128) = brev8(get_velem_quad(vs2_val, i)); |
| 40 | + |
| 41 | + var Z : bits(128) = zeros(); |
| 42 | + let S : bits(128) = brev8(Y ^ X); |
| 43 | + |
| 44 | + foreach (b from 0 to 127) { |
| 45 | + if S[b] == bitone then Z = Z ^ H; |
| 46 | + |
| 47 | + let reduce = H[127] == bitone; |
| 48 | + H = H << 1; |
| 49 | + if reduce then H = H[127..8] @ (H[7..0] ^ 0x87); |
| 50 | + }; |
| 51 | + |
| 52 | + write_velem_quad(vd, SEW, brev8(Z), i); |
| 53 | + }; |
| 54 | + |
| 55 | + set_vstart(zeros()); |
| 56 | + RETIRE_SUCCESS |
| 57 | +} |
| 58 | + |
| 59 | +union clause ast = VGMUL_VV : (vregidx, vregidx) |
| 60 | + |
| 61 | +mapping clause encdec = VGMUL_VV(vs2, vd) |
| 62 | + <-> 0b1010001 @ encdec_vreg(vs2) @ 0b10001 @ 0b010 @ encdec_vreg(vd) @ 0b1110111 |
| 63 | + when currentlyEnabled(Ext_Zvkg) & get_sew() == 32 & zvk_check_encdec(128, 4) |
| 64 | + |
| 65 | +mapping clause assembly = VGMUL_VV(vs2, vd) |
| 66 | + <-> "vgmul.vv" ^ spc() ^ vreg_name(vd) ^ sep() ^ vreg_name(vs2) |
| 67 | + |
| 68 | +function clause execute (VGMUL_VV(vs2, vd)) = { |
| 69 | + let SEW = get_sew(); |
| 70 | + let LMUL_pow = get_lmul_pow(); |
| 71 | + let num_elem = get_num_elem(LMUL_pow, SEW); |
| 72 | + |
| 73 | + assert(SEW == 32); |
| 74 | + |
| 75 | + let vs2_val = read_vreg(num_elem, SEW, LMUL_pow, vs2); |
| 76 | + let vd_val = read_vreg(num_elem, SEW, LMUL_pow, vd); |
| 77 | + |
| 78 | + let eg_len = (unsigned(vl) / 4); |
| 79 | + let eg_start = (unsigned(vstart) / 4); |
| 80 | + |
| 81 | + foreach (i from eg_start to (eg_len - 1)) { |
| 82 | + assert(i * 4 + 3 < num_elem); |
| 83 | + |
| 84 | + let Y : bits(128) = brev8(get_velem_quad(vd_val, i)); |
| 85 | + var H : bits(128) = brev8(get_velem_quad(vs2_val, i)); |
| 86 | + var Z : bits(128) = zeros(); |
| 87 | + |
| 88 | + foreach (b from 0 to 127) { |
| 89 | + if Y[b] == bitone then Z = Z ^ H; |
| 90 | + |
| 91 | + let reduce = H[127] == bitone; |
| 92 | + H = H << 1; |
| 93 | + if reduce then H = H[127..8] @ (H[7..0] ^ 0x87); |
| 94 | + }; |
| 95 | + |
| 96 | + write_velem_quad(vd, SEW, brev8(Z), i); |
| 97 | + }; |
| 98 | + |
| 99 | + set_vstart(zeros()); |
| 100 | + RETIRE_SUCCESS |
| 101 | +} |
0 commit comments