Coverage Report

Created: 2026-04-12 06:11

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/c-blosc2/plugins/codecs/zfp/src/template/encode.c
Line
Count
Source
1
#include <limits.h>
2
3
static void _t2(fwd_xform, Int, DIMS)(Int* p);
4
5
/* private functions ------------------------------------------------------- */
6
7
/* pad partial block of width n <= 4 and stride s */
8
static void
9
_t1(pad_block, Scalar)(Scalar* p, size_t n, ptrdiff_t s)
10
0
{
11
0
  switch (n) {
12
0
    case 0:
13
0
      p[0 * s] = 0;
14
      /* FALLTHROUGH */
15
0
    case 1:
16
0
      p[1 * s] = p[0 * s];
17
      /* FALLTHROUGH */
18
0
    case 2:
19
0
      p[2 * s] = p[1 * s];
20
      /* FALLTHROUGH */
21
0
    case 3:
22
0
      p[3 * s] = p[0 * s];
23
      /* FALLTHROUGH */
24
0
    default:
25
0
      break;
26
0
  }
27
0
}
Unexecuted instantiation: encode1d.c:pad_block_double
Unexecuted instantiation: encode1f.c:pad_block_float
Unexecuted instantiation: encode1i.c:pad_block_int32
Unexecuted instantiation: encode1l.c:pad_block_int64
Unexecuted instantiation: encode2d.c:pad_block_double
Unexecuted instantiation: encode2f.c:pad_block_float
Unexecuted instantiation: encode2i.c:pad_block_int32
Unexecuted instantiation: encode2l.c:pad_block_int64
Unexecuted instantiation: encode3d.c:pad_block_double
Unexecuted instantiation: encode3f.c:pad_block_float
Unexecuted instantiation: encode3i.c:pad_block_int32
Unexecuted instantiation: encode3l.c:pad_block_int64
Unexecuted instantiation: encode4d.c:pad_block_double
Unexecuted instantiation: encode4f.c:pad_block_float
Unexecuted instantiation: encode4i.c:pad_block_int32
Unexecuted instantiation: encode4l.c:pad_block_int64
28
29
/* forward lifting transform of 4-vector */
30
static void
31
_t1(fwd_lift, Int)(Int* p, ptrdiff_t s)
32
0
{
33
0
  Int x, y, z, w;
34
0
  x = *p; p += s;
35
0
  y = *p; p += s;
36
0
  z = *p; p += s;
37
0
  w = *p; p += s;
38
39
  /*
40
  ** non-orthogonal transform
41
  **        ( 4  4  4  4) (x)
42
  ** 1/16 * ( 5  1 -1 -5) (y)
43
  **        (-4  4  4 -4) (z)
44
  **        (-2  6 -6  2) (w)
45
  */
46
0
  x += w; x >>= 1; w -= x;
47
0
  z += y; z >>= 1; y -= z;
48
0
  x += z; x >>= 1; z -= x;
49
0
  w += y; w >>= 1; y -= w;
50
0
  w += y >> 1; y -= w >> 1;
51
52
0
  p -= s; *p = w;
53
0
  p -= s; *p = z;
54
0
  p -= s; *p = y;
55
0
  p -= s; *p = x;
56
0
}
Unexecuted instantiation: encode1d.c:fwd_lift_int64
Unexecuted instantiation: encode1f.c:fwd_lift_int32
Unexecuted instantiation: encode1i.c:fwd_lift_int32
Unexecuted instantiation: encode1l.c:fwd_lift_int64
Unexecuted instantiation: encode2d.c:fwd_lift_int64
Unexecuted instantiation: encode2f.c:fwd_lift_int32
Unexecuted instantiation: encode2i.c:fwd_lift_int32
Unexecuted instantiation: encode2l.c:fwd_lift_int64
Unexecuted instantiation: encode3d.c:fwd_lift_int64
Unexecuted instantiation: encode3f.c:fwd_lift_int32
Unexecuted instantiation: encode3i.c:fwd_lift_int32
Unexecuted instantiation: encode3l.c:fwd_lift_int64
Unexecuted instantiation: encode4d.c:fwd_lift_int64
Unexecuted instantiation: encode4f.c:fwd_lift_int32
Unexecuted instantiation: encode4i.c:fwd_lift_int32
Unexecuted instantiation: encode4l.c:fwd_lift_int64
57
58
#if ZFP_ROUNDING_MODE == ZFP_ROUND_FIRST
59
/* bias values such that truncation is equivalent to round to nearest */
60
static void
61
_t1(fwd_round, Int)(Int* iblock, uint n, uint maxprec)
62
{
63
  /* add or subtract 1/6 ulp to unbias errors */
64
  if (maxprec < (uint)(CHAR_BIT * sizeof(Int))) {
65
    Int bias = (NBMASK >> 2) >> maxprec;
66
    if (maxprec & 1u)
67
      do *iblock++ += bias; while (--n);
68
    else
69
      do *iblock++ -= bias; while (--n);
70
  }
71
}
72
#endif
73
74
/* map two's complement signed integer to negabinary unsigned integer */
75
static UInt
76
_t1(int2uint, Int)(Int x)
77
0
{
78
0
  return ((UInt)x + NBMASK) ^ NBMASK;
79
0
}
Unexecuted instantiation: encode1d.c:int2uint_int64
Unexecuted instantiation: encode1f.c:int2uint_int32
Unexecuted instantiation: encode1i.c:int2uint_int32
Unexecuted instantiation: encode1l.c:int2uint_int64
Unexecuted instantiation: encode2d.c:int2uint_int64
Unexecuted instantiation: encode2f.c:int2uint_int32
Unexecuted instantiation: encode2i.c:int2uint_int32
Unexecuted instantiation: encode2l.c:int2uint_int64
Unexecuted instantiation: encode3d.c:int2uint_int64
Unexecuted instantiation: encode3f.c:int2uint_int32
Unexecuted instantiation: encode3i.c:int2uint_int32
Unexecuted instantiation: encode3l.c:int2uint_int64
Unexecuted instantiation: encode4d.c:int2uint_int64
Unexecuted instantiation: encode4f.c:int2uint_int32
Unexecuted instantiation: encode4i.c:int2uint_int32
Unexecuted instantiation: encode4l.c:int2uint_int64
80
81
/* reorder signed coefficients and convert to unsigned integer */
82
static void
83
_t1(fwd_order, Int)(UInt* ublock, const Int* iblock, const uchar* perm, uint n)
84
0
{
85
0
  do
86
0
    *ublock++ = _t1(int2uint, Int)(iblock[*perm++]);
87
0
  while (--n);
88
0
}
Unexecuted instantiation: encode1d.c:fwd_order_int64
Unexecuted instantiation: encode1f.c:fwd_order_int32
Unexecuted instantiation: encode1i.c:fwd_order_int32
Unexecuted instantiation: encode1l.c:fwd_order_int64
Unexecuted instantiation: encode2d.c:fwd_order_int64
Unexecuted instantiation: encode2f.c:fwd_order_int32
Unexecuted instantiation: encode2i.c:fwd_order_int32
Unexecuted instantiation: encode2l.c:fwd_order_int64
Unexecuted instantiation: encode3d.c:fwd_order_int64
Unexecuted instantiation: encode3f.c:fwd_order_int32
Unexecuted instantiation: encode3i.c:fwd_order_int32
Unexecuted instantiation: encode3l.c:fwd_order_int64
Unexecuted instantiation: encode4d.c:fwd_order_int64
Unexecuted instantiation: encode4f.c:fwd_order_int32
Unexecuted instantiation: encode4i.c:fwd_order_int32
Unexecuted instantiation: encode4l.c:fwd_order_int64
89
90
/* compress sequence of size <= 64 unsigned integers */
91
static uint
92
_t1(encode_few_ints, UInt)(bitstream* restrict_ stream, uint maxbits, uint maxprec, const UInt* restrict_ data, uint size)
93
0
{
94
  /* make a copy of bit stream to avoid aliasing */
95
0
  bitstream s = *stream;
96
0
  uint intprec = (uint)(CHAR_BIT * sizeof(UInt));
97
0
  uint kmin = intprec > maxprec ? intprec - maxprec : 0;
98
0
  uint bits = maxbits;
99
0
  uint i, k, m, n;
100
0
  uint64 x;
101
102
  /* encode one bit plane at a time from MSB to LSB */
103
0
  for (k = intprec, n = 0; bits && k-- > kmin;) {
104
    /* step 1: extract bit plane #k to x */
105
0
    x = 0;
106
0
    for (i = 0; i < size; i++)
107
0
      x += (uint64)((data[i] >> k) & 1u) << i;
108
    /* step 2: encode first n bits of bit plane */
109
0
    m = MIN(n, bits);
110
0
    bits -= m;
111
0
    x = stream_write_bits(&s, x, m);
112
    /* step 3: unary run-length encode remainder of bit plane */
113
0
    for (; bits && n < size; x >>= 1, n++) {
114
0
      bits--;
115
0
      if (stream_write_bit(&s, !!x)) {
116
        /* positive group test (x != 0); scan for one-bit */
117
0
        for (; bits && n < size - 1; x >>= 1, n++) {
118
0
          bits--;
119
0
          if (stream_write_bit(&s, x & 1u))
120
0
            break;
121
0
        }
122
0
      }
123
0
      else {
124
        /* negative group test (x == 0); done with bit plane */
125
0
        break;
126
0
      }
127
0
    }
128
0
  }
129
130
0
  *stream = s;
131
0
  return maxbits - bits;
132
0
}
Unexecuted instantiation: encode1d.c:encode_few_ints_uint64
Unexecuted instantiation: encode1f.c:encode_few_ints_uint32
Unexecuted instantiation: encode1i.c:encode_few_ints_uint32
Unexecuted instantiation: encode1l.c:encode_few_ints_uint64
Unexecuted instantiation: encode2d.c:encode_few_ints_uint64
Unexecuted instantiation: encode2f.c:encode_few_ints_uint32
Unexecuted instantiation: encode2i.c:encode_few_ints_uint32
Unexecuted instantiation: encode2l.c:encode_few_ints_uint64
Unexecuted instantiation: encode3d.c:encode_few_ints_uint64
Unexecuted instantiation: encode3f.c:encode_few_ints_uint32
Unexecuted instantiation: encode3i.c:encode_few_ints_uint32
Unexecuted instantiation: encode3l.c:encode_few_ints_uint64
Unexecuted instantiation: encode4d.c:encode_few_ints_uint64
Unexecuted instantiation: encode4f.c:encode_few_ints_uint32
Unexecuted instantiation: encode4i.c:encode_few_ints_uint32
Unexecuted instantiation: encode4l.c:encode_few_ints_uint64
133
134
/* compress sequence of size > 64 unsigned integers */
135
static uint
136
_t1(encode_many_ints, UInt)(bitstream* restrict_ stream, uint maxbits, uint maxprec, const UInt* restrict_ data, uint size)
137
0
{
138
  /* make a copy of bit stream to avoid aliasing */
139
0
  bitstream s = *stream;
140
0
  uint intprec = (uint)(CHAR_BIT * sizeof(UInt));
141
0
  uint kmin = intprec > maxprec ? intprec - maxprec : 0;
142
0
  uint bits = maxbits;
143
0
  uint i, k, m, n, c;
144
145
  /* encode one bit plane at a time from MSB to LSB */
146
0
  for (k = intprec, n = 0; bits && k-- > kmin;) {
147
    /* step 1: encode first n bits of bit plane #k */
148
0
    m = MIN(n, bits);
149
0
    bits -= m;
150
0
    for (i = 0; i < m; i++)
151
0
      stream_write_bit(&s, (data[i] >> k) & 1u);
152
    /* step 2: count remaining one-bits in bit plane */
153
0
    c = 0;
154
0
    for (i = m; i < size; i++)
155
0
      c += (data[i] >> k) & 1u;
156
    /* step 3: unary run-length encode remainder of bit plane */
157
0
    for (; bits && n < size; n++) {
158
0
      bits--;
159
0
      if (stream_write_bit(&s, !!c)) {
160
        /* positive group test (c > 0); scan for one-bit */
161
0
        for (c--; bits && n < size - 1; n++) {
162
0
          bits--;
163
0
          if (stream_write_bit(&s, (data[n] >> k) & 1u))
164
0
            break;
165
0
        }
166
0
      }
167
0
      else {
168
        /* negative group test (c == 0); done with bit plane */
169
0
        break;
170
0
      }
171
0
    }
172
0
  }
173
174
0
  *stream = s;
175
0
  return maxbits - bits;
176
0
}
Unexecuted instantiation: encode1d.c:encode_many_ints_uint64
Unexecuted instantiation: encode1f.c:encode_many_ints_uint32
Unexecuted instantiation: encode1i.c:encode_many_ints_uint32
Unexecuted instantiation: encode1l.c:encode_many_ints_uint64
Unexecuted instantiation: encode2d.c:encode_many_ints_uint64
Unexecuted instantiation: encode2f.c:encode_many_ints_uint32
Unexecuted instantiation: encode2i.c:encode_many_ints_uint32
Unexecuted instantiation: encode2l.c:encode_many_ints_uint64
Unexecuted instantiation: encode3d.c:encode_many_ints_uint64
Unexecuted instantiation: encode3f.c:encode_many_ints_uint32
Unexecuted instantiation: encode3i.c:encode_many_ints_uint32
Unexecuted instantiation: encode3l.c:encode_many_ints_uint64
Unexecuted instantiation: encode4d.c:encode_many_ints_uint64
Unexecuted instantiation: encode4f.c:encode_many_ints_uint32
Unexecuted instantiation: encode4i.c:encode_many_ints_uint32
Unexecuted instantiation: encode4l.c:encode_many_ints_uint64
177
178
/* compress sequence of size <= 64 unsigned integers with no rate constraint */
179
static uint
180
_t1(encode_few_ints_prec, UInt)(bitstream* restrict_ stream, uint maxprec, const UInt* restrict_ data, uint size)
181
0
{
182
  /* make a copy of bit stream to avoid aliasing */
183
0
  bitstream s = *stream;
184
0
  size_t offset = stream_wtell(&s);
185
0
  uint intprec = (uint)(CHAR_BIT * sizeof(UInt));
186
0
  uint kmin = intprec > maxprec ? intprec - maxprec : 0;
187
0
  uint i, k, n;
188
189
  /* encode one bit plane at a time from MSB to LSB */
190
0
  for (k = intprec, n = 0; k-- > kmin;) {
191
    /* step 1: extract bit plane #k to x */
192
0
    uint64 x = 0;
193
0
    for (i = 0; i < size; i++)
194
0
      x += (uint64)((data[i] >> k) & 1u) << i;
195
    /* step 2: encode first n bits of bit plane */
196
0
    x = stream_write_bits(&s, x, n);
197
    /* step 3: unary run-length encode remainder of bit plane */
198
0
    for (; n < size && stream_write_bit(&s, !!x); x >>= 1, n++)
199
0
      for (; n < size - 1 && !stream_write_bit(&s, x & 1u); x >>= 1, n++)
200
0
        ;
201
0
  }
202
203
0
  *stream = s;
204
0
  return (uint)(stream_wtell(&s) - offset);
205
0
}
Unexecuted instantiation: encode1d.c:encode_few_ints_prec_uint64
Unexecuted instantiation: encode1f.c:encode_few_ints_prec_uint32
Unexecuted instantiation: encode1i.c:encode_few_ints_prec_uint32
Unexecuted instantiation: encode1l.c:encode_few_ints_prec_uint64
Unexecuted instantiation: encode2d.c:encode_few_ints_prec_uint64
Unexecuted instantiation: encode2f.c:encode_few_ints_prec_uint32
Unexecuted instantiation: encode2i.c:encode_few_ints_prec_uint32
Unexecuted instantiation: encode2l.c:encode_few_ints_prec_uint64
Unexecuted instantiation: encode3d.c:encode_few_ints_prec_uint64
Unexecuted instantiation: encode3f.c:encode_few_ints_prec_uint32
Unexecuted instantiation: encode3i.c:encode_few_ints_prec_uint32
Unexecuted instantiation: encode3l.c:encode_few_ints_prec_uint64
Unexecuted instantiation: encode4d.c:encode_few_ints_prec_uint64
Unexecuted instantiation: encode4f.c:encode_few_ints_prec_uint32
Unexecuted instantiation: encode4i.c:encode_few_ints_prec_uint32
Unexecuted instantiation: encode4l.c:encode_few_ints_prec_uint64
206
207
/* compress sequence of size > 64 unsigned integers with no rate constraint */
208
static uint
209
_t1(encode_many_ints_prec, UInt)(bitstream* restrict_ stream, uint maxprec, const UInt* restrict_ data, uint size)
210
0
{
211
  /* make a copy of bit stream to avoid aliasing */
212
0
  bitstream s = *stream;
213
0
  size_t offset = stream_wtell(&s);
214
0
  uint intprec = (uint)(CHAR_BIT * sizeof(UInt));
215
0
  uint kmin = intprec > maxprec ? intprec - maxprec : 0;
216
0
  uint i, k, n, c;
217
218
  /* encode one bit plane at a time from MSB to LSB */
219
0
  for (k = intprec, n = 0; k-- > kmin;) {
220
    /* step 1: encode first n bits of bit plane #k */
221
0
    for (i = 0; i < n; i++)
222
0
      stream_write_bit(&s, (data[i] >> k) & 1u);
223
    /* step 2: count remaining one-bits in bit plane */
224
0
    c = 0;
225
0
    for (i = n; i < size; i++)
226
0
      c += (data[i] >> k) & 1u;
227
    /* step 3: unary run-length encode remainder of bit plane */
228
0
    for (; n < size && stream_write_bit(&s, !!c); n++)
229
0
      for (c--; n < size - 1 && !stream_write_bit(&s, (data[n] >> k) & 1u); n++)
230
0
        ;
231
0
  }
232
233
0
  *stream = s;
234
0
  return (uint)(stream_wtell(&s) - offset);
235
0
}
Unexecuted instantiation: encode1d.c:encode_many_ints_prec_uint64
Unexecuted instantiation: encode1f.c:encode_many_ints_prec_uint32
Unexecuted instantiation: encode1i.c:encode_many_ints_prec_uint32
Unexecuted instantiation: encode1l.c:encode_many_ints_prec_uint64
Unexecuted instantiation: encode2d.c:encode_many_ints_prec_uint64
Unexecuted instantiation: encode2f.c:encode_many_ints_prec_uint32
Unexecuted instantiation: encode2i.c:encode_many_ints_prec_uint32
Unexecuted instantiation: encode2l.c:encode_many_ints_prec_uint64
Unexecuted instantiation: encode3d.c:encode_many_ints_prec_uint64
Unexecuted instantiation: encode3f.c:encode_many_ints_prec_uint32
Unexecuted instantiation: encode3i.c:encode_many_ints_prec_uint32
Unexecuted instantiation: encode3l.c:encode_many_ints_prec_uint64
Unexecuted instantiation: encode4d.c:encode_many_ints_prec_uint64
Unexecuted instantiation: encode4f.c:encode_many_ints_prec_uint32
Unexecuted instantiation: encode4i.c:encode_many_ints_prec_uint32
Unexecuted instantiation: encode4l.c:encode_many_ints_prec_uint64
236
237
/* compress sequence of size unsigned integers */
238
static uint
239
_t1(encode_ints, UInt)(bitstream* restrict_ stream, uint maxbits, uint maxprec, const UInt* restrict_ data, uint size)
240
0
{
241
  /* use fastest available encoder implementation */
242
0
  if (with_maxbits(maxbits, maxprec, size)) {
243
    /* rate constrained path: encode partial bit planes */
244
0
    if (size <= 64)
245
0
      return _t1(encode_few_ints, UInt)(stream, maxbits, maxprec, data, size); /* 1D, 2D, 3D blocks */
246
0
    else
247
0
      return _t1(encode_many_ints, UInt)(stream, maxbits, maxprec, data, size); /* 4D blocks */
248
0
  }
249
0
  else {
250
    /* variable-rate path: encode whole bit planes */
251
0
    if (size <= 64)
252
0
      return _t1(encode_few_ints_prec, UInt)(stream, maxprec, data, size); /* 1D, 2D, 3D blocks */
253
0
    else
254
0
      return _t1(encode_many_ints_prec, UInt)(stream, maxprec, data, size); /* 4D blocks */
255
0
  }
256
0
}
Unexecuted instantiation: encode1d.c:encode_ints_uint64
Unexecuted instantiation: encode1f.c:encode_ints_uint32
Unexecuted instantiation: encode1i.c:encode_ints_uint32
Unexecuted instantiation: encode1l.c:encode_ints_uint64
Unexecuted instantiation: encode2d.c:encode_ints_uint64
Unexecuted instantiation: encode2f.c:encode_ints_uint32
Unexecuted instantiation: encode2i.c:encode_ints_uint32
Unexecuted instantiation: encode2l.c:encode_ints_uint64
Unexecuted instantiation: encode3d.c:encode_ints_uint64
Unexecuted instantiation: encode3f.c:encode_ints_uint32
Unexecuted instantiation: encode3i.c:encode_ints_uint32
Unexecuted instantiation: encode3l.c:encode_ints_uint64
Unexecuted instantiation: encode4d.c:encode_ints_uint64
Unexecuted instantiation: encode4f.c:encode_ints_uint32
Unexecuted instantiation: encode4i.c:encode_ints_uint32
Unexecuted instantiation: encode4l.c:encode_ints_uint64
257
258
/* encode block of integers */
259
static uint
260
_t2(encode_block, Int, DIMS)(bitstream* stream, int minbits, int maxbits, int maxprec, Int* iblock)
261
0
{
262
0
  int bits;
263
0
  cache_align_(UInt ublock[BLOCK_SIZE]);
264
  /* perform decorrelating transform */
265
0
  _t2(fwd_xform, Int, DIMS)(iblock);
266
#if ZFP_ROUNDING_MODE == ZFP_ROUND_FIRST
267
  /* bias values to achieve proper rounding */
268
  _t1(fwd_round, Int)(iblock, BLOCK_SIZE, maxprec);
269
#endif
270
  /* reorder signed coefficients and convert to unsigned integer */
271
0
  _t1(fwd_order, Int)(ublock, iblock, PERM, BLOCK_SIZE);
272
  /* encode integer coefficients */
273
0
  bits = _t1(encode_ints, UInt)(stream, maxbits, maxprec, ublock, BLOCK_SIZE);
274
  /* write at least minbits bits by padding with zeros */
275
0
  if (bits < minbits) {
276
0
    stream_pad(stream, minbits - bits);
277
0
    bits = minbits;
278
0
  }
279
0
  return bits;
280
0
}
Unexecuted instantiation: encode1d.c:encode_block_int64_1
Unexecuted instantiation: encode1f.c:encode_block_int32_1
Unexecuted instantiation: encode1i.c:encode_block_int32_1
Unexecuted instantiation: encode1l.c:encode_block_int64_1
Unexecuted instantiation: encode2d.c:encode_block_int64_2
Unexecuted instantiation: encode2f.c:encode_block_int32_2
Unexecuted instantiation: encode2i.c:encode_block_int32_2
Unexecuted instantiation: encode2l.c:encode_block_int64_2
Unexecuted instantiation: encode3d.c:encode_block_int64_3
Unexecuted instantiation: encode3f.c:encode_block_int32_3
Unexecuted instantiation: encode3i.c:encode_block_int32_3
Unexecuted instantiation: encode3l.c:encode_block_int64_3
Unexecuted instantiation: encode4d.c:encode_block_int64_4
Unexecuted instantiation: encode4f.c:encode_block_int32_4
Unexecuted instantiation: encode4i.c:encode_block_int32_4
Unexecuted instantiation: encode4l.c:encode_block_int64_4