CIMFlow LogoCIMFlow

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.

31:26
25:21
20:16
15:0
1110XX
opcode
rs
operand 1
rt
operand 2
imm
16-bit offset
Syntax
BRANCH rs, rt, imm
Operation
if (GRF[rs] ⊙ GRF[rt]) then PC ← PC + imm

Branch Variants

The opcode bits XX specify the comparison operation:

BEQ111000
Branch if Equal
rs == rt
BNE111001
Branch if Not Equal
rs != rt
BGT111010
Branch if Greater Than
rs > rt
BLT111011
Branch if Less Than
rs < rt

Branch 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.

31:26
25:0
111100
opcode
imm
26-bit offset
Syntax
JMP imm
Operation
PC ← PC + imm

JMP 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