FreeBSD Bugzilla – Attachment 188033 Details for
Bug 223693
arm/armv6 buildworld failure in zstd
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Preprocessed sources
zstd_compress-54318d.c (text/plain), 603.71 KB, created by
Ravi Pokala
on 2017-11-15 23:05:35 UTC
(
hide
)
Description:
Preprocessed sources
Filename:
MIME Type:
Creator:
Ravi Pokala
Created:
2017-11-15 23:05:35 UTC
Size:
603.71 KB
patch
obsolete
># 1 "<built-in>" ># 1 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.c" >/* > * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. > * All rights reserved. > * > * This source code is licensed under both the BSD-style license (found in the > * LICENSE file in the root directory of this source tree) and the GPLv2 (found > * in the COPYING file in the root directory of this source tree). > * You may select, at your option, one of the above-listed licenses. > */ > > >/*-************************************* >* Tuning parameters >***************************************/ >#ifndef ZSTD_CLEVEL_DEFAULT ># define ZSTD_CLEVEL_DEFAULT 3 >#endif ># 18 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.c" > > >/*-************************************* >* Dependencies >***************************************/ >#if 0 /* expanded by -frewrite-includes */ >#include <string.h> /* memset */ >#endif /* expanded by -frewrite-includes */ ># 23 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.c" ># 1 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/string.h" 1 3 4 >/*- > * Copyright (c) 1990, 1993 > * The Regents of the University of California. All rights reserved. > * > * Redistribution and use in source and binary forms, with or without > * modification, are permitted provided that the following conditions > * are met: > * 1. Redistributions of source code must retain the above copyright > * notice, this list of conditions and the following disclaimer. > * 2. Redistributions in binary form must reproduce the above copyright > * notice, this list of conditions and the following disclaimer in the > * documentation and/or other materials provided with the distribution. > * 3. Neither the name of the University nor the names of its contributors > * may be used to endorse or promote products derived from this software > * without specific prior written permission. > * > * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND > * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE > * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE > * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE > * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL > * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS > * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) > * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT > * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY > * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF > * SUCH DAMAGE. > * > * @(#)string.h 8.1 (Berkeley) 6/2/93 > * $FreeBSD: head/include/string.h 316213 2017-03-30 04:57:26Z kib $ > */ > >#ifndef _STRING_H_ >#define _STRING_H_ > >#if 0 /* expanded by -frewrite-includes */ >#include <sys/cdefs.h> >#endif /* expanded by -frewrite-includes */ ># 36 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/string.h" 3 4 ># 1 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 1 3 4 >/*- > * Copyright (c) 1991, 1993 > * The Regents of the University of California. All rights reserved. > * > * This code is derived from software contributed to Berkeley by > * Berkeley Software Design, Inc. > * > * Redistribution and use in source and binary forms, with or without > * modification, are permitted provided that the following conditions > * are met: > * 1. Redistributions of source code must retain the above copyright > * notice, this list of conditions and the following disclaimer. > * 2. Redistributions in binary form must reproduce the above copyright > * notice, this list of conditions and the following disclaimer in the > * documentation and/or other materials provided with the distribution. > * 3. Neither the name of the University nor the names of its contributors > * may be used to endorse or promote products derived from this software > * without specific prior written permission. > * > * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND > * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE > * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE > * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE > * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL > * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS > * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) > * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT > * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY > * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF > * SUCH DAMAGE. > * > * @(#)cdefs.h 8.8 (Berkeley) 1/9/95 > * $FreeBSD: head/sys/sys/cdefs.h 322965 2017-08-28 09:35:17Z ed $ > */ > >#ifndef _SYS_CDEFS_H_ >#define _SYS_CDEFS_H_ > >/* > * Testing against Clang-specific extensions. > */ >#ifndef __has_attribute >#define __has_attribute(x) 0 >#endif ># 45 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#ifndef __has_extension >#define __has_extension __has_feature >#endif ># 48 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#ifndef __has_feature >#define __has_feature(x) 0 >#endif ># 51 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#ifndef __has_include >#define __has_include(x) 0 >#endif ># 54 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#ifndef __has_builtin >#define __has_builtin(x) 0 >#endif ># 57 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >#if defined(__cplusplus) >#define __BEGIN_DECLS extern "C" { >#define __END_DECLS } >#else ># 62 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __BEGIN_DECLS >#define __END_DECLS >#endif ># 65 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >/* > * This code has been put in place to help reduce the addition of > * compiler specific defines in FreeBSD code. It helps to aid in > * having a compiler-agnostic source tree. > */ > >#if defined(__GNUC__) || defined(__INTEL_COMPILER) > >#if __GNUC__ >= 3 || defined(__INTEL_COMPILER) >#define __GNUCLIKE_ASM 3 >#define __GNUCLIKE_MATH_BUILTIN_CONSTANTS >#else ># 78 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __GNUCLIKE_ASM 2 >#endif ># 80 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __GNUCLIKE___TYPEOF 1 >#define __GNUCLIKE___OFFSETOF 1 >#define __GNUCLIKE___SECTION 1 > >#ifndef __INTEL_COMPILER >#define __GNUCLIKE_CTOR_SECTION_HANDLING 1 >#endif ># 87 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >#define __GNUCLIKE_BUILTIN_CONSTANT_P 1 >#if defined(__INTEL_COMPILER) && defined(__cplusplus) && \ > __INTEL_COMPILER < 800 >#undef __GNUCLIKE_BUILTIN_CONSTANT_P >#endif ># 93 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >#if (__GNUC_MINOR__ > 95 || __GNUC__ >= 3) >#define __GNUCLIKE_BUILTIN_VARARGS 1 >#define __GNUCLIKE_BUILTIN_STDARG 1 >#define __GNUCLIKE_BUILTIN_VAALIST 1 >#endif ># 99 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >#if defined(__GNUC__) >#define __GNUC_VA_LIST_COMPATIBILITY 1 >#endif ># 103 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >/* > * Compiler memory barriers, specific to gcc and clang. > */ >#if defined(__GNUC__) >#define __compiler_membar() __asm __volatile(" " : : : "memory") >#endif ># 110 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >#ifndef __INTEL_COMPILER >#define __GNUCLIKE_BUILTIN_NEXT_ARG 1 >#define __GNUCLIKE_MATH_BUILTIN_RELOPS >#endif ># 115 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >#define __GNUCLIKE_BUILTIN_MEMCPY 1 > >/* XXX: if __GNUC__ >= 2: not tested everywhere originally, where replaced */ >#define __CC_SUPPORTS_INLINE 1 >#define __CC_SUPPORTS___INLINE 1 >#define __CC_SUPPORTS___INLINE__ 1 > >#define __CC_SUPPORTS___FUNC__ 1 >#define __CC_SUPPORTS_WARNING 1 > >#define __CC_SUPPORTS_VARADIC_XXX 1 /* see varargs.h */ > >#define __CC_SUPPORTS_DYNAMIC_ARRAY_INIT 1 > >#endif /* __GNUC__ || __INTEL_COMPILER */ ># 131 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >/* > * Macro to test if we're using a specific version of gcc or later. > */ >#if defined(__GNUC__) && !defined(__INTEL_COMPILER) >#define __GNUC_PREREQ__(ma, mi) \ > (__GNUC__ > (ma) || __GNUC__ == (ma) && __GNUC_MINOR__ >= (mi)) >#else ># 139 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __GNUC_PREREQ__(ma, mi) 0 >#endif ># 141 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >/* > * The __CONCAT macro is used to concatenate parts of symbol names, e.g. > * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo. > * The __CONCAT macro is a bit tricky to use if it must work in non-ANSI > * mode -- there must be no spaces between its arguments, and for nested > * __CONCAT's, all the __CONCAT's must be at the left. __CONCAT can also > * concatenate double-quoted strings produced by the __STRING macro, but > * this only works with ANSI C. > * > * __XSTRING is like __STRING, but it expands any macros in its argument > * first. It is only available with ANSI C. > */ >#if defined(__STDC__) || defined(__cplusplus) >#define __P(protos) protos /* full-blown ANSI C */ >#define __CONCAT1(x,y) x ## y >#define __CONCAT(x,y) __CONCAT1(x,y) >#define __STRING(x) #x /* stringify without expanding x */ >#define __XSTRING(x) __STRING(x) /* expand x, then stringify */ > >#define __const const /* define reserved names to standard */ >#define __signed signed >#define __volatile volatile >#if defined(__cplusplus) >#define __inline inline /* convert to C++ keyword */ >#else ># 167 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#if !(defined(__CC_SUPPORTS___INLINE)) >#define __inline /* delete GCC keyword */ >#endif /* ! __CC_SUPPORTS___INLINE */ ># 170 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#endif /* !__cplusplus */ ># 171 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >#else /* !(__STDC__ || __cplusplus) */ ># 173 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __P(protos) () /* traditional C preprocessor */ >#define __CONCAT(x,y) x/**/y >#define __STRING(x) "x" > >#if !defined(__CC_SUPPORTS___INLINE) >#define __const /* delete pseudo-ANSI C keywords */ >#define __inline >#define __signed >#define __volatile >/* > * In non-ANSI C environments, new programs will want ANSI-only C keywords > * deleted from the program and old programs will want them left alone. > * When using a compiler other than gcc, programs using the ANSI C keywords > * const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS. > * When using "gcc -traditional", we assume that this is the intent; if > * __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone. > */ >#ifndef NO_ANSI_KEYWORDS >#define const /* delete ANSI C keywords */ >#define inline >#define signed >#define volatile >#endif /* !NO_ANSI_KEYWORDS */ ># 196 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#endif /* !__CC_SUPPORTS___INLINE */ ># 197 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#endif /* !(__STDC__ || __cplusplus) */ ># 198 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >/* > * Compiler-dependent macros to help declare dead (non-returning) and > * pure (no side effects) functions, and unused variables. They are > * null except for versions of gcc that are known to support the features > * properly (old versions of gcc-2 supported the dead and pure features > * in a different (wrong) way). If we do not provide an implementation > * for a given compiler, let the compile fail if it is told to use > * a feature that we cannot live without. > */ >#ifdef lint >#define __dead2 >#define __pure2 >#define __unused >#define __packed >#define __aligned(x) >#define __alloc_align(x) >#define __alloc_size(x) >#define __section(x) >#define __weak_symbol >#else ># 219 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __weak_symbol __attribute__((__weak__)) >#if !__GNUC_PREREQ__(2, 5) && !defined(__INTEL_COMPILER) >#define __dead2 >#define __pure2 >#define __unused >#endif ># 225 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#if __GNUC__ == 2 && __GNUC_MINOR__ >= 5 && __GNUC_MINOR__ < 7 && !defined(__INTEL_COMPILER) >#define __dead2 __attribute__((__noreturn__)) >#define __pure2 __attribute__((__const__)) >#define __unused >/* XXX Find out what to do for __packed, __aligned and __section */ >#endif ># 231 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#if __GNUC_PREREQ__(2, 7) || defined(__INTEL_COMPILER) >#define __dead2 __attribute__((__noreturn__)) >#define __pure2 __attribute__((__const__)) >#define __unused __attribute__((__unused__)) >#define __used __attribute__((__used__)) >#define __packed __attribute__((__packed__)) >#define __aligned(x) __attribute__((__aligned__(x))) >#define __section(x) __attribute__((__section__(x))) >#endif ># 240 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#if __GNUC_PREREQ__(4, 3) || __has_attribute(__alloc_size__) >#define __alloc_size(x) __attribute__((__alloc_size__(x))) >#else ># 243 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __alloc_size(x) >#endif ># 245 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#if __GNUC_PREREQ__(4, 9) || __has_attribute(__alloc_align__) >#define __alloc_align(x) __attribute__((__alloc_align__(x))) >#else ># 248 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __alloc_align(x) >#endif ># 250 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#endif /* lint */ ># 251 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >#if !__GNUC_PREREQ__(2, 95) >#define __alignof(x) __offsetof(struct { char __a; x __b; }, __b) >#endif ># 255 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >/* > * Keywords added in C11. > */ > >#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L || defined(lint) > >#if !__has_extension(c_alignas) >#if (defined(__cplusplus) && __cplusplus >= 201103L) || \ > __has_extension(cxx_alignas) >#define _Alignas(x) alignas(x) >#else ># 267 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >/* XXX: Only emulates _Alignas(constant-expression); not _Alignas(type-name). */ >#define _Alignas(x) __aligned(x) >#endif ># 270 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#endif ># 271 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >#if defined(__cplusplus) && __cplusplus >= 201103L >#define _Alignof(x) alignof(x) >#else ># 275 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define _Alignof(x) __alignof(x) >#endif ># 277 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >#if !defined(__cplusplus) && !__has_extension(c_atomic) && \ > !__has_extension(cxx_atomic) >/* > * No native support for _Atomic(). Place object in structure to prevent > * most forms of direct non-atomic access. > */ >#define _Atomic(T) struct { T volatile __val; } >#endif ># 286 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >#if defined(__cplusplus) && __cplusplus >= 201103L >#define _Noreturn [[noreturn]] >#else ># 290 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define _Noreturn __dead2 >#endif ># 292 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >#if !__has_extension(c_static_assert) >#if (defined(__cplusplus) && __cplusplus >= 201103L) || \ > __has_extension(cxx_static_assert) >#define _Static_assert(x, y) static_assert(x, y) >#elif __GNUC_PREREQ__(4,6) && !defined(__cplusplus) ># 298 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >/* Nothing, gcc 4.6 and higher has _Static_assert built-in */ >#elif defined(__COUNTER__) ># 300 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define _Static_assert(x, y) __Static_assert(x, __COUNTER__) >#define __Static_assert(x, y) ___Static_assert(x, y) >#define ___Static_assert(x, y) typedef char __assert_ ## y[(x) ? 1 : -1] \ > __unused >#else ># 305 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define _Static_assert(x, y) struct __hack >#endif ># 307 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#endif ># 308 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >#if !__has_extension(c_thread_local) >/* > * XXX: Some compilers (Clang 3.3, GCC 4.7) falsely announce C++11 mode > * without actually supporting the thread_local keyword. Don't check for > * the presence of C++11 when defining _Thread_local. > */ >#if /* (defined(__cplusplus) && __cplusplus >= 201103L) || */ \ > __has_extension(cxx_thread_local) >#define _Thread_local thread_local >#else ># 319 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define _Thread_local __thread >#endif ># 321 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#endif ># 322 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >#endif /* __STDC_VERSION__ || __STDC_VERSION__ < 201112L */ ># 324 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >/* > * Emulation of C11 _Generic(). Unlike the previously defined C11 > * keywords, it is not possible to implement this using exactly the same > * syntax. Therefore implement something similar under the name > * __generic(). Unlike _Generic(), this macro can only distinguish > * between a single type, so it requires nested invocations to > * distinguish multiple cases. > */ > >#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \ > __has_extension(c_generic_selections) >#define __generic(expr, t, yes, no) \ > _Generic(expr, t: yes, default: no) >#elif __GNUC_PREREQ__(3, 1) && !defined(__cplusplus) ># 339 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __generic(expr, t, yes, no) \ > __builtin_choose_expr( \ > __builtin_types_compatible_p(__typeof(expr), t), yes, no) >#endif ># 343 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >/* > * C99 Static array indices in function parameter declarations. Syntax such as: > * void bar(int myArray[static 10]); > * is allowed in C99 but not in C++. Define __min_size appropriately so > * headers using it can be compiled in either language. Use like this: > * void bar(int myArray[__min_size(10)]); > */ >#if !defined(__cplusplus) && \ > (defined(__clang__) || __GNUC_PREREQ__(4, 6)) && \ > (!defined(__STDC_VERSION__) || (__STDC_VERSION__ >= 199901)) >#define __min_size(x) static (x) >#else ># 356 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __min_size(x) (x) >#endif ># 358 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >#if __GNUC_PREREQ__(2, 96) >#define __malloc_like __attribute__((__malloc__)) >#define __pure __attribute__((__pure__)) >#else ># 363 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __malloc_like >#define __pure >#endif ># 366 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >#if __GNUC_PREREQ__(3, 1) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800) >#define __always_inline __attribute__((__always_inline__)) >#else ># 370 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __always_inline >#endif ># 372 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >#if __GNUC_PREREQ__(3, 1) >#define __noinline __attribute__ ((__noinline__)) >#else ># 376 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __noinline >#endif ># 378 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >#if __GNUC_PREREQ__(3, 4) >#define __fastcall __attribute__((__fastcall__)) >#define __result_use_check __attribute__((__warn_unused_result__)) >#else ># 383 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __fastcall >#define __result_use_check >#endif ># 386 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >#if __GNUC_PREREQ__(4, 1) >#define __returns_twice __attribute__((__returns_twice__)) >#else ># 390 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __returns_twice >#endif ># 392 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >#if __GNUC_PREREQ__(4, 6) || __has_builtin(__builtin_unreachable) >#define __unreachable() __builtin_unreachable() >#else ># 396 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __unreachable() ((void)0) >#endif ># 398 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >/* XXX: should use `#if __STDC_VERSION__ < 199901'. */ >#if !__GNUC_PREREQ__(2, 7) && !defined(__INTEL_COMPILER) >#define __func__ NULL >#endif ># 403 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >#if (defined(__INTEL_COMPILER) || (defined(__GNUC__) && __GNUC__ >= 2)) && !defined(__STRICT_ANSI__) || __STDC_VERSION__ >= 199901 >#define __LONG_LONG_SUPPORTED >#endif ># 407 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >/* C++11 exposes a load of C99 stuff */ >#if defined(__cplusplus) && __cplusplus >= 201103L >#define __LONG_LONG_SUPPORTED >#ifndef __STDC_LIMIT_MACROS >#define __STDC_LIMIT_MACROS >#endif ># 414 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#ifndef __STDC_CONSTANT_MACROS >#define __STDC_CONSTANT_MACROS >#endif ># 417 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#endif ># 418 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >/* > * GCC 2.95 provides `__restrict' as an extension to C90 to support the > * C99-specific `restrict' type qualifier. We happen to use `__restrict' as > * a way to define the `restrict' type qualifier without disturbing older > * software that is unaware of C99 keywords. > */ >#if !(__GNUC__ == 2 && __GNUC_MINOR__ == 95) >#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901 || defined(lint) >#define __restrict >#else ># 429 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __restrict restrict >#endif ># 431 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#endif ># 432 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >/* > * GNU C version 2.96 adds explicit branch prediction so that > * the CPU back-end can hint the processor and also so that > * code blocks can be reordered such that the predicted path > * sees a more linear flow, thus improving cache behavior, etc. > * > * The following two macros provide us with a way to utilize this > * compiler feature. Use __predict_true() if you expect the expression > * to evaluate to true, and __predict_false() if you expect the > * expression to evaluate to false. > * > * A few notes about usage: > * > * * Generally, __predict_false() error condition checks (unless > * you have some _strong_ reason to do otherwise, in which case > * document it), and/or __predict_true() `no-error' condition > * checks, assuming you want to optimize for the no-error case. > * > * * Other than that, if you don't know the likelihood of a test > * succeeding from empirical or other `hard' evidence, don't > * make predictions. > * > * * These are meant to be used in places that are run `a lot'. > * It is wasteful to make predictions in code that is run > * seldomly (e.g. at subsystem initialization time) as the > * basic block reordering that this affects can often generate > * larger code. > */ >#if __GNUC_PREREQ__(2, 96) >#define __predict_true(exp) __builtin_expect((exp), 1) >#define __predict_false(exp) __builtin_expect((exp), 0) >#else ># 465 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __predict_true(exp) (exp) >#define __predict_false(exp) (exp) >#endif ># 468 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >#if __GNUC_PREREQ__(4, 0) >#define __null_sentinel __attribute__((__sentinel__)) >#define __exported __attribute__((__visibility__("default"))) >#define __hidden __attribute__((__visibility__("hidden"))) >#else ># 474 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __null_sentinel >#define __exported >#define __hidden >#endif ># 478 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >/* > * We define this here since <stddef.h>, <sys/queue.h>, and <sys/types.h> > * require it. > */ >#if __GNUC_PREREQ__(4, 1) >#define __offsetof(type, field) __builtin_offsetof(type, field) >#else ># 486 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#ifndef __cplusplus >#define __offsetof(type, field) \ > ((__size_t)(__uintptr_t)((const volatile void *)&((type *)0)->field)) >#else ># 490 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __offsetof(type, field) \ > (__offsetof__ (reinterpret_cast <__size_t> \ > (&reinterpret_cast <const volatile char &> \ > (static_cast<type *> (0)->field)))) >#endif ># 495 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#endif ># 496 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __rangeof(type, start, end) \ > (__offsetof(type, end) - __offsetof(type, start)) > >/* > * Given the pointer x to the member m of the struct s, return > * a pointer to the containing structure. When using GCC, we first > * assign pointer x to a local variable, to check that its type is > * compatible with member m. > */ >#if __GNUC_PREREQ__(3, 1) >#define __containerof(x, s, m) ({ \ > const volatile __typeof(((s *)0)->m) *__x = (x); \ > __DEQUALIFY(s *, (const volatile char *)__x - __offsetof(s, m));\ >}) >#else ># 511 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __containerof(x, s, m) \ > __DEQUALIFY(s *, (const volatile char *)(x) - __offsetof(s, m)) >#endif ># 514 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >/* > * Compiler-dependent macros to declare that functions take printf-like > * or scanf-like arguments. They are null except for versions of gcc > * that are known to support the features properly (old versions of gcc-2 > * didn't permit keeping the keywords out of the application namespace). > */ >#if !__GNUC_PREREQ__(2, 7) && !defined(__INTEL_COMPILER) >#define __printflike(fmtarg, firstvararg) >#define __scanflike(fmtarg, firstvararg) >#define __format_arg(fmtarg) >#define __strfmonlike(fmtarg, firstvararg) >#define __strftimelike(fmtarg, firstvararg) >#else ># 528 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __printflike(fmtarg, firstvararg) \ > __attribute__((__format__ (__printf__, fmtarg, firstvararg))) >#define __scanflike(fmtarg, firstvararg) \ > __attribute__((__format__ (__scanf__, fmtarg, firstvararg))) >#define __format_arg(fmtarg) __attribute__((__format_arg__ (fmtarg))) >#define __strfmonlike(fmtarg, firstvararg) \ > __attribute__((__format__ (__strfmon__, fmtarg, firstvararg))) >#define __strftimelike(fmtarg, firstvararg) \ > __attribute__((__format__ (__strftime__, fmtarg, firstvararg))) >#endif ># 538 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >/* Compiler-dependent macros that rely on FreeBSD-specific extensions. */ >#if defined(__FreeBSD_cc_version) && __FreeBSD_cc_version >= 300001 && \ > defined(__GNUC__) && !defined(__INTEL_COMPILER) >#define __printf0like(fmtarg, firstvararg) \ > __attribute__((__format__ (__printf0__, fmtarg, firstvararg))) >#else ># 545 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __printf0like(fmtarg, firstvararg) >#endif ># 547 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >#if defined(__GNUC__) || defined(__INTEL_COMPILER) >#ifndef __INTEL_COMPILER >#define __strong_reference(sym,aliassym) \ > extern __typeof (sym) aliassym __attribute__ ((__alias__ (#sym))) >#endif ># 553 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#ifdef __STDC__ >#define __weak_reference(sym,alias) \ > __asm__(".weak " #alias); \ > __asm__(".equ " #alias ", " #sym) >#define __warn_references(sym,msg) \ > __asm__(".section .gnu.warning." #sym); \ > __asm__(".asciz \"" msg "\""); \ > __asm__(".previous") >#define __sym_compat(sym,impl,verid) \ > __asm__(".symver " #impl ", " #sym "@" #verid) >#define __sym_default(sym,impl,verid) \ > __asm__(".symver " #impl ", " #sym "@@" #verid) >#else ># 566 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __weak_reference(sym,alias) \ > __asm__(".weak alias"); \ > __asm__(".equ alias, sym") >#define __warn_references(sym,msg) \ > __asm__(".section .gnu.warning.sym"); \ > __asm__(".asciz \"msg\""); \ > __asm__(".previous") >#define __sym_compat(sym,impl,verid) \ > __asm__(".symver impl, sym@verid") >#define __sym_default(impl,sym,verid) \ > __asm__(".symver impl, sym@@verid") >#endif /* __STDC__ */ ># 578 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#endif /* __GNUC__ || __INTEL_COMPILER */ ># 579 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >#define __GLOBL1(sym) __asm__(".globl " #sym) >#define __GLOBL(sym) __GLOBL1(sym) > >#if defined(__GNUC__) || defined(__INTEL_COMPILER) >#define __IDSTRING(name,string) __asm__(".ident\t\"" string "\"") >#else ># 586 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >/* > * The following definition might not work well if used in header files, > * but it should be better than nothing. If you want a "do nothing" > * version, then it should generate some harmless declaration, such as: > * #define __IDSTRING(name,string) struct __hack > */ >#define __IDSTRING(name,string) static const char name[] __unused = string >#endif ># 594 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >/* > * Embed the rcs id of a source file in the resulting library. Note that in > * more recent ELF binutils, we use .ident allowing the ID to be stripped. > * Usage: > * __FBSDID("$FreeBSD: head/sys/sys/cdefs.h 322965 2017-08-28 09:35:17Z ed $"); > */ >#ifndef __FBSDID >#if !defined(lint) && !defined(STRIP_FBSDID) >#define __FBSDID(s) __IDSTRING(__CONCAT(__rcsid_,__LINE__),s) >#else ># 605 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __FBSDID(s) struct __hack >#endif ># 607 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#endif ># 608 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >#ifndef __RCSID >#ifndef NO__RCSID >#define __RCSID(s) __IDSTRING(__CONCAT(__rcsid_,__LINE__),s) >#else ># 613 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __RCSID(s) struct __hack >#endif ># 615 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#endif ># 616 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >#ifndef __RCSID_SOURCE >#ifndef NO__RCSID_SOURCE >#define __RCSID_SOURCE(s) __IDSTRING(__CONCAT(__rcsid_source_,__LINE__),s) >#else ># 621 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __RCSID_SOURCE(s) struct __hack >#endif ># 623 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#endif ># 624 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >#ifndef __SCCSID >#ifndef NO__SCCSID >#define __SCCSID(s) __IDSTRING(__CONCAT(__sccsid_,__LINE__),s) >#else ># 629 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __SCCSID(s) struct __hack >#endif ># 631 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#endif ># 632 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >#ifndef __COPYRIGHT >#ifndef NO__COPYRIGHT >#define __COPYRIGHT(s) __IDSTRING(__CONCAT(__copyright_,__LINE__),s) >#else ># 637 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __COPYRIGHT(s) struct __hack >#endif ># 639 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#endif ># 640 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >#ifndef __DECONST >#define __DECONST(type, var) ((type)(__uintptr_t)(const void *)(var)) >#endif ># 644 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >#ifndef __DEVOLATILE >#define __DEVOLATILE(type, var) ((type)(__uintptr_t)(volatile void *)(var)) >#endif ># 648 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >#ifndef __DEQUALIFY >#define __DEQUALIFY(type, var) ((type)(__uintptr_t)(const volatile void *)(var)) >#endif ># 652 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >/*- > * The following definitions are an extension of the behavior originally > * implemented in <sys/_posix.h>, but with a different level of granularity. > * POSIX.1 requires that the macros we test be defined before any standard > * header file is included. > * > * Here's a quick run-down of the versions: > * defined(_POSIX_SOURCE) 1003.1-1988 > * _POSIX_C_SOURCE == 1 1003.1-1990 > * _POSIX_C_SOURCE == 2 1003.2-1992 C Language Binding Option > * _POSIX_C_SOURCE == 199309 1003.1b-1993 > * _POSIX_C_SOURCE == 199506 1003.1c-1995, 1003.1i-1995, > * and the omnibus ISO/IEC 9945-1: 1996 > * _POSIX_C_SOURCE == 200112 1003.1-2001 > * _POSIX_C_SOURCE == 200809 1003.1-2008 > * > * In addition, the X/Open Portability Guide, which is now the Single UNIX > * Specification, defines a feature-test macro which indicates the version of > * that specification, and which subsumes _POSIX_C_SOURCE. > * > * Our macros begin with two underscores to avoid namespace screwage. > */ > >/* Deal with IEEE Std. 1003.1-1990, in which _POSIX_C_SOURCE == 1. */ >#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 1 >#undef _POSIX_C_SOURCE /* Probably illegal, but beyond caring now. */ >#define _POSIX_C_SOURCE 199009 >#endif ># 681 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >/* Deal with IEEE Std. 1003.2-1992, in which _POSIX_C_SOURCE == 2. */ >#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 2 >#undef _POSIX_C_SOURCE >#define _POSIX_C_SOURCE 199209 >#endif ># 687 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >/* Deal with various X/Open Portability Guides and Single UNIX Spec. */ >#ifdef _XOPEN_SOURCE >#if _XOPEN_SOURCE - 0 >= 700 >#define __XSI_VISIBLE 700 >#undef _POSIX_C_SOURCE >#define _POSIX_C_SOURCE 200809 >#elif _XOPEN_SOURCE - 0 >= 600 ># 695 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __XSI_VISIBLE 600 >#undef _POSIX_C_SOURCE >#define _POSIX_C_SOURCE 200112 >#elif _XOPEN_SOURCE - 0 >= 500 ># 699 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __XSI_VISIBLE 500 >#undef _POSIX_C_SOURCE >#define _POSIX_C_SOURCE 199506 >#endif ># 703 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#endif ># 704 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >/* > * Deal with all versions of POSIX. The ordering relative to the tests above is > * important. > */ >#if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE) >#define _POSIX_C_SOURCE 198808 >#endif ># 712 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#ifdef _POSIX_C_SOURCE >#if _POSIX_C_SOURCE >= 200809 >#define __POSIX_VISIBLE 200809 >#define __ISO_C_VISIBLE 1999 >#elif _POSIX_C_SOURCE >= 200112 ># 717 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __POSIX_VISIBLE 200112 >#define __ISO_C_VISIBLE 1999 >#elif _POSIX_C_SOURCE >= 199506 ># 720 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __POSIX_VISIBLE 199506 >#define __ISO_C_VISIBLE 1990 >#elif _POSIX_C_SOURCE >= 199309 ># 723 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __POSIX_VISIBLE 199309 >#define __ISO_C_VISIBLE 1990 >#elif _POSIX_C_SOURCE >= 199209 ># 726 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __POSIX_VISIBLE 199209 >#define __ISO_C_VISIBLE 1990 >#elif _POSIX_C_SOURCE >= 199009 ># 729 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __POSIX_VISIBLE 199009 >#define __ISO_C_VISIBLE 1990 >#else ># 732 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __POSIX_VISIBLE 198808 >#define __ISO_C_VISIBLE 0 >#endif /* _POSIX_C_SOURCE */ ># 735 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#else ># 736 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >/*- > * Deal with _ANSI_SOURCE: > * If it is defined, and no other compilation environment is explicitly > * requested, then define our internal feature-test macros to zero. This > * makes no difference to the preprocessor (undefined symbols in preprocessing > * expressions are defined to have value zero), but makes it more convenient for > * a test program to print out the values. > * > * If a program mistakenly defines _ANSI_SOURCE and some other macro such as > * _POSIX_C_SOURCE, we will assume that it wants the broader compilation > * environment (and in fact we will never get here). > */ >#if defined(_ANSI_SOURCE) /* Hide almost everything. */ >#define __POSIX_VISIBLE 0 >#define __XSI_VISIBLE 0 >#define __BSD_VISIBLE 0 >#define __ISO_C_VISIBLE 1990 >#define __EXT1_VISIBLE 0 >#elif defined(_C99_SOURCE) /* Localism to specify strict C99 env. */ ># 755 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __POSIX_VISIBLE 0 >#define __XSI_VISIBLE 0 >#define __BSD_VISIBLE 0 >#define __ISO_C_VISIBLE 1999 >#define __EXT1_VISIBLE 0 >#elif defined(_C11_SOURCE) /* Localism to specify strict C11 env. */ ># 761 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __POSIX_VISIBLE 0 >#define __XSI_VISIBLE 0 >#define __BSD_VISIBLE 0 >#define __ISO_C_VISIBLE 2011 >#define __EXT1_VISIBLE 0 >#else /* Default environment: show everything. */ ># 767 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __POSIX_VISIBLE 200809 >#define __XSI_VISIBLE 700 >#define __BSD_VISIBLE 1 >#define __ISO_C_VISIBLE 2011 >#define __EXT1_VISIBLE 1 >#endif ># 773 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#endif ># 774 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >/* User override __EXT1_VISIBLE */ >#if defined(__STDC_WANT_LIB_EXT1__) >#undef __EXT1_VISIBLE >#if __STDC_WANT_LIB_EXT1__ >#define __EXT1_VISIBLE 1 >#else ># 781 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __EXT1_VISIBLE 0 >#endif ># 783 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#endif /* __STDC_WANT_LIB_EXT1__ */ ># 784 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >#if defined(__mips) || defined(__powerpc64__) || defined(__riscv) >#define __NO_TLS 1 >#endif ># 788 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >/* > * Old versions of GCC use non-standard ARM arch symbols; acle-compat.h > * translates them to __ARM_ARCH and the modern feature symbols defined by ARM. > */ >#if defined(__arm__) && !defined(__ARM_ARCH) >#if 0 /* expanded by -frewrite-includes */ >#include <machine/acle-compat.h> >#endif /* expanded by -frewrite-includes */ ># 794 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 ># 795 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#endif ># 796 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >/* > * Nullability qualifiers: currently only supported by Clang. > */ >#if !(defined(__clang__) && __has_feature(nullability)) >#define _Nonnull >#define _Nullable >#define _Null_unspecified >#define __NULLABILITY_PRAGMA_PUSH >#define __NULLABILITY_PRAGMA_POP >#else ># 807 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __NULLABILITY_PRAGMA_PUSH _Pragma("clang diagnostic push") \ > _Pragma("clang diagnostic ignored \"-Wnullability-completeness\"") >#define __NULLABILITY_PRAGMA_POP _Pragma("clang diagnostic pop") >#endif ># 811 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >/* > * Type Safety Checking > * > * Clang provides additional attributes to enable checking type safety > * properties that cannot be enforced by the C type system. > */ > >#if __has_attribute(__argument_with_type_tag__) && \ > __has_attribute(__type_tag_for_datatype__) && !defined(lint) >#define __arg_type_tag(arg_kind, arg_idx, type_tag_idx) \ > __attribute__((__argument_with_type_tag__(arg_kind, arg_idx, type_tag_idx))) >#define __datatype_type_tag(kind, type) \ > __attribute__((__type_tag_for_datatype__(kind, type))) >#else ># 826 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __arg_type_tag(arg_kind, arg_idx, type_tag_idx) >#define __datatype_type_tag(kind, type) >#endif ># 829 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >/* > * Lock annotations. > * > * Clang provides support for doing basic thread-safety tests at > * compile-time, by marking which locks will/should be held when > * entering/leaving a functions. > * > * Furthermore, it is also possible to annotate variables and structure > * members to enforce that they are only accessed when certain locks are > * held. > */ > >#if __has_extension(c_thread_safety_attributes) >#define __lock_annotate(x) __attribute__((x)) >#else ># 845 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 >#define __lock_annotate(x) >#endif ># 847 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 > >/* Structure implements a lock. */ >#define __lockable __lock_annotate(lockable) > >/* Function acquires an exclusive or shared lock. */ >#define __locks_exclusive(...) \ > __lock_annotate(exclusive_lock_function(__VA_ARGS__)) >#define __locks_shared(...) \ > __lock_annotate(shared_lock_function(__VA_ARGS__)) > >/* Function attempts to acquire an exclusive or shared lock. */ >#define __trylocks_exclusive(...) \ > __lock_annotate(exclusive_trylock_function(__VA_ARGS__)) >#define __trylocks_shared(...) \ > __lock_annotate(shared_trylock_function(__VA_ARGS__)) > >/* Function releases a lock. */ >#define __unlocks(...) __lock_annotate(unlock_function(__VA_ARGS__)) > >/* Function asserts that an exclusive or shared lock is held. */ >#define __asserts_exclusive(...) \ > __lock_annotate(assert_exclusive_lock(__VA_ARGS__)) >#define __asserts_shared(...) \ > __lock_annotate(assert_shared_lock(__VA_ARGS__)) > >/* Function requires that an exclusive or shared lock is or is not held. */ >#define __requires_exclusive(...) \ > __lock_annotate(exclusive_locks_required(__VA_ARGS__)) >#define __requires_shared(...) \ > __lock_annotate(shared_locks_required(__VA_ARGS__)) >#define __requires_unlocked(...) \ > __lock_annotate(locks_excluded(__VA_ARGS__)) > >/* Function should not be analyzed. */ >#define __no_lock_analysis __lock_annotate(no_thread_safety_analysis) > >/* Guard variables and structure members by lock. */ >#define __guarded_by(x) __lock_annotate(guarded_by(x)) >#define __pt_guarded_by(x) __lock_annotate(pt_guarded_by(x)) > >#endif /* !_SYS_CDEFS_H_ */ ># 888 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/cdefs.h" 3 4 ># 37 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/string.h" 2 3 4 >#if 0 /* expanded by -frewrite-includes */ >#include <sys/_null.h> >#endif /* expanded by -frewrite-includes */ ># 37 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/string.h" 3 4 ># 1 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/_null.h" 1 3 4 >/*- > * Copyright (c) 2003 Marcel Moolenaar > * All rights reserved. > * > * Redistribution and use in source and binary forms, with or without > * modification, are permitted provided that the following conditions > * are met: > * > * 1. Redistributions of source code must retain the above copyright > * notice, this list of conditions and the following disclaimer. > * 2. Redistributions in binary form must reproduce the above copyright > * notice, this list of conditions and the following disclaimer in the > * documentation and/or other materials provided with the distribution. > * > * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR > * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES > * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. > * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, > * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT > * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, > * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY > * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT > * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF > * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > * > * $FreeBSD: head/sys/sys/_null.h 228918 2011-12-27 21:36:31Z theraven $ > */ > >#ifndef NULL > >#if !defined(__cplusplus) >#define NULL ((void *)0) >#else ># 34 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/_null.h" 3 4 >#if __cplusplus >= 201103L >#define NULL nullptr >#elif defined(__GNUG__) && defined(__GNUC__) && __GNUC__ >= 4 ># 37 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/_null.h" 3 4 >#define NULL __null >#else ># 39 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/_null.h" 3 4 >#if defined(__LP64__) >#define NULL (0L) >#else ># 42 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/_null.h" 3 4 >#define NULL 0 >#endif /* __LP64__ */ ># 44 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/_null.h" 3 4 >#endif /* __GNUG__ */ ># 45 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/_null.h" 3 4 >#endif /* !__cplusplus */ ># 46 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/_null.h" 3 4 > >#endif ># 48 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/_null.h" 3 4 ># 38 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/string.h" 2 3 4 >#if 0 /* expanded by -frewrite-includes */ >#include <sys/_types.h> >#endif /* expanded by -frewrite-includes */ ># 38 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/string.h" 3 4 ># 1 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/_types.h" 1 3 4 >/*- > * Copyright (c) 2002 Mike Barcroft <mike@FreeBSD.org> > * All rights reserved. > * > * Redistribution and use in source and binary forms, with or without > * modification, are permitted provided that the following conditions > * are met: > * 1. Redistributions of source code must retain the above copyright > * notice, this list of conditions and the following disclaimer. > * 2. Redistributions in binary form must reproduce the above copyright > * notice, this list of conditions and the following disclaimer in the > * documentation and/or other materials provided with the distribution. > * > * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND > * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE > * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE > * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE > * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL > * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS > * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) > * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT > * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY > * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF > * SUCH DAMAGE. > * > * $FreeBSD: head/sys/sys/_types.h 318959 2017-05-26 16:29:55Z dim $ > */ > >#ifndef _SYS__TYPES_H_ >#define _SYS__TYPES_H_ > >#if 0 /* expanded by -frewrite-includes */ >#include <sys/cdefs.h> >#endif /* expanded by -frewrite-includes */ ># 32 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/_types.h" 3 4 ># 33 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/_types.h" 3 4 >#if 0 /* expanded by -frewrite-includes */ >#include <machine/_types.h> >#endif /* expanded by -frewrite-includes */ ># 33 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/_types.h" 3 4 ># 1 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/machine/_types.h" 1 3 4 >/*- > * Copyright (c) 2002 Mike Barcroft <mike@FreeBSD.org> > * Copyright (c) 1990, 1993 > * The Regents of the University of California. All rights reserved. > * > * Redistribution and use in source and binary forms, with or without > * modification, are permitted provided that the following conditions > * are met: > * 1. Redistributions of source code must retain the above copyright > * notice, this list of conditions and the following disclaimer. > * 2. Redistributions in binary form must reproduce the above copyright > * notice, this list of conditions and the following disclaimer in the > * documentation and/or other materials provided with the distribution. > * 3. All advertising materials mentioning features or use of this software > * must display the following acknowledgement: > * This product includes software developed by the University of > * California, Berkeley and its contributors. > * 4. Neither the name of the University nor the names of its contributors > * may be used to endorse or promote products derived from this software > * without specific prior written permission. > * > * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND > * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE > * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE > * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE > * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL > * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS > * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) > * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT > * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY > * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF > * SUCH DAMAGE. > * > * From: @(#)ansi.h 8.2 (Berkeley) 1/4/94 > * From: @(#)types.h 8.3 (Berkeley) 1/5/94 > * $FreeBSD: head/sys/arm/include/_types.h 313194 2017-02-04 12:26:38Z kib $ > */ > >#ifndef _MACHINE__TYPES_H_ >#define _MACHINE__TYPES_H_ > >#ifndef _SYS_CDEFS_H_ >#error this file needs sys/cdefs.h as a prerequisite >#endif ># 45 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/machine/_types.h" 3 4 > >/* > * Basic types upon which most other types are built. > */ >typedef signed char __int8_t; >typedef unsigned char __uint8_t; >typedef short __int16_t; >typedef unsigned short __uint16_t; >typedef int __int32_t; >typedef unsigned int __uint32_t; >#ifndef lint >__extension__ >#endif ># 58 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/machine/_types.h" 3 4 >/* LONGLONG */ >typedef long long __int64_t; >#ifndef lint >__extension__ >#endif ># 63 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/machine/_types.h" 3 4 >/* LONGLONG */ >typedef unsigned long long __uint64_t; > >/* > * Standard type definitions. > */ >typedef __uint32_t __clock_t; /* clock()... */ >typedef __int32_t __critical_t; >typedef double __double_t; >typedef float __float_t; >typedef __int32_t __intfptr_t; >typedef __int64_t __intmax_t; >typedef __int32_t __intptr_t; >typedef __int32_t __int_fast8_t; >typedef __int32_t __int_fast16_t; >typedef __int32_t __int_fast32_t; >typedef __int64_t __int_fast64_t; >typedef __int8_t __int_least8_t; >typedef __int16_t __int_least16_t; >typedef __int32_t __int_least32_t; >typedef __int64_t __int_least64_t; >typedef __int32_t __ptrdiff_t; /* ptr1 - ptr2 */ >typedef __int32_t __register_t; >typedef __int32_t __segsz_t; /* segment size (in pages) */ >typedef __uint32_t __size_t; /* sizeof() */ >typedef __int32_t __ssize_t; /* byte count or error */ >typedef __int64_t __time_t; /* time()... */ >typedef __uint32_t __uintfptr_t; >typedef __uint64_t __uintmax_t; >typedef __uint32_t __uintptr_t; >typedef __uint32_t __uint_fast8_t; >typedef __uint32_t __uint_fast16_t; >typedef __uint32_t __uint_fast32_t; >typedef __uint64_t __uint_fast64_t; >typedef __uint8_t __uint_least8_t; >typedef __uint16_t __uint_least16_t; >typedef __uint32_t __uint_least32_t; >typedef __uint64_t __uint_least64_t; >typedef __uint32_t __u_register_t; >typedef __uint32_t __vm_offset_t; >typedef __uint32_t __vm_paddr_t; >typedef __uint32_t __vm_size_t; > >typedef unsigned int ___wchar_t; >#define __WCHAR_MIN 0 /* min value for a wchar_t */ >#define __WCHAR_MAX __UINT_MAX /* max value for a wchar_t */ > >/* > * Unusual type definitions. > */ >#ifdef __GNUCLIKE_BUILTIN_VARARGS >typedef __builtin_va_list __va_list; /* internally known to gcc */ >#else ># 116 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/machine/_types.h" 3 4 >typedef char * __va_list; >#endif /* __GNUCLIKE_BUILTIN_VARARGS */ ># 118 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/machine/_types.h" 3 4 >#if defined(__GNUCLIKE_BUILTIN_VAALIST) && !defined(__GNUC_VA_LIST) \ > && !defined(__NO_GNUC_VA_LIST) >#define __GNUC_VA_LIST >typedef __va_list __gnuc_va_list; /* compatibility w/GNU headers*/ >#endif ># 123 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/machine/_types.h" 3 4 > >#endif /* !_MACHINE__TYPES_H_ */ ># 125 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/machine/_types.h" 3 4 ># 34 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/_types.h" 2 3 4 > >/* > * Standard type definitions. > */ >typedef __int32_t __blksize_t; /* file block size */ >typedef __int64_t __blkcnt_t; /* file block count */ >typedef __int32_t __clockid_t; /* clock_gettime()... */ >typedef __uint32_t __fflags_t; /* file flags */ >typedef __uint64_t __fsblkcnt_t; >typedef __uint64_t __fsfilcnt_t; >typedef __uint32_t __gid_t; >typedef __int64_t __id_t; /* can hold a gid_t, pid_t, or uid_t */ >typedef __uint64_t __ino_t; /* inode number */ >typedef long __key_t; /* IPC key (for Sys V IPC) */ >typedef __int32_t __lwpid_t; /* Thread ID (a.k.a. LWP) */ >typedef __uint16_t __mode_t; /* permissions */ >typedef int __accmode_t; /* access permissions */ >typedef int __nl_item; >typedef __uint64_t __nlink_t; /* link count */ >typedef __int64_t __off_t; /* file offset */ >typedef __int64_t __off64_t; /* file offset (alias) */ >typedef __int32_t __pid_t; /* process [group] */ >typedef __int64_t __rlim_t; /* resource limit - intentionally */ > /* signed, because of legacy code */ > /* that uses -1 for RLIM_INFINITY */ >typedef __uint8_t __sa_family_t; >typedef __uint32_t __socklen_t; >typedef long __suseconds_t; /* microseconds (signed) */ >typedef struct __timer *__timer_t; /* timer_gettime()... */ >typedef struct __mq *__mqd_t; /* mq_open()... */ >typedef __uint32_t __uid_t; >typedef unsigned int __useconds_t; /* microseconds (unsigned) */ >typedef int __cpuwhich_t; /* which parameter for cpuset. */ >typedef int __cpulevel_t; /* level parameter for cpuset. */ >typedef int __cpusetid_t; /* cpuset identifier. */ > >/* > * Unusual type definitions. > */ >/* > * rune_t is declared to be an ``int'' instead of the more natural > * ``unsigned long'' or ``long''. Two things are happening here. It is not > * unsigned so that EOF (-1) can be naturally assigned to it and used. Also, > * it looks like 10646 will be a 31 bit standard. This means that if your > * ints cannot hold 32 bits, you will be in trouble. The reason an int was > * chosen over a long is that the is*() and to*() routines take ints (says > * ANSI C), but they use __ct_rune_t instead of int. > * > * NOTE: rune_t is not covered by ANSI nor other standards, and should not > * be instantiated outside of lib/libc/locale. Use wchar_t. wint_t and > * rune_t must be the same type. Also, wint_t should be able to hold all > * members of the largest character set plus one extra value (WEOF), and > * must be at least 16 bits. > */ >typedef int __ct_rune_t; /* arg type for ctype funcs */ >typedef __ct_rune_t __rune_t; /* rune_t (see above) */ >typedef __ct_rune_t __wint_t; /* wint_t (see above) */ > >/* Clang already provides these types as built-ins, but only in C++ mode. */ >#if !defined(__clang__) || !defined(__cplusplus) >typedef __uint_least16_t __char16_t; >typedef __uint_least32_t __char32_t; >#endif ># 97 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/_types.h" 3 4 >/* In C++11, char16_t and char32_t are built-in types. */ >#if defined(__cplusplus) && __cplusplus >= 201103L >#define _CHAR16_T_DECLARED >#define _CHAR32_T_DECLARED >#endif ># 102 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/_types.h" 3 4 > >typedef struct { > long long __max_align1 __aligned(_Alignof(long long)); > long double __max_align2 __aligned(_Alignof(long double)); >} __max_align_t; > >typedef __uint64_t __dev_t; /* device number */ > >typedef __uint32_t __fixpt_t; /* fixed point number */ > >/* > * mbstate_t is an opaque object to keep conversion state during multibyte > * stream conversions. > */ >typedef union { > char __mbstate8[128]; > __int64_t _mbstateL; /* for alignment */ >} __mbstate_t; > >typedef __uintmax_t __rman_res_t; > >/* > * When the following macro is defined, the system uses 64-bit inode numbers. > * Programs can use this to avoid including <sys/param.h>, with its associated > * namespace pollution. > */ >#define __INO64 > >#endif /* !_SYS__TYPES_H_ */ ># 131 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/_types.h" 3 4 ># 39 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/string.h" 2 3 4 > >/* > * Prototype functions which were historically defined in <string.h>, but > * are required by POSIX to be prototyped in <strings.h>. > */ >#if __BSD_VISIBLE >#if 0 /* expanded by -frewrite-includes */ >#include <strings.h> >#endif /* expanded by -frewrite-includes */ ># 45 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/string.h" 3 4 ># 1 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/strings.h" 1 3 4 >/*- > * Copyright (c) 2002 Mike Barcroft <mike@FreeBSD.org> > * All rights reserved. > * > * Redistribution and use in source and binary forms, with or without > * modification, are permitted provided that the following conditions > * are met: > * 1. Redistributions of source code must retain the above copyright > * notice, this list of conditions and the following disclaimer. > * 2. Redistributions in binary form must reproduce the above copyright > * notice, this list of conditions and the following disclaimer in the > * documentation and/or other materials provided with the distribution. > * > * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND > * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE > * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE > * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE > * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL > * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS > * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) > * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT > * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY > * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF > * SUCH DAMAGE. > * > * $FreeBSD: head/include/strings.h 272673 2014-10-07 04:54:11Z delphij $ > */ > >#ifndef _STRINGS_H_ >#define _STRINGS_H_ > >#if 0 /* expanded by -frewrite-includes */ >#include <sys/cdefs.h> >#endif /* expanded by -frewrite-includes */ ># 32 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/strings.h" 3 4 ># 33 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/strings.h" 3 4 >#if 0 /* expanded by -frewrite-includes */ >#include <sys/_types.h> >#endif /* expanded by -frewrite-includes */ ># 33 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/strings.h" 3 4 ># 34 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/strings.h" 3 4 > >#ifndef _SIZE_T_DECLARED >typedef __size_t size_t; >#define _SIZE_T_DECLARED >#endif ># 39 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/strings.h" 3 4 > >__BEGIN_DECLS >#if __BSD_VISIBLE || __POSIX_VISIBLE <= 200112 >int bcmp(const void *, const void *, size_t) __pure; /* LEGACY */ >void bcopy(const void *, void *, size_t); /* LEGACY */ >void bzero(void *, size_t); /* LEGACY */ >#endif ># 46 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/strings.h" 3 4 >#if __BSD_VISIBLE >void explicit_bzero(void *, size_t); >#endif ># 49 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/strings.h" 3 4 >#if __XSI_VISIBLE >int ffs(int) __pure2; >#endif ># 52 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/strings.h" 3 4 >#if __BSD_VISIBLE >int ffsl(long) __pure2; >int ffsll(long long) __pure2; >int fls(int) __pure2; >int flsl(long) __pure2; >int flsll(long long) __pure2; >#endif ># 59 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/strings.h" 3 4 >#if __BSD_VISIBLE || __POSIX_VISIBLE <= 200112 >char *index(const char *, int) __pure; /* LEGACY */ >char *rindex(const char *, int) __pure; /* LEGACY */ >#endif ># 63 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/strings.h" 3 4 >int strcasecmp(const char *, const char *) __pure; >int strncasecmp(const char *, const char *, size_t) __pure; > >#if __POSIX_VISIBLE >= 200809 || defined(_XLOCALE_H_) >#if 0 /* expanded by -frewrite-includes */ >#include <xlocale/_strings.h> >#endif /* expanded by -frewrite-includes */ ># 67 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/strings.h" 3 4 ># 1 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/xlocale/_strings.h" 1 3 4 >/*- > * Copyright (c) 2011, 2012 The FreeBSD Foundation > * All rights reserved. > * > * Redistribution and use in source and binary forms, with or without > * modification, are permitted provided that the following conditions > * are met: > * 1. Redistributions of source code must retain the above copyright > * notice, this list of conditions and the following disclaimer. > * 2. Redistributions in binary form must reproduce the above copyright > * notice, this list of conditions and the following disclaimer in the > * documentation and/or other materials provided with the distribution. > * > * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND > * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE > * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE > * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE > * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL > * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS > * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) > * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT > * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY > * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF > * SUCH DAMAGE. > * > * $FreeBSD: head/include/xlocale/_strings.h 266865 2014-05-30 01:09:07Z pfg $ > */ > >#ifndef _LOCALE_T_DEFINED >#define _LOCALE_T_DEFINED >typedef struct _xlocale *locale_t; >#endif ># 33 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/xlocale/_strings.h" 3 4 > >/* > * This file is included from both strings.h and xlocale.h. We need to expose > * the declarations unconditionally if we are included from xlocale.h, but only > * if we are in POSIX2008 mode if included from string.h. > */ > >#ifndef _XLOCALE_STRINGS1_H >#define _XLOCALE_STRINGS1_H > >/* > * POSIX2008 functions > */ >int strcasecmp_l(const char *, const char *, locale_t); >int strncasecmp_l(const char *, const char *, size_t, locale_t); >#endif /* _XLOCALE_STRINGS1_H */ ># 49 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/xlocale/_strings.h" 3 4 ># 68 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/strings.h" 2 3 4 >#endif ># 69 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/strings.h" 3 4 >__END_DECLS > >#endif /* _STRINGS_H_ */ ># 72 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/strings.h" 3 4 ># 46 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/string.h" 2 3 4 >#endif ># 47 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/string.h" 3 4 > >#ifndef _SIZE_T_DECLARED >typedef __size_t size_t; >#define _SIZE_T_DECLARED >#endif ># 52 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/string.h" 3 4 > >__BEGIN_DECLS >#if __XSI_VISIBLE >= 600 >void *memccpy(void * __restrict, const void * __restrict, int, size_t); >#endif ># 57 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/string.h" 3 4 >void *memchr(const void *, int, size_t) __pure; >#if __BSD_VISIBLE >void *memrchr(const void *, int, size_t) __pure; >#endif ># 61 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/string.h" 3 4 >int memcmp(const void *, const void *, size_t) __pure; >void *memcpy(void * __restrict, const void * __restrict, size_t); >#if __BSD_VISIBLE >void *memmem(const void *, size_t, const void *, size_t) __pure; >#endif ># 66 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/string.h" 3 4 >void *memmove(void *, const void *, size_t); >void *memset(void *, int, size_t); >#if __POSIX_VISIBLE >= 200809 >char *stpcpy(char * __restrict, const char * __restrict); >char *stpncpy(char * __restrict, const char * __restrict, size_t); >#endif ># 72 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/string.h" 3 4 >#if __BSD_VISIBLE >char *strcasestr(const char *, const char *) __pure; >#endif ># 75 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/string.h" 3 4 >char *strcat(char * __restrict, const char * __restrict); >char *strchr(const char *, int) __pure; >#if __BSD_VISIBLE >char *strchrnul(const char*, int) __pure; >#endif ># 80 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/string.h" 3 4 >int strcmp(const char *, const char *) __pure; >int strcoll(const char *, const char *); >char *strcpy(char * __restrict, const char * __restrict); >size_t strcspn(const char *, const char *) __pure; >#if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE >char *strdup(const char *) __malloc_like; >#endif ># 87 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/string.h" 3 4 >char *strerror(int); >#if __POSIX_VISIBLE >= 200112 >int strerror_r(int, char *, size_t); >#endif ># 91 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/string.h" 3 4 >#if __BSD_VISIBLE >size_t strlcat(char * __restrict, const char * __restrict, size_t); >size_t strlcpy(char * __restrict, const char * __restrict, size_t); >#endif ># 95 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/string.h" 3 4 >size_t strlen(const char *) __pure; >#if __BSD_VISIBLE >void strmode(int, char *); >#endif ># 99 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/string.h" 3 4 >char *strncat(char * __restrict, const char * __restrict, size_t); >int strncmp(const char *, const char *, size_t) __pure; >char *strncpy(char * __restrict, const char * __restrict, size_t); >#if __POSIX_VISIBLE >= 200809 >char *strndup(const char *, size_t) __malloc_like; >size_t strnlen(const char *, size_t) __pure; >#endif ># 106 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/string.h" 3 4 >#if __BSD_VISIBLE >char *strnstr(const char *, const char *, size_t) __pure; >#endif ># 109 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/string.h" 3 4 >char *strpbrk(const char *, const char *) __pure; >char *strrchr(const char *, int) __pure; >#if __BSD_VISIBLE >char *strsep(char **, const char *); >#endif ># 114 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/string.h" 3 4 >#if __POSIX_VISIBLE >= 200809 >char *strsignal(int); >#endif ># 117 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/string.h" 3 4 >size_t strspn(const char *, const char *) __pure; >char *strstr(const char *, const char *) __pure; >char *strtok(char * __restrict, const char * __restrict); >#if __POSIX_VISIBLE >= 199506 || __XSI_VISIBLE >= 500 >char *strtok_r(char *, const char *, char **); >#endif ># 123 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/string.h" 3 4 >size_t strxfrm(char * __restrict, const char * __restrict, size_t); >#if __BSD_VISIBLE > >#ifndef _SWAB_DECLARED >#define _SWAB_DECLARED > >#ifndef _SSIZE_T_DECLARED >typedef __ssize_t ssize_t; >#define _SSIZE_T_DECLARED >#endif /* _SIZE_T_DECLARED */ ># 133 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/string.h" 3 4 > >void swab(const void * __restrict, void * __restrict, ssize_t); >#endif /* _SWAB_DECLARED */ ># 136 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/string.h" 3 4 > >int timingsafe_bcmp(const void *, const void *, size_t); >int timingsafe_memcmp(const void *, const void *, size_t); >#endif /* __BSD_VISIBLE */ ># 140 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/string.h" 3 4 > >#if __POSIX_VISIBLE >= 200809 || defined(_XLOCALE_H_) >#if 0 /* expanded by -frewrite-includes */ >#include <xlocale/_string.h> >#endif /* expanded by -frewrite-includes */ ># 142 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/string.h" 3 4 ># 1 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/xlocale/_string.h" 1 3 4 >/*- > * Copyright (c) 2011, 2012 The FreeBSD Foundation > * All rights reserved. > * > * Redistribution and use in source and binary forms, with or without > * modification, are permitted provided that the following conditions > * are met: > * 1. Redistributions of source code must retain the above copyright > * notice, this list of conditions and the following disclaimer. > * 2. Redistributions in binary form must reproduce the above copyright > * notice, this list of conditions and the following disclaimer in the > * documentation and/or other materials provided with the distribution. > * > * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND > * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE > * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE > * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE > * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL > * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS > * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) > * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT > * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY > * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF > * SUCH DAMAGE. > * > * $FreeBSD: head/include/xlocale/_string.h 266865 2014-05-30 01:09:07Z pfg $ > */ > >#ifndef _LOCALE_T_DEFINED >#define _LOCALE_T_DEFINED >typedef struct _xlocale *locale_t; >#endif ># 33 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/xlocale/_string.h" 3 4 > >/* > * This file is included from both string.h and xlocale.h. We need to expose > * the declarations unconditionally if we are included from xlocale.h, but only > * if we are in POSIX2008 mode if included from string.h. > */ > >#ifndef _XLOCALE_STRING1_H >#define _XLOCALE_STRING1_H > >/* > * POSIX2008 functions > */ >int strcoll_l(const char *, const char *, locale_t); >size_t strxfrm_l(char *, const char *, size_t, locale_t); >#endif /* _XLOCALE_STRING1_H */ ># 49 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/xlocale/_string.h" 3 4 > >/* > * xlocale extensions > */ >#ifdef _XLOCALE_H_ >#ifndef _XLOCALE_STRING2_H >#define _XLOCALE_STRING2_H >char *strcasestr_l(const char *, const char *, locale_t); > >#endif /* _XLOCALE_STRING2_H */ ># 59 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/xlocale/_string.h" 3 4 >#endif /* _XLOCALE_H_ */ ># 60 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/xlocale/_string.h" 3 4 ># 143 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/string.h" 2 3 4 >#endif ># 144 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/string.h" 3 4 > >#if __EXT1_VISIBLE > >#ifndef _RSIZE_T_DEFINED >#define _RSIZE_T_DEFINED >typedef size_t rsize_t; >#endif ># 151 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/string.h" 3 4 > >#ifndef _ERRNO_T_DEFINED >#define _ERRNO_T_DEFINED >typedef int errno_t; >#endif ># 156 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/string.h" 3 4 > >/* ISO/IEC 9899:2011 K.3.7.4.1.1 */ >errno_t memset_s(void *, rsize_t, int, rsize_t); >#endif /* __EXT1_VISIBLE */ ># 160 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/string.h" 3 4 >__END_DECLS > >#endif /* _STRING_H_ */ ># 163 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/string.h" 3 4 ># 24 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.c" 2 >#if 0 /* expanded by -frewrite-includes */ >#include "mem.h" >#endif /* expanded by -frewrite-includes */ ># 24 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.c" ># 1 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/mem.h" 1 >/* > * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. > * All rights reserved. > * > * This source code is licensed under both the BSD-style license (found in the > * LICENSE file in the root directory of this source tree) and the GPLv2 (found > * in the COPYING file in the root directory of this source tree). > * You may select, at your option, one of the above-listed licenses. > */ > >#ifndef MEM_H_MODULE >#define MEM_H_MODULE > >#if defined (__cplusplus) >extern "C" { >#endif ># 17 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/mem.h" > >/*-**************************************** >* Dependencies >******************************************/ >#if 0 /* expanded by -frewrite-includes */ >#include <stddef.h> /* size_t, ptrdiff_t */ >#endif /* expanded by -frewrite-includes */ ># 21 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/mem.h" ># 1 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/stddef.h" 1 3 4 >/*- > * Copyright (c) 1990, 1993 > * The Regents of the University of California. All rights reserved. > * > * Redistribution and use in source and binary forms, with or without > * modification, are permitted provided that the following conditions > * are met: > * 1. Redistributions of source code must retain the above copyright > * notice, this list of conditions and the following disclaimer. > * 2. Redistributions in binary form must reproduce the above copyright > * notice, this list of conditions and the following disclaimer in the > * documentation and/or other materials provided with the distribution. > * 3. Neither the name of the University nor the names of its contributors > * may be used to endorse or promote products derived from this software > * without specific prior written permission. > * > * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND > * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE > * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE > * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE > * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL > * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS > * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) > * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT > * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY > * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF > * SUCH DAMAGE. > * > * @(#)stddef.h 8.1 (Berkeley) 6/2/93 > * > * $FreeBSD: head/include/stddef.h 324622 2017-10-15 02:40:13Z cy $ > */ > >#ifndef _STDDEF_H_ >#define _STDDEF_H_ > >#if 0 /* expanded by -frewrite-includes */ >#include <sys/cdefs.h> >#endif /* expanded by -frewrite-includes */ ># 37 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/stddef.h" 3 4 ># 38 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/stddef.h" 3 4 >#if 0 /* expanded by -frewrite-includes */ >#include <sys/_null.h> >#endif /* expanded by -frewrite-includes */ ># 38 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/stddef.h" 3 4 ># 39 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/stddef.h" 3 4 >#if 0 /* expanded by -frewrite-includes */ >#include <sys/_types.h> >#endif /* expanded by -frewrite-includes */ ># 39 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/stddef.h" 3 4 ># 40 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/stddef.h" 3 4 > >#ifndef _PTRDIFF_T_DECLARED >typedef __ptrdiff_t ptrdiff_t; >#define _PTRDIFF_T_DECLARED >#endif ># 45 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/stddef.h" 3 4 > >#if __BSD_VISIBLE >#ifndef _RUNE_T_DECLARED >typedef __rune_t rune_t; >#define _RUNE_T_DECLARED >#endif ># 51 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/stddef.h" 3 4 >#endif ># 52 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/stddef.h" 3 4 > >#ifndef _SIZE_T_DECLARED >typedef __size_t size_t; >#define _SIZE_T_DECLARED >#endif ># 57 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/stddef.h" 3 4 > >#ifndef __cplusplus >#ifndef _WCHAR_T_DECLARED >typedef ___wchar_t wchar_t; >#define _WCHAR_T_DECLARED >#endif ># 63 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/stddef.h" 3 4 >#endif ># 64 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/stddef.h" 3 4 > >#if __ISO_C_VISIBLE >= 2011 || __cplusplus >= 201103L >#ifndef __CLANG_MAX_ALIGN_T_DEFINED >typedef __max_align_t max_align_t; >#define __CLANG_MAX_ALIGN_T_DEFINED >#define _GCC_MAX_ALIGN_T >#endif ># 71 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/stddef.h" 3 4 >#endif ># 72 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/stddef.h" 3 4 > >#define offsetof(type, field) __offsetof(type, field) > >#if __EXT1_VISIBLE >/* ISO/IEC 9899:2011 K.3.3.2 */ >#ifndef _RSIZE_T_DEFINED >#define _RSIZE_T_DEFINED >typedef size_t rsize_t; >#endif ># 81 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/stddef.h" 3 4 >#endif /* __EXT1_VISIBLE */ ># 82 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/stddef.h" 3 4 > >#endif /* _STDDEF_H_ */ ># 84 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/stddef.h" 3 4 ># 22 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/mem.h" 2 >#if 0 /* expanded by -frewrite-includes */ >#include <string.h> /* memcpy */ >#endif /* expanded by -frewrite-includes */ ># 22 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/mem.h" ># 23 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/mem.h" > > >/*-**************************************** >* Compiler specifics >******************************************/ >#if defined(_MSC_VER) /* Visual Studio */ >#if 0 /* expanded by -frewrite-includes */ ># include <stdlib.h> /* _byteswap_ulong */ >#endif /* expanded by -frewrite-includes */ ># 29 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/mem.h" ># 30 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/mem.h" >#if 0 /* expanded by -frewrite-includes */ ># include <intrin.h> /* _byteswap_* */ >#endif /* expanded by -frewrite-includes */ ># 30 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/mem.h" ># 31 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/mem.h" >#endif ># 32 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/mem.h" >#if defined(__GNUC__) ># define MEM_STATIC static __inline __attribute__((unused)) >#elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) ># 35 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/mem.h" ># define MEM_STATIC static inline >#elif defined(_MSC_VER) ># 37 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/mem.h" ># define MEM_STATIC static __inline >#else ># 39 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/mem.h" ># define MEM_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */ >#endif ># 41 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/mem.h" > >/* code only tested on 32 and 64 bits systems */ >#define MEM_STATIC_ASSERT(c) { enum { MEM_static_assert = 1/(int)(!!(c)) }; } >MEM_STATIC void MEM_check(void) { MEM_STATIC_ASSERT((sizeof(size_t)==4) || (sizeof(size_t)==8)); } > > >/*-************************************************************** >* Basic Types >*****************************************************************/ >#if !defined (__VMS) && (defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) ) >#if 0 /* expanded by -frewrite-includes */ ># include <stdint.h> >#endif /* expanded by -frewrite-includes */ ># 51 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/mem.h" ># 1 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/stdint.h" 1 3 4 >/*- > * Copyright (c) 2001 Mike Barcroft <mike@FreeBSD.org> > * All rights reserved. > * > * Redistribution and use in source and binary forms, with or without > * modification, are permitted provided that the following conditions > * are met: > * 1. Redistributions of source code must retain the above copyright > * notice, this list of conditions and the following disclaimer. > * 2. Redistributions in binary form must reproduce the above copyright > * notice, this list of conditions and the following disclaimer in the > * documentation and/or other materials provided with the distribution. > * > * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND > * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE > * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE > * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE > * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL > * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS > * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) > * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT > * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY > * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF > * SUCH DAMAGE. > * > * $FreeBSD: head/sys/sys/stdint.h 316213 2017-03-30 04:57:26Z kib $ > */ > >#ifndef _SYS_STDINT_H_ >#define _SYS_STDINT_H_ > >#if 0 /* expanded by -frewrite-includes */ >#include <sys/cdefs.h> >#endif /* expanded by -frewrite-includes */ ># 32 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/stdint.h" 3 4 ># 33 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/stdint.h" 3 4 >#if 0 /* expanded by -frewrite-includes */ >#include <sys/_types.h> >#endif /* expanded by -frewrite-includes */ ># 33 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/stdint.h" 3 4 ># 34 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/stdint.h" 3 4 > >#if 0 /* expanded by -frewrite-includes */ >#include <machine/_stdint.h> >#endif /* expanded by -frewrite-includes */ ># 35 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/stdint.h" 3 4 ># 1 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/machine/_stdint.h" 1 3 4 >/*- > * Copyright (c) 2001, 2002 Mike Barcroft <mike@FreeBSD.org> > * Copyright (c) 2001 The NetBSD Foundation, Inc. > * All rights reserved. > * > * This code is derived from software contributed to The NetBSD Foundation > * by Klaus Klein. > * > * Redistribution and use in source and binary forms, with or without > * modification, are permitted provided that the following conditions > * are met: > * 1. Redistributions of source code must retain the above copyright > * notice, this list of conditions and the following disclaimer. > * 2. Redistributions in binary form must reproduce the above copyright > * notice, this list of conditions and the following disclaimer in the > * documentation and/or other materials provided with the distribution. > * > * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS > * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED > * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR > * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS > * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR > * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF > * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS > * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN > * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) > * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE > * POSSIBILITY OF SUCH DAMAGE. > * > * $FreeBSD: head/sys/arm/include/_stdint.h 290648 2015-11-10 12:02:41Z mmel $ > */ > >#ifndef _MACHINE__STDINT_H_ >#define _MACHINE__STDINT_H_ > >#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) > >#define INT8_C(c) (c) >#define INT16_C(c) (c) >#define INT32_C(c) (c) >#define INT64_C(c) (c ## LL) > >#define UINT8_C(c) (c) >#define UINT16_C(c) (c) >#define UINT32_C(c) (c ## U) >#define UINT64_C(c) (c ## ULL) > >#define INTMAX_C(c) INT64_C(c) >#define UINTMAX_C(c) UINT64_C(c) > >#endif /* !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) */ ># 52 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/machine/_stdint.h" 3 4 > >#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) > >/* > * ISO/IEC 9899:1999 > * 7.18.2.1 Limits of exact-width integer types > */ >/* Minimum values of exact-width signed integer types. */ >#define INT8_MIN (-0x7f-1) >#define INT16_MIN (-0x7fff-1) >#define INT32_MIN (-0x7fffffff-1) >#define INT64_MIN (-0x7fffffffffffffffLL-1) > >/* Maximum values of exact-width signed integer types. */ >#define INT8_MAX 0x7f >#define INT16_MAX 0x7fff >#define INT32_MAX 0x7fffffff >#define INT64_MAX 0x7fffffffffffffffLL > >/* Maximum values of exact-width unsigned integer types. */ >#define UINT8_MAX 0xff >#define UINT16_MAX 0xffff >#define UINT32_MAX 0xffffffffU >#define UINT64_MAX 0xffffffffffffffffULL > >/* > * ISO/IEC 9899:1999 > * 7.18.2.2 Limits of minimum-width integer types > */ >/* Minimum values of minimum-width signed integer types. */ >#define INT_LEAST8_MIN INT8_MIN >#define INT_LEAST16_MIN INT16_MIN >#define INT_LEAST32_MIN INT32_MIN >#define INT_LEAST64_MIN INT64_MIN > >/* Maximum values of minimum-width signed integer types. */ >#define INT_LEAST8_MAX INT8_MAX >#define INT_LEAST16_MAX INT16_MAX >#define INT_LEAST32_MAX INT32_MAX >#define INT_LEAST64_MAX INT64_MAX > >/* Maximum values of minimum-width unsigned integer types. */ >#define UINT_LEAST8_MAX UINT8_MAX >#define UINT_LEAST16_MAX UINT16_MAX >#define UINT_LEAST32_MAX UINT32_MAX >#define UINT_LEAST64_MAX UINT64_MAX > >/* > * ISO/IEC 9899:1999 > * 7.18.2.3 Limits of fastest minimum-width integer types > */ >/* Minimum values of fastest minimum-width signed integer types. */ >#define INT_FAST8_MIN INT32_MIN >#define INT_FAST16_MIN INT32_MIN >#define INT_FAST32_MIN INT32_MIN >#define INT_FAST64_MIN INT64_MIN > >/* Maximum values of fastest minimum-width signed integer types. */ >#define INT_FAST8_MAX INT32_MAX >#define INT_FAST16_MAX INT32_MAX >#define INT_FAST32_MAX INT32_MAX >#define INT_FAST64_MAX INT64_MAX > >/* Maximum values of fastest minimum-width unsigned integer types. */ >#define UINT_FAST8_MAX UINT32_MAX >#define UINT_FAST16_MAX UINT32_MAX >#define UINT_FAST32_MAX UINT32_MAX >#define UINT_FAST64_MAX UINT64_MAX > >/* > * ISO/IEC 9899:1999 > * 7.18.2.4 Limits of integer types capable of holding object pointers > */ >#define INTPTR_MIN INT32_MIN >#define INTPTR_MAX INT32_MAX >#define UINTPTR_MAX UINT32_MAX > >/* > * ISO/IEC 9899:1999 > * 7.18.2.5 Limits of greatest-width integer types > */ >#define INTMAX_MIN INT64_MIN >#define INTMAX_MAX INT64_MAX >#define UINTMAX_MAX UINT64_MAX > >/* > * ISO/IEC 9899:1999 > * 7.18.3 Limits of other integer types > */ >/* Limits of ptrdiff_t. */ >#define PTRDIFF_MIN INT32_MIN >#define PTRDIFF_MAX INT32_MAX > >/* Limits of sig_atomic_t. */ >#define SIG_ATOMIC_MIN INT32_MIN >#define SIG_ATOMIC_MAX INT32_MAX > >/* Limit of size_t. */ >#define SIZE_MAX UINT32_MAX > >/* Limits of wint_t. */ >#define WINT_MIN INT32_MIN >#define WINT_MAX INT32_MAX > >#endif /* !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) */ ># 157 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/machine/_stdint.h" 3 4 > >#endif /* !_MACHINE__STDINT_H_ */ ># 159 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/machine/_stdint.h" 3 4 ># 36 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/stdint.h" 2 3 4 >#if 0 /* expanded by -frewrite-includes */ >#include <sys/_stdint.h> >#endif /* expanded by -frewrite-includes */ ># 36 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/stdint.h" 3 4 ># 1 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/_stdint.h" 1 3 4 >/*- > * Copyright (c) 2011 David E. O'Brien <obrien@FreeBSD.org> > * Copyright (c) 2001 Mike Barcroft <mike@FreeBSD.org> > * All rights reserved. > * > * Redistribution and use in source and binary forms, with or without > * modification, are permitted provided that the following conditions > * are met: > * 1. Redistributions of source code must retain the above copyright > * notice, this list of conditions and the following disclaimer. > * 2. Redistributions in binary form must reproduce the above copyright > * notice, this list of conditions and the following disclaimer in the > * documentation and/or other materials provided with the distribution. > * > * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND > * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE > * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE > * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE > * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL > * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS > * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) > * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT > * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY > * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF > * SUCH DAMAGE. > * > * $FreeBSD: head/sys/sys/_stdint.h 290492 2015-11-07 12:30:43Z kib $ > */ > >#ifndef _SYS__STDINT_H_ >#define _SYS__STDINT_H_ > >#ifndef _INT8_T_DECLARED >typedef __int8_t int8_t; >#define _INT8_T_DECLARED >#endif ># 37 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/_stdint.h" 3 4 > >#ifndef _INT16_T_DECLARED >typedef __int16_t int16_t; >#define _INT16_T_DECLARED >#endif ># 42 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/_stdint.h" 3 4 > >#ifndef _INT32_T_DECLARED >typedef __int32_t int32_t; >#define _INT32_T_DECLARED >#endif ># 47 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/_stdint.h" 3 4 > >#ifndef _INT64_T_DECLARED >typedef __int64_t int64_t; >#define _INT64_T_DECLARED >#endif ># 52 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/_stdint.h" 3 4 > >#ifndef _UINT8_T_DECLARED >typedef __uint8_t uint8_t; >#define _UINT8_T_DECLARED >#endif ># 57 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/_stdint.h" 3 4 > >#ifndef _UINT16_T_DECLARED >typedef __uint16_t uint16_t; >#define _UINT16_T_DECLARED >#endif ># 62 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/_stdint.h" 3 4 > >#ifndef _UINT32_T_DECLARED >typedef __uint32_t uint32_t; >#define _UINT32_T_DECLARED >#endif ># 67 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/_stdint.h" 3 4 > >#ifndef _UINT64_T_DECLARED >typedef __uint64_t uint64_t; >#define _UINT64_T_DECLARED >#endif ># 72 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/_stdint.h" 3 4 > >#ifndef _INTPTR_T_DECLARED >typedef __intptr_t intptr_t; >#define _INTPTR_T_DECLARED >#endif ># 77 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/_stdint.h" 3 4 >#ifndef _UINTPTR_T_DECLARED >typedef __uintptr_t uintptr_t; >#define _UINTPTR_T_DECLARED >#endif ># 81 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/_stdint.h" 3 4 >#ifndef _INTMAX_T_DECLARED >typedef __intmax_t intmax_t; >#define _INTMAX_T_DECLARED >#endif ># 85 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/_stdint.h" 3 4 >#ifndef _UINTMAX_T_DECLARED >typedef __uintmax_t uintmax_t; >#define _UINTMAX_T_DECLARED >#endif ># 89 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/_stdint.h" 3 4 > >#endif /* !_SYS__STDINT_H_ */ ># 91 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/sys/_stdint.h" 3 4 ># 37 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/stdint.h" 2 3 4 > >typedef __int_least8_t int_least8_t; >typedef __int_least16_t int_least16_t; >typedef __int_least32_t int_least32_t; >typedef __int_least64_t int_least64_t; > >typedef __uint_least8_t uint_least8_t; >typedef __uint_least16_t uint_least16_t; >typedef __uint_least32_t uint_least32_t; >typedef __uint_least64_t uint_least64_t; > >typedef __int_fast8_t int_fast8_t; >typedef __int_fast16_t int_fast16_t; >typedef __int_fast32_t int_fast32_t; >typedef __int_fast64_t int_fast64_t; > >typedef __uint_fast8_t uint_fast8_t; >typedef __uint_fast16_t uint_fast16_t; >typedef __uint_fast32_t uint_fast32_t; >typedef __uint_fast64_t uint_fast64_t; > >/* GNU and Darwin define this and people seem to think it's portable */ >#if defined(UINTPTR_MAX) && defined(UINT64_MAX) && (UINTPTR_MAX == UINT64_MAX) >#define __WORDSIZE 64 >#else ># 62 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/stdint.h" 3 4 >#define __WORDSIZE 32 >#endif ># 64 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/stdint.h" 3 4 > >/* Limits of wchar_t. */ >#define WCHAR_MIN __WCHAR_MIN >#define WCHAR_MAX __WCHAR_MAX > >#if __EXT1_VISIBLE >/* ISO/IEC 9899:2011 K.3.4.4 */ >#ifndef RSIZE_MAX >#define RSIZE_MAX (SIZE_MAX >> 1) >#endif ># 74 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/stdint.h" 3 4 >#endif /* __EXT1_VISIBLE */ ># 75 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/stdint.h" 3 4 > >#endif /* !_SYS_STDINT_H_ */ ># 77 "/build/usr/home/rpokala/freebsd/clean/base/head/arm.armv6/tmp/usr/include/stdint.h" 3 4 ># 52 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/mem.h" 2 > typedef uint8_t BYTE; > typedef uint16_t U16; > typedef int16_t S16; > typedef uint32_t U32; > typedef int32_t S32; > typedef uint64_t U64; > typedef int64_t S64; > typedef intptr_t iPtrDiff; > typedef uintptr_t uPtrDiff; >#else ># 62 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/mem.h" > typedef unsigned char BYTE; > typedef unsigned short U16; > typedef signed short S16; > typedef unsigned int U32; > typedef signed int S32; > typedef unsigned long long U64; > typedef signed long long S64; > typedef ptrdiff_t iPtrDiff; > typedef size_t uPtrDiff; >#endif ># 72 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/mem.h" > > >/*-************************************************************** >* Memory I/O >*****************************************************************/ >/* MEM_FORCE_MEMORY_ACCESS : > * By default, access to unaligned memory is controlled by `memcpy()`, which is safe and portable. > * Unfortunately, on some target/compiler combinations, the generated assembly is sub-optimal. > * The below switch allow to select different access method for improved performance. > * Method 0 (default) : use `memcpy()`. Safe and portable. > * Method 1 : `__packed` statement. It depends on compiler extension (i.e., not portable). > * This method is safe if your compiler supports it, and *generally* as fast or faster than `memcpy`. > * Method 2 : direct access. This method is portable but violate C standard. > * It can generate buggy code on targets depending on alignment. > * In some circumstances, it's the only known way to get the most performance (i.e. GCC + ARMv6) > * See http://fastcompression.blogspot.fr/2015/08/accessing-unaligned-memory.html for details. > * Prefer these methods in priority order (0 > 1 > 2) > */ >#ifndef MEM_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */ ># if defined(__GNUC__) && ( defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) ) ># define MEM_FORCE_MEMORY_ACCESS 2 ># elif defined(__INTEL_COMPILER) || defined(__GNUC__) ># 94 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/mem.h" ># define MEM_FORCE_MEMORY_ACCESS 1 ># endif ># 96 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/mem.h" >#endif ># 97 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/mem.h" > >MEM_STATIC unsigned MEM_32bits(void) { return sizeof(size_t)==4; } >MEM_STATIC unsigned MEM_64bits(void) { return sizeof(size_t)==8; } > >MEM_STATIC unsigned MEM_isLittleEndian(void) >{ > const union { U32 u; BYTE c[4]; } one = { 1 }; /* don't use static : performance detrimental */ > return one.c[0]; >} > >#if defined(MEM_FORCE_MEMORY_ACCESS) && (MEM_FORCE_MEMORY_ACCESS==2) > >/* violates C standard, by lying on structure alignment. >Only use if no other choice to achieve best performance on target platform */ >MEM_STATIC U16 MEM_read16(const void* memPtr) { return *(const U16*) memPtr; } >MEM_STATIC U32 MEM_read32(const void* memPtr) { return *(const U32*) memPtr; } >MEM_STATIC U64 MEM_read64(const void* memPtr) { return *(const U64*) memPtr; } >MEM_STATIC size_t MEM_readST(const void* memPtr) { return *(const size_t*) memPtr; } > >MEM_STATIC void MEM_write16(void* memPtr, U16 value) { *(U16*)memPtr = value; } >MEM_STATIC void MEM_write32(void* memPtr, U32 value) { *(U32*)memPtr = value; } >MEM_STATIC void MEM_write64(void* memPtr, U64 value) { *(U64*)memPtr = value; } > >#elif defined(MEM_FORCE_MEMORY_ACCESS) && (MEM_FORCE_MEMORY_ACCESS==1) ># 121 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/mem.h" > >/* __pack instructions are safer, but compiler specific, hence potentially problematic for some compilers */ >/* currently only defined for gcc and icc */ >#if defined(_MSC_VER) || (defined(__INTEL_COMPILER) && defined(WIN32)) > __pragma( pack(push, 1) ) > typedef union { U16 u16; U32 u32; U64 u64; size_t st; } unalign; > __pragma( pack(pop) ) >#else ># 129 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/mem.h" > typedef union { U16 u16; U32 u32; U64 u64; size_t st; } __attribute__((packed)) unalign; >#endif ># 131 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/mem.h" > >MEM_STATIC U16 MEM_read16(const void* ptr) { return ((const unalign*)ptr)->u16; } >MEM_STATIC U32 MEM_read32(const void* ptr) { return ((const unalign*)ptr)->u32; } >MEM_STATIC U64 MEM_read64(const void* ptr) { return ((const unalign*)ptr)->u64; } >MEM_STATIC size_t MEM_readST(const void* ptr) { return ((const unalign*)ptr)->st; } > >MEM_STATIC void MEM_write16(void* memPtr, U16 value) { ((unalign*)memPtr)->u16 = value; } >MEM_STATIC void MEM_write32(void* memPtr, U32 value) { ((unalign*)memPtr)->u32 = value; } >MEM_STATIC void MEM_write64(void* memPtr, U64 value) { ((unalign*)memPtr)->u64 = value; } > >#else ># 142 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/mem.h" > >/* default method, safe and standard. > can sometimes prove slower */ > >MEM_STATIC U16 MEM_read16(const void* memPtr) >{ > U16 val; memcpy(&val, memPtr, sizeof(val)); return val; >} > >MEM_STATIC U32 MEM_read32(const void* memPtr) >{ > U32 val; memcpy(&val, memPtr, sizeof(val)); return val; >} > >MEM_STATIC U64 MEM_read64(const void* memPtr) >{ > U64 val; memcpy(&val, memPtr, sizeof(val)); return val; >} > >MEM_STATIC size_t MEM_readST(const void* memPtr) >{ > size_t val; memcpy(&val, memPtr, sizeof(val)); return val; >} > >MEM_STATIC void MEM_write16(void* memPtr, U16 value) >{ > memcpy(memPtr, &value, sizeof(value)); >} > >MEM_STATIC void MEM_write32(void* memPtr, U32 value) >{ > memcpy(memPtr, &value, sizeof(value)); >} > >MEM_STATIC void MEM_write64(void* memPtr, U64 value) >{ > memcpy(memPtr, &value, sizeof(value)); >} > >#endif /* MEM_FORCE_MEMORY_ACCESS */ ># 182 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/mem.h" > >MEM_STATIC U32 MEM_swap32(U32 in) >{ >#if defined(_MSC_VER) /* Visual Studio */ > return _byteswap_ulong(in); >#elif defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 403) ># 188 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/mem.h" > return __builtin_bswap32(in); >#else ># 190 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/mem.h" > return ((in << 24) & 0xff000000 ) | > ((in << 8) & 0x00ff0000 ) | > ((in >> 8) & 0x0000ff00 ) | > ((in >> 24) & 0x000000ff ); >#endif ># 195 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/mem.h" >} > >MEM_STATIC U64 MEM_swap64(U64 in) >{ >#if defined(_MSC_VER) /* Visual Studio */ > return _byteswap_uint64(in); >#elif defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 403) ># 202 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/mem.h" > return __builtin_bswap64(in); >#else ># 204 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/mem.h" > return ((in << 56) & 0xff00000000000000ULL) | > ((in << 40) & 0x00ff000000000000ULL) | > ((in << 24) & 0x0000ff0000000000ULL) | > ((in << 8) & 0x000000ff00000000ULL) | > ((in >> 8) & 0x00000000ff000000ULL) | > ((in >> 24) & 0x0000000000ff0000ULL) | > ((in >> 40) & 0x000000000000ff00ULL) | > ((in >> 56) & 0x00000000000000ffULL); >#endif ># 213 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/mem.h" >} > >MEM_STATIC size_t MEM_swapST(size_t in) >{ > if (MEM_32bits()) > return (size_t)MEM_swap32((U32)in); > else > return (size_t)MEM_swap64((U64)in); >} > >/*=== Little endian r/w ===*/ > >MEM_STATIC U16 MEM_readLE16(const void* memPtr) >{ > if (MEM_isLittleEndian()) > return MEM_read16(memPtr); > else { > const BYTE* p = (const BYTE*)memPtr; > return (U16)(p[0] + (p[1]<<8)); > } >} > >MEM_STATIC void MEM_writeLE16(void* memPtr, U16 val) >{ > if (MEM_isLittleEndian()) { > MEM_write16(memPtr, val); > } else { > BYTE* p = (BYTE*)memPtr; > p[0] = (BYTE)val; > p[1] = (BYTE)(val>>8); > } >} > >MEM_STATIC U32 MEM_readLE24(const void* memPtr) >{ > return MEM_readLE16(memPtr) + (((const BYTE*)memPtr)[2] << 16); >} > >MEM_STATIC void MEM_writeLE24(void* memPtr, U32 val) >{ > MEM_writeLE16(memPtr, (U16)val); > ((BYTE*)memPtr)[2] = (BYTE)(val>>16); >} > >MEM_STATIC U32 MEM_readLE32(const void* memPtr) >{ > if (MEM_isLittleEndian()) > return MEM_read32(memPtr); > else > return MEM_swap32(MEM_read32(memPtr)); >} > >MEM_STATIC void MEM_writeLE32(void* memPtr, U32 val32) >{ > if (MEM_isLittleEndian()) > MEM_write32(memPtr, val32); > else > MEM_write32(memPtr, MEM_swap32(val32)); >} > >MEM_STATIC U64 MEM_readLE64(const void* memPtr) >{ > if (MEM_isLittleEndian()) > return MEM_read64(memPtr); > else > return MEM_swap64(MEM_read64(memPtr)); >} > >MEM_STATIC void MEM_writeLE64(void* memPtr, U64 val64) >{ > if (MEM_isLittleEndian()) > MEM_write64(memPtr, val64); > else > MEM_write64(memPtr, MEM_swap64(val64)); >} > >MEM_STATIC size_t MEM_readLEST(const void* memPtr) >{ > if (MEM_32bits()) > return (size_t)MEM_readLE32(memPtr); > else > return (size_t)MEM_readLE64(memPtr); >} > >MEM_STATIC void MEM_writeLEST(void* memPtr, size_t val) >{ > if (MEM_32bits()) > MEM_writeLE32(memPtr, (U32)val); > else > MEM_writeLE64(memPtr, (U64)val); >} > >/*=== Big endian r/w ===*/ > >MEM_STATIC U32 MEM_readBE32(const void* memPtr) >{ > if (MEM_isLittleEndian()) > return MEM_swap32(MEM_read32(memPtr)); > else > return MEM_read32(memPtr); >} > >MEM_STATIC void MEM_writeBE32(void* memPtr, U32 val32) >{ > if (MEM_isLittleEndian()) > MEM_write32(memPtr, MEM_swap32(val32)); > else > MEM_write32(memPtr, val32); >} > >MEM_STATIC U64 MEM_readBE64(const void* memPtr) >{ > if (MEM_isLittleEndian()) > return MEM_swap64(MEM_read64(memPtr)); > else > return MEM_read64(memPtr); >} > >MEM_STATIC void MEM_writeBE64(void* memPtr, U64 val64) >{ > if (MEM_isLittleEndian()) > MEM_write64(memPtr, MEM_swap64(val64)); > else > MEM_write64(memPtr, val64); >} > >MEM_STATIC size_t MEM_readBEST(const void* memPtr) >{ > if (MEM_32bits()) > return (size_t)MEM_readBE32(memPtr); > else > return (size_t)MEM_readBE64(memPtr); >} > >MEM_STATIC void MEM_writeBEST(void* memPtr, size_t val) >{ > if (MEM_32bits()) > MEM_writeBE32(memPtr, (U32)val); > else > MEM_writeBE64(memPtr, (U64)val); >} > > >#if defined (__cplusplus) >} >#endif ># 359 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/mem.h" > >#endif /* MEM_H_MODULE */ ># 361 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/mem.h" ># 25 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.c" 2 >#define FSE_STATIC_LINKING_ONLY /* FSE_encodeSymbol */ >#if 0 /* expanded by -frewrite-includes */ >#include "fse.h" >#endif /* expanded by -frewrite-includes */ ># 26 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.c" ># 1 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/fse.h" 1 >/* ****************************************************************** > FSE : Finite State Entropy codec > Public Prototypes declaration > Copyright (C) 2013-2016, Yann Collet. > > BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php) > > Redistribution and use in source and binary forms, with or without > modification, are permitted provided that the following conditions are > met: > > * Redistributions of source code must retain the above copyright > notice, this list of conditions and the following disclaimer. > * Redistributions in binary form must reproduce the above > copyright notice, this list of conditions and the following disclaimer > in the documentation and/or other materials provided with the > distribution. > > THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT > LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR > A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT > OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, > SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT > LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, > DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY > THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT > (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE > OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > > You can contact the author at : > - Source repository : https://github.com/Cyan4973/FiniteStateEntropy >****************************************************************** */ > >#if defined (__cplusplus) >extern "C" { >#endif ># 38 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/fse.h" > >#ifndef FSE_H >#define FSE_H > > >/*-***************************************** >* Dependencies >******************************************/ >#if 0 /* expanded by -frewrite-includes */ >#include <stddef.h> /* size_t, ptrdiff_t */ >#endif /* expanded by -frewrite-includes */ ># 46 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/fse.h" ># 47 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/fse.h" > > >/*-***************************************** >* FSE_PUBLIC_API : control library symbols visibility >******************************************/ >#if defined(FSE_DLL_EXPORT) && (FSE_DLL_EXPORT==1) && defined(__GNUC__) && (__GNUC__ >= 4) ># define FSE_PUBLIC_API __attribute__ ((visibility ("default"))) >#elif defined(FSE_DLL_EXPORT) && (FSE_DLL_EXPORT==1) /* Visual expected */ ># 55 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/fse.h" ># define FSE_PUBLIC_API __declspec(dllexport) >#elif defined(FSE_DLL_IMPORT) && (FSE_DLL_IMPORT==1) ># 57 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/fse.h" ># define FSE_PUBLIC_API __declspec(dllimport) /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/ >#else ># 59 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/fse.h" ># define FSE_PUBLIC_API >#endif ># 61 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/fse.h" > >/*------ Version ------*/ >#define FSE_VERSION_MAJOR 0 >#define FSE_VERSION_MINOR 9 >#define FSE_VERSION_RELEASE 0 > >#define FSE_LIB_VERSION FSE_VERSION_MAJOR.FSE_VERSION_MINOR.FSE_VERSION_RELEASE >#define FSE_QUOTE(str) #str >#define FSE_EXPAND_AND_QUOTE(str) FSE_QUOTE(str) >#define FSE_VERSION_STRING FSE_EXPAND_AND_QUOTE(FSE_LIB_VERSION) > >#define FSE_VERSION_NUMBER (FSE_VERSION_MAJOR *100*100 + FSE_VERSION_MINOR *100 + FSE_VERSION_RELEASE) >FSE_PUBLIC_API unsigned FSE_versionNumber(void); /**< library version number; to be used when checking dll version */ > >/*-**************************************** >* FSE simple functions >******************************************/ >/*! FSE_compress() : > Compress content of buffer 'src', of size 'srcSize', into destination buffer 'dst'. > 'dst' buffer must be already allocated. Compression runs faster is dstCapacity >= FSE_compressBound(srcSize). > @return : size of compressed data (<= dstCapacity). > Special values : if return == 0, srcData is not compressible => Nothing is stored within dst !!! > if return == 1, srcData is a single byte symbol * srcSize times. Use RLE compression instead. > if FSE_isError(return), compression failed (more details using FSE_getErrorName()) >*/ >FSE_PUBLIC_API size_t FSE_compress(void* dst, size_t dstCapacity, > const void* src, size_t srcSize); > >/*! FSE_decompress(): > Decompress FSE data from buffer 'cSrc', of size 'cSrcSize', > into already allocated destination buffer 'dst', of size 'dstCapacity'. > @return : size of regenerated data (<= maxDstSize), > or an error code, which can be tested using FSE_isError() . > > ** Important ** : FSE_decompress() does not decompress non-compressible nor RLE data !!! > Why ? : making this distinction requires a header. > Header management is intentionally delegated to the user layer, which can better manage special cases. >*/ >FSE_PUBLIC_API size_t FSE_decompress(void* dst, size_t dstCapacity, > const void* cSrc, size_t cSrcSize); > > >/*-***************************************** >* Tool functions >******************************************/ >FSE_PUBLIC_API size_t FSE_compressBound(size_t size); /* maximum compressed size */ > >/* Error Management */ >FSE_PUBLIC_API unsigned FSE_isError(size_t code); /* tells if a return value is an error code */ >FSE_PUBLIC_API const char* FSE_getErrorName(size_t code); /* provides error code string (useful for debugging) */ > > >/*-***************************************** >* FSE advanced functions >******************************************/ >/*! FSE_compress2() : > Same as FSE_compress(), but allows the selection of 'maxSymbolValue' and 'tableLog' > Both parameters can be defined as '0' to mean : use default value > @return : size of compressed data > Special values : if return == 0, srcData is not compressible => Nothing is stored within cSrc !!! > if return == 1, srcData is a single byte symbol * srcSize times. Use RLE compression. > if FSE_isError(return), it's an error code. >*/ >FSE_PUBLIC_API size_t FSE_compress2 (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog); > > >/*-***************************************** >* FSE detailed API >******************************************/ >/*! >FSE_compress() does the following: >1. count symbol occurrence from source[] into table count[] >2. normalize counters so that sum(count[]) == Power_of_2 (2^tableLog) >3. save normalized counters to memory buffer using writeNCount() >4. build encoding table 'CTable' from normalized counters >5. encode the data stream using encoding table 'CTable' > >FSE_decompress() does the following: >1. read normalized counters with readNCount() >2. build decoding table 'DTable' from normalized counters >3. decode the data stream using decoding table 'DTable' > >The following API allows targeting specific sub-functions for advanced tasks. >For example, it's possible to compress several blocks using the same 'CTable', >or to save and provide normalized distribution using external method. >*/ > >/* *** COMPRESSION *** */ > >/*! FSE_count(): > Provides the precise count of each byte within a table 'count'. > 'count' is a table of unsigned int, of minimum size (*maxSymbolValuePtr+1). > *maxSymbolValuePtr will be updated if detected smaller than initial value. > @return : the count of the most frequent symbol (which is not identified). > if return == srcSize, there is only one symbol. > Can also return an error code, which can be tested with FSE_isError(). */ >FSE_PUBLIC_API size_t FSE_count(unsigned* count, unsigned* maxSymbolValuePtr, const void* src, size_t srcSize); > >/*! FSE_optimalTableLog(): > dynamically downsize 'tableLog' when conditions are met. > It saves CPU time, by using smaller tables, while preserving or even improving compression ratio. > @return : recommended tableLog (necessarily <= 'maxTableLog') */ >FSE_PUBLIC_API unsigned FSE_optimalTableLog(unsigned maxTableLog, size_t srcSize, unsigned maxSymbolValue); > >/*! FSE_normalizeCount(): > normalize counts so that sum(count[]) == Power_of_2 (2^tableLog) > 'normalizedCounter' is a table of short, of minimum size (maxSymbolValue+1). > @return : tableLog, > or an errorCode, which can be tested using FSE_isError() */ >FSE_PUBLIC_API size_t FSE_normalizeCount(short* normalizedCounter, unsigned tableLog, const unsigned* count, size_t srcSize, unsigned maxSymbolValue); > >/*! FSE_NCountWriteBound(): > Provides the maximum possible size of an FSE normalized table, given 'maxSymbolValue' and 'tableLog'. > Typically useful for allocation purpose. */ >FSE_PUBLIC_API size_t FSE_NCountWriteBound(unsigned maxSymbolValue, unsigned tableLog); > >/*! FSE_writeNCount(): > Compactly save 'normalizedCounter' into 'buffer'. > @return : size of the compressed table, > or an errorCode, which can be tested using FSE_isError(). */ >FSE_PUBLIC_API size_t FSE_writeNCount (void* buffer, size_t bufferSize, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog); > > >/*! Constructor and Destructor of FSE_CTable. > Note that FSE_CTable size depends on 'tableLog' and 'maxSymbolValue' */ >typedef unsigned FSE_CTable; /* don't allocate that. It's only meant to be more restrictive than void* */ >FSE_PUBLIC_API FSE_CTable* FSE_createCTable (unsigned maxSymbolValue, unsigned tableLog); >FSE_PUBLIC_API void FSE_freeCTable (FSE_CTable* ct); > >/*! FSE_buildCTable(): > Builds `ct`, which must be already allocated, using FSE_createCTable(). > @return : 0, or an errorCode, which can be tested using FSE_isError() */ >FSE_PUBLIC_API size_t FSE_buildCTable(FSE_CTable* ct, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog); > >/*! FSE_compress_usingCTable(): > Compress `src` using `ct` into `dst` which must be already allocated. > @return : size of compressed data (<= `dstCapacity`), > or 0 if compressed data could not fit into `dst`, > or an errorCode, which can be tested using FSE_isError() */ >FSE_PUBLIC_API size_t FSE_compress_usingCTable (void* dst, size_t dstCapacity, const void* src, size_t srcSize, const FSE_CTable* ct); > >/*! >Tutorial : >---------- >The first step is to count all symbols. FSE_count() does this job very fast. >Result will be saved into 'count', a table of unsigned int, which must be already allocated, and have 'maxSymbolValuePtr[0]+1' cells. >'src' is a table of bytes of size 'srcSize'. All values within 'src' MUST be <= maxSymbolValuePtr[0] >maxSymbolValuePtr[0] will be updated, with its real value (necessarily <= original value) >FSE_count() will return the number of occurrence of the most frequent symbol. >This can be used to know if there is a single symbol within 'src', and to quickly evaluate its compressibility. >If there is an error, the function will return an ErrorCode (which can be tested using FSE_isError()). > >The next step is to normalize the frequencies. >FSE_normalizeCount() will ensure that sum of frequencies is == 2 ^'tableLog'. >It also guarantees a minimum of 1 to any Symbol with frequency >= 1. >You can use 'tableLog'==0 to mean "use default tableLog value". >If you are unsure of which tableLog value to use, you can ask FSE_optimalTableLog(), >which will provide the optimal valid tableLog given sourceSize, maxSymbolValue, and a user-defined maximum (0 means "default"). > >The result of FSE_normalizeCount() will be saved into a table, >called 'normalizedCounter', which is a table of signed short. >'normalizedCounter' must be already allocated, and have at least 'maxSymbolValue+1' cells. >The return value is tableLog if everything proceeded as expected. >It is 0 if there is a single symbol within distribution. >If there is an error (ex: invalid tableLog value), the function will return an ErrorCode (which can be tested using FSE_isError()). > >'normalizedCounter' can be saved in a compact manner to a memory area using FSE_writeNCount(). >'buffer' must be already allocated. >For guaranteed success, buffer size must be at least FSE_headerBound(). >The result of the function is the number of bytes written into 'buffer'. >If there is an error, the function will return an ErrorCode (which can be tested using FSE_isError(); ex : buffer size too small). > >'normalizedCounter' can then be used to create the compression table 'CTable'. >The space required by 'CTable' must be already allocated, using FSE_createCTable(). >You can then use FSE_buildCTable() to fill 'CTable'. >If there is an error, both functions will return an ErrorCode (which can be tested using FSE_isError()). > >'CTable' can then be used to compress 'src', with FSE_compress_usingCTable(). >Similar to FSE_count(), the convention is that 'src' is assumed to be a table of char of size 'srcSize' >The function returns the size of compressed data (without header), necessarily <= `dstCapacity`. >If it returns '0', compressed data could not fit into 'dst'. >If there is an error, the function will return an ErrorCode (which can be tested using FSE_isError()). >*/ > > >/* *** DECOMPRESSION *** */ > >/*! FSE_readNCount(): > Read compactly saved 'normalizedCounter' from 'rBuffer'. > @return : size read from 'rBuffer', > or an errorCode, which can be tested using FSE_isError(). > maxSymbolValuePtr[0] and tableLogPtr[0] will also be updated with their respective values */ >FSE_PUBLIC_API size_t FSE_readNCount (short* normalizedCounter, unsigned* maxSymbolValuePtr, unsigned* tableLogPtr, const void* rBuffer, size_t rBuffSize); > >/*! Constructor and Destructor of FSE_DTable. > Note that its size depends on 'tableLog' */ >typedef unsigned FSE_DTable; /* don't allocate that. It's just a way to be more restrictive than void* */ >FSE_PUBLIC_API FSE_DTable* FSE_createDTable(unsigned tableLog); >FSE_PUBLIC_API void FSE_freeDTable(FSE_DTable* dt); > >/*! FSE_buildDTable(): > Builds 'dt', which must be already allocated, using FSE_createDTable(). > return : 0, or an errorCode, which can be tested using FSE_isError() */ >FSE_PUBLIC_API size_t FSE_buildDTable (FSE_DTable* dt, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog); > >/*! FSE_decompress_usingDTable(): > Decompress compressed source `cSrc` of size `cSrcSize` using `dt` > into `dst` which must be already allocated. > @return : size of regenerated data (necessarily <= `dstCapacity`), > or an errorCode, which can be tested using FSE_isError() */ >FSE_PUBLIC_API size_t FSE_decompress_usingDTable(void* dst, size_t dstCapacity, const void* cSrc, size_t cSrcSize, const FSE_DTable* dt); > >/*! >Tutorial : >---------- >(Note : these functions only decompress FSE-compressed blocks. > If block is uncompressed, use memcpy() instead > If block is a single repeated byte, use memset() instead ) > >The first step is to obtain the normalized frequencies of symbols. >This can be performed by FSE_readNCount() if it was saved using FSE_writeNCount(). >'normalizedCounter' must be already allocated, and have at least 'maxSymbolValuePtr[0]+1' cells of signed short. >In practice, that means it's necessary to know 'maxSymbolValue' beforehand, >or size the table to handle worst case situations (typically 256). >FSE_readNCount() will provide 'tableLog' and 'maxSymbolValue'. >The result of FSE_readNCount() is the number of bytes read from 'rBuffer'. >Note that 'rBufferSize' must be at least 4 bytes, even if useful information is less than that. >If there is an error, the function will return an error code, which can be tested using FSE_isError(). > >The next step is to build the decompression tables 'FSE_DTable' from 'normalizedCounter'. >This is performed by the function FSE_buildDTable(). >The space required by 'FSE_DTable' must be already allocated using FSE_createDTable(). >If there is an error, the function will return an error code, which can be tested using FSE_isError(). > >`FSE_DTable` can then be used to decompress `cSrc`, with FSE_decompress_usingDTable(). >`cSrcSize` must be strictly correct, otherwise decompression will fail. >FSE_decompress_usingDTable() result will tell how many bytes were regenerated (<=`dstCapacity`). >If there is an error, the function will return an error code, which can be tested using FSE_isError(). (ex: dst buffer too small) >*/ > >#endif /* FSE_H */ ># 302 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/fse.h" > >#if defined(FSE_STATIC_LINKING_ONLY) && !defined(FSE_H_FSE_STATIC_LINKING_ONLY) >#define FSE_H_FSE_STATIC_LINKING_ONLY > >/* *** Dependency *** */ >#if 0 /* expanded by -frewrite-includes */ >#include "bitstream.h" >#endif /* expanded by -frewrite-includes */ ># 307 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/fse.h" ># 1 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/bitstream.h" 1 >/* ****************************************************************** > bitstream > Part of FSE library > header file (to include) > Copyright (C) 2013-2017, Yann Collet. > > BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php) > > Redistribution and use in source and binary forms, with or without > modification, are permitted provided that the following conditions are > met: > > * Redistributions of source code must retain the above copyright > notice, this list of conditions and the following disclaimer. > * Redistributions in binary form must reproduce the above > copyright notice, this list of conditions and the following disclaimer > in the documentation and/or other materials provided with the > distribution. > > THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT > LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR > A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT > OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, > SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT > LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, > DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY > THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT > (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE > OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > > You can contact the author at : > - Source repository : https://github.com/Cyan4973/FiniteStateEntropy >****************************************************************** */ >#ifndef BITSTREAM_H_MODULE >#define BITSTREAM_H_MODULE > >#if defined (__cplusplus) >extern "C" { >#endif ># 41 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/bitstream.h" > >/* >* This API consists of small unitary functions, which must be inlined for best performance. >* Since link-time-optimization is not available for all compilers, >* these functions are defined into a .h to be included. >*/ > >/*-**************************************** >* Dependencies >******************************************/ >#if 0 /* expanded by -frewrite-includes */ >#include "mem.h" /* unaligned access routines */ >#endif /* expanded by -frewrite-includes */ ># 51 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/bitstream.h" ># 52 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/bitstream.h" >#if 0 /* expanded by -frewrite-includes */ >#include "error_private.h" /* error codes and messages */ >#endif /* expanded by -frewrite-includes */ ># 52 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/bitstream.h" ># 1 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/error_private.h" 1 >/* > * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. > * All rights reserved. > * > * This source code is licensed under both the BSD-style license (found in the > * LICENSE file in the root directory of this source tree) and the GPLv2 (found > * in the COPYING file in the root directory of this source tree). > * You may select, at your option, one of the above-listed licenses. > */ > >/* Note : this module is expected to remain private, do not expose it */ > >#ifndef ERROR_H_MODULE >#define ERROR_H_MODULE > >#if defined (__cplusplus) >extern "C" { >#endif ># 19 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/error_private.h" > > >/* **************************************** >* Dependencies >******************************************/ >#if 0 /* expanded by -frewrite-includes */ >#include <stddef.h> /* size_t */ >#endif /* expanded by -frewrite-includes */ ># 24 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/error_private.h" ># 25 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/error_private.h" >#if 0 /* expanded by -frewrite-includes */ >#include "zstd_errors.h" /* enum list */ >#endif /* expanded by -frewrite-includes */ ># 25 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/error_private.h" ># 1 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_errors.h" 1 >/* > * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. > * All rights reserved. > * > * This source code is licensed under both the BSD-style license (found in the > * LICENSE file in the root directory of this source tree) and the GPLv2 (found > * in the COPYING file in the root directory of this source tree). > * You may select, at your option, one of the above-listed licenses. > */ > >#ifndef ZSTD_ERRORS_H_398273423 >#define ZSTD_ERRORS_H_398273423 > >#if defined (__cplusplus) >extern "C" { >#endif ># 17 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_errors.h" > >/*===== dependency =====*/ >#if 0 /* expanded by -frewrite-includes */ >#include <stddef.h> /* size_t */ >#endif /* expanded by -frewrite-includes */ ># 19 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_errors.h" ># 20 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_errors.h" > > >/* ===== ZSTDERRORLIB_API : control library symbols visibility ===== */ >#ifndef ZSTDERRORLIB_VISIBILITY ># if defined(__GNUC__) && (__GNUC__ >= 4) ># define ZSTDERRORLIB_VISIBILITY __attribute__ ((visibility ("default"))) ># else ># 27 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_errors.h" ># define ZSTDERRORLIB_VISIBILITY ># endif ># 29 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_errors.h" >#endif ># 30 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_errors.h" >#if defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1) ># define ZSTDERRORLIB_API __declspec(dllexport) ZSTDERRORLIB_VISIBILITY >#elif defined(ZSTD_DLL_IMPORT) && (ZSTD_DLL_IMPORT==1) ># 33 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_errors.h" ># define ZSTDERRORLIB_API __declspec(dllimport) ZSTDERRORLIB_VISIBILITY /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/ >#else ># 35 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_errors.h" ># define ZSTDERRORLIB_API ZSTDERRORLIB_VISIBILITY >#endif ># 37 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_errors.h" > >/*-**************************************** > * error codes list > * note : this API is still considered unstable > * and shall not be used with a dynamic library. > * only static linking is allowed > ******************************************/ >typedef enum { > ZSTD_error_no_error = 0, > ZSTD_error_GENERIC = 1, > ZSTD_error_prefix_unknown = 10, > ZSTD_error_version_unsupported = 12, > ZSTD_error_frameParameter_unsupported = 14, > ZSTD_error_frameParameter_windowTooLarge = 16, > ZSTD_error_corruption_detected = 20, > ZSTD_error_checksum_wrong = 22, > ZSTD_error_dictionary_corrupted = 30, > ZSTD_error_dictionary_wrong = 32, > ZSTD_error_dictionaryCreation_failed = 34, > ZSTD_error_parameter_unsupported = 40, > ZSTD_error_parameter_outOfBound = 42, > ZSTD_error_tableLog_tooLarge = 44, > ZSTD_error_maxSymbolValue_tooLarge = 46, > ZSTD_error_maxSymbolValue_tooSmall = 48, > ZSTD_error_stage_wrong = 60, > ZSTD_error_init_missing = 62, > ZSTD_error_memory_allocation = 64, > ZSTD_error_dstSize_tooSmall = 70, > ZSTD_error_srcSize_wrong = 72, > /* following error codes are not stable and may be removed or changed in a future version */ > ZSTD_error_frameIndex_tooLarge = 100, > ZSTD_error_seekableIO = 102, > ZSTD_error_maxCode = 120 /* never EVER use this value directly, it can change in future versions! Use ZSTD_isError() instead */ >} ZSTD_ErrorCode; > >/*! ZSTD_getErrorCode() : > convert a `size_t` function result into a `ZSTD_ErrorCode` enum type, > which can be used to compare with enum list published above */ >ZSTDERRORLIB_API ZSTD_ErrorCode ZSTD_getErrorCode(size_t functionResult); >ZSTDERRORLIB_API const char* ZSTD_getErrorString(ZSTD_ErrorCode code); /**< Same as ZSTD_getErrorName, but using a `ZSTD_ErrorCode` enum argument */ > > >#if defined (__cplusplus) >} >#endif ># 82 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_errors.h" > >#endif /* ZSTD_ERRORS_H_398273423 */ ># 84 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_errors.h" ># 26 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/error_private.h" 2 > > >/* **************************************** >* Compiler-specific >******************************************/ >#if defined(__GNUC__) ># define ERR_STATIC static __attribute__((unused)) >#elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) ># 34 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/error_private.h" ># define ERR_STATIC static inline >#elif defined(_MSC_VER) ># 36 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/error_private.h" ># define ERR_STATIC static __inline >#else ># 38 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/error_private.h" ># define ERR_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */ >#endif ># 40 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/error_private.h" > > >/*-**************************************** >* Customization (error_public.h) >******************************************/ >typedef ZSTD_ErrorCode ERR_enum; >#define PREFIX(name) ZSTD_error_##name > > >/*-**************************************** >* Error codes handling >******************************************/ >#undef ERROR /* reported already defined on VS 2015 (Rich Geldreich) */ >#define ERROR(name) ZSTD_ERROR(name) >#define ZSTD_ERROR(name) ((size_t)-PREFIX(name)) > >ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); } > >ERR_STATIC ERR_enum ERR_getErrorCode(size_t code) { if (!ERR_isError(code)) return (ERR_enum)0; return (ERR_enum) (0-code); } > > >/*-**************************************** >* Error Strings >******************************************/ > >const char* ERR_getErrorString(ERR_enum code); /* error_private.c */ > >ERR_STATIC const char* ERR_getErrorName(size_t code) >{ > return ERR_getErrorString(ERR_getErrorCode(code)); >} > >#if defined (__cplusplus) >} >#endif ># 75 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/error_private.h" > >#endif /* ERROR_H_MODULE */ ># 77 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/error_private.h" ># 53 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/bitstream.h" 2 > > >/*-************************************* >* Debug >***************************************/ >#if defined(BIT_DEBUG) && (BIT_DEBUG>=1) >#if 0 /* expanded by -frewrite-includes */ ># include <assert.h> >#endif /* expanded by -frewrite-includes */ ># 59 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/bitstream.h" ># 60 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/bitstream.h" >#else ># 61 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/bitstream.h" ># ifndef assert ># define assert(condition) ((void)0) ># endif ># 64 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/bitstream.h" >#endif ># 65 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/bitstream.h" > > >/*========================================= >* Target specific >=========================================*/ >#if defined(__BMI__) && defined(__GNUC__) >#if 0 /* expanded by -frewrite-includes */ ># include <immintrin.h> /* support for bextr (experimental) */ >#endif /* expanded by -frewrite-includes */ ># 71 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/bitstream.h" ># 72 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/bitstream.h" >#endif ># 73 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/bitstream.h" > >#define STREAM_ACCUMULATOR_MIN_32 25 >#define STREAM_ACCUMULATOR_MIN_64 57 >#define STREAM_ACCUMULATOR_MIN ((U32)(MEM_32bits() ? STREAM_ACCUMULATOR_MIN_32 : STREAM_ACCUMULATOR_MIN_64)) > > >/*-****************************************** >* bitStream encoding API (write forward) >********************************************/ >/* bitStream can mix input from multiple sources. > * A critical property of these streams is that they encode and decode in **reverse** direction. > * So the first bit sequence you add will be the last to be read, like a LIFO stack. > */ >typedef struct >{ > size_t bitContainer; > unsigned bitPos; > char* startPtr; > char* ptr; > char* endPtr; >} BIT_CStream_t; > >MEM_STATIC size_t BIT_initCStream(BIT_CStream_t* bitC, void* dstBuffer, size_t dstCapacity); >MEM_STATIC void BIT_addBits(BIT_CStream_t* bitC, size_t value, unsigned nbBits); >MEM_STATIC void BIT_flushBits(BIT_CStream_t* bitC); >MEM_STATIC size_t BIT_closeCStream(BIT_CStream_t* bitC); > >/* Start with initCStream, providing the size of buffer to write into. >* bitStream will never write outside of this buffer. >* `dstCapacity` must be >= sizeof(bitD->bitContainer), otherwise @return will be an error code. >* >* bits are first added to a local register. >* Local register is size_t, hence 64-bits on 64-bits systems, or 32-bits on 32-bits systems. >* Writing data into memory is an explicit operation, performed by the flushBits function. >* Hence keep track how many bits are potentially stored into local register to avoid register overflow. >* After a flushBits, a maximum of 7 bits might still be stored into local register. >* >* Avoid storing elements of more than 24 bits if you want compatibility with 32-bits bitstream readers. >* >* Last operation is to close the bitStream. >* The function returns the final size of CStream in bytes. >* If data couldn't fit into `dstBuffer`, it will return a 0 ( == not storable) >*/ > > >/*-******************************************** >* bitStream decoding API (read backward) >**********************************************/ >typedef struct >{ > size_t bitContainer; > unsigned bitsConsumed; > const char* ptr; > const char* start; > const char* limitPtr; >} BIT_DStream_t; > >typedef enum { BIT_DStream_unfinished = 0, > BIT_DStream_endOfBuffer = 1, > BIT_DStream_completed = 2, > BIT_DStream_overflow = 3 } BIT_DStream_status; /* result of BIT_reloadDStream() */ > /* 1,2,4,8 would be better for bitmap combinations, but slows down performance a bit ... :( */ > >MEM_STATIC size_t BIT_initDStream(BIT_DStream_t* bitD, const void* srcBuffer, size_t srcSize); >MEM_STATIC size_t BIT_readBits(BIT_DStream_t* bitD, unsigned nbBits); >MEM_STATIC BIT_DStream_status BIT_reloadDStream(BIT_DStream_t* bitD); >MEM_STATIC unsigned BIT_endOfDStream(const BIT_DStream_t* bitD); > > >/* Start by invoking BIT_initDStream(). >* A chunk of the bitStream is then stored into a local register. >* Local register size is 64-bits on 64-bits systems, 32-bits on 32-bits systems (size_t). >* You can then retrieve bitFields stored into the local register, **in reverse order**. >* Local register is explicitly reloaded from memory by the BIT_reloadDStream() method. >* A reload guarantee a minimum of ((8*sizeof(bitD->bitContainer))-7) bits when its result is BIT_DStream_unfinished. >* Otherwise, it can be less than that, so proceed accordingly. >* Checking if DStream has reached its end can be performed with BIT_endOfDStream(). >*/ > > >/*-**************************************** >* unsafe API >******************************************/ >MEM_STATIC void BIT_addBitsFast(BIT_CStream_t* bitC, size_t value, unsigned nbBits); >/* faster, but works only if value is "clean", meaning all high bits above nbBits are 0 */ > >MEM_STATIC void BIT_flushBitsFast(BIT_CStream_t* bitC); >/* unsafe version; does not check buffer overflow */ > >MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, unsigned nbBits); >/* faster, but works only if nbBits >= 1 */ > > > >/*-************************************************************** >* Internal functions >****************************************************************/ >MEM_STATIC unsigned BIT_highbit32 (register U32 val) >{ > assert(val != 0); > { ># if defined(_MSC_VER) /* Visual */ > unsigned long r=0; > _BitScanReverse ( &r, val ); > return (unsigned) r; ># elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */ ># 179 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/bitstream.h" > return 31 - __builtin_clz (val); ># else /* Software version */ ># 181 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/bitstream.h" > static const unsigned DeBruijnClz[32] = { 0, 9, 1, 10, 13, 21, 2, 29, > 11, 14, 16, 18, 22, 25, 3, 30, > 8, 12, 20, 28, 15, 17, 24, 7, > 19, 27, 23, 6, 26, 5, 4, 31 }; > U32 v = val; > v |= v >> 1; > v |= v >> 2; > v |= v >> 4; > v |= v >> 8; > v |= v >> 16; > return DeBruijnClz[ (U32) (v * 0x07C4ACDDU) >> 27]; ># endif ># 193 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/bitstream.h" > } >} > >/*===== Local Constants =====*/ >static const unsigned BIT_mask[] = { > 0, 1, 3, 7, 0xF, 0x1F, > 0x3F, 0x7F, 0xFF, 0x1FF, 0x3FF, 0x7FF, > 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF, 0x1FFFF, > 0x3FFFF, 0x7FFFF, 0xFFFFF, 0x1FFFFF, 0x3FFFFF, 0x7FFFFF, > 0xFFFFFF, 0x1FFFFFF, 0x3FFFFFF, 0x7FFFFFF, 0xFFFFFFF, 0x1FFFFFFF, > 0x3FFFFFFF, 0x7FFFFFFF}; /* up to 31 bits */ >#define BIT_MASK_SIZE (sizeof(BIT_mask) / sizeof(BIT_mask[0])) > >/*-************************************************************** >* bitStream encoding >****************************************************************/ >/*! BIT_initCStream() : > * `dstCapacity` must be > sizeof(size_t) > * @return : 0 if success, > * otherwise an error code (can be tested using ERR_isError()) */ >MEM_STATIC size_t BIT_initCStream(BIT_CStream_t* bitC, > void* startPtr, size_t dstCapacity) >{ > bitC->bitContainer = 0; > bitC->bitPos = 0; > bitC->startPtr = (char*)startPtr; > bitC->ptr = bitC->startPtr; > bitC->endPtr = bitC->startPtr + dstCapacity - sizeof(bitC->bitContainer); > if (dstCapacity <= sizeof(bitC->bitContainer)) return ERROR(dstSize_tooSmall); > return 0; >} > >/*! BIT_addBits() : > * can add up to 31 bits into `bitC`. > * Note : does not check for register overflow ! */ >MEM_STATIC void BIT_addBits(BIT_CStream_t* bitC, > size_t value, unsigned nbBits) >{ > MEM_STATIC_ASSERT(BIT_MASK_SIZE == 32); > assert(nbBits < BIT_MASK_SIZE); > assert(nbBits + bitC->bitPos < sizeof(bitC->bitContainer) * 8); > bitC->bitContainer |= (value & BIT_mask[nbBits]) << bitC->bitPos; > bitC->bitPos += nbBits; >} > >/*! BIT_addBitsFast() : > * works only if `value` is _clean_, meaning all high bits above nbBits are 0 */ >MEM_STATIC void BIT_addBitsFast(BIT_CStream_t* bitC, > size_t value, unsigned nbBits) >{ > assert((value>>nbBits) == 0); > assert(nbBits + bitC->bitPos < sizeof(bitC->bitContainer) * 8); > bitC->bitContainer |= value << bitC->bitPos; > bitC->bitPos += nbBits; >} > >/*! BIT_flushBitsFast() : > * assumption : bitContainer has not overflowed > * unsafe version; does not check buffer overflow */ >MEM_STATIC void BIT_flushBitsFast(BIT_CStream_t* bitC) >{ > size_t const nbBytes = bitC->bitPos >> 3; > assert(bitC->bitPos < sizeof(bitC->bitContainer) * 8); > MEM_writeLEST(bitC->ptr, bitC->bitContainer); > bitC->ptr += nbBytes; > assert(bitC->ptr <= bitC->endPtr); > bitC->bitPos &= 7; > bitC->bitContainer >>= nbBytes*8; >} > >/*! BIT_flushBits() : > * assumption : bitContainer has not overflowed > * safe version; check for buffer overflow, and prevents it. > * note : does not signal buffer overflow. > * overflow will be revealed later on using BIT_closeCStream() */ >MEM_STATIC void BIT_flushBits(BIT_CStream_t* bitC) >{ > size_t const nbBytes = bitC->bitPos >> 3; > assert(bitC->bitPos < sizeof(bitC->bitContainer) * 8); > MEM_writeLEST(bitC->ptr, bitC->bitContainer); > bitC->ptr += nbBytes; > if (bitC->ptr > bitC->endPtr) bitC->ptr = bitC->endPtr; > bitC->bitPos &= 7; > bitC->bitContainer >>= nbBytes*8; >} > >/*! BIT_closeCStream() : > * @return : size of CStream, in bytes, > * or 0 if it could not fit into dstBuffer */ >MEM_STATIC size_t BIT_closeCStream(BIT_CStream_t* bitC) >{ > BIT_addBitsFast(bitC, 1, 1); /* endMark */ > BIT_flushBits(bitC); > if (bitC->ptr >= bitC->endPtr) return 0; /* overflow detected */ > return (bitC->ptr - bitC->startPtr) + (bitC->bitPos > 0); >} > > >/*-******************************************************** >* bitStream decoding >**********************************************************/ >/*! BIT_initDStream() : > * Initialize a BIT_DStream_t. > * `bitD` : a pointer to an already allocated BIT_DStream_t structure. > * `srcSize` must be the *exact* size of the bitStream, in bytes. > * @return : size of stream (== srcSize), or an errorCode if a problem is detected > */ >MEM_STATIC size_t BIT_initDStream(BIT_DStream_t* bitD, const void* srcBuffer, size_t srcSize) >{ > if (srcSize < 1) { memset(bitD, 0, sizeof(*bitD)); return ERROR(srcSize_wrong); } > > bitD->start = (const char*)srcBuffer; > bitD->limitPtr = bitD->start + sizeof(bitD->bitContainer); > > if (srcSize >= sizeof(bitD->bitContainer)) { /* normal case */ > bitD->ptr = (const char*)srcBuffer + srcSize - sizeof(bitD->bitContainer); > bitD->bitContainer = MEM_readLEST(bitD->ptr); > { BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1]; > bitD->bitsConsumed = lastByte ? 8 - BIT_highbit32(lastByte) : 0; /* ensures bitsConsumed is always set */ > if (lastByte == 0) return ERROR(GENERIC); /* endMark not present */ } > } else { > bitD->ptr = bitD->start; > bitD->bitContainer = *(const BYTE*)(bitD->start); > switch(srcSize) > { > case 7: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[6]) << (sizeof(bitD->bitContainer)*8 - 16); > /* fall-through */ > > case 6: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[5]) << (sizeof(bitD->bitContainer)*8 - 24); > /* fall-through */ > > case 5: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[4]) << (sizeof(bitD->bitContainer)*8 - 32); > /* fall-through */ > > case 4: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[3]) << 24; > /* fall-through */ > > case 3: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[2]) << 16; > /* fall-through */ > > case 2: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[1]) << 8; > /* fall-through */ > > default: break; > } > { BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1]; > bitD->bitsConsumed = lastByte ? 8 - BIT_highbit32(lastByte) : 0; > if (lastByte == 0) return ERROR(corruption_detected); /* endMark not present */ > } > bitD->bitsConsumed += (U32)(sizeof(bitD->bitContainer) - srcSize)*8; > } > > return srcSize; >} > >MEM_STATIC size_t BIT_getUpperBits(size_t bitContainer, U32 const start) >{ > return bitContainer >> start; >} > >MEM_STATIC size_t BIT_getMiddleBits(size_t bitContainer, U32 const start, U32 const nbBits) >{ >#if defined(__BMI__) && defined(__GNUC__) && __GNUC__*1000+__GNUC_MINOR__ >= 4008 /* experimental */ ># if defined(__x86_64__) > if (sizeof(bitContainer)==8) > return _bextr_u64(bitContainer, start, nbBits); > else ># endif ># 361 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/bitstream.h" > return _bextr_u32(bitContainer, start, nbBits); >#else ># 363 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/bitstream.h" > assert(nbBits < BIT_MASK_SIZE); > return (bitContainer >> start) & BIT_mask[nbBits]; >#endif ># 366 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/bitstream.h" >} > >MEM_STATIC size_t BIT_getLowerBits(size_t bitContainer, U32 const nbBits) >{ > assert(nbBits < BIT_MASK_SIZE); > return bitContainer & BIT_mask[nbBits]; >} > >/*! BIT_lookBits() : > * Provides next n bits from local register. > * local register is not modified. > * On 32-bits, maxNbBits==24. > * On 64-bits, maxNbBits==56. > * @return : value extracted */ >MEM_STATIC size_t BIT_lookBits(const BIT_DStream_t* bitD, U32 nbBits) >{ >#if defined(__BMI__) && defined(__GNUC__) /* experimental; fails if bitD->bitsConsumed + nbBits > sizeof(bitD->bitContainer)*8 */ > return BIT_getMiddleBits(bitD->bitContainer, (sizeof(bitD->bitContainer)*8) - bitD->bitsConsumed - nbBits, nbBits); >#else ># 385 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/bitstream.h" > U32 const regMask = sizeof(bitD->bitContainer)*8 - 1; > return ((bitD->bitContainer << (bitD->bitsConsumed & regMask)) >> 1) >> ((regMask-nbBits) & regMask); >#endif ># 388 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/bitstream.h" >} > >/*! BIT_lookBitsFast() : > * unsafe version; only works if nbBits >= 1 */ >MEM_STATIC size_t BIT_lookBitsFast(const BIT_DStream_t* bitD, U32 nbBits) >{ > U32 const regMask = sizeof(bitD->bitContainer)*8 - 1; > assert(nbBits >= 1); > return (bitD->bitContainer << (bitD->bitsConsumed & regMask)) >> (((regMask+1)-nbBits) & regMask); >} > >MEM_STATIC void BIT_skipBits(BIT_DStream_t* bitD, U32 nbBits) >{ > bitD->bitsConsumed += nbBits; >} > >/*! BIT_readBits() : > * Read (consume) next n bits from local register and update. > * Pay attention to not read more than nbBits contained into local register. > * @return : extracted value. */ >MEM_STATIC size_t BIT_readBits(BIT_DStream_t* bitD, U32 nbBits) >{ > size_t const value = BIT_lookBits(bitD, nbBits); > BIT_skipBits(bitD, nbBits); > return value; >} > >/*! BIT_readBitsFast() : > * unsafe version; only works only if nbBits >= 1 */ >MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, U32 nbBits) >{ > size_t const value = BIT_lookBitsFast(bitD, nbBits); > assert(nbBits >= 1); > BIT_skipBits(bitD, nbBits); > return value; >} > >/*! BIT_reloadDStream() : > * Refill `bitD` from buffer previously set in BIT_initDStream() . > * This function is safe, it guarantees it will not read beyond src buffer. > * @return : status of `BIT_DStream_t` internal register. > * when status == BIT_DStream_unfinished, internal register is filled with at least 25 or 57 bits */ >MEM_STATIC BIT_DStream_status BIT_reloadDStream(BIT_DStream_t* bitD) >{ > if (bitD->bitsConsumed > (sizeof(bitD->bitContainer)*8)) /* overflow detected, like end of stream */ > return BIT_DStream_overflow; > > if (bitD->ptr >= bitD->limitPtr) { > bitD->ptr -= bitD->bitsConsumed >> 3; > bitD->bitsConsumed &= 7; > bitD->bitContainer = MEM_readLEST(bitD->ptr); > return BIT_DStream_unfinished; > } > if (bitD->ptr == bitD->start) { > if (bitD->bitsConsumed < sizeof(bitD->bitContainer)*8) return BIT_DStream_endOfBuffer; > return BIT_DStream_completed; > } > /* start < ptr < limitPtr */ > { U32 nbBytes = bitD->bitsConsumed >> 3; > BIT_DStream_status result = BIT_DStream_unfinished; > if (bitD->ptr - nbBytes < bitD->start) { > nbBytes = (U32)(bitD->ptr - bitD->start); /* ptr > start */ > result = BIT_DStream_endOfBuffer; > } > bitD->ptr -= nbBytes; > bitD->bitsConsumed -= nbBytes*8; > bitD->bitContainer = MEM_readLEST(bitD->ptr); /* reminder : srcSize > sizeof(bitD->bitContainer), otherwise bitD->ptr == bitD->start */ > return result; > } >} > >/*! BIT_endOfDStream() : > * @return : 1 if DStream has _exactly_ reached its end (all bits consumed). > */ >MEM_STATIC unsigned BIT_endOfDStream(const BIT_DStream_t* DStream) >{ > return ((DStream->ptr == DStream->start) && (DStream->bitsConsumed == sizeof(DStream->bitContainer)*8)); >} > >#if defined (__cplusplus) >} >#endif ># 470 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/bitstream.h" > >#endif /* BITSTREAM_H_MODULE */ ># 472 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/bitstream.h" ># 308 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/fse.h" 2 > > >/* ***************************************** >* Static allocation >*******************************************/ >/* FSE buffer bounds */ >#define FSE_NCOUNTBOUND 512 >#define FSE_BLOCKBOUND(size) (size + (size>>7)) >#define FSE_COMPRESSBOUND(size) (FSE_NCOUNTBOUND + FSE_BLOCKBOUND(size)) /* Macro version, useful for static allocation */ > >/* It is possible to statically allocate FSE CTable/DTable as a table of FSE_CTable/FSE_DTable using below macros */ >#define FSE_CTABLE_SIZE_U32(maxTableLog, maxSymbolValue) (1 + (1<<(maxTableLog-1)) + ((maxSymbolValue+1)*2)) >#define FSE_DTABLE_SIZE_U32(maxTableLog) (1 + (1<<maxTableLog)) > >/* or use the size to malloc() space directly. Pay attention to alignment restrictions though */ >#define FSE_CTABLE_SIZE(maxTableLog, maxSymbolValue) (FSE_CTABLE_SIZE_U32(maxTableLog, maxSymbolValue) * sizeof(FSE_CTable)) >#define FSE_DTABLE_SIZE(maxTableLog) (FSE_DTABLE_SIZE_U32(maxTableLog) * sizeof(FSE_DTable)) > > >/* ***************************************** >* FSE advanced API >*******************************************/ >/* FSE_count_wksp() : > * Same as FSE_count(), but using an externally provided scratch buffer. > * `workSpace` size must be table of >= `1024` unsigned > */ >size_t FSE_count_wksp(unsigned* count, unsigned* maxSymbolValuePtr, > const void* source, size_t sourceSize, unsigned* workSpace); > >/** FSE_countFast() : > * same as FSE_count(), but blindly trusts that all byte values within src are <= *maxSymbolValuePtr > */ >size_t FSE_countFast(unsigned* count, unsigned* maxSymbolValuePtr, const void* src, size_t srcSize); > >/* FSE_countFast_wksp() : > * Same as FSE_countFast(), but using an externally provided scratch buffer. > * `workSpace` must be a table of minimum `1024` unsigned > */ >size_t FSE_countFast_wksp(unsigned* count, unsigned* maxSymbolValuePtr, const void* src, size_t srcSize, unsigned* workSpace); > >/*! FSE_count_simple > * Same as FSE_countFast(), but does not use any additional memory (not even on stack). > * This function is unsafe, and will segfault if any value within `src` is `> *maxSymbolValuePtr` (presuming it's also the size of `count`). >*/ >size_t FSE_count_simple(unsigned* count, unsigned* maxSymbolValuePtr, const void* src, size_t srcSize); > > > >unsigned FSE_optimalTableLog_internal(unsigned maxTableLog, size_t srcSize, unsigned maxSymbolValue, unsigned minus); >/**< same as FSE_optimalTableLog(), which used `minus==2` */ > >/* FSE_compress_wksp() : > * Same as FSE_compress2(), but using an externally allocated scratch buffer (`workSpace`). > * FSE_WKSP_SIZE_U32() provides the minimum size required for `workSpace` as a table of FSE_CTable. > */ >#define FSE_WKSP_SIZE_U32(maxTableLog, maxSymbolValue) ( FSE_CTABLE_SIZE_U32(maxTableLog, maxSymbolValue) + ((maxTableLog > 12) ? (1 << (maxTableLog - 2)) : 1024) ) >size_t FSE_compress_wksp (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize); > >size_t FSE_buildCTable_raw (FSE_CTable* ct, unsigned nbBits); >/**< build a fake FSE_CTable, designed for a flat distribution, where each symbol uses nbBits */ > >size_t FSE_buildCTable_rle (FSE_CTable* ct, unsigned char symbolValue); >/**< build a fake FSE_CTable, designed to compress always the same symbolValue */ > >/* FSE_buildCTable_wksp() : > * Same as FSE_buildCTable(), but using an externally allocated scratch buffer (`workSpace`). > * `wkspSize` must be >= `(1<<tableLog)`. > */ >size_t FSE_buildCTable_wksp(FSE_CTable* ct, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize); > >size_t FSE_buildDTable_raw (FSE_DTable* dt, unsigned nbBits); >/**< build a fake FSE_DTable, designed to read a flat distribution where each symbol uses nbBits */ > >size_t FSE_buildDTable_rle (FSE_DTable* dt, unsigned char symbolValue); >/**< build a fake FSE_DTable, designed to always generate the same symbolValue */ > >size_t FSE_decompress_wksp(void* dst, size_t dstCapacity, const void* cSrc, size_t cSrcSize, FSE_DTable* workSpace, unsigned maxLog); >/**< same as FSE_decompress(), using an externally allocated `workSpace` produced with `FSE_DTABLE_SIZE_U32(maxLog)` */ > >typedef enum { > FSE_repeat_none, /**< Cannot use the previous table */ > FSE_repeat_check, /**< Can use the previous table but it must be checked */ > FSE_repeat_valid /**< Can use the previous table and it is asumed to be valid */ > } FSE_repeat; > >/* ***************************************** >* FSE symbol compression API >*******************************************/ >/*! > This API consists of small unitary functions, which highly benefit from being inlined. > Hence their body are included in next section. >*/ >typedef struct { > ptrdiff_t value; > const void* stateTable; > const void* symbolTT; > unsigned stateLog; >} FSE_CState_t; > >static void FSE_initCState(FSE_CState_t* CStatePtr, const FSE_CTable* ct); > >static void FSE_encodeSymbol(BIT_CStream_t* bitC, FSE_CState_t* CStatePtr, unsigned symbol); > >static void FSE_flushCState(BIT_CStream_t* bitC, const FSE_CState_t* CStatePtr); > >/**< >These functions are inner components of FSE_compress_usingCTable(). >They allow the creation of custom streams, mixing multiple tables and bit sources. > >A key property to keep in mind is that encoding and decoding are done **in reverse direction**. >So the first symbol you will encode is the last you will decode, like a LIFO stack. > >You will need a few variables to track your CStream. They are : > >FSE_CTable ct; // Provided by FSE_buildCTable() >BIT_CStream_t bitStream; // bitStream tracking structure >FSE_CState_t state; // State tracking structure (can have several) > > >The first thing to do is to init bitStream and state. > size_t errorCode = BIT_initCStream(&bitStream, dstBuffer, maxDstSize); > FSE_initCState(&state, ct); > >Note that BIT_initCStream() can produce an error code, so its result should be tested, using FSE_isError(); >You can then encode your input data, byte after byte. >FSE_encodeSymbol() outputs a maximum of 'tableLog' bits at a time. >Remember decoding will be done in reverse direction. > FSE_encodeByte(&bitStream, &state, symbol); > >At any time, you can also add any bit sequence. >Note : maximum allowed nbBits is 25, for compatibility with 32-bits decoders > BIT_addBits(&bitStream, bitField, nbBits); > >The above methods don't commit data to memory, they just store it into local register, for speed. >Local register size is 64-bits on 64-bits systems, 32-bits on 32-bits systems (size_t). >Writing data to memory is a manual operation, performed by the flushBits function. > BIT_flushBits(&bitStream); > >Your last FSE encoding operation shall be to flush your last state value(s). > FSE_flushState(&bitStream, &state); > >Finally, you must close the bitStream. >The function returns the size of CStream in bytes. >If data couldn't fit into dstBuffer, it will return a 0 ( == not compressible) >If there is an error, it returns an errorCode (which can be tested using FSE_isError()). > size_t size = BIT_closeCStream(&bitStream); >*/ > > >/* ***************************************** >* FSE symbol decompression API >*******************************************/ >typedef struct { > size_t state; > const void* table; /* precise table may vary, depending on U16 */ >} FSE_DState_t; > > >static void FSE_initDState(FSE_DState_t* DStatePtr, BIT_DStream_t* bitD, const FSE_DTable* dt); > >static unsigned char FSE_decodeSymbol(FSE_DState_t* DStatePtr, BIT_DStream_t* bitD); > >static unsigned FSE_endOfDState(const FSE_DState_t* DStatePtr); > >/**< >Let's now decompose FSE_decompress_usingDTable() into its unitary components. >You will decode FSE-encoded symbols from the bitStream, >and also any other bitFields you put in, **in reverse order**. > >You will need a few variables to track your bitStream. They are : > >BIT_DStream_t DStream; // Stream context >FSE_DState_t DState; // State context. Multiple ones are possible >FSE_DTable* DTablePtr; // Decoding table, provided by FSE_buildDTable() > >The first thing to do is to init the bitStream. > errorCode = BIT_initDStream(&DStream, srcBuffer, srcSize); > >You should then retrieve your initial state(s) >(in reverse flushing order if you have several ones) : > errorCode = FSE_initDState(&DState, &DStream, DTablePtr); > >You can then decode your data, symbol after symbol. >For information the maximum number of bits read by FSE_decodeSymbol() is 'tableLog'. >Keep in mind that symbols are decoded in reverse order, like a LIFO stack (last in, first out). > unsigned char symbol = FSE_decodeSymbol(&DState, &DStream); > >You can retrieve any bitfield you eventually stored into the bitStream (in reverse order) >Note : maximum allowed nbBits is 25, for 32-bits compatibility > size_t bitField = BIT_readBits(&DStream, nbBits); > >All above operations only read from local register (which size depends on size_t). >Refueling the register from memory is manually performed by the reload method. > endSignal = FSE_reloadDStream(&DStream); > >BIT_reloadDStream() result tells if there is still some more data to read from DStream. >BIT_DStream_unfinished : there is still some data left into the DStream. >BIT_DStream_endOfBuffer : Dstream reached end of buffer. Its container may no longer be completely filled. >BIT_DStream_completed : Dstream reached its exact end, corresponding in general to decompression completed. >BIT_DStream_tooFar : Dstream went too far. Decompression result is corrupted. > >When reaching end of buffer (BIT_DStream_endOfBuffer), progress slowly, notably if you decode multiple symbols per loop, >to properly detect the exact end of stream. >After each decoded symbol, check if DStream is fully consumed using this simple test : > BIT_reloadDStream(&DStream) >= BIT_DStream_completed > >When it's done, verify decompression is fully completed, by checking both DStream and the relevant states. >Checking if DStream has reached its end is performed by : > BIT_endOfDStream(&DStream); >Check also the states. There might be some symbols left there, if some high probability ones (>50%) are possible. > FSE_endOfDState(&DState); >*/ > > >/* ***************************************** >* FSE unsafe API >*******************************************/ >static unsigned char FSE_decodeSymbolFast(FSE_DState_t* DStatePtr, BIT_DStream_t* bitD); >/* faster, but works only if nbBits is always >= 1 (otherwise, result will be corrupted) */ > > >/* ***************************************** >* Implementation of inlined functions >*******************************************/ >typedef struct { > int deltaFindState; > U32 deltaNbBits; >} FSE_symbolCompressionTransform; /* total 8 bytes */ > >MEM_STATIC void FSE_initCState(FSE_CState_t* statePtr, const FSE_CTable* ct) >{ > const void* ptr = ct; > const U16* u16ptr = (const U16*) ptr; > const U32 tableLog = MEM_read16(ptr); > statePtr->value = (ptrdiff_t)1<<tableLog; > statePtr->stateTable = u16ptr+2; > statePtr->symbolTT = ((const U32*)ct + 1 + (tableLog ? (1<<(tableLog-1)) : 1)); > statePtr->stateLog = tableLog; >} > > >/*! FSE_initCState2() : >* Same as FSE_initCState(), but the first symbol to include (which will be the last to be read) >* uses the smallest state value possible, saving the cost of this symbol */ >MEM_STATIC void FSE_initCState2(FSE_CState_t* statePtr, const FSE_CTable* ct, U32 symbol) >{ > FSE_initCState(statePtr, ct); > { const FSE_symbolCompressionTransform symbolTT = ((const FSE_symbolCompressionTransform*)(statePtr->symbolTT))[symbol]; > const U16* stateTable = (const U16*)(statePtr->stateTable); > U32 nbBitsOut = (U32)((symbolTT.deltaNbBits + (1<<15)) >> 16); > statePtr->value = (nbBitsOut << 16) - symbolTT.deltaNbBits; > statePtr->value = stateTable[(statePtr->value >> nbBitsOut) + symbolTT.deltaFindState]; > } >} > >MEM_STATIC void FSE_encodeSymbol(BIT_CStream_t* bitC, FSE_CState_t* statePtr, U32 symbol) >{ > FSE_symbolCompressionTransform const symbolTT = ((const FSE_symbolCompressionTransform*)(statePtr->symbolTT))[symbol]; > const U16* const stateTable = (const U16*)(statePtr->stateTable); > U32 const nbBitsOut = (U32)((statePtr->value + symbolTT.deltaNbBits) >> 16); > BIT_addBits(bitC, statePtr->value, nbBitsOut); > statePtr->value = stateTable[ (statePtr->value >> nbBitsOut) + symbolTT.deltaFindState]; >} > >MEM_STATIC void FSE_flushCState(BIT_CStream_t* bitC, const FSE_CState_t* statePtr) >{ > BIT_addBits(bitC, statePtr->value, statePtr->stateLog); > BIT_flushBits(bitC); >} > > >/* ====== Decompression ====== */ > >typedef struct { > U16 tableLog; > U16 fastMode; >} FSE_DTableHeader; /* sizeof U32 */ > >typedef struct >{ > unsigned short newState; > unsigned char symbol; > unsigned char nbBits; >} FSE_decode_t; /* size == U32 */ > >MEM_STATIC void FSE_initDState(FSE_DState_t* DStatePtr, BIT_DStream_t* bitD, const FSE_DTable* dt) >{ > const void* ptr = dt; > const FSE_DTableHeader* const DTableH = (const FSE_DTableHeader*)ptr; > DStatePtr->state = BIT_readBits(bitD, DTableH->tableLog); > BIT_reloadDStream(bitD); > DStatePtr->table = dt + 1; >} > >MEM_STATIC BYTE FSE_peekSymbol(const FSE_DState_t* DStatePtr) >{ > FSE_decode_t const DInfo = ((const FSE_decode_t*)(DStatePtr->table))[DStatePtr->state]; > return DInfo.symbol; >} > >MEM_STATIC void FSE_updateState(FSE_DState_t* DStatePtr, BIT_DStream_t* bitD) >{ > FSE_decode_t const DInfo = ((const FSE_decode_t*)(DStatePtr->table))[DStatePtr->state]; > U32 const nbBits = DInfo.nbBits; > size_t const lowBits = BIT_readBits(bitD, nbBits); > DStatePtr->state = DInfo.newState + lowBits; >} > >MEM_STATIC BYTE FSE_decodeSymbol(FSE_DState_t* DStatePtr, BIT_DStream_t* bitD) >{ > FSE_decode_t const DInfo = ((const FSE_decode_t*)(DStatePtr->table))[DStatePtr->state]; > U32 const nbBits = DInfo.nbBits; > BYTE const symbol = DInfo.symbol; > size_t const lowBits = BIT_readBits(bitD, nbBits); > > DStatePtr->state = DInfo.newState + lowBits; > return symbol; >} > >/*! FSE_decodeSymbolFast() : > unsafe, only works if no symbol has a probability > 50% */ >MEM_STATIC BYTE FSE_decodeSymbolFast(FSE_DState_t* DStatePtr, BIT_DStream_t* bitD) >{ > FSE_decode_t const DInfo = ((const FSE_decode_t*)(DStatePtr->table))[DStatePtr->state]; > U32 const nbBits = DInfo.nbBits; > BYTE const symbol = DInfo.symbol; > size_t const lowBits = BIT_readBitsFast(bitD, nbBits); > > DStatePtr->state = DInfo.newState + lowBits; > return symbol; >} > >MEM_STATIC unsigned FSE_endOfDState(const FSE_DState_t* DStatePtr) >{ > return DStatePtr->state == 0; >} > > > >#ifndef FSE_COMMONDEFS_ONLY > >/* ************************************************************** >* Tuning parameters >****************************************************************/ >/*!MEMORY_USAGE : >* Memory usage formula : N->2^N Bytes (examples : 10 -> 1KB; 12 -> 4KB ; 16 -> 64KB; 20 -> 1MB; etc.) >* Increasing memory usage improves compression ratio >* Reduced memory usage can improve speed, due to cache effect >* Recommended max value is 14, for 16KB, which nicely fits into Intel x86 L1 cache */ >#ifndef FSE_MAX_MEMORY_USAGE ># define FSE_MAX_MEMORY_USAGE 14 >#endif ># 660 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/fse.h" >#ifndef FSE_DEFAULT_MEMORY_USAGE ># define FSE_DEFAULT_MEMORY_USAGE 13 >#endif ># 663 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/fse.h" > >/*!FSE_MAX_SYMBOL_VALUE : >* Maximum symbol value authorized. >* Required for proper stack allocation */ >#ifndef FSE_MAX_SYMBOL_VALUE ># define FSE_MAX_SYMBOL_VALUE 255 >#endif ># 670 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/fse.h" > >/* ************************************************************** >* template functions type & suffix >****************************************************************/ >#define FSE_FUNCTION_TYPE BYTE >#define FSE_FUNCTION_EXTENSION >#define FSE_DECODE_TYPE FSE_decode_t > > >#endif /* !FSE_COMMONDEFS_ONLY */ ># 680 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/fse.h" > > >/* *************************************************************** >* Constants >*****************************************************************/ >#define FSE_MAX_TABLELOG (FSE_MAX_MEMORY_USAGE-2) >#define FSE_MAX_TABLESIZE (1U<<FSE_MAX_TABLELOG) >#define FSE_MAXTABLESIZE_MASK (FSE_MAX_TABLESIZE-1) >#define FSE_DEFAULT_TABLELOG (FSE_DEFAULT_MEMORY_USAGE-2) >#define FSE_MIN_TABLELOG 5 > >#define FSE_TABLELOG_ABSOLUTE_MAX 15 >#if FSE_MAX_TABLELOG > FSE_TABLELOG_ABSOLUTE_MAX ># error "FSE_MAX_TABLELOG > FSE_TABLELOG_ABSOLUTE_MAX is not supported" >#endif ># 695 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/fse.h" > >#define FSE_TABLESTEP(tableSize) ((tableSize>>1) + (tableSize>>3) + 3) > > >#endif /* FSE_STATIC_LINKING_ONLY */ ># 700 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/fse.h" > > >#if defined (__cplusplus) >} >#endif ># 705 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/fse.h" ># 27 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.c" 2 >#define HUF_STATIC_LINKING_ONLY >#if 0 /* expanded by -frewrite-includes */ >#include "huf.h" >#endif /* expanded by -frewrite-includes */ ># 28 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.c" ># 1 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/huf.h" 1 >/* ****************************************************************** > Huffman coder, part of New Generation Entropy library > header file > Copyright (C) 2013-2016, Yann Collet. > > BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php) > > Redistribution and use in source and binary forms, with or without > modification, are permitted provided that the following conditions are > met: > > * Redistributions of source code must retain the above copyright > notice, this list of conditions and the following disclaimer. > * Redistributions in binary form must reproduce the above > copyright notice, this list of conditions and the following disclaimer > in the documentation and/or other materials provided with the > distribution. > > THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT > LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR > A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT > OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, > SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT > LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, > DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY > THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT > (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE > OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > > You can contact the author at : > - Source repository : https://github.com/Cyan4973/FiniteStateEntropy >****************************************************************** */ > >#if defined (__cplusplus) >extern "C" { >#endif ># 38 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/huf.h" > >#ifndef HUF_H_298734234 >#define HUF_H_298734234 > >/* *** Dependencies *** */ >#if 0 /* expanded by -frewrite-includes */ >#include <stddef.h> /* size_t */ >#endif /* expanded by -frewrite-includes */ ># 43 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/huf.h" ># 44 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/huf.h" > > >/* *** library symbols visibility *** */ >/* Note : when linking with -fvisibility=hidden on gcc, or by default on Visual, > * HUF symbols remain "private" (internal symbols for library only). > * Set macro FSE_DLL_EXPORT to 1 if you want HUF symbols visible on DLL interface */ >#if defined(FSE_DLL_EXPORT) && (FSE_DLL_EXPORT==1) && defined(__GNUC__) && (__GNUC__ >= 4) ># define HUF_PUBLIC_API __attribute__ ((visibility ("default"))) >#elif defined(FSE_DLL_EXPORT) && (FSE_DLL_EXPORT==1) /* Visual expected */ ># 53 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/huf.h" ># define HUF_PUBLIC_API __declspec(dllexport) >#elif defined(FSE_DLL_IMPORT) && (FSE_DLL_IMPORT==1) ># 55 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/huf.h" ># define HUF_PUBLIC_API __declspec(dllimport) /* not required, just to generate faster code (saves a function pointer load from IAT and an indirect jump) */ >#else ># 57 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/huf.h" ># define HUF_PUBLIC_API >#endif ># 59 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/huf.h" > > >/* *** simple functions *** */ >/** >HUF_compress() : > Compress content from buffer 'src', of size 'srcSize', into buffer 'dst'. > 'dst' buffer must be already allocated. > Compression runs faster if `dstCapacity` >= HUF_compressBound(srcSize). > `srcSize` must be <= `HUF_BLOCKSIZE_MAX` == 128 KB. > @return : size of compressed data (<= `dstCapacity`). > Special values : if return == 0, srcData is not compressible => Nothing is stored within dst !!! > if return == 1, srcData is a single repeated byte symbol (RLE compression). > if HUF_isError(return), compression failed (more details using HUF_getErrorName()) >*/ >HUF_PUBLIC_API size_t HUF_compress(void* dst, size_t dstCapacity, > const void* src, size_t srcSize); > >/** >HUF_decompress() : > Decompress HUF data from buffer 'cSrc', of size 'cSrcSize', > into already allocated buffer 'dst', of minimum size 'dstSize'. > `originalSize` : **must** be the ***exact*** size of original (uncompressed) data. > Note : in contrast with FSE, HUF_decompress can regenerate > RLE (cSrcSize==1) and uncompressed (cSrcSize==dstSize) data, > because it knows size to regenerate. > @return : size of regenerated data (== originalSize), > or an error code, which can be tested using HUF_isError() >*/ >HUF_PUBLIC_API size_t HUF_decompress(void* dst, size_t originalSize, > const void* cSrc, size_t cSrcSize); > > >/* *** Tool functions *** */ >#define HUF_BLOCKSIZE_MAX (128 * 1024) /**< maximum input size for a single block compressed with HUF_compress */ >HUF_PUBLIC_API size_t HUF_compressBound(size_t size); /**< maximum compressed size (worst case) */ > >/* Error Management */ >HUF_PUBLIC_API unsigned HUF_isError(size_t code); /**< tells if a return value is an error code */ >HUF_PUBLIC_API const char* HUF_getErrorName(size_t code); /**< provides error code string (useful for debugging) */ > > >/* *** Advanced function *** */ > >/** HUF_compress2() : > * Same as HUF_compress(), but offers direct control over `maxSymbolValue` and `tableLog`. > * `tableLog` must be `<= HUF_TABLELOG_MAX` . */ >HUF_PUBLIC_API size_t HUF_compress2 (void* dst, size_t dstCapacity, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog); > >/** HUF_compress4X_wksp() : > * Same as HUF_compress2(), but uses externally allocated `workSpace`. > * `workspace` must have minimum alignment of 4, and be at least as large as following macro */ >#define HUF_WORKSPACE_SIZE (6 << 10) >#define HUF_WORKSPACE_SIZE_U32 (HUF_WORKSPACE_SIZE / sizeof(U32)) >HUF_PUBLIC_API size_t HUF_compress4X_wksp (void* dst, size_t dstCapacity, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize); > >/** > * The minimum workspace size for the `workSpace` used in > * HUF_readDTableX2_wksp() and HUF_readDTableX4_wksp(). > * > * The space used depends on HUF_TABLELOG_MAX, ranging from ~1500 bytes when > * HUF_TABLE_LOG_MAX=12 to ~1850 bytes when HUF_TABLE_LOG_MAX=15. > * Buffer overflow errors may potentially occur if code modifications result in > * a required workspace size greater than that specified in the following > * macro. > */ >#define HUF_DECOMPRESS_WORKSPACE_SIZE (2 << 10) >#define HUF_DECOMPRESS_WORKSPACE_SIZE_U32 (HUF_DECOMPRESS_WORKSPACE_SIZE / sizeof(U32)) > >#endif /* HUF_H_298734234 */ ># 128 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/huf.h" > >/* ****************************************************************** > * WARNING !! > * The following section contains advanced and experimental definitions > * which shall never be used in the context of dll > * because they are not guaranteed to remain stable in the future. > * Only consider them in association with static linking. > *******************************************************************/ >#if defined(HUF_STATIC_LINKING_ONLY) && !defined(HUF_H_HUF_STATIC_LINKING_ONLY) >#define HUF_H_HUF_STATIC_LINKING_ONLY > >/* *** Dependencies *** */ >#if 0 /* expanded by -frewrite-includes */ >#include "mem.h" /* U32 */ >#endif /* expanded by -frewrite-includes */ ># 140 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/huf.h" ># 141 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/huf.h" > > >/* *** Constants *** */ >#define HUF_TABLELOG_MAX 12 /* max configured tableLog (for static allocation); can be modified up to HUF_ABSOLUTEMAX_TABLELOG */ >#define HUF_TABLELOG_DEFAULT 11 /* tableLog by default, when not specified */ >#define HUF_SYMBOLVALUE_MAX 255 > >#define HUF_TABLELOG_ABSOLUTEMAX 15 /* absolute limit of HUF_MAX_TABLELOG. Beyond that value, code does not work */ >#if (HUF_TABLELOG_MAX > HUF_TABLELOG_ABSOLUTEMAX) ># error "HUF_TABLELOG_MAX is too large !" >#endif ># 152 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/huf.h" > > >/* **************************************** >* Static allocation >******************************************/ >/* HUF buffer bounds */ >#define HUF_CTABLEBOUND 129 >#define HUF_BLOCKBOUND(size) (size + (size>>8) + 8) /* only true when incompressible is pre-filtered with fast heuristic */ >#define HUF_COMPRESSBOUND(size) (HUF_CTABLEBOUND + HUF_BLOCKBOUND(size)) /* Macro version, useful for static allocation */ > >/* static allocation of HUF's Compression Table */ >#define HUF_CTABLE_SIZE_U32(maxSymbolValue) ((maxSymbolValue)+1) /* Use tables of U32, for proper alignment */ >#define HUF_CTABLE_SIZE(maxSymbolValue) (HUF_CTABLE_SIZE_U32(maxSymbolValue) * sizeof(U32)) >#define HUF_CREATE_STATIC_CTABLE(name, maxSymbolValue) \ > U32 name##hb[HUF_CTABLE_SIZE_U32(maxSymbolValue)]; \ > void* name##hv = &(name##hb); \ > HUF_CElt* name = (HUF_CElt*)(name##hv) /* no final ; */ > >/* static allocation of HUF's DTable */ >typedef U32 HUF_DTable; >#define HUF_DTABLE_SIZE(maxTableLog) (1 + (1<<(maxTableLog))) >#define HUF_CREATE_STATIC_DTABLEX2(DTable, maxTableLog) \ > HUF_DTable DTable[HUF_DTABLE_SIZE((maxTableLog)-1)] = { ((U32)((maxTableLog)-1) * 0x01000001) } >#define HUF_CREATE_STATIC_DTABLEX4(DTable, maxTableLog) \ > HUF_DTable DTable[HUF_DTABLE_SIZE(maxTableLog)] = { ((U32)(maxTableLog) * 0x01000001) } > > >/* **************************************** >* Advanced decompression functions >******************************************/ >size_t HUF_decompress4X2 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< single-symbol decoder */ >size_t HUF_decompress4X4 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< double-symbols decoder */ > >size_t HUF_decompress4X_DCtx (HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< decodes RLE and uncompressed */ >size_t HUF_decompress4X_hufOnly(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< considers RLE and uncompressed as errors */ >size_t HUF_decompress4X_hufOnly_wksp(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize); /**< considers RLE and uncompressed as errors */ >size_t HUF_decompress4X2_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< single-symbol decoder */ >size_t HUF_decompress4X2_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize); /**< single-symbol decoder */ >size_t HUF_decompress4X4_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< double-symbols decoder */ >size_t HUF_decompress4X4_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize); /**< double-symbols decoder */ > > >/* **************************************** >* HUF detailed API >******************************************/ >/*! >HUF_compress() does the following: >1. count symbol occurrence from source[] into table count[] using FSE_count() >2. (optional) refine tableLog using HUF_optimalTableLog() >3. build Huffman table from count using HUF_buildCTable() >4. save Huffman table to memory buffer using HUF_writeCTable() >5. encode the data stream using HUF_compress4X_usingCTable() > >The following API allows targeting specific sub-functions for advanced tasks. >For example, it's possible to compress several blocks using the same 'CTable', >or to save and regenerate 'CTable' using external methods. >*/ >/* FSE_count() : find it within "fse.h" */ >unsigned HUF_optimalTableLog(unsigned maxTableLog, size_t srcSize, unsigned maxSymbolValue); >typedef struct HUF_CElt_s HUF_CElt; /* incomplete type */ >size_t HUF_buildCTable (HUF_CElt* CTable, const unsigned* count, unsigned maxSymbolValue, unsigned maxNbBits); >size_t HUF_writeCTable (void* dst, size_t maxDstSize, const HUF_CElt* CTable, unsigned maxSymbolValue, unsigned huffLog); >size_t HUF_compress4X_usingCTable(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable); > >typedef enum { > HUF_repeat_none, /**< Cannot use the previous table */ > HUF_repeat_check, /**< Can use the previous table but it must be checked. Note : The previous table must have been constructed by HUF_compress{1, 4}X_repeat */ > HUF_repeat_valid /**< Can use the previous table and it is asumed to be valid */ > } HUF_repeat; >/** HUF_compress4X_repeat() : >* Same as HUF_compress4X_wksp(), but considers using hufTable if *repeat != HUF_repeat_none. >* If it uses hufTable it does not modify hufTable or repeat. >* If it doesn't, it sets *repeat = HUF_repeat_none, and it sets hufTable to the table used. >* If preferRepeat then the old table will always be used if valid. */ >size_t HUF_compress4X_repeat(void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize, HUF_CElt* hufTable, HUF_repeat* repeat, int preferRepeat); /**< `workSpace` must be a table of at least HUF_WORKSPACE_SIZE_U32 unsigned */ > >/** HUF_buildCTable_wksp() : > * Same as HUF_buildCTable(), but using externally allocated scratch buffer. > * `workSpace` must be aligned on 4-bytes boundaries, and be at least as large as a table of 1024 unsigned. > */ >size_t HUF_buildCTable_wksp (HUF_CElt* tree, const U32* count, U32 maxSymbolValue, U32 maxNbBits, void* workSpace, size_t wkspSize); > >/*! HUF_readStats() : > Read compact Huffman tree, saved by HUF_writeCTable(). > `huffWeight` is destination buffer. > @return : size read from `src` , or an error Code . > Note : Needed by HUF_readCTable() and HUF_readDTableXn() . */ >size_t HUF_readStats(BYTE* huffWeight, size_t hwSize, U32* rankStats, > U32* nbSymbolsPtr, U32* tableLogPtr, > const void* src, size_t srcSize); > >/** HUF_readCTable() : >* Loading a CTable saved with HUF_writeCTable() */ >size_t HUF_readCTable (HUF_CElt* CTable, unsigned* maxSymbolValuePtr, const void* src, size_t srcSize); > > >/* >HUF_decompress() does the following: >1. select the decompression algorithm (X2, X4) based on pre-computed heuristics >2. build Huffman table from save, using HUF_readDTableXn() >3. decode 1 or 4 segments in parallel using HUF_decompressSXn_usingDTable >*/ > >/** HUF_selectDecoder() : >* Tells which decoder is likely to decode faster, >* based on a set of pre-determined metrics. >* @return : 0==HUF_decompress4X2, 1==HUF_decompress4X4 . >* Assumption : 0 < cSrcSize < dstSize <= 128 KB */ >U32 HUF_selectDecoder (size_t dstSize, size_t cSrcSize); > >size_t HUF_readDTableX2 (HUF_DTable* DTable, const void* src, size_t srcSize); >size_t HUF_readDTableX2_wksp (HUF_DTable* DTable, const void* src, size_t srcSize, void* workSpace, size_t wkspSize); >size_t HUF_readDTableX4 (HUF_DTable* DTable, const void* src, size_t srcSize); >size_t HUF_readDTableX4_wksp (HUF_DTable* DTable, const void* src, size_t srcSize, void* workSpace, size_t wkspSize); > >size_t HUF_decompress4X_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable); >size_t HUF_decompress4X2_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable); >size_t HUF_decompress4X4_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable); > > >/* single stream variants */ > >size_t HUF_compress1X (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog); >size_t HUF_compress1X_wksp (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize); /**< `workSpace` must be a table of at least HUF_WORKSPACE_SIZE_U32 unsigned */ >size_t HUF_compress1X_usingCTable(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable); >/** HUF_compress1X_repeat() : >* Same as HUF_compress1X_wksp(), but considers using hufTable if *repeat != HUF_repeat_none. >* If it uses hufTable it does not modify hufTable or repeat. >* If it doesn't, it sets *repeat = HUF_repeat_none, and it sets hufTable to the table used. >* If preferRepeat then the old table will always be used if valid. */ >size_t HUF_compress1X_repeat(void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize, HUF_CElt* hufTable, HUF_repeat* repeat, int preferRepeat); /**< `workSpace` must be a table of at least HUF_WORKSPACE_SIZE_U32 unsigned */ > >size_t HUF_decompress1X2 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /* single-symbol decoder */ >size_t HUF_decompress1X4 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /* double-symbol decoder */ > >size_t HUF_decompress1X_DCtx (HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); >size_t HUF_decompress1X_DCtx_wksp (HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize); >size_t HUF_decompress1X2_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< single-symbol decoder */ >size_t HUF_decompress1X2_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize); /**< single-symbol decoder */ >size_t HUF_decompress1X4_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< double-symbols decoder */ >size_t HUF_decompress1X4_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize); /**< double-symbols decoder */ > >size_t HUF_decompress1X_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable); /**< automatic selection of sing or double symbol decoder, based on DTable */ >size_t HUF_decompress1X2_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable); >size_t HUF_decompress1X4_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable); > >#endif /* HUF_STATIC_LINKING_ONLY */ ># 299 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/huf.h" > >#if defined (__cplusplus) >} >#endif ># 303 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/huf.h" ># 29 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.c" 2 >#if 0 /* expanded by -frewrite-includes */ >#include "zstd_compress.h" >#endif /* expanded by -frewrite-includes */ ># 29 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.c" ># 1 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.h" 1 >/* > * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. > * All rights reserved. > * > * This source code is licensed under both the BSD-style license (found in the > * LICENSE file in the root directory of this source tree) and the GPLv2 (found > * in the COPYING file in the root directory of this source tree). > * You may select, at your option, one of the above-listed licenses. > */ > > >#ifndef ZSTD_COMPRESS_H >#define ZSTD_COMPRESS_H > >/*-************************************* >* Dependencies >***************************************/ >#if 0 /* expanded by -frewrite-includes */ >#include "zstd_internal.h" >#endif /* expanded by -frewrite-includes */ ># 18 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.h" ># 1 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_internal.h" 1 >/* > * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. > * All rights reserved. > * > * This source code is licensed under both the BSD-style license (found in the > * LICENSE file in the root directory of this source tree) and the GPLv2 (found > * in the COPYING file in the root directory of this source tree). > * You may select, at your option, one of the above-listed licenses. > */ > >#ifndef ZSTD_CCOMMON_H_MODULE >#define ZSTD_CCOMMON_H_MODULE > > >/*-************************************* >* Dependencies >***************************************/ >#if 0 /* expanded by -frewrite-includes */ >#include "compiler.h" >#endif /* expanded by -frewrite-includes */ ># 18 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_internal.h" ># 1 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/compiler.h" 1 >/* > * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. > * All rights reserved. > * > * This source code is licensed under both the BSD-style license (found in the > * LICENSE file in the root directory of this source tree) and the GPLv2 (found > * in the COPYING file in the root directory of this source tree). > * You may select, at your option, one of the above-listed licenses. > */ > >#ifndef ZSTD_COMPILER_H >#define ZSTD_COMPILER_H > >/*-******************************************************* >* Compiler specifics >*********************************************************/ >/* force inlining */ >#if defined (__GNUC__) || defined(__cplusplus) || defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */ ># define INLINE_KEYWORD inline >#else ># 21 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/compiler.h" ># define INLINE_KEYWORD >#endif ># 23 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/compiler.h" > >#if defined(__GNUC__) ># define FORCE_INLINE_ATTR __attribute__((always_inline)) >#elif defined(_MSC_VER) ># 27 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/compiler.h" ># define FORCE_INLINE_ATTR __forceinline >#else ># 29 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/compiler.h" ># define FORCE_INLINE_ATTR >#endif ># 31 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/compiler.h" > >/** > * FORCE_INLINE_TEMPLATE is used to define C "templates", which take constant > * parameters. They must be inlined for the compiler to elimininate the constant > * branches. > */ >#define FORCE_INLINE_TEMPLATE static INLINE_KEYWORD FORCE_INLINE_ATTR >/** > * HINT_INLINE is used to help the compiler generate better code. It is *not* > * used for "templates", so it can be tweaked based on the compilers > * performance. > * > * gcc-4.8 and gcc-4.9 have been shown to benefit from leaving off the > * always_inline attribute. > * > * clang up to 5.0.0 (trunk) benefit tremendously from the always_inline > * attribute. > */ >#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 8 && __GNUC__ < 5 ># define HINT_INLINE static INLINE_KEYWORD >#else ># 52 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/compiler.h" ># define HINT_INLINE static INLINE_KEYWORD FORCE_INLINE_ATTR >#endif ># 54 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/compiler.h" > >/* force no inlining */ >#ifdef _MSC_VER ># define FORCE_NOINLINE static __declspec(noinline) >#else ># 59 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/compiler.h" ># ifdef __GNUC__ ># define FORCE_NOINLINE static __attribute__((__noinline__)) ># else ># 62 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/compiler.h" ># define FORCE_NOINLINE static ># endif ># 64 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/compiler.h" >#endif ># 65 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/compiler.h" > >/* prefetch */ >#if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_I86)) /* _mm_prefetch() is not defined outside of x86/x64 */ >#if 0 /* expanded by -frewrite-includes */ ># include <mmintrin.h> /* https://msdn.microsoft.com/fr-fr/library/84szxsww(v=vs.90).aspx */ >#endif /* expanded by -frewrite-includes */ ># 68 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/compiler.h" ># 69 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/compiler.h" ># define PREFETCH(ptr) _mm_prefetch((const char*)ptr, _MM_HINT_T0) >#elif defined(__GNUC__) ># 71 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/compiler.h" ># define PREFETCH(ptr) __builtin_prefetch(ptr, 0, 0) >#else ># 73 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/compiler.h" ># define PREFETCH(ptr) /* disabled */ >#endif ># 75 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/compiler.h" > >/* disable warnings */ >#ifdef _MSC_VER /* Visual Studio */ >#if 0 /* expanded by -frewrite-includes */ ># include <intrin.h> /* For Visual 2005 */ >#endif /* expanded by -frewrite-includes */ ># 78 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/compiler.h" ># 79 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/compiler.h" ># pragma warning(disable : 4100) /* disable: C4100: unreferenced formal parameter */ ># pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */ ># pragma warning(disable : 4204) /* disable: C4204: non-constant aggregate initializer */ ># pragma warning(disable : 4214) /* disable: C4214: non-int bitfields */ ># pragma warning(disable : 4324) /* disable: C4324: padded structure */ >#endif ># 85 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/compiler.h" > >#endif /* ZSTD_COMPILER_H */ ># 87 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/compiler.h" ># 19 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_internal.h" 2 >#if 0 /* expanded by -frewrite-includes */ >#include "mem.h" >#endif /* expanded by -frewrite-includes */ ># 19 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_internal.h" ># 20 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_internal.h" >#if 0 /* expanded by -frewrite-includes */ >#include "error_private.h" >#endif /* expanded by -frewrite-includes */ ># 20 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_internal.h" ># 21 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_internal.h" >#define ZSTD_STATIC_LINKING_ONLY >#if 0 /* expanded by -frewrite-includes */ >#include "zstd.h" >#endif /* expanded by -frewrite-includes */ ># 22 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_internal.h" ># 1 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/zstd.h" 1 >/* > * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. > * All rights reserved. > * > * This source code is licensed under both the BSD-style license (found in the > * LICENSE file in the root directory of this source tree) and the GPLv2 (found > * in the COPYING file in the root directory of this source tree). > * You may select, at your option, one of the above-listed licenses. > */ >#if defined (__cplusplus) >extern "C" { >#endif ># 13 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/zstd.h" > >#ifndef ZSTD_H_235446 >#define ZSTD_H_235446 > >/* ====== Dependency ======*/ >#if 0 /* expanded by -frewrite-includes */ >#include <stddef.h> /* size_t */ >#endif /* expanded by -frewrite-includes */ ># 18 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/zstd.h" ># 19 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/zstd.h" > > >/* ===== ZSTDLIB_API : control library symbols visibility ===== */ >#ifndef ZSTDLIB_VISIBILITY ># if defined(__GNUC__) && (__GNUC__ >= 4) ># define ZSTDLIB_VISIBILITY __attribute__ ((visibility ("default"))) ># else ># 26 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/zstd.h" ># define ZSTDLIB_VISIBILITY ># endif ># 28 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/zstd.h" >#endif ># 29 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/zstd.h" >#if defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1) ># define ZSTDLIB_API __declspec(dllexport) ZSTDLIB_VISIBILITY >#elif defined(ZSTD_DLL_IMPORT) && (ZSTD_DLL_IMPORT==1) ># 32 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/zstd.h" ># define ZSTDLIB_API __declspec(dllimport) ZSTDLIB_VISIBILITY /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/ >#else ># 34 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/zstd.h" ># define ZSTDLIB_API ZSTDLIB_VISIBILITY >#endif ># 36 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/zstd.h" > > >/******************************************************************************************************* > Introduction > > zstd, short for Zstandard, is a fast lossless compression algorithm, > targeting real-time compression scenarios at zlib-level and better compression ratios. > The zstd compression library provides in-memory compression and decompression functions. > The library supports compression levels from 1 up to ZSTD_maxCLevel() which is currently 22. > Levels >= 20, labeled `--ultra`, should be used with caution, as they require more memory. > Compression can be done in: > - a single step (described as Simple API) > - a single step, reusing a context (described as Explicit memory management) > - unbounded multiple steps (described as Streaming compression) > The compression ratio achievable on small data can be highly improved using a dictionary in: > - a single step (described as Simple dictionary API) > - a single step, reusing a dictionary (described as Fast dictionary API) > > Advanced experimental functions can be accessed using #define ZSTD_STATIC_LINKING_ONLY before including zstd.h. > Advanced experimental APIs shall never be used with a dynamic library. > They are not "stable", their definition may change in the future. Only static linking is allowed. >*********************************************************************************************************/ > >/*------ Version ------*/ >#define ZSTD_VERSION_MAJOR 1 >#define ZSTD_VERSION_MINOR 3 >#define ZSTD_VERSION_RELEASE 2 > >#define ZSTD_VERSION_NUMBER (ZSTD_VERSION_MAJOR *100*100 + ZSTD_VERSION_MINOR *100 + ZSTD_VERSION_RELEASE) >ZSTDLIB_API unsigned ZSTD_versionNumber(void); /**< useful to check dll version */ > >#define ZSTD_LIB_VERSION ZSTD_VERSION_MAJOR.ZSTD_VERSION_MINOR.ZSTD_VERSION_RELEASE >#define ZSTD_QUOTE(str) #str >#define ZSTD_EXPAND_AND_QUOTE(str) ZSTD_QUOTE(str) >#define ZSTD_VERSION_STRING ZSTD_EXPAND_AND_QUOTE(ZSTD_LIB_VERSION) >ZSTDLIB_API const char* ZSTD_versionString(void); /* v1.3.0 */ > > >/*************************************** >* Simple API >***************************************/ >/*! ZSTD_compress() : > * Compresses `src` content as a single zstd compressed frame into already allocated `dst`. > * Hint : compression runs faster if `dstCapacity` >= `ZSTD_compressBound(srcSize)`. > * @return : compressed size written into `dst` (<= `dstCapacity), > * or an error code if it fails (which can be tested using ZSTD_isError()). */ >ZSTDLIB_API size_t ZSTD_compress( void* dst, size_t dstCapacity, > const void* src, size_t srcSize, > int compressionLevel); > >/*! ZSTD_decompress() : > * `compressedSize` : must be the _exact_ size of some number of compressed and/or skippable frames. > * `dstCapacity` is an upper bound of originalSize to regenerate. > * If user cannot imply a maximum upper bound, it's better to use streaming mode to decompress data. > * @return : the number of bytes decompressed into `dst` (<= `dstCapacity`), > * or an errorCode if it fails (which can be tested using ZSTD_isError()). */ >ZSTDLIB_API size_t ZSTD_decompress( void* dst, size_t dstCapacity, > const void* src, size_t compressedSize); > >/*! ZSTD_getFrameContentSize() : v1.3.0 > * `src` should point to the start of a ZSTD encoded frame. > * `srcSize` must be at least as large as the frame header. > * hint : any size >= `ZSTD_frameHeaderSize_max` is large enough. > * @return : - decompressed size of the frame in `src`, if known > * - ZSTD_CONTENTSIZE_UNKNOWN if the size cannot be determined > * - ZSTD_CONTENTSIZE_ERROR if an error occurred (e.g. invalid magic number, srcSize too small) > * note 1 : a 0 return value means the frame is valid but "empty". > * note 2 : decompressed size is an optional field, it may not be present, typically in streaming mode. > * When `return==ZSTD_CONTENTSIZE_UNKNOWN`, data to decompress could be any size. > * In which case, it's necessary to use streaming mode to decompress data. > * Optionally, application can rely on some implicit limit, > * as ZSTD_decompress() only needs an upper bound of decompressed size. > * (For example, data could be necessarily cut into blocks <= 16 KB). > * note 3 : decompressed size is always present when compression is done with ZSTD_compress() > * note 4 : decompressed size can be very large (64-bits value), > * potentially larger than what local system can handle as a single memory segment. > * In which case, it's necessary to use streaming mode to decompress data. > * note 5 : If source is untrusted, decompressed size could be wrong or intentionally modified. > * Always ensure return value fits within application's authorized limits. > * Each application can set its own limits. > * note 6 : This function replaces ZSTD_getDecompressedSize() */ >#define ZSTD_CONTENTSIZE_UNKNOWN (0ULL - 1) >#define ZSTD_CONTENTSIZE_ERROR (0ULL - 2) >ZSTDLIB_API unsigned long long ZSTD_getFrameContentSize(const void *src, size_t srcSize); > >/*! ZSTD_getDecompressedSize() : > * NOTE: This function is now obsolete, in favor of ZSTD_getFrameContentSize(). > * Both functions work the same way, > * but ZSTD_getDecompressedSize() blends > * "empty", "unknown" and "error" results in the same return value (0), > * while ZSTD_getFrameContentSize() distinguishes them. > * > * 'src' is the start of a zstd compressed frame. > * @return : content size to be decompressed, as a 64-bits value _if known and not empty_, 0 otherwise. */ >ZSTDLIB_API unsigned long long ZSTD_getDecompressedSize(const void* src, size_t srcSize); > > >/*====== Helper functions ======*/ >#define ZSTD_COMPRESSBOUND(srcSize) ((srcSize) + ((srcSize)>>8) + (((srcSize) < 128 KB) ? ((128 KB - (srcSize)) >> 11) /* margin, from 64 to 0 */ : 0)) /* this formula ensures that bound(A) + bound(B) <= bound(A+B) as long as A and B >= 128 KB */ >ZSTDLIB_API size_t ZSTD_compressBound(size_t srcSize); /*!< maximum compressed size in worst case scenario */ >ZSTDLIB_API unsigned ZSTD_isError(size_t code); /*!< tells if a `size_t` function result is an error code */ >ZSTDLIB_API const char* ZSTD_getErrorName(size_t code); /*!< provides readable string from an error code */ >ZSTDLIB_API int ZSTD_maxCLevel(void); /*!< maximum compression level available */ > > >/*************************************** >* Explicit memory management >***************************************/ >/*= Compression context > * When compressing many times, > * it is recommended to allocate a context just once, and re-use it for each successive compression operation. > * This will make workload friendlier for system's memory. > * Use one context per thread for parallel execution in multi-threaded environments. */ >typedef struct ZSTD_CCtx_s ZSTD_CCtx; >ZSTDLIB_API ZSTD_CCtx* ZSTD_createCCtx(void); >ZSTDLIB_API size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx); > >/*! ZSTD_compressCCtx() : > * Same as ZSTD_compress(), requires an allocated ZSTD_CCtx (see ZSTD_createCCtx()). */ >ZSTDLIB_API size_t ZSTD_compressCCtx(ZSTD_CCtx* ctx, > void* dst, size_t dstCapacity, > const void* src, size_t srcSize, > int compressionLevel); > >/*= Decompression context > * When decompressing many times, > * it is recommended to allocate a context only once, > * and re-use it for each successive compression operation. > * This will make workload friendlier for system's memory. > * Use one context per thread for parallel execution. */ >typedef struct ZSTD_DCtx_s ZSTD_DCtx; >ZSTDLIB_API ZSTD_DCtx* ZSTD_createDCtx(void); >ZSTDLIB_API size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx); > >/*! ZSTD_decompressDCtx() : > * Same as ZSTD_decompress(), requires an allocated ZSTD_DCtx (see ZSTD_createDCtx()) */ >ZSTDLIB_API size_t ZSTD_decompressDCtx(ZSTD_DCtx* ctx, > void* dst, size_t dstCapacity, > const void* src, size_t srcSize); > > >/************************** >* Simple dictionary API >***************************/ >/*! ZSTD_compress_usingDict() : > * Compression using a predefined Dictionary (see dictBuilder/zdict.h). > * Note : This function loads the dictionary, resulting in significant startup delay. > * Note : When `dict == NULL || dictSize < 8` no dictionary is used. */ >ZSTDLIB_API size_t ZSTD_compress_usingDict(ZSTD_CCtx* ctx, > void* dst, size_t dstCapacity, > const void* src, size_t srcSize, > const void* dict,size_t dictSize, > int compressionLevel); > >/*! ZSTD_decompress_usingDict() : > * Decompression using a predefined Dictionary (see dictBuilder/zdict.h). > * Dictionary must be identical to the one used during compression. > * Note : This function loads the dictionary, resulting in significant startup delay. > * Note : When `dict == NULL || dictSize < 8` no dictionary is used. */ >ZSTDLIB_API size_t ZSTD_decompress_usingDict(ZSTD_DCtx* dctx, > void* dst, size_t dstCapacity, > const void* src, size_t srcSize, > const void* dict,size_t dictSize); > > >/********************************** > * Bulk processing dictionary API > *********************************/ >typedef struct ZSTD_CDict_s ZSTD_CDict; > >/*! ZSTD_createCDict() : > * When compressing multiple messages / blocks with the same dictionary, it's recommended to load it just once. > * ZSTD_createCDict() will create a digested dictionary, ready to start future compression operations without startup delay. > * ZSTD_CDict can be created once and shared by multiple threads concurrently, since its usage is read-only. > * `dictBuffer` can be released after ZSTD_CDict creation, since its content is copied within CDict */ >ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict(const void* dictBuffer, size_t dictSize, > int compressionLevel); > >/*! ZSTD_freeCDict() : > * Function frees memory allocated by ZSTD_createCDict(). */ >ZSTDLIB_API size_t ZSTD_freeCDict(ZSTD_CDict* CDict); > >/*! ZSTD_compress_usingCDict() : > * Compression using a digested Dictionary. > * Faster startup than ZSTD_compress_usingDict(), recommended when same dictionary is used multiple times. > * Note that compression level is decided during dictionary creation. > * Frame parameters are hardcoded (dictID=yes, contentSize=yes, checksum=no) */ >ZSTDLIB_API size_t ZSTD_compress_usingCDict(ZSTD_CCtx* cctx, > void* dst, size_t dstCapacity, > const void* src, size_t srcSize, > const ZSTD_CDict* cdict); > > >typedef struct ZSTD_DDict_s ZSTD_DDict; > >/*! ZSTD_createDDict() : > * Create a digested dictionary, ready to start decompression operation without startup delay. > * dictBuffer can be released after DDict creation, as its content is copied inside DDict */ >ZSTDLIB_API ZSTD_DDict* ZSTD_createDDict(const void* dictBuffer, size_t dictSize); > >/*! ZSTD_freeDDict() : > * Function frees memory allocated with ZSTD_createDDict() */ >ZSTDLIB_API size_t ZSTD_freeDDict(ZSTD_DDict* ddict); > >/*! ZSTD_decompress_usingDDict() : > * Decompression using a digested Dictionary. > * Faster startup than ZSTD_decompress_usingDict(), recommended when same dictionary is used multiple times. */ >ZSTDLIB_API size_t ZSTD_decompress_usingDDict(ZSTD_DCtx* dctx, > void* dst, size_t dstCapacity, > const void* src, size_t srcSize, > const ZSTD_DDict* ddict); > > >/**************************** >* Streaming >****************************/ > >typedef struct ZSTD_inBuffer_s { > const void* src; /**< start of input buffer */ > size_t size; /**< size of input buffer */ > size_t pos; /**< position where reading stopped. Will be updated. Necessarily 0 <= pos <= size */ >} ZSTD_inBuffer; > >typedef struct ZSTD_outBuffer_s { > void* dst; /**< start of output buffer */ > size_t size; /**< size of output buffer */ > size_t pos; /**< position where writing stopped. Will be updated. Necessarily 0 <= pos <= size */ >} ZSTD_outBuffer; > > > >/*-*********************************************************************** >* Streaming compression - HowTo >* >* A ZSTD_CStream object is required to track streaming operation. >* Use ZSTD_createCStream() and ZSTD_freeCStream() to create/release resources. >* ZSTD_CStream objects can be reused multiple times on consecutive compression operations. >* It is recommended to re-use ZSTD_CStream in situations where many streaming operations will be achieved consecutively, >* since it will play nicer with system's memory, by re-using already allocated memory. >* Use one separate ZSTD_CStream per thread for parallel execution. >* >* Start a new compression by initializing ZSTD_CStream. >* Use ZSTD_initCStream() to start a new compression operation. >* Use ZSTD_initCStream_usingDict() or ZSTD_initCStream_usingCDict() for a compression which requires a dictionary (experimental section) >* >* Use ZSTD_compressStream() repetitively to consume input stream. >* The function will automatically update both `pos` fields. >* Note that it may not consume the entire input, in which case `pos < size`, >* and it's up to the caller to present again remaining data. >* @return : a size hint, preferred nb of bytes to use as input for next function call >* or an error code, which can be tested using ZSTD_isError(). >* Note 1 : it's just a hint, to help latency a little, any other value will work fine. >* Note 2 : size hint is guaranteed to be <= ZSTD_CStreamInSize() >* >* At any moment, it's possible to flush whatever data remains within internal buffer, using ZSTD_flushStream(). >* `output->pos` will be updated. >* Note that some content might still be left within internal buffer if `output->size` is too small. >* @return : nb of bytes still present within internal buffer (0 if it's empty) >* or an error code, which can be tested using ZSTD_isError(). >* >* ZSTD_endStream() instructs to finish a frame. >* It will perform a flush and write frame epilogue. >* The epilogue is required for decoders to consider a frame completed. >* ZSTD_endStream() may not be able to flush full data if `output->size` is too small. >* In which case, call again ZSTD_endStream() to complete the flush. >* @return : 0 if frame fully completed and fully flushed, > or >0 if some data is still present within internal buffer > (value is minimum size estimation for remaining data to flush, but it could be more) >* or an error code, which can be tested using ZSTD_isError(). >* >* *******************************************************************/ > >typedef ZSTD_CCtx ZSTD_CStream; /**< CCtx and CStream are now effectively same object (>= v1.3.0) */ > /* Continue to distinguish them for compatibility with versions <= v1.2.0 */ >/*===== ZSTD_CStream management functions =====*/ >ZSTDLIB_API ZSTD_CStream* ZSTD_createCStream(void); >ZSTDLIB_API size_t ZSTD_freeCStream(ZSTD_CStream* zcs); > >/*===== Streaming compression functions =====*/ >ZSTDLIB_API size_t ZSTD_initCStream(ZSTD_CStream* zcs, int compressionLevel); >ZSTDLIB_API size_t ZSTD_compressStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output, ZSTD_inBuffer* input); >ZSTDLIB_API size_t ZSTD_flushStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output); >ZSTDLIB_API size_t ZSTD_endStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output); > >ZSTDLIB_API size_t ZSTD_CStreamInSize(void); /**< recommended size for input buffer */ >ZSTDLIB_API size_t ZSTD_CStreamOutSize(void); /**< recommended size for output buffer. Guarantee to successfully flush at least one complete compressed block in all circumstances. */ > > > >/*-*************************************************************************** >* Streaming decompression - HowTo >* >* A ZSTD_DStream object is required to track streaming operations. >* Use ZSTD_createDStream() and ZSTD_freeDStream() to create/release resources. >* ZSTD_DStream objects can be re-used multiple times. >* >* Use ZSTD_initDStream() to start a new decompression operation, >* or ZSTD_initDStream_usingDict() if decompression requires a dictionary. >* @return : recommended first input size >* >* Use ZSTD_decompressStream() repetitively to consume your input. >* The function will update both `pos` fields. >* If `input.pos < input.size`, some input has not been consumed. >* It's up to the caller to present again remaining data. >* If `output.pos < output.size`, decoder has flushed everything it could. >* @return : 0 when a frame is completely decoded and fully flushed, >* an error code, which can be tested using ZSTD_isError(), >* any other value > 0, which means there is still some decoding to do to complete current frame. >* The return value is a suggested next input size (a hint to improve latency) that will never load more than the current frame. >* *******************************************************************************/ > >typedef ZSTD_DCtx ZSTD_DStream; /**< DCtx and DStream are now effectively same object (>= v1.3.0) */ > /* Continue to distinguish them for compatibility with versions <= v1.2.0 */ >/*===== ZSTD_DStream management functions =====*/ >ZSTDLIB_API ZSTD_DStream* ZSTD_createDStream(void); >ZSTDLIB_API size_t ZSTD_freeDStream(ZSTD_DStream* zds); > >/*===== Streaming decompression functions =====*/ >ZSTDLIB_API size_t ZSTD_initDStream(ZSTD_DStream* zds); >ZSTDLIB_API size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inBuffer* input); > >ZSTDLIB_API size_t ZSTD_DStreamInSize(void); /*!< recommended size for input buffer */ >ZSTDLIB_API size_t ZSTD_DStreamOutSize(void); /*!< recommended size for output buffer. Guarantee to successfully flush at least one complete block in all circumstances. */ > >#endif /* ZSTD_H_235446 */ ># 361 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/zstd.h" > > > >/**************************************************************************************** > * START OF ADVANCED AND EXPERIMENTAL FUNCTIONS > * The definitions in this section are considered experimental. > * They should never be used with a dynamic library, as prototypes may change in the future. > * They are provided for advanced scenarios. > * Use them only in association with static linking. > * ***************************************************************************************/ > >#if defined(ZSTD_STATIC_LINKING_ONLY) && !defined(ZSTD_H_ZSTD_STATIC_LINKING_ONLY) >#define ZSTD_H_ZSTD_STATIC_LINKING_ONLY > >/* --- Constants ---*/ >#define ZSTD_MAGICNUMBER 0xFD2FB528 /* >= v0.8.0 */ >#define ZSTD_MAGIC_SKIPPABLE_START 0x184D2A50U >#define ZSTD_MAGIC_DICTIONARY 0xEC30A437 /* v0.7+ */ > >#define ZSTD_WINDOWLOG_MAX_32 30 >#define ZSTD_WINDOWLOG_MAX_64 31 >#define ZSTD_WINDOWLOG_MAX ((unsigned)(sizeof(size_t) == 4 ? ZSTD_WINDOWLOG_MAX_32 : ZSTD_WINDOWLOG_MAX_64)) >#define ZSTD_WINDOWLOG_MIN 10 >#define ZSTD_HASHLOG_MAX MIN(ZSTD_WINDOWLOG_MAX, 30) >#define ZSTD_HASHLOG_MIN 6 >#define ZSTD_CHAINLOG_MAX MIN(ZSTD_WINDOWLOG_MAX+1, 30) >#define ZSTD_CHAINLOG_MIN ZSTD_HASHLOG_MIN >#define ZSTD_HASHLOG3_MAX 17 >#define ZSTD_SEARCHLOG_MAX (ZSTD_WINDOWLOG_MAX-1) >#define ZSTD_SEARCHLOG_MIN 1 >#define ZSTD_SEARCHLENGTH_MAX 7 /* only for ZSTD_fast, other strategies are limited to 6 */ >#define ZSTD_SEARCHLENGTH_MIN 3 /* only for ZSTD_btopt, other strategies are limited to 4 */ >#define ZSTD_TARGETLENGTH_MIN 4 /* only useful for btopt */ >#define ZSTD_TARGETLENGTH_MAX 999 /* only useful for btopt */ >#define ZSTD_LDM_MINMATCH_MIN 4 >#define ZSTD_LDM_MINMATCH_MAX 4096 >#define ZSTD_LDM_BUCKETSIZELOG_MAX 8 > >#define ZSTD_FRAMEHEADERSIZE_PREFIX 5 /* minimum input size to know frame header size */ >#define ZSTD_FRAMEHEADERSIZE_MIN 6 >#define ZSTD_FRAMEHEADERSIZE_MAX 18 /* for static allocation */ >static const size_t ZSTD_frameHeaderSize_prefix = ZSTD_FRAMEHEADERSIZE_PREFIX; >static const size_t ZSTD_frameHeaderSize_min = ZSTD_FRAMEHEADERSIZE_MIN; >static const size_t ZSTD_frameHeaderSize_max = ZSTD_FRAMEHEADERSIZE_MAX; >static const size_t ZSTD_skippableHeaderSize = 8; /* magic number + skippable frame length */ > > >/*--- Advanced types ---*/ >typedef enum { ZSTD_fast=1, ZSTD_dfast, ZSTD_greedy, ZSTD_lazy, ZSTD_lazy2, > ZSTD_btlazy2, ZSTD_btopt, ZSTD_btultra } ZSTD_strategy; /* from faster to stronger */ > >typedef struct { > unsigned windowLog; /**< largest match distance : larger == more compression, more memory needed during decompression */ > unsigned chainLog; /**< fully searched segment : larger == more compression, slower, more memory (useless for fast) */ > unsigned hashLog; /**< dispatch table : larger == faster, more memory */ > unsigned searchLog; /**< nb of searches : larger == more compression, slower */ > unsigned searchLength; /**< match length searched : larger == faster decompression, sometimes less compression */ > unsigned targetLength; /**< acceptable match size for optimal parser (only) : larger == more compression, slower */ > ZSTD_strategy strategy; >} ZSTD_compressionParameters; > >typedef struct { > unsigned contentSizeFlag; /**< 1: content size will be in frame header (when known) */ > unsigned checksumFlag; /**< 1: generate a 32-bits checksum at end of frame, for error detection */ > unsigned noDictIDFlag; /**< 1: no dictID will be saved into frame header (if dictionary compression) */ >} ZSTD_frameParameters; > >typedef struct { > ZSTD_compressionParameters cParams; > ZSTD_frameParameters fParams; >} ZSTD_parameters; > >typedef struct ZSTD_CCtx_params_s ZSTD_CCtx_params; > >/*= Custom memory allocation functions */ >typedef void* (*ZSTD_allocFunction) (void* opaque, size_t size); >typedef void (*ZSTD_freeFunction) (void* opaque, void* address); >typedef struct { ZSTD_allocFunction customAlloc; ZSTD_freeFunction customFree; void* opaque; } ZSTD_customMem; >/* use this constant to defer to stdlib's functions */ >static const ZSTD_customMem ZSTD_defaultCMem = { NULL, NULL, NULL }; > > >/*************************************** >* Frame size functions >***************************************/ > >/*! ZSTD_findFrameCompressedSize() : > * `src` should point to the start of a ZSTD encoded frame or skippable frame > * `srcSize` must be at least as large as the frame > * @return : the compressed size of the first frame starting at `src`, > * suitable to pass to `ZSTD_decompress` or similar, > * or an error code if input is invalid */ >ZSTDLIB_API size_t ZSTD_findFrameCompressedSize(const void* src, size_t srcSize); > >/*! ZSTD_findDecompressedSize() : > * `src` should point the start of a series of ZSTD encoded and/or skippable frames > * `srcSize` must be the _exact_ size of this series > * (i.e. there should be a frame boundary exactly at `srcSize` bytes after `src`) > * @return : - decompressed size of all data in all successive frames > * - if the decompressed size cannot be determined: ZSTD_CONTENTSIZE_UNKNOWN > * - if an error occurred: ZSTD_CONTENTSIZE_ERROR > * > * note 1 : decompressed size is an optional field, that may not be present, especially in streaming mode. > * When `return==ZSTD_CONTENTSIZE_UNKNOWN`, data to decompress could be any size. > * In which case, it's necessary to use streaming mode to decompress data. > * note 2 : decompressed size is always present when compression is done with ZSTD_compress() > * note 3 : decompressed size can be very large (64-bits value), > * potentially larger than what local system can handle as a single memory segment. > * In which case, it's necessary to use streaming mode to decompress data. > * note 4 : If source is untrusted, decompressed size could be wrong or intentionally modified. > * Always ensure result fits within application's authorized limits. > * Each application can set its own limits. > * note 5 : ZSTD_findDecompressedSize handles multiple frames, and so it must traverse the input to > * read each contained frame header. This is fast as most of the data is skipped, > * however it does mean that all frame data must be present and valid. */ >ZSTDLIB_API unsigned long long ZSTD_findDecompressedSize(const void* src, size_t srcSize); > >/*! ZSTD_frameHeaderSize() : >* `src` should point to the start of a ZSTD frame >* `srcSize` must be >= ZSTD_frameHeaderSize_prefix. >* @return : size of the Frame Header */ >ZSTDLIB_API size_t ZSTD_frameHeaderSize(const void* src, size_t srcSize); > > >/*************************************** >* Context memory usage >***************************************/ > >/*! ZSTD_sizeof_*() : > * These functions give the current memory usage of selected object. > * Object memory usage can evolve when re-used multiple times. */ >ZSTDLIB_API size_t ZSTD_sizeof_CCtx(const ZSTD_CCtx* cctx); >ZSTDLIB_API size_t ZSTD_sizeof_DCtx(const ZSTD_DCtx* dctx); >ZSTDLIB_API size_t ZSTD_sizeof_CStream(const ZSTD_CStream* zcs); >ZSTDLIB_API size_t ZSTD_sizeof_DStream(const ZSTD_DStream* zds); >ZSTDLIB_API size_t ZSTD_sizeof_CDict(const ZSTD_CDict* cdict); >ZSTDLIB_API size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict); > >/*! ZSTD_estimate*() : > * These functions make it possible to estimate memory usage > * of a future {D,C}Ctx, before its creation. > * ZSTD_estimateCCtxSize() will provide a budget large enough for any compression level up to selected one. > * It will also consider src size to be arbitrarily "large", which is worst case. > * If srcSize is known to always be small, ZSTD_estimateCCtxSize_usingCParams() can provide a tighter estimation. > * ZSTD_estimateCCtxSize_usingCParams() can be used in tandem with ZSTD_getCParams() to create cParams from compressionLevel. > * ZSTD_estimateCCtxSize_usingCCtxParams() can be used in tandem with ZSTD_CCtxParam_setParameter(). Only single-threaded compression is supported. This function will return an error code if ZSTD_p_nbThreads is > 1. > * Note : CCtx estimation is only correct for single-threaded compression */ >ZSTDLIB_API size_t ZSTD_estimateCCtxSize(int compressionLevel); >ZSTDLIB_API size_t ZSTD_estimateCCtxSize_usingCParams(ZSTD_compressionParameters cParams); >ZSTDLIB_API size_t ZSTD_estimateCCtxSize_usingCCtxParams(const ZSTD_CCtx_params* params); >ZSTDLIB_API size_t ZSTD_estimateDCtxSize(void); > >/*! ZSTD_estimateCStreamSize() : > * ZSTD_estimateCStreamSize() will provide a budget large enough for any compression level up to selected one. > * It will also consider src size to be arbitrarily "large", which is worst case. > * If srcSize is known to always be small, ZSTD_estimateCStreamSize_usingCParams() can provide a tighter estimation. > * ZSTD_estimateCStreamSize_usingCParams() can be used in tandem with ZSTD_getCParams() to create cParams from compressionLevel. > * ZSTD_estimateCStreamSize_usingCCtxParams() can be used in tandem with ZSTD_CCtxParam_setParameter(). Only single-threaded compression is supported. This function will return an error code if ZSTD_p_nbThreads is set to a value > 1. > * Note : CStream estimation is only correct for single-threaded compression. > * ZSTD_DStream memory budget depends on window Size. > * This information can be passed manually, using ZSTD_estimateDStreamSize, > * or deducted from a valid frame Header, using ZSTD_estimateDStreamSize_fromFrame(); > * Note : if streaming is init with function ZSTD_init?Stream_usingDict(), > * an internal ?Dict will be created, which additional size is not estimated here. > * In this case, get total size by adding ZSTD_estimate?DictSize */ >ZSTDLIB_API size_t ZSTD_estimateCStreamSize(int compressionLevel); >ZSTDLIB_API size_t ZSTD_estimateCStreamSize_usingCParams(ZSTD_compressionParameters cParams); >ZSTDLIB_API size_t ZSTD_estimateCStreamSize_usingCCtxParams(const ZSTD_CCtx_params* params); >ZSTDLIB_API size_t ZSTD_estimateDStreamSize(size_t windowSize); >ZSTDLIB_API size_t ZSTD_estimateDStreamSize_fromFrame(const void* src, size_t srcSize); > >typedef enum { > ZSTD_dlm_byCopy = 0, /**< Copy dictionary content internally */ > ZSTD_dlm_byRef, /**< Reference dictionary content -- the dictionary buffer must outlive its users. */ >} ZSTD_dictLoadMethod_e; > >/*! ZSTD_estimate?DictSize() : > * ZSTD_estimateCDictSize() will bet that src size is relatively "small", and content is copied, like ZSTD_createCDict(). > * ZSTD_estimateCStreamSize_advanced_usingCParams() makes it possible to control precisely compression parameters, like ZSTD_createCDict_advanced(). > * Note : dictionary created by reference using ZSTD_dlm_byRef are smaller > */ >ZSTDLIB_API size_t ZSTD_estimateCDictSize(size_t dictSize, int compressionLevel); >ZSTDLIB_API size_t ZSTD_estimateCDictSize_advanced(size_t dictSize, ZSTD_compressionParameters cParams, ZSTD_dictLoadMethod_e dictLoadMethod); >ZSTDLIB_API size_t ZSTD_estimateDDictSize(size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod); > > >/*************************************** >* Advanced compression functions >***************************************/ >/*! ZSTD_createCCtx_advanced() : > * Create a ZSTD compression context using external alloc and free functions */ >ZSTDLIB_API ZSTD_CCtx* ZSTD_createCCtx_advanced(ZSTD_customMem customMem); > >/*! ZSTD_initStaticCCtx() : initialize a fixed-size zstd compression context > * workspace: The memory area to emplace the context into. > * Provided pointer must 8-bytes aligned. > * It must outlive context usage. > * workspaceSize: Use ZSTD_estimateCCtxSize() or ZSTD_estimateCStreamSize() > * to determine how large workspace must be to support scenario. > * @return : pointer to ZSTD_CCtx*, or NULL if error (size too small) > * Note : zstd will never resize nor malloc() when using a static cctx. > * If it needs more memory than available, it will simply error out. > * Note 2 : there is no corresponding "free" function. > * Since workspace was allocated externally, it must be freed externally too. > * Limitation 1 : currently not compatible with internal CDict creation, such as > * ZSTD_CCtx_loadDictionary() or ZSTD_initCStream_usingDict(). > * Limitation 2 : currently not compatible with multi-threading > */ >ZSTDLIB_API ZSTD_CCtx* ZSTD_initStaticCCtx(void* workspace, size_t workspaceSize); > > >/*! ZSTD_createCDict_byReference() : > * Create a digested dictionary for compression > * Dictionary content is simply referenced, and therefore stays in dictBuffer. > * It is important that dictBuffer outlives CDict, it must remain read accessible throughout the lifetime of CDict */ >ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict_byReference(const void* dictBuffer, size_t dictSize, int compressionLevel); > >typedef enum { ZSTD_dm_auto=0, /* dictionary is "full" if it starts with ZSTD_MAGIC_DICTIONARY, otherwise it is "rawContent" */ > ZSTD_dm_rawContent, /* ensures dictionary is always loaded as rawContent, even if it starts with ZSTD_MAGIC_DICTIONARY */ > ZSTD_dm_fullDict /* refuses to load a dictionary if it does not respect Zstandard's specification */ >} ZSTD_dictMode_e; >/*! ZSTD_createCDict_advanced() : > * Create a ZSTD_CDict using external alloc and free, and customized compression parameters */ >ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict_advanced(const void* dict, size_t dictSize, > ZSTD_dictLoadMethod_e dictLoadMethod, > ZSTD_dictMode_e dictMode, > ZSTD_compressionParameters cParams, > ZSTD_customMem customMem); > >/*! ZSTD_initStaticCDict_advanced() : > * Generate a digested dictionary in provided memory area. > * workspace: The memory area to emplace the dictionary into. > * Provided pointer must 8-bytes aligned. > * It must outlive dictionary usage. > * workspaceSize: Use ZSTD_estimateCDictSize() > * to determine how large workspace must be. > * cParams : use ZSTD_getCParams() to transform a compression level > * into its relevants cParams. > * @return : pointer to ZSTD_CDict*, or NULL if error (size too small) > * Note : there is no corresponding "free" function. > * Since workspace was allocated externally, it must be freed externally. > */ >ZSTDLIB_API ZSTD_CDict* ZSTD_initStaticCDict( > void* workspace, size_t workspaceSize, > const void* dict, size_t dictSize, > ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictMode_e dictMode, > ZSTD_compressionParameters cParams); > >/*! ZSTD_getCParams() : >* @return ZSTD_compressionParameters structure for a selected compression level and estimated srcSize. >* `estimatedSrcSize` value is optional, select 0 if not known */ >ZSTDLIB_API ZSTD_compressionParameters ZSTD_getCParams(int compressionLevel, unsigned long long estimatedSrcSize, size_t dictSize); > >/*! ZSTD_getParams() : >* same as ZSTD_getCParams(), but @return a full `ZSTD_parameters` object instead of sub-component `ZSTD_compressionParameters`. >* All fields of `ZSTD_frameParameters` are set to default (0) */ >ZSTDLIB_API ZSTD_parameters ZSTD_getParams(int compressionLevel, unsigned long long estimatedSrcSize, size_t dictSize); > >/*! ZSTD_checkCParams() : >* Ensure param values remain within authorized range */ >ZSTDLIB_API size_t ZSTD_checkCParams(ZSTD_compressionParameters params); > >/*! ZSTD_adjustCParams() : > * optimize params for a given `srcSize` and `dictSize`. > * both values are optional, select `0` if unknown. */ >ZSTDLIB_API ZSTD_compressionParameters ZSTD_adjustCParams(ZSTD_compressionParameters cPar, unsigned long long srcSize, size_t dictSize); > >/*! ZSTD_compress_advanced() : >* Same as ZSTD_compress_usingDict(), with fine-tune control over each compression parameter */ >ZSTDLIB_API size_t ZSTD_compress_advanced (ZSTD_CCtx* cctx, > void* dst, size_t dstCapacity, > const void* src, size_t srcSize, > const void* dict,size_t dictSize, > ZSTD_parameters params); > >/*! ZSTD_compress_usingCDict_advanced() : >* Same as ZSTD_compress_usingCDict(), with fine-tune control over frame parameters */ >ZSTDLIB_API size_t ZSTD_compress_usingCDict_advanced(ZSTD_CCtx* cctx, > void* dst, size_t dstCapacity, > const void* src, size_t srcSize, > const ZSTD_CDict* cdict, ZSTD_frameParameters fParams); > > >/*--- Advanced decompression functions ---*/ > >/*! ZSTD_isFrame() : > * Tells if the content of `buffer` starts with a valid Frame Identifier. > * Note : Frame Identifier is 4 bytes. If `size < 4`, @return will always be 0. > * Note 2 : Legacy Frame Identifiers are considered valid only if Legacy Support is enabled. > * Note 3 : Skippable Frame Identifiers are considered valid. */ >ZSTDLIB_API unsigned ZSTD_isFrame(const void* buffer, size_t size); > >/*! ZSTD_createDCtx_advanced() : > * Create a ZSTD decompression context using external alloc and free functions */ >ZSTDLIB_API ZSTD_DCtx* ZSTD_createDCtx_advanced(ZSTD_customMem customMem); > >/*! ZSTD_initStaticDCtx() : initialize a fixed-size zstd decompression context > * workspace: The memory area to emplace the context into. > * Provided pointer must 8-bytes aligned. > * It must outlive context usage. > * workspaceSize: Use ZSTD_estimateDCtxSize() or ZSTD_estimateDStreamSize() > * to determine how large workspace must be to support scenario. > * @return : pointer to ZSTD_DCtx*, or NULL if error (size too small) > * Note : zstd will never resize nor malloc() when using a static dctx. > * If it needs more memory than available, it will simply error out. > * Note 2 : static dctx is incompatible with legacy support > * Note 3 : there is no corresponding "free" function. > * Since workspace was allocated externally, it must be freed externally. > * Limitation : currently not compatible with internal DDict creation, > * such as ZSTD_initDStream_usingDict(). > */ >ZSTDLIB_API ZSTD_DCtx* ZSTD_initStaticDCtx(void* workspace, size_t workspaceSize); > >/*! ZSTD_createDDict_byReference() : > * Create a digested dictionary, ready to start decompression operation without startup delay. > * Dictionary content is referenced, and therefore stays in dictBuffer. > * It is important that dictBuffer outlives DDict, > * it must remain read accessible throughout the lifetime of DDict */ >ZSTDLIB_API ZSTD_DDict* ZSTD_createDDict_byReference(const void* dictBuffer, size_t dictSize); > >/*! ZSTD_createDDict_advanced() : > * Create a ZSTD_DDict using external alloc and free, optionally by reference */ >ZSTDLIB_API ZSTD_DDict* ZSTD_createDDict_advanced(const void* dict, size_t dictSize, > ZSTD_dictLoadMethod_e dictLoadMethod, > ZSTD_customMem customMem); > >/*! ZSTD_initStaticDDict() : > * Generate a digested dictionary in provided memory area. > * workspace: The memory area to emplace the dictionary into. > * Provided pointer must 8-bytes aligned. > * It must outlive dictionary usage. > * workspaceSize: Use ZSTD_estimateDDictSize() > * to determine how large workspace must be. > * @return : pointer to ZSTD_DDict*, or NULL if error (size too small) > * Note : there is no corresponding "free" function. > * Since workspace was allocated externally, it must be freed externally. > */ >ZSTDLIB_API ZSTD_DDict* ZSTD_initStaticDDict(void* workspace, size_t workspaceSize, > const void* dict, size_t dictSize, > ZSTD_dictLoadMethod_e dictLoadMethod); > >/*! ZSTD_getDictID_fromDict() : > * Provides the dictID stored within dictionary. > * if @return == 0, the dictionary is not conformant with Zstandard specification. > * It can still be loaded, but as a content-only dictionary. */ >ZSTDLIB_API unsigned ZSTD_getDictID_fromDict(const void* dict, size_t dictSize); > >/*! ZSTD_getDictID_fromDDict() : > * Provides the dictID of the dictionary loaded into `ddict`. > * If @return == 0, the dictionary is not conformant to Zstandard specification, or empty. > * Non-conformant dictionaries can still be loaded, but as content-only dictionaries. */ >ZSTDLIB_API unsigned ZSTD_getDictID_fromDDict(const ZSTD_DDict* ddict); > >/*! ZSTD_getDictID_fromFrame() : > * Provides the dictID required to decompressed the frame stored within `src`. > * If @return == 0, the dictID could not be decoded. > * This could for one of the following reasons : > * - The frame does not require a dictionary to be decoded (most common case). > * - The frame was built with dictID intentionally removed. Whatever dictionary is necessary is a hidden information. > * Note : this use case also happens when using a non-conformant dictionary. > * - `srcSize` is too small, and as a result, the frame header could not be decoded (only possible if `srcSize < ZSTD_FRAMEHEADERSIZE_MAX`). > * - This is not a Zstandard frame. > * When identifying the exact failure cause, it's possible to use ZSTD_getFrameHeader(), which will provide a more precise error code. */ >ZSTDLIB_API unsigned ZSTD_getDictID_fromFrame(const void* src, size_t srcSize); > > >/******************************************************************** >* Advanced streaming functions >********************************************************************/ > >/*===== Advanced Streaming compression functions =====*/ >ZSTDLIB_API ZSTD_CStream* ZSTD_createCStream_advanced(ZSTD_customMem customMem); >ZSTDLIB_API ZSTD_CStream* ZSTD_initStaticCStream(void* workspace, size_t workspaceSize); /**< same as ZSTD_initStaticCCtx() */ >ZSTDLIB_API size_t ZSTD_initCStream_srcSize(ZSTD_CStream* zcs, int compressionLevel, unsigned long long pledgedSrcSize); /**< pledgedSrcSize must be correct, a size of 0 means unknown. for a frame size of 0 use initCStream_advanced */ >ZSTDLIB_API size_t ZSTD_initCStream_usingDict(ZSTD_CStream* zcs, const void* dict, size_t dictSize, int compressionLevel); /**< creates of an internal CDict (incompatible with static CCtx), except if dict == NULL or dictSize < 8, in which case no dict is used. Note: dict is loaded with ZSTD_dm_auto (treated as a full zstd dictionary if it begins with ZSTD_MAGIC_DICTIONARY, else as raw content) and ZSTD_dlm_byCopy.*/ >ZSTDLIB_API size_t ZSTD_initCStream_advanced(ZSTD_CStream* zcs, const void* dict, size_t dictSize, > ZSTD_parameters params, unsigned long long pledgedSrcSize); /**< pledgedSrcSize is optional and can be 0 (meaning unknown). note: if the contentSizeFlag is set, pledgedSrcSize == 0 means the source size is actually 0. dict is loaded with ZSTD_dm_auto and ZSTD_dlm_byCopy. */ >ZSTDLIB_API size_t ZSTD_initCStream_usingCDict(ZSTD_CStream* zcs, const ZSTD_CDict* cdict); /**< note : cdict will just be referenced, and must outlive compression session */ >ZSTDLIB_API size_t ZSTD_initCStream_usingCDict_advanced(ZSTD_CStream* zcs, const ZSTD_CDict* cdict, ZSTD_frameParameters fParams, unsigned long long pledgedSrcSize); /**< same as ZSTD_initCStream_usingCDict(), with control over frame parameters */ > >/*! ZSTD_resetCStream() : > * start a new compression job, using same parameters from previous job. > * This is typically useful to skip dictionary loading stage, since it will re-use it in-place.. > * Note that zcs must be init at least once before using ZSTD_resetCStream(). > * pledgedSrcSize==0 means "srcSize unknown". > * If pledgedSrcSize > 0, its value must be correct, as it will be written in header, and controlled at the end. > * @return : 0, or an error code (which can be tested using ZSTD_isError()) */ >ZSTDLIB_API size_t ZSTD_resetCStream(ZSTD_CStream* zcs, unsigned long long pledgedSrcSize); > > >/*===== Advanced Streaming decompression functions =====*/ >ZSTDLIB_API ZSTD_DStream* ZSTD_createDStream_advanced(ZSTD_customMem customMem); >ZSTDLIB_API ZSTD_DStream* ZSTD_initStaticDStream(void* workspace, size_t workspaceSize); /**< same as ZSTD_initStaticDCtx() */ >typedef enum { DStream_p_maxWindowSize } ZSTD_DStreamParameter_e; >ZSTDLIB_API size_t ZSTD_setDStreamParameter(ZSTD_DStream* zds, ZSTD_DStreamParameter_e paramType, unsigned paramValue); /* obsolete : this API will be removed in a future version */ >ZSTDLIB_API size_t ZSTD_initDStream_usingDict(ZSTD_DStream* zds, const void* dict, size_t dictSize); /**< note: no dictionary will be used if dict == NULL or dictSize < 8 */ >ZSTDLIB_API size_t ZSTD_initDStream_usingDDict(ZSTD_DStream* zds, const ZSTD_DDict* ddict); /**< note : ddict is referenced, it must outlive decompression session */ >ZSTDLIB_API size_t ZSTD_resetDStream(ZSTD_DStream* zds); /**< re-use decompression parameters from previous init; saves dictionary loading */ > > >/********************************************************************* >* Buffer-less and synchronous inner streaming functions >* >* This is an advanced API, giving full control over buffer management, for users which need direct control over memory. >* But it's also a complex one, with several restrictions, documented below. >* Prefer normal streaming API for an easier experience. >********************************************************************* */ > >/** > Buffer-less streaming compression (synchronous mode) > > A ZSTD_CCtx object is required to track streaming operations. > Use ZSTD_createCCtx() / ZSTD_freeCCtx() to manage resource. > ZSTD_CCtx object can be re-used multiple times within successive compression operations. > > Start by initializing a context. > Use ZSTD_compressBegin(), or ZSTD_compressBegin_usingDict() for dictionary compression, > or ZSTD_compressBegin_advanced(), for finer parameter control. > It's also possible to duplicate a reference context which has already been initialized, using ZSTD_copyCCtx() > > Then, consume your input using ZSTD_compressContinue(). > There are some important considerations to keep in mind when using this advanced function : > - ZSTD_compressContinue() has no internal buffer. It uses externally provided buffers only. > - Interface is synchronous : input is consumed entirely and produces 1+ compressed blocks. > - Caller must ensure there is enough space in `dst` to store compressed data under worst case scenario. > Worst case evaluation is provided by ZSTD_compressBound(). > ZSTD_compressContinue() doesn't guarantee recover after a failed compression. > - ZSTD_compressContinue() presumes prior input ***is still accessible and unmodified*** (up to maximum distance size, see WindowLog). > It remembers all previous contiguous blocks, plus one separated memory segment (which can itself consists of multiple contiguous blocks) > - ZSTD_compressContinue() detects that prior input has been overwritten when `src` buffer overlaps. > In which case, it will "discard" the relevant memory section from its history. > > Finish a frame with ZSTD_compressEnd(), which will write the last block(s) and optional checksum. > It's possible to use srcSize==0, in which case, it will write a final empty block to end the frame. > Without last block mark, frames are considered unfinished (hence corrupted) by compliant decoders. > > `ZSTD_CCtx` object can be re-used (ZSTD_compressBegin()) to compress again. >*/ > >/*===== Buffer-less streaming compression functions =====*/ >ZSTDLIB_API size_t ZSTD_compressBegin(ZSTD_CCtx* cctx, int compressionLevel); >ZSTDLIB_API size_t ZSTD_compressBegin_usingDict(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, int compressionLevel); >ZSTDLIB_API size_t ZSTD_compressBegin_advanced(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, ZSTD_parameters params, unsigned long long pledgedSrcSize); /**< pledgedSrcSize is optional and can be 0 (meaning unknown). note: if the contentSizeFlag is set, pledgedSrcSize == 0 means the source size is actually 0 */ >ZSTDLIB_API size_t ZSTD_compressBegin_usingCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict); /**< note: fails if cdict==NULL */ >ZSTDLIB_API size_t ZSTD_compressBegin_usingCDict_advanced(ZSTD_CCtx* const cctx, const ZSTD_CDict* const cdict, ZSTD_frameParameters const fParams, unsigned long long const pledgedSrcSize); /* compression parameters are already set within cdict. pledgedSrcSize=0 means null-size */ >ZSTDLIB_API size_t ZSTD_copyCCtx(ZSTD_CCtx* cctx, const ZSTD_CCtx* preparedCCtx, unsigned long long pledgedSrcSize); /**< note: if pledgedSrcSize can be 0, indicating unknown size. if it is non-zero, it must be accurate. for 0 size frames, use compressBegin_advanced */ > >ZSTDLIB_API size_t ZSTD_compressContinue(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize); >ZSTDLIB_API size_t ZSTD_compressEnd(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize); > > >/*- > Buffer-less streaming decompression (synchronous mode) > > A ZSTD_DCtx object is required to track streaming operations. > Use ZSTD_createDCtx() / ZSTD_freeDCtx() to manage it. > A ZSTD_DCtx object can be re-used multiple times. > > First typical operation is to retrieve frame parameters, using ZSTD_getFrameHeader(). > Frame header is extracted from the beginning of compressed frame, so providing only the frame's beginning is enough. > Data fragment must be large enough to ensure successful decoding. > `ZSTD_frameHeaderSize_max` bytes is guaranteed to always be large enough. > @result : 0 : successful decoding, the `ZSTD_frameHeader` structure is correctly filled. > >0 : `srcSize` is too small, please provide at least @result bytes on next attempt. > errorCode, which can be tested using ZSTD_isError(). > > It fills a ZSTD_frameHeader structure with important information to correctly decode the frame, > such as the dictionary ID, content size, or maximum back-reference distance (`windowSize`). > Note that these values could be wrong, either because of data corruption, or because a 3rd party deliberately spoofs false information. > As a consequence, check that values remain within valid application range. > For example, do not allocate memory blindly, check that `windowSize` is within expectation. > Each application can set its own limits, depending on local restrictions. > For extended interoperability, it is recommended to support `windowSize` of at least 8 MB. > > ZSTD_decompressContinue() needs previous data blocks during decompression, up to `windowSize` bytes. > ZSTD_decompressContinue() is very sensitive to contiguity, > if 2 blocks don't follow each other, make sure that either the compressor breaks contiguity at the same place, > or that previous contiguous segment is large enough to properly handle maximum back-reference distance. > There are multiple ways to guarantee this condition. > > The most memory efficient way is to use a round buffer of sufficient size. > Sufficient size is determined by invoking ZSTD_decodingBufferSize_min(), > which can @return an error code if required value is too large for current system (in 32-bits mode). > In a round buffer methodology, ZSTD_decompressContinue() decompresses each block next to previous one, > up to the moment there is not enough room left in the buffer to guarantee decoding another full block, > which maximum size is provided in `ZSTD_frameHeader` structure, field `blockSizeMax`. > At which point, decoding can resume from the beginning of the buffer. > Note that already decoded data stored in the buffer should be flushed before being overwritten. > > There are alternatives possible, for example using two or more buffers of size `windowSize` each, though they consume more memory. > > Finally, if you control the compression process, you can also ignore all buffer size rules, > as long as the encoder and decoder progress in "lock-step", > aka use exactly the same buffer sizes, break contiguity at the same place, etc. > > Once buffers are setup, start decompression, with ZSTD_decompressBegin(). > If decompression requires a dictionary, use ZSTD_decompressBegin_usingDict() or ZSTD_decompressBegin_usingDDict(). > > Then use ZSTD_nextSrcSizeToDecompress() and ZSTD_decompressContinue() alternatively. > ZSTD_nextSrcSizeToDecompress() tells how many bytes to provide as 'srcSize' to ZSTD_decompressContinue(). > ZSTD_decompressContinue() requires this _exact_ amount of bytes, or it will fail. > > @result of ZSTD_decompressContinue() is the number of bytes regenerated within 'dst' (necessarily <= dstCapacity). > It can be zero : it just means ZSTD_decompressContinue() has decoded some metadata item. > It can also be an error code, which can be tested with ZSTD_isError(). > > A frame is fully decoded when ZSTD_nextSrcSizeToDecompress() returns zero. > Context can then be reset to start a new decompression. > > Note : it's possible to know if next input to present is a header or a block, using ZSTD_nextInputType(). > This information is not required to properly decode a frame. > > == Special case : skippable frames == > > Skippable frames allow integration of user-defined data into a flow of concatenated frames. > Skippable frames will be ignored (skipped) by decompressor. > The format of skippable frames is as follows : > a) Skippable frame ID - 4 Bytes, Little endian format, any value from 0x184D2A50 to 0x184D2A5F > b) Frame Size - 4 Bytes, Little endian format, unsigned 32-bits > c) Frame Content - any content (User Data) of length equal to Frame Size > For skippable frames ZSTD_getFrameHeader() returns zfhPtr->frameType==ZSTD_skippableFrame. > For skippable frames ZSTD_decompressContinue() always returns 0 : it only skips the content. >*/ > >/*===== Buffer-less streaming decompression functions =====*/ >typedef enum { ZSTD_frame, ZSTD_skippableFrame } ZSTD_frameType_e; >typedef struct { > unsigned long long frameContentSize; /* if == ZSTD_CONTENTSIZE_UNKNOWN, it means this field is not available. 0 means "empty" */ > unsigned long long windowSize; /* can be very large, up to <= frameContentSize */ > unsigned blockSizeMax; > ZSTD_frameType_e frameType; /* if == ZSTD_skippableFrame, frameContentSize is the size of skippable content */ > unsigned headerSize; > unsigned dictID; > unsigned checksumFlag; >} ZSTD_frameHeader; >ZSTDLIB_API size_t ZSTD_getFrameHeader(ZSTD_frameHeader* zfhPtr, const void* src, size_t srcSize); /**< doesn't consume input */ >ZSTDLIB_API size_t ZSTD_decodingBufferSize_min(unsigned long long windowSize, unsigned long long frameContentSize); /**< when frame content size is not known, pass in frameContentSize == ZSTD_CONTENTSIZE_UNKNOWN */ > >ZSTDLIB_API size_t ZSTD_decompressBegin(ZSTD_DCtx* dctx); >ZSTDLIB_API size_t ZSTD_decompressBegin_usingDict(ZSTD_DCtx* dctx, const void* dict, size_t dictSize); >ZSTDLIB_API size_t ZSTD_decompressBegin_usingDDict(ZSTD_DCtx* dctx, const ZSTD_DDict* ddict); > >ZSTDLIB_API size_t ZSTD_nextSrcSizeToDecompress(ZSTD_DCtx* dctx); >ZSTDLIB_API size_t ZSTD_decompressContinue(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize); > >/* misc */ >ZSTDLIB_API void ZSTD_copyDCtx(ZSTD_DCtx* dctx, const ZSTD_DCtx* preparedDCtx); >typedef enum { ZSTDnit_frameHeader, ZSTDnit_blockHeader, ZSTDnit_block, ZSTDnit_lastBlock, ZSTDnit_checksum, ZSTDnit_skippableFrame } ZSTD_nextInputType_e; >ZSTDLIB_API ZSTD_nextInputType_e ZSTD_nextInputType(ZSTD_DCtx* dctx); > > > >/* ============================================ */ >/** New advanced API (experimental) */ >/* ============================================ */ > >/* notes on API design : > * In this proposal, parameters are pushed one by one into an existing context, > * and then applied on all subsequent compression jobs. > * When no parameter is ever provided, CCtx is created with compression level ZSTD_CLEVEL_DEFAULT. > * > * This API is intended to replace all others experimental API. > * It can basically do all other use cases, and even new ones. > * In constrast with _advanced() variants, it stands a reasonable chance to become "stable", > * after a good testing period. > */ > >/* note on naming convention : > * Initially, the API favored names like ZSTD_setCCtxParameter() . > * In this proposal, convention is changed towards ZSTD_CCtx_setParameter() . > * The main driver is that it identifies more clearly the target object type. > * It feels clearer when considering multiple targets : > * ZSTD_CDict_setParameter() (rather than ZSTD_setCDictParameter()) > * ZSTD_CCtxParams_setParameter() (rather than ZSTD_setCCtxParamsParameter() ) > * etc... > */ > >/* note on enum design : > * All enum will be pinned to explicit values before reaching "stable API" status */ > >typedef enum { > /* Question : should we have a format ZSTD_f_auto ? > * For the time being, it would mean exactly the same as ZSTD_f_zstd1. > * But, in the future, should several formats be supported, > * on the compression side, it would mean "default format". > * On the decompression side, it would mean "multi format", > * and ZSTD_f_zstd1 could be reserved to mean "accept *only* zstd frames". > * Since meaning is a little different, another option could be to define different enums for compression and decompression. > * This question could be kept for later, when there are actually multiple formats to support, > * but there is also the question of pinning enum values, and pinning value `0` is especially important */ > ZSTD_f_zstd1 = 0, /* zstd frame format, specified in zstd_compression_format.md (default) */ > ZSTD_f_zstd1_magicless, /* Variant of zstd frame format, without initial 4-bytes magic number. > * Useful to save 4 bytes per generated frame. > * Decoder cannot recognise automatically this format, requiring instructions. */ >} ZSTD_format_e; > >typedef enum { > /* compression format */ > ZSTD_p_format = 10, /* See ZSTD_format_e enum definition. > * Cast selected format as unsigned for ZSTD_CCtx_setParameter() compatibility. */ > > /* compression parameters */ > ZSTD_p_compressionLevel=100, /* Update all compression parameters according to pre-defined cLevel table > * Default level is ZSTD_CLEVEL_DEFAULT==3. > * Special: value 0 means "do not change cLevel". */ > ZSTD_p_windowLog, /* Maximum allowed back-reference distance, expressed as power of 2. > * Must be clamped between ZSTD_WINDOWLOG_MIN and ZSTD_WINDOWLOG_MAX. > * Special: value 0 means "do not change windowLog". > * Note: Using a window size greater than ZSTD_MAXWINDOWSIZE_DEFAULT (default: 2^27) > * requires setting the maximum window size at least as large during decompression. */ > ZSTD_p_hashLog, /* Size of the probe table, as a power of 2. > * Resulting table size is (1 << (hashLog+2)). > * Must be clamped between ZSTD_HASHLOG_MIN and ZSTD_HASHLOG_MAX. > * Larger tables improve compression ratio of strategies <= dFast, > * and improve speed of strategies > dFast. > * Special: value 0 means "do not change hashLog". */ > ZSTD_p_chainLog, /* Size of the full-search table, as a power of 2. > * Resulting table size is (1 << (chainLog+2)). > * Larger tables result in better and slower compression. > * This parameter is useless when using "fast" strategy. > * Special: value 0 means "do not change chainLog". */ > ZSTD_p_searchLog, /* Number of search attempts, as a power of 2. > * More attempts result in better and slower compression. > * This parameter is useless when using "fast" and "dFast" strategies. > * Special: value 0 means "do not change searchLog". */ > ZSTD_p_minMatch, /* Minimum size of searched matches (note : repCode matches can be smaller). > * Larger values make faster compression and decompression, but decrease ratio. > * Must be clamped between ZSTD_SEARCHLENGTH_MIN and ZSTD_SEARCHLENGTH_MAX. > * Note that currently, for all strategies < btopt, effective minimum is 4. > * Note that currently, for all strategies > fast, effective maximum is 6. > * Special: value 0 means "do not change minMatchLength". */ > ZSTD_p_targetLength, /* Only useful for strategies >= btopt. > * Length of Match considered "good enough" to stop search. > * Larger values make compression stronger and slower. > * Special: value 0 means "do not change targetLength". */ > ZSTD_p_compressionStrategy, /* See ZSTD_strategy enum definition. > * Cast selected strategy as unsigned for ZSTD_CCtx_setParameter() compatibility. > * The higher the value of selected strategy, the more complex it is, > * resulting in stronger and slower compression. > * Special: value 0 means "do not change strategy". */ > > /* frame parameters */ > ZSTD_p_contentSizeFlag=200, /* Content size is written into frame header _whenever known_ (default:1) > * note that content size must be known at the beginning, > * it is sent using ZSTD_CCtx_setPledgedSrcSize() */ > ZSTD_p_checksumFlag, /* A 32-bits checksum of content is written at end of frame (default:0) */ > ZSTD_p_dictIDFlag, /* When applicable, dictID of dictionary is provided in frame header (default:1) */ > > /* multi-threading parameters */ > ZSTD_p_nbThreads=400, /* Select how many threads a compression job can spawn (default:1) > * More threads improve speed, but also increase memory usage. > * Can only receive a value > 1 if ZSTD_MULTITHREAD is enabled. > * Special: value 0 means "do not change nbThreads" */ > ZSTD_p_jobSize, /* Size of a compression job. Each compression job is completed in parallel. > * 0 means default, which is dynamically determined based on compression parameters. > * Job size must be a minimum of overlapSize, or 1 KB, whichever is largest > * The minimum size is automatically and transparently enforced */ > ZSTD_p_overlapSizeLog, /* Size of previous input reloaded at the beginning of each job. > * 0 => no overlap, 6(default) => use 1/8th of windowSize, >=9 => use full windowSize */ > > /* advanced parameters - may not remain available after API update */ > ZSTD_p_forceMaxWindow=1100, /* Force back-reference distances to remain < windowSize, > * even when referencing into Dictionary content (default:0) */ > ZSTD_p_enableLongDistanceMatching=1200, /* Enable long distance matching. > * This parameter is designed to improve the compression > * ratio for large inputs with long distance matches. > * This increases the memory usage as well as window size. > * Note: setting this parameter sets all the LDM parameters > * as well as ZSTD_p_windowLog. It should be set after > * ZSTD_p_compressionLevel and before ZSTD_p_windowLog and > * other LDM parameters. Setting the compression level > * after this parameter overrides the window log, though LDM > * will remain enabled until explicitly disabled. */ > ZSTD_p_ldmHashLog, /* Size of the table for long distance matching, as a power of 2. > * Larger values increase memory usage and compression ratio, but decrease > * compression speed. > * Must be clamped between ZSTD_HASHLOG_MIN and ZSTD_HASHLOG_MAX > * (default: windowlog - 7). */ > ZSTD_p_ldmMinMatch, /* Minimum size of searched matches for long distance matcher. > * Larger/too small values usually decrease compression ratio. > * Must be clamped between ZSTD_LDM_MINMATCH_MIN > * and ZSTD_LDM_MINMATCH_MAX (default: 64). */ > ZSTD_p_ldmBucketSizeLog, /* Log size of each bucket in the LDM hash table for collision resolution. > * Larger values usually improve collision resolution but may decrease > * compression speed. > * The maximum value is ZSTD_LDM_BUCKETSIZELOG_MAX (default: 3). */ > ZSTD_p_ldmHashEveryLog, /* Frequency of inserting/looking up entries in the LDM hash table. > * The default is MAX(0, (windowLog - ldmHashLog)) to > * optimize hash table usage. > * Larger values improve compression speed. Deviating far from the > * default value will likely result in a decrease in compression ratio. > * Must be clamped between 0 and ZSTD_WINDOWLOG_MAX - ZSTD_HASHLOG_MIN. */ > >} ZSTD_cParameter; > > >/*! ZSTD_CCtx_setParameter() : > * Set one compression parameter, selected by enum ZSTD_cParameter. > * Note : when `value` is an enum, cast it to unsigned for proper type checking. > * @result : 0, or an error code (which can be tested with ZSTD_isError()). */ >ZSTDLIB_API size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, unsigned value); > >/*! ZSTD_CCtx_setPledgedSrcSize() : > * Total input data size to be compressed as a single frame. > * This value will be controlled at the end, and result in error if not respected. > * @result : 0, or an error code (which can be tested with ZSTD_isError()). > * Note 1 : 0 means zero, empty. > * In order to mean "unknown content size", pass constant ZSTD_CONTENTSIZE_UNKNOWN. > * Note that ZSTD_CONTENTSIZE_UNKNOWN is default value for new compression jobs. > * Note 2 : If all data is provided and consumed in a single round, > * this value is overriden by srcSize instead. */ >ZSTDLIB_API size_t ZSTD_CCtx_setPledgedSrcSize(ZSTD_CCtx* cctx, unsigned long long pledgedSrcSize); > >/*! ZSTD_CCtx_loadDictionary() : > * Create an internal CDict from dict buffer. > * Decompression will have to use same buffer. > * @result : 0, or an error code (which can be tested with ZSTD_isError()). > * Special : Adding a NULL (or 0-size) dictionary invalidates any previous dictionary, > * meaning "return to no-dictionary mode". > * Note 1 : `dict` content will be copied internally. Use > * ZSTD_CCtx_loadDictionary_byReference() to reference dictionary > * content instead. The dictionary buffer must then outlive its > * users. > * Note 2 : Loading a dictionary involves building tables, which are dependent on compression parameters. > * For this reason, compression parameters cannot be changed anymore after loading a dictionary. > * It's also a CPU-heavy operation, with non-negligible impact on latency. > * Note 3 : Dictionary will be used for all future compression jobs. > * To return to "no-dictionary" situation, load a NULL dictionary > * Note 5 : Use ZSTD_CCtx_loadDictionary_advanced() to select how dictionary > * content will be interpreted. > */ >ZSTDLIB_API size_t ZSTD_CCtx_loadDictionary(ZSTD_CCtx* cctx, const void* dict, size_t dictSize); >ZSTDLIB_API size_t ZSTD_CCtx_loadDictionary_byReference(ZSTD_CCtx* cctx, const void* dict, size_t dictSize); >ZSTDLIB_API size_t ZSTD_CCtx_loadDictionary_advanced(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictMode_e dictMode); > > >/*! ZSTD_CCtx_refCDict() : > * Reference a prepared dictionary, to be used for all next compression jobs. > * Note that compression parameters are enforced from within CDict, > * and supercede any compression parameter previously set within CCtx. > * The dictionary will remain valid for future compression jobs using same CCtx. > * @result : 0, or an error code (which can be tested with ZSTD_isError()). > * Special : adding a NULL CDict means "return to no-dictionary mode". > * Note 1 : Currently, only one dictionary can be managed. > * Adding a new dictionary effectively "discards" any previous one. > * Note 2 : CDict is just referenced, its lifetime must outlive CCtx. > */ >ZSTDLIB_API size_t ZSTD_CCtx_refCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict); > >/*! ZSTD_CCtx_refPrefix() : > * Reference a prefix (single-usage dictionary) for next compression job. > * Decompression need same prefix to properly regenerate data. > * Prefix is **only used once**. Tables are discarded at end of compression job. > * Subsequent compression jobs will be done without prefix (if none is explicitly referenced). > * If there is a need to use same prefix multiple times, consider embedding it into a ZSTD_CDict instead. > * @result : 0, or an error code (which can be tested with ZSTD_isError()). > * Special : Adding any prefix (including NULL) invalidates any previous prefix or dictionary > * Note 1 : Prefix buffer is referenced. It must outlive compression job. > * Note 2 : Referencing a prefix involves building tables, which are dependent on compression parameters. > * It's a CPU-heavy operation, with non-negligible impact on latency. > * Note 3 : By default, the prefix is treated as raw content > * (ZSTD_dm_rawContent). Use ZSTD_CCtx_refPrefix_advanced() to alter > * dictMode. */ >ZSTDLIB_API size_t ZSTD_CCtx_refPrefix(ZSTD_CCtx* cctx, const void* prefix, size_t prefixSize); >ZSTDLIB_API size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx* cctx, const void* prefix, size_t prefixSize, ZSTD_dictMode_e dictMode); > > > >typedef enum { > ZSTD_e_continue=0, /* collect more data, encoder transparently decides when to output result, for optimal conditions */ > ZSTD_e_flush, /* flush any data provided so far - frame will continue, future data can still reference previous data for better compression */ > ZSTD_e_end /* flush any remaining data and close current frame. Any additional data starts a new frame. */ >} ZSTD_EndDirective; > >/*! ZSTD_compress_generic() : > * Behave about the same as ZSTD_compressStream. To note : > * - Compression parameters are pushed into CCtx before starting compression, using ZSTD_CCtx_setParameter() > * - Compression parameters cannot be changed once compression is started. > * - outpot->pos must be <= dstCapacity, input->pos must be <= srcSize > * - outpot->pos and input->pos will be updated. They are guaranteed to remain below their respective limit. > * - @return provides the minimum amount of data still to flush from internal buffers > * or an error code, which can be tested using ZSTD_isError(). > * if @return != 0, flush is not fully completed, there is some data left within internal buffers. > * - after a ZSTD_e_end directive, if internal buffer is not fully flushed, > * only ZSTD_e_end or ZSTD_e_flush operations are allowed. > * It is necessary to fully flush internal buffers > * before starting a new compression job, or changing compression parameters. > */ >ZSTDLIB_API size_t ZSTD_compress_generic (ZSTD_CCtx* cctx, > ZSTD_outBuffer* output, > ZSTD_inBuffer* input, > ZSTD_EndDirective endOp); > >/*! ZSTD_CCtx_reset() : > * Return a CCtx to clean state. > * Useful after an error, or to interrupt an ongoing compression job and start a new one. > * Any internal data not yet flushed is cancelled. > * Dictionary (if any) is dropped. > * All parameters are back to default values. > * It's possible to modify compression parameters after a reset. > */ >ZSTDLIB_API void ZSTD_CCtx_reset(ZSTD_CCtx* cctx); /* Not ready yet ! */ > > >/*! ZSTD_compress_generic_simpleArgs() : > * Same as ZSTD_compress_generic(), > * but using only integral types as arguments. > * Argument list is larger than ZSTD_{in,out}Buffer, > * but can be helpful for binders from dynamic languages > * which have troubles handling structures containing memory pointers. > */ >ZSTDLIB_API size_t ZSTD_compress_generic_simpleArgs ( > ZSTD_CCtx* cctx, > void* dst, size_t dstCapacity, size_t* dstPos, > const void* src, size_t srcSize, size_t* srcPos, > ZSTD_EndDirective endOp); > > >/*! ZSTD_CCtx_params : > * Quick howto : > * - ZSTD_createCCtxParams() : Create a ZSTD_CCtx_params structure > * - ZSTD_CCtxParam_setParameter() : Push parameters one by one into > * an existing ZSTD_CCtx_params structure. > * This is similar to > * ZSTD_CCtx_setParameter(). > * - ZSTD_CCtx_setParametersUsingCCtxParams() : Apply parameters to > * an existing CCtx. > * These parameters will be applied to > * all subsequent compression jobs. > * - ZSTD_compress_generic() : Do compression using the CCtx. > * - ZSTD_freeCCtxParams() : Free the memory. > * > * This can be used with ZSTD_estimateCCtxSize_advanced_usingCCtxParams() > * for static allocation for single-threaded compression. > */ >ZSTDLIB_API ZSTD_CCtx_params* ZSTD_createCCtxParams(void); > >/*! ZSTD_resetCCtxParams() : > * Reset params to default, with the default compression level. > */ >ZSTDLIB_API size_t ZSTD_resetCCtxParams(ZSTD_CCtx_params* params); > >/*! ZSTD_initCCtxParams() : > * Initializes the compression parameters of cctxParams according to > * compression level. All other parameters are reset to their default values. > */ >ZSTDLIB_API size_t ZSTD_initCCtxParams(ZSTD_CCtx_params* cctxParams, int compressionLevel); > >/*! ZSTD_initCCtxParams_advanced() : > * Initializes the compression and frame parameters of cctxParams according to > * params. All other parameters are reset to their default values. > */ >ZSTDLIB_API size_t ZSTD_initCCtxParams_advanced(ZSTD_CCtx_params* cctxParams, ZSTD_parameters params); > >ZSTDLIB_API size_t ZSTD_freeCCtxParams(ZSTD_CCtx_params* params); > >/*! ZSTD_CCtxParam_setParameter() : > * Similar to ZSTD_CCtx_setParameter. > * Set one compression parameter, selected by enum ZSTD_cParameter. > * Parameters must be applied to a ZSTD_CCtx using ZSTD_CCtx_setParametersUsingCCtxParams(). > * Note : when `value` is an enum, cast it to unsigned for proper type checking. > * @result : 0, or an error code (which can be tested with ZSTD_isError()). > */ >ZSTDLIB_API size_t ZSTD_CCtxParam_setParameter(ZSTD_CCtx_params* params, ZSTD_cParameter param, unsigned value); > >/*! ZSTD_CCtx_setParametersUsingCCtxParams() : > * Apply a set of ZSTD_CCtx_params to the compression context. > * This must be done before the dictionary is loaded. > * The pledgedSrcSize is treated as unknown. > * Multithreading parameters are applied only if nbThreads > 1. > */ >ZSTDLIB_API size_t ZSTD_CCtx_setParametersUsingCCtxParams( > ZSTD_CCtx* cctx, const ZSTD_CCtx_params* params); > > >/*=== Advanced parameters for decompression API ===*/ > >/* The following parameters must be set after creating a ZSTD_DCtx* (or ZSTD_DStream*) object, > * but before starting decompression of a frame. > */ > >/*! ZSTD_DCtx_loadDictionary() : > * Create an internal DDict from dict buffer, > * to be used to decompress next frames. > * @result : 0, or an error code (which can be tested with ZSTD_isError()). > * Special : Adding a NULL (or 0-size) dictionary invalidates any previous dictionary, > * meaning "return to no-dictionary mode". > * Note 1 : `dict` content will be copied internally. > * Use ZSTD_DCtx_loadDictionary_byReference() > * to reference dictionary content instead. > * In which case, the dictionary buffer must outlive its users. > * Note 2 : Loading a dictionary involves building tables, > * which has a non-negligible impact on CPU usage and latency. > * Note 3 : Use ZSTD_DCtx_loadDictionary_advanced() to select > * how dictionary content will be interpreted and loaded. > */ >ZSTDLIB_API size_t ZSTD_DCtx_loadDictionary(ZSTD_DCtx* dctx, const void* dict, size_t dictSize); /* not implemented */ >ZSTDLIB_API size_t ZSTD_DCtx_loadDictionary_byReference(ZSTD_DCtx* dctx, const void* dict, size_t dictSize); /* not implemented */ >ZSTDLIB_API size_t ZSTD_DCtx_loadDictionary_advanced(ZSTD_DCtx* dctx, const void* dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictMode_e dictMode); /* not implemented */ > > >/*! ZSTD_DCtx_refDDict() : > * Reference a prepared dictionary, to be used to decompress next frames. > * The dictionary remains active for decompression of future frames using same DCtx. > * @result : 0, or an error code (which can be tested with ZSTD_isError()). > * Note 1 : Currently, only one dictionary can be managed. > * Referencing a new dictionary effectively "discards" any previous one. > * Special : adding a NULL DDict means "return to no-dictionary mode". > * Note 2 : DDict is just referenced, its lifetime must outlive its usage from DCtx. > */ >ZSTDLIB_API size_t ZSTD_DCtx_refDDict(ZSTD_DCtx* dctx, const ZSTD_DDict* ddict); /* not implemented */ > > >/*! ZSTD_DCtx_refPrefix() : > * Reference a prefix (single-usage dictionary) for next compression job. > * Prefix is **only used once**. It must be explicitly referenced before each frame. > * If there is a need to use same prefix multiple times, consider embedding it into a ZSTD_DDict instead. > * @result : 0, or an error code (which can be tested with ZSTD_isError()). > * Note 1 : Adding any prefix (including NULL) invalidates any previously set prefix or dictionary > * Note 2 : Prefix buffer is referenced. It must outlive compression job. > * Note 3 : By default, the prefix is treated as raw content (ZSTD_dm_rawContent). > * Use ZSTD_CCtx_refPrefix_advanced() to alter dictMode. > * Note 4 : Referencing a raw content prefix has almost no cpu nor memory cost. > */ >ZSTDLIB_API size_t ZSTD_DCtx_refPrefix(ZSTD_DCtx* dctx, const void* prefix, size_t prefixSize); /* not implemented */ >ZSTDLIB_API size_t ZSTD_DCtx_refPrefix_advanced(ZSTD_DCtx* dctx, const void* prefix, size_t prefixSize, ZSTD_dictMode_e dictMode); /* not implemented */ > > >/*! ZSTD_DCtx_setMaxWindowSize() : > * Refuses allocating internal buffers for frames requiring a window size larger than provided limit. > * This is useful to prevent a decoder context from reserving too much memory for itself (potential attack scenario). > * This parameter is only useful in streaming mode, since no internal buffer is allocated in direct mode. > * By default, a decompression context accepts all window sizes <= (1 << ZSTD_WINDOWLOG_MAX) > * @return : 0, or an error code (which can be tested using ZSTD_isError()). > */ >ZSTDLIB_API size_t ZSTD_DCtx_setMaxWindowSize(ZSTD_DCtx* dctx, size_t maxWindowSize); > > >/*! ZSTD_DCtx_setFormat() : > * Instruct the decoder context about what kind of data to decode next. > * This instruction is mandatory to decode data without a fully-formed header, > * such ZSTD_f_zstd1_magicless for example. > * @return : 0, or an error code (which can be tested using ZSTD_isError()). > */ >ZSTDLIB_API size_t ZSTD_DCtx_setFormat(ZSTD_DCtx* dctx, ZSTD_format_e format); > > >/*! ZSTD_decompress_generic() : > * Behave the same as ZSTD_decompressStream. > * Decompression parameters cannot be changed once decompression is started. > * @return : an error code, which can be tested using ZSTD_isError() > * if >0, a hint, nb of expected input bytes for next invocation. > * `0` means : a frame has just been fully decoded and flushed. > */ >ZSTDLIB_API size_t ZSTD_decompress_generic(ZSTD_DCtx* dctx, > ZSTD_outBuffer* output, > ZSTD_inBuffer* input); > > >/*! ZSTD_decompress_generic_simpleArgs() : > * Same as ZSTD_decompress_generic(), > * but using only integral types as arguments. > * Argument list is larger than ZSTD_{in,out}Buffer, > * but can be helpful for binders from dynamic languages > * which have troubles handling structures containing memory pointers. > */ >ZSTDLIB_API size_t ZSTD_decompress_generic_simpleArgs ( > ZSTD_DCtx* dctx, > void* dst, size_t dstCapacity, size_t* dstPos, > const void* src, size_t srcSize, size_t* srcPos); > > >/*! ZSTD_DCtx_reset() : > * Return a DCtx to clean state. > * If a decompression was ongoing, any internal data not yet flushed is cancelled. > * All parameters are back to default values, including sticky ones. > * Dictionary (if any) is dropped. > * Parameters can be modified again after a reset. > */ >ZSTDLIB_API void ZSTD_DCtx_reset(ZSTD_DCtx* dctx); > > > >/* ============================ */ >/** Block level API */ >/* ============================ */ > >/*! > Block functions produce and decode raw zstd blocks, without frame metadata. > Frame metadata cost is typically ~18 bytes, which can be non-negligible for very small blocks (< 100 bytes). > User will have to take in charge required information to regenerate data, such as compressed and content sizes. > > A few rules to respect : > - Compressing and decompressing require a context structure > + Use ZSTD_createCCtx() and ZSTD_createDCtx() > - It is necessary to init context before starting > + compression : any ZSTD_compressBegin*() variant, including with dictionary > + decompression : any ZSTD_decompressBegin*() variant, including with dictionary > + copyCCtx() and copyDCtx() can be used too > - Block size is limited, it must be <= ZSTD_getBlockSize() <= ZSTD_BLOCKSIZE_MAX == 128 KB > + If input is larger than a block size, it's necessary to split input data into multiple blocks > + For inputs larger than a single block size, consider using the regular ZSTD_compress() instead. > Frame metadata is not that costly, and quickly becomes negligible as source size grows larger. > - When a block is considered not compressible enough, ZSTD_compressBlock() result will be zero. > In which case, nothing is produced into `dst`. > + User must test for such outcome and deal directly with uncompressed data > + ZSTD_decompressBlock() doesn't accept uncompressed data as input !!! > + In case of multiple successive blocks, should some of them be uncompressed, > decoder must be informed of their existence in order to follow proper history. > Use ZSTD_insertBlock() for such a case. >*/ > >#define ZSTD_BLOCKSIZELOG_MAX 17 >#define ZSTD_BLOCKSIZE_MAX (1<<ZSTD_BLOCKSIZELOG_MAX) /* define, for static allocation */ >/*===== Raw zstd block functions =====*/ >ZSTDLIB_API size_t ZSTD_getBlockSize (const ZSTD_CCtx* cctx); >ZSTDLIB_API size_t ZSTD_compressBlock (ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize); >ZSTDLIB_API size_t ZSTD_decompressBlock(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize); >ZSTDLIB_API size_t ZSTD_insertBlock(ZSTD_DCtx* dctx, const void* blockStart, size_t blockSize); /**< insert uncompressed block into `dctx` history. Useful for multi-blocks decompression */ > > >#endif /* ZSTD_H_ZSTD_STATIC_LINKING_ONLY */ ># 1383 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/zstd.h" > >#if defined (__cplusplus) >} >#endif ># 1387 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/zstd.h" ># 23 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_internal.h" 2 >#define FSE_STATIC_LINKING_ONLY >#if 0 /* expanded by -frewrite-includes */ >#include "fse.h" >#endif /* expanded by -frewrite-includes */ ># 24 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_internal.h" ># 1 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/fse.h" 1 >/* ****************************************************************** > FSE : Finite State Entropy codec > Public Prototypes declaration > Copyright (C) 2013-2016, Yann Collet. > > BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php) > > Redistribution and use in source and binary forms, with or without > modification, are permitted provided that the following conditions are > met: > > * Redistributions of source code must retain the above copyright > notice, this list of conditions and the following disclaimer. > * Redistributions in binary form must reproduce the above > copyright notice, this list of conditions and the following disclaimer > in the documentation and/or other materials provided with the > distribution. > > THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT > LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR > A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT > OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, > SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT > LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, > DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY > THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT > (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE > OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > > You can contact the author at : > - Source repository : https://github.com/Cyan4973/FiniteStateEntropy >****************************************************************** */ > >#if defined (__cplusplus) >extern "C" { >#endif ># 38 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/fse.h" > >#ifndef FSE_H >#define FSE_H > > >/*-***************************************** >* Dependencies >******************************************/ >#if 0 /* expanded by -frewrite-includes */ >#include <stddef.h> /* size_t, ptrdiff_t */ >#endif /* expanded by -frewrite-includes */ ># 46 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/fse.h" ># 47 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/fse.h" > > >/*-***************************************** >* FSE_PUBLIC_API : control library symbols visibility >******************************************/ >#if defined(FSE_DLL_EXPORT) && (FSE_DLL_EXPORT==1) && defined(__GNUC__) && (__GNUC__ >= 4) ># define FSE_PUBLIC_API __attribute__ ((visibility ("default"))) >#elif defined(FSE_DLL_EXPORT) && (FSE_DLL_EXPORT==1) /* Visual expected */ ># 55 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/fse.h" ># define FSE_PUBLIC_API __declspec(dllexport) >#elif defined(FSE_DLL_IMPORT) && (FSE_DLL_IMPORT==1) ># 57 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/fse.h" ># define FSE_PUBLIC_API __declspec(dllimport) /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/ >#else ># 59 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/fse.h" ># define FSE_PUBLIC_API >#endif ># 61 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/fse.h" > >/*------ Version ------*/ >#define FSE_VERSION_MAJOR 0 >#define FSE_VERSION_MINOR 9 >#define FSE_VERSION_RELEASE 0 > >#define FSE_LIB_VERSION FSE_VERSION_MAJOR.FSE_VERSION_MINOR.FSE_VERSION_RELEASE >#define FSE_QUOTE(str) #str >#define FSE_EXPAND_AND_QUOTE(str) FSE_QUOTE(str) >#define FSE_VERSION_STRING FSE_EXPAND_AND_QUOTE(FSE_LIB_VERSION) > >#define FSE_VERSION_NUMBER (FSE_VERSION_MAJOR *100*100 + FSE_VERSION_MINOR *100 + FSE_VERSION_RELEASE) >FSE_PUBLIC_API unsigned FSE_versionNumber(void); /**< library version number; to be used when checking dll version */ > >/*-**************************************** >* FSE simple functions >******************************************/ >/*! FSE_compress() : > Compress content of buffer 'src', of size 'srcSize', into destination buffer 'dst'. > 'dst' buffer must be already allocated. Compression runs faster is dstCapacity >= FSE_compressBound(srcSize). > @return : size of compressed data (<= dstCapacity). > Special values : if return == 0, srcData is not compressible => Nothing is stored within dst !!! > if return == 1, srcData is a single byte symbol * srcSize times. Use RLE compression instead. > if FSE_isError(return), compression failed (more details using FSE_getErrorName()) >*/ >FSE_PUBLIC_API size_t FSE_compress(void* dst, size_t dstCapacity, > const void* src, size_t srcSize); > >/*! FSE_decompress(): > Decompress FSE data from buffer 'cSrc', of size 'cSrcSize', > into already allocated destination buffer 'dst', of size 'dstCapacity'. > @return : size of regenerated data (<= maxDstSize), > or an error code, which can be tested using FSE_isError() . > > ** Important ** : FSE_decompress() does not decompress non-compressible nor RLE data !!! > Why ? : making this distinction requires a header. > Header management is intentionally delegated to the user layer, which can better manage special cases. >*/ >FSE_PUBLIC_API size_t FSE_decompress(void* dst, size_t dstCapacity, > const void* cSrc, size_t cSrcSize); > > >/*-***************************************** >* Tool functions >******************************************/ >FSE_PUBLIC_API size_t FSE_compressBound(size_t size); /* maximum compressed size */ > >/* Error Management */ >FSE_PUBLIC_API unsigned FSE_isError(size_t code); /* tells if a return value is an error code */ >FSE_PUBLIC_API const char* FSE_getErrorName(size_t code); /* provides error code string (useful for debugging) */ > > >/*-***************************************** >* FSE advanced functions >******************************************/ >/*! FSE_compress2() : > Same as FSE_compress(), but allows the selection of 'maxSymbolValue' and 'tableLog' > Both parameters can be defined as '0' to mean : use default value > @return : size of compressed data > Special values : if return == 0, srcData is not compressible => Nothing is stored within cSrc !!! > if return == 1, srcData is a single byte symbol * srcSize times. Use RLE compression. > if FSE_isError(return), it's an error code. >*/ >FSE_PUBLIC_API size_t FSE_compress2 (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog); > > >/*-***************************************** >* FSE detailed API >******************************************/ >/*! >FSE_compress() does the following: >1. count symbol occurrence from source[] into table count[] >2. normalize counters so that sum(count[]) == Power_of_2 (2^tableLog) >3. save normalized counters to memory buffer using writeNCount() >4. build encoding table 'CTable' from normalized counters >5. encode the data stream using encoding table 'CTable' > >FSE_decompress() does the following: >1. read normalized counters with readNCount() >2. build decoding table 'DTable' from normalized counters >3. decode the data stream using decoding table 'DTable' > >The following API allows targeting specific sub-functions for advanced tasks. >For example, it's possible to compress several blocks using the same 'CTable', >or to save and provide normalized distribution using external method. >*/ > >/* *** COMPRESSION *** */ > >/*! FSE_count(): > Provides the precise count of each byte within a table 'count'. > 'count' is a table of unsigned int, of minimum size (*maxSymbolValuePtr+1). > *maxSymbolValuePtr will be updated if detected smaller than initial value. > @return : the count of the most frequent symbol (which is not identified). > if return == srcSize, there is only one symbol. > Can also return an error code, which can be tested with FSE_isError(). */ >FSE_PUBLIC_API size_t FSE_count(unsigned* count, unsigned* maxSymbolValuePtr, const void* src, size_t srcSize); > >/*! FSE_optimalTableLog(): > dynamically downsize 'tableLog' when conditions are met. > It saves CPU time, by using smaller tables, while preserving or even improving compression ratio. > @return : recommended tableLog (necessarily <= 'maxTableLog') */ >FSE_PUBLIC_API unsigned FSE_optimalTableLog(unsigned maxTableLog, size_t srcSize, unsigned maxSymbolValue); > >/*! FSE_normalizeCount(): > normalize counts so that sum(count[]) == Power_of_2 (2^tableLog) > 'normalizedCounter' is a table of short, of minimum size (maxSymbolValue+1). > @return : tableLog, > or an errorCode, which can be tested using FSE_isError() */ >FSE_PUBLIC_API size_t FSE_normalizeCount(short* normalizedCounter, unsigned tableLog, const unsigned* count, size_t srcSize, unsigned maxSymbolValue); > >/*! FSE_NCountWriteBound(): > Provides the maximum possible size of an FSE normalized table, given 'maxSymbolValue' and 'tableLog'. > Typically useful for allocation purpose. */ >FSE_PUBLIC_API size_t FSE_NCountWriteBound(unsigned maxSymbolValue, unsigned tableLog); > >/*! FSE_writeNCount(): > Compactly save 'normalizedCounter' into 'buffer'. > @return : size of the compressed table, > or an errorCode, which can be tested using FSE_isError(). */ >FSE_PUBLIC_API size_t FSE_writeNCount (void* buffer, size_t bufferSize, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog); > > >/*! Constructor and Destructor of FSE_CTable. > Note that FSE_CTable size depends on 'tableLog' and 'maxSymbolValue' */ >typedef unsigned FSE_CTable; /* don't allocate that. It's only meant to be more restrictive than void* */ >FSE_PUBLIC_API FSE_CTable* FSE_createCTable (unsigned maxSymbolValue, unsigned tableLog); >FSE_PUBLIC_API void FSE_freeCTable (FSE_CTable* ct); > >/*! FSE_buildCTable(): > Builds `ct`, which must be already allocated, using FSE_createCTable(). > @return : 0, or an errorCode, which can be tested using FSE_isError() */ >FSE_PUBLIC_API size_t FSE_buildCTable(FSE_CTable* ct, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog); > >/*! FSE_compress_usingCTable(): > Compress `src` using `ct` into `dst` which must be already allocated. > @return : size of compressed data (<= `dstCapacity`), > or 0 if compressed data could not fit into `dst`, > or an errorCode, which can be tested using FSE_isError() */ >FSE_PUBLIC_API size_t FSE_compress_usingCTable (void* dst, size_t dstCapacity, const void* src, size_t srcSize, const FSE_CTable* ct); > >/*! >Tutorial : >---------- >The first step is to count all symbols. FSE_count() does this job very fast. >Result will be saved into 'count', a table of unsigned int, which must be already allocated, and have 'maxSymbolValuePtr[0]+1' cells. >'src' is a table of bytes of size 'srcSize'. All values within 'src' MUST be <= maxSymbolValuePtr[0] >maxSymbolValuePtr[0] will be updated, with its real value (necessarily <= original value) >FSE_count() will return the number of occurrence of the most frequent symbol. >This can be used to know if there is a single symbol within 'src', and to quickly evaluate its compressibility. >If there is an error, the function will return an ErrorCode (which can be tested using FSE_isError()). > >The next step is to normalize the frequencies. >FSE_normalizeCount() will ensure that sum of frequencies is == 2 ^'tableLog'. >It also guarantees a minimum of 1 to any Symbol with frequency >= 1. >You can use 'tableLog'==0 to mean "use default tableLog value". >If you are unsure of which tableLog value to use, you can ask FSE_optimalTableLog(), >which will provide the optimal valid tableLog given sourceSize, maxSymbolValue, and a user-defined maximum (0 means "default"). > >The result of FSE_normalizeCount() will be saved into a table, >called 'normalizedCounter', which is a table of signed short. >'normalizedCounter' must be already allocated, and have at least 'maxSymbolValue+1' cells. >The return value is tableLog if everything proceeded as expected. >It is 0 if there is a single symbol within distribution. >If there is an error (ex: invalid tableLog value), the function will return an ErrorCode (which can be tested using FSE_isError()). > >'normalizedCounter' can be saved in a compact manner to a memory area using FSE_writeNCount(). >'buffer' must be already allocated. >For guaranteed success, buffer size must be at least FSE_headerBound(). >The result of the function is the number of bytes written into 'buffer'. >If there is an error, the function will return an ErrorCode (which can be tested using FSE_isError(); ex : buffer size too small). > >'normalizedCounter' can then be used to create the compression table 'CTable'. >The space required by 'CTable' must be already allocated, using FSE_createCTable(). >You can then use FSE_buildCTable() to fill 'CTable'. >If there is an error, both functions will return an ErrorCode (which can be tested using FSE_isError()). > >'CTable' can then be used to compress 'src', with FSE_compress_usingCTable(). >Similar to FSE_count(), the convention is that 'src' is assumed to be a table of char of size 'srcSize' >The function returns the size of compressed data (without header), necessarily <= `dstCapacity`. >If it returns '0', compressed data could not fit into 'dst'. >If there is an error, the function will return an ErrorCode (which can be tested using FSE_isError()). >*/ > > >/* *** DECOMPRESSION *** */ > >/*! FSE_readNCount(): > Read compactly saved 'normalizedCounter' from 'rBuffer'. > @return : size read from 'rBuffer', > or an errorCode, which can be tested using FSE_isError(). > maxSymbolValuePtr[0] and tableLogPtr[0] will also be updated with their respective values */ >FSE_PUBLIC_API size_t FSE_readNCount (short* normalizedCounter, unsigned* maxSymbolValuePtr, unsigned* tableLogPtr, const void* rBuffer, size_t rBuffSize); > >/*! Constructor and Destructor of FSE_DTable. > Note that its size depends on 'tableLog' */ >typedef unsigned FSE_DTable; /* don't allocate that. It's just a way to be more restrictive than void* */ >FSE_PUBLIC_API FSE_DTable* FSE_createDTable(unsigned tableLog); >FSE_PUBLIC_API void FSE_freeDTable(FSE_DTable* dt); > >/*! FSE_buildDTable(): > Builds 'dt', which must be already allocated, using FSE_createDTable(). > return : 0, or an errorCode, which can be tested using FSE_isError() */ >FSE_PUBLIC_API size_t FSE_buildDTable (FSE_DTable* dt, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog); > >/*! FSE_decompress_usingDTable(): > Decompress compressed source `cSrc` of size `cSrcSize` using `dt` > into `dst` which must be already allocated. > @return : size of regenerated data (necessarily <= `dstCapacity`), > or an errorCode, which can be tested using FSE_isError() */ >FSE_PUBLIC_API size_t FSE_decompress_usingDTable(void* dst, size_t dstCapacity, const void* cSrc, size_t cSrcSize, const FSE_DTable* dt); > >/*! >Tutorial : >---------- >(Note : these functions only decompress FSE-compressed blocks. > If block is uncompressed, use memcpy() instead > If block is a single repeated byte, use memset() instead ) > >The first step is to obtain the normalized frequencies of symbols. >This can be performed by FSE_readNCount() if it was saved using FSE_writeNCount(). >'normalizedCounter' must be already allocated, and have at least 'maxSymbolValuePtr[0]+1' cells of signed short. >In practice, that means it's necessary to know 'maxSymbolValue' beforehand, >or size the table to handle worst case situations (typically 256). >FSE_readNCount() will provide 'tableLog' and 'maxSymbolValue'. >The result of FSE_readNCount() is the number of bytes read from 'rBuffer'. >Note that 'rBufferSize' must be at least 4 bytes, even if useful information is less than that. >If there is an error, the function will return an error code, which can be tested using FSE_isError(). > >The next step is to build the decompression tables 'FSE_DTable' from 'normalizedCounter'. >This is performed by the function FSE_buildDTable(). >The space required by 'FSE_DTable' must be already allocated using FSE_createDTable(). >If there is an error, the function will return an error code, which can be tested using FSE_isError(). > >`FSE_DTable` can then be used to decompress `cSrc`, with FSE_decompress_usingDTable(). >`cSrcSize` must be strictly correct, otherwise decompression will fail. >FSE_decompress_usingDTable() result will tell how many bytes were regenerated (<=`dstCapacity`). >If there is an error, the function will return an error code, which can be tested using FSE_isError(). (ex: dst buffer too small) >*/ > >#endif /* FSE_H */ ># 302 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/fse.h" > >#if defined(FSE_STATIC_LINKING_ONLY) && !defined(FSE_H_FSE_STATIC_LINKING_ONLY) >#define FSE_H_FSE_STATIC_LINKING_ONLY > >/* *** Dependency *** */ >#if 0 /* expanded by -frewrite-includes */ >#include "bitstream.h" >#endif /* expanded by -frewrite-includes */ ># 307 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/fse.h" ># 308 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/fse.h" > > >/* ***************************************** >* Static allocation >*******************************************/ >/* FSE buffer bounds */ >#define FSE_NCOUNTBOUND 512 >#define FSE_BLOCKBOUND(size) (size + (size>>7)) >#define FSE_COMPRESSBOUND(size) (FSE_NCOUNTBOUND + FSE_BLOCKBOUND(size)) /* Macro version, useful for static allocation */ > >/* It is possible to statically allocate FSE CTable/DTable as a table of FSE_CTable/FSE_DTable using below macros */ >#define FSE_CTABLE_SIZE_U32(maxTableLog, maxSymbolValue) (1 + (1<<(maxTableLog-1)) + ((maxSymbolValue+1)*2)) >#define FSE_DTABLE_SIZE_U32(maxTableLog) (1 + (1<<maxTableLog)) > >/* or use the size to malloc() space directly. Pay attention to alignment restrictions though */ >#define FSE_CTABLE_SIZE(maxTableLog, maxSymbolValue) (FSE_CTABLE_SIZE_U32(maxTableLog, maxSymbolValue) * sizeof(FSE_CTable)) >#define FSE_DTABLE_SIZE(maxTableLog) (FSE_DTABLE_SIZE_U32(maxTableLog) * sizeof(FSE_DTable)) > > >/* ***************************************** >* FSE advanced API >*******************************************/ >/* FSE_count_wksp() : > * Same as FSE_count(), but using an externally provided scratch buffer. > * `workSpace` size must be table of >= `1024` unsigned > */ >size_t FSE_count_wksp(unsigned* count, unsigned* maxSymbolValuePtr, > const void* source, size_t sourceSize, unsigned* workSpace); > >/** FSE_countFast() : > * same as FSE_count(), but blindly trusts that all byte values within src are <= *maxSymbolValuePtr > */ >size_t FSE_countFast(unsigned* count, unsigned* maxSymbolValuePtr, const void* src, size_t srcSize); > >/* FSE_countFast_wksp() : > * Same as FSE_countFast(), but using an externally provided scratch buffer. > * `workSpace` must be a table of minimum `1024` unsigned > */ >size_t FSE_countFast_wksp(unsigned* count, unsigned* maxSymbolValuePtr, const void* src, size_t srcSize, unsigned* workSpace); > >/*! FSE_count_simple > * Same as FSE_countFast(), but does not use any additional memory (not even on stack). > * This function is unsafe, and will segfault if any value within `src` is `> *maxSymbolValuePtr` (presuming it's also the size of `count`). >*/ >size_t FSE_count_simple(unsigned* count, unsigned* maxSymbolValuePtr, const void* src, size_t srcSize); > > > >unsigned FSE_optimalTableLog_internal(unsigned maxTableLog, size_t srcSize, unsigned maxSymbolValue, unsigned minus); >/**< same as FSE_optimalTableLog(), which used `minus==2` */ > >/* FSE_compress_wksp() : > * Same as FSE_compress2(), but using an externally allocated scratch buffer (`workSpace`). > * FSE_WKSP_SIZE_U32() provides the minimum size required for `workSpace` as a table of FSE_CTable. > */ >#define FSE_WKSP_SIZE_U32(maxTableLog, maxSymbolValue) ( FSE_CTABLE_SIZE_U32(maxTableLog, maxSymbolValue) + ((maxTableLog > 12) ? (1 << (maxTableLog - 2)) : 1024) ) >size_t FSE_compress_wksp (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize); > >size_t FSE_buildCTable_raw (FSE_CTable* ct, unsigned nbBits); >/**< build a fake FSE_CTable, designed for a flat distribution, where each symbol uses nbBits */ > >size_t FSE_buildCTable_rle (FSE_CTable* ct, unsigned char symbolValue); >/**< build a fake FSE_CTable, designed to compress always the same symbolValue */ > >/* FSE_buildCTable_wksp() : > * Same as FSE_buildCTable(), but using an externally allocated scratch buffer (`workSpace`). > * `wkspSize` must be >= `(1<<tableLog)`. > */ >size_t FSE_buildCTable_wksp(FSE_CTable* ct, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize); > >size_t FSE_buildDTable_raw (FSE_DTable* dt, unsigned nbBits); >/**< build a fake FSE_DTable, designed to read a flat distribution where each symbol uses nbBits */ > >size_t FSE_buildDTable_rle (FSE_DTable* dt, unsigned char symbolValue); >/**< build a fake FSE_DTable, designed to always generate the same symbolValue */ > >size_t FSE_decompress_wksp(void* dst, size_t dstCapacity, const void* cSrc, size_t cSrcSize, FSE_DTable* workSpace, unsigned maxLog); >/**< same as FSE_decompress(), using an externally allocated `workSpace` produced with `FSE_DTABLE_SIZE_U32(maxLog)` */ > >typedef enum { > FSE_repeat_none, /**< Cannot use the previous table */ > FSE_repeat_check, /**< Can use the previous table but it must be checked */ > FSE_repeat_valid /**< Can use the previous table and it is asumed to be valid */ > } FSE_repeat; > >/* ***************************************** >* FSE symbol compression API >*******************************************/ >/*! > This API consists of small unitary functions, which highly benefit from being inlined. > Hence their body are included in next section. >*/ >typedef struct { > ptrdiff_t value; > const void* stateTable; > const void* symbolTT; > unsigned stateLog; >} FSE_CState_t; > >static void FSE_initCState(FSE_CState_t* CStatePtr, const FSE_CTable* ct); > >static void FSE_encodeSymbol(BIT_CStream_t* bitC, FSE_CState_t* CStatePtr, unsigned symbol); > >static void FSE_flushCState(BIT_CStream_t* bitC, const FSE_CState_t* CStatePtr); > >/**< >These functions are inner components of FSE_compress_usingCTable(). >They allow the creation of custom streams, mixing multiple tables and bit sources. > >A key property to keep in mind is that encoding and decoding are done **in reverse direction**. >So the first symbol you will encode is the last you will decode, like a LIFO stack. > >You will need a few variables to track your CStream. They are : > >FSE_CTable ct; // Provided by FSE_buildCTable() >BIT_CStream_t bitStream; // bitStream tracking structure >FSE_CState_t state; // State tracking structure (can have several) > > >The first thing to do is to init bitStream and state. > size_t errorCode = BIT_initCStream(&bitStream, dstBuffer, maxDstSize); > FSE_initCState(&state, ct); > >Note that BIT_initCStream() can produce an error code, so its result should be tested, using FSE_isError(); >You can then encode your input data, byte after byte. >FSE_encodeSymbol() outputs a maximum of 'tableLog' bits at a time. >Remember decoding will be done in reverse direction. > FSE_encodeByte(&bitStream, &state, symbol); > >At any time, you can also add any bit sequence. >Note : maximum allowed nbBits is 25, for compatibility with 32-bits decoders > BIT_addBits(&bitStream, bitField, nbBits); > >The above methods don't commit data to memory, they just store it into local register, for speed. >Local register size is 64-bits on 64-bits systems, 32-bits on 32-bits systems (size_t). >Writing data to memory is a manual operation, performed by the flushBits function. > BIT_flushBits(&bitStream); > >Your last FSE encoding operation shall be to flush your last state value(s). > FSE_flushState(&bitStream, &state); > >Finally, you must close the bitStream. >The function returns the size of CStream in bytes. >If data couldn't fit into dstBuffer, it will return a 0 ( == not compressible) >If there is an error, it returns an errorCode (which can be tested using FSE_isError()). > size_t size = BIT_closeCStream(&bitStream); >*/ > > >/* ***************************************** >* FSE symbol decompression API >*******************************************/ >typedef struct { > size_t state; > const void* table; /* precise table may vary, depending on U16 */ >} FSE_DState_t; > > >static void FSE_initDState(FSE_DState_t* DStatePtr, BIT_DStream_t* bitD, const FSE_DTable* dt); > >static unsigned char FSE_decodeSymbol(FSE_DState_t* DStatePtr, BIT_DStream_t* bitD); > >static unsigned FSE_endOfDState(const FSE_DState_t* DStatePtr); > >/**< >Let's now decompose FSE_decompress_usingDTable() into its unitary components. >You will decode FSE-encoded symbols from the bitStream, >and also any other bitFields you put in, **in reverse order**. > >You will need a few variables to track your bitStream. They are : > >BIT_DStream_t DStream; // Stream context >FSE_DState_t DState; // State context. Multiple ones are possible >FSE_DTable* DTablePtr; // Decoding table, provided by FSE_buildDTable() > >The first thing to do is to init the bitStream. > errorCode = BIT_initDStream(&DStream, srcBuffer, srcSize); > >You should then retrieve your initial state(s) >(in reverse flushing order if you have several ones) : > errorCode = FSE_initDState(&DState, &DStream, DTablePtr); > >You can then decode your data, symbol after symbol. >For information the maximum number of bits read by FSE_decodeSymbol() is 'tableLog'. >Keep in mind that symbols are decoded in reverse order, like a LIFO stack (last in, first out). > unsigned char symbol = FSE_decodeSymbol(&DState, &DStream); > >You can retrieve any bitfield you eventually stored into the bitStream (in reverse order) >Note : maximum allowed nbBits is 25, for 32-bits compatibility > size_t bitField = BIT_readBits(&DStream, nbBits); > >All above operations only read from local register (which size depends on size_t). >Refueling the register from memory is manually performed by the reload method. > endSignal = FSE_reloadDStream(&DStream); > >BIT_reloadDStream() result tells if there is still some more data to read from DStream. >BIT_DStream_unfinished : there is still some data left into the DStream. >BIT_DStream_endOfBuffer : Dstream reached end of buffer. Its container may no longer be completely filled. >BIT_DStream_completed : Dstream reached its exact end, corresponding in general to decompression completed. >BIT_DStream_tooFar : Dstream went too far. Decompression result is corrupted. > >When reaching end of buffer (BIT_DStream_endOfBuffer), progress slowly, notably if you decode multiple symbols per loop, >to properly detect the exact end of stream. >After each decoded symbol, check if DStream is fully consumed using this simple test : > BIT_reloadDStream(&DStream) >= BIT_DStream_completed > >When it's done, verify decompression is fully completed, by checking both DStream and the relevant states. >Checking if DStream has reached its end is performed by : > BIT_endOfDStream(&DStream); >Check also the states. There might be some symbols left there, if some high probability ones (>50%) are possible. > FSE_endOfDState(&DState); >*/ > > >/* ***************************************** >* FSE unsafe API >*******************************************/ >static unsigned char FSE_decodeSymbolFast(FSE_DState_t* DStatePtr, BIT_DStream_t* bitD); >/* faster, but works only if nbBits is always >= 1 (otherwise, result will be corrupted) */ > > >/* ***************************************** >* Implementation of inlined functions >*******************************************/ >typedef struct { > int deltaFindState; > U32 deltaNbBits; >} FSE_symbolCompressionTransform; /* total 8 bytes */ > >MEM_STATIC void FSE_initCState(FSE_CState_t* statePtr, const FSE_CTable* ct) >{ > const void* ptr = ct; > const U16* u16ptr = (const U16*) ptr; > const U32 tableLog = MEM_read16(ptr); > statePtr->value = (ptrdiff_t)1<<tableLog; > statePtr->stateTable = u16ptr+2; > statePtr->symbolTT = ((const U32*)ct + 1 + (tableLog ? (1<<(tableLog-1)) : 1)); > statePtr->stateLog = tableLog; >} > > >/*! FSE_initCState2() : >* Same as FSE_initCState(), but the first symbol to include (which will be the last to be read) >* uses the smallest state value possible, saving the cost of this symbol */ >MEM_STATIC void FSE_initCState2(FSE_CState_t* statePtr, const FSE_CTable* ct, U32 symbol) >{ > FSE_initCState(statePtr, ct); > { const FSE_symbolCompressionTransform symbolTT = ((const FSE_symbolCompressionTransform*)(statePtr->symbolTT))[symbol]; > const U16* stateTable = (const U16*)(statePtr->stateTable); > U32 nbBitsOut = (U32)((symbolTT.deltaNbBits + (1<<15)) >> 16); > statePtr->value = (nbBitsOut << 16) - symbolTT.deltaNbBits; > statePtr->value = stateTable[(statePtr->value >> nbBitsOut) + symbolTT.deltaFindState]; > } >} > >MEM_STATIC void FSE_encodeSymbol(BIT_CStream_t* bitC, FSE_CState_t* statePtr, U32 symbol) >{ > FSE_symbolCompressionTransform const symbolTT = ((const FSE_symbolCompressionTransform*)(statePtr->symbolTT))[symbol]; > const U16* const stateTable = (const U16*)(statePtr->stateTable); > U32 const nbBitsOut = (U32)((statePtr->value + symbolTT.deltaNbBits) >> 16); > BIT_addBits(bitC, statePtr->value, nbBitsOut); > statePtr->value = stateTable[ (statePtr->value >> nbBitsOut) + symbolTT.deltaFindState]; >} > >MEM_STATIC void FSE_flushCState(BIT_CStream_t* bitC, const FSE_CState_t* statePtr) >{ > BIT_addBits(bitC, statePtr->value, statePtr->stateLog); > BIT_flushBits(bitC); >} > > >/* ====== Decompression ====== */ > >typedef struct { > U16 tableLog; > U16 fastMode; >} FSE_DTableHeader; /* sizeof U32 */ > >typedef struct >{ > unsigned short newState; > unsigned char symbol; > unsigned char nbBits; >} FSE_decode_t; /* size == U32 */ > >MEM_STATIC void FSE_initDState(FSE_DState_t* DStatePtr, BIT_DStream_t* bitD, const FSE_DTable* dt) >{ > const void* ptr = dt; > const FSE_DTableHeader* const DTableH = (const FSE_DTableHeader*)ptr; > DStatePtr->state = BIT_readBits(bitD, DTableH->tableLog); > BIT_reloadDStream(bitD); > DStatePtr->table = dt + 1; >} > >MEM_STATIC BYTE FSE_peekSymbol(const FSE_DState_t* DStatePtr) >{ > FSE_decode_t const DInfo = ((const FSE_decode_t*)(DStatePtr->table))[DStatePtr->state]; > return DInfo.symbol; >} > >MEM_STATIC void FSE_updateState(FSE_DState_t* DStatePtr, BIT_DStream_t* bitD) >{ > FSE_decode_t const DInfo = ((const FSE_decode_t*)(DStatePtr->table))[DStatePtr->state]; > U32 const nbBits = DInfo.nbBits; > size_t const lowBits = BIT_readBits(bitD, nbBits); > DStatePtr->state = DInfo.newState + lowBits; >} > >MEM_STATIC BYTE FSE_decodeSymbol(FSE_DState_t* DStatePtr, BIT_DStream_t* bitD) >{ > FSE_decode_t const DInfo = ((const FSE_decode_t*)(DStatePtr->table))[DStatePtr->state]; > U32 const nbBits = DInfo.nbBits; > BYTE const symbol = DInfo.symbol; > size_t const lowBits = BIT_readBits(bitD, nbBits); > > DStatePtr->state = DInfo.newState + lowBits; > return symbol; >} > >/*! FSE_decodeSymbolFast() : > unsafe, only works if no symbol has a probability > 50% */ >MEM_STATIC BYTE FSE_decodeSymbolFast(FSE_DState_t* DStatePtr, BIT_DStream_t* bitD) >{ > FSE_decode_t const DInfo = ((const FSE_decode_t*)(DStatePtr->table))[DStatePtr->state]; > U32 const nbBits = DInfo.nbBits; > BYTE const symbol = DInfo.symbol; > size_t const lowBits = BIT_readBitsFast(bitD, nbBits); > > DStatePtr->state = DInfo.newState + lowBits; > return symbol; >} > >MEM_STATIC unsigned FSE_endOfDState(const FSE_DState_t* DStatePtr) >{ > return DStatePtr->state == 0; >} > > > >#ifndef FSE_COMMONDEFS_ONLY > >/* ************************************************************** >* Tuning parameters >****************************************************************/ >/*!MEMORY_USAGE : >* Memory usage formula : N->2^N Bytes (examples : 10 -> 1KB; 12 -> 4KB ; 16 -> 64KB; 20 -> 1MB; etc.) >* Increasing memory usage improves compression ratio >* Reduced memory usage can improve speed, due to cache effect >* Recommended max value is 14, for 16KB, which nicely fits into Intel x86 L1 cache */ >#ifndef FSE_MAX_MEMORY_USAGE ># define FSE_MAX_MEMORY_USAGE 14 >#endif ># 660 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/fse.h" >#ifndef FSE_DEFAULT_MEMORY_USAGE ># define FSE_DEFAULT_MEMORY_USAGE 13 >#endif ># 663 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/fse.h" > >/*!FSE_MAX_SYMBOL_VALUE : >* Maximum symbol value authorized. >* Required for proper stack allocation */ >#ifndef FSE_MAX_SYMBOL_VALUE ># define FSE_MAX_SYMBOL_VALUE 255 >#endif ># 670 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/fse.h" > >/* ************************************************************** >* template functions type & suffix >****************************************************************/ >#define FSE_FUNCTION_TYPE BYTE >#define FSE_FUNCTION_EXTENSION >#define FSE_DECODE_TYPE FSE_decode_t > > >#endif /* !FSE_COMMONDEFS_ONLY */ ># 680 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/fse.h" > > >/* *************************************************************** >* Constants >*****************************************************************/ >#define FSE_MAX_TABLELOG (FSE_MAX_MEMORY_USAGE-2) >#define FSE_MAX_TABLESIZE (1U<<FSE_MAX_TABLELOG) >#define FSE_MAXTABLESIZE_MASK (FSE_MAX_TABLESIZE-1) >#define FSE_DEFAULT_TABLELOG (FSE_DEFAULT_MEMORY_USAGE-2) >#define FSE_MIN_TABLELOG 5 > >#define FSE_TABLELOG_ABSOLUTE_MAX 15 >#if FSE_MAX_TABLELOG > FSE_TABLELOG_ABSOLUTE_MAX ># error "FSE_MAX_TABLELOG > FSE_TABLELOG_ABSOLUTE_MAX is not supported" >#endif ># 695 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/fse.h" > >#define FSE_TABLESTEP(tableSize) ((tableSize>>1) + (tableSize>>3) + 3) > > >#endif /* FSE_STATIC_LINKING_ONLY */ ># 700 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/fse.h" > > >#if defined (__cplusplus) >} >#endif ># 705 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/fse.h" ># 25 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_internal.h" 2 >#define HUF_STATIC_LINKING_ONLY >#if 0 /* expanded by -frewrite-includes */ >#include "huf.h" >#endif /* expanded by -frewrite-includes */ ># 26 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_internal.h" ># 1 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/huf.h" 1 >/* ****************************************************************** > Huffman coder, part of New Generation Entropy library > header file > Copyright (C) 2013-2016, Yann Collet. > > BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php) > > Redistribution and use in source and binary forms, with or without > modification, are permitted provided that the following conditions are > met: > > * Redistributions of source code must retain the above copyright > notice, this list of conditions and the following disclaimer. > * Redistributions in binary form must reproduce the above > copyright notice, this list of conditions and the following disclaimer > in the documentation and/or other materials provided with the > distribution. > > THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT > LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR > A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT > OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, > SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT > LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, > DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY > THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT > (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE > OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > > You can contact the author at : > - Source repository : https://github.com/Cyan4973/FiniteStateEntropy >****************************************************************** */ > >#if defined (__cplusplus) >extern "C" { >#endif ># 38 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/huf.h" > >#ifndef HUF_H_298734234 >#define HUF_H_298734234 > >/* *** Dependencies *** */ >#if 0 /* expanded by -frewrite-includes */ >#include <stddef.h> /* size_t */ >#endif /* expanded by -frewrite-includes */ ># 43 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/huf.h" ># 44 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/huf.h" > > >/* *** library symbols visibility *** */ >/* Note : when linking with -fvisibility=hidden on gcc, or by default on Visual, > * HUF symbols remain "private" (internal symbols for library only). > * Set macro FSE_DLL_EXPORT to 1 if you want HUF symbols visible on DLL interface */ >#if defined(FSE_DLL_EXPORT) && (FSE_DLL_EXPORT==1) && defined(__GNUC__) && (__GNUC__ >= 4) ># define HUF_PUBLIC_API __attribute__ ((visibility ("default"))) >#elif defined(FSE_DLL_EXPORT) && (FSE_DLL_EXPORT==1) /* Visual expected */ ># 53 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/huf.h" ># define HUF_PUBLIC_API __declspec(dllexport) >#elif defined(FSE_DLL_IMPORT) && (FSE_DLL_IMPORT==1) ># 55 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/huf.h" ># define HUF_PUBLIC_API __declspec(dllimport) /* not required, just to generate faster code (saves a function pointer load from IAT and an indirect jump) */ >#else ># 57 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/huf.h" ># define HUF_PUBLIC_API >#endif ># 59 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/huf.h" > > >/* *** simple functions *** */ >/** >HUF_compress() : > Compress content from buffer 'src', of size 'srcSize', into buffer 'dst'. > 'dst' buffer must be already allocated. > Compression runs faster if `dstCapacity` >= HUF_compressBound(srcSize). > `srcSize` must be <= `HUF_BLOCKSIZE_MAX` == 128 KB. > @return : size of compressed data (<= `dstCapacity`). > Special values : if return == 0, srcData is not compressible => Nothing is stored within dst !!! > if return == 1, srcData is a single repeated byte symbol (RLE compression). > if HUF_isError(return), compression failed (more details using HUF_getErrorName()) >*/ >HUF_PUBLIC_API size_t HUF_compress(void* dst, size_t dstCapacity, > const void* src, size_t srcSize); > >/** >HUF_decompress() : > Decompress HUF data from buffer 'cSrc', of size 'cSrcSize', > into already allocated buffer 'dst', of minimum size 'dstSize'. > `originalSize` : **must** be the ***exact*** size of original (uncompressed) data. > Note : in contrast with FSE, HUF_decompress can regenerate > RLE (cSrcSize==1) and uncompressed (cSrcSize==dstSize) data, > because it knows size to regenerate. > @return : size of regenerated data (== originalSize), > or an error code, which can be tested using HUF_isError() >*/ >HUF_PUBLIC_API size_t HUF_decompress(void* dst, size_t originalSize, > const void* cSrc, size_t cSrcSize); > > >/* *** Tool functions *** */ >#define HUF_BLOCKSIZE_MAX (128 * 1024) /**< maximum input size for a single block compressed with HUF_compress */ >HUF_PUBLIC_API size_t HUF_compressBound(size_t size); /**< maximum compressed size (worst case) */ > >/* Error Management */ >HUF_PUBLIC_API unsigned HUF_isError(size_t code); /**< tells if a return value is an error code */ >HUF_PUBLIC_API const char* HUF_getErrorName(size_t code); /**< provides error code string (useful for debugging) */ > > >/* *** Advanced function *** */ > >/** HUF_compress2() : > * Same as HUF_compress(), but offers direct control over `maxSymbolValue` and `tableLog`. > * `tableLog` must be `<= HUF_TABLELOG_MAX` . */ >HUF_PUBLIC_API size_t HUF_compress2 (void* dst, size_t dstCapacity, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog); > >/** HUF_compress4X_wksp() : > * Same as HUF_compress2(), but uses externally allocated `workSpace`. > * `workspace` must have minimum alignment of 4, and be at least as large as following macro */ >#define HUF_WORKSPACE_SIZE (6 << 10) >#define HUF_WORKSPACE_SIZE_U32 (HUF_WORKSPACE_SIZE / sizeof(U32)) >HUF_PUBLIC_API size_t HUF_compress4X_wksp (void* dst, size_t dstCapacity, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize); > >/** > * The minimum workspace size for the `workSpace` used in > * HUF_readDTableX2_wksp() and HUF_readDTableX4_wksp(). > * > * The space used depends on HUF_TABLELOG_MAX, ranging from ~1500 bytes when > * HUF_TABLE_LOG_MAX=12 to ~1850 bytes when HUF_TABLE_LOG_MAX=15. > * Buffer overflow errors may potentially occur if code modifications result in > * a required workspace size greater than that specified in the following > * macro. > */ >#define HUF_DECOMPRESS_WORKSPACE_SIZE (2 << 10) >#define HUF_DECOMPRESS_WORKSPACE_SIZE_U32 (HUF_DECOMPRESS_WORKSPACE_SIZE / sizeof(U32)) > >#endif /* HUF_H_298734234 */ ># 128 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/huf.h" > >/* ****************************************************************** > * WARNING !! > * The following section contains advanced and experimental definitions > * which shall never be used in the context of dll > * because they are not guaranteed to remain stable in the future. > * Only consider them in association with static linking. > *******************************************************************/ >#if defined(HUF_STATIC_LINKING_ONLY) && !defined(HUF_H_HUF_STATIC_LINKING_ONLY) >#define HUF_H_HUF_STATIC_LINKING_ONLY > >/* *** Dependencies *** */ >#if 0 /* expanded by -frewrite-includes */ >#include "mem.h" /* U32 */ >#endif /* expanded by -frewrite-includes */ ># 140 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/huf.h" ># 141 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/huf.h" > > >/* *** Constants *** */ >#define HUF_TABLELOG_MAX 12 /* max configured tableLog (for static allocation); can be modified up to HUF_ABSOLUTEMAX_TABLELOG */ >#define HUF_TABLELOG_DEFAULT 11 /* tableLog by default, when not specified */ >#define HUF_SYMBOLVALUE_MAX 255 > >#define HUF_TABLELOG_ABSOLUTEMAX 15 /* absolute limit of HUF_MAX_TABLELOG. Beyond that value, code does not work */ >#if (HUF_TABLELOG_MAX > HUF_TABLELOG_ABSOLUTEMAX) ># error "HUF_TABLELOG_MAX is too large !" >#endif ># 152 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/huf.h" > > >/* **************************************** >* Static allocation >******************************************/ >/* HUF buffer bounds */ >#define HUF_CTABLEBOUND 129 >#define HUF_BLOCKBOUND(size) (size + (size>>8) + 8) /* only true when incompressible is pre-filtered with fast heuristic */ >#define HUF_COMPRESSBOUND(size) (HUF_CTABLEBOUND + HUF_BLOCKBOUND(size)) /* Macro version, useful for static allocation */ > >/* static allocation of HUF's Compression Table */ >#define HUF_CTABLE_SIZE_U32(maxSymbolValue) ((maxSymbolValue)+1) /* Use tables of U32, for proper alignment */ >#define HUF_CTABLE_SIZE(maxSymbolValue) (HUF_CTABLE_SIZE_U32(maxSymbolValue) * sizeof(U32)) >#define HUF_CREATE_STATIC_CTABLE(name, maxSymbolValue) \ > U32 name##hb[HUF_CTABLE_SIZE_U32(maxSymbolValue)]; \ > void* name##hv = &(name##hb); \ > HUF_CElt* name = (HUF_CElt*)(name##hv) /* no final ; */ > >/* static allocation of HUF's DTable */ >typedef U32 HUF_DTable; >#define HUF_DTABLE_SIZE(maxTableLog) (1 + (1<<(maxTableLog))) >#define HUF_CREATE_STATIC_DTABLEX2(DTable, maxTableLog) \ > HUF_DTable DTable[HUF_DTABLE_SIZE((maxTableLog)-1)] = { ((U32)((maxTableLog)-1) * 0x01000001) } >#define HUF_CREATE_STATIC_DTABLEX4(DTable, maxTableLog) \ > HUF_DTable DTable[HUF_DTABLE_SIZE(maxTableLog)] = { ((U32)(maxTableLog) * 0x01000001) } > > >/* **************************************** >* Advanced decompression functions >******************************************/ >size_t HUF_decompress4X2 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< single-symbol decoder */ >size_t HUF_decompress4X4 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< double-symbols decoder */ > >size_t HUF_decompress4X_DCtx (HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< decodes RLE and uncompressed */ >size_t HUF_decompress4X_hufOnly(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< considers RLE and uncompressed as errors */ >size_t HUF_decompress4X_hufOnly_wksp(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize); /**< considers RLE and uncompressed as errors */ >size_t HUF_decompress4X2_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< single-symbol decoder */ >size_t HUF_decompress4X2_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize); /**< single-symbol decoder */ >size_t HUF_decompress4X4_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< double-symbols decoder */ >size_t HUF_decompress4X4_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize); /**< double-symbols decoder */ > > >/* **************************************** >* HUF detailed API >******************************************/ >/*! >HUF_compress() does the following: >1. count symbol occurrence from source[] into table count[] using FSE_count() >2. (optional) refine tableLog using HUF_optimalTableLog() >3. build Huffman table from count using HUF_buildCTable() >4. save Huffman table to memory buffer using HUF_writeCTable() >5. encode the data stream using HUF_compress4X_usingCTable() > >The following API allows targeting specific sub-functions for advanced tasks. >For example, it's possible to compress several blocks using the same 'CTable', >or to save and regenerate 'CTable' using external methods. >*/ >/* FSE_count() : find it within "fse.h" */ >unsigned HUF_optimalTableLog(unsigned maxTableLog, size_t srcSize, unsigned maxSymbolValue); >typedef struct HUF_CElt_s HUF_CElt; /* incomplete type */ >size_t HUF_buildCTable (HUF_CElt* CTable, const unsigned* count, unsigned maxSymbolValue, unsigned maxNbBits); >size_t HUF_writeCTable (void* dst, size_t maxDstSize, const HUF_CElt* CTable, unsigned maxSymbolValue, unsigned huffLog); >size_t HUF_compress4X_usingCTable(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable); > >typedef enum { > HUF_repeat_none, /**< Cannot use the previous table */ > HUF_repeat_check, /**< Can use the previous table but it must be checked. Note : The previous table must have been constructed by HUF_compress{1, 4}X_repeat */ > HUF_repeat_valid /**< Can use the previous table and it is asumed to be valid */ > } HUF_repeat; >/** HUF_compress4X_repeat() : >* Same as HUF_compress4X_wksp(), but considers using hufTable if *repeat != HUF_repeat_none. >* If it uses hufTable it does not modify hufTable or repeat. >* If it doesn't, it sets *repeat = HUF_repeat_none, and it sets hufTable to the table used. >* If preferRepeat then the old table will always be used if valid. */ >size_t HUF_compress4X_repeat(void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize, HUF_CElt* hufTable, HUF_repeat* repeat, int preferRepeat); /**< `workSpace` must be a table of at least HUF_WORKSPACE_SIZE_U32 unsigned */ > >/** HUF_buildCTable_wksp() : > * Same as HUF_buildCTable(), but using externally allocated scratch buffer. > * `workSpace` must be aligned on 4-bytes boundaries, and be at least as large as a table of 1024 unsigned. > */ >size_t HUF_buildCTable_wksp (HUF_CElt* tree, const U32* count, U32 maxSymbolValue, U32 maxNbBits, void* workSpace, size_t wkspSize); > >/*! HUF_readStats() : > Read compact Huffman tree, saved by HUF_writeCTable(). > `huffWeight` is destination buffer. > @return : size read from `src` , or an error Code . > Note : Needed by HUF_readCTable() and HUF_readDTableXn() . */ >size_t HUF_readStats(BYTE* huffWeight, size_t hwSize, U32* rankStats, > U32* nbSymbolsPtr, U32* tableLogPtr, > const void* src, size_t srcSize); > >/** HUF_readCTable() : >* Loading a CTable saved with HUF_writeCTable() */ >size_t HUF_readCTable (HUF_CElt* CTable, unsigned* maxSymbolValuePtr, const void* src, size_t srcSize); > > >/* >HUF_decompress() does the following: >1. select the decompression algorithm (X2, X4) based on pre-computed heuristics >2. build Huffman table from save, using HUF_readDTableXn() >3. decode 1 or 4 segments in parallel using HUF_decompressSXn_usingDTable >*/ > >/** HUF_selectDecoder() : >* Tells which decoder is likely to decode faster, >* based on a set of pre-determined metrics. >* @return : 0==HUF_decompress4X2, 1==HUF_decompress4X4 . >* Assumption : 0 < cSrcSize < dstSize <= 128 KB */ >U32 HUF_selectDecoder (size_t dstSize, size_t cSrcSize); > >size_t HUF_readDTableX2 (HUF_DTable* DTable, const void* src, size_t srcSize); >size_t HUF_readDTableX2_wksp (HUF_DTable* DTable, const void* src, size_t srcSize, void* workSpace, size_t wkspSize); >size_t HUF_readDTableX4 (HUF_DTable* DTable, const void* src, size_t srcSize); >size_t HUF_readDTableX4_wksp (HUF_DTable* DTable, const void* src, size_t srcSize, void* workSpace, size_t wkspSize); > >size_t HUF_decompress4X_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable); >size_t HUF_decompress4X2_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable); >size_t HUF_decompress4X4_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable); > > >/* single stream variants */ > >size_t HUF_compress1X (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog); >size_t HUF_compress1X_wksp (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize); /**< `workSpace` must be a table of at least HUF_WORKSPACE_SIZE_U32 unsigned */ >size_t HUF_compress1X_usingCTable(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable); >/** HUF_compress1X_repeat() : >* Same as HUF_compress1X_wksp(), but considers using hufTable if *repeat != HUF_repeat_none. >* If it uses hufTable it does not modify hufTable or repeat. >* If it doesn't, it sets *repeat = HUF_repeat_none, and it sets hufTable to the table used. >* If preferRepeat then the old table will always be used if valid. */ >size_t HUF_compress1X_repeat(void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize, HUF_CElt* hufTable, HUF_repeat* repeat, int preferRepeat); /**< `workSpace` must be a table of at least HUF_WORKSPACE_SIZE_U32 unsigned */ > >size_t HUF_decompress1X2 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /* single-symbol decoder */ >size_t HUF_decompress1X4 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /* double-symbol decoder */ > >size_t HUF_decompress1X_DCtx (HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); >size_t HUF_decompress1X_DCtx_wksp (HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize); >size_t HUF_decompress1X2_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< single-symbol decoder */ >size_t HUF_decompress1X2_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize); /**< single-symbol decoder */ >size_t HUF_decompress1X4_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< double-symbols decoder */ >size_t HUF_decompress1X4_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize); /**< double-symbols decoder */ > >size_t HUF_decompress1X_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable); /**< automatic selection of sing or double symbol decoder, based on DTable */ >size_t HUF_decompress1X2_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable); >size_t HUF_decompress1X4_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable); > >#endif /* HUF_STATIC_LINKING_ONLY */ ># 299 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/huf.h" > >#if defined (__cplusplus) >} >#endif ># 303 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/huf.h" ># 27 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_internal.h" 2 >#ifndef XXH_STATIC_LINKING_ONLY ># define XXH_STATIC_LINKING_ONLY /* XXH64_state_t */ >#endif ># 30 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_internal.h" >#if 0 /* expanded by -frewrite-includes */ >#include "xxhash.h" /* XXH_reset, update, digest */ >#endif /* expanded by -frewrite-includes */ ># 30 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_internal.h" ># 1 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/xxhash.h" 1 >/* > xxHash - Extremely Fast Hash algorithm > Header File > Copyright (C) 2012-2016, Yann Collet. > > BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php) > > Redistribution and use in source and binary forms, with or without > modification, are permitted provided that the following conditions are > met: > > * Redistributions of source code must retain the above copyright > notice, this list of conditions and the following disclaimer. > * Redistributions in binary form must reproduce the above > copyright notice, this list of conditions and the following disclaimer > in the documentation and/or other materials provided with the > distribution. > > THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT > LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR > A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT > OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, > SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT > LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, > DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY > THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT > (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE > OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > > You can contact the author at : > - xxHash source repository : https://github.com/Cyan4973/xxHash >*/ > >/* Notice extracted from xxHash homepage : > >xxHash is an extremely fast Hash algorithm, running at RAM speed limits. >It also successfully passes all tests from the SMHasher suite. > >Comparison (single thread, Windows Seven 32 bits, using SMHasher on a Core 2 Duo @3GHz) > >Name Speed Q.Score Author >xxHash 5.4 GB/s 10 >CrapWow 3.2 GB/s 2 Andrew >MumurHash 3a 2.7 GB/s 10 Austin Appleby >SpookyHash 2.0 GB/s 10 Bob Jenkins >SBox 1.4 GB/s 9 Bret Mulvey >Lookup3 1.2 GB/s 9 Bob Jenkins >SuperFastHash 1.2 GB/s 1 Paul Hsieh >CityHash64 1.05 GB/s 10 Pike & Alakuijala >FNV 0.55 GB/s 5 Fowler, Noll, Vo >CRC32 0.43 GB/s 9 >MD5-32 0.33 GB/s 10 Ronald L. Rivest >SHA1-32 0.28 GB/s 10 > >Q.Score is a measure of quality of the hash function. >It depends on successfully passing SMHasher test set. >10 is a perfect score. > >A 64-bits version, named XXH64, is available since r35. >It offers much better speed, but for 64-bits applications only. >Name Speed on 64 bits Speed on 32 bits >XXH64 13.8 GB/s 1.9 GB/s >XXH32 6.8 GB/s 6.0 GB/s >*/ > >#if defined (__cplusplus) >extern "C" { >#endif ># 70 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/xxhash.h" > >#ifndef XXHASH_H_5627135585666179 >#define XXHASH_H_5627135585666179 1 > > >/* **************************** >* Definitions >******************************/ >#if 0 /* expanded by -frewrite-includes */ >#include <stddef.h> /* size_t */ >#endif /* expanded by -frewrite-includes */ ># 78 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/xxhash.h" ># 79 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/xxhash.h" >typedef enum { XXH_OK=0, XXH_ERROR } XXH_errorcode; > > >/* **************************** >* API modifier >******************************/ >/** XXH_PRIVATE_API >* This is useful if you want to include xxhash functions in `static` mode >* in order to inline them, and remove their symbol from the public list. >* Methodology : >* #define XXH_PRIVATE_API >* #include "xxhash.h" >* `xxhash.c` is automatically included. >* It's not useful to compile and link it as a separate module anymore. >*/ >#ifdef XXH_PRIVATE_API ># ifndef XXH_STATIC_LINKING_ONLY ># define XXH_STATIC_LINKING_ONLY ># endif ># 98 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/xxhash.h" ># if defined(__GNUC__) ># define XXH_PUBLIC_API static __inline __attribute__((unused)) ># elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) ># 101 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/xxhash.h" ># define XXH_PUBLIC_API static inline ># elif defined(_MSC_VER) ># 103 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/xxhash.h" ># define XXH_PUBLIC_API static __inline ># else ># 105 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/xxhash.h" ># define XXH_PUBLIC_API static /* this version may generate warnings for unused static functions; disable the relevant warning */ ># endif ># 107 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/xxhash.h" >#else ># 108 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/xxhash.h" ># define XXH_PUBLIC_API /* do nothing */ >#endif /* XXH_PRIVATE_API */ ># 110 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/xxhash.h" > >/*!XXH_NAMESPACE, aka Namespace Emulation : > >If you want to include _and expose_ xxHash functions from within your own library, >but also want to avoid symbol collisions with another library which also includes xxHash, > >you can use XXH_NAMESPACE, to automatically prefix any public symbol from xxhash library >with the value of XXH_NAMESPACE (so avoid to keep it NULL and avoid numeric values). > >Note that no change is required within the calling program as long as it includes `xxhash.h` : >regular symbol name will be automatically translated by this header. >*/ >#ifdef XXH_NAMESPACE ># define XXH_CAT(A,B) A##B ># define XXH_NAME2(A,B) XXH_CAT(A,B) ># define XXH32 XXH_NAME2(XXH_NAMESPACE, XXH32) ># define XXH64 XXH_NAME2(XXH_NAMESPACE, XXH64) ># define XXH_versionNumber XXH_NAME2(XXH_NAMESPACE, XXH_versionNumber) ># define XXH32_createState XXH_NAME2(XXH_NAMESPACE, XXH32_createState) ># define XXH64_createState XXH_NAME2(XXH_NAMESPACE, XXH64_createState) ># define XXH32_freeState XXH_NAME2(XXH_NAMESPACE, XXH32_freeState) ># define XXH64_freeState XXH_NAME2(XXH_NAMESPACE, XXH64_freeState) ># define XXH32_reset XXH_NAME2(XXH_NAMESPACE, XXH32_reset) ># define XXH64_reset XXH_NAME2(XXH_NAMESPACE, XXH64_reset) ># define XXH32_update XXH_NAME2(XXH_NAMESPACE, XXH32_update) ># define XXH64_update XXH_NAME2(XXH_NAMESPACE, XXH64_update) ># define XXH32_digest XXH_NAME2(XXH_NAMESPACE, XXH32_digest) ># define XXH64_digest XXH_NAME2(XXH_NAMESPACE, XXH64_digest) ># define XXH32_copyState XXH_NAME2(XXH_NAMESPACE, XXH32_copyState) ># define XXH64_copyState XXH_NAME2(XXH_NAMESPACE, XXH64_copyState) ># define XXH32_canonicalFromHash XXH_NAME2(XXH_NAMESPACE, XXH32_canonicalFromHash) ># define XXH64_canonicalFromHash XXH_NAME2(XXH_NAMESPACE, XXH64_canonicalFromHash) ># define XXH32_hashFromCanonical XXH_NAME2(XXH_NAMESPACE, XXH32_hashFromCanonical) ># define XXH64_hashFromCanonical XXH_NAME2(XXH_NAMESPACE, XXH64_hashFromCanonical) >#endif ># 145 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/xxhash.h" > > >/* ************************************* >* Version >***************************************/ >#define XXH_VERSION_MAJOR 0 >#define XXH_VERSION_MINOR 6 >#define XXH_VERSION_RELEASE 2 >#define XXH_VERSION_NUMBER (XXH_VERSION_MAJOR *100*100 + XXH_VERSION_MINOR *100 + XXH_VERSION_RELEASE) >XXH_PUBLIC_API unsigned XXH_versionNumber (void); > > >/* **************************** >* Simple Hash Functions >******************************/ >typedef unsigned int XXH32_hash_t; >typedef unsigned long long XXH64_hash_t; > >XXH_PUBLIC_API XXH32_hash_t XXH32 (const void* input, size_t length, unsigned int seed); >XXH_PUBLIC_API XXH64_hash_t XXH64 (const void* input, size_t length, unsigned long long seed); > >/*! >XXH32() : > Calculate the 32-bits hash of sequence "length" bytes stored at memory address "input". > The memory between input & input+length must be valid (allocated and read-accessible). > "seed" can be used to alter the result predictably. > Speed on Core 2 Duo @ 3 GHz (single thread, SMHasher benchmark) : 5.4 GB/s >XXH64() : > Calculate the 64-bits hash of sequence of length "len" stored at memory address "input". > "seed" can be used to alter the result predictably. > This function runs 2x faster on 64-bits systems, but slower on 32-bits systems (see benchmark). >*/ > > >/* **************************** >* Streaming Hash Functions >******************************/ >typedef struct XXH32_state_s XXH32_state_t; /* incomplete type */ >typedef struct XXH64_state_s XXH64_state_t; /* incomplete type */ > >/*! State allocation, compatible with dynamic libraries */ > >XXH_PUBLIC_API XXH32_state_t* XXH32_createState(void); >XXH_PUBLIC_API XXH_errorcode XXH32_freeState(XXH32_state_t* statePtr); > >XXH_PUBLIC_API XXH64_state_t* XXH64_createState(void); >XXH_PUBLIC_API XXH_errorcode XXH64_freeState(XXH64_state_t* statePtr); > > >/* hash streaming */ > >XXH_PUBLIC_API XXH_errorcode XXH32_reset (XXH32_state_t* statePtr, unsigned int seed); >XXH_PUBLIC_API XXH_errorcode XXH32_update (XXH32_state_t* statePtr, const void* input, size_t length); >XXH_PUBLIC_API XXH32_hash_t XXH32_digest (const XXH32_state_t* statePtr); > >XXH_PUBLIC_API XXH_errorcode XXH64_reset (XXH64_state_t* statePtr, unsigned long long seed); >XXH_PUBLIC_API XXH_errorcode XXH64_update (XXH64_state_t* statePtr, const void* input, size_t length); >XXH_PUBLIC_API XXH64_hash_t XXH64_digest (const XXH64_state_t* statePtr); > >/* >These functions generate the xxHash of an input provided in multiple segments. >Note that, for small input, they are slower than single-call functions, due to state management. >For small input, prefer `XXH32()` and `XXH64()` . > >XXH state must first be allocated, using XXH*_createState() . > >Start a new hash by initializing state with a seed, using XXH*_reset(). > >Then, feed the hash state by calling XXH*_update() as many times as necessary. >Obviously, input must be allocated and read accessible. >The function returns an error code, with 0 meaning OK, and any other value meaning there is an error. > >Finally, a hash value can be produced anytime, by using XXH*_digest(). >This function returns the nn-bits hash as an int or long long. > >It's still possible to continue inserting input into the hash state after a digest, >and generate some new hashes later on, by calling again XXH*_digest(). > >When done, free XXH state space if it was allocated dynamically. >*/ > > >/* ************************** >* Utils >****************************/ >#if !(defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) /* ! C99 */ ># define restrict /* disable restrict */ >#endif ># 233 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/xxhash.h" > >XXH_PUBLIC_API void XXH32_copyState(XXH32_state_t* restrict dst_state, const XXH32_state_t* restrict src_state); >XXH_PUBLIC_API void XXH64_copyState(XXH64_state_t* restrict dst_state, const XXH64_state_t* restrict src_state); > > >/* ************************** >* Canonical representation >****************************/ >/* Default result type for XXH functions are primitive unsigned 32 and 64 bits. >* The canonical representation uses human-readable write convention, aka big-endian (large digits first). >* These functions allow transformation of hash result into and from its canonical format. >* This way, hash values can be written into a file / memory, and remain comparable on different systems and programs. >*/ >typedef struct { unsigned char digest[4]; } XXH32_canonical_t; >typedef struct { unsigned char digest[8]; } XXH64_canonical_t; > >XXH_PUBLIC_API void XXH32_canonicalFromHash(XXH32_canonical_t* dst, XXH32_hash_t hash); >XXH_PUBLIC_API void XXH64_canonicalFromHash(XXH64_canonical_t* dst, XXH64_hash_t hash); > >XXH_PUBLIC_API XXH32_hash_t XXH32_hashFromCanonical(const XXH32_canonical_t* src); >XXH_PUBLIC_API XXH64_hash_t XXH64_hashFromCanonical(const XXH64_canonical_t* src); > >#endif /* XXHASH_H_5627135585666179 */ ># 256 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/xxhash.h" > > > >/* ================================================================================================ > This section contains definitions which are not guaranteed to remain stable. > They may change in future versions, becoming incompatible with a different version of the library. > They shall only be used with static linking. > Never use these definitions in association with dynamic linking ! >=================================================================================================== */ >#if defined(XXH_STATIC_LINKING_ONLY) && !defined(XXH_STATIC_H_3543687687345) >#define XXH_STATIC_H_3543687687345 > >/* These definitions are only meant to allow allocation of XXH state > statically, on stack, or in a struct for example. > Do not use members directly. */ > > struct XXH32_state_s { > unsigned total_len_32; > unsigned large_len; > unsigned v1; > unsigned v2; > unsigned v3; > unsigned v4; > unsigned mem32[4]; /* buffer defined as U32 for alignment */ > unsigned memsize; > unsigned reserved; /* never read nor write, will be removed in a future version */ > }; /* typedef'd to XXH32_state_t */ > > struct XXH64_state_s { > unsigned long long total_len; > unsigned long long v1; > unsigned long long v2; > unsigned long long v3; > unsigned long long v4; > unsigned long long mem64[4]; /* buffer defined as U64 for alignment */ > unsigned memsize; > unsigned reserved[2]; /* never read nor write, will be removed in a future version */ > }; /* typedef'd to XXH64_state_t */ > > ># ifdef XXH_PRIVATE_API >#if 0 /* expanded by -frewrite-includes */ ># include "xxhash.c" /* include xxhash functions as `static`, for inlining */ >#endif /* expanded by -frewrite-includes */ ># 297 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/xxhash.h" ># 298 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/xxhash.h" ># endif ># 299 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/xxhash.h" > >#endif /* XXH_STATIC_LINKING_ONLY && XXH_STATIC_H_3543687687345 */ ># 301 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/xxhash.h" > > >#if defined (__cplusplus) >} >#endif ># 306 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/xxhash.h" ># 31 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_internal.h" 2 > > >#if defined (__cplusplus) >extern "C" { >#endif ># 36 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_internal.h" > > >/*-************************************* >* Debug >***************************************/ >#if defined(ZSTD_DEBUG) && (ZSTD_DEBUG>=1) >#if 0 /* expanded by -frewrite-includes */ ># include <assert.h> >#endif /* expanded by -frewrite-includes */ ># 42 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_internal.h" ># 43 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_internal.h" >#else ># 44 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_internal.h" ># ifndef assert ># define assert(condition) ((void)0) ># endif ># 47 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_internal.h" >#endif ># 48 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_internal.h" > >#define ZSTD_STATIC_ASSERT(c) { enum { ZSTD_static_assert = 1/(int)(!!(c)) }; } > >#if defined(ZSTD_DEBUG) && (ZSTD_DEBUG>=2) >#if 0 /* expanded by -frewrite-includes */ ># include <stdio.h> >#endif /* expanded by -frewrite-includes */ ># 52 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_internal.h" ># 53 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_internal.h" >/* recommended values for ZSTD_DEBUG display levels : > * 1 : no display, enables assert() only > * 2 : reserved for currently active debugging path > * 3 : events once per object lifetime (CCtx, CDict) > * 4 : events once per frame > * 5 : events once per block > * 6 : events once per sequence (*very* verbose) */ ># define DEBUGLOG(l, ...) { \ > if (l<=ZSTD_DEBUG) { \ > fprintf(stderr, __FILE__ ": "); \ > fprintf(stderr, __VA_ARGS__); \ > fprintf(stderr, " \n"); \ > } } >#else ># 67 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_internal.h" ># define DEBUGLOG(l, ...) {} /* disabled */ >#endif ># 69 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_internal.h" > > >/*-************************************* >* shared macros >***************************************/ >#undef MIN >#undef MAX >#define MIN(a,b) ((a)<(b) ? (a) : (b)) >#define MAX(a,b) ((a)>(b) ? (a) : (b)) >#define CHECK_F(f) { size_t const errcod = f; if (ERR_isError(errcod)) return errcod; } /* check and Forward error code */ >#define CHECK_E(f, e) { size_t const errcod = f; if (ERR_isError(errcod)) return ERROR(e); } /* check and send Error code */ > > >/*-************************************* >* Common constants >***************************************/ >#define ZSTD_OPT_NUM (1<<12) > >#define ZSTD_REP_NUM 3 /* number of repcodes */ >#define ZSTD_REP_CHECK (ZSTD_REP_NUM) /* number of repcodes to check by the optimal parser */ >#define ZSTD_REP_MOVE (ZSTD_REP_NUM-1) >#define ZSTD_REP_MOVE_OPT (ZSTD_REP_NUM) >static const U32 repStartValue[ZSTD_REP_NUM] = { 1, 4, 8 }; > >#define KB *(1 <<10) >#define MB *(1 <<20) >#define GB *(1U<<30) > >#define BIT7 128 >#define BIT6 64 >#define BIT5 32 >#define BIT4 16 >#define BIT1 2 >#define BIT0 1 > >#define ZSTD_WINDOWLOG_ABSOLUTEMIN 10 >#define ZSTD_WINDOWLOG_DEFAULTMAX 27 /* Default maximum allowed window log */ >static const size_t ZSTD_fcs_fieldSize[4] = { 0, 2, 4, 8 }; >static const size_t ZSTD_did_fieldSize[4] = { 0, 1, 2, 4 }; > >#define ZSTD_FRAMEIDSIZE 4 >static const size_t ZSTD_frameIdSize = ZSTD_FRAMEIDSIZE; /* magic number size */ > >#define ZSTD_BLOCKHEADERSIZE 3 /* C standard doesn't allow `static const` variable to be init using another `static const` variable */ >static const size_t ZSTD_blockHeaderSize = ZSTD_BLOCKHEADERSIZE; >typedef enum { bt_raw, bt_rle, bt_compressed, bt_reserved } blockType_e; > >#define MIN_SEQUENCES_SIZE 1 /* nbSeq==0 */ >#define MIN_CBLOCK_SIZE (1 /*litCSize*/ + 1 /* RLE or RAW */ + MIN_SEQUENCES_SIZE /* nbSeq==0 */) /* for a non-null block */ > >#define HufLog 12 >typedef enum { set_basic, set_rle, set_compressed, set_repeat } symbolEncodingType_e; > >#define LONGNBSEQ 0x7F00 > >#define MINMATCH 3 > >#define Litbits 8 >#define MaxLit ((1<<Litbits) - 1) >#define MaxML 52 >#define MaxLL 35 >#define DefaultMaxOff 28 >#define MaxOff 31 >#define MaxSeq MAX(MaxLL, MaxML) /* Assumption : MaxOff < MaxLL,MaxML */ >#define MLFSELog 9 >#define LLFSELog 9 >#define OffFSELog 8 > >static const U32 LL_bits[MaxLL+1] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, > 1, 1, 1, 1, 2, 2, 3, 3, 4, 6, 7, 8, 9,10,11,12, > 13,14,15,16 }; >static const S16 LL_defaultNorm[MaxLL+1] = { 4, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, > 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 1, 1, 1, 1, 1, > -1,-1,-1,-1 }; >#define LL_DEFAULTNORMLOG 6 /* for static allocation */ >static const U32 LL_defaultNormLog = LL_DEFAULTNORMLOG; > >static const U32 ML_bits[MaxML+1] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, > 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, > 1, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 7, 8, 9,10,11, > 12,13,14,15,16 }; >static const S16 ML_defaultNorm[MaxML+1] = { 1, 4, 3, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, > 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, > 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,-1,-1, > -1,-1,-1,-1,-1 }; >#define ML_DEFAULTNORMLOG 6 /* for static allocation */ >static const U32 ML_defaultNormLog = ML_DEFAULTNORMLOG; > >static const S16 OF_defaultNorm[DefaultMaxOff+1] = { 1, 1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, > 1, 1, 1, 1, 1, 1, 1, 1,-1,-1,-1,-1,-1 }; >#define OF_DEFAULTNORMLOG 5 /* for static allocation */ >static const U32 OF_defaultNormLog = OF_DEFAULTNORMLOG; > > >/*-******************************************* >* Shared functions to include for inlining >*********************************************/ >static void ZSTD_copy8(void* dst, const void* src) { memcpy(dst, src, 8); } >#define COPY8(d,s) { ZSTD_copy8(d,s); d+=8; s+=8; } > >/*! ZSTD_wildcopy() : >* custom version of memcpy(), can copy up to 7 bytes too many (8 bytes if length==0) */ >#define WILDCOPY_OVERLENGTH 8 >MEM_STATIC void ZSTD_wildcopy(void* dst, const void* src, ptrdiff_t length) >{ > const BYTE* ip = (const BYTE*)src; > BYTE* op = (BYTE*)dst; > BYTE* const oend = op + length; > do > COPY8(op, ip) > while (op < oend); >} > >MEM_STATIC void ZSTD_wildcopy_e(void* dst, const void* src, void* dstEnd) /* should be faster for decoding, but strangely, not verified on all platform */ >{ > const BYTE* ip = (const BYTE*)src; > BYTE* op = (BYTE*)dst; > BYTE* const oend = (BYTE*)dstEnd; > do > COPY8(op, ip) > while (op < oend); >} > > >/*-******************************************* >* Private interfaces >*********************************************/ >typedef struct ZSTD_stats_s ZSTD_stats_t; > >typedef struct seqDef_s { > U32 offset; > U16 litLength; > U16 matchLength; >} seqDef; > > >typedef struct { > seqDef* sequencesStart; > seqDef* sequences; > BYTE* litStart; > BYTE* lit; > BYTE* llCode; > BYTE* mlCode; > BYTE* ofCode; > U32 longLengthID; /* 0 == no longLength; 1 == Lit.longLength; 2 == Match.longLength; */ > U32 longLengthPos; > U32 rep[ZSTD_REP_NUM]; > U32 repToConfirm[ZSTD_REP_NUM]; >} seqStore_t; > >typedef struct { > U32 off; > U32 len; >} ZSTD_match_t; > >typedef struct { > U32 price; > U32 off; > U32 mlen; > U32 litlen; > U32 rep[ZSTD_REP_NUM]; >} ZSTD_optimal_t; > >typedef struct { > U32* litFreq; > U32* litLengthFreq; > U32* matchLengthFreq; > U32* offCodeFreq; > ZSTD_match_t* matchTable; > ZSTD_optimal_t* priceTable; > > U32 matchLengthSum; > U32 matchSum; > U32 litLengthSum; > U32 litSum; > U32 offCodeSum; > U32 log2matchLengthSum; > U32 log2matchSum; > U32 log2litLengthSum; > U32 log2litSum; > U32 log2offCodeSum; > U32 factor; > U32 staticPrices; > U32 cachedPrice; > U32 cachedLitLength; > const BYTE* cachedLiterals; >} optState_t; > >typedef struct { > U32 offset; > U32 checksum; >} ldmEntry_t; > >typedef struct { > ldmEntry_t* hashTable; > BYTE* bucketOffsets; /* Next position in bucket to insert entry */ > U64 hashPower; /* Used to compute the rolling hash. > * Depends on ldmParams.minMatchLength */ >} ldmState_t; > >typedef struct { > U32 enableLdm; /* 1 if enable long distance matching */ > U32 hashLog; /* Log size of hashTable */ > U32 bucketSizeLog; /* Log bucket size for collision resolution, at most 8 */ > U32 minMatchLength; /* Minimum match length */ > U32 hashEveryLog; /* Log number of entries to skip */ >} ldmParams_t; > >typedef struct { > U32 hufCTable[HUF_CTABLE_SIZE_U32(255)]; > FSE_CTable offcodeCTable[FSE_CTABLE_SIZE_U32(OffFSELog, MaxOff)]; > FSE_CTable matchlengthCTable[FSE_CTABLE_SIZE_U32(MLFSELog, MaxML)]; > FSE_CTable litlengthCTable[FSE_CTABLE_SIZE_U32(LLFSELog, MaxLL)]; > U32 workspace[HUF_WORKSPACE_SIZE_U32]; > HUF_repeat hufCTable_repeatMode; > FSE_repeat offcode_repeatMode; > FSE_repeat matchlength_repeatMode; > FSE_repeat litlength_repeatMode; >} ZSTD_entropyCTables_t; > >struct ZSTD_CCtx_params_s { > ZSTD_format_e format; > ZSTD_compressionParameters cParams; > ZSTD_frameParameters fParams; > > int compressionLevel; > U32 forceWindow; /* force back-references to respect limit of > * 1<<wLog, even for dictionary */ > > /* Multithreading: used to pass parameters to mtctx */ > U32 nbThreads; > unsigned jobSize; > unsigned overlapSizeLog; > > /* Long distance matching parameters */ > ldmParams_t ldmParams; > > /* For use with createCCtxParams() and freeCCtxParams() only */ > ZSTD_customMem customMem; > >}; /* typedef'd to ZSTD_CCtx_params within "zstd.h" */ > >const seqStore_t* ZSTD_getSeqStore(const ZSTD_CCtx* ctx); >void ZSTD_seqToCodes(const seqStore_t* seqStorePtr); > >/* custom memory allocation functions */ >void* ZSTD_malloc(size_t size, ZSTD_customMem customMem); >void* ZSTD_calloc(size_t size, ZSTD_customMem customMem); >void ZSTD_free(void* ptr, ZSTD_customMem customMem); > > >/*====== common function ======*/ > >MEM_STATIC U32 ZSTD_highbit32(U32 val) >{ > assert(val != 0); > { ># if defined(_MSC_VER) /* Visual */ > unsigned long r=0; > _BitScanReverse(&r, val); > return (unsigned)r; ># elif defined(__GNUC__) && (__GNUC__ >= 3) /* GCC Intrinsic */ ># 331 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_internal.h" > return 31 - __builtin_clz(val); ># else /* Software version */ ># 333 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_internal.h" > static const int DeBruijnClz[32] = { 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30, 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31 }; > U32 v = val; > int r; > v |= v >> 1; > v |= v >> 2; > v |= v >> 4; > v |= v >> 8; > v |= v >> 16; > r = DeBruijnClz[(U32)(v * 0x07C4ACDDU) >> 27]; > return r; ># endif ># 344 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_internal.h" > } >} > > >/* hidden functions */ > >/* ZSTD_invalidateRepCodes() : > * ensures next compression will not use repcodes from previous block. > * Note : only works with regular variant; > * do not use with extDict variant ! */ >void ZSTD_invalidateRepCodes(ZSTD_CCtx* cctx); > > >/*! ZSTD_initCStream_internal() : > * Private use only. Init streaming operation. > * expects params to be valid. > * must receive dict, or cdict, or none, but not both. > * @return : 0, or an error code */ >size_t ZSTD_initCStream_internal(ZSTD_CStream* zcs, > const void* dict, size_t dictSize, > const ZSTD_CDict* cdict, > ZSTD_CCtx_params params, unsigned long long pledgedSrcSize); > >/*! ZSTD_compressStream_generic() : > * Private use only. To be called from zstdmt_compress.c in single-thread mode. */ >size_t ZSTD_compressStream_generic(ZSTD_CStream* zcs, > ZSTD_outBuffer* output, > ZSTD_inBuffer* input, > ZSTD_EndDirective const flushMode); > >/*! ZSTD_getCParamsFromCDict() : > * as the name implies */ >ZSTD_compressionParameters ZSTD_getCParamsFromCDict(const ZSTD_CDict* cdict); > >/* ZSTD_compressBegin_advanced_internal() : > * Private use only. To be called from zstdmt_compress.c. */ >size_t ZSTD_compressBegin_advanced_internal(ZSTD_CCtx* cctx, > const void* dict, size_t dictSize, > ZSTD_dictMode_e dictMode, > ZSTD_CCtx_params params, > unsigned long long pledgedSrcSize); > >/* ZSTD_compress_advanced_internal() : > * Private use only. To be called from zstdmt_compress.c. */ >size_t ZSTD_compress_advanced_internal(ZSTD_CCtx* cctx, > void* dst, size_t dstCapacity, > const void* src, size_t srcSize, > const void* dict,size_t dictSize, > ZSTD_CCtx_params params); > >typedef struct { > blockType_e blockType; > U32 lastBlock; > U32 origSize; >} blockProperties_t; > >/*! ZSTD_getcBlockSize() : >* Provides the size of compressed block from block header `src` */ >size_t ZSTD_getcBlockSize(const void* src, size_t srcSize, > blockProperties_t* bpPtr); > >#if defined (__cplusplus) >} >#endif ># 408 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_internal.h" > >#endif /* ZSTD_CCOMMON_H_MODULE */ ># 410 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/common/zstd_internal.h" ># 19 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.h" 2 >#ifdef ZSTD_MULTITHREAD >#if 0 /* expanded by -frewrite-includes */ ># include "zstdmt_compress.h" >#endif /* expanded by -frewrite-includes */ ># 20 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.h" ># 1 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstdmt_compress.h" 1 >/* > * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. > * All rights reserved. > * > * This source code is licensed under both the BSD-style license (found in the > * LICENSE file in the root directory of this source tree) and the GPLv2 (found > * in the COPYING file in the root directory of this source tree). > * You may select, at your option, one of the above-listed licenses. > */ > > #ifndef ZSTDMT_COMPRESS_H > #define ZSTDMT_COMPRESS_H > > #if defined (__cplusplus) > extern "C" { > #endif ># 17 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstdmt_compress.h" > > >/* Note : This is an internal API. > * Some methods are still exposed (ZSTDLIB_API), > * because it used to be the only way to invoke MT compression. > * Now, it's recommended to use ZSTD_compress_generic() instead. > * These methods will stop being exposed in a future version */ > >/* === Dependencies === */ >#if 0 /* expanded by -frewrite-includes */ >#include <stddef.h> /* size_t */ >#endif /* expanded by -frewrite-includes */ ># 26 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstdmt_compress.h" ># 27 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstdmt_compress.h" >#define ZSTD_STATIC_LINKING_ONLY /* ZSTD_parameters */ >#if 0 /* expanded by -frewrite-includes */ >#include "zstd.h" /* ZSTD_inBuffer, ZSTD_outBuffer, ZSTDLIB_API */ >#endif /* expanded by -frewrite-includes */ ># 28 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstdmt_compress.h" ># 1 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/zstd.h" 1 >/* > * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. > * All rights reserved. > * > * This source code is licensed under both the BSD-style license (found in the > * LICENSE file in the root directory of this source tree) and the GPLv2 (found > * in the COPYING file in the root directory of this source tree). > * You may select, at your option, one of the above-listed licenses. > */ >#if defined (__cplusplus) >extern "C" { >#endif ># 13 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/zstd.h" > >#ifndef ZSTD_H_235446 >#define ZSTD_H_235446 > >/* ====== Dependency ======*/ >#if 0 /* expanded by -frewrite-includes */ >#include <stddef.h> /* size_t */ >#endif /* expanded by -frewrite-includes */ ># 18 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/zstd.h" ># 19 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/zstd.h" > > >/* ===== ZSTDLIB_API : control library symbols visibility ===== */ >#ifndef ZSTDLIB_VISIBILITY ># if defined(__GNUC__) && (__GNUC__ >= 4) ># define ZSTDLIB_VISIBILITY __attribute__ ((visibility ("default"))) ># else ># 26 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/zstd.h" ># define ZSTDLIB_VISIBILITY ># endif ># 28 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/zstd.h" >#endif ># 29 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/zstd.h" >#if defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1) ># define ZSTDLIB_API __declspec(dllexport) ZSTDLIB_VISIBILITY >#elif defined(ZSTD_DLL_IMPORT) && (ZSTD_DLL_IMPORT==1) ># 32 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/zstd.h" ># define ZSTDLIB_API __declspec(dllimport) ZSTDLIB_VISIBILITY /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/ >#else ># 34 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/zstd.h" ># define ZSTDLIB_API ZSTDLIB_VISIBILITY >#endif ># 36 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/zstd.h" > > >/******************************************************************************************************* > Introduction > > zstd, short for Zstandard, is a fast lossless compression algorithm, > targeting real-time compression scenarios at zlib-level and better compression ratios. > The zstd compression library provides in-memory compression and decompression functions. > The library supports compression levels from 1 up to ZSTD_maxCLevel() which is currently 22. > Levels >= 20, labeled `--ultra`, should be used with caution, as they require more memory. > Compression can be done in: > - a single step (described as Simple API) > - a single step, reusing a context (described as Explicit memory management) > - unbounded multiple steps (described as Streaming compression) > The compression ratio achievable on small data can be highly improved using a dictionary in: > - a single step (described as Simple dictionary API) > - a single step, reusing a dictionary (described as Fast dictionary API) > > Advanced experimental functions can be accessed using #define ZSTD_STATIC_LINKING_ONLY before including zstd.h. > Advanced experimental APIs shall never be used with a dynamic library. > They are not "stable", their definition may change in the future. Only static linking is allowed. >*********************************************************************************************************/ > >/*------ Version ------*/ >#define ZSTD_VERSION_MAJOR 1 >#define ZSTD_VERSION_MINOR 3 >#define ZSTD_VERSION_RELEASE 2 > >#define ZSTD_VERSION_NUMBER (ZSTD_VERSION_MAJOR *100*100 + ZSTD_VERSION_MINOR *100 + ZSTD_VERSION_RELEASE) >ZSTDLIB_API unsigned ZSTD_versionNumber(void); /**< useful to check dll version */ > >#define ZSTD_LIB_VERSION ZSTD_VERSION_MAJOR.ZSTD_VERSION_MINOR.ZSTD_VERSION_RELEASE >#define ZSTD_QUOTE(str) #str >#define ZSTD_EXPAND_AND_QUOTE(str) ZSTD_QUOTE(str) >#define ZSTD_VERSION_STRING ZSTD_EXPAND_AND_QUOTE(ZSTD_LIB_VERSION) >ZSTDLIB_API const char* ZSTD_versionString(void); /* v1.3.0 */ > > >/*************************************** >* Simple API >***************************************/ >/*! ZSTD_compress() : > * Compresses `src` content as a single zstd compressed frame into already allocated `dst`. > * Hint : compression runs faster if `dstCapacity` >= `ZSTD_compressBound(srcSize)`. > * @return : compressed size written into `dst` (<= `dstCapacity), > * or an error code if it fails (which can be tested using ZSTD_isError()). */ >ZSTDLIB_API size_t ZSTD_compress( void* dst, size_t dstCapacity, > const void* src, size_t srcSize, > int compressionLevel); > >/*! ZSTD_decompress() : > * `compressedSize` : must be the _exact_ size of some number of compressed and/or skippable frames. > * `dstCapacity` is an upper bound of originalSize to regenerate. > * If user cannot imply a maximum upper bound, it's better to use streaming mode to decompress data. > * @return : the number of bytes decompressed into `dst` (<= `dstCapacity`), > * or an errorCode if it fails (which can be tested using ZSTD_isError()). */ >ZSTDLIB_API size_t ZSTD_decompress( void* dst, size_t dstCapacity, > const void* src, size_t compressedSize); > >/*! ZSTD_getFrameContentSize() : v1.3.0 > * `src` should point to the start of a ZSTD encoded frame. > * `srcSize` must be at least as large as the frame header. > * hint : any size >= `ZSTD_frameHeaderSize_max` is large enough. > * @return : - decompressed size of the frame in `src`, if known > * - ZSTD_CONTENTSIZE_UNKNOWN if the size cannot be determined > * - ZSTD_CONTENTSIZE_ERROR if an error occurred (e.g. invalid magic number, srcSize too small) > * note 1 : a 0 return value means the frame is valid but "empty". > * note 2 : decompressed size is an optional field, it may not be present, typically in streaming mode. > * When `return==ZSTD_CONTENTSIZE_UNKNOWN`, data to decompress could be any size. > * In which case, it's necessary to use streaming mode to decompress data. > * Optionally, application can rely on some implicit limit, > * as ZSTD_decompress() only needs an upper bound of decompressed size. > * (For example, data could be necessarily cut into blocks <= 16 KB). > * note 3 : decompressed size is always present when compression is done with ZSTD_compress() > * note 4 : decompressed size can be very large (64-bits value), > * potentially larger than what local system can handle as a single memory segment. > * In which case, it's necessary to use streaming mode to decompress data. > * note 5 : If source is untrusted, decompressed size could be wrong or intentionally modified. > * Always ensure return value fits within application's authorized limits. > * Each application can set its own limits. > * note 6 : This function replaces ZSTD_getDecompressedSize() */ >#define ZSTD_CONTENTSIZE_UNKNOWN (0ULL - 1) >#define ZSTD_CONTENTSIZE_ERROR (0ULL - 2) >ZSTDLIB_API unsigned long long ZSTD_getFrameContentSize(const void *src, size_t srcSize); > >/*! ZSTD_getDecompressedSize() : > * NOTE: This function is now obsolete, in favor of ZSTD_getFrameContentSize(). > * Both functions work the same way, > * but ZSTD_getDecompressedSize() blends > * "empty", "unknown" and "error" results in the same return value (0), > * while ZSTD_getFrameContentSize() distinguishes them. > * > * 'src' is the start of a zstd compressed frame. > * @return : content size to be decompressed, as a 64-bits value _if known and not empty_, 0 otherwise. */ >ZSTDLIB_API unsigned long long ZSTD_getDecompressedSize(const void* src, size_t srcSize); > > >/*====== Helper functions ======*/ >#define ZSTD_COMPRESSBOUND(srcSize) ((srcSize) + ((srcSize)>>8) + (((srcSize) < 128 KB) ? ((128 KB - (srcSize)) >> 11) /* margin, from 64 to 0 */ : 0)) /* this formula ensures that bound(A) + bound(B) <= bound(A+B) as long as A and B >= 128 KB */ >ZSTDLIB_API size_t ZSTD_compressBound(size_t srcSize); /*!< maximum compressed size in worst case scenario */ >ZSTDLIB_API unsigned ZSTD_isError(size_t code); /*!< tells if a `size_t` function result is an error code */ >ZSTDLIB_API const char* ZSTD_getErrorName(size_t code); /*!< provides readable string from an error code */ >ZSTDLIB_API int ZSTD_maxCLevel(void); /*!< maximum compression level available */ > > >/*************************************** >* Explicit memory management >***************************************/ >/*= Compression context > * When compressing many times, > * it is recommended to allocate a context just once, and re-use it for each successive compression operation. > * This will make workload friendlier for system's memory. > * Use one context per thread for parallel execution in multi-threaded environments. */ >typedef struct ZSTD_CCtx_s ZSTD_CCtx; >ZSTDLIB_API ZSTD_CCtx* ZSTD_createCCtx(void); >ZSTDLIB_API size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx); > >/*! ZSTD_compressCCtx() : > * Same as ZSTD_compress(), requires an allocated ZSTD_CCtx (see ZSTD_createCCtx()). */ >ZSTDLIB_API size_t ZSTD_compressCCtx(ZSTD_CCtx* ctx, > void* dst, size_t dstCapacity, > const void* src, size_t srcSize, > int compressionLevel); > >/*= Decompression context > * When decompressing many times, > * it is recommended to allocate a context only once, > * and re-use it for each successive compression operation. > * This will make workload friendlier for system's memory. > * Use one context per thread for parallel execution. */ >typedef struct ZSTD_DCtx_s ZSTD_DCtx; >ZSTDLIB_API ZSTD_DCtx* ZSTD_createDCtx(void); >ZSTDLIB_API size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx); > >/*! ZSTD_decompressDCtx() : > * Same as ZSTD_decompress(), requires an allocated ZSTD_DCtx (see ZSTD_createDCtx()) */ >ZSTDLIB_API size_t ZSTD_decompressDCtx(ZSTD_DCtx* ctx, > void* dst, size_t dstCapacity, > const void* src, size_t srcSize); > > >/************************** >* Simple dictionary API >***************************/ >/*! ZSTD_compress_usingDict() : > * Compression using a predefined Dictionary (see dictBuilder/zdict.h). > * Note : This function loads the dictionary, resulting in significant startup delay. > * Note : When `dict == NULL || dictSize < 8` no dictionary is used. */ >ZSTDLIB_API size_t ZSTD_compress_usingDict(ZSTD_CCtx* ctx, > void* dst, size_t dstCapacity, > const void* src, size_t srcSize, > const void* dict,size_t dictSize, > int compressionLevel); > >/*! ZSTD_decompress_usingDict() : > * Decompression using a predefined Dictionary (see dictBuilder/zdict.h). > * Dictionary must be identical to the one used during compression. > * Note : This function loads the dictionary, resulting in significant startup delay. > * Note : When `dict == NULL || dictSize < 8` no dictionary is used. */ >ZSTDLIB_API size_t ZSTD_decompress_usingDict(ZSTD_DCtx* dctx, > void* dst, size_t dstCapacity, > const void* src, size_t srcSize, > const void* dict,size_t dictSize); > > >/********************************** > * Bulk processing dictionary API > *********************************/ >typedef struct ZSTD_CDict_s ZSTD_CDict; > >/*! ZSTD_createCDict() : > * When compressing multiple messages / blocks with the same dictionary, it's recommended to load it just once. > * ZSTD_createCDict() will create a digested dictionary, ready to start future compression operations without startup delay. > * ZSTD_CDict can be created once and shared by multiple threads concurrently, since its usage is read-only. > * `dictBuffer` can be released after ZSTD_CDict creation, since its content is copied within CDict */ >ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict(const void* dictBuffer, size_t dictSize, > int compressionLevel); > >/*! ZSTD_freeCDict() : > * Function frees memory allocated by ZSTD_createCDict(). */ >ZSTDLIB_API size_t ZSTD_freeCDict(ZSTD_CDict* CDict); > >/*! ZSTD_compress_usingCDict() : > * Compression using a digested Dictionary. > * Faster startup than ZSTD_compress_usingDict(), recommended when same dictionary is used multiple times. > * Note that compression level is decided during dictionary creation. > * Frame parameters are hardcoded (dictID=yes, contentSize=yes, checksum=no) */ >ZSTDLIB_API size_t ZSTD_compress_usingCDict(ZSTD_CCtx* cctx, > void* dst, size_t dstCapacity, > const void* src, size_t srcSize, > const ZSTD_CDict* cdict); > > >typedef struct ZSTD_DDict_s ZSTD_DDict; > >/*! ZSTD_createDDict() : > * Create a digested dictionary, ready to start decompression operation without startup delay. > * dictBuffer can be released after DDict creation, as its content is copied inside DDict */ >ZSTDLIB_API ZSTD_DDict* ZSTD_createDDict(const void* dictBuffer, size_t dictSize); > >/*! ZSTD_freeDDict() : > * Function frees memory allocated with ZSTD_createDDict() */ >ZSTDLIB_API size_t ZSTD_freeDDict(ZSTD_DDict* ddict); > >/*! ZSTD_decompress_usingDDict() : > * Decompression using a digested Dictionary. > * Faster startup than ZSTD_decompress_usingDict(), recommended when same dictionary is used multiple times. */ >ZSTDLIB_API size_t ZSTD_decompress_usingDDict(ZSTD_DCtx* dctx, > void* dst, size_t dstCapacity, > const void* src, size_t srcSize, > const ZSTD_DDict* ddict); > > >/**************************** >* Streaming >****************************/ > >typedef struct ZSTD_inBuffer_s { > const void* src; /**< start of input buffer */ > size_t size; /**< size of input buffer */ > size_t pos; /**< position where reading stopped. Will be updated. Necessarily 0 <= pos <= size */ >} ZSTD_inBuffer; > >typedef struct ZSTD_outBuffer_s { > void* dst; /**< start of output buffer */ > size_t size; /**< size of output buffer */ > size_t pos; /**< position where writing stopped. Will be updated. Necessarily 0 <= pos <= size */ >} ZSTD_outBuffer; > > > >/*-*********************************************************************** >* Streaming compression - HowTo >* >* A ZSTD_CStream object is required to track streaming operation. >* Use ZSTD_createCStream() and ZSTD_freeCStream() to create/release resources. >* ZSTD_CStream objects can be reused multiple times on consecutive compression operations. >* It is recommended to re-use ZSTD_CStream in situations where many streaming operations will be achieved consecutively, >* since it will play nicer with system's memory, by re-using already allocated memory. >* Use one separate ZSTD_CStream per thread for parallel execution. >* >* Start a new compression by initializing ZSTD_CStream. >* Use ZSTD_initCStream() to start a new compression operation. >* Use ZSTD_initCStream_usingDict() or ZSTD_initCStream_usingCDict() for a compression which requires a dictionary (experimental section) >* >* Use ZSTD_compressStream() repetitively to consume input stream. >* The function will automatically update both `pos` fields. >* Note that it may not consume the entire input, in which case `pos < size`, >* and it's up to the caller to present again remaining data. >* @return : a size hint, preferred nb of bytes to use as input for next function call >* or an error code, which can be tested using ZSTD_isError(). >* Note 1 : it's just a hint, to help latency a little, any other value will work fine. >* Note 2 : size hint is guaranteed to be <= ZSTD_CStreamInSize() >* >* At any moment, it's possible to flush whatever data remains within internal buffer, using ZSTD_flushStream(). >* `output->pos` will be updated. >* Note that some content might still be left within internal buffer if `output->size` is too small. >* @return : nb of bytes still present within internal buffer (0 if it's empty) >* or an error code, which can be tested using ZSTD_isError(). >* >* ZSTD_endStream() instructs to finish a frame. >* It will perform a flush and write frame epilogue. >* The epilogue is required for decoders to consider a frame completed. >* ZSTD_endStream() may not be able to flush full data if `output->size` is too small. >* In which case, call again ZSTD_endStream() to complete the flush. >* @return : 0 if frame fully completed and fully flushed, > or >0 if some data is still present within internal buffer > (value is minimum size estimation for remaining data to flush, but it could be more) >* or an error code, which can be tested using ZSTD_isError(). >* >* *******************************************************************/ > >typedef ZSTD_CCtx ZSTD_CStream; /**< CCtx and CStream are now effectively same object (>= v1.3.0) */ > /* Continue to distinguish them for compatibility with versions <= v1.2.0 */ >/*===== ZSTD_CStream management functions =====*/ >ZSTDLIB_API ZSTD_CStream* ZSTD_createCStream(void); >ZSTDLIB_API size_t ZSTD_freeCStream(ZSTD_CStream* zcs); > >/*===== Streaming compression functions =====*/ >ZSTDLIB_API size_t ZSTD_initCStream(ZSTD_CStream* zcs, int compressionLevel); >ZSTDLIB_API size_t ZSTD_compressStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output, ZSTD_inBuffer* input); >ZSTDLIB_API size_t ZSTD_flushStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output); >ZSTDLIB_API size_t ZSTD_endStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output); > >ZSTDLIB_API size_t ZSTD_CStreamInSize(void); /**< recommended size for input buffer */ >ZSTDLIB_API size_t ZSTD_CStreamOutSize(void); /**< recommended size for output buffer. Guarantee to successfully flush at least one complete compressed block in all circumstances. */ > > > >/*-*************************************************************************** >* Streaming decompression - HowTo >* >* A ZSTD_DStream object is required to track streaming operations. >* Use ZSTD_createDStream() and ZSTD_freeDStream() to create/release resources. >* ZSTD_DStream objects can be re-used multiple times. >* >* Use ZSTD_initDStream() to start a new decompression operation, >* or ZSTD_initDStream_usingDict() if decompression requires a dictionary. >* @return : recommended first input size >* >* Use ZSTD_decompressStream() repetitively to consume your input. >* The function will update both `pos` fields. >* If `input.pos < input.size`, some input has not been consumed. >* It's up to the caller to present again remaining data. >* If `output.pos < output.size`, decoder has flushed everything it could. >* @return : 0 when a frame is completely decoded and fully flushed, >* an error code, which can be tested using ZSTD_isError(), >* any other value > 0, which means there is still some decoding to do to complete current frame. >* The return value is a suggested next input size (a hint to improve latency) that will never load more than the current frame. >* *******************************************************************************/ > >typedef ZSTD_DCtx ZSTD_DStream; /**< DCtx and DStream are now effectively same object (>= v1.3.0) */ > /* Continue to distinguish them for compatibility with versions <= v1.2.0 */ >/*===== ZSTD_DStream management functions =====*/ >ZSTDLIB_API ZSTD_DStream* ZSTD_createDStream(void); >ZSTDLIB_API size_t ZSTD_freeDStream(ZSTD_DStream* zds); > >/*===== Streaming decompression functions =====*/ >ZSTDLIB_API size_t ZSTD_initDStream(ZSTD_DStream* zds); >ZSTDLIB_API size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inBuffer* input); > >ZSTDLIB_API size_t ZSTD_DStreamInSize(void); /*!< recommended size for input buffer */ >ZSTDLIB_API size_t ZSTD_DStreamOutSize(void); /*!< recommended size for output buffer. Guarantee to successfully flush at least one complete block in all circumstances. */ > >#endif /* ZSTD_H_235446 */ ># 361 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/zstd.h" > > > >/**************************************************************************************** > * START OF ADVANCED AND EXPERIMENTAL FUNCTIONS > * The definitions in this section are considered experimental. > * They should never be used with a dynamic library, as prototypes may change in the future. > * They are provided for advanced scenarios. > * Use them only in association with static linking. > * ***************************************************************************************/ > >#if defined(ZSTD_STATIC_LINKING_ONLY) && !defined(ZSTD_H_ZSTD_STATIC_LINKING_ONLY) >#define ZSTD_H_ZSTD_STATIC_LINKING_ONLY > >/* --- Constants ---*/ >#define ZSTD_MAGICNUMBER 0xFD2FB528 /* >= v0.8.0 */ >#define ZSTD_MAGIC_SKIPPABLE_START 0x184D2A50U >#define ZSTD_MAGIC_DICTIONARY 0xEC30A437 /* v0.7+ */ > >#define ZSTD_WINDOWLOG_MAX_32 30 >#define ZSTD_WINDOWLOG_MAX_64 31 >#define ZSTD_WINDOWLOG_MAX ((unsigned)(sizeof(size_t) == 4 ? ZSTD_WINDOWLOG_MAX_32 : ZSTD_WINDOWLOG_MAX_64)) >#define ZSTD_WINDOWLOG_MIN 10 >#define ZSTD_HASHLOG_MAX MIN(ZSTD_WINDOWLOG_MAX, 30) >#define ZSTD_HASHLOG_MIN 6 >#define ZSTD_CHAINLOG_MAX MIN(ZSTD_WINDOWLOG_MAX+1, 30) >#define ZSTD_CHAINLOG_MIN ZSTD_HASHLOG_MIN >#define ZSTD_HASHLOG3_MAX 17 >#define ZSTD_SEARCHLOG_MAX (ZSTD_WINDOWLOG_MAX-1) >#define ZSTD_SEARCHLOG_MIN 1 >#define ZSTD_SEARCHLENGTH_MAX 7 /* only for ZSTD_fast, other strategies are limited to 6 */ >#define ZSTD_SEARCHLENGTH_MIN 3 /* only for ZSTD_btopt, other strategies are limited to 4 */ >#define ZSTD_TARGETLENGTH_MIN 4 /* only useful for btopt */ >#define ZSTD_TARGETLENGTH_MAX 999 /* only useful for btopt */ >#define ZSTD_LDM_MINMATCH_MIN 4 >#define ZSTD_LDM_MINMATCH_MAX 4096 >#define ZSTD_LDM_BUCKETSIZELOG_MAX 8 > >#define ZSTD_FRAMEHEADERSIZE_PREFIX 5 /* minimum input size to know frame header size */ >#define ZSTD_FRAMEHEADERSIZE_MIN 6 >#define ZSTD_FRAMEHEADERSIZE_MAX 18 /* for static allocation */ >static const size_t ZSTD_frameHeaderSize_prefix = ZSTD_FRAMEHEADERSIZE_PREFIX; >static const size_t ZSTD_frameHeaderSize_min = ZSTD_FRAMEHEADERSIZE_MIN; >static const size_t ZSTD_frameHeaderSize_max = ZSTD_FRAMEHEADERSIZE_MAX; >static const size_t ZSTD_skippableHeaderSize = 8; /* magic number + skippable frame length */ > > >/*--- Advanced types ---*/ >typedef enum { ZSTD_fast=1, ZSTD_dfast, ZSTD_greedy, ZSTD_lazy, ZSTD_lazy2, > ZSTD_btlazy2, ZSTD_btopt, ZSTD_btultra } ZSTD_strategy; /* from faster to stronger */ > >typedef struct { > unsigned windowLog; /**< largest match distance : larger == more compression, more memory needed during decompression */ > unsigned chainLog; /**< fully searched segment : larger == more compression, slower, more memory (useless for fast) */ > unsigned hashLog; /**< dispatch table : larger == faster, more memory */ > unsigned searchLog; /**< nb of searches : larger == more compression, slower */ > unsigned searchLength; /**< match length searched : larger == faster decompression, sometimes less compression */ > unsigned targetLength; /**< acceptable match size for optimal parser (only) : larger == more compression, slower */ > ZSTD_strategy strategy; >} ZSTD_compressionParameters; > >typedef struct { > unsigned contentSizeFlag; /**< 1: content size will be in frame header (when known) */ > unsigned checksumFlag; /**< 1: generate a 32-bits checksum at end of frame, for error detection */ > unsigned noDictIDFlag; /**< 1: no dictID will be saved into frame header (if dictionary compression) */ >} ZSTD_frameParameters; > >typedef struct { > ZSTD_compressionParameters cParams; > ZSTD_frameParameters fParams; >} ZSTD_parameters; > >typedef struct ZSTD_CCtx_params_s ZSTD_CCtx_params; > >/*= Custom memory allocation functions */ >typedef void* (*ZSTD_allocFunction) (void* opaque, size_t size); >typedef void (*ZSTD_freeFunction) (void* opaque, void* address); >typedef struct { ZSTD_allocFunction customAlloc; ZSTD_freeFunction customFree; void* opaque; } ZSTD_customMem; >/* use this constant to defer to stdlib's functions */ >static const ZSTD_customMem ZSTD_defaultCMem = { NULL, NULL, NULL }; > > >/*************************************** >* Frame size functions >***************************************/ > >/*! ZSTD_findFrameCompressedSize() : > * `src` should point to the start of a ZSTD encoded frame or skippable frame > * `srcSize` must be at least as large as the frame > * @return : the compressed size of the first frame starting at `src`, > * suitable to pass to `ZSTD_decompress` or similar, > * or an error code if input is invalid */ >ZSTDLIB_API size_t ZSTD_findFrameCompressedSize(const void* src, size_t srcSize); > >/*! ZSTD_findDecompressedSize() : > * `src` should point the start of a series of ZSTD encoded and/or skippable frames > * `srcSize` must be the _exact_ size of this series > * (i.e. there should be a frame boundary exactly at `srcSize` bytes after `src`) > * @return : - decompressed size of all data in all successive frames > * - if the decompressed size cannot be determined: ZSTD_CONTENTSIZE_UNKNOWN > * - if an error occurred: ZSTD_CONTENTSIZE_ERROR > * > * note 1 : decompressed size is an optional field, that may not be present, especially in streaming mode. > * When `return==ZSTD_CONTENTSIZE_UNKNOWN`, data to decompress could be any size. > * In which case, it's necessary to use streaming mode to decompress data. > * note 2 : decompressed size is always present when compression is done with ZSTD_compress() > * note 3 : decompressed size can be very large (64-bits value), > * potentially larger than what local system can handle as a single memory segment. > * In which case, it's necessary to use streaming mode to decompress data. > * note 4 : If source is untrusted, decompressed size could be wrong or intentionally modified. > * Always ensure result fits within application's authorized limits. > * Each application can set its own limits. > * note 5 : ZSTD_findDecompressedSize handles multiple frames, and so it must traverse the input to > * read each contained frame header. This is fast as most of the data is skipped, > * however it does mean that all frame data must be present and valid. */ >ZSTDLIB_API unsigned long long ZSTD_findDecompressedSize(const void* src, size_t srcSize); > >/*! ZSTD_frameHeaderSize() : >* `src` should point to the start of a ZSTD frame >* `srcSize` must be >= ZSTD_frameHeaderSize_prefix. >* @return : size of the Frame Header */ >ZSTDLIB_API size_t ZSTD_frameHeaderSize(const void* src, size_t srcSize); > > >/*************************************** >* Context memory usage >***************************************/ > >/*! ZSTD_sizeof_*() : > * These functions give the current memory usage of selected object. > * Object memory usage can evolve when re-used multiple times. */ >ZSTDLIB_API size_t ZSTD_sizeof_CCtx(const ZSTD_CCtx* cctx); >ZSTDLIB_API size_t ZSTD_sizeof_DCtx(const ZSTD_DCtx* dctx); >ZSTDLIB_API size_t ZSTD_sizeof_CStream(const ZSTD_CStream* zcs); >ZSTDLIB_API size_t ZSTD_sizeof_DStream(const ZSTD_DStream* zds); >ZSTDLIB_API size_t ZSTD_sizeof_CDict(const ZSTD_CDict* cdict); >ZSTDLIB_API size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict); > >/*! ZSTD_estimate*() : > * These functions make it possible to estimate memory usage > * of a future {D,C}Ctx, before its creation. > * ZSTD_estimateCCtxSize() will provide a budget large enough for any compression level up to selected one. > * It will also consider src size to be arbitrarily "large", which is worst case. > * If srcSize is known to always be small, ZSTD_estimateCCtxSize_usingCParams() can provide a tighter estimation. > * ZSTD_estimateCCtxSize_usingCParams() can be used in tandem with ZSTD_getCParams() to create cParams from compressionLevel. > * ZSTD_estimateCCtxSize_usingCCtxParams() can be used in tandem with ZSTD_CCtxParam_setParameter(). Only single-threaded compression is supported. This function will return an error code if ZSTD_p_nbThreads is > 1. > * Note : CCtx estimation is only correct for single-threaded compression */ >ZSTDLIB_API size_t ZSTD_estimateCCtxSize(int compressionLevel); >ZSTDLIB_API size_t ZSTD_estimateCCtxSize_usingCParams(ZSTD_compressionParameters cParams); >ZSTDLIB_API size_t ZSTD_estimateCCtxSize_usingCCtxParams(const ZSTD_CCtx_params* params); >ZSTDLIB_API size_t ZSTD_estimateDCtxSize(void); > >/*! ZSTD_estimateCStreamSize() : > * ZSTD_estimateCStreamSize() will provide a budget large enough for any compression level up to selected one. > * It will also consider src size to be arbitrarily "large", which is worst case. > * If srcSize is known to always be small, ZSTD_estimateCStreamSize_usingCParams() can provide a tighter estimation. > * ZSTD_estimateCStreamSize_usingCParams() can be used in tandem with ZSTD_getCParams() to create cParams from compressionLevel. > * ZSTD_estimateCStreamSize_usingCCtxParams() can be used in tandem with ZSTD_CCtxParam_setParameter(). Only single-threaded compression is supported. This function will return an error code if ZSTD_p_nbThreads is set to a value > 1. > * Note : CStream estimation is only correct for single-threaded compression. > * ZSTD_DStream memory budget depends on window Size. > * This information can be passed manually, using ZSTD_estimateDStreamSize, > * or deducted from a valid frame Header, using ZSTD_estimateDStreamSize_fromFrame(); > * Note : if streaming is init with function ZSTD_init?Stream_usingDict(), > * an internal ?Dict will be created, which additional size is not estimated here. > * In this case, get total size by adding ZSTD_estimate?DictSize */ >ZSTDLIB_API size_t ZSTD_estimateCStreamSize(int compressionLevel); >ZSTDLIB_API size_t ZSTD_estimateCStreamSize_usingCParams(ZSTD_compressionParameters cParams); >ZSTDLIB_API size_t ZSTD_estimateCStreamSize_usingCCtxParams(const ZSTD_CCtx_params* params); >ZSTDLIB_API size_t ZSTD_estimateDStreamSize(size_t windowSize); >ZSTDLIB_API size_t ZSTD_estimateDStreamSize_fromFrame(const void* src, size_t srcSize); > >typedef enum { > ZSTD_dlm_byCopy = 0, /**< Copy dictionary content internally */ > ZSTD_dlm_byRef, /**< Reference dictionary content -- the dictionary buffer must outlive its users. */ >} ZSTD_dictLoadMethod_e; > >/*! ZSTD_estimate?DictSize() : > * ZSTD_estimateCDictSize() will bet that src size is relatively "small", and content is copied, like ZSTD_createCDict(). > * ZSTD_estimateCStreamSize_advanced_usingCParams() makes it possible to control precisely compression parameters, like ZSTD_createCDict_advanced(). > * Note : dictionary created by reference using ZSTD_dlm_byRef are smaller > */ >ZSTDLIB_API size_t ZSTD_estimateCDictSize(size_t dictSize, int compressionLevel); >ZSTDLIB_API size_t ZSTD_estimateCDictSize_advanced(size_t dictSize, ZSTD_compressionParameters cParams, ZSTD_dictLoadMethod_e dictLoadMethod); >ZSTDLIB_API size_t ZSTD_estimateDDictSize(size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod); > > >/*************************************** >* Advanced compression functions >***************************************/ >/*! ZSTD_createCCtx_advanced() : > * Create a ZSTD compression context using external alloc and free functions */ >ZSTDLIB_API ZSTD_CCtx* ZSTD_createCCtx_advanced(ZSTD_customMem customMem); > >/*! ZSTD_initStaticCCtx() : initialize a fixed-size zstd compression context > * workspace: The memory area to emplace the context into. > * Provided pointer must 8-bytes aligned. > * It must outlive context usage. > * workspaceSize: Use ZSTD_estimateCCtxSize() or ZSTD_estimateCStreamSize() > * to determine how large workspace must be to support scenario. > * @return : pointer to ZSTD_CCtx*, or NULL if error (size too small) > * Note : zstd will never resize nor malloc() when using a static cctx. > * If it needs more memory than available, it will simply error out. > * Note 2 : there is no corresponding "free" function. > * Since workspace was allocated externally, it must be freed externally too. > * Limitation 1 : currently not compatible with internal CDict creation, such as > * ZSTD_CCtx_loadDictionary() or ZSTD_initCStream_usingDict(). > * Limitation 2 : currently not compatible with multi-threading > */ >ZSTDLIB_API ZSTD_CCtx* ZSTD_initStaticCCtx(void* workspace, size_t workspaceSize); > > >/*! ZSTD_createCDict_byReference() : > * Create a digested dictionary for compression > * Dictionary content is simply referenced, and therefore stays in dictBuffer. > * It is important that dictBuffer outlives CDict, it must remain read accessible throughout the lifetime of CDict */ >ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict_byReference(const void* dictBuffer, size_t dictSize, int compressionLevel); > >typedef enum { ZSTD_dm_auto=0, /* dictionary is "full" if it starts with ZSTD_MAGIC_DICTIONARY, otherwise it is "rawContent" */ > ZSTD_dm_rawContent, /* ensures dictionary is always loaded as rawContent, even if it starts with ZSTD_MAGIC_DICTIONARY */ > ZSTD_dm_fullDict /* refuses to load a dictionary if it does not respect Zstandard's specification */ >} ZSTD_dictMode_e; >/*! ZSTD_createCDict_advanced() : > * Create a ZSTD_CDict using external alloc and free, and customized compression parameters */ >ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict_advanced(const void* dict, size_t dictSize, > ZSTD_dictLoadMethod_e dictLoadMethod, > ZSTD_dictMode_e dictMode, > ZSTD_compressionParameters cParams, > ZSTD_customMem customMem); > >/*! ZSTD_initStaticCDict_advanced() : > * Generate a digested dictionary in provided memory area. > * workspace: The memory area to emplace the dictionary into. > * Provided pointer must 8-bytes aligned. > * It must outlive dictionary usage. > * workspaceSize: Use ZSTD_estimateCDictSize() > * to determine how large workspace must be. > * cParams : use ZSTD_getCParams() to transform a compression level > * into its relevants cParams. > * @return : pointer to ZSTD_CDict*, or NULL if error (size too small) > * Note : there is no corresponding "free" function. > * Since workspace was allocated externally, it must be freed externally. > */ >ZSTDLIB_API ZSTD_CDict* ZSTD_initStaticCDict( > void* workspace, size_t workspaceSize, > const void* dict, size_t dictSize, > ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictMode_e dictMode, > ZSTD_compressionParameters cParams); > >/*! ZSTD_getCParams() : >* @return ZSTD_compressionParameters structure for a selected compression level and estimated srcSize. >* `estimatedSrcSize` value is optional, select 0 if not known */ >ZSTDLIB_API ZSTD_compressionParameters ZSTD_getCParams(int compressionLevel, unsigned long long estimatedSrcSize, size_t dictSize); > >/*! ZSTD_getParams() : >* same as ZSTD_getCParams(), but @return a full `ZSTD_parameters` object instead of sub-component `ZSTD_compressionParameters`. >* All fields of `ZSTD_frameParameters` are set to default (0) */ >ZSTDLIB_API ZSTD_parameters ZSTD_getParams(int compressionLevel, unsigned long long estimatedSrcSize, size_t dictSize); > >/*! ZSTD_checkCParams() : >* Ensure param values remain within authorized range */ >ZSTDLIB_API size_t ZSTD_checkCParams(ZSTD_compressionParameters params); > >/*! ZSTD_adjustCParams() : > * optimize params for a given `srcSize` and `dictSize`. > * both values are optional, select `0` if unknown. */ >ZSTDLIB_API ZSTD_compressionParameters ZSTD_adjustCParams(ZSTD_compressionParameters cPar, unsigned long long srcSize, size_t dictSize); > >/*! ZSTD_compress_advanced() : >* Same as ZSTD_compress_usingDict(), with fine-tune control over each compression parameter */ >ZSTDLIB_API size_t ZSTD_compress_advanced (ZSTD_CCtx* cctx, > void* dst, size_t dstCapacity, > const void* src, size_t srcSize, > const void* dict,size_t dictSize, > ZSTD_parameters params); > >/*! ZSTD_compress_usingCDict_advanced() : >* Same as ZSTD_compress_usingCDict(), with fine-tune control over frame parameters */ >ZSTDLIB_API size_t ZSTD_compress_usingCDict_advanced(ZSTD_CCtx* cctx, > void* dst, size_t dstCapacity, > const void* src, size_t srcSize, > const ZSTD_CDict* cdict, ZSTD_frameParameters fParams); > > >/*--- Advanced decompression functions ---*/ > >/*! ZSTD_isFrame() : > * Tells if the content of `buffer` starts with a valid Frame Identifier. > * Note : Frame Identifier is 4 bytes. If `size < 4`, @return will always be 0. > * Note 2 : Legacy Frame Identifiers are considered valid only if Legacy Support is enabled. > * Note 3 : Skippable Frame Identifiers are considered valid. */ >ZSTDLIB_API unsigned ZSTD_isFrame(const void* buffer, size_t size); > >/*! ZSTD_createDCtx_advanced() : > * Create a ZSTD decompression context using external alloc and free functions */ >ZSTDLIB_API ZSTD_DCtx* ZSTD_createDCtx_advanced(ZSTD_customMem customMem); > >/*! ZSTD_initStaticDCtx() : initialize a fixed-size zstd decompression context > * workspace: The memory area to emplace the context into. > * Provided pointer must 8-bytes aligned. > * It must outlive context usage. > * workspaceSize: Use ZSTD_estimateDCtxSize() or ZSTD_estimateDStreamSize() > * to determine how large workspace must be to support scenario. > * @return : pointer to ZSTD_DCtx*, or NULL if error (size too small) > * Note : zstd will never resize nor malloc() when using a static dctx. > * If it needs more memory than available, it will simply error out. > * Note 2 : static dctx is incompatible with legacy support > * Note 3 : there is no corresponding "free" function. > * Since workspace was allocated externally, it must be freed externally. > * Limitation : currently not compatible with internal DDict creation, > * such as ZSTD_initDStream_usingDict(). > */ >ZSTDLIB_API ZSTD_DCtx* ZSTD_initStaticDCtx(void* workspace, size_t workspaceSize); > >/*! ZSTD_createDDict_byReference() : > * Create a digested dictionary, ready to start decompression operation without startup delay. > * Dictionary content is referenced, and therefore stays in dictBuffer. > * It is important that dictBuffer outlives DDict, > * it must remain read accessible throughout the lifetime of DDict */ >ZSTDLIB_API ZSTD_DDict* ZSTD_createDDict_byReference(const void* dictBuffer, size_t dictSize); > >/*! ZSTD_createDDict_advanced() : > * Create a ZSTD_DDict using external alloc and free, optionally by reference */ >ZSTDLIB_API ZSTD_DDict* ZSTD_createDDict_advanced(const void* dict, size_t dictSize, > ZSTD_dictLoadMethod_e dictLoadMethod, > ZSTD_customMem customMem); > >/*! ZSTD_initStaticDDict() : > * Generate a digested dictionary in provided memory area. > * workspace: The memory area to emplace the dictionary into. > * Provided pointer must 8-bytes aligned. > * It must outlive dictionary usage. > * workspaceSize: Use ZSTD_estimateDDictSize() > * to determine how large workspace must be. > * @return : pointer to ZSTD_DDict*, or NULL if error (size too small) > * Note : there is no corresponding "free" function. > * Since workspace was allocated externally, it must be freed externally. > */ >ZSTDLIB_API ZSTD_DDict* ZSTD_initStaticDDict(void* workspace, size_t workspaceSize, > const void* dict, size_t dictSize, > ZSTD_dictLoadMethod_e dictLoadMethod); > >/*! ZSTD_getDictID_fromDict() : > * Provides the dictID stored within dictionary. > * if @return == 0, the dictionary is not conformant with Zstandard specification. > * It can still be loaded, but as a content-only dictionary. */ >ZSTDLIB_API unsigned ZSTD_getDictID_fromDict(const void* dict, size_t dictSize); > >/*! ZSTD_getDictID_fromDDict() : > * Provides the dictID of the dictionary loaded into `ddict`. > * If @return == 0, the dictionary is not conformant to Zstandard specification, or empty. > * Non-conformant dictionaries can still be loaded, but as content-only dictionaries. */ >ZSTDLIB_API unsigned ZSTD_getDictID_fromDDict(const ZSTD_DDict* ddict); > >/*! ZSTD_getDictID_fromFrame() : > * Provides the dictID required to decompressed the frame stored within `src`. > * If @return == 0, the dictID could not be decoded. > * This could for one of the following reasons : > * - The frame does not require a dictionary to be decoded (most common case). > * - The frame was built with dictID intentionally removed. Whatever dictionary is necessary is a hidden information. > * Note : this use case also happens when using a non-conformant dictionary. > * - `srcSize` is too small, and as a result, the frame header could not be decoded (only possible if `srcSize < ZSTD_FRAMEHEADERSIZE_MAX`). > * - This is not a Zstandard frame. > * When identifying the exact failure cause, it's possible to use ZSTD_getFrameHeader(), which will provide a more precise error code. */ >ZSTDLIB_API unsigned ZSTD_getDictID_fromFrame(const void* src, size_t srcSize); > > >/******************************************************************** >* Advanced streaming functions >********************************************************************/ > >/*===== Advanced Streaming compression functions =====*/ >ZSTDLIB_API ZSTD_CStream* ZSTD_createCStream_advanced(ZSTD_customMem customMem); >ZSTDLIB_API ZSTD_CStream* ZSTD_initStaticCStream(void* workspace, size_t workspaceSize); /**< same as ZSTD_initStaticCCtx() */ >ZSTDLIB_API size_t ZSTD_initCStream_srcSize(ZSTD_CStream* zcs, int compressionLevel, unsigned long long pledgedSrcSize); /**< pledgedSrcSize must be correct, a size of 0 means unknown. for a frame size of 0 use initCStream_advanced */ >ZSTDLIB_API size_t ZSTD_initCStream_usingDict(ZSTD_CStream* zcs, const void* dict, size_t dictSize, int compressionLevel); /**< creates of an internal CDict (incompatible with static CCtx), except if dict == NULL or dictSize < 8, in which case no dict is used. Note: dict is loaded with ZSTD_dm_auto (treated as a full zstd dictionary if it begins with ZSTD_MAGIC_DICTIONARY, else as raw content) and ZSTD_dlm_byCopy.*/ >ZSTDLIB_API size_t ZSTD_initCStream_advanced(ZSTD_CStream* zcs, const void* dict, size_t dictSize, > ZSTD_parameters params, unsigned long long pledgedSrcSize); /**< pledgedSrcSize is optional and can be 0 (meaning unknown). note: if the contentSizeFlag is set, pledgedSrcSize == 0 means the source size is actually 0. dict is loaded with ZSTD_dm_auto and ZSTD_dlm_byCopy. */ >ZSTDLIB_API size_t ZSTD_initCStream_usingCDict(ZSTD_CStream* zcs, const ZSTD_CDict* cdict); /**< note : cdict will just be referenced, and must outlive compression session */ >ZSTDLIB_API size_t ZSTD_initCStream_usingCDict_advanced(ZSTD_CStream* zcs, const ZSTD_CDict* cdict, ZSTD_frameParameters fParams, unsigned long long pledgedSrcSize); /**< same as ZSTD_initCStream_usingCDict(), with control over frame parameters */ > >/*! ZSTD_resetCStream() : > * start a new compression job, using same parameters from previous job. > * This is typically useful to skip dictionary loading stage, since it will re-use it in-place.. > * Note that zcs must be init at least once before using ZSTD_resetCStream(). > * pledgedSrcSize==0 means "srcSize unknown". > * If pledgedSrcSize > 0, its value must be correct, as it will be written in header, and controlled at the end. > * @return : 0, or an error code (which can be tested using ZSTD_isError()) */ >ZSTDLIB_API size_t ZSTD_resetCStream(ZSTD_CStream* zcs, unsigned long long pledgedSrcSize); > > >/*===== Advanced Streaming decompression functions =====*/ >ZSTDLIB_API ZSTD_DStream* ZSTD_createDStream_advanced(ZSTD_customMem customMem); >ZSTDLIB_API ZSTD_DStream* ZSTD_initStaticDStream(void* workspace, size_t workspaceSize); /**< same as ZSTD_initStaticDCtx() */ >typedef enum { DStream_p_maxWindowSize } ZSTD_DStreamParameter_e; >ZSTDLIB_API size_t ZSTD_setDStreamParameter(ZSTD_DStream* zds, ZSTD_DStreamParameter_e paramType, unsigned paramValue); /* obsolete : this API will be removed in a future version */ >ZSTDLIB_API size_t ZSTD_initDStream_usingDict(ZSTD_DStream* zds, const void* dict, size_t dictSize); /**< note: no dictionary will be used if dict == NULL or dictSize < 8 */ >ZSTDLIB_API size_t ZSTD_initDStream_usingDDict(ZSTD_DStream* zds, const ZSTD_DDict* ddict); /**< note : ddict is referenced, it must outlive decompression session */ >ZSTDLIB_API size_t ZSTD_resetDStream(ZSTD_DStream* zds); /**< re-use decompression parameters from previous init; saves dictionary loading */ > > >/********************************************************************* >* Buffer-less and synchronous inner streaming functions >* >* This is an advanced API, giving full control over buffer management, for users which need direct control over memory. >* But it's also a complex one, with several restrictions, documented below. >* Prefer normal streaming API for an easier experience. >********************************************************************* */ > >/** > Buffer-less streaming compression (synchronous mode) > > A ZSTD_CCtx object is required to track streaming operations. > Use ZSTD_createCCtx() / ZSTD_freeCCtx() to manage resource. > ZSTD_CCtx object can be re-used multiple times within successive compression operations. > > Start by initializing a context. > Use ZSTD_compressBegin(), or ZSTD_compressBegin_usingDict() for dictionary compression, > or ZSTD_compressBegin_advanced(), for finer parameter control. > It's also possible to duplicate a reference context which has already been initialized, using ZSTD_copyCCtx() > > Then, consume your input using ZSTD_compressContinue(). > There are some important considerations to keep in mind when using this advanced function : > - ZSTD_compressContinue() has no internal buffer. It uses externally provided buffers only. > - Interface is synchronous : input is consumed entirely and produces 1+ compressed blocks. > - Caller must ensure there is enough space in `dst` to store compressed data under worst case scenario. > Worst case evaluation is provided by ZSTD_compressBound(). > ZSTD_compressContinue() doesn't guarantee recover after a failed compression. > - ZSTD_compressContinue() presumes prior input ***is still accessible and unmodified*** (up to maximum distance size, see WindowLog). > It remembers all previous contiguous blocks, plus one separated memory segment (which can itself consists of multiple contiguous blocks) > - ZSTD_compressContinue() detects that prior input has been overwritten when `src` buffer overlaps. > In which case, it will "discard" the relevant memory section from its history. > > Finish a frame with ZSTD_compressEnd(), which will write the last block(s) and optional checksum. > It's possible to use srcSize==0, in which case, it will write a final empty block to end the frame. > Without last block mark, frames are considered unfinished (hence corrupted) by compliant decoders. > > `ZSTD_CCtx` object can be re-used (ZSTD_compressBegin()) to compress again. >*/ > >/*===== Buffer-less streaming compression functions =====*/ >ZSTDLIB_API size_t ZSTD_compressBegin(ZSTD_CCtx* cctx, int compressionLevel); >ZSTDLIB_API size_t ZSTD_compressBegin_usingDict(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, int compressionLevel); >ZSTDLIB_API size_t ZSTD_compressBegin_advanced(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, ZSTD_parameters params, unsigned long long pledgedSrcSize); /**< pledgedSrcSize is optional and can be 0 (meaning unknown). note: if the contentSizeFlag is set, pledgedSrcSize == 0 means the source size is actually 0 */ >ZSTDLIB_API size_t ZSTD_compressBegin_usingCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict); /**< note: fails if cdict==NULL */ >ZSTDLIB_API size_t ZSTD_compressBegin_usingCDict_advanced(ZSTD_CCtx* const cctx, const ZSTD_CDict* const cdict, ZSTD_frameParameters const fParams, unsigned long long const pledgedSrcSize); /* compression parameters are already set within cdict. pledgedSrcSize=0 means null-size */ >ZSTDLIB_API size_t ZSTD_copyCCtx(ZSTD_CCtx* cctx, const ZSTD_CCtx* preparedCCtx, unsigned long long pledgedSrcSize); /**< note: if pledgedSrcSize can be 0, indicating unknown size. if it is non-zero, it must be accurate. for 0 size frames, use compressBegin_advanced */ > >ZSTDLIB_API size_t ZSTD_compressContinue(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize); >ZSTDLIB_API size_t ZSTD_compressEnd(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize); > > >/*- > Buffer-less streaming decompression (synchronous mode) > > A ZSTD_DCtx object is required to track streaming operations. > Use ZSTD_createDCtx() / ZSTD_freeDCtx() to manage it. > A ZSTD_DCtx object can be re-used multiple times. > > First typical operation is to retrieve frame parameters, using ZSTD_getFrameHeader(). > Frame header is extracted from the beginning of compressed frame, so providing only the frame's beginning is enough. > Data fragment must be large enough to ensure successful decoding. > `ZSTD_frameHeaderSize_max` bytes is guaranteed to always be large enough. > @result : 0 : successful decoding, the `ZSTD_frameHeader` structure is correctly filled. > >0 : `srcSize` is too small, please provide at least @result bytes on next attempt. > errorCode, which can be tested using ZSTD_isError(). > > It fills a ZSTD_frameHeader structure with important information to correctly decode the frame, > such as the dictionary ID, content size, or maximum back-reference distance (`windowSize`). > Note that these values could be wrong, either because of data corruption, or because a 3rd party deliberately spoofs false information. > As a consequence, check that values remain within valid application range. > For example, do not allocate memory blindly, check that `windowSize` is within expectation. > Each application can set its own limits, depending on local restrictions. > For extended interoperability, it is recommended to support `windowSize` of at least 8 MB. > > ZSTD_decompressContinue() needs previous data blocks during decompression, up to `windowSize` bytes. > ZSTD_decompressContinue() is very sensitive to contiguity, > if 2 blocks don't follow each other, make sure that either the compressor breaks contiguity at the same place, > or that previous contiguous segment is large enough to properly handle maximum back-reference distance. > There are multiple ways to guarantee this condition. > > The most memory efficient way is to use a round buffer of sufficient size. > Sufficient size is determined by invoking ZSTD_decodingBufferSize_min(), > which can @return an error code if required value is too large for current system (in 32-bits mode). > In a round buffer methodology, ZSTD_decompressContinue() decompresses each block next to previous one, > up to the moment there is not enough room left in the buffer to guarantee decoding another full block, > which maximum size is provided in `ZSTD_frameHeader` structure, field `blockSizeMax`. > At which point, decoding can resume from the beginning of the buffer. > Note that already decoded data stored in the buffer should be flushed before being overwritten. > > There are alternatives possible, for example using two or more buffers of size `windowSize` each, though they consume more memory. > > Finally, if you control the compression process, you can also ignore all buffer size rules, > as long as the encoder and decoder progress in "lock-step", > aka use exactly the same buffer sizes, break contiguity at the same place, etc. > > Once buffers are setup, start decompression, with ZSTD_decompressBegin(). > If decompression requires a dictionary, use ZSTD_decompressBegin_usingDict() or ZSTD_decompressBegin_usingDDict(). > > Then use ZSTD_nextSrcSizeToDecompress() and ZSTD_decompressContinue() alternatively. > ZSTD_nextSrcSizeToDecompress() tells how many bytes to provide as 'srcSize' to ZSTD_decompressContinue(). > ZSTD_decompressContinue() requires this _exact_ amount of bytes, or it will fail. > > @result of ZSTD_decompressContinue() is the number of bytes regenerated within 'dst' (necessarily <= dstCapacity). > It can be zero : it just means ZSTD_decompressContinue() has decoded some metadata item. > It can also be an error code, which can be tested with ZSTD_isError(). > > A frame is fully decoded when ZSTD_nextSrcSizeToDecompress() returns zero. > Context can then be reset to start a new decompression. > > Note : it's possible to know if next input to present is a header or a block, using ZSTD_nextInputType(). > This information is not required to properly decode a frame. > > == Special case : skippable frames == > > Skippable frames allow integration of user-defined data into a flow of concatenated frames. > Skippable frames will be ignored (skipped) by decompressor. > The format of skippable frames is as follows : > a) Skippable frame ID - 4 Bytes, Little endian format, any value from 0x184D2A50 to 0x184D2A5F > b) Frame Size - 4 Bytes, Little endian format, unsigned 32-bits > c) Frame Content - any content (User Data) of length equal to Frame Size > For skippable frames ZSTD_getFrameHeader() returns zfhPtr->frameType==ZSTD_skippableFrame. > For skippable frames ZSTD_decompressContinue() always returns 0 : it only skips the content. >*/ > >/*===== Buffer-less streaming decompression functions =====*/ >typedef enum { ZSTD_frame, ZSTD_skippableFrame } ZSTD_frameType_e; >typedef struct { > unsigned long long frameContentSize; /* if == ZSTD_CONTENTSIZE_UNKNOWN, it means this field is not available. 0 means "empty" */ > unsigned long long windowSize; /* can be very large, up to <= frameContentSize */ > unsigned blockSizeMax; > ZSTD_frameType_e frameType; /* if == ZSTD_skippableFrame, frameContentSize is the size of skippable content */ > unsigned headerSize; > unsigned dictID; > unsigned checksumFlag; >} ZSTD_frameHeader; >ZSTDLIB_API size_t ZSTD_getFrameHeader(ZSTD_frameHeader* zfhPtr, const void* src, size_t srcSize); /**< doesn't consume input */ >ZSTDLIB_API size_t ZSTD_decodingBufferSize_min(unsigned long long windowSize, unsigned long long frameContentSize); /**< when frame content size is not known, pass in frameContentSize == ZSTD_CONTENTSIZE_UNKNOWN */ > >ZSTDLIB_API size_t ZSTD_decompressBegin(ZSTD_DCtx* dctx); >ZSTDLIB_API size_t ZSTD_decompressBegin_usingDict(ZSTD_DCtx* dctx, const void* dict, size_t dictSize); >ZSTDLIB_API size_t ZSTD_decompressBegin_usingDDict(ZSTD_DCtx* dctx, const ZSTD_DDict* ddict); > >ZSTDLIB_API size_t ZSTD_nextSrcSizeToDecompress(ZSTD_DCtx* dctx); >ZSTDLIB_API size_t ZSTD_decompressContinue(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize); > >/* misc */ >ZSTDLIB_API void ZSTD_copyDCtx(ZSTD_DCtx* dctx, const ZSTD_DCtx* preparedDCtx); >typedef enum { ZSTDnit_frameHeader, ZSTDnit_blockHeader, ZSTDnit_block, ZSTDnit_lastBlock, ZSTDnit_checksum, ZSTDnit_skippableFrame } ZSTD_nextInputType_e; >ZSTDLIB_API ZSTD_nextInputType_e ZSTD_nextInputType(ZSTD_DCtx* dctx); > > > >/* ============================================ */ >/** New advanced API (experimental) */ >/* ============================================ */ > >/* notes on API design : > * In this proposal, parameters are pushed one by one into an existing context, > * and then applied on all subsequent compression jobs. > * When no parameter is ever provided, CCtx is created with compression level ZSTD_CLEVEL_DEFAULT. > * > * This API is intended to replace all others experimental API. > * It can basically do all other use cases, and even new ones. > * In constrast with _advanced() variants, it stands a reasonable chance to become "stable", > * after a good testing period. > */ > >/* note on naming convention : > * Initially, the API favored names like ZSTD_setCCtxParameter() . > * In this proposal, convention is changed towards ZSTD_CCtx_setParameter() . > * The main driver is that it identifies more clearly the target object type. > * It feels clearer when considering multiple targets : > * ZSTD_CDict_setParameter() (rather than ZSTD_setCDictParameter()) > * ZSTD_CCtxParams_setParameter() (rather than ZSTD_setCCtxParamsParameter() ) > * etc... > */ > >/* note on enum design : > * All enum will be pinned to explicit values before reaching "stable API" status */ > >typedef enum { > /* Question : should we have a format ZSTD_f_auto ? > * For the time being, it would mean exactly the same as ZSTD_f_zstd1. > * But, in the future, should several formats be supported, > * on the compression side, it would mean "default format". > * On the decompression side, it would mean "multi format", > * and ZSTD_f_zstd1 could be reserved to mean "accept *only* zstd frames". > * Since meaning is a little different, another option could be to define different enums for compression and decompression. > * This question could be kept for later, when there are actually multiple formats to support, > * but there is also the question of pinning enum values, and pinning value `0` is especially important */ > ZSTD_f_zstd1 = 0, /* zstd frame format, specified in zstd_compression_format.md (default) */ > ZSTD_f_zstd1_magicless, /* Variant of zstd frame format, without initial 4-bytes magic number. > * Useful to save 4 bytes per generated frame. > * Decoder cannot recognise automatically this format, requiring instructions. */ >} ZSTD_format_e; > >typedef enum { > /* compression format */ > ZSTD_p_format = 10, /* See ZSTD_format_e enum definition. > * Cast selected format as unsigned for ZSTD_CCtx_setParameter() compatibility. */ > > /* compression parameters */ > ZSTD_p_compressionLevel=100, /* Update all compression parameters according to pre-defined cLevel table > * Default level is ZSTD_CLEVEL_DEFAULT==3. > * Special: value 0 means "do not change cLevel". */ > ZSTD_p_windowLog, /* Maximum allowed back-reference distance, expressed as power of 2. > * Must be clamped between ZSTD_WINDOWLOG_MIN and ZSTD_WINDOWLOG_MAX. > * Special: value 0 means "do not change windowLog". > * Note: Using a window size greater than ZSTD_MAXWINDOWSIZE_DEFAULT (default: 2^27) > * requires setting the maximum window size at least as large during decompression. */ > ZSTD_p_hashLog, /* Size of the probe table, as a power of 2. > * Resulting table size is (1 << (hashLog+2)). > * Must be clamped between ZSTD_HASHLOG_MIN and ZSTD_HASHLOG_MAX. > * Larger tables improve compression ratio of strategies <= dFast, > * and improve speed of strategies > dFast. > * Special: value 0 means "do not change hashLog". */ > ZSTD_p_chainLog, /* Size of the full-search table, as a power of 2. > * Resulting table size is (1 << (chainLog+2)). > * Larger tables result in better and slower compression. > * This parameter is useless when using "fast" strategy. > * Special: value 0 means "do not change chainLog". */ > ZSTD_p_searchLog, /* Number of search attempts, as a power of 2. > * More attempts result in better and slower compression. > * This parameter is useless when using "fast" and "dFast" strategies. > * Special: value 0 means "do not change searchLog". */ > ZSTD_p_minMatch, /* Minimum size of searched matches (note : repCode matches can be smaller). > * Larger values make faster compression and decompression, but decrease ratio. > * Must be clamped between ZSTD_SEARCHLENGTH_MIN and ZSTD_SEARCHLENGTH_MAX. > * Note that currently, for all strategies < btopt, effective minimum is 4. > * Note that currently, for all strategies > fast, effective maximum is 6. > * Special: value 0 means "do not change minMatchLength". */ > ZSTD_p_targetLength, /* Only useful for strategies >= btopt. > * Length of Match considered "good enough" to stop search. > * Larger values make compression stronger and slower. > * Special: value 0 means "do not change targetLength". */ > ZSTD_p_compressionStrategy, /* See ZSTD_strategy enum definition. > * Cast selected strategy as unsigned for ZSTD_CCtx_setParameter() compatibility. > * The higher the value of selected strategy, the more complex it is, > * resulting in stronger and slower compression. > * Special: value 0 means "do not change strategy". */ > > /* frame parameters */ > ZSTD_p_contentSizeFlag=200, /* Content size is written into frame header _whenever known_ (default:1) > * note that content size must be known at the beginning, > * it is sent using ZSTD_CCtx_setPledgedSrcSize() */ > ZSTD_p_checksumFlag, /* A 32-bits checksum of content is written at end of frame (default:0) */ > ZSTD_p_dictIDFlag, /* When applicable, dictID of dictionary is provided in frame header (default:1) */ > > /* multi-threading parameters */ > ZSTD_p_nbThreads=400, /* Select how many threads a compression job can spawn (default:1) > * More threads improve speed, but also increase memory usage. > * Can only receive a value > 1 if ZSTD_MULTITHREAD is enabled. > * Special: value 0 means "do not change nbThreads" */ > ZSTD_p_jobSize, /* Size of a compression job. Each compression job is completed in parallel. > * 0 means default, which is dynamically determined based on compression parameters. > * Job size must be a minimum of overlapSize, or 1 KB, whichever is largest > * The minimum size is automatically and transparently enforced */ > ZSTD_p_overlapSizeLog, /* Size of previous input reloaded at the beginning of each job. > * 0 => no overlap, 6(default) => use 1/8th of windowSize, >=9 => use full windowSize */ > > /* advanced parameters - may not remain available after API update */ > ZSTD_p_forceMaxWindow=1100, /* Force back-reference distances to remain < windowSize, > * even when referencing into Dictionary content (default:0) */ > ZSTD_p_enableLongDistanceMatching=1200, /* Enable long distance matching. > * This parameter is designed to improve the compression > * ratio for large inputs with long distance matches. > * This increases the memory usage as well as window size. > * Note: setting this parameter sets all the LDM parameters > * as well as ZSTD_p_windowLog. It should be set after > * ZSTD_p_compressionLevel and before ZSTD_p_windowLog and > * other LDM parameters. Setting the compression level > * after this parameter overrides the window log, though LDM > * will remain enabled until explicitly disabled. */ > ZSTD_p_ldmHashLog, /* Size of the table for long distance matching, as a power of 2. > * Larger values increase memory usage and compression ratio, but decrease > * compression speed. > * Must be clamped between ZSTD_HASHLOG_MIN and ZSTD_HASHLOG_MAX > * (default: windowlog - 7). */ > ZSTD_p_ldmMinMatch, /* Minimum size of searched matches for long distance matcher. > * Larger/too small values usually decrease compression ratio. > * Must be clamped between ZSTD_LDM_MINMATCH_MIN > * and ZSTD_LDM_MINMATCH_MAX (default: 64). */ > ZSTD_p_ldmBucketSizeLog, /* Log size of each bucket in the LDM hash table for collision resolution. > * Larger values usually improve collision resolution but may decrease > * compression speed. > * The maximum value is ZSTD_LDM_BUCKETSIZELOG_MAX (default: 3). */ > ZSTD_p_ldmHashEveryLog, /* Frequency of inserting/looking up entries in the LDM hash table. > * The default is MAX(0, (windowLog - ldmHashLog)) to > * optimize hash table usage. > * Larger values improve compression speed. Deviating far from the > * default value will likely result in a decrease in compression ratio. > * Must be clamped between 0 and ZSTD_WINDOWLOG_MAX - ZSTD_HASHLOG_MIN. */ > >} ZSTD_cParameter; > > >/*! ZSTD_CCtx_setParameter() : > * Set one compression parameter, selected by enum ZSTD_cParameter. > * Note : when `value` is an enum, cast it to unsigned for proper type checking. > * @result : 0, or an error code (which can be tested with ZSTD_isError()). */ >ZSTDLIB_API size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, unsigned value); > >/*! ZSTD_CCtx_setPledgedSrcSize() : > * Total input data size to be compressed as a single frame. > * This value will be controlled at the end, and result in error if not respected. > * @result : 0, or an error code (which can be tested with ZSTD_isError()). > * Note 1 : 0 means zero, empty. > * In order to mean "unknown content size", pass constant ZSTD_CONTENTSIZE_UNKNOWN. > * Note that ZSTD_CONTENTSIZE_UNKNOWN is default value for new compression jobs. > * Note 2 : If all data is provided and consumed in a single round, > * this value is overriden by srcSize instead. */ >ZSTDLIB_API size_t ZSTD_CCtx_setPledgedSrcSize(ZSTD_CCtx* cctx, unsigned long long pledgedSrcSize); > >/*! ZSTD_CCtx_loadDictionary() : > * Create an internal CDict from dict buffer. > * Decompression will have to use same buffer. > * @result : 0, or an error code (which can be tested with ZSTD_isError()). > * Special : Adding a NULL (or 0-size) dictionary invalidates any previous dictionary, > * meaning "return to no-dictionary mode". > * Note 1 : `dict` content will be copied internally. Use > * ZSTD_CCtx_loadDictionary_byReference() to reference dictionary > * content instead. The dictionary buffer must then outlive its > * users. > * Note 2 : Loading a dictionary involves building tables, which are dependent on compression parameters. > * For this reason, compression parameters cannot be changed anymore after loading a dictionary. > * It's also a CPU-heavy operation, with non-negligible impact on latency. > * Note 3 : Dictionary will be used for all future compression jobs. > * To return to "no-dictionary" situation, load a NULL dictionary > * Note 5 : Use ZSTD_CCtx_loadDictionary_advanced() to select how dictionary > * content will be interpreted. > */ >ZSTDLIB_API size_t ZSTD_CCtx_loadDictionary(ZSTD_CCtx* cctx, const void* dict, size_t dictSize); >ZSTDLIB_API size_t ZSTD_CCtx_loadDictionary_byReference(ZSTD_CCtx* cctx, const void* dict, size_t dictSize); >ZSTDLIB_API size_t ZSTD_CCtx_loadDictionary_advanced(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictMode_e dictMode); > > >/*! ZSTD_CCtx_refCDict() : > * Reference a prepared dictionary, to be used for all next compression jobs. > * Note that compression parameters are enforced from within CDict, > * and supercede any compression parameter previously set within CCtx. > * The dictionary will remain valid for future compression jobs using same CCtx. > * @result : 0, or an error code (which can be tested with ZSTD_isError()). > * Special : adding a NULL CDict means "return to no-dictionary mode". > * Note 1 : Currently, only one dictionary can be managed. > * Adding a new dictionary effectively "discards" any previous one. > * Note 2 : CDict is just referenced, its lifetime must outlive CCtx. > */ >ZSTDLIB_API size_t ZSTD_CCtx_refCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict); > >/*! ZSTD_CCtx_refPrefix() : > * Reference a prefix (single-usage dictionary) for next compression job. > * Decompression need same prefix to properly regenerate data. > * Prefix is **only used once**. Tables are discarded at end of compression job. > * Subsequent compression jobs will be done without prefix (if none is explicitly referenced). > * If there is a need to use same prefix multiple times, consider embedding it into a ZSTD_CDict instead. > * @result : 0, or an error code (which can be tested with ZSTD_isError()). > * Special : Adding any prefix (including NULL) invalidates any previous prefix or dictionary > * Note 1 : Prefix buffer is referenced. It must outlive compression job. > * Note 2 : Referencing a prefix involves building tables, which are dependent on compression parameters. > * It's a CPU-heavy operation, with non-negligible impact on latency. > * Note 3 : By default, the prefix is treated as raw content > * (ZSTD_dm_rawContent). Use ZSTD_CCtx_refPrefix_advanced() to alter > * dictMode. */ >ZSTDLIB_API size_t ZSTD_CCtx_refPrefix(ZSTD_CCtx* cctx, const void* prefix, size_t prefixSize); >ZSTDLIB_API size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx* cctx, const void* prefix, size_t prefixSize, ZSTD_dictMode_e dictMode); > > > >typedef enum { > ZSTD_e_continue=0, /* collect more data, encoder transparently decides when to output result, for optimal conditions */ > ZSTD_e_flush, /* flush any data provided so far - frame will continue, future data can still reference previous data for better compression */ > ZSTD_e_end /* flush any remaining data and close current frame. Any additional data starts a new frame. */ >} ZSTD_EndDirective; > >/*! ZSTD_compress_generic() : > * Behave about the same as ZSTD_compressStream. To note : > * - Compression parameters are pushed into CCtx before starting compression, using ZSTD_CCtx_setParameter() > * - Compression parameters cannot be changed once compression is started. > * - outpot->pos must be <= dstCapacity, input->pos must be <= srcSize > * - outpot->pos and input->pos will be updated. They are guaranteed to remain below their respective limit. > * - @return provides the minimum amount of data still to flush from internal buffers > * or an error code, which can be tested using ZSTD_isError(). > * if @return != 0, flush is not fully completed, there is some data left within internal buffers. > * - after a ZSTD_e_end directive, if internal buffer is not fully flushed, > * only ZSTD_e_end or ZSTD_e_flush operations are allowed. > * It is necessary to fully flush internal buffers > * before starting a new compression job, or changing compression parameters. > */ >ZSTDLIB_API size_t ZSTD_compress_generic (ZSTD_CCtx* cctx, > ZSTD_outBuffer* output, > ZSTD_inBuffer* input, > ZSTD_EndDirective endOp); > >/*! ZSTD_CCtx_reset() : > * Return a CCtx to clean state. > * Useful after an error, or to interrupt an ongoing compression job and start a new one. > * Any internal data not yet flushed is cancelled. > * Dictionary (if any) is dropped. > * All parameters are back to default values. > * It's possible to modify compression parameters after a reset. > */ >ZSTDLIB_API void ZSTD_CCtx_reset(ZSTD_CCtx* cctx); /* Not ready yet ! */ > > >/*! ZSTD_compress_generic_simpleArgs() : > * Same as ZSTD_compress_generic(), > * but using only integral types as arguments. > * Argument list is larger than ZSTD_{in,out}Buffer, > * but can be helpful for binders from dynamic languages > * which have troubles handling structures containing memory pointers. > */ >ZSTDLIB_API size_t ZSTD_compress_generic_simpleArgs ( > ZSTD_CCtx* cctx, > void* dst, size_t dstCapacity, size_t* dstPos, > const void* src, size_t srcSize, size_t* srcPos, > ZSTD_EndDirective endOp); > > >/*! ZSTD_CCtx_params : > * Quick howto : > * - ZSTD_createCCtxParams() : Create a ZSTD_CCtx_params structure > * - ZSTD_CCtxParam_setParameter() : Push parameters one by one into > * an existing ZSTD_CCtx_params structure. > * This is similar to > * ZSTD_CCtx_setParameter(). > * - ZSTD_CCtx_setParametersUsingCCtxParams() : Apply parameters to > * an existing CCtx. > * These parameters will be applied to > * all subsequent compression jobs. > * - ZSTD_compress_generic() : Do compression using the CCtx. > * - ZSTD_freeCCtxParams() : Free the memory. > * > * This can be used with ZSTD_estimateCCtxSize_advanced_usingCCtxParams() > * for static allocation for single-threaded compression. > */ >ZSTDLIB_API ZSTD_CCtx_params* ZSTD_createCCtxParams(void); > >/*! ZSTD_resetCCtxParams() : > * Reset params to default, with the default compression level. > */ >ZSTDLIB_API size_t ZSTD_resetCCtxParams(ZSTD_CCtx_params* params); > >/*! ZSTD_initCCtxParams() : > * Initializes the compression parameters of cctxParams according to > * compression level. All other parameters are reset to their default values. > */ >ZSTDLIB_API size_t ZSTD_initCCtxParams(ZSTD_CCtx_params* cctxParams, int compressionLevel); > >/*! ZSTD_initCCtxParams_advanced() : > * Initializes the compression and frame parameters of cctxParams according to > * params. All other parameters are reset to their default values. > */ >ZSTDLIB_API size_t ZSTD_initCCtxParams_advanced(ZSTD_CCtx_params* cctxParams, ZSTD_parameters params); > >ZSTDLIB_API size_t ZSTD_freeCCtxParams(ZSTD_CCtx_params* params); > >/*! ZSTD_CCtxParam_setParameter() : > * Similar to ZSTD_CCtx_setParameter. > * Set one compression parameter, selected by enum ZSTD_cParameter. > * Parameters must be applied to a ZSTD_CCtx using ZSTD_CCtx_setParametersUsingCCtxParams(). > * Note : when `value` is an enum, cast it to unsigned for proper type checking. > * @result : 0, or an error code (which can be tested with ZSTD_isError()). > */ >ZSTDLIB_API size_t ZSTD_CCtxParam_setParameter(ZSTD_CCtx_params* params, ZSTD_cParameter param, unsigned value); > >/*! ZSTD_CCtx_setParametersUsingCCtxParams() : > * Apply a set of ZSTD_CCtx_params to the compression context. > * This must be done before the dictionary is loaded. > * The pledgedSrcSize is treated as unknown. > * Multithreading parameters are applied only if nbThreads > 1. > */ >ZSTDLIB_API size_t ZSTD_CCtx_setParametersUsingCCtxParams( > ZSTD_CCtx* cctx, const ZSTD_CCtx_params* params); > > >/*=== Advanced parameters for decompression API ===*/ > >/* The following parameters must be set after creating a ZSTD_DCtx* (or ZSTD_DStream*) object, > * but before starting decompression of a frame. > */ > >/*! ZSTD_DCtx_loadDictionary() : > * Create an internal DDict from dict buffer, > * to be used to decompress next frames. > * @result : 0, or an error code (which can be tested with ZSTD_isError()). > * Special : Adding a NULL (or 0-size) dictionary invalidates any previous dictionary, > * meaning "return to no-dictionary mode". > * Note 1 : `dict` content will be copied internally. > * Use ZSTD_DCtx_loadDictionary_byReference() > * to reference dictionary content instead. > * In which case, the dictionary buffer must outlive its users. > * Note 2 : Loading a dictionary involves building tables, > * which has a non-negligible impact on CPU usage and latency. > * Note 3 : Use ZSTD_DCtx_loadDictionary_advanced() to select > * how dictionary content will be interpreted and loaded. > */ >ZSTDLIB_API size_t ZSTD_DCtx_loadDictionary(ZSTD_DCtx* dctx, const void* dict, size_t dictSize); /* not implemented */ >ZSTDLIB_API size_t ZSTD_DCtx_loadDictionary_byReference(ZSTD_DCtx* dctx, const void* dict, size_t dictSize); /* not implemented */ >ZSTDLIB_API size_t ZSTD_DCtx_loadDictionary_advanced(ZSTD_DCtx* dctx, const void* dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictMode_e dictMode); /* not implemented */ > > >/*! ZSTD_DCtx_refDDict() : > * Reference a prepared dictionary, to be used to decompress next frames. > * The dictionary remains active for decompression of future frames using same DCtx. > * @result : 0, or an error code (which can be tested with ZSTD_isError()). > * Note 1 : Currently, only one dictionary can be managed. > * Referencing a new dictionary effectively "discards" any previous one. > * Special : adding a NULL DDict means "return to no-dictionary mode". > * Note 2 : DDict is just referenced, its lifetime must outlive its usage from DCtx. > */ >ZSTDLIB_API size_t ZSTD_DCtx_refDDict(ZSTD_DCtx* dctx, const ZSTD_DDict* ddict); /* not implemented */ > > >/*! ZSTD_DCtx_refPrefix() : > * Reference a prefix (single-usage dictionary) for next compression job. > * Prefix is **only used once**. It must be explicitly referenced before each frame. > * If there is a need to use same prefix multiple times, consider embedding it into a ZSTD_DDict instead. > * @result : 0, or an error code (which can be tested with ZSTD_isError()). > * Note 1 : Adding any prefix (including NULL) invalidates any previously set prefix or dictionary > * Note 2 : Prefix buffer is referenced. It must outlive compression job. > * Note 3 : By default, the prefix is treated as raw content (ZSTD_dm_rawContent). > * Use ZSTD_CCtx_refPrefix_advanced() to alter dictMode. > * Note 4 : Referencing a raw content prefix has almost no cpu nor memory cost. > */ >ZSTDLIB_API size_t ZSTD_DCtx_refPrefix(ZSTD_DCtx* dctx, const void* prefix, size_t prefixSize); /* not implemented */ >ZSTDLIB_API size_t ZSTD_DCtx_refPrefix_advanced(ZSTD_DCtx* dctx, const void* prefix, size_t prefixSize, ZSTD_dictMode_e dictMode); /* not implemented */ > > >/*! ZSTD_DCtx_setMaxWindowSize() : > * Refuses allocating internal buffers for frames requiring a window size larger than provided limit. > * This is useful to prevent a decoder context from reserving too much memory for itself (potential attack scenario). > * This parameter is only useful in streaming mode, since no internal buffer is allocated in direct mode. > * By default, a decompression context accepts all window sizes <= (1 << ZSTD_WINDOWLOG_MAX) > * @return : 0, or an error code (which can be tested using ZSTD_isError()). > */ >ZSTDLIB_API size_t ZSTD_DCtx_setMaxWindowSize(ZSTD_DCtx* dctx, size_t maxWindowSize); > > >/*! ZSTD_DCtx_setFormat() : > * Instruct the decoder context about what kind of data to decode next. > * This instruction is mandatory to decode data without a fully-formed header, > * such ZSTD_f_zstd1_magicless for example. > * @return : 0, or an error code (which can be tested using ZSTD_isError()). > */ >ZSTDLIB_API size_t ZSTD_DCtx_setFormat(ZSTD_DCtx* dctx, ZSTD_format_e format); > > >/*! ZSTD_decompress_generic() : > * Behave the same as ZSTD_decompressStream. > * Decompression parameters cannot be changed once decompression is started. > * @return : an error code, which can be tested using ZSTD_isError() > * if >0, a hint, nb of expected input bytes for next invocation. > * `0` means : a frame has just been fully decoded and flushed. > */ >ZSTDLIB_API size_t ZSTD_decompress_generic(ZSTD_DCtx* dctx, > ZSTD_outBuffer* output, > ZSTD_inBuffer* input); > > >/*! ZSTD_decompress_generic_simpleArgs() : > * Same as ZSTD_decompress_generic(), > * but using only integral types as arguments. > * Argument list is larger than ZSTD_{in,out}Buffer, > * but can be helpful for binders from dynamic languages > * which have troubles handling structures containing memory pointers. > */ >ZSTDLIB_API size_t ZSTD_decompress_generic_simpleArgs ( > ZSTD_DCtx* dctx, > void* dst, size_t dstCapacity, size_t* dstPos, > const void* src, size_t srcSize, size_t* srcPos); > > >/*! ZSTD_DCtx_reset() : > * Return a DCtx to clean state. > * If a decompression was ongoing, any internal data not yet flushed is cancelled. > * All parameters are back to default values, including sticky ones. > * Dictionary (if any) is dropped. > * Parameters can be modified again after a reset. > */ >ZSTDLIB_API void ZSTD_DCtx_reset(ZSTD_DCtx* dctx); > > > >/* ============================ */ >/** Block level API */ >/* ============================ */ > >/*! > Block functions produce and decode raw zstd blocks, without frame metadata. > Frame metadata cost is typically ~18 bytes, which can be non-negligible for very small blocks (< 100 bytes). > User will have to take in charge required information to regenerate data, such as compressed and content sizes. > > A few rules to respect : > - Compressing and decompressing require a context structure > + Use ZSTD_createCCtx() and ZSTD_createDCtx() > - It is necessary to init context before starting > + compression : any ZSTD_compressBegin*() variant, including with dictionary > + decompression : any ZSTD_decompressBegin*() variant, including with dictionary > + copyCCtx() and copyDCtx() can be used too > - Block size is limited, it must be <= ZSTD_getBlockSize() <= ZSTD_BLOCKSIZE_MAX == 128 KB > + If input is larger than a block size, it's necessary to split input data into multiple blocks > + For inputs larger than a single block size, consider using the regular ZSTD_compress() instead. > Frame metadata is not that costly, and quickly becomes negligible as source size grows larger. > - When a block is considered not compressible enough, ZSTD_compressBlock() result will be zero. > In which case, nothing is produced into `dst`. > + User must test for such outcome and deal directly with uncompressed data > + ZSTD_decompressBlock() doesn't accept uncompressed data as input !!! > + In case of multiple successive blocks, should some of them be uncompressed, > decoder must be informed of their existence in order to follow proper history. > Use ZSTD_insertBlock() for such a case. >*/ > >#define ZSTD_BLOCKSIZELOG_MAX 17 >#define ZSTD_BLOCKSIZE_MAX (1<<ZSTD_BLOCKSIZELOG_MAX) /* define, for static allocation */ >/*===== Raw zstd block functions =====*/ >ZSTDLIB_API size_t ZSTD_getBlockSize (const ZSTD_CCtx* cctx); >ZSTDLIB_API size_t ZSTD_compressBlock (ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize); >ZSTDLIB_API size_t ZSTD_decompressBlock(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize); >ZSTDLIB_API size_t ZSTD_insertBlock(ZSTD_DCtx* dctx, const void* blockStart, size_t blockSize); /**< insert uncompressed block into `dctx` history. Useful for multi-blocks decompression */ > > >#endif /* ZSTD_H_ZSTD_STATIC_LINKING_ONLY */ ># 1383 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/zstd.h" > >#if defined (__cplusplus) >} >#endif ># 1387 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/zstd.h" ># 29 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstdmt_compress.h" 2 > > >/* === Memory management === */ >typedef struct ZSTDMT_CCtx_s ZSTDMT_CCtx; >ZSTDLIB_API ZSTDMT_CCtx* ZSTDMT_createCCtx(unsigned nbThreads); >ZSTDLIB_API ZSTDMT_CCtx* ZSTDMT_createCCtx_advanced(unsigned nbThreads, > ZSTD_customMem cMem); >ZSTDLIB_API size_t ZSTDMT_freeCCtx(ZSTDMT_CCtx* mtctx); > >ZSTDLIB_API size_t ZSTDMT_sizeof_CCtx(ZSTDMT_CCtx* mtctx); > > >/* === Simple buffer-to-butter one-pass function === */ > >ZSTDLIB_API size_t ZSTDMT_compressCCtx(ZSTDMT_CCtx* mtctx, > void* dst, size_t dstCapacity, > const void* src, size_t srcSize, > int compressionLevel); > > > >/* === Streaming functions === */ > >ZSTDLIB_API size_t ZSTDMT_initCStream(ZSTDMT_CCtx* mtctx, int compressionLevel); >ZSTDLIB_API size_t ZSTDMT_resetCStream(ZSTDMT_CCtx* mtctx, unsigned long long pledgedSrcSize); /**< pledgedSrcSize is optional and can be zero == unknown */ > >ZSTDLIB_API size_t ZSTDMT_compressStream(ZSTDMT_CCtx* mtctx, ZSTD_outBuffer* output, ZSTD_inBuffer* input); > >ZSTDLIB_API size_t ZSTDMT_flushStream(ZSTDMT_CCtx* mtctx, ZSTD_outBuffer* output); /**< @return : 0 == all flushed; >0 : still some data to be flushed; or an error code (ZSTD_isError()) */ >ZSTDLIB_API size_t ZSTDMT_endStream(ZSTDMT_CCtx* mtctx, ZSTD_outBuffer* output); /**< @return : 0 == all flushed; >0 : still some data to be flushed; or an error code (ZSTD_isError()) */ > > >/* === Advanced functions and parameters === */ > >#ifndef ZSTDMT_SECTION_SIZE_MIN ># define ZSTDMT_SECTION_SIZE_MIN (1U << 20) /* 1 MB - Minimum size of each compression job */ >#endif ># 66 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstdmt_compress.h" > >ZSTDLIB_API size_t ZSTDMT_compress_advanced(ZSTDMT_CCtx* mtctx, > void* dst, size_t dstCapacity, > const void* src, size_t srcSize, > const ZSTD_CDict* cdict, > ZSTD_parameters const params, > unsigned overlapLog); > >ZSTDLIB_API size_t ZSTDMT_initCStream_advanced(ZSTDMT_CCtx* mtctx, > const void* dict, size_t dictSize, /* dict can be released after init, a local copy is preserved within zcs */ > ZSTD_parameters params, > unsigned long long pledgedSrcSize); /* pledgedSrcSize is optional and can be zero == unknown */ > >ZSTDLIB_API size_t ZSTDMT_initCStream_usingCDict(ZSTDMT_CCtx* mtctx, > const ZSTD_CDict* cdict, > ZSTD_frameParameters fparams, > unsigned long long pledgedSrcSize); /* note : zero means empty */ > >/* ZSTDMT_parameter : > * List of parameters that can be set using ZSTDMT_setMTCtxParameter() */ >typedef enum { > ZSTDMT_p_sectionSize, /* size of input "section". Each section is compressed in parallel. 0 means default, which is dynamically determined within compression functions */ > ZSTDMT_p_overlapSectionLog /* Log of overlapped section; 0 == no overlap, 6(default) == use 1/8th of window, >=9 == use full window */ >} ZSTDMT_parameter; > >/* ZSTDMT_setMTCtxParameter() : > * allow setting individual parameters, one at a time, among a list of enums defined in ZSTDMT_parameter. > * The function must be called typically after ZSTD_createCCtx(). > * Parameters not explicitly reset by ZSTDMT_init*() remain the same in consecutive compression sessions. > * @return : 0, or an error code (which can be tested using ZSTD_isError()) */ >ZSTDLIB_API size_t ZSTDMT_setMTCtxParameter(ZSTDMT_CCtx* mtctx, ZSTDMT_parameter parameter, unsigned value); > > >/*! ZSTDMT_compressStream_generic() : > * Combines ZSTDMT_compressStream() with ZSTDMT_flushStream() or ZSTDMT_endStream() > * depending on flush directive. > * @return : minimum amount of data still to be flushed > * 0 if fully flushed > * or an error code */ >ZSTDLIB_API size_t ZSTDMT_compressStream_generic(ZSTDMT_CCtx* mtctx, > ZSTD_outBuffer* output, > ZSTD_inBuffer* input, > ZSTD_EndDirective endOp); > > >/* === Private definitions; never ever use directly === */ > >size_t ZSTDMT_CCtxParam_setMTCtxParameter(ZSTD_CCtx_params* params, ZSTDMT_parameter parameter, unsigned value); > >size_t ZSTDMT_initializeCCtxParameters(ZSTD_CCtx_params* params, unsigned nbThreads); > >/*! ZSTDMT_initCStream_internal() : > * Private use only. Init streaming operation. > * expects params to be valid. > * must receive dict, or cdict, or none, but not both. > * @return : 0, or an error code */ >size_t ZSTDMT_initCStream_internal(ZSTDMT_CCtx* zcs, > const void* dict, size_t dictSize, ZSTD_dictMode_e dictMode, > const ZSTD_CDict* cdict, > ZSTD_CCtx_params params, unsigned long long pledgedSrcSize); > > >#if defined (__cplusplus) >} >#endif ># 131 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstdmt_compress.h" > >#endif /* ZSTDMT_COMPRESS_H */ ># 133 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstdmt_compress.h" ># 21 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.h" 2 >#endif ># 22 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.h" > >#if defined (__cplusplus) >extern "C" { >#endif ># 26 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.h" > >/*-************************************* >* Constants >***************************************/ >static const U32 g_searchStrength = 8; >#define HASH_READ_SIZE 8 > > >/*-************************************* >* Context memory management >***************************************/ >typedef enum { ZSTDcs_created=0, ZSTDcs_init, ZSTDcs_ongoing, ZSTDcs_ending } ZSTD_compressionStage_e; >typedef enum { zcss_init=0, zcss_load, zcss_flush } ZSTD_cStreamStage; > >typedef struct ZSTD_prefixDict_s { > const void* dict; > size_t dictSize; > ZSTD_dictMode_e dictMode; >} ZSTD_prefixDict; > >struct ZSTD_CCtx_s { > const BYTE* nextSrc; /* next block here to continue on current prefix */ > const BYTE* base; /* All regular indexes relative to this position */ > const BYTE* dictBase; /* extDict indexes relative to this position */ > U32 dictLimit; /* below that point, need extDict */ > U32 lowLimit; /* below that point, no more data */ > U32 nextToUpdate; /* index from which to continue dictionary update */ > U32 nextToUpdate3; /* index from which to continue dictionary update */ > U32 hashLog3; /* dispatch table : larger == faster, more memory */ > U32 loadedDictEnd; /* index of end of dictionary */ > ZSTD_compressionStage_e stage; > U32 dictID; > ZSTD_CCtx_params requestedParams; > ZSTD_CCtx_params appliedParams; > void* workSpace; > size_t workSpaceSize; > size_t blockSize; > U64 pledgedSrcSizePlusOne; /* this way, 0 (default) == unknown */ > U64 consumedSrcSize; > XXH64_state_t xxhState; > ZSTD_customMem customMem; > size_t staticSize; > > seqStore_t seqStore; /* sequences storage ptrs */ > optState_t optState; > ldmState_t ldmState; /* long distance matching state */ > U32* hashTable; > U32* hashTable3; > U32* chainTable; > ZSTD_entropyCTables_t* entropy; > > /* streaming */ > char* inBuff; > size_t inBuffSize; > size_t inToCompress; > size_t inBuffPos; > size_t inBuffTarget; > char* outBuff; > size_t outBuffSize; > size_t outBuffContentSize; > size_t outBuffFlushedSize; > ZSTD_cStreamStage streamStage; > U32 frameEnded; > > /* Dictionary */ > ZSTD_CDict* cdictLocal; > const ZSTD_CDict* cdict; > ZSTD_prefixDict prefixDict; /* single-usage dictionary */ > > /* Multi-threading */ >#ifdef ZSTD_MULTITHREAD > ZSTDMT_CCtx* mtctx; >#endif ># 99 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.h" >}; > > >static const BYTE LL_Code[64] = { 0, 1, 2, 3, 4, 5, 6, 7, > 8, 9, 10, 11, 12, 13, 14, 15, > 16, 16, 17, 17, 18, 18, 19, 19, > 20, 20, 20, 20, 21, 21, 21, 21, > 22, 22, 22, 22, 22, 22, 22, 22, > 23, 23, 23, 23, 23, 23, 23, 23, > 24, 24, 24, 24, 24, 24, 24, 24, > 24, 24, 24, 24, 24, 24, 24, 24 }; > >static const BYTE ML_Code[128] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, > 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, > 32, 32, 33, 33, 34, 34, 35, 35, 36, 36, 36, 36, 37, 37, 37, 37, > 38, 38, 38, 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, 39, 39, 39, > 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, > 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, > 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, > 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42 }; > >/*! ZSTD_storeSeq() : > Store a sequence (literal length, literals, offset code and match length code) into seqStore_t. > `offsetCode` : distance to match, or 0 == repCode. > `matchCode` : matchLength - MINMATCH >*/ >MEM_STATIC void ZSTD_storeSeq(seqStore_t* seqStorePtr, size_t litLength, const void* literals, U32 offsetCode, size_t matchCode) >{ >#if defined(ZSTD_DEBUG) && (ZSTD_DEBUG >= 6) > static const BYTE* g_start = NULL; > U32 const pos = (U32)((const BYTE*)literals - g_start); > if (g_start==NULL) g_start = (const BYTE*)literals; > if ((pos > 0) && (pos < 1000000000)) > DEBUGLOG(6, "Cpos %6u :%5u literals & match %3u bytes at distance %6u", > pos, (U32)litLength, (U32)matchCode+MINMATCH, (U32)offsetCode); >#endif ># 135 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.h" > /* copy Literals */ > assert(seqStorePtr->lit + litLength <= seqStorePtr->litStart + 128 KB); > ZSTD_wildcopy(seqStorePtr->lit, literals, litLength); > seqStorePtr->lit += litLength; > > /* literal Length */ > if (litLength>0xFFFF) { > seqStorePtr->longLengthID = 1; > seqStorePtr->longLengthPos = (U32)(seqStorePtr->sequences - seqStorePtr->sequencesStart); > } > seqStorePtr->sequences[0].litLength = (U16)litLength; > > /* match offset */ > seqStorePtr->sequences[0].offset = offsetCode + 1; > > /* match Length */ > if (matchCode>0xFFFF) { > seqStorePtr->longLengthID = 2; > seqStorePtr->longLengthPos = (U32)(seqStorePtr->sequences - seqStorePtr->sequencesStart); > } > seqStorePtr->sequences[0].matchLength = (U16)matchCode; > > seqStorePtr->sequences++; >} > > >/*-************************************* >* Match length counter >***************************************/ >static unsigned ZSTD_NbCommonBytes (register size_t val) >{ > if (MEM_isLittleEndian()) { > if (MEM_64bits()) { ># if defined(_MSC_VER) && defined(_WIN64) > unsigned long r = 0; > _BitScanForward64( &r, (U64)val ); > return (unsigned)(r>>3); ># elif defined(__GNUC__) && (__GNUC__ >= 4) ># 173 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.h" > return (__builtin_ctzll((U64)val) >> 3); ># else ># 175 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.h" > static const int DeBruijnBytePos[64] = { 0, 0, 0, 0, 0, 1, 1, 2, > 0, 3, 1, 3, 1, 4, 2, 7, > 0, 2, 3, 6, 1, 5, 3, 5, > 1, 3, 4, 4, 2, 5, 6, 7, > 7, 0, 1, 2, 3, 3, 4, 6, > 2, 6, 5, 5, 3, 4, 5, 6, > 7, 1, 2, 4, 6, 4, 4, 5, > 7, 2, 6, 5, 7, 6, 7, 7 }; > return DeBruijnBytePos[((U64)((val & -(long long)val) * 0x0218A392CDABBD3FULL)) >> 58]; ># endif ># 185 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.h" > } else { /* 32 bits */ ># if defined(_MSC_VER) > unsigned long r=0; > _BitScanForward( &r, (U32)val ); > return (unsigned)(r>>3); ># elif defined(__GNUC__) && (__GNUC__ >= 3) ># 191 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.h" > return (__builtin_ctz((U32)val) >> 3); ># else ># 193 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.h" > static const int DeBruijnBytePos[32] = { 0, 0, 3, 0, 3, 1, 3, 0, > 3, 2, 2, 1, 3, 2, 0, 1, > 3, 3, 1, 2, 2, 2, 2, 0, > 3, 1, 2, 0, 1, 0, 1, 1 }; > return DeBruijnBytePos[((U32)((val & -(S32)val) * 0x077CB531U)) >> 27]; ># endif ># 199 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.h" > } > } else { /* Big Endian CPU */ > if (MEM_64bits()) { ># if defined(_MSC_VER) && defined(_WIN64) > unsigned long r = 0; > _BitScanReverse64( &r, val ); > return (unsigned)(r>>3); ># elif defined(__GNUC__) && (__GNUC__ >= 4) ># 207 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.h" > return (__builtin_clzll(val) >> 3); ># else ># 209 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.h" > unsigned r; > const unsigned n32 = sizeof(size_t)*4; /* calculate this way due to compiler complaining in 32-bits mode */ > if (!(val>>n32)) { r=4; } else { r=0; val>>=n32; } > if (!(val>>16)) { r+=2; val>>=8; } else { val>>=24; } > r += (!val); > return r; ># endif ># 216 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.h" > } else { /* 32 bits */ ># if defined(_MSC_VER) > unsigned long r = 0; > _BitScanReverse( &r, (unsigned long)val ); > return (unsigned)(r>>3); ># elif defined(__GNUC__) && (__GNUC__ >= 3) ># 222 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.h" > return (__builtin_clz((U32)val) >> 3); ># else ># 224 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.h" > unsigned r; > if (!(val>>16)) { r=2; val>>=8; } else { r=0; val>>=24; } > r += (!val); > return r; ># endif ># 229 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.h" > } } >} > > >MEM_STATIC size_t ZSTD_count(const BYTE* pIn, const BYTE* pMatch, const BYTE* const pInLimit) >{ > const BYTE* const pStart = pIn; > const BYTE* const pInLoopLimit = pInLimit - (sizeof(size_t)-1); > > while (pIn < pInLoopLimit) { > size_t const diff = MEM_readST(pMatch) ^ MEM_readST(pIn); > if (!diff) { pIn+=sizeof(size_t); pMatch+=sizeof(size_t); continue; } > pIn += ZSTD_NbCommonBytes(diff); > return (size_t)(pIn - pStart); > } > if (MEM_64bits()) if ((pIn<(pInLimit-3)) && (MEM_read32(pMatch) == MEM_read32(pIn))) { pIn+=4; pMatch+=4; } > if ((pIn<(pInLimit-1)) && (MEM_read16(pMatch) == MEM_read16(pIn))) { pIn+=2; pMatch+=2; } > if ((pIn<pInLimit) && (*pMatch == *pIn)) pIn++; > return (size_t)(pIn - pStart); >} > >/** ZSTD_count_2segments() : >* can count match length with `ip` & `match` in 2 different segments. >* convention : on reaching mEnd, match count continue starting from iStart >*/ >MEM_STATIC size_t ZSTD_count_2segments(const BYTE* ip, const BYTE* match, const BYTE* iEnd, const BYTE* mEnd, const BYTE* iStart) >{ > const BYTE* const vEnd = MIN( ip + (mEnd - match), iEnd); > size_t const matchLength = ZSTD_count(ip, match, vEnd); > if (match + matchLength != mEnd) return matchLength; > return matchLength + ZSTD_count(ip+matchLength, iStart, iEnd); >} > > >/*-************************************* >* Hashes >***************************************/ >static const U32 prime3bytes = 506832829U; >static U32 ZSTD_hash3(U32 u, U32 h) { return ((u << (32-24)) * prime3bytes) >> (32-h) ; } >MEM_STATIC size_t ZSTD_hash3Ptr(const void* ptr, U32 h) { return ZSTD_hash3(MEM_readLE32(ptr), h); } /* only in zstd_opt.h */ > >static const U32 prime4bytes = 2654435761U; >static U32 ZSTD_hash4(U32 u, U32 h) { return (u * prime4bytes) >> (32-h) ; } >static size_t ZSTD_hash4Ptr(const void* ptr, U32 h) { return ZSTD_hash4(MEM_read32(ptr), h); } > >static const U64 prime5bytes = 889523592379ULL; >static size_t ZSTD_hash5(U64 u, U32 h) { return (size_t)(((u << (64-40)) * prime5bytes) >> (64-h)) ; } >static size_t ZSTD_hash5Ptr(const void* p, U32 h) { return ZSTD_hash5(MEM_readLE64(p), h); } > >static const U64 prime6bytes = 227718039650203ULL; >static size_t ZSTD_hash6(U64 u, U32 h) { return (size_t)(((u << (64-48)) * prime6bytes) >> (64-h)) ; } >static size_t ZSTD_hash6Ptr(const void* p, U32 h) { return ZSTD_hash6(MEM_readLE64(p), h); } > >static const U64 prime7bytes = 58295818150454627ULL; >static size_t ZSTD_hash7(U64 u, U32 h) { return (size_t)(((u << (64-56)) * prime7bytes) >> (64-h)) ; } >static size_t ZSTD_hash7Ptr(const void* p, U32 h) { return ZSTD_hash7(MEM_readLE64(p), h); } > >static const U64 prime8bytes = 0xCF1BBCDCB7A56463ULL; >static size_t ZSTD_hash8(U64 u, U32 h) { return (size_t)(((u) * prime8bytes) >> (64-h)) ; } >static size_t ZSTD_hash8Ptr(const void* p, U32 h) { return ZSTD_hash8(MEM_readLE64(p), h); } > >MEM_STATIC size_t ZSTD_hashPtr(const void* p, U32 hBits, U32 mls) >{ > switch(mls) > { > default: > case 4: return ZSTD_hash4Ptr(p, hBits); > case 5: return ZSTD_hash5Ptr(p, hBits); > case 6: return ZSTD_hash6Ptr(p, hBits); > case 7: return ZSTD_hash7Ptr(p, hBits); > case 8: return ZSTD_hash8Ptr(p, hBits); > } >} > >#if defined (__cplusplus) >} >#endif ># 306 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.h" > >#endif /* ZSTD_COMPRESS_H */ ># 308 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.h" ># 30 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.c" 2 >#if 0 /* expanded by -frewrite-includes */ >#include "zstd_fast.h" >#endif /* expanded by -frewrite-includes */ ># 30 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.c" ># 1 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_fast.h" 1 >/* > * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. > * All rights reserved. > * > * This source code is licensed under both the BSD-style license (found in the > * LICENSE file in the root directory of this source tree) and the GPLv2 (found > * in the COPYING file in the root directory of this source tree). > * You may select, at your option, one of the above-listed licenses. > */ > >#ifndef ZSTD_FAST_H >#define ZSTD_FAST_H > >#if 0 /* expanded by -frewrite-includes */ >#include "zstd_compress.h" >#endif /* expanded by -frewrite-includes */ ># 14 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_fast.h" ># 15 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_fast.h" > >#if defined (__cplusplus) >extern "C" { >#endif ># 19 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_fast.h" > >void ZSTD_fillHashTable(ZSTD_CCtx* zc, const void* end, const U32 mls); >size_t ZSTD_compressBlock_fast(ZSTD_CCtx* ctx, > const void* src, size_t srcSize); >size_t ZSTD_compressBlock_fast_extDict(ZSTD_CCtx* ctx, > const void* src, size_t srcSize); > >#if defined (__cplusplus) >} >#endif ># 29 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_fast.h" > >#endif /* ZSTD_FAST_H */ ># 31 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_fast.h" ># 31 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.c" 2 >#if 0 /* expanded by -frewrite-includes */ >#include "zstd_double_fast.h" >#endif /* expanded by -frewrite-includes */ ># 31 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.c" ># 1 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_double_fast.h" 1 >/* > * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. > * All rights reserved. > * > * This source code is licensed under both the BSD-style license (found in the > * LICENSE file in the root directory of this source tree) and the GPLv2 (found > * in the COPYING file in the root directory of this source tree). > * You may select, at your option, one of the above-listed licenses. > */ > >#ifndef ZSTD_DOUBLE_FAST_H >#define ZSTD_DOUBLE_FAST_H > >#if 0 /* expanded by -frewrite-includes */ >#include "zstd_compress.h" >#endif /* expanded by -frewrite-includes */ ># 14 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_double_fast.h" ># 15 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_double_fast.h" > >#if defined (__cplusplus) >extern "C" { >#endif ># 19 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_double_fast.h" > >void ZSTD_fillDoubleHashTable(ZSTD_CCtx* cctx, const void* end, const U32 mls); >size_t ZSTD_compressBlock_doubleFast(ZSTD_CCtx* ctx, const void* src, size_t srcSize); >size_t ZSTD_compressBlock_doubleFast_extDict(ZSTD_CCtx* ctx, const void* src, size_t srcSize); > >#if defined (__cplusplus) >} >#endif ># 27 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_double_fast.h" > >#endif /* ZSTD_DOUBLE_FAST_H */ ># 29 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_double_fast.h" ># 32 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.c" 2 >#if 0 /* expanded by -frewrite-includes */ >#include "zstd_lazy.h" >#endif /* expanded by -frewrite-includes */ ># 32 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.c" ># 1 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_lazy.h" 1 >/* > * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. > * All rights reserved. > * > * This source code is licensed under both the BSD-style license (found in the > * LICENSE file in the root directory of this source tree) and the GPLv2 (found > * in the COPYING file in the root directory of this source tree). > * You may select, at your option, one of the above-listed licenses. > */ > >#ifndef ZSTD_LAZY_H >#define ZSTD_LAZY_H > >#if 0 /* expanded by -frewrite-includes */ >#include "zstd_compress.h" >#endif /* expanded by -frewrite-includes */ ># 14 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_lazy.h" ># 15 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_lazy.h" > >#if defined (__cplusplus) >extern "C" { >#endif ># 19 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_lazy.h" > >U32 ZSTD_insertAndFindFirstIndex (ZSTD_CCtx* zc, const BYTE* ip, U32 mls); >void ZSTD_updateTree(ZSTD_CCtx* zc, const BYTE* const ip, const BYTE* const iend, const U32 nbCompares, const U32 mls); >void ZSTD_updateTree_extDict(ZSTD_CCtx* zc, const BYTE* const ip, const BYTE* const iend, const U32 nbCompares, const U32 mls); > >size_t ZSTD_compressBlock_btlazy2(ZSTD_CCtx* ctx, const void* src, size_t srcSize); >size_t ZSTD_compressBlock_lazy2(ZSTD_CCtx* ctx, const void* src, size_t srcSize); >size_t ZSTD_compressBlock_lazy(ZSTD_CCtx* ctx, const void* src, size_t srcSize); >size_t ZSTD_compressBlock_greedy(ZSTD_CCtx* ctx, const void* src, size_t srcSize); > >size_t ZSTD_compressBlock_greedy_extDict(ZSTD_CCtx* ctx, const void* src, size_t srcSize); >size_t ZSTD_compressBlock_lazy_extDict(ZSTD_CCtx* ctx, const void* src, size_t srcSize); >size_t ZSTD_compressBlock_lazy2_extDict(ZSTD_CCtx* ctx, const void* src, size_t srcSize); >size_t ZSTD_compressBlock_btlazy2_extDict(ZSTD_CCtx* ctx, const void* src, size_t srcSize); > >#if defined (__cplusplus) >} >#endif ># 37 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_lazy.h" > >#endif /* ZSTD_LAZY_H */ ># 39 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_lazy.h" ># 33 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.c" 2 >#if 0 /* expanded by -frewrite-includes */ >#include "zstd_opt.h" >#endif /* expanded by -frewrite-includes */ ># 33 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.c" ># 1 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_opt.h" 1 >/* > * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. > * All rights reserved. > * > * This source code is licensed under both the BSD-style license (found in the > * LICENSE file in the root directory of this source tree) and the GPLv2 (found > * in the COPYING file in the root directory of this source tree). > * You may select, at your option, one of the above-listed licenses. > */ > >#ifndef ZSTD_OPT_H >#define ZSTD_OPT_H > >#if 0 /* expanded by -frewrite-includes */ >#include "zstd_compress.h" >#endif /* expanded by -frewrite-includes */ ># 14 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_opt.h" ># 15 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_opt.h" > >#if defined (__cplusplus) >extern "C" { >#endif ># 19 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_opt.h" > >size_t ZSTD_compressBlock_btopt(ZSTD_CCtx* ctx, const void* src, size_t srcSize); >size_t ZSTD_compressBlock_btultra(ZSTD_CCtx* ctx, const void* src, size_t srcSize); > >size_t ZSTD_compressBlock_btopt_extDict(ZSTD_CCtx* ctx, const void* src, size_t srcSize); >size_t ZSTD_compressBlock_btultra_extDict(ZSTD_CCtx* ctx, const void* src, size_t srcSize); > >#if defined (__cplusplus) >} >#endif ># 29 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_opt.h" > >#endif /* ZSTD_OPT_H */ ># 31 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_opt.h" ># 34 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.c" 2 >#if 0 /* expanded by -frewrite-includes */ >#include "zstd_ldm.h" >#endif /* expanded by -frewrite-includes */ ># 34 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.c" ># 1 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_ldm.h" 1 >/* > * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. > * All rights reserved. > * > * This source code is licensed under both the BSD-style license (found in the > * LICENSE file in the root directory of this source tree) and the GPLv2 (found > * in the COPYING file in the root directory of this source tree). > */ > >#ifndef ZSTD_LDM_H >#define ZSTD_LDM_H > >#if 0 /* expanded by -frewrite-includes */ >#include "zstd_compress.h" >#endif /* expanded by -frewrite-includes */ ># 13 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_ldm.h" ># 14 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_ldm.h" > >#if defined (__cplusplus) >extern "C" { >#endif ># 18 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_ldm.h" > >/*-************************************* >* Long distance matching >***************************************/ > >#define ZSTD_LDM_DEFAULT_WINDOW_LOG ZSTD_WINDOWLOG_DEFAULTMAX >#define ZSTD_LDM_HASHEVERYLOG_NOTSET 9999 > >/** ZSTD_compressBlock_ldm_generic() : > * > * This is a block compressor intended for long distance matching. > * > * The function searches for matches of length at least > * ldmParams.minMatchLength using a hash table in cctx->ldmState. > * Matches can be at a distance of up to cParams.windowLog. > * > * Upon finding a match, the unmatched literals are compressed using a > * ZSTD_blockCompressor (depending on the strategy in the compression > * parameters), which stores the matched sequences. The "long distance" > * match is then stored with the remaining literals from the > * ZSTD_blockCompressor. */ >size_t ZSTD_compressBlock_ldm(ZSTD_CCtx* cctx, const void* src, size_t srcSize); >size_t ZSTD_compressBlock_ldm_extDict(ZSTD_CCtx* ctx, > const void* src, size_t srcSize); > >/** ZSTD_ldm_initializeParameters() : > * Initialize the long distance matching parameters to their default values. */ >size_t ZSTD_ldm_initializeParameters(ldmParams_t* params, U32 enableLdm); > >/** ZSTD_ldm_getTableSize() : > * Estimate the space needed for long distance matching tables. */ >size_t ZSTD_ldm_getTableSize(U32 hashLog, U32 bucketSizeLog); > >/** ZSTD_ldm_getTableSize() : > * Return prime8bytes^(minMatchLength-1) */ >U64 ZSTD_ldm_getHashPower(U32 minMatchLength); > >/** ZSTD_ldm_adjustParameters() : > * If the params->hashEveryLog is not set, set it to its default value based on > * windowLog and params->hashLog. > * > * Ensures that params->bucketSizeLog is <= params->hashLog (setting it to > * params->hashLog if it is not). */ >void ZSTD_ldm_adjustParameters(ldmParams_t* params, U32 windowLog); > >#if defined (__cplusplus) >} >#endif ># 66 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_ldm.h" > >#endif /* ZSTD_FAST_H */ ># 68 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_ldm.h" ># 35 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.c" 2 > > >/*-************************************* >* Helper functions >***************************************/ >size_t ZSTD_compressBound(size_t srcSize) { > return ZSTD_COMPRESSBOUND(srcSize); >} > > >/*-************************************* >* Sequence storage >***************************************/ >static void ZSTD_resetSeqStore(seqStore_t* ssPtr) >{ > ssPtr->lit = ssPtr->litStart; > ssPtr->sequences = ssPtr->sequencesStart; > ssPtr->longLengthID = 0; >} > > >/*-************************************* >* Context memory management >***************************************/ >struct ZSTD_CDict_s { > void* dictBuffer; > const void* dictContent; > size_t dictContentSize; > ZSTD_CCtx* refContext; >}; /* typedef'd to ZSTD_CDict within "zstd.h" */ > >ZSTD_CCtx* ZSTD_createCCtx(void) >{ > return ZSTD_createCCtx_advanced(ZSTD_defaultCMem); >} > >ZSTD_CCtx* ZSTD_createCCtx_advanced(ZSTD_customMem customMem) >{ > ZSTD_CCtx* cctx; > > if (!customMem.customAlloc ^ !customMem.customFree) return NULL; > > cctx = (ZSTD_CCtx*) ZSTD_calloc(sizeof(ZSTD_CCtx), customMem); > if (!cctx) return NULL; > cctx->customMem = customMem; > cctx->requestedParams.compressionLevel = ZSTD_CLEVEL_DEFAULT; > ZSTD_STATIC_ASSERT(zcss_init==0); > ZSTD_STATIC_ASSERT(ZSTD_CONTENTSIZE_UNKNOWN==(0ULL - 1)); > return cctx; >} > >ZSTD_CCtx* ZSTD_initStaticCCtx(void *workspace, size_t workspaceSize) >{ > ZSTD_CCtx* const cctx = (ZSTD_CCtx*) workspace; > if (workspaceSize <= sizeof(ZSTD_CCtx)) return NULL; /* minimum size */ > if ((size_t)workspace & 7) return NULL; /* must be 8-aligned */ > memset(workspace, 0, workspaceSize); /* may be a bit generous, could memset be smaller ? */ > cctx->staticSize = workspaceSize; > cctx->workSpace = (void*)(cctx+1); > cctx->workSpaceSize = workspaceSize - sizeof(ZSTD_CCtx); > > /* entropy space (never moves) */ > if (cctx->workSpaceSize < sizeof(ZSTD_entropyCTables_t)) return NULL; > assert(((size_t)cctx->workSpace & (sizeof(void*)-1)) == 0); /* ensure correct alignment */ > cctx->entropy = (ZSTD_entropyCTables_t*)cctx->workSpace; > > return cctx; >} > >size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx) >{ > if (cctx==NULL) return 0; /* support free on NULL */ > if (cctx->staticSize) return ERROR(memory_allocation); /* not compatible with static CCtx */ > ZSTD_free(cctx->workSpace, cctx->customMem); > cctx->workSpace = NULL; > ZSTD_freeCDict(cctx->cdictLocal); > cctx->cdictLocal = NULL; >#ifdef ZSTD_MULTITHREAD > ZSTDMT_freeCCtx(cctx->mtctx); > cctx->mtctx = NULL; >#endif ># 116 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.c" > ZSTD_free(cctx, cctx->customMem); > return 0; /* reserved as a potential error code in the future */ >} > > >static size_t ZSTD_sizeof_mtctx(const ZSTD_CCtx* cctx) >{ >#ifdef ZSTD_MULTITHREAD > return ZSTDMT_sizeof_CCtx(cctx->mtctx); >#else ># 126 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.c" > (void) cctx; > return 0; >#endif ># 129 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.c" >} > > >size_t ZSTD_sizeof_CCtx(const ZSTD_CCtx* cctx) >{ > if (cctx==NULL) return 0; /* support sizeof on NULL */ > DEBUGLOG(3, "sizeof(*cctx) : %u", (U32)sizeof(*cctx)); > DEBUGLOG(3, "workSpaceSize (including streaming buffers): %u", (U32)cctx->workSpaceSize); > DEBUGLOG(3, "inner cdict : %u", (U32)ZSTD_sizeof_CDict(cctx->cdictLocal)); > DEBUGLOG(3, "inner MTCTX : %u", (U32)ZSTD_sizeof_mtctx(cctx)); > return sizeof(*cctx) + cctx->workSpaceSize > + ZSTD_sizeof_CDict(cctx->cdictLocal) > + ZSTD_sizeof_mtctx(cctx); >} > >size_t ZSTD_sizeof_CStream(const ZSTD_CStream* zcs) >{ > return ZSTD_sizeof_CCtx(zcs); /* same object */ >} > >/* private API call, for dictBuilder only */ >const seqStore_t* ZSTD_getSeqStore(const ZSTD_CCtx* ctx) { return &(ctx->seqStore); } > >#define ZSTD_CLEVEL_CUSTOM 999 > >static ZSTD_compressionParameters ZSTD_getCParamsFromCCtxParams( > ZSTD_CCtx_params params, U64 srcSizeHint, size_t dictSize) >{ > return (params.compressionLevel == ZSTD_CLEVEL_CUSTOM ? > params.cParams : > ZSTD_getCParams(params.compressionLevel, srcSizeHint, dictSize)); >} > >static void ZSTD_cLevelToCCtxParams_srcSize(ZSTD_CCtx_params* params, U64 srcSize) >{ > params->cParams = ZSTD_getCParamsFromCCtxParams(*params, srcSize, 0); > params->compressionLevel = ZSTD_CLEVEL_CUSTOM; >} > >static void ZSTD_cLevelToCParams(ZSTD_CCtx* cctx) >{ > ZSTD_cLevelToCCtxParams_srcSize( > &cctx->requestedParams, cctx->pledgedSrcSizePlusOne-1); >} > >static void ZSTD_cLevelToCCtxParams(ZSTD_CCtx_params* params) >{ > ZSTD_cLevelToCCtxParams_srcSize(params, 0); >} > >static ZSTD_CCtx_params ZSTD_makeCCtxParamsFromCParams( > ZSTD_compressionParameters cParams) >{ > ZSTD_CCtx_params cctxParams; > memset(&cctxParams, 0, sizeof(cctxParams)); > cctxParams.cParams = cParams; > cctxParams.compressionLevel = ZSTD_CLEVEL_CUSTOM; > return cctxParams; >} > >static ZSTD_CCtx_params* ZSTD_createCCtxParams_advanced( > ZSTD_customMem customMem) >{ > ZSTD_CCtx_params* params; > if (!customMem.customAlloc ^ !customMem.customFree) return NULL; > params = (ZSTD_CCtx_params*)ZSTD_calloc( > sizeof(ZSTD_CCtx_params), customMem); > if (!params) { return NULL; } > params->customMem = customMem; > params->compressionLevel = ZSTD_CLEVEL_DEFAULT; > return params; >} > >ZSTD_CCtx_params* ZSTD_createCCtxParams(void) >{ > return ZSTD_createCCtxParams_advanced(ZSTD_defaultCMem); >} > >size_t ZSTD_freeCCtxParams(ZSTD_CCtx_params* params) >{ > if (params == NULL) { return 0; } > ZSTD_free(params, params->customMem); > return 0; >} > >size_t ZSTD_resetCCtxParams(ZSTD_CCtx_params* params) >{ > return ZSTD_initCCtxParams(params, ZSTD_CLEVEL_DEFAULT); >} > >size_t ZSTD_initCCtxParams(ZSTD_CCtx_params* cctxParams, int compressionLevel) { > if (!cctxParams) { return ERROR(GENERIC); } > memset(cctxParams, 0, sizeof(*cctxParams)); > cctxParams->compressionLevel = compressionLevel; > return 0; >} > >size_t ZSTD_initCCtxParams_advanced(ZSTD_CCtx_params* cctxParams, ZSTD_parameters params) >{ > if (!cctxParams) { return ERROR(GENERIC); } > CHECK_F( ZSTD_checkCParams(params.cParams) ); > memset(cctxParams, 0, sizeof(*cctxParams)); > cctxParams->cParams = params.cParams; > cctxParams->fParams = params.fParams; > cctxParams->compressionLevel = ZSTD_CLEVEL_CUSTOM; > return 0; >} > >static ZSTD_CCtx_params ZSTD_assignParamsToCCtxParams( > ZSTD_CCtx_params cctxParams, ZSTD_parameters params) >{ > ZSTD_CCtx_params ret = cctxParams; > ret.cParams = params.cParams; > ret.fParams = params.fParams; > ret.compressionLevel = ZSTD_CLEVEL_CUSTOM; > return ret; >} > >#define CLAMPCHECK(val,min,max) { \ > if (((val)<(min)) | ((val)>(max))) { \ > return ERROR(parameter_outOfBound); \ >} } > >size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, unsigned value) >{ > if (cctx->streamStage != zcss_init) return ERROR(stage_wrong); > > switch(param) > { > case ZSTD_p_format : > return ZSTD_CCtxParam_setParameter(&cctx->requestedParams, param, value); > > case ZSTD_p_compressionLevel: > if (value == 0) return 0; /* special value : 0 means "don't change anything" */ > if (cctx->cdict) return ERROR(stage_wrong); > return ZSTD_CCtxParam_setParameter(&cctx->requestedParams, param, value); > > case ZSTD_p_windowLog: > case ZSTD_p_hashLog: > case ZSTD_p_chainLog: > case ZSTD_p_searchLog: > case ZSTD_p_minMatch: > case ZSTD_p_targetLength: > case ZSTD_p_compressionStrategy: > if (value == 0) return 0; /* special value : 0 means "don't change anything" */ > if (cctx->cdict) return ERROR(stage_wrong); > ZSTD_cLevelToCParams(cctx); /* Can optimize if srcSize is known */ > return ZSTD_CCtxParam_setParameter(&cctx->requestedParams, param, value); > > case ZSTD_p_contentSizeFlag: > case ZSTD_p_checksumFlag: > case ZSTD_p_dictIDFlag: > return ZSTD_CCtxParam_setParameter(&cctx->requestedParams, param, value); > > case ZSTD_p_forceMaxWindow : /* Force back-references to remain < windowSize, > * even when referencing into Dictionary content > * default : 0 when using a CDict, 1 when using a Prefix */ > cctx->loadedDictEnd = 0; > return ZSTD_CCtxParam_setParameter(&cctx->requestedParams, param, value); > > case ZSTD_p_nbThreads: > if (value==0) return 0; > DEBUGLOG(5, " setting nbThreads : %u", value); > if (value > 1 && cctx->staticSize) { > return ERROR(parameter_unsupported); /* MT not compatible with static alloc */ > } > return ZSTD_CCtxParam_setParameter(&cctx->requestedParams, param, value); > > case ZSTD_p_jobSize: > return ZSTD_CCtxParam_setParameter(&cctx->requestedParams, param, value); > > case ZSTD_p_overlapSizeLog: > DEBUGLOG(5, " setting overlap with nbThreads == %u", cctx->requestedParams.nbThreads); > return ZSTD_CCtxParam_setParameter(&cctx->requestedParams, param, value); > > case ZSTD_p_enableLongDistanceMatching: > if (cctx->cdict) return ERROR(stage_wrong); > if (value != 0) { > ZSTD_cLevelToCParams(cctx); > } > return ZSTD_CCtxParam_setParameter(&cctx->requestedParams, param, value); > > case ZSTD_p_ldmHashLog: > case ZSTD_p_ldmMinMatch: > if (value == 0) return 0; /* special value : 0 means "don't change anything" */ > if (cctx->cdict) return ERROR(stage_wrong); > return ZSTD_CCtxParam_setParameter(&cctx->requestedParams, param, value); > > case ZSTD_p_ldmBucketSizeLog: > case ZSTD_p_ldmHashEveryLog: > if (cctx->cdict) return ERROR(stage_wrong); > return ZSTD_CCtxParam_setParameter(&cctx->requestedParams, param, value); > > default: return ERROR(parameter_unsupported); > } >} > >size_t ZSTD_CCtxParam_setParameter( > ZSTD_CCtx_params* params, ZSTD_cParameter param, unsigned value) >{ > switch(param) > { > case ZSTD_p_format : > if (value > (unsigned)ZSTD_f_zstd1_magicless) > return ERROR(parameter_unsupported); > params->format = (ZSTD_format_e)value; > return 0; > > case ZSTD_p_compressionLevel : > if ((int)value > ZSTD_maxCLevel()) value = ZSTD_maxCLevel(); > if (value == 0) return 0; > params->compressionLevel = value; > return 0; > > case ZSTD_p_windowLog : > if (value == 0) return 0; > CLAMPCHECK(value, ZSTD_WINDOWLOG_MIN, ZSTD_WINDOWLOG_MAX); > ZSTD_cLevelToCCtxParams(params); > params->cParams.windowLog = value; > return 0; > > case ZSTD_p_hashLog : > if (value == 0) return 0; > CLAMPCHECK(value, ZSTD_HASHLOG_MIN, ZSTD_HASHLOG_MAX); > ZSTD_cLevelToCCtxParams(params); > params->cParams.hashLog = value; > return 0; > > case ZSTD_p_chainLog : > if (value == 0) return 0; > CLAMPCHECK(value, ZSTD_CHAINLOG_MIN, ZSTD_CHAINLOG_MAX); > ZSTD_cLevelToCCtxParams(params); > params->cParams.chainLog = value; > return 0; > > case ZSTD_p_searchLog : > if (value == 0) return 0; > CLAMPCHECK(value, ZSTD_SEARCHLOG_MIN, ZSTD_SEARCHLOG_MAX); > ZSTD_cLevelToCCtxParams(params); > params->cParams.searchLog = value; > return 0; > > case ZSTD_p_minMatch : > if (value == 0) return 0; > CLAMPCHECK(value, ZSTD_SEARCHLENGTH_MIN, ZSTD_SEARCHLENGTH_MAX); > ZSTD_cLevelToCCtxParams(params); > params->cParams.searchLength = value; > return 0; > > case ZSTD_p_targetLength : > if (value == 0) return 0; > CLAMPCHECK(value, ZSTD_TARGETLENGTH_MIN, ZSTD_TARGETLENGTH_MAX); > ZSTD_cLevelToCCtxParams(params); > params->cParams.targetLength = value; > return 0; > > case ZSTD_p_compressionStrategy : > if (value == 0) return 0; > CLAMPCHECK(value, (unsigned)ZSTD_fast, (unsigned)ZSTD_btultra); > ZSTD_cLevelToCCtxParams(params); > params->cParams.strategy = (ZSTD_strategy)value; > return 0; > > case ZSTD_p_contentSizeFlag : > /* Content size written in frame header _when known_ (default:1) */ > DEBUGLOG(5, "set content size flag = %u", (value>0)); > params->fParams.contentSizeFlag = value > 0; > return 0; > > case ZSTD_p_checksumFlag : > /* A 32-bits content checksum will be calculated and written at end of frame (default:0) */ > params->fParams.checksumFlag = value > 0; > return 0; > > case ZSTD_p_dictIDFlag : /* When applicable, dictionary's dictID is provided in frame header (default:1) */ > DEBUGLOG(5, "set dictIDFlag = %u", (value>0)); > params->fParams.noDictIDFlag = (value == 0); > return 0; > > case ZSTD_p_forceMaxWindow : > params->forceWindow = value > 0; > return 0; > > case ZSTD_p_nbThreads : > if (value == 0) return 0; >#ifndef ZSTD_MULTITHREAD > if (value > 1) return ERROR(parameter_unsupported); > return 0; >#else ># 418 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.c" > return ZSTDMT_initializeCCtxParameters(params, value); >#endif ># 420 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.c" > > case ZSTD_p_jobSize : >#ifndef ZSTD_MULTITHREAD > return ERROR(parameter_unsupported); >#else ># 425 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.c" > if (params->nbThreads <= 1) return ERROR(parameter_unsupported); > return ZSTDMT_CCtxParam_setMTCtxParameter(params, ZSTDMT_p_sectionSize, value); >#endif ># 428 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.c" > > case ZSTD_p_overlapSizeLog : >#ifndef ZSTD_MULTITHREAD > return ERROR(parameter_unsupported); >#else ># 433 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.c" > if (params->nbThreads <= 1) return ERROR(parameter_unsupported); > return ZSTDMT_CCtxParam_setMTCtxParameter(params, ZSTDMT_p_overlapSectionLog, value); >#endif ># 436 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.c" > > case ZSTD_p_enableLongDistanceMatching : > if (value != 0) { > ZSTD_cLevelToCCtxParams(params); > params->cParams.windowLog = ZSTD_LDM_DEFAULT_WINDOW_LOG; > } > return ZSTD_ldm_initializeParameters(¶ms->ldmParams, value); > > case ZSTD_p_ldmHashLog : > if (value == 0) return 0; > CLAMPCHECK(value, ZSTD_HASHLOG_MIN, ZSTD_HASHLOG_MAX); > params->ldmParams.hashLog = value; > return 0; > > case ZSTD_p_ldmMinMatch : > if (value == 0) return 0; > CLAMPCHECK(value, ZSTD_LDM_MINMATCH_MIN, ZSTD_LDM_MINMATCH_MAX); > params->ldmParams.minMatchLength = value; > return 0; > > case ZSTD_p_ldmBucketSizeLog : > if (value > ZSTD_LDM_BUCKETSIZELOG_MAX) { > return ERROR(parameter_outOfBound); > } > params->ldmParams.bucketSizeLog = value; > return 0; > > case ZSTD_p_ldmHashEveryLog : > if (value > ZSTD_WINDOWLOG_MAX - ZSTD_HASHLOG_MIN) { > return ERROR(parameter_outOfBound); > } > params->ldmParams.hashEveryLog = value; > return 0; > > default: return ERROR(parameter_unsupported); > } >} > >/** > * This function should be updated whenever ZSTD_CCtx_params is updated. > * Parameters are copied manually before the dictionary is loaded. > * The multithreading parameters jobSize and overlapSizeLog are set only if > * nbThreads > 1. > * > * Pledged srcSize is treated as unknown. > */ >size_t ZSTD_CCtx_setParametersUsingCCtxParams( > ZSTD_CCtx* cctx, const ZSTD_CCtx_params* params) >{ > if (cctx->streamStage != zcss_init) return ERROR(stage_wrong); > if (cctx->cdict) return ERROR(stage_wrong); > > /* Assume the compression and frame parameters are validated */ > cctx->requestedParams.cParams = params->cParams; > cctx->requestedParams.fParams = params->fParams; > cctx->requestedParams.compressionLevel = params->compressionLevel; > > /* Set force window explicitly since it sets cctx->loadedDictEnd */ > CHECK_F( ZSTD_CCtx_setParameter( > cctx, ZSTD_p_forceMaxWindow, params->forceWindow) ); > > /* Set multithreading parameters explicitly */ > CHECK_F( ZSTD_CCtx_setParameter(cctx, ZSTD_p_nbThreads, params->nbThreads) ); > if (params->nbThreads > 1) { > CHECK_F( ZSTD_CCtx_setParameter(cctx, ZSTD_p_jobSize, params->jobSize) ); > CHECK_F( ZSTD_CCtx_setParameter( > cctx, ZSTD_p_overlapSizeLog, params->overlapSizeLog) ); > } > > /* Copy long distance matching parameters */ > cctx->requestedParams.ldmParams = params->ldmParams; > > /* customMem is used only for create/free params and can be ignored */ > return 0; >} > >ZSTDLIB_API size_t ZSTD_CCtx_setPledgedSrcSize(ZSTD_CCtx* cctx, unsigned long long pledgedSrcSize) >{ > DEBUGLOG(4, " setting pledgedSrcSize to %u", (U32)pledgedSrcSize); > if (cctx->streamStage != zcss_init) return ERROR(stage_wrong); > cctx->pledgedSrcSizePlusOne = pledgedSrcSize+1; > return 0; >} > >size_t ZSTD_CCtx_loadDictionary_advanced( > ZSTD_CCtx* cctx, const void* dict, size_t dictSize, > ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictMode_e dictMode) >{ > if (cctx->streamStage != zcss_init) return ERROR(stage_wrong); > if (cctx->staticSize) return ERROR(memory_allocation); /* no malloc for static CCtx */ > DEBUGLOG(4, "load dictionary of size %u", (U32)dictSize); > ZSTD_freeCDict(cctx->cdictLocal); /* in case one already exists */ > if (dict==NULL || dictSize==0) { /* no dictionary mode */ > cctx->cdictLocal = NULL; > cctx->cdict = NULL; > } else { > ZSTD_compressionParameters const cParams = > ZSTD_getCParamsFromCCtxParams(cctx->requestedParams, 0, dictSize); > cctx->cdictLocal = ZSTD_createCDict_advanced( > dict, dictSize, > dictLoadMethod, dictMode, > cParams, cctx->customMem); > cctx->cdict = cctx->cdictLocal; > if (cctx->cdictLocal == NULL) > return ERROR(memory_allocation); > } > return 0; >} > >ZSTDLIB_API size_t ZSTD_CCtx_loadDictionary_byReference( > ZSTD_CCtx* cctx, const void* dict, size_t dictSize) >{ > return ZSTD_CCtx_loadDictionary_advanced( > cctx, dict, dictSize, ZSTD_dlm_byRef, ZSTD_dm_auto); >} > >ZSTDLIB_API size_t ZSTD_CCtx_loadDictionary(ZSTD_CCtx* cctx, const void* dict, size_t dictSize) >{ > return ZSTD_CCtx_loadDictionary_advanced( > cctx, dict, dictSize, ZSTD_dlm_byCopy, ZSTD_dm_auto); >} > > >size_t ZSTD_CCtx_refCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict) >{ > if (cctx->streamStage != zcss_init) return ERROR(stage_wrong); > cctx->cdict = cdict; > memset(&cctx->prefixDict, 0, sizeof(cctx->prefixDict)); /* exclusive */ > return 0; >} > >size_t ZSTD_CCtx_refPrefix(ZSTD_CCtx* cctx, const void* prefix, size_t prefixSize) >{ > return ZSTD_CCtx_refPrefix_advanced(cctx, prefix, prefixSize, ZSTD_dm_rawContent); >} > >size_t ZSTD_CCtx_refPrefix_advanced( > ZSTD_CCtx* cctx, const void* prefix, size_t prefixSize, ZSTD_dictMode_e dictMode) >{ > if (cctx->streamStage != zcss_init) return ERROR(stage_wrong); > cctx->cdict = NULL; /* prefix discards any prior cdict */ > cctx->prefixDict.dict = prefix; > cctx->prefixDict.dictSize = prefixSize; > cctx->prefixDict.dictMode = dictMode; > return 0; >} > >static void ZSTD_startNewCompression(ZSTD_CCtx* cctx) >{ > cctx->streamStage = zcss_init; > cctx->pledgedSrcSizePlusOne = 0; >} > >/*! ZSTD_CCtx_reset() : > * Also dumps dictionary */ >void ZSTD_CCtx_reset(ZSTD_CCtx* cctx) >{ > ZSTD_startNewCompression(cctx); > cctx->cdict = NULL; >} > >/** ZSTD_checkCParams() : > control CParam values remain within authorized range. > @return : 0, or an error code if one value is beyond authorized range */ >size_t ZSTD_checkCParams(ZSTD_compressionParameters cParams) >{ > CLAMPCHECK(cParams.windowLog, ZSTD_WINDOWLOG_MIN, ZSTD_WINDOWLOG_MAX); > CLAMPCHECK(cParams.chainLog, ZSTD_CHAINLOG_MIN, ZSTD_CHAINLOG_MAX); > CLAMPCHECK(cParams.hashLog, ZSTD_HASHLOG_MIN, ZSTD_HASHLOG_MAX); > CLAMPCHECK(cParams.searchLog, ZSTD_SEARCHLOG_MIN, ZSTD_SEARCHLOG_MAX); > CLAMPCHECK(cParams.searchLength, ZSTD_SEARCHLENGTH_MIN, ZSTD_SEARCHLENGTH_MAX); > CLAMPCHECK(cParams.targetLength, ZSTD_TARGETLENGTH_MIN, ZSTD_TARGETLENGTH_MAX); > if ((U32)(cParams.strategy) > (U32)ZSTD_btultra) > return ERROR(parameter_unsupported); > return 0; >} > >/** ZSTD_clampCParams() : > * make CParam values within valid range. > * @return : valid CParams */ >static ZSTD_compressionParameters ZSTD_clampCParams(ZSTD_compressionParameters cParams) >{ ># define CLAMP(val,min,max) { \ > if (val<min) val=min; \ > else if (val>max) val=max; \ > } > CLAMP(cParams.windowLog, ZSTD_WINDOWLOG_MIN, ZSTD_WINDOWLOG_MAX); > CLAMP(cParams.chainLog, ZSTD_CHAINLOG_MIN, ZSTD_CHAINLOG_MAX); > CLAMP(cParams.hashLog, ZSTD_HASHLOG_MIN, ZSTD_HASHLOG_MAX); > CLAMP(cParams.searchLog, ZSTD_SEARCHLOG_MIN, ZSTD_SEARCHLOG_MAX); > CLAMP(cParams.searchLength, ZSTD_SEARCHLENGTH_MIN, ZSTD_SEARCHLENGTH_MAX); > CLAMP(cParams.targetLength, ZSTD_TARGETLENGTH_MIN, ZSTD_TARGETLENGTH_MAX); > if ((U32)(cParams.strategy) > (U32)ZSTD_btultra) cParams.strategy = ZSTD_btultra; > return cParams; >} > >/** ZSTD_cycleLog() : > * condition for correct operation : hashLog > 1 */ >static U32 ZSTD_cycleLog(U32 hashLog, ZSTD_strategy strat) >{ > U32 const btScale = ((U32)strat >= (U32)ZSTD_btlazy2); > return hashLog - btScale; >} > >/** ZSTD_adjustCParams_internal() : > optimize `cPar` for a given input (`srcSize` and `dictSize`). > mostly downsizing to reduce memory consumption and initialization latency. > Both `srcSize` and `dictSize` are optional (use 0 if unknown). > Note : cPar is considered validated at this stage. Use ZSTD_checkCParams() to ensure that condition. */ >ZSTD_compressionParameters ZSTD_adjustCParams_internal(ZSTD_compressionParameters cPar, unsigned long long srcSize, size_t dictSize) >{ > static const U64 minSrcSize = 513; /* (1<<9) + 1 */ > static const U64 maxWindowResize = 1ULL << (ZSTD_WINDOWLOG_MAX-1); > assert(ZSTD_checkCParams(cPar)==0); > > if (dictSize && (srcSize+1<2) /* srcSize unknown */ ) > srcSize = minSrcSize; /* presumed small when there is a dictionary */ > else if (srcSize == 0) > srcSize = ZSTD_CONTENTSIZE_UNKNOWN; /* 0 == unknown : presumed large */ > > /* resize windowLog if input is small enough, to use less memory */ > if ( (srcSize < maxWindowResize) > && (dictSize < maxWindowResize) ) { > U32 const tSize = (U32)(srcSize + dictSize); > static U32 const hashSizeMin = 1 << ZSTD_HASHLOG_MIN; > U32 const srcLog = (tSize < hashSizeMin) ? ZSTD_HASHLOG_MIN : > ZSTD_highbit32(tSize-1) + 1; > if (cPar.windowLog > srcLog) cPar.windowLog = srcLog; > } > if (cPar.hashLog > cPar.windowLog) cPar.hashLog = cPar.windowLog; > { U32 const cycleLog = ZSTD_cycleLog(cPar.chainLog, cPar.strategy); > if (cycleLog > cPar.windowLog) > cPar.chainLog -= (cycleLog - cPar.windowLog); > } > > if (cPar.windowLog < ZSTD_WINDOWLOG_ABSOLUTEMIN) > cPar.windowLog = ZSTD_WINDOWLOG_ABSOLUTEMIN; /* required for frame header */ > > return cPar; >} > >ZSTD_compressionParameters ZSTD_adjustCParams(ZSTD_compressionParameters cPar, unsigned long long srcSize, size_t dictSize) >{ > cPar = ZSTD_clampCParams(cPar); > return ZSTD_adjustCParams_internal(cPar, srcSize, dictSize); >} > >size_t ZSTD_estimateCCtxSize_usingCCtxParams(const ZSTD_CCtx_params* params) >{ > /* Estimate CCtx size is supported for single-threaded compression only. */ > if (params->nbThreads > 1) { return ERROR(GENERIC); } > { ZSTD_compressionParameters const cParams = > ZSTD_getCParamsFromCCtxParams(*params, 0, 0); > size_t const blockSize = MIN(ZSTD_BLOCKSIZE_MAX, (size_t)1 << cParams.windowLog); > U32 const divider = (cParams.searchLength==3) ? 3 : 4; > size_t const maxNbSeq = blockSize / divider; > size_t const tokenSpace = blockSize + 11*maxNbSeq; > size_t const chainSize = > (cParams.strategy == ZSTD_fast) ? 0 : ((size_t)1 << cParams.chainLog); > size_t const hSize = ((size_t)1) << cParams.hashLog; > U32 const hashLog3 = (cParams.searchLength>3) ? > 0 : MIN(ZSTD_HASHLOG3_MAX, cParams.windowLog); > size_t const h3Size = ((size_t)1) << hashLog3; > size_t const entropySpace = sizeof(ZSTD_entropyCTables_t); > size_t const tableSpace = (chainSize + hSize + h3Size) * sizeof(U32); > > size_t const optBudget = > ((MaxML+1) + (MaxLL+1) + (MaxOff+1) + (1<<Litbits))*sizeof(U32) > + (ZSTD_OPT_NUM+1)*(sizeof(ZSTD_match_t) + sizeof(ZSTD_optimal_t)); > size_t const optSpace = ((cParams.strategy == ZSTD_btopt) || (cParams.strategy == ZSTD_btultra)) ? optBudget : 0; > > size_t const ldmSpace = params->ldmParams.enableLdm ? > ZSTD_ldm_getTableSize(params->ldmParams.hashLog, > params->ldmParams.bucketSizeLog) : 0; > > size_t const neededSpace = entropySpace + tableSpace + tokenSpace + > optSpace + ldmSpace; > > DEBUGLOG(5, "sizeof(ZSTD_CCtx) : %u", (U32)sizeof(ZSTD_CCtx)); > DEBUGLOG(5, "estimate workSpace : %u", (U32)neededSpace); > return sizeof(ZSTD_CCtx) + neededSpace; > } >} > >size_t ZSTD_estimateCCtxSize_usingCParams(ZSTD_compressionParameters cParams) >{ > ZSTD_CCtx_params const params = ZSTD_makeCCtxParamsFromCParams(cParams); > return ZSTD_estimateCCtxSize_usingCCtxParams(¶ms); >} > >size_t ZSTD_estimateCCtxSize(int compressionLevel) >{ > ZSTD_compressionParameters const cParams = ZSTD_getCParams(compressionLevel, 0, 0); > return ZSTD_estimateCCtxSize_usingCParams(cParams); >} > >size_t ZSTD_estimateCStreamSize_usingCCtxParams(const ZSTD_CCtx_params* params) >{ > if (params->nbThreads > 1) { return ERROR(GENERIC); } > { size_t const CCtxSize = ZSTD_estimateCCtxSize_usingCCtxParams(params); > size_t const blockSize = MIN(ZSTD_BLOCKSIZE_MAX, (size_t)1 << params->cParams.windowLog); > size_t const inBuffSize = ((size_t)1 << params->cParams.windowLog) + blockSize; > size_t const outBuffSize = ZSTD_compressBound(blockSize) + 1; > size_t const streamingSize = inBuffSize + outBuffSize; > > return CCtxSize + streamingSize; > } >} > >size_t ZSTD_estimateCStreamSize_usingCParams(ZSTD_compressionParameters cParams) >{ > ZSTD_CCtx_params const params = ZSTD_makeCCtxParamsFromCParams(cParams); > return ZSTD_estimateCStreamSize_usingCCtxParams(¶ms); >} > >size_t ZSTD_estimateCStreamSize(int compressionLevel) { > ZSTD_compressionParameters const cParams = ZSTD_getCParams(compressionLevel, 0, 0); > return ZSTD_estimateCStreamSize_usingCParams(cParams); >} > >static U32 ZSTD_equivalentCParams(ZSTD_compressionParameters cParams1, > ZSTD_compressionParameters cParams2) >{ > U32 bslog1 = MIN(cParams1.windowLog, ZSTD_BLOCKSIZELOG_MAX); > U32 bslog2 = MIN(cParams2.windowLog, ZSTD_BLOCKSIZELOG_MAX); > return (bslog1 == bslog2) /* same block size */ > & (cParams1.hashLog == cParams2.hashLog) > & (cParams1.chainLog == cParams2.chainLog) > & (cParams1.strategy == cParams2.strategy) /* opt parser space */ > & ((cParams1.searchLength==3) == (cParams2.searchLength==3)); /* hashlog3 space */ >} > >/** The parameters are equivalent if ldm is not enabled in both sets or > * all the parameters are equivalent. */ >static U32 ZSTD_equivalentLdmParams(ldmParams_t ldmParams1, > ldmParams_t ldmParams2) >{ > return (!ldmParams1.enableLdm && !ldmParams2.enableLdm) || > (ldmParams1.enableLdm == ldmParams2.enableLdm && > ldmParams1.hashLog == ldmParams2.hashLog && > ldmParams1.bucketSizeLog == ldmParams2.bucketSizeLog && > ldmParams1.minMatchLength == ldmParams2.minMatchLength && > ldmParams1.hashEveryLog == ldmParams2.hashEveryLog); >} > >/** Equivalence for resetCCtx purposes */ >static U32 ZSTD_equivalentParams(ZSTD_CCtx_params params1, > ZSTD_CCtx_params params2) >{ > return ZSTD_equivalentCParams(params1.cParams, params2.cParams) && > ZSTD_equivalentLdmParams(params1.ldmParams, params2.ldmParams); >} > >/*! ZSTD_continueCCtx() : > * reuse CCtx without reset (note : requires no dictionary) */ >static size_t ZSTD_continueCCtx(ZSTD_CCtx* cctx, ZSTD_CCtx_params params, U64 pledgedSrcSize) >{ > U32 const end = (U32)(cctx->nextSrc - cctx->base); > DEBUGLOG(4, "continue mode"); > cctx->appliedParams = params; > cctx->pledgedSrcSizePlusOne = pledgedSrcSize+1; > cctx->consumedSrcSize = 0; > if (pledgedSrcSize == ZSTD_CONTENTSIZE_UNKNOWN) > cctx->appliedParams.fParams.contentSizeFlag = 0; > DEBUGLOG(4, "pledged content size : %u ; flag : %u", > (U32)pledgedSrcSize, cctx->appliedParams.fParams.contentSizeFlag); > cctx->lowLimit = end; > cctx->dictLimit = end; > cctx->nextToUpdate = end+1; > cctx->stage = ZSTDcs_init; > cctx->dictID = 0; > cctx->loadedDictEnd = 0; > { int i; for (i=0; i<ZSTD_REP_NUM; i++) cctx->seqStore.rep[i] = repStartValue[i]; } > cctx->optState.litLengthSum = 0; /* force reset of btopt stats */ > XXH64_reset(&cctx->xxhState, 0); > return 0; >} > >typedef enum { ZSTDcrp_continue, ZSTDcrp_noMemset } ZSTD_compResetPolicy_e; >typedef enum { ZSTDb_not_buffered, ZSTDb_buffered } ZSTD_buffered_policy_e; > >/*! ZSTD_resetCCtx_internal() : > note : `params` are assumed fully validated at this stage */ >static size_t ZSTD_resetCCtx_internal(ZSTD_CCtx* zc, > ZSTD_CCtx_params params, U64 pledgedSrcSize, > ZSTD_compResetPolicy_e const crp, > ZSTD_buffered_policy_e const zbuff) >{ > DEBUGLOG(4, "ZSTD_resetCCtx_internal"); > assert(!ZSTD_isError(ZSTD_checkCParams(params.cParams))); > DEBUGLOG(4, "pledgedSrcSize: %u", (U32)pledgedSrcSize); > > if (crp == ZSTDcrp_continue) { > if (ZSTD_equivalentParams(params, zc->appliedParams)) { > DEBUGLOG(4, "ZSTD_equivalentParams()==1"); > assert(!(params.ldmParams.enableLdm && > params.ldmParams.hashEveryLog == ZSTD_LDM_HASHEVERYLOG_NOTSET)); > zc->entropy->hufCTable_repeatMode = HUF_repeat_none; > zc->entropy->offcode_repeatMode = FSE_repeat_none; > zc->entropy->matchlength_repeatMode = FSE_repeat_none; > zc->entropy->litlength_repeatMode = FSE_repeat_none; > return ZSTD_continueCCtx(zc, params, pledgedSrcSize); > } } > > if (params.ldmParams.enableLdm) { > /* Adjust long distance matching parameters */ > ZSTD_ldm_adjustParameters(¶ms.ldmParams, params.cParams.windowLog); > assert(params.ldmParams.hashLog >= params.ldmParams.bucketSizeLog); > assert(params.ldmParams.hashEveryLog < 32); > zc->ldmState.hashPower = > ZSTD_ldm_getHashPower(params.ldmParams.minMatchLength); > } > > { size_t const blockSize = MIN(ZSTD_BLOCKSIZE_MAX, (size_t)1 << params.cParams.windowLog); > U32 const divider = (params.cParams.searchLength==3) ? 3 : 4; > size_t const maxNbSeq = blockSize / divider; > size_t const tokenSpace = blockSize + 11*maxNbSeq; > size_t const chainSize = (params.cParams.strategy == ZSTD_fast) ? > 0 : ((size_t)1 << params.cParams.chainLog); > size_t const hSize = ((size_t)1) << params.cParams.hashLog; > U32 const hashLog3 = (params.cParams.searchLength>3) ? > 0 : MIN(ZSTD_HASHLOG3_MAX, params.cParams.windowLog); > size_t const h3Size = ((size_t)1) << hashLog3; > size_t const tableSpace = (chainSize + hSize + h3Size) * sizeof(U32); > size_t const buffOutSize = (zbuff==ZSTDb_buffered) ? ZSTD_compressBound(blockSize)+1 : 0; > size_t const buffInSize = (zbuff==ZSTDb_buffered) ? ((size_t)1 << params.cParams.windowLog) + blockSize : 0; > void* ptr; > > /* Check if workSpace is large enough, alloc a new one if needed */ > { size_t const entropySpace = sizeof(ZSTD_entropyCTables_t); > size_t const optPotentialSpace = ((MaxML+1) + (MaxLL+1) + (MaxOff+1) + (1<<Litbits)) * sizeof(U32) > + (ZSTD_OPT_NUM+1) * (sizeof(ZSTD_match_t)+sizeof(ZSTD_optimal_t)); > size_t const optSpace = ( (params.cParams.strategy == ZSTD_btopt) > || (params.cParams.strategy == ZSTD_btultra)) ? > optPotentialSpace : 0; > size_t const bufferSpace = buffInSize + buffOutSize; > size_t const ldmSpace = params.ldmParams.enableLdm > ? ZSTD_ldm_getTableSize(params.ldmParams.hashLog, params.ldmParams.bucketSizeLog) > : 0; > size_t const neededSpace = entropySpace + optSpace + ldmSpace + > tableSpace + tokenSpace + bufferSpace; > > if (zc->workSpaceSize < neededSpace) { /* too small : resize */ > DEBUGLOG(5, "Need to update workSpaceSize from %uK to %uK \n", > (unsigned)zc->workSpaceSize>>10, > (unsigned)neededSpace>>10); > /* static cctx : no resize, error out */ > if (zc->staticSize) return ERROR(memory_allocation); > > zc->workSpaceSize = 0; > ZSTD_free(zc->workSpace, zc->customMem); > zc->workSpace = ZSTD_malloc(neededSpace, zc->customMem); > if (zc->workSpace == NULL) return ERROR(memory_allocation); > zc->workSpaceSize = neededSpace; > ptr = zc->workSpace; > > /* entropy space */ > assert(((size_t)zc->workSpace & 3) == 0); /* ensure correct alignment */ > assert(zc->workSpaceSize >= sizeof(ZSTD_entropyCTables_t)); > zc->entropy = (ZSTD_entropyCTables_t*)zc->workSpace; > } } > > /* init params */ > zc->appliedParams = params; > zc->pledgedSrcSizePlusOne = pledgedSrcSize+1; > zc->consumedSrcSize = 0; > if (pledgedSrcSize == ZSTD_CONTENTSIZE_UNKNOWN) > zc->appliedParams.fParams.contentSizeFlag = 0; > DEBUGLOG(5, "pledged content size : %u ; flag : %u", > (U32)pledgedSrcSize, zc->appliedParams.fParams.contentSizeFlag); > zc->blockSize = blockSize; > > XXH64_reset(&zc->xxhState, 0); > zc->stage = ZSTDcs_init; > zc->dictID = 0; > zc->loadedDictEnd = 0; > zc->entropy->hufCTable_repeatMode = HUF_repeat_none; > zc->entropy->offcode_repeatMode = FSE_repeat_none; > zc->entropy->matchlength_repeatMode = FSE_repeat_none; > zc->entropy->litlength_repeatMode = FSE_repeat_none; > zc->nextToUpdate = 1; > zc->nextSrc = NULL; > zc->base = NULL; > zc->dictBase = NULL; > zc->dictLimit = 0; > zc->lowLimit = 0; > { int i; for (i=0; i<ZSTD_REP_NUM; i++) zc->seqStore.rep[i] = repStartValue[i]; } > zc->hashLog3 = hashLog3; > zc->optState.litLengthSum = 0; > > ptr = zc->entropy + 1; > > /* opt parser space */ > if ((params.cParams.strategy == ZSTD_btopt) || (params.cParams.strategy == ZSTD_btultra)) { > DEBUGLOG(5, "reserving optimal parser space"); > assert(((size_t)ptr & 3) == 0); /* ensure ptr is properly aligned */ > zc->optState.litFreq = (U32*)ptr; > zc->optState.litLengthFreq = zc->optState.litFreq + (1<<Litbits); > zc->optState.matchLengthFreq = zc->optState.litLengthFreq + (MaxLL+1); > zc->optState.offCodeFreq = zc->optState.matchLengthFreq + (MaxML+1); > ptr = zc->optState.offCodeFreq + (MaxOff+1); > zc->optState.matchTable = (ZSTD_match_t*)ptr; > ptr = zc->optState.matchTable + ZSTD_OPT_NUM+1; > zc->optState.priceTable = (ZSTD_optimal_t*)ptr; > ptr = zc->optState.priceTable + ZSTD_OPT_NUM+1; > } > > /* ldm hash table */ > /* initialize bucketOffsets table later for pointer alignment */ > if (params.ldmParams.enableLdm) { > size_t const ldmHSize = ((size_t)1) << params.ldmParams.hashLog; > memset(ptr, 0, ldmHSize * sizeof(ldmEntry_t)); > assert(((size_t)ptr & 3) == 0); /* ensure ptr is properly aligned */ > zc->ldmState.hashTable = (ldmEntry_t*)ptr; > ptr = zc->ldmState.hashTable + ldmHSize; > } > > /* table Space */ > if (crp!=ZSTDcrp_noMemset) memset(ptr, 0, tableSpace); /* reset tables only */ > assert(((size_t)ptr & 3) == 0); /* ensure ptr is properly aligned */ > zc->hashTable = (U32*)(ptr); > zc->chainTable = zc->hashTable + hSize; > zc->hashTable3 = zc->chainTable + chainSize; > ptr = zc->hashTable3 + h3Size; > > /* sequences storage */ > zc->seqStore.sequencesStart = (seqDef*)ptr; > ptr = zc->seqStore.sequencesStart + maxNbSeq; > zc->seqStore.llCode = (BYTE*) ptr; > zc->seqStore.mlCode = zc->seqStore.llCode + maxNbSeq; > zc->seqStore.ofCode = zc->seqStore.mlCode + maxNbSeq; > zc->seqStore.litStart = zc->seqStore.ofCode + maxNbSeq; > ptr = zc->seqStore.litStart + blockSize; > > /* ldm bucketOffsets table */ > if (params.ldmParams.enableLdm) { > size_t const ldmBucketSize = > ((size_t)1) << (params.ldmParams.hashLog - > params.ldmParams.bucketSizeLog); > memset(ptr, 0, ldmBucketSize); > zc->ldmState.bucketOffsets = (BYTE*)ptr; > ptr = zc->ldmState.bucketOffsets + ldmBucketSize; > } > > /* buffers */ > zc->inBuffSize = buffInSize; > zc->inBuff = (char*)ptr; > zc->outBuffSize = buffOutSize; > zc->outBuff = zc->inBuff + buffInSize; > > return 0; > } >} > >/* ZSTD_invalidateRepCodes() : > * ensures next compression will not use repcodes from previous block. > * Note : only works with regular variant; > * do not use with extDict variant ! */ >void ZSTD_invalidateRepCodes(ZSTD_CCtx* cctx) { > int i; > for (i=0; i<ZSTD_REP_NUM; i++) cctx->seqStore.rep[i] = 0; >} > > >/*! ZSTD_copyCCtx_internal() : > * Duplicate an existing context `srcCCtx` into another one `dstCCtx`. > * The "context", in this case, refers to the hash and chain tables, entropy > * tables, and dictionary offsets. > * Only works during stage ZSTDcs_init (i.e. after creation, but before first call to ZSTD_compressContinue()). > * pledgedSrcSize=0 means "empty" if fParams.contentSizeFlag=1 > * @return : 0, or an error code */ >static size_t ZSTD_copyCCtx_internal(ZSTD_CCtx* dstCCtx, > const ZSTD_CCtx* srcCCtx, > ZSTD_frameParameters fParams, > unsigned long long pledgedSrcSize, > ZSTD_buffered_policy_e zbuff) >{ > DEBUGLOG(5, "ZSTD_copyCCtx_internal"); > if (srcCCtx->stage!=ZSTDcs_init) return ERROR(stage_wrong); > > memcpy(&dstCCtx->customMem, &srcCCtx->customMem, sizeof(ZSTD_customMem)); > { ZSTD_CCtx_params params = dstCCtx->requestedParams; > /* Copy only compression parameters related to tables. */ > params.cParams = srcCCtx->appliedParams.cParams; > params.fParams = fParams; > ZSTD_resetCCtx_internal(dstCCtx, params, pledgedSrcSize, > ZSTDcrp_noMemset, zbuff); > } > > /* copy tables */ > { size_t const chainSize = (srcCCtx->appliedParams.cParams.strategy == ZSTD_fast) ? 0 : ((size_t)1 << srcCCtx->appliedParams.cParams.chainLog); > size_t const hSize = (size_t)1 << srcCCtx->appliedParams.cParams.hashLog; > size_t const h3Size = (size_t)1 << srcCCtx->hashLog3; > size_t const tableSpace = (chainSize + hSize + h3Size) * sizeof(U32); > assert((U32*)dstCCtx->chainTable == (U32*)dstCCtx->hashTable + hSize); /* chainTable must follow hashTable */ > assert((U32*)dstCCtx->hashTable3 == (U32*)dstCCtx->chainTable + chainSize); > memcpy(dstCCtx->hashTable, srcCCtx->hashTable, tableSpace); /* presumes all tables follow each other */ > } > > /* copy dictionary offsets */ > dstCCtx->nextToUpdate = srcCCtx->nextToUpdate; > dstCCtx->nextToUpdate3= srcCCtx->nextToUpdate3; > dstCCtx->nextSrc = srcCCtx->nextSrc; > dstCCtx->base = srcCCtx->base; > dstCCtx->dictBase = srcCCtx->dictBase; > dstCCtx->dictLimit = srcCCtx->dictLimit; > dstCCtx->lowLimit = srcCCtx->lowLimit; > dstCCtx->loadedDictEnd= srcCCtx->loadedDictEnd; > dstCCtx->dictID = srcCCtx->dictID; > > /* copy entropy tables */ > memcpy(dstCCtx->entropy, srcCCtx->entropy, sizeof(ZSTD_entropyCTables_t)); > > return 0; >} > >/*! ZSTD_copyCCtx() : > * Duplicate an existing context `srcCCtx` into another one `dstCCtx`. > * Only works during stage ZSTDcs_init (i.e. after creation, but before first call to ZSTD_compressContinue()). > * pledgedSrcSize==0 means "unknown". >* @return : 0, or an error code */ >size_t ZSTD_copyCCtx(ZSTD_CCtx* dstCCtx, const ZSTD_CCtx* srcCCtx, unsigned long long pledgedSrcSize) >{ > ZSTD_frameParameters fParams = { 1 /*content*/, 0 /*checksum*/, 0 /*noDictID*/ }; > ZSTD_buffered_policy_e const zbuff = (ZSTD_buffered_policy_e)(srcCCtx->inBuffSize>0); > ZSTD_STATIC_ASSERT((U32)ZSTDb_buffered==1); > fParams.contentSizeFlag = pledgedSrcSize>0; > > return ZSTD_copyCCtx_internal(dstCCtx, srcCCtx, fParams, pledgedSrcSize, zbuff); >} > > >/*! ZSTD_reduceTable() : > * reduce table indexes by `reducerValue` */ >static void ZSTD_reduceTable (U32* const table, U32 const size, U32 const reducerValue) >{ > U32 u; > for (u=0 ; u < size ; u++) { > if (table[u] < reducerValue) table[u] = 0; > else table[u] -= reducerValue; > } >} > >/*! ZSTD_ldm_reduceTable() : > * reduce table indexes by `reducerValue` */ >static void ZSTD_ldm_reduceTable(ldmEntry_t* const table, U32 const size, > U32 const reducerValue) >{ > U32 u; > for (u = 0; u < size; u++) { > if (table[u].offset < reducerValue) table[u].offset = 0; > else table[u].offset -= reducerValue; > } >} > >/*! ZSTD_reduceIndex() : >* rescale all indexes to avoid future overflow (indexes are U32) */ >static void ZSTD_reduceIndex (ZSTD_CCtx* zc, const U32 reducerValue) >{ > { U32 const hSize = (U32)1 << zc->appliedParams.cParams.hashLog; > ZSTD_reduceTable(zc->hashTable, hSize, reducerValue); } > > { U32 const chainSize = (zc->appliedParams.cParams.strategy == ZSTD_fast) ? 0 : ((U32)1 << zc->appliedParams.cParams.chainLog); > ZSTD_reduceTable(zc->chainTable, chainSize, reducerValue); } > > { U32 const h3Size = (zc->hashLog3) ? (U32)1 << zc->hashLog3 : 0; > ZSTD_reduceTable(zc->hashTable3, h3Size, reducerValue); } > > { if (zc->appliedParams.ldmParams.enableLdm) { > U32 const ldmHSize = (U32)1 << zc->appliedParams.ldmParams.hashLog; > ZSTD_ldm_reduceTable(zc->ldmState.hashTable, ldmHSize, reducerValue); > } > } >} > > >/*-******************************************************* >* Block entropic compression >*********************************************************/ > >/* See doc/zstd_compression_format.md for detailed format description */ > >size_t ZSTD_noCompressBlock (void* dst, size_t dstCapacity, const void* src, size_t srcSize) >{ > if (srcSize + ZSTD_blockHeaderSize > dstCapacity) return ERROR(dstSize_tooSmall); > memcpy((BYTE*)dst + ZSTD_blockHeaderSize, src, srcSize); > MEM_writeLE24(dst, (U32)(srcSize << 2) + (U32)bt_raw); > return ZSTD_blockHeaderSize+srcSize; >} > > >static size_t ZSTD_noCompressLiterals (void* dst, size_t dstCapacity, const void* src, size_t srcSize) >{ > BYTE* const ostart = (BYTE* const)dst; > U32 const flSize = 1 + (srcSize>31) + (srcSize>4095); > > if (srcSize + flSize > dstCapacity) return ERROR(dstSize_tooSmall); > > switch(flSize) > { > case 1: /* 2 - 1 - 5 */ > ostart[0] = (BYTE)((U32)set_basic + (srcSize<<3)); > break; > case 2: /* 2 - 2 - 12 */ > MEM_writeLE16(ostart, (U16)((U32)set_basic + (1<<2) + (srcSize<<4))); > break; > case 3: /* 2 - 2 - 20 */ > MEM_writeLE32(ostart, (U32)((U32)set_basic + (3<<2) + (srcSize<<4))); > break; > default: /* not necessary : flSize is {1,2,3} */ > assert(0); > } > > memcpy(ostart + flSize, src, srcSize); > return srcSize + flSize; >} > >static size_t ZSTD_compressRleLiteralsBlock (void* dst, size_t dstCapacity, const void* src, size_t srcSize) >{ > BYTE* const ostart = (BYTE* const)dst; > U32 const flSize = 1 + (srcSize>31) + (srcSize>4095); > > (void)dstCapacity; /* dstCapacity already guaranteed to be >=4, hence large enough */ > > switch(flSize) > { > case 1: /* 2 - 1 - 5 */ > ostart[0] = (BYTE)((U32)set_rle + (srcSize<<3)); > break; > case 2: /* 2 - 2 - 12 */ > MEM_writeLE16(ostart, (U16)((U32)set_rle + (1<<2) + (srcSize<<4))); > break; > case 3: /* 2 - 2 - 20 */ > MEM_writeLE32(ostart, (U32)((U32)set_rle + (3<<2) + (srcSize<<4))); > break; > default: /* not necessary : flSize is {1,2,3} */ > assert(0); > } > > ostart[flSize] = *(const BYTE*)src; > return flSize+1; >} > > >static size_t ZSTD_minGain(size_t srcSize) { return (srcSize >> 6) + 2; } > >static size_t ZSTD_compressLiterals (ZSTD_entropyCTables_t * entropy, > ZSTD_strategy strategy, > void* dst, size_t dstCapacity, > const void* src, size_t srcSize) >{ > size_t const minGain = ZSTD_minGain(srcSize); > size_t const lhSize = 3 + (srcSize >= 1 KB) + (srcSize >= 16 KB); > BYTE* const ostart = (BYTE*)dst; > U32 singleStream = srcSize < 256; > symbolEncodingType_e hType = set_compressed; > size_t cLitSize; > > > /* small ? don't even attempt compression (speed opt) */ ># define LITERAL_NOENTROPY 63 > { size_t const minLitSize = entropy->hufCTable_repeatMode == HUF_repeat_valid ? 6 : LITERAL_NOENTROPY; > if (srcSize <= minLitSize) return ZSTD_noCompressLiterals(dst, dstCapacity, src, srcSize); > } > > if (dstCapacity < lhSize+1) return ERROR(dstSize_tooSmall); /* not enough space for compression */ > { HUF_repeat repeat = entropy->hufCTable_repeatMode; > int const preferRepeat = strategy < ZSTD_lazy ? srcSize <= 1024 : 0; > if (repeat == HUF_repeat_valid && lhSize == 3) singleStream = 1; > cLitSize = singleStream ? HUF_compress1X_repeat(ostart+lhSize, dstCapacity-lhSize, src, srcSize, 255, 11, > entropy->workspace, sizeof(entropy->workspace), (HUF_CElt*)entropy->hufCTable, &repeat, preferRepeat) > : HUF_compress4X_repeat(ostart+lhSize, dstCapacity-lhSize, src, srcSize, 255, 11, > entropy->workspace, sizeof(entropy->workspace), (HUF_CElt*)entropy->hufCTable, &repeat, preferRepeat); > if (repeat != HUF_repeat_none) { hType = set_repeat; } /* reused the existing table */ > else { entropy->hufCTable_repeatMode = HUF_repeat_check; } /* now have a table to reuse */ > } > > if ((cLitSize==0) | (cLitSize >= srcSize - minGain) | ERR_isError(cLitSize)) { > entropy->hufCTable_repeatMode = HUF_repeat_none; > return ZSTD_noCompressLiterals(dst, dstCapacity, src, srcSize); > } > if (cLitSize==1) { > entropy->hufCTable_repeatMode = HUF_repeat_none; > return ZSTD_compressRleLiteralsBlock(dst, dstCapacity, src, srcSize); > } > > /* Build header */ > switch(lhSize) > { > case 3: /* 2 - 2 - 10 - 10 */ > { U32 const lhc = hType + ((!singleStream) << 2) + ((U32)srcSize<<4) + ((U32)cLitSize<<14); > MEM_writeLE24(ostart, lhc); > break; > } > case 4: /* 2 - 2 - 14 - 14 */ > { U32 const lhc = hType + (2 << 2) + ((U32)srcSize<<4) + ((U32)cLitSize<<18); > MEM_writeLE32(ostart, lhc); > break; > } > case 5: /* 2 - 2 - 18 - 18 */ > { U32 const lhc = hType + (3 << 2) + ((U32)srcSize<<4) + ((U32)cLitSize<<22); > MEM_writeLE32(ostart, lhc); > ostart[4] = (BYTE)(cLitSize >> 10); > break; > } > default: /* not possible : lhSize is {3,4,5} */ > assert(0); > } > return lhSize+cLitSize; >} > > >void ZSTD_seqToCodes(const seqStore_t* seqStorePtr) >{ > BYTE const LL_deltaCode = 19; > BYTE const ML_deltaCode = 36; > const seqDef* const sequences = seqStorePtr->sequencesStart; > BYTE* const llCodeTable = seqStorePtr->llCode; > BYTE* const ofCodeTable = seqStorePtr->ofCode; > BYTE* const mlCodeTable = seqStorePtr->mlCode; > U32 const nbSeq = (U32)(seqStorePtr->sequences - seqStorePtr->sequencesStart); > U32 u; > for (u=0; u<nbSeq; u++) { > U32 const llv = sequences[u].litLength; > U32 const mlv = sequences[u].matchLength; > llCodeTable[u] = (llv> 63) ? (BYTE)ZSTD_highbit32(llv) + LL_deltaCode : LL_Code[llv]; > ofCodeTable[u] = (BYTE)ZSTD_highbit32(sequences[u].offset); > mlCodeTable[u] = (mlv>127) ? (BYTE)ZSTD_highbit32(mlv) + ML_deltaCode : ML_Code[mlv]; > } > if (seqStorePtr->longLengthID==1) > llCodeTable[seqStorePtr->longLengthPos] = MaxLL; > if (seqStorePtr->longLengthID==2) > mlCodeTable[seqStorePtr->longLengthPos] = MaxML; >} > >typedef enum { > ZSTD_defaultDisallowed = 0, > ZSTD_defaultAllowed = 1 >} ZSTD_defaultPolicy_e; > >MEM_STATIC symbolEncodingType_e ZSTD_selectEncodingType( > FSE_repeat* repeatMode, size_t const mostFrequent, size_t nbSeq, > U32 defaultNormLog, ZSTD_defaultPolicy_e const isDefaultAllowed) >{ >#define MIN_SEQ_FOR_DYNAMIC_FSE 64 >#define MAX_SEQ_FOR_STATIC_FSE 1000 > ZSTD_STATIC_ASSERT(ZSTD_defaultDisallowed == 0 && ZSTD_defaultAllowed != 0); > if ((mostFrequent == nbSeq) && (!isDefaultAllowed || nbSeq > 2)) { > /* Prefer set_basic over set_rle when there are 2 or less symbols, > * since RLE uses 1 byte, but set_basic uses 5-6 bits per symbol. > * If basic encoding isn't possible, always choose RLE. > */ > *repeatMode = FSE_repeat_check; > return set_rle; > } > if (isDefaultAllowed && (*repeatMode == FSE_repeat_valid) && (nbSeq < MAX_SEQ_FOR_STATIC_FSE)) { > return set_repeat; > } > if (isDefaultAllowed && ((nbSeq < MIN_SEQ_FOR_DYNAMIC_FSE) || (mostFrequent < (nbSeq >> (defaultNormLog-1))))) { > *repeatMode = FSE_repeat_valid; > return set_basic; > } > *repeatMode = FSE_repeat_check; > return set_compressed; >} > >MEM_STATIC size_t ZSTD_buildCTable(void* dst, size_t dstCapacity, > FSE_CTable* CTable, U32 FSELog, symbolEncodingType_e type, > U32* count, U32 max, > BYTE const* codeTable, size_t nbSeq, > S16 const* defaultNorm, U32 defaultNormLog, U32 defaultMax, > void* workspace, size_t workspaceSize) >{ > BYTE* op = (BYTE*)dst; > BYTE const* const oend = op + dstCapacity; > > switch (type) { > case set_rle: > *op = codeTable[0]; > CHECK_F(FSE_buildCTable_rle(CTable, (BYTE)max)); > return 1; > case set_repeat: > return 0; > case set_basic: > CHECK_F(FSE_buildCTable_wksp(CTable, defaultNorm, defaultMax, defaultNormLog, workspace, workspaceSize)); > return 0; > case set_compressed: { > S16 norm[MaxSeq + 1]; > size_t nbSeq_1 = nbSeq; > const U32 tableLog = FSE_optimalTableLog(FSELog, nbSeq, max); > if (count[codeTable[nbSeq-1]] > 1) { > count[codeTable[nbSeq-1]]--; > nbSeq_1--; > } > assert(nbSeq_1 > 1); > CHECK_F(FSE_normalizeCount(norm, tableLog, count, nbSeq_1, max)); > { size_t const NCountSize = FSE_writeNCount(op, oend - op, norm, max, tableLog); /* overflow protected */ > if (FSE_isError(NCountSize)) return NCountSize; > CHECK_F(FSE_buildCTable_wksp(CTable, norm, max, tableLog, workspace, workspaceSize)); > return NCountSize; > } > } > default: return assert(0), ERROR(GENERIC); > } >} > >MEM_STATIC size_t ZSTD_encodeSequences(void* dst, size_t dstCapacity, > FSE_CTable const* CTable_MatchLength, BYTE const* mlCodeTable, > FSE_CTable const* CTable_OffsetBits, BYTE const* ofCodeTable, > FSE_CTable const* CTable_LitLength, BYTE const* llCodeTable, > seqDef const* sequences, size_t nbSeq, int longOffsets) >{ > BIT_CStream_t blockStream; > FSE_CState_t stateMatchLength; > FSE_CState_t stateOffsetBits; > FSE_CState_t stateLitLength; > > CHECK_E(BIT_initCStream(&blockStream, dst, dstCapacity), dstSize_tooSmall); /* not enough space remaining */ > > /* first symbols */ > FSE_initCState2(&stateMatchLength, CTable_MatchLength, mlCodeTable[nbSeq-1]); > FSE_initCState2(&stateOffsetBits, CTable_OffsetBits, ofCodeTable[nbSeq-1]); > FSE_initCState2(&stateLitLength, CTable_LitLength, llCodeTable[nbSeq-1]); > BIT_addBits(&blockStream, sequences[nbSeq-1].litLength, LL_bits[llCodeTable[nbSeq-1]]); > if (MEM_32bits()) BIT_flushBits(&blockStream); > BIT_addBits(&blockStream, sequences[nbSeq-1].matchLength, ML_bits[mlCodeTable[nbSeq-1]]); > if (MEM_32bits()) BIT_flushBits(&blockStream); > if (longOffsets) { > U32 const ofBits = ofCodeTable[nbSeq-1]; > int const extraBits = ofBits - MIN(ofBits, STREAM_ACCUMULATOR_MIN-1); > if (extraBits) { > BIT_addBits(&blockStream, sequences[nbSeq-1].offset, extraBits); > BIT_flushBits(&blockStream); > } > BIT_addBits(&blockStream, sequences[nbSeq-1].offset >> extraBits, > ofBits - extraBits); > } else { > BIT_addBits(&blockStream, sequences[nbSeq-1].offset, ofCodeTable[nbSeq-1]); > } > BIT_flushBits(&blockStream); > > { size_t n; > for (n=nbSeq-2 ; n<nbSeq ; n--) { /* intentional underflow */ > BYTE const llCode = llCodeTable[n]; > BYTE const ofCode = ofCodeTable[n]; > BYTE const mlCode = mlCodeTable[n]; > U32 const llBits = LL_bits[llCode]; > U32 const ofBits = ofCode; /* 32b*/ /* 64b*/ > U32 const mlBits = ML_bits[mlCode]; > /* (7)*/ /* (7)*/ > FSE_encodeSymbol(&blockStream, &stateOffsetBits, ofCode); /* 15 */ /* 15 */ > FSE_encodeSymbol(&blockStream, &stateMatchLength, mlCode); /* 24 */ /* 24 */ > if (MEM_32bits()) BIT_flushBits(&blockStream); /* (7)*/ > FSE_encodeSymbol(&blockStream, &stateLitLength, llCode); /* 16 */ /* 33 */ > if (MEM_32bits() || (ofBits+mlBits+llBits >= 64-7-(LLFSELog+MLFSELog+OffFSELog))) > BIT_flushBits(&blockStream); /* (7)*/ > BIT_addBits(&blockStream, sequences[n].litLength, llBits); > if (MEM_32bits() && ((llBits+mlBits)>24)) BIT_flushBits(&blockStream); > BIT_addBits(&blockStream, sequences[n].matchLength, mlBits); > if (MEM_32bits() || (ofBits+mlBits+llBits > 56)) BIT_flushBits(&blockStream); > if (longOffsets) { > int const extraBits = ofBits - MIN(ofBits, STREAM_ACCUMULATOR_MIN-1); > if (extraBits) { > BIT_addBits(&blockStream, sequences[n].offset, extraBits); > BIT_flushBits(&blockStream); /* (7)*/ > } > BIT_addBits(&blockStream, sequences[n].offset >> extraBits, > ofBits - extraBits); /* 31 */ > } else { > BIT_addBits(&blockStream, sequences[n].offset, ofBits); /* 31 */ > } > BIT_flushBits(&blockStream); /* (7)*/ > } } > > FSE_flushCState(&blockStream, &stateMatchLength); > FSE_flushCState(&blockStream, &stateOffsetBits); > FSE_flushCState(&blockStream, &stateLitLength); > > { size_t const streamSize = BIT_closeCStream(&blockStream); > if (streamSize==0) return ERROR(dstSize_tooSmall); /* not enough space */ > return streamSize; > } >} > >MEM_STATIC size_t ZSTD_compressSequences_internal(seqStore_t* seqStorePtr, > ZSTD_entropyCTables_t* entropy, > ZSTD_compressionParameters const* cParams, > void* dst, size_t dstCapacity) >{ > const int longOffsets = cParams->windowLog > STREAM_ACCUMULATOR_MIN; > U32 count[MaxSeq+1]; > FSE_CTable* CTable_LitLength = entropy->litlengthCTable; > FSE_CTable* CTable_OffsetBits = entropy->offcodeCTable; > FSE_CTable* CTable_MatchLength = entropy->matchlengthCTable; > U32 LLtype, Offtype, MLtype; /* compressed, raw or rle */ > const seqDef* const sequences = seqStorePtr->sequencesStart; > const BYTE* const ofCodeTable = seqStorePtr->ofCode; > const BYTE* const llCodeTable = seqStorePtr->llCode; > const BYTE* const mlCodeTable = seqStorePtr->mlCode; > BYTE* const ostart = (BYTE*)dst; > BYTE* const oend = ostart + dstCapacity; > BYTE* op = ostart; > size_t const nbSeq = seqStorePtr->sequences - seqStorePtr->sequencesStart; > BYTE* seqHead; > > ZSTD_STATIC_ASSERT(sizeof(entropy->workspace) >= (1<<MAX(MLFSELog,LLFSELog))); > > /* Compress literals */ > { const BYTE* const literals = seqStorePtr->litStart; > size_t const litSize = seqStorePtr->lit - literals; > size_t const cSize = ZSTD_compressLiterals( > entropy, cParams->strategy, op, dstCapacity, literals, litSize); > if (ZSTD_isError(cSize)) > return cSize; > op += cSize; > } > > /* Sequences Header */ > if ((oend-op) < 3 /*max nbSeq Size*/ + 1 /*seqHead */) return ERROR(dstSize_tooSmall); > if (nbSeq < 0x7F) *op++ = (BYTE)nbSeq; > else if (nbSeq < LONGNBSEQ) op[0] = (BYTE)((nbSeq>>8) + 0x80), op[1] = (BYTE)nbSeq, op+=2; > else op[0]=0xFF, MEM_writeLE16(op+1, (U16)(nbSeq - LONGNBSEQ)), op+=3; > if (nbSeq==0) return op - ostart; > > /* seqHead : flags for FSE encoding type */ > seqHead = op++; > > /* convert length/distances into codes */ > ZSTD_seqToCodes(seqStorePtr); > /* CTable for Literal Lengths */ > { U32 max = MaxLL; > size_t const mostFrequent = FSE_countFast_wksp(count, &max, llCodeTable, nbSeq, entropy->workspace); > LLtype = ZSTD_selectEncodingType(&entropy->litlength_repeatMode, mostFrequent, nbSeq, LL_defaultNormLog, ZSTD_defaultAllowed); > { size_t const countSize = ZSTD_buildCTable(op, oend - op, CTable_LitLength, LLFSELog, (symbolEncodingType_e)LLtype, > count, max, llCodeTable, nbSeq, LL_defaultNorm, LL_defaultNormLog, MaxLL, > entropy->workspace, sizeof(entropy->workspace)); > if (ZSTD_isError(countSize)) return countSize; > op += countSize; > } } > /* CTable for Offsets */ > { U32 max = MaxOff; > size_t const mostFrequent = FSE_countFast_wksp(count, &max, ofCodeTable, nbSeq, entropy->workspace); > /* We can only use the basic table if max <= DefaultMaxOff, otherwise the offsets are too large */ > ZSTD_defaultPolicy_e const defaultPolicy = max <= DefaultMaxOff ? ZSTD_defaultAllowed : ZSTD_defaultDisallowed; > Offtype = ZSTD_selectEncodingType(&entropy->offcode_repeatMode, mostFrequent, nbSeq, OF_defaultNormLog, defaultPolicy); > { size_t const countSize = ZSTD_buildCTable(op, oend - op, CTable_OffsetBits, OffFSELog, (symbolEncodingType_e)Offtype, > count, max, ofCodeTable, nbSeq, OF_defaultNorm, OF_defaultNormLog, DefaultMaxOff, > entropy->workspace, sizeof(entropy->workspace)); > if (ZSTD_isError(countSize)) return countSize; > op += countSize; > } } > /* CTable for MatchLengths */ > { U32 max = MaxML; > size_t const mostFrequent = FSE_countFast_wksp(count, &max, mlCodeTable, nbSeq, entropy->workspace); > MLtype = ZSTD_selectEncodingType(&entropy->matchlength_repeatMode, mostFrequent, nbSeq, ML_defaultNormLog, ZSTD_defaultAllowed); > { size_t const countSize = ZSTD_buildCTable(op, oend - op, CTable_MatchLength, MLFSELog, (symbolEncodingType_e)MLtype, > count, max, mlCodeTable, nbSeq, ML_defaultNorm, ML_defaultNormLog, MaxML, > entropy->workspace, sizeof(entropy->workspace)); > if (ZSTD_isError(countSize)) return countSize; > op += countSize; > } } > > *seqHead = (BYTE)((LLtype<<6) + (Offtype<<4) + (MLtype<<2)); > > { size_t const streamSize = ZSTD_encodeSequences(op, oend - op, > CTable_MatchLength, mlCodeTable, > CTable_OffsetBits, ofCodeTable, > CTable_LitLength, llCodeTable, > sequences, nbSeq, longOffsets); > if (ZSTD_isError(streamSize)) return streamSize; > op += streamSize; > } > > return op - ostart; >} > >MEM_STATIC size_t ZSTD_compressSequences(seqStore_t* seqStorePtr, > ZSTD_entropyCTables_t* entropy, > ZSTD_compressionParameters const* cParams, > void* dst, size_t dstCapacity, > size_t srcSize) >{ > size_t const cSize = ZSTD_compressSequences_internal(seqStorePtr, entropy, cParams, > dst, dstCapacity); > size_t const minGain = ZSTD_minGain(srcSize); > size_t const maxCSize = srcSize - minGain; > /* If the srcSize <= dstCapacity, then there is enough space to write a > * raw uncompressed block. Since we ran out of space, the block must not > * be compressible, so fall back to a raw uncompressed block. > */ > int const uncompressibleError = cSize == ERROR(dstSize_tooSmall) && srcSize <= dstCapacity; > > if (ZSTD_isError(cSize) && !uncompressibleError) > return cSize; > /* Check compressibility */ > if (cSize >= maxCSize || uncompressibleError) { > entropy->hufCTable_repeatMode = HUF_repeat_none; > entropy->offcode_repeatMode = FSE_repeat_none; > entropy->matchlength_repeatMode = FSE_repeat_none; > entropy->litlength_repeatMode = FSE_repeat_none; > return 0; > } > assert(!ZSTD_isError(cSize)); > > /* confirm repcodes */ > { int i; for (i=0; i<ZSTD_REP_NUM; i++) seqStorePtr->rep[i] = seqStorePtr->repToConfirm[i]; } > return cSize; >} > >/* ZSTD_selectBlockCompressor() : > * Not static, but internal use only (used by long distance matcher) > * assumption : strat is a valid strategy */ >typedef size_t (*ZSTD_blockCompressor) (ZSTD_CCtx* ctx, const void* src, size_t srcSize); >ZSTD_blockCompressor ZSTD_selectBlockCompressor(ZSTD_strategy strat, int extDict) >{ > static const ZSTD_blockCompressor blockCompressor[2][(unsigned)ZSTD_btultra+1] = { > { ZSTD_compressBlock_fast /* default for 0 */, > ZSTD_compressBlock_fast, ZSTD_compressBlock_doubleFast, ZSTD_compressBlock_greedy, > ZSTD_compressBlock_lazy, ZSTD_compressBlock_lazy2, ZSTD_compressBlock_btlazy2, > ZSTD_compressBlock_btopt, ZSTD_compressBlock_btultra }, > { ZSTD_compressBlock_fast_extDict /* default for 0 */, > ZSTD_compressBlock_fast_extDict, ZSTD_compressBlock_doubleFast_extDict, ZSTD_compressBlock_greedy_extDict, > ZSTD_compressBlock_lazy_extDict,ZSTD_compressBlock_lazy2_extDict, ZSTD_compressBlock_btlazy2_extDict, > ZSTD_compressBlock_btopt_extDict, ZSTD_compressBlock_btultra_extDict } > }; > ZSTD_STATIC_ASSERT((unsigned)ZSTD_fast == 1); > assert((U32)strat >= (U32)ZSTD_fast); > assert((U32)strat <= (U32)ZSTD_btultra); > > return blockCompressor[extDict!=0][(U32)strat]; >} > >static void ZSTD_storeLastLiterals(seqStore_t* seqStorePtr, > const BYTE* anchor, size_t lastLLSize) >{ > memcpy(seqStorePtr->lit, anchor, lastLLSize); > seqStorePtr->lit += lastLLSize; >} > >static size_t ZSTD_compressBlock_internal(ZSTD_CCtx* zc, void* dst, size_t dstCapacity, const void* src, size_t srcSize) >{ > const BYTE* const base = zc->base; > const BYTE* const istart = (const BYTE*)src; > const U32 current = (U32)(istart-base); > size_t lastLLSize; > const BYTE* anchor; > U32 const extDict = zc->lowLimit < zc->dictLimit; > const ZSTD_blockCompressor blockCompressor = > zc->appliedParams.ldmParams.enableLdm > ? (extDict ? ZSTD_compressBlock_ldm_extDict : ZSTD_compressBlock_ldm) > : ZSTD_selectBlockCompressor(zc->appliedParams.cParams.strategy, extDict); > > if (srcSize < MIN_CBLOCK_SIZE+ZSTD_blockHeaderSize+1) return 0; /* don't even attempt compression below a certain srcSize */ > ZSTD_resetSeqStore(&(zc->seqStore)); > if (current > zc->nextToUpdate + 384) > zc->nextToUpdate = current - MIN(192, (U32)(current - zc->nextToUpdate - 384)); /* limited update after finding a very long match */ > > lastLLSize = blockCompressor(zc, src, srcSize); > > /* Last literals */ > anchor = (const BYTE*)src + srcSize - lastLLSize; > ZSTD_storeLastLiterals(&zc->seqStore, anchor, lastLLSize); > > return ZSTD_compressSequences(&zc->seqStore, zc->entropy, &zc->appliedParams.cParams, dst, dstCapacity, srcSize); >} > > >/*! ZSTD_compress_frameChunk() : >* Compress a chunk of data into one or multiple blocks. >* All blocks will be terminated, all input will be consumed. >* Function will issue an error if there is not enough `dstCapacity` to hold the compressed content. >* Frame is supposed already started (header already produced) >* @return : compressed size, or an error code >*/ >static size_t ZSTD_compress_frameChunk (ZSTD_CCtx* cctx, > void* dst, size_t dstCapacity, > const void* src, size_t srcSize, > U32 lastFrameChunk) >{ > size_t blockSize = cctx->blockSize; > size_t remaining = srcSize; > const BYTE* ip = (const BYTE*)src; > BYTE* const ostart = (BYTE*)dst; > BYTE* op = ostart; > U32 const maxDist = (U32)1 << cctx->appliedParams.cParams.windowLog; > > if (cctx->appliedParams.fParams.checksumFlag && srcSize) > XXH64_update(&cctx->xxhState, src, srcSize); > > while (remaining) { > U32 const lastBlock = lastFrameChunk & (blockSize >= remaining); > size_t cSize; > > if (dstCapacity < ZSTD_blockHeaderSize + MIN_CBLOCK_SIZE) > return ERROR(dstSize_tooSmall); /* not enough space to store compressed block */ > if (remaining < blockSize) blockSize = remaining; > > /* preemptive overflow correction: > * 1. correction is large enough: > * lowLimit > (3<<29) ==> current > 3<<29 + 1<<windowLog - blockSize > * 1<<windowLog <= newCurrent < 1<<chainLog + 1<<windowLog > * > * current - newCurrent > * > (3<<29 + 1<<windowLog - blockSize) - (1<<windowLog + 1<<chainLog) > * > (3<<29 - blockSize) - (1<<chainLog) > * > (3<<29 - blockSize) - (1<<30) (NOTE: chainLog <= 30) > * > 1<<29 - 1<<17 > * > * 2. (ip+blockSize - cctx->base) doesn't overflow: > * In 32 bit mode we limit windowLog to 30 so we don't get > * differences larger than 1<<31-1. > * 3. cctx->lowLimit < 1<<32: > * windowLog <= 31 ==> 3<<29 + 1<<windowLog < 7<<29 < 1<<32. > */ > if (cctx->lowLimit > (3U<<29)) { > U32 const cycleMask = ((U32)1 << ZSTD_cycleLog(cctx->appliedParams.cParams.chainLog, cctx->appliedParams.cParams.strategy)) - 1; > U32 const current = (U32)(ip - cctx->base); > U32 const newCurrent = (current & cycleMask) + ((U32)1 << cctx->appliedParams.cParams.windowLog); > U32 const correction = current - newCurrent; > ZSTD_STATIC_ASSERT(ZSTD_CHAINLOG_MAX <= 30); > ZSTD_STATIC_ASSERT(ZSTD_WINDOWLOG_MAX_32 <= 30); > ZSTD_STATIC_ASSERT(ZSTD_WINDOWLOG_MAX <= 31); > assert(current > newCurrent); > assert(correction > 1<<28); /* Loose bound, should be about 1<<29 */ > ZSTD_reduceIndex(cctx, correction); > cctx->base += correction; > cctx->dictBase += correction; > cctx->lowLimit -= correction; > cctx->dictLimit -= correction; > if (cctx->nextToUpdate < correction) cctx->nextToUpdate = 0; > else cctx->nextToUpdate -= correction; > DEBUGLOG(4, "Correction of 0x%x bytes to lowLimit=0x%x\n", correction, cctx->lowLimit); > } > > if ((U32)(ip+blockSize - cctx->base) > cctx->loadedDictEnd + maxDist) { > /* enforce maxDist */ > U32 const newLowLimit = (U32)(ip+blockSize - cctx->base) - maxDist; > if (cctx->lowLimit < newLowLimit) cctx->lowLimit = newLowLimit; > if (cctx->dictLimit < cctx->lowLimit) cctx->dictLimit = cctx->lowLimit; > } > > cSize = ZSTD_compressBlock_internal(cctx, op+ZSTD_blockHeaderSize, dstCapacity-ZSTD_blockHeaderSize, ip, blockSize); > if (ZSTD_isError(cSize)) return cSize; > > if (cSize == 0) { /* block is not compressible */ > U32 const cBlockHeader24 = lastBlock + (((U32)bt_raw)<<1) + (U32)(blockSize << 3); > if (blockSize + ZSTD_blockHeaderSize > dstCapacity) return ERROR(dstSize_tooSmall); > MEM_writeLE32(op, cBlockHeader24); /* no pb, 4th byte will be overwritten */ > memcpy(op + ZSTD_blockHeaderSize, ip, blockSize); > cSize = ZSTD_blockHeaderSize+blockSize; > } else { > U32 const cBlockHeader24 = lastBlock + (((U32)bt_compressed)<<1) + (U32)(cSize << 3); > MEM_writeLE24(op, cBlockHeader24); > cSize += ZSTD_blockHeaderSize; > } > > remaining -= blockSize; > dstCapacity -= cSize; > ip += blockSize; > op += cSize; > } > > if (lastFrameChunk && (op>ostart)) cctx->stage = ZSTDcs_ending; > return op-ostart; >} > > >static size_t ZSTD_writeFrameHeader(void* dst, size_t dstCapacity, > ZSTD_CCtx_params params, U64 pledgedSrcSize, U32 dictID) >{ BYTE* const op = (BYTE*)dst; > U32 const dictIDSizeCodeLength = (dictID>0) + (dictID>=256) + (dictID>=65536); /* 0-3 */ > U32 const dictIDSizeCode = params.fParams.noDictIDFlag ? 0 : dictIDSizeCodeLength; /* 0-3 */ > U32 const checksumFlag = params.fParams.checksumFlag>0; > U32 const windowSize = (U32)1 << params.cParams.windowLog; > U32 const singleSegment = params.fParams.contentSizeFlag && (windowSize >= pledgedSrcSize); > BYTE const windowLogByte = (BYTE)((params.cParams.windowLog - ZSTD_WINDOWLOG_ABSOLUTEMIN) << 3); > U32 const fcsCode = params.fParams.contentSizeFlag ? > (pledgedSrcSize>=256) + (pledgedSrcSize>=65536+256) + (pledgedSrcSize>=0xFFFFFFFFU) : 0; /* 0-3 */ > BYTE const frameHeaderDecriptionByte = (BYTE)(dictIDSizeCode + (checksumFlag<<2) + (singleSegment<<5) + (fcsCode<<6) ); > size_t pos=0; > > if (dstCapacity < ZSTD_frameHeaderSize_max) return ERROR(dstSize_tooSmall); > DEBUGLOG(4, "ZSTD_writeFrameHeader : dictIDFlag : %u ; dictID : %u ; dictIDSizeCode : %u", > !params.fParams.noDictIDFlag, dictID, dictIDSizeCode); > > if (params.format == ZSTD_f_zstd1) { > DEBUGLOG(4, "writing zstd magic number"); > MEM_writeLE32(dst, ZSTD_MAGICNUMBER); > pos = 4; > } > op[pos++] = frameHeaderDecriptionByte; > if (!singleSegment) op[pos++] = windowLogByte; > switch(dictIDSizeCode) > { > default: assert(0); /* impossible */ > case 0 : break; > case 1 : op[pos] = (BYTE)(dictID); pos++; break; > case 2 : MEM_writeLE16(op+pos, (U16)dictID); pos+=2; break; > case 3 : MEM_writeLE32(op+pos, dictID); pos+=4; break; > } > switch(fcsCode) > { > default: assert(0); /* impossible */ > case 0 : if (singleSegment) op[pos++] = (BYTE)(pledgedSrcSize); break; > case 1 : MEM_writeLE16(op+pos, (U16)(pledgedSrcSize-256)); pos+=2; break; > case 2 : MEM_writeLE32(op+pos, (U32)(pledgedSrcSize)); pos+=4; break; > case 3 : MEM_writeLE64(op+pos, (U64)(pledgedSrcSize)); pos+=8; break; > } > return pos; >} > > >static size_t ZSTD_compressContinue_internal (ZSTD_CCtx* cctx, > void* dst, size_t dstCapacity, > const void* src, size_t srcSize, > U32 frame, U32 lastFrameChunk) >{ > const BYTE* const ip = (const BYTE*) src; > size_t fhSize = 0; > > DEBUGLOG(5, "ZSTD_compressContinue_internal"); > DEBUGLOG(5, "stage: %u", cctx->stage); > if (cctx->stage==ZSTDcs_created) return ERROR(stage_wrong); /* missing init (ZSTD_compressBegin) */ > > if (frame && (cctx->stage==ZSTDcs_init)) { > fhSize = ZSTD_writeFrameHeader(dst, dstCapacity, cctx->appliedParams, > cctx->pledgedSrcSizePlusOne-1, cctx->dictID); > if (ZSTD_isError(fhSize)) return fhSize; > dstCapacity -= fhSize; > dst = (char*)dst + fhSize; > cctx->stage = ZSTDcs_ongoing; > } > > /* Check if blocks follow each other */ > if (src != cctx->nextSrc) { > /* not contiguous */ > ptrdiff_t const delta = cctx->nextSrc - ip; > cctx->lowLimit = cctx->dictLimit; > cctx->dictLimit = (U32)(cctx->nextSrc - cctx->base); > cctx->dictBase = cctx->base; > cctx->base -= delta; > cctx->nextToUpdate = cctx->dictLimit; > if (cctx->dictLimit - cctx->lowLimit < HASH_READ_SIZE) cctx->lowLimit = cctx->dictLimit; /* too small extDict */ > } > > /* if input and dictionary overlap : reduce dictionary (area presumed modified by input) */ > if ((ip+srcSize > cctx->dictBase + cctx->lowLimit) & (ip < cctx->dictBase + cctx->dictLimit)) { > ptrdiff_t const highInputIdx = (ip + srcSize) - cctx->dictBase; > U32 const lowLimitMax = (highInputIdx > (ptrdiff_t)cctx->dictLimit) ? cctx->dictLimit : (U32)highInputIdx; > cctx->lowLimit = lowLimitMax; > } > > cctx->nextSrc = ip + srcSize; > > if (srcSize) { > size_t const cSize = frame ? > ZSTD_compress_frameChunk (cctx, dst, dstCapacity, src, srcSize, lastFrameChunk) : > ZSTD_compressBlock_internal (cctx, dst, dstCapacity, src, srcSize); > if (ZSTD_isError(cSize)) return cSize; > cctx->consumedSrcSize += srcSize; > return cSize + fhSize; > } else > return fhSize; >} > >size_t ZSTD_compressContinue (ZSTD_CCtx* cctx, > void* dst, size_t dstCapacity, > const void* src, size_t srcSize) >{ > return ZSTD_compressContinue_internal(cctx, dst, dstCapacity, src, srcSize, 1 /* frame mode */, 0 /* last chunk */); >} > > >size_t ZSTD_getBlockSize(const ZSTD_CCtx* cctx) >{ > ZSTD_compressionParameters const cParams = > ZSTD_getCParamsFromCCtxParams(cctx->appliedParams, 0, 0); > return MIN (ZSTD_BLOCKSIZE_MAX, (U32)1 << cParams.windowLog); >} > >size_t ZSTD_compressBlock(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize) >{ > size_t const blockSizeMax = ZSTD_getBlockSize(cctx); > if (srcSize > blockSizeMax) return ERROR(srcSize_wrong); > return ZSTD_compressContinue_internal(cctx, dst, dstCapacity, src, srcSize, 0 /* frame mode */, 0 /* last chunk */); >} > >/*! ZSTD_loadDictionaryContent() : > * @return : 0, or an error code > */ >static size_t ZSTD_loadDictionaryContent(ZSTD_CCtx* zc, const void* src, size_t srcSize) >{ > const BYTE* const ip = (const BYTE*) src; > const BYTE* const iend = ip + srcSize; > > /* input becomes current prefix */ > zc->lowLimit = zc->dictLimit; > zc->dictLimit = (U32)(zc->nextSrc - zc->base); > zc->dictBase = zc->base; > zc->base += ip - zc->nextSrc; > zc->nextToUpdate = zc->dictLimit; > zc->loadedDictEnd = zc->appliedParams.forceWindow ? 0 : (U32)(iend - zc->base); > > zc->nextSrc = iend; > if (srcSize <= HASH_READ_SIZE) return 0; > > switch(zc->appliedParams.cParams.strategy) > { > case ZSTD_fast: > ZSTD_fillHashTable (zc, iend, zc->appliedParams.cParams.searchLength); > break; > case ZSTD_dfast: > ZSTD_fillDoubleHashTable (zc, iend, zc->appliedParams.cParams.searchLength); > break; > > case ZSTD_greedy: > case ZSTD_lazy: > case ZSTD_lazy2: > if (srcSize >= HASH_READ_SIZE) > ZSTD_insertAndFindFirstIndex(zc, iend-HASH_READ_SIZE, zc->appliedParams.cParams.searchLength); > break; > > case ZSTD_btlazy2: > case ZSTD_btopt: > case ZSTD_btultra: > if (srcSize >= HASH_READ_SIZE) > ZSTD_updateTree(zc, iend-HASH_READ_SIZE, iend, (U32)1 << zc->appliedParams.cParams.searchLog, zc->appliedParams.cParams.searchLength); > break; > > default: > assert(0); /* not possible : not a valid strategy id */ > } > > zc->nextToUpdate = (U32)(iend - zc->base); > return 0; >} > > >/* Dictionaries that assign zero probability to symbols that show up causes problems > when FSE encoding. Refuse dictionaries that assign zero probability to symbols > that we may encounter during compression. > NOTE: This behavior is not standard and could be improved in the future. */ >static size_t ZSTD_checkDictNCount(short* normalizedCounter, unsigned dictMaxSymbolValue, unsigned maxSymbolValue) { > U32 s; > if (dictMaxSymbolValue < maxSymbolValue) return ERROR(dictionary_corrupted); > for (s = 0; s <= maxSymbolValue; ++s) { > if (normalizedCounter[s] == 0) return ERROR(dictionary_corrupted); > } > return 0; >} > > >/* Dictionary format : > * See : > * https://github.com/facebook/zstd/blob/master/doc/zstd_compression_format.md#dictionary-format > */ >/*! ZSTD_loadZstdDictionary() : > * @return : 0, or an error code > * assumptions : magic number supposed already checked > * dictSize supposed > 8 > */ >static size_t ZSTD_loadZstdDictionary(ZSTD_CCtx* cctx, const void* dict, size_t dictSize) >{ > const BYTE* dictPtr = (const BYTE*)dict; > const BYTE* const dictEnd = dictPtr + dictSize; > short offcodeNCount[MaxOff+1]; > unsigned offcodeMaxValue = MaxOff; > > ZSTD_STATIC_ASSERT(sizeof(cctx->entropy->workspace) >= (1<<MAX(MLFSELog,LLFSELog))); > > dictPtr += 4; /* skip magic number */ > cctx->dictID = cctx->appliedParams.fParams.noDictIDFlag ? 0 : MEM_readLE32(dictPtr); > dictPtr += 4; > > { unsigned maxSymbolValue = 255; > size_t const hufHeaderSize = HUF_readCTable((HUF_CElt*)cctx->entropy->hufCTable, &maxSymbolValue, dictPtr, dictEnd-dictPtr); > if (HUF_isError(hufHeaderSize)) return ERROR(dictionary_corrupted); > if (maxSymbolValue < 255) return ERROR(dictionary_corrupted); > dictPtr += hufHeaderSize; > } > > { unsigned offcodeLog; > size_t const offcodeHeaderSize = FSE_readNCount(offcodeNCount, &offcodeMaxValue, &offcodeLog, dictPtr, dictEnd-dictPtr); > if (FSE_isError(offcodeHeaderSize)) return ERROR(dictionary_corrupted); > if (offcodeLog > OffFSELog) return ERROR(dictionary_corrupted); > /* Defer checking offcodeMaxValue because we need to know the size of the dictionary content */ > CHECK_E( FSE_buildCTable_wksp(cctx->entropy->offcodeCTable, offcodeNCount, offcodeMaxValue, offcodeLog, cctx->entropy->workspace, sizeof(cctx->entropy->workspace)), > dictionary_corrupted); > dictPtr += offcodeHeaderSize; > } > > { short matchlengthNCount[MaxML+1]; > unsigned matchlengthMaxValue = MaxML, matchlengthLog; > size_t const matchlengthHeaderSize = FSE_readNCount(matchlengthNCount, &matchlengthMaxValue, &matchlengthLog, dictPtr, dictEnd-dictPtr); > if (FSE_isError(matchlengthHeaderSize)) return ERROR(dictionary_corrupted); > if (matchlengthLog > MLFSELog) return ERROR(dictionary_corrupted); > /* Every match length code must have non-zero probability */ > CHECK_F( ZSTD_checkDictNCount(matchlengthNCount, matchlengthMaxValue, MaxML)); > CHECK_E( FSE_buildCTable_wksp(cctx->entropy->matchlengthCTable, matchlengthNCount, matchlengthMaxValue, matchlengthLog, cctx->entropy->workspace, sizeof(cctx->entropy->workspace)), > dictionary_corrupted); > dictPtr += matchlengthHeaderSize; > } > > { short litlengthNCount[MaxLL+1]; > unsigned litlengthMaxValue = MaxLL, litlengthLog; > size_t const litlengthHeaderSize = FSE_readNCount(litlengthNCount, &litlengthMaxValue, &litlengthLog, dictPtr, dictEnd-dictPtr); > if (FSE_isError(litlengthHeaderSize)) return ERROR(dictionary_corrupted); > if (litlengthLog > LLFSELog) return ERROR(dictionary_corrupted); > /* Every literal length code must have non-zero probability */ > CHECK_F( ZSTD_checkDictNCount(litlengthNCount, litlengthMaxValue, MaxLL)); > CHECK_E( FSE_buildCTable_wksp(cctx->entropy->litlengthCTable, litlengthNCount, litlengthMaxValue, litlengthLog, cctx->entropy->workspace, sizeof(cctx->entropy->workspace)), > dictionary_corrupted); > dictPtr += litlengthHeaderSize; > } > > if (dictPtr+12 > dictEnd) return ERROR(dictionary_corrupted); > cctx->seqStore.rep[0] = MEM_readLE32(dictPtr+0); > cctx->seqStore.rep[1] = MEM_readLE32(dictPtr+4); > cctx->seqStore.rep[2] = MEM_readLE32(dictPtr+8); > dictPtr += 12; > > { size_t const dictContentSize = (size_t)(dictEnd - dictPtr); > U32 offcodeMax = MaxOff; > if (dictContentSize <= ((U32)-1) - 128 KB) { > U32 const maxOffset = (U32)dictContentSize + 128 KB; /* The maximum offset that must be supported */ > offcodeMax = ZSTD_highbit32(maxOffset); /* Calculate minimum offset code required to represent maxOffset */ > } > /* All offset values <= dictContentSize + 128 KB must be representable */ > CHECK_F (ZSTD_checkDictNCount(offcodeNCount, offcodeMaxValue, MIN(offcodeMax, MaxOff))); > /* All repCodes must be <= dictContentSize and != 0*/ > { U32 u; > for (u=0; u<3; u++) { > if (cctx->seqStore.rep[u] == 0) return ERROR(dictionary_corrupted); > if (cctx->seqStore.rep[u] > dictContentSize) return ERROR(dictionary_corrupted); > } } > > cctx->entropy->hufCTable_repeatMode = HUF_repeat_valid; > cctx->entropy->offcode_repeatMode = FSE_repeat_valid; > cctx->entropy->matchlength_repeatMode = FSE_repeat_valid; > cctx->entropy->litlength_repeatMode = FSE_repeat_valid; > return ZSTD_loadDictionaryContent(cctx, dictPtr, dictContentSize); > } >} > >/** ZSTD_compress_insertDictionary() : >* @return : 0, or an error code */ >static size_t ZSTD_compress_insertDictionary(ZSTD_CCtx* cctx, > const void* dict, size_t dictSize, > ZSTD_dictMode_e dictMode) >{ > DEBUGLOG(5, "ZSTD_compress_insertDictionary"); > if ((dict==NULL) || (dictSize<=8)) return 0; > > /* dict restricted modes */ > if (dictMode==ZSTD_dm_rawContent) > return ZSTD_loadDictionaryContent(cctx, dict, dictSize); > > if (MEM_readLE32(dict) != ZSTD_MAGIC_DICTIONARY) { > if (dictMode == ZSTD_dm_auto) { > DEBUGLOG(5, "raw content dictionary detected"); > return ZSTD_loadDictionaryContent(cctx, dict, dictSize); > } > if (dictMode == ZSTD_dm_fullDict) > return ERROR(dictionary_wrong); > assert(0); /* impossible */ > } > > /* dict as full zstd dictionary */ > return ZSTD_loadZstdDictionary(cctx, dict, dictSize); >} > >/*! ZSTD_compressBegin_internal() : > * @return : 0, or an error code */ >static size_t ZSTD_compressBegin_internal(ZSTD_CCtx* cctx, > const void* dict, size_t dictSize, > ZSTD_dictMode_e dictMode, > const ZSTD_CDict* cdict, > ZSTD_CCtx_params params, U64 pledgedSrcSize, > ZSTD_buffered_policy_e zbuff) >{ > DEBUGLOG(4, "ZSTD_compressBegin_internal"); > /* params are supposed to be fully validated at this point */ > assert(!ZSTD_isError(ZSTD_checkCParams(params.cParams))); > assert(!((dict) && (cdict))); /* either dict or cdict, not both */ > > if (cdict && cdict->dictContentSize>0) { > return ZSTD_copyCCtx_internal(cctx, cdict->refContext, > params.fParams, pledgedSrcSize, > zbuff); > } > > CHECK_F( ZSTD_resetCCtx_internal(cctx, params, pledgedSrcSize, > ZSTDcrp_continue, zbuff) ); > return ZSTD_compress_insertDictionary(cctx, dict, dictSize, dictMode); >} > >size_t ZSTD_compressBegin_advanced_internal( > ZSTD_CCtx* cctx, > const void* dict, size_t dictSize, > ZSTD_dictMode_e dictMode, > ZSTD_CCtx_params params, > unsigned long long pledgedSrcSize) >{ > /* compression parameters verification and optimization */ > CHECK_F( ZSTD_checkCParams(params.cParams) ); > return ZSTD_compressBegin_internal(cctx, dict, dictSize, dictMode, NULL, > params, pledgedSrcSize, > ZSTDb_not_buffered); >} > >/*! ZSTD_compressBegin_advanced() : >* @return : 0, or an error code */ >size_t ZSTD_compressBegin_advanced(ZSTD_CCtx* cctx, > const void* dict, size_t dictSize, > ZSTD_parameters params, unsigned long long pledgedSrcSize) >{ > ZSTD_CCtx_params const cctxParams = > ZSTD_assignParamsToCCtxParams(cctx->requestedParams, params); > return ZSTD_compressBegin_advanced_internal(cctx, dict, dictSize, ZSTD_dm_auto, > cctxParams, > pledgedSrcSize); >} > >size_t ZSTD_compressBegin_usingDict(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, int compressionLevel) >{ > ZSTD_parameters const params = ZSTD_getParams(compressionLevel, 0, dictSize); > ZSTD_CCtx_params const cctxParams = > ZSTD_assignParamsToCCtxParams(cctx->requestedParams, params); > return ZSTD_compressBegin_internal(cctx, dict, dictSize, ZSTD_dm_auto, NULL, > cctxParams, 0, ZSTDb_not_buffered); >} > >size_t ZSTD_compressBegin(ZSTD_CCtx* cctx, int compressionLevel) >{ > return ZSTD_compressBegin_usingDict(cctx, NULL, 0, compressionLevel); >} > > >/*! ZSTD_writeEpilogue() : >* Ends a frame. >* @return : nb of bytes written into dst (or an error code) */ >static size_t ZSTD_writeEpilogue(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity) >{ > BYTE* const ostart = (BYTE*)dst; > BYTE* op = ostart; > size_t fhSize = 0; > > DEBUGLOG(5, "ZSTD_writeEpilogue"); > if (cctx->stage == ZSTDcs_created) return ERROR(stage_wrong); /* init missing */ > > /* special case : empty frame */ > if (cctx->stage == ZSTDcs_init) { > fhSize = ZSTD_writeFrameHeader(dst, dstCapacity, cctx->appliedParams, 0, 0); > if (ZSTD_isError(fhSize)) return fhSize; > dstCapacity -= fhSize; > op += fhSize; > cctx->stage = ZSTDcs_ongoing; > } > > if (cctx->stage != ZSTDcs_ending) { > /* write one last empty block, make it the "last" block */ > U32 const cBlockHeader24 = 1 /* last block */ + (((U32)bt_raw)<<1) + 0; > if (dstCapacity<4) return ERROR(dstSize_tooSmall); > MEM_writeLE32(op, cBlockHeader24); > op += ZSTD_blockHeaderSize; > dstCapacity -= ZSTD_blockHeaderSize; > } > > if (cctx->appliedParams.fParams.checksumFlag) { > U32 const checksum = (U32) XXH64_digest(&cctx->xxhState); > if (dstCapacity<4) return ERROR(dstSize_tooSmall); > MEM_writeLE32(op, checksum); > op += 4; > } > > cctx->stage = ZSTDcs_created; /* return to "created but no init" status */ > return op-ostart; >} > > >size_t ZSTD_compressEnd (ZSTD_CCtx* cctx, > void* dst, size_t dstCapacity, > const void* src, size_t srcSize) >{ > size_t endResult; > size_t const cSize = ZSTD_compressContinue_internal(cctx, > dst, dstCapacity, src, srcSize, > 1 /* frame mode */, 1 /* last chunk */); > if (ZSTD_isError(cSize)) return cSize; > endResult = ZSTD_writeEpilogue(cctx, (char*)dst + cSize, dstCapacity-cSize); > if (ZSTD_isError(endResult)) return endResult; > if (cctx->appliedParams.fParams.contentSizeFlag) { /* control src size */ > DEBUGLOG(4, "end of frame : controlling src size"); > if (cctx->pledgedSrcSizePlusOne != cctx->consumedSrcSize+1) { > DEBUGLOG(4, "error : pledgedSrcSize = %u, while realSrcSize = %u", > (U32)cctx->pledgedSrcSizePlusOne-1, (U32)cctx->consumedSrcSize); > return ERROR(srcSize_wrong); > } } > return cSize + endResult; >} > > >static size_t ZSTD_compress_internal (ZSTD_CCtx* cctx, > void* dst, size_t dstCapacity, > const void* src, size_t srcSize, > const void* dict,size_t dictSize, > ZSTD_parameters params) >{ > ZSTD_CCtx_params const cctxParams = > ZSTD_assignParamsToCCtxParams(cctx->requestedParams, params); > return ZSTD_compress_advanced_internal(cctx, > dst, dstCapacity, > src, srcSize, > dict, dictSize, > cctxParams); >} > >size_t ZSTD_compress_advanced (ZSTD_CCtx* ctx, > void* dst, size_t dstCapacity, > const void* src, size_t srcSize, > const void* dict,size_t dictSize, > ZSTD_parameters params) >{ > CHECK_F(ZSTD_checkCParams(params.cParams)); > return ZSTD_compress_internal(ctx, dst, dstCapacity, src, srcSize, dict, dictSize, params); >} > >/* Internal */ >size_t ZSTD_compress_advanced_internal( > ZSTD_CCtx* cctx, > void* dst, size_t dstCapacity, > const void* src, size_t srcSize, > const void* dict,size_t dictSize, > ZSTD_CCtx_params params) >{ > CHECK_F( ZSTD_compressBegin_internal(cctx, dict, dictSize, ZSTD_dm_auto, NULL, > params, srcSize, ZSTDb_not_buffered) ); > return ZSTD_compressEnd(cctx, dst, dstCapacity, src, srcSize); >} > >size_t ZSTD_compress_usingDict(ZSTD_CCtx* ctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize, > const void* dict, size_t dictSize, int compressionLevel) >{ > ZSTD_parameters params = ZSTD_getParams(compressionLevel, srcSize, dict ? dictSize : 0); > params.fParams.contentSizeFlag = 1; > return ZSTD_compress_internal(ctx, dst, dstCapacity, src, srcSize, dict, dictSize, params); >} > >size_t ZSTD_compressCCtx (ZSTD_CCtx* ctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize, int compressionLevel) >{ > return ZSTD_compress_usingDict(ctx, dst, dstCapacity, src, srcSize, NULL, 0, compressionLevel); >} > >size_t ZSTD_compress(void* dst, size_t dstCapacity, const void* src, size_t srcSize, int compressionLevel) >{ > size_t result; > ZSTD_CCtx ctxBody; > memset(&ctxBody, 0, sizeof(ctxBody)); > ctxBody.customMem = ZSTD_defaultCMem; > result = ZSTD_compressCCtx(&ctxBody, dst, dstCapacity, src, srcSize, compressionLevel); > ZSTD_free(ctxBody.workSpace, ZSTD_defaultCMem); /* can't free ctxBody itself, as it's on stack; free only heap content */ > return result; >} > > >/* ===== Dictionary API ===== */ > >/*! ZSTD_estimateCDictSize_advanced() : > * Estimate amount of memory that will be needed to create a dictionary with following arguments */ >size_t ZSTD_estimateCDictSize_advanced( > size_t dictSize, ZSTD_compressionParameters cParams, > ZSTD_dictLoadMethod_e dictLoadMethod) >{ > DEBUGLOG(5, "sizeof(ZSTD_CDict) : %u", (U32)sizeof(ZSTD_CDict)); > DEBUGLOG(5, "CCtx estimate : %u", > (U32)ZSTD_estimateCCtxSize_usingCParams(cParams)); > return sizeof(ZSTD_CDict) + ZSTD_estimateCCtxSize_usingCParams(cParams) > + (dictLoadMethod == ZSTD_dlm_byRef ? 0 : dictSize); >} > >size_t ZSTD_estimateCDictSize(size_t dictSize, int compressionLevel) >{ > ZSTD_compressionParameters const cParams = ZSTD_getCParams(compressionLevel, 0, dictSize); > return ZSTD_estimateCDictSize_advanced(dictSize, cParams, ZSTD_dlm_byCopy); >} > >size_t ZSTD_sizeof_CDict(const ZSTD_CDict* cdict) >{ > if (cdict==NULL) return 0; /* support sizeof on NULL */ > DEBUGLOG(5, "sizeof(*cdict) : %u", (U32)sizeof(*cdict)); > DEBUGLOG(5, "ZSTD_sizeof_CCtx : %u", (U32)ZSTD_sizeof_CCtx(cdict->refContext)); > return ZSTD_sizeof_CCtx(cdict->refContext) + (cdict->dictBuffer ? cdict->dictContentSize : 0) + sizeof(*cdict); >} > >static size_t ZSTD_initCDict_internal( > ZSTD_CDict* cdict, > const void* dictBuffer, size_t dictSize, > ZSTD_dictLoadMethod_e dictLoadMethod, > ZSTD_dictMode_e dictMode, > ZSTD_compressionParameters cParams) >{ > DEBUGLOG(5, "ZSTD_initCDict_internal, mode %u", (U32)dictMode); > if ((dictLoadMethod == ZSTD_dlm_byRef) || (!dictBuffer) || (!dictSize)) { > cdict->dictBuffer = NULL; > cdict->dictContent = dictBuffer; > } else { > void* const internalBuffer = ZSTD_malloc(dictSize, cdict->refContext->customMem); > cdict->dictBuffer = internalBuffer; > cdict->dictContent = internalBuffer; > if (!internalBuffer) return ERROR(memory_allocation); > memcpy(internalBuffer, dictBuffer, dictSize); > } > cdict->dictContentSize = dictSize; > > { ZSTD_CCtx_params cctxParams = cdict->refContext->requestedParams; > cctxParams.cParams = cParams; > CHECK_F( ZSTD_compressBegin_internal(cdict->refContext, > cdict->dictContent, dictSize, dictMode, > NULL, > cctxParams, ZSTD_CONTENTSIZE_UNKNOWN, > ZSTDb_not_buffered) ); > } > > return 0; >} > >ZSTD_CDict* ZSTD_createCDict_advanced(const void* dictBuffer, size_t dictSize, > ZSTD_dictLoadMethod_e dictLoadMethod, > ZSTD_dictMode_e dictMode, > ZSTD_compressionParameters cParams, ZSTD_customMem customMem) >{ > DEBUGLOG(5, "ZSTD_createCDict_advanced, mode %u", (U32)dictMode); > if (!customMem.customAlloc ^ !customMem.customFree) return NULL; > > { ZSTD_CDict* const cdict = (ZSTD_CDict*)ZSTD_malloc(sizeof(ZSTD_CDict), customMem); > ZSTD_CCtx* const cctx = ZSTD_createCCtx_advanced(customMem); > > if (!cdict || !cctx) { > ZSTD_free(cdict, customMem); > ZSTD_freeCCtx(cctx); > return NULL; > } > cdict->refContext = cctx; > if (ZSTD_isError( ZSTD_initCDict_internal(cdict, > dictBuffer, dictSize, > dictLoadMethod, dictMode, > cParams) )) { > ZSTD_freeCDict(cdict); > return NULL; > } > > return cdict; > } >} > >ZSTD_CDict* ZSTD_createCDict(const void* dict, size_t dictSize, int compressionLevel) >{ > ZSTD_compressionParameters cParams = ZSTD_getCParams(compressionLevel, 0, dictSize); > return ZSTD_createCDict_advanced(dict, dictSize, > ZSTD_dlm_byCopy, ZSTD_dm_auto, > cParams, ZSTD_defaultCMem); >} > >ZSTD_CDict* ZSTD_createCDict_byReference(const void* dict, size_t dictSize, int compressionLevel) >{ > ZSTD_compressionParameters cParams = ZSTD_getCParams(compressionLevel, 0, dictSize); > return ZSTD_createCDict_advanced(dict, dictSize, > ZSTD_dlm_byRef, ZSTD_dm_auto, > cParams, ZSTD_defaultCMem); >} > >size_t ZSTD_freeCDict(ZSTD_CDict* cdict) >{ > if (cdict==NULL) return 0; /* support free on NULL */ > { ZSTD_customMem const cMem = cdict->refContext->customMem; > ZSTD_freeCCtx(cdict->refContext); > ZSTD_free(cdict->dictBuffer, cMem); > ZSTD_free(cdict, cMem); > return 0; > } >} > >/*! ZSTD_initStaticCDict_advanced() : > * Generate a digested dictionary in provided memory area. > * workspace: The memory area to emplace the dictionary into. > * Provided pointer must 8-bytes aligned. > * It must outlive dictionary usage. > * workspaceSize: Use ZSTD_estimateCDictSize() > * to determine how large workspace must be. > * cParams : use ZSTD_getCParams() to transform a compression level > * into its relevants cParams. > * @return : pointer to ZSTD_CDict*, or NULL if error (size too small) > * Note : there is no corresponding "free" function. > * Since workspace was allocated externally, it must be freed externally. > */ >ZSTD_CDict* ZSTD_initStaticCDict(void* workspace, size_t workspaceSize, > const void* dict, size_t dictSize, > ZSTD_dictLoadMethod_e dictLoadMethod, > ZSTD_dictMode_e dictMode, > ZSTD_compressionParameters cParams) >{ > size_t const cctxSize = ZSTD_estimateCCtxSize_usingCParams(cParams); > size_t const neededSize = sizeof(ZSTD_CDict) + (dictLoadMethod == ZSTD_dlm_byRef ? 0 : dictSize) > + cctxSize; > ZSTD_CDict* const cdict = (ZSTD_CDict*) workspace; > void* ptr; > DEBUGLOG(5, "(size_t)workspace & 7 : %u", (U32)(size_t)workspace & 7); > if ((size_t)workspace & 7) return NULL; /* 8-aligned */ > DEBUGLOG(5, "(workspaceSize < neededSize) : (%u < %u) => %u", > (U32)workspaceSize, (U32)neededSize, (U32)(workspaceSize < neededSize)); > if (workspaceSize < neededSize) return NULL; > > if (dictLoadMethod == ZSTD_dlm_byCopy) { > memcpy(cdict+1, dict, dictSize); > dict = cdict+1; > ptr = (char*)workspace + sizeof(ZSTD_CDict) + dictSize; > } else { > ptr = cdict+1; > } > cdict->refContext = ZSTD_initStaticCCtx(ptr, cctxSize); > > if (ZSTD_isError( ZSTD_initCDict_internal(cdict, > dict, dictSize, > ZSTD_dlm_byRef, dictMode, > cParams) )) > return NULL; > > return cdict; >} > >ZSTD_compressionParameters ZSTD_getCParamsFromCDict(const ZSTD_CDict* cdict) { > return cdict->refContext->appliedParams.cParams; >} > >/* ZSTD_compressBegin_usingCDict_advanced() : > * cdict must be != NULL */ >size_t ZSTD_compressBegin_usingCDict_advanced( > ZSTD_CCtx* const cctx, const ZSTD_CDict* const cdict, > ZSTD_frameParameters const fParams, unsigned long long const pledgedSrcSize) >{ > if (cdict==NULL) return ERROR(dictionary_wrong); > { ZSTD_CCtx_params params = cctx->requestedParams; > params.cParams = ZSTD_getCParamsFromCDict(cdict); > params.fParams = fParams; > DEBUGLOG(5, "ZSTD_compressBegin_usingCDict_advanced"); > return ZSTD_compressBegin_internal(cctx, > NULL, 0, ZSTD_dm_auto, > cdict, > params, pledgedSrcSize, > ZSTDb_not_buffered); > } >} > >/* ZSTD_compressBegin_usingCDict() : > * pledgedSrcSize=0 means "unknown" > * if pledgedSrcSize>0, it will enable contentSizeFlag */ >size_t ZSTD_compressBegin_usingCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict) >{ > ZSTD_frameParameters const fParams = { 0 /*content*/, 0 /*checksum*/, 0 /*noDictID*/ }; > DEBUGLOG(5, "ZSTD_compressBegin_usingCDict : dictIDFlag == %u", !fParams.noDictIDFlag); > return ZSTD_compressBegin_usingCDict_advanced(cctx, cdict, fParams, 0); >} > >size_t ZSTD_compress_usingCDict_advanced(ZSTD_CCtx* cctx, > void* dst, size_t dstCapacity, > const void* src, size_t srcSize, > const ZSTD_CDict* cdict, ZSTD_frameParameters fParams) >{ > CHECK_F (ZSTD_compressBegin_usingCDict_advanced(cctx, cdict, fParams, srcSize)); /* will check if cdict != NULL */ > return ZSTD_compressEnd(cctx, dst, dstCapacity, src, srcSize); >} > >/*! ZSTD_compress_usingCDict() : > * Compression using a digested Dictionary. > * Faster startup than ZSTD_compress_usingDict(), recommended when same dictionary is used multiple times. > * Note that compression parameters are decided at CDict creation time > * while frame parameters are hardcoded */ >size_t ZSTD_compress_usingCDict(ZSTD_CCtx* cctx, > void* dst, size_t dstCapacity, > const void* src, size_t srcSize, > const ZSTD_CDict* cdict) >{ > ZSTD_frameParameters const fParams = { 1 /*content*/, 0 /*checksum*/, 0 /*noDictID*/ }; > return ZSTD_compress_usingCDict_advanced(cctx, dst, dstCapacity, src, srcSize, cdict, fParams); >} > > > >/* ****************************************************************** >* Streaming >********************************************************************/ > >ZSTD_CStream* ZSTD_createCStream(void) >{ > return ZSTD_createCStream_advanced(ZSTD_defaultCMem); >} > >ZSTD_CStream* ZSTD_initStaticCStream(void *workspace, size_t workspaceSize) >{ > return ZSTD_initStaticCCtx(workspace, workspaceSize); >} > >ZSTD_CStream* ZSTD_createCStream_advanced(ZSTD_customMem customMem) >{ /* CStream and CCtx are now same object */ > return ZSTD_createCCtx_advanced(customMem); >} > >size_t ZSTD_freeCStream(ZSTD_CStream* zcs) >{ > return ZSTD_freeCCtx(zcs); /* same object */ >} > > > >/*====== Initialization ======*/ > >size_t ZSTD_CStreamInSize(void) { return ZSTD_BLOCKSIZE_MAX; } > >size_t ZSTD_CStreamOutSize(void) >{ > return ZSTD_compressBound(ZSTD_BLOCKSIZE_MAX) + ZSTD_blockHeaderSize + 4 /* 32-bits hash */ ; >} > >static size_t ZSTD_resetCStream_internal(ZSTD_CStream* zcs, > const void* dict, size_t dictSize, ZSTD_dictMode_e dictMode, > const ZSTD_CDict* cdict, > const ZSTD_CCtx_params params, unsigned long long pledgedSrcSize) >{ > DEBUGLOG(4, "ZSTD_resetCStream_internal"); > /* params are supposed to be fully validated at this point */ > assert(!ZSTD_isError(ZSTD_checkCParams(params.cParams))); > assert(!((dict) && (cdict))); /* either dict or cdict, not both */ > > CHECK_F( ZSTD_compressBegin_internal(zcs, > dict, dictSize, dictMode, > cdict, > params, pledgedSrcSize, > ZSTDb_buffered) ); > > zcs->inToCompress = 0; > zcs->inBuffPos = 0; > zcs->inBuffTarget = zcs->blockSize; > zcs->outBuffContentSize = zcs->outBuffFlushedSize = 0; > zcs->streamStage = zcss_load; > zcs->frameEnded = 0; > return 0; /* ready to go */ >} > >size_t ZSTD_resetCStream(ZSTD_CStream* zcs, unsigned long long pledgedSrcSize) >{ > ZSTD_CCtx_params params = zcs->requestedParams; > params.fParams.contentSizeFlag = (pledgedSrcSize > 0); > params.cParams = ZSTD_getCParamsFromCCtxParams(params, pledgedSrcSize, 0); > DEBUGLOG(4, "ZSTD_resetCStream"); > return ZSTD_resetCStream_internal(zcs, NULL, 0, ZSTD_dm_auto, zcs->cdict, params, pledgedSrcSize); >} > >/*! ZSTD_initCStream_internal() : > * Note : not static, but hidden (not exposed). Used by zstdmt_compress.c > * Assumption 1 : params are valid > * Assumption 2 : either dict, or cdict, is defined, not both */ >size_t ZSTD_initCStream_internal(ZSTD_CStream* zcs, > const void* dict, size_t dictSize, const ZSTD_CDict* cdict, > ZSTD_CCtx_params params, unsigned long long pledgedSrcSize) >{ > DEBUGLOG(4, "ZSTD_initCStream_internal"); > assert(!ZSTD_isError(ZSTD_checkCParams(params.cParams))); > assert(!((dict) && (cdict))); /* either dict or cdict, not both */ > > if (dict && dictSize >= 8) { > DEBUGLOG(5, "loading dictionary of size %u", (U32)dictSize); > if (zcs->staticSize) { /* static CCtx : never uses malloc */ > /* incompatible with internal cdict creation */ > return ERROR(memory_allocation); > } > ZSTD_freeCDict(zcs->cdictLocal); > zcs->cdictLocal = ZSTD_createCDict_advanced(dict, dictSize, > ZSTD_dlm_byCopy, ZSTD_dm_auto, > params.cParams, zcs->customMem); > zcs->cdict = zcs->cdictLocal; > if (zcs->cdictLocal == NULL) return ERROR(memory_allocation); > } else { > if (cdict) { > params.cParams = ZSTD_getCParamsFromCDict(cdict); /* cParams are enforced from cdict */ > } > ZSTD_freeCDict(zcs->cdictLocal); > zcs->cdictLocal = NULL; > zcs->cdict = cdict; > } > > params.compressionLevel = ZSTD_CLEVEL_CUSTOM; > zcs->requestedParams = params; > > return ZSTD_resetCStream_internal(zcs, NULL, 0, ZSTD_dm_auto, zcs->cdict, params, pledgedSrcSize); >} > >/* ZSTD_initCStream_usingCDict_advanced() : > * same as ZSTD_initCStream_usingCDict(), with control over frame parameters */ >size_t ZSTD_initCStream_usingCDict_advanced(ZSTD_CStream* zcs, > const ZSTD_CDict* cdict, > ZSTD_frameParameters fParams, > unsigned long long pledgedSrcSize) >{ /* cannot handle NULL cdict (does not know what to do) */ > if (!cdict) return ERROR(dictionary_wrong); > { ZSTD_CCtx_params params = zcs->requestedParams; > params.cParams = ZSTD_getCParamsFromCDict(cdict); > params.fParams = fParams; > return ZSTD_initCStream_internal(zcs, > NULL, 0, cdict, > params, pledgedSrcSize); > } >} > >/* note : cdict must outlive compression session */ >size_t ZSTD_initCStream_usingCDict(ZSTD_CStream* zcs, const ZSTD_CDict* cdict) >{ > ZSTD_frameParameters const fParams = { 0 /* contentSize */, 0 /* checksum */, 0 /* hideDictID */ }; > return ZSTD_initCStream_usingCDict_advanced(zcs, cdict, fParams, 0); /* note : will check that cdict != NULL */ >} > >size_t ZSTD_initCStream_advanced(ZSTD_CStream* zcs, > const void* dict, size_t dictSize, > ZSTD_parameters params, unsigned long long pledgedSrcSize) >{ > ZSTD_CCtx_params const cctxParams = > ZSTD_assignParamsToCCtxParams(zcs->requestedParams, params); > CHECK_F( ZSTD_checkCParams(params.cParams) ); > return ZSTD_initCStream_internal(zcs, dict, dictSize, NULL, cctxParams, pledgedSrcSize); >} > >size_t ZSTD_initCStream_usingDict(ZSTD_CStream* zcs, const void* dict, size_t dictSize, int compressionLevel) >{ > ZSTD_parameters const params = ZSTD_getParams(compressionLevel, 0, dictSize); > ZSTD_CCtx_params const cctxParams = > ZSTD_assignParamsToCCtxParams(zcs->requestedParams, params); > return ZSTD_initCStream_internal(zcs, dict, dictSize, NULL, cctxParams, 0); >} > >size_t ZSTD_initCStream_srcSize(ZSTD_CStream* zcs, int compressionLevel, unsigned long long pledgedSrcSize) >{ > ZSTD_CCtx_params cctxParams; > ZSTD_parameters const params = ZSTD_getParams(compressionLevel, pledgedSrcSize, 0); > cctxParams = ZSTD_assignParamsToCCtxParams(zcs->requestedParams, params); > cctxParams.fParams.contentSizeFlag = (pledgedSrcSize>0); > return ZSTD_initCStream_internal(zcs, NULL, 0, NULL, cctxParams, pledgedSrcSize); >} > >size_t ZSTD_initCStream(ZSTD_CStream* zcs, int compressionLevel) >{ > return ZSTD_initCStream_srcSize(zcs, compressionLevel, 0); >} > >/*====== Compression ======*/ > >MEM_STATIC size_t ZSTD_limitCopy(void* dst, size_t dstCapacity, > const void* src, size_t srcSize) >{ > size_t const length = MIN(dstCapacity, srcSize); > if (length) memcpy(dst, src, length); > return length; >} > >/** ZSTD_compressStream_generic(): > * internal function for all *compressStream*() variants and *compress_generic() > * non-static, because can be called from zstdmt.c > * @return : hint size for next input */ >size_t ZSTD_compressStream_generic(ZSTD_CStream* zcs, > ZSTD_outBuffer* output, > ZSTD_inBuffer* input, > ZSTD_EndDirective const flushMode) >{ > const char* const istart = (const char*)input->src; > const char* const iend = istart + input->size; > const char* ip = istart + input->pos; > char* const ostart = (char*)output->dst; > char* const oend = ostart + output->size; > char* op = ostart + output->pos; > U32 someMoreWork = 1; > > /* check expectations */ > DEBUGLOG(5, "ZSTD_compressStream_generic, flush=%u", (U32)flushMode); > assert(zcs->inBuff != NULL); > assert(zcs->inBuffSize>0); > assert(zcs->outBuff!= NULL); > assert(zcs->outBuffSize>0); > assert(output->pos <= output->size); > assert(input->pos <= input->size); > > while (someMoreWork) { > switch(zcs->streamStage) > { > case zcss_init: > /* call ZSTD_initCStream() first ! */ > return ERROR(init_missing); > > case zcss_load: > if ( (flushMode == ZSTD_e_end) > && ((size_t)(oend-op) >= ZSTD_compressBound(iend-ip)) /* enough dstCapacity */ > && (zcs->inBuffPos == 0) ) { > /* shortcut to compression pass directly into output buffer */ > size_t const cSize = ZSTD_compressEnd(zcs, > op, oend-op, ip, iend-ip); > DEBUGLOG(4, "ZSTD_compressEnd : %u", (U32)cSize); > if (ZSTD_isError(cSize)) return cSize; > ip = iend; > op += cSize; > zcs->frameEnded = 1; > ZSTD_startNewCompression(zcs); > someMoreWork = 0; break; > } > /* complete loading into inBuffer */ > { size_t const toLoad = zcs->inBuffTarget - zcs->inBuffPos; > size_t const loaded = ZSTD_limitCopy( > zcs->inBuff + zcs->inBuffPos, toLoad, > ip, iend-ip); > zcs->inBuffPos += loaded; > ip += loaded; > if ( (flushMode == ZSTD_e_continue) > && (zcs->inBuffPos < zcs->inBuffTarget) ) { > /* not enough input to fill full block : stop here */ > someMoreWork = 0; break; > } > if ( (flushMode == ZSTD_e_flush) > && (zcs->inBuffPos == zcs->inToCompress) ) { > /* empty */ > someMoreWork = 0; break; > } > } > /* compress current block (note : this stage cannot be stopped in the middle) */ > DEBUGLOG(5, "stream compression stage (flushMode==%u)", flushMode); > { void* cDst; > size_t cSize; > size_t const iSize = zcs->inBuffPos - zcs->inToCompress; > size_t oSize = oend-op; > unsigned const lastBlock = (flushMode == ZSTD_e_end) && (ip==iend); > if (oSize >= ZSTD_compressBound(iSize)) > cDst = op; /* compress into output buffer, to skip flush stage */ > else > cDst = zcs->outBuff, oSize = zcs->outBuffSize; > cSize = lastBlock ? > ZSTD_compressEnd(zcs, cDst, oSize, > zcs->inBuff + zcs->inToCompress, iSize) : > ZSTD_compressContinue(zcs, cDst, oSize, > zcs->inBuff + zcs->inToCompress, iSize); > if (ZSTD_isError(cSize)) return cSize; > zcs->frameEnded = lastBlock; > /* prepare next block */ > zcs->inBuffTarget = zcs->inBuffPos + zcs->blockSize; > if (zcs->inBuffTarget > zcs->inBuffSize) > zcs->inBuffPos = 0, zcs->inBuffTarget = zcs->blockSize; > DEBUGLOG(5, "inBuffTarget:%u / inBuffSize:%u", > (U32)zcs->inBuffTarget, (U32)zcs->inBuffSize); > if (!lastBlock) > assert(zcs->inBuffTarget <= zcs->inBuffSize); > zcs->inToCompress = zcs->inBuffPos; > if (cDst == op) { /* no need to flush */ > op += cSize; > if (zcs->frameEnded) { > DEBUGLOG(5, "Frame completed directly in outBuffer"); > someMoreWork = 0; > ZSTD_startNewCompression(zcs); > } > break; > } > zcs->outBuffContentSize = cSize; > zcs->outBuffFlushedSize = 0; > zcs->streamStage = zcss_flush; /* pass-through to flush stage */ > } > /* fall-through */ > case zcss_flush: > DEBUGLOG(5, "flush stage"); > { size_t const toFlush = zcs->outBuffContentSize - zcs->outBuffFlushedSize; > size_t const flushed = ZSTD_limitCopy(op, oend-op, > zcs->outBuff + zcs->outBuffFlushedSize, toFlush); > DEBUGLOG(5, "toFlush: %u into %u ==> flushed: %u", > (U32)toFlush, (U32)(oend-op), (U32)flushed); > op += flushed; > zcs->outBuffFlushedSize += flushed; > if (toFlush!=flushed) { > /* flush not fully completed, presumably because dst is too small */ > assert(op==oend); > someMoreWork = 0; > break; > } > zcs->outBuffContentSize = zcs->outBuffFlushedSize = 0; > if (zcs->frameEnded) { > DEBUGLOG(5, "Frame completed on flush"); > someMoreWork = 0; > ZSTD_startNewCompression(zcs); > break; > } > zcs->streamStage = zcss_load; > break; > } > > default: /* impossible */ > assert(0); > } > } > > input->pos = ip - istart; > output->pos = op - ostart; > if (zcs->frameEnded) return 0; > { size_t hintInSize = zcs->inBuffTarget - zcs->inBuffPos; > if (hintInSize==0) hintInSize = zcs->blockSize; > return hintInSize; > } >} > >size_t ZSTD_compressStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output, ZSTD_inBuffer* input) >{ > /* check conditions */ > if (output->pos > output->size) return ERROR(GENERIC); > if (input->pos > input->size) return ERROR(GENERIC); > > return ZSTD_compressStream_generic(zcs, output, input, ZSTD_e_continue); >} > > >size_t ZSTD_compress_generic (ZSTD_CCtx* cctx, > ZSTD_outBuffer* output, > ZSTD_inBuffer* input, > ZSTD_EndDirective endOp) >{ > DEBUGLOG(5, "ZSTD_compress_generic"); > /* check conditions */ > if (output->pos > output->size) return ERROR(GENERIC); > if (input->pos > input->size) return ERROR(GENERIC); > assert(cctx!=NULL); > > /* transparent initialization stage */ > if (cctx->streamStage == zcss_init) { > ZSTD_prefixDict const prefixDict = cctx->prefixDict; > ZSTD_CCtx_params params = cctx->requestedParams; > params.cParams = ZSTD_getCParamsFromCCtxParams( > cctx->requestedParams, cctx->pledgedSrcSizePlusOne-1, 0 /*dictSize*/); > memset(&cctx->prefixDict, 0, sizeof(cctx->prefixDict)); /* single usage */ > assert(prefixDict.dict==NULL || cctx->cdict==NULL); /* only one can be set */ > DEBUGLOG(4, "ZSTD_compress_generic : transparent init stage"); > >#ifdef ZSTD_MULTITHREAD > if (params.nbThreads > 1) { > if (cctx->mtctx == NULL || cctx->appliedParams.nbThreads != params.nbThreads) { > ZSTDMT_freeCCtx(cctx->mtctx); > cctx->mtctx = ZSTDMT_createCCtx_advanced(params.nbThreads, cctx->customMem); > if (cctx->mtctx == NULL) return ERROR(memory_allocation); > } > DEBUGLOG(4, "call ZSTDMT_initCStream_internal as nbThreads=%u", params.nbThreads); > CHECK_F( ZSTDMT_initCStream_internal( > cctx->mtctx, > prefixDict.dict, prefixDict.dictSize, ZSTD_dm_rawContent, > cctx->cdict, params, cctx->pledgedSrcSizePlusOne-1) ); > cctx->streamStage = zcss_load; > cctx->appliedParams.nbThreads = params.nbThreads; > } else >#endif ># 2792 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.c" > { > CHECK_F( ZSTD_resetCStream_internal( > cctx, prefixDict.dict, prefixDict.dictSize, > prefixDict.dictMode, cctx->cdict, params, > cctx->pledgedSrcSizePlusOne-1) ); > } } > > /* compression stage */ >#ifdef ZSTD_MULTITHREAD > if (cctx->appliedParams.nbThreads > 1) { > size_t const flushMin = ZSTDMT_compressStream_generic(cctx->mtctx, output, input, endOp); > DEBUGLOG(5, "ZSTDMT_compressStream_generic result : %u", (U32)flushMin); > if ( ZSTD_isError(flushMin) > || (endOp == ZSTD_e_end && flushMin == 0) ) { /* compression completed */ > ZSTD_startNewCompression(cctx); > } > return flushMin; > } >#endif ># 2811 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.c" > CHECK_F( ZSTD_compressStream_generic(cctx, output, input, endOp) ); > DEBUGLOG(5, "completed ZSTD_compress_generic"); > return cctx->outBuffContentSize - cctx->outBuffFlushedSize; /* remaining to flush */ >} > >size_t ZSTD_compress_generic_simpleArgs ( > ZSTD_CCtx* cctx, > void* dst, size_t dstCapacity, size_t* dstPos, > const void* src, size_t srcSize, size_t* srcPos, > ZSTD_EndDirective endOp) >{ > ZSTD_outBuffer output = { dst, dstCapacity, *dstPos }; > ZSTD_inBuffer input = { src, srcSize, *srcPos }; > /* ZSTD_compress_generic() will check validity of dstPos and srcPos */ > size_t const cErr = ZSTD_compress_generic(cctx, &output, &input, endOp); > *dstPos = output.pos; > *srcPos = input.pos; > return cErr; >} > > >/*====== Finalize ======*/ > >/*! ZSTD_flushStream() : >* @return : amount of data remaining to flush */ >size_t ZSTD_flushStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output) >{ > ZSTD_inBuffer input = { NULL, 0, 0 }; > if (output->pos > output->size) return ERROR(GENERIC); > CHECK_F( ZSTD_compressStream_generic(zcs, output, &input, ZSTD_e_flush) ); > return zcs->outBuffContentSize - zcs->outBuffFlushedSize; /* remaining to flush */ >} > > >size_t ZSTD_endStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output) >{ > ZSTD_inBuffer input = { NULL, 0, 0 }; > if (output->pos > output->size) return ERROR(GENERIC); > CHECK_F( ZSTD_compressStream_generic(zcs, output, &input, ZSTD_e_end) ); > { size_t const lastBlockSize = zcs->frameEnded ? 0 : ZSTD_BLOCKHEADERSIZE; > size_t const checksumSize = zcs->frameEnded ? 0 : zcs->appliedParams.fParams.checksumFlag * 4; > size_t const toFlush = zcs->outBuffContentSize - zcs->outBuffFlushedSize + lastBlockSize + checksumSize; > DEBUGLOG(5, "ZSTD_endStream : remaining to flush : %u", > (unsigned)toFlush); > return toFlush; > } >} > > >/*-===== Pre-defined compression levels =====-*/ > >#define ZSTD_MAX_CLEVEL 22 >int ZSTD_maxCLevel(void) { return ZSTD_MAX_CLEVEL; } > >static const ZSTD_compressionParameters ZSTD_defaultCParameters[4][ZSTD_MAX_CLEVEL+1] = { >{ /* "default" - guarantees a monotonically increasing memory budget */ > /* W, C, H, S, L, TL, strat */ > { 18, 12, 12, 1, 7, 16, ZSTD_fast }, /* level 0 - never used */ > { 19, 13, 14, 1, 7, 16, ZSTD_fast }, /* level 1 */ > { 19, 15, 16, 1, 6, 16, ZSTD_fast }, /* level 2 */ > { 20, 16, 17, 1, 5, 16, ZSTD_dfast }, /* level 3 */ > { 20, 17, 18, 1, 5, 16, ZSTD_dfast }, /* level 4 */ > { 20, 17, 18, 2, 5, 16, ZSTD_greedy }, /* level 5 */ > { 21, 17, 19, 2, 5, 16, ZSTD_lazy }, /* level 6 */ > { 21, 18, 19, 3, 5, 16, ZSTD_lazy }, /* level 7 */ > { 21, 18, 20, 3, 5, 16, ZSTD_lazy2 }, /* level 8 */ > { 21, 19, 20, 3, 5, 16, ZSTD_lazy2 }, /* level 9 */ > { 21, 19, 21, 4, 5, 16, ZSTD_lazy2 }, /* level 10 */ > { 22, 20, 22, 4, 5, 16, ZSTD_lazy2 }, /* level 11 */ > { 22, 20, 22, 5, 5, 16, ZSTD_lazy2 }, /* level 12 */ > { 22, 21, 22, 5, 5, 16, ZSTD_lazy2 }, /* level 13 */ > { 22, 21, 22, 6, 5, 16, ZSTD_lazy2 }, /* level 14 */ > { 22, 21, 22, 5, 5, 16, ZSTD_btlazy2 }, /* level 15 */ > { 23, 22, 22, 5, 5, 16, ZSTD_btlazy2 }, /* level 16 */ > { 23, 22, 22, 4, 5, 24, ZSTD_btopt }, /* level 17 */ > { 23, 22, 22, 5, 4, 32, ZSTD_btopt }, /* level 18 */ > { 23, 23, 22, 6, 3, 48, ZSTD_btopt }, /* level 19 */ > { 25, 25, 23, 7, 3, 64, ZSTD_btultra }, /* level 20 */ > { 26, 26, 24, 7, 3,256, ZSTD_btultra }, /* level 21 */ > { 27, 27, 25, 9, 3,512, ZSTD_btultra }, /* level 22 */ >}, >{ /* for srcSize <= 256 KB */ > /* W, C, H, S, L, T, strat */ > { 0, 0, 0, 0, 0, 0, ZSTD_fast }, /* level 0 - not used */ > { 18, 13, 14, 1, 6, 8, ZSTD_fast }, /* level 1 */ > { 18, 14, 13, 1, 5, 8, ZSTD_dfast }, /* level 2 */ > { 18, 16, 15, 1, 5, 8, ZSTD_dfast }, /* level 3 */ > { 18, 15, 17, 1, 5, 8, ZSTD_greedy }, /* level 4.*/ > { 18, 16, 17, 4, 5, 8, ZSTD_greedy }, /* level 5.*/ > { 18, 16, 17, 3, 5, 8, ZSTD_lazy }, /* level 6.*/ > { 18, 17, 17, 4, 4, 8, ZSTD_lazy }, /* level 7 */ > { 18, 17, 17, 4, 4, 8, ZSTD_lazy2 }, /* level 8 */ > { 18, 17, 17, 5, 4, 8, ZSTD_lazy2 }, /* level 9 */ > { 18, 17, 17, 6, 4, 8, ZSTD_lazy2 }, /* level 10 */ > { 18, 18, 17, 6, 4, 8, ZSTD_lazy2 }, /* level 11.*/ > { 18, 18, 17, 7, 4, 8, ZSTD_lazy2 }, /* level 12.*/ > { 18, 19, 17, 6, 4, 8, ZSTD_btlazy2 }, /* level 13 */ > { 18, 18, 18, 4, 4, 16, ZSTD_btopt }, /* level 14.*/ > { 18, 18, 18, 4, 3, 16, ZSTD_btopt }, /* level 15.*/ > { 18, 19, 18, 6, 3, 32, ZSTD_btopt }, /* level 16.*/ > { 18, 19, 18, 8, 3, 64, ZSTD_btopt }, /* level 17.*/ > { 18, 19, 18, 9, 3,128, ZSTD_btopt }, /* level 18.*/ > { 18, 19, 18, 10, 3,256, ZSTD_btopt }, /* level 19.*/ > { 18, 19, 18, 11, 3,512, ZSTD_btultra }, /* level 20.*/ > { 18, 19, 18, 12, 3,512, ZSTD_btultra }, /* level 21.*/ > { 18, 19, 18, 13, 3,512, ZSTD_btultra }, /* level 22.*/ >}, >{ /* for srcSize <= 128 KB */ > /* W, C, H, S, L, T, strat */ > { 17, 12, 12, 1, 7, 8, ZSTD_fast }, /* level 0 - not used */ > { 17, 12, 13, 1, 6, 8, ZSTD_fast }, /* level 1 */ > { 17, 13, 16, 1, 5, 8, ZSTD_fast }, /* level 2 */ > { 17, 16, 16, 2, 5, 8, ZSTD_dfast }, /* level 3 */ > { 17, 13, 15, 3, 4, 8, ZSTD_greedy }, /* level 4 */ > { 17, 15, 17, 4, 4, 8, ZSTD_greedy }, /* level 5 */ > { 17, 16, 17, 3, 4, 8, ZSTD_lazy }, /* level 6 */ > { 17, 15, 17, 4, 4, 8, ZSTD_lazy2 }, /* level 7 */ > { 17, 17, 17, 4, 4, 8, ZSTD_lazy2 }, /* level 8 */ > { 17, 17, 17, 5, 4, 8, ZSTD_lazy2 }, /* level 9 */ > { 17, 17, 17, 6, 4, 8, ZSTD_lazy2 }, /* level 10 */ > { 17, 17, 17, 7, 4, 8, ZSTD_lazy2 }, /* level 11 */ > { 17, 17, 17, 8, 4, 8, ZSTD_lazy2 }, /* level 12 */ > { 17, 18, 17, 6, 4, 8, ZSTD_btlazy2 }, /* level 13.*/ > { 17, 17, 17, 7, 3, 8, ZSTD_btopt }, /* level 14.*/ > { 17, 17, 17, 7, 3, 16, ZSTD_btopt }, /* level 15.*/ > { 17, 18, 17, 7, 3, 32, ZSTD_btopt }, /* level 16.*/ > { 17, 18, 17, 7, 3, 64, ZSTD_btopt }, /* level 17.*/ > { 17, 18, 17, 7, 3,256, ZSTD_btopt }, /* level 18.*/ > { 17, 18, 17, 8, 3,256, ZSTD_btopt }, /* level 19.*/ > { 17, 18, 17, 9, 3,256, ZSTD_btultra }, /* level 20.*/ > { 17, 18, 17, 10, 3,256, ZSTD_btultra }, /* level 21.*/ > { 17, 18, 17, 11, 3,512, ZSTD_btultra }, /* level 22.*/ >}, >{ /* for srcSize <= 16 KB */ > /* W, C, H, S, L, T, strat */ > { 14, 12, 12, 1, 7, 6, ZSTD_fast }, /* level 0 - not used */ > { 14, 14, 14, 1, 6, 6, ZSTD_fast }, /* level 1 */ > { 14, 14, 14, 1, 4, 6, ZSTD_fast }, /* level 2 */ > { 14, 14, 14, 1, 4, 6, ZSTD_dfast }, /* level 3.*/ > { 14, 14, 14, 4, 4, 6, ZSTD_greedy }, /* level 4.*/ > { 14, 14, 14, 3, 4, 6, ZSTD_lazy }, /* level 5.*/ > { 14, 14, 14, 4, 4, 6, ZSTD_lazy2 }, /* level 6 */ > { 14, 14, 14, 5, 4, 6, ZSTD_lazy2 }, /* level 7 */ > { 14, 14, 14, 6, 4, 6, ZSTD_lazy2 }, /* level 8.*/ > { 14, 15, 14, 6, 4, 6, ZSTD_btlazy2 }, /* level 9.*/ > { 14, 15, 14, 3, 3, 6, ZSTD_btopt }, /* level 10.*/ > { 14, 15, 14, 6, 3, 8, ZSTD_btopt }, /* level 11.*/ > { 14, 15, 14, 6, 3, 16, ZSTD_btopt }, /* level 12.*/ > { 14, 15, 14, 6, 3, 24, ZSTD_btopt }, /* level 13.*/ > { 14, 15, 15, 6, 3, 48, ZSTD_btopt }, /* level 14.*/ > { 14, 15, 15, 6, 3, 64, ZSTD_btopt }, /* level 15.*/ > { 14, 15, 15, 6, 3, 96, ZSTD_btopt }, /* level 16.*/ > { 14, 15, 15, 6, 3,128, ZSTD_btopt }, /* level 17.*/ > { 14, 15, 15, 6, 3,256, ZSTD_btopt }, /* level 18.*/ > { 14, 15, 15, 7, 3,256, ZSTD_btopt }, /* level 19.*/ > { 14, 15, 15, 8, 3,256, ZSTD_btultra }, /* level 20.*/ > { 14, 15, 15, 9, 3,256, ZSTD_btultra }, /* level 21.*/ > { 14, 15, 15, 10, 3,256, ZSTD_btultra }, /* level 22.*/ >}, >}; > >#if defined(ZSTD_DEBUG) && (ZSTD_DEBUG>=1) >/* This function just controls > * the monotonic memory budget increase of ZSTD_defaultCParameters[0]. > * Run once, on first ZSTD_getCParams() usage, if ZSTD_DEBUG is enabled > */ >MEM_STATIC void ZSTD_check_compressionLevel_monotonicIncrease_memoryBudget(void) >{ > int level; > for (level=1; level<ZSTD_maxCLevel(); level++) { > ZSTD_compressionParameters const c1 = ZSTD_defaultCParameters[0][level]; > ZSTD_compressionParameters const c2 = ZSTD_defaultCParameters[0][level+1]; > assert(c1.windowLog <= c2.windowLog); ># define ZSTD_TABLECOST(h,c) ((1<<(h)) + (1<<(c))) > assert(ZSTD_TABLECOST(c1.hashLog, c1.chainLog) <= ZSTD_TABLECOST(c2.hashLog, c2.chainLog)); > } >} >#endif ># 2989 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.c" > >/*! ZSTD_getCParams() : >* @return ZSTD_compressionParameters structure for a selected compression level, `srcSize` and `dictSize`. >* Size values are optional, provide 0 if not known or unused */ >ZSTD_compressionParameters ZSTD_getCParams(int compressionLevel, unsigned long long srcSizeHint, size_t dictSize) >{ > size_t const addedSize = srcSizeHint ? 0 : 500; > U64 const rSize = srcSizeHint+dictSize ? srcSizeHint+dictSize+addedSize : (U64)-1; > U32 const tableID = (rSize <= 256 KB) + (rSize <= 128 KB) + (rSize <= 16 KB); /* intentional underflow for srcSizeHint == 0 */ > >#if defined(ZSTD_DEBUG) && (ZSTD_DEBUG>=1) > static int g_monotonicTest = 1; > if (g_monotonicTest) { > ZSTD_check_compressionLevel_monotonicIncrease_memoryBudget(); > g_monotonicTest=0; > } >#endif ># 3006 "/usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/compress/zstd_compress.c" > > if (compressionLevel <= 0) compressionLevel = ZSTD_CLEVEL_DEFAULT; /* 0 == default; no negative compressionLevel yet */ > if (compressionLevel > ZSTD_MAX_CLEVEL) compressionLevel = ZSTD_MAX_CLEVEL; > { ZSTD_compressionParameters const cp = ZSTD_defaultCParameters[tableID][compressionLevel]; > return ZSTD_adjustCParams_internal(cp, srcSizeHint, dictSize); } > >} > >/*! ZSTD_getParams() : >* same as ZSTD_getCParams(), but @return a `ZSTD_parameters` object (instead of `ZSTD_compressionParameters`). >* All fields of `ZSTD_frameParameters` are set to default (0) */ >ZSTD_parameters ZSTD_getParams(int compressionLevel, unsigned long long srcSizeHint, size_t dictSize) { > ZSTD_parameters params; > ZSTD_compressionParameters const cParams = ZSTD_getCParams(compressionLevel, srcSizeHint, dictSize); > memset(¶ms, 0, sizeof(params)); > params.cParams = cParams; > return params; >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 223693
: 188033 |
188034