]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/json/test/ryu/d2s_table_test.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / json / test / ryu / d2s_table_test.cpp
1 // Copyright 2018 Ulf Adams
2 //
3 // The contents of this file may be used under the terms of the Apache License,
4 // Version 2.0.
5 //
6 // (See accompanying file LICENSE-Apache or copy at
7 // http://www.apache.org/licenses/LICENSE-2.0)
8 //
9 // Alternatively, the contents of this file may be used under the terms of
10 // the Boost Software License, Version 1.0.
11 // (See accompanying file LICENSE-Boost or copy at
12 // https://www.boost.org/LICENSE_1_0.txt)
13 //
14 // Unless required by applicable law or agreed to in writing, this software
15 // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 // KIND, either express or implied.
17
18 /*
19 This is a derivative work
20 */
21
22 #if defined(__SIZEOF_INT128__) && !defined(_MSC_VER) && !defined(RYU_ONLY_64_BIT_OPS)
23 #define BOOST_JSON_RYU_HAS_UINT128
24 #elif defined(_MSC_VER) && !defined(RYU_ONLY_64_BIT_OPS) && defined(_M_X64) \
25 && !defined(__clang__) // https://bugs.llvm.org/show_bug.cgi?id=37755
26 #define BOOST_JSON_RYU_HAS_64_BIT_INTRINSICS
27 #endif
28
29 // We want to test the size-optimized case here.
30 #if !defined(BOOST_JSON_RYU_OPTIMIZE_SIZE)
31 #define BOOST_JSON_RYU_OPTIMIZE_SIZE
32 #endif
33 #include <boost/json/detail/ryu/detail/d2s.hpp>
34 #include <boost/json/detail/ryu/detail/d2s_full_table.hpp>
35 #include <array>
36 #include <cstdint>
37 #include <cmath>
38 #include "gtest.hpp"
39
40 BOOST_JSON_NS_BEGIN
41 namespace detail {
42
43 namespace ryu {
44 namespace detail {
45
46 TEST(D2sTableTest, double_computePow5) {
47 for (int i = 0; i < 326; i++) {
48 uint64_t m[2];
49 double_computePow5(i, m);
50 ASSERT_EQ(m[0], DOUBLE_POW5_SPLIT()[i][0]);
51 ASSERT_EQ(m[1], DOUBLE_POW5_SPLIT()[i][1]);
52 }
53 }
54
55 TEST(D2sTableTest, compute_offsets_for_double_computePow5) {
56 uint32_t totalErrors = 0;
57 uint32_t offsets[13] = {0};
58 for (int i = 0; i < 326; i++) {
59 uint64_t m[2];
60 double_computePow5(i, m);
61 if (m[0] != DOUBLE_POW5_SPLIT()[i][0]) {
62 offsets[i / POW5_TABLE_SIZE] |= 1 << (i % POW5_TABLE_SIZE);
63 totalErrors++;
64 }
65 }
66 if (totalErrors != 0) {
67 for (int i = 0; i < 13; i++) {
68 printf("0x%08x,\n", offsets[i]);
69 }
70 }
71 ASSERT_EQ(totalErrors, 0);
72 }
73
74 TEST(D2sTableTest, double_computeInvPow5) {
75 for (int i = 0; i < 292; i++) {
76 uint64_t m[2];
77 double_computeInvPow5(i, m);
78 ASSERT_EQ(m[0], DOUBLE_POW5_INV_SPLIT()[i][0]);
79 ASSERT_EQ(m[1], DOUBLE_POW5_INV_SPLIT()[i][1]);
80 }
81 }
82
83 TEST(D2sTableTest, compute_offsets_for_double_computeInvPow5) {
84 uint32_t totalErrors = 0;
85 uint32_t offsets[20] = {0};
86 for (int i = 0; i < 292; i++) {
87 uint64_t m[2];
88 double_computeInvPow5(i, m);
89 if (m[0] != DOUBLE_POW5_INV_SPLIT()[i][0]) {
90 offsets[i / 16] |= ((DOUBLE_POW5_INV_SPLIT()[i][0] - m[0]) & 3) << ((i % 16) << 1);
91 totalErrors++;
92 }
93 }
94 if (totalErrors != 0) {
95 for (int i = 0; i < 20; i++) {
96 printf("0x%08x,\n", offsets[i]);
97 }
98 }
99 ASSERT_EQ(totalErrors, 0);
100 }
101
102 } // detail
103 } // ryu
104
105 } // detail
106 BOOST_JSON_NS_END