11#include <daw/daw_cpp_feature_check.h>
12#include <daw/daw_is_constant_evaluated.h>
19#if defined( __BMI2__ ) and ( defined( __x86_64__ ) or defined( _M_X64 ) )
23#if __has_include( <simd> )
27#if defined( __cpp_lib_simd ) or defined( __glibcxx_simd )
29#define DAW_JSON_HAS_STD_SIMD 1
33#if ( defined( __ARM_NEON ) or defined( __ARM_NEON__ ) )
37#if defined( __AVX2__ ) or defined( _M_AVX2 )
39#elif defined( __SSE4_2__ ) or defined( __AVX__ ) or defined( _M_X64 ) or \
40 ( defined( _M_IX86_FP ) and _M_IX86_FP >= 2 )
44#if defined( DAW_JSON_HAS_STD_SIMD )
46#define DAW_JSON_HAS_SIMD 1
47#define DAW_JSON_SIMD_CONSTEXPR constexpr
50 namespace simd = std::simd;
53#elif defined( DAW_JSON_HAS_NEON_SIMD )
55#define DAW_JSON_HAS_SIMD 1
56#define DAW_JSON_SIMD_CONSTEXPR inline
59 namespace simd = simd_impl::neon;
62#elif defined( DAW_JSON_HAS_AVX2_SIMD )
64#define DAW_JSON_HAS_SIMD 1
65#define DAW_JSON_SIMD_CONSTEXPR inline
68 namespace simd = simd_impl::avx2;
71#elif defined( DAW_JSON_HAS_SSE42_SIMD )
73#define DAW_JSON_HAS_SIMD 1
74#define DAW_JSON_SIMD_CONSTEXPR inline
77 namespace simd = simd_impl::sse42;
82#if defined( DAW_JSON_HAS_SIMD )
84namespace daw::simd_impl {
90 [[nodiscard]]
constexpr std::uint64_t
91 compress_bits( std::uint64_t values, std::uint64_t selection )
noexcept {
92#if defined( __BMI2__ ) and ( defined( __x86_64__ ) or defined( _M_X64 ) )
93 if( not DAW_IS_CONSTANT_EVALUATED_COMPAT( ) ) {
94 return _pext_u64( values, selection );
97 auto result = std::uint64_t{ 0 };
98 auto output_bit = std::uint64_t{ 1 };
99 while( selection != 0 ) {
100 auto const selected_bit = selection & ( ~selection + 1U );
101 if( ( values & selected_bit ) != 0 ) {
102 result |= output_bit;
104 selection &= selection - 1U;
116 template<
typename Mask,
117 std::enable_if_t<not std::is_integral_v<Mask>,
int> = 0>
118 [[nodiscard]] DAW_JSON_SIMD_CONSTEXPR std::uint64_t
119 compress_bits( Mask values, std::uint64_t selection )
noexcept {
120 return compress_bits( values.to_ullong( ), selection );
123 template<
typename Mask,
124 std::enable_if_t<not std::is_integral_v<Mask>,
int> = 0>
125 [[nodiscard]] DAW_JSON_SIMD_CONSTEXPR std::uint64_t
126 compress_bits( Mask values, Mask selection )
noexcept {
127 return compress_bits( values.to_ullong( ), selection.to_ullong( ) );
133 namespace json_details {
135 char const *first =
nullptr;
136 char const *last =
nullptr;
137 char const *decimal_point =
nullptr;
138 char const *exponent_marker =
nullptr;
141 struct pending_number_span {
142 char const *first =
nullptr;
143 char const *decimal_point =
nullptr;
144 char const *exponent_marker =
nullptr;
147 struct integer_span {
148 char const *first =
nullptr;
149 char const *last =
nullptr;
152 struct pending_integer_span {
153 char const *first =
nullptr;
@ simd
testing Allow code paths that use SIMD intrinsics
Customization point traits.
#define DAW_JSON_VER
The version string used in namespace definitions. Must be a valid namespace name.