Hello community, here is the log from the commit of package lzfse for openSUSE:Factory checked in at 2016-08-12 15:42:59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/lzfse (Old) and /work/SRC/openSUSE:Factory/.lzfse.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "lzfse" Changes: -------- --- /work/SRC/openSUSE:Factory/lzfse/lzfse.changes 2016-07-14 09:49:17.000000000 +0200 +++ /work/SRC/openSUSE:Factory/.lzfse.new/lzfse.changes 2016-08-12 15:43:02.000000000 +0200 @@ -1,0 +2,15 @@ +Wed Aug 10 09:09:49 UTC 2016 - [email protected] + +- Update to version 0.0+git.20160802: + * Add extern declarations for linking into C++ code. + * Avoid pointer arithmetic on void pointers + * Implement GCC bit scan builtins for MSVC + * Fix issues related to use of __attribute__ + * Implement jump table as switch for non-GCC + * Use ptrdiff_t instead of ssize_t + * Add MSVC fixes for timing and file access + * Set _POSIX_C_SOURCE to 200112L for gettimeofday + * Set binary mode on stdin/stdout on Windows + * Update API export to work for CMake and MSVC + +------------------------------------------------------------------- Old: ---- lzfse-0.0+git.20160620.tar.xz New: ---- lzfse-0.0+git.20160802.tar.xz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ lzfse.spec ++++++ --- /var/tmp/diff_new_pack.uCCndt/_old 2016-08-12 15:43:03.000000000 +0200 +++ /var/tmp/diff_new_pack.uCCndt/_new 2016-08-12 15:43:03.000000000 +0200 @@ -17,13 +17,14 @@ Name: lzfse -Version: 0.0+git.20160620 +Version: 0.0+git.20160802 Release: 0 Summary: Reference C implementation of the LZFSE compressor License: BSD-3-Clause Group: Productivity/Archiving/Compression Url: https://github.com/lzfse/lzfse Source: %{name}-%{version}.tar.xz +BuildRequires: cmake BuildRequires: xz BuildRoot: %{_tmppath}/%{name}-%{version}-build @@ -32,20 +33,36 @@ Entropy coding. It targets similar compression rates at higher compression and decompression speed compared to deflate using zlib. +%package devel +Summary: Reference C implementation of the LZFSE compressor +Group: Development/Libraries/C and C++ +Requires: %{name} = %{version} + +%description devel +LZFSE is a Lempel-Ziv style data compression algorithm using Finite State +Entropy coding. It targets similar compression rates at higher compression +and decompression speed compared to deflate using zlib. + +This package contains devel files. + %prep %setup -q %build -make %{?_smp_mflags} CC="cc %{optflags}" +%cmake +make %{?_smp_mflags} %install -make install INSTALL_PREFIX=%{buildroot}%{_prefix} -# we don't want to ship any static libraries or orphaned .h files -find %{buildroot} -type f \( -name '*.a' -o -name '*.h' \) -delete -print +%cmake_install %files %defattr(-,root,root) %doc LICENSE README.md %{_bindir}/lzfse +%{_libdir}/liblzfse.so + +%files devel +%defattr(-,root,root) +%{_includedir}/lzfse.h %changelog ++++++ lzfse-0.0+git.20160620.tar.xz -> lzfse-0.0+git.20160802.tar.xz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lzfse-0.0+git.20160620/CMakeLists.txt new/lzfse-0.0+git.20160802/CMakeLists.txt --- old/lzfse-0.0+git.20160620/CMakeLists.txt 1970-01-01 01:00:00.000000000 +0100 +++ new/lzfse-0.0+git.20160802/CMakeLists.txt 2016-08-03 04:09:30.000000000 +0200 @@ -0,0 +1,97 @@ +project(lzfse C) +cmake_minimum_required(VERSION 2.8.6) + +include(CheckCCompilerFlag) + +# If LZFSE is being bundled in another project, we don't want to +# install anything. However, we want to let people override this, so +# we'll use the LZFSE_BUNDLE_MODE variable to let them do that; just +# set it to OFF in your project before you add_subdirectory(lzfse). +get_directory_property(LZFSE_PARENT_DIRECTORY PARENT_DIRECTORY) +if("${LZFSE_BUNDLE_MODE}" STREQUAL "") + # Bundled mode hasn't been set one way or the other, set the default + # depending on whether or not we are the top-level project. + if(LZFSE_PARENT_DIRECTORY) + set(LZFSE_BUNDLE_MODE ON) + else() + set(LZFSE_BUNDLE_MODE OFF) + endif(LZFSE_PARENT_DIRECTORY) +endif() +mark_as_advanced(LZFSE_BUNDLE_MODE) + +if(NOT LZFSE_BUNDLE_MODE) + option(BUILD_SHARED_LIBS "Build shared libraries" ON) +else() + set(BUILD_SHARED_LIBS OFF) +endif() + +if (CMAKE_VERSION VERSION_GREATER 3.2) + cmake_policy (SET CMP0063 NEW) +endif () + +# Compiler flags +function(lzfse_add_compiler_flags target) + set (flags ${ARGV}) + list (REMOVE_AT flags 0) + + foreach (FLAG ${flags}) + if(CMAKE_C_COMPILER_ID STREQUAL GNU) + # Because https://gcc.gnu.org/wiki/FAQ#wnowarning + string(REGEX REPLACE "\\-Wno\\-(.+)" "-W\\1" flag_to_test "${FLAG}") + else() + set (flag_to_test ${FLAG}) + endif() + + string(REGEX REPLACE "[^a-zA-Z0-9]+" "_" test_name "CFLAG_${flag_to_test}") + + check_c_compiler_flag("${flag_to_test}" "${test_name}") + if(${${test_name}}) + set_property(TARGET "${target}" APPEND_STRING PROPERTY COMPILE_FLAGS " ${FLAG}") + endif() + endforeach() +endfunction() + +add_library(lzfse + src/lzfse_decode.c + src/lzfse_decode_base.c + src/lzfse_encode.c + src/lzfse_encode_base.c + src/lzfse_fse.c + src/lzvn_decode_base.c + src/lzvn_encode_base.c) +lzfse_add_compiler_flags(lzfse -Wall -Wno-unknown-pragmas -Wno-unused-variable) + +add_executable(lzfse_cli + src/lzfse_main.c) +target_link_libraries(lzfse_cli lzfse) +set_target_properties(lzfse_cli PROPERTIES OUTPUT_NAME lzfse) +lzfse_add_compiler_flags(lzfse_cli -Wall -Wno-unknown-pragmas -Wno-unused-variable) + +if(CMAKE_VERSION VERSION_LESS 3.1 OR CMAKE_C_COMPLIER_ID STREQUAL "Intel") + lzfse_add_compiler_flags(lzfse -std=c99) + lzfse_add_compiler_flags(lzfse_cli -std=c99) +else() + set_property(TARGET lzfse PROPERTY C_STANDARD 99) + set_property(TARGET lzfse_cli PROPERTY C_STANDARD 99) +endif() + +set_target_properties(lzfse PROPERTIES + POSITION_INDEPENDENT_CODE TRUE + C_VISIBILITY_PRESET hidden + INTERPROCEDURAL_OPTIMIZATION TRUE) + +if(BUILD_SHARED_LIBS) + set_property(TARGET lzfse APPEND PROPERTY COMPILE_DEFINITIONS LZFSE_DLL LZFSE_DLL_EXPORTS) + set_property(TARGET lzfse APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS LZFSE_DLL) +endif() + +# Installation +if(NOT LZFSE_BUNDLE_MODE) + include(GNUInstallDirs) + + install(TARGETS lzfse lzfse_cli + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}") + install(FILES src/lzfse.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") +endif() diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lzfse-0.0+git.20160620/README.md new/lzfse-0.0+git.20160802/README.md --- old/lzfse-0.0+git.20160620/README.md 2016-07-11 17:41:16.000000000 +0200 +++ new/lzfse-0.0+git.20160802/README.md 2016-08-03 04:09:30.000000000 +0200 @@ -39,9 +39,9 @@ Produces the following files in `/tmp/lzfse.dst`: - usr/local/bin/lzfse command line tool - usr/local/include/lzfse.h LZFSE library header - usr/local/lib/liblzfse.a LZFSE library + usr/local/bin/lzfse command line tool + usr/local/include/lzfse.h LZFSE library header + usr/local/lib/liblzfse.a LZFSE library Building on Linux ----------------- @@ -52,7 +52,22 @@ Produces the following files in `/tmp/lzfse.dst`: + usr/local/bin/lzfse command line tool + usr/local/include/lzfse.h LZFSE library header + usr/local/lib/liblzfse.a LZFSE library + +Building with cmake +------------------- + + $ mkdir build + $ cd build + $ cmake .. + $ make install + +Installs the header, library, and command line tool in `/usr/local`. + +Bindings +-------- + +Python: [dimkr/pylzfse](https://github.com/dimkr/pylzfse) - usr/local/bin/lzfse command line tool - usr/local/include/lzfse.h LZFSE library header - usr/local/lib/liblzfse.a LZFSE library diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lzfse-0.0+git.20160620/src/lzfse.h new/lzfse-0.0+git.20160802/src/lzfse.h --- old/lzfse-0.0+git.20160620/src/lzfse.h 2016-07-11 17:41:16.000000000 +0200 +++ new/lzfse-0.0+git.20160802/src/lzfse.h 2016-08-03 04:09:30.000000000 +0200 @@ -1,7 +1,7 @@ /* Copyright (c) 2015-2016, Apple Inc. All rights reserved. -Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: +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. @@ -25,10 +25,35 @@ #include <stddef.h> #include <stdint.h> -#define LZFSE_LIB_API __attribute__((visibility("default"))) +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(_MSC_VER) && !defined(__clang__) +# define __attribute__(X) +# pragma warning(disable : 4068) +#endif + +#if defined(LZFSE_DLL) +# if defined(_WIN32) || defined(__CYGWIN__) +# if defined(LZFSE_DLL_EXPORTS) +# define LZFSE_API __declspec(dllexport) +# else +# define LZFSE_API __declspec(dllimport) +# endif +# endif +#endif + +#if !defined(LZFSE_API) +# if __GNUC__ >= 4 +# define LZFSE_API __attribute__((visibility("default"))) +# else +# define LZFSE_API +# endif +#endif /*! @abstract Get the required scratch buffer size to compress using LZFSE. */ -size_t lzfse_encode_scratch_size() LZFSE_LIB_API; +LZFSE_API size_t lzfse_encode_scratch_size(); /*! @abstract Compress a buffer using LZFSE. * @@ -59,14 +84,14 @@ * successfully compressed. If the input cannot be compressed to fit into * the provided buffer, or an error occurs, zero is returned, and the * contents of dst_buffer are unspecified. */ -size_t lzfse_encode_buffer(uint8_t *__restrict dst_buffer, - size_t dst_size, - const uint8_t *__restrict src_buffer, - size_t src_size, - void *__restrict scratch_buffer) LZFSE_LIB_API; +LZFSE_API size_t lzfse_encode_buffer(uint8_t *__restrict dst_buffer, + size_t dst_size, + const uint8_t *__restrict src_buffer, + size_t src_size, + void *__restrict scratch_buffer); /*! @abstract Get the required scratch buffer size to decompress using LZFSE. */ -size_t lzfse_decode_scratch_size() LZFSE_LIB_API; +LZFSE_API size_t lzfse_decode_scratch_size(); /*! @abstract Decompress a buffer using LZFSE. * @@ -98,10 +123,14 @@ * buffer to hold the entire expanded output, only the first dst_size bytes * will be written to the buffer and dst_size is returned. Note that this * behavior differs from that of lzfse_encode_buffer. */ -size_t lzfse_decode_buffer(uint8_t *__restrict dst_buffer, - size_t dst_size, - const uint8_t *__restrict src_buffer, - size_t src_size, - void *__restrict scratch_buffer) LZFSE_LIB_API; +LZFSE_API size_t lzfse_decode_buffer(uint8_t *__restrict dst_buffer, + size_t dst_size, + const uint8_t *__restrict src_buffer, + size_t src_size, + void *__restrict scratch_buffer); + +#ifdef __cplusplus +} /* extern "C" */ +#endif -#endif // LZFSE_H +#endif /* LZFSE_H */ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lzfse-0.0+git.20160620/src/lzfse_fse.h new/lzfse-0.0+git.20160802/src/lzfse_fse.h --- old/lzfse-0.0+git.20160620/src/lzfse_fse.h 2016-07-11 17:41:16.000000000 +0200 +++ new/lzfse-0.0+git.20160802/src/lzfse_fse.h 2016-08-03 04:09:30.000000000 +0200 @@ -34,13 +34,18 @@ // Select between 32/64-bit I/O streams for FSE. Note that the FSE stream // size need not match the word size of the machine, but in practice you // want to use 64b streams on 64b systems for better performance. -#if defined __x86_64__ || defined __arm64__ +#if defined(_M_AMD64) || defined(__x86_64__) || defined(__arm64__) #define FSE_IOSTREAM_64 1 #else #define FSE_IOSTREAM_64 0 #endif -#define FSE_INLINE static inline __attribute__((__always_inline__)) +#if defined(_MSC_VER) && !defined(__clang__) +# define FSE_INLINE __forceinline +# pragma warning(disable : 4068) // warning C4068: unknown pragma +#else +# define FSE_INLINE static inline __attribute__((__always_inline__)) +#endif #pragma mark - Bit utils @@ -101,9 +106,11 @@ * 0 <= start <= start+nbits <= 64 */ FSE_INLINE uint64_t fse_extract_bits64(uint64_t x, fse_bit_count start, fse_bit_count nbits) { +#if defined(__GNUC__) // If START and NBITS are constants, map to bit-field extraction instructions if (__builtin_constant_p(start) && __builtin_constant_p(nbits)) return (x >> start) & ((1LLU << nbits) - 1LLU); +#endif // Otherwise, shift and mask return fse_mask_lsb64(x >> start, nbits); @@ -113,9 +120,11 @@ * 0 <= start <= start+nbits <= 32 */ FSE_INLINE uint32_t fse_extract_bits32(uint32_t x, fse_bit_count start, fse_bit_count nbits) { +#if defined(__GNUC__) // If START and NBITS are constants, map to bit-field extraction instructions if (__builtin_constant_p(start) && __builtin_constant_p(nbits)) return (x >> start) & ((1U << nbits) - 1U); +#endif // Otherwise, shift and mask return fse_mask_lsb32(x >> start, nbits); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lzfse-0.0+git.20160620/src/lzfse_internal.h new/lzfse-0.0+git.20160802/src/lzfse_internal.h --- old/lzfse-0.0+git.20160620/src/lzfse_internal.h 2016-07-11 17:41:16.000000000 +0200 +++ new/lzfse-0.0+git.20160802/src/lzfse_internal.h 2016-08-03 04:09:30.000000000 +0200 @@ -33,6 +33,53 @@ #include <stddef.h> #include <stdint.h> +#if defined(_MSC_VER) && !defined(__clang__) +# define LZFSE_INLINE __forceinline +# define __builtin_expect(X, Y) (X) +# define __attribute__(X) +# pragma warning(disable : 4068) // warning C4068: unknown pragma +#else +# define LZFSE_INLINE static inline __attribute__((__always_inline__)) +#endif + +// Implement GCC bit scan builtins for MSVC +#if defined(_MSC_VER) && !defined(__clang__) +#include <intrin.h> + +LZFSE_INLINE int __builtin_clz(unsigned int val) { + unsigned long r = 0; + if (_BitScanReverse(&r, val)) { + return 31 - r; + } + return 32; +} + +LZFSE_INLINE int __builtin_ctzl(unsigned long val) { + unsigned long r = 0; + if (_BitScanForward(&r, val)) { + return r; + } + return 32; +} + +LZFSE_INLINE int __builtin_ctzll(uint64_t val) { + unsigned long r = 0; +#if defined(_M_AMD64) || defined(_M_ARM) + if (_BitScanForward64(&r, val)) { + return r; + } +#else + if (_BitScanForward(&r, (uint32_t)val)) { + return r; + } + if (_BitScanForward(&r, (uint32_t)(val >> 32))) { + return 32 + r; + } +#endif + return 64; +} +#endif + // Throughout LZFSE we refer to "L", "M" and "D"; these will always appear as // a triplet, and represent a "usual" LZ-style literal and match pair. "L" // is the number of literal bytes, "M" is the number of match bytes, and "D" @@ -375,8 +422,6 @@ #pragma mark - LZFSE utility functions -#define LZFSE_INLINE static inline __attribute__((__always_inline__)) - /*! @abstract Load bytes from memory location SRC. */ LZFSE_INLINE uint16_t load2(const void *ptr) { uint16_t data; @@ -417,9 +462,9 @@ LZFSE_INLINE void copy8(void *dst, const void *src) { store8(dst, load8(src)); } LZFSE_INLINE void copy16(void *dst, const void *src) { uint64_t m0 = load8(src); - uint64_t m1 = load8(src + 8); + uint64_t m1 = load8((const unsigned char *)src + 8); store8(dst, m0); - store8(dst + 8, m1); + store8((unsigned char *)dst + 8, m1); } // =============================================================== diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lzfse-0.0+git.20160620/src/lzfse_main.c new/lzfse-0.0+git.20160802/src/lzfse_main.c --- old/lzfse-0.0+git.20160620/src/lzfse_main.c 2016-07-11 17:41:16.000000000 +0200 +++ new/lzfse-0.0+git.20160802/src/lzfse_main.c 2016-08-03 04:09:30.000000000 +0200 @@ -1,7 +1,7 @@ /* Copyright (c) 2015-2016, Apple Inc. All rights reserved. -Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: +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. @@ -21,13 +21,35 @@ // LZFSE command line tool +#if !defined(_POSIX_C_SOURCE) || (_POSIX_C_SOURCE < 200112L) +# undef _POSIX_C_SOURCE +# define _POSIX_C_SOURCE 200112L +#endif + +#if defined(_MSC_VER) +# if !defined(_CRT_NONSTDC_NO_DEPRECATE) +# define _CRT_NONSTDC_NO_DEPRECATE +# endif +# if !defined(_CRT_SECURE_NO_WARNINGS) +# define _CRT_SECURE_NO_WARNINGS +# endif +#endif + #include "lzfse.h" #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/stat.h> -#include <unistd.h> +#include <sys/types.h> + +#if defined(_MSC_VER) +# include <io.h> +# include <windows.h> +#else +# include <sys/time.h> +# include <unistd.h> +#endif // Same as realloc(x,s), except x is freed when realloc fails static inline void *lzfse_reallocf(void *x, size_t s) { @@ -39,16 +61,21 @@ return y; } -// Get wall clock time -#include <sys/time.h> - static double get_time() { +#if defined(_MSC_VER) + LARGE_INTEGER count, freq; + if (QueryPerformanceFrequency(&freq) && QueryPerformanceCounter(&count)) { + return (double)count.QuadPart / (double)freq.QuadPart; + } + return 1.0e-3 * (double)GetTickCount(); +#else struct timeval tv; if (gettimeofday(&tv, 0) != 0) { perror("gettimeofday"); exit(1); } return (double)tv.tv_sec + 1.0e-6 * (double)tv.tv_usec; +#endif } //-------------------- @@ -137,7 +164,11 @@ if (in_file != 0) { // If we have a file name, open it, and allocate the exact input size struct stat st; +#if defined(_WIN32) + in_fd = open(in_file, O_RDONLY | O_BINARY); +#else in_fd = open(in_file, O_RDONLY); +#endif if (in_fd < 0) { perror(in_file); exit(1); @@ -155,6 +186,12 @@ // Otherwise, read from stdin, and allocate to 1 MB, grow as needed in_allocated = 1 << 20; in_fd = 0; +#if defined(_WIN32) + if (setmode(in_fd, O_BINARY) == -1) { + perror("setmode"); + exit(1); + } +#endif } in = (uint8_t *)malloc(in_allocated); if (in == 0) { @@ -176,7 +213,7 @@ } } - ssize_t r = read(in_fd, in + in_size, in_allocated - in_size); + ptrdiff_t r = read(in_fd, in + in_size, in_allocated - in_size); if (r < 0) { perror("read"); exit(1); @@ -253,16 +290,27 @@ // Write output int out_fd = -1; if (out_file) { +#if defined(_WIN32) + out_fd = open(out_file, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, + S_IWRITE); +#else out_fd = open(out_file, O_WRONLY | O_CREAT | O_TRUNC, 0644); +#endif if (out_fd < 0) { perror(out_file); exit(1); } } else { out_fd = 1; // stdout +#if defined(_WIN32) + if (setmode(out_fd, O_BINARY) == -1) { + perror("setmode"); + exit(1); + } +#endif } for (size_t out_pos = 0; out_pos < out_size;) { - ssize_t w = write(out_fd, out + out_pos, out_size - out_pos); + ptrdiff_t w = write(out_fd, out + out_pos, out_size - out_pos); if (w < 0) { perror("write"); exit(1); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lzfse-0.0+git.20160620/src/lzvn_decode_base.c new/lzfse-0.0+git.20160802/src/lzvn_decode_base.c --- old/lzfse-0.0+git.20160620/src/lzvn_decode_base.c 2016-07-11 17:41:16.000000000 +0200 +++ new/lzfse-0.0+git.20160802/src/lzvn_decode_base.c 2016-08-03 04:09:30.000000000 +0200 @@ -23,6 +23,14 @@ #include "lzvn_decode_base.h" +#if !defined(HAVE_LABELS_AS_VALUES) +# if defined(__GNUC__) || defined(__clang__) +# define HAVE_LABELS_AS_VALUES 1 +# else +# define HAVE_LABELS_AS_VALUES 0 +# endif +#endif + // Both the source and destination buffers are represented by a pointer and // a length; they are *always* updated in concert using this macro; however // many bytes the pointer is advanced, the length is decremented by the same @@ -37,6 +45,7 @@ (state->src = src_ptr, state->dst = dst_ptr, state->d_prev = D) void lzvn_decode(lzvn_decoder_state *state) { +#if HAVE_LABELS_AS_VALUES // Jump table for all instructions static const void *opc_tbl[256] = { &&sml_d, &&sml_d, &&sml_d, &&sml_d, &&sml_d, &&sml_d, &&eos, &&lrg_d, @@ -71,7 +80,7 @@ &&sml_l, &&sml_l, &&sml_l, &&sml_l, &&sml_l, &&sml_l, &&sml_l, &&sml_l, &&lrg_m, &&sml_m, &&sml_m, &&sml_m, &&sml_m, &&sml_m, &&sml_m, &&sml_m, &&sml_m, &&sml_m, &&sml_m, &&sml_m, &&sml_m, &&sml_m, &&sml_m, &&sml_m}; - +#endif size_t src_len = state->src_end - state->src; size_t dst_len = state->dst_end - state->dst; if (src_len == 0 || dst_len == 0) @@ -99,8 +108,13 @@ } unsigned char opc = src_ptr[0]; - goto *opc_tbl[opc]; +#if HAVE_LABELS_AS_VALUES + goto *opc_tbl[opc]; +#else + for (;;) { + switch (opc) { +#endif // =============================================================== // These four opcodes (sml_d, med_d, lrg_d, and pre_d) encode both a // literal and a match. The bulk of their implementations are shared; @@ -113,6 +127,128 @@ // the source has enough length to represent the full opcode before // reading past the first byte. sml_d: +#if !HAVE_LABELS_AS_VALUES + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 8: + case 9: + case 10: + case 11: + case 12: + case 13: + case 16: + case 17: + case 18: + case 19: + case 20: + case 21: + case 24: + case 25: + case 26: + case 27: + case 28: + case 29: + case 32: + case 33: + case 34: + case 35: + case 36: + case 37: + case 40: + case 41: + case 42: + case 43: + case 44: + case 45: + case 48: + case 49: + case 50: + case 51: + case 52: + case 53: + case 56: + case 57: + case 58: + case 59: + case 60: + case 61: + case 64: + case 65: + case 66: + case 67: + case 68: + case 69: + case 72: + case 73: + case 74: + case 75: + case 76: + case 77: + case 80: + case 81: + case 82: + case 83: + case 84: + case 85: + case 88: + case 89: + case 90: + case 91: + case 92: + case 93: + case 96: + case 97: + case 98: + case 99: + case 100: + case 101: + case 104: + case 105: + case 106: + case 107: + case 108: + case 109: + case 128: + case 129: + case 130: + case 131: + case 132: + case 133: + case 136: + case 137: + case 138: + case 139: + case 140: + case 141: + case 144: + case 145: + case 146: + case 147: + case 148: + case 149: + case 152: + case 153: + case 154: + case 155: + case 156: + case 157: + case 192: + case 193: + case 194: + case 195: + case 196: + case 197: + case 200: + case 201: + case 202: + case 203: + case 204: + case 205: +#endif UPDATE_GOOD; // "small distance": This opcode has the structure LLMMMDDD DDDDDDDD LITERAL // where the length of literal (0-3 bytes) is encoded by the high 2 bits of @@ -134,6 +270,40 @@ goto copy_literal_and_match; med_d: +#if !HAVE_LABELS_AS_VALUES + case 160: + case 161: + case 162: + case 163: + case 164: + case 165: + case 166: + case 167: + case 168: + case 169: + case 170: + case 171: + case 172: + case 173: + case 174: + case 175: + case 176: + case 177: + case 178: + case 179: + case 180: + case 181: + case 182: + case 183: + case 184: + case 185: + case 186: + case 187: + case 188: + case 189: + case 190: + case 191: +#endif UPDATE_GOOD; // "medium distance": This is a minor variant of the "small distance" // encoding, where we will now use two extra bytes instead of one to encode @@ -150,6 +320,28 @@ goto copy_literal_and_match; lrg_d: +#if !HAVE_LABELS_AS_VALUES + case 7: + case 15: + case 23: + case 31: + case 39: + case 47: + case 55: + case 63: + case 71: + case 79: + case 87: + case 95: + case 103: + case 111: + case 135: + case 143: + case 151: + case 159: + case 199: + case 207: +#endif UPDATE_GOOD; // "large distance": This is another variant of the "small distance" // encoding, where we will now use two extra bytes to encode the match @@ -164,6 +356,20 @@ goto copy_literal_and_match; pre_d: +#if !HAVE_LABELS_AS_VALUES + case 70: + case 78: + case 86: + case 94: + case 102: + case 110: + case 134: + case 142: + case 150: + case 158: + case 198: + case 206: +#endif UPDATE_GOOD; // "previous distance": This opcode has the structure LLMMM110, where the // length of the literal (0-3 bytes) is encoded by the high 2 bits of the @@ -269,7 +475,11 @@ // the appropriate implementation. PTR_LEN_INC(dst_ptr, dst_len, M); opc = src_ptr[0]; +#if HAVE_LABELS_AS_VALUES goto *opc_tbl[opc]; +#else + break; +#endif // =============================================================== // Opcodes representing only a match (no literal). @@ -279,6 +489,23 @@ // sequence from the literal and match opcodes to perform the actual // copy implementation. sml_m: +#if !HAVE_LABELS_AS_VALUES + case 241: + case 242: + case 243: + case 244: + case 245: + case 246: + case 247: + case 248: + case 249: + case 250: + case 251: + case 252: + case 253: + case 254: + case 255: +#endif UPDATE_GOOD; // "small match": This opcode has no literal, and uses the previous match // distance (i.e. it encodes only the match length), in a single byte as @@ -291,6 +518,9 @@ goto copy_match; lrg_m: +#if !HAVE_LABELS_AS_VALUES + case 240: +#endif UPDATE_GOOD; // "large match": This opcode has no literal, and uses the previous match // distance (i.e. it encodes only the match length). It is encoded in two @@ -310,6 +540,23 @@ // match length or match distance to worry about (but we need to *not* // touch D, as it must be preserved between opcodes). sml_l: +#if !HAVE_LABELS_AS_VALUES + case 225: + case 226: + case 227: + case 228: + case 229: + case 230: + case 231: + case 232: + case 233: + case 234: + case 235: + case 236: + case 237: + case 238: + case 239: +#endif UPDATE_GOOD; // "small literal": This opcode has no match, and encodes only a literal // of length up to 15 bytes. The format is 1110LLLL LITERAL. @@ -318,6 +565,9 @@ goto copy_literal; lrg_l: +#if !HAVE_LABELS_AS_VALUES + case 224: +#endif UPDATE_GOOD; // "large literal": This opcode has no match, and uses the previous match // distance (i.e. it encodes only the match length). It is encoded in two @@ -371,20 +621,35 @@ PTR_LEN_INC(src_ptr, src_len, L); // Load the first byte of the next opcode, and jump to its implementation. opc = src_ptr[0]; +#if HAVE_LABELS_AS_VALUES goto *opc_tbl[opc]; +#else + break; +#endif // =============================================================== // Other opcodes nop: +#if !HAVE_LABELS_AS_VALUES + case 6: + case 14: +#endif UPDATE_GOOD; opc_len = 1; if (src_len <= opc_len) return; // source truncated PTR_LEN_INC(src_ptr, src_len, opc_len); opc = src_ptr[0]; +#if HAVE_LABELS_AS_VALUES goto *opc_tbl[opc]; +#else + break; +#endif eos: +#if !HAVE_LABELS_AS_VALUES + case 22: +#endif opc_len = 8; if (src_len < opc_len) return; // source truncated (here we don't need an extra byte for next op @@ -397,7 +662,50 @@ // =============================================================== // Return on error udef: +#if !HAVE_LABELS_AS_VALUES + case 30: + case 38: + case 46: + case 54: + case 62: + case 112: + case 113: + case 114: + case 115: + case 116: + case 117: + case 118: + case 119: + case 120: + case 121: + case 122: + case 123: + case 124: + case 125: + case 126: + case 127: + case 208: + case 209: + case 210: + case 211: + case 212: + case 213: + case 214: + case 215: + case 216: + case 217: + case 218: + case 219: + case 220: + case 221: + case 222: + case 223: +#endif invalid_match_distance: return; // we already updated state +#if !HAVE_LABELS_AS_VALUES + } + } +#endif } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lzfse-0.0+git.20160620/src/lzvn_encode_base.c new/lzfse-0.0+git.20160802/src/lzvn_encode_base.c --- old/lzfse-0.0+git.20160620/src/lzvn_encode_base.c 2016-07-11 17:41:16.000000000 +0200 +++ new/lzfse-0.0+git.20160802/src/lzvn_encode_base.c 2016-08-03 04:09:30.000000000 +0200 @@ -1,7 +1,7 @@ /* Copyright (c) 2015-2016, Apple Inc. All rights reserved. -Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: +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. @@ -23,6 +23,10 @@ #include "lzvn_encode_base.h" +#if defined(_MSC_VER) && !defined(__clang__) +# define restrict __restrict +#endif + // =============================================================== // Coarse/fine copy, non overlapping buffers @@ -554,7 +558,7 @@ state.src_current = 0; state.dst = dst; state.dst_begin = dst; - state.dst_end = dst + dst_size - 8; // reserve 8 bytes for end-of-stream + state.dst_end = (unsigned char *)dst + dst_size - 8; // reserve 8 bytes for end-of-stream state.table = work; // Do not encode if the input buffer is too small. We'll emit a literal instead. @@ -571,7 +575,7 @@ lzvn_emit_literal(&state, state.src_end - state.src_literal); // Restore original size, so end-of-stream always succeeds, and emit it - state.dst_end = dst + dst_size; + state.dst_end = (unsigned char *)dst + dst_size; lzvn_emit_end_of_stream(&state); *src_used = state.src_literal;
