]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools LzmaCompress: Update LZMA to new 16.04 version
authorLiming Gao <liming.gao@intel.com>
Thu, 27 Oct 2016 06:50:54 +0000 (14:50 +0800)
committerLiming Gao <liming.gao@intel.com>
Thu, 3 Nov 2016 02:21:15 +0000 (10:21 +0800)
New version LZMA SDK improves the compression performance on windows OS,
and has no change on the compression ratio. I compress 8M FVMAIN image,
the compression time is reduced from 2.590s to 1.419s.

Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Liming Gao <liming.gao@intel.com>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
32 files changed:
BaseTools/Source/C/LzmaCompress/GNUmakefile
BaseTools/Source/C/LzmaCompress/LZMA-SDK-README.txt
BaseTools/Source/C/LzmaCompress/LzmaCompress.c
BaseTools/Source/C/LzmaCompress/Makefile
BaseTools/Source/C/LzmaCompress/Sdk/C/7zFile.c
BaseTools/Source/C/LzmaCompress/Sdk/C/7zFile.h
BaseTools/Source/C/LzmaCompress/Sdk/C/7zStream.c
BaseTools/Source/C/LzmaCompress/Sdk/C/7zTypes.h [new file with mode: 0644]
BaseTools/Source/C/LzmaCompress/Sdk/C/7zVersion.h
BaseTools/Source/C/LzmaCompress/Sdk/C/Alloc.c
BaseTools/Source/C/LzmaCompress/Sdk/C/Alloc.h
BaseTools/Source/C/LzmaCompress/Sdk/C/Bra.h
BaseTools/Source/C/LzmaCompress/Sdk/C/Bra86.c
BaseTools/Source/C/LzmaCompress/Sdk/C/Compiler.h [new file with mode: 0644]
BaseTools/Source/C/LzmaCompress/Sdk/C/CpuArch.h
BaseTools/Source/C/LzmaCompress/Sdk/C/LzFind.c
BaseTools/Source/C/LzmaCompress/Sdk/C/LzFind.h
BaseTools/Source/C/LzmaCompress/Sdk/C/LzFindMt.c
BaseTools/Source/C/LzmaCompress/Sdk/C/LzFindMt.h
BaseTools/Source/C/LzmaCompress/Sdk/C/LzHash.h
BaseTools/Source/C/LzmaCompress/Sdk/C/LzmaDec.c
BaseTools/Source/C/LzmaCompress/Sdk/C/LzmaDec.h
BaseTools/Source/C/LzmaCompress/Sdk/C/LzmaEnc.c
BaseTools/Source/C/LzmaCompress/Sdk/C/LzmaEnc.h
BaseTools/Source/C/LzmaCompress/Sdk/C/Precomp.h [new file with mode: 0644]
BaseTools/Source/C/LzmaCompress/Sdk/C/Threads.c
BaseTools/Source/C/LzmaCompress/Sdk/C/Threads.h
BaseTools/Source/C/LzmaCompress/Sdk/C/Types.h [deleted file]
BaseTools/Source/C/LzmaCompress/Sdk/DOC/lzma-history.txt [new file with mode: 0644]
BaseTools/Source/C/LzmaCompress/Sdk/DOC/lzma-sdk.txt [new file with mode: 0644]
BaseTools/Source/C/LzmaCompress/Sdk/history.txt [deleted file]
BaseTools/Source/C/LzmaCompress/Sdk/lzma.txt [deleted file]

index 21c75ef7df5dc3124754ecf7c29f4ba1df02ca1d..63d7ee0bc3439673fe89300bb781e185e9e433d0 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # GNU/Linux makefile for 'LzmaCompress' module build.\r
 #\r
-# Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>\r
 # This program and the accompanying materials\r
 # are licensed and made available under the terms and conditions of the BSD License\r
 # which accompanies this distribution.  The full text of the license may be found at\r
@@ -29,3 +29,4 @@ OBJECTS = \
 \r
 include $(MAKEROOT)/Makefiles/app.makefile\r
 \r
+BUILD_CFLAGS += -D_7ZIP_ST\r
index e0476ad9944cab93c104d5ae4fd6143de346c071..6882e7465b39ebbe91d262948d67639993a04ee0 100644 (file)
@@ -1,3 +1,3 @@
-LzmaCompress is based on the LZMA SDK 4.65.  LZMA SDK 4.65\r
-was placed in the public domain on 2009-02-03.  It was\r
+LzmaCompress is based on the LZMA SDK 16.04.  LZMA SDK 16.04\r
+was placed in the public domain on 2016-10-04.  It was\r
 released on the http://www.7-zip.org/sdk.html website.
\ No newline at end of file
index 1de07a35411ad1bdea5d7ce5241e21747d117b2f..aff0bed2c80830c118af1fc69ff8c5cbb99a5562 100644 (file)
@@ -1,11 +1,11 @@
 /** @file\r
   LZMA Compress/Decompress tool (LzmaCompress)\r
 \r
-  Based on LZMA SDK 4.65:\r
+  Based on LZMA SDK 16.04:\r
     LzmaUtil.c -- Test application for LZMA compression\r
-    2008-11-23 : Igor Pavlov : Public domain\r
+    2016-10-04 : Igor Pavlov : Public domain\r
 \r
-  Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -43,10 +43,6 @@ const char *kCantWriteMessage = "Can not write output file";
 const char *kCantAllocateMessage = "Can not allocate memory";\r
 const char *kDataErrorMessage = "Data error";\r
 \r
-static void *SzAlloc(void *p, size_t size) { (void)p; return MyAlloc(size); }\r
-static void SzFree(void *p, void *address) { (void)p; MyFree(address); }\r
-static ISzAlloc g_Alloc = { SzAlloc, SzFree };\r
-\r
 static Bool mQuietMode = False;\r
 static CONVERTER_TYPE mConType = NoConverter;\r
 \r
@@ -54,7 +50,7 @@ static CONVERTER_TYPE mConType = NoConverter;
 #define UTILITY_MAJOR_VERSION 0\r
 #define UTILITY_MINOR_VERSION 2\r
 #define INTEL_COPYRIGHT \\r
-  "Copyright (c) 2009-2012, Intel Corporation. All rights reserved."\r
+  "Copyright (c) 2009-2016, Intel Corporation. All rights reserved."\r
 void PrintHelp(char *buffer)\r
 {\r
   strcat(buffer,\r
index 872e8995128122b5f167187b1e219af090c647fb..48aca88913738cb49c88d397a8752a8ab4a180f6 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # Windows makefile for 'LzmaCompress' module build.\r
 #\r
-# Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>\r
 # This program and the accompanying materials\r
 # are licensed and made available under the terms and conditions of the BSD License\r
 # which accompanies this distribution.  The full text of the license may be found at\r
@@ -26,7 +26,9 @@ OBJECTS = \
   $(SDK_C)\LzmaEnc.obj \\r
   $(SDK_C)\7zFile.obj \\r
   $(SDK_C)\7zStream.obj \\r
-  $(SDK_C)\Bra86.obj\r
+  $(SDK_C)\Bra86.obj \\r
+  $(SDK_C)\LzFindMt.obj \\r
+  $(SDK_C)\Threads.obj\r
 \r
 !INCLUDE ..\Makefiles\ms.app\r
 \r
index 2b605a5665876d55d8183e14df153faa89c7a62b..98fe7164f56f85d4819f5a4921a7e8a9a49f05a7 100644 (file)
@@ -1,15 +1,17 @@
 /* 7zFile.c -- File IO\r
-2008-11-22 : Igor Pavlov : Public domain */\r
+2009-11-24 : Igor Pavlov : Public domain */\r
+\r
+#include "Precomp.h"\r
 \r
 #include "7zFile.h"\r
 \r
 #ifndef USE_WINDOWS_FILE\r
 \r
+#ifndef UNDER_CE\r
 #include <errno.h>\r
-\r
 #endif\r
 \r
-#ifdef USE_WINDOWS_FILE\r
+#else\r
 \r
 /*\r
    ReadFile and WriteFile functions in Windows have BUG:\r
@@ -34,6 +36,7 @@ void File_Construct(CSzFile *p)
   #endif\r
 }\r
 \r
+#if !defined(UNDER_CE) || !defined(USE_WINDOWS_FILE)\r
 static WRes File_Open(CSzFile *p, const char *name, int writeMode)\r
 {\r
   #ifdef USE_WINDOWS_FILE\r
@@ -45,12 +48,32 @@ static WRes File_Open(CSzFile *p, const char *name, int writeMode)
   return (p->handle != INVALID_HANDLE_VALUE) ? 0 : GetLastError();\r
   #else\r
   p->file = fopen(name, writeMode ? "wb+" : "rb");\r
-  return (p->file != 0) ? 0 : errno;\r
+  return (p->file != 0) ? 0 :\r
+    #ifdef UNDER_CE\r
+    2; /* ENOENT */\r
+    #else\r
+    errno;\r
+    #endif\r
   #endif\r
 }\r
 \r
 WRes InFile_Open(CSzFile *p, const char *name) { return File_Open(p, name, 0); }\r
 WRes OutFile_Open(CSzFile *p, const char *name) { return File_Open(p, name, 1); }\r
+#endif\r
+\r
+#ifdef USE_WINDOWS_FILE\r
+static WRes File_OpenW(CSzFile *p, const WCHAR *name, int writeMode)\r
+{\r
+  p->handle = CreateFileW(name,\r
+      writeMode ? GENERIC_WRITE : GENERIC_READ,\r
+      FILE_SHARE_READ, NULL,\r
+      writeMode ? CREATE_ALWAYS : OPEN_EXISTING,\r
+      FILE_ATTRIBUTE_NORMAL, NULL);\r
+  return (p->handle != INVALID_HANDLE_VALUE) ? 0 : GetLastError();\r
+}\r
+WRes InFile_OpenW(CSzFile *p, const WCHAR *name) { return File_OpenW(p, name, 0); }\r
+WRes OutFile_OpenW(CSzFile *p, const WCHAR *name) { return File_OpenW(p, name, 1); }\r
+#endif\r
 \r
 WRes File_Close(CSzFile *p)\r
 {\r
index 4fd2936cc3fca985b09c0712c66d36c709f4e8f1..d62a192609240fa9db5545358f41afe0aa2408ed 100644 (file)
@@ -1,5 +1,5 @@
 /* 7zFile.h -- File IO\r
-2008-11-22 : Igor Pavlov : Public domain */\r
+2013-01-18 : Igor Pavlov : Public domain */\r
 \r
 #ifndef __7Z_FILE_H\r
 #define __7Z_FILE_H\r
@@ -14,8 +14,9 @@
 #include <stdio.h>\r
 #endif\r
 \r
-#include "Types.h"\r
+#include "7zTypes.h"\r
 \r
+EXTERN_C_BEGIN\r
 \r
 /* ---------- File ---------- */\r
 \r
@@ -29,8 +30,14 @@ typedef struct
 } CSzFile;\r
 \r
 void File_Construct(CSzFile *p);\r
+#if !defined(UNDER_CE) || !defined(USE_WINDOWS_FILE)\r
 WRes InFile_Open(CSzFile *p, const char *name);\r
 WRes OutFile_Open(CSzFile *p, const char *name);\r
+#endif\r
+#ifdef USE_WINDOWS_FILE\r
+WRes InFile_OpenW(CSzFile *p, const WCHAR *name);\r
+WRes OutFile_OpenW(CSzFile *p, const WCHAR *name);\r
+#endif\r
 WRes File_Close(CSzFile *p);\r
 \r
 /* reads max(*size, remain file's size) bytes */\r
@@ -71,4 +78,6 @@ typedef struct
 \r
 void FileOutStream_CreateVTable(CFileOutStream *p);\r
 \r
+EXTERN_C_END\r
+\r
 #endif\r
index a0a2405d014a3f5e6e16219846df1725c6fdc679..5a92d532ccaa8887c223584bedc711e436743f69 100644 (file)
@@ -1,9 +1,11 @@
 /* 7zStream.c -- 7z Stream functions\r
-2008-11-23 : Igor Pavlov : Public domain */\r
+2013-11-12 : Igor Pavlov : Public domain */\r
+\r
+#include "Precomp.h"\r
 \r
 #include <string.h>\r
 \r
-#include "Types.h"\r
+#include "7zTypes.h"\r
 \r
 SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType)\r
 {\r
@@ -39,7 +41,7 @@ SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset)
 \r
 SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size)\r
 {\r
-  void *lookBuf;\r
+  const void *lookBuf;\r
   if (*size == 0)\r
     return SZ_OK;\r
   RINOK(stream->Look(stream, &lookBuf, size));\r
@@ -66,7 +68,7 @@ SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size)
   return LookInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF);\r
 }\r
 \r
-static SRes LookToRead_Look_Lookahead(void *pp, void **buf, size_t *size)\r
+static SRes LookToRead_Look_Lookahead(void *pp, const void **buf, size_t *size)\r
 {\r
   SRes res = SZ_OK;\r
   CLookToRead *p = (CLookToRead *)pp;\r
@@ -84,7 +86,7 @@ static SRes LookToRead_Look_Lookahead(void *pp, void **buf, size_t *size)
   return res;\r
 }\r
 \r
-static SRes LookToRead_Look_Exact(void *pp, void **buf, size_t *size)\r
+static SRes LookToRead_Look_Exact(void *pp, const void **buf, size_t *size)\r
 {\r
   SRes res = SZ_OK;\r
   CLookToRead *p = (CLookToRead *)pp;\r
diff --git a/BaseTools/Source/C/LzmaCompress/Sdk/C/7zTypes.h b/BaseTools/Source/C/LzmaCompress/Sdk/C/7zTypes.h
new file mode 100644 (file)
index 0000000..903047b
--- /dev/null
@@ -0,0 +1,256 @@
+/* 7zTypes.h -- Basic types\r
+2013-11-12 : Igor Pavlov : Public domain */\r
+\r
+#ifndef __7Z_TYPES_H\r
+#define __7Z_TYPES_H\r
+\r
+#ifdef _WIN32\r
+/* #include <windows.h> */\r
+#endif\r
+\r
+#include <stddef.h>\r
+\r
+#ifndef EXTERN_C_BEGIN\r
+#ifdef __cplusplus\r
+#define EXTERN_C_BEGIN extern "C" {\r
+#define EXTERN_C_END }\r
+#else\r
+#define EXTERN_C_BEGIN\r
+#define EXTERN_C_END\r
+#endif\r
+#endif\r
+\r
+EXTERN_C_BEGIN\r
+\r
+#define SZ_OK 0\r
+\r
+#define SZ_ERROR_DATA 1\r
+#define SZ_ERROR_MEM 2\r
+#define SZ_ERROR_CRC 3\r
+#define SZ_ERROR_UNSUPPORTED 4\r
+#define SZ_ERROR_PARAM 5\r
+#define SZ_ERROR_INPUT_EOF 6\r
+#define SZ_ERROR_OUTPUT_EOF 7\r
+#define SZ_ERROR_READ 8\r
+#define SZ_ERROR_WRITE 9\r
+#define SZ_ERROR_PROGRESS 10\r
+#define SZ_ERROR_FAIL 11\r
+#define SZ_ERROR_THREAD 12\r
+\r
+#define SZ_ERROR_ARCHIVE 16\r
+#define SZ_ERROR_NO_ARCHIVE 17\r
+\r
+typedef int SRes;\r
+\r
+#ifdef _WIN32\r
+/* typedef DWORD WRes; */\r
+typedef unsigned WRes;\r
+#else\r
+typedef int WRes;\r
+#endif\r
+\r
+#ifndef RINOK\r
+#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }\r
+#endif\r
+\r
+typedef unsigned char Byte;\r
+typedef short Int16;\r
+typedef unsigned short UInt16;\r
+\r
+#ifdef _LZMA_UINT32_IS_ULONG\r
+typedef long Int32;\r
+typedef unsigned long UInt32;\r
+#else\r
+typedef int Int32;\r
+typedef unsigned int UInt32;\r
+#endif\r
+\r
+#ifdef _SZ_NO_INT_64\r
+\r
+/* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.\r
+   NOTES: Some code will work incorrectly in that case! */\r
+\r
+typedef long Int64;\r
+typedef unsigned long UInt64;\r
+\r
+#else\r
+\r
+#if defined(_MSC_VER) || defined(__BORLANDC__)\r
+typedef __int64 Int64;\r
+typedef unsigned __int64 UInt64;\r
+#define UINT64_CONST(n) n\r
+#else\r
+typedef long long int Int64;\r
+typedef unsigned long long int UInt64;\r
+#define UINT64_CONST(n) n ## ULL\r
+#endif\r
+\r
+#endif\r
+\r
+#ifdef _LZMA_NO_SYSTEM_SIZE_T\r
+typedef UInt32 SizeT;\r
+#else\r
+typedef size_t SizeT;\r
+#endif\r
+\r
+typedef int Bool;\r
+#define True 1\r
+#define False 0\r
+\r
+\r
+#ifdef _WIN32\r
+#define MY_STD_CALL __stdcall\r
+#else\r
+#define MY_STD_CALL\r
+#endif\r
+\r
+#ifdef _MSC_VER\r
+\r
+#if _MSC_VER >= 1300\r
+#define MY_NO_INLINE __declspec(noinline)\r
+#else\r
+#define MY_NO_INLINE\r
+#endif\r
+\r
+#define MY_CDECL __cdecl\r
+#define MY_FAST_CALL __fastcall\r
+\r
+#else\r
+\r
+#define MY_NO_INLINE\r
+#define MY_CDECL\r
+#define MY_FAST_CALL\r
+\r
+#endif\r
+\r
+\r
+/* The following interfaces use first parameter as pointer to structure */\r
+\r
+typedef struct\r
+{\r
+  Byte (*Read)(void *p); /* reads one byte, returns 0 in case of EOF or error */\r
+} IByteIn;\r
+\r
+typedef struct\r
+{\r
+  void (*Write)(void *p, Byte b);\r
+} IByteOut;\r
+\r
+typedef struct\r
+{\r
+  SRes (*Read)(void *p, void *buf, size_t *size);\r
+    /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.\r
+       (output(*size) < input(*size)) is allowed */\r
+} ISeqInStream;\r
+\r
+/* it can return SZ_ERROR_INPUT_EOF */\r
+SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size);\r
+SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType);\r
+SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf);\r
+\r
+typedef struct\r
+{\r
+  size_t (*Write)(void *p, const void *buf, size_t size);\r
+    /* Returns: result - the number of actually written bytes.\r
+       (result < size) means error */\r
+} ISeqOutStream;\r
+\r
+typedef enum\r
+{\r
+  SZ_SEEK_SET = 0,\r
+  SZ_SEEK_CUR = 1,\r
+  SZ_SEEK_END = 2\r
+} ESzSeek;\r
+\r
+typedef struct\r
+{\r
+  SRes (*Read)(void *p, void *buf, size_t *size);  /* same as ISeqInStream::Read */\r
+  SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);\r
+} ISeekInStream;\r
+\r
+typedef struct\r
+{\r
+  SRes (*Look)(void *p, const void **buf, size_t *size);\r
+    /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.\r
+       (output(*size) > input(*size)) is not allowed\r
+       (output(*size) < input(*size)) is allowed */\r
+  SRes (*Skip)(void *p, size_t offset);\r
+    /* offset must be <= output(*size) of Look */\r
+\r
+  SRes (*Read)(void *p, void *buf, size_t *size);\r
+    /* reads directly (without buffer). It's same as ISeqInStream::Read */\r
+  SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);\r
+} ILookInStream;\r
+\r
+SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size);\r
+SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset);\r
+\r
+/* reads via ILookInStream::Read */\r
+SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType);\r
+SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size);\r
+\r
+#define LookToRead_BUF_SIZE (1 << 14)\r
+\r
+typedef struct\r
+{\r
+  ILookInStream s;\r
+  ISeekInStream *realStream;\r
+  size_t pos;\r
+  size_t size;\r
+  Byte buf[LookToRead_BUF_SIZE];\r
+} CLookToRead;\r
+\r
+void LookToRead_CreateVTable(CLookToRead *p, int lookahead);\r
+void LookToRead_Init(CLookToRead *p);\r
+\r
+typedef struct\r
+{\r
+  ISeqInStream s;\r
+  ILookInStream *realStream;\r
+} CSecToLook;\r
+\r
+void SecToLook_CreateVTable(CSecToLook *p);\r
+\r
+typedef struct\r
+{\r
+  ISeqInStream s;\r
+  ILookInStream *realStream;\r
+} CSecToRead;\r
+\r
+void SecToRead_CreateVTable(CSecToRead *p);\r
+\r
+typedef struct\r
+{\r
+  SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);\r
+    /* Returns: result. (result != SZ_OK) means break.\r
+       Value (UInt64)(Int64)-1 for size means unknown value. */\r
+} ICompressProgress;\r
+\r
+typedef struct\r
+{\r
+  void *(*Alloc)(void *p, size_t size);\r
+  void (*Free)(void *p, void *address); /* address can be 0 */\r
+} ISzAlloc;\r
+\r
+#define IAlloc_Alloc(p, size) (p)->Alloc((p), size)\r
+#define IAlloc_Free(p, a) (p)->Free((p), a)\r
+\r
+#ifdef _WIN32\r
+\r
+#define CHAR_PATH_SEPARATOR '\\'\r
+#define WCHAR_PATH_SEPARATOR L'\\'\r
+#define STRING_PATH_SEPARATOR "\\"\r
+#define WSTRING_PATH_SEPARATOR L"\\"\r
+\r
+#else\r
+\r
+#define CHAR_PATH_SEPARATOR '/'\r
+#define WCHAR_PATH_SEPARATOR L'/'\r
+#define STRING_PATH_SEPARATOR "/"\r
+#define WSTRING_PATH_SEPARATOR L"/"\r
+\r
+#endif\r
+\r
+EXTERN_C_END\r
+\r
+#endif\r
index 5a6bcadac6784ab39bd6730f74e1985b1ec3c3fd..acb67a94e5db1f9bbb1bf37f3c3e8a765176ee6c 100644 (file)
@@ -1,7 +1,19 @@
-#define MY_VER_MAJOR 4\r
-#define MY_VER_MINOR 65\r
+#define MY_VER_MAJOR 16\r
+#define MY_VER_MINOR 04\r
 #define MY_VER_BUILD 0\r
-#define MY_VERSION "4.65"\r
-#define MY_DATE "2009-02-03"\r
-#define MY_COPYRIGHT ": Igor Pavlov : Public domain"\r
-#define MY_VERSION_COPYRIGHT_DATE MY_VERSION " " MY_COPYRIGHT " : " MY_DATE\r
+#define MY_VERSION_NUMBERS "16.04"\r
+#define MY_VERSION "16.04"\r
+#define MY_DATE "2016-10-04"\r
+#undef MY_COPYRIGHT\r
+#undef MY_VERSION_COPYRIGHT_DATE\r
+#define MY_AUTHOR_NAME "Igor Pavlov"\r
+#define MY_COPYRIGHT_PD "Igor Pavlov : Public domain"\r
+#define MY_COPYRIGHT_CR "Copyright (c) 1999-2016 Igor Pavlov"\r
+\r
+#ifdef USE_COPYRIGHT_CR\r
+  #define MY_COPYRIGHT MY_COPYRIGHT_CR\r
+#else\r
+  #define MY_COPYRIGHT MY_COPYRIGHT_PD\r
+#endif\r
+\r
+#define MY_VERSION_COPYRIGHT_DATE MY_VERSION " : " MY_COPYRIGHT " : " MY_DATE\r
index bb24a772b340c9abfd925de3678c85b64273326a..9f1d036afe9759640c0b481cc0654b64ca4efcc3 100644 (file)
@@ -1,7 +1,7 @@
 /* Alloc.c -- Memory allocation functions\r
-2008-09-24\r
-Igor Pavlov\r
-Public domain */\r
+2015-02-21 : Igor Pavlov : Public domain */\r
+\r
+#include "Precomp.h"\r
 \r
 #ifdef _WIN32\r
 #include <windows.h>\r
@@ -125,3 +125,12 @@ void BigFree(void *address)
 }\r
 \r
 #endif\r
+\r
+\r
+static void *SzAlloc(void *p, size_t size) { UNUSED_VAR(p); return MyAlloc(size); }\r
+static void SzFree(void *p, void *address) { UNUSED_VAR(p); MyFree(address); }\r
+ISzAlloc g_Alloc = { SzAlloc, SzFree };\r
+\r
+static void *SzBigAlloc(void *p, size_t size) { UNUSED_VAR(p); return BigAlloc(size); }\r
+static void SzBigFree(void *p, void *address) { UNUSED_VAR(p); BigFree(address); }\r
+ISzAlloc g_BigAlloc = { SzBigAlloc, SzBigFree };\r
index a396c6b9e1f5530151b6cd4bcb1c55647f50713b..73b282a07152082afdd544f2429082d35f0741f0 100644 (file)
@@ -1,12 +1,12 @@
 /* Alloc.h -- Memory allocation functions\r
-2008-03-13\r
-Igor Pavlov\r
-Public domain */\r
+2015-02-21 : Igor Pavlov : Public domain */\r
 \r
 #ifndef __COMMON_ALLOC_H\r
 #define __COMMON_ALLOC_H\r
 \r
-#include <stddef.h>\r
+#include "7zTypes.h"\r
+\r
+EXTERN_C_BEGIN\r
 \r
 void *MyAlloc(size_t size);\r
 void MyFree(void *address);\r
@@ -29,4 +29,9 @@ void BigFree(void *address);
 \r
 #endif\r
 \r
+extern ISzAlloc g_Alloc;\r
+extern ISzAlloc g_BigAlloc;\r
+\r
+EXTERN_C_END\r
+\r
 #endif\r
index b9018eb991f5712d917b8e11b3f2b3a2fe36b4a5..aba8dce14f19cf33840b18d92a376789d920360d 100644 (file)
@@ -1,10 +1,12 @@
 /* Bra.h -- Branch converters for executables\r
-2008-10-04 : Igor Pavlov : Public domain */\r
+2013-01-18 : Igor Pavlov : Public domain */\r
 \r
 #ifndef __BRA_H\r
 #define __BRA_H\r
 \r
-#include "Types.h"\r
+#include "7zTypes.h"\r
+\r
+EXTERN_C_BEGIN\r
 \r
 /*\r
 These functions convert relative addresses to absolute addresses\r
@@ -57,4 +59,6 @@ SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
 SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);\r
 SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);\r
 \r
+EXTERN_C_END\r
+\r
 #endif\r
index 93566cb212043d435b367b250e41ba39292a2255..8dd3ed48d9aba8788489a5ba4ec3fb102694a4b7 100644 (file)
@@ -1,85 +1,82 @@
 /* Bra86.c -- Converter for x86 code (BCJ)\r
-2008-10-04 : Igor Pavlov : Public domain */\r
+2013-11-12 : Igor Pavlov : Public domain */\r
 \r
-#include "Bra.h"\r
+#include "Precomp.h"\r
 \r
-#define Test86MSByte(b) ((b) == 0 || (b) == 0xFF)\r
+#include "Bra.h"\r
 \r
-const Byte kMaskToAllowedStatus[8] = {1, 1, 1, 0, 1, 0, 0, 0};\r
-const Byte kMaskToBitNumber[8] = {0, 1, 2, 2, 3, 3, 3, 3};\r
+#define Test86MSByte(b) ((((b) + 1) & 0xFE) == 0)\r
 \r
 SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding)\r
 {\r
-  SizeT bufferPos = 0, prevPosT;\r
-  UInt32 prevMask = *state & 0x7;\r
+  SizeT pos = 0;\r
+  UInt32 mask = *state & 7;\r
   if (size < 5)\r
     return 0;\r
+  size -= 4;\r
   ip += 5;\r
-  prevPosT = (SizeT)0 - 1;\r
 \r
   for (;;)\r
   {\r
-    Byte *p = data + bufferPos;\r
-    Byte *limit = data + size - 4;\r
+    Byte *p = data + pos;\r
+    const Byte *limit = data + size;\r
     for (; p < limit; p++)\r
       if ((*p & 0xFE) == 0xE8)\r
         break;\r
-    bufferPos = (SizeT)(p - data);\r
-    if (p >= limit)\r
-      break;\r
-    prevPosT = bufferPos - prevPosT;\r
-    if (prevPosT > 3)\r
-      prevMask = 0;\r
-    else\r
+\r
     {\r
-      prevMask = (prevMask << ((int)prevPosT - 1)) & 0x7;\r
-      if (prevMask != 0)\r
+      SizeT d = (SizeT)(p - data - pos);\r
+      pos = (SizeT)(p - data);\r
+      if (p >= limit)\r
       {\r
-        Byte b = p[4 - kMaskToBitNumber[prevMask]];\r
-        if (!kMaskToAllowedStatus[prevMask] || Test86MSByte(b))\r
+        *state = (d > 2 ? 0 : mask >> (unsigned)d);\r
+        return pos;\r
+      }\r
+      if (d > 2)\r
+        mask = 0;\r
+      else\r
+      {\r
+        mask >>= (unsigned)d;\r
+        if (mask != 0 && (mask > 4 || mask == 3 || Test86MSByte(p[(mask >> 1) + 1])))\r
         {\r
-          prevPosT = bufferPos;\r
-          prevMask = ((prevMask << 1) & 0x7) | 1;\r
-          bufferPos++;\r
+          mask = (mask >> 1) | 4;\r
+          pos++;\r
           continue;\r
         }\r
       }\r
     }\r
-    prevPosT = bufferPos;\r
 \r
     if (Test86MSByte(p[4]))\r
     {\r
-      UInt32 src = ((UInt32)p[4] << 24) | ((UInt32)p[3] << 16) | ((UInt32)p[2] << 8) | ((UInt32)p[1]);\r
-      UInt32 dest;\r
-      for (;;)\r
+      UInt32 v = ((UInt32)p[4] << 24) | ((UInt32)p[3] << 16) | ((UInt32)p[2] << 8) | ((UInt32)p[1]);\r
+      UInt32 cur = ip + (UInt32)pos;\r
+      pos += 5;\r
+      if (encoding)\r
+        v += cur;\r
+      else\r
+        v -= cur;\r
+      if (mask != 0)\r
       {\r
-        Byte b;\r
-        int index;\r
-        if (encoding)\r
-          dest = (ip + (UInt32)bufferPos) + src;\r
-        else\r
-          dest = src - (ip + (UInt32)bufferPos);\r
-        if (prevMask == 0)\r
-          break;\r
-        index = kMaskToBitNumber[prevMask] * 8;\r
-        b = (Byte)(dest >> (24 - index));\r
-        if (!Test86MSByte(b))\r
-          break;\r
-        src = dest ^ ((1 << (32 - index)) - 1);\r
+        unsigned sh = (mask & 6) << 2;\r
+        if (Test86MSByte((Byte)(v >> sh)))\r
+        {\r
+          v ^= (((UInt32)0x100 << sh) - 1);\r
+          if (encoding)\r
+            v += cur;\r
+          else\r
+            v -= cur;\r
+        }\r
+        mask = 0;\r
       }\r
-      p[4] = (Byte)(~(((dest >> 24) & 1) - 1));\r
-      p[3] = (Byte)(dest >> 16);\r
-      p[2] = (Byte)(dest >> 8);\r
-      p[1] = (Byte)dest;\r
-      bufferPos += 5;\r
+      p[1] = (Byte)v;\r
+      p[2] = (Byte)(v >> 8);\r
+      p[3] = (Byte)(v >> 16);\r
+      p[4] = (Byte)(0 - ((v >> 24) & 1));\r
     }\r
     else\r
     {\r
-      prevMask = ((prevMask << 1) & 0x7) | 1;\r
-      bufferPos++;\r
+      mask = (mask >> 1) | 4;\r
+      pos++;\r
     }\r
   }\r
-  prevPosT = bufferPos - prevPosT;\r
-  *state = ((prevPosT > 3) ? 0 : ((prevMask << ((int)prevPosT - 1)) & 0x7));\r
-  return bufferPos;\r
 }\r
diff --git a/BaseTools/Source/C/LzmaCompress/Sdk/C/Compiler.h b/BaseTools/Source/C/LzmaCompress/Sdk/C/Compiler.h
new file mode 100644 (file)
index 0000000..de8fab3
--- /dev/null
@@ -0,0 +1,32 @@
+/* Compiler.h\r
+2015-08-02 : Igor Pavlov : Public domain */\r
+\r
+#ifndef __7Z_COMPILER_H\r
+#define __7Z_COMPILER_H\r
+\r
+#ifdef _MSC_VER\r
+\r
+  #ifdef UNDER_CE\r
+    #define RPC_NO_WINDOWS_H\r
+    /* #pragma warning(disable : 4115) // '_RPC_ASYNC_STATE' : named type definition in parentheses */\r
+    #pragma warning(disable : 4201) // nonstandard extension used : nameless struct/union\r
+    #pragma warning(disable : 4214) // nonstandard extension used : bit field types other than int\r
+  #endif\r
+\r
+  #if _MSC_VER >= 1300\r
+    #pragma warning(disable : 4996) // This function or variable may be unsafe\r
+  #else\r
+    #pragma warning(disable : 4511) // copy constructor could not be generated\r
+    #pragma warning(disable : 4512) // assignment operator could not be generated\r
+    #pragma warning(disable : 4514) // unreferenced inline function has been removed\r
+    #pragma warning(disable : 4702) // unreachable code\r
+    #pragma warning(disable : 4710) // not inlined\r
+    #pragma warning(disable : 4786) // identifier was truncated to '255' characters in the debug information\r
+  #endif\r
+\r
+#endif\r
+\r
+#define UNUSED_VAR(x) (void)x;\r
+/* #define UNUSED_VAR(x) x=x; */\r
+\r
+#endif\r
index 006361f2f2de769f2731f9e3840f1dbf7906946f..ef6083c3b8ba468bb4c793c774c28c2fea757a90 100644 (file)
-/* CpuArch.h\r
-2008-08-05\r
-Igor Pavlov\r
-Public domain */\r
+/* CpuArch.h -- CPU specific code\r
+2016-06-09: Igor Pavlov : Public domain */\r
 \r
-#ifndef __CPUARCH_H\r
-#define __CPUARCH_H\r
+#ifndef __CPU_ARCH_H\r
+#define __CPU_ARCH_H\r
+\r
+#include "7zTypes.h"\r
+\r
+EXTERN_C_BEGIN\r
 \r
 /*\r
-LITTLE_ENDIAN_UNALIGN means:\r
-  1) CPU is LITTLE_ENDIAN\r
-  2) it's allowed to make unaligned memory accesses\r
-if LITTLE_ENDIAN_UNALIGN is not defined, it means that we don't know\r
-about these properties of platform.\r
+MY_CPU_LE means that CPU is LITTLE ENDIAN.\r
+MY_CPU_BE means that CPU is BIG ENDIAN.\r
+If MY_CPU_LE and MY_CPU_BE are not defined, we don't know about ENDIANNESS of platform.\r
+\r
+MY_CPU_LE_UNALIGN means that CPU is LITTLE ENDIAN and CPU supports unaligned memory accesses.\r
 */\r
 \r
