]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/config/test/boost_has_int128.ipp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / config / test / boost_has_int128.ipp
CommitLineData
7c673cae 1// (C) Copyright John Maddock 2012.
b32b8144 2// (C) Copyright Dynatrace 2017.
7c673cae
FG
3// Use, modification and distribution are subject to the
4// Boost Software License, Version 1.0. (See accompanying file
5// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6
7// See http://www.boost.org/libs/config for most recent version.
8
9// MACRO: BOOST_HAS_INT128
10// TITLE: __int128
11// DESCRIPTION: The platform supports __int128.
12
13#include <cstdlib>
b32b8144
FG
14#include <stdio.h>
15#include <limits.h>
7c673cae
FG
16
17namespace boost_has_int128{
18
7c673cae 19#ifdef __GNUC__
b32b8144
FG
20__extension__ typedef __int128 my_int128_t;
21__extension__ typedef unsigned __int128 my_uint128_t;
7c673cae 22#else
b32b8144
FG
23typedef __int128 my_int128_t;
24typedef unsigned __int128 my_uint128_t;
7c673cae 25#endif
b32b8144
FG
26
27my_uint128_t volatile g_ui128 = 0;
28unsigned long volatile g_ul = 0;
29
30int test()
31{
32 my_int128_t si128 = 0;
33 (void)&si128;
34
35 // 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...
36 // #1: check __int128 size
37 if (sizeof(my_uint128_t) < (128 / CHAR_BIT))
38 {
39 fputs("Type too small.", stderr);
40 return 1;
41 }
42
43 // #2: check result of computation with __int128
44 my_uint128_t p1 = 1;
45 my_uint128_t p2 = 1;
46 unsigned int i = 0;
47 for (; i < 180; i++)
48 {
49 g_ui128 = p1 + p2;
50 if (g_ui128 < p1)
51 {
52 fputs("Unexpected overflow.", stderr);
53 return 1;
54 }
55 p2 = p1;
56 p1 = g_ui128;
57 }
58
59 g_ul = static_cast<unsigned long>((g_ui128 >> 92) & 0xFFFFFFFFUL);
60 g_ul -= 1216382273UL;
61 if (g_ul != 0)
62 {
63 fputs("Incorrect computation result.", stderr);
64 return 1;
65 }
66
7c673cae
FG
67 return 0;
68}
69
70}
71
72
73
74
75