Repository navigation
Hexagon ISA 06 hvx
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.
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.
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).
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"]
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
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).
- 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.
- Computer Architecture Overview
- Fundamentals: CPU, Memory and Instructions
- Pipelining
- Branches and Remedies
- Instruction-Level Parallelism
- Memory and Ordering
- Caches and Coherence
- Multicore
- Multithreading in Hardware
- SIMD and GPUs
- Glossary and Summary
- Hexagon Overview and Processor Properties
- ISA Fundamentals: Packets, Slots and Threads
- Registers
- Instruction Encoding and Mnemonics
- Data, Memory and Control Instructions
- Floating Point, HVX and Alignment
- Caches, MMU and Glossary
- Operating Systems Overview
- Processes
- Threads
- CPU Scheduling
- Synchronization
- Deadlock
- Memory Management
- Virtual Memory
- Files, Storage and I/O
- Kernel and System Calls
- Interview Q&A and Glossary
- C++ for LLVM Development: Overview
- C++ Basics
- Classes and RAII
- Ownership and Move Semantics
- Templates and Lambdas
- LLVM Data Structures (ADT)
- LLVM-Style RTTI: isa, cast, dyn_cast
- Errors, Output and Assertions
- Iterators and Ranges
- Building, Debugging and Exercises
- LLVM IR Overview
- Structure: Modules, Functions, Blocks and Values
- Type System
- Arithmetic, Bitwise and Cast Instructions
- Compare and Select
- Memory: alloca, load, store and getelementptr
- Control Flow: br, switch, ret and call
- SSA and Phi
- Control Flow Graph and Loops
- Dominance, Dominator Tree and Dominance Frontier
- Data-flow Analysis
- Writing an IR Pass
- Common Passes
- Exercises, Tooling and Glossary
- SelectionDAG Overview
- Pipeline, Phases and Traversal Orders
- Core Data Structures
- DAG Construction
- DAG Combiner
- Legalization
- Type Legalization
- Operation and Vector Legalization
- Instruction Selection
- TableGen Pattern Language
- Matcher Interpreter and Folding
- AArch64 Instruction Selection
- Scheduling and MIR Emission
- PHI Node Resolution
- AArch64 Walkthroughs
- Arithmetic and Data Movement
- Memory Instructions
- Control Flow and Calls
- End-to-End Example
- Tooling, Debugging and Extending
- Selector Comparison and Glossary
- Assignments: Build the Toy Backend
- Stage 1: Build Setup
- Stage 2: Target Registration
- Stage 3: TableGen Skeleton
- Stage 4: MC Layer for Assembly Output
- Stage 5: TargetMachine and Subtarget
- Stage 6: TargetLowering, Arguments and Returns
- Stage 7: Instruction Selection and the First Function
- Stage 8: Registers, Copies and Spills
- Stage 9: Frame Lowering
- Stage 10: Memory, Globals and Control Flow
- Stage 11: Calls
- Stage 12: Scheduling Model
- Stage 13: Object Files
- Stage 14: Capstone, a Complete Toy Backend
- Target Bring-up Overview
- Directory Layout, CMake and Registration
- The Target .td File
- TargetMachine and Subtarget
- TargetLowering Setup
- Calling Conventions
- Instructions and Instruction Selection
- Registers and Allocation Hooks
- Frame Lowering
- AsmPrinter and the MC Layer
- Scheduling
- A Minimal Toy Target
- Bring-up Checklist and AArch64 File Map
- Tooling and Glossary
- Calling Conventions Overview
- The CallingConv.td Language
- CCState and CCValAssign
- LowerFormalArguments
- LowerCall
- LowerReturn and CanLowerReturn
- Varargs, byval, sret and swifterror
- Tail Calls and Sibling Calls
- Custom Backend Guide and Checklist
- AArch64 Walkthroughs
- Tooling and Glossary
- Frame Lowering Overview
- MachineFrameInfo
- TargetFrameLowering Hooks
- The PEI Pass
- Callee-Saved Registers and Stack Layout
- Frame Index Elimination and the Register Scavenger
- Shrink Wrapping
- CFI and Unwind Information
- Custom Backend Guide and Checklist
- AArch64 Walkthroughs
- Tooling and Glossary
- MC Layer Overview
- Core Data Structures
- Streamers
- Assembler and Layout
- Fixups and Relocations
- Writing an MC Layer for a Custom Backend
- MCAsmInfo and the Instruction Printer
- Code Emitter
- AsmBackend and Object Writer
- Assembly Parser and Disassembler
- Bring-up Checklist and Common Failures
- Tooling and Glossary
- Register Allocation Overview
- The Register Allocation Pipeline
- Registers, Virtual Registers and Register Classes
- Liveness: Slot Indexes and Live Intervals
- Preparing Code for Allocation
- PHI Elimination and Two-Address Lowering
- Register Coalescer
- Allocation Framework
- The Register Allocators
- Fast Register Allocator
- Basic Register Allocator
- Greedy Register Allocator
- PBQP Register Allocator
- Spilling and Splitting
- Spill Weights and Copy Hints
- The Inline Spiller
- Live Range Splitting
- Rewriting and Post-RA Passes
- Writing Register Allocation Support for a Custom Backend
- Register Definitions in TableGen
- TargetRegisterInfo Hooks
- TargetInstrInfo Hooks
- Pass Pipeline Hooks
- Bring-up Checklist and Common Failures
- AArch64 Walkthroughs
- Tooling and Debugging
- Glossary and Where Do I Look