Go to the documentation of this file.
23 #ifndef ABSL_STRINGS_NUMBERS_H_
24 #define ABSL_STRINGS_NUMBERS_H_
27 #include <tmmintrin.h>
40 #include <type_traits>
42 #include "absl/base/config.h"
43 #include "absl/base/internal/endian.h"
44 #include "absl/base/macros.h"
45 #include "absl/base/port.h"
46 #include "absl/numeric/bits.h"
47 #include "absl/numeric/int128.h"
48 #include "absl/strings/string_view.h"
61 template <
typename int_type>
106 template <
typename int_type>
122 namespace numbers_internal {
174 template <
typename int_type>
176 static_assert(
sizeof(
i) <= 64 / 8,
177 "FastIntToBuffer works only with 64-bit-or-less integers.");
182 constexpr
bool kIsSigned =
static_cast<int_type
>(1) - 2 < 0;
183 constexpr
bool kUse64Bit =
sizeof(
i) > 32 / 8;
201 template <
typename int_type>
204 static_assert(
sizeof(*
out) == 4 ||
sizeof(*
out) == 8,
205 "SimpleAtoi works only with 32-bit or 64-bit integers.");
207 "Use SimpleAtof or SimpleAtod instead.");
213 constexpr
bool kIsSigned =
static_cast<int_type
>(1) - 2 < 0;
214 constexpr
bool kUse64Bit =
sizeof(*out) == 64 / 8;
219 *
out =
static_cast<int_type
>(val);
223 *
out =
static_cast<int_type
>(val);
229 *
out =
static_cast<int_type
>(val);
233 *
out =
static_cast<int_type
>(val);
246 #ifdef ABSL_INTERNAL_HAVE_SSSE3
247 uint64_t be = absl::big_endian::FromHost64(val);
248 const auto kNibbleMask = _mm_set1_epi8(0xf);
249 const auto kHexDigits = _mm_setr_epi8(
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
250 '8',
'9',
'a',
'b',
'c',
'd',
'e',
'f');
251 auto v = _mm_loadl_epi64(
reinterpret_cast<__m128i*
>(&be));
252 auto v4 = _mm_srli_epi64(
v, 4);
253 auto il = _mm_unpacklo_epi8(v4,
v);
254 auto m = _mm_and_si128(il, kNibbleMask);
255 auto hexchars = _mm_shuffle_epi8(kHexDigits,
m);
256 _mm_storeu_si128(
reinterpret_cast<__m128i*
>(
out), hexchars);
258 for (
int i = 0;
i < 8; ++
i) {
259 auto byte = (val >> (56 - 8 *
i)) & 0xFF;
265 return 16 -
static_cast<size_t>(
countl_zero(val | 0x1) / 4);
270 template <
typename int_type>
285 template <
typename int_type>
303 #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
ABSL_MUST_USE_RESULT bool SimpleHexAtoi(absl::string_view str, int_type *out)
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