-#if defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64) || defined(__i386__) || defined(__x86_64__)\r
-#define LITTLE_ENDIAN_UNALIGN\r
+#if defined(_M_X64) \\r
+   || defined(_M_AMD64) \\r
+   || defined(__x86_64__) \\r
+   || defined(__AMD64__) \\r
+   || defined(__amd64__)\r
+  #define MY_CPU_AMD64\r
+#endif\r
+\r
+#if defined(MY_CPU_AMD64) \\r
+    || defined(_M_IA64) \\r
+    || defined(__AARCH64EL__) \\r
+    || defined(__AARCH64EB__)\r
+  #define MY_CPU_64BIT\r
+#endif\r
+\r
+#if defined(_M_IX86) || defined(__i386__)\r
+#define MY_CPU_X86\r
+#endif\r
+\r
+#if defined(MY_CPU_X86) || defined(MY_CPU_AMD64)\r
+#define MY_CPU_X86_OR_AMD64\r
+#endif\r
+\r
+#if defined(MY_CPU_X86) \\r
+    || defined(_M_ARM) \\r
+    || defined(__ARMEL__) \\r
+    || defined(__THUMBEL__) \\r
+    || defined(__ARMEB__) \\r
+    || defined(__THUMBEB__)\r
+  #define MY_CPU_32BIT\r
+#endif\r
+\r
+#if defined(_WIN32) && defined(_M_ARM)\r
+#define MY_CPU_ARM_LE\r
 #endif\r
 \r
-#ifdef LITTLE_ENDIAN_UNALIGN\r
+#if defined(_WIN32) && defined(_M_IA64)\r
+#define MY_CPU_IA64_LE\r
+#endif\r
+\r
+#if defined(MY_CPU_X86_OR_AMD64) \\r
+    || defined(MY_CPU_ARM_LE) \\r
+    || defined(MY_CPU_IA64_LE) \\r
+    || defined(__LITTLE_ENDIAN__) \\r
+    || defined(__ARMEL__) \\r
+    || defined(__THUMBEL__) \\r
+    || defined(__AARCH64EL__) \\r
+    || defined(__MIPSEL__) \\r
+    || defined(__MIPSEL) \\r
+    || defined(_MIPSEL) \\r
+    || defined(__BFIN__) \\r
+    || (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))\r
+  #define MY_CPU_LE\r
+#endif\r
+\r
+#if defined(__BIG_ENDIAN__) \\r
+    || defined(__ARMEB__) \\r
+    || defined(__THUMBEB__) \\r
+    || defined(__AARCH64EB__) \\r
+    || defined(__MIPSEB__) \\r
+    || defined(__MIPSEB) \\r
+    || defined(_MIPSEB) \\r
+    || defined(__m68k__) \\r
+    || defined(__s390__) \\r
+    || defined(__s390x__) \\r
+    || defined(__zarch__) \\r
+    || (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))\r
+  #define MY_CPU_BE\r
+#endif\r
+\r
+#if defined(MY_CPU_LE) && defined(MY_CPU_BE)\r
+Stop_Compiling_Bad_Endian\r
+#endif\r
+\r
+\r
+#ifdef MY_CPU_LE\r
+  #if defined(MY_CPU_X86_OR_AMD64) \\r
+      /* || defined(__AARCH64EL__) */\r
+    #define MY_CPU_LE_UNALIGN\r
+  #endif\r
+#endif\r
+\r
+\r
+#ifdef MY_CPU_LE_UNALIGN\r
 \r
-#define GetUi16(p) (*(const UInt16 *)(p))\r
-#define GetUi32(p) (*(const UInt32 *)(p))\r
-#define GetUi64(p) (*(const UInt64 *)(p))\r
-#define SetUi32(p, d) *(UInt32 *)(p) = (d);\r
+#define GetUi16(p) (*(const UInt16 *)(const void *)(p))\r
+#define GetUi32(p) (*(const UInt32 *)(const void *)(p))\r
+#define GetUi64(p) (*(const UInt64 *)(const void *)(p))\r
+\r
+#define SetUi16(p, v) { *(UInt16 *)(p) = (v); }\r
+#define SetUi32(p, v) { *(UInt32 *)(p) = (v); }\r
+#define SetUi64(p, v) { *(UInt64 *)(p) = (v); }\r
 \r
 #else\r
 \r
-#define GetUi16(p) (((const Byte *)(p))[0] | ((UInt16)((const Byte *)(p))[1] << 8))\r
+#define GetUi16(p) ( (UInt16) ( \\r
+             ((const Byte *)(p))[0] | \\r
+    ((UInt16)((const Byte *)(p))[1] << 8) ))\r
 \r
 #define GetUi32(p) ( \\r
              ((const Byte *)(p))[0]        | \\r
@@ -37,21 +123,43 @@ about these properties of platform.
 \r
 #define GetUi64(p) (GetUi32(p) | ((UInt64)GetUi32(((const Byte *)(p)) + 4) << 32))\r
 \r
-#define SetUi32(p, d) { UInt32 _x_ = (d); \\r
-    ((Byte *)(p))[0] = (Byte)_x_; \\r
-    ((Byte *)(p))[1] = (Byte)(_x_ >> 8); \\r
-    ((Byte *)(p))[2] = (Byte)(_x_ >> 16); \\r
-    ((Byte *)(p))[3] = (Byte)(_x_ >> 24); }\r
+#define SetUi16(p, v) { Byte *_ppp_ = (Byte *)(p); UInt32 _vvv_ = (v); \\r
+    _ppp_[0] = (Byte)_vvv_; \\r
+    _ppp_[1] = (Byte)(_vvv_ >> 8); }\r
+\r
+#define SetUi32(p, v) { Byte *_ppp_ = (Byte *)(p); UInt32 _vvv_ = (v); \\r
+    _ppp_[0] = (Byte)_vvv_; \\r
+    _ppp_[1] = (Byte)(_vvv_ >> 8); \\r
+    _ppp_[2] = (Byte)(_vvv_ >> 16); \\r
+    _ppp_[3] = (Byte)(_vvv_ >> 24); }\r
+\r
+#define SetUi64(p, v) { Byte *_ppp2_ = (Byte *)(p); UInt64 _vvv2_ = (v); \\r
+    SetUi32(_ppp2_    , (UInt32)_vvv2_); \\r
+    SetUi32(_ppp2_ + 4, (UInt32)(_vvv2_ >> 32)); }\r
 \r
 #endif\r
 \r
-#if defined(LITTLE_ENDIAN_UNALIGN) && defined(_WIN64) && (_MSC_VER >= 1300)\r
+\r
+#if defined(MY_CPU_LE_UNALIGN) && /* defined(_WIN64) && */ (_MSC_VER >= 1300)\r
+\r
+/* Note: we use bswap instruction, that is unsupported in 386 cpu */\r
+\r
+#include <stdlib.h>\r
 \r
 #pragma intrinsic(_byteswap_ulong)\r
 #pragma intrinsic(_byteswap_uint64)\r
 #define GetBe32(p) _byteswap_ulong(*(const UInt32 *)(const Byte *)(p))\r
 #define GetBe64(p) _byteswap_uint64(*(const UInt64 *)(const Byte *)(p))\r
 \r
+#define SetBe32(p, v) (*(UInt32 *)(void *)(p)) = _byteswap_ulong(v)\r
+\r
+#elif defined(MY_CPU_LE_UNALIGN) && defined (__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))\r
+\r
+#define GetBe32(p) __builtin_bswap32(*(const UInt32 *)(const Byte *)(p))\r
+#define GetBe64(p) __builtin_bswap64(*(const UInt64 *)(const Byte *)(p))\r
+\r
+#define SetBe32(p, v) (*(UInt32 *)(void *)(p)) = __builtin_bswap32(v)\r
+\r
 #else\r
 \r
 #define GetBe32(p) ( \\r
@@ -62,8 +170,54 @@ about these properties of platform.
 \r
 #define GetBe64(p) (((UInt64)GetBe32(p) << 32) | GetBe32(((const Byte *)(p)) + 4))\r
 \r
+#define SetBe32(p, v) { Byte *_ppp_ = (Byte *)(p); UInt32 _vvv_ = (v); \\r
+    _ppp_[0] = (Byte)(_vvv_ >> 24); \\r
+    _ppp_[1] = (Byte)(_vvv_ >> 16); \\r
+    _ppp_[2] = (Byte)(_vvv_ >> 8); \\r
+    _ppp_[3] = (Byte)_vvv_; }\r
+\r
+#endif\r
+\r
+\r
+#define GetBe16(p) ( (UInt16) ( \\r
+    ((UInt16)((const Byte *)(p))[0] << 8) | \\r
+             ((const Byte *)(p))[1] ))\r
+\r
+\r
+\r
+#ifdef MY_CPU_X86_OR_AMD64\r
+\r
+typedef struct\r
+{\r
+  UInt32 maxFunc;\r
+  UInt32 vendor[3];\r
+  UInt32 ver;\r
+  UInt32 b;\r
+  UInt32 c;\r
+  UInt32 d;\r
+} Cx86cpuid;\r
+\r
+enum\r
+{\r
+  CPU_FIRM_INTEL,\r
+  CPU_FIRM_AMD,\r
+  CPU_FIRM_VIA\r
+};\r
+\r
+void MyCPUID(UInt32 function, UInt32 *a, UInt32 *b, UInt32 *c, UInt32 *d);\r
+\r
+Bool x86cpuid_CheckAndRead(Cx86cpuid *p);\r
+int x86cpuid_GetFirm(const Cx86cpuid *p);\r
+\r
+#define x86cpuid_GetFamily(ver) (((ver >> 16) & 0xFF0) | ((ver >> 8) & 0xF))\r
+#define x86cpuid_GetModel(ver)  (((ver >> 12) &  0xF0) | ((ver >> 4) & 0xF))\r
+#define x86cpuid_GetStepping(ver) (ver & 0xF)\r
+\r
+Bool CPU_Is_InOrder();\r
+Bool CPU_Is_Aes_Supported();\r
+\r
 #endif\r
 \r
-#define GetBe16(p) (((UInt16)((const Byte *)(p))[0] << 8) | ((const Byte *)(p))[1])\r
+EXTERN_C_END\r
 \r
 #endif\r
index e0ebe62356637f152e0c60c9eaee1197384bef47..c335d363ce75aae880243f2b52c7a243e21fdfdd 100644 (file)
@@ -1,5 +1,7 @@
 /* LzFind.c -- Match finder for LZ algorithms\r
-2008-10-04 : Igor Pavlov : Public domain */\r
+2015-10-15 : Igor Pavlov : Public domain */\r
+\r
+#include "Precomp.h"\r
 \r
 #include <string.h>\r
 \r
@@ -9,8 +11,8 @@
 #define kEmptyHashValue 0\r
 #define kMaxValForNormalize ((UInt32)0xFFFFFFFF)\r
 #define kNormalizeStepMin (1 << 10) /* it must be power of 2 */\r
-#define kNormalizeMask (~(kNormalizeStepMin - 1))\r
-#define kMaxHistorySize ((UInt32)3 << 30)\r
+#define kNormalizeMask (~(UInt32)(kNormalizeStepMin - 1))\r
+#define kMaxHistorySize ((UInt32)7 << 29)\r
 \r
 #define kStartMaxLen 3\r
 \r
@@ -19,7 +21,7 @@ static void LzInWindow_Free(CMatchFinder *p, ISzAlloc *alloc)
   if (!p->directInput)\r
   {\r
     alloc->Free(alloc, p->bufferBase);\r
-    p->bufferBase = 0;\r
+    p->bufferBase = NULL;\r
   }\r
 }\r
 \r
@@ -33,17 +35,16 @@ static int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *a
     p->blockSize = blockSize;\r
     return 1;\r
   }\r
-  if (p->bufferBase == 0 || p->blockSize != blockSize)\r
+  if (!p->bufferBase || p->blockSize != blockSize)\r
   {\r
     LzInWindow_Free(p, alloc);\r
     p->blockSize = blockSize;\r
     p->bufferBase = (Byte *)alloc->Alloc(alloc, (size_t)blockSize);\r
   }\r
-  return (p->bufferBase != 0);\r
+  return (p->bufferBase != NULL);\r
 }\r
 \r
 Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; }\r
-Byte MatchFinder_GetIndexByte(CMatchFinder *p, Int32 index) { return p->buffer[index]; }\r
 \r
 UInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }\r
 \r
@@ -58,12 +59,28 @@ static void MatchFinder_ReadBlock(CMatchFinder *p)
 {\r
   if (p->streamEndWasReached || p->result != SZ_OK)\r
     return;\r
+\r
+  /* We use (p->streamPos - p->pos) value. (p->streamPos < p->pos) is allowed. */\r
+\r
+  if (p->directInput)\r
+  {\r
+    UInt32 curSize = 0xFFFFFFFF - (p->streamPos - p->pos);\r
+    if (curSize > p->directInputRem)\r
+      curSize = (UInt32)p->directInputRem;\r
+    p->directInputRem -= curSize;\r
+    p->streamPos += curSize;\r
+    if (p->directInputRem == 0)\r
+      p->streamEndWasReached = 1;\r
+    return;\r
+  }\r
+  \r
   for (;;)\r
   {\r
     Byte *dest = p->buffer + (p->streamPos - p->pos);\r
     size_t size = (p->bufferBase + p->blockSize - dest);\r
     if (size == 0)\r
       return;\r
+\r
     p->result = p->stream->Read(p->stream, dest, &size);\r
     if (p->result != SZ_OK)\r
       return;\r
@@ -81,13 +98,15 @@ static void MatchFinder_ReadBlock(CMatchFinder *p)
 void MatchFinder_MoveBlock(CMatchFinder *p)\r
 {\r
   memmove(p->bufferBase,\r
-    p->buffer - p->keepSizeBefore,\r
-    (size_t)(p->streamPos - p->pos + p->keepSizeBefore));\r
+      p->buffer - p->keepSizeBefore,\r
+      (size_t)(p->streamPos - p->pos) + p->keepSizeBefore);\r
   p->buffer = p->bufferBase + p->keepSizeBefore;\r
 }\r
 \r
 int MatchFinder_NeedMove(CMatchFinder *p)\r
 {\r
+  if (p->directInput)\r
+    return 0;\r
   /* if (p->streamEndWasReached) return 0; */\r
   return ((size_t)(p->bufferBase + p->blockSize - p->buffer) <= p->keepSizeAfter);\r
 }\r
@@ -112,8 +131,6 @@ static void MatchFinder_SetDefaultSettings(CMatchFinder *p)
   p->cutValue = 32;\r
   p->btMode = 1;\r
   p->numHashBytes = 4;\r
-  /* p->skipModeBits = 0; */\r
-  p->directInput = 0;\r
   p->bigHash = 0;\r
 }\r
 \r
@@ -122,15 +139,15 @@ static void MatchFinder_SetDefaultSettings(CMatchFinder *p)
 void MatchFinder_Construct(CMatchFinder *p)\r
 {\r
   UInt32 i;\r
-  p->bufferBase = 0;\r
+  p->bufferBase = NULL;\r
   p->directInput = 0;\r
-  p->hash = 0;\r
+  p->hash = NULL;\r
   MatchFinder_SetDefaultSettings(p);\r
 \r
   for (i = 0; i < 256; i++)\r
   {\r
     UInt32 r = i;\r
-    int j;\r
+    unsigned j;\r
     for (j = 0; j < 8; j++)\r
       r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));\r
     p->crc[i] = r;\r
@@ -140,7 +157,7 @@ void MatchFinder_Construct(CMatchFinder *p)
 static void MatchFinder_FreeThisClassMemory(CMatchFinder *p, ISzAlloc *alloc)\r
 {\r
   alloc->Free(alloc, p->hash);\r
-  p->hash = 0;\r
+  p->hash = NULL;\r
 }\r
 \r
 void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc)\r
@@ -149,11 +166,11 @@ void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc)
   LzInWindow_Free(p, alloc);\r
 }\r
 \r
-static CLzRef* AllocRefs(UInt32 num, ISzAlloc *alloc)\r
+static CLzRef* AllocRefs(size_t num, ISzAlloc *alloc)\r
 {\r
   size_t sizeInBytes = (size_t)num * sizeof(CLzRef);\r
   if (sizeInBytes / sizeof(CLzRef) != num)\r
-    return 0;\r
+    return NULL;\r
   return (CLzRef *)alloc->Alloc(alloc, sizeInBytes);\r
 }\r
 \r
@@ -162,22 +179,27 @@ int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
     ISzAlloc *alloc)\r
 {\r
   UInt32 sizeReserv;\r
+  \r
   if (historySize > kMaxHistorySize)\r
   {\r
     MatchFinder_Free(p, alloc);\r
     return 0;\r
   }\r
+  \r
   sizeReserv = historySize >> 1;\r
-  if (historySize > ((UInt32)2 << 30))\r
-    sizeReserv = historySize >> 2;\r
+       if (historySize >= ((UInt32)3 << 30)) sizeReserv = historySize >> 3;\r
+  else if (historySize >= ((UInt32)2 << 30)) sizeReserv = historySize >> 2;\r
+  \r
   sizeReserv += (keepAddBufferBefore + matchMaxLen + keepAddBufferAfter) / 2 + (1 << 19);\r
 \r
   p->keepSizeBefore = historySize + keepAddBufferBefore + 1;\r
   p->keepSizeAfter = matchMaxLen + keepAddBufferAfter;\r
+  \r
   /* we need one additional byte, since we use MoveBlock after pos++ and before dictionary using */\r
+  \r
   if (LzInWindow_Create(p, sizeReserv, alloc))\r
   {\r
-    UInt32 newCyclicBufferSize = (historySize /* >> p->skipModeBits */) + 1;\r
+    UInt32 newCyclicBufferSize = historySize + 1;\r
     UInt32 hs;\r
     p->matchMaxLen = matchMaxLen;\r
     {\r
@@ -192,7 +214,6 @@ int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
         hs |= (hs >> 4);\r
         hs |= (hs >> 8);\r
         hs >>= 1;\r
-        /* hs >>= p->skipModeBits; */\r
         hs |= 0xFFFF; /* don't change it! It's required for Deflate */\r
         if (hs > (1 << 24))\r
         {\r
@@ -200,6 +221,7 @@ int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
             hs = (1 << 24) - 1;\r
           else\r
             hs >>= 1;\r
+          /* if (bigHash) mode, GetHeads4b() in LzFindMt.c needs (hs >= ((1 << 24) - 1))) */\r
         }\r
       }\r
       p->hashMask = hs;\r
@@ -211,24 +233,32 @@ int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
     }\r
 \r
     {\r
-      UInt32 prevSize = p->hashSizeSum + p->numSons;\r
-      UInt32 newSize;\r
+      size_t newSize;\r
+      size_t numSons;\r
       p->historySize = historySize;\r
       p->hashSizeSum = hs;\r
       p->cyclicBufferSize = newCyclicBufferSize;\r
-      p->numSons = (p->btMode ? newCyclicBufferSize * 2 : newCyclicBufferSize);\r
-      newSize = p->hashSizeSum + p->numSons;\r
-      if (p->hash != 0 && prevSize == newSize)\r
+      \r
+      numSons = newCyclicBufferSize;\r
+      if (p->btMode)\r
+        numSons <<= 1;\r
+      newSize = hs + numSons;\r
+\r
+      if (p->hash && p->numRefs == newSize)\r
         return 1;\r
+      \r
       MatchFinder_FreeThisClassMemory(p, alloc);\r
+      p->numRefs = newSize;\r
       p->hash = AllocRefs(newSize, alloc);\r
-      if (p->hash != 0)\r
+      \r
+      if (p->hash)\r
       {\r
         p->son = p->hash + p->hashSizeSum;\r
         return 1;\r
       }\r
     }\r
   }\r
+\r
   MatchFinder_Free(p, alloc);\r
   return 0;\r
 }\r
@@ -237,9 +267,11 @@ static void MatchFinder_SetLimits(CMatchFinder *p)
 {\r
   UInt32 limit = kMaxValForNormalize - p->pos;\r
   UInt32 limit2 = p->cyclicBufferSize - p->cyclicBufferPos;\r
+  \r
   if (limit2 < limit)\r
     limit = limit2;\r
   limit2 = p->streamPos - p->pos;\r
+  \r
   if (limit2 <= p->keepSizeAfter)\r
   {\r
     if (limit2 > 0)\r
@@ -247,8 +279,10 @@ static void MatchFinder_SetLimits(CMatchFinder *p)
   }\r
   else\r
     limit2 -= p->keepSizeAfter;\r
+  \r
   if (limit2 < limit)\r
     limit = limit2;\r
+  \r
   {\r
     UInt32 lenLimit = p->streamPos - p->pos;\r
     if (lenLimit > p->matchMaxLen)\r
@@ -258,28 +292,39 @@ static void MatchFinder_SetLimits(CMatchFinder *p)
   p->posLimit = p->pos + limit;\r
 }\r
 \r
-void MatchFinder_Init(CMatchFinder *p)\r
+void MatchFinder_Init_2(CMatchFinder *p, int readData)\r
 {\r
   UInt32 i;\r
-  for (i = 0; i < p->hashSizeSum; i++)\r
-    p->hash[i] = kEmptyHashValue;\r
+  UInt32 *hash = p->hash;\r
+  UInt32 num = p->hashSizeSum;\r
+  for (i = 0; i < num; i++)\r
+    hash[i] = kEmptyHashValue;\r
+  \r
   p->cyclicBufferPos = 0;\r
   p->buffer = p->bufferBase;\r
   p->pos = p->streamPos = p->cyclicBufferSize;\r
   p->result = SZ_OK;\r
   p->streamEndWasReached = 0;\r
-  MatchFinder_ReadBlock(p);\r
+  \r
+  if (readData)\r
+    MatchFinder_ReadBlock(p);\r
+  \r
   MatchFinder_SetLimits(p);\r
 }\r
 \r
+void MatchFinder_Init(CMatchFinder *p)\r
+{\r
+  MatchFinder_Init_2(p, True);\r
+}\r
+  \r
 static UInt32 MatchFinder_GetSubValue(CMatchFinder *p)\r
 {\r
   return (p->pos - p->historySize - 1) & kNormalizeMask;\r
 }\r
 \r
-void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems)\r
+void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, size_t numItems)\r
 {\r
-  UInt32 i;\r
+  size_t i;\r
   for (i = 0; i < numItems; i++)\r
   {\r
     UInt32 value = items[i];\r
@@ -294,7 +339,7 @@ void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems)
 static void MatchFinder_Normalize(CMatchFinder *p)\r
 {\r
   UInt32 subValue = MatchFinder_GetSubValue(p);\r
-  MatchFinder_Normalize3(subValue, p->hash, p->hashSizeSum + p->numSons);\r
+  MatchFinder_Normalize3(subValue, p->hash, p->numRefs);\r
   MatchFinder_ReduceOffsets(p, subValue);\r
 }\r
 \r
@@ -455,7 +500,7 @@ static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const
 static void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }\r
 \r
 #define GET_MATCHES_HEADER2(minLen, ret_op) \\r
-  UInt32 lenLimit; UInt32 hashValue; const Byte *cur; UInt32 curMatch; \\r
+  UInt32 lenLimit; UInt32 hv; const Byte *cur; UInt32 curMatch; \\r
   lenLimit = p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \\r
   cur = p->buffer;\r
 \r
@@ -471,13 +516,20 @@ static void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }
 #define SKIP_FOOTER \\r
   SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS;\r
 \r
+#define UPDATE_maxLen { \\r
+    ptrdiff_t diff = (ptrdiff_t)0 - d2; \\r
+    const Byte *c = cur + maxLen; \\r
+    const Byte *lim = cur + lenLimit; \\r
+    for (; c != lim; c++) if (*(c + diff) != *c) break; \\r
+    maxLen = (UInt32)(c - cur); }\r
+\r
 static UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r
 {\r
   UInt32 offset;\r
   GET_MATCHES_HEADER(2)\r
   HASH2_CALC;\r
-  curMatch = p->hash[hashValue];\r
-  p->hash[hashValue] = p->pos;\r
+  curMatch = p->hash[hv];\r
+  p->hash[hv] = p->pos;\r
   offset = 0;\r
   GET_MATCHES_FOOTER(offset, 1)\r
 }\r
@@ -487,35 +539,38 @@ UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
   UInt32 offset;\r
   GET_MATCHES_HEADER(3)\r
   HASH_ZIP_CALC;\r
-  curMatch = p->hash[hashValue];\r
-  p->hash[hashValue] = p->pos;\r
+  curMatch = p->hash[hv];\r
+  p->hash[hv] = p->pos;\r
   offset = 0;\r
   GET_MATCHES_FOOTER(offset, 2)\r
 }\r
 \r
 static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r
 {\r
-  UInt32 hash2Value, delta2, maxLen, offset;\r
+  UInt32 h2, d2, maxLen, offset, pos;\r
+  UInt32 *hash;\r
   GET_MATCHES_HEADER(3)\r
 \r
   HASH3_CALC;\r
 \r
-  delta2 = p->pos - p->hash[hash2Value];\r
-  curMatch = p->hash[kFix3HashSize + hashValue];\r
-  \r
-  p->hash[hash2Value] =\r
-  p->hash[kFix3HashSize + hashValue] = p->pos;\r
+  hash = p->hash;\r
+  pos = p->pos;\r
 \r
+  d2 = pos - hash[h2];\r
+\r
+  curMatch = hash[kFix3HashSize + hv];\r
+  \r
+  hash[h2] = pos;\r
+  hash[kFix3HashSize + hv] = pos;\r
 \r
   maxLen = 2;\r
   offset = 0;\r
-  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)\r
+\r
+  if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur)\r
   {\r
-    for (; maxLen != lenLimit; maxLen++)\r
-      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])\r
-        break;\r
+    UPDATE_maxLen\r
     distances[0] = maxLen;\r
-    distances[1] = delta2 - 1;\r
+    distances[1] = d2 - 1;\r
     offset = 2;\r
     if (maxLen == lenLimit)\r
     {\r
@@ -523,44 +578,51 @@ static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
       MOVE_POS_RET;\r
     }\r
   }\r
+  \r
   GET_MATCHES_FOOTER(offset, maxLen)\r
 }\r
 \r
 static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r
 {\r
-  UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;\r
+  UInt32 h2, h3, d2, d3, maxLen, offset, pos;\r
+  UInt32 *hash;\r
   GET_MATCHES_HEADER(4)\r
 \r
   HASH4_CALC;\r
 \r
-  delta2 = p->pos - p->hash[                hash2Value];\r
-  delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];\r
-  curMatch = p->hash[kFix4HashSize + hashValue];\r
-  \r
-  p->hash[                hash2Value] =\r
-  p->hash[kFix3HashSize + hash3Value] =\r
-  p->hash[kFix4HashSize + hashValue] = p->pos;\r
+  hash = p->hash;\r
+  pos = p->pos;\r
+\r
+  d2 = pos - hash[                h2];\r
+  d3 = pos - hash[kFix3HashSize + h3];\r
+\r
+  curMatch = hash[kFix4HashSize + hv];\r
 \r
-  maxLen = 1;\r
+  hash[                h2] = pos;\r
+  hash[kFix3HashSize + h3] = pos;\r
+  hash[kFix4HashSize + hv] = pos;\r
+\r
+  maxLen = 0;\r
   offset = 0;\r
-  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)\r
+  \r
+  if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur)\r
   {\r
     distances[0] = maxLen = 2;\r
-    distances[1] = delta2 - 1;\r
+    distances[1] = d2 - 1;\r
     offset = 2;\r
   }\r
-  if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)\r
+  \r
+  if (d2 != d3 && d3 < p->cyclicBufferSize && *(cur - d3) == *cur)\r
   {\r
     maxLen = 3;\r
-    distances[offset + 1] = delta3 - 1;\r
+    distances[offset + 1] = d3 - 1;\r
     offset += 2;\r
-    delta2 = delta3;\r
+    d2 = d3;\r
   }\r
+  \r
   if (offset != 0)\r
   {\r
-    for (; maxLen != lenLimit; maxLen++)\r
-      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])\r
-        break;\r
+    UPDATE_maxLen\r
     distances[offset - 2] = maxLen;\r
     if (maxLen == lenLimit)\r
     {\r
@@ -568,46 +630,131 @@ static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
       MOVE_POS_RET;\r
     }\r
   }\r
+  \r
   if (maxLen < 3)\r
     maxLen = 3;\r
+  \r
   GET_MATCHES_FOOTER(offset, maxLen)\r
 }\r
 \r
+/*\r
+static UInt32 Bt5_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r
+{\r
+  UInt32 h2, h3, h4, d2, d3, d4, maxLen, offset, pos;\r
+  UInt32 *hash;\r
+  GET_MATCHES_HEADER(5)\r
+\r
+  HASH5_CALC;\r
+\r
+  hash = p->hash;\r
+  pos = p->pos;\r
+\r
+  d2 = pos - hash[                h2];\r
+  d3 = pos - hash[kFix3HashSize + h3];\r
+  d4 = pos - hash[kFix4HashSize + h4];\r
+\r
+  curMatch = hash[kFix5HashSize + hv];\r
+\r
+  hash[                h2] = pos;\r
+  hash[kFix3HashSize + h3] = pos;\r
+  hash[kFix4HashSize + h4] = pos;\r
+  hash[kFix5HashSize + hv] = pos;\r
+\r
+  maxLen = 0;\r
+  offset = 0;\r
+\r
+  if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur)\r
+  {\r
+    distances[0] = maxLen = 2;\r
+    distances[1] = d2 - 1;\r
+    offset = 2;\r
+    if (*(cur - d2 + 2) == cur[2])\r
+      distances[0] = maxLen = 3;\r
+    else if (d3 < p->cyclicBufferSize && *(cur - d3) == *cur)\r
+    {\r
+      distances[2] = maxLen = 3;\r
+      distances[3] = d3 - 1;\r
+      offset = 4;\r
+      d2 = d3;\r
+    }\r
+  }\r
+  else if (d3 < p->cyclicBufferSize && *(cur - d3) == *cur)\r
+  {\r
+    distances[0] = maxLen = 3;\r
+    distances[1] = d3 - 1;\r
+    offset = 2;\r
+    d2 = d3;\r
+  }\r
+  \r
+  if (d2 != d4 && d4 < p->cyclicBufferSize\r
+      && *(cur - d4) == *cur\r
+      && *(cur - d4 + 3) == *(cur + 3))\r
+  {\r
+    maxLen = 4;\r
+    distances[offset + 1] = d4 - 1;\r
+    offset += 2;\r
+    d2 = d4;\r
+  }\r
+  \r
+  if (offset != 0)\r
+  {\r
+    UPDATE_maxLen\r
+    distances[offset - 2] = maxLen;\r
+    if (maxLen == lenLimit)\r
+    {\r
+      SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));\r
+      MOVE_POS_RET;\r
+    }\r
+  }\r
+\r
+  if (maxLen < 4)\r
+    maxLen = 4;\r
+  \r
+  GET_MATCHES_FOOTER(offset, maxLen)\r
+}\r
+*/\r
+\r
 static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r
 {\r
-  UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;\r
+  UInt32 h2, h3, d2, d3, maxLen, offset, pos;\r
+  UInt32 *hash;\r
   GET_MATCHES_HEADER(4)\r
 \r
   HASH4_CALC;\r
 \r
-  delta2 = p->pos - p->hash[                hash2Value];\r
-  delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];\r
-  curMatch = p->hash[kFix4HashSize + hashValue];\r
+  hash = p->hash;\r
+  pos = p->pos;\r
+  \r
+  d2 = pos - hash[                h2];\r
+  d3 = pos - hash[kFix3HashSize + h3];\r
+  \r
+  curMatch = hash[kFix4HashSize + hv];\r
 \r
-  p->hash[                hash2Value] =\r
-  p->hash[kFix3HashSize + hash3Value] =\r
-  p->hash[kFix4HashSize + hashValue] = p->pos;\r
+  hash[                h2] = pos;\r
+  hash[kFix3HashSize + h3] = pos;\r
+  hash[kFix4HashSize + hv] = pos;\r
 \r
-  maxLen = 1;\r
+  maxLen = 0;\r
   offset = 0;\r
-  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)\r
+\r
+  if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur)\r
   {\r
     distances[0] = maxLen = 2;\r
-    distances[1] = delta2 - 1;\r
+    distances[1] = d2 - 1;\r
     offset = 2;\r
   }\r
-  if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)\r
+  \r
+  if (d2 != d3 && d3 < p->cyclicBufferSize && *(cur - d3) == *cur)\r
   {\r
     maxLen = 3;\r
-    distances[offset + 1] = delta3 - 1;\r
+    distances[offset + 1] = d3 - 1;\r
     offset += 2;\r
-    delta2 = delta3;\r
+    d2 = d3;\r
   }\r
+  \r
   if (offset != 0)\r
   {\r
-    for (; maxLen != lenLimit; maxLen++)\r
-      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])\r
-        break;\r
+    UPDATE_maxLen\r
     distances[offset - 2] = maxLen;\r
     if (maxLen == lenLimit)\r
     {\r
@@ -615,22 +762,103 @@ static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
       MOVE_POS_RET;\r
     }\r
   }\r
+  \r
   if (maxLen < 3)\r
     maxLen = 3;\r
+\r
   offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),\r
-    distances + offset, maxLen) - (distances));\r
+      distances + offset, maxLen) - (distances));\r
   MOVE_POS_RET\r
 }\r
 \r
