Revert "Revert "Switch over to using native vector types, for better codegen. Remove noise.""

This reverts commit d137271083.
이 커밋은 다음에 포함됨:
Alex Voicu가 2018-06-16 22:59:36 +01:00를 커밋했습니다
1 부모 edab13da7d
커밋 fa370fcf19
5 파일이 변경됨
+488 -15986

검색과 일치하는 파일 없음

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다. Diff 로드
파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다. Diff 로드
+105
파일 보기
@@ -0,0 +1,105 @@
/*
Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#pragma once
#include <type_traits>
template<bool b, typename T = void>
using Enable_if_t = typename std::enable_if<b, T>::type;
__host__ __device__
std::false_type is_vec4(...);
__host__ __device__
std::false_type is_vec3(...);
__host__ __device__
std::false_type is_vec2(...);
__host__ __device__
std::false_type is_vec1(...);
template<typename T>
__host__ __device__
auto is_vec4(const T&) -> decltype(std::declval<T>().xyzw, std::true_type{});
template<
typename T, Enable_if_t<decltype(!is_vec4(std::declval<T>())){}>* = nullptr>
__host__ __device__
auto is_vec3(const T&) -> decltype(std::declval<T>().xyz, std::true_type{});
template<
typename T,
Enable_if_t<
!decltype(is_vec4(std::declval<T>())){} &&
!decltype(is_vec3(std::declval<T>())){}>* = nullptr>
__host__ __device__
auto is_vec2(const T&) -> decltype(std::declval<T>().xy, std::true_type{});
template<
typename T,
Enable_if_t<
!decltype(is_vec4(std::declval<T>())){} &&
!decltype(is_vec3(std::declval<T>())){} &&
!decltype(is_vec2(std::declval<T>())){}>* = nullptr>
__host__ __device__
auto is_vec1(const T&) -> decltype(std::declval<T>().x, std::true_type{});
template<typename T, int dimension>
__host__ __device__
constexpr
bool is_vec() {
return (dimension == 1) ? decltype(is_vec1(std::declval<T>())){} :
((dimension == 2) ? decltype(is_vec2(std::declval<T>())){} :
((dimension == 3) ? decltype(is_vec3(std::declval<T>())){} :
decltype(is_vec4(std::declval<T>())){}));
}
template<typename T, typename U, Enable_if_t<is_vec<T, 1>()>* = nullptr>
__host__ __device__
inline
bool cmp(const T& x, U expected) {
const auto r = x == T(expected);
return r.x != 0;
}
template<typename T, typename U, Enable_if_t<is_vec<T, 2>()>* = nullptr>
__host__ __device__
inline
bool cmp(const T& x, U expected) {
const auto r = x == T(expected);
return r.x != 0 && r.y != 0;
}
template<typename T, typename U, Enable_if_t<is_vec<T, 3>()>* = nullptr>
__host__ __device__
inline
bool cmp(const T& x, U expected) {
const auto r = x == T(expected);
return r.x != 0 && r.y != 0 && r.z != 0;
}
template<typename T, typename U, Enable_if_t<is_vec<T, 4>()>* = nullptr>
__host__ __device__
inline
bool cmp(const T& x, U expected) {
const auto r = x == T(expected);
return r.x != 0 && r.y != 0 && r.z != 0 && r.w != 0;
}