Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
Announcements
The Intel sign-in experience has changed to support enhanced security controls. If you sign in, click here for more information.

int128 on Linux for Intel compiler

alexvi
Beginner
2,545 Views

Linux 2.6.32

Intel compiler: icpc version 13.0.1 (gcc version 4.4.6 compatibility)

#include <iostream> #include <sys/types.h> int main() {     std::cerr << sizeof (__uint128_t) << std::endl;         return 0; } Output: 16

So, type __uint128_t exists.  However, working with __uint128_t produces compilation and run errors.

 

Programs:

------------------ File int01.cpp #include <cstdint> int main() {  uint128_t val128 = 0;  return 0; }

------------------ File int02.cpp #include <cstdint> int main() {  __uint128_t val128 = 0;  return 0; }

------------------ File int03.cpp #include <iostream> #include <cstdint> int main() {  __uint128_t val128 = 0;  std::cerr << val128 << std::endl;  return 0; }

Compilations:

> icpc int01.cpp /usr/include/c++/4.4.6/c++0x_warning.h(31): catastrophic error: #error directive: This file requires compiler and library support for the upcoming ISO C++ standard, C++0x. This support is currently experimental, and must be enabled with the -std=c++0x or -std=gnu++0x compiler options.   #error This file requires compiler and library support for the upcoming \    ^

compilation aborted for int01.cpp (code 4)

> icpc int01.cpp -std=c++0x int01.cpp(4): error: identifier "uint128_t" is undefined    uint128_t val128 = 0;    ^

compilation aborted for int01.cpp (code 2)

> icpc int02.cpp -std=c++0x // No errors

> icpc int03.cpp -std=c++0x

int03.cpp(6): error: more than one operator "<<" matches these operands:             function "std::basic_ostream<_CharT, _Traits>::operator<<(long) [with _CharT=char, _Traits=std::char_traits<char>]"             function "std::basic_ostream<_CharT, _Traits>::operator<<(unsigned long) [with _CharT=char, _Traits=std::char_traits<char>]"             function "std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT=char, _Traits=std::char_traits<char>]"             function "std::basic_ostream<_CharT, _Traits>::operator<<(short) [with _CharT=char, _Traits=std::char_traits<char>]"             function "std::basic_ostream<_CharT, _Traits>::operator<<(unsigned short) [with _CharT=char, _Traits=std::char_traits<char>]"             function "std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT=char, _Traits=std::char_traits<char>]"             function "std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT=char, _Traits=std::char_traits<char>]"             function "std::basic_ostream<_CharT, _Traits>::operator<<(long long) [with _CharT=char, _Traits=std::char_traits<char>]"             function "std::basic_ostream<_CharT, _Traits>::operator<<(unsigned long long) [with _CharT=char, _Traits=std::char_traits<char>]"             function "std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT=char, _Traits=std::char_traits<char>]"             function "std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT=char, _Traits=std::char_traits<char>]"             function "std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT=char, _Traits=std::char_traits<char>]"             operand types are: std::ostream << __uint128_t    std::cerr << val128 << std::endl;              ^

compilation aborted for int03.cpp (code 2)

 

 

0 Kudos
29 Replies
SergeyKostrov
Valued Contributor II
2,107 Views
>>... icpc int01.cpp /usr/include/c++/4.4.6/c++0x_warning.h(31): catastrophic error: #error directive: This file requires... Could you attach c++0x_warning.h(31) and cstdint header files? >>...int01.cpp(4): error: identifier "uint128_t" is undefined uint128_t val128 = 0;... There are no underscores for uint128_t in that case.
SergeyKostrov
Valued Contributor II
2,107 Views
>>...File int03.cpp #include #include int main() { __uint128_t val128 = 0; std::cerr << val128... I see that there are No C++ operator << for the type __uint128_t and this is why the last test failed and try to use printf CRT function instead. The following types could be used with C++ operator <<: ::operator << (long) ::operator << (unsigned long) ::operator << (bool) ::operator << (short) ::operator << (unsigned short) ::operator << (int) ::operator << (unsigned int) ::operator << (long long) ::operator << (unsigned long long) ::operator << (double) ::operator << (float) ::operator << (long double)
alexvi
Beginner
2,107 Views

CRT function: what does it mean?

alexvi
Beginner
2,107 Views

CRT function: what does it mean?

alexvi
Beginner
2,107 Views

Attached

alexvi
Beginner
2,107 Views

Attached

alexvi
Beginner
2,107 Views

Attached

SergeyKostrov
Valued Contributor II
2,107 Views
>>...CRT function: what does it mean? C Run-Time. All functions, like printf, fprintf, etc, are called CRT functions.
SergeyKostrov
Valued Contributor II
2,107 Views
Define __GXX_EXPERIMENTAL_CXX0X__ macro at the beginning of your sources.
alexvi
Beginner
2,107 Views

printf (..., "%llx", ) doesn't work for uint128.

Could you send  a small program with uint128 that prints uint128-value?

 

Thanks

 

 

SergeyKostrov
Valued Contributor II
2,107 Views
>>...Could you attach ... cstdint header files? I'd like to see how the type __uint128_t is declared in cstdint header file.
alexvi
Beginner
2,107 Views

__GXX_EXPERIMENTAL_CXX0X__ #include <iostream> #include <cstdint> int main() {  __uint128_t val128 = 0;  std::cerr << val128 << std::endl;  return 0; }

