Fermat
register_array.h
Go to the documentation of this file.
1 /*
2  * cugar
3  * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the NVIDIA CORPORATION nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
32 #pragma once
33 
34 #include <cugar/basic/types.h>
35 #include <cugar/basic/iterator.h>
36 
37 namespace cugar {
38 
48 
51 
57 
58 
67 template <typename Iterator, uint32 SIZE>
69 {
70  typedef iterator_traits<Iterator>::reference reference_type;
71  static const uint32 DIM = SIZE;
72 
75  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE register_array() {}
76 
79  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE register_array(Iterator it) : r(it) {}
80 
83  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE reference_type operator[](const uint32 i) const { select( r, i ); }
84 
87  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
88  static reference select(const Iterator& it, const uint32 i) { return it[i]; }
89 
92  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE operator Iterator() const { return r; }
93 
94  Iterator r;
95 };
96 
102 template <typename Iterator>
103 struct register_array<Iterator,4>
104 {
105  typedef iterator_traits<Iterator>::reference reference_type;
106  static const uint32 DIM = 4;
107 
110  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE register_array() {}
111 
114  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE register_array(const Iterator& it) : r(it) {}
115 
118  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE reference_type operator[](const uint32 i) const { select( r, i ); }
119 
122  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE operator Iterator() const { return r; }
123 
126  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
127  static reference select(const Iterator& it, const uint32 i)
128  {
129  return i < 2 ? (i == 0 ? it[0] : it[1]) :
130  (i == 2 ? it[2] : it[3]);
131  }
132 
133  Iterator r;
134 };
135 
141 template <typename Iterator>
142 struct register_array<Iterator,5>
143 {
144  typedef iterator_traits<Iterator>::reference reference_type;
145  static const uint32 DIM = 5;
146 
149  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE register_array() {}
150 
153  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE register_array(const Iterator& it) : r(it) {}
154 
157  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE reference_type operator[](const uint32 i) const { select( r, i ); }
158 
161  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE operator Iterator() const { return r; }
162 
165  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
166  static reference select(const Iterator& it, const uint32 i)
167  {
168  return i == 4 ? it[4] :
169  i < 2 ? (i == 0 ? it[0] : it[1]) :
170  (i == 2 ? it[2] : it[3]);
171  }
172 
173  Iterator r;
174 };
175 
181 template <typename Iterator>
182 struct register_array<Iterator,8>
183 {
184  typedef iterator_traits<Iterator>::reference reference_type;
185  static const uint32 DIM = 8;
186 
189  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE register_array() {}
190 
193  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE register_array(const Iterator& it) : r(it) {}
194 
197  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE reference_type operator[](const uint32 i) const { select( r, i ); }
198 
201  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE operator Iterator() const { return r; }
202 
205  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
206  static reference select(const Iterator& it, const uint32 i)
207  {
208  return i < 4 ?
209  (i < 2 ? (i == 0 ? it[0] : it[1]) :
210  (i == 2 ? it[2] : it[3])) :
211  (i < 6 ? (i == 4 ? it[4] : it[5]) :
212  (i == 6 ? it[6] : it[7]));
213  }
214 
215  Iterator r;
216 };
217 
223 template <typename Iterator>
224 struct register_array<Iterator,16>
225 {
226  typedef iterator_traits<Iterator>::reference reference_type;
227  static const uint32 DIM = 16;
228 
231  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE register_array() {}
232 
235  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE register_array(const Iterator& it) : r(it) {}
236 
239  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE reference_type operator[](const uint32 i) const { select( r, i ); }
240 
243  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE operator Iterator() const { return r; }
244 
247  CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
248  static reference select(const Iterator& it, const uint32 i)
249  {
250  return i < 8 ?
251  (i < 4 ?
252  (i < 2 ? (i == 0 ? it[0] : it[1]) :
253  (i == 2 ? it[2] : it[3])) :
254  (i < 6 ? (i == 4 ? it[4] : it[5]) :
255  (i == 6 ? it[6] : it[7]))) :
256  (i < 12 ?
257  (i < 10 ? (i == 8 ? it[8] : it[9]) :
258  (i == 10 ? it[10] : it[11])) :
259  (i < 14 ? (i == 12 ? it[12] : it[13]) :
260  (i == 14 ? it[14] : it[15])));
261  }
262  Iterator r;
263 };
264 
267 template <uint32 SIZE, typename iterator_type>
268 iterator_traits<iterator_type>::reference dynamic_index(const iterator_type& T, const uint32 i)
269 {
271 }
272 
275 
276 } // namespace cugar
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE register_array(const Iterator &it)
Definition: register_array.h:193
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE register_array()
Definition: register_array.h:110
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE register_array(const Iterator &it)
Definition: register_array.h:114
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE register_array()
Definition: register_array.h:149
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE reference_type operator[](const uint32 i) const
Definition: register_array.h:83
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE register_array(Iterator it)
Definition: register_array.h:79
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE register_array()
Definition: register_array.h:75
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE reference_type operator[](const uint32 i) const
Definition: register_array.h:118
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE register_array(const Iterator &it)
Definition: register_array.h:153
CUGAR_FORCEINLINE static CUGAR_HOST_DEVICE reference select(const Iterator &it, const uint32 i)
Definition: register_array.h:166
CUGAR_FORCEINLINE static CUGAR_HOST_DEVICE reference select(const Iterator &it, const uint32 i)
Definition: register_array.h:88
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE register_array(const Iterator &it)
Definition: register_array.h:235
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE reference_type operator[](const uint32 i) const
Definition: register_array.h:239
Define a vector_view POD type and plain_view() for std::vector.
Definition: diff.h:38
Definition: register_array.h:68
CUGAR_FORCEINLINE static CUGAR_HOST_DEVICE reference select(const Iterator &it, const uint32 i)
Definition: register_array.h:248
CUGAR_FORCEINLINE static CUGAR_HOST_DEVICE reference select(const Iterator &it, const uint32 i)
Definition: register_array.h:127
CUGAR_FORCEINLINE static CUGAR_HOST_DEVICE reference select(const Iterator &it, const uint32 i)
Definition: register_array.h:206
iterator_traits< iterator_type >::reference dynamic_index(const iterator_type &T, const uint32 i)
Definition: register_array.h:268
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE reference_type operator[](const uint32 i) const
Definition: register_array.h:157
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE reference_type operator[](const uint32 i) const
Definition: register_array.h:197
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE register_array()
Definition: register_array.h:231
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE register_array()
Definition: register_array.h:189