Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Douglas_S_1
Beginner
1,099 Views

128-bit Integer Arithmetic

As a non-standard extension, both GCC and Clang provide __uint128_t and __int128_t for emulated 128-bit integer arithmetic in C. The basic arithmetic operations +, -, *, /, %, as well as bitwise operations work on these datatypes in the same fashion as normal integers, and performance is quite good. I'm wondering (1) if there are any equivalent datatypes supported by ICC and (2) if there are plans to include anything similar in ICC.

I also posted this question on Stack Overflow: http://stackoverflow.com/questions/16365840/128-bit-integers-supporting-and-in-the-intel-c-compiler

0 Kudos
6 Replies
jimdempseyatthecove
Black Belt
1,099 Views

http://homepages.ihug.co.nz/~aurora76/Malc/Useful_Classes.htm

See bigint.h link on above page.

Jim Dempsey

Douglas_S_1
Beginner
1,099 Views

Yes, it's true that there are libraries to do high-precision arithmetic and some of these are efficient for "smaller" widths like 128-bits. That class you linked to might be a candidate if I were using C++ instead of C. Does it overload the built-in operators like +, -, *, /, and %? I get the impression that this int128 class does just that (again, C++ only): http://mx-3.cz/tringi/www/int128

Unfortunately C doesn't have overloading so no such library exists for C.

SKost
Valued Contributor II
1,099 Views

This is a 4-year-old discussion and I'd like to reiterate interest in that subject since I just hit limitations of 64-bit integer arithmetic. I wonder if latest versions of Intel C++ compilers ( v16.x and 17.x ) have a built-in ( native ) support of 128-bit integer arithmetic? Unfortunately, a solution to use a 3rd-party library can't be considered in my case.
SKost
Valued Contributor II
1,099 Views

>>...Unfortunately, a solution to use a 3rd-party library can't be considered in my case. Due to performance impact on some processing In overall, more than 2^64 cases need to be verified. A KNL Server with 64-cores and 256 threads works for many hours just to process all 2^63 cases of some processing.
SKost
Valued Contributor II
1,099 Views

>>...limitations of 64-bit integer arithmetic... Here is why: 1. Maximum signed 64-bit integer number I could process is 9223372036854775807 ( = 2^63 - 1 = 9223372036854775808 - 1 ). 2. Even if I change declarations of variables to unsigned 64-bit integer nothing could be done after 2^64 - 1 ( 18446744073709551615 = 18446744073709551616 - 1 ) limit is reached. 3. Because 18446744073709551615U + 1U = 0 ( check it by yourself... ).
SKost
Valued Contributor II
1,099 Views

I also would like to address that message to Intel Processing Units designers and engineers. I think: - 128-bit native arithmetic had to be introduced when 128-bit SSE/SSE2 was introduced - 256-bit native arithmetic had to be introduced when 256-bit AVX was introduced - 512-bit native arithmetic had to be introduced when 512-bit AVX2 was introduced For example, a fundamental union of SSE2 Instruction Set Architecture __m128i should look like: [ emmintrin.h ] ... typedef union __declspec(intrin_type) _CRT_ALIGN(16) __m128i { __int8 m128i_i8[16]; __int16 m128i_i16[8]; __int32 m128i_i32[4]; __int64 m128i_i64[2]; __int128 m128i_i128[1]; unsigned __int8 m128i_u8[16]; unsigned __int16 m128i_u16[8]; unsigned __int32 m128i_u32[4]; unsigned __int64 m128i_u64[2]; unsigned __int128 m128i_u128[1]; } __m128i; ...