+/*\r
+static UInt32 Hc5_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r
+{\r
+  UInt32 h2, h3, h4, d2, d3, d4, maxLen, offset, pos\r
+  UInt32 *hash;\r
+  GET_MATCHES_HEADER(5)\r
+\r
+  HASH5_CALC;\r
+\r
+  hash = p->hash;\r
+  pos = p->pos;\r
+  \r
+  d2 = pos - hash[                h2];\r
+  d3 = pos - hash[kFix3HashSize + h3];\r
+  d4 = pos - hash[kFix4HashSize + h4];\r
+\r
+  curMatch = hash[kFix5HashSize + hv];\r
+\r
+  hash[                h2] = pos;\r
+  hash[kFix3HashSize + h3] = pos;\r
+  hash[kFix4HashSize + h4] = pos;\r
+  hash[kFix5HashSize + hv] = pos;\r
+\r
+  maxLen = 0;\r
+  offset = 0;\r
+\r
+  if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur)\r
+  {\r
+    distances[0] = maxLen = 2;\r
+    distances[1] = d2 - 1;\r
+    offset = 2;\r
+    if (*(cur - d2 + 2) == cur[2])\r
+      distances[0] = maxLen = 3;\r
+    else if (d3 < p->cyclicBufferSize && *(cur - d3) == *cur)\r
+    {\r
+      distances[2] = maxLen = 3;\r
+      distances[3] = d3 - 1;\r
+      offset = 4;\r
+      d2 = d3;\r
+    }\r
+  }\r
+  else if (d3 < p->cyclicBufferSize && *(cur - d3) == *cur)\r
+  {\r
+    distances[0] = maxLen = 3;\r
+    distances[1] = d3 - 1;\r
+    offset = 2;\r
+    d2 = d3;\r
+  }\r
+  \r
+  if (d2 != d4 && d4 < p->cyclicBufferSize\r
+      && *(cur - d4) == *cur\r
+      && *(cur - d4 + 3) == *(cur + 3))\r
+  {\r
+    maxLen = 4;\r
+    distances[offset + 1] = d4 - 1;\r
+    offset += 2;\r
+    d2 = d4;\r
+  }\r
+  \r
+  if (offset != 0)\r
+  {\r
+    UPDATE_maxLen\r
+    distances[offset - 2] = maxLen;\r
+    if (maxLen == lenLimit)\r
+    {\r
+      p->son[p->cyclicBufferPos] = curMatch;\r
+      MOVE_POS_RET;\r
+    }\r
+  }\r
+  \r
+  if (maxLen < 4)\r
+    maxLen = 4;\r
+\r
+  offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),\r
+      distances + offset, maxLen) - (distances));\r
+  MOVE_POS_RET\r
+}\r
+*/\r
+\r
 UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)\r
 {\r
   UInt32 offset;\r
   GET_MATCHES_HEADER(3)\r
   HASH_ZIP_CALC;\r
-  curMatch = p->hash[hashValue];\r
-  p->hash[hashValue] = p->pos;\r
+  curMatch = p->hash[hv];\r
+  p->hash[hv] = p->pos;\r
   offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),\r
-    distances, 2) - (distances));\r
+      distances, 2) - (distances));\r
   MOVE_POS_RET\r
 }\r
 \r
@@ -640,8 +868,8 @@ static void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
   {\r
     SKIP_HEADER(2)\r
     HASH2_CALC;\r
-    curMatch = p->hash[hashValue];\r
-    p->hash[hashValue] = p->pos;\r
+    curMatch = p->hash[hv];\r
+    p->hash[hv] = p->pos;\r
     SKIP_FOOTER\r
   }\r
   while (--num != 0);\r
@@ -653,8 +881,8 @@ void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
   {\r
     SKIP_HEADER(3)\r
     HASH_ZIP_CALC;\r
-    curMatch = p->hash[hashValue];\r
-    p->hash[hashValue] = p->pos;\r
+    curMatch = p->hash[hv];\r
+    p->hash[hv] = p->pos;\r
     SKIP_FOOTER\r
   }\r
   while (--num != 0);\r
@@ -664,12 +892,14 @@ static void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
 {\r
   do\r
   {\r
-    UInt32 hash2Value;\r
+    UInt32 h2;\r
+    UInt32 *hash;\r
     SKIP_HEADER(3)\r
     HASH3_CALC;\r
-    curMatch = p->hash[kFix3HashSize + hashValue];\r
-    p->hash[hash2Value] =\r
-    p->hash[kFix3HashSize + hashValue] = p->pos;\r
+    hash = p->hash;\r
+    curMatch = hash[kFix3HashSize + hv];\r
+    hash[h2] =\r
+    hash[kFix3HashSize + hv] = p->pos;\r
     SKIP_FOOTER\r
   }\r
   while (--num != 0);\r
@@ -679,34 +909,81 @@ static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
 {\r
   do\r
   {\r
-    UInt32 hash2Value, hash3Value;\r
+    UInt32 h2, h3;\r
+    UInt32 *hash;\r
     SKIP_HEADER(4)\r
     HASH4_CALC;\r
-    curMatch = p->hash[kFix4HashSize + hashValue];\r
-    p->hash[                hash2Value] =\r
-    p->hash[kFix3HashSize + hash3Value] = p->pos;\r
-    p->hash[kFix4HashSize + hashValue] = p->pos;\r
+    hash = p->hash;\r
+    curMatch = hash[kFix4HashSize + hv];\r
+    hash[                h2] =\r
+    hash[kFix3HashSize + h3] =\r
+    hash[kFix4HashSize + hv] = p->pos;\r
     SKIP_FOOTER\r
   }\r
   while (--num != 0);\r
 }\r
 \r
+/*\r
+static void Bt5_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r
+{\r
+  do\r
+  {\r
+    UInt32 h2, h3, h4;\r
+    UInt32 *hash;\r
+    SKIP_HEADER(5)\r
+    HASH5_CALC;\r
+    hash = p->hash;\r
+    curMatch = hash[kFix5HashSize + hv];\r
+    hash[                h2] =\r
+    hash[kFix3HashSize + h3] =\r
+    hash[kFix4HashSize + h4] =\r
+    hash[kFix5HashSize + hv] = p->pos;\r
+    SKIP_FOOTER\r
+  }\r
+  while (--num != 0);\r
+}\r
+*/\r
+\r
 static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r
 {\r
   do\r
   {\r
-    UInt32 hash2Value, hash3Value;\r
+    UInt32 h2, h3;\r
+    UInt32 *hash;\r
     SKIP_HEADER(4)\r
     HASH4_CALC;\r
-    curMatch = p->hash[kFix4HashSize + hashValue];\r
-    p->hash[                hash2Value] =\r
-    p->hash[kFix3HashSize + hash3Value] =\r
-    p->hash[kFix4HashSize + hashValue] = p->pos;\r
+    hash = p->hash;\r
+    curMatch = hash[kFix4HashSize + hv];\r
+    hash[                h2] =\r
+    hash[kFix3HashSize + h3] =\r
+    hash[kFix4HashSize + hv] = p->pos;\r
+    p->son[p->cyclicBufferPos] = curMatch;\r
+    MOVE_POS\r
+  }\r
+  while (--num != 0);\r
+}\r
+\r
+/*\r
+static void Hc5_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r
+{\r
+  do\r
+  {\r
+    UInt32 h2, h3, h4;\r
+    UInt32 *hash;\r
+    SKIP_HEADER(5)\r
+    HASH5_CALC;\r
+    hash = p->hash;\r
+    curMatch = p->hash[kFix5HashSize + hv];\r
+    hash[                h2] =\r
+    hash[kFix3HashSize + h3] =\r
+    hash[kFix4HashSize + h4] =\r
+    hash[kFix5HashSize + hv] = p->pos;\r
     p->son[p->cyclicBufferPos] = curMatch;\r
     MOVE_POS\r
   }\r
   while (--num != 0);\r
 }\r
+*/\r
 \r
 void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)\r
 {\r
@@ -714,8 +991,8 @@ void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
   {\r
     SKIP_HEADER(3)\r
     HASH_ZIP_CALC;\r
-    curMatch = p->hash[hashValue];\r
-    p->hash[hashValue] = p->pos;\r
+    curMatch = p->hash[hv];\r
+    p->hash[hv] = p->pos;\r
     p->son[p->cyclicBufferPos] = curMatch;\r
     MOVE_POS\r
   }\r
@@ -725,13 +1002,22 @@ void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
 void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable)\r
 {\r
   vTable->Init = (Mf_Init_Func)MatchFinder_Init;\r
-  vTable->GetIndexByte = (Mf_GetIndexByte_Func)MatchFinder_GetIndexByte;\r
   vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinder_GetNumAvailableBytes;\r
   vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinder_GetPointerToCurrentPos;\r
   if (!p->btMode)\r
   {\r
-    vTable->GetMatches = (Mf_GetMatches_Func)Hc4_MatchFinder_GetMatches;\r
-    vTable->Skip = (Mf_Skip_Func)Hc4_MatchFinder_Skip;\r
+    /* if (p->numHashBytes <= 4) */\r
+    {\r
+      vTable->GetMatches = (Mf_GetMatches_Func)Hc4_MatchFinder_GetMatches;\r
+      vTable->Skip = (Mf_Skip_Func)Hc4_MatchFinder_Skip;\r
+    }\r
+    /*\r
+    else\r
+    {\r
+      vTable->GetMatches = (Mf_GetMatches_Func)Hc5_MatchFinder_GetMatches;\r
+      vTable->Skip = (Mf_Skip_Func)Hc5_MatchFinder_Skip;\r
+    }\r
+    */\r
   }\r
   else if (p->numHashBytes == 2)\r
   {\r
@@ -743,9 +1029,16 @@ void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable)
     vTable->GetMatches = (Mf_GetMatches_Func)Bt3_MatchFinder_GetMatches;\r
     vTable->Skip = (Mf_Skip_Func)Bt3_MatchFinder_Skip;\r
   }\r
-  else\r
+  else /* if (p->numHashBytes == 4) */\r
   {\r
     vTable->GetMatches = (Mf_GetMatches_Func)Bt4_MatchFinder_GetMatches;\r
     vTable->Skip = (Mf_Skip_Func)Bt4_MatchFinder_Skip;\r
   }\r
+  /*\r
+  else\r
+  {\r
+    vTable->GetMatches = (Mf_GetMatches_Func)Bt5_MatchFinder_GetMatches;\r
+    vTable->Skip = (Mf_Skip_Func)Bt5_MatchFinder_Skip;\r
+  }\r
+  */\r
 }\r
index 423d67e0c3e0cb9db952c1c99b4a2e53415c5c8b..2ff667377166b6bb54b5306a4641515c9ccf1039 100644 (file)
@@ -1,10 +1,12 @@
 /* LzFind.h -- Match finder for LZ algorithms\r
-2008-10-04 : Igor Pavlov : Public domain */\r
+2015-10-15 : Igor Pavlov : Public domain */\r
 \r
-#ifndef __LZFIND_H\r
-#define __LZFIND_H\r
+#ifndef __LZ_FIND_H\r
+#define __LZ_FIND_H\r
 \r
-#include "Types.h"\r
+#include "7zTypes.h"\r
+\r
+EXTERN_C_BEGIN\r
 \r
 typedef UInt32 CLzRef;\r
 \r
@@ -19,6 +21,11 @@ typedef struct _CMatchFinder
   UInt32 cyclicBufferPos;\r
   UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */\r
 \r
+  Byte streamEndWasReached;\r
+  Byte btMode;\r
+  Byte bigHash;\r
+  Byte directInput;\r
+\r
   UInt32 matchMaxLen;\r
   CLzRef *hash;\r
   CLzRef *son;\r
@@ -27,30 +34,30 @@ typedef struct _CMatchFinder
 \r
   Byte *bufferBase;\r
   ISeqInStream *stream;\r
-  int streamEndWasReached;\r
-\r
+  \r
   UInt32 blockSize;\r
   UInt32 keepSizeBefore;\r
   UInt32 keepSizeAfter;\r
 \r
   UInt32 numHashBytes;\r
-  int directInput;\r
-  int btMode;\r
-  /* int skipModeBits; */\r
-  int bigHash;\r
+  size_t directInputRem;\r
   UInt32 historySize;\r
   UInt32 fixedHashSize;\r
   UInt32 hashSizeSum;\r
-  UInt32 numSons;\r
   SRes result;\r
   UInt32 crc[256];\r
+  size_t numRefs;\r
 } CMatchFinder;\r
 \r
 #define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer)\r
-#define Inline_MatchFinder_GetIndexByte(p, index) ((p)->buffer[(Int32)(index)])\r
 \r
 #define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos)\r
 \r
+#define Inline_MatchFinder_IsFinishedOK(p) \\r
+    ((p)->streamEndWasReached \\r
+        && (p)->streamPos == (p)->pos \\r
+        && (!(p)->directInput || (p)->directInputRem == 0))\r
+      \r
 int MatchFinder_NeedMove(CMatchFinder *p);\r
 Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p);\r
 void MatchFinder_MoveBlock(CMatchFinder *p);\r
@@ -66,7 +73,7 @@ int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
     UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,\r
     ISzAlloc *alloc);\r
 void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc);\r
-void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems);\r
+void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, size_t numItems);\r
 void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue);\r
 \r
 UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son,\r
@@ -80,7 +87,6 @@ Conditions:
 */\r
 \r
 typedef void (*Mf_Init_Func)(void *object);\r
-typedef Byte (*Mf_GetIndexByte_Func)(void *object, Int32 index);\r
 typedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object);\r
 typedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object);\r
 typedef UInt32 (*Mf_GetMatches_Func)(void *object, UInt32 *distances);\r
@@ -89,7 +95,6 @@ typedef void (*Mf_Skip_Func)(void *object, UInt32);
 typedef struct _IMatchFinder\r
 {\r
   Mf_Init_Func Init;\r
-  Mf_GetIndexByte_Func GetIndexByte;\r
   Mf_GetNumAvailableBytes_Func GetNumAvailableBytes;\r
   Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos;\r
   Mf_GetMatches_Func GetMatches;\r
@@ -98,10 +103,15 @@ typedef struct _IMatchFinder
 \r
 void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable);\r
 \r
+void MatchFinder_Init_2(CMatchFinder *p, int readData);\r
 void MatchFinder_Init(CMatchFinder *p);\r
+\r
 UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);\r
 UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);\r
+\r
 void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);\r
 void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);\r
 \r
+EXTERN_C_END\r
+\r
 #endif\r
index 0ef134735d6c506684c81791a82b73e5363757fd..cb61e0953a01ec92a77bee1219389d8b8dbbb2e7 100644 (file)
@@ -1,11 +1,13 @@
 /* LzFindMt.c -- multithreaded Match finder for LZ algorithms\r
-2008-10-04 : Igor Pavlov : Public domain */\r
+2015-10-15 : Igor Pavlov : Public domain */\r
+\r
+#include "Precomp.h"\r
 \r
 #include "LzHash.h"\r
 \r
 #include "LzFindMt.h"\r
 \r
-void MtSync_Construct(CMtSync *p)\r
+static void MtSync_Construct(CMtSync *p)\r
 {\r
   p->wasCreated = False;\r
   p->csWasInitialized = False;\r
@@ -18,7 +20,7 @@ void MtSync_Construct(CMtSync *p)
   Semaphore_Construct(&p->filledSemaphore);\r
 }\r
 \r
-void MtSync_GetNextBlock(CMtSync *p)\r
+static void MtSync_GetNextBlock(CMtSync *p)\r
 {\r
   if (p->needStart)\r
   {\r
@@ -46,7 +48,7 @@ void MtSync_GetNextBlock(CMtSync *p)
 \r
 /* MtSync_StopWriting must be called if Writing was started */\r
 \r
-void MtSync_StopWriting(CMtSync *p)\r
+static void MtSync_StopWriting(CMtSync *p)\r
 {\r
   UInt32 myNumBlocks = p->numProcessedBlocks;\r
   if (!Thread_WasCreated(&p->thread) || p->needStart)\r
@@ -69,7 +71,7 @@ void MtSync_StopWriting(CMtSync *p)
   p->needStart = True;\r
 }\r
 \r
-void MtSync_Destruct(CMtSync *p)\r
+static void MtSync_Destruct(CMtSync *p)\r
 {\r
   if (Thread_WasCreated(&p->thread))\r
   {\r
@@ -97,7 +99,7 @@ void MtSync_Destruct(CMtSync *p)
 \r
 #define RINOK_THREAD(x) { if ((x) != 0) return SZ_ERROR_THREAD; }\r
 \r
-static SRes MtSync_Create2(CMtSync *p, unsigned (MY_STD_CALL *startAddress)(void *), void *obj, UInt32 numBlocks)\r
+static SRes MtSync_Create2(CMtSync *p, THREAD_FUNC_TYPE startAddress, void *obj, UInt32 numBlocks)\r
 {\r
   if (p->wasCreated)\r
     return SZ_OK;\r
@@ -119,7 +121,7 @@ static SRes MtSync_Create2(CMtSync *p, unsigned (MY_STD_CALL *startAddress)(void
   return SZ_OK;\r
 }\r
 \r
-static SRes MtSync_Create(CMtSync *p, unsigned (MY_STD_CALL *startAddress)(void *), void *obj, UInt32 numBlocks)\r
+static SRes MtSync_Create(CMtSync *p, THREAD_FUNC_TYPE startAddress, void *obj, UInt32 numBlocks)\r
 {\r
   SRes res = MtSync_Create2(p, startAddress, obj, numBlocks);\r
   if (res != SZ_OK)\r
@@ -132,20 +134,20 @@ void MtSync_Init(CMtSync *p) { p->needStart = True; }
 #define kMtMaxValForNormalize 0xFFFFFFFF\r
 \r
 #define DEF_GetHeads2(name, v, action) \\r
-static void GetHeads ## name(const Byte *p, UInt32 pos, \\r
-UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc) \\r
-{ action; for (; numHeads != 0; numHeads--) { \\r
-const UInt32 value = (v); p++; *heads++ = pos - hash[value]; hash[value] = pos++;  } }\r
+  static void GetHeads ## name(const Byte *p, UInt32 pos, \\r
+      UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc) \\r
+    { action; for (; numHeads != 0; numHeads--) { \\r
+      const UInt32 value = (v); p++; *heads++ = pos - hash[value]; hash[value] = pos++;  } }\r
 \r
 #define DEF_GetHeads(name, v) DEF_GetHeads2(name, v, ;)\r
 \r
-DEF_GetHeads2(2,  (p[0] | ((UInt32)p[1] << 8)), hashMask = hashMask; crc = crc; )\r
+DEF_GetHeads2(2,  (p[0] | ((UInt32)p[1] << 8)), UNUSED_VAR(hashMask); UNUSED_VAR(crc); )\r
 DEF_GetHeads(3,  (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8)) & hashMask)\r
 DEF_GetHeads(4,  (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ (crc[p[3]] << 5)) & hashMask)\r
 DEF_GetHeads(4b, (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ ((UInt32)p[3] << 16)) & hashMask)\r
-DEF_GetHeads(5,  (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ (crc[p[3]] << 5) ^ (crc[p[4]] << 3)) & hashMask)\r
+/* DEF_GetHeads(5,  (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ (crc[p[3]] << 5) ^ (crc[p[4]] << 3)) & hashMask) */\r
 \r
-void HashThreadFunc(CMatchFinderMt *mt)\r
+static void HashThreadFunc(CMatchFinderMt *mt)\r
 {\r
   CMtSync *p = &mt->hashSync;\r
   for (;;)\r
@@ -171,12 +173,12 @@ void HashThreadFunc(CMatchFinderMt *mt)
           CriticalSection_Enter(&mt->btSync.cs);\r
           CriticalSection_Enter(&mt->hashSync.cs);\r
           {\r
-            const Byte *beforePtr = MatchFinder_GetPointerToCurrentPos(mf);\r
-            const Byte *afterPtr;\r
+            const Byte *beforePtr = Inline_MatchFinder_GetPointerToCurrentPos(mf);\r
+            ptrdiff_t offset;\r
             MatchFinder_MoveBlock(mf);\r
-            afterPtr = MatchFinder_GetPointerToCurrentPos(mf);\r
-            mt->pointerToCurPos -= beforePtr - afterPtr;\r
-            mt->buffer -= beforePtr - afterPtr;\r
+            offset = beforePtr - Inline_MatchFinder_GetPointerToCurrentPos(mf);\r
+            mt->pointerToCurPos -= offset;\r
+            mt->buffer -= offset;\r
           }\r
           CriticalSection_Leave(&mt->btSync.cs);\r
           CriticalSection_Leave(&mt->hashSync.cs);\r
@@ -190,7 +192,7 @@ void HashThreadFunc(CMatchFinderMt *mt)
         {\r
           UInt32 subValue = (mf->pos - mf->historySize - 1);\r
           MatchFinder_ReduceOffsets(mf, subValue);\r
-          MatchFinder_Normalize3(subValue, mf->hash + mf->fixedHashSize, mf->hashMask + 1);\r
+          MatchFinder_Normalize3(subValue, mf->hash + mf->fixedHashSize, (size_t)mf->hashMask + 1);\r
         }\r
         {\r
           UInt32 *heads = mt->hashBuf + ((numProcessedBlocks++) & kMtHashNumBlocksMask) * kMtHashBlockSize;\r
@@ -215,7 +217,7 @@ void HashThreadFunc(CMatchFinderMt *mt)
   }\r
 }\r
 \r
-void MatchFinderMt_GetNextBlock_Hash(CMatchFinderMt *p)\r
+static void MatchFinderMt_GetNextBlock_Hash(CMatchFinderMt *p)\r
 {\r
   MtSync_GetNextBlock(&p->hashSync);\r
   p->hashBufPosLimit = p->hashBufPos = ((p->hashSync.numProcessedBlocks - 1) & kMtHashNumBlocksMask) * kMtHashBlockSize;\r
@@ -231,7 +233,7 @@ void MatchFinderMt_GetNextBlock_Hash(CMatchFinderMt *p)
 \r
 #define NO_INLINE MY_FAST_CALL\r
 \r
-Int32 NO_INLINE GetMatchesSpecN(UInt32 lenLimit, UInt32 pos, const Byte *cur, CLzRef *son,\r
+static Int32 NO_INLINE GetMatchesSpecN(UInt32 lenLimit, UInt32 pos, const Byte *cur, CLzRef *son,\r
     UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,\r
     UInt32 *_distances, UInt32 _maxLen, const UInt32 *hash, Int32 limit, UInt32 size, UInt32 *posRes)\r
 {\r
@@ -308,12 +310,14 @@ Int32 NO_INLINE GetMatchesSpecN(UInt32 lenLimit, UInt32 pos, const Byte *cur, CL
 \r
 #endif\r
 \r
-void BtGetMatches(CMatchFinderMt *p, UInt32 *distances)\r
+static void BtGetMatches(CMatchFinderMt *p, UInt32 *distances)\r
 {\r
   UInt32 numProcessed = 0;\r
   UInt32 curPos = 2;\r
   UInt32 limit = kMtBtBlockSize - (p->matchMaxLen * 2);\r
+  \r
   distances[1] = p->hashNumAvail;\r
+  \r
   while (curPos < limit)\r
   {\r
     if (p->hashBufPos == p->hashBufPosLimit)\r
@@ -322,9 +326,11 @@ void BtGetMatches(CMatchFinderMt *p, UInt32 *distances)
       distances[1] = numProcessed + p->hashNumAvail;\r
       if (p->hashNumAvail >= p->numHashBytes)\r
         continue;\r
+      distances[0] = curPos + p->hashNumAvail;\r
+      distances += curPos;\r
       for (; p->hashNumAvail != 0; p->hashNumAvail--)\r
-        distances[curPos++] = 0;\r
-      break;\r
+        *distances++ = 0;\r
+      return;\r
     }\r
     {\r
       UInt32 size = p->hashBufPosLimit - p->hashBufPos;\r
@@ -341,13 +347,14 @@ void BtGetMatches(CMatchFinderMt *p, UInt32 *distances)
         if (size2 < size)\r
           size = size2;\r
       }\r
+      \r
       #ifndef MFMT_GM_INLINE\r
       while (curPos < limit && size-- != 0)\r
       {\r
         UInt32 *startDistances = distances + curPos;\r
         UInt32 num = (UInt32)(GetMatchesSpec1(lenLimit, pos - p->hashBuf[p->hashBufPos++],\r
-          pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue,\r
-          startDistances + 1, p->numHashBytes - 1) - startDistances);\r
+            pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue,\r
+            startDistances + 1, p->numHashBytes - 1) - startDistances);\r
         *startDistances = num - 1;\r
         curPos += num;\r
         cyclicBufferPos++;\r
@@ -358,7 +365,7 @@ void BtGetMatches(CMatchFinderMt *p, UInt32 *distances)
       {\r
         UInt32 posRes;\r
         curPos = limit - GetMatchesSpecN(lenLimit, pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue,\r
-          distances + curPos, p->numHashBytes - 1, p->hashBuf + p->hashBufPos, (Int32)(limit - curPos) , size, &posRes);\r
+            distances + curPos, p->numHashBytes - 1, p->hashBuf + p->hashBufPos, (Int32)(limit - curPos), size, &posRes);\r
         p->hashBufPos += posRes - pos;\r
         cyclicBufferPos += posRes - pos;\r
         p->buffer += posRes - pos;\r
@@ -374,10 +381,11 @@ void BtGetMatches(CMatchFinderMt *p, UInt32 *distances)
       p->cyclicBufferPos = cyclicBufferPos;\r
     }\r
   }\r
+  \r
   distances[0] = curPos;\r
 }\r
 \r
-void BtFillBlock(CMatchFinderMt *p, UInt32 globalBlockIndex)\r
+static void BtFillBlock(CMatchFinderMt *p, UInt32 globalBlockIndex)\r
 {\r
   CMtSync *sync = &p->hashSync;\r
   if (!sync->needStart)\r
@@ -391,7 +399,7 @@ void BtFillBlock(CMatchFinderMt *p, UInt32 globalBlockIndex)
   if (p->pos > kMtMaxValForNormalize - kMtBtBlockSize)\r
   {\r
     UInt32 subValue = p->pos - p->cyclicBufferSize;\r
-    MatchFinder_Normalize3(subValue, p->son, p->cyclicBufferSize * 2);\r
+    MatchFinder_Normalize3(subValue, p->son, (size_t)p->cyclicBufferSize * 2);\r
     p->pos -= subValue;\r
   }\r
 \r
@@ -430,15 +438,15 @@ void BtThreadFunc(CMatchFinderMt *mt)
 \r
 void MatchFinderMt_Construct(CMatchFinderMt *p)\r
 {\r
-  p->hashBuf = 0;\r
+  p->hashBuf = NULL;\r
   MtSync_Construct(&p->hashSync);\r
   MtSync_Construct(&p->btSync);\r
 }\r
 \r
-void MatchFinderMt_FreeMem(CMatchFinderMt *p, ISzAlloc *alloc)\r
+static void MatchFinderMt_FreeMem(CMatchFinderMt *p, ISzAlloc *alloc)\r
 {\r
   alloc->Free(alloc, p->hashBuf);\r
-  p->hashBuf = 0;\r
+  p->hashBuf = NULL;\r
 }\r
 \r
 void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc)\r
@@ -451,14 +459,15 @@ void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc)
 #define kHashBufferSize (kMtHashBlockSize * kMtHashNumBlocks)\r
 #define kBtBufferSize (kMtBtBlockSize * kMtBtNumBlocks)\r
 \r
-static unsigned MY_STD_CALL HashThreadFunc2(void *p) { HashThreadFunc((CMatchFinderMt *)p);  return 0; }\r
-static unsigned MY_STD_CALL BtThreadFunc2(void *p)\r
+static THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE HashThreadFunc2(void *p) { HashThreadFunc((CMatchFinderMt *)p);  return 0; }\r
+static THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE BtThreadFunc2(void *p)\r
 {\r
   Byte allocaDummy[0x180];\r
-  int i = 0;\r
+  unsigned i = 0;\r
   for (i = 0; i < 16; i++)\r
-    allocaDummy[i] = (Byte)i;\r
-  BtThreadFunc((CMatchFinderMt *)p);\r
+    allocaDummy[i] = (Byte)0;\r
+  if (allocaDummy[0] == 0)\r
+    BtThreadFunc((CMatchFinderMt *)p);\r
   return 0;\r
 }\r
 \r
@@ -469,10 +478,10 @@ SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddB
   p->historySize = historySize;\r
   if (kMtBtBlockSize <= matchMaxLen * 4)\r
     return SZ_ERROR_PARAM;\r
-  if (p->hashBuf == 0)\r
+  if (!p->hashBuf)\r
   {\r
     p->hashBuf = (UInt32 *)alloc->Alloc(alloc, (kHashBufferSize + kBtBufferSize) * sizeof(UInt32));\r
-    if (p->hashBuf == 0)\r
+    if (!p->hashBuf)\r
       return SZ_ERROR_MEM;\r
     p->btBuf = p->hashBuf + kHashBufferSize;\r
   }\r
@@ -492,8 +501,11 @@ void MatchFinderMt_Init(CMatchFinderMt *p)
   CMatchFinder *mf = p->MatchFinder;\r
   p->btBufPos = p->btBufPosLimit = 0;\r
   p->hashBufPos = p->hashBufPosLimit = 0;\r
-  MatchFinder_Init(mf);\r
-  p->pointerToCurPos = MatchFinder_GetPointerToCurrentPos(mf);\r
+\r
+  /* Init without data reading. We don't want to read data in this thread */\r
+  MatchFinder_Init_2(mf, False);\r
+  \r
+  p->pointerToCurPos = Inline_MatchFinder_GetPointerToCurrentPos(mf);\r
   p->btNumAvailBytes = 0;\r
   p->lzPos = p->historySize + 1;\r
 \r
@@ -518,13 +530,13 @@ void MatchFinderMt_ReleaseStream(CMatchFinderMt *p)
   /* p->MatchFinder->ReleaseStream(); */\r
 }\r
 \r
-void MatchFinderMt_Normalize(CMatchFinderMt *p)\r
+static void MatchFinderMt_Normalize(CMatchFinderMt *p)\r
 {\r
   MatchFinder_Normalize3(p->lzPos - p->historySize - 1, p->hash, p->fixedHashSize);\r
   p->lzPos = p->historySize + 1;\r
 }\r
 \r
-void MatchFinderMt_GetNextBlock_Bt(CMatchFinderMt *p)\r
+static void MatchFinderMt_GetNextBlock_Bt(CMatchFinderMt *p)\r
 {\r
   UInt32 blockIndex;\r
   MtSync_GetNextBlock(&p->btSync);\r
@@ -536,34 +548,29 @@ void MatchFinderMt_GetNextBlock_Bt(CMatchFinderMt *p)
     MatchFinderMt_Normalize(p);\r
 }\r
 \r
-const Byte * MatchFinderMt_GetPointerToCurrentPos(CMatchFinderMt *p)\r
+static const Byte * MatchFinderMt_GetPointerToCurrentPos(CMatchFinderMt *p)\r
 {\r
   return p->pointerToCurPos;\r
 }\r
 \r
 #define GET_NEXT_BLOCK_IF_REQUIRED if (p->btBufPos == p->btBufPosLimit) MatchFinderMt_GetNextBlock_Bt(p);\r
 \r
-UInt32 MatchFinderMt_GetNumAvailableBytes(CMatchFinderMt *p)\r
+static UInt32 MatchFinderMt_GetNumAvailableBytes(CMatchFinderMt *p)\r
 {\r
   GET_NEXT_BLOCK_IF_REQUIRED;\r
   return p->btNumAvailBytes;\r
 }\r
 \r
-Byte MatchFinderMt_GetIndexByte(CMatchFinderMt *p, Int32 index)\r
+static UInt32 * MixMatches2(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)\r
 {\r
-  return p->pointerToCurPos[index];\r
-}\r
-\r
-UInt32 * MixMatches2(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)\r
-{\r
-  UInt32 hash2Value, curMatch2;\r
+  UInt32 h2, curMatch2;\r
   UInt32 *hash = p->hash;\r
   const Byte *cur = p->pointerToCurPos;\r
   UInt32 lzPos = p->lzPos;\r
   MT_HASH2_CALC\r
       \r
-  curMatch2 = hash[hash2Value];\r
-  hash[hash2Value] = lzPos;\r
+  curMatch2 = hash[h2];\r
+  hash[h2] = lzPos;\r
 \r
   if (curMatch2 >= matchMinPos)\r
     if (cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])\r
@@ -571,23 +578,23 @@ UInt32 * MixMatches2(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)
       *distances++ = 2;\r
       *distances++ = lzPos - curMatch2 - 1;\r
     }\r
+  \r
   return distances;\r
 }\r
 \r
-UInt32 * MixMatches3(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)\r
+static UInt32 * MixMatches3(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)\r
 {\r
-  UInt32 hash2Value, hash3Value, curMatch2, curMatch3;\r
+  UInt32 h2, h3, curMatch2, curMatch3;\r
   UInt32 *hash = p->hash;\r
   const Byte *cur = p->pointerToCurPos;\r
   UInt32 lzPos = p->lzPos;\r
   MT_HASH3_CALC\r
 \r
-  curMatch2 = hash[                hash2Value];\r
-  curMatch3 = hash[kFix3HashSize + hash3Value];\r
+  curMatch2 = hash[                h2];\r
+  curMatch3 = hash[kFix3HashSize + h3];\r
   \r
-  hash[                hash2Value] =\r
-  hash[kFix3HashSize + hash3Value] =\r
-    lzPos;\r
+  hash[                h2] = lzPos;\r
+  hash[kFix3HashSize + h3] = lzPos;\r
 \r
   if (curMatch2 >= matchMinPos && cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])\r
   {\r
@@ -600,43 +607,45 @@ UInt32 * MixMatches3(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)
     distances[0] = 2;\r
     distances += 2;\r
   }\r
+  \r
   if (curMatch3 >= matchMinPos && cur[(ptrdiff_t)curMatch3 - lzPos] == cur[0])\r
   {\r
     *distances++ = 3;\r
     *distances++ = lzPos - curMatch3 - 1;\r
   }\r
+  \r
   return distances;\r
 }\r
 \r
 /*\r
-UInt32 *MixMatches4(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)\r
+static UInt32 *MixMatches4(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)\r
 {\r
-  UInt32 hash2Value, hash3Value, hash4Value, curMatch2, curMatch3, curMatch4;\r
+  UInt32 h2, h3, h4, curMatch2, curMatch3, curMatch4;\r
   UInt32 *hash = p->hash;\r
   const Byte *cur = p->pointerToCurPos;\r
   UInt32 lzPos = p->lzPos;\r
   MT_HASH4_CALC\r
       \r
-  curMatch2 = hash[                hash2Value];\r
-  curMatch3 = hash[kFix3HashSize + hash3Value];\r
-  curMatch4 = hash[kFix4HashSize + hash4Value];\r
+  curMatch2 = hash[                h2];\r
+  curMatch3 = hash[kFix3HashSize + h3];\r
+  curMatch4 = hash[kFix4HashSize + h4];\r
   \r
-  hash[                hash2Value] =\r
-  hash[kFix3HashSize + hash3Value] =\r
-  hash[kFix4HashSize + hash4Value] =\r
-    lzPos;\r
+  hash[                h2] = lzPos;\r
+  hash[kFix3HashSize + h3] = lzPos;\r
+  hash[kFix4HashSize + h4] = lzPos;\r
 \r
   if (curMatch2 >= matchMinPos && cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])\r
   {\r
     distances[1] = lzPos - curMatch2 - 1;\r
     if (cur[(ptrdiff_t)curMatch2 - lzPos + 2] == cur[2])\r
     {\r
-      distances[0] =  (cur[(ptrdiff_t)curMatch2 - lzPos + 3] == cur[3]) ? 4 : 3;\r
+      distances[0] = (cur[(ptrdiff_t)curMatch2 - lzPos + 3] == cur[3]) ? 4 : 3;\r
       return distances + 2;\r
     }\r
     distances[0] = 2;\r
     distances += 2;\r
   }\r
+  \r
   if (curMatch3 >= matchMinPos && cur[(ptrdiff_t)curMatch3 - lzPos] == cur[0])\r
   {\r
     distances[1] = lzPos - curMatch3 - 1;\r
@@ -658,13 +667,14 @@ UInt32 *MixMatches4(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)
       *distances++ = 4;\r
       *distances++ = lzPos - curMatch4 - 1;\r
     }\r
+  \r
   return distances;\r
 }\r
 */\r
 \r
 #define INCREASE_LZ_POS p->lzPos++; p->pointerToCurPos++;\r
 \r
