2012-12-10 17:26:30 +00:00
// (C) Copyright John Maddock 2012.
2017-02-26 18:59:19 +00:00
// (C) Copyright Dynatrace 2017.
2012-12-10 17:26:30 +00:00
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org/libs/config for most recent version.
// MACRO: BOOST_HAS_INT128
// TITLE: __int128
// DESCRIPTION: The platform supports __int128.
#include <cstdlib>
2017-02-26 18:59:19 +00:00
#include <stdio.h>
#include <limits.h>
2012-12-10 17:26:30 +00:00
namespace boost_has_int128 {
2017-02-26 18:59:19 +00:00
#ifdef __GNUC__
__extension__ typedef __int128 my_int128_t ;
__extension__ typedef unsigned __int128 my_uint128_t ;
#else
typedef __int128 my_int128_t ;
typedef unsigned __int128 my_uint128_t ;
#endif
my_uint128_t volatile g_ui128 = 0 ;
unsigned long volatile g_ul = 0 ;
2012-12-10 17:26:30 +00:00
int test ()
{
2017-02-26 18:59:19 +00:00
my_int128_t si128 = 0 ;
( void ) & si128 ;
// Some compilers have seriously broken __int128 implementations, so we need to do a little more than simply check if we can declare variables with __int128...
// #1: check __int128 size
if ( sizeof ( my_uint128_t ) < ( 128 / CHAR_BIT ))
{
fputs ( "Type too small." , stderr );
return 1 ;
}
// #2: check result of computation with __int128
my_uint128_t p1 = 1 ;
my_uint128_t p2 = 1 ;
unsigned int i = 0 ;
for (; i < 180 ; i ++ )
{
g_ui128 = p1 + p2 ;
if ( g_ui128 < p1 )
{
fputs ( "Unexpected overflow." , stderr );
return 1 ;
}
p2 = p1 ;
p1 = g_ui128 ;
}
g_ul = static_cast < unsigned long > (( g_ui128 >> 92 ) & 0xFFFFFFFFUL );
g_ul -= 1216382273UL ;
if ( g_ul != 0 )
{
fputs ( "Incorrect computation result." , stderr );
return 1 ;
}
2020-04-11 12:41:56 -04:00
2020-04-12 06:30:42 -04:00
my_uint128_t ii ( 2 ), jj ( 1 ), kk ;
kk = ii / jj ;
2017-02-26 18:59:19 +00:00
2012-12-10 17:26:30 +00:00
return 0 ;
}
}