On Fri, Aug 22, 2025 at 5:50 PM Eduard Zingerman <eddyz87@xxxxxxxxx> wrote: > > On Fri, 2025-08-22 at 22:38 +0530, Nandakumar Edamana wrote: [...] > +struct tnum tnum_mul_new(struct tnum a, struct tnum b) > +{ > + struct tnum ab = __tnum_mul_new(a, b); > + struct tnum ba = __tnum_mul_new(b, a); > + > + return __builtin_popcountl(ab.mask) < __builtin_popcountl(ba.mask) ? ab : ba; > +} > + We had originally observed in our paper [1] that tnum_mul is not commutative, and considered taking the best of two possible results (a*b) versus (b*a). Indeed, the new tnum_mul is also not commutative so we can do this. We decided against it eventually because this approach involves running two loops, each of which will run 64 times in the worst case. [1] https://arxiv.org/pdf/2105.05398 > For the 8-bit case I get the following stats (using the same [1] as > before): > > Patch as-is Patch with above modification > ----------- ----------------------------- > Tnums : 6560 > New win: 30086328 70 % 31282549 73 % > Old win: 1463809 3 % 907850 2 % > Same : 11483463 27 % 10843201 25 % > > > Looks a bit ugly, though. > Wdyt? > > [1] https://github.com/eddyz87/tnum_mul_compare/blob/master/README.md > > [...]