PowerPC application-level instruction set
Table 1 lists different instruction categories and the types of instructions in each.
Table 1. Instruction categories
Instruction category | Base instructions |
Branch | branch, branch conditional, branch to LR, branch to CTR |
Condition register | crand, crnor, creqv, crxor, crandc, crorc, crnand, cror, CR move |
Storage access | load GPR/FPR, store GPR/FPR |
Integer arithmetic | add, subtract, negate, multiply, divide |
Integer comparison | compare algebraic, compare algebraic immediate, compare logical, compare logical immediate |
Integer logical | and, andc, nand, or, orc, nor, xor, eqv, sign extension, count leading zeros |
Integer rotate/shift | rotate, rotate and mask, shift left, shift right |
Floating-point arithmetic | add, subtract, negate, multiply, divide, square root, multiply-add, multiply-subtract, negative multiply-add, negative multiply-subtract |
Floating-point comparison | compare ordered, compare unordered |
Floating-point conversion | round to single, convert from/to integer word/doubleword |
FPSCR management | move to/from FPSCR, set/clear FPSCR bit, copy FPSCR field to CR |
Cache control | touch, zero, flush, store |
Processor management | system call, move to/from special purpose registers, mtcrf, mfcr |
All instruction encodings are 32 bits in length. Bit numbering for PowerPC is the opposite of most other definitions: bit 0 is the most significant bit, and bit 31 is the least significant bit. Instructions are first decoded by the upper 6 bits in a field,
called theprimary opcode. The remaining 26 bits contain fields for operand specifiers, immediate operands, and extended opcodes, and these may be reserved bits or fields. PowerPC defines the basic instruction formats listed in Table 2.
Table 2. PowerPC instruction formats
Format | 0 | 6 | 11 | 16 | 21 | 26 | 30 | 31 |
D-form | opcd | tgt/src | src/tgt | immediate | ||||
X-form | opcd | tgt/src | src/tgt | src | extended opcd | |||
A-form | opcd | tgt/src | src/tgt | src | src | extended opcd | Rc | |
BD-form | opcd | BO | BI | BD | AA | LK | ||
I-form | opcd | LI | AA | LK |
-
D-form
This instruction format provides up to two registers as source operands, one immediate source, and up to two registers as target operands. Some variations of this instruction format use portions of the target and source register operand specifiers as immediate
fields or as extended opcodes. -
X-form
This instruction format provides up to two registers as source operands and up to two target operands. Some variations of this instruction format use portions of the target and source operand specifiers as immediate fields or as extended opcodes. -
A-form
This instruction format provides up to three registers as source operands, and one target operand. Some variations of this instruction format use portions of the target and source operand specifiers as immediate fields or as extended opcodes. -
BD-form
This instruction format is used by the conditional branch instruction. The BO instruction field specifies the type of condition; the BI instruction field specifies which CR bit is to be used as the condition; and the BD field is used as the branch displacement.
The AA bit specifies whether the branch is an absolute or relative branch. That is, the branch target address is the value of the immediate field or is the sum of the value of the immediate field and the address of the branch. The LK bit specifies whether
the address of the next sequential instruction is saved in the Link Register as a return address for a subroutine call. -
I-form
This instruction format is used by the unconditional branch instruction. Being unconditional, the BO and BI fields of the BD format are exchanged for additional branch displacement to form the LI instruction field. This instruction format also supports the
AA and LK bits in the same fashion as the BD format.
As mentioned, there are variations to these instruction formats. However, these formats best represent the makeup of most of the PowerPC instruction set encodings.
PowerPC provides a set of instructions for control flow that include:
- Both conditional and unconditional branch instructions
- A "decrement count and branch if zero/not zero" capability
- Absolute and relative branching
- Branch instructions using the contents of the Link Register or Count Register to specify the branch target address
The ability to save the address of the next sequential instruction is provided on all branch instructions, including the Branch to Link Register instruction. Conditional branches allow specifying any one of the 32 Condition Register bits to be used as the condition,
and to specify whether that CR bit must be equal to 0 or 1 for the branch condition to succeed.
Condition register instructions
PowerPC provides a set of instructions for performing boolean operations on specific bits of the CR as well as copying CR fields. This allows the combining of multiple branching conditions, which can reduce the number of costly conditional branches. Table 3
lists PowerPC CR logical instructions.
Table 3. PowerPC CR logical instructions
Mnemonic | Instruction name |
crand | CR logical and |
crandc | CR logical and with complement |
creqv | CR logical equivalent |
crnand | CR logical not and |
crnor | CR logical not or |
cror | CR logical or |
crorc | CR logical or with complement |
crxor | CR logical xor |
Integer arithmetic instructions
Many instructions exist for performing arithmetic operations, including add, subtract, negate, compare, multiply, and divide. Many forms exist for immediate values, overflow detection, and carry in and out. Multiply and divide instruction performance varies
among implementations, as these are typically multi-cycle instructions. Table 4 lists PowerPC integer arithmetic instructions.
Table 4. PowerPC integer arithmetic instructions
Mnemonic | Instruction name |
add[o][.] | add [& record OV] [& record CR0] |
addc[o][.] | add carrying [& record OV] [& record CR0] |
adde[o][.] | add extended [& record OV] [& record CR0] |
addi | add immediate |
addis | add immediate shifted |
addic[.] | add immediate carrying [& record CR0] |
addme[o][.] | add to minus one [& record OV] [& record CR0] |
addze[o][.] | add to zero [& record OV] [& record CR0] |
divd[o][.] | divide doubleword [& record OV] [& record CR0] |
divdu[o][.] | divide doubleword unsigned [& record OV] [& record CR0] |
divw[o][.] | divide word [& record OV] [& record CR0] |
divwu[o][.] | divide word unsigned [& record OV] [& record CR0] |
mulhd[.] | multiply high doubleword [& record CR0] |
mulhdu[.] | multiply high doubleword unsigned [& record CR0] |
mulhw[.] | multiply high word [& record CR0] |
mulhwu[.] | multiply high word unsigned [& record CR0] |
mulld[o][.] | multiply low doubleword [& record OV] [& record CR0] |
mulli | multiply low immediate |
mullw[o][.] | multiply low word [& record OV] [& record CR0] |
neg[o][.] | negate [& record OV] [& record CR0] |
subf[o][.] | subtract from [& record OV] [& record CR0] |
subfc[o][.] | subtract from carrying [& record OV] [& record CR0] |
subfe[o][.] | subtract from extended [& record OV] [& record CR0] |
subfi | subtract from immediate |
subfis | subtract from immediate shifted |
subfic[.] | subtract from immediate carrying [& record CR0] |
subfme[o][.] | subtract from to minus one [& record OV] [& record CR0] |
subfze[o][.] | subtract from to zero [& record OV] [& record CR0] |
Logical, rotate, and shift instructions
PowerPC provides a complete set of logical operations, and also provides support for sign-extension and counting the number of leading zeros in a GPR. Table 5 lists PowerPC logical instructions.
Table 5. PowerPC logical instructions
Mnemonic | Instruction name |
and[.] | and [& record CR0] |
andc[.] | and with complement [& record CR0] |
andi. | and immediate & record CR0 |
andis. | and immediate shifted & record CR0 |
eqv[.] | equivalent [& record CR0] |
nand[.] | not and [& record CR0] |
nor[.] | not or [& record CR0] |
or[.] | or [& record CR0] |
orc[.] | or with complement [& record CR0] |
oris | or immediate shifted |
ori | or immediate |
xor[.] | xor [& record CR0] |
xoris | xor immediate shifted |
xori | xor immediate |
cntlzd[.] | count leading zeros doubleword [& record CR0] |
cntlzw[.] | count leading zeros word [& record CR0] |
extsb[.] | extend sign byte [& record CR0] |
extsh[.] | extend sign halfword [& record CR0] |
extsw[.] | extend sign word [& record CR0] |
PowerPC provides a robust and powerful set of rotate and shift operations, as listed in Table 6.
Table 6. PowerPC rotate and shift instructions
Mnemonic | Instruction name | ||
rldc[.] |
|