Skip to content

mul-hi: real high-half multiply, and stop lying when we can't - #138

Merged
Zaneham merged 5 commits into
masterfrom
feat/mul-hi
Jul 26, 2026
Merged

mul-hi: real high-half multiply, and stop lying when we can't#138
Zaneham merged 5 commits into
masterfrom
feat/mul-hi

Conversation

@Zaneham

@Zaneham Zaneham commented Jul 25, 2026

Copy link
Copy Markdown
Owner

__umulhi/__umul64hi were quietly broken. NVIDIA emitted a store of an
undefined register and exited 0; AMD emitted no multiply at all, also exit 0.
Both are the silent-wrong-answer case, and mul-hi is on the ZK field-arith path.

NVIDIA now emits real mul.hi at both widths (PTX has it natively). Checked on a
4060 Ti: umul64hi(0x123456789, 0xfedcba987) = 18, matches the __int128 answer.

AMD gets v_mul_hi_u32 wired across gfx9/10/11/12 (each encoding confirmed with
llvm-objdump) and a real 32-bit __umulhi, verified on emulated RDNA3/4. The
64-bit __umul64hi needs an i64 result the backend can't hold yet (VGPR pairs +
dwordx2 store + regalloc alignment), so it refuses the compile rather than
emitting nothing. The same error path now also catches device calls, which were
printing an error but still exiting 0.

Also wires __umulhi (32-bit) through sema + the lowerer, and moves nv_rt's
device banner to stderr so stdout is just results.

Zaneham added 5 commits July 25, 2026 22:24
Was emitting a store of an undefined register and exiting 0. PTX has mul.hi
at both widths, verified on a 4060 Ti: umul64hi(0x123456789,0xfedcba987)=18.
Adds the opcode across gfx9/10/11/12 (objdump-verified) and a real 32-bit
high-half multiply, checked on emulated RDNA3/4. __umul64hi needs an i64
result the backend can't hold yet, so it fails the compile instead of
silently emitting nothing. Same guard now catches device calls.
@Zaneham Zaneham added backend: AMD AMD GFX9/10/11/12 backend (isel, regalloc, ELF encode) backend: NVIDIA NVIDIA PTX backend labels Jul 26, 2026
@Zaneham Zaneham self-assigned this Jul 26, 2026
@Zaneham
Zaneham merged commit db2c041 into master Jul 26, 2026
7 checks passed
@Zaneham
Zaneham deleted the feat/mul-hi branch July 28, 2026 06:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend: AMD AMD GFX9/10/11/12 backend (isel, regalloc, ELF encode) backend: NVIDIA NVIDIA PTX backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant