Skip to content

Conversation

@czurnieden
Copy link
Contributor

This PR replaces the comba-squaring cut-off MP_MAX_COMBA/2 with MP_MAX_COMBA.

Saw @tomstdenis taking part in the discussion over at #429 lately and remembered the curious results for the faster squaring algorithms (Karatsuba and Toom-Cook-3) where the cut-offs for both coincided with the upper limit of comba-squaring but not for comba-multiplying.

The upper limit for comba-multiplying is the size of min(a.used,b.used) but for comba-squaring it is a.used/2. Neither the actual code nor tests with inputs of the form -1 + 2^(n*MP_DIGIT_BIT) (all bits set in every limb with MP_MASK) for all MP_16BIT, MP_32BIT, and MP_64BIT showed a reason for that difference.

Also: running tune gives reasonable cut-offs now for the Karatsuba and Toom-Cook-3 squaring algorithms.

@czurnieden czurnieden requested a review from sjaeckel January 7, 2021 08:20
@czurnieden
Copy link
Contributor Author

It is not a proper mathematical proof but I can make an exhaustive test with the fully filled limbs (intermediate results cannot get bigger than with that input).

`MP_DIGIT_BIT` `max floor(log_2(2*_W + W1))`
15 30
28 63
31*62
60 127
So, yes: the Comba cut-off for squaring can safely be set to `MP_MAX_COMBA`.

\* 31-bit cannot be defined by simply adding "-DMP_31BIT" to `LTM_CFLAGS` it needs manual editing of `tommath.h`. (I think that has been done intentionally but I cannot find the discussion about it quickly)

@czurnieden
Copy link
Contributor Author

I'm trying to clean up my PRs (quite a mess), so:
Is it useful or can it go?

@sjaeckel sjaeckel merged commit e4b789b into libtom:develop Apr 5, 2023
@czurnieden czurnieden mentioned this pull request Apr 5, 2023
@czurnieden czurnieden deleted the comba_cutoff_squaring branch April 5, 2023 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants