Skip to content

Commit

Permalink
Merge branch 'trcrsired:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
MacroModel authored Aug 3, 2024
2 parents 91db56b + 2b958fa commit 2ba00f9
Show file tree
Hide file tree
Showing 18 changed files with 8,209 additions and 1,212 deletions.
1,373 changes: 1,373 additions & 0 deletions benchmark/0012.isa/sha512_loongarch64_clang.s

Large diffs are not rendered by default.

1,302 changes: 1,302 additions & 0 deletions benchmark/0012.isa/sha512_loongarch64_clang_nosimd.s

Large diffs are not rendered by default.

2,371 changes: 1,188 additions & 1,183 deletions benchmark/0012.isa/sha512_loongarch64_gcc.s

Large diffs are not rendered by default.

2,185 changes: 2,185 additions & 0 deletions benchmark/0012.isa/sha512_riscv64_clang.s

Large diffs are not rendered by default.

2,006 changes: 2,006 additions & 0 deletions benchmark/0012.isa/sha512_riscv64_gcc.s

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions examples/0007.legacy/construct_fstream_from_syscall.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ FILE* or fstream apis
#if defined(__GLIBC__)
"GNU C Library ",
__GLIBC__, ".", __GLIBC_MINOR__,
#ifdef __GLIBC_SOURCE__
" (Source: ",__GLIBC_SOURCE__, ".", __GLIBC_MINOR_SOURCE__,")"
#endif
"\n"
#elif defined(__CYGWIN__) || defined(__NEWLIB__)
"Newlib cygwin\n"
Expand Down
1 change: 1 addition & 0 deletions include/fast_io_core_impl/enums/mmap_flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ enum class mmap_prot : ::std::uint_least32_t
prot_exec = 0x4, /* page can be executed */
prot_sem = 0x8, /* page may be used for atomic ops */
prot_none = 0x0, /* page can not be accessed */
prot_mte = 0x20, /* page is protected with Memory Tagging (ARM MTE for example) */
prot_growsdown = 0x01000000, /* mprotect flag: extend change to start of growsdown vma */
prot_growsup = 0x02000000, /* mprotect flag: extend change to end of growsup vma */
};
Expand Down
8 changes: 4 additions & 4 deletions include/fast_io_core_impl/operations/transcodeimpl/ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ inline constexpr ::std::byte const *transcode_bytes_imaginary_decay(T t,
for (; (n && ::fast_io::operations::decay::transcode_bytes_tosize_decay(t, fromfirst, fromfirst + n) <= mxsz); n >>= 1u)
{
}
return n;
return fromfirst + n;
}
}

