33$schema : inst_schema.json#
44kind : instruction
55name : xperm4
6- long_name : No synopsis available.
6+ long_name : Crossbar permutation (nibbles)
77description : |
8- No description available.
9- definedBy :
10- anyOf : [B, Zbkx, Zk, Zkn, Zks]
8+ The xperm4 instruction operates on nibbles. The rs1 register contains a vector of XLEN/4 4-bit
9+ elements. The rs2 register contains a vector of XLEN/4 4-bit indexes. The result is each element in
10+ rs2 replaced by the indexed element in rs1, or zero if the index into rs2 is out of bounds.
11+ definedBy : Zbkx
1112assembly : xd, xs1, xs2
1213encoding :
1314 match : 0010100----------010-----0110011
@@ -25,3 +26,29 @@ access:
2526 vu : always
2627data_independent_timing : false
2728operation() : |
29+ XReg input1 = X[rs1];
30+ XReg input2 = X[rs2];
31+ XReg output = 0;
32+
33+ for(U32 i=0; i<(xlen()-4); i = i+4) {
34+ XReg index = input2[i+3:i];
35+ if(4*index < xlen()) {
36+ output[i+3:i] = input1[4*index+3:4*index];
37+ }
38+ }
39+
40+ X[rd] = output;
41+
42+ sail() : |
43+ val xperm4_lookup : (bits(4), xlenbits) -> bits(4)
44+ function xperm4_lookup (idx, lut) = {
45+ (lut >> (idx @ 0b00))[3..0]
46+ }
47+ function clause execute ( XPERM_4 (rs2,rs1,rd)) = {
48+ result : xlenbits = EXTZ(0b0);
49+ foreach(i from 0 to xlen by 4) {
50+ result[i+3..i] = xperm4_lookup(X(rs2)[i+3..i], X(rs1));
51+ };
52+ X(rd) = result;
53+ RETIRE_SUCCESS
54+ }
0 commit comments