-UInt32 MatchFinderMt2_GetMatches(CMatchFinderMt *p, UInt32 *distances)\r
+static UInt32 MatchFinderMt2_GetMatches(CMatchFinderMt *p, UInt32 *distances)\r
 {\r
   const UInt32 *btBuf = p->btBuf + p->btBufPos;\r
   UInt32 len = *btBuf++;\r
@@ -682,7 +692,7 @@ UInt32 MatchFinderMt2_GetMatches(CMatchFinderMt *p, UInt32 *distances)
   return len;\r
 }\r
 \r
-UInt32 MatchFinderMt_GetMatches(CMatchFinderMt *p, UInt32 *distances)\r
+static UInt32 MatchFinderMt_GetMatches(CMatchFinderMt *p, UInt32 *distances)\r
 {\r
   const UInt32 *btBuf = p->btBuf + p->btBufPos;\r
   UInt32 len = *btBuf++;\r
@@ -690,6 +700,7 @@ UInt32 MatchFinderMt_GetMatches(CMatchFinderMt *p, UInt32 *distances)
 \r
   if (len == 0)\r
   {\r
+    /* change for bt5 ! */\r
     if (p->btNumAvailBytes-- >= 4)\r
       len = (UInt32)(p->MixMatchesFunc(p, p->lzPos - p->historySize, distances) - (distances));\r
   }\r
@@ -705,64 +716,64 @@ UInt32 MatchFinderMt_GetMatches(CMatchFinderMt *p, UInt32 *distances)
       *distances2++ = *btBuf++;\r
     }\r
     while ((len -= 2) != 0);\r
-    len  = (UInt32)(distances2 - (distances));\r
+    len = (UInt32)(distances2 - (distances));\r
   }\r
   INCREASE_LZ_POS\r
   return len;\r
 }\r
 \r
-#define SKIP_HEADER2  do { GET_NEXT_BLOCK_IF_REQUIRED\r
-#define SKIP_HEADER(n) SKIP_HEADER2 if (p->btNumAvailBytes-- >= (n)) { const Byte *cur = p->pointerToCurPos; UInt32 *hash = p->hash;\r
-#define SKIP_FOOTER } INCREASE_LZ_POS p->btBufPos += p->btBuf[p->btBufPos] + 1; } while (--num != 0);\r
+#define SKIP_HEADER2_MT  do { GET_NEXT_BLOCK_IF_REQUIRED\r
+#define SKIP_HEADER_MT(n) SKIP_HEADER2_MT if (p->btNumAvailBytes-- >= (n)) { const Byte *cur = p->pointerToCurPos; UInt32 *hash = p->hash;\r
+#define SKIP_FOOTER_MT } INCREASE_LZ_POS p->btBufPos += p->btBuf[p->btBufPos] + 1; } while (--num != 0);\r
 \r
-void MatchFinderMt0_Skip(CMatchFinderMt *p, UInt32 num)\r
+static void MatchFinderMt0_Skip(CMatchFinderMt *p, UInt32 num)\r
 {\r
-  SKIP_HEADER2 { p->btNumAvailBytes--;\r
-  SKIP_FOOTER\r
+  SKIP_HEADER2_MT { p->btNumAvailBytes--;\r
+  SKIP_FOOTER_MT\r
 }\r
 \r
-void MatchFinderMt2_Skip(CMatchFinderMt *p, UInt32 num)\r
+static void MatchFinderMt2_Skip(CMatchFinderMt *p, UInt32 num)\r
 {\r
-  SKIP_HEADER(2)\r
-      UInt32 hash2Value;\r
+  SKIP_HEADER_MT(2)\r
+      UInt32 h2;\r
       MT_HASH2_CALC\r
-      hash[hash2Value] = p->lzPos;\r
-  SKIP_FOOTER\r
+      hash[h2] = p->lzPos;\r
+  SKIP_FOOTER_MT\r
 }\r
 \r
-void MatchFinderMt3_Skip(CMatchFinderMt *p, UInt32 num)\r
+static void MatchFinderMt3_Skip(CMatchFinderMt *p, UInt32 num)\r
 {\r
-  SKIP_HEADER(3)\r
-      UInt32 hash2Value, hash3Value;\r
+  SKIP_HEADER_MT(3)\r
+      UInt32 h2, h3;\r
       MT_HASH3_CALC\r
-      hash[kFix3HashSize + hash3Value] =\r
-      hash[                hash2Value] =\r
+      hash[kFix3HashSize + h3] =\r
+      hash[                h2] =\r
         p->lzPos;\r
-  SKIP_FOOTER\r
+  SKIP_FOOTER_MT\r
 }\r
 \r
 /*\r
-void MatchFinderMt4_Skip(CMatchFinderMt *p, UInt32 num)\r
+static void MatchFinderMt4_Skip(CMatchFinderMt *p, UInt32 num)\r
 {\r
-  SKIP_HEADER(4)\r
-      UInt32 hash2Value, hash3Value, hash4Value;\r
+  SKIP_HEADER_MT(4)\r
+      UInt32 h2, h3, h4;\r
       MT_HASH4_CALC\r
-      hash[kFix4HashSize + hash4Value] =\r
-      hash[kFix3HashSize + hash3Value] =\r
-      hash[                hash2Value] =\r
+      hash[kFix4HashSize + h4] =\r
+      hash[kFix3HashSize + h3] =\r
+      hash[                h2] =\r
         p->lzPos;\r
-  SKIP_FOOTER\r
+  SKIP_FOOTER_MT\r
 }\r
 */\r
 \r
 void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable)\r
 {\r
   vTable->Init = (Mf_Init_Func)MatchFinderMt_Init;\r
-  vTable->GetIndexByte = (Mf_GetIndexByte_Func)MatchFinderMt_GetIndexByte;\r
   vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinderMt_GetNumAvailableBytes;\r
   vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinderMt_GetPointerToCurrentPos;\r
   vTable->GetMatches = (Mf_GetMatches_Func)MatchFinderMt_GetMatches;\r
-  switch(p->MatchFinder->numHashBytes)\r
+  \r
+  switch (p->MatchFinder->numHashBytes)\r
   {\r
     case 2:\r
       p->GetHeadsFunc = GetHeads2;\r
@@ -778,7 +789,6 @@ void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable)
     default:\r
     /* case 4: */\r
       p->GetHeadsFunc = p->MatchFinder->bigHash ? GetHeads4b : GetHeads4;\r
-      /* p->GetHeadsFunc = GetHeads4; */\r
       p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches3;\r
       vTable->Skip = (Mf_Skip_Func)MatchFinderMt3_Skip;\r
       break;\r
index b7ead2d472f443bac162876b89af9e51bf89aa0a..46b6924ad72e2263bebe6794a70e18b3287a480a 100644 (file)
@@ -1,11 +1,13 @@
 /* LzFindMt.h -- multithreaded Match finder for LZ algorithms\r
-2008-10-04 : Igor Pavlov : Public domain */\r
+2015-05-03 : Igor Pavlov : Public domain */\r
 \r
-#ifndef __LZFINDMT_H\r
-#define __LZFINDMT_H\r
+#ifndef __LZ_FIND_MT_H\r
+#define __LZ_FIND_MT_H\r
 \r
-#include "Threads.h"\r
 #include "LzFind.h"\r
+#include "Threads.h"\r
+\r
+EXTERN_C_BEGIN\r
 \r
 #define kMtHashBlockSize (1 << 13)\r
 #define kMtHashNumBlocks (1 << 3)\r
@@ -73,7 +75,7 @@ typedef struct _CMatchFinderMt
   UInt32 matchMaxLen;\r
   UInt32 numHashBytes;\r
   UInt32 pos;\r
-  Byte *buffer;\r
+  const Byte *buffer;\r
   UInt32 cyclicBufferPos;\r
   UInt32 cyclicBufferSize; /* it must be historySize + 1 */\r
   UInt32 cutValue;\r
@@ -94,4 +96,6 @@ SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddB
 void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable);\r
 void MatchFinderMt_ReleaseStream(CMatchFinderMt *p);\r
 \r
+EXTERN_C_END\r
+\r
 #endif\r
index c923417501689882dfd773a91c412f993f6272a4..2191444072a13a459ea9bbee411329e65e42f1fe 100644 (file)
@@ -1,8 +1,8 @@
 /* LzHash.h -- HASH functions for LZ algorithms\r
-2008-10-04 : Igor Pavlov : Public domain */\r
+2015-04-12 : Igor Pavlov : Public domain */\r
 \r
-#ifndef __LZHASH_H\r
-#define __LZHASH_H\r
+#ifndef __LZ_HASH_H\r
+#define __LZ_HASH_H\r
 \r
 #define kHash2Size (1 << 10)\r
 #define kHash3Size (1 << 16)\r
 #define kFix4HashSize (kHash2Size + kHash3Size)\r
 #define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size)\r
 \r
-#define HASH2_CALC hashValue = cur[0] | ((UInt32)cur[1] << 8);\r
+#define HASH2_CALC hv = cur[0] | ((UInt32)cur[1] << 8);\r
 \r
 #define HASH3_CALC { \\r
   UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\r
-  hash2Value = temp & (kHash2Size - 1); \\r
-  hashValue = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; }\r
+  h2 = temp & (kHash2Size - 1); \\r
+  hv = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; }\r
 \r
 #define HASH4_CALC { \\r
   UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\r
-  hash2Value = temp & (kHash2Size - 1); \\r
-  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \\r
-  hashValue = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & p->hashMask; }\r
+  h2 = temp & (kHash2Size - 1); \\r
+  temp ^= ((UInt32)cur[2] << 8); \\r
+  h3 = temp & (kHash3Size - 1); \\r
+  hv = (temp ^ (p->crc[cur[3]] << 5)) & p->hashMask; }\r
 \r
 #define HASH5_CALC { \\r
   UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\r
-  hash2Value = temp & (kHash2Size - 1); \\r
-  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \\r
-  hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)); \\r
-  hashValue = (hash4Value ^ (p->crc[cur[4]] << 3)) & p->hashMask; \\r
-  hash4Value &= (kHash4Size - 1); }\r
+  h2 = temp & (kHash2Size - 1); \\r
+  temp ^= ((UInt32)cur[2] << 8); \\r
+  h3 = temp & (kHash3Size - 1); \\r
+  temp ^= (p->crc[cur[3]] << 5); \\r
+  h4 = temp & (kHash4Size - 1); \\r
+  hv = (temp ^ (p->crc[cur[4]] << 3)) & p->hashMask; }\r
 \r
-/* #define HASH_ZIP_CALC hashValue = ((cur[0] | ((UInt32)cur[1] << 8)) ^ p->crc[cur[2]]) & 0xFFFF; */\r
-#define HASH_ZIP_CALC hashValue = ((cur[2] | ((UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF;\r
+/* #define HASH_ZIP_CALC hv = ((cur[0] | ((UInt32)cur[1] << 8)) ^ p->crc[cur[2]]) & 0xFFFF; */\r
+#define HASH_ZIP_CALC hv = ((cur[2] | ((UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF;\r
 \r
 \r
 #define MT_HASH2_CALC \\r
-  hash2Value = (p->crc[cur[0]] ^ cur[1]) & (kHash2Size - 1);\r
+  h2 = (p->crc[cur[0]] ^ cur[1]) & (kHash2Size - 1);\r
 \r
 #define MT_HASH3_CALC { \\r
   UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\r
-  hash2Value = temp & (kHash2Size - 1); \\r
-  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); }\r
+  h2 = temp & (kHash2Size - 1); \\r
+  h3 = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); }\r
 \r
 #define MT_HASH4_CALC { \\r
   UInt32 temp = p->crc[cur[0]] ^ cur[1]; \\r
-  hash2Value = temp & (kHash2Size - 1); \\r
-  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \\r
-  hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & (kHash4Size - 1); }\r
+  h2 = temp & (kHash2Size - 1); \\r
+  temp ^= ((UInt32)cur[2] << 8); \\r
+  h3 = temp & (kHash3Size - 1); \\r
+  h4 = (temp ^ (p->crc[cur[3]] << 5)) & (kHash4Size - 1); }\r
 \r
 #endif\r
index 87bea866e4a1324b0c1586784023f98089988182..64f1164f3de60ad7d400929d6f8ec180c0daa387 100644 (file)
@@ -1,5 +1,7 @@
 /* LzmaDec.c -- LZMA Decoder\r
-2008-11-06 : Igor Pavlov : Public domain */\r
+2016-05-16 : Igor Pavlov : Public domain */\r
+\r
+#include "Precomp.h"\r
 \r
 #include "LzmaDec.h"\r
 \r
   i -= 0x40; }\r
 #endif\r
 \r
+#define NORMAL_LITER_DEC GET_BIT(prob + symbol, symbol)\r
+#define MATCHED_LITER_DEC \\r
+  matchByte <<= 1; \\r
+  bit = (matchByte & offs); \\r
+  probLit = prob + offs + bit + symbol; \\r
+  GET_BIT2(probLit, symbol, offs &= ~bit, offs &= bit)\r
+\r
 #define NORMALIZE_CHECK if (range < kTopValue) { if (buf >= bufLimit) return DUMMY_ERROR; range <<= 8; code = (code << 8) | (*buf++); }\r
 \r
 #define IF_BIT_0_CHECK(p) ttt = *(p); NORMALIZE_CHECK; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)\r
 #define Literal (RepLenCoder + kNumLenProbs)\r
 \r
 #define LZMA_BASE_SIZE 1846\r
-#define LZMA_LIT_SIZE 768\r
-\r
-#define LzmaProps_GetNumProbs(p) ((UInt32)LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((p)->lc + (p)->lp)))\r
+#define LZMA_LIT_SIZE 0x300\r
 \r
 #if Literal != LZMA_BASE_SIZE\r
 StopCompilingDueBUG\r
 #endif\r
 \r
-static const Byte kLiteralNextStates[kNumStates * 2] =\r
-{\r
-  0, 0, 0, 0, 1, 2, 3,  4,  5,  6,  4,  5,\r
-  7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10\r
-};\r
+#define LzmaProps_GetNumProbs(p) (Literal + ((UInt32)LZMA_LIT_SIZE << ((p)->lc + (p)->lp)))\r
 \r
 #define LZMA_DIC_MIN (1 << 12)\r
 \r
@@ -130,8 +133,8 @@ Out:
   p->remainLen:\r
     < kMatchSpecLenStart : normal remain\r
     = kMatchSpecLenStart : finished\r
-    = kMatchSpecLenStart + 1 : Flush marker\r
-    = kMatchSpecLenStart + 2 : State Init Marker\r
+    = kMatchSpecLenStart + 1 : Flush marker (unused now)\r
+    = kMatchSpecLenStart + 2 : State Init Marker (unused now)\r
 */\r
 \r
 static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte *bufLimit)\r
@@ -169,39 +172,62 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
       unsigned symbol;\r
       UPDATE_0(prob);\r
       prob = probs + Literal;\r
-      if (checkDicSize != 0 || processedPos != 0)\r
-        prob += (LZMA_LIT_SIZE * (((processedPos & lpMask) << lc) +\r
-        (dic[(dicPos == 0 ? dicBufSize : dicPos) - 1] >> (8 - lc))));\r
+      if (processedPos != 0 || checkDicSize != 0)\r
+        prob += ((UInt32)LZMA_LIT_SIZE * (((processedPos & lpMask) << lc) +\r
+            (dic[(dicPos == 0 ? dicBufSize : dicPos) - 1] >> (8 - lc))));\r
+      processedPos++;\r
 \r
       if (state < kNumLitStates)\r
       {\r
+        state -= (state < 4) ? state : 3;\r
         symbol = 1;\r
-        do { GET_BIT(prob + symbol, symbol) } while (symbol < 0x100);\r
+        #ifdef _LZMA_SIZE_OPT\r
+        do { NORMAL_LITER_DEC } while (symbol < 0x100);\r
+        #else\r
+        NORMAL_LITER_DEC\r
+        NORMAL_LITER_DEC\r
+        NORMAL_LITER_DEC\r
+        NORMAL_LITER_DEC\r
+        NORMAL_LITER_DEC\r
+        NORMAL_LITER_DEC\r
+        NORMAL_LITER_DEC\r
+        NORMAL_LITER_DEC\r
+        #endif\r
       }\r
       else\r
       {\r
-        unsigned matchByte = p->dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];\r
+        unsigned matchByte = dic[dicPos - rep0 + (dicPos < rep0 ? dicBufSize : 0)];\r
         unsigned offs = 0x100;\r
+        state -= (state < 10) ? 3 : 6;\r
         symbol = 1;\r
+        #ifdef _LZMA_SIZE_OPT\r
         do\r
         {\r
           unsigned bit;\r
           CLzmaProb *probLit;\r
-          matchByte <<= 1;\r
-          bit = (matchByte & offs);\r
-          probLit = prob + offs + bit + symbol;\r
-          GET_BIT2(probLit, symbol, offs &= ~bit, offs &= bit)\r
+          MATCHED_LITER_DEC\r
         }\r
         while (symbol < 0x100);\r
+        #else\r
+        {\r
+          unsigned bit;\r
+          CLzmaProb *probLit;\r
+          MATCHED_LITER_DEC\r
+          MATCHED_LITER_DEC\r
+          MATCHED_LITER_DEC\r
+          MATCHED_LITER_DEC\r
+          MATCHED_LITER_DEC\r
+          MATCHED_LITER_DEC\r
+          MATCHED_LITER_DEC\r
+          MATCHED_LITER_DEC\r
+        }\r
+        #endif\r
       }\r
-      dic[dicPos++] = (Byte)symbol;\r
-      processedPos++;\r
 \r
-      state = kLiteralNextStates[state];\r
-      /* if (state < 4) state = 0; else if (state < 10) state -= 3; else state -= 6; */\r
+      dic[dicPos++] = (Byte)symbol;\r
       continue;\r
     }\r
-    else\r
+    \r
     {\r
       UPDATE_1(prob);\r
       prob = probs + IsRep + state;\r
@@ -224,7 +250,7 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
           IF_BIT_0(prob)\r
           {\r
             UPDATE_0(prob);\r
-            dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];\r
+            dic[dicPos] = dic[dicPos - rep0 + (dicPos < rep0 ? dicBufSize : 0)];\r
             dicPos++;\r
             processedPos++;\r
             state = state < kNumLitStates ? 9 : 11;\r
@@ -265,15 +291,17 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
         state = state < kNumLitStates ? 8 : 11;\r
         prob = probs + RepLenCoder;\r
       }\r
+      \r
+      #ifdef _LZMA_SIZE_OPT\r
       {\r
-        unsigned offset;\r
+        unsigned lim, offset;\r
         CLzmaProb *probLen = prob + LenChoice;\r
         IF_BIT_0(probLen)\r
         {\r
           UPDATE_0(probLen);\r
           probLen = prob + LenLow + (posState << kLenNumLowBits);\r
           offset = 0;\r
-          limit = (1 << kLenNumLowBits);\r
+          lim = (1 << kLenNumLowBits);\r
         }\r
         else\r
         {\r
@@ -284,19 +312,55 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
             UPDATE_0(probLen);\r
             probLen = prob + LenMid + (posState << kLenNumMidBits);\r
             offset = kLenNumLowSymbols;\r
-            limit = (1 << kLenNumMidBits);\r
+            lim = (1 << kLenNumMidBits);\r
           }\r
           else\r
           {\r
             UPDATE_1(probLen);\r
             probLen = prob + LenHigh;\r
             offset = kLenNumLowSymbols + kLenNumMidSymbols;\r
-            limit = (1 << kLenNumHighBits);\r
+            lim = (1 << kLenNumHighBits);\r
           }\r
         }\r
-        TREE_DECODE(probLen, limit, len);\r
+        TREE_DECODE(probLen, lim, len);\r
         len += offset;\r
       }\r
+      #else\r
+      {\r
+        CLzmaProb *probLen = prob + LenChoice;\r
+        IF_BIT_0(probLen)\r
+        {\r
+          UPDATE_0(probLen);\r
+          probLen = prob + LenLow + (posState << kLenNumLowBits);\r
+          len = 1;\r
+          TREE_GET_BIT(probLen, len);\r
+          TREE_GET_BIT(probLen, len);\r
+          TREE_GET_BIT(probLen, len);\r
+          len -= 8;\r
+        }\r
+        else\r
+        {\r
+          UPDATE_1(probLen);\r
+          probLen = prob + LenChoice2;\r
+          IF_BIT_0(probLen)\r
+          {\r
+            UPDATE_0(probLen);\r
+            probLen = prob + LenMid + (posState << kLenNumMidBits);\r
+            len = 1;\r
+            TREE_GET_BIT(probLen, len);\r
+            TREE_GET_BIT(probLen, len);\r
+            TREE_GET_BIT(probLen, len);\r
+          }\r
+          else\r
+          {\r
+            UPDATE_1(probLen);\r
+            probLen = prob + LenHigh;\r
+            TREE_DECODE(probLen, (1 << kLenNumHighBits), len);\r
+            len += kLenNumLowSymbols + kLenNumMidSymbols;\r
+          }\r
+        }\r
+      }\r
+      #endif\r
 \r
       if (state >= kNumStates)\r
       {\r
@@ -307,7 +371,7 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
         if (distance >= kStartPosModelIndex)\r
         {\r
           unsigned posSlot = (unsigned)distance;\r
-          int numDirectBits = (int)(((distance >> 1) - 1));\r
+          unsigned numDirectBits = (unsigned)(((distance >> 1) - 1));\r
           distance = (2 | (distance & 1));\r
           if (posSlot < kEndPosModelIndex)\r
           {\r
@@ -366,6 +430,7 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
             }\r
           }\r
         }\r
+        \r
         rep3 = rep2;\r
         rep2 = rep1;\r
         rep1 = rep0;\r
@@ -373,27 +438,39 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
         if (checkDicSize == 0)\r
         {\r
           if (distance >= processedPos)\r
+          {\r
+            p->dicPos = dicPos;\r
             return SZ_ERROR_DATA;\r
+          }\r
         }\r
         else if (distance >= checkDicSize)\r
+        {\r
+          p->dicPos = dicPos;\r
           return SZ_ERROR_DATA;\r
+        }\r
         state = (state < kNumStates + kNumLitStates) ? kNumLitStates : kNumLitStates + 3;\r
-        /* state = kLiteralNextStates[state]; */\r
       }\r
 \r
       len += kMatchMinLen;\r
 \r
-      if (limit == dicPos)\r
-        return SZ_ERROR_DATA;\r
       {\r
-        SizeT rem = limit - dicPos;\r
-        unsigned curLen = ((rem < len) ? (unsigned)rem : len);\r
-        SizeT pos = (dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0);\r
+        SizeT rem;\r
+        unsigned curLen;\r
+        SizeT pos;\r
+        \r
+        if ((rem = limit - dicPos) == 0)\r
+        {\r
+          p->dicPos = dicPos;\r
+          return SZ_ERROR_DATA;\r
+        }\r
+        \r
+        curLen = ((rem < len) ? (unsigned)rem : len);\r
+        pos = dicPos - rep0 + (dicPos < rep0 ? dicBufSize : 0);\r
 \r
         processedPos += curLen;\r
 \r
         len -= curLen;\r
-        if (pos + curLen <= dicBufSize)\r
+        if (curLen <= dicBufSize - pos)\r
         {\r
           Byte *dest = dic + dicPos;\r
           ptrdiff_t src = (ptrdiff_t)pos - (ptrdiff_t)dicPos;\r
@@ -417,7 +494,9 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
     }\r
   }\r
   while (dicPos < limit && buf < bufLimit);\r
+\r
   NORMALIZE;\r
+  \r
   p->buf = buf;\r
   p->range = range;\r
   p->code = code;\r
@@ -441,18 +520,20 @@ static void MY_FAST_CALL LzmaDec_WriteRem(CLzmaDec *p, SizeT limit)
     SizeT dicPos = p->dicPos;\r
     SizeT dicBufSize = p->dicBufSize;\r
     unsigned len = p->remainLen;\r
-    UInt32 rep0 = p->reps[0];\r
-    if (limit - dicPos < len)\r
-      len = (unsigned)(limit - dicPos);\r
+    SizeT rep0 = p->reps[0]; /* we use SizeT to avoid the BUG of VC14 for AMD64 */\r
+    SizeT rem = limit - dicPos;\r
+    if (rem < len)\r
+      len = (unsigned)(rem);\r
 \r
     if (p->checkDicSize == 0 && p->prop.dicSize - p->processedPos <= len)\r
       p->checkDicSize = p->prop.dicSize;\r
 \r
     p->processedPos += len;\r
     p->remainLen -= len;\r
-    while (len-- != 0)\r
+    while (len != 0)\r
     {\r
-      dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];\r
+      len--;\r
+      dic[dicPos] = dic[dicPos - rep0 + (dicPos < rep0 ? dicBufSize : 0)];\r
       dicPos++;\r
     }\r
     p->dicPos = dicPos;\r
@@ -470,17 +551,19 @@ static int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte
       if (limit - p->dicPos > rem)\r
         limit2 = p->dicPos + rem;\r
     }\r
+    \r
     RINOK(LzmaDec_DecodeReal(p, limit2, bufLimit));\r
-    if (p->processedPos >= p->prop.dicSize)\r
+    \r
+    if (p->checkDicSize == 0 && p->processedPos >= p->prop.dicSize)\r
       p->checkDicSize = p->prop.dicSize;\r
+    \r
     LzmaDec_WriteRem(p, limit);\r
   }\r
   while (p->dicPos < limit && p->buf < bufLimit && p->remainLen < kMatchSpecLenStart);\r
 \r
   if (p->remainLen > kMatchSpecLenStart)\r
-  {\r
     p->remainLen = kMatchSpecLenStart;\r
-  }\r
+\r
   return 0;\r
 }\r
 \r
@@ -497,12 +580,12 @@ static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inS
   UInt32 range = p->range;\r
   UInt32 code = p->code;\r
   const Byte *bufLimit = buf + inSize;\r
-  CLzmaProb *probs = p->probs;\r
+  const CLzmaProb *probs = p->probs;\r
   unsigned state = p->state;\r
   ELzmaDummy res;\r
 \r
   {\r
-    CLzmaProb *prob;\r
+    const CLzmaProb *prob;\r
     UInt32 bound;\r
     unsigned ttt;\r
     unsigned posState = (p->processedPos) & ((1 << p->prop.pb) - 1);\r
@@ -516,9 +599,9 @@ static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inS
 \r
       prob = probs + Literal;\r
       if (p->checkDicSize != 0 || p->processedPos != 0)\r
-        prob += (LZMA_LIT_SIZE *\r
-          ((((p->processedPos) & ((1 << (p->prop.lp)) - 1)) << p->prop.lc) +\r
-          (p->dic[(p->dicPos == 0 ? p->dicBufSize : p->dicPos) - 1] >> (8 - p->prop.lc))));\r
+        prob += ((UInt32)LZMA_LIT_SIZE *\r
+            ((((p->processedPos) & ((1 << (p->prop.lp)) - 1)) << p->prop.lc) +\r
+            (p->dic[(p->dicPos == 0 ? p->dicBufSize : p->dicPos) - 1] >> (8 - p->prop.lc))));\r
 \r
       if (state < kNumLitStates)\r
       {\r
@@ -528,13 +611,13 @@ static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inS
       else\r
       {\r
         unsigned matchByte = p->dic[p->dicPos - p->reps[0] +\r
-            ((p->dicPos < p->reps[0]) ? p->dicBufSize : 0)];\r
+            (p->dicPos < p->reps[0] ? p->dicBufSize : 0)];\r
         unsigned offs = 0x100;\r
         unsigned symbol = 1;\r
         do\r
         {\r
           unsigned bit;\r
-          CLzmaProb *probLit;\r
+          const CLzmaProb *probLit;\r
           matchByte <<= 1;\r
           bit = (matchByte & offs);\r
           probLit = prob + offs + bit + symbol;\r
@@ -604,7 +687,7 @@ static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inS
       }\r
       {\r
         unsigned limit, offset;\r
-        CLzmaProb *probLen = prob + LenChoice;\r
+        const CLzmaProb *probLen = prob + LenChoice;\r
         IF_BIT_0_CHECK(probLen)\r
         {\r
           UPDATE_0_CHECK;\r
@@ -644,7 +727,7 @@ static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inS
         TREE_DECODE_CHECK(prob, 1 << kNumPosSlotBits, posSlot);\r
         if (posSlot >= kStartPosModelIndex)\r
         {\r
-          int numDirectBits = ((posSlot >> 1) - 1);\r
+          unsigned numDirectBits = ((posSlot >> 1) - 1);\r
 \r
           /* if (bufLimit - buf >= 8) return DUMMY_MATCH; */\r
 \r
@@ -683,13 +766,6 @@ static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inS
 }\r
 \r
 \r
-static void LzmaDec_InitRc(CLzmaDec *p, const Byte *data)\r
-{\r
-  p->code = ((UInt32)data[1] << 24) | ((UInt32)data[2] << 16) | ((UInt32)data[3] << 8) | ((UInt32)data[4]);\r
-  p->range = 0xFFFFFFFF;\r
-  p->needFlush = 0;\r
-}\r
-\r
 void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState)\r
 {\r
   p->needFlush = 1;\r
@@ -714,8 +790,8 @@ void LzmaDec_Init(CLzmaDec *p)
 \r
 static void LzmaDec_InitStateReal(CLzmaDec *p)\r
 {\r
-  UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (p->prop.lc + p->prop.lp));\r
-  UInt32 i;\r
+  SizeT numProbs = LzmaProps_GetNumProbs(&p->prop);\r
+  SizeT i;\r
   CLzmaProb *probs = p->probs;\r
   for (i = 0; i < numProbs; i++)\r
     probs[i] = kBitModelTotal >> 1;\r
@@ -737,7 +813,7 @@ SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *sr
   {\r
       int checkEndMarkNow;\r
 \r
-      if (p->needFlush != 0)\r
+      if (p->needFlush)\r
       {\r
         for (; inSize > 0 && p->tempBufSize < RC_INIT_SIZE; (*srcLen)++, inSize--)\r
           p->tempBuf[p->tempBufSize++] = *src++;\r
@@ -748,8 +824,13 @@ SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *sr
         }\r
         if (p->tempBuf[0] != 0)\r
           return SZ_ERROR_DATA;\r
-\r
-        LzmaDec_InitRc(p, p->tempBuf);\r
+        p->code =\r
+              ((UInt32)p->tempBuf[1] << 24)\r
+            | ((UInt32)p->tempBuf[2] << 16)\r
+            | ((UInt32)p->tempBuf[3] << 8)\r
+            | ((UInt32)p->tempBuf[4]);\r
+        p->range = 0xFFFFFFFF;\r
+        p->needFlush = 0;\r
         p->tempBufSize = 0;\r
       }\r
 \r
@@ -833,7 +914,16 @@ SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *sr
         p->buf = p->tempBuf;\r
         if (LzmaDec_DecodeReal2(p, dicLimit, p->buf) != 0)\r
           return SZ_ERROR_DATA;\r
-        lookAhead -= (rem - (unsigned)(p->buf - p->tempBuf));\r
+        \r
+        {\r
+          unsigned kkk = (unsigned)(p->buf - p->tempBuf);\r
+          if (rem < kkk)\r
+            return SZ_ERROR_FAIL; /* some internal error */\r
+          rem -= kkk;\r
+          if (lookAhead < rem)\r
+            return SZ_ERROR_FAIL; /* some internal error */\r
+          lookAhead -= rem;\r
+        }\r
         (*srcLen) += lookAhead;\r
         src += lookAhead;\r
         inSize -= lookAhead;\r
@@ -888,13 +978,13 @@ SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *sr
 void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc)\r
 {\r
   alloc->Free(alloc, p->probs);\r
-  p->probs = 0;\r
+  p->probs = NULL;\r
 }\r
 \r
 static void LzmaDec_FreeDict(CLzmaDec *p, ISzAlloc *alloc)\r
 {\r
   alloc->Free(alloc, p->dic);\r
-  p->dic = 0;\r
+  p->dic = NULL;\r
 }\r
 \r
 void LzmaDec_Free(CLzmaDec *p, ISzAlloc *alloc)\r
@@ -932,12 +1022,12 @@ SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)
 static SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAlloc *alloc)\r
 {\r
   UInt32 numProbs = LzmaProps_GetNumProbs(propNew);\r
-  if (p->probs == 0 || numProbs != p->numProbs)\r
+  if (!p->probs || numProbs != p->numProbs)\r
   {\r
     LzmaDec_FreeProbs(p, alloc);\r
     p->probs = (CLzmaProb *)alloc->Alloc(alloc, numProbs * sizeof(CLzmaProb));\r
     p->numProbs = numProbs;\r
-    if (p->probs == 0)\r
+    if (!p->probs)\r
       return SZ_ERROR_MEM;\r
   }\r
   return SZ_OK;\r
@@ -958,12 +1048,22 @@ SRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAll
   SizeT dicBufSize;\r
   RINOK(LzmaProps_Decode(&propNew, props, propsSize));\r
   RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));\r
