xref: /freebsd-src/contrib/llvm-project/libcxx/include/__charconv/tables.h (revision 06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e)
181ad6265SDimitry Andric // -*- C++ -*-
281ad6265SDimitry Andric //===----------------------------------------------------------------------===//
381ad6265SDimitry Andric //
481ad6265SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
581ad6265SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
681ad6265SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
781ad6265SDimitry Andric //
881ad6265SDimitry Andric //===----------------------------------------------------------------------===//
981ad6265SDimitry Andric 
1081ad6265SDimitry Andric #ifndef _LIBCPP___CHARCONV_TABLES
1181ad6265SDimitry Andric #define _LIBCPP___CHARCONV_TABLES
1281ad6265SDimitry Andric 
1381ad6265SDimitry Andric #include <__config>
1481ad6265SDimitry Andric #include <cstdint>
1581ad6265SDimitry Andric 
1681ad6265SDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1781ad6265SDimitry Andric #  pragma GCC system_header
1881ad6265SDimitry Andric #endif
1981ad6265SDimitry Andric 
2081ad6265SDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD
2181ad6265SDimitry Andric 
22*06c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 17
2381ad6265SDimitry Andric 
2481ad6265SDimitry Andric namespace __itoa {
2581ad6265SDimitry Andric 
26bdd1243dSDimitry Andric inline constexpr char __base_2_lut[64] = {
2781ad6265SDimitry Andric     '0', '0', '0', '0', '0', '0', '0', '1', '0', '0', '1', '0', '0', '0', '1', '1', '0', '1', '0', '0', '0', '1',
2881ad6265SDimitry Andric     '0', '1', '0', '1', '1', '0', '0', '1', '1', '1', '1', '0', '0', '0', '1', '0', '0', '1', '1', '0', '1', '0',
2981ad6265SDimitry Andric     '1', '0', '1', '1', '1', '1', '0', '0', '1', '1', '0', '1', '1', '1', '1', '0', '1', '1', '1', '1'};
3081ad6265SDimitry Andric 
31bdd1243dSDimitry Andric inline constexpr char __base_8_lut[128] = {
3281ad6265SDimitry Andric     '0', '0', '0', '1', '0', '2', '0', '3', '0', '4', '0', '5', '0', '6', '0', '7', '1', '0', '1', '1', '1', '2',
3381ad6265SDimitry Andric     '1', '3', '1', '4', '1', '5', '1', '6', '1', '7', '2', '0', '2', '1', '2', '2', '2', '3', '2', '4', '2', '5',
3481ad6265SDimitry Andric     '2', '6', '2', '7', '3', '0', '3', '1', '3', '2', '3', '3', '3', '4', '3', '5', '3', '6', '3', '7', '4', '0',
3581ad6265SDimitry Andric     '4', '1', '4', '2', '4', '3', '4', '4', '4', '5', '4', '6', '4', '7', '5', '0', '5', '1', '5', '2', '5', '3',
3681ad6265SDimitry Andric     '5', '4', '5', '5', '5', '6', '5', '7', '6', '0', '6', '1', '6', '2', '6', '3', '6', '4', '6', '5', '6', '6',
3781ad6265SDimitry Andric     '6', '7', '7', '0', '7', '1', '7', '2', '7', '3', '7', '4', '7', '5', '7', '6', '7', '7'};
3881ad6265SDimitry Andric 
39bdd1243dSDimitry Andric inline constexpr char __base_16_lut[512] = {
4081ad6265SDimitry Andric     '0', '0', '0', '1', '0', '2', '0', '3', '0', '4', '0', '5', '0', '6', '0', '7', '0', '8', '0', '9', '0', 'a', '0',
4181ad6265SDimitry Andric     'b', '0', 'c', '0', 'd', '0', 'e', '0', 'f', '1', '0', '1', '1', '1', '2', '1', '3', '1', '4', '1', '5', '1', '6',
4281ad6265SDimitry Andric     '1', '7', '1', '8', '1', '9', '1', 'a', '1', 'b', '1', 'c', '1', 'd', '1', 'e', '1', 'f', '2', '0', '2', '1', '2',
4381ad6265SDimitry Andric     '2', '2', '3', '2', '4', '2', '5', '2', '6', '2', '7', '2', '8', '2', '9', '2', 'a', '2', 'b', '2', 'c', '2', 'd',
4481ad6265SDimitry Andric     '2', 'e', '2', 'f', '3', '0', '3', '1', '3', '2', '3', '3', '3', '4', '3', '5', '3', '6', '3', '7', '3', '8', '3',
4581ad6265SDimitry Andric     '9', '3', 'a', '3', 'b', '3', 'c', '3', 'd', '3', 'e', '3', 'f', '4', '0', '4', '1', '4', '2', '4', '3', '4', '4',
4681ad6265SDimitry Andric     '4', '5', '4', '6', '4', '7', '4', '8', '4', '9', '4', 'a', '4', 'b', '4', 'c', '4', 'd', '4', 'e', '4', 'f', '5',
4781ad6265SDimitry Andric     '0', '5', '1', '5', '2', '5', '3', '5', '4', '5', '5', '5', '6', '5', '7', '5', '8', '5', '9', '5', 'a', '5', 'b',
4881ad6265SDimitry Andric     '5', 'c', '5', 'd', '5', 'e', '5', 'f', '6', '0', '6', '1', '6', '2', '6', '3', '6', '4', '6', '5', '6', '6', '6',
4981ad6265SDimitry Andric     '7', '6', '8', '6', '9', '6', 'a', '6', 'b', '6', 'c', '6', 'd', '6', 'e', '6', 'f', '7', '0', '7', '1', '7', '2',
5081ad6265SDimitry Andric     '7', '3', '7', '4', '7', '5', '7', '6', '7', '7', '7', '8', '7', '9', '7', 'a', '7', 'b', '7', 'c', '7', 'd', '7',
5181ad6265SDimitry Andric     'e', '7', 'f', '8', '0', '8', '1', '8', '2', '8', '3', '8', '4', '8', '5', '8', '6', '8', '7', '8', '8', '8', '9',
5281ad6265SDimitry Andric     '8', 'a', '8', 'b', '8', 'c', '8', 'd', '8', 'e', '8', 'f', '9', '0', '9', '1', '9', '2', '9', '3', '9', '4', '9',
5381ad6265SDimitry Andric     '5', '9', '6', '9', '7', '9', '8', '9', '9', '9', 'a', '9', 'b', '9', 'c', '9', 'd', '9', 'e', '9', 'f', 'a', '0',
5481ad6265SDimitry Andric     'a', '1', 'a', '2', 'a', '3', 'a', '4', 'a', '5', 'a', '6', 'a', '7', 'a', '8', 'a', '9', 'a', 'a', 'a', 'b', 'a',
5581ad6265SDimitry Andric     'c', 'a', 'd', 'a', 'e', 'a', 'f', 'b', '0', 'b', '1', 'b', '2', 'b', '3', 'b', '4', 'b', '5', 'b', '6', 'b', '7',
5681ad6265SDimitry Andric     'b', '8', 'b', '9', 'b', 'a', 'b', 'b', 'b', 'c', 'b', 'd', 'b', 'e', 'b', 'f', 'c', '0', 'c', '1', 'c', '2', 'c',
5781ad6265SDimitry Andric     '3', 'c', '4', 'c', '5', 'c', '6', 'c', '7', 'c', '8', 'c', '9', 'c', 'a', 'c', 'b', 'c', 'c', 'c', 'd', 'c', 'e',
5881ad6265SDimitry Andric     'c', 'f', 'd', '0', 'd', '1', 'd', '2', 'd', '3', 'd', '4', 'd', '5', 'd', '6', 'd', '7', 'd', '8', 'd', '9', 'd',
5981ad6265SDimitry Andric     'a', 'd', 'b', 'd', 'c', 'd', 'd', 'd', 'e', 'd', 'f', 'e', '0', 'e', '1', 'e', '2', 'e', '3', 'e', '4', 'e', '5',
6081ad6265SDimitry Andric     'e', '6', 'e', '7', 'e', '8', 'e', '9', 'e', 'a', 'e', 'b', 'e', 'c', 'e', 'd', 'e', 'e', 'e', 'f', 'f', '0', 'f',
6181ad6265SDimitry Andric     '1', 'f', '2', 'f', '3', 'f', '4', 'f', '5', 'f', '6', 'f', '7', 'f', '8', 'f', '9', 'f', 'a', 'f', 'b', 'f', 'c',
6281ad6265SDimitry Andric     'f', 'd', 'f', 'e', 'f', 'f'};
6381ad6265SDimitry Andric 
64bdd1243dSDimitry Andric inline constexpr uint32_t __pow10_32[10] = {
65*06c3fb27SDimitry Andric     UINT32_C(0),
66*06c3fb27SDimitry Andric     UINT32_C(10),
67*06c3fb27SDimitry Andric     UINT32_C(100),
68*06c3fb27SDimitry Andric     UINT32_C(1000),
69*06c3fb27SDimitry Andric     UINT32_C(10000),
70*06c3fb27SDimitry Andric     UINT32_C(100000),
71*06c3fb27SDimitry Andric     UINT32_C(1000000),
72*06c3fb27SDimitry Andric     UINT32_C(10000000),
73*06c3fb27SDimitry Andric     UINT32_C(100000000),
74*06c3fb27SDimitry Andric     UINT32_C(1000000000)};
7581ad6265SDimitry Andric 
76*06c3fb27SDimitry Andric inline constexpr uint64_t __pow10_64[20] = {
77*06c3fb27SDimitry Andric     UINT64_C(0),
7881ad6265SDimitry Andric     UINT64_C(10),
7981ad6265SDimitry Andric     UINT64_C(100),
8081ad6265SDimitry Andric     UINT64_C(1000),
8181ad6265SDimitry Andric     UINT64_C(10000),
8281ad6265SDimitry Andric     UINT64_C(100000),
8381ad6265SDimitry Andric     UINT64_C(1000000),
8481ad6265SDimitry Andric     UINT64_C(10000000),
8581ad6265SDimitry Andric     UINT64_C(100000000),
8681ad6265SDimitry Andric     UINT64_C(1000000000),
8781ad6265SDimitry Andric     UINT64_C(10000000000),
8881ad6265SDimitry Andric     UINT64_C(100000000000),
8981ad6265SDimitry Andric     UINT64_C(1000000000000),
9081ad6265SDimitry Andric     UINT64_C(10000000000000),
9181ad6265SDimitry Andric     UINT64_C(100000000000000),
9281ad6265SDimitry Andric     UINT64_C(1000000000000000),
9381ad6265SDimitry Andric     UINT64_C(10000000000000000),
9481ad6265SDimitry Andric     UINT64_C(100000000000000000),
9581ad6265SDimitry Andric     UINT64_C(1000000000000000000),
9681ad6265SDimitry Andric     UINT64_C(10000000000000000000)};
9781ad6265SDimitry Andric 
98753f127fSDimitry Andric #  ifndef _LIBCPP_HAS_NO_INT128
99bdd1243dSDimitry Andric inline constexpr int __pow10_128_offset      = 0;
100bdd1243dSDimitry Andric inline constexpr __uint128_t __pow10_128[40] = {
101753f127fSDimitry Andric     UINT64_C(0),
102753f127fSDimitry Andric     UINT64_C(10),
103753f127fSDimitry Andric     UINT64_C(100),
104753f127fSDimitry Andric     UINT64_C(1000),
105753f127fSDimitry Andric     UINT64_C(10000),
106753f127fSDimitry Andric     UINT64_C(100000),
107753f127fSDimitry Andric     UINT64_C(1000000),
108753f127fSDimitry Andric     UINT64_C(10000000),
109753f127fSDimitry Andric     UINT64_C(100000000),
110753f127fSDimitry Andric     UINT64_C(1000000000),
111753f127fSDimitry Andric     UINT64_C(10000000000),
112753f127fSDimitry Andric     UINT64_C(100000000000),
113753f127fSDimitry Andric     UINT64_C(1000000000000),
114753f127fSDimitry Andric     UINT64_C(10000000000000),
115753f127fSDimitry Andric     UINT64_C(100000000000000),
116753f127fSDimitry Andric     UINT64_C(1000000000000000),
117753f127fSDimitry Andric     UINT64_C(10000000000000000),
118753f127fSDimitry Andric     UINT64_C(100000000000000000),
119753f127fSDimitry Andric     UINT64_C(1000000000000000000),
120753f127fSDimitry Andric     UINT64_C(10000000000000000000),
121753f127fSDimitry Andric     __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(10),
122753f127fSDimitry Andric     __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(100),
123753f127fSDimitry Andric     __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(1000),
124753f127fSDimitry Andric     __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(10000),
125753f127fSDimitry Andric     __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(100000),
126753f127fSDimitry Andric     __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(1000000),
127753f127fSDimitry Andric     __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(10000000),
128753f127fSDimitry Andric     __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(100000000),
129753f127fSDimitry Andric     __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(1000000000),
130753f127fSDimitry Andric     __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(10000000000),
131753f127fSDimitry Andric     __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(100000000000),
132753f127fSDimitry Andric     __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(1000000000000),
133753f127fSDimitry Andric     __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(10000000000000),
134753f127fSDimitry Andric     __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(100000000000000),
135753f127fSDimitry Andric     __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(1000000000000000),
136753f127fSDimitry Andric     __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(10000000000000000),
137753f127fSDimitry Andric     __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(100000000000000000),
138753f127fSDimitry Andric     __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(1000000000000000000),
139753f127fSDimitry Andric     __uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(10000000000000000000),
140753f127fSDimitry Andric     (__uint128_t(UINT64_C(10000000000000000000)) * UINT64_C(10000000000000000000)) * 10};
141753f127fSDimitry Andric #  endif
142753f127fSDimitry Andric 
143bdd1243dSDimitry Andric inline constexpr char __digits_base_10[200] = {
14481ad6265SDimitry Andric     // clang-format off
14581ad6265SDimitry Andric     '0', '0', '0', '1', '0', '2', '0', '3', '0', '4', '0', '5', '0', '6', '0', '7', '0', '8', '0', '9',
14681ad6265SDimitry Andric     '1', '0', '1', '1', '1', '2', '1', '3', '1', '4', '1', '5', '1', '6', '1', '7', '1', '8', '1', '9',
14781ad6265SDimitry Andric     '2', '0', '2', '1', '2', '2', '2', '3', '2', '4', '2', '5', '2', '6', '2', '7', '2', '8', '2', '9',
14881ad6265SDimitry Andric     '3', '0', '3', '1', '3', '2', '3', '3', '3', '4', '3', '5', '3', '6', '3', '7', '3', '8', '3', '9',
14981ad6265SDimitry Andric     '4', '0', '4', '1', '4', '2', '4', '3', '4', '4', '4', '5', '4', '6', '4', '7', '4', '8', '4', '9',
15081ad6265SDimitry Andric     '5', '0', '5', '1', '5', '2', '5', '3', '5', '4', '5', '5', '5', '6', '5', '7', '5', '8', '5', '9',
15181ad6265SDimitry Andric     '6', '0', '6', '1', '6', '2', '6', '3', '6', '4', '6', '5', '6', '6', '6', '7', '6', '8', '6', '9',
15281ad6265SDimitry Andric     '7', '0', '7', '1', '7', '2', '7', '3', '7', '4', '7', '5', '7', '6', '7', '7', '7', '8', '7', '9',
15381ad6265SDimitry Andric     '8', '0', '8', '1', '8', '2', '8', '3', '8', '4', '8', '5', '8', '6', '8', '7', '8', '8', '8', '9',
15481ad6265SDimitry Andric     '9', '0', '9', '1', '9', '2', '9', '3', '9', '4', '9', '5', '9', '6', '9', '7', '9', '8', '9', '9'};
15581ad6265SDimitry Andric // clang-format on
15681ad6265SDimitry Andric 
15781ad6265SDimitry Andric } // namespace __itoa
15881ad6265SDimitry Andric 
159*06c3fb27SDimitry Andric #endif // _LIBCPP_STD_VER >= 17
16081ad6265SDimitry Andric 
16181ad6265SDimitry Andric _LIBCPP_END_NAMESPACE_STD
16281ad6265SDimitry Andric 
16381ad6265SDimitry Andric #endif // _LIBCPP___CHARCONV_TABLES
164