asmjit::CallConv Struct Reference

Function calling convention.

Function calling convention is a scheme that defines how function parameters are passed and how function returns its result. AsmJit defines a variety of architecture and OS specific calling conventions and also provides a compile time detection to make the code-generation easier.

Public Members

Classes

Public Types

Member Functions

Construction & Destruction
Accessors

Member Enumeration Documentation

CallConv::Limits : uint32_tenum

Internal limits of AsmJit's CallConv.

ConstantDescription
kMaxRegArgsPerGroup 

Maximum number of register arguments per register group.

\note This is not really AsmJit's limitatation, it's just the number
that makes sense considering all common calling conventions. Usually
even conventions that use registers to pass function arguments are
limited to 8 and less arguments passed via registers per group. 

CallConv::Id : uint32_tenum

Calling convention id.

Calling conventions can be divided into the following groups:

  • Universal - calling conventions are applicable to any target. They will be converted to a target dependent calling convention at runtime by init(). The purpose of these conventions is to make using functions less target dependent and closer to how they are declared in C and C++.
  • Target specific - calling conventions that are used by a particular architecture and ABI. For example Windows 64-bit calling convention and AMD64 SystemV calling convention.
ConstantDescription
kIdNone 

None or invalid (can't be used).

kIdCDecl 

Standard function call or explicit __cdecl where it can be specified.

This is a universal calling convention, which is used to initialize
specific calling connventions based on architecture, platform, and its ABI. 
kIdStdCall 

__stdcall on targets that support this calling convention (X86).

\note This calling convention is only supported on 32-bit X86. If used
on environment that doesn't support this calling convention it will be
replaced by \ref kIdCDecl. 
kIdFastCall 

__fastcall on targets that support this calling convention (X86).

\note This calling convention is only supported on 32-bit X86. If used
on environment that doesn't support this calling convention it will be
replaced by \ref kIdCDecl. 
kIdVectorCall 

__vectorcall on targets that support this calling convention (X86/X64).

\note This calling convention is only supported on 32-bit and 64-bit
X86 architecture on Windows platform. If used on environment that doesn't
support this calling it will be replaced by \ref kIdCDecl. 
kIdThisCall 

__thiscall on targets that support this calling convention (X86).

\note This calling convention is only supported on 32-bit X86 Windows
platform. If used on environment that doesn't support this calling
convention it will be replaced by \ref kIdCDecl. 
kIdRegParm1 

__attribute__((regparm(1))) convention (GCC and Clang).

kIdRegParm2 

__attribute__((regparm(2))) convention (GCC and Clang).

kIdRegParm3 

__attribute__((regparm(3))) convention (GCC and Clang).

kIdSoftFloat 

Soft-float calling convention (ARM).

Floating point arguments are passed via general purpose registers. 
kIdHardFloat 

Hard-float calling convention (ARM).

Floating point arguments are passed via SIMD registers. 
kIdLightCall2 

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...

kIdX64SystemV 

X64 System-V calling convention.

kIdX64Windows 

X64 Windows calling convention.

kIdHost 

Host calling convention detected at compile-time.

CallConv::Strategy : uint32_tenum

Strategy used to assign registers to function arguments.

This is AsmJit specific. It basically describes how AsmJit should convert the function arguments defined by FuncSignature into register IDs and stack offsets. The default strategy kStrategyDefault assigns registers and then stack whereas kStrategyWin64 strategy does register shadowing as defined by WIN64 calling convention - it applies to 64-bit calling conventions only.

ConstantDescription
kStrategyDefault 

Default register assignment strategy.

kStrategyX64Windows 

Windows 64-bit ABI register assignment strategy.

kStrategyX64VectorCall 

Windows 64-bit __vectorcall register assignment strategy.

kStrategyCount 

Number of assignment strategies.

CallConv::Flags : uint32_tenum

Calling convention flags.

ConstantDescription
kFlagCalleePopsStack 

Callee is responsible for cleaning up the stack.

kFlagIndirectVecArgs 

Pass vector arguments indirectly (as a pointer).

kFlagPassFloatsByVec 

Pass F32 and F64 arguments via VEC128 register.

kFlagPassVecByStackIfVA 

Pass MMX and vector arguments via stack if the function has variable arguments.

kFlagPassMmxByGp 

MMX registers are passed and returned via GP registers.

kFlagPassMmxByXmm 

MMX registers are passed and returned via XMM registers.

kFlagVarArgCompatible 

Calling convention can be used with variable arguments.

Member Function Documentation

Error CallConv::init(uint32_t ccId, const Environment& environment)noexcept

Initializes this calling convention to the given ccId based on the environment.

See Id and Environment for more details.

void CallConv::reset()noexcept

Resets this CallConv struct into a defined state.

It's recommended to reset the CallConv struct in case you would like create a custom calling convention as it prevents from using an uninitialized data (CallConv doesn't have a constructor that would initialize it, it's just a struct).

uint32_t CallConv::id() constnoexcept

Returns the calling convention id, see Id.

void CallConv::setId(uint32_t id)noexcept

Sets the calling convention id, see Id.

uint32_t CallConv::arch() constnoexcept

Returns the calling function architecture id.

void CallConv::setArch(uint32_t arch)noexcept

Sets the calling function architecture id.

uint32_t CallConv::strategy() constnoexcept

Returns the strategy used to assign registers to arguments, see Strategy.

void CallConv::setStrategy(uint32_t strategy)noexcept

Sets the strategy used to assign registers to arguments, see Strategy.

bool CallConv::hasFlag(uint32_t flag) constnoexcept

Tests whether the calling convention has the given flag set.

uint32_t CallConv::flags() constnoexcept

Returns the calling convention flags, see Flags.

void CallConv::setFlags(uint32_t flag)noexcept

Adds the calling convention flags, see Flags.

void CallConv::addFlags(uint32_t flags)noexcept

Adds the calling convention flags, see Flags.

bool CallConv::hasRedZone() constnoexcept

Tests whether this calling convention specifies 'RedZone'.

bool CallConv::hasSpillZone() constnoexcept

Tests whether this calling convention specifies 'SpillZone'.

uint32_t CallConv::redZoneSize() constnoexcept

Returns size of 'RedZone'.

uint32_t CallConv::spillZoneSize() constnoexcept

Returns size of 'SpillZone'.

void CallConv::setRedZoneSize(uint32_t size)noexcept

Sets size of 'RedZone'.

void CallConv::setSpillZoneSize(uint32_t size)noexcept

Sets size of 'SpillZone'.

uint32_t CallConv::naturalStackAlignment() constnoexcept

Returns a natural stack alignment.

void CallConv::setNaturalStackAlignment(uint32_t value)noexcept

Sets a natural stack alignment.

This function can be used to override the default stack alignment in case that you know that it's alignment is different. For example it allows to implement custom calling conventions that guarantee higher stack alignment.

uint32_t CallConv::saveRestoreRegSize(uint32_t group) constnoexcept

Returns the size of a register (or its part) to be saved and restored of the given group.

void CallConv::setSaveRestoreRegSize(uint32_t group, uint32_t size)noexcept

Sets the size of a vector register (or its part) to be saved and restored.

uint32_t CallConv::saveRestoreAlignment(uint32_t group) constnoexcept

Returns the alignment of a save-restore area of the given group.

void CallConv::setSaveRestoreAlignment(uint32_t group, uint32_t alignment)noexcept

Sets the alignment of a save-restore area of the given group.

const uint8_t* CallConv::passedOrder(uint32_t group) constnoexcept

Returns the order of passed registers of the given group, see BaseReg::RegGroup.

uint32_t CallConv::passedRegs(uint32_t group) constnoexcept

Returns the mask of passed registers of the given group, see BaseReg::RegGroup.

void CallConv::setPassedToNone(uint32_t group)noexcept

Resets the order and mask of passed registers.

void CallConv::setPassedOrder(uint32_t group, uint32_t a0, uint32_t a1 = 0xFF, uint32_t a2 = 0xFF, uint32_t a3 = 0xFF, uint32_t a4 = 0xFF, uint32_t a5 = 0xFF, uint32_t a6 = 0xFF, uint32_t a7 = 0xFF)noexcept

Sets the order and mask of passed registers.

uint32_t CallConv::preservedRegs(uint32_t group) constnoexcept

Returns preserved register mask of the given group, see BaseReg::RegGroup.

void CallConv::setPreservedRegs(uint32_t group, uint32_t regs)noexcept

Sets preserved register mask of the given group, see BaseReg::RegGroup.

Member Data Documentation

uint8_t CallConv::_id

Calling convention id, see Id.

uint8_t CallConv::_arch

Architecture identifier, see Environment::Arch.

uint8_t CallConv::_strategy

Register assignment strategy, see Strategy.

uint8_t CallConv::_redZoneSize

Red zone size (AMD64 == 128 bytes).

uint8_t CallConv::_spillZoneSize

Spill zone size (WIN-X64 == 32 bytes).

uint8_t CallConv::_naturalStackAlignment

Natural stack alignment as defined by OS/ABI.

uint16_t CallConv::_flags

Flags.

uint8_t CallConv::_saveRestoreRegSize[BaseReg::kGroupVirt]

Size to save/restore per register group.

uint8_t CallConv::_saveRestoreAlignment[BaseReg::kGroupVirt]

Alignment of save/restore groups.

uint32_t CallConv::_passedRegs[BaseReg::kGroupVirt]

Mask of all passed registers, per group.

uint32_t CallConv::_preservedRegs[BaseReg::kGroupVirt]

Mask of all preserved registers, per group.

RegOrder CallConv::_passedOrder[BaseReg::kGroupVirt]

Passed registers' order, per register group.