-
Notifications
You must be signed in to change notification settings - Fork 983
Add __preserve_none documentation #5894
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
HulonJenkins
wants to merge
4
commits into
MicrosoftDocs:main
from
HulonJenkins:dev/hulonjenkins/preserve_none
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| --- | ||
| description: "Learn more about: __preserve_none" | ||
| title: "__preserve_none" | ||
| ms.date: 02/11/2026 | ||
| f1_keywords: ["__preserve_none", "register spilling", "non preserving calling convention"] | ||
| helpviewer_keywords: ["__preserve_none keyword"] | ||
| --- | ||
| # __preserve_none | ||
|
|
||
| **Microsoft Specific** | ||
|
|
||
| > [!IMPORTANT] | ||
| > The **`__preserve_none`** calling convention is experimental and subject to change. | ||
|
|
||
| The **`__preserve_none`** calling convention specifies that arguments to functions are to be passed in registers, with most general-purpose registers treated as volatile. This calling convention is only supported for C programs and only applies to the x64 architecture. | ||
|
|
||
| This calling convention is designed to minimize register spilling and improve performance. | ||
|
|
||
| The following list shows the implementation of this calling convention. | ||
|
|
||
| | Element | Implementation | | ||
| |---------|----------------| | ||
| | Argument-passing order | Arguments are passed in up to 10 registers in the following order: r13, r14, r15, rbx, rsi, rdi, r9, r8, rdx, rcx. If a hidden parameter is required for struct returns, it is passed in r13 (the first parameter register), reducing available parameter registers to 9. Registers r10-r12 are reserved for various CRT and Windows runtimes. All parameters must be passed through registers; stack-based parameters are not currently supported. | | ||
| | Register allocation strategy | To help minimize register spilling, the allocator assigns r9, r8, rdx, and rcx only after other registers have been used. | | ||
| | Argument limit | Functions are restricted to a maximum of 10 parameters. An error is generated if this limit is exceeded. | | ||
| | Return value convention | Follows the regular x64 calling convention rules. Scalar return values are returned in rax. Structs of size 1, 2, 4, or 8 bytes are returned through the rax register. For structs of other sizes, a pointer to memory allocated by the caller and passed through the hidden parameter is returned in rax. | | ||
| | Volatile registers | All general-purpose registers except rsp (stack pointer) and rbp (base pointer) are treated as volatile and do not need to be preserved across function calls. While r10 and r11 are volatile, they are not used for parameter passing to maintain compatibility with existing programs. | | ||
| | Nonvolatile registers | Only rsp, rbp, and r12 are nonvolatile. | | ||
| | Stack alignment | The stack must maintain 16-byte alignment. | | ||
| | Frame pointer | The rbp register and frame chain follow the [/Gy switch](../build/reference/gy-enable-function-level-linking.md) settings. | | ||
| | Stack-maintenance responsibility | The callee is responsible for cleaning up its own stack space. | | ||
| | Shadow space | A 32 byte shadow space is reserved on the stack to maintain compatibility with profilers and debugging tools. *(Shadow space is a reserved area on the stack where register parameters can be spilled if needed. It's typically 32 bytes (4 registers × 8 bytes each) reserved by the caller for the first 4 register parameters.)* | | ||
| | Floating-point support | Floating-point parameters are not supported. | | ||
| | Name-decoration convention | Function names are decorated with @@_A suffix. | | ||
| | Case-translation convention | No case translation performed. | | ||
|
|
||
| ## Restrictions and Limitations | ||
|
|
||
| The **`__preserve_none`** calling convention has the following restrictions: | ||
|
|
||
| - **C only**: Only supported for C programs. | ||
| - **x64 only**: Only supported on x64. | ||
| - **No floating-point**: Floating-point parameters are not supported. | ||
| - **No variadic functions**: Variadic functions (varargs) are not supported. | ||
| - **Parameter limit**: Maximum of 10 parameters, all passed through registers. | ||
|
|
||
| ## Use Cases | ||
|
|
||
| The **`__preserve_none`** calling convention is designed for performance-critical scenarios where: | ||
|
|
||
| - Most functions in the codebase use the **`__preserve_none`** calling convention | ||
| - Used in conjunction with `msvc::musttail` to tail call between functions with no stack usage | ||
| - Minimizing register spilling is important for performance | ||
| - The codebase is compatible with treating most registers as volatile | ||
|
|
||
| ## Example | ||
|
|
||
| In the following example, the function `ProcessData` uses the **`__preserve_none`** calling convention: | ||
|
|
||
| ```c | ||
| // Example of the __preserve_none keyword | ||
| void __preserve_none ProcessData(int a, int b, int c, int d, int e); | ||
|
|
||
| // Example of the __preserve_none keyword on function pointer | ||
| typedef int (__preserve_none *callback_ptr)(void* context, int value, int flags); | ||
| ``` | ||
|
|
||
| **END Microsoft Specific** | ||
|
|
||
| ## See also | ||
|
|
||
| [Argument Passing and Naming Conventions](argument-passing-and-naming-conventions.md) | ||
| [x64 Calling Convention](../build/x64-calling-convention.md) | ||
| [Keywords](keywords-cpp.md) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR reviewers may ask you to change the filename to something like preserve-none.md Might do it now to save yourself the bother later.