/* * SPDX-FileCopyrightText: 2022 L. E. Segovia * * SPDX-License-Identifier: BSD-3-Clause */ #ifndef KIS_XSIMD_GENERIC_DETAILS_DECL_HPP #define KIS_XSIMD_GENERIC_DETAILS_DECL_HPP #include #include namespace xsimd { /*********************** * Truncate-initialize * ***********************/ template batch truncate_to_type(batch const &self) noexcept; /************************** * Masked initializations * **************************/ // Mask to 0 elements of a vector. template inline auto set_zero(const batch &src, const batch_bool &mask) noexcept; // Mask to 1 elements of a vector. template inline auto set_one(const batch &src, const batch_bool &mask) noexcept; /********************************** * Sign-extending unaligned loads * **********************************/ // Load `T::size` values from the array of `T2` elements. template inline T load_and_extend(const T2 *src) noexcept; /************************************************* * Type-inferred, auto-aligned memory allocation * *************************************************/ // Allocate size bytes of memory aligned to `batch::alignment()`. template inline T *aligned_malloc(size_t size) noexcept; // Allocate memory for `sz` T items, aligned to the selected architecture's // alignment. template inline T *vector_aligned_malloc(size_t sz) noexcept; // Free allocated memory, hiding the `const_cast` if necessary. template inline void vector_aligned_free(const T *ptr) noexcept; /**************** * Interleaving * ****************/ // Return the tuple of interleaved batches `a` and `b`. // First element is the low half, second is the upper half. template inline std::pair interleave(const V &a, const V &b) noexcept; template inline xsimd::batch pow2(xsimd::batch const &self) noexcept; namespace kernel { namespace detail { /***************************** * Helpers: unary applicator * *****************************/ template inline batch apply_with_value(F &&func, batch const &self) noexcept { alignas(A::alignment()) std::array::size> self_buffer; self.store_aligned(self_buffer.data()); for (std::size_t i = 0; i < batch::size; ++i) { self_buffer[i] = func(self_buffer[i]); } return batch::load_aligned(self_buffer.data()); } template inline batch apply_with_index_and_value(F &&func, batch const &self) noexcept { alignas(A::alignment()) std::array::size> self_buffer; self.store_aligned(self_buffer.data()); for (std::size_t i = 0; i < batch::size; ++i) { self_buffer[i] = func(i, self_buffer[i]); } return batch::load_aligned(self_buffer.data()); } } // namespace kernel } // namespace detail }; // namespace xsimd #endif // KIS_XSIMD_GENERIC_DETAILS_DECL_HPP