-  dicBufSize = propNew.dicSize;\r
-  if (p->dic == 0 || dicBufSize != p->dicBufSize)\r
+\r
+  {\r
+    UInt32 dictSize = propNew.dicSize;\r
+    SizeT mask = ((UInt32)1 << 12) - 1;\r
+         if (dictSize >= ((UInt32)1 << 30)) mask = ((UInt32)1 << 22) - 1;\r
+    else if (dictSize >= ((UInt32)1 << 22)) mask = ((UInt32)1 << 20) - 1;;\r
+    dicBufSize = ((SizeT)dictSize + mask) & ~mask;\r
+    if (dicBufSize < dictSize)\r
+      dicBufSize = dictSize;\r
+  }\r
+\r
+  if (!p->dic || dicBufSize != p->dicBufSize)\r
   {\r
     LzmaDec_FreeDict(p, alloc);\r
     p->dic = (Byte *)alloc->Alloc(alloc, dicBufSize);\r
-    if (p->dic == 0)\r
+    if (!p->dic)\r
     {\r
       LzmaDec_FreeProbs(p, alloc);\r
       return SZ_ERROR_MEM;\r
@@ -980,28 +1080,21 @@ SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
 {\r
   CLzmaDec p;\r
   SRes res;\r
-  SizeT inSize = *srcLen;\r
-  SizeT outSize = *destLen;\r
-  *srcLen = *destLen = 0;\r
+  SizeT outSize = *destLen, inSize = *srcLen;\r
+  *destLen = *srcLen = 0;\r
+  *status = LZMA_STATUS_NOT_SPECIFIED;\r
   if (inSize < RC_INIT_SIZE)\r
     return SZ_ERROR_INPUT_EOF;\r
-\r
   LzmaDec_Construct(&p);\r
-  res = LzmaDec_AllocateProbs(&p, propData, propSize, alloc);\r
-  if (res != 0)\r
-    return res;\r
+  RINOK(LzmaDec_AllocateProbs(&p, propData, propSize, alloc));\r
   p.dic = dest;\r
   p.dicBufSize = outSize;\r
-\r
   LzmaDec_Init(&p);\r
-  \r
   *srcLen = inSize;\r
   res = LzmaDec_DecodeToDic(&p, outSize, src, srcLen, finishMode, status);\r
-\r
+  *destLen = p.dicPos;\r
   if (res == SZ_OK && *status == LZMA_STATUS_NEEDS_MORE_INPUT)\r
     res = SZ_ERROR_INPUT_EOF;\r
-\r
-  (*destLen) = p.dicPos;\r
   LzmaDec_FreeProbs(&p, alloc);\r
   return res;\r
 }\r
index ad7d7057a4f18570383a66ad5039b4b80d5834e5..2633abeac9db432a032c28083ed0382e1ad1826b 100644 (file)
@@ -1,10 +1,12 @@
 /* LzmaDec.h -- LZMA Decoder\r
-2008-10-04 : Igor Pavlov : Public domain */\r
+2013-01-18 : Igor Pavlov : Public domain */\r
 \r
-#ifndef __LZMADEC_H\r
-#define __LZMADEC_H\r
+#ifndef __LZMA_DEC_H\r
+#define __LZMA_DEC_H\r
 \r
-#include "Types.h"\r
+#include "7zTypes.h"\r
+\r
+EXTERN_C_BEGIN\r
 \r
 /* #define _LZMA_PROB32 */\r
 /* _LZMA_PROB32 can increase the speed on some CPUs,\r
@@ -220,4 +222,6 @@ SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
     const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,\r
     ELzmaStatus *status, ISzAlloc *alloc);\r
 \r
+EXTERN_C_END\r
+\r
 #endif\r
index 5f70ebdef08eb65d0974a14c1d8d7bbbc8808d48..462ca675652439ddb2dd504b600f62178ae52ea5 100644 (file)
@@ -1,18 +1,7 @@
-/** @file\r
-  Based on LZMA SDK 4.65:\r
-    LzmaEnc.c -- LZMA Encoder\r
-    2009-02-02 : Igor Pavlov : Public domain\r
+/* LzmaEnc.c -- LZMA Encoder\r
+2016-05-16 : Igor Pavlov : Public domain */\r
 \r
-  Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.<BR>\r
-  This program and the accompanying materials\r
-  are licensed and made available under the terms and conditions of the BSD License\r
-  which accompanies this distribution.  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
+#include "Precomp.h"\r
 \r
 #include <string.h>\r
 \r
 #include "LzmaEnc.h"\r
 \r
 #include "LzFind.h"\r
-#ifdef COMPRESS_MF_MT\r
+#ifndef _7ZIP_ST\r
 #include "LzFindMt.h"\r
 #endif\r
 \r
 #ifdef SHOW_STAT\r
-static int ttt = 0;\r
+static unsigned g_STAT_OFFSET = 0;\r
 #endif\r
 \r
+#define kMaxHistorySize ((UInt32)3 << 29)\r
+/* #define kMaxHistorySize ((UInt32)7 << 29) */\r
+\r
 #define kBlockSizeMax ((1 << LZMA_NUM_BLOCK_SIZE_BITS) - 1)\r
 \r
 #define kBlockSize (9 << 10)\r
@@ -59,6 +51,7 @@ void LzmaEncProps_Init(CLzmaEncProps *p)
 {\r
   p->level = 5;\r
   p->dictSize = p->mc = 0;\r
+  p->reduceSize = (UInt64)(Int64)-1;\r
   p->lc = p->lp = p->pb = p->algo = p->fb = p->btMode = p->numHashBytes = p->numThreads = -1;\r
   p->writeEndMark = 0;\r
 }\r
@@ -68,18 +61,31 @@ void LzmaEncProps_Normalize(CLzmaEncProps *p)
   int level = p->level;\r
   if (level < 0) level = 5;\r
   p->level = level;\r
+  \r
   if (p->dictSize == 0) p->dictSize = (level <= 5 ? (1 << (level * 2 + 14)) : (level == 6 ? (1 << 25) : (1 << 26)));\r
+  if (p->dictSize > p->reduceSize)\r
+  {\r
+    unsigned i;\r
+    for (i = 11; i <= 30; i++)\r
+    {\r
+      if ((UInt32)p->reduceSize <= ((UInt32)2 << i)) { p->dictSize = ((UInt32)2 << i); break; }\r
+      if ((UInt32)p->reduceSize <= ((UInt32)3 << i)) { p->dictSize = ((UInt32)3 << i); break; }\r
+    }\r
+  }\r
+\r
   if (p->lc < 0) p->lc = 3;\r
   if (p->lp < 0) p->lp = 0;\r
   if (p->pb < 0) p->pb = 2;\r
+\r
   if (p->algo < 0) p->algo = (level < 5 ? 0 : 1);\r
   if (p->fb < 0) p->fb = (level < 7 ? 32 : 64);\r
   if (p->btMode < 0) p->btMode = (p->algo == 0 ? 0 : 1);\r
   if (p->numHashBytes < 0) p->numHashBytes = 4;\r
-  if (p->mc == 0)  p->mc = (16 + (p->fb >> 1)) >> (p->btMode ? 0 : 1);\r
+  if (p->mc == 0) p->mc = (16 + (p->fb >> 1)) >> (p->btMode ? 0 : 1);\r
+  \r
   if (p->numThreads < 0)\r
     p->numThreads =\r
-      #ifdef COMPRESS_MF_MT\r
+      #ifndef _7ZIP_ST\r
       ((p->btMode && p->algo) ? 2 : 1);\r
       #else\r
       1;\r
@@ -93,17 +99,18 @@ UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2)
   return props.dictSize;\r
 }\r
 \r
+#if (_MSC_VER >= 1400)\r
+/* BSR code is fast for some new CPUs */\r
 /* #define LZMA_LOG_BSR */\r
-/* Define it for Intel's CPU */\r
-\r
+#endif\r
 \r
 #ifdef LZMA_LOG_BSR\r
 \r
-#define kDicLogSizeMaxCompress 30\r
+#define kDicLogSizeMaxCompress 32\r
 \r
-#define BSR2_RET(pos, res) { unsigned long i; _BitScanReverse(&i, (pos)); res = (i + i) + ((pos >> (i - 1)) & 1); }\r
+#define BSR2_RET(pos, res) { unsigned long zz; _BitScanReverse(&zz, (pos)); res = (zz + zz) + ((pos >> (zz - 1)) & 1); }\r
 \r
-UInt32 GetPosSlot1(UInt32 pos)\r
+static UInt32 GetPosSlot1(UInt32 pos)\r
 {\r
   UInt32 res;\r
   BSR2_RET(pos, res);\r
@@ -114,27 +121,44 @@ UInt32 GetPosSlot1(UInt32 pos)
 \r
 #else\r
 \r
-#define kNumLogBits (9 + (int)sizeof(size_t) / 2)\r
+#define kNumLogBits (9 + sizeof(size_t) / 2)\r
+/* #define kNumLogBits (11 + sizeof(size_t) / 8 * 3) */\r
+\r
 #define kDicLogSizeMaxCompress ((kNumLogBits - 1) * 2 + 7)\r
 \r
-void LzmaEnc_FastPosInit(Byte *g_FastPos)\r
+static void LzmaEnc_FastPosInit(Byte *g_FastPos)\r
 {\r
-  int c = 2, slotFast;\r
+  unsigned slot;\r
   g_FastPos[0] = 0;\r
   g_FastPos[1] = 1;\r
+  g_FastPos += 2;\r
   \r
-  for (slotFast = 2; slotFast < kNumLogBits * 2; slotFast++)\r
+  for (slot = 2; slot < kNumLogBits * 2; slot++)\r
   {\r
-    UInt32 k = (1 << ((slotFast >> 1) - 1));\r
-    UInt32 j;\r
-    for (j = 0; j < k; j++, c++)\r
-      g_FastPos[c] = (Byte)slotFast;\r
+    size_t k = ((size_t)1 << ((slot >> 1) - 1));\r
+    size_t j;\r
+    for (j = 0; j < k; j++)\r
+      g_FastPos[j] = (Byte)slot;\r
+    g_FastPos += k;\r
   }\r
 }\r
 \r
-#define BSR2_RET(pos, res) { UInt32 ij = 6 + ((kNumLogBits - 1) & \\r
+/* we can use ((limit - pos) >> 31) only if (pos < ((UInt32)1 << 31)) */\r
+/*\r
+#define BSR2_RET(pos, res) { UInt32 zz = 6 + ((kNumLogBits - 1) & \\r
   (0 - (((((UInt32)1 << (kNumLogBits + 6)) - 1) - pos) >> 31))); \\r
-  res = p->g_FastPos[pos >> ij] + (ij * 2); }\r
+  res = p->g_FastPos[pos >> zz] + (zz * 2); }\r
+*/\r
+\r
+/*\r
+#define BSR2_RET(pos, res) { UInt32 zz = 6 + ((kNumLogBits - 1) & \\r
+  (0 - (((((UInt32)1 << (kNumLogBits)) - 1) - (pos >> 6)) >> 31))); \\r
+  res = p->g_FastPos[pos >> zz] + (zz * 2); }\r
+*/\r
+\r
+#define BSR2_RET(pos, res) { UInt32 zz = (pos < (1 << (kNumLogBits + 6))) ? 6 : 6 + kNumLogBits - 1; \\r
+  res = p->g_FastPos[pos >> zz] + (zz * 2); }\r
+\r
 /*\r
 #define BSR2_RET(pos, res) { res = (pos < (1 << (kNumLogBits + 6))) ? \\r
   p->g_FastPos[pos >> 6] + 12 : \\r
@@ -152,7 +176,7 @@ void LzmaEnc_FastPosInit(Byte *g_FastPos)
 \r
 typedef unsigned CState;\r
 \r
-typedef struct _COptimal\r
+typedef struct\r
 {\r
   UInt32 price;\r
 \r
@@ -185,7 +209,7 @@ typedef struct _COptimal
 #define kEndPosModelIndex 14\r
 #define kNumPosModels (kEndPosModelIndex - kStartPosModelIndex)\r
 \r
-#define kNumFullDistances (1 << (kEndPosModelIndex / 2))\r
+#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))\r
 \r
 #ifdef _LZMA_PROB32\r
 #define CLzmaProb UInt32\r
@@ -214,6 +238,7 @@ typedef struct _COptimal
 \r
 #define kNumStates 12\r
 \r
+\r
 typedef struct\r
 {\r
   CLzmaProb choice;\r
@@ -223,15 +248,17 @@ typedef struct
   CLzmaProb high[kLenNumHighSymbols];\r
 } CLenEnc;\r
 \r
+\r
 typedef struct\r
 {\r
   CLenEnc p;\r
-  UInt32 prices[LZMA_NUM_PB_STATES_MAX][kLenNumSymbolsTotal];\r
   UInt32 tableSize;\r
+  UInt32 prices[LZMA_NUM_PB_STATES_MAX][kLenNumSymbolsTotal];\r
   UInt32 counters[LZMA_NUM_PB_STATES_MAX];\r
 } CLenPriceEnc;\r
 \r
-typedef struct _CRangeEnc\r
+\r
+typedef struct\r
 {\r
   UInt32 range;\r
   Byte cache;\r
@@ -245,30 +272,14 @@ typedef struct _CRangeEnc
   SRes res;\r
 } CRangeEnc;\r
 \r
-typedef struct _CSeqInStreamBuf\r
-{\r
-  ISeqInStream funcTable;\r
-  const Byte *data;\r
-  SizeT rem;\r
-} CSeqInStreamBuf;\r
-\r
-static SRes MyRead(void *pp, void *data, size_t *size)\r
-{\r
-  size_t curSize = *size;\r
-  CSeqInStreamBuf *p = (CSeqInStreamBuf *)pp;\r
-  if (p->rem < curSize)\r
-    curSize = p->rem;\r
-  memcpy(data, p->data, curSize);\r
-  p->rem -= curSize;\r
-  p->data += curSize;\r
-  *size = curSize;\r
-  return SZ_OK;\r
-}\r
 \r
 typedef struct\r
 {\r
   CLzmaProb *litProbs;\r
 \r
+  UInt32 state;\r
+  UInt32 reps[LZMA_NUM_REPS];\r
+\r
   CLzmaProb isMatch[kNumStates][LZMA_NUM_PB_STATES_MAX];\r
   CLzmaProb isRep[kNumStates];\r
   CLzmaProb isRepG0[kNumStates];\r
@@ -282,33 +293,61 @@ typedef struct
   \r
   CLenPriceEnc lenEnc;\r
   CLenPriceEnc repLenEnc;\r
-\r
-  UInt32 reps[LZMA_NUM_REPS];\r
-  UInt32 state;\r
 } CSaveState;\r
 \r
-typedef struct _CLzmaEnc\r
+\r
+typedef struct\r
 {\r
-  IMatchFinder matchFinder;\r
   void *matchFinderObj;\r
+  IMatchFinder matchFinder;\r
+\r
+  UInt32 optimumEndIndex;\r
+  UInt32 optimumCurrentIndex;\r
 \r
-  #ifdef COMPRESS_MF_MT\r
+  UInt32 longestMatchLength;\r
+  UInt32 numPairs;\r
+  UInt32 numAvail;\r
+\r
+  UInt32 numFastBytes;\r
+  UInt32 additionalOffset;\r
+  UInt32 reps[LZMA_NUM_REPS];\r
+  UInt32 state;\r
+\r
+  unsigned lc, lp, pb;\r
+  unsigned lpMask, pbMask;\r
+  unsigned lclp;\r
+\r
+  CLzmaProb *litProbs;\r
+\r
+  Bool fastMode;\r
+  Bool writeEndMark;\r
+  Bool finished;\r
+  Bool multiThread;\r
+  Bool needInit;\r
+\r
+  UInt64 nowPos64;\r
+  \r
+  UInt32 matchPriceCount;\r
+  UInt32 alignPriceCount;\r
+\r
+  UInt32 distTableSize;\r
+\r
+  UInt32 dictSize;\r
+  SRes result;\r
+\r
+  CRangeEnc rc;\r
+\r
+  #ifndef _7ZIP_ST\r
   Bool mtMode;\r
   CMatchFinderMt matchFinderMt;\r
   #endif\r
 \r
   CMatchFinder matchFinderBase;\r
 \r
-  #ifdef COMPRESS_MF_MT\r
+  #ifndef _7ZIP_ST\r
   Byte pad[128];\r
   #endif\r
   \r
-  UInt32 optimumEndIndex;\r
-  UInt32 optimumCurrentIndex;\r
-\r
-  UInt32 longestMatchLength;\r
-  UInt32 numPairs;\r
-  UInt32 numAvail;\r
   COptimal opt[kNumOpts];\r
   \r
   #ifndef LZMA_LOG_BSR\r
@@ -317,22 +356,10 @@ typedef struct _CLzmaEnc
 \r
   UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];\r
   UInt32 matches[LZMA_MATCH_LEN_MAX * 2 + 2 + 1];\r
-  UInt32 numFastBytes;\r
-  UInt32 additionalOffset;\r
-  UInt32 reps[LZMA_NUM_REPS];\r
-  UInt32 state;\r
 \r
   UInt32 posSlotPrices[kNumLenToPosStates][kDistTableSizeMax];\r
   UInt32 distancesPrices[kNumLenToPosStates][kNumFullDistances];\r
   UInt32 alignPrices[kAlignTableSize];\r
-  UInt32 alignPriceCount;\r
-\r
-  UInt32 distTableSize;\r
-\r
-  unsigned lc, lp, pb;\r
-  unsigned lpMask, pbMask;\r
-\r
-  CLzmaProb *litProbs;\r
 \r
   CLzmaProb isMatch[kNumStates][LZMA_NUM_PB_STATES_MAX];\r
   CLzmaProb isRep[kNumStates];\r
@@ -348,28 +375,14 @@ typedef struct _CLzmaEnc
   CLenPriceEnc lenEnc;\r
   CLenPriceEnc repLenEnc;\r
 \r
-  unsigned lclp;\r
-\r
-  Bool fastMode;\r
-  \r
-  CRangeEnc rc;\r
-\r
-  Bool writeEndMark;\r
-  UInt64 nowPos64;\r
-  UInt32 matchPriceCount;\r
-  Bool finished;\r
-  Bool multiThread;\r
-\r
-  SRes result;\r
-  UInt32 dictSize;\r
-  UInt32 matchFinderCycles;\r
-\r
-  ISeqInStream *inStream;\r
-  CSeqInStreamBuf seqBufInStream;\r
-\r
   CSaveState saveState;\r
+\r
+  #ifndef _7ZIP_ST\r
+  Byte pad2[128];\r
+  #endif\r
 } CLzmaEnc;\r
 \r
+\r
 void LzmaEnc_SaveState(CLzmaEncHandle pp)\r
 {\r
   CLzmaEnc *p = (CLzmaEnc *)pp;\r
@@ -393,7 +406,7 @@ void LzmaEnc_SaveState(CLzmaEncHandle pp)
   memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders));\r
   memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder));\r
   memcpy(dest->reps, p->reps, sizeof(p->reps));\r
-  memcpy(dest->litProbs, p->litProbs, (0x300 << p->lclp) * sizeof(CLzmaProb));\r
+  memcpy(dest->litProbs, p->litProbs, ((UInt32)0x300 << p->lclp) * sizeof(CLzmaProb));\r
 }\r
 \r
 void LzmaEnc_RestoreState(CLzmaEncHandle pp)\r
@@ -419,7 +432,7 @@ void LzmaEnc_RestoreState(CLzmaEncHandle pp)
   memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders));\r
   memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder));\r
   memcpy(dest->reps, p->reps, sizeof(p->reps));\r
-  memcpy(dest->litProbs, p->litProbs, (0x300 << dest->lclp) * sizeof(CLzmaProb));\r
+  memcpy(dest->litProbs, p->litProbs, ((UInt32)0x300 << dest->lclp) * sizeof(CLzmaProb));\r
 }\r
 \r
 SRes LzmaEnc_SetProps(CLzmaEncHandle pp, const CLzmaEncProps *props2)\r
@@ -428,11 +441,14 @@ SRes LzmaEnc_SetProps(CLzmaEncHandle pp, const CLzmaEncProps *props2)
   CLzmaEncProps props = *props2;\r
   LzmaEncProps_Normalize(&props);\r
 \r
-  if (props.lc > LZMA_LC_MAX || props.lp > LZMA_LP_MAX || props.pb > LZMA_PB_MAX ||\r
-      props.dictSize > (1 << kDicLogSizeMaxCompress) || props.dictSize > (1 << 30))\r
+  if (props.lc > LZMA_LC_MAX\r
+      || props.lp > LZMA_LP_MAX\r
+      || props.pb > LZMA_PB_MAX\r
+      || props.dictSize > ((UInt64)1 << kDicLogSizeMaxCompress)\r
+      || props.dictSize > kMaxHistorySize)\r
     return SZ_ERROR_PARAM;\r
+\r
   p->dictSize = props.dictSize;\r
-  p->matchFinderCycles = props.mc;\r
   {\r
     unsigned fb = props.fb;\r
     if (fb < 5)\r
@@ -445,7 +461,7 @@ SRes LzmaEnc_SetProps(CLzmaEncHandle pp, const CLzmaEncProps *props2)
   p->lp = props.lp;\r
   p->pb = props.pb;\r
   p->fastMode = (props.algo == 0);\r
-  p->matchFinderBase.btMode = props.btMode;\r
+  p->matchFinderBase.btMode = (Byte)(props.btMode ? 1 : 0);\r
   {\r
     UInt32 numHashBytes = 4;\r
     if (props.btMode)\r
@@ -462,7 +478,7 @@ SRes LzmaEnc_SetProps(CLzmaEncHandle pp, const CLzmaEncProps *props2)
 \r
   p->writeEndMark = props.writeEndMark;\r
 \r
-  #ifdef COMPRESS_MF_MT\r
+  #ifndef _7ZIP_ST\r
   /*\r
   if (newMultiThread != _multiThread)\r
   {\r
@@ -489,8 +505,8 @@ static const int kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11,
 \r
 static void RangeEnc_Construct(CRangeEnc *p)\r
 {\r
-  p->outStream = 0;\r
-  p->bufBase = 0;\r
+  p->outStream = NULL;\r
+  p->bufBase = NULL;\r
 }\r
 \r
 #define RangeEnc_GetProcessed(p) ((p)->processed + ((p)->buf - (p)->bufBase) + (p)->cacheSize)\r
@@ -498,10 +514,10 @@ static void RangeEnc_Construct(CRangeEnc *p)
 #define RC_BUF_SIZE (1 << 16)\r
 static int RangeEnc_Alloc(CRangeEnc *p, ISzAlloc *alloc)\r
 {\r
-  if (p->bufBase == 0)\r
+  if (!p->bufBase)\r
   {\r
     p->bufBase = (Byte *)alloc->Alloc(alloc, RC_BUF_SIZE);\r
-    if (p->bufBase == 0)\r
+    if (!p->bufBase)\r
       return 0;\r
     p->bufLim = p->bufBase + RC_BUF_SIZE;\r
   }\r
@@ -542,7 +558,7 @@ static void RangeEnc_FlushStream(CRangeEnc *p)
 \r
 static void MY_FAST_CALL RangeEnc_ShiftLow(CRangeEnc *p)\r
 {\r
-  if ((UInt32)p->low < (UInt32)0xFF000000 || (int)(p->low >> 32) != 0)\r
+  if ((UInt32)p->low < (UInt32)0xFF000000 || (unsigned)(p->low >> 32) != 0)\r
   {\r
     Byte temp = p->cache;\r
     do\r
@@ -568,7 +584,7 @@ static void RangeEnc_FlushData(CRangeEnc *p)
     RangeEnc_ShiftLow(p);\r
 }\r
 \r
-static void RangeEnc_EncodeDirectBits(CRangeEnc *p, UInt32 value, int numBits)\r
+static void RangeEnc_EncodeDirectBits(CRangeEnc *p, UInt32 value, unsigned numBits)\r
 {\r
   do\r
   {\r
@@ -631,7 +647,7 @@ static void LitEnc_EncodeMatched(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol,
   while (symbol < 0x10000);\r
 }\r
 \r
-void LzmaEnc_InitPriceTables(UInt32 *ProbPrices)\r
+static void LzmaEnc_InitPriceTables(UInt32 *ProbPrices)\r
 {\r
   UInt32 i;\r
   for (i = (1 << kNumMoveReducingBits) / 2; i < kBitModelTotal; i += (1 << kNumMoveReducingBits))\r
@@ -667,7 +683,7 @@ void LzmaEnc_InitPriceTables(UInt32 *ProbPrices)
 #define GET_PRICE_0a(prob) ProbPrices[(prob) >> kNumMoveReducingBits]\r
 #define GET_PRICE_1a(prob) ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]\r
 \r
-static UInt32 LitEnc_GetPrice(const CLzmaProb *probs, UInt32 symbol, UInt32 *ProbPrices)\r
+static UInt32 LitEnc_GetPrice(const CLzmaProb *probs, UInt32 symbol, const UInt32 *ProbPrices)\r
 {\r
   UInt32 price = 0;\r
   symbol |= 0x100;\r
@@ -680,7 +696,7 @@ static UInt32 LitEnc_GetPrice(const CLzmaProb *probs, UInt32 symbol, UInt32 *Pro
   return price;\r
 }\r
 \r
-static UInt32 LitEnc_GetPriceMatched(const CLzmaProb *probs, UInt32 symbol, UInt32 matchByte, UInt32 *ProbPrices)\r
+static UInt32 LitEnc_GetPriceMatched(const CLzmaProb *probs, UInt32 symbol, UInt32 matchByte, const UInt32 *ProbPrices)\r
 {\r
   UInt32 price = 0;\r
   UInt32 offs = 0x100;\r
@@ -724,7 +740,7 @@ static void RcTree_ReverseEncode(CRangeEnc *rc, CLzmaProb *probs, int numBitLeve
   }\r
 }\r
 \r
-static UInt32 RcTree_GetPrice(const CLzmaProb *probs, int numBitLevels, UInt32 symbol, UInt32 *ProbPrices)\r
+static UInt32 RcTree_GetPrice(const CLzmaProb *probs, int numBitLevels, UInt32 symbol, const UInt32 *ProbPrices)\r
 {\r
   UInt32 price = 0;\r
   symbol |= (1 << numBitLevels);\r
@@ -736,7 +752,7 @@ static UInt32 RcTree_GetPrice(const CLzmaProb *probs, int numBitLevels, UInt32 s
   return price;\r
 }\r
 \r
-static UInt32 RcTree_ReverseGetPrice(const CLzmaProb *probs, int numBitLevels, UInt32 symbol, UInt32 *ProbPrices)\r
+static UInt32 RcTree_ReverseGetPrice(const CLzmaProb *probs, int numBitLevels, UInt32 symbol, const UInt32 *ProbPrices)\r
 {\r
   UInt32 price = 0;\r
   UInt32 m = 1;\r
@@ -787,7 +803,7 @@ static void LenEnc_Encode(CLenEnc *p, CRangeEnc *rc, UInt32 symbol, UInt32 posSt
   }\r
 }\r
 \r
-static void LenEnc_SetPrices(CLenEnc *p, UInt32 posState, UInt32 numSymbols, UInt32 *prices, UInt32 *ProbPrices)\r
+static void LenEnc_SetPrices(CLenEnc *p, UInt32 posState, UInt32 numSymbols, UInt32 *prices, const UInt32 *ProbPrices)\r
 {\r
   UInt32 a0 = GET_PRICE_0a(p->choice);\r
   UInt32 a1 = GET_PRICE_1a(p->choice);\r
@@ -810,20 +826,20 @@ static void LenEnc_SetPrices(CLenEnc *p, UInt32 posState, UInt32 numSymbols, UIn
     prices[i] = b1 + RcTree_GetPrice(p->high, kLenNumHighBits, i - kLenNumLowSymbols - kLenNumMidSymbols, ProbPrices);\r
 }\r
 \r
-static void MY_FAST_CALL LenPriceEnc_UpdateTable(CLenPriceEnc *p, UInt32 posState, UInt32 *ProbPrices)\r
+static void MY_FAST_CALL LenPriceEnc_UpdateTable(CLenPriceEnc *p, UInt32 posState, const UInt32 *ProbPrices)\r
 {\r
   LenEnc_SetPrices(&p->p, posState, p->tableSize, p->prices[posState], ProbPrices);\r
   p->counters[posState] = p->tableSize;\r
 }\r
 \r
-static void LenPriceEnc_UpdateTables(CLenPriceEnc *p, UInt32 numPosStates, UInt32 *ProbPrices)\r
+static void LenPriceEnc_UpdateTables(CLenPriceEnc *p, UInt32 numPosStates, const UInt32 *ProbPrices)\r
 {\r
   UInt32 posState;\r
   for (posState = 0; posState < numPosStates; posState++)\r
     LenPriceEnc_UpdateTable(p, posState, ProbPrices);\r
 }\r
 \r
-static void LenEnc_Encode2(CLenPriceEnc *p, CRangeEnc *rc, UInt32 symbol, UInt32 posState, Bool updatePrice, UInt32 *ProbPrices)\r
+static void LenEnc_Encode2(CLenPriceEnc *p, CRangeEnc *rc, UInt32 symbol, UInt32 posState, Bool updatePrice, const UInt32 *ProbPrices)\r
 {\r
   LenEnc_Encode(&p->p, rc, symbol, posState);\r
   if (updatePrice)\r
@@ -837,9 +853,10 @@ static void LenEnc_Encode2(CLenPriceEnc *p, CRangeEnc *rc, UInt32 symbol, UInt32
 static void MovePos(CLzmaEnc *p, UInt32 num)\r
 {\r
   #ifdef SHOW_STAT\r
-  ttt += num;\r
-  printf("\n MovePos %d", num);\r
+  g_STAT_OFFSET += num;\r
+  printf("\n MovePos %u", num);\r
   #endif\r
+  \r
   if (num != 0)\r
   {\r
     p->additionalOffset += num;\r
@@ -852,28 +869,32 @@ static UInt32 ReadMatchDistances(CLzmaEnc *p, UInt32 *numDistancePairsRes)
   UInt32 lenRes = 0, numPairs;\r
   p->numAvail = p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);\r
   numPairs = p->matchFinder.GetMatches(p->matchFinderObj, p->matches);\r
+  \r
   #ifdef SHOW_STAT\r
-  printf("\n i = %d numPairs = %d    ", ttt, numPairs / 2);\r
-  ttt++;\r
+  printf("\n i = %u numPairs = %u    ", g_STAT_OFFSET, numPairs / 2);\r
+  g_STAT_OFFSET++;\r
   {\r
     UInt32 i;\r
     for (i = 0; i < numPairs; i += 2)\r
-      printf("%2d %6d   | ", p->matches[i], p->matches[i + 1]);\r
+      printf("%2u %6u   | ", p->matches[i], p->matches[i + 1]);\r
   }\r
   #endif\r
+  \r
   if (numPairs > 0)\r
   {\r
     lenRes = p->matches[numPairs - 2];\r
     if (lenRes == p->numFastBytes)\r
     {\r
-      const Byte *pby = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;\r
-      UInt32 distance = p->matches[numPairs - 1] + 1;\r
       UInt32 numAvail = p->numAvail;\r
       if (numAvail > LZMA_MATCH_LEN_MAX)\r
         numAvail = LZMA_MATCH_LEN_MAX;\r
       {\r
-        const Byte *pby2 = pby - distance;\r
-        for (; lenRes < numAvail && pby[lenRes] == pby2[lenRes]; lenRes++);\r
+        const Byte *pbyCur = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;\r
+        const Byte *pby = pbyCur + lenRes;\r
+        ptrdiff_t dif = (ptrdiff_t)-1 - p->matches[numPairs - 1];\r
+        const Byte *pbyLim = pbyCur + numAvail;\r
+        for (; pby != pbyLim && *pby == pby[dif]; pby++);\r
+        lenRes = (UInt32)(pby - pbyCur);\r
       }\r
     }\r
   }\r
@@ -958,16 +979,21 @@ static UInt32 Backward(CLzmaEnc *p, UInt32 *backRes, UInt32 cur)
   return p->optimumCurrentIndex;\r
 }\r
 \r
-#define LIT_PROBS(pos, prevByte) (p->litProbs + ((((pos) & p->lpMask) << p->lc) + ((prevByte) >> (8 - p->lc))) * 0x300)\r
+#define LIT_PROBS(pos, prevByte) (p->litProbs + ((((pos) & p->lpMask) << p->lc) + ((prevByte) >> (8 - p->lc))) * (UInt32)0x300)\r
 \r
 static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)\r
 {\r
-  UInt32 numAvail, mainLen, numPairs, repMaxIndex, i, posState, lenEnd, len, cur;\r
-  UInt32 matchPrice, repMatchPrice, normalMatchPrice;\r
+  UInt32 lenEnd, cur;\r
   UInt32 reps[LZMA_NUM_REPS], repLens[LZMA_NUM_REPS];\r
   UInt32 *matches;\r
+\r
+  {\r
+\r
+  UInt32 numAvail, mainLen, numPairs, repMaxIndex, i, posState, len;\r
+  UInt32 matchPrice, repMatchPrice, normalMatchPrice;\r
   const Byte *data;\r
   Byte curByte, matchByte;\r
+\r
   if (p->optimumEndIndex != p->optimumCurrentIndex)\r
   {\r
     const COptimal *opt = &p->opt[p->optimumCurrentIndex];\r
@@ -1002,7 +1028,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
     UInt32 lenTest;\r
     const Byte *data2;\r
     reps[i] = p->reps[i];\r
-    data2 = data - (reps[i] + 1);\r
+    data2 = data - reps[i] - 1;\r
     if (data[0] != data2[0] || data[1] != data2[1])\r
     {\r
       repLens[i] = 0;\r
@@ -1146,20 +1172,25 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
   cur = 0;\r
 \r
     #ifdef SHOW_STAT2\r
-    if (position >= 0)\r
+    /* if (position >= 0) */\r
     {\r
-      unsigned ii;\r
+      unsigned i;\r
       printf("\n pos = %4X", position);\r
-      for (ii = cur; ii <= lenEnd; ii++)\r
-      printf("\nprice[%4X] = %d", position - cur + ii, p->opt[ii].price);\r
+      for (i = cur; i <= lenEnd; i++)\r
+      printf("\nprice[%4X] = %u", position - cur + i, p->opt[i].price);\r
     }\r
     #endif\r
 \r
