cheshirekow  v0.1.0
PackedIndex.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Josh Bialkowski (jbialk@mit.edu)
3  *
4  * This file is part of mpblocks.
5  *
6  * mpblocks is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * mpblocks is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with mpblocks. If not, see <http://www.gnu.org/licenses/>.
18  */
27 #ifndef MPBLOCKS_DUBINS_CURVES_CUDA2_PACKEDINDEX_HPP_
28 #define MPBLOCKS_DUBINS_CURVES_CUDA2_PACKEDINDEX_HPP_
29 
30 
31 namespace mpblocks {
32 namespace dubins {
33 namespace curves_cuda {
34 
35 
36 template <typename Format_t>
39 {
40  setId(id);
41  setIdx(idx);
42 }
43 
44 template <typename Format_t>
47 {
48  setPun(bits);
49 }
50 
51 template <typename Format_t>
54 {
55  // the number of bits in Storage_t is sizeof(Format_t)*sizeof(char)
56  const Storage_t size = sizeof(Format_t)*8;
57 
58  // we'll use the first four bits to store the id so
59  const Storage_t field = 4;
60 
61  return (SolutionId)( m_storage >> (size-field) );
62 }
63 
64 template <typename Format_t>
67 {
68  // the number of bits in Storage_t is sizeof(Format_t)*sizeof(char)
69  const Storage_t size = sizeof(Format_t)*8;
70 
71  // we'll use the first four bits to store the id so
72  const Storage_t field = 4;
73  const Storage_t mask = ~( 0x0F << (size-field) );
74 
75  return (m_storage & mask);
76 }
77 
78 template <typename Format_t>
81 {
82  const Storage_t mask = 0x0FFFFFFF;
83  Storage_t idBits = id;
84  m_storage = (idBits << (sizeof(Format_t)*8-4) ) | (m_storage & mask);
85 }
86 
87 template <typename Format_t>
90 {
91  const Storage_t idMask = 0xF0000000;
92  const Storage_t idxMask = 0x0FFFFFFF;
93 
94  m_storage = ( idMask & m_storage ) | ( idxMask & idx );
95 }
96 
97 template <typename Format_t>
100 {
101  return reinterpret_cast<Format_t&>(m_storage);
102 }
103 
104 template <typename Format_t>
106 void PackedIndex<Format_t>::setPun( Format_t bits )
107 {
108  reinterpret_cast<Format_t&>(m_storage) = bits;
109 }
110 
111 template <typename Format_t>
114 {
115  return m_storage;
116 }
117 
118 template <typename Format_t>
121 {
122  m_storage = bits;
123 }
124 
125 
126 
127 
128 
129 } // curves
130 } // dubins
131 } // mpblocks
132 
133 
134 
135 
136 
137 
138 
139 
140 
141 
142 
143 
144 
145 
146 #endif // PACKEDINDEX_H_
__device__ __host__ Storage_t getIdx() const
Definition: PackedIndex.hpp:66
__device__ __host__ SolutionId getId() const
Definition: PackedIndex.hpp:53
__device__ __host__ Format_t & getPun()
Definition: PackedIndex.hpp:99
__device__ __host__ void setUnsigned(Storage_t bits)
PackedStorage< sizeof(Format_t) >::Result Storage_t
Definition: PackedIndex.h:55
__device__ __host__ void setIdx(Storage_t idx)
Definition: PackedIndex.hpp:89
__device__ __host__ PackedIndex(Format_t bits)
Definition: PackedIndex.hpp:46
__device__ __host__ void setId(SolutionId id)
Definition: PackedIndex.hpp:80
__device__ __host__ Storage_t getUnsigned()
#define __device__
Definition: fakecuda.h:34
#define __host__
Definition: fakecuda.h:37
SolutionId
enumerates solution types
Definition: types.h:49
__device__ __host__ void setPun(Format_t bits)