← Back to blog

AArch64 Branches

This is a personal study note — I write these to solidify my own understanding. If you spot anything wrong or have thoughts, feel free to reach out. Layout, formatting, and grammar assisted by Claude.


bit 0 3 7 11 15 19 23 27 31 reach CONDITIONAL, RELATIVE b.cond b.eq L 01010100 imm19 0 cond ±1 MiB cbz / cbnz cbz x0, L sf 0 W / 1 X 011010 op 0 cbz / 1 cbnz imm19 Rt ±1 MiB tbz / tbnz tbz x2, #63, L b5 bit[5] 011011 op 0 tbz / 1 tbnz b40 imm14 Rt ±32 KiB cb<cc> cbge x0, x1, L sf 0 W / 1 X 1110100 cc Rm 00 imm9 Rt ±1 KiB cb<cc> #imm cbgt x0, #3, L sf 0 W / 1 X 1110101 cc imm6 0 imm9 Rt ±1 KiB DIRECT, RELATIVE b b L 000101 imm26 ±128 MiB bl bl L 100101 imm26 ±128 MiB INDIRECT, REGISTER br br x16 110101100 00 op 11111 000000 Rn 00000 any aligned VA blr blr x17 110101100 01 op 11111 000000 Rn 00000 any aligned VA ret ret (x30) 110101100 10 op 11111 000000 Rn 00000 any aligned VA CONDITIONAL FAULT, NO BRANCH flt.cond flt.hs #0 11010100 001 imm16 1 cond no target cflt<cc> cflths #0, w2, w0 sf 0 W / 1 X 1110110 cc Rm 0000 reason 10000 Rt no target cflt<cc> #imm cfltlo #1, w0, #16 sf 0 W / 1 X 1110110 cc imm9h 0000 reason 0 imm9l Rt no target tfltz tfltz #2, x0, #63 b5 1110110 b40 0000000 reason 1001 0 op Rt no target fixed opcode bits selector bits (variant) operand field: register, immediate, condition Every instruction is 4 bytes; offsets are in words (×4) from the branch itself.

Conditional branches

There is nothing surprising about conditional branches. AArch64 has four flag bits: N (negative), Z (zero), C (carry, which after a compare means unsigned higher or same), and V (signed overflow). Conditional instructions act on these flags, and instructions like compare and test set them. Interestingly, unlike x86, where add always writes the flags, AArch64 lets you choose: add leaves the flags alone and adds sets them.

AArch64 also has branches that do not read the flags at all. cbz and cbnz branch if a register is zero or not zero. tbz and tbnz test a single bit of a register and branch on it. Both have been there since Armv8.0. The cb<cc> instructions are new in Armv9.6.

equal 0000 EQ Z = 1 0001 NE Z = 0 ¬ unsigned higher or same 0010 CS / HS C = 1 0011 CC / LO C = 0 ¬ negative 0100 MI N = 1 0101 PL N = 0 ¬ signed overflow 0110 VS V = 1 0111 VC V = 0 ¬ unsigned higher 1000 HI C = 1 and Z = 0 1001 LS C = 0 or Z = 1 ¬ signed greater or equal 1010 GE N = V 1011 LT N ≠ V ¬ signed greater 1100 GT Z = 0 and N = V 1101 LE Z = 1 or N ≠ V ¬ always 1110 AL any flags 1111 NV any flags, same as AL = Conditional branches that test a register, not the flags CBZ Rt = 0 ±1 MiB CBNZ Rt ≠ 0 ±1 MiB TBZ Rt<bit> = 0 ±32 KiB TBNZ Rt<bit> = 1 ±32 KiB CB<cc> Rt <cc> Rm (cc: GT GE HI HS EQ NE) Armv9.6, FEAT_CMPBR ±1 KiB CB<cc> Rt <cc> #imm6 (cc: GT LT HI LO EQ NE) Armv9.6, FEAT_CMPBR ±1 KiB

cb<cc> compares two registers, or a register and an immediate from 0 to 63, and branches on the condition in one instruction. It works on 32-bit and 64-bit registers and does not touch the flags.

Direct B and BL

B and BL are very straightforward. B carries a 26-bit offset, so it can branch to anywhere within ±128 MiB of itself. BL does the same, but the L stands for link: it also saves the address of the next instruction, PC + 4, into X30, the link register, so that the callee can ret back to it.

If X30 already holds a value, BL overwrites it and the old value is discarded. A leaf function never has to touch the stack for its return address. It runs and executes ret with the caller's address still in X30.

x86-64: CALL caller: call f add rax, 1 ← the return address f: … ret pop RIP the stack in memory, RSP at the top return address caller's frame … call pushes RIP + 5, ret pops it. Every call writes memory. AARCH64: BL caller: bl f add x0, x0, #1 ← the return address f: … ret jump to X30 X30, the link register return address bl writes PC + 4, ret jumps to it. A leaf never touches memory for it.

Indirect BR, BLR and RET

Unlike x86, where an indirect jmp rax is two bytes and ret is one, an AArch64 indirect branch is still four bytes, most of them fixed. In return, AArch64 does not have x86’s problem with variable-length instructions. Every instruction sits on a 4-byte boundary and a branch to any other address faults, so there are no hidden instructions inside other instructions for an attacker to jump into.

AArch64 also has an instruction to mark where an indirect branch is allowed to land: bti. In a page the kernel marks as guarded, a br or blr that lands anywhere other than a bti raises an exception [1]. The compiler places one at every function entry and switch target.

