|
4 | 4 |
|
5 | 5 | - [Technical Debt](#technical-debt) |
6 | 6 | - [R10 reserved globally for division scratch](#r10-reserved-globally-for-division-scratch) |
7 | | - - [XMM register save area for variadic functions](#xmm-register-save-area-for-variadic-functions-x86-64) |
8 | 7 | - [Future Features](#future-features) |
9 | 8 | - [C11 Atomics (`_Atomic`)](#c11-atomics-_atomic-implementation) |
10 | 9 | - [C11 Alignment Specifiers (`_Alignas`, `_Alignof`)](#c11-alignment-specifiers-_alignas-_alignof) |
|
25 | 24 |
|
26 | 25 | ### R10 reserved globally for division scratch |
27 | 26 |
|
28 | | -**Location**: `arch/x86_64/codegen.rs` lines 160-179 |
| 27 | +**Location**: `arch/x86_64/regalloc.rs` lines 187-208 |
29 | 28 |
|
30 | 29 | **Issue**: R10 is permanently excluded from the allocatable register pool because x86-64 `div`/`idiv` instructions clobber RAX (quotient) and RDX (remainder). When the divisor operand happens to be in RAX or RDX, we need a scratch register to hold it during the division. |
31 | 30 |
|
|
45 | 44 |
|
46 | 45 | Production compilers (GCC, LLVM) use approaches 2-4. The current approach is simple and correct but sacrifices some optimization potential. |
47 | 46 |
|
48 | | -### XMM register save area for variadic functions (x86-64) |
49 | | - |
50 | | -**Location**: `arch/x86_64/codegen.rs` lines 1012-1015 |
51 | | - |
52 | | -**Issue**: On x86-64 SysV ABI, variadic functions that receive floating-point arguments via XMM0-XMM7 should save those registers in the register save area during the prologue. This allows `va_arg(ap, double)` to retrieve FP arguments passed in registers. |
53 | | - |
54 | | -**Current state**: The compiler correctly: |
55 | | -- Passes FP arguments to variadic functions (caller side) in XMM registers |
56 | | -- Sets AL to the count of XMM registers used for variadic calls |
57 | | -- Saves GP registers (RDI, RSI, RDX, RCX, R8, R9) in the register save area |
58 | | - |
59 | | -However, XMM registers are not saved, so user-defined variadic functions cannot use `va_arg` to retrieve `double` arguments. |
60 | | - |
61 | | -**Impact**: Low. Most POSIX variadic functions (printf, sprintf, scanf, etc.) are provided by libc and work correctly. This only affects user-defined variadic functions that accept floating-point variadic arguments. |
62 | | - |
63 | | -**Solution**: In the function prologue for variadic functions: |
64 | | -1. Allocate additional space in the register save area (8 XMM regs × 16 bytes = 128 bytes) |
65 | | -2. Use `movaps` to save XMM0-XMM7 at their ABI-specified offsets |
66 | | -3. Update `va_start` to initialize the FP register save area pointer correctly |
67 | | -4. Update `va_arg` to read from XMM save area when extracting FP types |
68 | | - |
69 | 47 | --- |
70 | 48 |
|
71 | 49 | ## Future Features |
|
0 commit comments