+  }\r
+\r
   for (;;)\r
   {\r
-    UInt32 numAvailFull, newLen, posPrev, state, startLen;\r
-    UInt32 curPrice, curAnd1Price;\r
+    UInt32 numAvail;\r
+    UInt32 numAvailFull, newLen, numPairs, posPrev, state, posState, startLen;\r
+    UInt32 curPrice, curAnd1Price, matchPrice, repMatchPrice;\r
     Bool nextIsChar;\r
+    Byte curByte, matchByte;\r
+    const Byte *data;\r
     COptimal *curOpt;\r
     COptimal *nextOpt;\r
 \r
@@ -1222,6 +1253,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
       prevOpt = &p->opt[posPrev];\r
       if (pos < LZMA_NUM_REPS)\r
       {\r
+        UInt32 i;\r
         reps[0] = prevOpt->backs[pos];\r
         for (i = 1; i <= pos; i++)\r
           reps[i] = prevOpt->backs[i - 1];\r
@@ -1230,6 +1262,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
       }\r
       else\r
       {\r
+        UInt32 i;\r
         reps[0] = (pos - LZMA_NUM_REPS);\r
         for (i = 1; i < LZMA_NUM_REPS; i++)\r
           reps[i] = prevOpt->backs[i - 1];\r
@@ -1299,7 +1332,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
       /* try Literal + rep0 */\r
       UInt32 temp;\r
       UInt32 lenTest2;\r
-      const Byte *data2 = data - (reps[0] + 1);\r
+      const Byte *data2 = data - reps[0] - 1;\r
       UInt32 limit = p->numFastBytes + 1;\r
       if (limit > numAvailFull)\r
         limit = numAvailFull;\r
@@ -1315,11 +1348,12 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
             GET_PRICE_1(p->isRep[state2]);\r
         /* for (; lenTest2 >= 2; lenTest2--) */\r
         {\r
+          UInt32 curAndLenPrice;\r
           COptimal *opt;\r
           UInt32 offset = cur + 1 + lenTest2;\r
           while (lenEnd < offset)\r
             p->opt[++lenEnd].price = kInfinityPrice;\r
-          UInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);\r
+          curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);\r
           opt = &p->opt[offset];\r
           if (curAndLenPrice < opt->price)\r
           {\r
@@ -1341,7 +1375,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
       UInt32 lenTest;\r
       UInt32 lenTestTemp;\r
       UInt32 price;\r
-      const Byte *data2 = data - (reps[repIndex] + 1);\r
+      const Byte *data2 = data - reps[repIndex] - 1;\r
       if (data[0] != data2[0] || data[1] != data2[1])\r
         continue;\r
       for (lenTest = 2; lenTest < numAvail && data[lenTest] == data2[lenTest]; lenTest++);\r
@@ -1366,20 +1400,18 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
       \r
       if (repIndex == 0)\r
         startLen = lenTest + 1;\r
-\r
-#ifndef _MSC_VER\r
-      if (1 /* _maxMode */)\r
-#endif\r
+        \r
+      /* if (_maxMode) */\r
         {\r
           UInt32 lenTest2 = lenTest + 1;\r
           UInt32 limit = lenTest2 + p->numFastBytes;\r
-          UInt32 nextRepMatchPrice;\r
           if (limit > numAvailFull)\r
             limit = numAvailFull;\r
           for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++);\r
           lenTest2 -= lenTest + 1;\r
           if (lenTest2 >= 2)\r
           {\r
+            UInt32 nextRepMatchPrice;\r
             UInt32 state2 = kRepNextStates[state];\r
             UInt32 posStateNext = (position + lenTest) & p->pbMask;\r
             UInt32 curAndLenCharPrice =\r
@@ -1427,7 +1459,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
     }\r
     if (newLen >= startLen)\r
     {\r
-      normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[state]);\r
+      UInt32 normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[state]);\r
       UInt32 offs, curBack, posSlot;\r
       UInt32 lenTest;\r
       while (lenEnd < cur + newLen)\r
@@ -1440,8 +1472,8 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
       GetPosSlot2(curBack, posSlot);\r
       for (lenTest = /*2*/ startLen; ; lenTest++)\r
       {\r
-        UInt32 curAndLenPrice;\r
-        curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][lenTest - LZMA_MATCH_LEN_MIN];\r
+        UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][lenTest - LZMA_MATCH_LEN_MIN];\r
+        {\r
         UInt32 lenToPosState = GetLenToPosState(lenTest);\r
         COptimal *opt;\r
         if (curBack < kNumFullDistances)\r
@@ -1457,20 +1489,21 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
           opt->backPrev = curBack + LZMA_NUM_REPS;\r
           opt->prev1IsChar = False;\r
         }\r
+        }\r
 \r
         if (/*_maxMode && */lenTest == matches[offs])\r
         {\r
           /* Try Match + Literal + Rep0 */\r
-          const Byte *data2 = data - (curBack + 1);\r
+          const Byte *data2 = data - curBack - 1;\r
           UInt32 lenTest2 = lenTest + 1;\r
           UInt32 limit = lenTest2 + p->numFastBytes;\r
-          UInt32 nextRepMatchPrice;\r
           if (limit > numAvailFull)\r
             limit = numAvailFull;\r
           for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++);\r
           lenTest2 -= lenTest + 1;\r
           if (lenTest2 >= 2)\r
           {\r
+            UInt32 nextRepMatchPrice;\r
             UInt32 state2 = kMatchNextStates[state];\r
             UInt32 posStateNext = (position + lenTest) & p->pbMask;\r
             UInt32 curAndLenCharPrice = curAndLenPrice +\r
@@ -1486,14 +1519,15 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
             /* for (; lenTest2 >= 2; lenTest2--) */\r
             {\r
               UInt32 offset = cur + lenTest + 1 + lenTest2;\r
-\r
+              UInt32 curAndLenPrice2;\r
+              COptimal *opt;\r
               while (lenEnd < offset)\r
                 p->opt[++lenEnd].price = kInfinityPrice;\r
-              curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);\r
+              curAndLenPrice2 = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);\r
               opt = &p->opt[offset];\r
-              if (curAndLenPrice < opt->price)\r
+              if (curAndLenPrice2 < opt->price)\r
               {\r
-                opt->price = curAndLenPrice;\r
+                opt->price = curAndLenPrice2;\r
                 opt->posPrev = cur + lenTest + 1;\r
                 opt->backPrev = 0;\r
                 opt->prev1IsChar = True;\r
@@ -1543,7 +1577,7 @@ static UInt32 GetOptimumFast(CLzmaEnc *p, UInt32 *backRes)
   for (i = 0; i < LZMA_NUM_REPS; i++)\r
   {\r
     UInt32 len;\r
-    const Byte *data2 = data - (p->reps[i] + 1);\r
+    const Byte *data2 = data - p->reps[i] - 1;\r
     if (data[0] != data2[0] || data[1] != data2[1])\r
       continue;\r
     for (len = 2; len < numAvail && data[len] == data2[len]; len++);\r
@@ -1612,7 +1646,7 @@ static UInt32 GetOptimumFast(CLzmaEnc *p, UInt32 *backRes)
   for (i = 0; i < LZMA_NUM_REPS; i++)\r
   {\r
     UInt32 len, limit;\r
-    const Byte *data2 = data - (p->reps[i] + 1);\r
+    const Byte *data2 = data - p->reps[i] - 1;\r
     if (data[0] != data2[0] || data[1] != data2[1])\r
       continue;\r
     limit = mainLen - 1;\r
@@ -1694,7 +1728,6 @@ static void FillDistancesPrices(CLzmaEnc *p)
 \r
     {\r
       UInt32 *distancesPrices = p->distancesPrices[lenToPosState];\r
-\r
       for (i = 0; i < kStartPosModelIndex; i++)\r
         distancesPrices[i] = posSlotPrices[i];\r
       for (; i < kNumFullDistances; i++)\r
@@ -1708,7 +1741,8 @@ void LzmaEnc_Construct(CLzmaEnc *p)
 {\r
   RangeEnc_Construct(&p->rc);\r
   MatchFinder_Construct(&p->matchFinderBase);\r
-  #ifdef COMPRESS_MF_MT\r
+  \r
+  #ifndef _7ZIP_ST\r
   MatchFinderMt_Construct(&p->matchFinderMt);\r
   p->matchFinderMt.MatchFinder = &p->matchFinderBase;\r
   #endif\r
@@ -1724,15 +1758,15 @@ void LzmaEnc_Construct(CLzmaEnc *p)
   #endif\r
 \r
   LzmaEnc_InitPriceTables(p->ProbPrices);\r
-  p->litProbs = 0;\r
-  p->saveState.litProbs = 0;\r
+  p->litProbs = NULL;\r
+  p->saveState.litProbs = NULL;\r
 }\r
 \r
 CLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc)\r
 {\r
   void *p;\r
   p = alloc->Alloc(alloc, sizeof(CLzmaEnc));\r
-  if (p != 0)\r
+  if (p)\r
     LzmaEnc_Construct((CLzmaEnc *)p);\r
   return p;\r
 }\r
@@ -1741,15 +1775,16 @@ void LzmaEnc_FreeLits(CLzmaEnc *p, ISzAlloc *alloc)
 {\r
   alloc->Free(alloc, p->litProbs);\r
   alloc->Free(alloc, p->saveState.litProbs);\r
-  p->litProbs = 0;\r
-  p->saveState.litProbs = 0;\r
+  p->litProbs = NULL;\r
+  p->saveState.litProbs = NULL;\r
 }\r
 \r
 void LzmaEnc_Destruct(CLzmaEnc *p, ISzAlloc *alloc, ISzAlloc *allocBig)\r
 {\r
-  #ifdef COMPRESS_MF_MT\r
+  #ifndef _7ZIP_ST\r
   MatchFinderMt_Destruct(&p->matchFinderMt, allocBig);\r
   #endif\r
+  \r
   MatchFinder_Free(&p->matchFinderBase, allocBig);\r
   LzmaEnc_FreeLits(p, alloc);\r
   RangeEnc_Free(&p->rc, alloc);\r
@@ -1764,11 +1799,10 @@ void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig)
 static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize, UInt32 maxUnpackSize)\r
 {\r
   UInt32 nowPos32, startPos32;\r
-  if (p->inStream != 0)\r
+  if (p->needInit)\r
   {\r
-    p->matchFinderBase.stream = p->inStream;\r
     p->matchFinder.Init(p->matchFinderObj);\r
-    p->inStream = 0;\r
+    p->needInit = 0;\r
   }\r
 \r
   if (p->finished)\r
@@ -1787,7 +1821,7 @@ static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize
     ReadMatchDistances(p, &numPairs);\r
     RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][0], 0);\r
     p->state = kLiteralNextStates[p->state];\r
-    curByte = p->matchFinder.GetIndexByte(p->matchFinderObj, 0 - p->additionalOffset);\r
+    curByte = *(p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset);\r
     LitEnc_Encode(&p->rc, p->litProbs, curByte);\r
     p->additionalOffset--;\r
     nowPos32++;\r
@@ -1804,7 +1838,7 @@ static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize
       len = GetOptimum(p, nowPos32, &pos);\r
 \r
     #ifdef SHOW_STAT2\r
-    printf("\n pos = %4X,   len = %d   pos = %d", nowPos32, len, pos);\r
+    printf("\n pos = %4X,   len = %u   pos = %u", nowPos32, len, pos);\r
     #endif\r
 \r
     posState = nowPos32 & p->pbMask;\r
@@ -1913,7 +1947,7 @@ static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize
             RangeEnc_GetProcessed(&p->rc) + kNumOpts * 2 >= maxPackSize)\r
           break;\r
       }\r
-      else if (processed >= (1 << 15))\r
+      else if (processed >= (1 << 17))\r
       {\r
         p->nowPos64 += nowPos32 - startPos32;\r
         return CheckErrors(p);\r
@@ -1929,24 +1963,21 @@ static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize
 static SRes LzmaEnc_Alloc(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)\r
 {\r
   UInt32 beforeSize = kNumOpts;\r
-  #ifdef COMPRESS_MF_MT\r
-  Bool btMode;\r
-  #endif\r
   if (!RangeEnc_Alloc(&p->rc, alloc))\r
     return SZ_ERROR_MEM;\r
-  #ifdef COMPRESS_MF_MT\r
-  btMode = (p->matchFinderBase.btMode != 0);\r
-  p->mtMode = (p->multiThread && !p->fastMode && btMode);\r
+\r
+  #ifndef _7ZIP_ST\r
+  p->mtMode = (p->multiThread && !p->fastMode && (p->matchFinderBase.btMode != 0));\r
   #endif\r
 \r
   {\r
     unsigned lclp = p->lc + p->lp;\r
-    if (p->litProbs == 0 || p->saveState.litProbs == 0 || p->lclp != lclp)\r
+    if (!p->litProbs || !p->saveState.litProbs || p->lclp != lclp)\r
     {\r
       LzmaEnc_FreeLits(p, alloc);\r
-      p->litProbs = (CLzmaProb *)alloc->Alloc(alloc, (0x300 << lclp) * sizeof(CLzmaProb));\r
-      p->saveState.litProbs = (CLzmaProb *)alloc->Alloc(alloc, (0x300 << lclp) * sizeof(CLzmaProb));\r
-      if (p->litProbs == 0 || p->saveState.litProbs == 0)\r
+      p->litProbs = (CLzmaProb *)alloc->Alloc(alloc, ((UInt32)0x300 << lclp) * sizeof(CLzmaProb));\r
+      p->saveState.litProbs = (CLzmaProb *)alloc->Alloc(alloc, ((UInt32)0x300 << lclp) * sizeof(CLzmaProb));\r
+      if (!p->litProbs || !p->saveState.litProbs)\r
       {\r
         LzmaEnc_FreeLits(p, alloc);\r
         return SZ_ERROR_MEM;\r
@@ -1955,12 +1986,12 @@ static SRes LzmaEnc_Alloc(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, I
     }\r
   }\r
 \r
-  p->matchFinderBase.bigHash = (p->dictSize > kBigHashDicLimit);\r
+  p->matchFinderBase.bigHash = (Byte)(p->dictSize > kBigHashDicLimit ? 1 : 0);\r
 \r
   if (beforeSize + p->dictSize < keepWindowSize)\r
     beforeSize = keepWindowSize - p->dictSize;\r
 \r
-  #ifdef COMPRESS_MF_MT\r
+  #ifndef _7ZIP_ST\r
   if (p->mtMode)\r
   {\r
     RINOK(MatchFinderMt_Create(&p->matchFinderMt, p->dictSize, beforeSize, p->numFastBytes, LZMA_MATCH_LEN_MAX, allocBig));\r
@@ -1975,6 +2006,7 @@ static SRes LzmaEnc_Alloc(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, I
     p->matchFinderObj = &p->matchFinderBase;\r
     MatchFinder_CreateVTable(&p->matchFinderBase, &p->matchFinder);\r
   }\r
+  \r
   return SZ_OK;\r
 }\r
 \r
@@ -2003,9 +2035,10 @@ void LzmaEnc_Init(CLzmaEnc *p)
   }\r
 \r
   {\r
-    UInt32 num = 0x300 << (p->lp + p->lc);\r
+    UInt32 num = (UInt32)0x300 << (p->lp + p->lc);\r
+    CLzmaProb *probs = p->litProbs;\r
     for (i = 0; i < num; i++)\r
-      p->litProbs[i] = kProbInitValue;\r
+      probs[i] = kProbInitValue;\r
   }\r
 \r
   {\r
@@ -2068,11 +2101,12 @@ static SRes LzmaEnc_AllocAndInit(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *a
   return SZ_OK;\r
 }\r
 \r
-static SRes LzmaEnc_Prepare(CLzmaEncHandle pp, ISeqInStream *inStream, ISeqOutStream *outStream,\r
+static SRes LzmaEnc_Prepare(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream,\r
     ISzAlloc *alloc, ISzAlloc *allocBig)\r
 {\r
   CLzmaEnc *p = (CLzmaEnc *)pp;\r
-  p->inStream = inStream;\r
+  p->matchFinderBase.stream = inStream;\r
+  p->needInit = 1;\r
   p->rc.outStream = outStream;\r
   return LzmaEnc_AllocAndInit(p, 0, alloc, allocBig);\r
 }\r
@@ -2082,15 +2116,16 @@ SRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp,
     ISzAlloc *alloc, ISzAlloc *allocBig)\r
 {\r
   CLzmaEnc *p = (CLzmaEnc *)pp;\r
-  p->inStream = inStream;\r
+  p->matchFinderBase.stream = inStream;\r
+  p->needInit = 1;\r
   return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);\r
 }\r
 \r
 static void LzmaEnc_SetInputBuf(CLzmaEnc *p, const Byte *src, SizeT srcLen)\r
 {\r
-  p->seqBufInStream.funcTable.Read = MyRead;\r
-  p->seqBufInStream.data = src;\r
-  p->seqBufInStream.rem = srcLen;\r
+  p->matchFinderBase.directInput = 1;\r
+  p->matchFinderBase.bufferBase = (Byte *)src;\r
+  p->matchFinderBase.directInputRem = srcLen;\r
 }\r
 \r
 SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen,\r
@@ -2098,22 +2133,24 @@ SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen,
 {\r
   CLzmaEnc *p = (CLzmaEnc *)pp;\r
   LzmaEnc_SetInputBuf(p, src, srcLen);\r
-  p->inStream = &p->seqBufInStream.funcTable;\r
+  p->needInit = 1;\r
+\r
   return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);\r
 }\r
 \r
 void LzmaEnc_Finish(CLzmaEncHandle pp)\r
 {\r
-  #ifdef COMPRESS_MF_MT\r
+  #ifndef _7ZIP_ST\r
   CLzmaEnc *p = (CLzmaEnc *)pp;\r
   if (p->mtMode)\r
     MatchFinderMt_ReleaseStream(&p->matchFinderMt);\r
   #else\r
-  (void)pp;\r
+  UNUSED_VAR(pp);\r
   #endif\r
 }\r
 \r
-typedef struct _CSeqOutStreamBuf\r
+\r
+typedef struct\r
 {\r
   ISeqOutStream funcTable;\r
   Byte *data;\r
@@ -2142,12 +2179,14 @@ UInt32 LzmaEnc_GetNumAvailableBytes(CLzmaEncHandle pp)
   return p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);\r
 }\r
 \r
+\r
 const Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp)\r
 {\r
   const CLzmaEnc *p = (CLzmaEnc *)pp;\r
   return p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;\r
 }\r
 \r
+\r
 SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, Bool reInit,\r
     Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize)\r
 {\r
@@ -2182,27 +2221,23 @@ SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, Bool reInit,
   return res;\r
 }\r
 \r
-SRes LzmaEnc_Encode(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress,\r
-    ISzAlloc *alloc, ISzAlloc *allocBig)\r
+\r
+static SRes LzmaEnc_Encode2(CLzmaEnc *p, ICompressProgress *progress)\r
 {\r
-  CLzmaEnc *p = (CLzmaEnc *)pp;\r
   SRes res = SZ_OK;\r
 \r
-  #ifdef COMPRESS_MF_MT\r
+  #ifndef _7ZIP_ST\r
   Byte allocaDummy[0x300];\r
-  int i = 0;\r
-  for (i = 0; i < 16; i++)\r
-    allocaDummy[i] = (Byte)i;\r
+  allocaDummy[0] = 0;\r
+  allocaDummy[1] = allocaDummy[0];\r
   #endif\r
 \r
-  RINOK(LzmaEnc_Prepare(pp, inStream, outStream, alloc, allocBig));\r
-\r
   for (;;)\r
   {\r
     res = LzmaEnc_CodeOneBlock(p, False, 0, 0);\r
-    if (res != SZ_OK || p->finished != 0)\r
+    if (res != SZ_OK || p->finished)\r
       break;\r
-    if (progress != 0)\r
+    if (progress)\r
     {\r
       res = progress->Progress(progress, p->nowPos64, RangeEnc_GetProcessed(&p->rc));\r
       if (res != SZ_OK)\r
@@ -2212,32 +2247,47 @@ SRes LzmaEnc_Encode(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *i
       }\r
     }\r
   }\r
-  LzmaEnc_Finish(pp);\r
+  \r
+  LzmaEnc_Finish(p);\r
+\r
+  /*\r
+  if (res == S_OK && !Inline_MatchFinder_IsFinishedOK(&p->matchFinderBase))\r
+    res = SZ_ERROR_FAIL;\r
+  }\r
+  */\r
+\r
   return res;\r
 }\r
 \r
+\r
+SRes LzmaEnc_Encode(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress,\r
+    ISzAlloc *alloc, ISzAlloc *allocBig)\r
+{\r
+  RINOK(LzmaEnc_Prepare(pp, outStream, inStream, alloc, allocBig));\r
+  return LzmaEnc_Encode2((CLzmaEnc *)pp, progress);\r
+}\r
+\r
+\r
 SRes LzmaEnc_WriteProperties(CLzmaEncHandle pp, Byte *props, SizeT *size)\r
 {\r
   CLzmaEnc *p = (CLzmaEnc *)pp;\r
-  int i;\r
+  unsigned i;\r
   UInt32 dictSize = p->dictSize;\r
   if (*size < LZMA_PROPS_SIZE)\r
     return SZ_ERROR_PARAM;\r
   *size = LZMA_PROPS_SIZE;\r
   props[0] = (Byte)((p->pb * 5 + p->lp) * 9 + p->lc);\r
 \r
-  for (i = 11; i <= 30; i++)\r
+  if (dictSize >= ((UInt32)1 << 22))\r
   {\r
-    if (dictSize <= ((UInt32)2 << i))\r
-    {\r
-      dictSize = (2 << i);\r
-      break;\r
-    }\r
-    if (dictSize <= ((UInt32)3 << i))\r
-    {\r
-      dictSize = (3 << i);\r
-      break;\r
-    }\r
+    UInt32 kDictMask = ((UInt32)1 << 20) - 1;\r
+    if (dictSize < (UInt32)0xFFFFFFFF - kDictMask)\r
+      dictSize = (dictSize + kDictMask) & ~kDictMask;\r
+  }\r
+  else for (i = 11; i <= 30; i++)\r
+  {\r
+    if (dictSize <= ((UInt32)2 << i)) { dictSize = (2 << i); break; }\r
+    if (dictSize <= ((UInt32)3 << i)) { dictSize = (3 << i); break; }\r
   }\r
 \r
   for (i = 0; i < 4; i++)\r
@@ -2245,6 +2295,7 @@ SRes LzmaEnc_WriteProperties(CLzmaEncHandle pp, Byte *props, SizeT *size)
   return SZ_OK;\r
 }\r
 \r
+\r
 SRes LzmaEnc_MemEncode(CLzmaEncHandle pp, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\r
     int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig)\r
 {\r
@@ -2253,16 +2304,22 @@ SRes LzmaEnc_MemEncode(CLzmaEncHandle pp, Byte *dest, SizeT *destLen, const Byte
 \r
   CSeqOutStreamBuf outStream;\r
 \r
-  LzmaEnc_SetInputBuf(p, src, srcLen);\r
-\r
   outStream.funcTable.Write = MyWrite;\r
   outStream.data = dest;\r
   outStream.rem = *destLen;\r
   outStream.overflow = False;\r
 \r
   p->writeEndMark = writeEndMark;\r
-  res = LzmaEnc_Encode(pp, &outStream.funcTable, &p->seqBufInStream.funcTable,\r
-      progress, alloc, allocBig);\r
+  p->rc.outStream = &outStream.funcTable;\r
+\r
+  res = LzmaEnc_MemPrepare(pp, src, srcLen, 0, alloc, allocBig);\r
+  \r
+  if (res == SZ_OK)\r
+  {\r
+    res = LzmaEnc_Encode2(p, progress);\r
+    if (res == SZ_OK && p->nowPos64 != srcLen)\r
+      res = SZ_ERROR_FAIL;\r
+  }\r
 \r
   *destLen -= outStream.rem;\r
   if (outStream.overflow)\r
@@ -2270,13 +2327,14 @@ SRes LzmaEnc_MemEncode(CLzmaEncHandle pp, Byte *dest, SizeT *destLen, const Byte
   return res;\r
 }\r
 \r
+\r
 SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\r
     const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,\r
     ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig)\r
 {\r
   CLzmaEnc *p = (CLzmaEnc *)LzmaEnc_Create(alloc);\r
   SRes res;\r
-  if (p == 0)\r
+  if (!p)\r
     return SZ_ERROR_MEM;\r
 \r
   res = LzmaEnc_SetProps(p, props);\r
index e3d84fa35e55681b04ef31d47d25529e0792bb75..c2806b45f46dc5c39a98cdc13ad4f34291304234 100644 (file)
@@ -1,10 +1,12 @@
 /*  LzmaEnc.h -- LZMA Encoder\r
-2008-10-04 : Igor Pavlov : Public domain */\r
+2013-01-18 : Igor Pavlov : Public domain */\r
 \r
-#ifndef __LZMAENC_H\r
-#define __LZMAENC_H\r
+#ifndef __LZMA_ENC_H\r
+#define __LZMA_ENC_H\r
 \r
-#include "Types.h"\r
+#include "7zTypes.h"\r
+\r
+EXTERN_C_BEGIN\r
 \r
 #define LZMA_PROPS_SIZE 5\r
 \r
@@ -14,6 +16,8 @@ typedef struct _CLzmaEncProps
   UInt32 dictSize; /* (1 << 12) <= dictSize <= (1 << 27) for 32-bit version\r
                       (1 << 12) <= dictSize <= (1 << 30) for 64-bit version\r
                        default = (1 << 24) */\r
+  UInt64 reduceSize; /* estimated size of data that will be compressed. default = 0xFFFFFFFF.\r
+                        Encoder uses this value to reduce dictionary size */\r
   int lc;          /* 0 <= lc <= 8, default = 3 */\r
   int lp;          /* 0 <= lp <= 4, default = 0 */\r
   int pb;          /* 0 <= pb <= 4, default = 2 */\r
@@ -69,4 +73,6 @@ SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
     const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,\r
     ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);\r
 \r
+EXTERN_C_END\r
+\r
 #endif\r
diff --git a/BaseTools/Source/C/LzmaCompress/Sdk/C/Precomp.h b/BaseTools/Source/C/LzmaCompress/Sdk/C/Precomp.h
new file mode 100644 (file)
index 0000000..edb5814
--- /dev/null
@@ -0,0 +1,10 @@
+/* Precomp.h -- StdAfx\r
+2013-11-12 : Igor Pavlov : Public domain */\r
+\r
+#ifndef __7Z_PRECOMP_H\r
+#define __7Z_PRECOMP_H\r
+\r
+#include "Compiler.h"\r
+/* #include "7zTypes.h" */\r
+\r
+#endif\r
index c7d8b0a8abbb158b51836f33f7e9085c05bd916b..ece07e618a5e480512cc1726b174453d89458fad 100644 (file)
@@ -1,10 +1,13 @@
 /* Threads.c -- multithreading library\r
-2008-08-05\r
-Igor Pavlov\r
-Public domain */\r
+2014-09-21 : Igor Pavlov : Public domain */\r
 \r
-#include "Threads.h"\r
+#include "Precomp.h"\r
+\r
+#ifndef UNDER_CE\r
 #include <process.h>\r
+#endif\r
+\r
+#include "Threads.h"\r
 \r
 static WRes GetError()\r
 {\r
@@ -15,95 +18,76 @@ static WRes GetError()
 WRes HandleToWRes(HANDLE h) { return (h != 0) ? 0 : GetError(); }\r
 WRes BOOLToWRes(BOOL v) { return v ? 0 : GetError(); }\r
 \r
-static WRes MyCloseHandle(HANDLE *h)\r
+WRes HandlePtr_Close(HANDLE *p)\r
 {\r
-  if (*h != NULL)\r
-    if (!CloseHandle(*h))\r
+  if (*p != NULL)\r
+    if (!CloseHandle(*p))\r
       return GetError();\r
-  *h = NULL;\r
+  *p = NULL;\r
   return 0;\r
 }\r
 \r
-WRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter)\r
-{\r
-  unsigned threadId; /* Windows Me/98/95: threadId parameter may not be NULL in _beginthreadex/CreateThread functions */\r
-  thread->handle =\r
-    /* CreateThread(0, 0, startAddress, parameter, 0, &threadId); */\r
-    (HANDLE)_beginthreadex(NULL, 0, startAddress, parameter, 0, &threadId);\r
-    /* maybe we must use errno here, but probably GetLastError() is also OK. */\r
-  return HandleToWRes(thread->handle);\r
-}\r
+WRes Handle_WaitObject(HANDLE h) { return (WRes)WaitForSingleObject(h, INFINITE); }\r
 \r
-WRes WaitObject(HANDLE h)\r
+WRes Thread_Create(CThread *p, THREAD_FUNC_TYPE func, LPVOID param)\r
 {\r
-  return (WRes)WaitForSingleObject(h, INFINITE);\r
+  /* Windows Me/98/95: threadId parameter may not be NULL in _beginthreadex/CreateThread functions */\r
+  \r
+  #ifdef UNDER_CE\r
+  \r
+  DWORD threadId;\r
+  *p = CreateThread(0, 0, func, param, 0, &threadId);\r
+\r
+  #else\r
+\r
+  unsigned threadId;\r
+  *p = (HANDLE)_beginthreadex(NULL, 0, func, param, 0, &threadId);\r
+   \r
+  #endif\r
+\r
+  /* maybe we must use errno here, but probably GetLastError() is also OK. */\r
+  return HandleToWRes(*p);\r
 }\r
 \r
-WRes Thread_Wait(CThread *thread)\r
+WRes Event_Create(CEvent *p, BOOL manualReset, int signaled)\r
 {\r
-  if (thread->handle == NULL)\r
-    return 1;\r
-  return WaitObject(thread->handle);\r
+  *p = CreateEvent(NULL, manualReset, (signaled ? TRUE : FALSE), NULL);\r
+  return HandleToWRes(*p);\r
 }\r
 \r
-WRes Thread_Close(CThread *thread)\r
-{\r
-  return MyCloseHandle(&thread->handle);\r
-}\r
-\r
-WRes Event_Create(CEvent *p, BOOL manualReset, int initialSignaled)\r
-{\r
-  p->handle = CreateEvent(NULL, manualReset, (initialSignaled ? TRUE : FALSE), NULL);\r
-  return HandleToWRes(p->handle);\r
-}\r
+WRes Event_Set(CEvent *p) { return BOOLToWRes(SetEvent(*p)); }\r
+WRes Event_Reset(CEvent *p) { return BOOLToWRes(ResetEvent(*p)); }\r
 \r
-WRes ManualResetEvent_Create(CManualResetEvent *p, int initialSignaled)\r
-  { return Event_Create(p, TRUE, initialSignaled); }\r
-WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p)\r
-  { return ManualResetEvent_Create(p, 0); }\r
+WRes ManualResetEvent_Create(CManualResetEvent *p, int signaled) { return Event_Create(p, TRUE, signaled); }\r
+WRes AutoResetEvent_Create(CAutoResetEvent *p, int signaled) { return Event_Create(p, FALSE, signaled); }\r
+WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p) { return ManualResetEvent_Create(p, 0); }\r
+WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p) { return AutoResetEvent_Create(p, 0); }\r
 \r
-WRes AutoResetEvent_Create(CAutoResetEvent *p, int initialSignaled)\r
-  { return Event_Create(p, FALSE, initialSignaled); }\r
-WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p)\r
-  { return AutoResetEvent_Create(p, 0); }\r
 \r
-WRes Event_Set(CEvent *p) { return BOOLToWRes(SetEvent(p->handle)); }\r
-WRes Event_Reset(CEvent *p) { return BOOLToWRes(ResetEvent(p->handle)); }\r
-WRes Event_Wait(CEvent *p) { return WaitObject(p->handle); }\r
-WRes Event_Close(CEvent *p) { return MyCloseHandle(&p->handle); }\r
-\r
-\r
-WRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount)\r
-{\r
-  p->handle = CreateSemaphore(NULL, (LONG)initiallyCount, (LONG)maxCount, NULL);\r
-  return HandleToWRes(p->handle);\r
-}\r
-\r
-WRes Semaphore_Release(CSemaphore *p, LONG releaseCount, LONG *previousCount)\r
+WRes Semaphore_Create(CSemaphore *p, UInt32 initCount, UInt32 maxCount)\r
 {\r
-  return BOOLToWRes(ReleaseSemaphore(p->handle, releaseCount, previousCount));\r
-}\r
-WRes Semaphore_ReleaseN(CSemaphore *p, UInt32 releaseCount)\r
-{\r
-  return Semaphore_Release(p, (LONG)releaseCount, NULL);\r
-}\r
-WRes Semaphore_Release1(CSemaphore *p)\r
-{\r
-  return Semaphore_ReleaseN(p, 1);\r
+  *p = CreateSemaphore(NULL, (LONG)initCount, (LONG)maxCount, NULL);\r
+  return HandleToWRes(*p);\r
 }\r
 \r
-WRes Semaphore_Wait(CSemaphore *p) { return WaitObject(p->handle); }\r
-WRes Semaphore_Close(CSemaphore *p) { return MyCloseHandle(&p->handle); }\r
+static WRes Semaphore_Release(CSemaphore *p, LONG releaseCount, LONG *previousCount)\r
+  { return BOOLToWRes(ReleaseSemaphore(*p, releaseCount, previousCount)); }\r
+WRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num)\r
+  { return Semaphore_Release(p, (LONG)num, NULL); }\r
+WRes Semaphore_Release1(CSemaphore *p) { return Semaphore_ReleaseN(p, 1); }\r
 \r
 WRes CriticalSection_Init(CCriticalSection *p)\r
 {\r
   /* InitializeCriticalSection can raise only STATUS_NO_MEMORY exception */\r
+  #ifdef _MSC_VER\r
   __try\r
+  #endif\r
   {\r
     InitializeCriticalSection(p);\r
     /* InitializeCriticalSectionAndSpinCount(p, 0); */\r
   }\r
+  #ifdef _MSC_VER\r
   __except (EXCEPTION_EXECUTE_HANDLER) { return 1; }\r
+  #endif\r
   return 0;\r
 }\r
-\r
index 3d9072946e7c07780081ffb68f96a6359bb92ebd..e927208d79affb4a053d4bb01552707ec70ade12 100644 (file)
@@ -1,68 +1,67 @@
 /* Threads.h -- multithreading library\r
-2008-11-22 : Igor Pavlov : Public domain */\r
+2013-11-12 : Igor Pavlov : Public domain */\r
 \r
-#ifndef __7Z_THRESDS_H\r
-#define __7Z_THRESDS_H\r
+#ifndef __7Z_THREADS_H\r
+#define __7Z_THREADS_H\r
 \r
-#include "Types.h"\r
-\r
-typedef struct _CThread\r
-{\r
-  HANDLE handle;\r
-} CThread;\r
-\r
-#define Thread_Construct(thread) (thread)->handle = NULL\r
-#define Thread_WasCreated(thread) ((thread)->handle != NULL)\r
\r
-typedef unsigned THREAD_FUNC_RET_TYPE;\r
-#define THREAD_FUNC_CALL_TYPE MY_STD_CALL\r
-#define THREAD_FUNC_DECL THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE\r
-\r
-WRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter);\r
-WRes Thread_Wait(CThread *thread);\r
-WRes Thread_Close(CThread *thread);\r
-\r
-typedef struct _CEvent\r
-{\r
-  HANDLE handle;\r
-} CEvent;\r
+#ifdef _WIN32\r
+#include <windows.h>\r
+#endif\r
 \r
-typedef CEvent CAutoResetEvent;\r
-typedef CEvent CManualResetEvent;\r
+#include "7zTypes.h"\r
 \r
-#define Event_Construct(event) (event)->handle = NULL\r
-#define Event_IsCreated(event) ((event)->handle != NULL)\r
+EXTERN_C_BEGIN\r
 \r
-WRes ManualResetEvent_Create(CManualResetEvent *event, int initialSignaled);\r
-WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *event);\r
-WRes AutoResetEvent_Create(CAutoResetEvent *event, int initialSignaled);\r
-WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *event);\r
-WRes Event_Set(CEvent *event);\r
-WRes Event_Reset(CEvent *event);\r
-WRes Event_Wait(CEvent *event);\r
-WRes Event_Close(CEvent *event);\r
+WRes HandlePtr_Close(HANDLE *h);\r
+WRes Handle_WaitObject(HANDLE h);\r
 \r
+typedef HANDLE CThread;\r
+#define Thread_Construct(p) *(p) = NULL\r
+#define Thread_WasCreated(p) (*(p) != NULL)\r
+#define Thread_Close(p) HandlePtr_Close(p)\r
+#define Thread_Wait(p) Handle_WaitObject(*(p))\r
 \r
