Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/realworld-perf-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- name: Compare build time (PR vs main)
run: >-
python3 scripts/compare_realworld.py ${{ matrix.project }}
--time-budget 5m --max-reps 5
--time-budget 10m --max-reps 10
| tee diff.md
- name: Post realworld perf diff as PR comment
uses: marocchino/sticky-pull-request-comment@v3
Expand Down
42 changes: 39 additions & 3 deletions include/__psychicstd_char_traits
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,25 @@ template <typename Char> struct char_traits {
size_t n) noexcept {
if (!n)
return dst;
if (__builtin_is_constant_evaluated()) {
for (size_t i = 0; i < n; ++i)
dst[i] = src[i];
return dst;
}
return (char_type*)__builtin_memcpy(dst, src, n * sizeof(char_type));
}
static constexpr char_type* move(char_type* dst, const char_type* src,
size_t n) noexcept {
if (__builtin_is_constant_evaluated()) {
if (dst < src) {
for (size_t i = 0; i < n; ++i)
dst[i] = src[i];
} else if (dst > src) {
for (size_t i = n; i-- > 0;)
dst[i] = src[i];
}
return dst;
}
return (char_type*)__builtin_memmove(dst, src, n * sizeof(char_type));
}
static constexpr const char_type* find(const char_type* s, size_t n,
Expand Down Expand Up @@ -76,6 +91,15 @@ template <> struct char_traits<char> {
}
static constexpr int compare(const char* s1, const char* s2,
size_t n) noexcept {
if (__builtin_is_constant_evaluated()) {
for (size_t i = 0; i < n; ++i) {
if ((unsigned char)s1[i] < (unsigned char)s2[i])
return -1;
if ((unsigned char)s1[i] > (unsigned char)s2[i])
return 1;
}
return 0;
}
return __builtin_memcmp(s1, s2, n);
}
static constexpr size_t length(const char* s) noexcept {
Expand All @@ -89,10 +113,12 @@ template <> struct char_traits<char> {
#pragma GCC diagnostic ignored "-Wrestrict"
#endif
static constexpr char* copy(char* d, const char* s, size_t n) noexcept {
if (n) {
return (char*)__builtin_memcpy(d, s, n);
if (__builtin_is_constant_evaluated()) {
for (size_t i = 0; i < n; ++i)
d[i] = s[i];
return d;
}
return d;
return n ? (char*)__builtin_memcpy(d, s, n) : d;
}
#ifndef __clang__
#pragma GCC diagnostic pop
Expand All @@ -102,6 +128,16 @@ template <> struct char_traits<char> {
#pragma GCC diagnostic ignored "-Wrestrict"
#endif
static constexpr char* move(char* d, const char* s, size_t n) noexcept {
if (__builtin_is_constant_evaluated()) {
if (d < s) {
for (size_t i = 0; i < n; ++i)
d[i] = s[i];
} else if (d > s) {
for (size_t i = n; i-- > 0;)
d[i] = s[i];
}
return d;
}
return (char*)__builtin_memmove(d, s, n);
}
#ifndef __clang__
Expand Down
22 changes: 16 additions & 6 deletions include/__psychicstd_contiguous_iterator
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,31 @@ template <typename T> struct __vec_iter {
constexpr T& operator*() const noexcept { return *ptr_; }
constexpr T* operator->() const noexcept { return ptr_; }
constexpr T& operator[](ptrdiff_t n) const noexcept { return ptr_[n]; }
constexpr __vec_iter& operator++() noexcept { return ++ptr_, *this; }
constexpr __vec_iter& operator++() noexcept {
++ptr_;
return *this;
}
constexpr __vec_iter operator++(int) noexcept {
auto t = *this;
return ++ptr_, t;
++ptr_;
return t;
}
constexpr __vec_iter& operator--() noexcept {
--ptr_;
return *this;
}
constexpr __vec_iter& operator--() noexcept { return --ptr_, *this; }
constexpr __vec_iter operator--(int) noexcept {
auto t = *this;
return --ptr_, t;
--ptr_;
return t;
}
constexpr __vec_iter& operator+=(ptrdiff_t n) noexcept {
return ptr_ += n, *this;
ptr_ += n;
return *this;
}
constexpr __vec_iter& operator-=(ptrdiff_t n) noexcept {
return ptr_ -= n, *this;
ptr_ -= n;
return *this;
}
constexpr __vec_iter operator+(ptrdiff_t n) const noexcept {
return __vec_iter{ptr_ + n};
Expand Down
8 changes: 4 additions & 4 deletions include/compare
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,12 @@ constexpr bool is_lteq(partial_ordering v) noexcept { return v <= 0; }
constexpr bool is_gteq(partial_ordering v) noexcept { return v >= 0; }

// three_way_comparable concept
template <typename T, typename U = T>
template <typename T, typename Cat = partial_ordering>
concept three_way_comparable =
requires(const __psychicstd_detail::remove_reference_t<T>& a,
const __psychicstd_detail::remove_reference_t<U>& b) {
a <=> b;
b <=> a;
const __psychicstd_detail::remove_reference_t<T>& b) {
static_cast<Cat>(a <=> b);
static_cast<Cat>(b <=> a);
};

template <typename T, typename U>
Expand Down
17 changes: 15 additions & 2 deletions include/memory
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ inline void* align(size_t alignment, size_t size, void*& ptr,
}

namespace __detail {
template <typename Ptr, typename = void> struct __pointer_element;
template <template <typename, typename...> class Ptr, typename T,
typename... Args>
struct __pointer_element<Ptr<T, Args...>, void> {
using type = T;
};
template <typename Ptr>
struct __pointer_element<Ptr, void_t<typename Ptr::element_type>> {
using type = typename Ptr::element_type;
};

template <typename Ptr, typename U, typename = void> struct __pointer_rebind {
using type = U*;
};
Expand All @@ -38,11 +49,13 @@ template <typename T> const T* addressof(const T&&) = delete;
// pointer_traits
template <typename Ptr> struct pointer_traits {
using pointer = Ptr;
using element_type = typename Ptr::element_type;
using element_type = typename __detail::__pointer_element<Ptr>::type;
using difference_type = ptrdiff_t;
template <typename U>
using rebind = typename __detail::__pointer_rebind<Ptr, U>::type;
static pointer pointer_to(element_type& r) { return Ptr::pointer_to(r); }
static constexpr pointer pointer_to(element_type& r) {
return Ptr::pointer_to(r);
}
};
template <typename T> struct pointer_traits<T*> {
using pointer = T*;
Expand Down
4 changes: 4 additions & 0 deletions include/new
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
#include <cstddef>
#include <exception>

namespace std {
enum class align_val_t : size_t {};
}

// placement new is a language built-in; the header just declares the
// signatures. global operator new/delete are provided by the runtime
// (libstdc++/libc).
Expand Down
Loading
Loading