Skip to content

Commit

Permalink
Reversion.
Browse files Browse the repository at this point in the history
  • Loading branch information
RealTimeChris committed Jan 3, 2025
1 parent 49c1874 commit 5829299
Show file tree
Hide file tree
Showing 36 changed files with 1,415 additions and 1,414 deletions.
12 changes: 6 additions & 6 deletions Include/jsonifier/Array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ namespace jsonifier_internal {
using reverse_iterator = std::reverse_iterator<iterator>;
using const_reverse_iterator = std::reverse_iterator<const_iterator>;

JSONIFIER_INLINE constexpr array() noexcept = default;
constexpr array() noexcept = default;

JSONIFIER_INLINE constexpr array(std::initializer_list<value_type> initList) {
constexpr array(std::initializer_list<value_type> initList) {
for (size_t i = 0; i < initList.size() && i < sizeNew; ++i) {
values[i] = initList.begin()[i];
}
Expand Down Expand Up @@ -94,7 +94,7 @@ namespace jsonifier_internal {
return values;
}

JSONIFIER_INLINE constexpr void fill(const value_type& value) noexcept {
constexpr void fill(const value_type& value) noexcept {
for (size_t i = 0; i < sizeNew; ++i) {
values[i] = value;
}
Expand All @@ -120,7 +120,7 @@ namespace jsonifier_internal {
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
using difference_type = std::ptrdiff_t;

JSONIFIER_INLINE constexpr array(std::initializer_list<value_type>) {
constexpr array(std::initializer_list<value_type>) {
}

JSONIFIER_INLINE constexpr const_pointer data() const noexcept {
Expand Down Expand Up @@ -159,10 +159,10 @@ namespace jsonifier_internal {
return nullptr;
}

JSONIFIER_INLINE constexpr void fill(const value_type&) noexcept {
constexpr void fill(const value_type&) noexcept {
}

JSONIFIER_ALIGN value_type* dataVal{};
value_type* dataVal{};
};

}
102 changes: 51 additions & 51 deletions Include/jsonifier/Compare.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,30 @@

namespace jsonifier_internal {

template<const uint8_t repeat, jsonifier::concepts::uns16_t return_type> JSONIFIER_INLINE constexpr return_type repeatByte() noexcept {
template<const uint8_t repeat, jsonifier::concepts::uns16_t return_type> constexpr return_type repeatByte() noexcept {
return 0x0101ull * repeat;
}

template<const uint8_t repeat, jsonifier::concepts::uns32_t return_type> JSONIFIER_INLINE constexpr return_type repeatByte() noexcept {
template<const uint8_t repeat, jsonifier::concepts::uns32_t return_type> constexpr return_type repeatByte() noexcept {
return 0x01010101ull * repeat;
}

template<const uint8_t repeat, jsonifier::concepts::uns64_t return_type> JSONIFIER_INLINE constexpr return_type repeatByte() noexcept {
template<const uint8_t repeat, jsonifier::concepts::uns64_t return_type> constexpr return_type repeatByte() noexcept {
return 0x0101010101010101ull * repeat;
}

template<char valueNewer, typename char_type> struct char_comparison {
static constexpr char value{ valueNewer };
JSONIFIER_INLINE static const char_type* memchar(const char_type* data, size_t lengthNew) noexcept {
#if JSONIFIER_CHECK_FOR_INSTRUCTION(JSONIFIER_AVX512)
if (static_cast<int64_t>(lengthNew) >= 64) {
using simd_type = typename get_type_at_index<simd_internal::avx_list, 2>::type::type;
using integer_type = typename get_type_at_index<simd_internal::avx_list, 2>::type::integer_type;
static constexpr int64_t vectorSize = get_type_at_index<simd_internal::avx_list, 2>::type::bytesProcessed;
const simd_type search_value = simd_internal::gatherValue<simd_type>(static_cast<uint8_t>(value));
if (lengthNew >= 64) {
using simd_type = typename get_type_at_index<simd_internal::avx_list, 2>::type::type;
using integer_type = typename get_type_at_index<simd_internal::avx_list, 2>::type::integer_type;
static constexpr size_t vectorSize = get_type_at_index<simd_internal::avx_list, 2>::type::bytesProcessed;
const simd_type search_value = simd_internal::gatherValue<simd_type>(static_cast<uint8_t>(value));
integer_type mask;
simd_type chunk;
while (static_cast<int64_t>(lengthNew) >= vectorSize) {
while (lengthNew >= vectorSize) {
chunk = simd_internal::gatherValuesU<simd_type>(data);
mask = simd_internal::opCmpEq(chunk, search_value);
if JSONIFIER_UNLIKELY (mask != 0) {
Expand All @@ -65,14 +65,14 @@ namespace jsonifier_internal {
#endif

#if JSONIFIER_CHECK_FOR_INSTRUCTION(JSONIFIER_AVX512) || JSONIFIER_CHECK_FOR_INSTRUCTION(JSONIFIER_AVX2)
if (static_cast<int64_t>(lengthNew) >= 32) {
using simd_type = typename get_type_at_index<simd_internal::avx_list, 1>::type::type;
using integer_type = typename get_type_at_index<simd_internal::avx_list, 1>::type::integer_type;
static constexpr int64_t vectorSize = get_type_at_index<simd_internal::avx_list, 1>::type::bytesProcessed;
const simd_type search_value = simd_internal::gatherValue<simd_type>(static_cast<uint8_t>(value));
if (lengthNew >= 32) {
using simd_type = typename get_type_at_index<simd_internal::avx_list, 1>::type::type;
using integer_type = typename get_type_at_index<simd_internal::avx_list, 1>::type::integer_type;
static constexpr size_t vectorSize = get_type_at_index<simd_internal::avx_list, 1>::type::bytesProcessed;
const simd_type search_value = simd_internal::gatherValue<simd_type>(static_cast<uint8_t>(value));
integer_type mask;
simd_type chunk;
while (static_cast<int64_t>(lengthNew) >= vectorSize) {
while (lengthNew >= vectorSize) {
chunk = simd_internal::gatherValuesU<simd_type>(data);
mask = simd_internal::opCmpEq(chunk, search_value);
if JSONIFIER_UNLIKELY (mask != 0) {
Expand All @@ -86,14 +86,14 @@ namespace jsonifier_internal {
#endif
#if JSONIFIER_CHECK_FOR_INSTRUCTION(JSONIFIER_AVX512) || JSONIFIER_CHECK_FOR_INSTRUCTION(JSONIFIER_AVX2) || JSONIFIER_CHECK_FOR_INSTRUCTION(JSONIFIER_AVX) || \
JSONIFIER_CHECK_FOR_INSTRUCTION(JSONIFIER_NEON)
if (static_cast<int64_t>(lengthNew) >= 16) {
using simd_type = typename get_type_at_index<simd_internal::avx_list, 0>::type::type;
using integer_type = typename get_type_at_index<simd_internal::avx_list, 0>::type::integer_type;
static constexpr int64_t vectorSize = get_type_at_index<simd_internal::avx_list, 0>::type::bytesProcessed;
const simd_type search_value = simd_internal::gatherValue<simd_type>(static_cast<uint8_t>(value));
if (lengthNew >= 16) {
using simd_type = typename get_type_at_index<simd_internal::avx_list, 0>::type::type;
using integer_type = typename get_type_at_index<simd_internal::avx_list, 0>::type::integer_type;
static constexpr size_t vectorSize = get_type_at_index<simd_internal::avx_list, 0>::type::bytesProcessed;
const simd_type search_value = simd_internal::gatherValue<simd_type>(static_cast<uint8_t>(value));
integer_type mask;
simd_type chunk;
while (static_cast<int64_t>(lengthNew) >= vectorSize) {
while (lengthNew >= vectorSize) {
chunk = simd_internal::gatherValuesU<simd_type>(data);
mask = static_cast<integer_type>(simd_internal::opCmpEq(chunk, search_value));
if JSONIFIER_UNLIKELY (mask != 0) {
Expand All @@ -106,13 +106,13 @@ namespace jsonifier_internal {
}
#endif
{
static constexpr int64_t nBytes{ static_cast<int64_t>(sizeof(uint64_t)) };
if (static_cast<int64_t>(lengthNew) >= static_cast<int64_t>(nBytes)) {
static constexpr size_t nBytes{ sizeof(size_t) };
if (lengthNew >= nBytes) {
static constexpr auto valueNew{ repeatByte<value, size_t>() };
static constexpr auto highBits{ repeatByte<0x80, size_t>() };
static constexpr auto lowBits{ repeatByte<0x01, size_t>() };
size_t simdValue;
while (static_cast<int64_t>(lengthNew) >= nBytes) {
while (lengthNew >= nBytes) {
std::memcpy(&simdValue, data, sizeof(size_t));
const auto chunk = simdValue ^ valueNew;
auto next = ((chunk - lowBits) & ~chunk) & highBits;
Expand All @@ -128,8 +128,8 @@ namespace jsonifier_internal {
}
}
{
static constexpr int64_t nBytes{ static_cast<int64_t>(sizeof(uint32_t)) };
if (static_cast<int64_t>(lengthNew) >= static_cast<int64_t>(nBytes)) {
static constexpr size_t nBytes{ sizeof(uint32_t) };
if (lengthNew >= nBytes) {
static constexpr auto valueNew{ repeatByte<value, uint32_t>() };
static constexpr auto highBits{ repeatByte<0x80, uint32_t>() };
static constexpr auto lowBits{ repeatByte<0x01, uint32_t>() };
Expand All @@ -148,8 +148,8 @@ namespace jsonifier_internal {
}
}
{
static constexpr int64_t nBytes{ static_cast<int64_t>(sizeof(uint16_t)) };
if (static_cast<int64_t>(lengthNew) >= static_cast<int64_t>(nBytes)) {
static constexpr size_t nBytes{ sizeof(uint16_t) };
if (lengthNew >= nBytes) {
static constexpr auto valueNew{ repeatByte<value, uint16_t>() };
static constexpr auto highBits{ repeatByte<0x80, uint16_t>() };
static constexpr auto lowBits{ repeatByte<0x01, uint16_t>() };
Expand All @@ -168,7 +168,7 @@ namespace jsonifier_internal {
}
}

if (static_cast<int64_t>(lengthNew) > 0 && *data == value) {
if (lengthNew > 0 && *data == value) {
++data;
return data;
}
Expand All @@ -179,12 +179,12 @@ namespace jsonifier_internal {
struct comparison {
template<typename char_type01, typename char_type02> JSONIFIER_INLINE static bool compare(const char_type01* lhs, char_type02* rhs, size_t lengthNew) noexcept {
#if JSONIFIER_CHECK_FOR_INSTRUCTION(JSONIFIER_AVX512)
if (static_cast<int64_t>(lengthNew) >= 64) {
using simd_type = typename get_type_at_index<simd_internal::avx_list, 2>::type::type;
static constexpr int64_t vectorSize = get_type_at_index<simd_internal::avx_list, 2>::type::bytesProcessed;
static constexpr size_t mask = get_type_at_index<simd_internal::avx_list, 2>::type::mask;
if (lengthNew >= 64) {
using simd_type = typename get_type_at_index<simd_internal::avx_list, 2>::type::type;
static constexpr size_t vectorSize = get_type_at_index<simd_internal::avx_list, 2>::type::bytesProcessed;
static constexpr size_t mask = get_type_at_index<simd_internal::avx_list, 2>::type::mask;
simd_type value01, value02;
while (static_cast<int64_t>(lengthNew) >= vectorSize) {
while (lengthNew >= vectorSize) {
value01 = simd_internal::gatherValuesU<simd_type>(lhs);
value02 = simd_internal::gatherValuesU<simd_type>(rhs);
if (simd_internal::opCmpEq(value01, value02) != mask) {
Expand All @@ -197,12 +197,12 @@ namespace jsonifier_internal {
}
#endif
#if JSONIFIER_CHECK_FOR_INSTRUCTION(JSONIFIER_AVX512) || JSONIFIER_CHECK_FOR_INSTRUCTION(JSONIFIER_AVX2)
if (static_cast<int64_t>(lengthNew) >= 32) {
using simd_type = typename get_type_at_index<simd_internal::avx_list, 1>::type::type;
static constexpr int64_t vectorSize = get_type_at_index<simd_internal::avx_list, 1>::type::bytesProcessed;
static constexpr size_t mask = get_type_at_index<simd_internal::avx_list, 1>::type::mask;
if (lengthNew >= 32) {
using simd_type = typename get_type_at_index<simd_internal::avx_list, 1>::type::type;
static constexpr size_t vectorSize = get_type_at_index<simd_internal::avx_list, 1>::type::bytesProcessed;
static constexpr size_t mask = get_type_at_index<simd_internal::avx_list, 1>::type::mask;
simd_type value01, value02;
while (static_cast<int64_t>(lengthNew) >= vectorSize) {
while (lengthNew >= vectorSize) {
value01 = simd_internal::gatherValuesU<simd_type>(lhs);
value02 = simd_internal::gatherValuesU<simd_type>(rhs);
if (simd_internal::opCmpEq(value01, value02) != mask) {
Expand All @@ -216,12 +216,12 @@ namespace jsonifier_internal {
#endif
#if JSONIFIER_CHECK_FOR_INSTRUCTION(JSONIFIER_AVX512) || JSONIFIER_CHECK_FOR_INSTRUCTION(JSONIFIER_AVX2) || JSONIFIER_CHECK_FOR_INSTRUCTION(JSONIFIER_AVX) || \
JSONIFIER_CHECK_FOR_INSTRUCTION(JSONIFIER_NEON)
if (static_cast<int64_t>(lengthNew) >= 16) {
using simd_type = typename get_type_at_index<simd_internal::avx_list, 0>::type::type;
static constexpr int64_t vectorSize = get_type_at_index<simd_internal::avx_list, 0>::type::bytesProcessed;
static constexpr size_t mask = get_type_at_index<simd_internal::avx_list, 0>::type::mask;
if (lengthNew >= 16) {
using simd_type = typename get_type_at_index<simd_internal::avx_list, 0>::type::type;
static constexpr size_t vectorSize = get_type_at_index<simd_internal::avx_list, 0>::type::bytesProcessed;
static constexpr size_t mask = get_type_at_index<simd_internal::avx_list, 0>::type::mask;
simd_type value01, value02;
while (static_cast<int64_t>(lengthNew) >= vectorSize) {
while (lengthNew >= vectorSize) {
value01 = simd_internal::gatherValuesU<simd_type>(lhs);
value02 = simd_internal::gatherValuesU<simd_type>(rhs);
if (simd_internal::opCmpEq(value01, value02) != mask) {
Expand All @@ -234,10 +234,10 @@ namespace jsonifier_internal {
}
#endif
{
static constexpr int64_t nBytes{ static_cast<int64_t>(sizeof(uint64_t)) };
if (static_cast<int64_t>(lengthNew) >= static_cast<int64_t>(nBytes)) {
static constexpr size_t nBytes{ sizeof(size_t) };
if (lengthNew >= nBytes) {
size_t v[2];
while (static_cast<int64_t>(lengthNew) >= nBytes) {
while (lengthNew >= nBytes) {
std::memcpy(v, lhs, nBytes);
std::memcpy(v + 1, rhs, nBytes);
if ((v[0] ^ v[1]) != 0) {
Expand All @@ -250,8 +250,8 @@ namespace jsonifier_internal {
}
}
{
static constexpr int64_t nBytes{ static_cast<int64_t>(sizeof(uint32_t)) };
if (static_cast<int64_t>(lengthNew) >= static_cast<int64_t>(nBytes)) {
static constexpr size_t nBytes{ sizeof(uint32_t) };
if (lengthNew >= nBytes) {
uint32_t v[2];
std::memcpy(v, lhs, nBytes);
std::memcpy(v + 1, rhs, nBytes);
Expand All @@ -264,8 +264,8 @@ namespace jsonifier_internal {
}
}
{
static constexpr int64_t nBytes{ static_cast<int64_t>(sizeof(uint16_t)) };
if (static_cast<int64_t>(lengthNew) >= static_cast<int64_t>(nBytes)) {
static constexpr size_t nBytes{ sizeof(uint16_t) };
if (lengthNew >= nBytes) {
uint16_t v[2];
std::memcpy(v, lhs, nBytes);
std::memcpy(v + 1, rhs, nBytes);
Expand Down
2 changes: 1 addition & 1 deletion Include/jsonifier/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,4 @@ static constexpr uint64_t forceInlineLimitSerialize{ 20 };
#else
static constexpr uint64_t forceInlineLimitParse{ 4 };
static constexpr uint64_t forceInlineLimitSerialize{ 4 };
#endif
#endif
1 change: 0 additions & 1 deletion Include/jsonifier/Core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ namespace jsonifier_internal {
template<typename value_type> JSONIFIER_INLINE_VARIABLE auto sortedTupleReferencesByFirstByte{ sortTupleRefsByFirstByte(tupleRefs<value_type>) };
template<typename value_type> JSONIFIER_INLINE_VARIABLE auto tupleReferencesByFirstByte{ consolidateTupleRefs(sortedTupleReferencesByFirstByte<value_type>) };

// Idea for this interface sampled from Stephen Berry and his library, Glaze library: https://github.com/stephenberry/glaze
template<typename value_type> using core_tuple_type = decltype(jsonifier::core<std::remove_cvref_t<value_type>>::parseValue);

}// namespace jsonifier_internal
Loading

0 comments on commit 5829299

Please sign in to comment.