nx_bigint_lib.nx
buildroot/runtime/nx_bigint_lib.nx
about
nx_bigint_lib.nx -- multi-precision integer PRIMITIVES (unsigned), the IMPORTABLE library.
Split 2026-07-09 from the nx_bigint.nx / bigint.nx twins (which were code-identical and BOTH carried a
main() KAT battery, making them unimportable into any main-bearing binary -- the nx_qa_score_lib precedent).
The twins now import THIS lib and keep their main() gates; new consumers (e.g. nx_swcompare_bench) import
the lib directly. ZERO imports by design: every primitive is pure limb math on caller-owned buffers (BI3),
so this lib is syscall-module-agnostic (safe under both syscalls.nx and nx_syscalls.nx import chains).
Representation: array of u32 limbs in LITTLE-ENDIAN order (limb 0 is least-significant 32 bits), stored in
i64 slots (low 32 bits used) so 32x32 products and carried sums fit in i64 without overflow.
Invariants (from the original):
BI1 Limbs past the declared length are never read; callers pass explicit lengths.
BI2 Results are written with LENGTH HINTS the caller allocates for (bi_add output needs n+1 limbs).
BI3 No heap allocation inside primitives -- caller owns limb buffers.
BI4 Comparison returns -1 / 0 / +1 like strcmp.
BI5 Arithmetic is UNSIGNED; signed lives at the caller's layer.
license_tier: ORIGINAL
dependencies 0 imports · 3 importers
imports: none
imported by: bigint.nxnx_bigint.nxnx_swcompare_bench.nx
structs
| none |
consts
| 20 | const LIMB_BITS: i64 = 32 |
| 21 | const LIMB_MASK: i64 = 0xFFFFFFFF |
functions
| 24 | func bi_copy(dst: *i64, src: *i64, n: i64) -> i64 called by 1: bi_modexp |
| 31 | func bi_zero(dst: *i64, n: i64) -> i64 |
| 39 | func bi_cmp(a: *i64, b: *i64, n: i64) -> i64 called by 1: bi_mod |
| 53 | func bi_add(r: *i64, a: *i64, b: *i64, n: i64) -> i64 |
| 69 | func bi_sub(r: *i64, a: *i64, b: *i64, n: i64) -> i64 called by 1: bi_mod |
| 84 | func bi_shl1(r: *i64, n: i64) -> i64 called by 1: bi_mod |
| 98 | func bi_shr1(r: *i64, n: i64, carry_in: i64) -> i64 |
| 114 | func bi_mul(r: *i64, a: *i64, a_len: i64, b: *i64, b_len: i64) -> i64 |
| 142 | func bi_from_bytes_be(r: *i64, n_limbs: i64, |
| 159 | func bi_to_bytes_be(out: *u8, n_bytes: i64, |