Low-Latency Machine Code Generation
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:
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:
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.
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...
Soft-float calling convention (AArch32).
Floating point arguments are passed via general purpose registers.
Hard-float calling convention (AArch32).
Floating point arguments are passed via SIMD registers.
X64 System-V calling convention.
X64 Windows calling convention.
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.
Default register assignment strategy.
Windows 64-bit ABI register assignment strategy.
Windows 64-bit __vectorcall register assignment strategy.
Maximum value of
Calling convention flags.
Callee is responsible for cleaning up the stack.
Pass vector arguments indirectly (as a pointer).
Pass F32 and F64 arguments via VEC128 register.
Pass MMX and vector arguments via stack if the function has variable arguments.
MMX registers are passed and returned via GP registers.
MMX registers are passed and returned via XMM registers.
Calling convention can be used with variable arguments.
Attributes are designed in a way that all are initially false, and user or FuncFrame finalizer adds them when necessary.
Function has variable number of arguments.
Preserve frame pointer (don't omit FP).
Function calls other functions (is not leaf).
Function has aligned save/restore of vector registers.
Function must begin with an instruction that marks a start of a branch or function.
* `ENDBR32/ENDBR64` instruction is inserted at the beginning of the function (X86, X86_64). * `BTI` instruction is inserted at the beginning of the function (AArch64)
FuncFrame is finalized and can be used by prolog/epilog inserter (PEI).
Enables the use of AVX within the function's body, prolog, and epilog (X86).
This flag instructs prolog and epilog emitter to use AVX instead of SSE for manipulating XMM registers.
Enables the use of AVX-512 within the function's body, prolog, and epilog (X86).
This flag instructs Compiler register allocator to use additional 16 registers introduced by AVX-512. Additionally, if the functions saves full width of ZMM registers (custom calling conventions only) then the prolog/epilog inserter would use AVX-512 move instructions to emit the save and restore sequence.
This flag instructs the epilog writer to emit EMMS instruction before RET (X86).
This flag instructs the epilog writer to emit VZEROUPPER instruction before RET (X86).