Skip to content

Commit

Permalink
Merge pull request cppfastio#10 from MacroModel/trcrsired-master
Browse files Browse the repository at this point in the history
Trcrsired master
  • Loading branch information
MacroModel authored Nov 5, 2024
2 parents 09f733e + 14f470d commit d42da22
Show file tree
Hide file tree
Showing 65 changed files with 1,870 additions and 128 deletions.
205 changes: 200 additions & 5 deletions include/fast_io_core_impl/allocation/mimalloc_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ extern void *
#endif
#endif
;

#if defined(_MSC_VER) && !defined(__clang__)
__declspec(dllimport)
#elif (__has_cpp_attribute(__gnu__::__dllimport__) && !defined(__WINE__))
Expand Down Expand Up @@ -115,6 +116,114 @@ extern void *
#endif
;

#if defined(_MSC_VER) && !defined(__clang__)
__declspec(dllimport)
#elif (__has_cpp_attribute(__gnu__::__dllimport__) && !defined(__WINE__))
[[__gnu__::__dllimport__]]
#endif
#if __has_cpp_attribute(__gnu__::__cdecl__) && ((defined(_WIN32) && !defined(__WINE__)) || defined(__CYGWIN__))
[[__gnu__::__cdecl__]]
#endif
extern void *
#if !__has_cpp_attribute(__gnu__::__cdecl__) && defined(_MSC_VER)
__cdecl
#endif
mi_malloc_aligned(::std::size_t size, ::std::size_t alignment) noexcept
#if (defined(__clang__) || defined(__GNUC__))
#if SIZE_MAX <= UINT_LEAST32_MAX && (defined(__x86__) || defined(_M_IX86) || defined(__i386__)) && \
((defined(_WIN32) && !defined(__WINE__)) || defined(__CYGWIN__))
#if !defined(__clang__)
__asm__("mi_malloc_aligned")
#else
__asm__("_mi_malloc_aligned")
#endif
#else
__asm__("mi_malloc_aligned")
#endif
#endif
;

#if defined(_MSC_VER) && !defined(__clang__)
__declspec(dllimport)
#elif (__has_cpp_attribute(__gnu__::__dllimport__) && !defined(__WINE__))
[[__gnu__::__dllimport__]]
#endif
#if __has_cpp_attribute(__gnu__::__cdecl__) && ((defined(_WIN32) && !defined(__WINE__)) || defined(__CYGWIN__))
[[__gnu__::__cdecl__]]
#endif
extern void *
#if !__has_cpp_attribute(__gnu__::__cdecl__) && defined(_MSC_VER)
__cdecl
#endif
mi_ralloc_aligned(void *p, ::std::size_t size, ::std::size_t alignment) noexcept
#if (defined(__clang__) || defined(__GNUC__))
#if SIZE_MAX <= UINT_LEAST32_MAX && (defined(__x86__) || defined(_M_IX86) || defined(__i386__)) && \
((defined(_WIN32) && !defined(__WINE__)) || defined(__CYGWIN__))
#if !defined(__clang__)
__asm__("mi_ralloc_aligned")
#else
__asm__("_mi_ralloc_aligned")
#endif
#else
__asm__("mi_ralloc_aligned")
#endif
#endif
;

#if defined(_MSC_VER) && !defined(__clang__)
__declspec(dllimport)
#elif (__has_cpp_attribute(__gnu__::__dllimport__) && !defined(__WINE__))
[[__gnu__::__dllimport__]]
#endif
#if __has_cpp_attribute(__gnu__::__cdecl__) && ((defined(_WIN32) && !defined(__WINE__)) || defined(__CYGWIN__))
[[__gnu__::__cdecl__]]
#endif
extern void *
#if !__has_cpp_attribute(__gnu__::__cdecl__) && defined(_MSC_VER)
__cdecl
#endif
mi_calloc_aligned(::std::size_t count, ::std::size_t size, ::std::size_t alignment) noexcept
#if (defined(__clang__) || defined(__GNUC__))
#if SIZE_MAX <= UINT_LEAST32_MAX && (defined(__x86__) || defined(_M_IX86) || defined(__i386__)) && \
((defined(_WIN32) && !defined(__WINE__)) || defined(__CYGWIN__))
#if !defined(__clang__)
__asm__("mi_calloc_aligned")
#else
__asm__("_mi_calloc_aligned")
#endif
#else
__asm__("mi_calloc_aligned")
#endif
#endif
;

