Skip to content

Commit 269d306

Browse files
authored
Merge pull request #25123 from johnno1962/reg-docco
Document ABI registers
2 parents 258f532 + 07750f5 commit 269d306

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed
File renamed without changes.

docs/ABI/RegisterUsage.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## 64-Bit Architecture Register Usage
2+
3+
From Swift 5, the calling convention register allocation for 64-bit architectures is largely based on [existing](https://developer.apple.com/library/content/documentation/Xcode/Conceptual/iPhoneOSABIReference/Articles/ARM64FunctionCallingConventions.html) [standards](https://developer.apple.com/library/content/documentation/DeveloperTools/Conceptual/LowLevelABI/140-x86-64_Function_Calling_Conventions/x86_64.html), with the addition of the context and error return registers discussed in the [ABI stability manifesto](https://github.com/apple/swift/blob/master/docs/ABIStabilityManifesto.md):
4+
5+
| Register Purpose | ARM64 | x86_64 |
6+
| ------------- |:-------------:| ----- |
7+
| Context register (self) | x20 | r13 |
8+
| Error return register | x21 | r12 |
9+
| Struct return pointer | x8 | rax |
10+
| Float call arguments | v0 … v7 | xmm0 … xmm7 |
11+
| Integer call arguments | x0 … x7 | rdi, rsi, rdx, rcx, r8, r9 |
12+
| Float return | v0 … v3 | xmm0 … xmm3 |
13+
| Integer return | x0 … x3 | rax, rdx, rcx, r8 |

docs/ABIStabilityManifesto.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,8 @@ Having the call context register be callee-saved is advantageous. It keeps the r
337337

338338
Throwing functions communicate error values to their callers through the *error* register on some platforms. The error register holds a pointer to the error value if an error occurred, otherwise 0. The caller of a throwing function is expected to quickly check for 0 before continuing on with non-error code, otherwise branching to code to handle or propagate the error. Using a callee-saved register for the error register enables free conversion from non-throwing to throwing functions, which is required to honor the subtyping relationship.
339339

340+
The specific registers used in these roles are documented in [another document on register usage](https://github.com/apple/swift/blob/master/docs/ABI/RegisterUsage.md).
341+
340342
### <a name="function-signature-lowering"></a>Function Signature Lowering
341343

342344
Function signature lowering is the mapping of a function's source-language type, which includes formal parameters and results, all the way down to a physical convention, which dictates what values are stored in what registers and what values to pass on the stack.

0 commit comments

Comments
 (0)