do proper rounding, no rounding for SH=0 (for now), add tests
[openpower-isa.git] / openpower / isa / bitmanip.mdwn
1 <!-- Draft Instructions here described in -->
2 <!-- https://libre-soc.org/openpower/sv/bitmanip/ -->
3 <!-- These instructions are *not yet official* -->
4
5 # Ternary Bitwise Logic Immediate
6
7 TLI-Form
8
9 * ternlogi RT,RA,RB,TLI (Rc=0)
10 * ternlogi. RT,RA,RB,TLI (Rc=1)
11
12 Pseudo-code:
13
14 result <- [0] * XLEN
15 do i = 0 to XLEN - 1
16 idx <- (RT)[i] || (RA)[i] || (RB)[i]
17 result[i] <- TLI[7-idx]
18 RT <- result
19
20 Special Registers Altered:
21
22 CR0 (if Rc=1)
23
24 # Generalized Bit-Reverse
25
26 X-Form
27
28 * grev RT,RA,RB (Rc=0)
29 * grev. RT,RA,RB (Rc=1)
30
31 Pseudo-code:
32
33 result <- [0] * XLEN
34 b <- EXTZ64(RB)
35 do i = 0 to XLEN - 1
36 idx <- b[64-log2(XLEN):63] ^ i
37 result[i] <- (RA)[idx]
38 RT <- result
39
40 Special Registers Altered:
41
42 CR0 (if Rc=1)
43
44 # Generalized Bit-Reverse Immediate
45
46 XB-Form
47
48 * grevi RT,RA,XBI (Rc=0)
49 * grevi. RT,RA,XBI (Rc=1)
50
51 Pseudo-code:
52
53 result <- [0] * XLEN
54 do i = 0 to XLEN - 1
55 idx <- XBI[6-log2(XLEN):5] ^ i
56 result[i] <- (RA)[idx]
57 RT <- result
58
59 Special Registers Altered:
60
61 CR0 (if Rc=1)
62
63 # Generalized Bit-Reverse Word
64
65 X-Form
66
67 * grevw RT,RA,RB (Rc=0)
68 * grevw. RT,RA,RB (Rc=1)
69
70 Pseudo-code:
71
72 result <- [0] * (XLEN / 2)
73 a <- (RA)[XLEN/2:XLEN-1]
74 b <- EXTZ64(RB)
75 do i = 0 to XLEN / 2 - 1
76 idx <- b[64-log2(XLEN/2):63] ^ i
77 result[i] <- a[idx]
78 RT <- ([0] * (XLEN / 2)) || result
79
80 Special Registers Altered:
81
82 CR0 (if Rc=1)
83
84 # Generalized Bit-Reverse Word Immediate
85
86 X-Form
87
88 * grevwi RT,RA,SH (Rc=0)
89 * grevwi. RT,RA,SH (Rc=1)
90
91 Pseudo-code:
92
93 result <- [0] * (XLEN / 2)
94 a <- (RA)[XLEN/2:XLEN-1]
95 do i = 0 to XLEN / 2 - 1
96 idx <- SH[5-log2(XLEN/2):4] ^ i
97 result[i] <- a[idx]
98 RT <- ([0] * (XLEN / 2)) || result
99
100 Special Registers Altered:
101
102 CR0 (if Rc=1)
103
104 # Add With Shift By Immediate
105
106 Z23-Form
107
108 * shadd RT,RA,RB,sm (Rc=0)
109 * shadd. RT,RA,RB,sm (Rc=1)
110
111 Pseudo-code:
112
113 n <- (RB)
114 m <- ((0b0 || sm) + 1)
115 RT <- (n[m:XLEN-1] || [0]*m) + (RA)
116
117 Special Registers Altered:
118
119 CR0 (if Rc=1)
120
121 # Add With Shift By Immediate Word
122
123 Z23-Form
124
125 * shaddw RT,RA,RB,sm (Rc=0)
126 * shaddw. RT,RA,RB,sm (Rc=1)
127
128 Pseudo-code:
129
130 n <- ([0]*(XLEN/2)) || (RB)[XLEN/2:XLEN-1]
131 if (RB)[XLEN/2] = 1 then
132 n[0:XLEN/2-1] <- [1]*(XLEN/2)
133 m <- ((0b0 || sm) + 1)
134 RT <- (n[m:XLEN-1] || [0]*m) + (RA)
135
136 Special Registers Altered:
137
138 CR0 (if Rc=1)
139
140 # Add With Shift By Immediate Unsigned Word
141
142 Z23-Form
143
144 * shadduw RT,RA,RB,sm (Rc=0)
145 * shadduw. RT,RA,RB,sm (Rc=1)
146
147 Pseudo-code:
148
149 n <- ([0]*(XLEN/2)) || (RB)[XLEN/2:XLEN-1]
150 m <- ((0b0 || sm) + 1)
151 RT <- (n[m:XLEN-1] || [0]*m) + (RA)
152
153 Special Registers Altered:
154
155 CR0 (if Rc=1)