#if defined(_MSC_VER) && !defined(__clang__)
__declspec(dllimport)
#elif (__has_cpp_attribute(__gnu__::__dllimport__) && !defined(__WINE__))
[[__gnu__::__dllimport__]]
#endif
#if __has_cpp_attribute(__gnu__::__cdecl__) && ((defined(_WIN32) && !defined(__WINE__)) || defined(__CYGWIN__))
[[__gnu__::__cdecl__]]
#endif
extern void *
#if !__has_cpp_attribute(__gnu__::__cdecl__) && defined(_MSC_VER)
__cdecl
#endif
mi_free_aligned(void *p, ::std::size_t alignment) noexcept
#if (defined(__clang__) || defined(__GNUC__))
#if SIZE_MAX <= UINT_LEAST32_MAX && (defined(__x86__) || defined(_M_IX86) || defined(__i386__)) && \
((defined(_WIN32) && !defined(__WINE__)) || defined(__CYGWIN__))
#if !defined(__clang__)
__asm__("mi_calloc_aligned")
#else
__asm__("_mi_calloc_aligned")
#endif
#else
__asm__("mi_calloc_aligned")
#endif
#endif
;

} // namespace mimalloc

class mimalloc_allocator
Expand All @@ -123,37 +232,123 @@ class mimalloc_allocator
#if __has_cpp_attribute(__gnu__::__returns_nonnull__)
[[__gnu__::__returns_nonnull__]]
#endif
static inline void *allocate(::std::size_t n) noexcept
static inline void *
allocate(::std::size_t n) noexcept
{
if (n == 0) [[unlikely]]
{
n = 1;
}
void *p = ::fast_io::mimalloc::mi_malloc(n);
if (p == nullptr)
{
::fast_io::fast_terminate();
}
return p;
}
static inline void *reallocate(void *p, ::std::size_t n) noexcept

#if __has_cpp_attribute(__gnu__::__returns_nonnull__)
[[__gnu__::__returns_nonnull__]]
#endif
static inline void *
reallocate(void *p, ::std::size_t n) noexcept
{
if (n == 0) [[unlikely]]
{
n = 1;
}
p = ::fast_io::mimalloc::mi_realloc(p, n);
if (p == nullptr)
{
::fast_io::fast_terminate();
}
return p;
}
static inline void *allocate_zero(::std::size_t n) noexcept

#if __has_cpp_attribute(__gnu__::__returns_nonnull__)
[[__gnu__::__returns_nonnull__]]
#endif
static inline void *
allocate_zero(::std::size_t n) noexcept
{
if (n == 0) [[unlikely]]
{
n = 1;
}
void *p = ::fast_io::mimalloc::mi_calloc(1, n);
if (p == nullptr)
{
::fast_io::fast_terminate();
}
return p;
}
static inline void deallocate(void *p) noexcept

inline static void deallocate(void *p) noexcept
{
::fast_io::mimalloc::mi_free(p);
}
#if __has_cpp_attribute(__gnu__::__returns_nonnull__)
[[__gnu__::__returns_nonnull__]]
#endif
static inline void *
allocate_aligned(::std::size_t alignment, ::std::size_t n) noexcept
{
if (n == 0) [[unlikely]]
{
n = 1;
}
void *p = ::fast_io::mimalloc::mi_malloc_aligned(n, alignment);
if (p == nullptr)
{
::fast_io::fast_terminate();
}
return p;
}

#if __has_cpp_attribute(__gnu__::__returns_nonnull__)
[[__gnu__::__returns_nonnull__]]
#endif
static inline void *
reallocate_aligned(void *p, ::std::size_t alignment, ::std::size_t n) noexcept
{
if (n == 0) [[unlikely]]
{
n = 1;
}
p = ::fast_io::mimalloc::mi_ralloc_aligned(p, n, alignment);
if (p == nullptr)
{
::fast_io::fast_terminate();
}
return p;
}

#if __has_cpp_attribute(__gnu__::__returns_nonnull__)
[[__gnu__::__returns_nonnull__]]
#endif
static inline void *
allocate_zero_aligned(::std::size_t n, ::std::size_t alignment) noexcept
{
if (n == 0) [[unlikely]]
{
n = 1;
}
void *p = ::fast_io::mimalloc::mi_calloc_aligned(1, n, alignment);
if (p == nullptr)
{
::fast_io::fast_terminate();
}
return p;
}

