Comments (7)
Hi Keith / @bitlush ,
Thank you for your interest in the project! I've never tried compiling with MS's Visual Studio, nor do I have windows/Visual Studio... Would you be interested in contributing, e.g., by sending a pull request?
-
__uint128_t is indeed a clang/gcc-only thing. Do you know whether MS has something like that?
Probably, some macros (or constexpr-if) can help here to switch this case off for the MS compiler.
BTW, even if MS does not provide a 128-bit type, then as a workaround you can use the big-ints with 32-bit limbs, since most of the code is templated on the limb type,
or I can define a dedicated 64x64bit mul function. (I already did that once, but removed it some time ago) -
Regarding the always inline, this should probably be "__forceinline" for Visual Studio,
a macro should then choose between the GNU and Microsoft pragma based on the detected compiler. -
Regarding:
explicit operator auto() const { return data; }
I am not sure if I actually use that somewhere.
Does the following (explicitly spelling the type to the compiler) compile?
explicit operator big_int<sizeof...(Modulus), T>() const { return data; }
- The error with:
constexpr auto ext_gcd(std::integer_sequence<T, A...>,
std::integer_sequence<T, B...>)
must have been caused by the Is
template parameter pack, which did not serve any purpose (it probably originated from some copy pasting from ext_gcd_impl
), but neither clang nor gcc complained about it. I have already removed that.
from ctbignum.
I'll fork and create a pull request as I've managed to get the bits I've tried compiling. I've also had to sprinkle a few static_casts around the code to remove compiler warnings. I also use Clang and AppleClang as well so I can easily do a regression on those.
Great work by the way, this is a wonderful library.
from ctbignum.
Great! I'd be very interested to see where exactly those static_casts are needed.
BTW The old multiplication code (circumventing __uint128_t ) can be found commit: fba16e2
from ctbignum.
@bitlush,
I discovered that in type_traits.hpp
, the specialization of dbl_bitlen
for unsigned long
interfered with that of uint64_t
, so I commented-out the former, see commit 1223979
from ctbignum.
@niekbouman, OK thanks for the heads up. It'll be a day or two before I can check my changes through as the tests are problematic under MSVC.
I'm going to propose using the following to fix the missing 128-bit integers in type_traits.hpp
:
#if defined(_MSC_VER)
using default_limb_t = uint32_t;
#else
using default_limb_t = uint64_t;
#endif
And then I can update all templates like so:
template <size_t N, typename T = default_limb_t,
typename = std::enable_if_t<std::is_integral<T>::value>>
struct big_int : std::array<T, N> {};
If you've got a view on this approach, please let me know, I'm not overly convinced it's a great way to go.
I'm undecided if a better approach is to actually use a zero abstraction wrapper for limb data types i.e. limb8_t
, limb32_t
, limb64_t
which would overload the maths operations, provide a better route to fix all the overflow warnings in MSVC by keeping the code free of static_cast
fixes, allow limb64_t
to use platform specific code for multiplications etc when 128-bit integers don't exist, but it's a lot of work and adds more code and complexity.
After some more thought, I think the simplest approach is to provide a custom implementation of 128 integers for non-supporting platforms so that enough of __uint128_t
would need implementing for the library to work.
I haven't spent enough time understanding the compiler warnings to have a strong view on the cleanest way to avoid them.
from ctbignum.
With respect to 128-bit arithmetic, the following seems to be useful, i.e., an 128-bit multiply intrinsic for MS Visual C++:
https://docs.microsoft.com/en-gb/cpp/intrinsics/mul128?view=vs-2017
However, double-word (128bit) addition is also needed, because of line 53 in the mul
function:
TT t = static_cast<TT>(u[i]) * static_cast<TT>(v[j]) + w[i + j] + k;
what is used here, is that if you multiply two unsigned operands A and B that can maximally be 2^{64}-1, then there is room left for adding two extra unsigned operands C and D to the result, where C and D can also maximally be 2^{64}-1.
Maybe there is also an intrinsic for that (or we can simply use the addition function defined in add.hpp for this purpose)
from ctbignum.
Hi Keith @bitlush ,
Any luck so far getting the code to run on MSVC?
best,
Niek
from ctbignum.
Related Issues (20)
- Untested branch in addition.hpp HOT 1
- rename all.hpp to ctbignum.hpp
- dedicated type for big_int
- Add documentation
- Remove NTL dependency in unittest HOT 1
- Add text on how to refer / refer to publication HOT 1
- add AUTHORS file HOT 1
- Inline attribute should be configurable HOT 1
- io.hpp should only include <ostream> instead of <iostream> HOT 1
- Add begin() and end() to big_int
- Additional Benchmark comparison HOT 1
- implement natural syntax for integer_sequences
- implement optimized reduction for mersenne / NIST-like primes
- implement separation between fixed-size and expanding integers
- Wrong value for mod_inv HOT 1
- Montgomery arithmetic doesn't seem to be constant-time HOT 2
- Compiling on Fedora 36: <stdexcept> needed HOT 1
- SIGSTKSZ changed to be a syscall HOT 1
- bigint? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ctbignum.