1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// SPDX-FileCopyrightText: 2026 John Moxley
// SPDX-License-Identifier: MIT OR Apache-2.0
// candidate: N<=2 signed div_rem via direct two's-complement i128 `/` and
// `%` (skips the unsigned_abs / from_mag_limbs sign-magnitude round trip
// the shipped Int::div_rem pays on BOTH operands and BOTH outputs), not
// wired.
//
//! Direct-`i128` signed `div_rem` candidate for narrow `Int<N>` (`N <= 2`).
//!
//! The shipped [`crate::int::types::Int::div_rem`] (which the `Int<N>`
//! `Div` and `Rem` operators route through) computes on UNSIGNED
//! magnitudes: it calls `unsigned_abs()` (a `neg_dispatch` round trip on a
//! negative operand) on BOTH `self` and `rhs`, runs `div_rem_mag_fixed`
//! (whose `N <= 2` arm is already a native `u64`/`u128` idiv), then rebuilds
//! BOTH the quotient and the remainder via `from_mag_limbs` with the
//! reconstructed signs. That is two `unsigned_abs` + two `from_mag_limbs`
//! sign-magnitude conversions wrapping a single hardware divide.
//!
//! This is the SAME overhead the rem-only sibling
//! [`crate::int::algos::rem::rem_native_direct`] removes, and the SAME
//! overhead `Int::as_i128` avoids. For `N <= 2` the limbs
//! ARE the i64/i128 two's-complement value (see `Int::as_i128`'s `N <= 2`
//! fast path), and hardware signed `/` and `%` already implement
//! truncating-toward-zero with the exact sign rules `div_rem`
//! reconstructs, so the magnitudes never need to be materialised.
//!
//! The only hazard signed `/`/`%` carry is the `i128::MIN / -1` (and
//! `i128::MIN % -1`) overflow trap; we guard it explicitly (quotient
//! `MIN`, remainder `0` — the `wrapping_div`/`wrapping_rem` results, which
//! match the magnitude path: |MIN|/1 = |MIN| re-signed wraps to MIN, and
//! |MIN| % 1 = 0). Bit-identical to the magnitude path for every operand
//! relationship.
//!
//! Both `as_i128` (the read) and `from_i128` (the write-back) const-fold to
//! plain limb loads/stores for `N <= 2`, so this stays a single generic
//! kernel — no per-tier type, no macro duplication. Valid only for
//! `N <= 2`; intended for the `Int<N>` `Div`/`Rem` operator fast arm at
//! `N == 1` / `N == 2`.
use crateInt;
/// Direct two's-complement signed `(quotient, remainder)` for `Int<N>`,
/// `N <= 2`.
///
/// Reads both operands as native `i128` (the `N <= 2` fast path is a plain
/// limb load), takes hardware signed `/` and `%`, and stores back. Panics
/// on a zero divisor, matching `Int::div_rem`. Guards the `i128::MIN / -1`
/// overflow boundary (quotient `MIN`, remainder `0`, as the wrapping
/// primitives do), so it is bit-identical to the shipped magnitude path.
pub