]> git.sesse.net Git - plocate/blob - turbopfor.h
Add SSE2 versions of the _interleaved codecs.
[plocate] / turbopfor.h
1 #ifndef _TURBOPFOR_H
2 #define _TURBOPFOR_H 1
3
4 // A reimplementation of parts of the TurboPFor codecs, using the same
5 // storage format. These are not as fast as the reference implementation
6 // (about 60% of the performance, averaged over a real plocate corpus),
7 // and do not support the same breadth of codecs (in particular, only
8 // delta-plus-1 is implemented, and only 32-bit docids are tested),
9 // but aim to be more portable and (ideally) easier-to-understand.
10 // In particular, they will compile on x86 without SSE4.1 or AVX support.
11 //
12 // The main reference is https://michael.stapelberg.ch/posts/2019-02-05-turbopfor-analysis/,
13 // although some implementation details have been worked out by studying the
14 // TurboPFor code.
15
16 #include <assert.h>
17 #include <endian.h>
18 #include <stdint.h>
19 #include <string.h>
20 #include <limits.h>
21
22 #include <algorithm>
23
24 #if defined(__i386__) || defined(__x86_64__)
25 #define COULD_HAVE_SSE2
26 #include <immintrin.h>
27 #endif
28
29 // Forward declarations to declare to the template code below that they exist.
30 // (These must seemingly be non-templates for function multiversioning to work.)
31 __attribute__((target("default")))
32 const unsigned char *decode_for_interleaved_128_32(const unsigned char *in, uint32_t *out);
33 __attribute__((target("default")))
34 const unsigned char *decode_pfor_bitmap_interleaved_128_32(const unsigned char *in, uint32_t *out);
35 __attribute__((target("default")))
36 const unsigned char *decode_pfor_vb_interleaved_128_32(const unsigned char *in, uint32_t *out);
37
38 #ifdef COULD_HAVE_SSE2
39 __attribute__((target("sse2")))
40 const unsigned char *decode_for_interleaved_128_32(const unsigned char *in, uint32_t *out);
41 __attribute__((target("sse2")))
42 const unsigned char *decode_pfor_bitmap_interleaved_128_32(const unsigned char *in, uint32_t *out);
43 __attribute__((target("sse2")))
44 const unsigned char *decode_pfor_vb_interleaved_128_32(const unsigned char *in, uint32_t *out);
45 #endif
46
47 template<class Docid>
48 Docid read_le(const void *in)
49 {
50         Docid val;
51         memcpy(&val, in, sizeof(val));
52         if constexpr (sizeof(Docid) == 8) {
53                 return le64toh(val);
54         } else if constexpr (sizeof(Docid) == 4) {
55                 return le32toh(val);
56         } else if constexpr (sizeof(Docid) == 2) {
57                 return le16toh(val);
58         } else if constexpr (sizeof(Docid) == 1) {
59                 return val;
60         } else {
61                 assert(false);
62         }
63 }
64
65 // Reads a single value with an encoding that looks a bit like PrefixVarint.
66 // It's unclear why this doesn't use the varbyte encoding.
67 template<class Docid>
68 const unsigned char *read_baseval(const unsigned char *in, Docid *out)
69 {
70         //fprintf(stderr, "baseval: 0x%02x 0x%02x 0x%02x 0x%02x\n", in[0], in[1], in[2], in[3]);
71         if (*in < 128) {
72                 *out = *in;
73                 return in + 1;
74         } else if (*in < 192) {
75                 *out = ((uint32_t(in[0]) << 8) | uint32_t(in[1])) & 0x3fff;
76                 return in + 2;
77         } else if (*in < 224) {
78                 *out = ((uint32_t(in[0]) << 16) |
79                         (uint32_t(in[2]) << 8) |
80                         (uint32_t(in[1]))) & 0x1fffff;
81                 return in + 3;
82         } else {
83                 assert(false);  // Not implemented.
84         }
85 }
86
87 template<class Docid>
88 const unsigned char *read_vb(const unsigned char *in, Docid *out)
89 {
90         if (*in <= 176) {
91                 *out = *in;
92                 return in + 1;
93         } else if (*in <= 240) {
94                 *out = ((uint32_t(in[0] - 177) << 8) | uint32_t(in[1])) + 177;
95                 return in + 2;
96         } else if (*in <= 248) {
97                 *out = ((uint32_t(in[0] - 241) << 16) | read_le<uint16_t>(in + 1)) + 16561;
98                 return in + 3;
99         } else if (*in == 249) {
100                 *out = (uint32_t(in[1])) |
101                         (uint32_t(in[2]) << 8) |
102                         (uint32_t(in[3]) << 16);
103                 return in + 4;
104         } else if (*in == 250) {
105                 *out = read_le<uint32_t>(in + 1);
106                 return in + 5;
107         } else {
108                 assert(false);
109         }
110 }
111
112 struct BitReader {
113 public:
114         BitReader(const unsigned char *in, unsigned bits)
115                 : in(in), bits(bits), mask((1U << bits) - 1) {}
116         uint32_t read()
117         {
118                 uint32_t val = (read_le<uint32_t>(in) >> bits_used) & mask;
119
120                 bits_used += bits;
121                 in += bits_used / 8;
122                 bits_used %= 8;
123
124                 return val;
125         }
126
127 private:
128         const unsigned char *in;
129         const unsigned bits;
130         const unsigned mask;
131         unsigned bits_used = 0;
132 };
133
134 template<unsigned NumStreams>
135 struct InterleavedBitReader {
136 public:
137         InterleavedBitReader(const unsigned char *in, unsigned bits)
138                 : in(in), bits(bits), mask((1U << bits) - 1) {}
139         uint32_t read()
140         {
141                 uint32_t val;
142                 if (bits_used + bits > 32) {
143                         val = (read_le<uint32_t>(in) >> bits_used) | (read_le<uint32_t>(in + Stride) << (32 - bits_used));
144                 } else {
145                         val = (read_le<uint32_t>(in) >> bits_used);
146                 }
147
148                 bits_used += bits;
149                 in += Stride * (bits_used / 32);
150                 bits_used %= 32;
151
152                 return val & mask;
153         }
154
155 private:
156         static constexpr unsigned Stride = NumStreams * sizeof(uint32_t);
157         const unsigned char *in;
158         const unsigned bits;
159         const unsigned mask;
160         unsigned bits_used = 0;
161 };
162
163 // Does not properly account for overflow.
164 inline unsigned div_round_up(unsigned val, unsigned div)
165 {
166         return (val + div - 1) / div;
167 }
168
169 inline unsigned bytes_for_packed_bits(unsigned num, unsigned bit_width)
170 {
171         return div_round_up(num * bit_width, CHAR_BIT);
172 }
173
174 // Constant block. Layout:
175 //
176 //  - Bit width (6 bits) | type << 6
177 //  - Base values (<bits> bits, rounded up to nearest byte)
178 template<class Docid>
179 const unsigned char *decode_constant(const unsigned char *in, unsigned num, Docid *out)
180 {
181         const unsigned bit_width = *in++ & 0x3f;
182         Docid val = read_le<Docid>(in);
183         if (bit_width < sizeof(Docid) * 8) {
184                 val &= ((1U << bit_width) - 1);
185         }
186
187         Docid prev_val = out[-1];
188         for (unsigned i = 0; i < num; ++i) {
189                 out[i] = prev_val = val + prev_val + 1;
190         }
191         return in + div_round_up(bit_width, 8);
192 }
193
194 // FOR block (ie., PFor without exceptions). Layout:
195 //
196 //  - Bit width (6 bits) | type << 6
197 //  - Base values (<num> values of <bits> bits, rounded up to a multiple of 32 values)
198 template<class Docid>
199 const unsigned char *decode_for(const unsigned char *in, unsigned num, Docid *out)
200 {
201         const unsigned bit_width = *in++ & 0x3f;
202
203         Docid prev_val = out[-1];
204         BitReader bs(in, bit_width);
205         for (unsigned i = 0; i < num; ++i) {
206                 prev_val = out[i] = bs.read() + prev_val + 1;
207         }
208         return in + bytes_for_packed_bits(num, bit_width);
209 }
210
211 #ifdef COULD_HAVE_SSE2
212 template<unsigned BlockSize>
213 __attribute__((target("sse2")))
214 inline void delta_decode_sse2(uint32_t *out)
215 {
216         // Use 4/3/2/1 as delta instead of fixed 1, so that we can do the prev_val + delta
217         // in parallel with something else.
218         const __m128i delta = _mm_set_epi32(4, 3, 2, 1);
219         __m128i prev_val = _mm_set1_epi32(out[-1]);
220         __m128i *outvec = reinterpret_cast<__m128i *>(out);
221         for (unsigned i = 0; i < BlockSize / 4; ++i) {
222                 __m128i val = _mm_loadu_si128(outvec + i);
223                 val = _mm_add_epi32(val, _mm_slli_si128(val, 4));
224                 val = _mm_add_epi32(val, _mm_slli_si128(val, 8));
225                 val = _mm_add_epi32(val, _mm_add_epi32(prev_val, delta));
226                 _mm_storeu_si128(outvec + i, val);
227
228                 prev_val = _mm_shuffle_epi32(val, _MM_SHUFFLE(3, 3, 3, 3));
229         }
230 }
231
232 template<unsigned BlockSize, bool OrWithExisting>
233 __attribute__((target("sse2")))
234 const unsigned char *decode_bitmap_sse2(const unsigned char *in, unsigned bit_width, uint32_t *out)
235 {
236         const __m128i *invec = reinterpret_cast<const __m128i *>(in);
237         __m128i *outvec = reinterpret_cast<__m128i *>(out);
238         const __m128i mask = _mm_set1_epi32((1U << bit_width) - 1);
239         unsigned bits_used = 0;
240         for (unsigned i = 0; i < BlockSize / 4; ++i) {
241                 __m128i val = _mm_srli_epi32(_mm_loadu_si128(invec), bits_used);
242                 if (bits_used + bit_width > 32) {
243                         __m128i val_upper = _mm_slli_epi32(_mm_loadu_si128(invec + 1), 32 - bits_used);
244                         val = _mm_or_si128(val, val_upper);
245                 }
246                 val = _mm_and_si128(val, mask);
247                 if constexpr (OrWithExisting) {
248                         val = _mm_or_si128(val, _mm_loadu_si128(outvec + i));
249                 }
250                 _mm_storeu_si128(outvec + i, val);
251
252                 bits_used += bit_width;
253                 invec += bits_used / 32;
254                 bits_used %= 32;
255         }
256         in += bytes_for_packed_bits(BlockSize, bit_width);
257         return in;
258 }
259 #endif
260
261 // Like decode_for(), but the values are organized in four independent streams,
262 // for SIMD (presumably SSE2). Supports a whole block only.
263 template<unsigned BlockSize, class Docid>
264 const unsigned char *decode_for_interleaved_generic(const unsigned char *in, Docid *out)
265 {
266         const unsigned bit_width = *in++ & 0x3f;
267
268         InterleavedBitReader<4> bs0(in + 0 * sizeof(uint32_t), bit_width);
269         InterleavedBitReader<4> bs1(in + 1 * sizeof(uint32_t), bit_width);
270         InterleavedBitReader<4> bs2(in + 2 * sizeof(uint32_t), bit_width);
271         InterleavedBitReader<4> bs3(in + 3 * sizeof(uint32_t), bit_width);
272         for (unsigned i = 0; i < BlockSize / 4; ++i) {
273                 out[i * 4 + 0] = bs0.read();
274                 out[i * 4 + 1] = bs1.read();
275                 out[i * 4 + 2] = bs2.read();
276                 out[i * 4 + 3] = bs3.read();
277         }
278         Docid prev_val = out[-1];
279         for (unsigned i = 0; i < BlockSize; ++i) {
280                 out[i] = prev_val = out[i] + prev_val + 1;
281         }
282         return in + bytes_for_packed_bits(BlockSize, bit_width);
283 }
284
285 template<unsigned BlockSize, class Docid>
286 const unsigned char *decode_for_interleaved(const unsigned char *in, Docid *out)
287 {
288         if constexpr (BlockSize == 128 && sizeof(Docid) == sizeof(uint32_t)) {
289                 return decode_for_interleaved_128_32(in, out);
290         } else {
291                 return decode_for_interleaved_generic(in, out);
292         }
293 }
294
295 __attribute__((target("default")))
296 const unsigned char *decode_for_interleaved_128_32(const unsigned char *in, uint32_t *out)
297 {
298         return decode_for_interleaved_generic<128>(in, out);
299 }
300
301 #ifdef COULD_HAVE_SSE2
302 // Specialized version for SSE2.
303 __attribute__((target("sse2")))
304 const unsigned char *decode_for_interleaved_128_32(const unsigned char *in, uint32_t *out)
305 {
306         constexpr unsigned BlockSize = 128;
307
308         const unsigned bit_width = *in++ & 0x3f;
309
310         in = decode_bitmap_sse2<BlockSize, false>(in, bit_width, out);
311         delta_decode_sse2<BlockSize>(out);
312
313         return in;
314 }
315 #endif
316
317 template<class Docid>
318 const unsigned char *decode_pfor_bitmap_exceptions(const unsigned char *in, unsigned num, unsigned bit_width, Docid *out)
319 {
320         const unsigned exception_bit_width = *in++;
321         const uint64_t *exception_bitmap_ptr = reinterpret_cast<const uint64_t *>(in);
322         in += div_round_up(num, 8);
323
324         int num_exceptions = 0;
325
326         BitReader bs(in, exception_bit_width);
327         for (unsigned i = 0; i < num; i += 64, ++exception_bitmap_ptr) {
328                 uint64_t exceptions = read_le<uint64_t>(exception_bitmap_ptr);
329                 if (num - i < 64) {
330                         // We've read some bytes past the end, so clear out the junk bits.
331                         exceptions &= (1ULL << (num - i)) - 1;
332                 }
333                 for (; exceptions != 0; exceptions &= exceptions - 1, ++num_exceptions) {
334                         unsigned idx = (ffsll(exceptions) - 1) + i;
335                         out[idx] = bs.read() << bit_width;
336                 }
337         }
338         in += bytes_for_packed_bits(num_exceptions, exception_bit_width);
339         return in;
340 }
341
342 // PFor block with bitmap exceptions. Layout:
343 //
344 //  - Bit width (6 bits) | type << 6
345 //  - Exception bit width (8 bits)
346 //  - Bitmap of which values have exceptions (<num> bits, rounded up to a byte)
347 //  - Exceptions (<num_exc> values of <bits_exc> bits, rounded up to a byte)
348 //  - Base values (<num> values of <bits> bits, rounded up to a byte)
349 template<class Docid>
350 const unsigned char *decode_pfor_bitmap(const unsigned char *in, unsigned num, Docid *out)
351 {
352         memset(out, 0, num * sizeof(Docid));
353
354         const unsigned bit_width = *in++ & 0x3f;
355
356         in = decode_pfor_bitmap_exceptions(in, num, bit_width, out);
357
358         // Decode the base values, and delta-decode.
359         Docid prev_val = out[-1];
360         BitReader bs(in, bit_width);
361         for (unsigned i = 0; i < num; ++i) {
362                 out[i] = prev_val = (out[i] | bs.read()) + prev_val + 1;
363         }
364         return in + bytes_for_packed_bits(num, bit_width);
365 }
366
367 // Like decode_pfor_bitmap(), but the base values are organized in four
368 // independent streams, for SIMD (presumably SSE2). Supports a whole block only.
369 template<unsigned BlockSize, class Docid>
370 const unsigned char *decode_pfor_bitmap_interleaved_generic(const unsigned char *in, Docid *out)
371 {
372         memset(out, 0, BlockSize * sizeof(Docid));
373
374         const unsigned bit_width = *in++ & 0x3f;
375
376         in = decode_pfor_bitmap_exceptions(in, BlockSize, bit_width, out);
377
378         // Decode the base values.
379         InterleavedBitReader<4> bs0(in + 0 * sizeof(uint32_t), bit_width);
380         InterleavedBitReader<4> bs1(in + 1 * sizeof(uint32_t), bit_width);
381         InterleavedBitReader<4> bs2(in + 2 * sizeof(uint32_t), bit_width);
382         InterleavedBitReader<4> bs3(in + 3 * sizeof(uint32_t), bit_width);
383         for (unsigned i = 0; i < BlockSize / 4; ++i) {
384                 out[i * 4 + 0] |= bs0.read();
385                 out[i * 4 + 1] |= bs1.read();
386                 out[i * 4 + 2] |= bs2.read();
387                 out[i * 4 + 3] |= bs3.read();
388         }
389
390         // Delta-decode.
391         Docid prev_val = out[-1];
392         for (unsigned i = 0; i < BlockSize; ++i) {
393                 out[i] = prev_val = out[i] + prev_val + 1;
394         }
395         return in + bytes_for_packed_bits(BlockSize, bit_width);
396 }
397
398 template<unsigned BlockSize, class Docid>
399 const unsigned char *decode_pfor_bitmap_interleaved(const unsigned char *in, Docid *out)
400 {
401         if constexpr (BlockSize == 128 && sizeof(Docid) == sizeof(uint32_t)) {
402                 return decode_pfor_bitmap_interleaved_128_32(in, out);
403         } else {
404                 return decode_pfor_bitmap_interleaved_generic(in, out);
405         }
406 }
407
408 __attribute__((target("default")))
409 const unsigned char *decode_pfor_bitmap_interleaved_128_32(const unsigned char *in, uint32_t *out)
410 {
411         return decode_pfor_bitmap_interleaved_generic<128>(in, out);
412 }
413
414 #ifdef COULD_HAVE_SSE2
415 // Specialized version for SSE2.
416 __attribute__((target("sse2")))
417 const unsigned char *decode_pfor_bitmap_interleaved_128_32(const unsigned char *in, uint32_t *out)
418 {
419         constexpr unsigned BlockSize = 128;
420         using Docid = uint32_t;
421
422         memset(out, 0, BlockSize * sizeof(Docid));
423
424         const unsigned bit_width = *in++ & 0x3f;
425
426         in = decode_pfor_bitmap_exceptions(in, BlockSize, bit_width, out);
427         in = decode_bitmap_sse2<BlockSize, true>(in, bit_width, out);
428         delta_decode_sse2<BlockSize>(out);
429
430         return in;
431 }
432 #endif
433
434 // PFor block with variable-byte exceptions. Layout:
435 //
436 //  - Bit width (6 bits) | type << 6
437 //  - Number of exceptions (8 bits)
438 //  - Base values (<num> values of <bits> bits, rounded up to a byte)
439 //  - Exceptions:
440 //    - If first byte is 255, <num_exc> 32-bit values (does not include the 255 byte)
441 //    - Else, <num_exc> varbyte-encoded values (includes the non-255 byte)
442 //  - Indexes of exceptions (<num_exc> bytes).
443 template<unsigned BlockSize, class Docid>
444 const unsigned char *decode_pfor_vb(const unsigned char *in, unsigned num, Docid *out)
445 {
446         //fprintf(stderr, "in=%p out=%p num=%u\n", in, out, num);
447
448         const unsigned bit_width = *in++ & 0x3f;
449         unsigned num_exceptions = *in++;
450
451         // Decode the base values.
452         BitReader bs(in, bit_width);
453         for (unsigned i = 0; i < num; ++i) {
454                 out[i] = bs.read();
455         }
456         in += bytes_for_packed_bits(num, bit_width);
457
458         // Decode exceptions.
459         Docid exceptions[BlockSize];
460         if (*in == 255) {
461                 ++in;
462                 for (unsigned i = 0; i < num_exceptions; ++i) {
463                         exceptions[i] = read_le<Docid>(in);
464                         in += sizeof(Docid);
465                 }
466         } else {
467                 for (unsigned i = 0; i < num_exceptions; ++i) {
468                         in = read_vb(in, &exceptions[i]);
469                 }
470         }
471         // Apply exceptions.
472         for (unsigned i = 0; i < num_exceptions; ++i) {
473                 unsigned idx = *in++;
474                 out[idx] |= exceptions[i] << bit_width;
475         }
476
477         // Delta-decode.
478         Docid prev_val = out[-1];
479         for (unsigned i = 0; i < num; ++i) {
480                 out[i] = prev_val = out[i] + prev_val + 1;
481         }
482
483         return in;
484 }
485
486 // Like decode_pfor_vb(), but the base values are organized in four
487 // independent streams, for SIMD (presumably SSE2). Supports a whole block only.
488 template<unsigned BlockSize, class Docid>
489 const unsigned char *decode_pfor_vb_interleaved_generic(const unsigned char *in, Docid *out)
490 {
491         const unsigned bit_width = *in++ & 0x3f;
492         unsigned num_exceptions = *in++;
493
494         // Decode the base values.
495         InterleavedBitReader<4> bs0(in + 0 * sizeof(uint32_t), bit_width);
496         InterleavedBitReader<4> bs1(in + 1 * sizeof(uint32_t), bit_width);
497         InterleavedBitReader<4> bs2(in + 2 * sizeof(uint32_t), bit_width);
498         InterleavedBitReader<4> bs3(in + 3 * sizeof(uint32_t), bit_width);
499         for (unsigned i = 0; i < BlockSize / 4; ++i) {
500                 out[i * 4 + 0] = bs0.read();
501                 out[i * 4 + 1] = bs1.read();
502                 out[i * 4 + 2] = bs2.read();
503                 out[i * 4 + 3] = bs3.read();
504         }
505         in += bytes_for_packed_bits(BlockSize, bit_width);
506
507         // Decode exceptions.
508         Docid exceptions[BlockSize];
509         if (*in == 255) {
510                 ++in;
511                 for (unsigned i = 0; i < num_exceptions; ++i) {
512                         exceptions[i] = read_le<Docid>(in);
513                         in += sizeof(Docid);
514                 }
515         } else {
516                 for (unsigned i = 0; i < num_exceptions; ++i) {
517                         in = read_vb(in, &exceptions[i]);
518                 }
519         }
520
521         // Apply exceptions.
522         for (unsigned i = 0; i < num_exceptions; ++i) {
523                 unsigned idx = *in++;
524                 out[idx] |= exceptions[i] << bit_width;
525         }
526
527         // Delta-decode.
528         Docid prev_val = out[-1];
529         for (unsigned i = 0; i < BlockSize; ++i) {
530                 out[i] = prev_val = out[i] + prev_val + 1;
531         }
532
533         return in;
534 }
535
536 template<unsigned BlockSize, class Docid>
537 const unsigned char *decode_pfor_vb_interleaved(const unsigned char *in, Docid *out)
538 {
539         if constexpr (BlockSize == 128 && sizeof(Docid) == sizeof(uint32_t)) {
540                 return decode_pfor_vb_interleaved_128_32(in, out);
541         } else {
542                 return decode_pfor_vb_interleaved_generic(in, out);
543         }
544 }
545
546 __attribute__((target("default")))
547 const unsigned char *decode_pfor_vb_interleaved_128_32(const unsigned char *in, uint32_t *out)
548 {
549         return decode_pfor_vb_interleaved_generic<128>(in, out);
550 }
551
552 // Specialized version for SSE2.
553 __attribute__((target("sse2")))
554 const unsigned char *decode_pfor_vb_interleaved_128_32(const unsigned char *in, uint32_t *out)
555 {
556         constexpr unsigned BlockSize = 128;
557         using Docid = uint32_t;
558
559         const unsigned bit_width = *in++ & 0x3f;
560         unsigned num_exceptions = *in++;
561
562         // Decode the base values.
563         in = decode_bitmap_sse2<BlockSize, false>(in, bit_width, out);
564
565         // Decode exceptions.
566         Docid exceptions[BlockSize];
567         if (*in == 255) {
568                 ++in;
569                 for (unsigned i = 0; i < num_exceptions; ++i) {
570                         exceptions[i] = read_le<Docid>(in);
571                         in += sizeof(Docid);
572                 }
573         } else {
574                 for (unsigned i = 0; i < num_exceptions; ++i) {
575                         in = read_vb(in, &exceptions[i]);
576                 }
577         }
578
579         // Apply exceptions.
580         for (unsigned i = 0; i < num_exceptions; ++i) {
581                 unsigned idx = *in++;
582                 out[idx] |= exceptions[i] << bit_width;
583         }
584
585         delta_decode_sse2<BlockSize>(out);
586
587         return in;
588 }
589
590 enum BlockType {
591         FOR = 0,
592         PFOR_VB = 1,
593         PFOR_BITMAP = 2,
594         CONSTANT = 3
595 };
596
597 template<unsigned BlockSize, class Docid>
598 const unsigned char *decode_pfor_delta1(const unsigned char *in, unsigned num, bool interleaved, Docid *out)
599 {
600         if (num == 0) {
601                 return in;
602         }
603         in = read_baseval(in, out++);
604
605         for (unsigned i = 1; i < num; i += BlockSize, out += BlockSize) {
606                 const unsigned num_this_block = std::min<unsigned>(num - i, BlockSize);
607                 switch (in[0] >> 6) {
608                 case BlockType::FOR:
609                         if (interleaved && num_this_block == BlockSize) {
610                                 dprintf("%d+%d: blocktype=%d (for, interleaved), bitwidth=%d\n", i, num_this_block, in[0] >> 6, in[0] & 0x3f);
611                                 in = decode_for_interleaved<BlockSize>(in, out);
612                         } else {
613                                 dprintf("%d+%d: blocktype=%d (for), bitwidth=%d\n", i, num_this_block, in[0] >> 6, in[0] & 0x3f);
614                                 in = decode_for(in, num_this_block, out);
615                         }
616                         break;
617                 case BlockType::PFOR_VB:
618                         if (interleaved && num_this_block == BlockSize) {
619                                 dprintf("%d+%d: blocktype=%d (pfor + vb, interleaved), bitwidth=%d\n", i, num_this_block, in[0] >> 6, in[0] & 0x3f);
620                                 in = decode_pfor_vb_interleaved<BlockSize>(in, out);
621                         } else {
622                                 dprintf("%d+%d: blocktype=%d (pfor + vb), bitwidth=%d\n", i, num_this_block, in[0] >> 6, in[0] & 0x3f);
623                                 in = decode_pfor_vb<BlockSize>(in, num_this_block, out);
624                         }
625                         break;
626                 case BlockType::PFOR_BITMAP:
627                         if (interleaved && num_this_block == BlockSize) {
628                                 dprintf("%d+%d: blocktype=%d (pfor + bitmap, interleaved), bitwidth=%d\n", i, num_this_block, in[0] >> 6, in[0] & 0x3f);
629                                 in = decode_pfor_bitmap_interleaved<BlockSize>(in, out);
630                         } else {
631                                 dprintf("%d+%d: blocktype=%d (pfor + bitmap), bitwidth=%d\n", i, num_this_block, in[0] >> 6, in[0] & 0x3f);
632                                 in = decode_pfor_bitmap(in, num_this_block, out);
633                         }
634                         break;
635                 case BlockType::CONSTANT:
636                         dprintf("%d+%d: blocktype=%d (constant), bitwidth=%d\n", i, num_this_block, in[0] >> 6, in[0] & 0x3f);
637                         in = decode_constant(in, num_this_block, out);
638                         break;
639                 }
640         }
641
642         return in;
643 }
644
645 #endif  // !defined(_TURBOPFOR_H)