6 #ifndef TURI_SFRAME_INTEGER_PACK_IMPL_HPP 7 #define TURI_SFRAME_INTEGER_PACK_IMPL_HPP 10 #include <core/storage/serialization/serialization_includes.hpp> 23 namespace integer_pack {
28 static inline size_t pack_1(
const uint64_t* src,
size_t srclen, uint8_t* out) {
29 uint8_t* initial_out = out;
30 size_t n = (srclen + 7) / 8;
33 case 0:
do { c |= ((*src++));
34 case 7: c |= ((*src++)) << 1;
35 case 6: c |= ((*src++)) << 2;
36 case 5: c |= ((*src++)) << 3;
37 case 4: c |= ((*src++)) << 4;
38 case 3: c |= ((*src++)) << 5;
39 case 2: c |= ((*src++)) << 6;
40 case 1: c |= ((*src++)) << 7;
45 return out - initial_out;
51 static inline size_t pack_2(
const uint64_t* src,
size_t srclen, uint8_t* out) {
52 uint8_t* initial_out = out;
53 size_t n = (srclen + 7) / 8;
56 case 0:
do { c |= ((*src++));
57 case 7: c |= ((*src++)) << 2;
58 case 6: c |= ((*src++)) << 4;
59 case 5: c |= ((*src++)) << 6;
62 case 4: c |= ((*src++));
63 case 3: c |= ((*src++)) << 2;
64 case 2: c |= ((*src++)) << 4;
65 case 1: c |= ((*src++)) << 6;
70 return out - initial_out;
77 static inline size_t pack_4(
const uint64_t* src,
size_t srclen, uint8_t* out) {
78 uint8_t* initial_out = out;
79 size_t n = (srclen + 7) / 8;
82 case 0:
do { c |= ((*src++));
83 case 7: c |= ((*src++)) << 4;
86 case 6: c |= ((*src++));
87 case 5: c |= ((*src++)) << 4;
90 case 4: c |= ((*src++));
91 case 3: c |= ((*src++)) << 4;
94 case 2: c |= ((*src++));
95 case 1: c |= ((*src++)) << 4;
100 return out - initial_out;
106 static inline size_t pack_8(
const uint64_t* src,
size_t srclen, uint8_t* out) {
107 uint8_t* initial_out = out;
108 const uint64_t* src_end = src + srclen;
109 while(src != src_end) {
112 return out - initial_out;
118 static inline size_t pack_16(
const uint64_t* src,
size_t srclen, uint16_t* out) {
119 uint16_t* initial_out = out;
120 const uint64_t* src_end = src + srclen;
121 while(src != src_end) {
124 return 2*(out - initial_out);
130 static inline size_t pack_32(
const uint64_t* src,
size_t srclen, uint32_t* out) {
131 uint32_t* initial_out = out;
132 const uint64_t* src_end = src + srclen;
133 while(src != src_end) {
134 (*out++) = static_cast<uint32_t>(*src++);
136 return 4*(out - initial_out);
143 static inline void unpack_1(
const uint8_t* src,
size_t nout_values, uint64_t* out) {
144 size_t n = (nout_values + 7) / 8;
145 uint8_t c = (*src++);
149 c >>= ((8 - (nout_values % 8)) % 8);
150 switch(nout_values % 8) {
152 case 0: (*out++) = c & 1; c >>= 1;
153 case 7: (*out++) = c & 1; c >>= 1;
154 case 6: (*out++) = c & 1; c >>= 1;
155 case 5: (*out++) = c & 1; c >>= 1;
156 case 4: (*out++) = c & 1; c >>= 1;
157 case 3: (*out++) = c & 1; c >>= 1;
158 case 2: (*out++) = c & 1; c >>= 1;
159 case 1: (*out++) = c & 1; c >>= 1;
168 static inline void unpack_2(
const uint8_t* src,
size_t nout_values, uint64_t* out) {
169 size_t n = (nout_values + 7) / 8;
170 uint8_t c = (*src++);
171 c >>= ((8 - 2 * (nout_values % 4)) % 8);
172 switch(nout_values % 8) {
174 case 0: (*out++) = c & 3; c >>= 2;
175 case 7: (*out++) = c & 3; c >>= 2;
176 case 6: (*out++) = c & 3; c >>= 2;
177 case 5: (*out++) = c & 3; c >>= 2;
179 case 4: (*out++) = c & 3; c >>= 2;
180 case 3: (*out++) = c & 3; c >>= 2;
181 case 2: (*out++) = c & 3; c >>= 2;
182 case 1: (*out++) = c & 3; c >>= 2;
191 static inline void unpack_4(
const uint8_t* src,
size_t nout_values, uint64_t* out) {
192 size_t n = (nout_values + 7) / 8;
193 uint8_t c = (*src++);
194 c >>= ((8 - 4 * (nout_values % 2)) % 8);
195 switch(nout_values % 8) {
197 case 0: (*out++) = c & 15; c >>= 4;
198 case 7: (*out++) = c & 15; c >>= 4;
200 case 6: (*out++) = c & 15; c >>= 4;
201 case 5: (*out++) = c & 15; c >>= 4;
203 case 4: (*out++) = c & 15; c >>= 4;
204 case 3: (*out++) = c & 15; c >>= 4;
206 case 2: (*out++) = c & 15; c >>= 4;
207 case 1: (*out++) = c & 15; c >>= 4;
216 static inline void unpack_8(
const uint8_t* src,
size_t nout_values, uint64_t* out) {
217 const uint8_t* src_end = src + nout_values;
218 while(src != src_end) {
227 static inline void unpack_16(
const uint16_t* src,
size_t nout_values, uint64_t* out) {
228 const uint16_t* src_end = src + nout_values;
229 while(src != src_end) {
237 static inline void unpack_32(
const uint32_t* src,
size_t nout_values, uint64_t* out) {
238 const uint32_t* src_end = src + nout_values;
239 while(src != src_end) {
static void unpack_16(const uint16_t *src, size_t nout_values, uint64_t *out)
static size_t pack_32(const uint64_t *src, size_t srclen, uint32_t *out)
static size_t pack_4(const uint64_t *src, size_t srclen, uint8_t *out)
static size_t pack_8(const uint64_t *src, size_t srclen, uint8_t *out)
static size_t pack_16(const uint64_t *src, size_t srclen, uint16_t *out)
static size_t pack_2(const uint64_t *src, size_t srclen, uint8_t *out)
static void unpack_1(const uint8_t *src, size_t nout_values, uint64_t *out)
static void unpack_2(const uint8_t *src, size_t nout_values, uint64_t *out)
static void unpack_32(const uint32_t *src, size_t nout_values, uint64_t *out)
static void unpack_8(const uint8_t *src, size_t nout_values, uint64_t *out)
static size_t pack_1(const uint64_t *src, size_t srclen, uint8_t *out)
static void unpack_4(const uint8_t *src, size_t nout_values, uint64_t *out)