Possible Bug or Typo

Brett Kuntz kuntz at shaw.ca
Fri Mar 7 19:42:52 CET 2025


Hello, I am perusing through /mpn/powm.c in order to try and solve the seg-faults on larger operations, and it uses (in some cases) mpn_sqr(), which uses mpn_toom3_sqr_itch(n) and mpn_toom4_sqr_itch(n) to allocate some stack memory.

These are both defined inside gmp-impl.h and there might be a typo or copy-paste bug but I can't know for sure. The defines are:

    /* toom33/toom3: Scratch need is 5an/2 + 10k, k is the recursion depth.
       We use 3an + C, so that we can use a smaller constant.
     */
    #define mpn_toom33_mul_itch(an, bn) \
      (3 * (an) + GMP_NUMB_BITS)
    #define mpn_toom3_sqr_itch(an) \
      (3 * (an) + GMP_NUMB_BITS)

    /* toom33/toom3: Scratch need is 8an/3 + 13k, k is the recursion depth.
       We use 3an + C, so that we can use a smaller constant.
     */
    #define mpn_toom44_mul_itch(an, bn) \
      (3 * (an) + GMP_NUMB_BITS)
    #define mpn_toom4_sqr_itch(an) \
      (3 * (an) + GMP_NUMB_BITS)


As you can see both are defined as "(3 * (an) + GMP_NUMB_BITS)". I am only bringing this up as the commenting for 3 is "Scratch need is 5an/2 + 10k, k is the recursion depth" and the commenting for 4 is "Scratch need is 8an/3 + 13k, k is the recursion depth".

So my question is was the mpn_toom4_sqr_itch() define supposed to use different (larger) numbers than the mpn_toom3_sqr_itch() define? 

-Brett


More information about the gmp-bugs mailing list