int128 on Linux for Intel compiler

int128 on Linux for Intel compiler

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)

 

 

30 posts / novo 0
Último post
Para obter mais informações sobre otimizações de compiladores, consulte Aviso sobre otimizações.

>>... 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.

>>...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)

CRT function: what does it mean?

CRT function: what does it mean?

Attached

Anexos: 

AnexoTamanho
Download c0x-warning.h1.41 KB

Attached

Anexos: 

AnexoTamanho
Download stdint.h8.34 KB
Download stdint-h-trl.h1.19 KB

Attached

Anexos: 

>>...CRT function: what does it mean?

C Run-Time. All functions, like printf, fprintf, etc, are called CRT functions.

Define __GXX_EXPERIMENTAL_CXX0X__ macro at the beginning of your sources.

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

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

 

Thanks

 

 

>>...Could you attach ... cstdint header files?

I'd like to see how the type __uint128_t is declared in cstdint header file.

__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

 

Anexos: 

AnexoTamanho
Download log.txt23.06 KB

// <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

 

>>...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.

Thanks.

But problem is not only with print.

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

 

 

>>...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.

#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

>>>>...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 ).

I need it in a real application.

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

>>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.

> Did you miss *t* in *__uint128_*?

Of course. Thanks

stdint.h attached

 

 

 

Anexos: 

AnexoTamanho
Download stdint.h8.34 KB

Intel(R) C++ Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 13.0.1.117 Build 20121010 Copyright (C) 1985-2012 Intel Corporation.  All rights reserved.

 

Just for reference. Please take a look at:

software.intel.com/en-us/articles/c0x-features-supported-by-intel-c-compiler

int128_t doesn't appear in that copy of stdint.h nor in any I can find among my installations of gcc 4.4 or 4.8.  I thought when I saw such things in the past it was treated as a case of __m128i.  If it's done internal to gcc and not expressed in a header file, icc can't share it with gcc.

If gcc defines the usual arithmetic operations on such data types, it would appear to require support in libgcc. In a default build of libgcc, the only 128-bit data types are bid128.

http://gcc.gnu.org/onlinedocs/gcc/_005f_005fint128.html states that int128 support requires a matching long long int data type.

>>... I thought when I saw such things in the past it was treated as a case of __m128i...

It is declared as follows:
...
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];
unsigned __int8 m128i_u8[16];
unsigned __int16 m128i_u16[8];
unsigned __int32 m128i_u32[4];
unsigned __int64 m128i_u64[2];
} __m128i;
...
and if this is the case __uint128_t needs to be considered as unsigned __int64 m128i_u64[2].

I'm still investigating...

Attached are four stdint.h headers and I have Not found a declaration for the type __uint128_t. Does it mean that the type is built-in?

Anexos: 

imagem de jimdempseyatthecove

The __m128i is a container class for use with SSE (AVX). This container class partitions the 128-bit register (and memory storage thereof) into the working uints supported by the small vector instructions. Currently this does not include (unsigned/signed) integer classes of 128-bits for arithmatic operations. Logical operations can be performed as they do not produce a carry or borrow across bit fields.

At some future date AVX may be extended to support 128-bit integers and hopefully 128-bit floating point formats. At this time this is hopeful thinking.

There are extended precision as well as arbitrary precision libraries that are available.

Jim Dempsey

www.quickthreadprogramming.com

>>...and hopefully 128-bit floating point formats...

That would be helpful!

>>... I have Not found a declaration for the type __uint128_t. Does it mean that the type is built-in?

Here are two questions:

1. Is the type __uint128_t is built-in type supported by the most recent version of a C++ compiler ( Intel or GCC )?

2. If it is Not built-in type where is it declared and how ( I expect a typedef... )?

Here is a compilation output for a test case compiled with a recent version of Intel C++ compiler for Windows ( 13.x ):
...
__uint128_t uiValue = 0;
...

...
.\GenTestApp.cpp(31): error: identifier "__uint128_t" is undefined
__uint128_t uiValue = 0;
...

Faça login para deixar um comentário.