-
Notifications
You must be signed in to change notification settings - Fork 0
/
packing.cu
1210 lines (1115 loc) · 53.1 KB
/
packing.cu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <cuda_runtime.h>
#include "buf_mgmt.h"
#include "gcli_budget.h"
#include "pred.h"
#include "bitpacking.h"
#include "precinct.h"
#include "sigbuffer.h"
#include "gcli_methods.h"
#include "rate_control.h"
#include "packing.cuh"
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <assert.h>
#include "libjxs.h"
#include "xs_config.h"
#include "xs_markers.h"
#include "common.h"
#include "precinct.h"
#include "buf_mgmt.h"
#include "bitpacking.h"
#include "budget.h"
#include "packing.h"
#include "quant.h"
#include "ids.h"
#include "dwt.h"
#include "mct.h"
#include "nlt.h"
/*
nvcc bitpacking.c budget.c buf_mgmt.c data_budget.c dwt.c gcli_budget.c gcli_methods.c ids.c image.c mct.c nlt.c packing.c precinct.c precinct_budget.c precinct_budget_table.c pred.c predbuffer.c quant.c rate_control.c sb_weighting.c sig_flags.c sigbuffer.c version.c xs_config.c xs_config_parser.c xs_dec.c xs_markers.c packing.cu xs_dec_main.c file_io.c cmdline_options.c file_sequence.c image_open.c v210.c rgb16.c yuv16.c planar.c uyvy8.c argb.c mono.c ppm.c pgx.c helpers.c -o jpegxs_decoder -w -rdc=true -gencode=arch=compute_61,code=compute_61
*/
#define SIGFLAGS_NEXTLVL_SIZE(w, g) (((w) + (g)-1) / (g))
#define MAXB (sizeof(uint64_t) * 8)
__global__ void kernel_convert_ipx_htobe64(uint64_t *bitstream_ptr, uint64_t len)
{
const uint64_t tid = threadIdx.x + blockIdx.x * blockDim.x;
if (tid < len)
{
uint64_t in = bitstream_ptr[tid];
union
{
uint64_t integer;
uint8_t bytes[8];
} a, b;
a.integer = in;
for (int i = 0; i < 8; i++)
b.bytes[i] = a.bytes[7 - i];
bitstream_ptr[tid] = b.integer;
}
}
void gpu_convert_ipx_htobe64(uint64_t *bitstream_ptr, uint64_t max_size)
{
const int block_size = BLOCK_SIZE;
const int grid_size = (max_size + block_size - 1) / block_size;
kernel_convert_ipx_htobe64<<<grid_size, block_size>>>(bitstream_ptr, max_size);
}
__global__ void kernel_compute_gtli_tables(gpu_unpacked_info_t *infos,
const uint8_t *sb_gains, const uint8_t *sb_priority,
const uint32_t n_lvls, const uint32_t column_num, const uint32_t len)
{
const uint32_t tid = threadIdx.x + blockIdx.x * blockDim.x;
if (tid < len)
{
const uint32_t prec_y_idx = tid / (n_lvls * column_num);
const uint32_t column = (tid / n_lvls) % column_num;
const uint32_t lvl = tid % n_lvls;
gpu_unpacked_info_t info_cur = infos[prec_y_idx * column_num + column];
const int gain = sb_gains[lvl];
const int scenario = info_cur.quantization;
const int refinement = info_cur.refinement;
int val = scenario - gain;
const uint8_t add_1bp = (sb_priority[lvl] < refinement);
if (add_1bp)
val -= 1;
val = MAX(val, 0);
val = MIN(val, MAX_GCLI);
info_cur.gtli_table_data[lvl] = info_cur.gtli_table_gcli[lvl] = val;
}
}
inline int prec_y_idx_is_first_of_slice(const ids_t *ids, const uint32_t prec_y_idx, const uint32_t slice_height)
{
assert(prec_y_idx >= 0 && slice_height > 0);
return (((prec_y_idx * ids->ph) % slice_height) == 0);
}
inline int precinct_subpkt_of(const ids_t *ids, uint32_t position)
{
return ids->pi[position].s;
}
__device__ __host__ void precinct_band_index_of(const ids_t *ids, uint32_t position, uint32_t *val)
{
*val = ids->pi[position].b;
}
__device__ __host__ void precinct_ypos_of(const ids_t *ids, uint32_t position, uint32_t *val)
{
*val = ids->pi[position].y - ids->l0[ids->pi[position].b];
}
__device__ __host__ void precinct_in_band_height_of(const ids_t *ids, const uint32_t prec_y_idx, uint32_t band_index, uint32_t *val)
{
const int is_last_precinct_y = (prec_y_idx < (ids->npy - 1)) ? 0 : 1;
*val = ids->l1[is_last_precinct_y][band_index] - ids->l0[band_index];
}
__device__ __host__ void precinct_is_line_present(const ids_t *ids, const uint32_t prec_y_idx, uint32_t lvl, uint32_t ypos, uint32_t *val)
{
precinct_in_band_height_of(ids, prec_y_idx, lvl, val);
*val = ypos < *val;
}
__device__ __host__ void precinct_gcli_width_of(uint32_t *gclis_sizes, int idx_from_level[MAX_PRECINCT_HEIGHT][MAX_PACKETS], uint32_t column, uint32_t npi, uint32_t band_index, uint32_t *val)
{
int idx = idx_from_level[0][band_index];
*val = gclis_sizes[column * npi + idx];
}
__device__ __host__ void precinct_gcli_offset_of(uint32_t *prefix_sum_of_size, int idx_from_level[MAX_PRECINCT_HEIGHT][MAX_PACKETS], uint32_t column, uint32_t npi, uint32_t band_index, uint32_t *val)
{
int idx = idx_from_level[0][band_index];
*val = prefix_sum_of_size[column * npi + idx];
}
__device__ void _device_read_n_bits(uint64_t *bitstream_ptr, uint64_t *bitstream_ptr_cur, uint32_t bit_offset,
uint64_t max_size, uint64_t *val, uint16_t nbits)
{
bitstream_ptr_cur += bit_offset / MAXB;
bit_offset %= MAXB;
uint64_t temp = 0;
int available0 = MAXB - bit_offset;
int len0 = (available0 >= nbits) ? nbits : available0;
int len1 = nbits - len0;
if (len0)
{
temp |= (((*bitstream_ptr_cur) >> (available0 - len0)) << len1);
}
if (len1)
{
uint64_t cur = 0UL;
bitstream_ptr_cur++;
if ((uint64_t)(bitstream_ptr_cur + 1 - bitstream_ptr) * 8 <= max_size)
{
cur = *bitstream_ptr_cur;
}
else
{
for (uint64_t i = 0; i < (max_size % 8); ++i)
{
((uint8_t *)&cur)[i] = ((uint8_t *)(bitstream_ptr_cur))[i];
}
}
bit_offset = 0;
temp |= ((cur) >> (MAXB - len1));
}
if (nbits < 64)
{
*val = temp & ((1ULL << nbits) - 1ULL);
}
}
__device__ void _device_gcli_method_is_enabled(uint32_t enabled, int gcli_method, int precinct_group, int *ret)
{
#define is_run_enabled(run) ((1ULL << (run)) & (enabled_runs))
const uint32_t enabled_alphabets = (enabled >> METHOD_ENABLE_MASK_ALPHABETS_OFFSET) & ((1UL << ALPHABET_COUNT) - 1);
const uint32_t enabled_predictions = (enabled >> METHOD_ENABLE_MASK_PREDICTIONS_OFFSET) & ((1UL << PRED_COUNT) - 1);
const uint32_t enabled_runs = (enabled >> METHOD_ENABLE_MASK_RUNS_OFFSET) & ((1UL << RUN_COUNT) - 1);
const int alphabet = method_get_alphabet(gcli_method);
const int pred = method_get_pred(gcli_method);
const int run = method_get_run(gcli_method);
if (!((1ULL << alphabet) & enabled_alphabets))
{
*ret = 0;
return;
}
if (alphabet != ALPHABET_RAW_4BITS)
{
if (!is_run_enabled(run))
{
*ret = 0;
return;
}
if (!((1ULL << pred) & enabled_predictions))
{
*ret = 0;
return;
}
if (precinct_group == PRECINCT_FIRST_OF_SLICE && pred != PRED_NONE)
{
*ret = 0;
return;
}
}
else
{
if (run != RUN_NONE || pred != PRED_NONE)
{
*ret = 0;
return;
}
}
*ret = 1;
return;
}
__device__ void _device_gcli_method_get_signaling(int gcli_method, uint32_t enabled_methods, int *ret)
{
int signaling = 0;
if (gcli_method == method_get_idx(ALPHABET_RAW_4BITS, 0, 0))
{
*ret = -1;
return;
}
const int uses_run = ((method_get_run(gcli_method) == RUN_SIGFLAGS_ZRF) || (method_get_run(gcli_method) == RUN_SIGFLAGS_ZRCSF));
*ret = (uses_run ? 0x2 : 0) | ((method_get_pred(gcli_method) == PRED_VER) ? 0x1 : 0);
return;
}
__global__ void kernel_read_gcli_sb_methods(gpu_unpacked_info_t *infos, uint64_t *bitstream_ptr,
uint64_t max_size, const int enabled_methods,
const uint32_t bands_count, const uint32_t column_num,
const uint32_t len)
{
const uint32_t tid = threadIdx.x + blockIdx.x * blockDim.x;
if (tid < len)
{
const uint32_t prec_y_idx = tid / (bands_count * column_num);
const uint32_t column = (tid / bands_count) % column_num;
const uint32_t band_idx = tid % bands_count;
uint64_t val;
gpu_unpacked_info_t info = infos[prec_y_idx * column_num + column];
uint64_t *bitstream_ptr_cur = bitstream_ptr + info.gcli_sb_methods_bitstream_info.ptr_diff;
uint32_t bit_offset = info.gcli_sb_methods_bitstream_info.offset;
_device_read_n_bits(bitstream_ptr, bitstream_ptr_cur, bit_offset + GCLI_METHOD_NBITS * band_idx, max_size, &val, GCLI_METHOD_NBITS);
for (int gcli_method = 0; gcli_method < GCLI_METHODS_NB; gcli_method++)
{
int ret = 0;
_device_gcli_method_is_enabled(enabled_methods, gcli_method, PRECINCT_ALL, &ret);
if (ret)
{
_device_gcli_method_get_signaling(gcli_method, enabled_methods, &ret);
if (ret == (int)val)
{
info.gcli_sb_methods[band_idx] = gcli_method;
return;
}
}
}
info.gcli_sb_methods[band_idx] = -1;
return;
}
}
__global__ void kernel_read_inclusion_mask(gpu_unpacked_info_t *info_cur, uint64_t *bitstream_ptr, uint64_t *bitstream_ptr_cur,
uint32_t bit_offset, uint32_t gcli_band_offset,
uint64_t max_size,
const uint32_t significance_group_size,
const uint32_t len)
{
uint32_t tid = threadIdx.x + blockIdx.x * blockDim.x;
if (tid < len)
{
uint64_t val = 0;
_device_read_n_bits(bitstream_ptr, bitstream_ptr_cur, bit_offset + tid, max_size, &val, 1);
val = (!val) & 0x1;
tid += gcli_band_offset;
for (int i = 0; i < significance_group_size; i++)
{
info_cur->gpu_inclusion_mask[tid + i] = val;
}
}
}
__global__ void kernel_prepare_inclusion_mask(uint32_t *gclis_prefix_sum, uint32_t *gclis_sizes, gpu_unpacked_info_t *info_cur, int idx_from_level[MAX_PRECINCT_HEIGHT][MAX_PACKETS], uint64_t *bitstream_ptr,
uint64_t max_size,
ids_t *ids,
const uint32_t significance_group_size,
uint32_t prec_y_idx, uint32_t column, uint32_t subpkt,
const uint32_t len)
{
uint32_t tid = threadIdx.x + blockIdx.x * blockDim.x;
if (tid < len)
{
const int idx = info_cur->line_idxs[subpkt].start_idx + tid;
uint32_t lvl;
precinct_band_index_of(ids, idx, &lvl);
uint32_t ypos;
precinct_ypos_of(ids, idx, &ypos);
uint32_t is_present;
precinct_is_line_present(ids, prec_y_idx, lvl, ypos, &is_present);
if (is_present)
{
const int sb_gcli_method = info_cur->gcli_sb_methods[lvl];
if (method_uses_sig_flags(sb_gcli_method))
{
const int block_size = BLOCK_SIZE;
uint32_t gcli_width;
// precinct_gcli_width_of(multi_buf_t * gclis_mb, int **idx_from_level, int band_index, int *val)
precinct_gcli_width_of(gclis_sizes, idx_from_level, column, ids->npi, lvl, &gcli_width);
uint64_t *bitstream_ptr_cur = info_cur->significance_bitstream_infos->ptr_diff + bitstream_ptr;
uint32_t bit_offset = info_cur->significance_bitstream_infos->offset;
uint32_t gcli_band_offset;
precinct_gcli_offset_of(gclis_prefix_sum, idx_from_level, column, ids->npi, lvl, &gcli_band_offset);
const int grid_size = (gcli_width / significance_group_size + block_size - 1) / block_size;
kernel_read_inclusion_mask<<<grid_size, block_size>>>(info_cur, bitstream_ptr, bitstream_ptr_cur, bit_offset,
gcli_band_offset, max_size, significance_group_size, gcli_width / significance_group_size);
}
}
}
}
__global__ void kernel_unpack_gclis_significance(uint32_t *gclis_prefix_sum, uint32_t *gclis_sizes, gpu_unpacked_info_t *infos, int idx_from_level[MAX_PRECINCT_HEIGHT][MAX_PACKETS], uint64_t *bitstream_ptr,
ids_t *ids, const uint32_t significance_group_size, uint32_t nb_subpkts, uint32_t column_num, const uint32_t max_size, uint32_t len)
{
const uint32_t tid = threadIdx.x + blockIdx.x * blockDim.x;
if (tid < len)
{
const uint32_t subpkt = tid % nb_subpkts;
const uint32_t column = (tid / nb_subpkts) % column_num;
const uint32_t prec_y_idx = tid / (nb_subpkts * column_num);
gpu_unpacked_info_t *info_cur = infos + prec_y_idx * column_num + column;
const uint32_t block_size = BLOCK_SIZE;
const uint32_t prepare_len = info_cur->line_idxs[subpkt].stop_idx - info_cur->line_idxs[subpkt].start_idx + 1;
const uint32_t grid_size = (prepare_len + block_size - 1) / block_size; // ctx->xs_config->p.S_s
kernel_prepare_inclusion_mask<<<grid_size, block_size>>>(gclis_prefix_sum, gclis_sizes, info_cur, idx_from_level, bitstream_ptr, max_size, ids, significance_group_size, prec_y_idx, column, subpkt, prepare_len);
}
}
void gpu_unpack_gtlis_and_gclis_significance(gpu_xs_dec_context_t *ctx, gpu_unpacked_info_t *infos, const ids_t *ids,
int nb_subpkts, const int n_precs, const int column_num)
{
cudaStream_t streams[2];
cudaStreamCreate(streams);
cudaStreamCreate(streams + 1);
const uint32_t block_size = BLOCK_SIZE;
const uint32_t bands_count = ids->nbands * n_precs * column_num;
uint32_t grid_size = (bands_count + block_size - 1) / block_size;
kernel_read_gcli_sb_methods<<<grid_size, block_size, 0, streams[0]>>>(infos, ctx->gpu_bitstream_ptr, ctx->max_size, ctx->enabled_methods, ids->nbands, column_num, bands_count);
// put to different stream
const uint32_t gtli_tables_len = ctx->level_count * n_precs * column_num;
grid_size = (gtli_tables_len + block_size - 1) / block_size;
kernel_compute_gtli_tables<<<grid_size, block_size, 0, streams[1]>>>(infos, ctx->gpu_lvl_gains, ctx->gpu_lvl_priorities, ctx->level_count, column_num, gtli_tables_len);
cudaDeviceSynchronize();
const uint32_t significance_len = ctx->level_count * n_precs * column_num;
grid_size = (significance_len + block_size - 1) / block_size;
kernel_unpack_gclis_significance<<<grid_size, block_size>>>(ctx->gpu_gclis_prefix_sum, ctx->gpu_gclis_sizes, infos, ctx->idx_from_level, ctx->gpu_bitstream_ptr, ctx->gpu_ids, ctx->xs_config->p.S_s, nb_subpkts, column_num, ctx->max_size, significance_len);
cudaDeviceSynchronize();
cudaStreamDestroy(streams[0]);
cudaStreamDestroy(streams[1]);
}
__global__ void kernel_unpack_raw_gclis(uint64_t *bitstream_ptr, uint64_t *bitstream_ptr_cur, uint32_t bit_offset, uint64_t max_size, gcli_data_t *gclis, uint32_t gcli_width)
{
const uint32_t tid = threadIdx.x + blockIdx.x * blockDim.x;
if (tid < gcli_width)
{
uint64_t val;
_device_read_n_bits(bitstream_ptr, bitstream_ptr_cur, bit_offset + tid * 4, max_size, &val, 4);
gclis[tid] = (gcli_data_t)val;
}
}
__device__ void _device_read_unary_unsigned(uint64_t *bitstream_ptr, uint64_t *bitstream_ptr_cur, uint32_t bit_offset, uint64_t max_size, int8_t *ret, uint32_t *n_bits)
{
uint64_t bit = 1;
int val = -1;
while (bit)
{
_device_read_n_bits(bitstream_ptr, bitstream_ptr_cur, bit_offset++, max_size, &bit, 1);
++val;
}
*ret = val;
*n_bits += val + 1;
}
__device__ void _device_read_unary_signed(uint64_t *bitstream_ptr, uint64_t *bitstream_ptr_cur, uint32_t bit_offset, uint64_t max_size, int8_t *ret, unary_alphabet_t alphabet, uint32_t *n_bits)
{
int val = -1;
uint32_t bit_offset_flag = bit_offset;
switch (alphabet)
{
case UNARY_ALPHABET_FULL:
{
uint64_t bit = 1;
do
{
_device_read_n_bits(bitstream_ptr, bitstream_ptr_cur, bit_offset++, max_size, &bit, 1);
val++;
} while (bit && val < 17);
if (val == 1)
val = -1;
else if (val == 2)
val = 1;
else if (val == 3)
val = -2;
else if (val == 4)
val = 2;
else if (val > 4)
{
val -= 2;
_device_read_n_bits(bitstream_ptr, bitstream_ptr_cur, bit_offset++, max_size, &bit, 1);
if (bit)
val = -val;
}
*ret = val;
break;
}
case UNARY_ALPHABET_4_CLIPPED:
{
uint64_t bit = 1;
do
{
_device_read_n_bits(bitstream_ptr, bitstream_ptr_cur, bit_offset++, max_size, &bit, 1);
val++;
} while (bit && val < 15);
if (val == 1)
val = -1;
else if (val == 2)
val = 1;
else if (val == 3)
val = -2;
else if (val == 4)
val = 2;
if (val > 4)
{
val -= 2;
if ((val) && (val != MAX_UNARY - 2))
_device_read_n_bits(bitstream_ptr, bitstream_ptr_cur, bit_offset++, max_size, &bit, 1);
if (bit)
val = -val;
}
*ret = val;
break;
}
case UNARY_ALPHABET_0:
{
uint64_t bit = 1;
while (bit && (val < MAX_UNARY))
{
_device_read_n_bits(bitstream_ptr, bitstream_ptr_cur, bit_offset++, max_size, &bit, 1);
val++;
}
if (val && (val != MAX_UNARY))
_device_read_n_bits(bitstream_ptr, bitstream_ptr_cur, bit_offset++, max_size, &bit, 1);
if (bit)
val = -val;
*ret = val;
break;
}
default:
assert(!"invalid alphabet specified");
return;
}
*n_bits += bit_offset - bit_offset_flag;
}
__device__ void _device_read_bounded_code(uint64_t *bitstream_ptr, uint64_t *bitstream_ptr_cur, uint32_t bit_offset, uint64_t max_size,
int8_t min_allowed, int8_t max_allowed,
int8_t *val, uint32_t *n_bits)
{
int8_t tmp;
const int trigger = abs(min_allowed);
_device_read_unary_unsigned(bitstream_ptr, bitstream_ptr_cur, bit_offset, max_size, &tmp, n_bits);
if (tmp > 2 * trigger)
{
*val = tmp - trigger;
}
else
{
*val = (tmp + 1) / 2;
if (tmp % 2)
{
*val = -*val;
}
}
}
__device__ void _device_unary_decode2(uint64_t *bitstream_ptr, uint64_t *bitstream_ptr_cur, uint32_t bit_offset, uint64_t max_size, gcli_pred_t *gcli_pred_buf, uint32_t *inclusion_mask,
int len, int no_sign, int sb_gcli_method, unary_alphabet_t alph, uint32_t *n_bits)
{
for (int i = 0; i < len; i++)
{
if (!method_uses_sig_flags(sb_gcli_method) || inclusion_mask[i])
{
if (!no_sign)
{
_device_read_unary_signed(bitstream_ptr, bitstream_ptr_cur, bit_offset + *n_bits, max_size, gcli_pred_buf + i, alph, n_bits);
}
else
{
_device_read_unary_unsigned(bitstream_ptr, bitstream_ptr_cur, bit_offset + *n_bits, max_size, gcli_pred_buf + i, n_bits);
}
}
else
{
gcli_pred_buf[i] = 0;
}
}
}
__device__ void _device_bounded_decode2(uint64_t *bitstream_ptr, uint64_t *bitstream_ptr_cur, uint32_t bit_offset, uint64_t max_size,
gcli_pred_t *gcli_pred_buf, uint32_t *inclusion_mask, gcli_data_t *gcli_top_buf,
int sb_gcli_method, int gtli, int gtli_top, int len,
uint32_t *n_bits)
{
for (int i = 0; i < len; i++)
{
if (!method_uses_sig_flags(sb_gcli_method) || inclusion_mask[i])
{
int min_value = -20;
int max_value = 20;
if (gcli_top_buf)
{
int predictor = MAX(gcli_top_buf[i], MAX(gtli, gtli_top));
min_value = -MAX(predictor - gtli, 0);
max_value = MAX(MAX_GCLI - MAX(predictor, gtli), 0);
}
_device_read_bounded_code(bitstream_ptr, bitstream_ptr_cur, bit_offset, max_size, min_value, max_value, &gcli_pred_buf[i], n_bits);
}
else
{
gcli_pred_buf[i] = 0;
}
}
}
__global__ void kernel_tco_pred_ver_inverse(gcli_data_t *gclis_top, gcli_data_t *gclis, uint32_t *inclusion_mask, const int gtli, const int gtli_top, const int sig_flags_are_zrcsf, uint32_t len)
{
const uint32_t tid = threadIdx.x + blockIdx.x * blockDim.x;
if (tid < len)
{
int top = MAX(gclis_top[tid], MAX(gtli, gtli_top));
gclis[tid] = top + gclis[tid];
if (gclis[tid] <= gtli)
{
gclis[tid] -= gtli;
}
if (sig_flags_are_zrcsf && !inclusion_mask[tid])
{
gclis[tid] = 0;
}
}
}
__global__ void kernel_tco_pred_none_inverse(gcli_data_t *gclis, const int gtli, uint32_t len)
{
const uint32_t tid = threadIdx.x + blockIdx.x * blockDim.x;
if (tid < len)
{
gclis[tid] = (gclis[tid] > 0) ? gclis[tid] + gtli : 0;
}
}
__global__ void kernel_unpack_gclis(gpu_unpacked_info_t *infos, uint64_t *bitstream_ptr, uint64_t max_size, uint32_t *gclis_prefix_sum, uint32_t *gclis_sizes,
int idx_from_level[MAX_PRECINCT_HEIGHT][MAX_PACKETS],
uint32_t len,
const uint32_t slice_height, const uint32_t column_num,
uint32_t nb_subpkts, const ids_t *gpu_ids)
{
const uint32_t tid = threadIdx.x + blockIdx.x * blockDim.x;
if (tid < len)
{
const uint32_t column = tid % column_num;
const uint32_t slice_prec_y_idx = slice_height * (tid / column_num); //????
const uint32_t bands_count = gpu_ids->nbands;
int *gtli_table_top = NULL;
gcli_data_t *gclis_top = NULL;
for (int line_idx = 0; line_idx < slice_height; line_idx += gpu_ids->ph)
{
const int is_first_of_slice = !line_idx;
const int prec_y_idx = ((line_idx + slice_prec_y_idx) / gpu_ids->ph);
gpu_unpacked_info_t unpack_cur = infos[tid];
for (int subpkt = 0; subpkt < nb_subpkts; subpkt++)
{
const int uses_raw_fallback = unpack_cur.uses_raw_fallback[subpkt];
const int idx_start = unpack_cur.line_idxs[subpkt].start_idx;
const int idx_stop = unpack_cur.line_idxs[subpkt].stop_idx;
uint64_t *bitstream_ptr_cur = bitstream_ptr + unpack_cur.gcli_bitstream_infos[subpkt].ptr_diff;
uint32_t bit_offset = unpack_cur.gcli_bitstream_infos[subpkt].offset;
for (int idx = idx_start; idx <= idx_stop; idx++)
{
uint32_t lvl;
precinct_band_index_of(gpu_ids, idx, &lvl);
uint32_t ypos;
precinct_ypos_of(gpu_ids, idx, &ypos);
if (ypos == 0 && !is_first_of_slice)
{
const int is_last_precinct_y = ((prec_y_idx - 1) < (gpu_ids->npy - 1)) ? 0 : 1;
const int ylast = gpu_ids->l1[is_last_precinct_y][lvl] - gpu_ids->l0[lvl] - 1;
int temp_idx = idx_from_level[ylast][lvl];
uint32_t gcli_offset_top;
precinct_gcli_offset_of(gclis_prefix_sum, idx_from_level, column, gpu_ids->npi, temp_idx, &gcli_offset_top);
gclis_top += gcli_offset_top;
}
else if (ypos != 0)
{
const int ylast = ypos - 1;
int temp_idx = idx_from_level[ylast][lvl];
uint32_t gcli_offset_top;
precinct_gcli_offset_of(gclis_prefix_sum, idx_from_level, column, gpu_ids->npi, temp_idx, &gcli_offset_top);
gclis_top = unpack_cur.gpu_gcli_buf + gcli_offset_top;
}
else
{
gclis_top = NULL;
}
uint32_t is_present;
precinct_is_line_present(gpu_ids, prec_y_idx, lvl, ypos, &is_present);
if (is_present)
{
int sb_gcli_method = uses_raw_fallback ? method_get_idx(ALPHABET_RAW_4BITS, 0, 0) : unpack_cur.gcli_sb_methods[gpu_ids->pi[idx].b];
const int gtli = unpack_cur.gtli_table_gcli[lvl];
const int gtli_top = (ypos == 0) ? ((gtli_table_top != NULL) ? gtli_table_top[lvl] : gtli) : (gtli);
uint32_t gcli_width;
precinct_gcli_width_of(gclis_sizes, idx_from_level, column, gpu_ids->npi, lvl, &gcli_width);
uint32_t gcli_offset;
precinct_gcli_offset_of(gclis_prefix_sum, idx_from_level, column, gpu_ids->npi, lvl, &gcli_offset);
gcli_data_t *gclis = unpack_cur.gpu_gcli_buf + gcli_offset;
uint32_t *inclusion_mask = unpack_cur.gpu_inclusion_mask + gcli_offset;
unary_alphabet_t alph = FIRST_ALPHABET;
if (method_is_raw(sb_gcli_method))
{
const int block_size = BLOCK_SIZE;
const int grid_size = (gcli_width + block_size - 1) / block_size;
kernel_unpack_raw_gclis<<<grid_size, block_size>>>(bitstream_ptr, bitstream_ptr_cur, bit_offset, max_size, gclis, gcli_width);
bit_offset += gcli_width << 2;
}
else
{
uint32_t n_bits = 0;
int no_prediction = method_uses_no_pred(sb_gcli_method) || ((method_uses_ver_pred(sb_gcli_method) && method_get_alphabet(sb_gcli_method) == ALPHABET_UNARY_UNSIGNED_BOUNDED) && (gclis_top == NULL));
int sig_flags_are_zrcsf = (method_get_run(sb_gcli_method) == RUN_SIGFLAGS_ZRCSF);
if ((method_get_alphabet(sb_gcli_method) != ALPHABET_UNARY_UNSIGNED_BOUNDED) || no_prediction)
{
_device_unary_decode2(bitstream_ptr, bitstream_ptr_cur, bit_offset, max_size, gclis, inclusion_mask, gcli_width, no_prediction, sb_gcli_method, alph, &n_bits);
}
else
{
_device_bounded_decode2(bitstream_ptr, bitstream_ptr_cur, bit_offset, max_size, gclis, inclusion_mask, gclis_top, sb_gcli_method, gtli, gtli_top, gcli_width, &n_bits);
}
bit_offset += n_bits;
if ((method_uses_ver_pred(sb_gcli_method) && gclis_top))
{
const int block_size = BLOCK_SIZE;
const int grid_size = (gcli_width + block_size - 1) / block_size;
kernel_tco_pred_ver_inverse<<<grid_size, block_size>>>(gclis_top, gclis, inclusion_mask, gtli, gtli_top, sig_flags_are_zrcsf, gcli_width);
}
else if (method_uses_no_pred(sb_gcli_method) || (method_uses_ver_pred(sb_gcli_method) && gclis_top == NULL))
{
const int block_size = BLOCK_SIZE;
const int grid_size = (gcli_width + block_size - 1) / block_size;
kernel_tco_pred_none_inverse<<<grid_size, block_size>>>(gclis, gtli, gcli_width);
}
}
}
}
}
gtli_table_top = unpack_cur.gtli_table_gcli;
gclis_top = unpack_cur.gpu_gcli_buf;
}
}
}
void gpu_unpack_gclis(gpu_xs_dec_context_t *ctx, gpu_unpacked_info_t *infos, const uint32_t column_num)
{
const uint32_t block_size = BLOCK_SIZE;
const uint32_t slice_height = ctx->xs_config->p.slice_height;
const uint32_t slice_size = SIGFLAGS_NEXTLVL_SIZE(ctx->ids.h, slice_height) * column_num;
const uint32_t grid_size = (slice_size + block_size - 1) / block_size;
kernel_unpack_gclis<<<grid_size, block_size>>>(infos, ctx->gpu_bitstream_ptr, ctx->max_size, ctx->gpu_gclis_prefix_sum, ctx->gpu_gclis_sizes, ctx->idx_from_level, slice_size, slice_height, column_num, ctx->nb_subpkts, ctx->gpu_ids);
}
__global__ void kernel_unpack_data(uint64_t *bitstream_ptr, uint64_t *bitstream_ptr_cur, uint32_t bit_offset, uint64_t max_size,
gcli_data_t *gclis, uint32_t *inclusion_mask,
const int group_size, const int gtli, const uint8_t sign_packing,
xs_data_in_t *image, uint64_t dst_inc, const int quant_type, const uint32_t len)
{
const uint32_t tid = threadIdx.x + blockIdx.x * blockDim.x;
if (tid < len)
{
// tid is
const int i = tid % group_size;
const int group = tid / group_size;
const int gcli = gclis[group];
uint32_t ret = 0;
if (gcli > gtli)
{
uint64_t val;
bit_offset += inclusion_mask[group - 1] * group_size;
for (int bp = 0; bp < gcli - gtli; bp++)
{
_device_read_n_bits(bitstream_ptr, bitstream_ptr_cur, bit_offset + group_size + i + group_size * bp, max_size, &val, 1);
ret |= (sig_mag_data_t)((val & 0x01) << (gcli - 1 - bp));
}
if (sign_packing == 0)
{
_device_read_n_bits(bitstream_ptr, bitstream_ptr_cur, bit_offset + i, max_size, &val, 1);
ret |= (sig_mag_data_t)val << SIGN_BIT_POSITION;
// dequant
if (quant_type == 1)
{
int sign = (ret & SIGN_BIT_MASK);
int phi = ret & ~SIGN_BIT_MASK;
int zeta = gcli - gtli + 1;
int rho = 0;
for (rho = 0; phi > 0; phi >>= zeta)
rho += phi;
ret = sign | rho;
}
else if (quant_type == 0)
{
if (gtli > 0 && (ret & ~SIGN_BIT_MASK))
ret |= (1 << (gtli - 1));
}
}
}
image[tid * dst_inc] = ret;
}
}
__global__ void kernel_unpack_sign(uint64_t *bitstream_ptr, uint64_t *bitstream_ptr_cur, uint32_t bit_offset, uint64_t max_size,
gcli_data_t *gclis, uint32_t *inclusion_mask, const int group_size, const int gtli, const uint8_t sign_packing,
xs_data_in_t *image, uint64_t dst_inc, const int quant_type, const uint32_t len)
{
const uint32_t tid = threadIdx.x + blockIdx.x * blockDim.x;
if (tid < len)
{
// tid is
const int i = tid % group_size;
const int group = tid / group_size;
const int gcli = gclis[group];
uint32_t ret = image[tid * dst_inc];
if (ret)
{
uint64_t val;
bit_offset += inclusion_mask[group - 1] * group_size;
_device_read_n_bits(bitstream_ptr, bitstream_ptr_cur, bit_offset + i, max_size, &val, 1);
ret |= (sig_mag_data_t)((val & 0x01) << SIGN_BIT_POSITION);
// dequant
if (quant_type == 1)
{
int sign = (ret & SIGN_BIT_MASK);
int phi = ret & ~SIGN_BIT_MASK;
int zeta = gcli - gtli + 1;
int rho = 0;
for (rho = 0; phi > 0; phi >>= zeta)
rho += phi;
ret = sign | rho;
}
else if (quant_type == 0)
{
if (gtli > 0 && (ret & ~SIGN_BIT_MASK))
ret |= (1 << (gtli - 1));
}
image[tid * dst_inc] = ret;
}
}
}
// __global__ void kernel_prepare_data(bit_unpacker_t *bitstream, sig_mag_data_t *buf, int buf_len, gcli_data_t *gclis, int group_size, int gtli, const uint8_t sign_packing)
// {
// const uint32_t tid = threadIdx.x + blockIdx.x * blockDim.x;
// if (tid < len)
// {
// }
// }
__device__ __host__ void precinct_ptr_for_line_of_band(const ids_t *ids, xs_image_t *image,
const int band_idx, const int in_band_ypos,
const uint32_t prec_y_idx, const uint32_t column, const uint32_t is_last_column,
xs_data_in_t **ptr, uint64_t *x_inc, uint64_t *len)
{
const int c = ids->band_idx_to_c_and_b[band_idx].c;
const int b = ids->band_idx_to_c_and_b[band_idx].b;
// Handle precinct component base.
xs_data_in_t *the_ptr = image->comps_array[c];
// Handle start y position of band.
the_ptr += ids->band_is_high[b].y * ((uint64_t)1 << (ids->band_d[c][b].y - 1)) * ids->comp_w[c];
// Handle start x position of band.
the_ptr += ids->band_is_high[b].x * ((uint64_t)1 << (ids->band_d[c][b].x - 1));
// Handle precinct y index.
the_ptr += (uint64_t)ids->comp_w[c] * (ids->ph >> (image->sy[c] - 1)) * prec_y_idx;
// Go to ypos line in precinct.
the_ptr += (uint64_t)ids->comp_w[c] * in_band_ypos * ((uint64_t)1 << ids->band_d[c][b].y);
// Handle precinct x index.
the_ptr += (ids->pw[0] >> (image->sx[c] - 1)) * column;
*ptr = the_ptr; // first sample
*x_inc = 1ull << ids->band_d[c][b].x; // increment to next sample
*len = ids->pwb[is_last_column][band_idx]; // number of samples in line of band in precinct
}
__global__ void kernel_unpack_data_and_sign(uint64_t *bitstream_ptr, const uint64_t max_size, gpu_unpacked_info_t *infos,
uint32_t *gclis_prefix_sum, uint32_t *gclis_sizes, int idx_from_level[MAX_PRECINCT_HEIGHT][MAX_PACKETS],
const uint32_t nb_subpkts, const uint32_t column_num, const int sign_packing,
const uint32_t group_size, const uint32_t len, const int quant_type,
xs_image_t *gpu_image, ids_t *gpu_ids)
{
const uint32_t tid = threadIdx.x + blockIdx.x * blockDim.x;
if (tid < len)
{
const uint32_t subpkt = tid % nb_subpkts;
const uint32_t column = (tid / nb_subpkts) % column_num;
const uint32_t prec_y_idx = tid / (nb_subpkts * column_num);
gpu_unpacked_info_t *info_cur = infos + prec_y_idx * column_num + column;
uint32_t start_idx = info_cur->line_idxs[subpkt].start_idx;
uint32_t stop_idx = info_cur->line_idxs[subpkt].stop_idx;
uint32_t gcli_width;
uint32_t gcli_offset;
uint64_t *bitstream_ptr_cur = info_cur->data_bitstream_infos[subpkt].ptr_diff + bitstream_ptr;
uint32_t bit_offset = info_cur->data_bitstream_infos[subpkt].offset;
for (int idx = start_idx; idx <= stop_idx; idx++)
{
uint32_t lvl;
precinct_band_index_of(gpu_ids, idx, &lvl);
uint32_t ypos;
precinct_ypos_of(gpu_ids, idx, &ypos);
uint32_t is_present;
precinct_is_line_present(gpu_ids, prec_y_idx, lvl, ypos, &is_present);
if (is_present)
{
const int gtli = info_cur->gtli_table_gcli[lvl];
precinct_gcli_width_of(gclis_sizes, idx_from_level, column, gpu_ids->npi, lvl, &gcli_width);
precinct_gcli_offset_of(gclis_prefix_sum, idx_from_level, column, gpu_ids->npi, lvl, &gcli_offset);
gcli_data_t *gclis = gcli_width + info_cur->gpu_gcli_buf;
uint8_t offset_width = (sign_packing == 0) ? group_size : 0;
uint32_t *inclusion_mask = info_cur->gpu_inclusion_mask + gcli_offset;
inclusion_mask[0] = (gclis[0] > gtli) ? (gclis[0] - gtli + offset_width) : 0;
for (int group = 1; group < gcli_width; group++)
{
inclusion_mask[group] = inclusion_mask[group - 1];
if (gclis[group] > gtli)
{
inclusion_mask[group] += gclis[group] - gtli + offset_width;
}
}
uint32_t bits_sum = inclusion_mask[gcli_width - 1];
const int coff_width = gcli_width * group_size;
xs_data_in_t *dst;
uint64_t dst_inc, dst_len;
uint32_t is_last_column = (column == gpu_ids->npx - 1) ? 1 : 0;
precinct_ptr_for_line_of_band(gpu_ids, gpu_image, lvl, ypos, prec_y_idx, column, is_last_column, &dst, &dst_inc, &dst_len);
int block_size = BLOCK_SIZE;
int grid_size = (coff_width + block_size - 1) / block_size;
kernel_unpack_data<<<grid_size, block_size>>>(bitstream_ptr, bitstream_ptr_cur, bit_offset, max_size, gclis, inclusion_mask, group_size, gtli, sign_packing, dst, dst_inc, quant_type, coff_width);
if (sign_packing)
{
inclusion_mask = (uint32_t *)malloc(sizeof(uint32_t) * coff_width);
inclusion_mask[0] = (dst[0] != 0) ? 1 : 0;
for (int group = 1; group < coff_width; group++)
{
inclusion_mask[group] = inclusion_mask[group - 1];
if (dst[group * dst_inc] != 0)
{
inclusion_mask[group]++;
}
}
grid_size = (coff_width + block_size - 1) / block_size;
kernel_unpack_sign<<<grid_size, block_size>>>(bitstream_ptr, bitstream_ptr_cur, bit_offset, max_size, gclis, inclusion_mask, group_size, gtli, sign_packing, dst, dst_inc, quant_type, coff_width);
free(inclusion_mask);
}
bit_offset += bits_sum;
}
}
}
}
void gpu_unpack_data_and_sign(gpu_xs_dec_context_t *ctx, gpu_unpacked_info_t *infos, xs_image_t *gpu_image, const uint32_t column_num)
{
const uint32_t block_size = BLOCK_SIZE;
const uint32_t n_precs = SIGFLAGS_NEXTLVL_SIZE(ctx->ids.h, ctx->ids.ph) * column_num;
const uint32_t grid_size = (n_precs + block_size - 1) / block_size;
kernel_unpack_data_and_sign<<<grid_size, block_size>>>(ctx->gpu_bitstream_ptr, ctx->max_size, infos,
ctx->gpu_gclis_prefix_sum, ctx->gpu_gclis_sizes, ctx->idx_from_level,
ctx->nb_subpkts, column_num, ctx->use_sign_subpkt,
ctx->group_size, n_precs, ctx->quant_type,
gpu_image, ctx->gpu_ids);
}
void unpack_bit_offset_info(gpu_xs_dec_context_t *ctx, bit_unpacker_t *bitstream, gpu_unpacked_info_t *info, gpu_unpacked_info_t *gpu_info,
uint32_t prec_y_idx, uint32_t column, int extra_bits_before_precinct)
{
uint64_t val;
int empty;
int len_before_subpkt = 0;
int gcli_sb_methods[MAX_NBANDS];
int subpkt = 0;
int subpkt_len;
const uint32_t position_count = ctx->ids.npi;
const bool use_long_precinct_headers = ctx->ids.use_long_precinct_headers;
const int bitpos_prc_start = (int)bitunpacker_consumed_bits(bitstream);
if (ctx->xs_config->verbose > 2)
{
fprintf(stderr, "(bitpos=%d) Precinct (bytepos=%d)\n", bitpos_prc_start, bitpos_prc_start >> 3);
}
cudaDeviceSynchronize();
if (!ctx->is_init)
{
cudaMalloc((void **)&(info->gpu_inclusion_mask), sizeof(uint32_t) * 1);
cudaMalloc((void **)&(info->gpu_gcli_buf), sizeof(gcli_type_t) * 1);
}
// Start of precinct.
bitunpacker_read(bitstream, &val, PREC_HDR_PREC_SIZE);
const int Lprc = info->Lprc = ((int)val << 3);
bitunpacker_read(bitstream, &val, PREC_HDR_QUANTIZATION_SIZE);
const int quantization = info->quantization = (int)val;
bitunpacker_read(bitstream, &val, PREC_HDR_REFINEMENT_SIZE);
const int refinement = info->refinement = (int)val;
bitunpacker_set_info(bitstream, &(info->gcli_sb_methods_bitstream_info));
const int bands_count = ctx->level_count;
bitunpacker_skip(bitstream, bands_count * GCLI_METHOD_NBITS);
// for (int band = 0; band < bands_count; ++band)
// {
// bitunpacker_read(bitstream, &val, GCLI_METHOD_NBITS);
// gcli_sb_methods[band] = gcli_method_from_signaling((int)val, ctx->enabled_methods);
// }
bitunpacker_align(bitstream, PREC_HDR_ALIGNMENT);
const int bitpos_at_prc_data = (int)bitunpacker_consumed_bits(bitstream);
#ifdef PACKING_GENERATE_FRAGMENT_CODE
// Add precinct header bits.
extra_bits_before_precinct += bitpos_at_prc_data - bitpos_prc_start;
#endif
if (ctx->xs_config->verbose > 3)
{
fprintf(stderr, "(bitpos=%d) precinct header read (prec_len=%d quant=(%d,%d)\n", bitpos_at_prc_data, Lprc, quantization, refinement);
}
// compute gtli
// gpu_compute_gtli_tables(quantization, refinement, ctx->level_count, ctx->xs_config->p.lvl_gains, ctx->xs_config->p.lvl_priorities, ctx->gtli_table_data, ctx->gtli_table_gcli, &empty);
for (int idx_start = 0, idx_stop = 0; idx_stop < position_count; idx_stop++)
{
if ((idx_stop != (position_count - 1)) && (precinct_subpkt_of(&ctx->ids, idx_stop) == precinct_subpkt_of(&ctx->ids, idx_stop + 1)))
{
continue;
}
uint32_t lvl;
precinct_band_index_of(&ctx->ids, idx_start, &lvl);
uint32_t ypos;
precinct_ypos_of(&ctx->ids, idx_start, &ypos);
uint32_t is_present;
precinct_is_line_present(&ctx->ids, prec_y_idx, lvl, ypos, &is_present);
if (!is_present)
{
++subpkt;
idx_start = idx_stop + 1;
continue;
}
#ifdef PACKING_GENERATE_FRAGMENT_CODE
const int bitpos_packet_start = (int)bitunpacker_consumed_bits(bitstream);
#endif
// Start of packet.
bitunpacker_read(bitstream, &val, 1);
info->uses_raw_fallback[subpkt] = (int)val & 0x1;
bitunpacker_read(bitstream, &val, use_long_precinct_headers ? PKT_HDR_DATA_SIZE_LONG : PKT_HDR_DATA_SIZE_SHORT);
info->data_len[subpkt] = (int)val;
bitunpacker_read(bitstream, &val, use_long_precinct_headers ? PKT_HDR_GCLI_SIZE_LONG : PKT_HDR_GCLI_SIZE_SHORT);
info->gcli_len[subpkt] = (int)val;
bitunpacker_read(bitstream, &val, use_long_precinct_headers ? PKT_HDR_SIGN_SIZE_LONG : PKT_HDR_SIGN_SIZE_SHORT);
info->sign_len[subpkt] = (int)val;