> icpc int03.cpp

 

Log attached

 

alexvi
Beginner
2,107 Views

// <cstdint> -*- C++ -*-

// Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library.  This library is free // software; you can redistribute it and/or modify it under the // terms of the GNU General Public License as published by the // Free Software Foundation; either version 3, or (at your option) // any later version.

// This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the // GNU General Public License for more details.

// Under Section 7 of GPL version 3, you are granted additional // permissions described in the GCC Runtime Library Exception, version // 3.1, as published by the Free Software Foundation.

// You should have received a copy of the GNU General Public License and // a copy of the GCC Runtime Library Exception along with this program; // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see // <http://www.gnu.org/licenses/>.

/** @file include/cstdint  *  This is a Standard C++ Library header.  */

#ifndef _GLIBCXX_CSTDINT #define _GLIBCXX_CSTDINT 1

#pragma GCC system_header

#ifndef __GXX_EXPERIMENTAL_CXX0X__ # include <c++0x_warning.h> #endif

#if defined(_GLIBCXX_INCLUDE_AS_TR1) #  error C++0x header cannot be included from TR1 header #endif

#include <bits/c++config.h>

// For 8.22.1/1 (see C99, Notes 219, 220, 222) #if _GLIBCXX_HAVE_STDINT_H # ifndef __STDC_LIMIT_MACROS #  define _UNDEF__STDC_LIMIT_MACROS #  define __STDC_LIMIT_MACROS # endif # ifndef __STDC_CONSTANT_MACROS #  define _UNDEF__STDC_CONSTANT_MACROS #  define __STDC_CONSTANT_MACROS # endif # include <stdint.h> # ifdef _UNDEF__STDC_LIMIT_MACROS #  undef __STDC_LIMIT_MACROS #  undef _UNDEF__STDC_LIMIT_MACROS # endif # ifdef _UNDEF__STDC_CONSTANT_MACROS #  undef __STDC_CONSTANT_MACROS #  undef _UNDEF__STDC_CONSTANT_MACROS # endif #endif

#if defined(_GLIBCXX_INCLUDE_AS_CXX0X) #  include <tr1_impl/cstdint> #else #  define _GLIBCXX_INCLUDE_AS_CXX0X #  define _GLIBCXX_BEGIN_NAMESPACE_TR1 #  define _GLIBCXX_END_NAMESPACE_TR1 #  define _GLIBCXX_TR1 #  include <tr1_impl/cstdint> #  undef _GLIBCXX_TR1 #  undef _GLIBCXX_END_NAMESPACE_TR1 #  undef _GLIBCXX_BEGIN_NAMESPACE_TR1 #  undef _GLIBCXX_INCLUDE_AS_CXX0X #endif

#endif // _GLIBCXX_CSTDINT

 

SergeyKostrov
Valued Contributor II
2,107 Views
>>...File int02.cpp #include int main() { __uint128_t val128 = 0; return 0; } #include int main() { __uint128_t val128 = 12345678901234567890ULL; return 0; } For the second test use modulus val128 % 10 to print all the digits in the 128-bit number. You need to implement a simple for loop with 128 iterations with printf which prints every digit. Unfortunately, I don't see a builtin support for __uint128_t type in printf CRT-function.
alexvi
Beginner
2,107 Views

Thanks.

But problem is not only with print.

For instance, std::numeric_limits<__uint128_>::max() returns 0.

 

 

SergeyKostrov
Valued Contributor II
2,107 Views
>>...You need to implement a simple for loop with 128 iterations with printf which prints every digit.... Correction: The for loop should work until ( val128 % 10 ) is not equal to zero. >>...For instance, std::numeric_limits<__uint128_>::max() returns 0... It means, that support for that type is partially implemented.
alexvi
Beginner
2,107 Views

#include <iostream> #include <iomanip> #include <cstdint> int main() {  __uint128_t val128 = 0xeeee1234567812345678;  unsigned long val64l = static_cast<unsigned long>((val128 << 64) >> 64);  unsigned long val64m = static_cast<unsigned long>(val128 >> 64);  std::cerr << std::hex << val64l << std::dec << std::endl;  std::cerr << std::hex << val64m << std::dec << std::endl;  return 0; }

 

> icpc int03.cpp -std=c++0x

> ./a.out

560800000000  // Expected 1234567812345678

 eeee

SergeyKostrov
Valued Contributor II
2,107 Views
>>>>...For instance, std::numeric_limits<__uint128_>::max() returns 0... >> >>It means, that support for that type is partially implemented. Do you need this in a real application or just for tests? Take a look at how std::numeric_limits<__uint128_>::max() is implemented and add support. It will be your own patch / fix ( 3.4028236692093846346337460743177e+38 - 1 ).
alexvi
Beginner
2,107 Views

I need it in a real application.

But "partially supported" feature is worse than non-supported one. 

SergeyKostrov
Valued Contributor II
1,620 Views
>>For instance, std::numeric_limits[ __uint128_ ]::max() returns 0... Did you miss t in __uint128_? >>...# include "stdint.h"... Could you attach stdint.h header file? Sorry, but I still don't see how __uint128_t is declared. In Intel C++ compiler v12.x there is no support for that type ( just verified ). I'll take a look at v13.x and let you know.
Reply