Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Zbk* extensions #398

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
13 changes: 11 additions & 2 deletions arch/inst/Zbkb/brev8.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
$schema: inst_schema.json#
kind: instruction
name: brev8
long_name: No synopsis available.
long_name: Reverse the bits in each byte of a source register.
description: |
No description available.
This instruction reverses the order of the bits in every byte of a register.
definedBy:
anyOf: [B, Zbkb, Zk, Zkn, Zks]
assembly: xd, xs1
Expand All @@ -23,3 +23,12 @@ access:
vu: always
data_independent_timing: false
operation(): |
if (implemented?(ExtensionName::B) && (CSR[misa].Zbkb == 1'b0)) {
raise (ExceptionCode::IllegalInstruction, mode(), $encoding);
}

result : xlenbits = EXTZ(0b0);
foreach (i from 0 to sizeof(xlen) by 8) {
result[i+7..i] = reverse_bits_in_byte(X(rs1)[i+7..i]);
};
X(rd) = result;
dhower-qc marked this conversation as resolved.
Show resolved Hide resolved
14 changes: 12 additions & 2 deletions arch/inst/Zbkb/unzip.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
$schema: inst_schema.json#
kind: instruction
name: unzip
long_name: No synopsis available.
long_name: Inverse of Zip.
description: |
No description available.
This instruction gathers bits from the high and low halves of the source word into odd/even bit
positions in the destination word. It is the inverse of the zip instruction. This instruction is
available only on RV32.
definedBy:
anyOf: [B, Zbkb, Zk, Zkn, Zks]
assembly: xd, xs1
Expand All @@ -24,3 +26,11 @@ access:
data_independent_timing: false
base: 32
operation(): |
if (implemented?(ExtensionName::B) && (CSR[misa].Zbkb == 1'b0)) {
raise (ExceptionCode::IllegalInstruction, mode(), $encoding);
}

foreach (i from 0 to xlen/2-1) {
X(rd)[i] = X(rs1)[2*i]
X(rd)[i+xlen/2] = X(rs1)[2*i+1]
}
14 changes: 12 additions & 2 deletions arch/inst/Zbkb/zip.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
$schema: inst_schema.json#
kind: instruction
name: zip
long_name: No synopsis available.
long_name: Gather odd and even bits of the source word into upper/lower halves of the destination.
description: |
No description available.
This instruction scatters all of the odd and even bits of a source word into the high and low halves
of a destination word. It is the inverse of the unzip instruction. This instruction is available only on
RV32.
definedBy:
anyOf: [B, Zbkb, Zk, Zkn, Zks]
assembly: xd, xs1
Expand All @@ -24,3 +26,11 @@ access:
data_independent_timing: false
base: 32
operation(): |
if (implemented?(ExtensionName::B) && (CSR[misa].Zbkb == 1'b0)) {
raise (ExceptionCode::IllegalInstruction, mode(), $encoding);
}

foreach (i from 0 to xlen/2-1) {
X(rd)[2*i] = X(rs1)[i]
X(rd)[2*i+1] = X(rs1)[i+xlen/2]
}
22 changes: 20 additions & 2 deletions arch/inst/Zbkx/xperm4.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
$schema: inst_schema.json#
kind: instruction
name: xperm4
long_name: No synopsis available.
long_name: Nibble-wise lookup of indicies into a vector.
description: |
No description available.
The xperm4 instruction operates on nibbles. The rs1 register contains a vector of XLEN/4 4-bit
elements. The rs2 register contains a vector of XLEN/4 4-bit indexes. The result is each element in
rs2 replaced by the indexed element in rs1, or zero if the index into rs2 is out of bounds.
definedBy:
anyOf: [B, Zbkx, Zk, Zkn, Zks]
assembly: xd, xs1, xs2
Expand All @@ -25,3 +27,19 @@ access:
vu: always
data_independent_timing: false
operation(): |
if (implemented?(ExtensionName::B) && (CSR[misa].Zbkx == 1'b0)) {
raise (ExceptionCode::IllegalInstruction, mode(), $encoding);
}

val xperm4_lookup : (bits(4), xlenbits) -> bits(4)
function xperm4_lookup (idx, lut) = {
(lut >> (idx @ 0b00))[3..0]
}
function clause execute ( XPERM_4 (rs2,rs1,rd)) = {
result : xlenbits = EXTZ(0b0);
foreach(i from 0 to xlen by 4) {
result[i+3..i] = xperm4_lookup(X(rs2)[i+3..i], X(rs1));
};
X(rd) = result;
RETIRE_SUCCESS
}
22 changes: 20 additions & 2 deletions arch/inst/Zbkx/xperm8.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
$schema: inst_schema.json#
kind: instruction
name: xperm8
long_name: No synopsis available.
long_name: Byte-wise lookup of indicies into a vector.
description: |
No description available.
The xperm8 instruction operates on bytes. The rs1 register contains a vector of XLEN/8 8-bit
elements. The rs2 register contains a vector of XLEN/8 8-bit indexes. The result is each element in
rs2 replaced by the indexed element in rs1, or zero if the index into rs2 is out of bounds.
definedBy:
anyOf: [B, Zbkx, Zk, Zkn, Zks]
assembly: xd, xs1, xs2
Expand All @@ -25,3 +27,19 @@ access:
vu: always
data_independent_timing: false
operation(): |
if (implemented?(ExtensionName::B) && (CSR[misa].Zbkx == 1'b0)) {
raise (ExceptionCode::IllegalInstruction, mode(), $encoding);
}

val xperm8_lookup : (bits(8), xlenbits) -> bits(8)
function xperm8_lookup (idx, lut) = {
(lut >> (idx @ 0b00))[7..0]
}
function clause execute ( XPERM_8 (rs2,rs1,rd)) = {
result : xlenbits = EXTZ(0b0);
foreach(i from 0 to xlen by 8) {
result[i+7..i] = xperm4_lookup(X(rs2)[i+7..i], X(rs1));
};
X(rd) = result;
RETIRE_SUCCESS
}
Loading