feat(asm): Phase E — multi-output asm returns tuples
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).
This commit is contained in:
1
examples/expected/1640-platform-asm-parse.build
Normal file
1
examples/expected/1640-platform-asm-parse.build
Normal file
@@ -0,0 +1 @@
|
||||
{ "target": "x86_64-linux" }
|
||||
@@ -1 +1 @@
|
||||
1
|
||||
0
|
||||
|
||||
26
examples/expected/1640-platform-asm-parse.ir
Normal file
26
examples/expected/1640-platform-asm-parse.ir
Normal file
@@ -0,0 +1,26 @@
|
||||
|
||||
; Function Attrs: nounwind
|
||||
define internal { i64, i64 } @divmod(i64 %0, i64 %1) #0 {
|
||||
entry:
|
||||
%alloca = alloca i64, align 8
|
||||
store i64 %0, ptr %alloca, align 8
|
||||
%allocaN = alloca i64, align 8
|
||||
store i64 %1, ptr %allocaN, align 8
|
||||
%load = load i64, ptr %alloca, align 8
|
||||
%loadN = load i64, ptr %allocaN, align 8
|
||||
%asm = call { i64, i64 } asm "divq ${4}", "={rax},={rdx},{rax},{rdx},r,~{cc}"(i64 %load, i64 0, i64 %loadN)
|
||||
ret { i64, i64 } %asm
|
||||
}
|
||||
|
||||
; Function Attrs: nounwind
|
||||
define i32 @main() #0 {
|
||||
entry:
|
||||
%call = call { i64, i64 } @divmod(i64 17, i64 5)
|
||||
%tg = extractvalue { i64, i64 } %call, 0
|
||||
%alloca = alloca i64, align 8
|
||||
store i64 %tg, ptr %alloca, align 8
|
||||
%tgN = extractvalue { i64, i64 } %call, 1
|
||||
%allocaN = alloca i64, align 8
|
||||
store i64 %tgN, ptr %allocaN, align 8
|
||||
ret i32 0
|
||||
}
|
||||
@@ -1,17 +1 @@
|
||||
error: multi-output (tuple-returning) inline assembly is not yet implemented (ASM stream Phase E)
|
||||
--> examples/1640-platform-asm-parse.sx:9:12
|
||||
|
|
||||
9 | return asm {
|
||||
| ^^^^^
|
||||
10 | "divq %[d]",
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
11 | [quot] "={rax}" -> u64,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
12 | [rem] "={rdx}" -> u64,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
13 | "{rax}" = n, "{rdx}" = 0, [d] "r" = d,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
14 | clobbers(.cc),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
15 | };
|
||||
| ^^^^^
|
||||
|
||||
|
||||
1
examples/expected/1647-platform-asm-aarch64-multi.build
Normal file
1
examples/expected/1647-platform-asm-aarch64-multi.build
Normal file
@@ -0,0 +1 @@
|
||||
{ "target": "macos" }
|
||||
1
examples/expected/1647-platform-asm-aarch64-multi.exit
Normal file
1
examples/expected/1647-platform-asm-aarch64-multi.exit
Normal file
@@ -0,0 +1 @@
|
||||
70
|
||||
31
examples/expected/1647-platform-asm-aarch64-multi.ir
Normal file
31
examples/expected/1647-platform-asm-aarch64-multi.ir
Normal file
@@ -0,0 +1,31 @@
|
||||
|
||||
; Function Attrs: nounwind
|
||||
define internal { i64, i64 } @split(i64 %0) #0 {
|
||||
entry:
|
||||
%alloca = alloca i64, align 8
|
||||
store i64 %0, ptr %alloca, align 8
|
||||
%load = load i64, ptr %alloca, align 8
|
||||
%asm = call { i64, i64 } asm " and ${0}, ${2}, #0xff\0A lsr ${1}, ${2}, #8\0A", "=r,=r,r"(i64 %load)
|
||||
%tg = extractvalue { i64, i64 } %asm, 0
|
||||
%tgN = extractvalue { i64, i64 } %asm, 1
|
||||
%ti = insertvalue { i64, i64 } undef, i64 %tg, 0
|
||||
%tiN = insertvalue { i64, i64 } %ti, i64 %tgN, 1
|
||||
ret { i64, i64 } %tiN
|
||||
}
|
||||
|
||||
; Function Attrs: nounwind
|
||||
define i32 @main() #0 {
|
||||
entry:
|
||||
%call = call { i64, i64 } @split(i64 4660)
|
||||
%tg = extractvalue { i64, i64 } %call, 0
|
||||
%alloca = alloca i64, align 8
|
||||
store i64 %tg, ptr %alloca, align 8
|
||||
%tgN = extractvalue { i64, i64 } %call, 1
|
||||
%allocaN = alloca i64, align 8
|
||||
store i64 %tgN, ptr %allocaN, align 8
|
||||
%load = load i64, ptr %alloca, align 8
|
||||
%loadN = load i64, ptr %allocaN, align 8
|
||||
%add = add i64 %load, %loadN
|
||||
%ca.tr = trunc i64 %add to i32
|
||||
ret i32 %ca.tr
|
||||
}
|
||||
1
examples/expected/1647-platform-asm-aarch64-multi.stderr
Normal file
1
examples/expected/1647-platform-asm-aarch64-multi.stderr
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
1
examples/expected/1647-platform-asm-aarch64-multi.stdout
Normal file
1
examples/expected/1647-platform-asm-aarch64-multi.stdout
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
Reference in New Issue
Block a user