Intra-Core Control
Control flow instructions for branching and jumping
Intra-core control instructions manage program execution flow within a single core, providing both conditional branching based on register comparisons and unconditional jumps using PC-relative addressing.
BRANCH
Performs a conditional jump based on comparison of two register values. The instruction supports four comparison types encoded in the opcode, enabling efficient decision-making for loops, conditionals, and control flow.
BRANCH rs, rt, immif (GRF[rs] ⊙ GRF[rt]) then PC ← PC + immBranch Variants
The opcode bits XX specify the comparison operation:
111000111001111010111011Branch offset is PC-relative: target = PC + imm. The offset is measured in instruction units from the next instruction.
JMP
Performs an unconditional jump to a target address specified by a PC-relative offset. Unlike BRANCH, JMP always transfers control regardless of any condition.
JMP immPC ← PC + immJMP provides a larger offset range (26 bits) compared to BRANCH (16 bits), enabling jumps across larger code sections.
Examples
; Simple if-then-else
G_LI r1, 10
G_LI r2, 20
BLT r1, r2, 3 ; if (10 < 20), jump 3 instructions
G_LI r3, 0 ; else: r3 = 0
JMP 2 ; skip then block (2 instructions)
G_LI r3, 1 ; then: r3 = 1
; Counting loop
G_LI r1, 0 ; i = 0
G_LI r2, 10 ; limit = 10
G_LI r3, 0 ; sum = 0
; loop_start:
BEQ r1, r2, 4 ; if (i == 10), jump to loop_end (4 instructions)
SC_ADD r3, r3, r1 ; sum += i
SC_ADDI r1, r1, 1 ; i++
JMP -3 ; jump back to loop_start (-3 instructions)
; loop_end:
; Nested conditionals
BNE r1, r2, 4 ; if r1 != r2, jump to else_block
BGT r3, r4, 2 ; if r3 > r4, jump to inner_then
JMP 1 ; skip inner_then
; inner_then:
; code here
; else_block:Last updated on