Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

128-bit integers supporting +, -, *, /, and % in the Intel C Compiler?

Tags:

c

icc

int128

GCC and Clang have the __int128_t and __uint128_t extensions for 128-bit integer arithmetic.

I was hopeful that __m128i would give something similar for the Intel C Compiler, but (if it's even possible) it looks to me like I'd have to write explicit SSE2 function calls in order to use __m128i, instead of using "built-in" operators like +, -, *, /, and %. I was hoping to do something like this (this doesn't work):

#if defined(__INTEL_COMPILER) && defined(__SSE2__)
  #include "xmmintrin.h"
  typedef __u128 uint128_t;
#elif defined (__GNUC__)
  typedef __uint128_t uint128_t;
#else
  #error For 128-bit arithmetic we need GCC or ICC, or uint128_t
#endif

Is there 128-bit integer support with the operators +, -, *, /, and % somewhere buried in icc?

like image 283
Douglas B. Staple Avatar asked May 03 '13 19:05

Douglas B. Staple


People also ask

Does C support 128-bit integers?

In the same way that compilers emulate e.g. 64-bit integer arithmetic on architectures with register sizes less than 64 bits, some compilers also support 128-bit integer arithmetic. For example, the GCC C compiler 4.6 and later has a 128-bit integer type __int128 for some architectures.

What is the 128-bit integer limit?

The 128-bit data type can handle up to 31 significant digits (compared to 17 handled by the 64-bit long double). However, while this data type can store numbers with more precision than the 64-bit data type, it does not store numbers of greater magnitude.

How do you write a 128-bit integer?

DrinkMoreBoilingWater's blog. As an extension the integer scalar type __int128 is supported for targets which have an integer mode wide enough to hold 128 bits. Simply write __int128 for a signed 128-bit integer, or unsigned __int128 for an unsigned 128-bit integer.

What is __ int128 in C++?

The int128 type defines a signed 128-bit integer. The API is meant to mimic an intrinsic integer type as closely as possible, so that any forthcoming int128_t can be a drop-in replacement. The int128 type supports the following: Implicit conversion from signed integral types and unsigned types narrower than 128 bits.


1 Answers

From what I can tell, at least icc 13.0.1+ support __int128_t and __uint128_t. Courtesy of Matt Godbolt's Compiler Explorer:

__int128_t ai (__int128_t x, __int128_t y) {
  return x + y;
}

__int128_t mi (__int128_t x, __int128_t y) {
  return x * y;
}

__int128_t di (__int128_t x, __int128_t y) {
  return x / y;
}

__int128_t ri (__int128_t x, __int128_t y) {
  return x % y;
}

compiles to:

L__routine_start_ai_0:
ai:
        add       rdi, rdx                                      #2.14
        mov       rax, rdi                                      #2.14
        adc       rsi, rcx                                      #2.14
        mov       rdx, rsi                                      #2.14
        ret                                                     #2.14
L__routine_start_mi_1:
mi:
        mov       rax, rdi                                      #6.14
        imul      rsi, rdx                                      #6.14
        imul      rcx, rdi                                      #6.14
        mul       rdx                                           #6.14
        add       rsi, rcx                                      #6.14
        add       rdx, rsi                                      #6.14
        ret                                                     #6.14
L__routine_start_di_2:
di:
        push      rsi                                           #9.44
        call      __divti3                                      #10.14
        pop       rcx                                           #10.14
        ret                                                     #10.14
L__routine_start_ri_3:
ri:
        push      rsi                                           #13.44
        call      __modti3                                      #14.14
        pop       rcx                                           #14.14
        ret                                                     #14.14

with icc 13.0.1 (http://goo.gl/UnxEFt).

like image 157
haneefmubarak Avatar answered Sep 22 '22 11:09

haneefmubarak