inline static void deallocate_aligned(void *p, ::std::size_t alignment) noexcept
{
if (p == nullptr)
{
return;
}
::fast_io::mimalloc::mi_free_aligned(p, alignment);
}
};

} // namespace fast_io
} // namespace fast_io
12 changes: 12 additions & 0 deletions include/fast_io_core_impl/allocation/msvc/msvc_linker_32.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,17 @@
#pragma comment(linker, "/alternatename:__imp_?RtlGetCurrentPeb@nt@win32@fast_io@@YAPAUpeb@123@XZ=__imp_RtlGetCurrentPeb")
#pragma comment(linker, "/alternatename:__imp_?RtlReAllocateHeap@nt@win32@fast_io@@YAPAXPAXI0I@Z=__imp_RtlReAllocateHeap")
#pragma comment(linker, "/alternatename:__imp_?RtlSizeHeap@nt@win32@fast_io@@YAIPAXI0@Z=__imp_RtlSizeHeap")
#pragma comment(linker, "/alternatename:__imp_?VirtualAlloc@win32@fast_io@@YAPAXPAXIII@Z=__imp_VirtualAlloc")
#pragma comment(linker, "/alternatename:__imp_?VirtualProtect@win32@fast_io@@YAHPAXIIPAI@Z=__imp_VirtualProtect")
#pragma comment(linker, "/alternatename:__imp_?VirtualFree@win32@fast_io@@YAHPAXII@Z=__imp_VirtualFree")
#pragma comment(linker, "/alternatename:__imp_?VirtualQuery@win32@fast_io@@YAHPBXPAUmemory_basic_information@12@I@Z=__imp_VirtualQuery")

#pragma comment(linker, "/alternatename:__imp_?mi_malloc@mimalloc@fast_io@@YAPAXI@Z=mi_malloc")
#pragma comment(linker, "/alternatename:__imp_?mi_free@mimalloc@fast_io@@YAXPAX@Z=mi_free")
#pragma comment(linker, "/alternatename:__imp_?mi_calloc@mimalloc@fast_io@@YAPAXII@Z=mi_calloc")
#pragma comment(linker, "/alternatename:__imp_?mi_realloc@mimalloc@fast_io@@YAPAXPAXI@Z=mi_realloc")
#pragma comment(linker, "/alternatename:__imp_?mi_malloc_aligned@mimalloc@fast_io@@YAPAXII@Z=mi_malloc_aligned")
#pragma comment(linker, "/alternatename:__imp_?mi_ralloc_aligned@mimalloc@fast_io@@YAPAXPAXII@Z=mi_ralloc_aligned")
#pragma comment(linker, "/alternatename:__imp_?mi_calloc_aligned@mimalloc@fast_io@@YAPAXIII@Z=mi_calloc_aligned")
#pragma comment(linker, "/alternatename:__imp_?mi_free_aligned@mimalloc@fast_io@@YAPAXPAXI@Z=mi_free_aligned")
// clang-format on
12 changes: 12 additions & 0 deletions include/fast_io_core_impl/allocation/msvc/msvc_linker_32_i686.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,17 @@
#pragma comment(linker, "/alternatename:__imp_?RtlGetCurrentPeb@nt@win32@fast_io@@YGPAUpeb@123@XZ=__imp__RtlGetCurrentPeb@0")
#pragma comment(linker, "/alternatename:__imp_?RtlReAllocateHeap@nt@win32@fast_io@@YGPAXPAXI0I@Z=__imp__RtlReAllocateHeap@16")
#pragma comment(linker, "/alternatename:__imp_?RtlSizeHeap@nt@win32@fast_io@@YGIPAXI0@Z=__imp__RtlSizeHeap@12")
#pragma comment(linker, "/alternatename:__imp_?VirtualAlloc@win32@fast_io@@YGPAXPAXIII@Z=__imp__VirtualAlloc@16")
#pragma comment(linker, "/alternatename:__imp_?VirtualProtect@win32@fast_io@@YGHPAXIIPAI@Z=__imp__VirtualProtect@16")
#pragma comment(linker, "/alternatename:__imp_?VirtualFree@win32@fast_io@@YGHPAXII@Z=__imp__VirtualFree@12")
#pragma comment(linker, "/alternatename:__imp_?VirtualQuery@win32@fast_io@@YGHPBXPAUmemory_basic_information@12@I@Z=__imp__VirtualQuery@12")

