Compress-Zstd
view release on metacpan or search on metacpan
ext/zstd/contrib/linux-kernel/lib/zstd/decompress.c view on Meta::CPAN
/**
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of https://github.com/facebook/zstd.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 2 as published by the
* Free Software Foundation. This program is dual-licensed; you may select
* either version 2 of the GNU General Public License ("GPL") or BSD license
* ("BSD").
*/
/* ***************************************************************
* Tuning parameters
*****************************************************************/
/*!
* MAXWINDOWSIZE_DEFAULT :
* maximum window size accepted by DStream, by default.
* Frames requiring more memory will be rejected.
*/
#ifndef ZSTD_MAXWINDOWSIZE_DEFAULT
#define ZSTD_MAXWINDOWSIZE_DEFAULT ((1 << ZSTD_WINDOWLOG_MAX) + 1) /* defined within zstd.h */
#endif
/*-*******************************************************
* Dependencies
*********************************************************/
#include "fse.h"
#include "huf.h"
#include "mem.h" /* low level memory routines */
#include "zstd_internal.h"
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/string.h> /* memcpy, memmove, memset */
#define ZSTD_PREFETCH(ptr) __builtin_prefetch(ptr, 0, 0)
/*-*************************************
* Macros
***************************************/
#define ZSTD_isError ERR_isError /* for inlining */
#define FSE_isError ERR_isError
#define HUF_isError ERR_isError
/*_*******************************************************
* Memory operations
**********************************************************/
static void ZSTD_copy4(void *dst, const void *src) { memcpy(dst, src, 4); }
/*-*************************************************************
* Context management
***************************************************************/
typedef enum {
ZSTDds_getFrameHeaderSize,
ZSTDds_decodeFrameHeader,
ZSTDds_decodeBlockHeader,
ZSTDds_decompressBlock,
ZSTDds_decompressLastBlock,
ZSTDds_checkChecksum,
ZSTDds_decodeSkippableHeader,
ZSTDds_skipFrame
} ZSTD_dStage;
typedef struct {
FSE_DTable LLTable[FSE_DTABLE_SIZE_U32(LLFSELog)];
FSE_DTable OFTable[FSE_DTABLE_SIZE_U32(OffFSELog)];
FSE_DTable MLTable[FSE_DTABLE_SIZE_U32(MLFSELog)];
HUF_DTable hufTable[HUF_DTABLE_SIZE(HufLog)]; /* can accommodate HUF_decompress4X */
U64 workspace[HUF_DECOMPRESS_WORKSPACE_SIZE_U32 / 2];
U32 rep[ZSTD_REP_NUM];
} ZSTD_entropyTables_t;
struct ZSTD_DCtx_s {
const FSE_DTable *LLTptr;
const FSE_DTable *MLTptr;
const FSE_DTable *OFTptr;
const HUF_DTable *HUFptr;
ZSTD_entropyTables_t entropy;
const void *previousDstEnd; /* detect continuity */
const void *base; /* start of curr segment */
const void *vBase; /* virtual start of previous segment if it was just before curr one */
const void *dictEnd; /* end of previous segment */
size_t expected;
ZSTD_frameParams fParams;
blockType_e bType; /* used in ZSTD_decompressContinue(), to transfer blockType between header decoding and block decoding stages */
ZSTD_dStage stage;
U32 litEntropy;
U32 fseEntropy;
struct xxh64_state xxhState;
size_t headerSize;
U32 dictID;
const BYTE *litPtr;
ZSTD_customMem customMem;
size_t litSize;
size_t rleSize;
BYTE litBuffer[ZSTD_BLOCKSIZE_ABSOLUTEMAX + WILDCOPY_OVERLENGTH];
BYTE headerBuffer[ZSTD_FRAMEHEADERSIZE_MAX];
}; /* typedef'd to ZSTD_DCtx within "zstd.h" */
( run in 1.387 second using v1.01-cache-2.11-cpan-39bf76dae61 )