-typedef struct _CSemaphore\r
-{\r
-  HANDLE handle;\r
-} CSemaphore;\r
+typedef\r
+#ifdef UNDER_CE\r
+  DWORD\r
+#else\r
+  unsigned\r
+#endif\r
+  THREAD_FUNC_RET_TYPE;\r
 \r
-#define Semaphore_Construct(p) (p)->handle = NULL\r
+#define THREAD_FUNC_CALL_TYPE MY_STD_CALL\r
+#define THREAD_FUNC_DECL THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE\r
+typedef THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE * THREAD_FUNC_TYPE)(void *);\r
+WRes Thread_Create(CThread *p, THREAD_FUNC_TYPE func, LPVOID param);\r
 \r
-WRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount);\r
+typedef HANDLE CEvent;\r
+typedef CEvent CAutoResetEvent;\r
+typedef CEvent CManualResetEvent;\r
+#define Event_Construct(p) *(p) = NULL\r
+#define Event_IsCreated(p) (*(p) != NULL)\r
+#define Event_Close(p) HandlePtr_Close(p)\r
+#define Event_Wait(p) Handle_WaitObject(*(p))\r
+WRes Event_Set(CEvent *p);\r
+WRes Event_Reset(CEvent *p);\r
+WRes ManualResetEvent_Create(CManualResetEvent *p, int signaled);\r
+WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p);\r
+WRes AutoResetEvent_Create(CAutoResetEvent *p, int signaled);\r
+WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p);\r
+\r
+typedef HANDLE CSemaphore;\r
+#define Semaphore_Construct(p) (*p) = NULL\r
+#define Semaphore_Close(p) HandlePtr_Close(p)\r
+#define Semaphore_Wait(p) Handle_WaitObject(*(p))\r
+WRes Semaphore_Create(CSemaphore *p, UInt32 initCount, UInt32 maxCount);\r
 WRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num);\r
 WRes Semaphore_Release1(CSemaphore *p);\r
-WRes Semaphore_Wait(CSemaphore *p);\r
-WRes Semaphore_Close(CSemaphore *p);\r
-\r
 \r
 typedef CRITICAL_SECTION CCriticalSection;\r
-\r
 WRes CriticalSection_Init(CCriticalSection *p);\r
 #define CriticalSection_Delete(p) DeleteCriticalSection(p)\r
 #define CriticalSection_Enter(p) EnterCriticalSection(p)\r
 #define CriticalSection_Leave(p) LeaveCriticalSection(p)\r
 \r
-#endif\r
+EXTERN_C_END\r
 \r
