QUDA: quda/include/externals/generics/detail/alias.h Source File

QUDA  v1.1.0
A library for QCD on GPUs
alias.h
Go to the documentation of this file.
1 #pragma once
2 #include <generics/detail/array.h>
3 
4  namespace detail {
5 
6 template<typename T, int p>
7  struct size_multiple_power_of_two {
8   static const bool value = (sizeof(T) & ((1 << p) - 1)) == 0;
9 };
10 
11 template<typename T,
12  bool use_int=size_multiple_power_of_two<T, 2>::value>
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,
37  int r=aliased_size<T, U>::value>
38  struct dismember {
39   typedef array<U, r> result_type;
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],
44  dismember<T, U, r-1>::impl(t));
45  }
46 };
47 
48 template<typename T, typename U>
49  struct dismember<T, U, 1> {
50   typedef array<U, 1> result_type;
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__
60  array<U, detail::aliased_size<T, U>::value> lyse(const T& in) {
61  return detail::dismember<T, U>::impl(in);
62 }
63 
64 
65 template<typename T,
66  typename U=typename working_type<T>::type,
67  int r=aliased_size<T, U>::value>
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;
73  remember<T, U, r-1>::impl(d.tail, t);
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 
detail
Definition: alias.h:4
detail::lyse
__host__ __device__ __forceinline__ array< U, detail::aliased_size< T, U >::value > lyse(const T &in)
Definition: alias.h:60
detail::fuse
__host__ __device__ __forceinline__ T fuse(const typename working_array< T >::type &in)
Definition: alias.h:89
detail::aliased_size::value
static const int value
Definition: alias.h:25
detail::array::tail
tail_type tail
Definition: array.h:12
detail::array::head
head_type head
Definition: array.h:11
detail::dismember< T, U, 1 >::result_type
array< U, 1 > result_type
Definition: alias.h:50
detail::dismember< T, U, 1 >::impl
__host__ __device__ static __forceinline__ result_type impl(const T &t)
Definition: alias.h:53
detail::dismember::idx
static const int idx
Definition: alias.h:40
detail::dismember::result_type
array< U, r > result_type
Definition: alias.h:39
detail::dismember::impl
__host__ __device__ static __forceinline__ result_type impl(const T &t)
Definition: alias.h:42
detail::remember< T, U, 1 >::impl
__host__ __device__ static __forceinline__ void impl(const array< U, 1 > &d, const T &t)
Definition: alias.h:81
detail::remember::impl
__host__ __device__ static __forceinline__ void impl(const array< U, r > &d, T &t)
Definition: alias.h:71
detail::remember::idx
static const int idx
Definition: alias.h:69
detail::size_multiple_power_of_two::value
static const bool value
Definition: alias.h:8
detail::working_array::U
working_type< T >::type U
Definition: alias.h:30
detail::working_array::type
array< U, r > type
Definition: alias.h:32
detail::working_array::r
static const int r
Definition: alias.h:31

Generated on Thu Oct 28 2021 16:10:26 for QUDA by doxygen 1.9.1

AltStyle によって変換されたページ (->オリジナル) /