Files
LithosAnanke/v4/src/umul.c
T
Claude 3bd81097e1 chore(license): an SPDX header on every source file that had none (LicenseRef-Starship-1.0) [skip ci]
The header scan (Captain Bob, 2026-11-10): 788 source files -- 351 with the
SL-1.0 header, 12 with the old name (docs/working/experiments, kept by
ruling), 31 under someone else's licence (tools/kconfig, Linux's, GPL-2.0:
kept), and 394 with none. Ruled: the SPDX form; capsules (.4th, .f18) and
proofs (.thy) left for a ruling of their own (mkcapsule's 64x16 block format,
content-addressed capsules).

253 files now begin
    SPDX-License-Identifier: LicenseRef-Starship-1.0
    Copyright (c) 2023-2026 Robert A. James
as a /* */ block (C, headers, assembly, linker scripts) or # lines (scripts,
Makefiles, Kconfig; below a shebang or a coding line); tools/mkcapsule.c,
which had the copyright line, gets the SPDX line only.

Not touched: docs/working/ (archive and old campaign material, as the
ruling kept the experiments); v4/system/post_cases.c (generated by
v4/tools/mkpost.py, "do not edit" -- the generator has the header).

Comments only: the kernel builds on amd64, aarch64, riscv64; make -C v4
test-32: 39 programs, 0 failures; every changed script parses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GE3SDvQn5EoxdGufk84zz2
2026-11-10 04:12:49 +00:00

31 lines
1.0 KiB
C

/* SPDX-License-Identifier: LicenseRef-Starship-1.0
* Copyright (c) 2023-2026 Robert A. James
*/
/* umul.c -- reference unsigned multiply. See umul.h.
*
* Schoolbook multiplication on half-cells, in v4_ucell only. No wider type is
* used, so the same code is correct at both cell widths and builds on a host
* with no 128-bit integer (ARMv7 is one, and is a v4 host).
*/
#include "v4/umul.h"
#define HALF_BITS (V4_CELL_BITS / 2)
#define HALF_MASK ((((v4_ucell)1) << HALF_BITS) - 1u)
void v4_umul(v4_ucell u1, v4_ucell u2, v4_ucell *ulo, v4_ucell *uhi)
{
v4_ucell a0 = u1 & HALF_MASK, a1 = u1 >> HALF_BITS;
v4_ucell b0 = u2 & HALF_MASK, b1 = u2 >> HALF_BITS;
v4_ucell p00 = a0 * b0;
v4_ucell p10 = a1 * b0;
v4_ucell p01 = a0 * b1;
v4_ucell p11 = a1 * b1;
/* Cannot overflow: at most (2^h - 1) + (2^h - 1) + (2^h - 1)^2 = 2^2h - 1. */
v4_ucell mid = (p00 >> HALF_BITS) + (p10 & HALF_MASK) + p01;
if (ulo) *ulo = (mid << HALF_BITS) | (p00 & HALF_MASK);
if (uhi) *uhi = p11 + (p10 >> HALF_BITS) + (mid >> HALF_BITS);
}