|
||||
File indexing completed on 2025-01-30 10:25:45
0001 /* This file is part of the Vc library. {{{ 0002 Copyright © 2015 Matthias Kretz <kretz@kde.org> 0003 0004 Redistribution and use in source and binary forms, with or without 0005 modification, are permitted provided that the following conditions are met: 0006 * Redistributions of source code must retain the above copyright 0007 notice, this list of conditions and the following disclaimer. 0008 * Redistributions in binary form must reproduce the above copyright 0009 notice, this list of conditions and the following disclaimer in the 0010 documentation and/or other materials provided with the distribution. 0011 * Neither the names of contributing organizations nor the 0012 names of its contributors may be used to endorse or promote products 0013 derived from this software without specific prior written permission. 0014 0015 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 0016 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 0017 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 0018 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY 0019 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 0020 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 0021 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 0022 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0023 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 0024 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0025 0026 }}}*/ 0027 0028 #ifndef VC_COMMON_ALIGNEDBASE_H_ 0029 #define VC_COMMON_ALIGNEDBASE_H_ 0030 0031 #include "types.h" 0032 #include "macros.h" 0033 0034 namespace Vc_VERSIONED_NAMESPACE 0035 { 0036 namespace Detail 0037 { 0038 /**\internal 0039 * Break the recursion of the function below. 0040 */ 0041 template <typename T> constexpr T max(T a) { return a; } 0042 /**\internal 0043 * \returns the maximum of all specified arguments. 0044 */ 0045 template <typename T, typename... Ts> constexpr T max(T a, T b, Ts... rest) 0046 { 0047 return a > b ? max(a, rest...) : max(b, rest...); 0048 } 0049 } // namespace Detail 0050 namespace Common 0051 { 0052 template <std::size_t> Vc_INTRINSIC void *aligned_malloc(std::size_t); 0053 Vc_ALWAYS_INLINE void free(void *); 0054 } // namespace Common 0055 0056 /** 0057 * \ingroup Utilities 0058 * 0059 * Helper class to ensure a given alignment. 0060 * 0061 * This class reimplements the \c new and \c delete operators to align objects allocated 0062 * on the heap suitably with the specified alignment \c Alignment. 0063 * 0064 * \see Vc::VectorAlignedBase 0065 * \see Vc::MemoryAlignedBase 0066 */ 0067 template <std::size_t Alignment> struct alignas(Alignment) AlignedBase 0068 { 0069 Vc_FREE_STORE_OPERATORS_ALIGNED(Alignment); 0070 }; 0071 0072 /** 0073 * \ingroup Utilities 0074 * 0075 * Helper type to ensure suitable alignment for any Vc::Vector<T> type (using the default 0076 * VectorAbi). 0077 * 0078 * This class reimplements the \c new and \c delete operators to align objects allocated 0079 * on the heap suitably for objects of Vc::Vector<T> type. This is necessary since the 0080 * standard \c new operator does not adhere to the alignment requirements of the type. 0081 * 0082 * \see Vc::VectorAlignedBaseT 0083 * \see Vc::MemoryAlignedBase 0084 * \see Vc::AlignedBase 0085 */ 0086 using VectorAlignedBase = AlignedBase< 0087 Detail::max(alignof(Vector<float>), alignof(Vector<double>), alignof(Vector<ullong>), 0088 alignof(Vector<llong>), alignof(Vector<ulong>), alignof(Vector<long>), 0089 alignof(Vector<uint>), alignof(Vector<int>), alignof(Vector<ushort>), 0090 alignof(Vector<short>), alignof(Vector<uchar>), alignof(Vector<schar>))>; 0091 0092 /** 0093 * \ingroup Utilities 0094 * Variant of the above type ensuring suitable alignment only for the specified vector 0095 * type \p V. 0096 * 0097 * \see Vc::VectorAlignedBase 0098 * \see Vc::MemoryAlignedBaseT 0099 */ 0100 template <typename V> using VectorAlignedBaseT = AlignedBase<alignof(V)>; 0101 0102 /** 0103 * \ingroup Utilities 0104 * 0105 * Helper class to ensure suitable alignment for arrays of scalar objects for any 0106 * Vc::Vector<T> type (using the default VectorAbi). 0107 * 0108 * This class reimplements the \c new and \c delete operators to align objects allocated 0109 * on the heap suitably for arrays of type \p Vc::Vector<T>::EntryType. Subsequent load 0110 * and store operations are safe to use the aligned variant. 0111 * 0112 * \see Vc::MemoryAlignedBaseT 0113 * \see Vc::VectorAlignedBase 0114 * \see Vc::AlignedBase 0115 */ 0116 using MemoryAlignedBase = AlignedBase< 0117 Detail::max(Vector<float>::MemoryAlignment, Vector<double>::MemoryAlignment, 0118 Vector<ullong>::MemoryAlignment, Vector<llong>::MemoryAlignment, 0119 Vector<ulong>::MemoryAlignment, Vector<long>::MemoryAlignment, 0120 Vector<uint>::MemoryAlignment, Vector<int>::MemoryAlignment, 0121 Vector<ushort>::MemoryAlignment, Vector<short>::MemoryAlignment, 0122 Vector<uchar>::MemoryAlignment, Vector<schar>::MemoryAlignment)>; 0123 0124 /** 0125 * \ingroup Utilities 0126 * Variant of the above type ensuring suitable alignment only for the specified vector 0127 * type \p V. 0128 * 0129 * \see Vc::MemoryAlignedBase 0130 * \see Vc::VectorAlignedBaseT 0131 */ 0132 template <typename V> using MemoryAlignedBaseT = AlignedBase<V::MemoryAlignment>; 0133 } 0134 0135 #endif // VC_COMMON_ALIGNEDBASE_H_ 0136 0137 // vim: foldmethod=marker
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |