Replaces the N>1 "Phase E" bail with a shared asmResultType helper (lowering +
inferType) that derives the result type from the out_value operands: 0→void,
1→T, N→a named tuple (fields named via the §II.5 effective-name rule).
Key realization: toLLVMType(tuple) already produces a literal struct {T1,…,Tn} —
exactly what LLVM's multi-output inline asm returns — so emit needs NO change.
Building the op with a tuple result type makes the asm call return the struct,
which IS sx's tuple value (destructured by the normal tuple_get path).
inferType's .asm_expr arm now also delegates to asmResultType (single owner), so
`return asm`, `x := asm`, and `q, r := asm` all agree on the type.
Verified end-to-end on aarch64: split(0x1234)→(lo=52,hi=18), a udiv/msub
divmod→(3,2). IR: `call { i64, i64 } asm "divq ${4}",
"={rax},={rdx},{rax},{rdx},r,~{cc}"(…)` → extractvalue → tuple.
1640 → the x86_64 multi-output IR lock (ir-only); 1647 → a multi-output example
that runs on aarch64.
zig build test green (655 corpus, 446 unit).
21 lines
688 B
Plaintext
21 lines
688 B
Plaintext
// ASM stream Phase E — multi-output asm that RUNS end-to-end on aarch64. Splits
|
|
// a value into low/high bytes via two value outputs, returned + destructured as
|
|
// a `(lo, hi)` tuple. The two outputs become an LLVM `{ i64, i64 }` struct =
|
|
// sx's tuple. aarch64-pinned via `.build`: executes on a matching host (exit
|
|
// reflects lo+hi), ir-only elsewhere.
|
|
split :: (x: u64) -> (lo: u64, hi: u64) {
|
|
return asm {
|
|
#string ASM
|
|
and %[l], %[x], #0xff
|
|
lsr %[h], %[x], #8
|
|
ASM,
|
|
[l] "=r" -> u64,
|
|
[h] "=r" -> u64,
|
|
[x] "r" = x,
|
|
};
|
|
}
|
|
main :: () -> i64 {
|
|
lo, hi := split(0x1234);
|
|
return xx (lo + hi); // 0x34 + 0x12 = 52 + 18 = 70
|
|
}
|