A calling convention is a low-level protocol that defines how functions receive parameters, return values, and manage CPU registers and the call stack during a subroutine call. It specifies the order in which arguments are passed (e.g., left-to-right or right-to-left), which party—the caller or callee—is responsible for cleaning the stack, and which registers must be preserved across the call. This protocol is essential for ensuring binary compatibility between modules compiled separately, such as an application and a vendor's NPU runtime library.
Glossary
Calling Convention

What is a Calling Convention?
A foundational protocol in systems programming that governs how functions are called and return in compiled code.
In the context of NPU acceleration, calling conventions are critical when linking code compiled for the host CPU with functions implemented in a vendor SDK or hardware intrinsics library targeting the accelerator. Mismatched conventions cause catastrophic runtime failures. Common examples include the cdecl, stdcall, and fastcall conventions on x86, and the AAPCS (ARM Architecture Procedure Call Standard) on ARM platforms. Compilers and linkers use this agreed-upon contract to generate correct machine code for function prologues and epilogues.
Key Components of a Calling Convention
A calling convention is a foundational low-level protocol that dictates the precise mechanics of function invocation. It ensures binary compatibility between modules compiled by different tools or for different hardware targets, which is critical for linking vendor libraries with custom code on NPUs.
Parameter Passing
Defines how arguments are transferred from the caller to the callee. This specifies:
- Register-based passing: Fast, using designated general-purpose or special-purpose registers (e.g., R0-R3 on ARM).
- Stack-based passing: For excess arguments or large data structures, pushed onto the call stack in a defined order (left-to-right or right-to-left).
- Composite types: Rules for passing structs or vectors, which may be split across registers, passed by reference, or copied to the stack.
- Example: The ARM Procedure Call Standard (AAPCS) uses R0-R3 for the first four integer/pointer arguments, with subsequent arguments passed on the stack.
Register Usage & Preservation
Governs which CPU/NPU registers are volatile (caller-saved) and which are non-volatile (callee-saved). This is essential for preventing unintended side-effects.
- Volatile Registers: Can be overwritten by a called function. The caller must save any important values before the call. Used for scratch computation and return values.
- Non-Volatile Registers: Must be preserved by the callee. If used, the callee must save their original values to the stack and restore them before returning.
- Implications: Incorrect register preservation leads to subtle, hard-to-debug corruption. Vendor intrinsics and runtime libraries adhere strictly to the target's convention.
Stack Frame Management
Specifies the layout and responsibilities for managing the call stack during a function's lifetime.
- Stack Pointer (SP) Alignment: Often requires alignment to a specific boundary (e.g., 16 bytes) for performance and hardware requirements.
- Frame Pointer (FP): An optional register (e.g., R29 on ARM, RBP on x86) that points to a stable location within the current stack frame, aiding debugging and stack unwinding.
- Prologue/Epilogue: The sequence of instructions at the start and end of a function that allocates/deallocates stack space, saves/restores registers, and sets up/tears down the frame pointer.
- Local Variables: Space for automatic (local) variables is allocated on the stack within the function's frame.
Return Value Handling
Defines how a function returns its result to the caller.
- Simple Scalars: Typically returned in a designated register (e.g., R0 on ARM, RAX on x86-64).
- Floating-Point/SIMD Values: Returned in specific vector registers (e.g., S0/D0 on ARM, XMM0 on x86).
- Large Values: Structs or vectors too large for registers are handled via hidden pointer: the caller allocates memory and passes its address as an implicit first argument; the callee writes the result there.
- Multiple Return Values: Some conventions (or language extensions) support returning multiple values via a combination of registers and the hidden pointer method.
Caller vs. Callee Cleanup
Determines which party is responsible for removing arguments from the stack after the call, a critical distinction for variadic functions and code size.
- Callee-cleanup (e.g.,
stdcall): The called function pops its own arguments. This often leads to smaller code in the caller but cannot support variadic functions likeprintf. - Caller-cleanup (e.g.,
cdecl): The caller removes the arguments after the call returns. This supports variadic functions and allows for cleaner stack management in the callee but increases caller code size. - Impact on NPUs: Vendor SDKs dictate a specific model. Mixing conventions when linking custom assembly with C/C++ code will cause catastrophic stack corruption.
System vs. Hardware Conventions
Highlights the distinction between conventions for different execution environments on the same chip.
- System (CPU) Calling Convention: Governs function calls on the host CPU (e.g., ARM AAPCS, x86-64 System V ABI). Used for control code and invoking the NPU driver.
- Hardware (NPU) Calling Convention: A vendor-specific protocol for invoking kernels or microcode on the accelerator itself. This defines:
- How kernel arguments are packed and passed via command buffers.
- The register state of the NPU's tensor/vector cores upon kernel entry/exit.
- Management of the NPU's internal scratchpad memory or local data RAM (LDRAM).
- Interaction: The CPU uses its convention to call the Vendor Runtime API, which then formats commands adhering to the NPU's internal convention.
Role in NPU Acceleration and Vendor SDKs
A calling convention is a low-level protocol that defines how functions receive parameters, return values, and manage registers and the stack during a subroutine call, ensuring binary compatibility between different modules.
In NPU acceleration, the calling convention is a critical contract between the host CPU and the accelerator's execution units. It dictates how kernel arguments—such as tensor pointers, dimensions, and scalar parameters—are passed from the host driver to the NPU's specialized cores. This protocol is strictly defined by the vendor's Instruction Set Architecture (ISA) and enforced by its compiler toolchain and runtime libraries. Adherence guarantees that compiled kernels execute correctly on the target hardware, managing the handoff of control and data across the heterogeneous system.
Vendor SDKs and hardware abstraction layers (HALs) implement this convention, providing the Application Binary Interface (ABI) that bridges high-level frameworks and low-level hardware. Developers typically interact with it indirectly through compiler intrinsics or driver APIs. The convention governs register allocation, stack frame management, and parameter passing order for NPU kernels, which is essential for binary portability and the correct functioning of statically linked libraries within the accelerator's execution environment.
Common Calling Conventions: A Comparison
This table compares the key characteristics of prevalent calling conventions used in system-level programming, particularly relevant for interfacing with vendor SDKs and hardware intrinsics.
| Feature / Rule | cdecl (C Declaration) | stdcall (Standard Call) | fastcall | System V AMD64 ABI |
|---|---|---|---|---|
Primary Use Case | C language default (x86) | Microsoft Win32 API | Performance-critical x86 code | Default for x86-64 on Linux, macOS |
Caller/Callee Stack Cleanup | Caller | Callee | Callee | Caller (for variable arguments) |
Integer/Pointer Parameter Passing (First 2-6 args) | Stack only | Stack only | Registers (ECX, EDX), then stack | Registers (RDI, RSI, RDX, RCX, R8, R9), then stack |
Floating-Point Parameter Passing (x86-64) | N/A (x86 stack) | N/A (x86 stack) | N/A | XMM0–XMM7 registers, then stack |
Return Value (Integer/Pointer) | EAX register | EAX register | EAX register | RAX register |
Return Value (Floating-Point) | ST0 (x87 FPU stack) | ST0 (x87 FPU stack) | ST0 (x87 FPU stack) | XMM0 register |
Registers Preserved (Callee-saved) | EBX, ESI, EDI, EBP, ESP | EBX, ESI, EDI, EBP, ESP | EBX, ESI, EDI, EBP, ESP | RBX, RBP, R12-R15 |
Name Mangling (C++) | Underscore prefix (varies) | Decorated with argument size | Decorated with '@' and size | Complex mangling (Itanium C++ ABI) |
Variable Argument Support (e.g., printf) |
Frequently Asked Questions
A calling convention is a critical low-level protocol that defines how functions are called in compiled code. It ensures binary compatibility between modules by standardizing parameter passing, register usage, stack management, and return value handling.
A calling convention is a low-level protocol that defines how a function (a subroutine or procedure) receives its parameters, returns its result, and manages CPU registers and the stack memory during a call. It is a contract between the caller (the code making the function call) and the callee (the function being called) that ensures they agree on where to find arguments, which registers must be preserved, and how to clean up the stack after the call. This protocol is essential for binary compatibility, allowing code compiled by different compilers or at different times to interoperate correctly. For NPU programming, calling conventions are crucial when interfacing hand-optimized kernels written in assembly or with hardware intrinsics with higher-level code generated by a compiler.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
A calling convention operates within a broader ecosystem of low-level interfaces and binary specifications. These related concepts define how software components interact with hardware and each other at the machine level.
Application Binary Interface (ABI)
The Application Binary Interface (ABI) is a comprehensive low-level specification that defines the complete system-level contract for binary compatibility. It encompasses the calling convention but extends far beyond it to include:
- Data structure layout (struct/class packing, alignment)
- Object file format (e.g., ELF, COFF)
- Name mangling schemes for function overloading
- Exception handling and runtime type information (RTTI) propagation
- System call mechanisms
While a calling convention governs function calls, the ABI ensures that independently compiled modules, libraries, and even different compilers can interoperate correctly by agreeing on these fundamental binary-level rules.
Vendor ISA
A Vendor Instruction Set Architecture (ISA) is the formal definition of the machine-level language for a specific processor or accelerator, such as an NPU. It is the hardware blueprint that the calling convention and compiler must target. Key components include:
- The set of machine instructions (opcodes) the hardware can execute.
- The register file architecture (number, size, and purpose of registers).
- Supported data types (e.g., tensor cores for INT8/FP16).
- Memory addressing modes and access semantics.
The calling convention is built on top of the ISA, dictating how the ISA's registers and stack are used during subroutine execution. For example, an NPU's ISA might define a dedicated tensor register, and the calling convention would specify whether function arguments can be passed in it.
Hardware Intrinsics
Hardware intrinsics are compiler-specific functions that map directly to single or short sequences of machine instructions, providing controlled access to hardware features like SIMD or tensor operations. They have a direct relationship with calling conventions:
- Intrinsics are inlined by the compiler, meaning the function call overhead defined by the calling convention (e.g., register save/restore) is often eliminated.
- They allow programmers to use low-level hardware capabilities (e.g.,
_mm256_add_psfor AVX) from high-level languages like C/C++. - The compiler must still respect the calling convention for any arguments or return values that are not handled entirely within the intrinsic's expanded code sequence. Using intrinsics is a primary method for writing performance-critical code that efficiently utilizes an NPU's specialized units.
Inline Assembly
Inline assembly is a programming construct that allows raw assembly language instructions to be embedded within a high-level language source file (e.g., C). It provides the ultimate level of control, bypassing the compiler's code generation for specific blocks. Its interaction with the calling convention is critical:
- The programmer is directly responsible for adhering to the platform's calling convention within the assembly block. This includes preserving certain caller-saved and callee-saved registers.
- It requires explicit management of parameter passing (reading from the correct registers/stack locations) and return value placement.
- Used for accessing processor features not exposed by intrinsics or for hand-optimizing kernels where compiler output is suboptimal. Misalignment with the calling convention is a common source of subtle, catastrophic bugs.
Stack Frame
A stack frame (or activation record) is a region of the call stack allocated for a single function's execution. It is the physical memory manifestation of the calling convention's rules. Its layout is precisely defined by the convention and typically includes:
- Return Address: The location to jump back to after the function completes.
- Saved Registers: Space for callee-saved registers that the function will modify.
- Local Variables: Storage for the function's automatic variables.
- Parameter Area: Space for arguments passed on the stack (or a home space for register-passed arguments on some conventions like x64).
The frame pointer (e.g., EBP/RBP) or stack pointer (ESP/RSP) is used to navigate this structure. The calling convention dictates who (caller or callee) is responsible for setting up and tearing down the stack frame.
System V AMD64 ABI
The System V AMD64 ABI is the dominant calling convention standard for 64-bit x86 systems on Unix-like operating systems (Linux, macOS, BSD). It serves as a canonical example of a modern, register-heavy convention:
- Integer/pointer arguments are passed in registers: RDI, RSI, RDX, RCX, R8, R9.
- Floating-point arguments are passed in XMM0–XMM7.
- Additional arguments are passed on the stack.
- The return value for integers goes in RAX; for floats, in XMM0.
- A red zone, a 128-byte area below the stack pointer, is guaranteed to be safe from interruption, allowing leaf functions to avoid frame setup.
This convention maximizes performance by minimizing expensive memory accesses (stack spills). Understanding it is foundational for systems programming and debugging on most server and desktop platforms.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us