Chasm is an easy-to-use, high-performance runtime assembler that assembles up to 100 million instructions per second. Ideal for JIT compilers, emulators, and runtime optimizations, it supports AVX-256 and various x86 extensions with minimal function calls, simplifying dynamic code generation.
Overview
The Chasm Runtime Assembler, or Chasm, is a high-performance assembler designed for ease of use and efficiency, allowing dynamic generation of machine code across various platforms. Leveraging a simple API, Chasm brings advanced features such as AVX-256 support, making it ideal for applications requiring runtime code generation.
Key Features
- Ease of Use: Integrate Chasm into your projects with minimal effort. Utilizing only two main function calls, code can be assembled and executed seamlessly.
- High Speed: Capable of assembling up to 100 million instructions per second, optimizing performance.
- Extensive Support: Includes support for AVX-256 and many x86 extensions, offering broad coverage for various modern computing needs.
- Flexible Syntax: Offers a user-friendly, flexible syntax that accommodates diverse coding styles and practices.
- Debugging Made Easy: Features like instruction set stringification with
x64stringify
simplify debugging and inspection of intermediate representation (IR). - Simple Error Handling: Utilize easy error handling mechanisms, with functions returning
0
to indicate failure and quick access to error details withx64error(NULL)
.
Use Cases
Chasm excels in scenarios where code is dynamically generated or executed at runtime, including:
- Just-In-Time (JIT) Compilers
- Emulators
- Code Generation and Runtime Optimizations
- Performance Testing and Benchmarking Tools
Performance
Optimized to handle assembly tasks efficiently, Chasm precomputes as much as it can, often assembling instructions within 15 to 30 nanoseconds, varying with optimization levels.
API Overview
Defining Instructions
Chasm uses an array of x64Ins
structs to define code:
x64 code = { MOV, rax, imm(0) };
Here, rax
is an example of x86 registers, predefined as macros, making code definition straightforward.
Memory References
Leverage powerful macros like mem()
, m<size>()
, or rel()
to define complex memory address computations:
x64 code = { LEA, rax, mem($rax, 0x0ffe, $rdx, 2, $ds) };
Functions
x64as()
: Assembles and links code, supportingrel()
andmem($riprel)
syntax.x64emit()
: Assembles a single instruction quickly without linking.x64exec()
: Allocates executable memory for the assembled code and provides a callable function pointer.x64exec_free()
: Frees memory allocated byx64exec()
.x64stringify()
: Converts IR sequences to string format for easier debugging.
Limitations
Currently, Chasm does not support some instruction sets and platforms:
- Lacks support for protected mode and ARM instructions.
- Does not support AVX-512 due to its potential CPU performance drawbacks.
Chasm remains an adaptable tool with plans for expanded instruction set support in future updates.
No comments yet.
Sign in to be the first to comment.