Introduction
PowerPC has no delay slots. A branch takes effect immediately, and the instruction after it is simply the next one. The
target of b and bc is the address of the branch plus a signed displacement (a multiple of four), or, with the
a (absolute) form, the displacement itself. bclr branches to the address in the link register
(LR) and bcctr to the count register (CTR); bctar uses the target address register.
Every branch has an l (link) form that writes the address of the next instruction into LR, which is how a call is made.
A function returns with blr, a bclr that always branches.
The condition register, CR, is eight 4-bit fields, cr0 to cr7. Each field holds the bits
LT, GT, EQ and SO (summary overflow, a copy of XER[SO] after an integer record
form or compare). A conditional branch names one of the 32 bits of the condition register in its BI field, and says what to test in its
BO field. Most assembly programs never write BO and BI: they use the simplified mnemonics.
The condition register logic instructions combine bits of it, and the move instructions copy fields to and from general registers.
The BO and BI fields
BI (5 bits) selects the condition register bit: BI = 4 × field + bit, where the bit within a field is 0 for LT, 1 for GT, 2 for EQ and 3 for SO.
So BI = 2 is cr0[EQ] and BI = 6 is cr1[EQ]. BO (5 bits) says whether to test the bit, whether to decrement the
count register and test it, and gives a prediction hint. In the manuals' numbering (bit 0 of BO is its most significant bit) the values are:
| BO | Meaning | Simplified mnemonic |
|---|---|---|
0000y (0, 1) | Decrement CTR; branch if CTR ≠ 0 and the CR bit is 0. | bdnzf |
0001y (2, 3) | Decrement CTR; branch if CTR = 0 and the CR bit is 0. | bdzf |
001zy (4 to 7) | Branch if the CR bit is 0. | bf, bge, ble, bne, bns |
0100y (8, 9) | Decrement CTR; branch if CTR ≠ 0 and the CR bit is 1. | bdnzt |
0101y (10, 11) | Decrement CTR; branch if CTR = 0 and the CR bit is 1. | bdzt |
011zy (12 to 15) | Branch if the CR bit is 1. | bt, blt, bgt, beq, bso |
1z00y (16, 17, 24, 25) | Decrement CTR; branch if CTR ≠ 0. | bdnz |
1z01y (18, 19, 26, 27) | Decrement CTR; branch if CTR = 0. | bdz |
1z1zz (20) | Branch always (BI is ignored). | b, blr, bctr |
The low bit y (with the z bit above it, the pair the later manuals call at) is a prediction hint. The z bits are ignored by the hardware but should be zero. The explorer writes the hint
as a trailing + (predict taken) or - (predict not taken), as in bne- cr1, target. For bcctr and bctar the
count register cannot be decremented, so a BO that decrements CTR is an invalid form.
Simplified branch mnemonics
With simplified mnemonics on (the default), the explorer writes a conditional branch by its condition. The condition names are lt, gt,
eq, so for a set bit and ge (not LT), le (not GT), ne (not EQ), ns (not SO) for a clear bit;
b + condition is a branch to a target, + lr a branch to the link register and + ctr one to the count register; an l after that links.
The condition register field is the first operand, and is left out when it is cr0.
| Simplified | Written in full |
|---|---|
blr, blrl | bclr 20, 0, bclrl 20, 0: return, and call the address in LR. |
bctr, bctrl | bcctr 20, 0: jump to or call the address in CTR. |
bl target | bl is the link form of b: a call. |
beq target, beq cr1, target | bc 12, 2, target, bc 12, 6, target |
bne, blt, bge, bgt, ble | bc 4, 2, bc 12, 0, bc 4, 0, bc 12, 1, bc 4, 1 (with the field added to BI) |
bt bi, target, bf bi, target | bc 12, bi, target, bc 4, bi, target |
bdnz target, bdz target | bc 16, 0, target, bc 18, 0, target |
bdnzt, bdnzf, bdzt, bdzf bi, target | bc 8, bc 0, bc 10, bc 2 with the bit number bi |
beqlr, bnelr, bgtctr ... | The same conditions on bclr and bcctr. |
bne-, beq+ | The same with the hint bits set to predict not taken or taken. |
crclr bt, crset bt | crxor bt, bt, bt, creqv bt, bt, bt |
crmove bt, ba, crnot bt, ba | cror bt, ba, ba, crnor bt, ba, ba |
mtcr rs | mtcrf 255, rs |
A BO that has no simplified name (a branch always with a nonzero BI, for example) is shown in full as bc, bclr or bcctr.
Branches and system calls
| Mnemonic | Operands | Form and opcode | Available in | What it does |
|---|---|---|---|---|
b, bl, ba, bla | target (li) | I 18 | all PowerPC | Branch to the address given by a 26-bit signed displacement (relative, or absolute with the a form); the l form saves the return address in LR. |
bc, bcl, bca, bcla | bo, bi, target | B 16 | all PowerPC | Branch conditionally on the condition register bit BI and the count register, as BO says. The displacement is 14 bits. |
bclr, bclrl | bo, bi[, bh] | XL 19/16 | all PowerPC | Branch conditionally to the address in the link register (the return). BH is a hint about the kind of branch. |
bcctr, bcctrl | bo, bi[, bh] | XL 19/528 | all PowerPC | Branch conditionally to the address in the count register. |
bctar, bctarl | bo, bi[, bh] | XL 19/560 | ISA 2.07 and later | Branch conditionally to the address in the branch target address register. |
sc | [lev] | SC 17 (bit 30 set) | all PowerPC | System call: trap to the operating system. |
scv | lev | SC 17 (bit 31 set) | ISA 3.0 and later | System call vectored: trap to the operating system at the level LEV. |
Condition register logic and moves
The logic instructions take condition register bit numbers (0 to 31, the same numbering as BI) for bt, ba and bb.
The fields are named bf and bfa (field numbers 0 to 7), which the explorer writes as cr0 to cr7 or as plain numbers (an option).
| Mnemonic | Operands | Form and opcode | Available in | What it does |
|---|---|---|---|---|
crand | bt, ba, bb | XL 19/257 | all PowerPC | CR bit BT = CR bit BA and CR bit BB. |
crandc | bt, ba, bb | XL 19/129 | all PowerPC | CR bit BT = CR bit BA and not CR bit BB. |
creqv | bt, ba, bb | XL 19/289 | all PowerPC | CR bit BT = CR bit BA equivalent (xnor) to CR bit BB. crset when all three are the same bit. |
crnand | bt, ba, bb | XL 19/225 | all PowerPC | CR bit BT = not (CR bit BA and CR bit BB). |
crnor | bt, ba, bb | XL 19/33 | all PowerPC | CR bit BT = not (CR bit BA or CR bit BB). crnot when BA and BB are the same bit. |
cror | bt, ba, bb | XL 19/449 | all PowerPC | CR bit BT = CR bit BA or CR bit BB. crmove when BA and BB are the same bit. |
crorc | bt, ba, bb | XL 19/417 | all PowerPC | CR bit BT = CR bit BA or not CR bit BB. |
crxor | bt, ba, bb | XL 19/193 | all PowerPC | CR bit BT = CR bit BA xor CR bit BB. crclr when all three are the same bit. |
mcrf | bf, bfa | XL 19/0 | all PowerPC | Copy condition register field BFA to field BF. |
isync | none | XL 19/150 | all PowerPC | Instruction synchronise: discard prefetched instructions. |
mcrxr | bf | X 31/512 | all PowerPC before ISA 3.0 | Move the XER summary bits SO, OV, CA to CR field BF and clear them. |
mcrxrx | bf | X 31/576 | ISA 3.0 and later | Move the XER OV, OV32, CA, CA32 bits to CR field BF. |
setb | rt, bfa | X 31/128 | ISA 3.0 and later | Set rt to -1, 0 or 1 from the LT, GT bits of CR field BFA. |
mfcr | rt | XFX 31/19 | all PowerPC | Move the whole condition register to rt. |
mfocrf | rt, fxm | XFX 31/19 (bit 11 set) | all PowerPC | Move one condition register field to rt. |
mtcrf | fxm, rs | XFX 31/144 | all PowerPC | Move the fields of rs that FXM selects into the condition register. mtcr when FXM is 255. |
mtocrf | fxm, rs | XFX 31/144 (bit 11 set) | all PowerPC | Move one field of rs into the condition register. |
The branch-and-link forms return through LR, and mflr and mtlr (mfspr and mtspr with the link register) save and restore it.
The compare instructions and the record forms (add., andi.) set condition register fields; see the integer page.
Not described
Known, not yet covered
- Reference: the Book E and embedded branch variants and the ISA 3.1 prefixed (8-byte) instructions.
- Reference and viewer: the exact meaning of the
BHfield hints (return, call, not a subroutine) is stated only as “a hint”. - Viewer: following a jump through a register (
bctrafter a table load) to its target.
Unknown
- Reference: none known.
Links
Reference
- Power ISA – the instruction set architecture, from the OpenPOWER Foundation
- The LLVM code generator – the PowerPC target used to check the decoder