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.

Encoding

Binary Layout
3
0:5
TO
6:10
RA
11:15
SI
16:31
 
Format D-form
Opcode 0x0C000000
Extension Base

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

Example

twi 4, r4, 4

Registers Altered

CR0, XER

Related

Across architectures

Breakpoint Trap : how x86, ARM, RISC-V, and PowerISA each do this.

More in Base

Reference

Description

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.

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

Extended Mnemonics

Extended Mnemonic Equivalent Instruction
tweq
twgti
twllei

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.