Hexagon Overview and Processor Properties
Relevant source files
The following files were used as context for generating this wiki page:
- llvm/lib/Target/Hexagon/HexagonDepArch.td
- llvm/lib/Target/Hexagon/Hexagon.td
- Wikipedia: Qualcomm Hexagon
- Wikipedia: Very long instruction word
- Qualcomm: Hexagon V6x/V7x Programmer's Reference Manual and HVX Programmer's Reference Manual (Qualcomm developer network)
Hexagon is Qualcomm's digital signal processor (DSP) architecture, found in Snapdragon chips as the audio/sensor DSP and the compute DSP that Qualcomm markets as the Hexagon NPU. It is a 32-bit VLIW machine: the compiler groups up to four instructions into a packet that executes in one go, so the hardware does not need complex out-of-order logic. A wide vector unit, HVX, adds SIMD for image, audio and AI workloads.
> About this wiki. Facts about registers, encodings, instruction names and architecture versions are cited from the LLVM Hexagon backend at commit a2171756. Hardware details not visible in LLVM (cache sizes, thread counts, MMU behaviour) follow Qualcomm's public Hexagon reference manuals; they vary by chip and are marked as general. All assembly is illustrative: the local LLVM build does not include the Hexagon target, so nothing was assembled.
Purpose and Scope
| # | Page | Covers |
|---|---|---|
| 1 | Overview | What Hexagon is, processor properties, versions |
| 2 | ISA Fundamentals | Packets, slots, .new, hardware loops, threads |
| 3 | Registers | General, pair, predicate, control, HVX registers; ABI |
| 4 | Encoding and Mnemonics | 32-bit words, parse bits, extenders, duplexes, assembly syntax |
| 5 | Data, Memory and Control | ALU, loads/stores, addressing, branches, loops, calls |
| 6 | FP, HVX and Alignment | Scalar floating point, HVX vectors, alignment rules |
| 7 | Caches, MMU and Glossary | Cache hierarchy and maintenance, VTCM, MMU, glossary |
Background: VLIW and multithreading are explained in the Computer Architecture wiki.
Processor Properties at a Glance
| Property | Hexagon |
|---|---|
| Word size | 32-bit (32-bit registers and addresses), 64-bit register pairs |
| Instruction size | 32 bits each; up to 4 per packet (16 bytes) |
| Issue model | VLIW: compiler-scheduled packets, in-order |
| Execution slots | 4 (slots 0-3) |
| Threads | Several hardware threads per core, interleaved (count depends on the chip) |
| Endianness | Little-endian |
| Memory accesses | Must be naturally aligned (scalar) |
| Vector extension | HVX: 32 vector registers of 64 or 128 bytes |
| Loops | Two zero-overhead hardware loops |
| Typical role | Low-power signal processing and ML inference next to the CPU |
Why VLIW for a DSP?
flowchart LR
subgraph OoO["Big CPU core (e.g. Arm Cortex-X)"]
A1["Hardware finds parallelism<br/>rename, reorder, speculate"] --> A2["Fast single thread,<br/>high power"]
end
subgraph VLIW["Hexagon"]
B1["Compiler finds parallelism<br/>packs up to 4 instructions"] --> B2["Simple in-order hardware,<br/>low power, predictable timing"]
end
DSP code (filters, transforms, neural-network layers) is regular and loop-heavy, so a compiler can schedule it well ahead of time. That saves the power an out-of-order engine would spend, which matters in phones.
Sources: Wikipedia: Qualcomm Hexagon, Wikipedia: Very long instruction word
Where Hexagon Sits in a Snapdragon Chip
flowchart TB
subgraph SoC["Snapdragon SoC (simplified)"]
CPU["Arm CPU cores<br/>Android / Linux"]
GPU["Adreno GPU"]
subgraph DSP["Hexagon DSP / NPU"]
SC["Scalar core<br/>VLIW, hardware threads"]
HVX["HVX vector unit"]
TCM["VTCM (local memory)"]
end
CPU <-->|"FastRPC: offload calls"| DSP
MEM["Shared DRAM"]
CPU --- MEM
GPU --- MEM
DSP --- MEM
end
Applications on the Arm CPU offload work to the DSP through Qualcomm's FastRPC mechanism. The DSP runs its own real-time OS (QuRT).
Architecture Versions
LLVM knows these Hexagon versions, each enabled by a subtarget feature such as v68:
| Versions in LLVM | Notes |
|---|---|
| V5, V55 | Older scalar DSPs |
| V60, V62, V65, V66 | HVX introduced in V60 |
| V67, V68, V69 | V68+ add HVX floating point (hvx-qfloat) |
| V71, V73, V75, V79, V81 | Recent NPU-generation cores |
Matching HVX versions (hvxv60 … hvxv81), vector length (hvx-length64b, hvx-length128b) and options such as audio and hvx-ieee-fp are separate features.
clang --target=hexagon -mcpu=hexagonv73 -mhvx -mhvx-length=128B -O2 -c kernel.c (illustrative)
Sources: llvm/lib/Target/Hexagon/HexagonDepArch.td:11-37, llvm/lib/Target/Hexagon/Hexagon.td:32-96
Key Points
- Hexagon is a 32-bit, in-order VLIW DSP that executes packets of up to four 32-bit instructions.
- HVX adds wide SIMD; versions V60 onward have it, V68 onward add vector floating point.
- It trades single-thread speed for low power and predictable timing.
ISA Fundamentals: Packets, Slots and Threads
Relevant source files
The following files were used as context for generating this wiki page:
- llvm/lib/Target/Hexagon/HexagonInstrFormats.td
- llvm/lib/Target/Hexagon/HexagonPseudo.td
- Wikipedia: Barrel processor
- Qualcomm: Hexagon V6x/V7x Programmer's Reference Manual, chapters on packets and pipeline
The single most important idea in Hexagon is the packet: a group of one to four instructions, written between { and }, that the hardware issues together. Everything else (slots, .new values, hardware loops) follows from it.
> Assembly on this page is illustrative and was not assembled.
Purpose and Scope
This page covers packets and their rules, execution slots and instruction classes, reading values inside a packet (.new), predication, zero-overhead hardware loops, and hardware threads. Bit-level encoding is on Encoding and Mnemonics.
The Team Analogy
| Kitchen team | Hexagon |
|---|---|
| A ticket listing up to four jobs that start together | A packet |
| Four stations, each able to do certain jobs | Slots 0-3 |
| Chef plans the tickets in advance | The compiler schedules packets |
| A job can use a result another job on the same ticket just made | .new operands |
| Several orders cooking at once, taking turns at the stations | Hardware threads |
Packets
// illustrative: four instructions issued together
{
r1 = add(r2, r3) // ALU
r4 = memw(r5 + #8) // load
memw(r6 + #0) = r7 // store
p0 = cmp.eq(r8, #0) // compare
}
flowchart LR
P["Packet {i0; i1; i2; i3}"] --> S3["Slot 3"]
P --> S2["Slot 2"]
P --> S1["Slot 1"]
P --> S0["Slot 0"]
S3 --> E["All instructions read operands,<br/>execute, then write results together"]
S2 --> E
S1 --> E
S0 --> E
Rules that follow from "issued together":
| Rule | Consequence |
|---|---|
| Instructions in a packet see register values from before the packet | { r0 = r1; r1 = r0 } swaps the two registers |
| Two instructions may not write the same register | The assembler rejects it |
| Resource limits per packet | At most two memory operations, one branch, limited slot types |
| The packet is atomic for interrupts | An interrupt is taken between packets, never inside one |
Sources: llvm/lib/Target/Hexagon/HexagonInstrFormats.td:50
Slots and Instruction Classes
Each instruction belongs to a class that says which slots can run it. In general:
| Class | Typical instructions | Slots (general) |
|---|---|---|
| LD (load) | memw, memb, memd reads | 0, 1 |
| ST (store) | stores | 0, 1 |
| ALU32 | add, sub, logical, simple moves, compares | 0-3 |
| XTYPE (complex) | multiply, shift, bit manipulation, 64-bit ops | 2, 3 |
| J (jump) | branches, calls | 2, 3 |
| CR (control register) | loops, predicate logic | 3 |
| HVX | vector instructions, with their own resources | see HVX |
LLVM's instruction descriptions carry flags for these constraints, for example a flag restricting slot 1 to ALU-only instructions and one marking instructions that prefer slot 3.
Sources: llvm/lib/Target/Hexagon/HexagonInstrFormats.td:75-77, llvm/lib/Target/Hexagon/HexagonInstrFormats.td:151-152
Using a Result in the Same Packet: .new
Normally a packet only sees old values. A few instructions may consume a value produced in the same packet by writing .new:
// illustrative
{ p0 = cmp.eq(r0, #0) // produce predicate
if (p0.new) jump:t done } // use it in the same packet ("dot-new predicate")
{ r2 = add(r1, #1)
memw(r3 + #0) = r2.new } // store the value computed this packet ("new-value store")
sequenceDiagram
participant C as cmp.eq (slot 2)
participant J as jump (slot 3)
C->>J: p0 forwarded inside the packet (.new)
Note over C,J: without .new, the jump would see p0 from before the packet
:t / :nt are static branch hints (taken / not taken).
Predication
Most instructions can be made conditional on a predicate register, which removes short branches:
// illustrative: r0 = (r1 > r2) ? r3 : r4, without a branch
{ p0 = cmp.gt(r1, r2) }
{ if (p0) r0 = add(r3, #0)
if (!p0) r0 = add(r4, #0) }
The two writes to r0 are allowed in one packet because their predicates are complementary.
Zero-Overhead Hardware Loops
// illustrative: sum 64 words
{ loop0(.Lbody, #64) // start address, iteration count
r0 = #0 }
.Lbody:
{ r1 = memw(r2++#4)
r0 = add(r0, r1) }:endloop0 // end-of-loop marker; no branch instruction
flowchart LR
L["loop0(start, N):<br/>SA0 = start, LC0 = N"] --> B["Loop body packets"]
B --> E{"Packet marked :endloop0"}
E -->|"LC0 > 1: LC0--, jump to SA0"| B
E -->|"LC0 = 1: fall through"| X["After loop"]
There are two loops, loop0 and loop1 (which can nest), using control registers SA0/LC0 and SA1/LC1 (Registers). The end of the loop is marked by bits in the last packet's encoding, not by a branch, so the loop costs no extra cycles.
Sources: llvm/lib/Target/Hexagon/HexagonPseudo.td:92-107
Hardware Threads
A Hexagon core runs several hardware threads and interleaves their packets, so while one thread waits for memory others keep the pipeline busy. This resembles a barrel processor. Each thread has its own register set; caches and execution units are shared. HVX contexts are a separate, smaller pool that threads must acquire. See the Architecture wiki: Multithreading.
Sources: Wikipedia: Barrel processor
Key Points
- A packet of up to four instructions reads old values, executes together and writes together.
- Slots limit which instruction classes share a packet;
.newpasses a value within a packet. - Predication and zero-overhead
loop0/loop1remove most branch cost; hardware threads hide latency.
Registers
Relevant source files
The following files were used as context for generating this wiki page:
- llvm/lib/Target/Hexagon/HexagonRegisterInfo.td
- llvm/lib/Target/Hexagon/HexagonCallingConv.td
- Qualcomm: Hexagon Application Binary Interface User Guide
Hexagon has a small, regular register model: 32 general registers that can also be used as 16 pairs, 4 predicate registers, a set of control registers, and (with HVX) 32 wide vector registers with 4 vector predicates.
Purpose and Scope
This page covers each register file, register pairs, the control registers, the HVX registers, and the calling-convention roles. How instructions use them is on Data, Memory and Control.
The Register Files
flowchart TB
subgraph Scalar["Scalar core (per hardware thread)"]
R["R0-R31: 32 x 32-bit general<br/>(pairs R1:0 ... R31:30 = 64-bit)"]
P["P0-P3: 4 x 8-bit predicates"]
C["C0-C31: control registers<br/>loops, USR, PC, GP, CS, timers"]
end
subgraph Vec["HVX (per vector context)"]
V["V0-V31: 64 or 128 bytes each<br/>(pairs W = V1:0 ... V31:30)"]
Q["Q0-Q3: vector predicates"]
end
| File | Count | Width | LLVM register class |
|---|---|---|---|
| General | 32 (r0-r31) | 32 bits | IntRegs |
| General pairs | 16 (r1:0 … r31:30) | 64 bits | DoubleRegs (holds i64, f64, small vectors) |
| Predicate | 4 (p0-p3) | 8 bits | PredRegs |
| Control | c0-c31 (not all defined) | 32 bits | CtrRegs |
| HVX vector | 32 (v0-v31) | 512 or 1024 bits | HvxVR |
| HVX pairs | 16 (v1:0 …) | 2 × vector | HvxWR |
| HVX predicate | 4 (q0-q3) | 1 bit per vector byte | HvxQR |
Sources: llvm/lib/Target/Hexagon/HexagonRegisterInfo.td:222, llvm/lib/Target/Hexagon/HexagonRegisterInfo.td:273-276, llvm/lib/Target/Hexagon/HexagonRegisterInfo.td:521, llvm/lib/Target/Hexagon/HexagonRegisterInfo.td:552
General Registers and Pairs
Three general registers have fixed jobs, defined with these aliases in LLVM:
| Register | Alias | Role |
|---|---|---|
r29 | sp | Stack pointer |
r30 | fp | Frame pointer |
r31 | lr | Link register (return address, set by call) |
A pair r1:0 is two consecutive registers used as one 64-bit value, high half in the odd register. Pairs must start at an even register.
flowchart LR
PR["r1:0 (64-bit)"] --> HI["r1 = bits 63..32"]
PR --> LO["r0 = bits 31..0"]
Sources: llvm/lib/Target/Hexagon/HexagonRegisterInfo.td:116-118
Predicate Registers
p0-p3 hold results of comparisons. They are 8 bits wide so that vector compares on 8 bytes (vcmpb) set one bit per byte; scalar compares set all bits. They drive conditional instructions, conditional jumps and .new forwarding (ISA Fundamentals). Together they are also readable as control register c4 (p3:0).
Sources: llvm/lib/Target/Hexagon/HexagonRegisterInfo.td:141-144
Control Registers
| Number | Name | Purpose |
|---|---|---|
| c0, c1 | sa0, lc0 | Hardware loop 0: start address, loop count |
| c2, c3 | sa1, lc1 | Hardware loop 1 |
| c4 | p3:0 | All four predicates together |
| c6, c7 | m0, m1 | Modifier registers for post-increment and circular addressing |
| c8 | usr | User status register: overflow flags, floating-point flags and rounding mode, loop configuration |
| c9 | pc | Program counter (read-only) |
| c10 | ugp | User general pointer (thread-local storage base) |
| c11 | gp | Global pointer for GP-relative small-data addressing |
| c12, c13 | cs0, cs1 | Circular buffer start addresses |
| c14 | upcyclelo | Cycle counter (low; c15 high) |
| c16, c17 | framelimit, framekey | Stack overflow check limit, return-address scrambling key |
| c18 | pktcountlo | Packet counter |
| c30 | utimerlo | User timer |
Control registers are moved with r0 = c8 style transfers (or by name, r0 = usr). Supervisor-only system registers exist in addition (see Caches, MMU).
Sources: llvm/lib/Target/Hexagon/HexagonRegisterInfo.td:152-185
HVX Registers
Each v register is one full vector: 64 bytes in 64-byte mode or 128 bytes in 128-byte mode, chosen by the chip and -mhvx-length. The same register holds 128 bytes, 64 halfwords or 32 words (in 128-byte mode). q registers hold one bit per byte lane and act as masks. More on FP, HVX and Alignment.
Calling Convention Roles
In the standard Hexagon ABI (general description; see the ABI guide):
| Registers | Role |
|---|---|
r0-r5 | First six 32-bit arguments (64-bit values in aligned pairs) |
r0 (r1:0) | Return value |
r6-r15, r28 | Caller-saved temporaries |
r16-r27 | Callee-saved |
r29, r30, r31 | sp, fp, lr |
LLVM's calling-convention description assigns i32 and i64 (and small vector) values to registers by type in this order; values that do not fit go on the stack.
Sources: llvm/lib/Target/Hexagon/HexagonCallingConv.td:19-32
Key Points
- 32 general registers (
r29/r30/r31=sp/fp/lr), usable as 64-bit even/odd pairs. - 4 predicate registers drive conditional execution; control registers hold loops,
usr,pc,gp, modifiers. - HVX adds 32 wide vector registers, vector pairs, and 4 vector predicates.
Instruction Encoding and Mnemonics
Relevant source files
The following files were used as context for generating this wiki page:
- llvm/lib/Target/Hexagon/MCTargetDesc/HexagonBaseInfo.h
- llvm/lib/Target/Hexagon/HexagonInstrFormats.td
- llvm/lib/Target/Hexagon/HexagonDepInstrInfo.td
- Qualcomm: Hexagon V6x/V7x Programmer's Reference Manual, instruction encoding chapter
Every Hexagon instruction is one 32-bit word. Two bits inside each word, the parse bits, say where the packet ends, so the hardware can find packet boundaries without a separate header. Two tricks make code smaller and constants bigger: duplexes (two short instructions in one word) and constant extenders (an extra word that widens an immediate).
> Assembly on this page is illustrative and was not assembled.
Purpose and Scope
This page covers the assembly syntax, the 32-bit word layout, parse bits, constant extenders, and duplexes. The instructions themselves are on Data, Memory and Control.
Assembly Syntax: Algebraic Mnemonics
Hexagon assembly reads like assignments rather than opcode lists:
| Hexagon | Meaning | Typical other-ISA style |
|---|---|---|
r0 = add(r1, r2) | r0 = r1 + r2 | add r0, r1, r2 |
r0 = memw(r1 + #8) | load word | ldr r0, [r1, #8] |
memw(r1 + #8) = r0 | store word | str r0, [r1, #8] |
p0 = cmp.eq(r0, #5) | compare | cmp r0, #5 |
if (p0) jump target | conditional branch | beq target |
r1:0 = memd(r2) | 64-bit load into a pair | |
{ ... } | a packet |
Suffixes add meaning: :sat (saturate), :rnd (round), :t/:nt (branch hints), .new (same-packet value), :endloop0 (loop end). LLVM's instruction definitions contain these strings directly, for example "memw($Rs32+#$Ii) = $Rt32" and "loop0($Ii,#$II)".
Sources: llvm/lib/Target/Hexagon/HexagonDepInstrInfo.td:5639, llvm/lib/Target/Hexagon/HexagonDepInstrInfo.td:21720
The 32-bit Word
flowchart LR
W["32-bit instruction word"] --> IC["bits 31..28<br/>ICLASS: instruction class"]
W --> MID["bits 27..16<br/>opcode, registers, immediates"]
W --> PB["bits 15..14<br/>PARSE bits"]
W --> LOW["bits 13..0<br/>more fields"]
The class field selects the instruction group (loads, stores, ALU, jumps, ...); the remaining fields depend on the class.
Parse Bits
| Bits 15:14 | LLVM name | Meaning |
|---|---|---|
11 | INST_PARSE_PACKET_END | Last instruction of the packet |
10 | INST_PARSE_LOOP_END | Not last; marks a hardware-loop end (with position in the packet) |
01 | INST_PARSE_NOT_END | Not last; more instructions follow |
00 | INST_PARSE_DUPLEX | This word is a duplex (also used for extenders) |
flowchart LR
I0["word 0<br/>parse 01"] --> I1["word 1<br/>parse 01"] --> I2["word 2<br/>parse 11 = end"]
I2 --> N["next packet starts here"]
The :endloop0 marker is not an instruction: it is encoded in the parse bits of the first and second words of the last packet of the loop.
Sources: llvm/lib/Target/Hexagon/MCTargetDesc/HexagonBaseInfo.h:280-285
Constant Extenders
Instructions have only small immediate fields. For a full 32-bit constant or address, the assembler places an extender word, written immext(#value), just before the instruction. The extender supplies the upper 26 bits and the instruction's own field supplies the low 6 bits. It uses one of the packet's four word positions.
// illustrative
{ r0 = ##0x12345678 } // "##" asks for an extended immediate
// encodes as two words: immext(#0x12345640); r0 = #0x38
LLVM records, per instruction, whether an operand is extendable and where (ExtendedPos) and how wide the field is (ExtentBitsPos).
Sources: llvm/lib/Target/Hexagon/HexagonDepInstrInfo.td:2604, llvm/lib/Target/Hexagon/MCTargetDesc/HexagonBaseInfo.h:132-141
Duplexes
Many common instructions (small adds, short loads and stores, moves, returns) have 13-bit sub-instruction forms. Two of them can be packed into one 32-bit duplex word, marked by parse bits 00. The assembler does this automatically, which shrinks code significantly. A duplex occupies slots 0 and 1.
flowchart LR
D["duplex word (parse bits 00)"] --> H["high sub-instruction<br/>e.g. r0 = memw(r1)"]
D --> L["low sub-instruction<br/>e.g. r2 = add(r2, #1)"]
Sources: llvm/lib/Target/Hexagon/HexagonInstrFormats.td:271-274
Key Points
- Each instruction is 32 bits; parse bits 15:14 mark packet end, loop end, or duplex.
immextextender words widen immediates to 32 bits; duplexes pack two short instructions in one word.- Assembly is algebraic:
r0 = add(r1, r2),memw(r1+#4) = r0.
Data, Memory and Control Instructions
Relevant source files
The following files were used as context for generating this wiki page:
- llvm/lib/Target/Hexagon/HexagonDepInstrInfo.td
- llvm/lib/Target/Hexagon/HexagonRegisterInfo.td
- Qualcomm: Hexagon V6x/V7x Programmer's Reference Manual, instruction set chapters
This page tours the scalar instruction set by job: computing on data, moving data to and from memory, and changing control flow. It uses the algebraic syntax from Encoding and Mnemonics.
> Assembly on this page is illustrative and was not assembled.
Purpose and Scope
This page covers ALU and multiply instructions, saturation and DSP-style operations, loads and stores with their addressing modes, atomics, and branches, calls, returns and hardware loops. Vector and floating-point instructions are on FP, HVX and Alignment.
Map of the Instruction Set
flowchart TD
ISA["Scalar Hexagon ISA"] --> D["Data"]
ISA --> M["Memory"]
ISA --> C["Control"]
D --> D1["ALU32: add, sub, and, or, xor, mux, cmp"]
D --> D2["XTYPE: mpy, shifts, bit ops, 64-bit, saturating DSP ops"]
M --> M1["Loads: memb/memub/memh/memuh/memw/memd"]
M --> M2["Stores, new-value stores"]
M --> M3["Atomics: memw_locked, barriers"]
C --> C1["jump, call, jumpr, dealloc_return"]
C --> C2["Compare-and-jump, loop0/loop1"]
Data Instructions
| Instruction | Meaning |
|---|---|
r0 = add(r1, r2) / r0 = add(r1, #-4) | Add register or immediate |
r0 = sub(r1, r2) | Subtract |
r0 = and(r1, r2), or, xor, r0 = not(r1) | Logic |
r0 = mux(p0, r1, r2) | Select: p0 ? r1 : r2 |
p0 = cmp.gt(r1, r2), cmp.eq, cmp.gtu | Compare into a predicate (signed/unsigned) |
r0 = mpyi(r1, r2) | 32-bit multiply, low result |
r1:0 = mpy(r2, r3) | 32×32 → 64-bit multiply into a pair |
r0 += mpyi(r1, r2) | Multiply-accumulate |
r0 = asl(r1, #3), asr, lsr | Shifts |
r0 = add(r1, r2):sat | Saturating add: clamps instead of wrapping |
r1:0 = add(r3:2, r5:4) | 64-bit add on pairs |
r0 = vaddh(r1, r2) | Two 16-bit adds packed in 32 bits (small scalar SIMD) |
Saturation and packed halfword/byte operations are why Hexagon suits audio and fixed-point DSP: overflow clamps to the maximum instead of wrapping (overflow is recorded in usr).
Memory Instructions
| Load | Size | Store |
|---|---|---|
r0 = memb(...) / memub | 8-bit, signed / unsigned | memb(...) = r0 |
r0 = memh(...) / memuh | 16-bit | memh(...) = r0 |
r0 = memw(...) | 32-bit | memw(...) = r0 |
r1:0 = memd(...) | 64-bit into a pair | memd(...) = r1:0 |
Addressing Modes
| Mode | Syntax | Use |
|---|---|---|
| Base + offset | memw(r1 + #8) | Struct fields |
| Base + scaled index | memw(r1 + r2 << #2) | Arrays |
| Post-increment | memw(r1++#4) | Walking arrays in loops |
| Post-increment by modifier | memw(r1++m0) | Step held in m0/m1 |
| Circular | memw(r1++#4:circ(m0)) | Ring buffers using cs0/cs1 and m0 |
| Absolute / GP-relative | memw(#global), memw(gp + #x) | Globals and small data |
flowchart LR
B["r1 = buffer start"] --> L["r0 = memw(r1++#4)"]
L --> R["load from r1, then r1 = r1 + 4"]
R --> L
Loads and stores run in slots 0 and 1, so a packet holds at most two memory operations. Accesses must be naturally aligned (FP, HVX and Alignment).
Atomics
Hexagon uses a load-locked / store-conditional pair:
// illustrative: atomic increment of *r1
retry:
r2 = memw_locked(r1)
r2 = add(r2, #1)
memw_locked(r1, p0) = r2 // p0 = true if the store succeeded
if (!p0) jump retry
barrier orders memory operations between threads.
Sources: llvm/lib/Target/Hexagon/HexagonDepInstrInfo.td:21720, llvm/lib/Target/Hexagon/HexagonDepInstrInfo.td:21995, llvm/lib/Target/Hexagon/HexagonRegisterInfo.td:166-178
Control Instructions
| Instruction | Meaning |
|---|---|
jump label | Unconditional branch |
if (p0) jump:t label | Conditional branch with a taken hint |
p0 = cmp.eq(r0, #0); if (p0.new) jump:nt label | Compare and branch in one packet |
call func | Call: return address to r31 (lr) |
jumpr r31 | Return (jump to register) |
allocframe(#n) / deallocframe | Push/pop fp and lr and reserve stack |
dealloc_return | Restore frame and return in one instruction |
loop0(label, #N) / :endloop0 | Zero-overhead loop |
sequenceDiagram
participant A as caller
participant F as func
A->>F: call func (r31 = return address)
F->>F: allocframe(#16): save fp, lr; sp -= 16+8
F->>F: body
F->>A: dealloc_return: restore fp, lr, sp; jump to lr
A function in this style:
// illustrative: int sum(int *p, int n)
sum:
{ loop0(.L1, r1)
r2 = #0 }
.L1:
{ r3 = memw(r0++#4)
r2 = add(r2, r3) }:endloop0
{ r0 = r2
jumpr r31 }
Sources: llvm/lib/Target/Hexagon/HexagonDepInstrInfo.td:5020, llvm/lib/Target/Hexagon/HexagonDepInstrInfo.td:5639-5656
Key Points
- Data instructions include saturating, packed and multiply-accumulate forms for DSP work.
- Memory instructions have rich addressing: post-increment, modifiers, circular buffers; at most two per packet.
- Control uses predicates, compare-and-jump in one packet,
call/jumpr r31, frame helpers and hardware loops.
Floating Point, HVX and Alignment
Relevant source files
The following files were used as context for generating this wiki page:
- llvm/lib/Target/Hexagon/Hexagon.td
- llvm/lib/Target/Hexagon/HexagonRegisterInfo.td
- Wikipedia: Digital signal processor
- Qualcomm: Hexagon HVX Programmer's Reference Manual
Hexagon computes in three ways: scalar integer (previous page), scalar floating point in the general registers, and wide SIMD in the HVX vector unit. HVX is where most image, audio and neural-network throughput comes from. Both scalar and vector memory accesses have alignment rules worth learning early.
> Assembly on this page is illustrative and was not assembled. Instruction availability depends on the architecture version.
Purpose and Scope
This page covers scalar floating point, the HVX programming model (vector registers, lanes, instruction syntax, vector predicates, floating point), HVX contexts, and alignment rules. Caches and VTCM are on Caches, MMU and Glossary.
Scalar Floating Point
Floating point uses the ordinary general registers: single precision in one register, double precision in a pair. There is no separate FP register file.
| Instruction (general form) | Meaning |
|---|---|
r0 = sfadd(r1, r2) | Single-precision add |
r0 = sfmpy(r1, r2) | Single-precision multiply |
r0 += sfmpy(r1, r2) | Fused multiply-add |
p0 = sfcmp.gt(r1, r2) | Compare into a predicate |
r0 = convert_sf2w(r1) / convert_w2sf | Float ↔ integer |
r1:0 = dfadd(r3:2, r5:4) | Double-precision add (newer versions) |
Rounding mode and exception flags live in usr (Registers).
The HVX Model
flowchart LR
subgraph Core["Hexagon core"]
T0["thread 0"]
T1["thread 1"]
T2["thread 2"]
end
subgraph HVXU["HVX unit"]
C0["HVX context A<br/>v0-v31, q0-q3"]
C1["HVX context B"]
end
T0 -->|"acquire"| C0
T2 -->|"acquire"| C1
HVXU --> VT["VTCM / L2"]
| Concept | Meaning |
|---|---|
| Vector length | 64 bytes or 128 bytes (hvx-length64b / hvx-length128b); 128 B on recent chips |
| Registers | v0-v31, pairs v1:0…, predicates q0-q3 |
| Lanes | The element type is written on the register: .b byte, .h halfword, .w word, .ub/.uh unsigned, .sf/.hf float |
| Contexts | Fewer HVX contexts than scalar threads; a thread must own one to run HVX code |
| Issue | HVX instructions sit in packets with scalar ones and use their own vector resources |
With 128-byte vectors one register holds 128 bytes, 64 halfwords or 32 words.
// illustrative: c[i] = a[i] + b[i] for 32 words at a time (128-byte HVX)
{ v0 = vmem(r0++#1) } // load 128 bytes, advance by one vector
{ v1 = vmem(r1++#1) }
{ v2.w = vadd(v0.w, v1.w) } // 32 word adds
{ vmem(r2++#1) = v2 } // store 128 bytes
| HVX operation family | Example |
|---|---|
| Arithmetic | v2.h = vadd(v0.h, v1.h):sat |
| Multiply / multiply-accumulate | v3:2.w += vmpy(v0.h, v1.h) (widening into a pair) |
| Compare into a vector predicate | q0 = vcmp.gt(v0.w, v1.w) |
| Predicated select | v2 = vmux(q0, v0, v1) |
| Permute / shuffle | vshuff, vdeal, valign, vlut |
| Reduce, saturate, narrow | vasr, vsat, vpack |
flowchart LR
A["v0.w: a0 a1 ... a31"] --> ADD["vadd(.w)"]
B["v1.w: b0 b1 ... b31"] --> ADD
ADD --> R["v2.w: a0+b0 ... a31+b31"]
HVX Floating Point
From V68, HVX can do floating point. LLVM has two feature switches: hvx-qfloat (Qualcomm's "qfloat" format with extra internal precision, converted to IEEE when stored) and hvx-ieee-fp (IEEE half and single precision arithmetic).
Sources: llvm/lib/Target/Hexagon/Hexagon.td:32-96, llvm/lib/Target/Hexagon/HexagonRegisterInfo.td:521
Alignment
flowchart TD
A["Memory access"] --> S{"Scalar or vector?"}
S -->|"scalar memh/memw/memd"| N{"Address multiple of size?"}
N -->|"yes"| OK["OK"]
N -->|"no"| X["Misaligned access exception"]
S -->|"vector vmem"| V["Address rounded down to the vector size<br/>(low bits ignored)"]
S -->|"vector vmemu"| U["Unaligned load, costs more"]
| Access | Rule |
|---|---|
memh / memw / memd | Must be 2-, 4-, 8-byte aligned; otherwise an exception |
vmem | Treated as aligned to the vector size: low address bits are ignored, so a misaligned pointer silently reads the wrong bytes |
vmemu | Unaligned vector load; slower |
valign / vlalign | Combine two aligned loads into one unaligned vector, the usual fast technique |
Practical rule: align buffers for HVX to 128 bytes (__attribute__((aligned(128))) or an aligned allocator).
Key Points
- Scalar FP uses general registers and pairs; HVX adds 32 vector registers of 64 or 128 bytes.
- HVX lanes are typed by suffix (
.b,.h,.w,.sf);qregisters mask lanes; V68+ adds vector FP. - Scalar accesses must be naturally aligned;
vmemsilently aligns; usevmemuorvalignfor unaligned data.
Caches, MMU and Glossary
Relevant source files
The following files were used as context for generating this wiki page:
- llvm/lib/Target/Hexagon/HexagonDepInstrInfo.td
- Qualcomm: Hexagon V6x/V7x Programmer's Reference Manual (memory system) and System-Level Specification
Hexagon has a conventional cache hierarchy plus a fast local memory for vectors (VTCM), and an MMU that the real-time OS (QuRT) programs. Application code mostly meets the memory system through a handful of cache instructions: prefetch, clean, invalidate and zero.
> Cache sizes, associativity and MMU details vary by chip and are described generally here from Qualcomm's public manuals. Instruction names are cited from LLVM. Assembly is illustrative.
Purpose and Scope
This page covers the memory hierarchy, VTCM, cache maintenance and prefetch instructions, the MMU and privilege model, and a glossary of the whole wiki.
Memory Hierarchy
flowchart TD
T["Hardware threads"] --> L1I["L1 instruction cache"]
T --> L1D["L1 data cache (scalar)"]
H["HVX unit"] -->|"vector loads bypass L1D"| L2["L2 cache (unified, shared by threads)"]
H --> VT["VTCM: vector tightly coupled memory<br/>software-managed, low latency"]
L1D --> L2
L1I --> L2
L2 --> DDR["System DRAM via the SoC interconnect"]
| Level | Notes (general) |
|---|---|
| L1 I / L1 D | Small, per core, shared by the core's threads |
| L2 | Larger, unified; HVX loads and stores go here rather than L1 D |
| VTCM | On-chip memory for HVX data; not a cache: software copies data in and out (often with DMA) |
| DRAM | Shared with the CPU and GPU |
Cache Instructions
| Instruction | Effect | Typical use |
|---|---|---|
dcfetch(r0) / dcfetch(r0+#n) | Hint: bring a line into the data cache | Software prefetch |
l2fetch(r0, r1) | Background prefetch of a 2-D block into L2 (width, height, stride in r1) | Prefetch image tiles ahead of an HVX loop |
dccleana(r0) | Write a dirty line back to memory | Before another agent reads the buffer |
dcinva(r0) | Invalidate a line, dropping its data | After another agent wrote the buffer |
dczeroa(r0) | Allocate a line and fill it with zero, without reading memory | Fast zeroing of output buffers |
icinva(r0) + isync | Invalidate instruction cache line, then resynchronise | After writing code |
barrier, syncht | Order or drain memory operations | Synchronisation with other threads or devices |
sequenceDiagram
participant D as DSP thread
participant C as Cache
participant M as Shared memory
participant X as Other agent (CPU, DMA)
D->>C: write results (dirty lines)
D->>C: dccleana each line
C->>M: write back
D->>X: signal "buffer ready"
X->>M: read results
X->>M: write new input
D->>C: dcinva each line (drop stale copies)
D->>M: read new input
Sources: llvm/lib/Target/Hexagon/HexagonDepInstrInfo.td:41156-41214, llvm/lib/Target/Hexagon/HexagonDepInstrInfo.td:41263, llvm/lib/Target/Hexagon/HexagonDepInstrInfo.td:41326-41374, llvm/lib/Target/Hexagon/HexagonDepInstrInfo.td:41490, llvm/lib/Target/Hexagon/HexagonDepInstrInfo.td:41611-41710
MMU and Privilege
Hexagon has an MMU, managed by the operating system rather than by applications.
| Feature (general) | Description |
|---|---|
| Software-managed TLB | The OS fills a joint TLB on misses; no hardware page-table walker on classic designs |
| Page sizes | Several sizes, from small pages up to large ones for big buffers |
| Per-page attributes | Read/write/execute, user/supervisor, cacheability |
| Address-space IDs | Tag TLB entries per process, avoiding flushes on switches |
| Modes | User, guest-OS (supervisor), and monitor, with system registers only accessible above user mode |
flowchart LR
VA["Virtual address"] --> TLB{"TLB hit?"}
TLB -->|"yes"| PA["Physical address + attributes"]
TLB -->|"no"| EX["TLB-miss exception"] --> OS["QuRT fills the TLB entry"] --> TLB
Background on paging and TLBs: OS wiki: Memory Management.
Glossary
| Term | Meaning | Page |
|---|---|---|
.new | Use a value produced in the same packet | ISA Fundamentals |
:endloop0 | Marks the last packet of hardware loop 0 | ISA Fundamentals |
| Constant extender | immext word supplying the high 26 bits of an immediate | Encoding |
| Duplex | One word containing two 13-bit sub-instructions | Encoding |
| FastRPC | Mechanism for CPU code to call DSP code | Overview |
| HVX | Hexagon Vector eXtensions, 64/128-byte SIMD | FP, HVX and Alignment |
| HVX context | A set of vector registers a thread must hold to run HVX | FP, HVX and Alignment |
l2fetch | Background 2-D prefetch into L2 | this page |
lc0/sa0 | Loop count / start address of hardware loop 0 | Registers |
| Packet | Up to four instructions issued together | ISA Fundamentals |
| Parse bits | Bits 15:14 marking packet end, loop end, or duplex | Encoding |
| Predicate register | p0-p3, comparison results | Registers |
| QuRT | Qualcomm's real-time OS on Hexagon | Overview |
| Slot | One of four execution positions in a packet | ISA Fundamentals |
usr | User status register (flags, rounding) | Registers |
| VLIW | Very long instruction word: compiler-scheduled parallel issue | Overview |
vmem / vmemu | Aligned / unaligned vector memory access | FP, HVX and Alignment |
| VTCM | Software-managed local memory for HVX | this page |
Key Points
- L1 caches serve scalar code; HVX goes to L2 and VTCM, which software manages.
- Prefetch, clean, invalidate and zero instructions keep data where it is needed and coherent with other agents.
- The OS-managed MMU uses a software-filled TLB with per-page attributes and address-space IDs.