diff options
author | Bilal Sakhawat <63648044+bilalsakhawat-10xe@users.noreply.github.com> | 2022-01-21 15:06:54 +0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-21 10:06:54 +0000 |
commit | 4da2ab1df34056d7a7c0d033dc7f43c50a6d2db4 (patch) | |
tree | 742e28f313eaa677eb05d225907d04d384ba2367 /model/riscv_insts_zbkb.sail | |
parent | 5dd1ff612323bd4b3f2a21520bf24e0e9ae4e4ac (diff) | |
download | sail-riscv-4da2ab1df34056d7a7c0d033dc7f43c50a6d2db4.zip sail-riscv-4da2ab1df34056d7a7c0d033dc7f43c50a6d2db4.tar.gz sail-riscv-4da2ab1df34056d7a7c0d033dc7f43c50a6d2db4.tar.bz2 |
Add support for Scalar Cryptography Zbkb, Zbkc and Zbkx Extensions (#135)
Diffstat (limited to 'model/riscv_insts_zbkb.sail')
-rw-r--r-- | model/riscv_insts_zbkb.sail | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/model/riscv_insts_zbkb.sail b/model/riscv_insts_zbkb.sail new file mode 100644 index 0000000..d8a6592 --- /dev/null +++ b/model/riscv_insts_zbkb.sail @@ -0,0 +1,105 @@ +/* ****************************************************************** */ +union clause ast = ZBKB_RTYPE : (regidx, regidx, regidx, brop_zbkb) + +mapping clause encdec = ZBKB_RTYPE(rs2, rs1, rd, RISCV_PACK) if haveZbkb() + <-> 0b0000100 @ rs2 @ rs1 @ 0b100 @ rd @ 0b0110011 if haveZbkb() + +mapping clause encdec = ZBKB_RTYPE(rs2, rs1, rd, RISCV_PACKH) if haveZbkb() + <-> 0b0000100 @ rs2 @ rs1 @ 0b111 @ rd @ 0b0110011 if haveZbkb() + +mapping zbkb_rtype_mnemonic : brop_zbkb <-> string = { + RISCV_PACK <-> "pack", + RISCV_PACKH <-> "packh" +} + +mapping clause assembly = ZBKB_RTYPE(rs2, rs1, rd, op) + <-> zbkb_rtype_mnemonic(op) ^ spc() ^ reg_name(rd) ^ sep() ^ reg_name(rs1) ^ sep() ^ reg_name(rs2) + +function clause execute (ZBKB_RTYPE(rs2, rs1, rd, op)) = { + let rs1_val = X(rs1); + let rs2_val = X(rs2); + let result : xlenbits = match op { + RISCV_PACK => rs2_val[(sizeof(xlen_bytes)*4 - 1)..0] @ rs1_val[(sizeof(xlen_bytes)*4 - 1)..0], + RISCV_PACKH => EXTZ(rs2_val[7..0] @ rs1_val[7..0]) + }; + X(rd) = result; + RETIRE_SUCCESS +} + +/* ****************************************************************** */ +union clause ast = ZBKB_PACKW : (regidx, regidx, regidx) + +mapping clause encdec = ZBKB_PACKW(rs2, rs1, rd) if haveZbkb() & sizeof(xlen) == 64 + <-> 0b0000100 @ rs2 @ rs1 @ 0b100 @ rd @ 0b0111011 if haveZbkb() & sizeof(xlen) == 64 + +mapping clause assembly = ZBKB_PACKW(rs2, rs1, rd) + <-> "packw" ^ spc() ^ reg_name(rd) ^ sep() ^ reg_name(rs1) ^ sep() ^ reg_name(rs2) + +function clause execute (ZBKB_PACKW(rs2, rs1, rd)) = { + assert(sizeof(xlen) == 64); + let rs1_val = X(rs1); + let rs2_val = X(rs2); + let result : bits(32) = rs2_val[15..0] @ rs1_val[15..0]; + X(rd) = EXTZ(result); + RETIRE_SUCCESS +} + +/* ****************************************************************** */ +union clause ast = RISCV_ZIP : (regidx, regidx) + +mapping clause encdec = RISCV_ZIP(rs1, rd) if haveZbkb() & sizeof(xlen) == 32 + <-> 0b000010001111 @ rs1 @ 0b001 @ rd @ 0b0010011 if haveZbkb() & sizeof(xlen) == 32 + +mapping clause assembly = RISCV_ZIP(rs1, rd) + <-> "zip" ^ spc() ^ reg_name(rd) ^ sep() ^ reg_name(rs1) + +function clause execute (RISCV_ZIP(rs1, rd)) = { + assert(sizeof(xlen) == 32); + let rs1_val = X(rs1); + result : xlenbits = zeros(); + foreach (i from 0 to (sizeof(xlen_bytes)*4 - 1)) { + result[i*2] = rs1_val[i]; + result[i*2 + 1] = rs1_val[i + sizeof(xlen_bytes)*4]; + }; + X(rd) = result; + RETIRE_SUCCESS +} + +/* ****************************************************************** */ +union clause ast = RISCV_UNZIP : (regidx, regidx) + +mapping clause encdec = RISCV_UNZIP(rs1, rd) if haveZbkb() & sizeof(xlen) == 32 + <-> 0b000010001111 @ rs1 @ 0b101 @ rd @ 0b0010011 if haveZbkb() & sizeof(xlen) == 32 + +mapping clause assembly = RISCV_UNZIP(rs1, rd) + <-> "unzip" ^ spc() ^ reg_name(rd) ^ sep() ^ reg_name(rs1) + +function clause execute (RISCV_UNZIP(rs1, rd)) = { + assert(sizeof(xlen) == 32); + let rs1_val = X(rs1); + result : xlenbits = zeros(); + foreach (i from 0 to (sizeof(xlen_bytes)*4 - 1)) { + result[i] = rs1_val[i*2]; + result[i + sizeof(xlen_bytes)*4] = rs1_val[i*2 + 1]; + }; + X(rd) = result; + RETIRE_SUCCESS +} + +/* ****************************************************************** */ +union clause ast = RISCV_BREV8 : (regidx, regidx) + +mapping clause encdec = RISCV_BREV8(rs1, rd) if haveZbkb() + <-> 0b011010000111 @ rs1 @ 0b101 @ rd @ 0b0010011 if haveZbkb() + +mapping clause assembly = RISCV_BREV8(rs1, rd) + <-> "brev8" ^ spc() ^ reg_name(rd) ^ sep() ^ reg_name(rs1) + +function clause execute (RISCV_BREV8(rs1, rd)) = { + let rs1_val = X(rs1); + result : xlenbits = zeros(); + foreach (i from 0 to (sizeof(xlen) - 8) by 8) + result[i+7..i] = reverse(rs1_val[i+7..i]); + X(rd) = result; + RETIRE_SUCCESS +} |