Skip to content

Commit

Permalink
Jsonifier Release v0.9.7
Browse files Browse the repository at this point in the history
-Removed a bunch of superfluous "inline" calls.
-Updated a few types.
-Updated the Vector class to fill its implementation out.
-Updated the Iterator and ConstIterator implementations as well as the iterator-related members of the String, StringView and Vector classes.
  • Loading branch information
RealTimeChris committed Sep 5, 2023
1 parent c0ceec8 commit d93d19b
Show file tree
Hide file tree
Showing 43 changed files with 3,306 additions and 2,572 deletions.
8 changes: 3 additions & 5 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Format Style Options - Created with Clang Power Tools
---
AlignAfterOpenBracket: DontAlign
AlignConsecutiveAssignments: false
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: false
AlignConsecutiveMacros: false
AlignEscapedNewlines: DontAlign
Expand All @@ -19,9 +18,9 @@ AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakTemplateDeclarations: No
ColumnLimit: 150
ColumnLimit: 180
CompactNamespaces: false
ConstructorInitializerIndentWidth : 4
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
FixNamespaceComments: false
Expand Down Expand Up @@ -60,4 +59,3 @@ SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 4
UseTab: Always
...
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build-and-Test-CLANG
name: Build-and-Test-CLANG-MacOS

on:
push:
Expand All @@ -24,6 +24,8 @@ jobs:
run: |
brew install llvm
echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> ~/.bash_profile
export LDFLAGS="-L/usr/local/opt/llvm/lib"
export CPPFLAGS="-I/usr/local/opt/llvm/include"
- name: Configure CMake
working-directory: Tests
Expand All @@ -39,4 +41,5 @@ jobs:
working-directory: Tests/Build
run: |
./Json-Performance
continue-on-error: true

44 changes: 0 additions & 44 deletions .github/workflows/CLANG_17.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build-and-Test-GCC
name: Build-and-Test-GCC-Ubuntu

on:
push:
Expand Down Expand Up @@ -36,4 +36,5 @@ jobs:
- name: Run the Test
working-directory: Tests/Build
run: |
./Json-Performance
./Json-Performance
continue-on-error: true
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build-and-Test-MSVC
name: Build-and-Test-MSVC-Windows

on:
push:
Expand Down Expand Up @@ -40,4 +40,5 @@ jobs:
working-directory: Tests/Build/${{matrix.build_type}}/
run: |
./Json-Performance.exe
continue-on-error: true

