1 // -*- C++ -*- 2 //===----------------------------------------------------------------------===// 3 // 4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5 // See https://llvm.org/LICENSE.txt for license information. 6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef _LIBCPP___CHARCONV_TABLES 11 #define _LIBCPP___CHARCONV_TABLES 12 13 #include <__config> 14 #include <cstdint> 15 16 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 17 # pragma GCC system_header 18 #endif 19 20 _LIBCPP_BEGIN_NAMESPACE_STD 21 22 #ifndef _LIBCPP_CXX03_LANG 23 24 namespace __itoa { 25 26 /// Contains the charconv helper tables. 27 /// 28 /// In C++17 these could be inline constexpr variable, but libc++ supports 29 /// charconv for integrals in C++11 mode. 30 template <class = void> 31 struct __table { 32 static const char __base_2_lut[64]; 33 static const char __base_8_lut[128]; 34 static const char __base_16_lut[512]; 35 36 static const uint32_t __pow10_32[10]; 37 static const uint64_t __pow10_64[20]; 38 # ifndef _LIBCPP_HAS_NO_INT128 39 // TODO FMT Reduce the number of entries in this table. 40 static const __uint128_t __pow10_128[40]; 41 static const int __pow10_128_offset = 0; 42 # endif 43 static const char __digits_base_10[200]; 44 }; 45 46 template <class _Tp> 47 const char __table<_Tp>::__base_2_lut[64] = { 48 '0', '0', '0', '0', '0', '0', '0', '1', '0', '0', '1', '0', '0', '0', '1', '1', '0', '1', '0', '0', '0', '1', 49 '0', '1', '0', '1', '1', '0', '0', '1', '1', '1', '1', '0', '0', '0', '1', '0', '0', '1', '1', '0', '1', '0', 50 '1', '0', '1', '1', '1', '1', '0', '0', '1', '1', '0', '1', '1', '1', '1', '0', '1', '1', '1', '1'}; 51 52 template <class _Tp> 53 const char __table<_Tp>::__base_8_lut[128] = { 54 '0', '0', '0', '1', '0', '2', '0', '3', '0', '4', '0', '5', '0', '6', '0', '7', '1', '0', '1', '1', '1', '2', 55 '1', '3', '1', '4', '1', '5', '1', '6', '1', '7', '2', '0', '2', '1', '2', '2', '2', '3', '2', '4', '2', '5', 56 '2', '6', '2', '7', '3', '0', '3', '1', '3', '2', '3', '3', '3', '4', '3', '5', '3', '6', '3', '7', '4', '0', 57 '4', '1', '4', '2', '4', '3', '4', '4', '4', '5', '4', '6', '4', '7', '5', '0', '5', '1', '5', '2', '5', '3', 58 '5', '4', '5', '5', '5', '6', '5', '7', '6', '0', '6', '1', '6', '2', '6', '3', '6', '4', '6', '5', '6', '6', 59 '6', '7', '7', '0', '7', '1', '7', '2', '7', '3', '7', '4', '7', '5', '7', '6', '7', '7'}; 60 61 template <class _Tp> 62 const char __table<_Tp>::__base_16_lut[512] = { 63 '0', '0', '0', '1', '0', '2', '0', '3', '0', '4', '0', '5', '0', '6', '0', '7', '0', '8', '0', '9', '0', 'a', '0', 64 'b', '0', 'c', '0', 'd', '0', 'e', '0', 'f', '1', '0', '1', '1', '1', '2', '1', '3', '1', '4', '1', '5', '1', '6', 65 '1', '7', '1', '8', '1', '9', '1', 'a', '1', 'b', '1', 'c', '1', 'd', '1', 'e', '1', 'f', '2', '0', '2', '1', '2', 66 '2', '2', '3', '2', '4', '2', '5', '2', '6', '2', '7', '2', '8', '2', '9', '2', 'a', '2', 'b', '2', 'c', '2', 'd', 67 '2', 'e', '2', 'f', '3', '0', '3', '1', '3', '2', '3', '3', '3', '4', '3', '5', '3', '6', '3', '7', '3', '8', '3', 68 '9', '3', 'a', '3', 'b', '3', 'c', '3', 'd', '3', 'e', '3', 'f', '4', '0', '4', '1', '4', '2', '4', '3', '4', '4', 69 '4', '5', '4', '6', '4', '7', '4', '8', '4', '9', '4', 'a', '4', 'b', '4', 'c', '4', 'd', '4', 'e', '4', 'f', '5', 70 '0', '5', '1', '5', '2', '5', '3', '5', '4', '5', '5', '5', '6', '5', '7', '5', '8', '5', '9', '5', 'a', '5', 'b', 71 '5', 'c', '5', 'd', '5', 'e', '5', 'f', '6', '0', '6', '1', '6', '2', '6', '3', '6', '4', '6', '5', '6', '6', '6', 72 '7', '6', '8', '6', '9', '6', 'a', '6', 'b', '6', 'c', '6', 'd', '6', 'e', '6', 'f', '7', '0', '7', '1', '7', '2', 73 '7', '3', '7', '4', '7', '5', '7', '6', '7', '7', '7', '8', '7', '9', '7', 'a', '7', 'b', '7', 'c', '7', 'd', '7', 74 'e', '7', 'f', '8', '0', '8', '1', '8', '2', '8', '3', '8', '4', '8', '5', '8', '6', '8', '7', '8', '8', '8', '9', 75 '8', 'a', '8', 'b', '8', 'c', '8', 'd', '8', 'e', '8', 'f', '9', '0', '9', '1', '9', '2', '9', '3', '9', '4', '9', 76 '5', '9', '6', '9', '7', '9', '8', '9', '9', '9', 'a', '9', 'b', '9', 'c', '9', 'd', '9', 'e', '9', 'f', 'a', '0', 77 'a', '1', 'a', '2', 'a', '3', 'a', '4', 'a', '5', 'a', '6', 'a', '7', 'a', '8', 'a', '9', 'a', 'a', 'a', 'b', 'a', 78 'c', 'a', 'd', 'a', 'e', 'a', 'f', 'b', '0', 'b', '1', 'b', '2', 'b', '3', 'b', '4', 'b', '5', 'b', '6', 'b', '7', 79 'b', '8', 'b', '9', 'b', 'a', 'b', 'b', 'b', 'c', 'b', 'd', 'b', 'e', 'b', 'f', 'c', '0', 'c', '1', 'c', '2', 'c', 80 '3', 'c', '4', 'c', '5', 'c', '6', 'c', '7', 'c', '8', 'c', '9', 'c', 'a', 'c', 'b', 'c', 'c', 'c', 'd', 'c', 'e', 81 'c', 'f', 'd', '0', 'd', '1', 'd', '2', 'd', '3', 'd', '4', 'd', '5', 'd', '6', 'd', '7', 'd', '8', 'd', '9', 'd', 82 'a', 'd', 'b', 'd', 'c', 'd', 'd', 'd', 'e', 'd', 'f', 'e', '0', 'e', '1', 'e', '2', 'e', '3', 'e', '4', 'e', '5', 83 'e', '6', 'e', '7', 'e', '8', 'e', '9', 'e', 'a', 'e', 'b', 'e', 'c', 'e', 'd', 'e', 'e', 'e', 'f', 'f', '0', 'f', 84 '1', 'f', '2', 'f', '3', 'f', '4', 'f', '5', 'f', '6', 'f', '7', 'f', '8', 'f', '9', 'f', 'a', 'f', 'b', 'f', 'c', 85 'f', 'd', 'f', 'e', 'f', 'f'}; 86 87 template <class _Tp> 88 const uint32_t __table<_Tp>::__pow10_32[10] = { 89 UINT32_C(0), UINT32_C(10), UINT32_C(100), UINT32_C(1000), UINT32_C(10000), 90 UINT32_C(100000), UINT32_C(1000000), UINT32_C(10000000), UINT32_C(100000000), UINT32_C(1000000000)}; 91 92 template <class _Tp> 93 const uint64_t __table<_Tp>::__pow10_64[20] = {UINT64_C(0), 94 UINT64_C(10), 95 UINT64_C(100), 96 UINT64_C(1000), 97 UINT64_C(10000), 98 UINT64_C(100000), 99 UINT64_C(1000000), 100 UINT64_C(10000000), 101 UINT64_C(100000000), 102 UINT64_C(1000000000), 103 UINT64_C(10000000000), 104 UINT64_C(100000000000), 105 UINT64_C(1000000000000), 106 UINT64_C(10000000000000), 107 UINT64_C(100000000000000), 108 UINT64_C(1000000000000000), 109 UINT64_C(10000000000000000), 110 UINT64_C(100000000000000000), 111 UINT64_C(1000000000000000000), 112 UINT64_C(10000000000000000000)}; 113 114 # ifndef _LIBCPP_HAS_NO_INT128 115 template <class _Tp> 116 const __uint128_t __table<_Tp>::__pow10_128[40] = { 117 UINT64_C(0), 118 UINT64_C(10), 119 UINT64_C(100), 120 UINT64_C(1000), 121 UINT64_C(10000), 122 UINT64_C(100000), 123 UINT64_C(1000000), 124 UINT64_C(10000000), 125 UINT64_C(100000000), 126 UINT64_C(1000000000), 127 UINT64_C(10000000000), 128 UINT64_C(100000000000), 129 UINT64_C(1000000000000), 130 UINT64_C(10000000000000), 131 UINT64_C(100000000000000), 132 UINT64_C(1000000000000000), 133 UINT64_C(10000000000000000), 134 UINT64_C(100000000000000000), 135 UINT64_C(1000000000000000000), 136 UINT64_C(10000000000000000000), 137 __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(10), 138 __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(100), 139 __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(1000), 140 __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(10000), 141 __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(100000), 142 __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(1000000), 143 __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(10000000), 144 __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(100000000), 145 __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(1000000000), 146 __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(10000000000), 147 __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(100000000000), 148 __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(1000000000000), 149 __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(10000000000000), 150 __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(100000000000000), 151 __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(1000000000000000), 152 __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(10000000000000000), 153 __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(100000000000000000), 154 __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(1000000000000000000), 155 __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(10000000000000000000), 156 (__uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(10000000000000000000)) * 10}; 157 # endif 158 159 template <class _Tp> 160 const char __table<_Tp>::__digits_base_10[200] = { 161 // clang-format off 162 '0', '0', '0', '1', '0', '2', '0', '3', '0', '4', '0', '5', '0', '6', '0', '7', '0', '8', '0', '9', 163 '1', '0', '1', '1', '1', '2', '1', '3', '1', '4', '1', '5', '1', '6', '1', '7', '1', '8', '1', '9', 164 '2', '0', '2', '1', '2', '2', '2', '3', '2', '4', '2', '5', '2', '6', '2', '7', '2', '8', '2', '9', 165 '3', '0', '3', '1', '3', '2', '3', '3', '3', '4', '3', '5', '3', '6', '3', '7', '3', '8', '3', '9', 166 '4', '0', '4', '1', '4', '2', '4', '3', '4', '4', '4', '5', '4', '6', '4', '7', '4', '8', '4', '9', 167 '5', '0', '5', '1', '5', '2', '5', '3', '5', '4', '5', '5', '5', '6', '5', '7', '5', '8', '5', '9', 168 '6', '0', '6', '1', '6', '2', '6', '3', '6', '4', '6', '5', '6', '6', '6', '7', '6', '8', '6', '9', 169 '7', '0', '7', '1', '7', '2', '7', '3', '7', '4', '7', '5', '7', '6', '7', '7', '7', '8', '7', '9', 170 '8', '0', '8', '1', '8', '2', '8', '3', '8', '4', '8', '5', '8', '6', '8', '7', '8', '8', '8', '9', 171 '9', '0', '9', '1', '9', '2', '9', '3', '9', '4', '9', '5', '9', '6', '9', '7', '9', '8', '9', '9'}; 172 // clang-format on 173 174 } // namespace __itoa 175 176 #endif // _LIBCPP_CXX03_LANG 177 178 _LIBCPP_END_NAMESPACE_STD 179 180 #endif // _LIBCPP___CHARCONV_TABLES 181