Status: Alpha
NativeASM is a Win64/x86-64 machine-code generation and runtime instrumentation toolkit for Delphi.
The project is intentionally practical in scope. Some parts are deliberately small and direct, while other parts are more structured where the problem benefits from it. NativeASM does not try to model every x86-64 feature, replace a full compiler backend, or hide all low-level details behind a large abstraction layer.
Development is driven by technical interest and available time. There is no guaranteed release schedule, long-term maintenance commitment, or response time for issues and pull requests. APIs, supported instruction subsets, and internal architecture may still change. Contributions, independent research, extensions, and forks are welcome. If active development of this repository slows down or stops, the source will remain available so others can study, adapt, and continue the work independently.
NOTE JIT and runtime generated machine code can trigger heuristic or machine learning based antivirus detections in some environments.
- Fluent x86-64 instruction builder for Delphi, now also covering string instructions, atomics (
CMPXCHG/XADD/CMPXCHG8B/CMPXCHG16B),LOCK/REP/REPE/REPNEprefixes, extended shifts/bit-test ops, flag and CPU-state instructions, andXSAVE/FXSAVEfamily context save/restore. - Static instruction database with operand validation and deterministic form selection.
- JIT allocation and execution on Win64, including batch allocation, self-modifying-code support, and a growable code cache.
- Labels, fixups, alignment, constant pools, stubs, and Win64 ABI helpers, plus a Win64 SEH unwind-info builder and a higher-level function-frame builder for generated functions.
- SIMD support covering selected SSE/SSE2/SSSE3/SSE4.x, AES, SHA, PCLMULQDQ, and related instructions.
- AVX, AVX2, and FMA encoder with typed per-mnemonic helpers and a generic mnemonic-based API.
- BMI and BMI2 encoder (
ANDN,BEXTR,BZHI,MULX,PDEP,PEXT,SHLX/SHRX/SARX,RORX, and theBLS*family). - CPU feature detection and runtime dispatch helpers, covering SSE/AVX/AVX2/FMA/BMI/BMI2 and other selected extensions.
- Instruction maps and symbol/address resolution for generated code.
- Disassembly backed by NativeASM instruction metadata, covering the core, SIMD, AVX, and BMI databases.
- Runtime software breakpoints with context capture and byte restoration.
- Core regression tests plus higher-level Showcase libraries and benchmarks, and dedicated AVX/AVX2/BMI audit, closure, and showcase projects.
NativeASM is currently Win64 only. The core source enforces a 64-bit Windows target.
var
B: TAsmBuilder;
R: UInt64;
begin
B := TAsmBuilder.New;
try
B.Mov(RAX, RCX)
.Add(RAX, RDX)
.Ret;
R := B.Run(10, 32); // R = 42
finally
B.Free;
end;
end;This builds and executes a Win64 function that returns RCX + RDX.
Delphi code
|
v
TAsmBuilder
|
+--> operand and API validation
|
v
InstructionDB / SIMD DB
|
v
static encoders
|
v
machine code + labels/fixups
|
v
JIT memory
|
v
native x86-64 execution
The runtime does not parse the AsmJit JSON database. The JSON data is development-time input for NativeASM's checked-in generated tables.
The current generated core database contains 187 mnemonics, 619 concrete encoding forms, and 1146 operand descriptors. The current generated SIMD database contains 275 mnemonics, 338 forms, and 719 operand descriptors. The current generated AVX/AVX2/FMA database contains 340 mnemonics, 644 forms, and 1814 operand descriptors. The current generated BMI/BMI2 database contains 13 mnemonics, 26 forms, and 72 operand descriptors. These numbers describe the current NativeASM subset, not the complete x86/x64 ISA; some source forms are intentionally retained as metadata without being exposed through the public Builder API. See README_STATIC_DB.md for the database model, generation process, restrictions, and regeneration tools.
NativeASM contains more than an encoder. Generated code can be associated with instruction maps and symbols, decoded again, and instrumented with software breakpoints.
Relevant documentation:
The JIT path uses writable memory while generating code and transitions it to executable protection for execution. Debugger-style runtime patching can temporarily change page protection when a breakpoint byte is installed or restored.
TWin64FunctionFrame (NativeAsm.Functions.Win64.pas) builds the stack layout for a generated function:
- local stack slots (
AddLocal) - nonvolatile GPR saves (
PreserveGpr) and nonvolatile XMM saves (PreserveXmm) - shadow-space and stack-alignment handling for frames that call out to other functions (
CallsOtherFunctions) FinalizeLayoutfixes slot offsets and sizes, after whichEmitProlog/EmitEpilogemit the matching push/sub/pop/add sequence into aTAsmBuilderand record the exact code offset of each prolog operation
AddUnwindFunction feeds that frame layout directly into TWin64UnwindFunction/TWin64UnwindPlan (NativeAsm.Unwind.Win64.pas), which builds a real Win64 UNWIND_INFO and RUNTIME_FUNCTION table, including chained functions and exception/unwind handlers, and can register it with the OS through RtlAddFunctionTable or the growable function-table APIs. TWin64GrowableJitCache (NativeAsm.Extensions.pas) ties this together for code that keeps adding functions over time, keeping growable JIT regions and their unwind registration in sync.
This gives generated Win64 functions correct unwind information so Windows structured exception handling, debuggers, and stack walkers can unwind through JIT-generated code.
NativeASM includes a separate SIMD encoding layer and selected CPU-extension support. The project currently demonstrates SSE-family code, CRC32/CRC32C, AES-NI, SHA extensions, POPCNT, PCLMULQDQ, AVX, AVX2, FMA, and BMI/BMI2 among other covered operations.
See:
Showcase/ contains higher-level code built on NativeASM rather than additional core dependencies. It includes practical algorithms, SIMD paths, cryptographic primitives, BigInt arithmetic, ECC experiments, pattern matching, self-tests, and benchmarks.
Examples currently include CRC, Base64, Hex, Bloom/hash utilities, Aho-Corasick, Levenshtein, ChaCha20, Poly1305, ChaCha20-Poly1305, BLAKE3, Xoshiro256++, multi-precision arithmetic, Montgomery arithmetic, X25519/Ed25519, secp256k1, and P-256 related code.
The Showcase exists primarily to demonstrate what can be expressed, generated, executed, and tested with NativeASM. It is not presented as a collection of audited production cryptography or as the final/optimal implementation of every demonstrated algorithm.
See Showcase/README.md.
Separate top-level directories demonstrate the AVX/AVX2/FMA and BMI/BMI2 encoders with real JIT-generated workloads:
- AVXShowcase/README.md: AVX/FMA FFT, matrix transpose, Mandelbrot, Horner/FMA polynomial evaluation, float edge-case checks, and an AVX face-detection pipeline.
- AVX2Showcase/README.md: a packed-integer AVX2 Conway's Game of Life kernel.
- AVX2Test/README.md: the AVX2 closure/certification suite (database coverage, a GNU Binutils golden matrix, runtime semantics, and mixed integration tests).
AVXTests/: DUnitX tests for the AVX and BMI encoders.
Open the Delphi project/group files in RAD Studio and build for Win64.
A small console demo can also be compiled with dcc64, for example from Demo/:
dcc64.exe NativeAsmDemo.dpr -B -U..\Source
The generated instruction database is checked in. Normal users do not need Python, PowerShell generation scripts, AsmJit, or JSON parsing at runtime.
The current development snapshot has been exercised locally with the following results:
| Suite | Result |
|---|---|
| Showcase DUnitX | 158 / 158 passed |
| Feature DUnitX | 73 / 73 passed |
| Showcase self-test | 19 / 19 groups passed |
| NativeAsmEncodingTests | 277 passed |
| StaticDbRegression | OK |
Additional demos for breakpoints, instruction maps, disassembly, SHA encodings, and the benchmark projects have also been run successfully during development, along with the AVX/BMI audit, AVX2 closure, and AVX/AVX2 showcase projects.
These results describe the currently covered behavior. They are not a claim of complete ISA coverage or formal verification.
The repository contains both core and practical benchmark projects. They are intended to measure NativeASM overhead and to demonstrate the performance available from generated CPU-specific code.
Benchmark results are hardware, compiler, build-mode, and workload dependent. Publish numbers together with the system and build configuration used to produce them.
Source/ NativeASM core
Tests/ core, feature, encoding, and regression tests
AVXTests/ DUnitX tests for the AVX and BMI encoders
AVX2Test/ AVX2 closure/certification suite
Tools/ instruction DB generation and verification tools
Demo/ small core demonstrations
Benchmarks/ core and practical benchmarks
Showcase/ higher-level examples and libraries built on NativeASM
AVXShowcase/ AVX/FMA showcase workloads
AVX2Showcase/ AVX2 packed-integer showcase
See STRUCTURE.md for the dependency split between core and Showcase.
For the current alpha, assume the following:
- APIs and internal structures can still change.
- Instruction coverage is intentionally incomplete.
- Some valid x86 forms are intentionally not exposed by the public Builder API.
- Some implementations favor a focused, pragmatic solution over maximum generality.
- NativeASM is not a compiler optimizer, register allocator, SSA framework, or LLVM replacement.
- Showcase implementations are demonstrations of the framework and can be simpler or more specialized than a production library would choose to be.
- There is no branch relaxation or code layout pass: labels and fixups use the existing rel32 model as-is, with no automatic shortening or reordering.
- EVEX and APX have internal encoding-model support in
Source/NativeAsm.X86.*.pas, but no EVEX/APX instruction form is wired up yet, so no EVEX/APX instruction can currently be generated through the Builder.
The guiding idea is simple: keep the implementation direct where that is sufficient, and add complexity only where it solves a real problem for the framework.
NativeASM includes several demos and tools that exercise code generation, runtime instrumentation, disassembly, instruction mapping, and JIT execution.
NativeASM uses x86 instruction database material and design/test inspiration from AsmJit, created and maintained by Petr Kobalicek.
The checked-in Tools/isa_x86.json file is an exact copy of AsmJit's db/isa_x86.json from commit:
0bd5787b54b575ed94bf32ac452153b34385c514
Its SHA-256 is:
0bc3fde0376e3c7db93ce1fa6da35b9d69b868db738e60dba382a2bee54d1f48
NativeASM uses this JSON file only as development-time input. NativeASM's generators select and transform supported information into NativeASM-specific generated Pascal tables. AsmJit is not a runtime dependency.
Test ideas, test organization, and selected encoding vectors were also inspired by or adapted from the AsmJit test suite at commit:
dffd8b164f228abbc47246c9881f107d656952b2
Reference date: 2026-09-16.
NativeASM is an independent Delphi project and is not affiliated with or endorsed by AsmJit.
AsmJit is distributed under the zlib License. The original license text is preserved in Tools/ASMJIT_LICENSE.md. Detailed database provenance is recorded in Tools/ASMJIT_SOURCE.md, and test-specific attribution is recorded in Tests/ASMJIT_TEST_SOURCE.md.
See THIRD_PARTY_NOTICES.md for the consolidated third-party notice.
MIT license. Provided as is. The AsmJit-derived material remains subject to AsmJit's zlib License regardless of the license selected for NativeASM's original code.



