Skip to content
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

Support __int128_t, __uint128_t types #82

Closed
kimwalisch opened this issue Nov 19, 2017 · 8 comments
Closed

Support __int128_t, __uint128_t types #82

kimwalisch opened this issue Nov 19, 2017 · 8 comments

Comments

@kimwalisch
Copy link

kimwalisch commented Nov 19, 2017

Hi,

The __int128_t and __uint128_t types are non standard C/C++ extensions supported by Clang and GCC (and I guess by the Intel Linux compiler as well). Currently they seem to be not supported:

$ make

src/P2.cpp: In function ‘primesum::maxint_t {anonymous}::P2_OpenMP_master(primesum::int128_t, int64_t, int)’:
src/P2.cpp:150:24: error: conversion from ‘__int128’ to non-scalar type ‘primesum::maxint_t {aka mppp::integer<4ul>}’ requested
   maxint_t prime_sum = n128

Boost multiprecision supports the __int128_t and __uint128_t types, I was hoping to be able to use mp++ instead of Boost multiprecision in my primesum program and get a performance benefit.

@bluescarni
Copy link
Owner

What type of interfacing do you need from mp++? Is it enough to be able to construct/convert mp++ integers from/to __(u)int128_t or would you need also overloaded operators?

@kimwalisch
Copy link
Author

Yes, I would also need overloaded operators. My primsum program currently mixes __(u)int128_t with Boost's int256_t type using the standard integer arithmetic operators +, - , *, /. If you would support overloaded operators I could use your mp++ as a drop in replacement for the Boost multiprecision library.

Here is a C++ code snippet used in my program:

while ((prime = iter.next_prime()) < stop)
{
    int64_t xn = (int64_t) max(x / (prime * prime), prime);
    maxint_t diff = prime_sums[pi[y]] - prime_sums[pi[xn]];
    s2_trivial += prime * diff;
}

maxint_t is a typedef for the boost multiprecision int256_t type. Hence I need to be able to assign an ___int128_t value to an mppp::integer<4> type which I would use instead of int256_t. And e.g. for the expression s2_trivial += prime * diff; I would need overloaded operators.

I don't know how much work it is for your to support the overloaded operators but it would definitely be very usefull to me,

@bluescarni
Copy link
Owner

I think supporting the 128 bit integers is definitely worthwhile, so consider it on the roadmap now :)

As a word of caution, I haven't really looked into optimizing performance for integers with more than 2 static limbs. For > 2 limbs, I am just using the mpn_ primitives from GMP, but I have not done any performance measurement/tuning yet. That is another chunk of work that is already on the todo list.

@kimwalisch
Copy link
Author

For your information:

__int128_t and __int128_t are only supported on 64-bit architectures by GCC and Clang. Hence they are e.g. supported on x86_64, PPC64, ARM64 but not on i386, ARM and so on.

One possible way to support this in your library would be using:

#if defined(__SIZEOF_INT128__)

#endif

This works using both GCC and Clang.

@bluescarni
Copy link
Owner

Indeed! I am using 128bit integers already in the optimised 2-limbs implementations of basic arithmetic, and using that very same definition to check for availability:

https://github.com/bluescarni/mppp/blob/master/include/mp%2B%2B/integer.hpp#L82

I'll ping you here as soon as I make progress.

@bluescarni
Copy link
Owner

@kimwalisch This may be a bit OT, but do you need modular arithmetic behaviour on integer operations?

@kimwalisch
Copy link
Author

No, I don't need that.

@bluescarni
Copy link
Owner

This has been implemented in #90, just merged to master.

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

No branches or pull requests

2 participants