diff options
| author | Nandakumar Edamana <nandakumar@nandakumar.co.in> | 2025-08-26 09:15:23 +0530 |
|---|---|---|
| committer | Andrii Nakryiko <andrii@kernel.org> | 2025-08-27 15:00:26 -0700 |
| commit | 1df7dad4d5c49335b72e26d833def960b2de76e3 (patch) | |
| tree | 9f96e2afa5ac408fe3b108e964b586fe4c238793 /include | |
| parent | 2465bb83e0b44e19ae7e3ad07148db61fbe0e2bf (diff) | |
bpf: Improve the general precision of tnum_mul
Drop the value-mask decomposition technique and adopt straightforward
long-multiplication with a twist: when LSB(a) is uncertain, find the
two partial products (for LSB(a) = known 0 and LSB(a) = known 1) and
take a union.
Experiment shows that applying this technique in long multiplication
improves the precision in a significant number of cases (at the cost
of losing precision in a relatively lower number of cases).
Signed-off-by: Nandakumar Edamana <nandakumar@nandakumar.co.in>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Tested-by: Harishankar Vishwanathan <harishankar.vishwanathan@gmail.com>
Reviewed-by: Harishankar Vishwanathan <harishankar.vishwanathan@gmail.com>
Acked-by: Eduard Zingerman <eddyz87@gmail.com>
Link: https://lore.kernel.org/bpf/20250826034524.2159515-1-nandakumar@nandakumar.co.in
Diffstat (limited to 'include')
| -rw-r--r-- | include/linux/tnum.h | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/include/linux/tnum.h b/include/linux/tnum.h index 0ffb77ffe0e8..c52b862dad45 100644 --- a/include/linux/tnum.h +++ b/include/linux/tnum.h @@ -57,6 +57,9 @@ bool tnum_overlap(struct tnum a, struct tnum b); /* Return a tnum representing numbers satisfying both @a and @b */ struct tnum tnum_intersect(struct tnum a, struct tnum b); +/* Returns a tnum representing numbers satisfying either @a or @b */ +struct tnum tnum_union(struct tnum t1, struct tnum t2); + /* Return @a with all but the lowest @size bytes cleared */ struct tnum tnum_cast(struct tnum a, u8 size); |
