Skip to content

Commit 22f2027

Browse files
committed
[otbn,doc] Extend the programmer's guide with bn.trn explanations
This illustrates the functionlaty of the bn.trn1 and bn.trn2 instructions. Signed-off-by: Pascal Etterli <[email protected]>
1 parent d6e2cf1 commit 22f2027

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

hw/ip/otbn/doc/bn_trn_illustration.svg

Lines changed: 3 additions & 0 deletions
Loading

hw/ip/otbn/doc/programmers_guide.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,6 @@ This allows one to construct all the required packings.
389389

390390
<img src="./pack_instruction_shifting.svg" width="780"/>
391391

392-
To unpack vectors one can use the following approach.
393392
The unpacking works by concatenating two 256-bit strings loaded from memory and shifting the desired bits to the lower 192 bits.
394393
These 192 bits are then expanded to 8x 32 bits by inserting zero bytes every 3 bytes.
395394
```
@@ -408,6 +407,14 @@ bn.unpk w2, w12, w11, 128 /* unpack the green vector to w2 */
408407
bn.unpk w3, wXX, w12, 64 /* unpack the blue vector to w3, wXX represents that any WDR can be used */
409408
```
410409

410+
### Transposing vector elements
411+
To efficiently shuffle vectors, one can use the `bn.trn1` and `bn.trn2` instructions.
412+
These instructions reorder the vector elements as illustrated in the image below for `bn.trn1.4d` and `bn.trn2.4d`.
413+
- The `bn.trn1 wrd, wrs1, wrs2` instruction places even-indexed vector elements from `wrs1` into even-indexed elements of `wrd` and even-indexed vector elements from `wrs2` are placed into odd-indexed elements of `wrd`.
414+
- The `bn.trn2 wrd, wrs1, wrs2` instruction places odd-indexed vector elements from `wrs1` into even-indexed elements of `wrd` and odd-indexed vector elements from `wrs2` are placed into odd-indexed elements of `wrd`.
415+
416+
<img src="./bn_trn_illustration.svg" width="780">
417+
411418
## Device Interface Functions (DIFs)
412419

413420
- [Device Interface Functions](../../../../sw/device/lib/dif/dif_otbn.h)

0 commit comments

Comments
 (0)