wcc: tuple-param ABI via SSE/GP arg cursors (#163)
Tuples were unhandled as parameters — no tuple arm in arg-push, arg-pop, or callee-recv in either stage — so a tuple param fell to the 1-GP-word else and dropped all but its first element (integer tuple params too; floats doubly lost). Add tuple-param arms (SEND push+pop, callee RECV) across both stages, reusing #164's per-element SysV classify with the 6-GP (DI,SI,DX,CX,R8,R9) + 8-SSE (X0-X7) arg cursors. A frame slot @tupargscr decouples the producing call's return cursor from the overlapping arg cursor (capture-before-clobber). Overflow (>6 GP / >8 SSE) fails loud (rule 7). Scoped to the N_CALL producer; first-class tuple values (ident/literal) remain a separate unimplemented gap. Gate-blind (the bootstrap passes no tuple params) — covered by table-driven probe 905, which proves pre-fix element-drop and the loud-stop.
This commit is contained in:
@@ -3932,7 +3932,54 @@ fn cgcall(c: *cgen, n: *node) void = {
|
||||
stackslots += 1;
|
||||
};
|
||||
popped += 1;
|
||||
} else {
|
||||
} else { let tuparg: *node = rettupleof(c, a);
|
||||
if (tuparg != nil) {
|
||||
// #163: drain the tuple's staged words (slot+0 pushed
|
||||
// first) into the SysV arg cursor by SysV class — a
|
||||
// float MOVSD/MOVSS off (SP) into the next XMM, else
|
||||
// POPQ into the next INTEGER arg reg; a slice/str its
|
||||
// 3 words. Reg overflow loud-stops (rule 7); the
|
||||
// partial-spill stitch is out of scope (twin of #164).
|
||||
let p: *node = tuparg.list;
|
||||
for (p != nil) {
|
||||
let et: *node = p.lhs;
|
||||
if (isfloattype(c, et)) {
|
||||
if (fpidx >= 8) {
|
||||
let msg: str = "tuple arg float element overflows SSE arg regs (X0..X7); stitch out of scope, see #163\n";
|
||||
os.write(2, msg.ptr, msg.len: u64);
|
||||
os.exit(1);
|
||||
};
|
||||
let mov: str = "MOVSD";
|
||||
if (isf32type(c, et)) { mov = "MOVSS"; };
|
||||
emitline("\t");
|
||||
emitline(mov);
|
||||
emitline("\t(SP), ");
|
||||
emitline(fargregname(fpidx));
|
||||
emitline("\n");
|
||||
emitline("\tADDQ\t$8, SP\n");
|
||||
fpidx += 1;
|
||||
popped += 1;
|
||||
} else {
|
||||
let wide: bool = isstrtype(c, et) || isslicetype(c, et);
|
||||
let eb: i32 = tupebytes(wide);
|
||||
if (intidx + eb > 6) {
|
||||
let msg: str = "tuple arg element overflows integer arg regs (DI/SI/DX/CX/R8/R9); stitch out of scope, see #163\n";
|
||||
os.write(2, msg.ptr, msg.len: u64);
|
||||
os.exit(1);
|
||||
};
|
||||
let k: i32 = 0;
|
||||
for (k < eb) {
|
||||
emitline("\tPOPQ\t");
|
||||
emitline(argregname(intidx));
|
||||
emitline("\n");
|
||||
intidx += 1;
|
||||
popped += 1;
|
||||
k += 1;
|
||||
};
|
||||
};
|
||||
p = p.next;
|
||||
};
|
||||
} else {
|
||||
let extra: i32 = 0;
|
||||
// str IS []u8: 3-word arg, same as slice (#1/Phase 3).
|
||||
if (nodeisstr(c, a)) { extra = 2; };
|
||||
@@ -3957,6 +4004,7 @@ fn cgcall(c: *cgen, n: *node) void = {
|
||||
popped += 1;
|
||||
w += 1;
|
||||
};
|
||||
};
|
||||
};
|
||||
a = a.next;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user