Go to the documentation of this file.
23 #ifndef ABSL_STRINGS_NUMBERS_H_
24 #define ABSL_STRINGS_NUMBERS_H_
27 #include <x86intrin.h>
36 #include <type_traits>
38 #include "absl/base/config.h"
45 #include "absl/base/internal/endian.h"
47 #include "absl/base/macros.h"
48 #include "absl/base/port.h"
49 #include "absl/numeric/bits.h"
50 #include "absl/numeric/int128.h"
51 #include "absl/strings/string_view.h"
64 template <
typename int_type>
106 namespace numbers_internal {
158 template <
typename int_type>
160 static_assert(
sizeof(i) <= 64 / 8,
161 "FastIntToBuffer works only with 64-bit-or-less integers.");
165 if (
static_cast<int_type
>(1) - 2 < 0) {
166 if (
sizeof(i) > 32 / 8) {
172 if (
sizeof(i) > 32 / 8) {
182 template <
typename int_type>
185 static_assert(
sizeof(*
out) == 4 ||
sizeof(*
out) == 8,
186 "SimpleAtoi works only with 32-bit or 64-bit integers.");
188 "Use SimpleAtof or SimpleAtod instead.");
193 if (
static_cast<int_type
>(1) - 2 < 0) {
194 if (
sizeof(*
out) == 64 / 8) {
197 *
out =
static_cast<int_type
>(val);
201 *
out =
static_cast<int_type
>(val);
204 if (
sizeof(*
out) == 64 / 8) {
207 *
out =
static_cast<int_type
>(val);
211 *
out =
static_cast<int_type
>(val);
225 uint64_t be = absl::big_endian::FromHost64(val);
226 const auto kNibbleMask = _mm_set1_epi8(0xf);
227 const auto kHexDigits = _mm_setr_epi8(
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
228 '8',
'9',
'a',
'b',
'c',
'd',
'e',
'f');
229 auto v = _mm_loadl_epi64(
reinterpret_cast<__m128i*
>(&be));
230 auto v4 = _mm_srli_epi64(
v, 4);
231 auto il = _mm_unpacklo_epi8(v4,
v);
232 auto m = _mm_and_si128(il, kNibbleMask);
233 auto hexchars = _mm_shuffle_epi8(kHexDigits,
m);
234 _mm_storeu_si128(
reinterpret_cast<__m128i*
>(
out), hexchars);
236 for (
int i = 0;
i < 8; ++
i) {
237 auto byte = (val >> (56 - 8 *
i)) & 0xFF;
248 template <
typename int_type>
266 #endif // ABSL_STRINGS_NUMBERS_H_
void PutTwoDigits(size_t i, char *buf)
size_t FastHexToBufferZeroPad16(uint64_t val, char *out)
ABSL_NAMESPACE_BEGIN bool SimpleAtof(absl::string_view str, float *out)
size_t SixDigitsToBuffer(double d, char *buffer)
#define ABSL_NAMESPACE_END
bool SimpleAtob(absl::string_view str, bool *out)
bool safe_strto32_base(absl::string_view text, int32_t *value, int base)
#define ABSL_MUST_USE_RESULT
ABSL_NAMESPACE_BEGIN ABSL_MUST_USE_RESULT bool SimpleAtoi(absl::string_view str, int_type *out)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
#define ABSL_NAMESPACE_BEGIN
unsigned __int64 uint64_t
bool SimpleAtod(absl::string_view str, double *out)
ABSL_CONST_INIT const ABSL_DLL char two_ASCII_digits[100][2]
bool safe_strtou32_base(absl::string_view text, uint32_t *value, int base)
ABSL_INTERNAL_CONSTEXPR_CLZ std::enable_if< std::is_unsigned< T >::value, int >::type countl_zero(T x) noexcept
ABSL_MUST_USE_RESULT bool safe_strtoi_base(absl::string_view s, int_type *out, int base)
bool safe_strto128_base(absl::string_view text, int128 *value, int base)
bool safe_strto64_base(absl::string_view text, int64_t *value, int base)
ABSL_CONST_INIT const ABSL_DLL char kHexChar[]
static const int kFastToBufferSize
bool safe_strtou128_base(absl::string_view text, uint128 *value, int base)
static const int kSixDigitsToBufferSize
ABSL_CONST_INIT const ABSL_DLL char kHexTable[513]
char * FastIntToBuffer(int32_t, char *)
bool safe_strtou64_base(absl::string_view text, uint64_t *value, int base)
grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:33