w6c+wwstage: array return-by-value via the struct-return ABI (#267 fold-2)
Wire TY_ARRAY into the existing struct-return gates so arrays ride the same reg-class (<=24B in AX:DX:CX) / sret-class (>24B) path the struct return ABI already emits byte-identically. No new ABI machinery. Both stages, uniform gate-widen: - cg_sret_retsize / sretretsize: +TY_ARRAY (natural size sub.size*len, the type table) -> auto-enables sret send/recv + the >24B sret N_IDENT word-copy + return-forward, all keyed on the shared sret SSoT. - cgreturn <=24B reg-send: +TY_ARRAY (N_IDENT scratch word-copy -> AX/DX/CX). reg-class return-forward rides the default cgexpr passthrough. - let-init / assign <=24B recv: +TY_ARRAY (AX/DX/CX sized stores). struct_float_class stays struct-only: pure-int element arrays only; no pure-float-array-return consumer exists today. 949 +11 rows: reg-class 8/16/24B + sret-class 32B, [N]u32 and [N]u8, at let-init/assign/return-forward, full-member readback, + a struct- return regression control. All cstage-run + cs==ww byte-id.
This commit is contained in:
@@ -16814,6 +16814,18 @@ export fn sretretsize(c: *cgen, t: *node) i32 = {
|
||||
};
|
||||
return 0;
|
||||
};
|
||||
// #267: arrays ride the struct-return ABI — natural size
|
||||
// (sub.size*len, the type table) gates ≤24 reg / >24 sret, mirroring
|
||||
// cstage cg_sret_retsize TY_ARRAY arm. Pure-int element arrays only;
|
||||
// no float-array-return consumer (structfloatclass stays struct-only).
|
||||
if (r.kind == nkind.N_TARRAY) {
|
||||
let ati: *tinfo = r.type_: *tinfo;
|
||||
for (ati != nil && ati.kind == tykind.TY_NAMED) { ati = ati.under; };
|
||||
if (ati == nil) { return 0; };
|
||||
let asz: i32 = ati.size: i32;
|
||||
if (asz <= 24) { return 0; };
|
||||
return asz;
|
||||
};
|
||||
if (r.kind != nkind.N_TNAME) { return 0; };
|
||||
// Primitives / aliased-to-primitives are never sret.
|
||||
if (primsize(r.str) > 0) { return 0; };
|
||||
@@ -26968,6 +26980,69 @@ fn cgassign(c: *cgen, n: *node) void = {
|
||||
};
|
||||
};
|
||||
};
|
||||
// #267: array return-by-value RECV — `c = mk()` where c is
|
||||
// an array local. Arrays ride the struct reg/sret recv path.
|
||||
// >24B sret keys on callsretsize (the shared SSoT, c's slot
|
||||
// IS the prealloc dest); ≤24B arrives in AX/DX/CX, sized
|
||||
// stores. Array natural size (tinfo.size = sub.size*len)
|
||||
// mirrors cstage lu->size. No structfloatclass (pure-int
|
||||
// element arrays).
|
||||
if (lcn != nil && n.op == tkind.TK_ASSIGN
|
||||
&& n.rhs != nil && n.rhs.kind == nkind.N_CALL) {
|
||||
let acati: *tinfo = nil;
|
||||
if (lcn.tnode != nil) { acati = lcn.tnode.type_: *tinfo; };
|
||||
for (acati != nil && acati.kind == tykind.TY_NAMED) {
|
||||
acati = acati.under;
|
||||
};
|
||||
if (acati != nil && acati.kind == tykind.TY_ARRAY) {
|
||||
let lcsz: i32 = acati.size: i32;
|
||||
if (lcsz > 24) {
|
||||
let rscs: i32 = callsretsize(c, n.rhs);
|
||||
if (rscs > 0) {
|
||||
c.sretdestoff = off;
|
||||
cgexpr(c, n.rhs);
|
||||
c.sretdestoff = 0;
|
||||
return;
|
||||
};
|
||||
};
|
||||
if (lcsz <= 24) {
|
||||
let tlm: i32 = lcsz - (lcsz / 8) * 8;
|
||||
if (tlm == 0 || tlm == 1
|
||||
|| tlm == 2 || tlm == 4) {
|
||||
cgexpr(c, n.rhs);
|
||||
let full: i32 = lcsz / 8;
|
||||
let i: i32 = 0;
|
||||
for (i < full) {
|
||||
let reg: str = "AX";
|
||||
if (i == 1) { reg = "DX"; };
|
||||
if (i == 2) { reg = "CX"; };
|
||||
emitline("\tMOVQ\t");
|
||||
emitline(reg);
|
||||
emitline(", ");
|
||||
emitoff((off + i * 8): i64);
|
||||
emitline("(BP)\n");
|
||||
i += 1;
|
||||
};
|
||||
if (tlm > 0) {
|
||||
let top: str = "MOVB";
|
||||
if (tlm == 4) { top = "MOVL"; };
|
||||
if (tlm == 2) { top = "MOVW"; };
|
||||
let treg: str = "AX";
|
||||
if (full == 1) { treg = "DX"; };
|
||||
if (full == 2) { treg = "CX"; };
|
||||
emitline("\t");
|
||||
emitline(top);
|
||||
emitline("\t");
|
||||
emitline(treg);
|
||||
emitline(", ");
|
||||
emitoff((off + full * 8): i64);
|
||||
emitline("(BP)\n");
|
||||
};
|
||||
return;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
// Float-typed local: rhs lands in X0; store via MOVSD/
|
||||
// MOVSS, no AX shuffle. Compound (+= -= *= /=) loads
|
||||
// slot into X1, combines into X1, stores X1 back —
|
||||
@@ -28229,6 +28304,80 @@ fn cgreturn(c: *cgen, n: *node) void = {
|
||||
};
|
||||
};
|
||||
};
|
||||
// #267: array return-by-value SEND. >24B sret rides the sret
|
||||
// block above (scs = sretretsize keys it, N_IDENT word-copy /
|
||||
// N_CALL forward generic). ≤24B reg-class `return a;` (N_IDENT)
|
||||
// mirrors the struct ≤24B path: zero-pad a 24B scratch, word-
|
||||
// copy the array slot in, ship AX/DX/CX. Array natural size
|
||||
// (tinfo.size = sub.size*len) mirrors cstage rt->size. No
|
||||
// structfloatclass (pure-int arrays); N_CALL forward at reg-
|
||||
// class falls to the default cgexpr passthrough below.
|
||||
if (c.fnret != nil && c.fnret.kind == nkind.N_TARRAY
|
||||
&& rhs.kind == nkind.N_IDENT) {
|
||||
let ati: *tinfo = c.fnret.type_: *tinfo;
|
||||
for (ati != nil && ati.kind == tykind.TY_NAMED) { ati = ati.under; };
|
||||
if (ati != nil) {
|
||||
let rsz: i32 = ati.size: i32;
|
||||
if (rsz <= 24) {
|
||||
let rl: *local = localfindnode(c, rhs.str);
|
||||
if (rl != nil) {
|
||||
let scroff: i32 = localadd(c, "@retscr", 24, nil);
|
||||
emitline("\tXORQ\tAX, AX\n");
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitoff(scroff: i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitoff((scroff + 8): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitoff((scroff + 16): i64);
|
||||
emitline("(BP)\n");
|
||||
let k: i32 = 0;
|
||||
for (k + 8 <= rsz) {
|
||||
emitline("\tMOVQ\t");
|
||||
emitoff((rl.off + k): i64);
|
||||
emitline("(BP), AX\n");
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitoff((scroff + k): i64);
|
||||
emitline("(BP)\n");
|
||||
k += 8;
|
||||
};
|
||||
for (k + 4 <= rsz) {
|
||||
emitline("\tMOVL\t");
|
||||
emitoff((rl.off + k): i64);
|
||||
emitline("(BP), AX\n");
|
||||
emitline("\tMOVL\tAX, ");
|
||||
emitoff((scroff + k): i64);
|
||||
emitline("(BP)\n");
|
||||
k += 4;
|
||||
};
|
||||
for (k < rsz) {
|
||||
emitline("\tMOVB\t");
|
||||
emitoff((rl.off + k): i64);
|
||||
emitline("(BP), AX\n");
|
||||
emitline("\tMOVB\tAX, ");
|
||||
emitoff((scroff + k): i64);
|
||||
emitline("(BP)\n");
|
||||
k += 1;
|
||||
};
|
||||
emitline("\tMOVQ\t");
|
||||
emitoff(scroff: i64);
|
||||
emitline("(BP), AX\n");
|
||||
emitline("\tMOVQ\t");
|
||||
emitoff((scroff + 8): i64);
|
||||
emitline("(BP), DX\n");
|
||||
emitline("\tMOVQ\t");
|
||||
emitoff((scroff + 16): i64);
|
||||
emitline("(BP), CX\n");
|
||||
emitline("\tMOVQ\tBP, SP\n");
|
||||
emitline("\tPOPQ\tBP\n");
|
||||
emitline("\tRET\n");
|
||||
c.lastwasreturn = 1;
|
||||
return;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
cgexpr(c, rhs);
|
||||
} else {
|
||||
// Bare `return;` from a tagged-union-returning fn is
|
||||
@@ -28796,6 +28945,57 @@ fn cglet(c: *cgen, n: *node) void = {
|
||||
};
|
||||
};
|
||||
};
|
||||
// #267: array return-by-value RECV ≤24B — `let c = mk()`
|
||||
// where mk returns an array. Arrays ride the struct reg-recv
|
||||
// path (AX/DX/CX, sized tail). >24B sret rides the sret recv
|
||||
// above (callsretsize keyed). Array natural size (tinfo.size
|
||||
// = sub.size*len) mirrors cstage lu->size. No structfloatclass
|
||||
// (pure-int element arrays).
|
||||
if (rhs.kind == nkind.N_CALL && tn != nil
|
||||
&& tn.kind == nkind.N_TARRAY) {
|
||||
let ati: *tinfo = tn.type_: *tinfo;
|
||||
for (ati != nil && ati.kind == tykind.TY_NAMED) { ati = ati.under; };
|
||||
if (ati != nil) {
|
||||
let lsz: i32 = ati.size: i32;
|
||||
let tlm: i32 = lsz - (lsz / 8) * 8;
|
||||
if (lsz <= 24) {
|
||||
if (tlm == 0 || tlm == 1
|
||||
|| tlm == 2 || tlm == 4) {
|
||||
cgexpr(c, rhs);
|
||||
let full: i32 = lsz / 8;
|
||||
let i: i32 = 0;
|
||||
for (i < full) {
|
||||
let reg: str = "AX";
|
||||
if (i == 1) { reg = "DX"; };
|
||||
if (i == 2) { reg = "CX"; };
|
||||
emitline("\tMOVQ\t");
|
||||
emitline(reg);
|
||||
emitline(", ");
|
||||
emitoff((off + i * 8): i64);
|
||||
emitline("(BP)\n");
|
||||
i += 1;
|
||||
};
|
||||
if (tlm > 0) {
|
||||
let top: str = "MOVB";
|
||||
if (tlm == 4) { top = "MOVL"; };
|
||||
if (tlm == 2) { top = "MOVW"; };
|
||||
let treg: str = "AX";
|
||||
if (full == 1) { treg = "DX"; };
|
||||
if (full == 2) { treg = "CX"; };
|
||||
emitline("\t");
|
||||
emitline(top);
|
||||
emitline("\t");
|
||||
emitline(treg);
|
||||
emitline(", ");
|
||||
emitoff((off + full * 8): i64);
|
||||
emitline("(BP)\n");
|
||||
};
|
||||
c.lastwasreturn = 0;
|
||||
return;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
// Struct ident copy: `let p2: T = p1;` where T is a struct
|
||||
// >8B and rhs is a local ident. Per-qword MOVQ from src
|
||||
// slot to dst slot, with a sized tail (MOVL/MOVB) for
|
||||
|
||||
@@ -7500,6 +7500,69 @@ fn cgassign(c: *cgen, n: *node) void = {
|
||||
};
|
||||
};
|
||||
};
|
||||
// #267: array return-by-value RECV — `c = mk()` where c is
|
||||
// an array local. Arrays ride the struct reg/sret recv path.
|
||||
// >24B sret keys on callsretsize (the shared SSoT, c's slot
|
||||
// IS the prealloc dest); ≤24B arrives in AX/DX/CX, sized
|
||||
// stores. Array natural size (tinfo.size = sub.size*len)
|
||||
// mirrors cstage lu->size. No structfloatclass (pure-int
|
||||
// element arrays).
|
||||
if (lcn != nil && n.op == tkind.TK_ASSIGN
|
||||
&& n.rhs != nil && n.rhs.kind == nkind.N_CALL) {
|
||||
let acati: *tinfo = nil;
|
||||
if (lcn.tnode != nil) { acati = lcn.tnode.type_: *tinfo; };
|
||||
for (acati != nil && acati.kind == tykind.TY_NAMED) {
|
||||
acati = acati.under;
|
||||
};
|
||||
if (acati != nil && acati.kind == tykind.TY_ARRAY) {
|
||||
let lcsz: i32 = acati.size: i32;
|
||||
if (lcsz > 24) {
|
||||
let rscs: i32 = callsretsize(c, n.rhs);
|
||||
if (rscs > 0) {
|
||||
c.sretdestoff = off;
|
||||
cgexpr(c, n.rhs);
|
||||
c.sretdestoff = 0;
|
||||
return;
|
||||
};
|
||||
};
|
||||
if (lcsz <= 24) {
|
||||
let tlm: i32 = lcsz - (lcsz / 8) * 8;
|
||||
if (tlm == 0 || tlm == 1
|
||||
|| tlm == 2 || tlm == 4) {
|
||||
cgexpr(c, n.rhs);
|
||||
let full: i32 = lcsz / 8;
|
||||
let i: i32 = 0;
|
||||
for (i < full) {
|
||||
let reg: str = "AX";
|
||||
if (i == 1) { reg = "DX"; };
|
||||
if (i == 2) { reg = "CX"; };
|
||||
emitline("\tMOVQ\t");
|
||||
emitline(reg);
|
||||
emitline(", ");
|
||||
emitoff((off + i * 8): i64);
|
||||
emitline("(BP)\n");
|
||||
i += 1;
|
||||
};
|
||||
if (tlm > 0) {
|
||||
let top: str = "MOVB";
|
||||
if (tlm == 4) { top = "MOVL"; };
|
||||
if (tlm == 2) { top = "MOVW"; };
|
||||
let treg: str = "AX";
|
||||
if (full == 1) { treg = "DX"; };
|
||||
if (full == 2) { treg = "CX"; };
|
||||
emitline("\t");
|
||||
emitline(top);
|
||||
emitline("\t");
|
||||
emitline(treg);
|
||||
emitline(", ");
|
||||
emitoff((off + full * 8): i64);
|
||||
emitline("(BP)\n");
|
||||
};
|
||||
return;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
// Float-typed local: rhs lands in X0; store via MOVSD/
|
||||
// MOVSS, no AX shuffle. Compound (+= -= *= /=) loads
|
||||
// slot into X1, combines into X1, stores X1 back —
|
||||
|
||||
@@ -1089,6 +1089,80 @@ fn cgreturn(c: *cgen, n: *node) void = {
|
||||
};
|
||||
};
|
||||
};
|
||||
// #267: array return-by-value SEND. >24B sret rides the sret
|
||||
// block above (scs = sretretsize keys it, N_IDENT word-copy /
|
||||
// N_CALL forward generic). ≤24B reg-class `return a;` (N_IDENT)
|
||||
// mirrors the struct ≤24B path: zero-pad a 24B scratch, word-
|
||||
// copy the array slot in, ship AX/DX/CX. Array natural size
|
||||
// (tinfo.size = sub.size*len) mirrors cstage rt->size. No
|
||||
// structfloatclass (pure-int arrays); N_CALL forward at reg-
|
||||
// class falls to the default cgexpr passthrough below.
|
||||
if (c.fnret != nil && c.fnret.kind == nkind.N_TARRAY
|
||||
&& rhs.kind == nkind.N_IDENT) {
|
||||
let ati: *tinfo = c.fnret.type_: *tinfo;
|
||||
for (ati != nil && ati.kind == tykind.TY_NAMED) { ati = ati.under; };
|
||||
if (ati != nil) {
|
||||
let rsz: i32 = ati.size: i32;
|
||||
if (rsz <= 24) {
|
||||
let rl: *local = localfindnode(c, rhs.str);
|
||||
if (rl != nil) {
|
||||
let scroff: i32 = localadd(c, "@retscr", 24, nil);
|
||||
emitline("\tXORQ\tAX, AX\n");
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitoff(scroff: i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitoff((scroff + 8): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitoff((scroff + 16): i64);
|
||||
emitline("(BP)\n");
|
||||
let k: i32 = 0;
|
||||
for (k + 8 <= rsz) {
|
||||
emitline("\tMOVQ\t");
|
||||
emitoff((rl.off + k): i64);
|
||||
emitline("(BP), AX\n");
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitoff((scroff + k): i64);
|
||||
emitline("(BP)\n");
|
||||
k += 8;
|
||||
};
|
||||
for (k + 4 <= rsz) {
|
||||
emitline("\tMOVL\t");
|
||||
emitoff((rl.off + k): i64);
|
||||
emitline("(BP), AX\n");
|
||||
emitline("\tMOVL\tAX, ");
|
||||
emitoff((scroff + k): i64);
|
||||
emitline("(BP)\n");
|
||||
k += 4;
|
||||
};
|
||||
for (k < rsz) {
|
||||
emitline("\tMOVB\t");
|
||||
emitoff((rl.off + k): i64);
|
||||
emitline("(BP), AX\n");
|
||||
emitline("\tMOVB\tAX, ");
|
||||
emitoff((scroff + k): i64);
|
||||
emitline("(BP)\n");
|
||||
k += 1;
|
||||
};
|
||||
emitline("\tMOVQ\t");
|
||||
emitoff(scroff: i64);
|
||||
emitline("(BP), AX\n");
|
||||
emitline("\tMOVQ\t");
|
||||
emitoff((scroff + 8): i64);
|
||||
emitline("(BP), DX\n");
|
||||
emitline("\tMOVQ\t");
|
||||
emitoff((scroff + 16): i64);
|
||||
emitline("(BP), CX\n");
|
||||
emitline("\tMOVQ\tBP, SP\n");
|
||||
emitline("\tPOPQ\tBP\n");
|
||||
emitline("\tRET\n");
|
||||
c.lastwasreturn = 1;
|
||||
return;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
cgexpr(c, rhs);
|
||||
} else {
|
||||
// Bare `return;` from a tagged-union-returning fn is
|
||||
@@ -1656,6 +1730,57 @@ fn cglet(c: *cgen, n: *node) void = {
|
||||
};
|
||||
};
|
||||
};
|
||||
// #267: array return-by-value RECV ≤24B — `let c = mk()`
|
||||
// where mk returns an array. Arrays ride the struct reg-recv
|
||||
// path (AX/DX/CX, sized tail). >24B sret rides the sret recv
|
||||
// above (callsretsize keyed). Array natural size (tinfo.size
|
||||
// = sub.size*len) mirrors cstage lu->size. No structfloatclass
|
||||
// (pure-int element arrays).
|
||||
if (rhs.kind == nkind.N_CALL && tn != nil
|
||||
&& tn.kind == nkind.N_TARRAY) {
|
||||
let ati: *tinfo = tn.type_: *tinfo;
|
||||
for (ati != nil && ati.kind == tykind.TY_NAMED) { ati = ati.under; };
|
||||
if (ati != nil) {
|
||||
let lsz: i32 = ati.size: i32;
|
||||
let tlm: i32 = lsz - (lsz / 8) * 8;
|
||||
if (lsz <= 24) {
|
||||
if (tlm == 0 || tlm == 1
|
||||
|| tlm == 2 || tlm == 4) {
|
||||
cgexpr(c, rhs);
|
||||
let full: i32 = lsz / 8;
|
||||
let i: i32 = 0;
|
||||
for (i < full) {
|
||||
let reg: str = "AX";
|
||||
if (i == 1) { reg = "DX"; };
|
||||
if (i == 2) { reg = "CX"; };
|
||||
emitline("\tMOVQ\t");
|
||||
emitline(reg);
|
||||
emitline(", ");
|
||||
emitoff((off + i * 8): i64);
|
||||
emitline("(BP)\n");
|
||||
i += 1;
|
||||
};
|
||||
if (tlm > 0) {
|
||||
let top: str = "MOVB";
|
||||
if (tlm == 4) { top = "MOVL"; };
|
||||
if (tlm == 2) { top = "MOVW"; };
|
||||
let treg: str = "AX";
|
||||
if (full == 1) { treg = "DX"; };
|
||||
if (full == 2) { treg = "CX"; };
|
||||
emitline("\t");
|
||||
emitline(top);
|
||||
emitline("\t");
|
||||
emitline(treg);
|
||||
emitline(", ");
|
||||
emitoff((off + full * 8): i64);
|
||||
emitline("(BP)\n");
|
||||
};
|
||||
c.lastwasreturn = 0;
|
||||
return;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
// Struct ident copy: `let p2: T = p1;` where T is a struct
|
||||
// >8B and rhs is a local ident. Per-qword MOVQ from src
|
||||
// slot to dst slot, with a sized tail (MOVL/MOVB) for
|
||||
|
||||
@@ -1304,6 +1304,18 @@ export fn sretretsize(c: *cgen, t: *node) i32 = {
|
||||
};
|
||||
return 0;
|
||||
};
|
||||
// #267: arrays ride the struct-return ABI — natural size
|
||||
// (sub.size*len, the type table) gates ≤24 reg / >24 sret, mirroring
|
||||
// cstage cg_sret_retsize TY_ARRAY arm. Pure-int element arrays only;
|
||||
// no float-array-return consumer (structfloatclass stays struct-only).
|
||||
if (r.kind == nkind.N_TARRAY) {
|
||||
let ati: *tinfo = r.type_: *tinfo;
|
||||
for (ati != nil && ati.kind == tykind.TY_NAMED) { ati = ati.under; };
|
||||
if (ati == nil) { return 0; };
|
||||
let asz: i32 = ati.size: i32;
|
||||
if (asz <= 24) { return 0; };
|
||||
return asz;
|
||||
};
|
||||
if (r.kind != nkind.N_TNAME) { return 0; };
|
||||
// Primitives / aliased-to-primitives are never sret.
|
||||
if (primsize(r.str) > 0) { return 0; };
|
||||
|
||||
@@ -16814,6 +16814,18 @@ export fn sretretsize(c: *cgen, t: *node) i32 = {
|
||||
};
|
||||
return 0;
|
||||
};
|
||||
// #267: arrays ride the struct-return ABI — natural size
|
||||
// (sub.size*len, the type table) gates ≤24 reg / >24 sret, mirroring
|
||||
// cstage cg_sret_retsize TY_ARRAY arm. Pure-int element arrays only;
|
||||
// no float-array-return consumer (structfloatclass stays struct-only).
|
||||
if (r.kind == nkind.N_TARRAY) {
|
||||
let ati: *tinfo = r.type_: *tinfo;
|
||||
for (ati != nil && ati.kind == tykind.TY_NAMED) { ati = ati.under; };
|
||||
if (ati == nil) { return 0; };
|
||||
let asz: i32 = ati.size: i32;
|
||||
if (asz <= 24) { return 0; };
|
||||
return asz;
|
||||
};
|
||||
if (r.kind != nkind.N_TNAME) { return 0; };
|
||||
// Primitives / aliased-to-primitives are never sret.
|
||||
if (primsize(r.str) > 0) { return 0; };
|
||||
@@ -26968,6 +26980,69 @@ fn cgassign(c: *cgen, n: *node) void = {
|
||||
};
|
||||
};
|
||||
};
|
||||
// #267: array return-by-value RECV — `c = mk()` where c is
|
||||
// an array local. Arrays ride the struct reg/sret recv path.
|
||||
// >24B sret keys on callsretsize (the shared SSoT, c's slot
|
||||
// IS the prealloc dest); ≤24B arrives in AX/DX/CX, sized
|
||||
// stores. Array natural size (tinfo.size = sub.size*len)
|
||||
// mirrors cstage lu->size. No structfloatclass (pure-int
|
||||
// element arrays).
|
||||
if (lcn != nil && n.op == tkind.TK_ASSIGN
|
||||
&& n.rhs != nil && n.rhs.kind == nkind.N_CALL) {
|
||||
let acati: *tinfo = nil;
|
||||
if (lcn.tnode != nil) { acati = lcn.tnode.type_: *tinfo; };
|
||||
for (acati != nil && acati.kind == tykind.TY_NAMED) {
|
||||
acati = acati.under;
|
||||
};
|
||||
if (acati != nil && acati.kind == tykind.TY_ARRAY) {
|
||||
let lcsz: i32 = acati.size: i32;
|
||||
if (lcsz > 24) {
|
||||
let rscs: i32 = callsretsize(c, n.rhs);
|
||||
if (rscs > 0) {
|
||||
c.sretdestoff = off;
|
||||
cgexpr(c, n.rhs);
|
||||
c.sretdestoff = 0;
|
||||
return;
|
||||
};
|
||||
};
|
||||
if (lcsz <= 24) {
|
||||
let tlm: i32 = lcsz - (lcsz / 8) * 8;
|
||||
if (tlm == 0 || tlm == 1
|
||||
|| tlm == 2 || tlm == 4) {
|
||||
cgexpr(c, n.rhs);
|
||||
let full: i32 = lcsz / 8;
|
||||
let i: i32 = 0;
|
||||
for (i < full) {
|
||||
let reg: str = "AX";
|
||||
if (i == 1) { reg = "DX"; };
|
||||
if (i == 2) { reg = "CX"; };
|
||||
emitline("\tMOVQ\t");
|
||||
emitline(reg);
|
||||
emitline(", ");
|
||||
emitoff((off + i * 8): i64);
|
||||
emitline("(BP)\n");
|
||||
i += 1;
|
||||
};
|
||||
if (tlm > 0) {
|
||||
let top: str = "MOVB";
|
||||
if (tlm == 4) { top = "MOVL"; };
|
||||
if (tlm == 2) { top = "MOVW"; };
|
||||
let treg: str = "AX";
|
||||
if (full == 1) { treg = "DX"; };
|
||||
if (full == 2) { treg = "CX"; };
|
||||
emitline("\t");
|
||||
emitline(top);
|
||||
emitline("\t");
|
||||
emitline(treg);
|
||||
emitline(", ");
|
||||
emitoff((off + full * 8): i64);
|
||||
emitline("(BP)\n");
|
||||
};
|
||||
return;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
// Float-typed local: rhs lands in X0; store via MOVSD/
|
||||
// MOVSS, no AX shuffle. Compound (+= -= *= /=) loads
|
||||
// slot into X1, combines into X1, stores X1 back —
|
||||
@@ -28229,6 +28304,80 @@ fn cgreturn(c: *cgen, n: *node) void = {
|
||||
};
|
||||
};
|
||||
};
|
||||
// #267: array return-by-value SEND. >24B sret rides the sret
|
||||
// block above (scs = sretretsize keys it, N_IDENT word-copy /
|
||||
// N_CALL forward generic). ≤24B reg-class `return a;` (N_IDENT)
|
||||
// mirrors the struct ≤24B path: zero-pad a 24B scratch, word-
|
||||
// copy the array slot in, ship AX/DX/CX. Array natural size
|
||||
// (tinfo.size = sub.size*len) mirrors cstage rt->size. No
|
||||
// structfloatclass (pure-int arrays); N_CALL forward at reg-
|
||||
// class falls to the default cgexpr passthrough below.
|
||||
if (c.fnret != nil && c.fnret.kind == nkind.N_TARRAY
|
||||
&& rhs.kind == nkind.N_IDENT) {
|
||||
let ati: *tinfo = c.fnret.type_: *tinfo;
|
||||
for (ati != nil && ati.kind == tykind.TY_NAMED) { ati = ati.under; };
|
||||
if (ati != nil) {
|
||||
let rsz: i32 = ati.size: i32;
|
||||
if (rsz <= 24) {
|
||||
let rl: *local = localfindnode(c, rhs.str);
|
||||
if (rl != nil) {
|
||||
let scroff: i32 = localadd(c, "@retscr", 24, nil);
|
||||
emitline("\tXORQ\tAX, AX\n");
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitoff(scroff: i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitoff((scroff + 8): i64);
|
||||
emitline("(BP)\n");
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitoff((scroff + 16): i64);
|
||||
emitline("(BP)\n");
|
||||
let k: i32 = 0;
|
||||
for (k + 8 <= rsz) {
|
||||
emitline("\tMOVQ\t");
|
||||
emitoff((rl.off + k): i64);
|
||||
emitline("(BP), AX\n");
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitoff((scroff + k): i64);
|
||||
emitline("(BP)\n");
|
||||
k += 8;
|
||||
};
|
||||
for (k + 4 <= rsz) {
|
||||
emitline("\tMOVL\t");
|
||||
emitoff((rl.off + k): i64);
|
||||
emitline("(BP), AX\n");
|
||||
emitline("\tMOVL\tAX, ");
|
||||
emitoff((scroff + k): i64);
|
||||
emitline("(BP)\n");
|
||||
k += 4;
|
||||
};
|
||||
for (k < rsz) {
|
||||
emitline("\tMOVB\t");
|
||||
emitoff((rl.off + k): i64);
|
||||
emitline("(BP), AX\n");
|
||||
emitline("\tMOVB\tAX, ");
|
||||
emitoff((scroff + k): i64);
|
||||
emitline("(BP)\n");
|
||||
k += 1;
|
||||
};
|
||||
emitline("\tMOVQ\t");
|
||||
emitoff(scroff: i64);
|
||||
emitline("(BP), AX\n");
|
||||
emitline("\tMOVQ\t");
|
||||
emitoff((scroff + 8): i64);
|
||||
emitline("(BP), DX\n");
|
||||
emitline("\tMOVQ\t");
|
||||
emitoff((scroff + 16): i64);
|
||||
emitline("(BP), CX\n");
|
||||
emitline("\tMOVQ\tBP, SP\n");
|
||||
emitline("\tPOPQ\tBP\n");
|
||||
emitline("\tRET\n");
|
||||
c.lastwasreturn = 1;
|
||||
return;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
cgexpr(c, rhs);
|
||||
} else {
|
||||
// Bare `return;` from a tagged-union-returning fn is
|
||||
@@ -28796,6 +28945,57 @@ fn cglet(c: *cgen, n: *node) void = {
|
||||
};
|
||||
};
|
||||
};
|
||||
// #267: array return-by-value RECV ≤24B — `let c = mk()`
|
||||
// where mk returns an array. Arrays ride the struct reg-recv
|
||||
// path (AX/DX/CX, sized tail). >24B sret rides the sret recv
|
||||
// above (callsretsize keyed). Array natural size (tinfo.size
|
||||
// = sub.size*len) mirrors cstage lu->size. No structfloatclass
|
||||
// (pure-int element arrays).
|
||||
if (rhs.kind == nkind.N_CALL && tn != nil
|
||||
&& tn.kind == nkind.N_TARRAY) {
|
||||
let ati: *tinfo = tn.type_: *tinfo;
|
||||
for (ati != nil && ati.kind == tykind.TY_NAMED) { ati = ati.under; };
|
||||
if (ati != nil) {
|
||||
let lsz: i32 = ati.size: i32;
|
||||
let tlm: i32 = lsz - (lsz / 8) * 8;
|
||||
if (lsz <= 24) {
|
||||
if (tlm == 0 || tlm == 1
|
||||
|| tlm == 2 || tlm == 4) {
|
||||
cgexpr(c, rhs);
|
||||
let full: i32 = lsz / 8;
|
||||
let i: i32 = 0;
|
||||
for (i < full) {
|
||||
let reg: str = "AX";
|
||||
if (i == 1) { reg = "DX"; };
|
||||
if (i == 2) { reg = "CX"; };
|
||||
emitline("\tMOVQ\t");
|
||||
emitline(reg);
|
||||
emitline(", ");
|
||||
emitoff((off + i * 8): i64);
|
||||
emitline("(BP)\n");
|
||||
i += 1;
|
||||
};
|
||||
if (tlm > 0) {
|
||||
let top: str = "MOVB";
|
||||
if (tlm == 4) { top = "MOVL"; };
|
||||
if (tlm == 2) { top = "MOVW"; };
|
||||
let treg: str = "AX";
|
||||
if (full == 1) { treg = "DX"; };
|
||||
if (full == 2) { treg = "CX"; };
|
||||
emitline("\t");
|
||||
emitline(top);
|
||||
emitline("\t");
|
||||
emitline(treg);
|
||||
emitline(", ");
|
||||
emitoff((off + full * 8): i64);
|
||||
emitline("(BP)\n");
|
||||
};
|
||||
c.lastwasreturn = 0;
|
||||
return;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
// Struct ident copy: `let p2: T = p1;` where T is a struct
|
||||
// >8B and rhs is a local ident. Per-qword MOVQ from src
|
||||
// slot to dst slot, with a sized tail (MOVL/MOVB) for
|
||||
|
||||
Reference in New Issue
Block a user