10 #ifndef vtk_m_worklet_zfp_encode_h
11 #define vtk_m_worklet_zfp_encode_h
26 template <
typename Scalar>
48 template <vtkm::Int32 N,
typename FloatType>
54 maxVal = vtkm::Max(maxVal, vtkm::Abs(vals[i]));
62 return vtkm::Max(exponent, 1 - get_ebias<FloatType>());
64 return -get_ebias<FloatType>();
70 return vtkm::Min(maxprec, vtkm::Max(0, maxexp - minexp + 8));
73 template <
typename Scalar>
79 template <
typename Int,
typename Scalar, vtkm::Int32 BlockSize>
82 Scalar s = quantize<Scalar>(1, emax);
85 iblock[i] =
static_cast<Int
>(s * fblock[i]);
89 template <
typename Int, vtkm::Int32 S>
134 template <
typename Int,
typename UInt>
138 inline VTKM_EXEC vtkm::UInt64 int2uint<vtkm::Int64, vtkm::UInt64>(
const vtkm::Int64 x)
140 return (
static_cast<vtkm::UInt64
>(x) + (vtkm::UInt64)0xaaaaaaaaaaaaaaaaull) ^
141 (vtkm::UInt64)0xaaaaaaaaaaaaaaaaull;
152 template <
typename UInt,
typename Int, vtkm::Int32 BlockSize>
159 ublock[i] = int2uint<Int, UInt>(iblock[idx]);
163 template <
typename Int, vtkm::Int32 BlockSize>
167 inline VTKM_EXEC void fwd_xform<vtkm::Int64, 64>(vtkm::Int64* p)
171 for (z = 0; z < 4; z++)
172 for (y = 0; y < 4; y++)
173 fwd_lift<vtkm::Int64, 1>(p + 4 * y + 16 * z);
175 for (x = 0; x < 4; x++)
176 for (z = 0; z < 4; z++)
177 fwd_lift<vtkm::Int64, 4>(p + 16 * z + 1 * x);
179 for (y = 0; y < 4; y++)
180 for (x = 0; x < 4; x++)
181 fwd_lift<vtkm::Int64, 16>(p + 1 * x + 4 * y);
189 for (z = 0; z < 4; z++)
190 for (y = 0; y < 4; y++)
191 fwd_lift<vtkm::Int32, 1>(p + 4 * y + 16 * z);
193 for (x = 0; x < 4; x++)
194 for (z = 0; z < 4; z++)
195 fwd_lift<vtkm::Int32, 4>(p + 16 * z + 1 * x);
197 for (y = 0; y < 4; y++)
198 for (x = 0; x < 4; x++)
199 fwd_lift<vtkm::Int32, 16>(p + 1 * x + 4 * y);
203 inline VTKM_EXEC void fwd_xform<vtkm::Int64, 16>(vtkm::Int64* p)
207 for (y = 0; y < 4; y++)
208 fwd_lift<vtkm::Int64, 1>(p + 4 * y);
210 for (x = 0; x < 4; x++)
211 fwd_lift<vtkm::Int64, 4>(p + 1 * x);
219 for (y = 0; y < 4; y++)
220 fwd_lift<vtkm::Int32, 1>(p + 4 * y);
222 for (x = 0; x < 4; x++)
223 fwd_lift<vtkm::Int32, 4>(p + 1 * x);
227 inline VTKM_EXEC void fwd_xform<vtkm::Int64, 4>(vtkm::Int64* p)
230 fwd_lift<vtkm::Int64, 1>(p);
237 fwd_lift<vtkm::Int32, 1>(p);
240 template <vtkm::Int32 BlockSize,
typename PortalType,
typename Int>
248 fwd_xform<Int, BlockSize>(iblock);
250 UInt ublock[BlockSize];
251 fwd_order<UInt, Int, BlockSize>(ublock, iblock);
265 for (i = 0; i < BlockSize; i++)
267 x += (vtkm::UInt64)((ublock[i] >> k) & 1u) << i;
270 m = vtkm::Min(n, bits);
274 for (; n < BlockSize && bits && (bits--, stream.
write_bit(!!x)); x >>= 1, n++)
276 for (; n < BlockSize - 1 && bits && (bits--, !stream.
write_bit(x & 1u)); x >>= 1, n++)
284 template <vtkm::Int32 BlockSize,
typename Scalar,
typename PortalType>
292 vtkm::Int32 emax = zfp::MaxExponent<BlockSize, Scalar>(fblock);
295 zfp::precision(emax, zfp::get_precision<Scalar>(), zfp::get_min_exp<Scalar>());
304 Int iblock[BlockSize];
305 zfp::fwd_cast<Int, Scalar, BlockSize>(iblock, fblock, emax);
307 encode_block<BlockSize>(blockWriter, maxbits -
vtkm::Int32(ebits), maxprec, iblock);
313 template <vtkm::Int32 BlockSize,
typename Scalar,
typename PortalType>
318 template <vtkm::Int32 BlockSize,
typename PortalType>
326 zfp_encodef<BlockSize>(fblock, maxbits, blockIdx, stream);
330 template <vtkm::Int32 BlockSize,
typename PortalType>
338 zfp_encodef<BlockSize>(fblock, maxbits, blockIdx, stream);
342 template <vtkm::Int32 BlockSize,
typename PortalType>
352 encode_block<BlockSize>(blockWriter, maxbits, get_precision<vtkm::Int32>(), (Int*)fblock);
356 template <vtkm::Int32 BlockSize,
typename PortalType>
366 encode_block<BlockSize>(blockWriter, maxbits, get_precision<vtkm::Int64>(), (Int*)fblock);