Two more security features sit on these instructions. Pointer authentication, from Armv8.3, signs X30 before it is saved to the stack and checks the signature before ret uses it [2]. The Guarded Control Stack, from Armv9.4, keeps a second copy of every return address in memory that only the hardware can write, and ret compares against it [3]. I will cover how they work and their limitations in future posts.

AArch64 instructions so far are all 4 bytes. This means the encoding space is finite, and Arm already treats it as scarce. When SVE was announced in 2016, Arm wrote that “75% of the A64 encoding space is already allocated” [4]. It would be interesting to see how they address this.

Conditional fault

Conditional fault was announced in October 2026 with Armv9.8. The concept is straightforward: a compare that raises an exception when the condition is true, instead of branching. The motivation comes from memory-safe languages like Rust [5]. Bounds and null checks are the perfect example.

TODAY: COMPARE, BRANCH, SLOW PATH cmp w2, w0 b.hs slow ldr w3, [x1, w2, uxtw #2] … index against length taken only on failure the access slow: mov x1, x0 mov x0, x2 bl throw_bounds_error The slow path is a branch target: it has an address, and the predictor has to track the branch that leads to it. 5 instructions, 20 bytes, 1 branch target ARMV9.8: CONDITIONAL FAULT cflths #0, w2, w0 ldr w3, [x1, w2, uxtw #2] … fault if index >= length the access Conditional fault exception ESR_ELx: reason #0, “array bounds” Not a branch: there is no target address, so there is nothing for the predictor to learn. 1 instruction, 4 bytes, 0 branch targets

I am not so familiar with exception-related registers yet, so here is a table I wrote for myself.

  • ELR_EL1, Exception Link Register: does the same job X30 does for bl, but for exceptions.
  • SPSR_EL1, Saved Program Status Register: a snapshot of PSTATE at the moment of the exception. The NZCV flags, the interrupt mask bits, the exception level and the stack pointer the program was using are all recorded. eret restores PSTATE from it, so the program resumes with its flags intact.
  • ESR_EL1, Exception Syndrome Register: why the exception happened. The top 6 bits are the exception class, a code for the kind of event, and the lower bits are the instruction-specific syndrome.
  • VBAR_EL1, Vector Base Address Register, holds the base address of the vector table, the kernel’s entry points, and the core adds a fixed offset for the type of exception.
  • SCTLR_EL1, System Control Register, is a bag of enable bits for the kernel’s own level and for user space below it. SCTLR2_EL1 is its overflow, added when the first one filled up, and that is where the new EnCF0 bit lives.
0 4 8 12 16 20 24 28 31 bit ELR_EL1 where to return address of the cflt instruction itself (64-bit, low half shown) ThisInstrAddr(): a handler that returns without changing it re-executes the check. SPSR_EL1 the program's PSTATE N Z C V RES0 TCO DIT UAO PAN SS IL RES0 BTYPE D A I F 0 0 M[4] M[3:0] EL, SP N Z C V are the flags, D A I F the exception masks; 13 ALLINT, 12 SSBS. M[4] = 0 for AArch64; M[3:0] = 0000 for EL0, 0101 for EL1 on SP_EL1. ESR_EL1 why it happened 001011 EC: conditional fault 1 IL IsFLT RES0 Reason EC 0x0B is the class Arm allocated for FEAT_CFLT. IsFLT = 1 for flt.cond, 0 for cflt and tflt. Reason is the instruction's immediate; for cflt and tflt only bits 1:0 can be set. SCTLR2_EL1 the enable RES0 EnCF0 other enable bits EnCF0 = 1 lets user space (EL0) run the conditional fault instructions; 0, the reset value, makes them UNDEFINED there. value fixed for this exception field reserved, reads as zero the bit the kernel must set All four are 64-bit; bits 63:32 are reserved or unused for this exception and are not drawn.

There are four conditional fault instructions, and each of them mirrors a regular branch instruction. flt.cond mirrors b.cond. cflt<cc> #r, Xt, Xm mirrors cb<cc> with two registers as operands. cflt<cc> #r, Xt, #imm mirrors cb<cc> #imm and cbz, comparing a register against a constant. tfltz and tfltnz mirror tbz and tbnz, testing one bit of a register. Like the branches, they split on the flags: flt.cond is the only one that reads them, so it needs a cmp or another flag-setting instruction ahead of it. The other three do their own compare.

All four raise the same exception, class 0x0B, with ELR pointing at the instruction itself. ESR tells the kernel whether it was flt.cond or one of the other three, and carries the reason from the instruction.

References

[1] Arm’s description of FEAT_BTI, which "allows memory pages to be guarded against the execution of instructions that are not the intended target of a branch": Feature names in A-profile architecture, The Armv8.5 architecture extension, Arm document 109697, 2026.09.

[2] Arm’s description of FEAT_PAuth, which "supports address authentication of the contents of a register before that register is used as the target of an indirect branch, or as a load": Feature names in A-profile architecture, The Armv8.3 architecture extension, Arm document 109697, 2026.09.

[3] Arm’s description of FEAT_GCS, "an area of memory in which procedure return addresses and exception return addresses are stored and protected from modification": Feature names in A-profile architecture, The Armv9.4 architecture extension, Arm document 109697, 2026.09.

[4] The SVE announcement, with the figure for how much of the A64 encoding space was allocated by 2016: Nigel Stephens, Technology Update: The Scalable Vector Extension (SVE) for the Armv8-A architecture, Arm Community blog, 22 August 2016.

[5] Arm’s motivation for the Conditional fault instructions: Martin Weidmann, Arm A-Profile Architecture Developments 2026, Arm Community blog, 5 October 2026. "These checks can increase code size and branch frequency, which puts more pressure on branch prediction logic."