Introduction
PowerPC is a load-store architecture: arithmetic works on registers (the 32 general registers r0 to r31), and only the
load and store instructions touch memory. Most instructions name a destination and two sources, three registers in all.
In a 32-bit implementation the registers are 32 bits wide; in a 64-bit one they are 64 bits wide and the word instructions (add, slw,
cmpw) work on the low 32 bits, while the doubleword instructions (mulld, sld, rldicl) are
available only on 64-bit models (the “Available in” column says 64-bit).
Many entries have suffixed forms, written in the Mnemonic column. A trailing dot (add.) is the record form: it also sets
cr0 to the sign of the result (LT, GT, EQ) and a copy of XER[SO]. An o (addo) enables overflow detection: the instruction sets
XER[OV] and the sticky XER[SO]; addo. does both. Instructions that carry set or use XER[CA].
Several instructions are best read by their simplified mnemonics.
In the table, rt and rs are the same bits of the word (the destination when written, the source when read), ra and rb are the other registers,
si is a signed 16-bit immediate and ui an unsigned one. ra0 in a manual is ra where the value 0 replaces register r0; the table writes ra and notes it.
Arithmetic
| Mnemonic | Operands | Form and opcode | Available in | What it does |
|---|---|---|---|---|
addi | rt, ra, si | D 14 | all PowerPC | Add immediate (a zero ra means the value 0: li). |
addis | rt, ra, si | D 15 | all PowerPC | Add immediate shifted left 16 (lis). |
addic | rt, ra, si | D 12 | all PowerPC | Add immediate carrying. |
addic. | rt, ra, si | D 13 | all PowerPC | Add immediate carrying and record. |
addpcis | rt, d | DX 19/2 | ISA 3.0 and later | Add the immediate shifted left 16 to the address of the next instruction. |
subfic | rt, ra, si | D 8 | all PowerPC | Subtract from immediate carrying. |
mulli | rt, ra, si | D 7 | all PowerPC | Multiply low immediate. |
add, add., addo, addo. | rt, ra, rb | XO 31/266 | all PowerPC | Add. |
addc, addc., addco, addco. | rt, ra, rb | XO 31/10 | all PowerPC | Add carrying. |
adde, adde., addeo, addeo. | rt, ra, rb | XO 31/138 | all PowerPC | Add extended (with carry). |
addme, addme., addmeo, addmeo. | rt, ra | XO 31/234 | all PowerPC | Add to minus one extended. |
addze, addze., addzeo, addzeo. | rt, ra | XO 31/202 | all PowerPC | Add to zero extended. |
addex | rt, ra, rb, cy | Z23 31/170 | ISA 3.0 and later | Add extended using the OV bit as the carry. |
subf, subf., subfo, subfo. | rt, ra, rb | XO 31/40 | all PowerPC | Subtract from: rb - ra (sub rt, rb, ra). |
subfc, subfc., subfco, subfco. | rt, ra, rb | XO 31/8 | all PowerPC | Subtract from carrying. |
subfe, subfe., subfeo, subfeo. | rt, ra, rb | XO 31/136 | all PowerPC | Subtract from extended. |
subfme, subfme., subfmeo, subfmeo. | rt, ra | XO 31/232 | all PowerPC | Subtract from minus one extended. |
subfze, subfze., subfzeo, subfzeo. | rt, ra | XO 31/200 | all PowerPC | Subtract from zero extended. |
neg, neg., nego, nego. | rt, ra | XO 31/104 | all PowerPC | Negate. |
mullw, mullw., mullwo, mullwo. | rt, ra, rb | XO 31/235 | all PowerPC | Multiply low word. |
mulhw, mulhw. | rt, ra, rb | XO 31/75 | all PowerPC | Multiply high word (signed). |
mulhwu, mulhwu. | rt, ra, rb | XO 31/11 | all PowerPC | Multiply high word unsigned. |
mulld, mulld., mulldo, mulldo. | rt, ra, rb | XO 31/233 | 64-bit | Multiply low doubleword. |
mulhd, mulhd. | rt, ra, rb | XO 31/73 | 64-bit | Multiply high doubleword. |
mulhdu, mulhdu. | rt, ra, rb | XO 31/9 | 64-bit | Multiply high doubleword unsigned. |
divw, divw., divwo, divwo. | rt, ra, rb | XO 31/491 | all PowerPC | Divide word (signed). |
divwu, divwu., divwuo, divwuo. | rt, ra, rb | XO 31/459 | all PowerPC | Divide word unsigned. |
divwe, divwe., divweo, divweo. | rt, ra, rb | XO 31/427 | ISA 2.06 and later | Divide word extended: (ra << 32) / rb. |
divweu, divweu., divweuo, divweuo. | rt, ra, rb | XO 31/395 | ISA 2.06 and later | Divide word extended unsigned. |
divd, divd., divdo, divdo. | rt, ra, rb | XO 31/489 | 64-bit | Divide doubleword (signed). |
divdu, divdu., divduo, divduo. | rt, ra, rb | XO 31/457 | 64-bit | Divide doubleword unsigned. |
divde, divde., divdeo, divdeo. | rt, ra, rb | XO 31/425 | 64-bit, ISA 2.06 and later | Divide doubleword extended: (ra << 64) / rb. |
divdeu, divdeu., divdeuo, divdeuo. | rt, ra, rb | XO 31/393 | 64-bit, ISA 2.06 and later | Divide doubleword extended unsigned. |
modsw | rt, ra, rb | X 31/779 | ISA 3.0 and later | Modulo signed word. |
moduw | rt, ra, rb | X 31/267 | ISA 3.0 and later | Modulo unsigned word. |
modsd | rt, ra, rb | X 31/777 | ISA 3.0 and later, 64-bit | Modulo signed doubleword. |
modud | rt, ra, rb | X 31/265 | ISA 3.0 and later, 64-bit | Modulo unsigned doubleword. |
maddhd | rt, ra, rb, rc | VA 4/48 | ISA 3.0 and later | Multiply-add high doubleword. |
maddhdu | rt, ra, rb, rc | VA 4/49 | ISA 3.0 and later | Multiply-add high doubleword unsigned. |
maddld | rt, ra, rb, rc | VA 4/51 | ISA 3.0 and later | Multiply-add low doubleword. |
darn | rt, l | X 31/755 | ISA 3.0 and later, 64-bit | Deliver a random number (conditioned, raw or 32-bit). |
Compare
A compare writes one condition register field, bf (cr0 if left out), with LT, GT, EQ and a copy of XER[SO]. The l operand chooses a 32-bit
(0) or 64-bit (1) comparison; the simplified mnemonics cmpw, cmpd, cmplw, cmpld, cmpwi and cmpdi write it.
| Mnemonic | Operands | Form and opcode | Available in | What it does |
|---|---|---|---|---|
cmpi | bf, l, ra, si | D 11 | all PowerPC | Compare immediate (signed). |
cmpli | bf, l, ra, ui | D 10 | all PowerPC | Compare logical immediate (unsigned). |
cmp | bf, l, ra, rb | X 31/0 | all PowerPC | Compare (signed). |
cmpl | bf, l, ra, rb | X 31/32 | all PowerPC | Compare logical (unsigned). |
cmprb | bf, l, ra, rb | X 31/192 | ISA 3.0 and later | Compare ranges of bytes. |
cmpeqb | bf, ra, rb | X 31/224 | ISA 3.0 and later | Compare equal byte: any byte of rb equals the low byte of ra. |
cmpb | ra, rs, rb | X 31/508 | ISA 2.05 and later | Compare bytes: each byte of ra is FF where the bytes of rs and rb are equal. |
Trap
A trap instruction raises a trap exception when a comparison of its operands is true under the condition bits of to (5 bits: less than, greater than, equal,
unsigned less than, unsigned greater than). The simplified mnemonics (twlt, tweqi, tdgti ...) name the condition, and trap is tw 31, 0, 0, the
unconditional trap used for breakpoints.
| Mnemonic | Operands | Form and opcode | Available in | What it does |
|---|---|---|---|---|
twi | to, ra, si | D 3 | all PowerPC | Trap word immediate. |
tdi | to, ra, si | D 2 | 64-bit | Trap doubleword immediate. |
tw | to, ra, rb | X 31/4 | all PowerPC | Trap word. |
td | to, ra, rb | X 31/68 | 64-bit | Trap doubleword. |
Logical, sign extension and bit counting
The logical instructions write ra and read rs (the manuals' names), the reverse of the arithmetic ones.
| Mnemonic | Operands | Form and opcode | Available in | What it does |
|---|---|---|---|---|
ori | ra, rs, ui | D 24 | all PowerPC | OR immediate. ori 0, 0, 0 is nop. |
oris | ra, rs, ui | D 25 | all PowerPC | OR immediate shifted left 16. |
xori | ra, rs, ui | D 26 | all PowerPC | XOR immediate. |
xoris | ra, rs, ui | D 27 | all PowerPC | XOR immediate shifted left 16. |
andi. | ra, rs, ui | D 28 | all PowerPC | AND immediate and record (always sets cr0). |
andis. | ra, rs, ui | D 29 | all PowerPC | AND immediate shifted left 16 and record. |
and, and. | ra, rs, rb | X 31/28 | all PowerPC | AND. |
andc, andc. | ra, rs, rb | X 31/60 | all PowerPC | AND with complement. |
or, or. | ra, rs, rb | X 31/444 | all PowerPC | OR. or ra, rs, rs is mr. |
orc, orc. | ra, rs, rb | X 31/412 | all PowerPC | OR with complement. |
xor, xor. | ra, rs, rb | X 31/316 | all PowerPC | XOR. |
nand, nand. | ra, rs, rb | X 31/476 | all PowerPC | NAND. |
nor, nor. | ra, rs, rb | X 31/124 | all PowerPC | NOR. nor ra, rs, rs is not. |
eqv, eqv. | ra, rs, rb | X 31/284 | all PowerPC | Equivalent (XNOR). |
extsb, extsb. | ra, rs | X 31/954 | all PowerPC | Extend sign byte. |
extsh, extsh. | ra, rs | X 31/922 | all PowerPC | Extend sign halfword. |
extsw, extsw. | ra, rs | X 31/986 | 64-bit | Extend sign word. |
cntlzw, cntlzw. | ra, rs | X 31/26 | all PowerPC | Count leading zeros word. |
cntlzd, cntlzd. | ra, rs | X 31/58 | 64-bit | Count leading zeros doubleword. |
cnttzw, cnttzw. | ra, rs | X 31/538 | ISA 3.0 and later | Count trailing zeros word. |
cnttzd, cnttzd. | ra, rs | X 31/570 | ISA 3.0 and later, 64-bit | Count trailing zeros doubleword. |
popcntb | ra, rs | X 31/122 | ISA 2.03 and later | Population count bytes. |
popcntw | ra, rs | X 31/378 | ISA 2.06 and later | Population count words. |
popcntd | ra, rs | X 31/506 | ISA 2.06 and later, 64-bit | Population count doubleword. |
prtyw | ra, rs | X 31/154 | ISA 2.05 and later | Parity word. |
prtyd | ra, rs | X 31/186 | ISA 2.05 and later, 64-bit | Parity doubleword. |
bpermd | ra, rs, rb | X 31/252 | ISA 2.06 and later, 64-bit | Bit permute doubleword. |
isel | rt, ra, rb, bc | A 31/15 | ISA 2.03 and later | Integer select: ra if the CR bit BC is set, else rb (a zero ra means the value 0). Written isellt, iselgt, iseleq for the first three bits. |
Rotate and shift
The rotate instructions rotate rs left, then combine it with a mask of ones from bit mb to bit me (in the manuals' numbering, bit 0 on the left of the
32-bit word); the shifts are special cases of them, and the simplified mnemonics name the useful ones (slwi, srwi, clrlwi, rotlwi, extrdi ...).
The doubleword rotates take a 6-bit shift and mask (sh, mb or me), written in the instruction word with its high bit in a separate position.
| Mnemonic | Operands | Form and opcode | Available in | What it does |
|---|---|---|---|---|
rlwimi, rlwimi. | ra, rs, sh, mb, me | M 20 | all PowerPC | Rotate left word immediate then mask insert. |
rlwinm, rlwinm. | ra, rs, sh, mb, me | M 21 | all PowerPC | Rotate left word immediate then AND with mask. |
rlwnm, rlwnm. | ra, rs, rb, mb, me | M 23 | all PowerPC | Rotate left word then AND with mask (the count is in rb). |
rldicl, rldicl. | ra, rs, sh, mb | MD 30/0 | 64-bit | Rotate left doubleword immediate then clear left. |
rldicr, rldicr. | ra, rs, sh, me | MD 30/1 | 64-bit | Rotate left doubleword immediate then clear right. |
rldic, rldic. | ra, rs, sh, mb | MD 30/2 | 64-bit | Rotate left doubleword immediate then clear. |
rldimi, rldimi. | ra, rs, sh, mb | MD 30/3 | 64-bit | Rotate left doubleword immediate then mask insert. |
rldcl, rldcl. | ra, rs, rb, mb | MDS 30/8 | 64-bit | Rotate left doubleword then clear left. |
rldcr, rldcr. | ra, rs, rb, me | MDS 30/9 | 64-bit | Rotate left doubleword then clear right. |
slw, slw. | ra, rs, rb | X 31/24 | all PowerPC | Shift left word. |
srw, srw. | ra, rs, rb | X 31/536 | all PowerPC | Shift right word. |
sraw, sraw. | ra, rs, rb | X 31/792 | all PowerPC | Shift right algebraic word (sets XER[CA]). |
srawi, srawi. | ra, rs, sh | X 31/824 | all PowerPC | Shift right algebraic word immediate. |
sld, sld. | ra, rs, rb | X 31/27 | 64-bit | Shift left doubleword. |
srd, srd. | ra, rs, rb | X 31/539 | 64-bit | Shift right doubleword. |
srad, srad. | ra, rs, rb | X 31/794 | 64-bit | Shift right algebraic doubleword. |
sradi, sradi. | ra, rs, sh | XS 31/413 | 64-bit | Shift right algebraic doubleword immediate. |
extswsli, extswsli. | ra, rs, sh | XS 31/445 | ISA 3.0 and later, 64-bit | Extend sign word and shift left immediate. |
Special registers and the time base
mfspr and mtspr move between a general register and a special-purpose register (SPR). The user-level ones are XER (1), LR (8), CTR (9), VRSAVE (256)
and the time base (268, 269); the supervisor registers are on the supervisor page. With simplified mnemonics on, the explorer writes
mflr r0 for mfspr r0, 8, mtctr r9, mtxer, mfsrr0 and so on.
| Mnemonic | Operands | Form and opcode | Available in | What it does |
|---|---|---|---|---|
mfspr | rt, spr | XFX 31/339 | all PowerPC | Move from special-purpose register. |
mtspr | spr, rs | XFX 31/467 | all PowerPC | Move to special-purpose register. |
mftb | rt, tbr | XFX 31/371 | all PowerPC | Move from time base (mftb and mftbu for the low and upper halves). |
Simplified mnemonics
With simplified mnemonics on (the default) the explorer writes these instead of the encoded form; with them off it shows the instruction as encoded. The branch ones are on the branches page.
| Simplified | Encoded as |
|---|---|
li rt, si, lis rt, si | addi rt, 0, si, addis rt, 0, si |
nop | ori 0, 0, 0 |
mr ra, rs, not ra, rs | or ra, rs, rs, nor ra, rs, rs |
sub rt, ra, rb, subc rt, ra, rb | subf rt, rb, ra, subfc rt, rb, ra |
slwi ra, rs, n | rlwinm ra, rs, n, 0, 31-n |
srwi ra, rs, n | rlwinm ra, rs, 32-n, n, 31 |
clrlwi ra, rs, n, clrrwi ra, rs, n | rlwinm ra, rs, 0, n, 31, rlwinm ra, rs, 0, 0, 31-n |
rotlwi ra, rs, n, rotlw ra, rs, rb | rlwinm ra, rs, n, 0, 31, rlwnm ra, rs, rb, 0, 31 |
clrlslwi, insrwi | Other forms of rlwinm and rlwimi. |
clrldi, rotldi, srdi, sldi, clrrdi, extldi, extrdi, insrdi, rotld | The same for the doubleword rotates rldicl, rldicr, rldimi, rldcl. |
cmpwi, cmplwi, cmpw, cmplw | cmpi, cmpli, cmp, cmpl with l = 0 (and cmpdi and the others with l = 1). |
trap, tweq, twlti ... | tw 31, 0, 0 and the condition forms of tw, twi, td, tdi. |
mflr, mtlr, mfctr, mtctr, mfxer ... | mfspr and mtspr with the register number. |
mtcr rs | mtcrf 255, rs |
Not described
Known, not yet covered
- Reference and viewer: the Book E and embedded integer instructions (multiply-accumulate,
mulhhwand the like), and the ISA 3.1 prefixed (8-byte) instructions with their new integer forms. - Reference: the exact condition register and
XERresults of each instruction beyond the record and overflow forms noted above.
Unknown
- Reference: none known.
Links
Reference
- Power ISA – the instruction set architecture, from the OpenPOWER Foundation; the appendix on simplified mnemonics lists the extended names
- The LLVM code generator – the PowerPC target used to check the decoder