imneme / pcg-cpp

PCG — C++ Implementation
Apache License 2.0
735 stars 98 forks source link

pcg64_c32 not usable #64

Open TopoIogist opened 3 years ago

TopoIogist commented 3 years ago

When trying to use pgc with a fully updated visual studio 2019 (version 16.7.5) I can use generators as

    // Make a random number engine 
    pcg64 rng(1234);

without any problem, but when trying out pcg64_c32 instead of pcg64 I see compile errors (I am using c++17 language mode but it doesn't matter). It complains about line 1246 in pcg_random.hpp. For some reason the table_mask constexpr seems to not evaluate to a constant.

image

imneme commented 3 years ago

This happens because on Windows, pcg64 needs to use a helper library to do 128-bit math, and not enough of the functions in that library are constexpr functions. If you were using pcg32 with the extension scheme, it'd not be an issue.

Long term, the solution is to fix the 128-bit math library or find a better way to do 128-bit math on Windows.

musicinmybrain commented 3 years ago

I think this is the same issue that prevents graph-tool from building on 32-bit architectures in Fedora Linux, with messages like:

[omitted pages and pages of template spew from graph-tool]
../../../src/pcg-cpp/include/pcg_random.hpp:1247:40: error: call to non-'constexpr' function 'pcg_extras::uint_x4<U, V> pcg_extras::operator-(const pcg_extras::uint_x4<U, V>&, const pcg_extras::uint_x4<U, V>&) [with UInt = unsigned int; UIntX2 = long long unsigned int]'
 1247 |         (state_type(1U) << table_pow2) - state_type(1U);
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
In file included from ../../../src/pcg-cpp/include/pcg_extras.hpp:84,
                 from ../../../src/pcg-cpp/include/pcg_random.hpp:114,
                 from ../../../src/graph/random.hh:21,
                 from graph_motifs.hh:26,
                 from graph_motifs.cc:24:
../../../src/pcg-cpp/include/pcg_uint128.hpp:779:22: note: 'pcg_extras::uint_x4<U, V> pcg_extras::operator-(const pcg_extras::uint_x4<U, V>&, const pcg_extras::uint_x4<U, V>&) [with UInt = unsigned int; UIntX2 = long long unsigned int]' declared here
  779 | uint_x4<UInt,UIntX2> operator-(const uint_x4<UInt,UIntX2>& a,
      |                      ^~~~~~~~