Repository navigation
feat(intrinsics): lower carrying_mul_add; refuse unrecognized rustc intrinsics loudly - #161
Merged
Merged
Conversation
…ing call Root cause: `u32::carrying_mul_add` (and the sibling bigint helpers `carrying_mul` / `widening_mul` / signed `carrying_mul_add`) compile to a call to the rustc intrinsic `core::intrinsics::carrying_mul_add` in MIR. `try_dispatch_intrinsic` had no arm for it, so the call fell through to the regular `mir.call` path against the intrinsic's mangled symbol. The collector skips `InstanceKind::Intrinsic` by design, so no definition for that symbol ever exists, and the build died late with the unhelpful "Symbol _RINv..carrying_mul_add.. not found" from the LLVM dialect module verifier. The fix has two parts: 1. A new `bigint` intrinsic family (modelled on the saturating family) carries the call as a placeholder `mir.call` through the importer. The MIR-to-LLVM lowering then expands it the same way core's fallback computes it: widen all four operands to 2*N bits (zext for unsigned, sext for signed), compute `a * b + c + d` (which cannot overflow 2*N bits), and split the wide value into the `(low, high)` tuple via trunc / lshr / trunc. NVPTX folds the idiom into mul.wide / mul.lo / mul.hi / mad instructions. 128-bit element types are rejected with a clear diagnostic since they would need 256-bit intermediate arithmetic. 2. The fall-through in `translate_call` now refuses to emit a regular call to any unrecognized `core::intrinsics::*` / `std::intrinsics::*` callee and instead returns an "Unsupported construct: rustc intrinsic `...` is not yet supported on the device" error with the source span. Such a call can never link, so every future intrinsic gap now surfaces as an actionable per-site diagnostic at translation time instead of a late verifier failure. The new `carrying_mul_add` example exercises the literal-argument shape from the issue plus runtime-argument u32 / u64 / i32 cases (including the all-MAX inputs whose exact result is 2^64 - 1) and verifies device results against the host methods. Fixes #137
meefs
pushed a commit
to meefs/cuda-oxide
that referenced
this pull request
Sep 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
u32::carrying_mul_add(andcarrying_mul/widening_mul, which funnel into the same intrinsic) now compiles and runs in kernels. Separately, ANY unrecognizedcore::intrinsics::*callee now fails at translation with an actionable message instead of the late "Symbol ... not found" verifier error.How
bigintintrinsic family in the importer (modelled on the siblingsaturatingfamily) emits a placeholder call with the(T, T)tuple return.wide = a*b + c + d(cannot overflow 2N bits; the proof is in the function doc), low/high via trunc and lshr. 128-bit elements are rejected with a targeted diagnostic (would need 256-bit intermediates).core::intrinsics::*/std::intrinsics::*callees at translation time (the collector skips intrinsic instances by design, so such symbols can never link).Evidence
carrying_mul_add: literal shape from the issue, all-MAX u32 (exact 2^64 - 1), u64 (i128 wide path), signed i32 (sext path); executes on sm_120 (SUCCESS).impl_carrying_mul_add_by_wideningexactly.mul.wide.u32/ carry chains as expected. Tests/clippy/fmt clean; full compile-only smoketest green.Fixes #137