#pragma comment(linker, "/alternatename:__imp_?mi_malloc@mimalloc@fast_io@@YAPAXI@Z=_mi_malloc")
#pragma comment(linker, "/alternatename:__imp_?mi_free@mimalloc@fast_io@@YAXPAX@Z=_mi_free")
#pragma comment(linker, "/alternatename:__imp_?mi_calloc@mimalloc@fast_io@@YAPAXII@Z=_mi_calloc")
#pragma comment(linker, "/alternatename:__imp_?mi_realloc@mimalloc@fast_io@@YAPAXPAXI@Z=_mi_realloc")
#pragma comment(linker, "/alternatename:__imp_?mi_malloc_aligned@mimalloc@fast_io@@YAPAXII@Z=_mi_malloc_aligned")
#pragma comment(linker, "/alternatename:__imp_?mi_ralloc_aligned@mimalloc@fast_io@@YAPAXPAXII@Z=_mi_ralloc_aligned")
#pragma comment(linker, "/alternatename:__imp_?mi_calloc_aligned@mimalloc@fast_io@@YAPAXIII@Z=_mi_calloc_aligned")
#pragma comment(linker, "/alternatename:__imp_?mi_free_aligned@mimalloc@fast_io@@YAPAXPAXI@Z=_mi_free_aligned")
// clang-format on
13 changes: 13 additions & 0 deletions include/fast_io_core_impl/allocation/msvc/msvc_linker_64.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,18 @@
#pragma comment(linker, "/alternatename:__imp_?RtlGetCurrentPeb@nt@win32@fast_io@@YAPEAUpeb@123@XZ=__imp_RtlGetCurrentPeb")
#pragma comment(linker, "/alternatename:__imp_?RtlReAllocateHeap@nt@win32@fast_io@@YAPEAXPEAXI0_K@Z=__imp_RtlReAllocateHeap")
#pragma comment(linker, "/alternatename:__imp_?RtlSizeHeap@nt@win32@fast_io@@YA_KPEAXI0@Z=__imp_RtlSizeHeap")
#pragma comment(linker, "/alternatename:__imp_?VirtualAlloc@win32@fast_io@@YAPEAXPEAX_KII@Z=__imp_VirtualAlloc")
#pragma comment(linker, "/alternatename:__imp_?VirtualProtect@win32@fast_io@@YAHPEAX_KIPEAI@Z=__imp_VirtualProtect")
#pragma comment(linker, "/alternatename:__imp_?VirtualFree@win32@fast_io@@YAHPEAX_KI@Z=__imp_VirtualFree")
#pragma comment(linker, "/alternatename:__imp_?__imp_?VirtualQuery@win32@fast_io@@YAHPEBXPEAUmemory_basic_information@12@_K@Z=__imp_VirtualQuery")

#pragma comment(linker, "/alternatename:__imp_?mi_malloc@mimalloc@fast_io@@YAPEAX_K@Z=mi_malloc")
#pragma comment(linker, "/alternatename:__imp_?mi_free@mimalloc@fast_io@@YAXPEAX@Z=mi_free")
#pragma comment(linker, "/alternatename:__imp_?mi_calloc@mimalloc@fast_io@@YAPEAX_K0@Z=mi_calloc")
#pragma comment(linker, "/alternatename:__imp_?mi_realloc@mimalloc@fast_io@@YAPEAXPEAX_K@Z=mi_realloc")
#pragma comment(linker, "/alternatename:__imp_?mi_malloc_aligned@mimalloc@fast_io@@YAPEAX_K0@Z=mi_malloc_aligned")
#pragma comment(linker, "/alternatename:__imp_?mi_ralloc_aligned@mimalloc@fast_io@@YAPEAXPEAX_K1@Z=mi_ralloc_aligned")
#pragma comment(linker, "/alternatename:__imp_?mi_calloc_aligned@mimalloc@fast_io@@YAPEAX_K00@Z=mi_calloc_aligned")
#pragma comment(linker, "/alternatename:__imp_?mi_free_aligned@mimalloc@fast_io@@YAPEAXPEAX_K@Z=mi_free_aligned")

// clang-format on
Loading

0 comments on commit d42da22

Please sign in to comment.