+#endif\r
diff --git a/BaseTools/Source/C/LzmaCompress/Sdk/C/Types.h b/BaseTools/Source/C/LzmaCompress/Sdk/C/Types.h
deleted file mode 100644 (file)
index 2638196..0000000
+++ /dev/null
@@ -1,208 +0,0 @@
-/* Types.h -- Basic types\r
-2008-11-23 : Igor Pavlov : Public domain */\r
-\r
-#ifndef __7Z_TYPES_H\r
-#define __7Z_TYPES_H\r
-\r
-#include <stddef.h>\r
-\r
-#ifdef _WIN32\r
-#include <windows.h>\r
-#endif\r
-\r
-#define SZ_OK 0\r
-\r
-#define SZ_ERROR_DATA 1\r
-#define SZ_ERROR_MEM 2\r
-#define SZ_ERROR_CRC 3\r
-#define SZ_ERROR_UNSUPPORTED 4\r
-#define SZ_ERROR_PARAM 5\r
-#define SZ_ERROR_INPUT_EOF 6\r
-#define SZ_ERROR_OUTPUT_EOF 7\r
-#define SZ_ERROR_READ 8\r
-#define SZ_ERROR_WRITE 9\r
-#define SZ_ERROR_PROGRESS 10\r
-#define SZ_ERROR_FAIL 11\r
-#define SZ_ERROR_THREAD 12\r
-\r
-#define SZ_ERROR_ARCHIVE 16\r
-#define SZ_ERROR_NO_ARCHIVE 17\r
-\r
-typedef int SRes;\r
-\r
-#ifdef _WIN32\r
-typedef DWORD WRes;\r
-#else\r
-typedef int WRes;\r
-#endif\r
-\r
-#ifndef RINOK\r
-#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }\r
-#endif\r
-\r
-typedef unsigned char Byte;\r
-typedef short Int16;\r
-typedef unsigned short UInt16;\r
-\r
-#ifdef _LZMA_UINT32_IS_ULONG\r
-typedef long Int32;\r
-typedef unsigned long UInt32;\r
-#else\r
-typedef int Int32;\r
-typedef unsigned int UInt32;\r
-#endif\r
-\r
-#ifdef _SZ_NO_INT_64\r
-\r
-/* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.\r
-   NOTES: Some code will work incorrectly in that case! */\r
-\r
-typedef long Int64;\r
-typedef unsigned long UInt64;\r
-\r
-#else\r
-\r
-#if defined(_MSC_VER) || defined(__BORLANDC__)\r
-typedef __int64 Int64;\r
-typedef unsigned __int64 UInt64;\r
-#else\r
-typedef long long int Int64;\r
-typedef unsigned long long int UInt64;\r
-#endif\r
-\r
-#endif\r
-\r
-#ifdef _LZMA_NO_SYSTEM_SIZE_T\r
-typedef UInt32 SizeT;\r
-#else\r
-typedef size_t SizeT;\r
-#endif\r
-\r
-typedef int Bool;\r
-#define True 1\r
-#define False 0\r
-\r
-\r
-#ifdef _MSC_VER\r
-\r
-#if _MSC_VER >= 1300\r
-#define MY_NO_INLINE __declspec(noinline)\r
-#else\r
-#define MY_NO_INLINE\r
-#endif\r
-\r
-#define MY_CDECL __cdecl\r
-#define MY_STD_CALL __stdcall\r
-#define MY_FAST_CALL MY_NO_INLINE __fastcall\r
-\r
-#else\r
-\r
-#define MY_CDECL\r
-#define MY_STD_CALL\r
-#define MY_FAST_CALL\r
-\r
-#endif\r
-\r
-\r
-/* The following interfaces use first parameter as pointer to structure */\r
-\r
-typedef struct\r
-{\r
-  SRes (*Read)(void *p, void *buf, size_t *size);\r
-    /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.\r
-       (output(*size) < input(*size)) is allowed */\r
-} ISeqInStream;\r
-\r
-/* it can return SZ_ERROR_INPUT_EOF */\r
-SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size);\r
-SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType);\r
-SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf);\r
-\r
-typedef struct\r
-{\r
-  size_t (*Write)(void *p, const void *buf, size_t size);\r
-    /* Returns: result - the number of actually written bytes.\r
-       (result < size) means error */\r
-} ISeqOutStream;\r
-\r
-typedef enum\r
-{\r
-  SZ_SEEK_SET = 0,\r
-  SZ_SEEK_CUR = 1,\r
-  SZ_SEEK_END = 2\r
-} ESzSeek;\r
-\r
-typedef struct\r
-{\r
-  SRes (*Read)(void *p, void *buf, size_t *size);  /* same as ISeqInStream::Read */\r
-  SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);\r
-} ISeekInStream;\r
-\r
-typedef struct\r
-{\r
-  SRes (*Look)(void *p, void **buf, size_t *size);\r
-    /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.\r
-       (output(*size) > input(*size)) is not allowed\r
-       (output(*size) < input(*size)) is allowed */\r
-  SRes (*Skip)(void *p, size_t offset);\r
-    /* offset must be <= output(*size) of Look */\r
-\r
-  SRes (*Read)(void *p, void *buf, size_t *size);\r
-    /* reads directly (without buffer). It's same as ISeqInStream::Read */\r
-  SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);\r
-} ILookInStream;\r
-\r
-SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size);\r
-SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset);\r
-\r
-/* reads via ILookInStream::Read */\r
-SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType);\r
-SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size);\r
-\r
-#define LookToRead_BUF_SIZE (1 << 14)\r
-\r
-typedef struct\r
-{\r
-  ILookInStream s;\r
-  ISeekInStream *realStream;\r
-  size_t pos;\r
-  size_t size;\r
-  Byte buf[LookToRead_BUF_SIZE];\r
-} CLookToRead;\r
-\r
-void LookToRead_CreateVTable(CLookToRead *p, int lookahead);\r
-void LookToRead_Init(CLookToRead *p);\r
-\r
-typedef struct\r
-{\r
-  ISeqInStream s;\r
-  ILookInStream *realStream;\r
-} CSecToLook;\r
-\r
-void SecToLook_CreateVTable(CSecToLook *p);\r
-\r
-typedef struct\r
-{\r
-  ISeqInStream s;\r
-  ILookInStream *realStream;\r
-} CSecToRead;\r
-\r
-void SecToRead_CreateVTable(CSecToRead *p);\r
-\r
-typedef struct\r
-{\r
-  SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);\r
-    /* Returns: result. (result != SZ_OK) means break.\r
-       Value (UInt64)(Int64)-1 for size means unknown value. */\r
-} ICompressProgress;\r
-\r
-typedef struct\r
-{\r
-  void *(*Alloc)(void *p, size_t size);\r
-  void (*Free)(void *p, void *address); /* address can be 0 */\r
-} ISzAlloc;\r
-\r
-#define IAlloc_Alloc(p, size) (p)->Alloc((p), size)\r
-#define IAlloc_Free(p, a) (p)->Free((p), a)\r
-\r
-#endif\r
diff --git a/BaseTools/Source/C/LzmaCompress/Sdk/DOC/lzma-history.txt b/BaseTools/Source/C/LzmaCompress/Sdk/DOC/lzma-history.txt
new file mode 100644 (file)
index 0000000..7aaeb07
--- /dev/null
@@ -0,0 +1,363 @@
+HISTORY of the LZMA SDK\r
+-----------------------\r
+\r
+16.04          2016-10-04\r
+-------------------------\r
+- The bug was fixed in DllSecur.c.\r
+\r
+\r
+16.03          2016-09-28\r
+-------------------------\r
+- SFX modules now use some protection against DLL preloading attack.\r
+- Some bugs in 7z code were fixed.\r
+\r
+\r
+16.02          2016-05-21\r
+-------------------------\r
+- The BUG in 16.00 - 16.01 was fixed:\r
+  Split Handler (SplitHandler.cpp) returned incorrect \r
+  total size value (kpidSize) for split archives.\r
+\r
+\r
+16.01          2016-05-19\r
+-------------------------      \r
+- Some internal changes to reduce the number of compiler warnings.\r
+\r
+\r
+16.00          2016-05-10\r
+-------------------------      \r
+- Some bugs were fixed.\r
+\r
+\r
+15.12          2015-11-19\r
+-------------------------      \r
+- The BUG in C version of 7z decoder was fixed:\r
+  7zDec.c : SzDecodeLzma2()\r
+  7z decoder could mistakenly report about decoding error for some 7z archives\r
+  that use LZMA2 compression method.\r
+  The probability to get that mistaken decoding error report was about \r
+  one error per 16384 solid blocks for solid blocks larger than 16 KB (compressed size). \r
+- The BUG (in 9.26-15.11) in C version of 7z decoder was fixed:\r
+  7zArcIn.c : SzReadHeader2()\r
+  7z decoder worked incorrectly for 7z archives that contain \r
+  empty solid blocks, that can be placed to 7z archive, if some file is \r
+  unavailable for reading during archive creation.\r
+\r
+\r
+15.09 beta     2015-10-16\r
+-------------------------      \r
+- The BUG in LZMA / LZMA2 encoding code was fixed.\r
+  The BUG in LzFind.c::MatchFinder_ReadBlock() function.\r
+  If input data size is larger than (4 GiB - dictionary_size),\r
+  the following code worked incorrectly:\r
+  -  LZMA : LzmaEnc_MemEncode(), LzmaEncode() : LZMA encoding functions \r
+     for compressing from memory to memory. \r
+     That BUG is not related to LZMA encoder version that works via streams.\r
+  -  LZMA2 : multi-threaded version of LZMA2 encoder worked incorrectly, if \r
+     default value of chunk size (CLzma2EncProps::blockSize) is changed \r
+     to value larger than (4 GiB - dictionary_size).\r
+\r
+\r
+9.38 beta      2015-01-03\r
+-------------------------      \r
+- The BUG in 9.31-9.37 was fixed:\r
+  IArchiveGetRawProps interface was disabled for 7z archives.\r
+- The BUG in 9.26-9.36 was fixed:\r
+  Some code in CPP\7zip\Archive\7z\ worked correctly only under Windows.\r
+\r
+\r
+9.36 beta      2014-12-26\r
+-------------------------      \r
+- The BUG in command line version was fixed:\r
+  7-Zip created temporary archive in current folder during update archive\r
+  operation, if -w{Path} switch was not specified. \r
+  The fixed 7-Zip creates temporary archive in folder that contains updated archive.\r
+- The BUG in 9.33-9.35 was fixed:\r
+  7-Zip silently ignored file reading errors during 7z or gz archive creation,\r
+  and the created archive contained only part of file that was read before error.\r
+  The fixed 7-Zip stops archive creation and it reports about error.\r
+\r
+\r
+9.35 beta      2014-12-07\r
+-------------------------      \r
+- 7zr.exe now support AES encryption.\r
+- SFX mudules were added to LZMA SDK\r
+- Some bugs were fixed.\r
+\r
+\r
+9.21 beta      2011-04-11\r
+-------------------------      \r
+- New class FString for file names at file systems.\r
+- Speed optimization in CRC code for big-endian CPUs.\r
+- The BUG in Lzma2Dec.c was fixed:\r
+    Lzma2Decode function didn't work.\r
+\r
+\r
+9.18 beta      2010-11-02\r
+-------------------------      \r
+- New small SFX module for installers (SfxSetup).\r
+\r
+\r
+9.12 beta      2010-03-24\r
+-------------------------\r
+- The BUG in LZMA SDK 9.* was fixed: LZMA2 codec didn't work,\r
+  if more than 10 threads were used (or more than 20 threads in some modes).\r
+\r
+\r
+9.11 beta      2010-03-15\r
+-------------------------\r
+- PPMd compression method support\r
+   \r
+\r
+9.09           2009-12-12\r
+-------------------------\r
+- The bug was fixed:\r
+   Utf16_To_Utf8 funstions in UTFConvert.cpp and 7zMain.c\r
+   incorrectly converted surrogate characters (the code >= 0x10000) to UTF-8.\r
+- Some bugs were fixed\r
+\r
+\r
+9.06           2009-08-17\r
+-------------------------\r
+- Some changes in ANSI-C 7z Decoder interfaces.\r
+\r
+\r
+9.04           2009-05-30\r
+-------------------------\r
+- LZMA2 compression method support\r
+- xz format support\r
+\r
+\r
+4.65           2009-02-03\r
+-------------------------\r
+- Some minor fixes\r
+\r
+\r
+4.63           2008-12-31\r
+-------------------------\r
+- Some minor fixes\r
+\r
+\r
+4.61 beta      2008-11-23\r
+-------------------------\r
+- The bug in ANSI-C LZMA Decoder was fixed:\r
+    If encoded stream was corrupted, decoder could access memory \r
+    outside of allocated range.\r
+- Some changes in ANSI-C 7z Decoder interfaces.\r
+- LZMA SDK is placed in the public domain.\r
+\r
+\r
+4.60 beta      2008-08-19\r
+-------------------------\r
+- Some minor fixes.\r
+\r
+\r
+4.59 beta      2008-08-13\r
+-------------------------\r
+- The bug was fixed:\r
+    LZMA Encoder in fast compression mode could access memory outside of \r
+    allocated range in some rare cases.\r
+\r
+\r
+4.58 beta      2008-05-05\r
+-------------------------\r
+- ANSI-C LZMA Decoder was rewritten for speed optimizations.\r
+- ANSI-C LZMA Encoder was included to LZMA SDK.\r
+- C++ LZMA code now is just wrapper over ANSI-C code.\r
+\r
+\r
+4.57           2007-12-12\r
+-------------------------\r
+- Speed optimizations in C++ LZMA Decoder. \r
+- Small changes for more compatibility with some C/C++ compilers.\r
+\r
+\r
+4.49 beta      2007-07-05\r
+-------------------------\r
+- .7z ANSI-C Decoder:\r
+     - now it supports BCJ and BCJ2 filters\r
+     - now it supports files larger than 4 GB.\r
+     - now it supports "Last Write Time" field for files.\r
+- C++ code for .7z archives compressing/decompressing from 7-zip \r
+  was included to LZMA SDK.\r
+  \r
+\r
+4.43           2006-06-04\r
+-------------------------\r
+- Small changes for more compatibility with some C/C++ compilers.\r
+  \r
+\r
+4.42           2006-05-15\r
+-------------------------\r
+- Small changes in .h files in ANSI-C version.\r
+  \r
+\r
+4.39 beta      2006-04-14\r
+-------------------------\r
+- The bug in versions 4.33b:4.38b was fixed:\r
+  C++ version of LZMA encoder could not correctly compress \r
+  files larger than 2 GB with HC4 match finder (-mfhc4).\r
+  \r
+\r
+4.37 beta      2005-04-06\r
+-------------------------\r
+- Fixes in C++ code: code could no be compiled if _NO_EXCEPTIONS was defined. \r
+\r
+\r
+4.35 beta      2005-03-02\r
+-------------------------\r
+- The bug was fixed in C++ version of LZMA Decoder:\r
+    If encoded stream was corrupted, decoder could access memory \r
+    outside of allocated range.\r
+\r
+\r
+4.34 beta      2006-02-27\r
+-------------------------\r
+- Compressing speed and memory requirements for compressing were increased\r
+- LZMA now can use only these match finders: HC4, BT2, BT3, BT4\r
+\r
+\r
+4.32           2005-12-09\r
+-------------------------\r
+- Java version of LZMA SDK was included\r
+\r
+\r
+4.30           2005-11-20\r
+-------------------------\r
+- Compression ratio was improved in -a2 mode\r
+- Speed optimizations for compressing in -a2 mode\r
+- -fb switch now supports values up to 273\r
+- The bug in 7z_C (7zIn.c) was fixed:\r
+  It used Alloc/Free functions from different memory pools.\r
+  So if program used two memory pools, it worked incorrectly.\r
+- 7z_C: .7z format supporting was improved\r
+- LZMA# SDK (C#.NET version) was included\r
+\r
+\r
+4.27 (Updated) 2005-09-21\r
+-------------------------\r
+- Some GUIDs/interfaces in C++ were changed.\r
+ IStream.h:\r
+   ISequentialInStream::Read now works as old ReadPart\r
+   ISequentialOutStream::Write now works as old WritePart\r
+\r
+\r
+4.27           2005-08-07\r
+-------------------------\r
+- The bug in LzmaDecodeSize.c was fixed:\r
+   if _LZMA_IN_CB and _LZMA_OUT_READ were defined,\r
+   decompressing worked incorrectly.\r
+\r
+\r
+4.26           2005-08-05\r
+-------------------------\r
+- Fixes in 7z_C code and LzmaTest.c:\r
+  previous versions could work incorrectly,\r
+  if malloc(0) returns 0\r
+\r
+\r
+4.23           2005-06-29\r
+-------------------------\r
+- Small fixes in C++ code\r
+\r
+\r
+4.22           2005-06-10\r
+-------------------------\r
+- Small fixes\r
+\r
+\r
+4.21           2005-06-08\r
+-------------------------\r
+- Interfaces for ANSI-C LZMA Decoder (LzmaDecode.c) were changed\r
+- New additional version of ANSI-C LZMA Decoder with zlib-like interface:\r
+    - LzmaStateDecode.h\r
+    - LzmaStateDecode.c\r
+    - LzmaStateTest.c\r
+- ANSI-C LZMA Decoder now can decompress files larger than 4 GB\r
+\r
+\r
+4.17           2005-04-18\r
+-------------------------\r
+- New example for RAM->RAM compressing/decompressing: \r
+  LZMA + BCJ (filter for x86 code):\r
+    - LzmaRam.h\r
+    - LzmaRam.cpp\r
+    - LzmaRamDecode.h\r
+    - LzmaRamDecode.c\r
+    - -f86 switch for lzma.exe\r
+\r
+\r
+4.16           2005-03-29\r
+-------------------------\r
+- The bug was fixed in LzmaDecode.c (ANSI-C LZMA Decoder): \r
+   If _LZMA_OUT_READ was defined, and if encoded stream was corrupted,\r
+   decoder could access memory outside of allocated range.\r
+- Speed optimization of ANSI-C LZMA Decoder (now it's about 20% faster).\r
+  Old version of LZMA Decoder now is in file LzmaDecodeSize.c. \r
+  LzmaDecodeSize.c can provide slightly smaller code than LzmaDecode.c\r
+- Small speed optimization in LZMA C++ code\r
+- filter for SPARC's code was added\r
+- Simplified version of .7z ANSI-C Decoder was included\r
+\r
+\r
+4.06           2004-09-05\r
+-------------------------\r
+- The bug in v4.05 was fixed:\r
+    LZMA-Encoder didn't release output stream in some cases.\r
+\r
+\r
+4.05           2004-08-25\r
+-------------------------\r
+- Source code of filters for x86, IA-64, ARM, ARM-Thumb \r
+  and PowerPC code was included to SDK\r
+- Some internal minor changes\r
+\r
+\r
+4.04           2004-07-28\r
+-------------------------\r
+- More compatibility with some C++ compilers\r
+\r
+\r
+4.03           2004-06-18\r
+-------------------------\r
+- "Benchmark" command was added. It measures compressing \r
+  and decompressing speed and shows rating values. \r
+  Also it checks hardware errors.\r
+\r
+\r
+4.02           2004-06-10\r
+-------------------------\r
+- C++ LZMA Encoder/Decoder code now is more portable\r
+  and it can be compiled by GCC on Linux.\r
+\r
+\r
+4.01           2004-02-15\r
+-------------------------\r
+- Some detection of data corruption was enabled.\r
+    LzmaDecode.c / RangeDecoderReadByte\r
+    .....\r
+    {\r
+      rd->ExtraBytes = 1;\r
+      return 0xFF;\r
+    }\r
+\r
+\r
+4.00           2004-02-13\r
+-------------------------\r
+- Original version of LZMA SDK\r
+\r
+\r
+\r
+HISTORY of the LZMA\r
+-------------------\r
+  2001-2008:  Improvements to LZMA compressing/decompressing code, \r
+              keeping compatibility with original LZMA format\r
+  1996-2001:  Development of LZMA compression format\r
+\r
+  Some milestones:\r
+\r
+  2001-08-30: LZMA compression was added to 7-Zip\r
+  1999-01-02: First version of 7-Zip was released\r
+  \r
+\r
+End of document\r
diff --git a/BaseTools/Source/C/LzmaCompress/Sdk/DOC/lzma-sdk.txt b/BaseTools/Source/C/LzmaCompress/Sdk/DOC/lzma-sdk.txt
new file mode 100644 (file)
index 0000000..86fef24
--- /dev/null
@@ -0,0 +1,357 @@
+LZMA SDK 16.04\r
+--------------\r
+\r
+LZMA SDK provides the documentation, samples, header files,\r
+libraries, and tools you need to develop applications that \r
+use 7z / LZMA / LZMA2 / XZ compression.\r
+\r
+LZMA is an improved version of famous LZ77 compression algorithm. \r
+It was improved in way of maximum increasing of compression ratio,\r
+keeping high decompression speed and low memory requirements for \r
+decompressing.\r
+\r
+LZMA2 is a LZMA based compression method. LZMA2 provides better \r
+multithreading support for compression than LZMA and some other improvements.\r
+\r
+7z is a file format for data compression and file archiving.\r
+7z is a main file format for 7-Zip compression program (www.7-zip.org).\r
+7z format supports different compression methods: LZMA, LZMA2 and others.\r
+7z also supports AES-256 based encryption.\r
+\r
+XZ is a file format for data compression that uses LZMA2 compression.\r
+XZ format provides additional features: SHA/CRC check, filters for \r
+improved compression ratio, splitting to blocks and streams,\r
+\r
+\r
+\r
+LICENSE\r
+-------\r
+\r
+LZMA SDK is written and placed in the public domain by Igor Pavlov.\r
+\r
+Some code in LZMA SDK is based on public domain code from another developers:\r
+  1) PPMd var.H (2001): Dmitry Shkarin\r
+  2) SHA-256: Wei Dai (Crypto++ library)\r
+\r
+Anyone is free to copy, modify, publish, use, compile, sell, or distribute the \r
+original LZMA SDK code, either in source code form or as a compiled binary, for \r
+any purpose, commercial or non-commercial, and by any means.\r
+\r
+LZMA SDK code is compatible with open source licenses, for example, you can \r
+include it to GNU GPL or GNU LGPL code.\r
+\r
+\r
+LZMA SDK Contents\r
+-----------------\r
+\r
+  Source code:\r
+\r
+    - C / C++ / C# / Java   - LZMA compression and decompression\r
+    - C / C++               - LZMA2 compression and decompression\r
+    - C / C++               - XZ compression and decompression\r
+    - C                     - 7z decompression\r
+    -     C++               - 7z compression and decompression\r
+    - C                     - small SFXs for installers (7z decompression)\r
+    -     C++               - SFXs and SFXs for installers (7z decompression)\r
+\r
+  Precomiled binaries:\r
+\r
+    - console programs for lzma / 7z / xz compression and decompression\r
+    - SFX modules for installers.\r
+\r
+\r
+UNIX/Linux version \r
+------------------\r
+To compile C++ version of file->file LZMA encoding, go to directory\r
+CPP/7zip/Bundles/LzmaCon\r
+and call make to recompile it:\r
+  make -f makefile.gcc clean all\r
+\r
+In some UNIX/Linux versions you must compile LZMA with static libraries.\r
+To compile with static libraries, you can use \r
+LIB = -lm -static\r
+\r
+Also you can use p7zip (port of 7-Zip for POSIX systems like Unix or Linux):\r
+  \r
+  http://p7zip.sourceforge.net/\r
+\r
+\r
+Files\r
+-----\r
+\r
+DOC/7zC.txt          - 7z ANSI-C Decoder description\r
+DOC/7zFormat.txt     - 7z Format description\r
+DOC/installer.txt    - information about 7-Zip for installers\r
+DOC/lzma.txt         - LZMA compression description\r
+DOC/lzma-sdk.txt     - LZMA SDK description (this file)\r
+DOC/lzma-history.txt - history of LZMA SDK\r
+DOC/lzma-specification.txt - Specification of LZMA\r
+DOC/Methods.txt      - Compression method IDs for .7z\r
+\r
+bin/installer/   - example script to create installer that uses SFX module,\r
+\r
+bin/7zdec.exe    - simplified 7z archive decoder\r
+bin/7zr.exe      - 7-Zip console program (reduced version)\r
+bin/x64/7zr.exe  - 7-Zip console program (reduced version) (x64 version)\r
+bin/lzma.exe     - file->file LZMA encoder/decoder for Windows\r
+bin/7zS2.sfx     - small SFX module for installers (GUI version)\r
+bin/7zS2con.sfx  - small SFX module for installers (Console version)\r
+bin/7zSD.sfx     - SFX module for installers.\r
+\r
+\r
+7zDec.exe\r
+---------\r
+7zDec.exe is simplified 7z archive decoder.\r
+It supports only LZMA, LZMA2, and PPMd methods.\r
+7zDec decodes whole solid block from 7z archive to RAM.\r
+The RAM consumption can be high.\r
+\r
+\r
+\r
+\r
+Source code structure\r
+---------------------\r
+\r
+\r
+Asm/ - asm files (optimized code for CRC calculation and Intel-AES encryption)\r
+\r
+C/  - C files (compression / decompression and other)\r
+  Util/\r
+    7z       - 7z decoder program (decoding 7z files)\r
+    Lzma     - LZMA program (file->file LZMA encoder/decoder).\r
+    LzmaLib  - LZMA library (.DLL for Windows)\r
+    SfxSetup - small SFX module for installers \r
+\r
+CPP/ -- CPP files\r
+\r
+  Common  - common files for C++ projects\r
+  Windows - common files for Windows related code\r
+\r
+  7zip    - files related to 7-Zip\r
+\r
+    Archive - files related to archiving\r
+\r
+      Common   - common files for archive handling\r
+      7z       - 7z C++ Encoder/Decoder\r
+\r
+    Bundles  - Modules that are bundles of other modules (files)\r
+  \r
+      Alone7z       - 7zr.exe: Standalone 7-Zip console program (reduced version)\r
+      Format7zExtractR  - 7zxr.dll: Reduced version of 7z DLL: extracting from 7z/LZMA/BCJ/BCJ2.\r
+      Format7zR         - 7zr.dll:  Reduced version of 7z DLL: extracting/compressing to 7z/LZMA/BCJ/BCJ2\r
+      LzmaCon       - lzma.exe: LZMA compression/decompression\r
+      LzmaSpec      - example code for LZMA Specification\r
+      SFXCon        - 7zCon.sfx: Console 7z SFX module\r
+      SFXSetup      - 7zS.sfx: 7z SFX module for installers\r
+      SFXWin        - 7z.sfx: GUI 7z SFX module\r
+\r
+    Common   - common files for 7-Zip\r
+\r
+    Compress - files for compression/decompression\r
+\r
+    Crypto   - files for encryption / decompression\r
+\r
+    UI       - User Interface files\r
+         \r
+      Client7z - Test application for 7za.dll, 7zr.dll, 7zxr.dll\r
+      Common   - Common UI files\r
+      Console  - Code for console program (7z.exe)\r
+      Explorer    - Some code from 7-Zip Shell extension\r
+      FileManager - Some GUI code from 7-Zip File Manager\r
+      GUI         - Some GUI code from 7-Zip\r
+\r
+\r
+CS/ - C# files\r
+  7zip\r
+    Common   - some common files for 7-Zip\r
+    Compress - files related to compression/decompression\r
+      LZ     - files related to LZ (Lempel-Ziv) compression algorithm\r
+      LZMA         - LZMA compression/decompression\r
+      LzmaAlone    - file->file LZMA compression/decompression\r
+      RangeCoder   - Range Coder (special code of compression/decompression)\r
+\r
+Java/  - Java files\r
+  SevenZip\r
+    Compression    - files related to compression/decompression\r
+      LZ           - files related to LZ (Lempel-Ziv) compression algorithm\r
+      LZMA         - LZMA compression/decompression\r
+      RangeCoder   - Range Coder (special code of compression/decompression)\r
+\r
+\r
+Note: \r
+  Asm / C / C++ source code of LZMA SDK is part of 7-Zip's source code.\r
+  7-Zip's source code can be downloaded from 7-Zip's SourceForge page:\r
+\r
+  http://sourceforge.net/projects/sevenzip/\r
+\r
+\r
+\r
+LZMA features\r
+-------------\r
+  - Variable dictionary size (up to 1 GB)\r
+  - Estimated compressing speed: about 2 MB/s on 2 GHz CPU\r
+  - Estimated decompressing speed: \r
+      - 20-30 MB/s on modern 2 GHz cpu\r
+      - 1-2 MB/s on 200 MHz simple RISC cpu: (ARM, MIPS, PowerPC)\r
+  - Small memory requirements for decompressing (16 KB + DictionarySize)\r
+  - Small code size for decompressing: 5-8 KB\r
+\r
+LZMA decoder uses only integer operations and can be \r
+implemented in any modern 32-bit CPU (or on 16-bit CPU with some conditions).\r
+\r
+Some critical operations that affect the speed of LZMA decompression:\r
+  1) 32*16 bit integer multiply\r
+  2) Mispredicted branches (penalty mostly depends from pipeline length)\r
+  3) 32-bit shift and arithmetic operations\r
+\r
+The speed of LZMA decompressing mostly depends from CPU speed.\r
+Memory speed has no big meaning. But if your CPU has small data cache, \r
+overall weight of memory speed will slightly increase.\r
+\r
+\r
+How To Use\r
+----------\r
+\r
+Using LZMA encoder/decoder executable\r
+--------------------------------------\r
+\r
+Usage:  LZMA <e|d> inputFile outputFile [<switches>...]\r
+\r
+  e: encode file\r
+\r
+  d: decode file\r
+\r
+  b: Benchmark. There are two tests: compressing and decompressing \r
+     with LZMA method. Benchmark shows rating in MIPS (million \r
+     instructions per second). Rating value is calculated from \r
+     measured speed and it is normalized with Intel's Core 2 results.\r
+     Also Benchmark checks possible hardware errors (RAM \r
+     errors in most cases). Benchmark uses these settings:\r
+     (-a1, -d21, -fb32, -mfbt4). You can change only -d parameter. \r
+     Also you can change the number of iterations. Example for 30 iterations:\r
+       LZMA b 30\r
+     Default number of iterations is 10.\r
+\r
+<Switches>\r
+  \r
+\r
+  -a{N}:  set compression mode 0 = fast, 1 = normal\r
+          default: 1 (normal)\r
+\r
+  d{N}:   Sets Dictionary size - [0, 30], default: 23 (8MB)\r
+          The maximum value for dictionary size is 1 GB = 2^30 bytes.\r
+          Dictionary size is calculated as DictionarySize = 2^N bytes. \r
+          For decompressing file compressed by LZMA method with dictionary \r
+          size D = 2^N you need about D bytes of memory (RAM).\r
+\r
+  -fb{N}: set number of fast bytes - [5, 273], default: 128\r
+          Usually big number gives a little bit better compression ratio \r
+          and slower compression process.\r
+\r
+  -lc{N}: set number of literal context bits - [0, 8], default: 3\r
+          Sometimes lc=4 gives gain for big files.\r
+\r
+  -lp{N}: set number of literal pos bits - [0, 4], default: 0\r
+          lp switch is intended for periodical data when period is \r
+          equal 2^N. For example, for 32-bit (4 bytes) \r
+          periodical data you can use lp=2. Often it's better to set lc0, \r
+          if you change lp switch.\r
+\r
+  -pb{N}: set number of pos bits - [0, 4], default: 2\r
+          pb switch is intended for periodical data \r
+          when period is equal 2^N.\r
+\r
+  -mf{MF_ID}: set Match Finder. Default: bt4. \r
+              Algorithms from hc* group doesn't provide good compression \r
+              ratio, but they often works pretty fast in combination with \r
+              fast mode (-a0).\r
+\r
+              Memory requirements depend from dictionary size \r
+              (parameter "d" in table below). \r
+\r
+               MF_ID     Memory                   Description\r
+\r
+                bt2    d *  9.5 + 4MB  Binary Tree with 2 bytes hashing.\r
+                bt3    d * 11.5 + 4MB  Binary Tree with 3 bytes hashing.\r
+                bt4    d * 11.5 + 4MB  Binary Tree with 4 bytes hashing.\r
+                hc4    d *  7.5 + 4MB  Hash Chain with 4 bytes hashing.\r
+\r
+  -eos:   write End Of Stream marker. By default LZMA doesn't write \r
+          eos marker, since LZMA decoder knows uncompressed size \r
+          stored in .lzma file header.\r
+\r
+  -si:    Read data from stdin (it will write End Of Stream marker).\r
+  -so:    Write data to stdout\r
+\r
+\r
+Examples:\r
+\r
+1) LZMA e file.bin file.lzma -d16 -lc0 \r
+\r
+compresses file.bin to file.lzma with 64 KB dictionary (2^16=64K)  \r
+and 0 literal context bits. -lc0 allows to reduce memory requirements \r
+for decompression.\r
+\r
+\r
+2) LZMA e file.bin file.lzma -lc0 -lp2\r
+\r
+compresses file.bin to file.lzma with settings suitable \r
+for 32-bit periodical data (for example, ARM or MIPS code).\r
+\r
+3) LZMA d file.lzma file.bin\r
+\r
+decompresses file.lzma to file.bin.\r
+\r
+\r
+Compression ratio hints\r
+-----------------------\r
+\r
+Recommendations\r
+---------------\r
+\r
+To increase the compression ratio for LZMA compressing it's desirable \r
+to have aligned data (if it's possible) and also it's desirable to locate\r
+data in such order, where code is grouped in one place and data is \r
+grouped in other place (it's better than such mixing: code, data, code,\r
+data, ...).\r
+\r
+\r
+Filters\r
+-------\r
+You can increase the compression ratio for some data types, using\r
+special filters before compressing. For example, it's possible to \r
+increase the compression ratio on 5-10% for code for those CPU ISAs: \r
+x86, IA-64, ARM, ARM-Thumb, PowerPC, SPARC.\r
+\r
+You can find C source code of such filters in C/Bra*.* files\r
+\r
+You can check the compression ratio gain of these filters with such \r
+7-Zip commands (example for ARM code):\r
+No filter:\r
+  7z a a1.7z a.bin -m0=lzma\r
+\r
+With filter for little-endian ARM code:\r
+  7z a a2.7z a.bin -m0=arm -m1=lzma        \r
+\r
+It works in such manner:\r
+Compressing    = Filter_encoding + LZMA_encoding\r
+Decompressing  = LZMA_decoding + Filter_decoding\r
+\r
+Compressing and decompressing speed of such filters is very high,\r
+so it will not increase decompressing time too much.\r
+Moreover, it reduces decompression time for LZMA_decoding, \r
+since compression ratio with filtering is higher.\r
+\r
+These filters convert CALL (calling procedure) instructions \r
+from relative offsets to absolute addresses, so such data becomes more \r
+compressible.\r
+\r
+For some ISAs (for example, for MIPS) it's impossible to get gain from such filter.\r
+\r
+\r
+\r
+---\r
+\r
+http://www.7-zip.org\r
+http://www.7-zip.org/sdk.html\r
+http://www.7-zip.org/support.html\r
diff --git a/BaseTools/Source/C/LzmaCompress/Sdk/history.txt b/BaseTools/Source/C/LzmaCompress/Sdk/history.txt
deleted file mode 100644 (file)
index 9bed5eb..0000000
+++ /dev/null
@@ -1,236 +0,0 @@
-HISTORY of the LZMA SDK\r
------------------------\r
-\r
-4.65           2009-02-03\r
--------------------------\r
-- Some minor fixes\r
-\r
-\r
-4.63           2008-12-31\r
--------------------------\r
-- Some minor fixes\r
-\r
-\r
-4.61 beta      2008-11-23\r
--------------------------\r
-- The bug in ANSI-C LZMA Decoder was fixed:\r
-    If encoded stream was corrupted, decoder could access memory \r
-    outside of allocated range.\r
-- Some changes in ANSI-C 7z Decoder interfaces.\r
-- LZMA SDK is placed in the public domain.\r
-\r
-\r
-4.60 beta      2008-08-19\r
--------------------------\r
-- Some minor fixes.\r
-\r
-\r
-4.59 beta      2008-08-13\r
--------------------------\r
-- The bug was fixed:\r
-    LZMA Encoder in fast compression mode could access memory outside of \r
-    allocated range in some rare cases.\r
-\r
-\r
-4.58 beta      2008-05-05\r
--------------------------\r
-- ANSI-C LZMA Decoder was rewritten for speed optimizations.\r
-- ANSI-C LZMA Encoder was included to LZMA SDK.\r
-- C++ LZMA code now is just wrapper over ANSI-C code.\r
-\r
-\r
-4.57           2007-12-12\r
--------------------------\r
-- Speed optimizations in Ã‘++ LZMA Decoder. \r
-- Small changes for more compatibility with some C/C++ compilers.\r
-\r
-\r
-4.49 beta      2007-07-05\r
--------------------------\r
-- .7z ANSI-C Decoder:\r
-     - now it supports BCJ and BCJ2 filters\r
-     - now it supports files larger than 4 GB.\r
-     - now it supports "Last Write Time" field for files.\r
-- C++ code for .7z archives compressing/decompressing from 7-zip \r
-  was included to LZMA SDK.\r
-  \r
-\r
-4.43           2006-06-04\r
--------------------------\r
-- Small changes for more compatibility with some C/C++ compilers.\r
-  \r
-\r
-4.42           2006-05-15\r
--------------------------\r
-- Small changes in .h files in ANSI-C version.\r
-  \r
-\r
-4.39 beta      2006-04-14\r
--------------------------\r
-- The bug in versions 4.33b:4.38b was fixed:\r
-  C++ version of LZMA encoder could not correctly compress \r
-  files larger than 2 GB with HC4 match finder (-mfhc4).\r
-  \r
-\r
-4.37 beta      2005-04-06\r
--------------------------\r
-- Fixes in C++ code: code could no be compiled if _NO_EXCEPTIONS was defined. \r
-\r
-\r
-4.35 beta      2005-03-02\r
--------------------------\r
-- The bug was fixed in C++ version of LZMA Decoder:\r
-    If encoded stream was corrupted, decoder could access memory \r
-    outside of allocated range.\r
-\r
-\r
-4.34 beta      2006-02-27\r
--------------------------\r
-- Compressing speed and memory requirements for compressing were increased\r
-- LZMA now can use only these match finders: HC4, BT2, BT3, BT4\r
-\r
-\r
-4.32           2005-12-09\r
--------------------------\r
-- Java version of LZMA SDK was included\r
-\r
-\r
-4.30           2005-11-20\r
--------------------------\r
-- Compression ratio was improved in -a2 mode\r
-- Speed optimizations for compressing in -a2 mode\r
-- -fb switch now supports values up to 273\r
-- The bug in 7z_C (7zIn.c) was fixed:\r
-  It used Alloc/Free functions from different memory pools.\r
-  So if program used two memory pools, it worked incorrectly.\r
-- 7z_C: .7z format supporting was improved\r
-- LZMA# SDK (C#.NET version) was included\r
-\r
-\r
-4.27 (Updated) 2005-09-21\r
--------------------------\r
-- Some GUIDs/interfaces in C++ were changed.\r
- IStream.h:\r
-   ISequentialInStream::Read now works as old ReadPart\r
-   ISequentialOutStream::Write now works as old WritePart\r
-\r
-\r
-4.27           2005-08-07\r
--------------------------\r
-- The bug in LzmaDecodeSize.c was fixed:\r
-   if _LZMA_IN_CB and _LZMA_OUT_READ were defined,\r
-   decompressing worked incorrectly.\r
-\r
-\r
-4.26           2005-08-05\r
--------------------------\r
-- Fixes in 7z_C code and LzmaTest.c:\r
-  previous versions could work incorrectly,\r
-  if malloc(0) returns 0\r
-\r
-\r
-4.23           2005-06-29\r
--------------------------\r
-- Small fixes in C++ code\r
-\r
-\r
-4.22           2005-06-10\r
--------------------------\r
-- Small fixes\r
-\r
-\r
-4.21           2005-06-08\r
--------------------------\r
-- Interfaces for ANSI-C LZMA Decoder (LzmaDecode.c) were changed\r
-- New additional version of ANSI-C LZMA Decoder with zlib-like interface:\r
-    - LzmaStateDecode.h\r
-    - LzmaStateDecode.c\r
-    - LzmaStateTest.c\r
-- ANSI-C LZMA Decoder now can decompress files larger than 4 GB\r
-\r
-\r
-4.17           2005-04-18\r
--------------------------\r
-- New example for RAM->RAM compressing/decompressing: \r
-  LZMA + BCJ (filter for x86 code):\r
-    - LzmaRam.h\r
-    - LzmaRam.cpp\r
-    - LzmaRamDecode.h\r
-    - LzmaRamDecode.c\r
-    - -f86 switch for lzma.exe\r
-\r
-\r
-4.16           2005-03-29\r
--------------------------\r
-- The bug was fixed in LzmaDecode.c (ANSI-C LZMA Decoder): \r
-   If _LZMA_OUT_READ was defined, and if encoded stream was corrupted,\r
-   decoder could access memory outside of allocated range.\r
-- Speed optimization of ANSI-C LZMA Decoder (now it's about 20% faster).\r
-  Old version of LZMA Decoder now is in file LzmaDecodeSize.c. \r
-  LzmaDecodeSize.c can provide slightly smaller code than LzmaDecode.c\r
-- Small speed optimization in LZMA C++ code\r
-- filter for SPARC's code was added\r
-- Simplified version of .7z ANSI-C Decoder was included\r
-\r
-\r
-4.06           2004-09-05\r
--------------------------\r
-- The bug in v4.05 was fixed:\r
-    LZMA-Encoder didn't release output stream in some cases.\r
-\r
-\r
-4.05           2004-08-25\r
--------------------------\r
-- Source code of filters for x86, IA-64, ARM, ARM-Thumb \r
-  and PowerPC code was included to SDK\r
-- Some internal minor changes\r
-\r
-\r
-4.04           2004-07-28\r
--------------------------\r
-- More compatibility with some C++ compilers\r
-\r
-\r
-4.03           2004-06-18\r
--------------------------\r
-- "Benchmark" command was added. It measures compressing \r
-  and decompressing speed and shows rating values. \r
-  Also it checks hardware errors.\r
-\r
-\r
-4.02           2004-06-10\r
--------------------------\r
-- C++ LZMA Encoder/Decoder code now is more portable\r
-  and it can be compiled by GCC on Linux.\r
-\r
-\r
-4.01           2004-02-15\r
--------------------------\r
-- Some detection of data corruption was enabled.\r
-    LzmaDecode.c / RangeDecoderReadByte\r
-    .....\r
-    {\r
-      rd->ExtraBytes = 1;\r
-      return 0xFF;\r
-    }\r
-\r
-\r
-4.00           2004-02-13\r
--------------------------\r
-- Original version of LZMA SDK\r
-\r
-\r
-\r
-HISTORY of the LZMA\r
--------------------\r
-  2001-2008:  Improvements to LZMA compressing/decompressing code, \r
-              keeping compatibility with original LZMA format\r
-  1996-2001:  Development of LZMA compression format\r
-\r
-  Some milestones:\r
-\r
-  2001-08-30: LZMA compression was added to 7-Zip\r
-  1999-01-02: First version of 7-Zip was released\r
-  \r
-\r
-End of document\r
diff --git a/BaseTools/Source/C/LzmaCompress/Sdk/lzma.txt b/BaseTools/Source/C/LzmaCompress/Sdk/lzma.txt
deleted file mode 100644 (file)
index d4f4af9..0000000
+++ /dev/null
@@ -1,594 +0,0 @@
-LZMA SDK 4.65\r
--------------\r
-\r
-LZMA SDK provides the documentation, samples, header files, libraries, \r
-and tools you need to develop applications that use LZMA compression.\r
-\r
-LZMA is default and general compression method of 7z format\r
-in 7-Zip compression program (www.7-zip.org). LZMA provides high \r
-compression ratio and very fast decompression.\r
-\r
-LZMA is an improved version of famous LZ77 compression algorithm. \r
-It was improved in way of maximum increasing of compression ratio,\r
-keeping high decompression speed and low memory requirements for \r
-decompressing.\r
-\r
-\r
-\r
-LICENSE\r
--------\r
-\r
-LZMA SDK is written and placed in the public domain by Igor Pavlov.\r
-\r
-\r
-LZMA SDK Contents\r
------------------\r
-\r
-LZMA SDK includes:\r
-\r
-  - ANSI-C/C++/C#/Java source code for LZMA compressing and decompressing\r
-  - Compiled file->file LZMA compressing/decompressing program for Windows system\r
-\r
-\r
-UNIX/Linux version \r
-------------------\r
-To compile C++ version of file->file LZMA encoding, go to directory\r
-C++/7zip/Compress/LZMA_Alone \r
-and call make to recompile it:\r
-  make -f makefile.gcc clean all\r
-\r
-In some UNIX/Linux versions you must compile LZMA with static libraries.\r
-To compile with static libraries, you can use \r
-LIB = -lm -static\r
-\r
-\r
-Files\r
----------------------\r
-lzma.txt     - LZMA SDK description (this file)\r
-7zFormat.txt - 7z Format description\r
-7zC.txt      - 7z ANSI-C Decoder description\r
-methods.txt  - Compression method IDs for .7z\r
-lzma.exe     - Compiled file->file LZMA encoder/decoder for Windows\r
-history.txt  - history of the LZMA SDK\r
-\r
-\r
-Source code structure\r
----------------------\r
-\r
-C/  - C files\r
-        7zCrc*.*   - CRC code\r
-        Alloc.*    - Memory allocation functions\r
-        Bra*.*     - Filters for x86, IA-64, ARM, ARM-Thumb, PowerPC and SPARC code\r
-        LzFind.*   - Match finder for LZ (LZMA) encoders \r
-        LzFindMt.* - Match finder for LZ (LZMA) encoders for multithreading encoding\r
-        LzHash.h   - Additional file for LZ match finder\r
-        LzmaDec.*  - LZMA decoding\r
-        LzmaEnc.*  - LZMA encoding\r
-        LzmaLib.*  - LZMA Library for DLL calling\r
-        Types.h    - Basic types for another .c files\r
-       Threads.*  - The code for multithreading.\r
-\r
-    LzmaLib  - LZMA Library (.DLL for Windows)\r
-    \r
-    LzmaUtil - LZMA Utility (file->file LZMA encoder/decoder).\r
-\r
-    Archive - files related to archiving\r
-      7z     - 7z ANSI-C Decoder\r
-\r
-CPP/ -- CPP files\r
-\r
-  Common  - common files for C++ projects\r
-  Windows - common files for Windows related code\r
-\r
-  7zip    - files related to 7-Zip Project\r
-\r
-    Common   - common files for 7-Zip\r
-\r
-    Compress - files related to compression/decompression\r
-\r
-      Copy         - Copy coder\r
-      RangeCoder   - Range Coder (special code of compression/decompression)\r
-      LZMA         - LZMA compression/decompression on C++\r
-      LZMA_Alone   - file->file LZMA compression/decompression\r
-      Branch       - Filters for x86, IA-64, ARM, ARM-Thumb, PowerPC and SPARC code\r
-\r
-    Archive - files related to archiving\r
-\r
-      Common   - common files for archive handling\r
-      7z       - 7z C++ Encoder/Decoder\r
-\r
-    Bundles    - Modules that are bundles of other modules\r
-  \r
-      Alone7z           - 7zr.exe: Standalone version of 7z.exe that supports only 7z/LZMA/BCJ/BCJ2\r
-      Format7zR         - 7zr.dll: Reduced version of 7za.dll: extracting/compressing to 7z/LZMA/BCJ/BCJ2\r
-      Format7zExtractR  - 7zxr.dll: Reduced version of 7zxa.dll: extracting from 7z/LZMA/BCJ/BCJ2.\r
-\r
-    UI        - User Interface files\r
-         \r
-      Client7z - Test application for 7za.dll,  7zr.dll, 7zxr.dll\r
-      Common   - Common UI files\r
-      Console  - Code for console archiver\r
-\r
-\r
-\r
-CS/ - C# files\r
-  7zip\r
-    Common   - some common files for 7-Zip\r
-    Compress - files related to compression/decompression\r
-      LZ     - files related to LZ (Lempel-Ziv) compression algorithm\r
-      LZMA         - LZMA compression/decompression\r
-      LzmaAlone    - file->file LZMA compression/decompression\r
-      RangeCoder   - Range Coder (special code of compression/decompression)\r
-\r
-Java/  - Java files\r
-  SevenZip\r
-    Compression    - files related to compression/decompression\r
-      LZ           - files related to LZ (Lempel-Ziv) compression algorithm\r
-      LZMA         - LZMA compression/decompression\r
-      RangeCoder   - Range Coder (special code of compression/decompression)\r
-\r
-\r
-C/C++ source code of LZMA SDK is part of 7-Zip project.\r
-7-Zip source code can be downloaded from 7-Zip's SourceForge page:\r
-\r
-  http://sourceforge.net/projects/sevenzip/\r
-\r
-\r
-\r
-LZMA features\r
--------------\r
-  - Variable dictionary size (up to 1 GB)\r
-  - Estimated compressing speed: about 2 MB/s on 2 GHz CPU\r
-  - Estimated decompressing speed: \r
-      - 20-30 MB/s on 2 GHz Core 2 or AMD Athlon 64\r
-      - 1-2 MB/s on 200 MHz ARM, MIPS, PowerPC or other simple RISC\r
-  - Small memory requirements for decompressing (16 KB + DictionarySize)\r
-  - Small code size for decompressing: 5-8 KB\r
-\r
-LZMA decoder uses only integer operations and can be \r
-implemented in any modern 32-bit CPU (or on 16-bit CPU with some conditions).\r
-\r
-Some critical operations that affect the speed of LZMA decompression:\r
-  1) 32*16 bit integer multiply\r
-  2) Misspredicted branches (penalty mostly depends from pipeline length)\r
-  3) 32-bit shift and arithmetic operations\r
-\r
-The speed of LZMA decompressing mostly depends from CPU speed.\r
-Memory speed has no big meaning. But if your CPU has small data cache, \r
-overall weight of memory speed will slightly increase.\r
-\r
-\r
-How To Use\r
-----------\r
-\r
-Using LZMA encoder/decoder executable\r
---------------------------------------\r
-\r
-Usage:  LZMA <e|d> inputFile outputFile [<switches>...]\r
-\r
-  e: encode file\r
-\r
-  d: decode file\r
-\r
-  b: Benchmark. There are two tests: compressing and decompressing \r
-     with LZMA method. Benchmark shows rating in MIPS (million \r
-     instructions per second). Rating value is calculated from \r
-     measured speed and it is normalized with Intel's Core 2 results.\r
-     Also Benchmark checks possible hardware errors (RAM \r
-     errors in most cases). Benchmark uses these settings:\r
-     (-a1, -d21, -fb32, -mfbt4). You can change only -d parameter. \r
-     Also you can change the number of iterations. Example for 30 iterations:\r
-       LZMA b 30\r
-     Default number of iterations is 10.\r
-\r
-<Switches>\r
-  \r
-\r
-  -a{N}:  set compression mode 0 = fast, 1 = normal\r
-          default: 1 (normal)\r
-\r
-  d{N}:   Sets Dictionary size - [0, 30], default: 23 (8MB)\r
-          The maximum value for dictionary size is 1 GB = 2^30 bytes.\r
-          Dictionary size is calculated as DictionarySize = 2^N bytes. \r
-          For decompressing file compressed by LZMA method with dictionary \r
-          size D = 2^N you need about D bytes of memory (RAM).\r
-\r
-  -fb{N}: set number of fast bytes - [5, 273], default: 128\r
-          Usually big number gives a little bit better compression ratio \r
-          and slower compression process.\r
-\r
-  -lc{N}: set number of literal context bits - [0, 8], default: 3\r
-          Sometimes lc=4 gives gain for big files.\r
-\r
-  -lp{N}: set number of literal pos bits - [0, 4], default: 0\r
-          lp switch is intended for periodical data when period is \r
-          equal 2^N. For example, for 32-bit (4 bytes) \r
-          periodical data you can use lp=2. Often it's better to set lc0, \r
-          if you change lp switch.\r
-\r
-  -pb{N}: set number of pos bits - [0, 4], default: 2\r
-          pb switch is intended for periodical data \r
-          when period is equal 2^N.\r
-\r
-  -mf{MF_ID}: set Match Finder. Default: bt4. \r
-              Algorithms from hc* group doesn't provide good compression \r
-              ratio, but they often works pretty fast in combination with \r
-              fast mode (-a0).\r
-\r
-              Memory requirements depend from dictionary size \r
-              (parameter "d" in table below). \r
-\r
-               MF_ID     Memory                   Description\r
-\r
-                bt2    d *  9.5 + 4MB  Binary Tree with 2 bytes hashing.\r
-                bt3    d * 11.5 + 4MB  Binary Tree with 3 bytes hashing.\r
-                bt4    d * 11.5 + 4MB  Binary Tree with 4 bytes hashing.\r
-                hc4    d *  7.5 + 4MB  Hash Chain with 4 bytes hashing.\r
-\r
-  -eos:   write End Of Stream marker. By default LZMA doesn't write \r
-          eos marker, since LZMA decoder knows uncompressed size \r
-          stored in .lzma file header.\r
-\r
-  -si:    Read data from stdin (it will write End Of Stream marker).\r
-  -so:    Write data to stdout\r
-\r
-\r
-Examples:\r
-\r
-1) LZMA e file.bin file.lzma -d16 -lc0 \r
-\r
-compresses file.bin to file.lzma with 64 KB dictionary (2^16=64K)  \r
-and 0 literal context bits. -lc0 allows to reduce memory requirements \r
-for decompression.\r
-\r
-\r
-2) LZMA e file.bin file.lzma -lc0 -lp2\r
-\r
-compresses file.bin to file.lzma with settings suitable \r
-for 32-bit periodical data (for example, ARM or MIPS code).\r
-\r
-3) LZMA d file.lzma file.bin\r
-\r
-decompresses file.lzma to file.bin.\r
-\r
-\r
-Compression ratio hints\r
------------------------\r
-\r
-Recommendations\r
----------------\r
-\r
-To increase the compression ratio for LZMA compressing it's desirable \r
-to have aligned data (if it's possible) and also it's desirable to locate\r
-data in such order, where code is grouped in one place and data is \r
-grouped in other place (it's better than such mixing: code, data, code,\r
-data, ...).\r
-\r
-\r
-Filters\r
--------\r
-You can increase the compression ratio for some data types, using\r
-special filters before compressing. For example, it's possible to \r
-increase the compression ratio on 5-10% for code for those CPU ISAs: \r
-x86, IA-64, ARM, ARM-Thumb, PowerPC, SPARC.\r
-\r
-You can find C source code of such filters in C/Bra*.* files\r
-\r
-You can check the compression ratio gain of these filters with such \r
-7-Zip commands (example for ARM code):\r
-No filter:\r
-  7z a a1.7z a.bin -m0=lzma\r
-\r
-With filter for little-endian ARM code:\r
-  7z a a2.7z a.bin -m0=arm -m1=lzma        \r
-\r
-It works in such manner:\r
-Compressing    = Filter_encoding + LZMA_encoding\r
-Decompressing  = LZMA_decoding + Filter_decoding\r
-\r
-Compressing and decompressing speed of such filters is very high,\r
-so it will not increase decompressing time too much.\r
-Moreover, it reduces decompression time for LZMA_decoding, \r
-since compression ratio with filtering is higher.\r
-\r
-These filters convert CALL (calling procedure) instructions \r
-from relative offsets to absolute addresses, so such data becomes more \r
-compressible.\r
-\r
-For some ISAs (for example, for MIPS) it's impossible to get gain from such filter.\r
-\r
-\r
-LZMA compressed file format\r
----------------------------\r
-Offset Size Description\r
-  0     1   Special LZMA properties (lc,lp, pb in encoded form)\r
-  1     4   Dictionary size (little endian)\r
-  5     8   Uncompressed size (little endian). -1 means unknown size\r
- 13         Compressed data\r
-\r
-\r
-ANSI-C LZMA Decoder\r
-~~~~~~~~~~~~~~~~~~~\r
-\r
-Please note that interfaces for ANSI-C code were changed in LZMA SDK 4.58.\r
-If you want to use old interfaces you can download previous version of LZMA SDK\r
-from sourceforge.net site.\r
-\r
-To use ANSI-C LZMA Decoder you need the following files:\r
-1) LzmaDec.h + LzmaDec.c + Types.h\r
-LzmaUtil/LzmaUtil.c is example application that uses these files.\r
-\r
-\r
-Memory requirements for LZMA decoding\r
--------------------------------------\r
-\r
-Stack usage of LZMA decoding function for local variables is not \r
-larger than 200-400 bytes.\r
-\r
-LZMA Decoder uses dictionary buffer and internal state structure.\r
-Internal state structure consumes\r
-  state_size = (4 + (1.5 << (lc + lp))) KB\r
-by default (lc=3, lp=0), state_size = 16 KB.\r
-\r
-\r
-How To decompress data\r
-----------------------\r
-\r
-LZMA Decoder (ANSI-C version) now supports 2 interfaces:\r
-1) Single-call Decompressing\r
-2) Multi-call State Decompressing (zlib-like interface)\r
-\r
-You must use external allocator:\r
-Example:\r
-void *SzAlloc(void *p, size_t size) { p = p; return malloc(size); }\r
-void SzFree(void *p, void *address) { p = p; free(address); }\r
-ISzAlloc alloc = { SzAlloc, SzFree };\r
-\r
-You can use p = p; operator to disable compiler warnings.\r
-\r
-\r
-Single-call Decompressing\r
--------------------------\r
-When to use: RAM->RAM decompressing\r
-Compile files: LzmaDec.h + LzmaDec.c + Types.h\r
-Compile defines: no defines\r
-Memory Requirements:\r
-  - Input buffer: compressed size\r
-  - Output buffer: uncompressed size\r
-  - LZMA Internal Structures: state_size (16 KB for default settings) \r
-\r
-Interface:\r
-  int LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,\r
-      const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode, \r
-      ELzmaStatus *status, ISzAlloc *alloc);\r
-  In: \r
-    dest     - output data\r
-    destLen  - output data size\r
-    src      - input data\r
-    srcLen   - input data size\r
-    propData - LZMA properties  (5 bytes)\r
-    propSize - size of propData buffer (5 bytes)\r
-    finishMode - It has meaning only if the decoding reaches output limit (*destLen).\r
-        LZMA_FINISH_ANY - Decode just destLen bytes.\r
-        LZMA_FINISH_END - Stream must be finished after (*destLen).\r
-                           You can use LZMA_FINISH_END, when you know that \r
-                           current output buffer covers last bytes of stream. \r
-    alloc    - Memory allocator.\r
-\r
-  Out: \r
-    destLen  - processed output size \r
-    srcLen   - processed input size \r
-\r
-  Output:\r
-    SZ_OK\r
-      status:\r
-        LZMA_STATUS_FINISHED_WITH_MARK\r
-        LZMA_STATUS_NOT_FINISHED \r
-        LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK\r
-    SZ_ERROR_DATA - Data error\r
-    SZ_ERROR_MEM  - Memory allocation error\r
-    SZ_ERROR_UNSUPPORTED - Unsupported properties\r
-    SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).\r
-\r
-  If LZMA decoder sees end_marker before reaching output limit, it returns OK result,\r
-  and output value of destLen will be less than output buffer size limit.\r
-\r
-  You can use multiple checks to test data integrity after full decompression:\r
-    1) Check Result and "status" variable.\r
-    2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.\r
-    3) Check that output(srcLen) = compressedSize, if you know real compressedSize. \r
-       You must use correct finish mode in that case. */ \r
-\r
-\r
-Multi-call State Decompressing (zlib-like interface)\r
-----------------------------------------------------\r
-\r
-When to use: file->file decompressing \r
-Compile files: LzmaDec.h + LzmaDec.c + Types.h\r
-\r
-Memory Requirements:\r
- - Buffer for input stream: any size (for example, 16 KB)\r
- - Buffer for output stream: any size (for example, 16 KB)\r
- - LZMA Internal Structures: state_size (16 KB for default settings) \r
- - LZMA dictionary (dictionary size is encoded in LZMA properties header)\r
-\r
-1) read LZMA properties (5 bytes) and uncompressed size (8 bytes, little-endian) to header:\r
-   unsigned char header[LZMA_PROPS_SIZE + 8];\r
-   ReadFile(inFile, header, sizeof(header)\r
-\r
-2) Allocate CLzmaDec structures (state + dictionary) using LZMA properties\r
-\r
-  CLzmaDec state;\r
-  LzmaDec_Constr(&state);\r
-  res = LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc);\r
-  if (res != SZ_OK)\r
-    return res;\r
-\r
-3) Init LzmaDec structure before any new LZMA stream. And call LzmaDec_DecodeToBuf in loop\r
-\r
-  LzmaDec_Init(&state);\r
-  for (;;)\r
-  {\r
-    ... \r
-    int res = LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, \r
-       const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode);\r
-    ...\r
-  }\r
-\r
-\r
-4) Free all allocated structures\r
-  LzmaDec_Free(&state, &g_Alloc);\r
-\r
-For full code example, look at C/LzmaUtil/LzmaUtil.c code.\r
-\r
-\r
-How To compress data\r
---------------------\r
-\r
-Compile files: LzmaEnc.h + LzmaEnc.c + Types.h +\r
-LzFind.c + LzFind.h + LzFindMt.c + LzFindMt.h + LzHash.h\r
-\r
-Memory Requirements:\r
-  - (dictSize * 11.5 + 6 MB) + state_size\r
-\r
-Lzma Encoder can use two memory allocators:\r
-1) alloc - for small arrays.\r
-2) allocBig - for big arrays.\r
-\r
-For example, you can use Large RAM Pages (2 MB) in allocBig allocator for \r
-better compression speed. Note that Windows has bad implementation for \r
-Large RAM Pages. \r
-It's OK to use same allocator for alloc and allocBig.\r
-\r
-\r
-Single-call Compression with callbacks\r
---------------------------------------\r
-\r
-Check C/LzmaUtil/LzmaUtil.c as example, \r
-\r
-When to use: file->file decompressing \r
-\r
-1) you must implement callback structures for interfaces:\r
-ISeqInStream\r
-ISeqOutStream\r
-ICompressProgress\r
-ISzAlloc\r
-\r
-static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }\r
-static void SzFree(void *p, void *address) {  p = p; MyFree(address); }\r
-static ISzAlloc g_Alloc = { SzAlloc, SzFree };\r
-\r
-  CFileSeqInStream inStream;\r
-  CFileSeqOutStream outStream;\r
-\r
-  inStream.funcTable.Read = MyRead;\r
-  inStream.file = inFile;\r
-  outStream.funcTable.Write = MyWrite;\r
-  outStream.file = outFile;\r
-\r
-\r
-2) Create CLzmaEncHandle object;\r
-\r
-  CLzmaEncHandle enc;\r
-\r
-  enc = LzmaEnc_Create(&g_Alloc);\r
-  if (enc == 0)\r
-    return SZ_ERROR_MEM;\r
-\r
-\r
-3) initialize CLzmaEncProps properties;\r
-\r
-  LzmaEncProps_Init(&props);\r
-\r
-  Then you can change some properties in that structure.\r
-\r
-4) Send LZMA properties to LZMA Encoder\r
-\r
-  res = LzmaEnc_SetProps(enc, &props);\r
-\r
-5) Write encoded properties to header\r
-\r
-    Byte header[LZMA_PROPS_SIZE + 8];\r
-    size_t headerSize = LZMA_PROPS_SIZE;\r
-    UInt64 fileSize;\r
-    int i;\r
-\r
-    res = LzmaEnc_WriteProperties(enc, header, &headerSize);\r
-    fileSize = MyGetFileLength(inFile);\r
-    for (i = 0; i < 8; i++)\r
-      header[headerSize++] = (Byte)(fileSize >> (8 * i));\r
-    MyWriteFileAndCheck(outFile, header, headerSize)\r
-\r
-6) Call encoding function:\r
-      res = LzmaEnc_Encode(enc, &outStream.funcTable, &inStream.funcTable, \r
-        NULL, &g_Alloc, &g_Alloc);\r
-\r
-7) Destroy LZMA Encoder Object\r
-  LzmaEnc_Destroy(enc, &g_Alloc, &g_Alloc);\r
-\r
-\r
-If callback function return some error code, LzmaEnc_Encode also returns that code.\r
-\r
-\r
-Single-call RAM->RAM Compression\r
---------------------------------\r
-\r
-Single-call RAM->RAM Compression is similar to Compression with callbacks,\r
-but you provide pointers to buffers instead of pointers to stream callbacks:\r
-\r
-HRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,\r
-    CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark, \r
-    ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);\r
-\r
-Return code:\r
-  SZ_OK               - OK\r
-  SZ_ERROR_MEM        - Memory allocation error \r
-  SZ_ERROR_PARAM      - Incorrect paramater\r
-  SZ_ERROR_OUTPUT_EOF - output buffer overflow\r
-  SZ_ERROR_THREAD     - errors in multithreading functions (only for Mt version)\r
-\r
-\r
-\r
-LZMA Defines\r
-------------\r
-\r
-_LZMA_SIZE_OPT - Enable some optimizations in LZMA Decoder to get smaller executable code.\r
-\r
-_LZMA_PROB32   - It can increase the speed on some 32-bit CPUs, but memory usage for \r
-                 some structures will be doubled in that case.\r
-\r
-_LZMA_UINT32_IS_ULONG  - Define it if int is 16-bit on your compiler and long is 32-bit.\r
-\r
-_LZMA_NO_SYSTEM_SIZE_T  - Define it if you don't want to use size_t type.\r
-\r
-\r
-C++ LZMA Encoder/Decoder \r
-~~~~~~~~~~~~~~~~~~~~~~~~\r
-C++ LZMA code use COM-like interfaces. So if you want to use it, \r
-you can study basics of COM/OLE.\r
-C++ LZMA code is just wrapper over ANSI-C code.\r
-\r
-\r
-C++ Notes\r
-~~~~~~~~~~~~~~~~~~~~~~~~\r
-If you use some C++ code folders in 7-Zip (for example, C++ code for .7z handling),\r
-you must check that you correctly work with "new" operator.\r
-7-Zip can be compiled with MSVC 6.0 that doesn't throw "exception" from "new" operator.\r
-So 7-Zip uses "CPP\Common\NewHandler.cpp" that redefines "new" operator:\r
-operator new(size_t size)\r
-{\r
-  void *p = ::malloc(size);\r
-  if (p == 0)\r
-    throw CNewException();\r
-  return p;\r
-}\r
-If you use MSCV that throws exception for "new" operator, you can compile without \r
-"NewHandler.cpp". So standard exception will be used. Actually some code of \r
-7-Zip catches any exception in internal code and converts it to HRESULT code.\r
-So you don't need to catch CNewException, if you call COM interfaces of 7-Zip.\r
-\r
----\r
-\r
-http://www.7-zip.org\r
-http://www.7-zip.org/sdk.html\r
-http://www.7-zip.org/support.html\r