HOG2
NBitArray.cpp
Go to the documentation of this file.
1 //
2 // NBitArray.cpp
3 // hog2 glut
4 //
5 // Created by Nathan Sturtevant on 10/5/15.
6 // Copyright © 2015 University of Denver. All rights reserved.
7 //
8 
9 #include <stdio.h>
10 #include "NBitArray.h"
11 
12 template <>
14 {
15  uint64_t v = 0;
16  return ~v;
17 }
18 
19 
20 template <>
21 uint64_t NBitArray<64>::Get(uint64_t index) const
22 {
23  return mem[index];
24 }
25 
26 template <>
27 uint64_t NBitArray<32>::Get(uint64_t index) const
28 {
29  return (mem[index>>1]>>(32*(index&0x1)))&0xFFFFFFFF;
30 }
31 
32 template <>
33 uint64_t NBitArray<16>::Get(uint64_t index) const
34 {
35  return (mem[index>>2]>>(16*(index&0x3)))&0xFFFF;
36 }
37 
38 template <>
39 uint64_t NBitArray<8>::Get(uint64_t index) const
40 {
41  return (mem[index>>3]>>(8*(index&0x7)))&0xFF;
42 }
43 
44 template <>
45 uint64_t NBitArray<4>::Get(uint64_t index) const
46 {
47  return (mem[index>>4]>>(4*(index&0xF)))&0xF;
48 }
49 
50 template <>
51 uint64_t NBitArray<2>::Get(uint64_t index) const
52 {
53  return (mem[index>>5]>>(2*(index&0x1F)))&0x3;
54 }
55 
56 template <>
57 uint64_t NBitArray<1>::Get(uint64_t index) const
58 {
59  return (mem[index>>6]>>(1*(index&0x3F)))&0x1;
60 }
61 
62 
63 
64 template <>
65 void NBitArray<64>::Set(uint64_t index, uint64_t val)
66 {
67  mem[index] = val;
68 }
69 
70 template <>
71 void NBitArray<32>::Set(uint64_t index, uint64_t val)
72 {
73  val = (val&0xFFFFFFFF)<<(32*(index&0x1));
74  uint64_t mask = ~((0xFFFFFFFFull)<<(32*(index&0x1)));
75  mem[index>>1] = (mem[index>>1]&mask)|val;
76 }
77 
78 template <>
79 void NBitArray<16>::Set(uint64_t index, uint64_t val)
80 {
81  val = (val&0xFFFF)<<(16*(index&0x3));
82  uint64_t mask = ~((0xFFFFull)<<(16*(index&0x3)));
83  mem[index>>2] = (mem[index>>2]&mask)|val;
84 }
85 
86 template <>
87 void NBitArray<8>::Set(uint64_t index, uint64_t val)
88 {
89  val = (val&0xFF)<<(8*(index&0x7));
90  uint64_t mask = ~((0xFFull)<<(8*(index&0x7)));
91  mem[index>>3] = (mem[index>>3]&mask)|val;
92 }
93 
94 template <>
95 void NBitArray<4>::Set(uint64_t index, uint64_t val)
96 {
97  // 2^4 = 16;
98  val = (val&0xF)<<(4*(index&0xF));
99  uint64_t mask = ~((0xFull)<<(4*(index&0xF)));
100  mem[index>>4] = (mem[index>>4]&mask)|val;
101 }
102 
103 template <>
104 void NBitArray<2>::Set(uint64_t index, uint64_t val)
105 {
106  // 2^4 = 16;
107  val = (val&0x3)<<(2*(index&0x1F));
108  uint64_t mask = ~((0x3ull)<<(2*(index&0x1F)));
109  mem[index>>5] = (mem[index>>5]&mask)|val;
110 }
111 
112 template <>
113 void NBitArray<1>::Set(uint64_t index, uint64_t val)
114 {
115  // 2^4 = 16;
116  val = (val&0x1)<<(1*(index&0x3F));
117  uint64_t mask = ~((0x1ull)<<(1*(index&0x3F)));
118  mem[index>>6] = (mem[index>>6]&mask)|val;
119 }
NBitArray::mem
uint64_t * mem
Definition: NBitArray.h:45
NBitArray::Set
void Set(uint64_t index, uint64_t val)
Definition: NBitArray.h:224
NBitArray::Get
uint64_t Get(uint64_t index) const
Definition: NBitArray.h:209
NBitArray.h
NBitArray::GetMaxValue
uint64_t GetMaxValue() const
Definition: NBitArray.h:38