odin-blend2d

Odin bindings to Blend2D
Log | Files | Refs | README | LICENSE

deflatedecoderfast_p.h (2340B)


      1 // This file is part of Blend2D project <https://blend2d.com>
      2 //
      3 // See blend2d.h or LICENSE.md for license and copyright information
      4 // SPDX-License-Identifier: Zlib
      5 
      6 #ifndef BLEND2D_COMPRESSION_DEFLATEDECODERFAST_P_H_INCLUDED
      7 #define BLEND2D_COMPRESSION_DEFLATEDECODERFAST_P_H_INCLUDED
      8 
      9 #include "../api-internal_p.h"
     10 #include "../compression/deflatedecoder_p.h"
     11 #include "../support/intops_p.h"
     12 
     13 //! \cond INTERNAL
     14 
     15 namespace bl::Compression::Deflate::Fast {
     16 
     17 // Must be powers of 2 so we can divide easily from raw buffer lengths to calculate `safe_iters`.
     18 // We definitely want extra safety here and to actually be more strict than necessary.
     19 constexpr uint32_t kSrcBytesPerIter = 8u;
     20 constexpr uint32_t kDstBytesPerIter = 8u;
     21 
     22 constexpr uint32_t kDstCopyBytesPerIter = 16u;
     23 
     24 constexpr uint32_t kSrcBytesPerIterShift = IntOps::ctz_static(kSrcBytesPerIter);
     25 constexpr uint32_t kDstBytesPerIterShift = IntOps::ctz_static(kDstBytesPerIter);
     26 
     27 // Scratch - extra size that must always be available to perform a single iteration.
     28 constexpr uint32_t kSrcMinScratch = sizeof(BLBitWord) * 2u;
     29 constexpr uint32_t kDstMinScratch = kMaxMatchLen + kDstCopyBytesPerIter * 2u;
     30 
     31 // Scratch aligned to iteration count and shifted the same way as dst/src counters.
     32 constexpr uint32_t kSrcMinScratchShifted = (kSrcMinScratch + kSrcBytesPerIter - 1) >> kSrcBytesPerIterShift;
     33 constexpr uint32_t kDstMinScratchShifted = (kDstMinScratch + kDstBytesPerIter - 1) >> kDstBytesPerIterShift;
     34 
     35 constexpr uint32_t kMinimumFastIterationCount = 20;
     36 
     37 constexpr uint32_t kMinimumFastDstBuffer = kDstMinScratch + kDstBytesPerIter * kMinimumFastIterationCount;
     38 constexpr uint32_t kMinimumFastSrcBuffer = kSrcMinScratch + kSrcBytesPerIter * kMinimumFastIterationCount;
     39 
     40 #if BL_TARGET_ARCH_BITS >= 64
     41 
     42 DecoderFastResult BL_CDECL decode(
     43   Decoder* ctx,
     44   uint8_t* dst_start,
     45   uint8_t* dst_ptr,
     46   uint8_t* dst_end,
     47   const uint8_t* src_ptr,
     48   const uint8_t* src_end
     49 ) noexcept;
     50 
     51 #if defined(BL_BUILD_OPT_AVX2)
     52 DecoderFastResult BL_CDECL decode_avx2(
     53   Decoder* ctx,
     54   uint8_t* dst_start,
     55   uint8_t* dst_ptr,
     56   uint8_t* dst_end,
     57   const uint8_t* src_ptr,
     58   const uint8_t* src_end
     59 ) noexcept;
     60 #endif // BL_BUILD_OPT_AVX2
     61 
     62 #endif // BL_TARGET_ARCH_BITS == 64
     63 
     64 } // {bl::Compression::Deflate::Fast}
     65 
     66 //! \endcond
     67 
     68 #endif // BLEND2D_COMPRESSION_DEFLATEDECODERFAST_P_H_INCLUDED