Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/uint256.zig
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,14 @@ pub fn safeMul(a: u256, b: u256) ?u256 {
}

/// Division (returns null on divide by zero).
///
/// Routes through the limb-based `divLimbsDirect` rather than the builtin
/// `u256 /`, which lowers to a slow software long-division on aarch64
/// (measured ~330ns for a 256/128-bit divide vs a few tens of ns here). Same
/// fast path `mulDiv` and the dex math already use.
pub fn safeDiv(a: u256, b: u256) ?u256 {
if (b == 0) return null;
return a / b;
return limbsToU256(divLimbsDirect(u256ToLimbs(a), u256ToLimbs(b)));
}

/// Fast u256 division using u64-limb schoolbook algorithm.
Expand Down
Loading