Skip to content

Fix compiler errors and warnings #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

kimwalisch
Copy link

This pull request fixes the compiler errors and warnings further down that I encountered in my Pseudosquares-Prime-Sieve. I have tested these fixes on the montgomery_pow_kary branch of my Pseudosquares-Prime-Sieve project and all unit tests pass successfully: https://github.com/kimwalisch/Pseudosquares-Prime-Sieve/actions/runs/15957320257

I tested using Clang on macOS, using GCC on Windows with MSYS2/MinGW-w64 and using GCC and Clang on Linux. My code compiles without any compilers warnings now using -Wall -Wextra -pedantic.

Fixed errors

The errors below have been fixed by using if constexpr() from C++17. I have also updated the CMakeLists.txt and set cxx_std_17 on the hurchalla_modular_arithmetic interface library so that the compiler uses a C++ standard >= 2017 (when your library is included by some other CMake project). My error fixes require C++17 or later because I currently don't know how to fix these errors without C++17.

In file included from /Users/kim/GitHub/Pseudosquares-Prime-Sieve/src/pseudosquares_prime_sieve.cpp:19:
In file included from /Users/kim/GitHub/Pseudosquares-Prime-Sieve/src/modpow.hpp:23:
/Users/kim/GitHub/Pseudosquares-Prime-Sieve/lib/modular_arithmetic/montgomery_arithmetic/include/hurchalla/montgomery_arithmetic/detail/experimental/montgomery_pow_kary.h:119:23: error: static assertion failed due to requirement 'TABLESIZE % 64 == 0': 
  119 |         static_assert(TABLESIZE % 64 == 0, "");
      |                       ^~~~~~~~~~~~~~~~~~~
/Users/kim/GitHub/Pseudosquares-Prime-Sieve/lib/modular_arithmetic/montgomery_arithmetic/include/hurchalla/montgomery_arithmetic/detail/experimental/montgomery_pow_kary.h:100:9: warning: array index 16 is past the end of the array (that has type 'V[16]' (aka 'hurchalla::detail::MontyQRValueTypes<unsigned long long>::V[16]')) [-Warray-bounds]
  100 |         table[16] = mf.square(table[8]);

Fixed warnings

The warnings below have been fixed by using int instead of size_t for the P variable. I could also have casted P to an int but since this is basically required for every single usage of P it seemed better to simply change P's type to an int.

In file included from /Users/kim/GitHub/Pseudosquares-Prime-Sieve/src/modpow.hpp:23:
/Users/kim/GitHub/Pseudosquares-Prime-Sieve/lib/modular_arithmetic/montgomery_arithmetic/include/hurchalla/montgomery_arithmetic/detail/experimental/montgomery_pow_kary.h:288:36: warning: comparison of integers of different signs: 'int' and 'const size_t' (aka 'const unsigned long') [-Wsign-compare]
  288 |     HPBC_ASSERT(0 < shift && shift < P);
/Users/kim/GitHub/Pseudosquares-Prime-Sieve/lib/modular_arithmetic/montgomery_arithmetic/include/hurchalla/montgomery_arithmetic/detail/experimental/montgomery_pow_kary.h:141:25: warning: comparison of integers of different signs: 'int' and 'const size_t' (aka 'const unsigned long') [-Wsign-compare]
  141 |     HPBC_ASSERT(numbits > P);

@kimwalisch
Copy link
Author

For your information:

I have now further optimized the math formulas in my Pseudosquares-Prime-Sieve project and using your montgomery_pow_kary() implementation is now slower than the default montgomery implementation for 128-bit numbers on all my three CPUs: Apple M2, AMD EPYC Zen2 and Intel Core Ultra 5 245K. Hence I will not use montgomery_pow_kary() in my project for the time being.

I do however use your montgomery_two_pow() implementation now, as I found it consistently speeds up my program by a small amount.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant