]> git.proxmox.com Git - ceph.git/blob - 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
1 // (C) Copyright John Maddock 2012.
2 // (C) Copyright Dynatrace 2017.
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>
14 #include <stdio.h>
15 #include <limits.h>
16
17 namespace boost_has_int128{
18
19 #ifdef __GNUC__
20 __extension__ typedef __int128 my_int128_t;
21 __extension__ typedef unsigned __int128 my_uint128_t;
22 #else
23 typedef __int128 my_int128_t;
24 typedef unsigned __int128 my_uint128_t;
25 #endif
26
27 my_uint128_t volatile g_ui128 = 0;
28 unsigned long volatile g_ul = 0;
29
30 int 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
67 return 0;
68 }
69
70 }
71
72
73
74
75