Skip to content

Commit

Permalink
Jsonifier Release v0.9.92
Browse files Browse the repository at this point in the history
* Refactored the number-parsing functions to use lookup tables instead of subtraction operations.
* Refactored the simd_string_reader class.
* Refactored some functions with fold-expressions for manual loop unrolliing.
* Refactored the toChars and parseNumber functions.
* Removed some superfluous typedefs.
* Testing new simd logic for string parsing.
* Renamed some types to snake_case.
* Refactored the jsonifier_core, parser, and serializer classes to utilize the CRTP.
* Refactored the simd_structural_iterator and serialization_iterator classes to remain contained.
  • Loading branch information
RealTimeChris committed Nov 27, 2023
1 parent 5cb79df commit 454f5a8
Show file tree
Hide file tree
Showing 56 changed files with 4,743 additions and 5,682 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CLANG_18-Ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

jobs:
Build:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest

strategy:
fail-fast: false
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/MSVC_2022-Windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

jobs:
Build:
runs-on: windows-2022
runs-on: windows-latest

strategy:
fail-fast: false
Expand Down
16 changes: 8 additions & 8 deletions BuildTools/Classes/Packager/Vcpkg.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,22 +137,26 @@ function constructPortAndVersionFile(string $sha512 = "0"): string
$portFileContent = 'vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO realtimechris/jsonifier
REF "v${VERSION}"
REF "v${VERSION}"
SHA512 ' . $sha512 . '
HEAD_REF main
PATCHES
uninstall-head.patch
)
set(VCPKG_BUILD_TYPE release) # header-only
vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
)
vcpkg_cmake_install()
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug")
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/License.md")
';
// ./Vcpkg/ports/jsonifier/vcpkg.json


