Re: [PATCH v2 bpf-next] bpf: improve the general precision of tnum_mul

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Aug 19, 2025 at 11:20:04AM +0200, Jakub Sitnicki wrote:
> On Mon, Aug 18, 2025 at 03:49 PM -07, Eduard Zingerman wrote:
> > On Mon, 2025-08-18 at 20:23 +0200, Jakub Sitnicki wrote:
> >> On Fri, Aug 15, 2025 at 07:35 PM +0530, Nandakumar Edamana wrote:
[...]
> >> > +struct tnum tnum_union(struct tnum a, struct tnum b)
> >> > +{
> >> > +	u64 v = a.value & b.value;
> >> > +	u64 mu = (a.value ^ b.value) | a.mask | b.mask;
> >> > +
> >> > +	return TNUM(v & ~mu, mu);
> >> > +}
> >> 
> >> Not sure I follow. So if I have two tnums that represent known contants,
> >> say a=(v=0b1010, m=0) and b=(v=0b0101, m=0), then their union is an
> >> unknown u=(v=0b0000, m=0b1111)?
> >
> > Yes, because a and b have no bits in common.
> > As far as I understand, tnum_union() computes a tnum that is a
> > superset of both `a` and `b`. Maybe `union` is not the best name.

Purely bike shedding, now that v6 is merged :)

I find `union` name well fit, because it mimics the union of two sets of
integers. For example, using Python-like syntax and assuming tnumify()
is a magical function that creates the best representation of tnum for
any set of integers.

  tnum(v=0b1010, m=0) = tnumify({ 10 })
  tnum(v=0b0101, m=0) = tnumify({  5 })

Whether you find union of { 5 } and { 10 } first, then come up with the
best representation of tnum

  tnumify(union({ 5 }, { 10 })) = tnumify({ 5, 10 })

Or converting { 5 } and { 10 } to tnum first, then use tnum_union() to
mimic union in the integer world

  tnum_union(tnumify({ 5 }), tnumify({ 10 }))

You will end up with the exact same thing

  tnum(v=0b0000, m=0b1111)

In other words the inability to represent { 5, 10 } is an inherent tnum
constrain, rather than of tnum_union's.

And while saying that the function computes a superset of both `a` and
`b` is correct, it is not as precise, because there could be many
supersets.

E.g. for a=tnum(v=0b0001, b=0) and b=tnum(v=0b0101, b=0) it gives
tnum(v=0b0001, m=0b0100). While that is indeed is a superset of `a`
and `b`, so is something like tnum(v=0b0001, m=0b1110).

> Makes sense if I think about it like that. Thanks.




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux