Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-08-28 09:11:38

0001 /***************************************************************************
0002  * Copyright (c) Johan Mabille, Sylvain Corlay, Wolf Vollprecht and         *
0003  * Martin Renou                                                             *
0004  * Copyright (c) QuantStack                                                 *
0005  * Copyright (c) Serge Guelton                                              *
0006  *                                                                          *
0007  * Distributed under the terms of the BSD 3-Clause License.                 *
0008  *                                                                          *
0009  * The full license is in the file LICENSE, distributed with this software. *
0010  ****************************************************************************/
0011 
0012 #ifndef XSIMD_ALIGNMENT_HPP
0013 #define XSIMD_ALIGNMENT_HPP
0014 
0015 #include "../types/xsimd_utils.hpp"
0016 #include "xsimd_aligned_allocator.hpp"
0017 
0018 namespace xsimd
0019 {
0020     /**
0021      * @struct aligned_mode
0022      * @brief tag for load and store of aligned memory.
0023      */
0024     struct aligned_mode
0025     {
0026     };
0027 
0028     /**
0029      * @struct unaligned_mode
0030      * @brief tag for load and store of unaligned memory.
0031      */
0032     struct unaligned_mode
0033     {
0034     };
0035 
0036     /***********************
0037      * Allocator alignment *
0038      ***********************/
0039 
0040     template <class A>
0041     struct allocator_alignment
0042     {
0043         using type = unaligned_mode;
0044     };
0045 
0046     template <class T, size_t N>
0047     struct allocator_alignment<aligned_allocator<T, N>>
0048     {
0049         using type = aligned_mode;
0050     };
0051 
0052     template <class A>
0053     using allocator_alignment_t = typename allocator_alignment<A>::type;
0054 
0055     /***********************
0056      * container alignment *
0057      ***********************/
0058 
0059     template <class C, class = void>
0060     struct container_alignment
0061     {
0062         using type = unaligned_mode;
0063     };
0064 
0065     template <class C>
0066     struct container_alignment<C, detail::void_t<typename C::allocator_type>>
0067     {
0068         using type = allocator_alignment_t<typename C::allocator_type>;
0069     };
0070 
0071     template <class C>
0072     using container_alignment_t = typename container_alignment<C>::type;
0073 
0074     /*********************
0075      * alignment checker *
0076      *********************/
0077 
0078     /**
0079      * Checks whether pointer \c ptr is aligned according the alignment
0080      * requirements of \c Arch.
0081      * @return true if the alignment requirements are met
0082      */
0083     template <class Arch = default_arch>
0084     XSIMD_INLINE bool is_aligned(void const* ptr)
0085     {
0086         return (reinterpret_cast<uintptr_t>(ptr) % static_cast<uintptr_t>(Arch::alignment())) == 0;
0087     }
0088 
0089 }
0090 
0091 #endif