diff --git a/src/simd/aligned_allocator.h b/src/simd/aligned_allocator.h index 5d600f5..e03435a 100644 --- a/src/simd/aligned_allocator.h +++ b/src/simd/aligned_allocator.h @@ -61,32 +61,32 @@ inline void aligned_free(void* ptr) { } // 对齐分配器模板类 -template +template class aligned_allocator { public: - using value_type = type; - using pointer = type*; - using const_pointer = const type*; - using reference = type&; - using const_reference = const type&; + using value_type = T; + using pointer = T*; + using const_pointer = const T*; + using reference = T&; + using const_reference = const T&; using size_type = std::size_t; using difference_type = std::ptrdiff_t; - template + template struct rebind { - using other = aligned_allocator; + using other = aligned_allocator; }; aligned_allocator() noexcept = default; - template - aligned_allocator(const aligned_allocator&) noexcept {} + template + aligned_allocator(const aligned_allocator&) noexcept {} auto allocate(size_type n) -> pointer { if (n == 0) return nullptr; - size_type size = n * sizeof(type); - void* ptr = aligned_malloc(size, alignment); + size_type size = n * sizeof(T); + void* ptr = aligned_malloc(size, Alignment); if (!ptr) { throw std::bad_alloc(); @@ -99,44 +99,44 @@ public: aligned_free(p); } - template - void construct(u* p, args&&... in_args) { - ::new(static_cast(p)) u(std::forward(in_args)...); + template + void construct(U* p, Args&&... args) { + ::new(static_cast(p)) U(std::forward(args)...); } - template - void destroy(u* p) { + template + void destroy(U* p) { p->~u(); } static auto max_size() noexcept { - return std::numeric_limits::max() / sizeof(type); + return std::numeric_limits::max() / sizeof(T); } }; -template -bool operator==(const aligned_allocator&, const aligned_allocator&) noexcept { - return a1 == a2; +template +bool operator==(const aligned_allocator&, const aligned_allocator&) noexcept { + return A1 == A2; } -template -bool operator!=(const aligned_allocator&, const aligned_allocator&) noexcept { - return a1 != a2; +template +bool operator!=(const aligned_allocator&, const aligned_allocator&) noexcept { + return A1 != A2; } // 类型别名,方便使用不同对齐方式的分配器 -template -using sse_aligned_allocator = aligned_allocator; -template -using avx_aligned_allocator = aligned_allocator; -template -using avx512_aligned_allocator = aligned_allocator; -template -using cache_aligned_allocator = aligned_allocator; +template +using sse_aligned_allocator = aligned_allocator; +template +using avx_aligned_allocator = aligned_allocator; +template +using avx512_aligned_allocator = aligned_allocator; +template +using cache_aligned_allocator = aligned_allocator; -template +template auto is_aligned(void* ptr) -> bool { - return (reinterpret_cast(ptr) % alignment) == 0; + return (reinterpret_cast(ptr) % Alignment) == 0; } inline auto is_aligned(const void* ptr, size_t alignment) -> bool { @@ -147,14 +147,14 @@ inline auto align_size(size_t size, size_t alignment) -> size_t { return (size + alignment - 1) & ~(alignment - 1); } -template +template auto align_pointer(void* ptr) -> void* { const auto addr = reinterpret_cast(ptr); - const auto aligned_addr = (addr + alignment - 1) & ~(alignment - 1); + const auto aligned_addr = (addr + Alignment - 1) & ~(Alignment - 1); return reinterpret_cast(aligned_addr); } -template +template class aligned_buffer { public: aligned_buffer() = default; @@ -174,7 +174,7 @@ public: return; } - data_ = static_cast(aligned_malloc(new_size * sizeof(type), alignment)); + data_ = static_cast(aligned_malloc(new_size * sizeof(T), Alignment)); if (!data_) { throw std::bad_alloc(); } @@ -182,9 +182,9 @@ public: size_ = new_size; // 对于非POD类型,需要构造对象 - if constexpr (!std::is_trivially_constructible_v) { + if constexpr (!std::is_trivially_constructible_v) { for (size_t i = 0; i < size_; ++i) { - new(&data_[i]) type(); + new(&data_[i]) T(); } } } @@ -193,7 +193,7 @@ public: if (!data_) return; // 对于非POD类型,需要析构对象 - if constexpr (!std::is_trivially_destructible_v) { + if constexpr (!std::is_trivially_destructible_v) { for (size_t i = 0; i < size_; ++i) { data_[i].~T(); } @@ -223,10 +223,10 @@ public: auto end() const noexcept { return data_ + size_; } [[nodiscard]] auto is_properly_aligned() const noexcept -> bool { - return is_aligned(data_); + return is_aligned(data_); } private: - type* data_ = nullptr; + T* data_ = nullptr; size_t size_ = 0; };