// ./Vcpkg/ports/jsonifier/vcpkg.json
$versionFileContent = '{
"name": "jsonifier",
"version": ' . json_encode($this->getVersion()) . ',
Expand All @@ -164,10 +168,6 @@ function constructPortAndVersionFile(string $sha512 = "0"): string
{
"name": "vcpkg-cmake",
"host": true
},
{
"name": "vcpkg-cmake-config",
"host": true
}
]
}';
Expand Down
24 changes: 12 additions & 12 deletions CMake/JsonifierDetectArchitecture.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ function(jsonifier_check_instruction_set INSTRUCTION_SET_NAME INSTRUCTION_SET_IN
endfunction()

set(INSTRUCTION_SET_NAMES "POPCNT" "LZCNT" "BMI" "BMI2" "AVX" "AVX2" "AVX512")
set (INSTRUCTION_SET_CODE
set(INSTRUCTION_SET_CODE
"auto result = _mm_popcnt_u64(uint64_t{})"
"auto result = _lzcnt_u64(int64_t{})"
"auto result = _blsr_u64(uint64_t{}).result = _tzcnt_u32(uint16_t{})"
"auto result = _pdep_u64(uint64_t{}, uint64_t{})"
"auto result = _mm_castsi128_pd(__m128i{}).auto result02 = _mm_setzero_si128()"
"auto result = _mm_castsi128_pd(__m128i{}).auto result01 = _mm_setzero_si128()"
"auto result = _mm256_add_epi32(__m256i{}, __m256i{})"
"auto result = _mm512_add_ps(__m512i{}, __m512i{}).auto result2 = _mm512_cmplt_epu8_mask(__m512i{}, __m512i{}).auto result03 = _mm_abs_epi64 (__m128i{})"
"auto result = _mm_abs_epi64 (__m128i{}).auto result01 = _mm512_abs_epi16(__m512i{})"
)

set(INDEX_SET "0" "1" "2" "3" "4" "5" "6")

if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(INSTRUCTION_SET_IN_FLAGS "/arch:AVX" "/arch:AVX" "/arch:AVX" "/arch:AVX" "/arch:AVX" "/arch:AVX2" "/arch:AVX512")
set(INSTRUCTION_SET_OUT_FLAGS "/arch:AVX" "/arch:AVX" "/arch:AVX" "/arch:AVX" "/arch:AVX" "/arch:AVX2" "/arch:AVX512")
else()
Expand All @@ -70,7 +70,7 @@ endif()

set(CMAKE_REQUIRED_FLAGS_SAVE "${CMAKE_REQUIRED_FLAGS}")

if ((${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64") OR (${CMAKE_SYSTEM_PROCESSOR} MATCHES "i386") OR (${CMAKE_SYSTEM_PROCESSOR} MATCHES "AMD64"))
if((${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64") OR (${CMAKE_SYSTEM_PROCESSOR} MATCHES "i386") OR (${CMAKE_SYSTEM_PROCESSOR} MATCHES "AMD64"))

foreach(CURRENT_INDEX IN LISTS INDEX_SET)
list(GET INSTRUCTION_SET_NAMES "${CURRENT_INDEX}" INSTRUCTION_SET_NAME)
Expand All @@ -90,29 +90,29 @@ endif()
set(AVX_FLAG)
set(JSONIFIER_CPU_INSTRUCTIONS 0)

if (NOT "${POPCNT}" STREQUAL "")
if(NOT "${POPCNT}" STREQUAL "")
list(APPEND AVX_FLAG "${POPCNT}")
math(EXPR JSONIFIER_CPU_INSTRUCTIONS "${JSONIFIER_CPU_INSTRUCTIONS} | 1 << 0" OUTPUT_FORMAT DECIMAL)
endif()
if (NOT "${LZCNT}" STREQUAL "")
if(NOT "${LZCNT}" STREQUAL "")
list(APPEND AVX_FLAG "${LZCNT}")
math(EXPR JSONIFIER_CPU_INSTRUCTIONS "${JSONIFIER_CPU_INSTRUCTIONS} | 1 << 1" OUTPUT_FORMAT DECIMAL)
endif()
if (NOT "${BMI}" STREQUAL "")
if(NOT "${BMI}" STREQUAL "")
list(APPEND AVX_FLAG "${BMI}")
math(EXPR JSONIFIER_CPU_INSTRUCTIONS "${JSONIFIER_CPU_INSTRUCTIONS} | 1 << 2" OUTPUT_FORMAT DECIMAL)
endif()
if (NOT "${BMI2}" STREQUAL "")
if(NOT "${BMI2}" STREQUAL "")
list(APPEND AVX_FLAG "${BMI2}")
math(EXPR JSONIFIER_CPU_INSTRUCTIONS "${JSONIFIER_CPU_INSTRUCTIONS} | 1 << 3" OUTPUT_FORMAT DECIMAL)
endif()
if (NOT "${AVX512}" STREQUAL "")
if(NOT "${AVX512}" STREQUAL "")
list(APPEND AVX_FLAG "${AVX512}")
math(EXPR JSONIFIER_CPU_INSTRUCTIONS "${JSONIFIER_CPU_INSTRUCTIONS} | 1 << 6" OUTPUT_FORMAT DECIMAL)
elseif (NOT "${AVX2}" STREQUAL "")
elseif(NOT "${AVX2}" STREQUAL "")
list(APPEND AVX_FLAG "${AVX2}")
math(EXPR JSONIFIER_CPU_INSTRUCTIONS "${JSONIFIER_CPU_INSTRUCTIONS} | 1 << 5" OUTPUT_FORMAT DECIMAL)
elseif (NOT "${AVX}" STREQUAL "")
elseif(NOT "${AVX}" STREQUAL "")
list(APPEND AVX_FLAG "${AVX}")
math(EXPR JSONIFIER_CPU_INSTRUCTIONS "${JSONIFIER_CPU_INSTRUCTIONS} | 1 << 4" OUTPUT_FORMAT DECIMAL)
endif()
Expand Down
10 changes: 5 additions & 5 deletions Documentation/Custom/doxygen-awesome.css
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ code, div.fragment, pre.fragment {
}

code {
display: jsonifier_inline;
display: inline;
background: var(--code-background);
color: var(--code-foreground);
padding: 2px 6px;
Expand Down Expand Up @@ -1026,7 +1026,7 @@ div.fragment span.preprocessor {
}

div.fragment span.lineno {
display: jsonifier_inline-block;
display: inline-block;
width: 27px;
border-right: none;
background: var(--fragment-linenumber-background);
Expand Down Expand Up @@ -1100,7 +1100,7 @@ dl.deprecated dt a {
}

dl.section dd, dl.bug dd, dl.deprecated dd {
margin-jsonifier_inline-start: 0px;
margin-inline-start: 0px;
}

dl.invariant, dl.pre {
Expand Down Expand Up @@ -1429,7 +1429,7 @@ address.footer {

.navpath li.navelem a {
text-shadow: none;
display: jsonifier_inline-block;
display: inline-block;
color: var(--primary-color) !important;
}

Expand Down Expand Up @@ -1481,7 +1481,7 @@ li.navelem:first-child:before {
*/

doxygen-awesome-dark-mode-toggle {
display: jsonifier_inline-block;
display: inline-block;
margin: 0 0 0 var(--spacing-small);
padding: 0;
width: var(--searchbar-height);
Expand Down
6 changes: 3 additions & 3 deletions Documentation/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ SUBGROUPING = NO
INLINE_GROUPED_CLASSES = NO

# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and unions
# with only public data fields or simple typedef fields will be shown jsonifier_inline in
# with only public data fields or simple typedef fields will be shown inline in
# the documentation of the scope in which they are defined (i.e. file,
# namespace, or group documentation), provided this scope is documented. If set
# to NO, structs, classes, and unions are shown on a separate page (for HTML and
Expand Down Expand Up @@ -648,8 +648,8 @@ SHOW_GROUPED_MEMB_INC = NO

FORCE_LOCAL_INCLUDES = NO

# If the INLINE_INFO tag is set to YES then a tag [jsonifier_inline] is inserted in the
# documentation for jsonifier_inline members.
# If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the
# documentation for inline members.
# The default value is: YES.

INLINE_INFO = YES
Expand Down
57 changes: 39 additions & 18 deletions Include/jsonifier/Allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,40 +28,61 @@

namespace jsonifier_internal {

template<uint64_t multiple> jsonifier_inline uint64_t roundUpToMultiple(uint64_t num) {
template<uint64_t multiple> JSONIFIER_INLINE uint64_t roundUpToMultiple(uint64_t num) {
uint64_t remainder = num % multiple;
return remainder == 0 ? num : num + (multiple - remainder);
}

template<int64_t multiple> jsonifier_inline uint64_t roundDownToMultiple(int64_t value) {
template<int64_t multiple> JSONIFIER_INLINE uint64_t roundDownToMultiple(int64_t value) {
return static_cast<uint64_t>(value >= 0 ? (value / multiple) * multiple : ((value - multiple + 1) / multiple) * multiple);
}

template<typename value_type_new> class aligned_allocator : public std::pmr::polymorphic_allocator<value_type_new> {
#if defined(_MSC_VER)

template<typename value_type> JSONIFIER_INLINE value_type* jsonifierAlignedAlloc(uint64_t size) {
return static_cast<value_type*>(_aligned_malloc(roundUpToMultiple<BytesPerStep>(size * sizeof(value_type)), BytesPerStep));
}

JSONIFIER_INLINE void jsonifierFree(void* ptr) {
_aligned_free(ptr);
}

#else

template<typename value_type> JSONIFIER_INLINE value_type* jsonifierAlignedAlloc(uint64_t size) {
return static_cast<value_type*>(std::aligned_alloc(BytesPerStep, roundUpToMultiple<BytesPerStep>(size * sizeof(value_type))));
}

JSONIFIER_INLINE void jsonifierFree(void* ptr) {
free(ptr);
}

#endif

template<typename value_type_new> class aligned_allocator {
public:
using value_type = value_type_new;
using pointer = value_type*;
using size_type = uint64_t;
using allocator = std::pmr::polymorphic_allocator<value_type_new>;

jsonifier_inline pointer allocate(size_type n) {
JSONIFIER_INLINE pointer allocate(size_type n) {
if (n == 0) {
return nullptr;
}
return static_cast<pointer>(allocator::allocate_bytes(roundUpToMultiple<BytesPerStep>(n * sizeof(value_type)), BytesPerStep));
return jsonifierAlignedAlloc<value_type>(n);
}

jsonifier_inline void deallocate(pointer ptr, size_type n) {
JSONIFIER_INLINE void deallocate(pointer ptr, size_type) {
if (ptr) {
allocator::deallocate_bytes(ptr, roundUpToMultiple<BytesPerStep>(n * sizeof(value_type)), BytesPerStep);
jsonifierFree(ptr);
}
}

template<typename... Args> jsonifier_inline void construct(pointer p, Args&&... args) {
new (p) value_type(std::forward<Args>(args)...);
template<typename... arg_types> JSONIFIER_INLINE void construct(pointer p, arg_types&&... args) {
new (p) value_type(std::forward<arg_types>(args)...);
}

jsonifier_inline void destroy(pointer p) {
JSONIFIER_INLINE void destroy(pointer p) {
p->~value_type();
}
};
Expand All @@ -74,23 +95,23 @@ namespace jsonifier_internal {
using allocator = aligned_allocator<value_type>;
using allocator_traits = std::allocator_traits<allocator>;

jsonifier_inline pointer allocate(size_type count) {
JSONIFIER_INLINE pointer allocate(size_type count) {
return allocator_traits::allocate(*this, count);
}

jsonifier_inline void deallocate(pointer ptr, size_type count) {
JSONIFIER_INLINE void deallocate(pointer ptr, size_type count) {
allocator_traits::deallocate(*this, ptr, count);
}

template<typename... Args> jsonifier_inline void construct(pointer ptr, Args&&... args) {
allocator_traits::construct(*this, ptr, std::forward<Args>(args)...);
template<typename... arg_types> JSONIFIER_INLINE void construct(pointer ptr, arg_types&&... args) {
allocator_traits::construct(*this, ptr, std::forward<arg_types>(args)...);
}

jsonifier_inline static size_type maxSize() {
return allocator_traits::max_size(allocator{});
JSONIFIER_INLINE size_type maxSize() {
return allocator_traits::max_size(*this);
}

jsonifier_inline void destroy(pointer ptr) {
JSONIFIER_INLINE void destroy(pointer ptr) {
allocator_traits::destroy(*this, ptr);
}
};
Expand Down
Loading

0 comments on commit 454f5a8

Please sign in to comment.