This repo contains the test programs to benchmark a rewritten version
of tnum_mul, the function used in the Linux kernel to multiply
tristate numbers. The new algorithm addresses a challenge ("How can we
incorporate correlation in unknown bits across partial products?")
pointed out by Harishankar et al. in their
paper.
UPDATE: The tnum_mul presented by this repo has been merged to the upstream Linux kernel (version 6.18).
As an example, at 6 bits, the new algorithm achieved optimality in in 81% cases compared to the 38% obtained by the current algorithm.
While work is underway on a detailed explanation on the new algorithm and its soundness proof, please refer to the following to get an initial picture:
- The comments for
my_tnum_mulin lib.c - Quote from the paper by Harishankar et al., given in this section
- An example given in this section
From the paper by Harishankar et al.:
While our_mul is sound, it is not optimal. Key questions remain in designing a sound and optimal algorithm with O(n) or faster run time. (1) How can we incorporate correlation in unknown bits across partial products? For example, multiplying P = 11, Q = 𝜇1 produces the partial products T1 = 11, T2 = 𝜇𝜇0. However, the two 𝜇 trits in T2 are concretely either both 0 or both 1, resulting from the same 𝜇 trit in Q. Failing to consider this in the addition makes the result imprecise. ...
Example showing the above-mentioned imprecision with the current
tnum_mul(a, b), with a = 𝜇1 and b = 11.
11 *
x1
------
11
xx
------
xxx1
The same example with the new algorithm:
11 *
x1
------
11
xx
------
????
acc_0:
11 *
01
------
11
00
------
0011
acc_1:
11 *
11
------
11
11
------
1001
Union:
Value = 0011 & 1001 = 0001
Mask = (0011 ^ 1001) | 0000 | 0000 = 1010
Result = x0x1 (more precise compared to xxx1)
This repo contains the code for "the current algorithm" from the kernel, which is taken from:
commit 0cc53520e68bea7fb80fdc6bdf8d226d1b6a98d9 (origin/master, origin/HEAD, master)
Merge: dfc0f6373094 e2f9ae91619a
Author: Linus Torvalds <torvalds@linux-foundation.org>
Date: Wed Aug 13 20:23:32 2025 -0700
Merge tag 'probes-fixes-v6.17-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace
Copyright 2025, 2026 Nandakumar Edamana; lib.c (multiple copies) contains snippets from the Linux kernel. Released under the terms of the GNU General Public License version 2 only.