diff --git a/hipamd/include/hip/amd_detail/amd_hip_vector_types.h b/hipamd/include/hip/amd_detail/amd_hip_vector_types.h index 88943ab962..dfd3b39ab6 100644 --- a/hipamd/include/hip/amd_detail/amd_hip_vector_types.h +++ b/hipamd/include/hip/amd_detail/amd_hip_vector_types.h @@ -133,261 +133,6 @@ template struct is_scalar : public integral_constant struct Scalar_accessor; - } // Namespace hip_impl. - - namespace std { - template - struct is_integral> - : std::is_integral {}; - template - struct is_floating_point> - : std::is_floating_point {}; - } // Namespace std. - - namespace hip_impl { - template - struct Scalar_accessor { - struct Address { - const Scalar_accessor* p; - - __HOST_DEVICE__ - operator const T*() const noexcept { - return &reinterpret_cast(p)[idx]; - } - __HOST_DEVICE__ - operator const T*() const volatile noexcept { - return &reinterpret_cast(p)[idx]; - } - __HOST_DEVICE__ - operator T*() noexcept { - return &reinterpret_cast( - const_cast(p))[idx]; - } - __HOST_DEVICE__ - operator T*() volatile noexcept { - return &reinterpret_cast( - const_cast(p))[idx]; - } - }; - - friend - inline - std::ostream& operator<<(std::ostream& os, - const Scalar_accessor& x) noexcept { - return os << x.data[idx]; - } - friend - inline - std::istream& operator>>(std::istream& is, - Scalar_accessor& x) noexcept { - T tmp; - is >> tmp; - x.data[idx] = tmp; - - return is; - } - - // Idea from https://t0rakka.silvrback.com/simd-scalar-accessor - /* Copyright (c) 2012-2019 Twilight Finland 3D Oy Ltd. All rights reserved. - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution.*/ - Vector data; - - __HOST_DEVICE__ - operator T() const noexcept { return data[idx]; } - __HOST_DEVICE__ - operator T() const volatile noexcept { return data[idx]; } - -#ifdef __HIP_ENABLE_VECTOR_SCALAR_ACCESSORY_ENUM_CONVERSION__ - // The conversions to enum are fairly ghastly, but unfortunately used in - // some pre-existing, difficult to modify, code. - template< - typename U, - typename std::enable_if< - !std::is_same{} && - std::is_enum{} && - std::is_convertible< - T, typename std::enable_if::value, std::underlying_type>::type::type>{}>::type* = nullptr> - __HOST_DEVICE__ - operator U() const noexcept { return static_cast(data[idx]); } - template< - typename U, - typename std::enable_if< - !std::is_same{} && - std::is_enum{} && - std::is_convertible< - T, typename std::enable_if::value, std::underlying_type>::type::type>{}>::type* = nullptr> - __HOST_DEVICE__ - operator U() const volatile noexcept { return static_cast(data[idx]); } -#endif - - __HOST_DEVICE__ - operator T&() noexcept { - return reinterpret_cast< - T (&)[sizeof(Vector) / sizeof(T)]>(data)[idx]; - } - __HOST_DEVICE__ - operator volatile T&() volatile noexcept { - return reinterpret_cast< - volatile T (&)[sizeof(Vector) / sizeof(T)]>(data)[idx]; - } - - __HOST_DEVICE__ - Address operator&() const noexcept { return Address{this}; } - - __HOST_DEVICE__ - Scalar_accessor& operator=(const Scalar_accessor& x) noexcept { - data[idx] = x.data[idx]; - - return *this; - } - __HOST_DEVICE__ - Scalar_accessor& operator=(T x) noexcept { - data[idx] = x; - - return *this; - } - __HOST_DEVICE__ - volatile Scalar_accessor& operator=(T x) volatile noexcept { - data[idx] = x; - - return *this; - } - - __HOST_DEVICE__ - Scalar_accessor& operator++() noexcept { - ++data[idx]; - return *this; - } - __HOST_DEVICE__ - T operator++(int) noexcept { - auto r{data[idx]}; - ++data[idx]; - return *this; - } - __HOST_DEVICE__ - Scalar_accessor& operator--() noexcept { - --data[idx]; - return *this; - } - __HOST_DEVICE__ - T operator--(int) noexcept { - auto r{data[idx]}; - --data[idx]; - return *this; - } - - // TODO: convertibility is too restrictive, constraint should be on - // the operator being invocable with a value of type U. - template< - typename U, - typename std::enable_if< - std::is_convertible{}>::type* = nullptr> - __HOST_DEVICE__ - Scalar_accessor& operator+=(U x) noexcept { - data[idx] += x; - return *this; - } - template< - typename U, - typename std::enable_if< - std::is_convertible{}>::type* = nullptr> - __HOST_DEVICE__ - Scalar_accessor& operator-=(U x) noexcept { - data[idx] -= x; - return *this; - } - - template< - typename U, - typename std::enable_if< - std::is_convertible{}>::type* = nullptr> - __HOST_DEVICE__ - Scalar_accessor& operator*=(U x) noexcept { - data[idx] *= x; - return *this; - } - template< - typename U, - typename std::enable_if< - std::is_convertible{}>::type* = nullptr> - __HOST_DEVICE__ - Scalar_accessor& operator/=(U x) noexcept { - data[idx] /= x; - return *this; - } - template< - typename U = T, - typename std::enable_if{} && - std::is_integral{}>::type* = nullptr> - __HOST_DEVICE__ - Scalar_accessor& operator%=(U x) noexcept { - data[idx] %= x; - return *this; - } - - template< - typename U = T, - typename std::enable_if{} && - std::is_integral{}>::type* = nullptr> - __HOST_DEVICE__ - Scalar_accessor& operator>>=(U x) noexcept { - data[idx] >>= x; - return *this; - } - template< - typename U = T, - typename std::enable_if{} && - std::is_integral{}>::type* = nullptr> - __HOST_DEVICE__ - Scalar_accessor& operator<<=(U x) noexcept { - data[idx] <<= x; - return *this; - } - template< - typename U = T, - typename std::enable_if{} && - std::is_integral{}>::type* = nullptr> - __HOST_DEVICE__ - Scalar_accessor& operator&=(U x) noexcept { - data[idx] &= x; - return *this; - } - template< - typename U = T, - typename std::enable_if{} && - std::is_integral{}>::type* = nullptr> - __HOST_DEVICE__ - Scalar_accessor& operator|=(U x) noexcept { - data[idx] |= x; - return *this; - } - template< - typename U = T, - typename std::enable_if{} && - std::is_integral{}>::type* = nullptr> - __HOST_DEVICE__ - Scalar_accessor& operator^=(U x) noexcept { - data[idx] ^= x; - return *this; - } - }; - inline constexpr unsigned int next_pot(unsigned int x) { @@ -404,13 +149,9 @@ template struct is_scalar : public integral_constant x; -#endif }; using value_type = T; @@ -429,22 +170,8 @@ template struct is_scalar : public integral_constant @@ -457,15 +184,10 @@ template struct is_scalar : public integral_constant x; - hip_impl::Scalar_accessor y; -#endif }; using value_type = T; @@ -487,23 +209,8 @@ template struct is_scalar : public integral_constant @@ -701,19 +408,12 @@ template struct is_scalar : public integral_constant x; - hip_impl::Scalar_accessor y; - hip_impl::Scalar_accessor z; - hip_impl::Scalar_accessor w; -#endif }; using value_type = T; @@ -735,25 +435,8 @@ template struct is_scalar : public integral_constant