50 changes: 31 additions & 19 deletions CMake/DetectArchitecture.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ function(check_instruction_set INSTRUCTION_SET_NAME INSTRUCTION_SET_FLAG INSTRUC
set(CMAKE_REQUIRED_FLAGS "${INSTRUCTION_SET_FLAG}")
CHECK_CXX_SOURCE_RUNS("${INSTRUCTION_SET_CODE}" "${INSTRUCTION_SET_NAME}")
if(${INSTRUCTION_SET_NAME})
set(AVX_TYPE "${INSTRUCTION_SET_NAME}" PARENT_SCOPE)
set(AVX_FLAG "${INSTRUCTION_SET_FLAG}" PARENT_SCOPE)
set(AVX_NAME "${INSTRUCTION_SET_NAME}" PARENT_SCOPE)
set(AVX_TYPE "${INSTRUCTION_SET_NAME}" PARENT_SCOPE)
else()
message(STATUS "Instruction set ${INSTRUCTION_SET_NAME} not supported. Falling back to the previous instruction set.")
return()
Expand All @@ -27,30 +26,43 @@ endfunction()
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(INSTRUCTION_SETS
"T_AVX?/arch:AVX?auto result = _mm_testz_ps(__m128{}, __m128{})"
"T_AVX2?/arch:AVX2?auto result = _mm256_extract_epi64(__m256i{}, 0)"
"T_AVX512?/arch:AVX512?auto result = _mm512_add_ps(__m512i{}, __m512i{}).auto result2 = _mm512_cmplt_epu8_mask(__m512i{}, __m512i{}).char newArray[64]{}.auto result = _mm_loadu_epi64(newArray)"
"T_AVX2?/arch:AVX2?auto result = _mm256_add_epi32(__m256i{}, __m256i{})"
"T_AVX512?/arch:AVX512?auto result = _mm512_add_ps(__m512i{}, __m512i{}).auto result2 = _mm512_cmplt_epu8_mask(__m512i{}, __m512i{})"
)
elseif(APPLE)
set(INSTRUCTION_SETS
"T_AVX?-mavx.-mpclmul.-mbmi.-mlzcnt?auto result = _mm_testz_ps(__m128{}, __m128{}).auto result2 = _blsr_u64(std::uint64_t{})"
"T_AVX2?-mavx2.-mavx.-mpclmul.-mbmi.-mlzcnt?auto result = _mm256_add_epi32(__m256i{}, __m256i{})"
"T_AVX512?-mavx512bw.-mavx512f.-mavx2.-mavx.-mpclmul.-mbmi.-mlzcnt?auto result = _mm512_add_ps(__m512i{}, __m512i{}).auto result2 = _mm512_cmplt_epu8_mask(__m512i{}, __m512i{})"
)
else()
set(INSTRUCTION_SETS
"T_AVX?-mavx.-mpclmul.-mbmi?auto result = _mm_testz_ps(__m128{}, __m128{})"
"T_AVX2?-mavx2.-mavx.-mpclmul.-mbmi?auto result = _mm256_extract_epi64(__m256i{}, 0)"
"T_AVX512?-mavx512bw.-avx512vl.-mavx512f.-mavx2.-mavx.-mpclmul.-mbmi?auto result = _mm512_add_ps(__m512i{}, __m512i{}).auto result2 = _mm512_cmplt_epu8_mask(__m512i{}, __m512i{}).char newArray[64]{}.auto result = _mm_loadu_epi64(newArray)"
"T_AVX?-mavx.-mpclmul.-mbmi.-mlzcnt?auto result = _mm_testz_ps(__m128{}, __m128{})"
"T_AVX2?-mavx2.-mavx.-mpclmul.-mbmi.-mlzcnt?auto result = _mm256_add_epi32(__m256i{}, __m256i{})"
"T_AVX512?-mavx512bw.-mavx512f.-mavx2.-mavx.-mpclmul.-mbmi.-mlzcnt?auto result = _mm512_add_ps(__m512i{}, __m512i{}).auto result2 = _mm512_cmplt_epu8_mask(__m512i{}, __m512i{})"
)
endif()

set(CMAKE_REQUIRED_FLAGS_SAVE "${CMAKE_REQUIRED_FLAGS}")

set(AVX_NAME "T_Fallback")
set(AVX_TYPE "T_Fallback")

foreach(INSTRUCTION_SET IN LISTS INSTRUCTION_SETS)
string(REPLACE "?" ";" CURRENT_LIST "${INSTRUCTION_SET}")
list(GET CURRENT_LIST 0 INSTRUCTION_SET_NAME)
list(GET CURRENT_LIST 1 INSTRUCTION_SET_FLAG)
string(REPLACE "." ";" INSTRUCTION_SET_FLAG "${INSTRUCTION_SET_FLAG}")
list(GET CURRENT_LIST 2 INSTRUCTION_SET_INTRINSIC)
string(REPLACE "." ";" INSTRUCTION_SET_INTRINSIC "${INSTRUCTION_SET_INTRINSIC}")
check_instruction_set("${INSTRUCTION_SET_NAME}" "${INSTRUCTION_SET_FLAG}" "${INSTRUCTION_SET_INTRINSIC}")
endforeach()
if ((${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64") OR (${CMAKE_SYSTEM_PROCESSOR} MATCHES "i386") OR (${CMAKE_SYSTEM_PROCESSOR} MATCHES "AMD64"))

foreach(INSTRUCTION_SET IN LISTS INSTRUCTION_SETS)
string(REPLACE "?" ";" CURRENT_LIST "${INSTRUCTION_SET}")
list(GET CURRENT_LIST 0 INSTRUCTION_SET_NAME)
list(GET CURRENT_LIST 1 INSTRUCTION_SET_FLAG)
string(REPLACE "." ";" INSTRUCTION_SET_FLAG "${INSTRUCTION_SET_FLAG}")
list(GET CURRENT_LIST 2 INSTRUCTION_SET_INTRINSIC)
string(REPLACE "." ";" INSTRUCTION_SET_INTRINSIC "${INSTRUCTION_SET_INTRINSIC}")
check_instruction_set("${INSTRUCTION_SET_NAME}" "${INSTRUCTION_SET_FLAG}" "${INSTRUCTION_SET_INTRINSIC}")
endforeach()

string(REPLACE "T_" "" AVX_DISPLAY ${AVX_TYPE})
message(STATUS "Detected CPU Architecture: ${AVX_DISPLAY}")
else()
message(STATUS "SSE not supported by architecture ${CMAKE_SYSTEM_PROCESSOR}")
endif()

message(STATUS "Detected CPU Architecture: ${AVX_NAME}")
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS_SAVE}")
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS_SAVE}")
10 changes: 8 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,17 @@ target_compile_options(
"${PROJECT_NAME}" INTERFACE
"$<$<CXX_COMPILER_ID:MSVC>:$<$<STREQUAL:${ASAN_ENABLED},TRUE>:/fsanitize=address>>"
"$<$<CXX_COMPILER_ID:MSVC>:$<$<STREQUAL:${ASAN_ENABLED},TRUE>:/EHsc>>"
"$<$<CXX_COMPILER_ID:MSVC>:/Zc:preprocessor>"
"$<$<CXX_COMPILER_ID:MSVC>:/permissive->"
"$<$<CXX_COMPILER_ID:MSVC>:/Zc:lambda>"
"$<$<CXX_COMPILER_ID:CLANG>:-Wextra>"
"$<$<CXX_COMPILER_ID:CLANG>:-Wall>"
"$<$<CXX_COMPILER_ID:GNU>:-Wextra>"
"$<$<CXX_COMPILER_ID:GNU>:-Wall>"
"$<$<CXX_COMPILER_ID:GNU>:-Wextra>"
"$<$<CXX_COMPILER_ID:MSVC>:/W4>"
"$<$<CXX_COMPILER_ID:GNU>:-Wall>"
"$<$<CXX_COMPILER_ID:MSVC>:/GL>"
"$<$<CXX_COMPILER_ID:GNU>:-pedantic>"
"$<$<CXX_COMPILER_ID:CLANG>:-pedantic>"
"${AVX_FLAG}"
)

Expand Down
2 changes: 1 addition & 1 deletion Documentation/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ STRIP_FROM_PATH =
# header file to include in order to use a class. If left blank only the name of
# the header file containing the class definition is used. Otherwise one should
# specify the list of include paths that are normally passed to the compiler
# using the -I flag.
# using the -Index flag.

STRIP_FROM_INC_PATH =

Expand Down
74 changes: 44 additions & 30 deletions Include/jsonifier/Allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,30 @@
Copyright (c) 2023 RealTimeChris
Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software, and to permit
Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
/// https://github.com/RealTimeChris/Jsonifier
/// Feb 3, 2023
#pragma once

#include <cstdint>
#include <utility>
#include <memory>
#include <memory_resource>
#include <utility>

#if defined(_MSC_VER)
#define ALIGNED_ALLOC(size, alignment) _aligned_malloc(size, alignment)
Expand All @@ -35,60 +36,73 @@
#define ALIGNED_FREE(ptr) free(ptr)
#endif

#if defined T_AVX512
#define ALIGNMENT 64
#elif defined T_AVX2
#define ALIGNMENT 32
#elif defined T_AVX
#define ALIGNMENT 16
#else
#define ALIGNMENT 8
#endif

namespace JsonifierInternal {

template<typename ValueType, uint64_t Alignment = alignof(ValueType)> class AlignedAllocator {
template<typename ValueType> class AlignedAllocator {
public:
using value_type = ValueType;
using pointer = value_type*;
using size_type = uint64_t;
using pointer = value_type*;
using size_type = uint64_t;

inline pointer allocate(size_type n) {
inline pointer allocate(size_type n) const {
if (n == 0) {
return nullptr;
}

return static_cast<pointer>(ALIGNED_ALLOC(n * sizeof(ValueType), Alignment < 32 ? 32 : Alignment));
return static_cast<pointer>(ALIGNED_ALLOC(n * sizeof(ValueType), ALIGNMENT));
}

inline void deallocate(pointer p, size_type) {
inline void deallocate(pointer p, size_type) const {
if (p) {
ALIGNED_FREE(p);
}
}

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

inline void destroy(pointer p) {
inline void destroy(pointer p) const {
p->~value_type();
}
};

template<typename ValueType> class AllocWrapper : public AlignedAllocator<ValueType> {
public:
using value_type = ValueType;
using pointer = value_type*;
using size_type = uint64_t;
using allocator = AlignedAllocator<value_type>;
using allocator_traits = std::allocator_traits<allocator>;
using value_type = ValueType;
using pointer = value_type*;
using size_type = uint64_t;
using allocator = const AlignedAllocator<value_type>;
using allocator_traits = const std::allocator_traits<allocator>;

inline pointer allocate(size_type count) noexcept {
inline AllocWrapper(){};

inline pointer allocate(size_type count) const {
return allocator_traits::allocate(*this, count);
}

inline void deallocate(pointer ptr, size_type count) noexcept {
inline void deallocate(pointer ptr, size_type count) const {
allocator_traits::deallocate(*this, ptr, count);
}

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

inline void destroy(pointer ptr) noexcept {
inline void destroy(pointer ptr) const {
allocator_traits::destroy(*this, ptr);
}

inline ~AllocWrapper(){};
};

}
}// namespace JsonifierInternal
Loading

0 comments on commit d93d19b

Please sign in to comment.