Repository navigation
Hexagon ISA 04 encoding
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.
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.
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
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.
| 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
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
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
- 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.
- 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