Machine Code Generation for C++
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).
FuncFramedoesn'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:
None or invalid (can't be used).
Standard function call or explicit
This is a universal calling convention, which is used to initialize specific calling connventions based on architecture, platform, and its ABI.
Soft-float calling convention (ARM).
Floating point arguments are passed via general purpose registers.
Hard-float calling convention (ARM).
Floating point arguments are passed via SIMD registers.
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...
X64 System-V calling convention.
X64 Windows calling convention.
Maximum value of
Host calling convention detected at compile-time.
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.
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).