|
||||
File indexing completed on 2025-01-30 10:25:51
0001 /* This file is part of the Vc library. {{{ 0002 Copyright © 2014-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_UTILITY_H_ 0029 #define VC_COMMON_UTILITY_H_ 0030 0031 #include "macros.h" 0032 0033 namespace Vc_VERSIONED_NAMESPACE 0034 { 0035 namespace Common 0036 { 0037 /** 0038 * \internal 0039 * Returns the next power of 2 larger than or equal to \p x. 0040 */ 0041 template <size_t x, bool = (x & (x - 1)) == 0> struct NextPowerOfTwo; 0042 template <size_t x> 0043 struct NextPowerOfTwo<x, true> : public std::integral_constant<size_t, x> { 0044 }; 0045 template <size_t x> 0046 struct NextPowerOfTwo<x, false> 0047 : public std::integral_constant< 0048 size_t, NextPowerOfTwo<(x | (x >> 1) | (x >> 2) | (x >> 5)) + 1>::value> { 0049 }; 0050 0051 /** 0052 * \internal 0053 * Enforce an upper bound to an alignment value. This is necessary because some compilers 0054 * implement such an upper bound and emit a warning if it is encountered. 0055 */ 0056 template <size_t A> 0057 struct BoundedAlignment : public std::integral_constant<size_t, 0058 #if defined Vc_MSVC || defined Vc_GCC 0059 ((A - 1) & 0060 #ifdef Vc_MSVC 0061 31 0062 #elif defined __AVX__ 0063 255 0064 #else 0065 127 0066 #endif 0067 ) + 1 0068 #else 0069 A 0070 #endif 0071 > { 0072 }; 0073 0074 /** 0075 * \internal 0076 * Returns the size of the left/first SimdArray member. 0077 */ 0078 template <std::size_t N> static constexpr std::size_t left_size() 0079 { 0080 return Common::NextPowerOfTwo<(N + 1) / 2>::value; 0081 } 0082 /** 0083 * \internal 0084 * Returns the size of the right/second SimdArray member. 0085 */ 0086 template <std::size_t N> static constexpr std::size_t right_size() 0087 { 0088 return N - left_size<N>(); 0089 } 0090 0091 } // namespace Common 0092 } // namespace Vc 0093 0094 #endif // VC_COMMON_UTILITY_H_ 0095 0096 // 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 |