X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;ds=sidebyside;f=openpower%2Fsv%2Fbitmanip.mdwn;h=fc1904a86e4cb8b3939b95c0e2c373cb7251513f;hb=246ee647dd5ba6f67e761a38a732b64fff015f15;hp=6a65a5a62bef89816287db31b104fa894a9e91e8;hpb=caf0a0251b6a5e56970d8f95571b77d187b616cd;p=libreriscv.git
diff --git a/openpower/sv/bitmanip.mdwn b/openpower/sv/bitmanip.mdwn
index 6a65a5a62..fc1904a86 100644
--- a/openpower/sv/bitmanip.mdwn
+++ b/openpower/sv/bitmanip.mdwn
@@ -15,17 +15,20 @@
pseudocode: [[openpower/isa/bitmanip]]
-this extension amalgamates bitmanipulation primitives from many sources, including RISC-V bitmanip, Packed SIMD, AVX-512 and OpenPOWER VSX. Vectorisation and SIMD are removed: these are straight scalar (element) operations making them suitable for embedded applications.
+this extension amalgamates bitmanipulation primitives from many sources, including RISC-V bitmanip, Packed SIMD, AVX-512 and OpenPOWER VSX.
+Also included are DSP/Multimedia operations suitable for
+Audio/Video. Vectorisation and SIMD are removed: these are straight scalar (element) operations making them suitable for embedded applications.
Vectorisation Context is provided by [[openpower/sv]].
-When combined with SV, scalar variants of bitmanip operations found in VSX are added so that VSX may be retired as "legacy" in the far future (10 to 20 years). Also, VSX is hundreds of opcodes, requires 128 bit pathways, and is wholly unsuited to low power or embedded scenarios.
+When combined with SV, scalar variants of bitmanip operations found in VSX are added so that the Packed SIMD aspects of VSX may be retired as "legacy"
+in the far future (10 to 20 years). Also, VSX is hundreds of opcodes, requires 128 bit pathways, and is wholly unsuited to low power or embedded scenarios.
ternlogv is experimental and is the only operation that may be considered a "Packed SIMD". It is added as a variant of the already well-justified ternlog operation (done in AVX512 as an immediate only) "because it looks fun". As it is based on the LUT4 concept it will allow accelerated emulation of FPGAs. Other vendors of ISAs are buying FPGA companies to achieve similar objectives.
general-purpose Galois Field 2^M operations are added so as to avoid huge custom opcode proliferation across many areas of Computer Science. however for convenience and also to avoid setup costs, some of the more common operations (clmul, crc32) are also added. The expectation is that these operations would all be covered by the same pipeline.
note that there are brownfield spaces below that could incorporate some of the set-before-first and other scalar operations listed in [[sv/vector_ops]], and
-the [[sv/av_opcodes]] as well as [[sv/setvl]]
+the [[sv/av_opcodes]] as well as [[sv/setvl]], [[sv/svstep]], [[sv/remap]]
Useful resource:
@@ -52,7 +55,7 @@ ternlog has its own major opcode
| -00 |1 | grevlog |
| -01 | | crternlog |
| 010 |Rc| bitmask |
-| 011 | | gf/cl madd* |
+| 011 | | SVP64 |
| 110 |Rc| 1/2-op |
| 111 | | bmrevi |
@@ -88,23 +91,18 @@ ternlog has its own major opcode
TODO: convert all instructions to use RT and not RS
-| 0.5|6.8 | 9.11|12.14|15.17|18.20|21.28 | 29.30|31|name|
-| -- | -- | --- | --- | --- |-----|----- | -----|--|----|
-| NN | BT | BA | BB | BC |m0-2 | imm | 10 |m3|crternlog|
-
| 0.5|6.10|11.15|16.20 |21..25 | 26....30 |31| name |
| -- | -- | --- | --- | ----- | -------- |--| ------ |
| NN | RT | RA |itype/| im0-4 | im5-7 00 |0 | xpermi |
| NN | RT | RA | RB | im0-4 | im5-7 00 |1 | grevlog |
-| NN | | | | | ..... 01 |0 | crternlog |
+| NN | | | | | ----- 01 |m3| crternlog |
| NN | RT | RA | RB | RC | mode 010 |Rc| bitmask* |
-| NN | RS | RA | RB | RC | 00 011 |0 | gfbmadd |
-| NN | RS | RA | RB | RC | 00 011 |1 | gfbmaddsub |
-| NN | RS | RA | RB | RC | 01 011 |0 | clmadd |
-| NN | RS | RA | RB | RC | 01 011 |1 | clmaddsub |
-| NN | RS | RA | RB | RC | 10 011 |0 | gfpmadd |
-| NN | RS | RA | RB | RC | 10 011 |1 | gfpmaddsub |
-| NN | RS | RA | RB | RC | 11 011 | | rsvd |
+| NN | | | | | 00 011 | | rsvd |
+| NN | | | | | 01 011 |0 | svshape |
+| NN | | | | | 01 011 |1 | svremap |
+| NN | | | | | 10 011 |Rc| svstep |
+| NN | | | | | 11 011 |Rc| setvl |
+| NN | | | | | ---- 110 | | 1/2 ops |
| NN | RT | RA | RB | sh0-4 | sh5 1 111 |Rc| bmrevi |
ops (note that av avg and abs as well as vec scalar mask
@@ -120,20 +118,21 @@ double check that instructions didn't need 3 inputs.
| NN | RS | RB | sh | SH | 0 1 | nn00 110 |Rc| bmopsi |
| NN | RT | RA | RB | 1 | 00 | 0001 110 |Rc| cldiv |
| NN | RT | RA | RB | 1 | 01 | 0001 110 |Rc| clmod |
-| NN | RT | RA | RB | 1 | 10 | 0001 110 |Rc| |
-| NN | RT | RB | RB | 1 | 11 | 0001 110 |Rc| clinv |
+| NN | RT | RA | | 1 | 10 | 0001 110 |Rc| bmatflip |
+| NN | | | | 1 | 11 | 0001 110 |Rc| rsvd |
| NN | RA | RB | RC | 0 | 00 | 0001 110 |Rc| vec sbfm |
| NN | RA | RB | RC | 0 | 01 | 0001 110 |Rc| vec sofm |
| NN | RA | RB | RC | 0 | 10 | 0001 110 |Rc| vec sifm |
| NN | RA | RB | RC | 0 | 11 | 0001 110 |Rc| vec cprop |
+| NN | | | | 0 | | 0101 110 |Rc| rsvd |
| NN | RT | RA | RB | 1 | itype | 0101 110 |Rc| xperm |
-| NN | RA | RB | RC | 0 | itype | 0101 110 |Rc| av minmax |
-| NN | RA | RB | RC | 1 | 00 | 0101 110 |Rc| av abss |
-| NN | RA | RB | RC | 1 | 01 | 0101 110 |Rc| av absu|
-| NN | RA | RB | | 1 | 10 | 0101 110 |Rc| av avgadd |
-| NN | RA | RB | | 1 | 11 | 0101 110 |Rc| rsvd |
-| NN | RA | RB | | | | 1001 110 |Rc| rsvd |
-| NN | RA | RB | | | | 1101 110 |Rc| rsvd |
+| NN | RA | RB | RC | 0 | itype | 1001 110 |Rc| av minmax |
+| NN | RA | RB | RC | 1 | 00 | 1001 110 |Rc| av abss |
+| NN | RA | RB | RC | 1 | 01 | 1001 110 |Rc| av absu |
+| NN | RA | RB | | 1 | 10 | 1001 110 |Rc| av avgadd |
+| NN | | | | 1 | 11 | 1001 110 |Rc| rsvd |
+| NN | RT | RA | RB | 0 | sh | 1101 110 |Rc| shadd |
+| NN | RT | RA | RB | 1 | sh | 1101 110 |Rc| shadduw |
| NN | RA | RB | RC | 0 | 00 | 0010 110 |Rc| gorc |
| NN | RA | RB | sh | SH | 00 | 1010 110 |Rc| gorci |
| NN | RA | RB | RC | 0 | 00 | 0110 110 |Rc| gorcw |
@@ -145,10 +144,10 @@ double check that instructions didn't need 3 inputs.
| NN | RA | RB | RC | 0 | 01 | 0110 110 |Rc| grevw |
| NN | RA | RB | sh | 0 | 01 | 1110 110 |Rc| grevwi |
| NN | RA | RB | RC | 1 | 01 | 1110 110 |Rc| bmatxor |
-| NN | RA | RB | RC | | 10 | --10 110 |Rc| rsvd |
+| NN | | | | | 10 | --10 110 |Rc| rsvd |
| NN | RA | RB | RC | 0 | 11 | 1110 110 |Rc| clmulr |
| NN | RA | RB | RC | 1 | 11 | 1110 110 |Rc| clmulh |
-| NN | | | | | | --11 110 |Rc| setvl |
+| NN | | | | | | --11 110 |Rc| rsvd |
# ternlog bitops
@@ -204,21 +203,18 @@ another mode selection would be CRs not Ints.
| 0.5|6.8 | 9.11|12.14|15.17|18.20|21.28 | 29.30|31|
| -- | -- | --- | --- | --- |-----|----- | -----|--|
-| NN | BT | BA | BB | BC |m0-2 | imm | 10 |m3|
+| NN | BT | BA | BB | BC |m0-2 | imm | 01 |m3|
mask = m0-3,m4
for i in range(4):
- if not mask[i] continue
- crregs[BT][i] = lut3(imm,
- crregs[BA][i],
- crregs[BB][i],
- crregs[BC][i])
+ a,b,c = CRs[BA][i], CRs[BB][i], CRs[BC][i])
+ if mask[i] CRs[BT][i] = lut3(imm, a, b, c)
+# int ops
-# int min/max
+## min/m
-required for
-the [[sv/av_opcodes]]
+required for the [[sv/av_opcodes]]
signed and unsigned min/max for integer. this is sort-of partly synthesiseable in [[sv/svp64]] with pred-result as long as the dest reg is one of the sources, but not both signed and unsigned. when the dest is also one of the srces and the mv fails due to the CR bittest failing this will only overwrite the dest where the src is greater (or less).
@@ -239,8 +235,46 @@ uint_xlen_t maxu(uint_xlen_t rs1, uint_xlen_t rs2)
}
```
+## average
+
+required for the [[sv/av_opcodes]], these exist in Packed SIMD (VSX)
+but not scalar
+
+```
+uint_xlen_t intavg(uint_xlen_t rs1, uint_xlen_t rs2) {
+ return (rs1 + rs2 + 1) >> 1:
+}
+```
+
+## abs
+
+required for the [[sv/av_opcodes]], these exist in Packed SIMD (VSX)
+but not scalar
+
+```
+uint_xlen_t intabs(uint_xlen_t rs1, uint_xlen_t rs2) {
+ return (src1 > src2) ? (src1-src2) : (src2-src1)
+}
+```
+
+# shift-and-add
+
+Power ISA is missing LD/ST with shift, which is present in both ARM and x86.
+Too complex to add more LD/ST, a compromise is to add shift-and-add.
+Replaces a pair of explicit instructions in hot-loops.
-## cmix
+```
+uint_xlen_t shadd(uint_xlen_t rs1, uint_xlen_t rs2, uint8_t sh) {
+ return (rs1 << (sh+1)) + rs2;
+}
+
+uint_xlen_t shadduw(uint_xlen_t rs1, uint_xlen_t rs2, uint8_t sh) {
+ uint_xlen_t rs1z = rs1 & 0xFFFFFFFF;
+ return (rs1z << (sh+1)) + rs2;
+}
+```
+
+# cmix
based on RV bitmanip, covered by ternlog bitops
@@ -350,8 +384,8 @@ generalised reverse combined with a pair of LUT2s and allowing
a constant `0b0101...0101` when RA=0, and an option to invert
(including when RA=0, giving a constant 0b1010...1010 as the
initial value) provides a wide range of instructions
-and a means to set regular 64 bit patterns in one
-32 bit instruction.
+and a means to set hundreds of regular 64 bit patterns with one
+single 32 bit instruction.
the two LUT2s are applied left-half (when not swapping)
and right-half (when swapping) so as to allow a wider
@@ -370,7 +404,7 @@ This only requires 2 instructions (grevlut, bext).
Note that if the mask is required to be placed
directly into CR Fields (for use as CR Predicate
-masks rather than a integer mask) then sv.ori
+masks rather than a integer mask) then sv.cmpi or sv.ori
may be used instead, bearing in mind that sv.ori
is a 64-bit instruction, and `VL` must have been
set to the required length:
@@ -433,6 +467,8 @@ uint64_t grevlut64(uint64_t RA, uint64_t RB, uint8 imm, bool iv)
# grev
+superceded by grevlut
+
based on RV bitmanip, this is also known as a butterfly network. however
where a butterfly network allows setting of every crossbar setting in
every row and every column, generalised-reverse (grev) only allows
@@ -463,13 +499,54 @@ uint64_t grev64(uint64_t RA, uint64_t RB)
```
+# gorc
+
+based on RV bitmanip, gorc is superceded by grevlut
+
+```
+uint32_t gorc32(uint32_t RA, uint32_t RB)
+{
+ uint32_t x = RA;
+ int shamt = RB & 31;
+ if (shamt & 1) x |= ((x & 0x55555555) << 1) | ((x & 0xAAAAAAAA) >> 1);
+ if (shamt & 2) x |= ((x & 0x33333333) << 2) | ((x & 0xCCCCCCCC) >> 2);
+ if (shamt & 4) x |= ((x & 0x0F0F0F0F) << 4) | ((x & 0xF0F0F0F0) >> 4);
+ if (shamt & 8) x |= ((x & 0x00FF00FF) << 8) | ((x & 0xFF00FF00) >> 8);
+ if (shamt & 16) x |= ((x & 0x0000FFFF) << 16) | ((x & 0xFFFF0000) >> 16);
+ return x;
+}
+uint64_t gorc64(uint64_t RA, uint64_t RB)
+{
+ uint64_t x = RA;
+ int shamt = RB & 63;
+ if (shamt & 1) x |= ((x & 0x5555555555555555LL) << 1) |
+ ((x & 0xAAAAAAAAAAAAAAAALL) >> 1);
+ if (shamt & 2) x |= ((x & 0x3333333333333333LL) << 2) |
+ ((x & 0xCCCCCCCCCCCCCCCCLL) >> 2);
+ if (shamt & 4) x |= ((x & 0x0F0F0F0F0F0F0F0FLL) << 4) |
+ ((x & 0xF0F0F0F0F0F0F0F0LL) >> 4);
+ if (shamt & 8) x |= ((x & 0x00FF00FF00FF00FFLL) << 8) |
+ ((x & 0xFF00FF00FF00FF00LL) >> 8);
+ if (shamt & 16) x |= ((x & 0x0000FFFF0000FFFFLL) << 16) |
+ ((x & 0xFFFF0000FFFF0000LL) >> 16);
+ if (shamt & 32) x |= ((x & 0x00000000FFFFFFFFLL) << 32) |
+ ((x & 0xFFFFFFFF00000000LL) >> 32);
+ return x;
+}
+
+```
+
# xperm
based on RV bitmanip.
RA contains a vector of indices to select parts of RB to be
copied to RT. The immediate-variant allows up to an 8 bit
-pattern (repeated) to be targetted at different parts of RT
+pattern (repeated) to be targetted at different parts of RT.
+
+xperm shares some similarity with one of the uses of bmator
+in that xperm indices are binary addressing where bitmator
+may be considered to be unary addressing.
```
uint_xlen_t xpermi(uint8_t imm8, uint_xlen_t RB, int sz_log2)
@@ -507,42 +584,54 @@ uint_xlen_t xperm_w (uint_xlen_t RA, uint_xlen_t RB)
{ return xperm(RA, RB, 5); }
```
-# gorc
-
-based on RV bitmanip
+# bitmatrix
```
-uint32_t gorc32(uint32_t RA, uint32_t RB)
+uint64_t bmatflip(uint64_t RA)
{
- uint32_t x = RA;
- int shamt = RB & 31;
- if (shamt & 1) x |= ((x & 0x55555555) << 1) | ((x & 0xAAAAAAAA) >> 1);
- if (shamt & 2) x |= ((x & 0x33333333) << 2) | ((x & 0xCCCCCCCC) >> 2);
- if (shamt & 4) x |= ((x & 0x0F0F0F0F) << 4) | ((x & 0xF0F0F0F0) >> 4);
- if (shamt & 8) x |= ((x & 0x00FF00FF) << 8) | ((x & 0xFF00FF00) >> 8);
- if (shamt & 16) x |= ((x & 0x0000FFFF) << 16) | ((x & 0xFFFF0000) >> 16);
+ uint64_t x = RA;
+ x = shfl64(x, 31);
+ x = shfl64(x, 31);
+ x = shfl64(x, 31);
return x;
}
-uint64_t gorc64(uint64_t RA, uint64_t RB)
+uint64_t bmatxor(uint64_t RA, uint64_t RB)
{
- uint64_t x = RA;
- int shamt = RB & 63;
- if (shamt & 1) x |= ((x & 0x5555555555555555LL) << 1) |
- ((x & 0xAAAAAAAAAAAAAAAALL) >> 1);
- if (shamt & 2) x |= ((x & 0x3333333333333333LL) << 2) |
- ((x & 0xCCCCCCCCCCCCCCCCLL) >> 2);
- if (shamt & 4) x |= ((x & 0x0F0F0F0F0F0F0F0FLL) << 4) |
- ((x & 0xF0F0F0F0F0F0F0F0LL) >> 4);
- if (shamt & 8) x |= ((x & 0x00FF00FF00FF00FFLL) << 8) |
- ((x & 0xFF00FF00FF00FF00LL) >> 8);
- if (shamt & 16) x |= ((x & 0x0000FFFF0000FFFFLL) << 16) |
- ((x & 0xFFFF0000FFFF0000LL) >> 16);
- if (shamt & 32) x |= ((x & 0x00000000FFFFFFFFLL) << 32) |
- ((x & 0xFFFFFFFF00000000LL) >> 32);
+ // transpose of RB
+ uint64_t RBt = bmatflip(RB);
+ uint8_t u[8]; // rows of RA
+ uint8_t v[8]; // cols of RB
+ for (int i = 0; i < 8; i++) {
+ u[i] = RA >> (i*8);
+ v[i] = RBt >> (i*8);
+ }
+ uint64_t x = 0;
+ for (int i = 0; i < 64; i++) {
+ if (pcnt(u[i / 8] & v[i % 8]) & 1)
+ x |= 1LL << i;
+ }
+ return x;
+}
+uint64_t bmator(uint64_t RA, uint64_t RB)
+{
+ // transpose of RB
+ uint64_t RBt = bmatflip(RB);
+ uint8_t u[8]; // rows of RA
+ uint8_t v[8]; // cols of RB
+ for (int i = 0; i < 8; i++) {
+ u[i] = RA >> (i*8);
+ v[i] = RBt >> (i*8);
+ }
+ uint64_t x = 0;
+ for (int i = 0; i < 64; i++) {
+ if ((u[i / 8] & v[i % 8]) != 0)
+ x |= 1LL << i;
+ }
return x;
}
```
+
# Introduction to Carry-less and GF arithmetic
* obligatory xkcd
@@ -608,7 +697,7 @@ These are operations on polynomials with coefficients in `GF(2)`, with the
polynomial's coefficients packed into integers with the following algorithm:
```python
-[[!inline pagenames="openpower/sv/bitmanip/pack_poly.py" raw="yes"]]
+[[!inline pagenames="gf_reference/pack_poly.py" raw="yes"]]
```
## Carry-less Multiply Instructions
@@ -624,13 +713,13 @@ They are worth adding as their own non-overwrite operations
### `clmul` Carry-less Multiply
```python
-[[!inline pagenames="openpower/sv/bitmanip/clmul.py" raw="yes"]]
+[[!inline pagenames="gf_reference/clmul.py" raw="yes"]]
```
### `clmulh` Carry-less Multiply High
```python
-[[!inline pagenames="openpower/sv/bitmanip/clmulh.py" raw="yes"]]
+[[!inline pagenames="gf_reference/clmulh.py" raw="yes"]]
```
### `clmulr` Carry-less Multiply (Reversed)
@@ -639,7 +728,7 @@ Useful for CRCs. Equivalent to bit-reversing the result of `clmul` on
bit-reversed inputs.
```python
-[[!inline pagenames="openpower/sv/bitmanip/clmulr.py" raw="yes"]]
+[[!inline pagenames="gf_reference/clmulr.py" raw="yes"]]
```
## `clmadd` Carry-less Multiply-Add
@@ -686,7 +775,7 @@ c = (RC)
for other instructions.
```python
-[[!inline pagenames="openpower/sv/bitmanip/cldivrem.py" raw="yes"]]
+[[!inline pagenames="gf_reference/cldivrem.py" raw="yes"]]
```
## `cldiv` Carry-less Division
@@ -743,7 +832,7 @@ making it reducible, making whatever we're working on no longer a Field.
Therefore, we can reuse the LSB to indicate `degree == XLEN`.
```python
-[[!inline pagenames="openpower/sv/bitmanip/decode_reducing_polynomial.py" raw="yes"]]
+[[!inline pagenames="gf_reference/decode_reducing_polynomial.py" raw="yes"]]
```
## `gfbredpoly` -- Set the Reducing Polynomial SPR `GFBREDPOLY`
@@ -751,7 +840,7 @@ Therefore, we can reuse the LSB to indicate `degree == XLEN`.
unless this is an immediate op, `mtspr` is completely sufficient.
```python
-[[!inline pagenames="openpower/sv/bitmanip/gfbredpoly.py" raw="yes"]]
+[[!inline pagenames="gf_reference/gfbredpoly.py" raw="yes"]]
```
## `gfbmul` -- Binary Galois Field `GF(2^m)` Multiplication
@@ -761,7 +850,7 @@ gfbmul RT, RA, RB
```
```python
-[[!inline pagenames="openpower/sv/bitmanip/gfbmul.py" raw="yes"]]
+[[!inline pagenames="gf_reference/gfbmul.py" raw="yes"]]
```
## `gfbmadd` -- Binary Galois Field `GF(2^m)` Multiply-Add
@@ -771,7 +860,7 @@ gfbmadd RT, RA, RB, RC
```
```python
-[[!inline pagenames="openpower/sv/bitmanip/gfbmadd.py" raw="yes"]]
+[[!inline pagenames="gf_reference/gfbmadd.py" raw="yes"]]
```
## `gfbtmadd` -- Binary Galois Field `GF(2^m)` Twin Multiply-Add (for FFT)
@@ -803,7 +892,7 @@ gfbinv RT, RA
```
```python
-[[!inline pagenames="openpower/sv/bitmanip/gfbinv.py" raw="yes"]]
+[[!inline pagenames="gf_reference/gfbinv.py" raw="yes"]]
```
# Instructions for Prime Galois Fields `GF(p)`
@@ -817,7 +906,7 @@ gfpadd RT, RA, RB
```
```python
-[[!inline pagenames="openpower/sv/bitmanip/gfpadd.py" raw="yes"]]
+[[!inline pagenames="gf_reference/gfpadd.py" raw="yes"]]
```
the addition happens on infinite-precision integers
@@ -829,7 +918,7 @@ gfpsub RT, RA, RB
```
```python
-[[!inline pagenames="openpower/sv/bitmanip/gfpsub.py" raw="yes"]]
+[[!inline pagenames="gf_reference/gfpsub.py" raw="yes"]]
```
the subtraction happens on infinite-precision integers
@@ -841,7 +930,7 @@ gfpmul RT, RA, RB
```
```python
-[[!inline pagenames="openpower/sv/bitmanip/gfpmul.py" raw="yes"]]
+[[!inline pagenames="gf_reference/gfpmul.py" raw="yes"]]
```
the multiplication happens on infinite-precision integers
@@ -856,7 +945,7 @@ Some potential hardware implementations are found in:
```python
-[[!inline pagenames="openpower/sv/bitmanip/gfpinv.py" raw="yes"]]
+[[!inline pagenames="gf_reference/gfpinv.py" raw="yes"]]
```
## `gfpmadd` Prime Galois Field `GF(p)` Multiply-Add
@@ -866,7 +955,7 @@ gfpmadd RT, RA, RB, RC
```
```python
-[[!inline pagenames="openpower/sv/bitmanip/gfpmadd.py" raw="yes"]]
+[[!inline pagenames="gf_reference/gfpmadd.py" raw="yes"]]
```
the multiplication and addition happens on infinite-precision integers
@@ -878,7 +967,7 @@ gfpmsub RT, RA, RB, RC
```
```python
-[[!inline pagenames="openpower/sv/bitmanip/gfpmsub.py" raw="yes"]]
+[[!inline pagenames="gf_reference/gfpmsub.py" raw="yes"]]
```
the multiplication and subtraction happens on infinite-precision integers
@@ -890,7 +979,7 @@ gfpmsubr RT, RA, RB, RC
```
```python
-[[!inline pagenames="openpower/sv/bitmanip/gfpmsubr.py" raw="yes"]]
+[[!inline pagenames="gf_reference/gfpmsubr.py" raw="yes"]]
```
the multiplication and subtraction happens on infinite-precision integers
@@ -918,54 +1007,6 @@ term = (RC)
(RS) = gfpmsubr(factor1, factor2, term)
```
-# bitmatrix
-
-```
-uint64_t bmatflip(uint64_t RA)
-{
- uint64_t x = RA;
- x = shfl64(x, 31);
- x = shfl64(x, 31);
- x = shfl64(x, 31);
- return x;
-}
-uint64_t bmatxor(uint64_t RA, uint64_t RB)
-{
- // transpose of RB
- uint64_t RBt = bmatflip(RB);
- uint8_t u[8]; // rows of RA
- uint8_t v[8]; // cols of RB
- for (int i = 0; i < 8; i++) {
- u[i] = RA >> (i*8);
- v[i] = RBt >> (i*8);
- }
- uint64_t x = 0;
- for (int i = 0; i < 64; i++) {
- if (pcnt(u[i / 8] & v[i % 8]) & 1)
- x |= 1LL << i;
- }
- return x;
-}
-uint64_t bmator(uint64_t RA, uint64_t RB)
-{
- // transpose of RB
- uint64_t RBt = bmatflip(RB);
- uint8_t u[8]; // rows of RA
- uint8_t v[8]; // cols of RB
- for (int i = 0; i < 8; i++) {
- u[i] = RA >> (i*8);
- v[i] = RBt >> (i*8);
- }
- uint64_t x = 0;
- for (int i = 0; i < 64; i++) {
- if ((u[i / 8] & v[i % 8]) != 0)
- x |= 1LL << i;
- }
- return x;
-}
-
-```
-
# Already in POWER ISA
## count leading/trailing zeros with mask
@@ -981,7 +1022,7 @@ RA â EXTZ64(count)
## bit deposit
-vpdepd VRT,VRA,VRB, identical to RV bitmamip bdep, found already in v3.1 p106
+pdepd VRT,VRA,VRB, identical to RV bitmamip bdep, found already in v3.1 p106
do while(m < 64)
if VSR[VRB+32].dword[i].bit[63-m]=1 then do
@@ -1006,9 +1047,9 @@ uint_xlen_t bdep(uint_xlen_t RA, uint_xlen_t RB)
```
-# bit extract
+## bit extract
-other way round: identical to RV bext, found in v3.1 p196
+other way round: identical to RV bext: pextd, found in v3.1 p196
```
uint_xlen_t bext(uint_xlen_t RA, uint_xlen_t RB)
@@ -1024,7 +1065,7 @@ uint_xlen_t bext(uint_xlen_t RA, uint_xlen_t RB)
}
```
-# centrifuge
+## centrifuge
found in v3.1 p106 so not to be added here
@@ -1043,13 +1084,18 @@ do i = 0 to 63
RA = result
```
-# bit to byte permute
+## bit to byte permute
similar to matrix permute in RV bitmanip, which has XOR and OR variants,
-these perform a transpose.
+these perform a transpose. TODO this looks VSX is there a scalar variant
+in v3.0/1 already
do j = 0 to 7
do k = 0 to 7
b = VSR[VRB+32].dword[i].byte[k].bit[j]
VSR[VRT+32].dword[i].byte[j].bit[k] = b
+# Appendix
+
+see [[bitmanip/appendix]]
+