DAW JSON Link
Loading...
Searching...
No Matches
daw_json_simd.h
Go to the documentation of this file.
1// Copyright (c) Darrell Wright
2//
3// Distributed under the Boost Software License, Version 1.0. (See accompanying
4// file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)
5//
6// Official repository: https://github.com/beached/daw_json_link
7//
8
9#pragma once
10
11#include <daw/daw_cpp_feature_check.h>
12#include <daw/daw_is_constant_evaluated.h>
13
15
16#include <cstdint>
17#include <type_traits>
18
19#if defined( __BMI2__ ) and ( defined( __x86_64__ ) or defined( _M_X64 ) )
20#include <immintrin.h>
21#endif
22
23#if __has_include( <simd> )
24#include <simd>
25#endif
26
27#if defined( __cpp_lib_simd ) or defined( __glibcxx_simd )
28
29#define DAW_JSON_HAS_STD_SIMD 1
30
31#endif
32
33#if ( defined( __ARM_NEON ) or defined( __ARM_NEON__ ) )
35#endif
36
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 )
42#endif
43
44#if defined( DAW_JSON_HAS_STD_SIMD )
45
46#define DAW_JSON_HAS_SIMD 1
47#define DAW_JSON_SIMD_CONSTEXPR constexpr
48
49namespace daw {
50 namespace simd = std::simd;
51}
52
53#elif defined( DAW_JSON_HAS_NEON_SIMD )
54
55#define DAW_JSON_HAS_SIMD 1
56#define DAW_JSON_SIMD_CONSTEXPR inline
57
58namespace daw {
59 namespace simd = simd_impl::neon;
60}
61
62#elif defined( DAW_JSON_HAS_AVX2_SIMD )
63
64#define DAW_JSON_HAS_SIMD 1
65#define DAW_JSON_SIMD_CONSTEXPR inline
66
67namespace daw {
68 namespace simd = simd_impl::avx2;
69}
70
71#elif defined( DAW_JSON_HAS_SSE42_SIMD )
72
73#define DAW_JSON_HAS_SIMD 1
74#define DAW_JSON_SIMD_CONSTEXPR inline
75
76namespace daw {
77 namespace simd = simd_impl::sse42;
78}
79
80#endif
81
82#if defined( DAW_JSON_HAS_SIMD )
83
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 );
95 }
96#endif
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;
103 }
104 selection &= selection - 1U;
105 output_bit <<= 1U;
106 }
107 return result;
108 }
109
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 );
121 }
122
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( ) );
128 }
129} // namespace daw::simd_impl
130
131namespace daw::json {
132 inline namespace DAW_JSON_VER {
133 namespace json_details {
134 struct number_span {
135 char const *first = nullptr;
136 char const *last = nullptr;
137 char const *decimal_point = nullptr;
138 char const *exponent_marker = nullptr;
139 };
140
141 struct pending_number_span {
142 char const *first = nullptr;
143 char const *decimal_point = nullptr;
144 char const *exponent_marker = nullptr;
145 };
146
147 struct integer_span {
148 char const *first = nullptr;
149 char const *last = nullptr;
150 };
151
152 struct pending_integer_span {
153 char const *first = nullptr;
154 };
155 } // namespace json_details
156 } // namespace DAW_JSON_VER
157} // namespace daw::json
158
159#endif
Customization point traits.
#define DAW_JSON_VER
The version string used in namespace definitions. Must be a valid namespace name.
Definition version.h:20