NvBlastFixedBitmap.h
Go to the documentation of this file.
1 // This code contains NVIDIA Confidential Information and is disclosed to you
2 // under a form of NVIDIA software license agreement provided separately to you.
3 //
4 // Notice
5 // NVIDIA Corporation and its licensors retain all intellectual property and
6 // proprietary rights in and to this software and related documentation and
7 // any modifications thereto. Any use, reproduction, disclosure, or
8 // distribution of this software and related documentation without an express
9 // license agreement from NVIDIA Corporation is strictly prohibited.
10 //
11 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
12 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
13 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
14 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
15 //
16 // Information and code furnished is believed to be accurate and reliable.
17 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
18 // information or for any infringement of patents or other rights of third parties that may
19 // result from its use. No license is granted by implication or otherwise under any patent
20 // or patent rights of NVIDIA Corporation. Details are subject to change without notice.
21 // This code supersedes and replaces all information previously supplied.
22 // NVIDIA Corporation products are not authorized for use as critical
23 // components in life support devices or systems without express written approval of
24 // NVIDIA Corporation.
25 //
26 // Copyright (c) 2016-2020 NVIDIA Corporation. All rights reserved.
27 
28 
29 #ifndef NVBLASTFIXEDBITMAP_H
30 #define NVBLASTFIXEDBITMAP_H
31 
32 #include "NvBlastAssert.h"
33 #include "NvBlastMemory.h"
34 #include <cstring>
35 
36 namespace Nv
37 {
38 namespace Blast
39 {
40 
64 {
65 public:
66  explicit FixedBitmap(uint32_t bitsCount)
67  {
68  m_bitsCount = bitsCount;
69  }
70 
71  static uint32_t getWordsCount(uint32_t bitsCount)
72  {
73  return (bitsCount + 31) >> 5;
74  }
75 
76  static size_t requiredMemorySize(uint32_t bitsCount)
77  {
78  return align16(sizeof(FixedBitmap)) + align16(getWordsCount(bitsCount) * sizeof(uint32_t));
79  }
80 
81  void clear()
82  {
83  memset(data(), 0, getWordsCount(m_bitsCount) * sizeof(uint32_t));
84  }
85 
86  void fill()
87  {
88  const uint32_t wordCount = getWordsCount(m_bitsCount);
89  uint32_t* mem = data();
90  memset(mem, 0xFF, wordCount * sizeof(uint32_t));
91  const uint32_t bitsRemainder = m_bitsCount & 31;
92  if (bitsRemainder > 0)
93  {
94  mem[wordCount - 1] &= ~(0xFFFFFFFF << bitsRemainder);
95  }
96  }
97 
98  int test(uint32_t index) const
99  {
100  NVBLAST_ASSERT(index < m_bitsCount);
101  return data()[index >> 5] & (1 << (index & 31));
102  }
103 
104  void set(uint32_t index)
105  {
106  NVBLAST_ASSERT(index < m_bitsCount);
107  data()[index >> 5] |= 1 << (index & 31);
108  }
109 
110  void reset(uint32_t index)
111  {
112  NVBLAST_ASSERT(index < m_bitsCount);
113  data()[index >> 5] &= ~(1 << (index & 31));
114  }
115 
116 private:
117  uint32_t m_bitsCount;
118 
119  NV_FORCE_INLINE uint32_t* data()
120  {
121  return (uint32_t*)((char*)this + sizeof(FixedBitmap));
122  }
123 
124  NV_FORCE_INLINE const uint32_t* data() const
125  {
126  return (uint32_t*)((char*)this + sizeof(FixedBitmap));
127  }
128 
129 private:
130  FixedBitmap(const FixedBitmap& that);
131 };
132 
133 } // namespace Blast
134 } // namespace Nv
135 
136 #endif // ifndef NVBLASTFIXEDBITMAP_H
static size_t requiredMemorySize(uint32_t bitsCount)
Definition: NvBlastFixedBitmap.h:76
static uint32_t getWordsCount(uint32_t bitsCount)
Definition: NvBlastFixedBitmap.h:71
int test(uint32_t index) const
Definition: NvBlastFixedBitmap.h:98
void reset(uint32_t index)
Definition: NvBlastFixedBitmap.h:110
#define NVBLAST_ASSERT(exp)
Definition: NvBlastAssert.h:37
Definition: NvBlastFixedBitmap.h:63
FixedBitmap(uint32_t bitsCount)
Definition: NvBlastFixedBitmap.h:66
void fill()
Definition: NvBlastFixedBitmap.h:86
NV_INLINE T align16(T value)
Definition: NvBlastMemory.h:46
Definition: NvBlastArray.h:37
#define NV_FORCE_INLINE
Definition: NvPreprocessor.h:365
void clear()
Definition: NvBlastFixedBitmap.h:81