105206c06Stls /* 205206c06Stls * Copyright (c) 2000-2007 Marc Alexander Lehmann <schmorp@schmorp.de> 305206c06Stls * 405206c06Stls * Redistribution and use in source and binary forms, with or without modifica- 505206c06Stls * tion, are permitted provided that the following conditions are met: 605206c06Stls * 705206c06Stls * 1. Redistributions of source code must retain the above copyright notice, 805206c06Stls * this list of conditions and the following disclaimer. 905206c06Stls * 1005206c06Stls * 2. Redistributions in binary form must reproduce the above copyright 1105206c06Stls * notice, this list of conditions and the following disclaimer in the 1205206c06Stls * documentation and/or other materials provided with the distribution. 1305206c06Stls * 1405206c06Stls * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 1505206c06Stls * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- 1605206c06Stls * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 1705206c06Stls * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- 1805206c06Stls * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 1905206c06Stls * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 2005206c06Stls * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 2105206c06Stls * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH- 2205206c06Stls * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 2305206c06Stls * OF THE POSSIBILITY OF SUCH DAMAGE. 2405206c06Stls * 2505206c06Stls * Alternatively, the contents of this file may be used under the terms of 2605206c06Stls * the GNU General Public License ("GPL") version 2 or any later version, 2705206c06Stls * in which case the provisions of the GPL are applicable instead of 2805206c06Stls * the above. If you wish to allow the use of your version of this file 2905206c06Stls * only under the terms of the GPL and not to allow others to use your 3005206c06Stls * version of this file under the BSD license, indicate your decision 3105206c06Stls * by deleting the provisions above and replace them with the notice 3205206c06Stls * and other provisions required by the GPL. If you do not delete the 3305206c06Stls * provisions above, a recipient may use your version of this file under 3405206c06Stls * either the BSD or the GPL. 3505206c06Stls */ 3605206c06Stls 3705206c06Stls #ifndef LZFP_h 3805206c06Stls #define LZFP_h 3905206c06Stls 40*ea6af427Stls #if !defined(_KERNEL) && !defined(_STANDALONE) 41*ea6af427Stls #include <sys/types.h> 42*ea6af427Stls #include <inttypes.h> 4305206c06Stls #endif 4405206c06Stls 4505206c06Stls /* 46*ea6af427Stls * Size of hashtable is (1 << LZF_HLOG) * sizeof (char *) 4705206c06Stls * decompression is independent of the hash table size 4805206c06Stls * the difference between 15 and 14 is very small 4905206c06Stls * for small blocks (and 14 is usually a bit faster). 50*ea6af427Stls * For a low-memory/faster configuration, use LZF_HLOG == 13; 5105206c06Stls * For best compression, use 15 or 16 (or more, up to 23). 5205206c06Stls */ 53*ea6af427Stls #ifndef LZF_HLOG 54*ea6af427Stls # define LZF_HLOG 16 5505206c06Stls #endif 5605206c06Stls 5705206c06Stls /* 5805206c06Stls * Sacrifice very little compression quality in favour of compression speed. 5905206c06Stls * This gives almost the same compression as the default code, and is 6005206c06Stls * (very roughly) 15% faster. This is the preferred mode of operation. 6105206c06Stls */ 6205206c06Stls #ifndef VERY_FAST 6305206c06Stls # define VERY_FAST 1 6405206c06Stls #endif 6505206c06Stls 6605206c06Stls /* 6705206c06Stls * Sacrifice some more compression quality in favour of compression speed. 6805206c06Stls * (roughly 1-2% worse compression for large blocks and 6905206c06Stls * 9-10% for small, redundant, blocks and >>20% better speed in both cases) 7005206c06Stls * In short: when in need for speed, enable this for binary data, 7105206c06Stls * possibly disable this for text data. 7205206c06Stls */ 7305206c06Stls #ifndef ULTRA_FAST 7405206c06Stls # define ULTRA_FAST 0 7505206c06Stls #endif 7605206c06Stls 7705206c06Stls /* 7805206c06Stls * Unconditionally aligning does not cost very much, so do it if unsure 79*ea6af427Stls * 80*ea6af427Stls * In fact, on modern x86 processors, strict alignment is faster whether 81*ea6af427Stls * in 32 or 64 bit mode. 8205206c06Stls */ 8305206c06Stls #ifndef STRICT_ALIGN 84*ea6af427Stls # define STRICT_ALIGN 1 /* !(defined(__i386) || defined (__amd64)) */ 8505206c06Stls #endif 8605206c06Stls 8705206c06Stls /* 8805206c06Stls * You may choose to pre-set the hash table (might be faster on some 8905206c06Stls * modern cpus and large (>>64k) blocks, and also makes compression 9005206c06Stls * deterministic/repeatable when the configuration otherwise is the same). 9105206c06Stls */ 9205206c06Stls #ifndef INIT_HTAB 9305206c06Stls # define INIT_HTAB 0 9405206c06Stls #endif 9505206c06Stls 9605206c06Stls /* 9705206c06Stls * Avoid assigning values to errno variable? for some embedding purposes 9805206c06Stls * (linux kernel for example), this is neccessary. NOTE: this breaks 9905206c06Stls * the documentation in lzf.h. 10005206c06Stls */ 10105206c06Stls #ifndef AVOID_ERRNO 10205206c06Stls # define AVOID_ERRNO 0 10305206c06Stls #endif 10405206c06Stls 10505206c06Stls /* 10605206c06Stls * Wether to pass the LZF_STATE variable as argument, or allocate it 10705206c06Stls * on the stack. For small-stack environments, define this to 1. 10805206c06Stls * NOTE: this breaks the prototype in lzf.h. 10905206c06Stls */ 11005206c06Stls #ifndef LZF_STATE_ARG 111e6ea0ca4Stls # define LZF_STATE_ARG 0 11205206c06Stls #endif 11305206c06Stls 11405206c06Stls /* 11505206c06Stls * Wether to add extra checks for input validity in lzf_decompress 11605206c06Stls * and return EINVAL if the input stream has been corrupted. This 11705206c06Stls * only shields against overflowing the input buffer and will not 11805206c06Stls * detect most corrupted streams. 11905206c06Stls * This check is not normally noticable on modern hardware 12005206c06Stls * (<1% slowdown), but might slow down older cpus considerably. 12105206c06Stls */ 12205206c06Stls #ifndef CHECK_INPUT 12305206c06Stls # define CHECK_INPUT 1 12405206c06Stls #endif 12505206c06Stls 12605206c06Stls /*****************************************************************************/ 12705206c06Stls /* nothing should be changed below */ 12805206c06Stls 129*ea6af427Stls typedef uint8_t u8; 130*ea6af427Stls typedef uint16_t u16; 13105206c06Stls 132*ea6af427Stls #if !defined(_KERNEL) && !defined(STANDALONE) 133*ea6af427Stls typedef const u8 *LZF_STATE[1 << (LZF_HLOG)]; 13405206c06Stls #endif 13505206c06Stls 13605206c06Stls #if ULTRA_FAST 13705206c06Stls # if defined(VERY_FAST) 13805206c06Stls # undef VERY_FAST 13905206c06Stls # endif 14005206c06Stls #endif 14105206c06Stls 14205206c06Stls #if INIT_HTAB 14305206c06Stls # ifdef __cplusplus 14405206c06Stls # include <cstring> 14505206c06Stls # else 14605206c06Stls # include <string.h> 14705206c06Stls # endif 14805206c06Stls #endif 14905206c06Stls 15005206c06Stls #endif 15105206c06Stls 152