twi

Trap Word Immediate

twi TO, RA, SIM

Compares the contents of register RA with an immediate value and invokes the system trap handler if any specified condition is met.

Details

The contents of register RA are compared with the sign-extended value of the SI field. If any bit in the TO field is set to 1 and its corresponding condition is met by the result of the comparison, the system trap handler is invoked.

Pseudocode Operation

a ← EXTS((RA)32:63)
if (a < EXTS(SI)) & TO0 then TRAP
if (a > EXTS(SI)) & TO1 then TRAP
if (a = EXTS(SI)) & TO2 then TRAP
if (a <u EXTS(SI)) & TO3 then TRAP
if (a >u EXTS(SI)) & TO4 then TRAP

Programming Note

Generates a program exception (System Call or Trap type) when the trap condition is true. The condition codes in TO select which comparisons trigger the trap: bit 0 = LT, bit 1 = GT, bit 2 = EQ, bit 3 = LU (unsigned), bit 4 = GU (unsigned). TO=31 (all bits set) always traps.

Extended Mnemonics

Extended Mnemonic Equivalent Instruction
tweq
twgti
twllei

Example

twi 4, r4, 4

Encoding

Binary Layout
3
0
TO
6
RA
11
SI
16
 
Format D-form
Opcode 0x0C000000
Extension Base
Registers Altered CR0, XER

Operands

  • TO
    Options
  • RA
    Src
  • SIM
    Imm
  • SI
    Sign-Extended Immediate Value
  • CRb
    Condition Register Field
  • L
    Link Bit
  • Ra
    Source General Purpose Register
  • SIm
    Immediate Value
  • LK
    Link Bit