Changeset View
Changeset View
Standalone View
Standalone View
contrib/zstd/lib/compress/fse_compress.c
Show All 29 Lines | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||
You can contact the author at : | You can contact the author at : | ||||
- FSE source repository : https://github.com/Cyan4973/FiniteStateEntropy | - FSE source repository : https://github.com/Cyan4973/FiniteStateEntropy | ||||
- Public forum : https://groups.google.com/forum/#!forum/lz4c | - Public forum : https://groups.google.com/forum/#!forum/lz4c | ||||
****************************************************************** */ | ****************************************************************** */ | ||||
/* ************************************************************** | /* ************************************************************** | ||||
* Includes | * Includes | ||||
****************************************************************/ | ****************************************************************/ | ||||
#ifdef _KERNEL | |||||
#include "zstd_kmalloc.h" /* malloc, free */ | |||||
#include <sys/systm.h> /* memcpy, memset */ | |||||
#else | |||||
#include <stdlib.h> /* malloc, free, qsort */ | #include <stdlib.h> /* malloc, free, qsort */ | ||||
#include <string.h> /* memcpy, memset */ | #include <string.h> /* memcpy, memset */ | ||||
#include <stdio.h> /* printf (debug) */ | #include <stdio.h> /* printf (debug) */ | ||||
#endif | |||||
#include "bitstream.h" | #include "bitstream.h" | ||||
#include "compiler.h" | #include "compiler.h" | ||||
#define FSE_STATIC_LINKING_ONLY | #define FSE_STATIC_LINKING_ONLY | ||||
#include "fse.h" | #include "fse.h" | ||||
#include "error_private.h" | #include "error_private.h" | ||||
/* ************************************************************** | /* ************************************************************** | ||||
▲ Show 20 Lines • Show All 396 Lines • ▼ Show 20 Lines | size_t FSE_sizeof_CTable (unsigned maxSymbolValue, unsigned tableLog) | ||||
return FSE_CTABLE_SIZE_U32 (tableLog, maxSymbolValue) * sizeof(U32); | return FSE_CTABLE_SIZE_U32 (tableLog, maxSymbolValue) * sizeof(U32); | ||||
} | } | ||||
FSE_CTable* FSE_createCTable (unsigned maxSymbolValue, unsigned tableLog) | FSE_CTable* FSE_createCTable (unsigned maxSymbolValue, unsigned tableLog) | ||||
{ | { | ||||
size_t size; | size_t size; | ||||
if (tableLog > FSE_TABLELOG_ABSOLUTE_MAX) tableLog = FSE_TABLELOG_ABSOLUTE_MAX; | if (tableLog > FSE_TABLELOG_ABSOLUTE_MAX) tableLog = FSE_TABLELOG_ABSOLUTE_MAX; | ||||
size = FSE_CTABLE_SIZE_U32 (tableLog, maxSymbolValue) * sizeof(U32); | size = FSE_CTABLE_SIZE_U32 (tableLog, maxSymbolValue) * sizeof(U32); | ||||
#ifdef _KERNEL | |||||
printf("ZSTD:%s:%u: malloc(%zu)\n", __func__, __LINE__, size); | |||||
return (FSE_CTable*)malloc(size, M_ZSTD, M_WAITOK); | |||||
#else | |||||
return (FSE_CTable*)malloc(size); | return (FSE_CTable*)malloc(size); | ||||
#endif | |||||
} | } | ||||
void FSE_freeCTable (FSE_CTable* ct) { free(ct); } | void FSE_freeCTable (FSE_CTable* ct) { | ||||
#ifdef _KERNEL | |||||
free(ct, M_ZSTD); | |||||
#else | |||||
free(ct); | |||||
#endif | |||||
} | |||||
/* provides the minimum logSize to safely represent a distribution */ | /* provides the minimum logSize to safely represent a distribution */ | ||||
static unsigned FSE_minTableLog(size_t srcSize, unsigned maxSymbolValue) | static unsigned FSE_minTableLog(size_t srcSize, unsigned maxSymbolValue) | ||||
{ | { | ||||
U32 minBitsSrc = BIT_highbit32((U32)(srcSize - 1)) + 1; | U32 minBitsSrc = BIT_highbit32((U32)(srcSize - 1)) + 1; | ||||
U32 minBitsSymbols = BIT_highbit32(maxSymbolValue) + 2; | U32 minBitsSymbols = BIT_highbit32(maxSymbolValue) + 2; | ||||
U32 minBits = minBitsSrc < minBitsSymbols ? minBitsSrc : minBitsSymbols; | U32 minBits = minBitsSrc < minBitsSymbols ? minBitsSrc : minBitsSymbols; | ||||
return minBits; | return minBits; | ||||
▲ Show 20 Lines • Show All 375 Lines • Show Last 20 Lines |