AsmJit
Low-Latency Machine Code Generation
Function definitions.
AsmJit provides functionality that can be used to define function signatures and to calculate automatically optimal function frame that can be used directly by a prolog and epilog insertion. This feature was exclusive to AsmJit's Compiler for a very long time, but was abstracted out and is now available for all users regardless of the emitter they use. The following use cases are possible:
The following concepts are used to describe and create functions in AsmJit:
int8_t
, uint32_t
, uintptr_t
, float
, double
, and all possible vector types to match ISAs up to AVX512. TypeId was introduced originally for Compiler, but it's now used by FuncSignature as well.int func(int, int)
. FuncSignature contains a function calling convention id, return value type, and function arguments. The signature itself is platform independent and uses TypeId to describe types of function arguments and function return value(s).FuncFrame
doesn't know anything about function's arguments or return values, it hold only information necessary to create a valid and ABI conforming function prologs and epilogs.It's a lot of concepts where each represents one step in a function frame calculation. It can be used to create function prologs, epilogs, and also to calculate information necessary to perform function calls.
Calling convention id.
Calling conventions can be divided into the following groups:
Constant | Description |
---|---|
kCDecl | Standard function call or explicit This is a universal calling convention, which is used to initialize specific calling conventions based on architecture, platform, and its ABI. |
kStdCall |
|
kFastCall |
|
kVectorCall |
|
kThisCall |
|
kRegParm1 |
|
kRegParm2 |
|
kRegParm3 |
|
kLightCall2 | AsmJit specific calling convention designed for calling functions inside a multimedia code that don't use many registers internally, but are long enough to be called and not inlined. These functions are usually used to calculate trigonometric functions, logarithms, etc... |
kSoftFloat | Soft-float calling convention (AArch32). Floating point arguments are passed via general purpose registers. |
kHardFloat | Hard-float calling convention (AArch32). Floating point arguments are passed via SIMD registers. |
kX64SystemV | X64 System-V calling convention. |
kX64Windows | X64 Windows calling convention. |
kMaxValue | Maximum value of |
Strategy used by calling conventions to assign registers to function arguments.
Calling convention strategy describes how AsmJit should convert function arguments used by FuncSignature into register identifiers and stack offsets. The CallConvStrategy::kDefault strategy assigns registers and then stack whereas CallConvStrategy::kX64Windows strategy does register shadowing as defined by WIN64 calling convention, which is only used by 64-bit Windows.
Calling convention flags.
Attributes are designed in a way that all are initially false, and user or FuncFrame finalizer adds them when necessary.