QUDA  v1.1.0
A library for QCD on GPUs
alias.h
Go to the documentation of this file.
1 #pragma once
3 
4 namespace detail {
5 
6 template<typename T, int p>
8  static const bool value = (sizeof(T) & ((1 << p) - 1)) == 0;
9 };
10 
11 template<typename T,
13 struct working_type {
14  typedef char type;
15 };
16 
17 template<typename T>
18 struct working_type<T, true> {
19  typedef int type;
20 };
21 
22 
23 template<typename T, typename U>
24 struct aliased_size {
25  static const int value = sizeof(T)/sizeof(U);
26 };
27 
28 template<typename T>
29 struct working_array {
30  typedef typename working_type<T>::type U;
31  static const int r = aliased_size<T, U>::value;
32  typedef array<U, r> type;
33 };
34 
35 template<typename T,
36  typename U=typename working_type<T>::type,
38 struct dismember {
40  static const int idx = aliased_size<T, U>::value - r;
41  __host__ __device__ __forceinline__
42  static result_type impl(const T& t) {
43  return result_type(((const U*)&t)[idx],
45  }
46 };
47 
48 template<typename T, typename U>
49 struct dismember<T, U, 1> {
51  static const int idx = aliased_size<T, U>::value - 1;
52  __host__ __device__ __forceinline__
53  static result_type impl(const T& t) {
54  return result_type(((const U*)&t)[idx]);
55  }
56 };
57 
58 template<typename U, typename T>
59 __host__ __device__ __forceinline__
62 }
63 
64 
65 template<typename T,
66  typename U=typename working_type<T>::type,
68 struct remember {
69  static const int idx = aliased_size<T, U>::value - r;
70  __host__ __device__ __forceinline__
71  static void impl(const array<U, r>& d, T& t) {
72  ((U*)&t)[idx] = d.head;
74  }
75 };
76 
77 template<typename T, typename U>
78 struct remember<T, U, 1> {
79  static const int idx = aliased_size<T, U>::value - 1;
80  __host__ __device__ __forceinline__
81  static void impl(const array<U, 1>& d, const T& t) {
82  ((U*)&t)[idx] = d.head;
83  }
84 };
85 
86 
87 template<typename T>
88 __host__ __device__ __forceinline__
89 T fuse(const typename working_array<T>::type& in) {
90  T result;
91  typedef typename working_type<T>::type U;
92  remember<T, U>::impl(in, result);
93  return result;
94 }
95 
96 }
97 
Definition: alias.h:4
__host__ __device__ __forceinline__ array< U, detail::aliased_size< T, U >::value > lyse(const T &in)
Definition: alias.h:60
__host__ __device__ __forceinline__ T fuse(const typename working_array< T >::type &in)
Definition: alias.h:89
static const int value
Definition: alias.h:25
tail_type tail
Definition: array.h:12
head_type head
Definition: array.h:11
array< U, 1 > result_type
Definition: alias.h:50
__host__ __device__ static __forceinline__ result_type impl(const T &t)
Definition: alias.h:53
static const int idx
Definition: alias.h:40
array< U, r > result_type
Definition: alias.h:39
__host__ __device__ static __forceinline__ result_type impl(const T &t)
Definition: alias.h:42
__host__ __device__ static __forceinline__ void impl(const array< U, 1 > &d, const T &t)
Definition: alias.h:81
__host__ __device__ static __forceinline__ void impl(const array< U, r > &d, T &t)
Definition: alias.h:71
static const int idx
Definition: alias.h:69
static const bool value
Definition: alias.h:8
working_type< T >::type U
Definition: alias.h:30
array< U, r > type
Definition: alias.h:32
static const int r
Definition: alias.h:31