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 
31 
32 namespace mpblocks {
33 namespace dubins {
34 namespace curves_cuda {
35 
36 template <typename PunType>
39  setId(id);
40  setIdx(idx);
41 }
42 
43 template <typename PunType>
46  setPun(bits);
47 }
48 
49 template <typename PunType>
52  // the number of bits in StorageType is sizeof(PunType)*sizeof(char)
53  const StorageType size = sizeof(PunType) * 8;
54 
55  // we'll use the first four bits to store the id so
56  const StorageType field = 4;
57 
58  return (SolutionId)(m_storage >> (size - field));
59 }
60 
61 template <typename PunType>
63 typename PackedIndex<PunType>::StorageType
65  // the number of bits in StorageType is sizeof(PunType)*sizeof(char)
66  const StorageType size = sizeof(PunType) * 8;
67 
68  // we'll use the first four bits to store the id so
69  const StorageType field = 4;
70  const StorageType mask = ~(0x0F << (size - field));
71 
72  return (m_storage & mask);
73 }
74 
75 template <typename PunType>
78  const StorageType mask = 0x0FFFFFFF;
79  StorageType idBits = id;
80  m_storage = (idBits << (sizeof(PunType) * 8 - 4)) | (m_storage & mask);
81 }
82 
83 template <typename PunType>
86  const StorageType idMask = 0xF0000000;
87  const StorageType idxMask = 0x0FFFFFFF;
88 
89  m_storage = (idMask & m_storage) | (idxMask & idx);
90 }
91 
92 template <typename PunType>
95  return reinterpret_cast<PunType&>(m_storage);
96 }
97 
98 template <typename PunType>
100 void PackedIndex<PunType>::setPun(PunType bits) {
101  reinterpret_cast<PunType&>(m_storage) = bits;
102 }
103 
104 template <typename PunType>
108  return m_storage;
109 }
110 
111 template <typename PunType>
114  m_storage = bits;
115 }
116 
117 } // curves
118 } // dubins
119 } // mpblocks
120 
121 #endif // MPBLOCKS_DUBINS_CURVES_CUDA2_PACKEDINDEX_HPP_
PackedStorage< sizeof(PunType)>::Result StorageType
Definition: PackedIndex.h:55
__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)
__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)