(no commit message)
[libreriscv.git] / openpower / sv / bitmanip.mdwn
index 3774322ed9ef3756565e2ee06db30a683a39014e..fb95b2dbfc67cc6a709b8f2a0e433bdc1a67fa18 100644 (file)
@@ -114,14 +114,8 @@ double check that instructions didn't need 3 inputs.
 
 | 0.5|6.10|11.15|16.20| 21 | 22.23 | 24....30 |31| name |
 | -- | -- | --- | --- | -- | ----- | -------- |--| ---- |
-| NN | RT | RA  | RB  | 0  |       | 0000 110 |Rc| rsvd   |
-| NN | RT | RA  | RB  | 1  | itype | 0000 110 |Rc| xperm |
-| NN | RA | RB  | RC  | 0  | itype | 0100 110 |Rc| minmax |
-| NN | RA | RB  | RC  | 1  |   00  | 0100 110 |Rc| av avgadd |
-| NN | RA | RB  | RC  | 1  |   01  | 0100 110 |Rc| av abs |
-| NN | RA | RB  |     | 1  |   10  | 0100 110 |Rc| rsvd |
-| NN | RA | RB  |     | 1  |   11  | 0100 110 |Rc| rsvd |
-| NN | RA | RB  | sh  | SH | itype | 1000 110 |Rc| bmopsi |
+| NN | RS | me  | sh  | SH | ME 0  | nn00 110 |Rc| bmopsi |
+| NN | RS | RB  | sh  | SH | /   0 | nn00 110 |Rc| bmopsi |
 | NN | RT | RA  | RB  |    |       | 1100 110 |Rc| srsvd |
 | NN | RT | RA  | RB  | 1  |  00   | 0001 110 |Rc| cldiv |
 | NN | RT | RA  | RB  | 1  |  01   | 0001 110 |Rc| clmod |
@@ -131,7 +125,12 @@ double check that instructions didn't need 3 inputs.
 | 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 | RA | RB  |     | 0  |       | 0101 110 |Rc| rsvd |
+| NN | RT | RA  | RB  | 1  | itype | 0101 110 |Rc| xperm |
+| NN | RA | RB  | RC  | 0  | itype | 0101 110 |Rc| minmax |
+| NN | RA | RB  | RC  | 1  |   00  | 0101 110 |Rc| av avgadd |
+| NN | RA | RB  | RC  | 1  |   01  | 0101 110 |Rc| av abs |
+| NN | RA | RB  |     | 1  |   10  | 0101 110 |Rc| rsvd |
+| NN | RA | RB  |     | 1  |   11  | 0101 110 |Rc| rsvd |
 | 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 |
@@ -270,25 +269,36 @@ Immediate-variant is an overwrite form:
 | NN | RS | RB  | sh  | SH | itype | 1000 110 |Rc| bm*i |
 
 ```
+def MASK(x, y):
+     if x < y:
+         x = x+1
+         mask_a = ((1 << x) - 1) & ((1 << 64) - 1)
+         mask_b = ((1 << y) - 1) & ((1 << 64) - 1)
+     elif x == y:
+         return 1 << x
+     else:
+         x = x+1
+         mask_a = ((1 << x) - 1) & ((1 << 64) - 1)
+         mask_b = (~((1 << y) - 1)) & ((1 << 64) - 1)
+     return mask_a ^ mask_b
+
+
 uint_xlen_t bmset(RS, RB, sh)
 {
     int shamt = RB & (XLEN - 1);
-    mask = (2<<sh)-1;
-    return RS | (mask << shamt);
+    return RS | MASK(shamt, sh)
 }
 
 uint_xlen_t bmclr(RS, RB, sh)
 {
     int shamt = RB & (XLEN - 1);
-    mask = (2<<sh)-1;
-    return RS & ~(mask << shamt);
+    return RS & ~MASK(shamt, sh)
 }
 
 uint_xlen_t bminv(RS, RB, sh)
 {
     int shamt = RB & (XLEN - 1);
-    mask = (2<<sh)-1;
-    return RS ^ (mask << shamt);
+    return RS ^ MASK(shamt, sh)
 }
 
 uint_xlen_t bmext(RS, RB, sh)
@@ -299,7 +309,7 @@ uint_xlen_t bmext(RS, RB, sh)
 }
 ```
 
-bitmask extract with reverse.  can be done by bitinverting all of RB and getting bits of RB from the opposite end.
+bitmask extract with reverse.  can be done by bit-order-inverting all of RB and getting bits of RB from the opposite end.
 
 when RA is zero, no shift occurs. this makes bmextrev useful for
 simply reversing all bits of a register.
@@ -312,7 +322,7 @@ rt = ZE(rev[msb:0]);
 uint_xlen_t bmextrev(RA, RB, sh)
 {
     int shamt = XLEN-1;
-    if (RA != 0) (GPR(RA) & (XLEN - 1));
+    if (RA != 0) shamt = (GPR(RA) & (XLEN - 1));
     shamt = (XLEN-1)-shamt;  # shift other end
     bra = bitreverse(RB)     # swap LSB-MSB
     mask = (2<<sh)-1;