Expand Down Expand Up @@ -265,8 +265,8 @@ template <typename T>
(sizeof(typename T::from_value_type) == 1 && sizeof(typename T::to_value_type) == 1)) ||
::fast_io::operations::decay::defines::has_transcode_bytes_imaginary_decay_define<T> ||
::fast_io::operations::decay::defines::has_transcode_imaginary_decay_define<T>)
inline constexpr ::std::size_t transcode_imaginary_decay(T t,
typename T::from_value_type const *fromfirst, typename T::from_value_type const *fromlast, ::std::size_t mxsz)
inline constexpr typename T::from_value_type const *transcode_imaginary_decay(T t,
typename T::from_value_type const *fromfirst, typename T::from_value_type const *fromlast, ::std::size_t mxsz)
{
if constexpr (::fast_io::operations::decay::defines::has_transcode_imaginary_decay_define<T>)
{
Expand All @@ -289,7 +289,7 @@ inline constexpr ::std::size_t transcode_imaginary_decay(T t,
for (; (n && ::fast_io::operations::decay::transcode_tosize_decay(t, fromfirst, fromfirst + n) <= mxsz); n >>= 1u)
{
}
return n;
return fromfirst + n;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace fast_io
{

namespace manipulators
inline namespace manipulators
{

template<::std::integral chartype, typename T>
Expand Down
8 changes: 4 additions & 4 deletions include/fast_io_dsal/impl/deque.h
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ class deque
grow_back();
}
auto currptr{controller.back_block.curr_ptr};
if constexpr (::std::is_trivially_constructible_v<value_type>)
if constexpr (!::std::is_trivially_constructible_v<value_type>)
{
::std::construct_at(currptr, ::std::forward<Args>(args)...);
}
Expand Down Expand Up @@ -794,7 +794,7 @@ class deque

constexpr void pop_back_unchecked() noexcept
{
if constexpr (::std::is_trivially_destructible_v<value_type>)
if constexpr (!::std::is_trivially_destructible_v<value_type>)
{
::std::destroy_at(controller.back_block.curr_ptr - 1);
}
Expand Down Expand Up @@ -842,7 +842,7 @@ class deque
{
grow_front();
}
if constexpr (::std::is_trivially_constructible_v<value_type>)
if constexpr (!::std::is_trivially_constructible_v<value_type>)
{
::std::construct_at(--controller.front_block.curr_ptr, ::std::forward<Args>(args)...);
}
Expand Down Expand Up @@ -871,7 +871,7 @@ class deque

constexpr void pop_front_unchecked() noexcept
{
if constexpr (::std::is_trivially_destructible_v<value_type>)
if constexpr (!::std::is_trivially_destructible_v<value_type>)
{
::std::destroy_at(controller.front_block.curr_ptr);
}
Expand Down
20 changes: 20 additions & 0 deletions include/fast_io_hosted/filesystem/posix_at.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,25 @@ namespace fast_io

namespace posix
{
#ifdef __DARWIN_C_LEVEL
extern int libc_faccessat(int dirfd, char const *pathname, int mode, int flags) noexcept __asm__("_faccessat");
extern int libc_renameat(int olddirfd, char const *oldpath, int newdirfd, char const *newpath) noexcept
__asm__("_renameat");
extern int libc_linkat(int olddirfd, char const *oldpath, int newdirfd, char const *newpath, int flags) noexcept
__asm__("_linkat");
extern int libc_symlinkat(char const *oldpath, int newdirfd, char const *newpath) noexcept __asm__("_symlinkat");
extern int libc_fchmodat(int dirfd, char const *pathname, mode_t mode, int flags) noexcept __asm__("_fchmodat");
extern int libc_utimensat(int dirfd, char const *pathname, struct timespec const *times, int flags) noexcept
__asm__("_utimensat");
extern int libc_fchownat(int dirfd, char const *pathname, uid_t owner, gid_t group, int flags) noexcept
__asm__("_fchownat");
extern int libc_fstatat(int dirfd, char const *pathname, struct stat *buf, int flags) noexcept __asm__("_fstatat");
extern int libc_mkdirat(int dirfd, char const *pathname, mode_t mode) noexcept __asm__("_mkdirat");
extern int libc_mknodat(int dirfd, char const *pathname, mode_t mode, dev_t dev) noexcept __asm__("_mknodat");
extern int libc_unlinkat(int dirfd, char const *pathname, int flags) noexcept __asm__("_unlinkat");
extern int libc_readlinkat(int dirfd, char const *pathname, char *buf, ::std::size_t bufsiz) noexcept
__asm__("_readlinkat");
#else
extern int libc_faccessat(int dirfd, char const *pathname, int mode, int flags) noexcept __asm__("faccessat");
extern int libc_renameat(int olddirfd, char const *oldpath, int newdirfd, char const *newpath) noexcept
__asm__("renameat");
Expand All @@ -22,6 +41,7 @@ extern int libc_mknodat(int dirfd, char const *pathname, mode_t mode, dev_t dev)
extern int libc_unlinkat(int dirfd, char const *pathname, int flags) noexcept __asm__("unlinkat");
extern int libc_readlinkat(int dirfd, char const *pathname, char *buf, ::std::size_t bufsiz) noexcept
__asm__("readlinkat");
#endif
} // namespace posix

namespace details
Expand Down
7 changes: 6 additions & 1 deletion include/fast_io_hosted/mmap/posix_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ struct posix_mmap_options
prottemp |= PROT_EXEC;
}
#endif

#ifdef PROT_MTE
if ((protv & ::fast_io::mmap_prot::prot_mte) == ::fast_io::mmap_prot::prot_mte)
{
prottemp |= PROT_MTE;
}
#endif
#ifdef PROT_SEM
if ((protv & ::fast_io::mmap_prot::prot_sem) == ::fast_io::mmap_prot::prot_sem)
{
Expand Down
24 changes: 16 additions & 8 deletions include/fast_io_hosted/platforms/linux/loongarch64.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ inline return_value_type system_call() noexcept
{
register ::std::uint_least64_t a7 __asm__("$a7") = syscall_number;
register ::std::uint_least64_t a0 __asm__("$a0");
__asm__ __volatile__("syscall 0" : "+r"(a0) : "r"(a7) : "memory");
__asm__ __volatile__("syscall 0" : "+r"(a0) : "r"(a7) : "$t0", "$t1", "$t2", "$t3", "$t4",
"$t5", "$t6", "$t7", "$t8", "memory");
return static_cast<return_value_type>(a0);
}

Expand All @@ -24,7 +25,8 @@ inline return_value_type system_call(auto p1) noexcept
{
register ::std::uint_least64_t a7 __asm__("$a7") = syscall_number;
register ::std::uint_least64_t a0 __asm__("$a0") = (::std::uint_least64_t)p1;
__asm__ __volatile__("syscall 0" : "+r"(a0) : "r"(a7) : "memory");
__asm__ __volatile__("syscall 0" : "+r"(a0) : "r"(a7) : "$t0", "$t1", "$t2", "$t3", "$t4",
"$t5", "$t6", "$t7", "$t8", "memory");
return static_cast<return_value_type>(a0);
}

Expand All @@ -33,7 +35,8 @@ inline void system_call_no_return(auto p1) noexcept
{
register ::std::uint_least64_t a7 __asm__("$a7") = syscall_number;
register ::std::uint_least64_t a0 __asm__("$a0") = (::std::uint_least64_t)p1;
__asm__ __volatile__("syscall 0" : "+r"(a0) : "r"(a7) : "memory");
__asm__ __volatile__("syscall 0" : "+r"(a0) : "r"(a7) : "$t0", "$t1", "$t2", "$t3", "$t4",
"$t5", "$t6", "$t7", "$t8", "memory");
}

template <::std::uint_least64_t syscall_number, ::std::signed_integral return_value_type>
Expand All @@ -43,7 +46,8 @@ inline return_value_type system_call(auto p1, auto p2) noexcept
register ::std::uint_least64_t a7 __asm__("$a7") = syscall_number;
register ::std::uint_least64_t a0 __asm__("$a0") = (::std::uint_least64_t)p1;
register ::std::uint_least64_t a1 __asm__("$a1") = (::std::uint_least64_t)p2;
__asm__ __volatile__("syscall 0" : "+r"(a0) : "r"(a7), "r"(a1) : "memory");
__asm__ __volatile__("syscall 0" : "+r"(a0) : "r"(a7), "r"(a1) : "$t0", "$t1", "$t2", "$t3", "$t4",
"$t5", "$t6", "$t7", "$t8", "memory");
return static_cast<return_value_type>(a0);
}

Expand All @@ -55,7 +59,8 @@ inline return_value_type system_call(auto p1, auto p2, auto p3) noexcept
register ::std::uint_least64_t a0 __asm__("$a0") = (::std::uint_least64_t)p1;
register ::std::uint_least64_t a1 __asm__("$a1") = (::std::uint_least64_t)p2;
register ::std::uint_least64_t a2 __asm__("$a2") = (::std::uint_least64_t)p3;
__asm__ __volatile__("syscall 0" : "+r"(a0) : "r"(a7), "r"(a1), "r"(a2) : "memory");
__asm__ __volatile__("syscall 0" : "+r"(a0) : "r"(a7), "r"(a1), "r"(a2) : "$t0", "$t1", "$t2", "$t3", "$t4",
"$t5", "$t6", "$t7", "$t8", "memory");
return static_cast<return_value_type>(a0);
}

Expand All @@ -68,7 +73,8 @@ inline return_value_type system_call(auto p1, auto p2, auto p3, auto p4) noexcep
register ::std::uint_least64_t a1 __asm__("$a1") = (::std::uint_least64_t)p2;
register ::std::uint_least64_t a2 __asm__("$a2") = (::std::uint_least64_t)p3;
register ::std::uint_least64_t a3 __asm__("$a3") = (::std::uint_least64_t)p4;
__asm__ __volatile__("syscall 0" : "+r"(a0) : "r"(a7), "r"(a1), "r"(a2), "r"(a3) : "memory");
__asm__ __volatile__("syscall 0" : "+r"(a0) : "r"(a7), "r"(a1), "r"(a2), "r"(a3) : "$t0", "$t1", "$t2", "$t3", "$t4",
"$t5", "$t6", "$t7", "$t8", "memory");
return static_cast<return_value_type>(a0);
}

Expand All @@ -82,7 +88,8 @@ inline return_value_type system_call(auto p1, auto p2, auto p3, auto p4, auto p5
register ::std::uint_least64_t a2 __asm__("$a2") = (::std::uint_least64_t)p3;
register ::std::uint_least64_t a3 __asm__("$a3") = (::std::uint_least64_t)p4;
register ::std::uint_least64_t a4 __asm__("$a4") = (::std::uint_least64_t)p5;
__asm__ __volatile__("syscall 0" : "+r"(a0) : "r"(a7), "r"(a1), "r"(a2), "r"(a3), "r"(a4) : "memory");
__asm__ __volatile__("syscall 0" : "+r"(a0) : "r"(a7), "r"(a1), "r"(a2), "r"(a3), "r"(a4) : "$t0", "$t1", "$t2", "$t3", "$t4",
"$t5", "$t6", "$t7", "$t8", "memory");
return static_cast<return_value_type>(a0);
}

Expand All @@ -97,7 +104,8 @@ inline return_value_type system_call(auto p1, auto p2, auto p3, auto p4, auto p5
register ::std::uint_least64_t a3 __asm__("$a3") = (::std::uint_least64_t)p4;
register ::std::uint_least64_t a4 __asm__("$a4") = (::std::uint_least64_t)p5;
register ::std::uint_least64_t a5 __asm__("$a5") = (::std::uint_least64_t)p6;
__asm__ __volatile__("syscall 0" : "+r"(a0) : "r"(a7), "r"(a1), "r"(a2), "r"(a3), "r"(a4), "r"(a5) : "memory");
__asm__ __volatile__("syscall 0" : "+r"(a0) : "r"(a7), "r"(a1), "r"(a2), "r"(a3), "r"(a4), "r"(a5) : "$t0", "$t1", "$t2", "$t3", "$t4",
"$t5", "$t6", "$t7", "$t8", "memory");
return static_cast<return_value_type>(a0);
}

Expand Down
6 changes: 6 additions & 0 deletions include/fast_io_hosted/timeutil/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ namespace fast_io
namespace posix
{
#if !defined(_WIN32) && !defined(__AVR__) && !defined(__MSDOS__)
#ifdef __DARWIN_C_LEVEL
extern int libc_clock_getres(clockid_t clk_id, struct timespec *tp) noexcept __asm__("_clock_getres");
extern int libc_clock_settime(clockid_t clk_id, struct timespec const *tp) noexcept __asm__("_clock_settime");
extern int libc_clock_gettime(clockid_t clk_id, struct timespec *tp) noexcept __asm__("_clock_gettime");
#else
extern int libc_clock_getres(clockid_t clk_id, struct timespec *tp) noexcept __asm__("clock_getres");
extern int libc_clock_settime(clockid_t clk_id, struct timespec const *tp) noexcept __asm__("clock_settime");
extern int libc_clock_gettime(clockid_t clk_id, struct timespec *tp) noexcept __asm__("clock_gettime");
#endif
#elif defined(__MSDOS__)
struct tm *libc_localtime_r(::std::time_t const *timep, struct tm *result) noexcept
#ifdef __MSDOS__
Expand Down
77 changes: 77 additions & 0 deletions include/fast_io_hosted/white_hole/bsd_arc4random.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#pragma once

namespace fast_io
{

template <::std::integral char_type>
struct basic_bsd_arc4random
{
public:
using input_char_type = char_type;
constexpr void close() noexcept
{}
};

template <::std::integral char_type>
inline constexpr basic_bsd_arc4random<char_type> input_stream_ref_define(basic_bsd_arc4random<char_type> barc4) noexcept
{
return barc4;
}

using bsd_arc4random = basic_bsd_arc4random<char>;

template <::std::integral char_type>
inline constexpr void input_stream_require_secure_clear_define(basic_bsd_arc4random<char_type>) noexcept
{
}

#if !defined(__GLIBC__) || (defined(__GLIBC__) && __GLIBC_PREREQ(2,36))
namespace details
{

inline void bsd_arc4random_read_all_bytes_define_impl(::std::byte *first, ::std::byte *last) noexcept
{
::fast_io::noexcept_call(arc4random_buf, first, static_cast<::std::size_t>(last-first));
}

}

template <::std::integral char_type>
inline void read_all_bytes_underflow_define(basic_bsd_arc4random<char_type>, ::std::byte *first,
::std::byte *last) noexcept
{
::fast_io::details::bsd_arc4random_read_all_bytes_define_impl(first, last);
}

#else

namespace details
{
[[__gnu__::__weak__]]
extern void glibc_arc4random_buf(void *, size_t) noexcept __asm__("arc4random_buf");

inline ::std::byte* bsd_arc4random_read_some_bytes_define_impl(::std::byte* first, ::std::byte* last)
{
constexpr auto *glibc_arc4random_bufptr{::fast_io::details::glibc_arc4random_buf};
if (glibc_arc4random_bufptr==nullptr)
{
return ::fast_io::details::linux_getrandom_read_some_bytes_define_impl(0,first,last);
}
else
{
glibc_arc4random_bufptr(first,static_cast<::std::size_t>(last-first));
return last;
}
}
}

template <::std::integral char_type>
inline ::std::byte* read_some_bytes_underflow_define(basic_bsd_arc4random<char_type>, ::std::byte *first,
::std::byte *last)
{
return ::fast_io::details::bsd_arc4random_read_some_bytes_define_impl(first, last);
}

#endif

}
5 changes: 5 additions & 0 deletions include/fast_io_hosted/white_hole/white_hole.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ concept minimum_buffer_input_stream_require_size_impl =
(!defined(__linux__) && __has_include(<sys/random.h>))) && !defined(__wasi__) && !defined(__DARWIN_C_LEVEL)
#include "linux_getrandom.h"
#endif
#if ((defined(__linux__) && defined(__GLIBC__)) || (defined(__BSD_VISIBLE) && !defined(__DARWIN_C_LEVEL))) && 0
#include "bsd_arc4random.h"
#endif
#include "posix_dev_urandom.h"

namespace fast_io
Expand Down Expand Up @@ -73,6 +76,8 @@ using basic_native_white_hole =
#endif
#elif defined(__wasi__)
basic_wasi_random_get<char_type>;
#elif (((defined(__linux__) && defined(__GLIBC__)) || (defined(__BSD_VISIBLE) && !defined(__DARWIN_C_LEVEL)))) && 0
basic_bsd_arc4random<char_type>;
#elif (defined(__linux__) && defined(__NR_getrandom)) || \
(!defined(__linux__) && __has_include(<sys/random.h>)) && !defined(__DARWIN_C_LEVEL)
basic_linux_getrandom<char_type>;
Expand Down
2 changes: 0 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
WE REFUSE TO SUPPORT C++20 MODULE. FUCK YOU WG21 FOR THIS BS.

# fast_io

fast_io represents a cutting-edge input/output (I/O) library for C++20, designed to achieve [exceptional speed](readme.md#Benchmarks). Its primary purpose is to supersede the widely used `<iostream>` and `<cstdio>` libraries. This header-only library is distributed under the permissive [MIT license](license.txt), simplifying integration into any project. However, its utilization mandates a C++20 compiler with support for concepts.
Expand Down
21 changes: 12 additions & 9 deletions support.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
## Compiler Support
- GCC >= 15
- Clang >= 19
- REMOVE MSVC SUPPORT SINCE IT SUPPORTS MODULE
- Clang >= 20
- MSVC

## C++ standard library support
- GCC libstdc++
- LLVM libc++
- MSVC STL

## Architecture Support
- alpha
## Mainstream Architecture Support
- i686
- x86_64
- arm
- aarch64
- riscv
- riscv64
- powerpc64
- wasm32-wasi
- wasm64-wasi
- loongarch64

## Architecture Support
- alpha
- riscv (RISC-V is crap. Stop using it)
- riscv64
- powerpc64
- mips-abi32
- mips-abin32
- mips-abi64
- avr
- ia64
- loongarch64
- xtensa-esp32
- All other architectures should work, they just aren't tested due to time not being infinite.

Expand Down Expand Up @@ -113,7 +115,7 @@ On Windows 95 or 95 Plus! you can enable `-O3` but not `-Ofast`. You'll also nee
- Universal CRT
- Universal CRT with MSVC debugging
- Wine's MSVCRT
- Wine's UCRT 9.11+
- Wine's UCRT 9.13+

See wine bug [PR53960](https://gitlab.winehq.org/wine/wine/-/merge_requests/5752)

Expand Down Expand Up @@ -147,3 +149,4 @@ See wine bug [PR53960](https://gitlab.winehq.org/wine/wine/-/merge_requests/5752
- LLVM Address Sanitizer
- Full freestanding support (which means we do not have any headers besides freestanding headers. Tested with GCC's --disable-hosted-libstdcxx without any libc, including newlib)
- Pintool support
- ARM MTE support

0 comments on commit 2ba00f9

Please sign in to comment.