069a995c06f72da641888ed3959e247c051d97dd
[openpower-isa.git] / openpower / isa / fixedlogical.mdwn
1 <!-- This defines instructions described in PowerISA Version 3.0 B Book 1 -->
2
3 <!-- Section 3.3.13 Fixed-Point Logical Instructions page 92 - 100 -->
4
5 <!-- The Logical instructions perform bit-parallel operations on 64-bit operands. -->
6
7 <!-- The X-form Logical instructions with Rc=1, and the D-form Logical instructions -->
8 <!-- andi. and andis., set the first three bits of CR Field 0 as described in -->
9 <!-- Section 3.3.8, “Other Fixed-Point Instructions” on page 66. The Logical -->
10 <!-- instructions do not change the SO, OV, OV32, CA, and CA32 bits in the XER. -->
11
12
13 # AND Immediate
14
15 D-Form
16
17 * andi. RA,RS,UI
18
19 Pseudo-code:
20
21 RA <- (RS) & ([0]*(XLEN-16) || UI)
22
23 Special Registers Altered:
24
25 CR0
26
27 # OR Immediate
28
29 D-Form
30
31 * ori RA,RS,UI
32
33 Pseudo-code:
34
35 RA <- (RS) | ([0]*(XLEN-16) || UI)
36
37 Special Registers Altered:
38
39 None
40
41 # AND Immediate Shifted
42
43 D-Form
44
45 * andis. RA,RS,UI
46
47 Pseudo-code:
48
49 RA <- (RS) & ([0]*(XLEN-32) || UI || [0]*16)
50
51 Special Registers Altered:
52
53 CR0
54
55 # OR Immediate Shifted
56
57 D-Form
58
59 * oris RA,RS,UI
60
61 Pseudo-code:
62
63 RA <- (RS) | ([0]*(XLEN-32) || UI || [0]*16)
64
65 Special Registers Altered:
66
67 None
68
69 # XOR Immediate Shifted
70
71 D-Form
72
73 * xoris RA,RS,UI
74
75 Pseudo-code:
76
77 RA <- (RS) ^ ([0]*(XLEN-32) || UI || [0]*16)
78
79 Special Registers Altered:
80
81 None
82
83 # XOR Immediate
84
85 D-Form
86
87 * xori RA,RS,UI
88
89 Pseudo-code:
90
91 RA <- (RS) ^ ([0]*(XLEN-16) || UI)
92
93 Special Registers Altered:
94
95 None
96
97 # AND
98
99 X-Form
100
101 * and RA,RS,RB (Rc=0)
102 * and. RA,RS,RB (Rc=1)
103
104 Pseudo-code:
105
106 RA <- (RS) & (RB)
107
108 Special Registers Altered:
109
110 CR0 (if Rc=1)
111
112 # OR
113
114 X-Form
115
116 * or RA,RS,RB (Rc=0)
117 * or. RA,RS,RB (Rc=1)
118
119 Pseudo-code:
120
121 RA <- (RS) | (RB)
122
123 Special Registers Altered:
124
125 CR0 (if Rc=1)
126
127 # XOR
128
129 X-Form
130
131 * xor RA,RS,RB (Rc=0)
132 * xor. RA,RS,RB (Rc=1)
133
134 Pseudo-code:
135
136 RA <- (RS) ^ (RB)
137
138 Special Registers Altered:
139
140 CR0 (if Rc=1)
141
142 # NAND
143
144 X-Form
145
146 * nand RA,RS,RB (Rc=0)
147 * nand. RA,RS,RB (Rc=1)
148
149 Pseudo-code:
150
151 RA <- ¬((RS) & (RB))
152
153 Special Registers Altered:
154
155 CR0 (if Rc=1)
156
157 # NOR
158
159 X-Form
160
161 * nor RA,RS,RB (Rc=0)
162 * nor. RA,RS,RB (Rc=1)
163
164 Pseudo-code:
165
166 RA <- ¬((RS) | (RB))
167
168 Special Registers Altered:
169
170 CR0 (if Rc=1)
171
172 # Equivalent
173
174 X-Form
175
176 * eqv RA,RS,RB (Rc=0)
177 * eqv. RA,RS,RB (Rc=1)
178
179 Pseudo-code:
180
181 RA <- ¬((RS) ^ (RB))
182
183 Special Registers Altered:
184
185 CR0 (if Rc=1)
186
187 # AND with Complement
188
189 X-Form
190
191 * andc RA,RS,RB (Rc=0)
192 * andc. RA,RS,RB (Rc=1)
193
194 Pseudo-code:
195
196 RA <- (RS) & ¬(RB)
197
198 Special Registers Altered:
199
200 CR0 (if Rc=1)
201
202 # OR with Complement
203
204 X-Form
205
206 * orc RA,RS,RB (Rc=0)
207 * orc. RA,RS,RB (Rc=1)
208
209 Pseudo-code:
210
211 RA <- (RS) | ¬(RB)
212
213 Special Registers Altered:
214
215 CR0 (if Rc=1)
216
217 # Extend Sign Byte
218
219 X-Form
220
221 * extsb RA,RS (Rc=0)
222 * extsb. RA,RS (Rc=1)
223
224 Pseudo-code:
225
226 s <- (RS)[56]
227 RA[56:63] <- (RS)[56:63]
228 RA[0:55] <- [s]*56
229
230 Special Registers Altered:
231
232 CR0 (if Rc=1)
233
234 # Extend Sign Halfword
235
236 X-Form
237
238 * extsh RA,RS (Rc=0)
239 * extsh. RA,RS (Rc=1)
240
241 Pseudo-code:
242
243 s <- (RS)[48]
244 RA[48:63] <- (RS)[48:63]
245 RA[0:47] <- [s]*48
246
247 Special Registers Altered:
248
249 CR0 (if Rc=1)
250
251 # Count Leading Zeros Word
252
253 X-Form
254
255 * cntlzw RA,RS (Rc=0)
256 * cntlzw. RA,RS (Rc=1)
257
258 Pseudo-code:
259
260 n <- 32
261 do while n < 64
262 if (RS)[n] = 1 then
263 leave
264 n <- n + 1
265 RA <- n - 32
266
267 Special Registers Altered:
268
269 CR0 (if Rc=1)
270
271 # Count Trailing Zeros Word
272
273 X-Form
274
275 * cnttzw RA,RS (Rc=0)
276 * cnttzw. RA,RS (Rc=1)
277
278 Pseudo-code:
279
280 n <- 0
281 do while n < 32
282 if (RS)[63-n] = 0b1 then
283 leave
284 n <- n + 1
285 RA <- EXTZ64(n)
286
287 Special Registers Altered:
288
289 CR0 (if Rc=1)
290
291 # Compare Bytes
292
293 X-Form
294
295 * cmpb RA,RS,RB
296
297 Pseudo-code:
298
299 do n = 0 to 7
300 if RS[8*n:8* n+7] = (RB)[8*n:8*n+7] then
301 RA[8*n:8* n+7] <- [1]*8
302 else
303 RA[8*n:8* n+7] <- [0]*8
304
305 Special Registers Altered:
306
307 None
308
309 # Population Count Bytes
310
311 X-Form
312
313 * popcntb RA, RS
314
315 Pseudo-code:
316
317 do i = 0 to 7
318 n <- 0
319 do j = 0 to 7
320 if (RS)[(i*8)+j] = 1 then
321 n <- n+1
322 RA[(i*8):(i*8)+7] <- n
323
324 Special Registers Altered:
325
326 None
327
328 # Population Count Words
329
330 X-Form
331
332 * popcntw RA, RS
333
334 Pseudo-code:
335
336 do i = 0 to 1
337 n <- 0
338 do j = 0 to 31
339 if (RS)[(i*32)+j] = 1 then
340 n <- n+1
341 RA[(i*32):(i*32)+31] <- n
342
343 Special Registers Altered:
344
345 None
346
347 # Parity Doubleword
348
349 X-Form
350
351 * prtyd RA,RS
352
353 Pseudo-code:
354
355 s <- 0
356 do i = 0 to 7
357 s <- s ^ (RS)[i*8+7]
358 RA <- [0] * 63 || s
359
360 Special Registers Altered:
361
362 None
363
364 # Parity Word
365
366 X-Form
367
368 * prtyw RA,RS
369
370 Pseudo-code:
371
372 s <- 0
373 t <- 0
374 do i = 0 to 3
375 s <- s ^ (RS)[i*8+7]
376 do i = 4 to 7
377 t <- t ^ (RS)[i*8+7]
378 RA[0:31] <- [0]*31 || s
379 RA[32:63] <- [0]*31 || t
380
381 Special Registers Altered:
382
383 None
384
385 # Extend Sign Word
386
387 X-Form
388
389 * extsw RA,RS (Rc=0)
390 * extsw. RA,RS (Rc=1)
391
392 Pseudo-code:
393
394 s <- (RS)[32]
395 RA[32:63] <- (RS)[32:63]
396 RA[0:31] <- [s]*32
397
398 Special Registers Altered:
399
400 CR0 (if Rc=1)
401
402 # Population Count Doubleword
403
404 X-Form
405
406 * popcntd RA, RS
407
408 Pseudo-code:
409
410 n <- 0
411 do i = 0 to 63
412 if (RS)[i] = 1 then
413 n <- n+1
414 RA <- n
415
416 Special Registers Altered:
417
418 None
419
420 # Count Leading Zeros Doubleword
421
422 X-Form
423
424 * cntlzd RA,RS (Rc=0)
425 * cntlzd. RA,RS (Rc=1)
426
427 Pseudo-code:
428
429 n <- 0
430 do while n < 64
431 if (RS)[n] = 1 then
432 leave
433 n <- n + 1
434 RA <- n
435
436 Special Registers Altered:
437
438 CR0 (if Rc=1)
439
440 # Count Trailing Zeros Doubleword
441
442 X-Form
443
444 * cnttzd RA,RS (Rc=0)
445 * cnttzd. RA,RS (Rc=1)
446
447 Pseudo-code:
448
449 n <- 0
450 do while n < 64
451 if (RS)[63-n] = 0b1 then
452 leave
453 n <- n + 1
454 RA <- EXTZ64(n)
455
456 Special Registers Altered:
457
458 CR0 (if Rc=1)
459
460 # Bit Permute Doubleword
461
462 X-Form
463
464 * bpermd RA,RS,RB]
465
466 Pseudo-code:
467
468 perm <- [0] * 8
469 for i = 0 to 7
470 index <- (RS)[8*i:8*i+7]
471 if index <u 64 then
472 perm[i] <- (RB)[index]
473 else
474 perm[i] <- 0
475 RA <- [0]*56 || perm[0:7]
476
477 Special Registers Altered:
478
479 None
480
481 <!-- Checked March 2021 -->