Skip to content

Commit

Permalink
chore: move packed_bytes to namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
MistEO committed Nov 29, 2023
1 parent f0fa087 commit 32ae314
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 20 deletions.
6 changes: 3 additions & 3 deletions include/bitops.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#if __cplusplus >= 202002L || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L)
#include <bit>
namespace json::__bitops
namespace _bitops
{
using std::countl_one;
using std::countl_zero;
Expand All @@ -15,7 +15,7 @@ inline constexpr bool is_little_endian()
}
#else
#include <cstdint>
namespace json::__bitops
namespace _bitops
{
#if defined(__GNUC__) || defined(__clang__)
inline constexpr int countl_zero(uint32_t x)
Expand Down Expand Up @@ -108,5 +108,5 @@ inline bool is_little_endian()
} u = { 0x01020304 };
return u.u8 == 4;
}
} // namespace json::__bitops
} // namespace _bitops
#endif // C++20
9 changes: 6 additions & 3 deletions include/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
#include <variant>
#include <vector>

#include "packed_bytes.hpp"

namespace json
{
template <typename string_t>
Expand Down Expand Up @@ -487,8 +485,13 @@ class basic_object
// * parser declare *
// ****************************

namespace _packed_bytes
{
#include "packed_bytes.hpp"
}

template <typename string_t = default_string_t, typename parsing_t = void,
typename accel_traits = packed_bytes_trait_max>
typename accel_traits = _packed_bytes::packed_bytes_trait_max>
class parser
{
public:
Expand Down
22 changes: 11 additions & 11 deletions include/packed_bytes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ struct packed_bytes_trait_uint64

__packed_bytes_strong_inline static size_t first_nonzero_byte(value_type x)
{
if (json::__bitops::is_little_endian())
return json::__bitops::countr_zero(x) / 8;
if (_bitops::is_little_endian())
return _bitops::countr_zero(x) / 8;
else
return json::__bitops::countl_zero(x) / 8;
return _bitops::countl_zero(x) / 8;
}
};

Expand All @@ -87,7 +87,7 @@ struct packed_bytes_trait_uint32

__packed_bytes_strong_inline static value_type less(value_type x, uint8_t n)
{
return (((x) - ~UINT32_C(0) / 255 * (n)) & ~(x) & ~UINT32_C(0) / 255 * 128);
return (((x)-~UINT32_C(0) / 255 * (n)) & ~(x) & ~UINT32_C(0) / 255 * 128);
}

__packed_bytes_strong_inline static value_type is_zero_memberwise(value_type v)
Expand All @@ -107,10 +107,10 @@ struct packed_bytes_trait_uint32

__packed_bytes_strong_inline static size_t first_nonzero_byte(value_type x)
{
if (json::__bitops::is_little_endian())
return json::__bitops::countr_zero(x) / 8;
if (_bitops::is_little_endian())
return _bitops::countr_zero(x) / 8;
else
return json::__bitops::countl_zero(x) / 8;
return _bitops::countl_zero(x) / 8;
}
};
template <>
Expand All @@ -129,7 +129,7 @@ template <size_t N>
using packed_bytes_trait = typename packed_bytes<N>::traits;

using packed_bytes_trait_max =
std::conditional_t<packed_bytes_trait<32>::available, packed_bytes_trait<32>,
std::conditional_t<packed_bytes_trait<16>::available, packed_bytes_trait<16>,
std::conditional_t<packed_bytes_trait<8>::available, packed_bytes_trait<8>,
packed_bytes_trait<4>>>>;
std::conditional_t<packed_bytes_trait<32>::available, packed_bytes_trait<32>,
std::conditional_t<packed_bytes_trait<16>::available, packed_bytes_trait<16>,
std::conditional_t<packed_bytes_trait<8>::available, packed_bytes_trait<8>,
packed_bytes_trait<4>>>>;
2 changes: 1 addition & 1 deletion include/packed_bytes_arm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct packed_bytes_trait_neon
auto cmp = equal(x, 0);
auto res = vshrn_n_u16(cmp, 4);
auto mask64 = vget_lane_u64(vreinterpret_u64_u8(res), 0);
return json::__bitops::countr_one(mask64) >> 2;
return _bitops::countr_one(mask64) >> 2;
}
};

Expand Down
4 changes: 2 additions & 2 deletions include/packed_bytes_x86.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct packed_bytes_trait_sse
{
auto cmp = _mm_cmpeq_epi8(x, _mm_set1_epi8(0));
auto mask = (uint16_t)_mm_movemask_epi8(cmp);
return json::__bitops::countr_one((uint32_t)mask);
return _bitops::countr_one((uint32_t)mask);
}
};

Expand Down Expand Up @@ -107,7 +107,7 @@ struct packed_bytes_trait_avx2
auto cmp = _mm256_cmpeq_epi8(x, _mm256_set1_epi8(0));
auto mask = (uint32_t)_mm256_movemask_epi8(cmp);
// AVX512 alternative: _mm_cmpeq_epi8_mask
return json::__bitops::countr_one(mask);
return _bitops::countr_one(mask);
}
};

Expand Down

0 comments on commit 32ae314

Please sign in to comment.