]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/json/test/ryu/d2s_table_test.cpp
import quincy beta 17.1.0
[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 <cstdint>
36 #include <cmath>
37 #include "gtest.hpp"
38
39 BOOST_JSON_NS_BEGIN
40 namespace detail {
41
42 namespace ryu {
43 namespace detail {
44
45 TEST(D2sTableTest, double_computePow5) {
46 for (int i = 0; i < 326; i++) {
47 uint64_t m[2];
48 double_computePow5(i, m);
49 ASSERT_EQ(m[0], DOUBLE_POW5_SPLIT()[i][0]);
50 ASSERT_EQ(m[1], DOUBLE_POW5_SPLIT()[i][1]);
51 }
52 }
53
54 TEST(D2sTableTest, compute_offsets_for_double_computePow5) {
55 uint32_t totalErrors = 0;
56 uint32_t offsets[13] = {0};
57 for (int i = 0; i < 326; i++) {
58 uint64_t m[2];
59 double_computePow5(i, m);
60 if (m[0] != DOUBLE_POW5_SPLIT()[i][0]) {
61 offsets[i / POW5_TABLE_SIZE] |= 1 << (i % POW5_TABLE_SIZE);
62 totalErrors++;
63 }
64 }
65 if (totalErrors != 0) {
66 for (int i = 0; i < 13; i++) {
67 printf("0x%08x,\n", offsets[i]);
68 }
69 }
70 ASSERT_EQ(totalErrors, 0);
71 }
72
73 TEST(D2sTableTest, double_computeInvPow5) {
74 for (int i = 0; i < 292; i++) {
75 uint64_t m[2];
76 double_computeInvPow5(i, m);
77 ASSERT_EQ(m[0], DOUBLE_POW5_INV_SPLIT()[i][0]);
78 ASSERT_EQ(m[1], DOUBLE_POW5_INV_SPLIT()[i][1]);
79 }
80 }
81
82 TEST(D2sTableTest, compute_offsets_for_double_computeInvPow5) {
83 uint32_t totalErrors = 0;
84 uint32_t offsets[20] = {0};
85 for (int i = 0; i < 292; i++) {
86 uint64_t m[2];
87 double_computeInvPow5(i, m);
88 if (m[0] != DOUBLE_POW5_INV_SPLIT()[i][0]) {
89 offsets[i / 16] |= ((DOUBLE_POW5_INV_SPLIT()[i][0] - m[0]) & 3) << ((i % 16) << 1);
90 totalErrors++;
91 }
92 }
93 if (totalErrors != 0) {
94 for (int i = 0; i < 20; i++) {
95 printf("0x%08x,\n", offsets[i]);
96 }
97 }
98 ASSERT_EQ(totalErrors, 0);
99 }
100
101 } // detail
102 } // ryu
103
104 } // detail
105 BOOST_JSON_NS_END