summaryrefslogtreecommitdiffstats
path: root/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C
diff options
context:
space:
mode:
Diffstat (limited to 'MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C')
-rw-r--r--MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/7zTypes.h425
-rw-r--r--MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/7zVersion.h30
-rw-r--r--MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/Bra.h56
-rw-r--r--MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/Bra86.c81
-rw-r--r--MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/Compiler.h6
-rw-r--r--MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/CpuArch.h358
-rw-r--r--MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzFind.c1110
-rw-r--r--MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzFind.h260
-rw-r--r--MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzHash.h27
-rw-r--r--MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzmaDec.c1344
-rw-r--r--MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzmaDec.h153
11 files changed, 2190 insertions, 1660 deletions
diff --git a/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/7zTypes.h b/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/7zTypes.h
index 42b7040dd7..502a32e4da 100644
--- a/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/7zTypes.h
+++ b/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/7zTypes.h
@@ -9,73 +9,71 @@
#endif
#ifdef EFIAPI
-#include "UefiLzma.h"
+ #include "UefiLzma.h"
#else
-#include <stddef.h>
+ #include <stddef.h>
#endif
#ifndef EXTERN_C_BEGIN
-#ifdef __cplusplus
-#define EXTERN_C_BEGIN extern "C" {
-#define EXTERN_C_END }
-#else
+ #ifdef __cplusplus
+#define EXTERN_C_BEGIN extern "C" {
+#define EXTERN_C_END }
+ #else
#define EXTERN_C_BEGIN
#define EXTERN_C_END
-#endif
+ #endif
#endif
EXTERN_C_BEGIN
-#define SZ_OK 0
+#define SZ_OK 0
-#define SZ_ERROR_DATA 1
-#define SZ_ERROR_MEM 2
-#define SZ_ERROR_CRC 3
-#define SZ_ERROR_UNSUPPORTED 4
-#define SZ_ERROR_PARAM 5
-#define SZ_ERROR_INPUT_EOF 6
-#define SZ_ERROR_OUTPUT_EOF 7
-#define SZ_ERROR_READ 8
-#define SZ_ERROR_WRITE 9
-#define SZ_ERROR_PROGRESS 10
-#define SZ_ERROR_FAIL 11
-#define SZ_ERROR_THREAD 12
+#define SZ_ERROR_DATA 1
+#define SZ_ERROR_MEM 2
+#define SZ_ERROR_CRC 3
+#define SZ_ERROR_UNSUPPORTED 4
+#define SZ_ERROR_PARAM 5
+#define SZ_ERROR_INPUT_EOF 6
+#define SZ_ERROR_OUTPUT_EOF 7
+#define SZ_ERROR_READ 8
+#define SZ_ERROR_WRITE 9
+#define SZ_ERROR_PROGRESS 10
+#define SZ_ERROR_FAIL 11
+#define SZ_ERROR_THREAD 12
-#define SZ_ERROR_ARCHIVE 16
-#define SZ_ERROR_NO_ARCHIVE 17
+#define SZ_ERROR_ARCHIVE 16
+#define SZ_ERROR_NO_ARCHIVE 17
typedef int SRes;
-
#ifdef _WIN32
/* typedef DWORD WRes; */
typedef unsigned WRes;
-#define MY_SRes_HRESULT_FROM_WRes(x) HRESULT_FROM_WIN32(x)
+#define MY_SRes_HRESULT_FROM_WRes(x) HRESULT_FROM_WIN32(x)
#else
typedef int WRes;
-#define MY__FACILITY_WIN32 7
-#define MY__FACILITY__WRes MY__FACILITY_WIN32
-#define MY_SRes_HRESULT_FROM_WRes(x) ((HRESULT)(x) <= 0 ? ((HRESULT)(x)) : ((HRESULT) (((x) & 0x0000FFFF) | (MY__FACILITY__WRes << 16) | 0x80000000)))
+#define MY__FACILITY_WIN32 7
+#define MY__FACILITY__WRes MY__FACILITY_WIN32
+#define MY_SRes_HRESULT_FROM_WRes(x) ((HRESULT)(x) <= 0 ? ((HRESULT)(x)) : ((HRESULT) (((x) & 0x0000FFFF) | (MY__FACILITY__WRes << 16) | 0x80000000)))
#endif
-
#ifndef RINOK
-#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }
+#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }
#endif
-typedef unsigned char Byte;
-typedef short Int16;
+typedef unsigned char Byte;
+typedef short Int16;
typedef unsigned short UInt16;
#ifdef _LZMA_UINT32_IS_ULONG
-typedef long Int32;
+typedef long Int32;
typedef unsigned long UInt32;
#else
-typedef int Int32;
+typedef int Int32;
typedef unsigned int UInt32;
#endif
@@ -84,20 +82,20 @@ typedef unsigned int UInt32;
/* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.
NOTES: Some code will work incorrectly in that case! */
-typedef long Int64;
+typedef long Int64;
typedef unsigned long UInt64;
#else
-#if defined(_MSC_VER) || defined(__BORLANDC__)
-typedef __int64 Int64;
+ #if defined (_MSC_VER) || defined (__BORLANDC__)
+typedef __int64 Int64;
typedef unsigned __int64 UInt64;
-#define UINT64_CONST(n) n
-#else
-typedef long long int Int64;
+#define UINT64_CONST(n) n
+ #else
+typedef long long int Int64;
typedef unsigned long long int UInt64;
-#define UINT64_CONST(n) n ## ULL
-#endif
+#define UINT64_CONST(n) n ## ULL
+ #endif
#endif
@@ -109,28 +107,27 @@ typedef size_t SizeT;
typedef int BoolInt;
/* typedef BoolInt Bool; */
-#define True 1
-#define False 0
-
+#define True 1
+#define False 0
#ifdef _WIN32
-#define MY_STD_CALL __stdcall
+#define MY_STD_CALL __stdcall
#else
#define MY_STD_CALL
#endif
-#if defined(_MSC_VER) && !defined(__clang__)
+#if defined (_MSC_VER) && !defined (__clang__)
-#if _MSC_VER >= 1300
-#define MY_NO_INLINE __declspec(noinline)
-#else
+ #if _MSC_VER >= 1300
+#define MY_NO_INLINE __declspec(noinline)
+ #else
#define MY_NO_INLINE
-#endif
+ #endif
-#define MY_FORCE_INLINE __forceinline
+#define MY_FORCE_INLINE __forceinline
-#define MY_CDECL __cdecl
-#define MY_FAST_CALL __fastcall
+#define MY_CDECL __cdecl
+#define MY_FAST_CALL __fastcall
#else
@@ -142,6 +139,7 @@ typedef int BoolInt;
/* inline keyword : for C++ / C99 */
/* GCC, clang: */
+
/*
#if defined (__GNUC__) && (__GNUC__ >= 4)
#define MY_FORCE_INLINE __attribute__((always_inline))
@@ -151,179 +149,252 @@ typedef int BoolInt;
#endif
-
/* The following interfaces use first parameter as pointer to structure */
typedef struct IByteIn IByteIn;
-struct IByteIn
-{
- Byte (*Read)(const IByteIn *p); /* reads one byte, returns 0 in case of EOF or error */
+struct IByteIn {
+ Byte (*Read)(
+ const IByteIn *p
+ ); /* reads one byte, returns 0 in case of EOF or error */
};
-#define IByteIn_Read(p) (p)->Read(p)
+#define IByteIn_Read(p) (p)->Read(p)
typedef struct IByteOut IByteOut;
-struct IByteOut
-{
- void (*Write)(const IByteOut *p, Byte b);
+struct IByteOut {
+ void (*Write)(
+ const IByteOut *p,
+ Byte b
+ );
};
-#define IByteOut_Write(p, b) (p)->Write(p, b)
+#define IByteOut_Write(p, b) (p)->Write(p, b)
typedef struct ISeqInStream ISeqInStream;
-struct ISeqInStream
-{
- SRes (*Read)(const ISeqInStream *p, void *buf, size_t *size);
- /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
- (output(*size) < input(*size)) is allowed */
+struct ISeqInStream {
+ SRes (*Read)(
+ const ISeqInStream *p,
+ void *buf,
+ size_t *size
+ );
+
+ /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
+ (output(*size) < input(*size)) is allowed */
};
-#define ISeqInStream_Read(p, buf, size) (p)->Read(p, buf, size)
-/* it can return SZ_ERROR_INPUT_EOF */
-SRes SeqInStream_Read(const ISeqInStream *stream, void *buf, size_t size);
-SRes SeqInStream_Read2(const ISeqInStream *stream, void *buf, size_t size, SRes errorType);
-SRes SeqInStream_ReadByte(const ISeqInStream *stream, Byte *buf);
+#define ISeqInStream_Read(p, buf, size) (p)->Read(p, buf, size)
+/* it can return SZ_ERROR_INPUT_EOF */
+SRes
+SeqInStream_Read (
+ const ISeqInStream *stream,
+ void *buf,
+ size_t size
+ );
+
+SRes
+SeqInStream_Read2 (
+ const ISeqInStream *stream,
+ void *buf,
+ size_t size,
+ SRes errorType
+ );
+
+SRes
+SeqInStream_ReadByte (
+ const ISeqInStream *stream,
+ Byte *buf
+ );
typedef struct ISeqOutStream ISeqOutStream;
-struct ISeqOutStream
-{
- size_t (*Write)(const ISeqOutStream *p, const void *buf, size_t size);
- /* Returns: result - the number of actually written bytes.
- (result < size) means error */
+struct ISeqOutStream {
+ size_t (*Write)(
+ const ISeqOutStream *p,
+ const void *buf,
+ size_t size
+ );
+
+ /* Returns: result - the number of actually written bytes.
+ (result < size) means error */
};
-#define ISeqOutStream_Write(p, buf, size) (p)->Write(p, buf, size)
-typedef enum
-{
+#define ISeqOutStream_Write(p, buf, size) (p)->Write(p, buf, size)
+
+typedef enum {
SZ_SEEK_SET = 0,
SZ_SEEK_CUR = 1,
SZ_SEEK_END = 2
} ESzSeek;
-
typedef struct ISeekInStream ISeekInStream;
-struct ISeekInStream
-{
- SRes (*Read)(const ISeekInStream *p, void *buf, size_t *size); /* same as ISeqInStream::Read */
- SRes (*Seek)(const ISeekInStream *p, Int64 *pos, ESzSeek origin);
+struct ISeekInStream {
+ SRes (*Read)(
+ const ISeekInStream *p,
+ void *buf,
+ size_t *size
+ ); /* same as ISeqInStream::Read */
+ SRes (*Seek)(
+ const ISeekInStream *p,
+ Int64 *pos,
+ ESzSeek origin
+ );
};
-#define ISeekInStream_Read(p, buf, size) (p)->Read(p, buf, size)
-#define ISeekInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin)
+#define ISeekInStream_Read(p, buf, size) (p)->Read(p, buf, size)
+#define ISeekInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin)
typedef struct ILookInStream ILookInStream;
-struct ILookInStream
-{
- SRes (*Look)(const ILookInStream *p, const void **buf, size_t *size);
- /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
- (output(*size) > input(*size)) is not allowed
- (output(*size) < input(*size)) is allowed */
- SRes (*Skip)(const ILookInStream *p, size_t offset);
- /* offset must be <= output(*size) of Look */
-
- SRes (*Read)(const ILookInStream *p, void *buf, size_t *size);
- /* reads directly (without buffer). It's same as ISeqInStream::Read */
- SRes (*Seek)(const ILookInStream *p, Int64 *pos, ESzSeek origin);
+struct ILookInStream {
+ SRes (*Look)(
+ const ILookInStream *p,
+ const void **buf,
+ size_t *size
+ );
+
+ /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
+ (output(*size) > input(*size)) is not allowed
+ (output(*size) < input(*size)) is allowed */
+ SRes (*Skip)(
+ const ILookInStream *p,
+ size_t offset
+ );
+ /* offset must be <= output(*size) of Look */
+
+ SRes (*Read)(
+ const ILookInStream *p,
+ void *buf,
+ size_t *size
+ );
+ /* reads directly (without buffer). It's same as ISeqInStream::Read */
+ SRes (*Seek)(
+ const ILookInStream *p,
+ Int64 *pos,
+ ESzSeek origin
+ );
};
-#define ILookInStream_Look(p, buf, size) (p)->Look(p, buf, size)
-#define ILookInStream_Skip(p, offset) (p)->Skip(p, offset)
-#define ILookInStream_Read(p, buf, size) (p)->Read(p, buf, size)
-#define ILookInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin)
+#define ILookInStream_Look(p, buf, size) (p)->Look(p, buf, size)
+#define ILookInStream_Skip(p, offset) (p)->Skip(p, offset)
+#define ILookInStream_Read(p, buf, size) (p)->Read(p, buf, size)
+#define ILookInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin)
+SRes
+LookInStream_LookRead (
+ const ILookInStream *stream,
+ void *buf,
+ size_t *size
+ );
-SRes LookInStream_LookRead(const ILookInStream *stream, void *buf, size_t *size);
-SRes LookInStream_SeekTo(const ILookInStream *stream, UInt64 offset);
+SRes
+LookInStream_SeekTo (
+ const ILookInStream *stream,
+ UInt64 offset
+ );
/* reads via ILookInStream::Read */
-SRes LookInStream_Read2(const ILookInStream *stream, void *buf, size_t size, SRes errorType);
-SRes LookInStream_Read(const ILookInStream *stream, void *buf, size_t size);
-
-
-
-typedef struct
-{
- ILookInStream vt;
- const ISeekInStream *realStream;
-
- size_t pos;
- size_t size; /* it's data size */
+SRes
+LookInStream_Read2 (
+ const ILookInStream *stream,
+ void *buf,
+ size_t size,
+ SRes errorType
+ );
+
+SRes
+LookInStream_Read (
+ const ILookInStream *stream,
+ void *buf,
+ size_t size
+ );
+
+typedef struct {
+ ILookInStream vt;
+ const ISeekInStream *realStream;
+
+ size_t pos;
+ size_t size; /* it's data size */
/* the following variables must be set outside */
- Byte *buf;
- size_t bufSize;
+ Byte *buf;
+ size_t bufSize;
} CLookToRead2;
-void LookToRead2_CreateVTable(CLookToRead2 *p, int lookahead);
-
-#define LookToRead2_Init(p) { (p)->pos = (p)->size = 0; }
+void
+LookToRead2_CreateVTable (
+ CLookToRead2 *p,
+ int lookahead
+ );
+#define LookToRead2_Init(p) { (p)->pos = (p)->size = 0; }
-typedef struct
-{
- ISeqInStream vt;
- const ILookInStream *realStream;
+typedef struct {
+ ISeqInStream vt;
+ const ILookInStream *realStream;
} CSecToLook;
-void SecToLook_CreateVTable(CSecToLook *p);
+void
+SecToLook_CreateVTable (
+ CSecToLook *p
+ );
-
-
-typedef struct
-{
- ISeqInStream vt;
- const ILookInStream *realStream;
+typedef struct {
+ ISeqInStream vt;
+ const ILookInStream *realStream;
} CSecToRead;
-void SecToRead_CreateVTable(CSecToRead *p);
-
+void
+SecToRead_CreateVTable (
+ CSecToRead *p
+ );
typedef struct ICompressProgress ICompressProgress;
-struct ICompressProgress
-{
- SRes (*Progress)(const ICompressProgress *p, UInt64 inSize, UInt64 outSize);
- /* Returns: result. (result != SZ_OK) means break.
- Value (UInt64)(Int64)-1 for size means unknown value. */
-};
-#define ICompressProgress_Progress(p, inSize, outSize) (p)->Progress(p, inSize, outSize)
+struct ICompressProgress {
+ SRes (*Progress)(
+ const ICompressProgress *p,
+ UInt64 inSize,
+ UInt64 outSize
+ );
+ /* Returns: result. (result != SZ_OK) means break.
+ Value (UInt64)(Int64)-1 for size means unknown value. */
+};
+#define ICompressProgress_Progress(p, inSize, outSize) (p)->Progress(p, inSize, outSize)
typedef struct ISzAlloc ISzAlloc;
-typedef const ISzAlloc * ISzAllocPtr;
-
-struct ISzAlloc
-{
- void *(*Alloc)(ISzAllocPtr p, size_t size);
- void (*Free)(ISzAllocPtr p, void *address); /* address can be 0 */
+typedef const ISzAlloc *ISzAllocPtr;
+
+struct ISzAlloc {
+ void *(*Alloc)(
+ ISzAllocPtr p,
+ size_t size
+ );
+ void (*Free)(
+ ISzAllocPtr p,
+ void *address
+ ); /* address can be 0 */
};
-#define ISzAlloc_Alloc(p, size) (p)->Alloc(p, size)
-#define ISzAlloc_Free(p, a) (p)->Free(p, a)
+#define ISzAlloc_Alloc(p, size) (p)->Alloc(p, size)
+#define ISzAlloc_Free(p, a) (p)->Free(p, a)
/* deprecated */
-#define IAlloc_Alloc(p, size) ISzAlloc_Alloc(p, size)
-#define IAlloc_Free(p, a) ISzAlloc_Free(p, a)
-
-
-
-
+#define IAlloc_Alloc(p, size) ISzAlloc_Alloc(p, size)
+#define IAlloc_Free(p, a) ISzAlloc_Free(p, a)
#ifndef MY_offsetof
#ifdef offsetof
- #define MY_offsetof(type, m) offsetof(type, m)
- /*
- #define MY_offsetof(type, m) FIELD_OFFSET(type, m)
- */
+#define MY_offsetof(type, m) offsetof(type, m)
+
+/*
+#define MY_offsetof(type, m) FIELD_OFFSET(type, m)
+*/
#else
- #define MY_offsetof(type, m) ((size_t)&(((type *)0)->m))
+#define MY_offsetof(type, m) ((size_t)&(((type *)0)->m))
#endif
#endif
-
-
#ifndef MY_container_of
/*
@@ -339,38 +410,36 @@ struct ISzAlloc
GCC 4.8.1 : classes with non-public variable members"
*/
-#define MY_container_of(ptr, type, m) ((type *)((char *)(1 ? (ptr) : &((type *)0)->m) - MY_offsetof(type, m)))
-
+#define MY_container_of(ptr, type, m) ((type *)((char *)(1 ? (ptr) : &((type *)0)->m) - MY_offsetof(type, m)))
#endif
-#define CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m) ((type *)(ptr))
+#define CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m) ((type *)(ptr))
/*
#define CONTAINER_FROM_VTBL(ptr, type, m) CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m)
*/
-#define CONTAINER_FROM_VTBL(ptr, type, m) MY_container_of(ptr, type, m)
+#define CONTAINER_FROM_VTBL(ptr, type, m) MY_container_of(ptr, type, m)
+
+#define CONTAINER_FROM_VTBL_CLS(ptr, type, m) CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m)
-#define CONTAINER_FROM_VTBL_CLS(ptr, type, m) CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m)
/*
#define CONTAINER_FROM_VTBL_CLS(ptr, type, m) CONTAINER_FROM_VTBL(ptr, type, m)
*/
-
-
#ifdef _WIN32
-#define CHAR_PATH_SEPARATOR '\\'
-#define WCHAR_PATH_SEPARATOR L'\\'
-#define STRING_PATH_SEPARATOR "\\"
-#define WSTRING_PATH_SEPARATOR L"\\"
+#define CHAR_PATH_SEPARATOR '\\'
+#define WCHAR_PATH_SEPARATOR L'\\'
+#define STRING_PATH_SEPARATOR "\\"
+#define WSTRING_PATH_SEPARATOR L"\\"
#else
-#define CHAR_PATH_SEPARATOR '/'
-#define WCHAR_PATH_SEPARATOR L'/'
-#define STRING_PATH_SEPARATOR "/"
-#define WSTRING_PATH_SEPARATOR L"/"
+#define CHAR_PATH_SEPARATOR '/'
+#define WCHAR_PATH_SEPARATOR L'/'
+#define STRING_PATH_SEPARATOR "/"
+#define WSTRING_PATH_SEPARATOR L"/"
#endif
diff --git a/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/7zVersion.h b/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/7zVersion.h
index 0074c64be9..a45aa2008f 100644
--- a/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/7zVersion.h
+++ b/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/7zVersion.h
@@ -1,27 +1,27 @@
-#define MY_VER_MAJOR 19
-#define MY_VER_MINOR 00
-#define MY_VER_BUILD 0
-#define MY_VERSION_NUMBERS "19.00"
-#define MY_VERSION MY_VERSION_NUMBERS
+#define MY_VER_MAJOR 19
+#define MY_VER_MINOR 00
+#define MY_VER_BUILD 0
+#define MY_VERSION_NUMBERS "19.00"
+#define MY_VERSION MY_VERSION_NUMBERS
#ifdef MY_CPU_NAME
- #define MY_VERSION_CPU MY_VERSION " (" MY_CPU_NAME ")"
+#define MY_VERSION_CPU MY_VERSION " (" MY_CPU_NAME ")"
#else
- #define MY_VERSION_CPU MY_VERSION
+#define MY_VERSION_CPU MY_VERSION
#endif
-#define MY_DATE "2019-02-21"
+#define MY_DATE "2019-02-21"
#undef MY_COPYRIGHT
#undef MY_VERSION_COPYRIGHT_DATE
-#define MY_AUTHOR_NAME "Igor Pavlov"
-#define MY_COPYRIGHT_PD "Igor Pavlov : Public domain"
-#define MY_COPYRIGHT_CR "Copyright (c) 1999-2018 Igor Pavlov"
+#define MY_AUTHOR_NAME "Igor Pavlov"
+#define MY_COPYRIGHT_PD "Igor Pavlov : Public domain"
+#define MY_COPYRIGHT_CR "Copyright (c) 1999-2018 Igor Pavlov"
#ifdef USE_COPYRIGHT_CR
- #define MY_COPYRIGHT MY_COPYRIGHT_CR
+#define MY_COPYRIGHT MY_COPYRIGHT_CR
#else
- #define MY_COPYRIGHT MY_COPYRIGHT_PD
+#define MY_COPYRIGHT MY_COPYRIGHT_PD
#endif
-#define MY_COPYRIGHT_DATE MY_COPYRIGHT " : " MY_DATE
-#define MY_VERSION_COPYRIGHT_DATE MY_VERSION_CPU " : " MY_COPYRIGHT " : " MY_DATE
+#define MY_COPYRIGHT_DATE MY_COPYRIGHT " : " MY_DATE
+#define MY_VERSION_COPYRIGHT_DATE MY_VERSION_CPU " : " MY_COPYRIGHT " : " MY_DATE
diff --git a/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/Bra.h b/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/Bra.h
index ecf7b0c447..85085192fb 100644
--- a/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/Bra.h
+++ b/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/Bra.h
@@ -51,13 +51,55 @@ in CALL instructions to increase the compression ratio.
}
*/
-#define x86_Convert_Init(state) { state = 0; }
-SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding);
-SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
-SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
-SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
-SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
-SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
+#define x86_Convert_Init(state) { state = 0; }
+SizeT
+x86_Convert (
+ Byte *data,
+ SizeT size,
+ UInt32 ip,
+ UInt32 *state,
+ int encoding
+ );
+
+SizeT
+ARM_Convert (
+ Byte *data,
+ SizeT size,
+ UInt32 ip,
+ int encoding
+ );
+
+SizeT
+ARMT_Convert (
+ Byte *data,
+ SizeT size,
+ UInt32 ip,
+ int encoding
+ );
+
+SizeT
+PPC_Convert (
+ Byte *data,
+ SizeT size,
+ UInt32 ip,
+ int encoding
+ );
+
+SizeT
+SPARC_Convert (
+ Byte *data,
+ SizeT size,
+ UInt32 ip,
+ int encoding
+ );
+
+SizeT
+IA64_Convert (
+ Byte *data,
+ SizeT size,
+ UInt32 ip,
+ int encoding
+ );
EXTERN_C_END
diff --git a/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/Bra86.c b/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/Bra86.c
index a6463c63ba..ec5f574035 100644
--- a/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/Bra86.c
+++ b/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/Bra86.c
@@ -5,40 +5,49 @@
#include "Bra.h"
-#define Test86MSByte(b) ((((b) + 1) & 0xFE) == 0)
+#define Test86MSByte(b) ((((b) + 1) & 0xFE) == 0)
-SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding)
+SizeT
+x86_Convert (
+ Byte *data,
+ SizeT size,
+ UInt32 ip,
+ UInt32 *state,
+ int encoding
+ )
{
- SizeT pos = 0;
- UInt32 mask = *state & 7;
- if (size < 5)
+ SizeT pos = 0;
+ UInt32 mask = *state & 7;
+
+ if (size < 5) {
return 0;
+ }
+
size -= 4;
- ip += 5;
+ ip += 5;
- for (;;)
- {
- Byte *p = data + pos;
- const Byte *limit = data + size;
- for (; p < limit; p++)
- if ((*p & 0xFE) == 0xE8)
+ for ( ; ;) {
+ Byte *p = data + pos;
+ const Byte *limit = data + size;
+ for ( ; p < limit; p++) {
+ if ((*p & 0xFE) == 0xE8) {
break;
+ }
+ }
{
- SizeT d = (SizeT)(p - data - pos);
+ SizeT d = (SizeT)(p - data - pos);
pos = (SizeT)(p - data);
- if (p >= limit)
- {
+ if (p >= limit) {
*state = (d > 2 ? 0 : mask >> (unsigned)d);
return pos;
}
- if (d > 2)
+
+ if (d > 2) {
mask = 0;
- else
- {
+ } else {
mask >>= (unsigned)d;
- if (mask != 0 && (mask > 4 || mask == 3 || Test86MSByte(p[(size_t)(mask >> 1) + 1])))
- {
+ if ((mask != 0) && ((mask > 4) || (mask == 3) || Test86MSByte (p[(size_t)(mask >> 1) + 1]))) {
mask = (mask >> 1) | 4;
pos++;
continue;
@@ -46,35 +55,35 @@ SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding
}
}
- if (Test86MSByte(p[4]))
- {
- UInt32 v = ((UInt32)p[4] << 24) | ((UInt32)p[3] << 16) | ((UInt32)p[2] << 8) | ((UInt32)p[1]);
- UInt32 cur = ip + (UInt32)pos;
+ if (Test86MSByte (p[4])) {
+ UInt32 v = ((UInt32)p[4] << 24) | ((UInt32)p[3] << 16) | ((UInt32)p[2] << 8) | ((UInt32)p[1]);
+ UInt32 cur = ip + (UInt32)pos;
pos += 5;
- if (encoding)
+ if (encoding) {
v += cur;
- else
+ } else {
v -= cur;
- if (mask != 0)
- {
- unsigned sh = (mask & 6) << 2;
- if (Test86MSByte((Byte)(v >> sh)))
- {
+ }
+
+ if (mask != 0) {
+ unsigned sh = (mask & 6) << 2;
+ if (Test86MSByte ((Byte)(v >> sh))) {
v ^= (((UInt32)0x100 << sh) - 1);
- if (encoding)
+ if (encoding) {
v += cur;
- else
+ } else {
v -= cur;
+ }
}
+
mask = 0;
}
+
p[1] = (Byte)v;
p[2] = (Byte)(v >> 8);
p[3] = (Byte)(v >> 16);
p[4] = (Byte)(0 - ((v >> 24) & 1));
- }
- else
- {
+ } else {
mask = (mask >> 1) | 4;
pos++;
}
diff --git a/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/Compiler.h b/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/Compiler.h
index c788648cd2..e8968d3497 100644
--- a/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/Compiler.h
+++ b/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/Compiler.h
@@ -7,8 +7,8 @@
#ifdef _MSC_VER
#ifdef UNDER_CE
- #define RPC_NO_WINDOWS_H
- /* #pragma warning(disable : 4115) // '_RPC_ASYNC_STATE' : named type definition in parentheses */
+#define RPC_NO_WINDOWS_H
+/* #pragma warning(disable : 4115) // '_RPC_ASYNC_STATE' : named type definition in parentheses */
#pragma warning(disable : 4201) // nonstandard extension used : nameless struct/union
#pragma warning(disable : 4214) // nonstandard extension used : bit field types other than int
#endif
@@ -27,7 +27,7 @@
#endif
-#define UNUSED_VAR(x) (void)x;
+#define UNUSED_VAR(x) (void)x;
/* #define UNUSED_VAR(x) x=x; */
#endif
diff --git a/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/CpuArch.h b/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/CpuArch.h
index 5f74c1c0cb..671a77bdb7 100644
--- a/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/CpuArch.h
+++ b/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/CpuArch.h
@@ -16,269 +16,252 @@ If MY_CPU_LE and MY_CPU_BE are not defined, we don't know about ENDIANNESS of pl
MY_CPU_LE_UNALIGN means that CPU is LITTLE ENDIAN and CPU supports unaligned memory accesses.
*/
-#if defined(_M_X64) \
- || defined(_M_AMD64) \
- || defined(__x86_64__) \
- || defined(__AMD64__) \
- || defined(__amd64__)
- #define MY_CPU_AMD64
+#if defined (_M_X64) \
+ || defined (_M_AMD64) \
+ || defined (__x86_64__) \
+ || defined (__AMD64__) \
+ || defined (__amd64__)
+#define MY_CPU_AMD64
#ifdef __ILP32__
- #define MY_CPU_NAME "x32"
+#define MY_CPU_NAME "x32"
#else
- #define MY_CPU_NAME "x64"
+#define MY_CPU_NAME "x64"
#endif
- #define MY_CPU_64BIT
+#define MY_CPU_64BIT
#endif
-
-#if defined(_M_IX86) \
- || defined(__i386__)
- #define MY_CPU_X86
- #define MY_CPU_NAME "x86"
- #define MY_CPU_32BIT
+#if defined (_M_IX86) \
+ || defined (__i386__)
+#define MY_CPU_X86
+#define MY_CPU_NAME "x86"
+#define MY_CPU_32BIT
#endif
-
-#if defined(_M_ARM64) \
- || defined(__AARCH64EL__) \
- || defined(__AARCH64EB__) \
- || defined(__aarch64__)
- #define MY_CPU_ARM64
- #define MY_CPU_NAME "arm64"
- #define MY_CPU_64BIT
+#if defined (_M_ARM64) \
+ || defined (__AARCH64EL__) \
+ || defined (__AARCH64EB__) \
+ || defined (__aarch64__)
+#define MY_CPU_ARM64
+#define MY_CPU_NAME "arm64"
+#define MY_CPU_64BIT
#endif
-
-#if defined(_M_ARM) \
- || defined(_M_ARM_NT) \
- || defined(_M_ARMT) \
- || defined(__arm__) \
- || defined(__thumb__) \
- || defined(__ARMEL__) \
- || defined(__ARMEB__) \
- || defined(__THUMBEL__) \
- || defined(__THUMBEB__)
- #define MY_CPU_ARM
- #define MY_CPU_NAME "arm"
- #define MY_CPU_32BIT
+#if defined (_M_ARM) \
+ || defined (_M_ARM_NT) \
+ || defined (_M_ARMT) \
+ || defined (__arm__) \
+ || defined (__thumb__) \
+ || defined (__ARMEL__) \
+ || defined (__ARMEB__) \
+ || defined (__THUMBEL__) \
+ || defined (__THUMBEB__)
+#define MY_CPU_ARM
+#define MY_CPU_NAME "arm"
+#define MY_CPU_32BIT
#endif
-
-#if defined(_M_IA64) \
- || defined(__ia64__)
- #define MY_CPU_IA64
- #define MY_CPU_NAME "ia64"
- #define MY_CPU_64BIT
+#if defined (_M_IA64) \
+ || defined (__ia64__)
+#define MY_CPU_IA64
+#define MY_CPU_NAME "ia64"
+#define MY_CPU_64BIT
#endif
-
-#if defined(__mips64) \
- || defined(__mips64__) \
- || (defined(__mips) && (__mips == 64 || __mips == 4 || __mips == 3))
- #define MY_CPU_NAME "mips64"
- #define MY_CPU_64BIT
-#elif defined(__mips__)
- #define MY_CPU_NAME "mips"
- /* #define MY_CPU_32BIT */
+#if defined (__mips64) \
+ || defined (__mips64__) \
+ || (defined (__mips) && (__mips == 64 || __mips == 4 || __mips == 3))
+#define MY_CPU_NAME "mips64"
+#define MY_CPU_64BIT
+#elif defined (__mips__)
+#define MY_CPU_NAME "mips"
+/* #define MY_CPU_32BIT */
#endif
-
-#if defined(__ppc64__) \
- || defined(__powerpc64__)
+#if defined (__ppc64__) \
+ || defined (__powerpc64__)
#ifdef __ILP32__
- #define MY_CPU_NAME "ppc64-32"
+#define MY_CPU_NAME "ppc64-32"
#else
- #define MY_CPU_NAME "ppc64"
+#define MY_CPU_NAME "ppc64"
#endif
- #define MY_CPU_64BIT
-#elif defined(__ppc__) \
- || defined(__powerpc__)
- #define MY_CPU_NAME "ppc"
- #define MY_CPU_32BIT
+#define MY_CPU_64BIT
+#elif defined (__ppc__) \
+ || defined (__powerpc__)
+#define MY_CPU_NAME "ppc"
+#define MY_CPU_32BIT
#endif
-
-#if defined(__sparc64__)
- #define MY_CPU_NAME "sparc64"
- #define MY_CPU_64BIT
-#elif defined(__sparc__)
- #define MY_CPU_NAME "sparc"
- /* #define MY_CPU_32BIT */
+#if defined (__sparc64__)
+#define MY_CPU_NAME "sparc64"
+#define MY_CPU_64BIT
+#elif defined (__sparc__)
+#define MY_CPU_NAME "sparc"
+/* #define MY_CPU_32BIT */
#endif
-
-#if defined(MY_CPU_X86) || defined(MY_CPU_AMD64)
+#if defined (MY_CPU_X86) || defined (MY_CPU_AMD64)
#define MY_CPU_X86_OR_AMD64
#endif
-
#ifdef _WIN32
#ifdef MY_CPU_ARM
- #define MY_CPU_ARM_LE
+#define MY_CPU_ARM_LE
#endif
#ifdef MY_CPU_ARM64
- #define MY_CPU_ARM64_LE
+#define MY_CPU_ARM64_LE
#endif
#ifdef _M_IA64
- #define MY_CPU_IA64_LE
+#define MY_CPU_IA64_LE
#endif
#endif
-
-#if defined(MY_CPU_X86_OR_AMD64) \
- || defined(MY_CPU_ARM_LE) \
- || defined(MY_CPU_ARM64_LE) \
- || defined(MY_CPU_IA64_LE) \
- || defined(__LITTLE_ENDIAN__) \
- || defined(__ARMEL__) \
- || defined(__THUMBEL__) \
- || defined(__AARCH64EL__) \
- || defined(__MIPSEL__) \
- || defined(__MIPSEL) \
- || defined(_MIPSEL) \
- || defined(__BFIN__) \
- || (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))
- #define MY_CPU_LE
+#if defined (MY_CPU_X86_OR_AMD64) \
+ || defined (MY_CPU_ARM_LE) \
+ || defined (MY_CPU_ARM64_LE) \
+ || defined (MY_CPU_IA64_LE) \
+ || defined (__LITTLE_ENDIAN__) \
+ || defined (__ARMEL__) \
+ || defined (__THUMBEL__) \
+ || defined (__AARCH64EL__) \
+ || defined (__MIPSEL__) \
+ || defined (__MIPSEL) \
+ || defined (_MIPSEL) \
+ || defined (__BFIN__) \
+ || (defined (__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))
+#define MY_CPU_LE
#endif
-#if defined(__BIG_ENDIAN__) \
- || defined(__ARMEB__) \
- || defined(__THUMBEB__) \
- || defined(__AARCH64EB__) \
- || defined(__MIPSEB__) \
- || defined(__MIPSEB) \
- || defined(_MIPSEB) \
- || defined(__m68k__) \
- || defined(__s390__) \
- || defined(__s390x__) \
- || defined(__zarch__) \
- || (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))
- #define MY_CPU_BE
+#if defined (__BIG_ENDIAN__) \
+ || defined (__ARMEB__) \
+ || defined (__THUMBEB__) \
+ || defined (__AARCH64EB__) \
+ || defined (__MIPSEB__) \
+ || defined (__MIPSEB) \
+ || defined (_MIPSEB) \
+ || defined (__m68k__) \
+ || defined (__s390__) \
+ || defined (__s390x__) \
+ || defined (__zarch__) \
+ || (defined (__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))
+#define MY_CPU_BE
#endif
-
-#if defined(MY_CPU_LE) && defined(MY_CPU_BE)
+#if defined (MY_CPU_LE) && defined (MY_CPU_BE)
#error Stop_Compiling_Bad_Endian
#endif
-
-#if defined(MY_CPU_32BIT) && defined(MY_CPU_64BIT)
+#if defined (MY_CPU_32BIT) && defined (MY_CPU_64BIT)
#error Stop_Compiling_Bad_32_64_BIT
#endif
-
#ifndef MY_CPU_NAME
#ifdef MY_CPU_LE
- #define MY_CPU_NAME "LE"
- #elif defined(MY_CPU_BE)
- #define MY_CPU_NAME "BE"
+#define MY_CPU_NAME "LE"
+ #elif defined (MY_CPU_BE)
+#define MY_CPU_NAME "BE"
#else
- /*
- #define MY_CPU_NAME ""
- */
+
+/*
+#define MY_CPU_NAME ""
+*/
#endif
#endif
-
-
-
-
#ifdef MY_CPU_LE
- #if defined(MY_CPU_X86_OR_AMD64) \
- || defined(MY_CPU_ARM64) \
- || defined(__ARM_FEATURE_UNALIGNED)
- #define MY_CPU_LE_UNALIGN
+ #if defined (MY_CPU_X86_OR_AMD64) \
+ || defined (MY_CPU_ARM64) \
+ || defined (__ARM_FEATURE_UNALIGNED)
+#define MY_CPU_LE_UNALIGN
#endif
#endif
-
#ifdef MY_CPU_LE_UNALIGN
-#define GetUi16(p) (*(const UInt16 *)(const void *)(p))
-#define GetUi32(p) (*(const UInt32 *)(const void *)(p))
-#define GetUi64(p) (*(const UInt64 *)(const void *)(p))
+#define GetUi16(p) (*(const UInt16 *)(const void *)(p))
+#define GetUi32(p) (*(const UInt32 *)(const void *)(p))
+#define GetUi64(p) (*(const UInt64 *)(const void *)(p))
-#define SetUi16(p, v) { *(UInt16 *)(p) = (v); }
-#define SetUi32(p, v) { *(UInt32 *)(p) = (v); }
-#define SetUi64(p, v) { *(UInt64 *)(p) = (v); }
+#define SetUi16(p, v) { *(UInt16 *)(p) = (v); }
+#define SetUi32(p, v) { *(UInt32 *)(p) = (v); }
+#define SetUi64(p, v) { *(UInt64 *)(p) = (v); }
#else
-#define GetUi16(p) ( (UInt16) ( \
+#define GetUi16(p) ( (UInt16) (\
((const Byte *)(p))[0] | \
((UInt16)((const Byte *)(p))[1] << 8) ))
-#define GetUi32(p) ( \
+#define GetUi32(p) (\
((const Byte *)(p))[0] | \
((UInt32)((const Byte *)(p))[1] << 8) | \
((UInt32)((const Byte *)(p))[2] << 16) | \
((UInt32)((const Byte *)(p))[3] << 24))
-#define GetUi64(p) (GetUi32(p) | ((UInt64)GetUi32(((const Byte *)(p)) + 4) << 32))
+#define GetUi64(p) (GetUi32(p) | ((UInt64)GetUi32(((const Byte *)(p)) + 4) << 32))
-#define SetUi16(p, v) { Byte *_ppp_ = (Byte *)(p); UInt32 _vvv_ = (v); \
+#define SetUi16(p, v) { Byte *_ppp_ = (Byte *)(p); UInt32 _vvv_ = (v);\
_ppp_[0] = (Byte)_vvv_; \
_ppp_[1] = (Byte)(_vvv_ >> 8); }
-#define SetUi32(p, v) { Byte *_ppp_ = (Byte *)(p); UInt32 _vvv_ = (v); \
+#define SetUi32(p, v) { Byte *_ppp_ = (Byte *)(p); UInt32 _vvv_ = (v);\
_ppp_[0] = (Byte)_vvv_; \
_ppp_[1] = (Byte)(_vvv_ >> 8); \
_ppp_[2] = (Byte)(_vvv_ >> 16); \
_ppp_[3] = (Byte)(_vvv_ >> 24); }
-#define SetUi64(p, v) { Byte *_ppp2_ = (Byte *)(p); UInt64 _vvv2_ = (v); \
+#define SetUi64(p, v) { Byte *_ppp2_ = (Byte *)(p); UInt64 _vvv2_ = (v);\
SetUi32(_ppp2_ , (UInt32)_vvv2_); \
SetUi32(_ppp2_ + 4, (UInt32)(_vvv2_ >> 32)); }
#endif
#ifdef __has_builtin
- #define MY__has_builtin(x) __has_builtin(x)
+#define MY__has_builtin(x) __has_builtin(x)
#else
- #define MY__has_builtin(x) 0
+#define MY__has_builtin(x) 0
#endif
-#if defined(MY_CPU_LE_UNALIGN) && /* defined(_WIN64) && */ (_MSC_VER >= 1300)
+#if defined (MY_CPU_LE_UNALIGN) && /* defined(_WIN64) && */ (_MSC_VER >= 1300)
/* Note: we use bswap instruction, that is unsupported in 386 cpu */
-#include <stdlib.h>
+ #include <stdlib.h>
-#pragma intrinsic(_byteswap_ushort)
-#pragma intrinsic(_byteswap_ulong)
-#pragma intrinsic(_byteswap_uint64)
+ #pragma intrinsic(_byteswap_ushort)
+ #pragma intrinsic(_byteswap_ulong)
+ #pragma intrinsic(_byteswap_uint64)
/* #define GetBe16(p) _byteswap_ushort(*(const UInt16 *)(const Byte *)(p)) */
-#define GetBe32(p) _byteswap_ulong(*(const UInt32 *)(const Byte *)(p))
-#define GetBe64(p) _byteswap_uint64(*(const UInt64 *)(const Byte *)(p))
+#define GetBe32(p) _byteswap_ulong(*(const UInt32 *)(const Byte *)(p))
+#define GetBe64(p) _byteswap_uint64(*(const UInt64 *)(const Byte *)(p))
-#define SetBe32(p, v) (*(UInt32 *)(void *)(p)) = _byteswap_ulong(v)
+#define SetBe32(p, v) (*(UInt32 *)(void *)(p)) = _byteswap_ulong(v)
-#elif defined(MY_CPU_LE_UNALIGN) && ( \
- (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))) \
- || (defined(__clang__) && MY__has_builtin(__builtin_bswap16)) )
+#elif defined (MY_CPU_LE_UNALIGN) && ( \
+ (defined (__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))) \
+ || (defined (__clang__) && MY__has_builtin (__builtin_bswap16)))
/* #define GetBe16(p) __builtin_bswap16(*(const UInt16 *)(const Byte *)(p)) */
-#define GetBe32(p) __builtin_bswap32(*(const UInt32 *)(const Byte *)(p))
-#define GetBe64(p) __builtin_bswap64(*(const UInt64 *)(const Byte *)(p))
+#define GetBe32(p) __builtin_bswap32(*(const UInt32 *)(const Byte *)(p))
+#define GetBe64(p) __builtin_bswap64(*(const UInt64 *)(const Byte *)(p))
-#define SetBe32(p, v) (*(UInt32 *)(void *)(p)) = __builtin_bswap32(v)
+#define SetBe32(p, v) (*(UInt32 *)(void *)(p)) = __builtin_bswap32(v)
#else
-#define GetBe32(p) ( \
+#define GetBe32(p) (\
((UInt32)((const Byte *)(p))[0] << 24) | \
((UInt32)((const Byte *)(p))[1] << 16) | \
((UInt32)((const Byte *)(p))[2] << 8) | \
((const Byte *)(p))[3] )
-#define GetBe64(p) (((UInt64)GetBe32(p) << 32) | GetBe32(((const Byte *)(p)) + 4))
+#define GetBe64(p) (((UInt64)GetBe32(p) << 32) | GetBe32(((const Byte *)(p)) + 4))
-#define SetBe32(p, v) { Byte *_ppp_ = (Byte *)(p); UInt32 _vvv_ = (v); \
+#define SetBe32(p, v) { Byte *_ppp_ = (Byte *)(p); UInt32 _vvv_ = (v);\
_ppp_[0] = (Byte)(_vvv_ >> 24); \
_ppp_[1] = (Byte)(_vvv_ >> 16); \
_ppp_[2] = (Byte)(_vvv_ >> 8); \
@@ -286,48 +269,65 @@ MY_CPU_LE_UNALIGN means that CPU is LITTLE ENDIAN and CPU supports unaligned mem
#endif
-
#ifndef GetBe16
-#define GetBe16(p) ( (UInt16) ( \
+#define GetBe16(p) ( (UInt16) (\
((UInt16)((const Byte *)(p))[0] << 8) | \
((const Byte *)(p))[1] ))
#endif
-
-
#ifdef MY_CPU_X86_OR_AMD64
-typedef struct
-{
- UInt32 maxFunc;
- UInt32 vendor[3];
- UInt32 ver;
- UInt32 b;
- UInt32 c;
- UInt32 d;
+typedef struct {
+ UInt32 maxFunc;
+ UInt32 vendor[3];
+ UInt32 ver;
+ UInt32 b;
+ UInt32 c;
+ UInt32 d;
} Cx86cpuid;
-enum
-{
+enum {
CPU_FIRM_INTEL,
CPU_FIRM_AMD,
CPU_FIRM_VIA
};
-void MyCPUID(UInt32 function, UInt32 *a, UInt32 *b, UInt32 *c, UInt32 *d);
-
-BoolInt x86cpuid_CheckAndRead(Cx86cpuid *p);
-int x86cpuid_GetFirm(const Cx86cpuid *p);
-
-#define x86cpuid_GetFamily(ver) (((ver >> 16) & 0xFF0) | ((ver >> 8) & 0xF))
-#define x86cpuid_GetModel(ver) (((ver >> 12) & 0xF0) | ((ver >> 4) & 0xF))
-#define x86cpuid_GetStepping(ver) (ver & 0xF)
-
-BoolInt CPU_Is_InOrder();
-BoolInt CPU_Is_Aes_Supported();
-BoolInt CPU_IsSupported_PageGB();
+void
+MyCPUID (
+ UInt32 function,
+ UInt32 *a,
+ UInt32 *b,
+ UInt32 *c,
+ UInt32 *d
+ );
+
+BoolInt
+x86cpuid_CheckAndRead (
+ Cx86cpuid *p
+ );
+
+int
+x86cpuid_GetFirm (
+ const Cx86cpuid *p
+ );
+
+#define x86cpuid_GetFamily(ver) (((ver >> 16) & 0xFF0) | ((ver >> 8) & 0xF))
+#define x86cpuid_GetModel(ver) (((ver >> 12) & 0xF0) | ((ver >> 4) & 0xF))
+#define x86cpuid_GetStepping(ver) (ver & 0xF)
+
+BoolInt
+CPU_Is_InOrder (
+ );
+
+BoolInt
+CPU_Is_Aes_Supported (
+ );
+
+BoolInt
+CPU_IsSupported_PageGB (
+ );
#endif
diff --git a/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzFind.c b/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzFind.c
index 670a9fab12..2102409a4b 100644
--- a/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzFind.c
+++ b/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzFind.c
@@ -4,393 +4,547 @@
#include "Precomp.h"
#ifndef EFIAPI
-#include <string.h>
+ #include <string.h>
#endif
#include "LzFind.h"
#include "LzHash.h"
-#define kEmptyHashValue 0
-#define kMaxValForNormalize ((UInt32)0xFFFFFFFF)
-#define kNormalizeStepMin (1 << 10) /* it must be power of 2 */
-#define kNormalizeMask (~(UInt32)(kNormalizeStepMin - 1))
-#define kMaxHistorySize ((UInt32)7 << 29)
+#define kEmptyHashValue 0
+#define kMaxValForNormalize ((UInt32)0xFFFFFFFF)
+#define kNormalizeStepMin (1 << 10)/* it must be power of 2 */
+#define kNormalizeMask (~(UInt32)(kNormalizeStepMin - 1))
+#define kMaxHistorySize ((UInt32)7 << 29)
-#define kStartMaxLen 3
+#define kStartMaxLen 3
-static void LzInWindow_Free(CMatchFinder *p, ISzAllocPtr alloc)
+static void
+LzInWindow_Free (
+ CMatchFinder *p,
+ ISzAllocPtr alloc
+ )
{
- if (!p->directInput)
- {
- ISzAlloc_Free(alloc, p->bufferBase);
+ if (!p->directInput) {
+ ISzAlloc_Free (alloc, p->bufferBase);
p->bufferBase = NULL;
}
}
/* keepSizeBefore + keepSizeAfter + keepSizeReserv must be < 4G) */
-static int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAllocPtr alloc)
+static int
+LzInWindow_Create (
+ CMatchFinder *p,
+ UInt32 keepSizeReserv,
+ ISzAllocPtr alloc
+ )
{
- UInt32 blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv;
- if (p->directInput)
- {
+ UInt32 blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv;
+
+ if (p->directInput) {
p->blockSize = blockSize;
return 1;
}
- if (!p->bufferBase || p->blockSize != blockSize)
- {
- LzInWindow_Free(p, alloc);
- p->blockSize = blockSize;
- p->bufferBase = (Byte *)ISzAlloc_Alloc(alloc, (size_t)blockSize);
+
+ if (!p->bufferBase || (p->blockSize != blockSize)) {
+ LzInWindow_Free (p, alloc);
+ p->blockSize = blockSize;
+ p->bufferBase = (Byte *)ISzAlloc_Alloc (alloc, (size_t)blockSize);
}
+
return (p->bufferBase != NULL);
}
-Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; }
+Byte *
+MatchFinder_GetPointerToCurrentPos (
+ CMatchFinder *p
+ )
+{
+ return p->buffer;
+}
-UInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }
+UInt32
+MatchFinder_GetNumAvailableBytes (
+ CMatchFinder *p
+ )
+{
+ return p->streamPos - p->pos;
+}
-void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue)
+void
+MatchFinder_ReduceOffsets (
+ CMatchFinder *p,
+ UInt32 subValue
+ )
{
- p->posLimit -= subValue;
- p->pos -= subValue;
+ p->posLimit -= subValue;
+ p->pos -= subValue;
p->streamPos -= subValue;
}
-static void MatchFinder_ReadBlock(CMatchFinder *p)
+static void
+MatchFinder_ReadBlock (
+ CMatchFinder *p
+ )
{
- if (p->streamEndWasReached || p->result != SZ_OK)
+ if (p->streamEndWasReached || (p->result != SZ_OK)) {
return;
+ }
/* We use (p->streamPos - p->pos) value. (p->streamPos < p->pos) is allowed. */
- if (p->directInput)
- {
- UInt32 curSize = 0xFFFFFFFF - (p->streamPos - p->pos);
- if (curSize > p->directInputRem)
+ if (p->directInput) {
+ UInt32 curSize = 0xFFFFFFFF - (p->streamPos - p->pos);
+ if (curSize > p->directInputRem) {
curSize = (UInt32)p->directInputRem;
+ }
+
p->directInputRem -= curSize;
- p->streamPos += curSize;
- if (p->directInputRem == 0)
+ p->streamPos += curSize;
+ if (p->directInputRem == 0) {
p->streamEndWasReached = 1;
+ }
+
return;
}
- for (;;)
- {
- Byte *dest = p->buffer + (p->streamPos - p->pos);
- size_t size = (p->bufferBase + p->blockSize - dest);
- if (size == 0)
+ for ( ; ;) {
+ Byte *dest = p->buffer + (p->streamPos - p->pos);
+ size_t size = (p->bufferBase + p->blockSize - dest);
+ if (size == 0) {
return;
+ }
- p->result = ISeqInStream_Read(p->stream, dest, &size);
- if (p->result != SZ_OK)
+ p->result = ISeqInStream_Read (p->stream, dest, &size);
+ if (p->result != SZ_OK) {
return;
- if (size == 0)
- {
+ }
+
+ if (size == 0) {
p->streamEndWasReached = 1;
return;
}
+
p->streamPos += (UInt32)size;
- if (p->streamPos - p->pos > p->keepSizeAfter)
+ if (p->streamPos - p->pos > p->keepSizeAfter) {
return;
+ }
}
}
-void MatchFinder_MoveBlock(CMatchFinder *p)
+void
+MatchFinder_MoveBlock (
+ CMatchFinder *p
+ )
{
- memmove(p->bufferBase,
- p->buffer - p->keepSizeBefore,
- (size_t)(p->streamPos - p->pos) + p->keepSizeBefore);
+ memmove (
+ p->bufferBase,
+ p->buffer - p->keepSizeBefore,
+ (size_t)(p->streamPos - p->pos) + p->keepSizeBefore
+ );
p->buffer = p->bufferBase + p->keepSizeBefore;
}
-int MatchFinder_NeedMove(CMatchFinder *p)
+int
+MatchFinder_NeedMove (
+ CMatchFinder *p
+ )
{
- if (p->directInput)
+ if (p->directInput) {
return 0;
+ }
+
/* if (p->streamEndWasReached) return 0; */
return ((size_t)(p->bufferBase + p->blockSize - p->buffer) <= p->keepSizeAfter);
}
-void MatchFinder_ReadIfRequired(CMatchFinder *p)
+void
+MatchFinder_ReadIfRequired (
+ CMatchFinder *p
+ )
{
- if (p->streamEndWasReached)
+ if (p->streamEndWasReached) {
return;
- if (p->keepSizeAfter >= p->streamPos - p->pos)
- MatchFinder_ReadBlock(p);
+ }
+
+ if (p->keepSizeAfter >= p->streamPos - p->pos) {
+ MatchFinder_ReadBlock (p);
+ }
}
-static void MatchFinder_CheckAndMoveAndRead(CMatchFinder *p)
+static void
+MatchFinder_CheckAndMoveAndRead (
+ CMatchFinder *p
+ )
{
- if (MatchFinder_NeedMove(p))
- MatchFinder_MoveBlock(p);
- MatchFinder_ReadBlock(p);
+ if (MatchFinder_NeedMove (p)) {
+ MatchFinder_MoveBlock (p);
+ }
+
+ MatchFinder_ReadBlock (p);
}
-static void MatchFinder_SetDefaultSettings(CMatchFinder *p)
+static void
+MatchFinder_SetDefaultSettings (
+ CMatchFinder *p
+ )
{
- p->cutValue = 32;
- p->btMode = 1;
+ p->cutValue = 32;
+ p->btMode = 1;
p->numHashBytes = 4;
- p->bigHash = 0;
+ p->bigHash = 0;
}
-#define kCrcPoly 0xEDB88320
+#define kCrcPoly 0xEDB88320
-void MatchFinder_Construct(CMatchFinder *p)
+void
+MatchFinder_Construct (
+ CMatchFinder *p
+ )
{
- unsigned i;
- p->bufferBase = NULL;
- p->directInput = 0;
- p->hash = NULL;
+ unsigned i;
+
+ p->bufferBase = NULL;
+ p->directInput = 0;
+ p->hash = NULL;
p->expectedDataSize = (UInt64)(Int64)-1;
- MatchFinder_SetDefaultSettings(p);
+ MatchFinder_SetDefaultSettings (p);
- for (i = 0; i < 256; i++)
- {
- UInt32 r = (UInt32)i;
- unsigned j;
- for (j = 0; j < 8; j++)
+ for (i = 0; i < 256; i++) {
+ UInt32 r = (UInt32)i;
+ unsigned j;
+ for (j = 0; j < 8; j++) {
r = (r >> 1) ^ (kCrcPoly & ((UInt32)0 - (r & 1)));
+ }
+
p->crc[i] = r;
}
}
-static void MatchFinder_FreeThisClassMemory(CMatchFinder *p, ISzAllocPtr alloc)
+static void
+MatchFinder_FreeThisClassMemory (
+ CMatchFinder *p,
+ ISzAllocPtr alloc
+ )
{
- ISzAlloc_Free(alloc, p->hash);
+ ISzAlloc_Free (alloc, p->hash);
p->hash = NULL;
}
-void MatchFinder_Free(CMatchFinder *p, ISzAllocPtr alloc)
+void
+MatchFinder_Free (
+ CMatchFinder *p,
+ ISzAllocPtr alloc
+ )
{
- MatchFinder_FreeThisClassMemory(p, alloc);
- LzInWindow_Free(p, alloc);
+ MatchFinder_FreeThisClassMemory (p, alloc);
+ LzInWindow_Free (p, alloc);
}
-static CLzRef* AllocRefs(size_t num, ISzAllocPtr alloc)
+static CLzRef *
+AllocRefs (
+ size_t num,
+ ISzAllocPtr alloc
+ )
{
- size_t sizeInBytes = (size_t)num * sizeof(CLzRef);
- if (sizeInBytes / sizeof(CLzRef) != num)
+ size_t sizeInBytes = (size_t)num * sizeof (CLzRef);
+
+ if (sizeInBytes / sizeof (CLzRef) != num) {
return NULL;
- return (CLzRef *)ISzAlloc_Alloc(alloc, sizeInBytes);
+ }
+
+ return (CLzRef *)ISzAlloc_Alloc (alloc, sizeInBytes);
}
-int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
- UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,
- ISzAllocPtr alloc)
+int
+MatchFinder_Create (
+ CMatchFinder *p,
+ UInt32 historySize,
+ UInt32 keepAddBufferBefore,
+ UInt32 matchMaxLen,
+ UInt32 keepAddBufferAfter,
+ ISzAllocPtr alloc
+ )
{
- UInt32 sizeReserv;
+ UInt32 sizeReserv;
- if (historySize > kMaxHistorySize)
- {
- MatchFinder_Free(p, alloc);
+ if (historySize > kMaxHistorySize) {
+ MatchFinder_Free (p, alloc);
return 0;
}
sizeReserv = historySize >> 1;
- if (historySize >= ((UInt32)3 << 30)) sizeReserv = historySize >> 3;
- else if (historySize >= ((UInt32)2 << 30)) sizeReserv = historySize >> 2;
+ if (historySize >= ((UInt32)3 << 30)) {
+ sizeReserv = historySize >> 3;
+ } else if (historySize >= ((UInt32)2 << 30)) {
+ sizeReserv = historySize >> 2;
+ }
sizeReserv += (keepAddBufferBefore + matchMaxLen + keepAddBufferAfter) / 2 + (1 << 19);
p->keepSizeBefore = historySize + keepAddBufferBefore + 1;
- p->keepSizeAfter = matchMaxLen + keepAddBufferAfter;
+ p->keepSizeAfter = matchMaxLen + keepAddBufferAfter;
/* we need one additional byte, since we use MoveBlock after pos++ and before dictionary using */
- if (LzInWindow_Create(p, sizeReserv, alloc))
- {
- UInt32 newCyclicBufferSize = historySize + 1;
- UInt32 hs;
+ if (LzInWindow_Create (p, sizeReserv, alloc)) {
+ UInt32 newCyclicBufferSize = historySize + 1;
+ UInt32 hs;
p->matchMaxLen = matchMaxLen;
{
p->fixedHashSize = 0;
- if (p->numHashBytes == 2)
+ if (p->numHashBytes == 2) {
hs = (1 << 16) - 1;
- else
- {
+ } else {
hs = historySize;
- if (hs > p->expectedDataSize)
+ if (hs > p->expectedDataSize) {
hs = (UInt32)p->expectedDataSize;
- if (hs != 0)
+ }
+
+ if (hs != 0) {
hs--;
- hs |= (hs >> 1);
- hs |= (hs >> 2);
- hs |= (hs >> 4);
- hs |= (hs >> 8);
+ }
+
+ hs |= (hs >> 1);
+ hs |= (hs >> 2);
+ hs |= (hs >> 4);
+ hs |= (hs >> 8);
hs >>= 1;
- hs |= 0xFFFF; /* don't change it! It's required for Deflate */
- if (hs > (1 << 24))
- {
- if (p->numHashBytes == 3)
+ hs |= 0xFFFF; /* don't change it! It's required for Deflate */
+ if (hs > (1 << 24)) {
+ if (p->numHashBytes == 3) {
hs = (1 << 24) - 1;
- else
+ } else {
hs >>= 1;
+ }
+
/* if (bigHash) mode, GetHeads4b() in LzFindMt.c needs (hs >= ((1 << 24) - 1))) */
}
}
+
p->hashMask = hs;
hs++;
- if (p->numHashBytes > 2) p->fixedHashSize += kHash2Size;
- if (p->numHashBytes > 3) p->fixedHashSize += kHash3Size;
- if (p->numHashBytes > 4) p->fixedHashSize += kHash4Size;
+ if (p->numHashBytes > 2) {
+ p->fixedHashSize += kHash2Size;
+ }
+
+ if (p->numHashBytes > 3) {
+ p->fixedHashSize += kHash3Size;
+ }
+
+ if (p->numHashBytes > 4) {
+ p->fixedHashSize += kHash4Size;
+ }
+
hs += p->fixedHashSize;
}
{
- size_t newSize;
- size_t numSons;
- p->historySize = historySize;
- p->hashSizeSum = hs;
+ size_t newSize;
+ size_t numSons;
+ p->historySize = historySize;
+ p->hashSizeSum = hs;
p->cyclicBufferSize = newCyclicBufferSize;
numSons = newCyclicBufferSize;
- if (p->btMode)
+ if (p->btMode) {
numSons <<= 1;
+ }
+
newSize = hs + numSons;
- if (p->hash && p->numRefs == newSize)
+ if (p->hash && (p->numRefs == newSize)) {
return 1;
+ }
- MatchFinder_FreeThisClassMemory(p, alloc);
+ MatchFinder_FreeThisClassMemory (p, alloc);
p->numRefs = newSize;
- p->hash = AllocRefs(newSize, alloc);
+ p->hash = AllocRefs (newSize, alloc);
- if (p->hash)
- {
+ if (p->hash) {
p->son = p->hash + p->hashSizeSum;
return 1;
}
}
}
- MatchFinder_Free(p, alloc);
+ MatchFinder_Free (p, alloc);
return 0;
}
-static void MatchFinder_SetLimits(CMatchFinder *p)
+static void
+MatchFinder_SetLimits (
+ CMatchFinder *p
+ )
{
- UInt32 limit = kMaxValForNormalize - p->pos;
- UInt32 limit2 = p->cyclicBufferSize - p->cyclicBufferPos;
+ UInt32 limit = kMaxValForNormalize - p->pos;
+ UInt32 limit2 = p->cyclicBufferSize - p->cyclicBufferPos;
- if (limit2 < limit)
+ if (limit2 < limit) {
limit = limit2;
+ }
+
limit2 = p->streamPos - p->pos;
- if (limit2 <= p->keepSizeAfter)
- {
- if (limit2 > 0)
+ if (limit2 <= p->keepSizeAfter) {
+ if (limit2 > 0) {
limit2 = 1;
- }
- else
+ }
+ } else {
limit2 -= p->keepSizeAfter;
+ }
- if (limit2 < limit)
+ if (limit2 < limit) {
limit = limit2;
+ }
{
- UInt32 lenLimit = p->streamPos - p->pos;
- if (lenLimit > p->matchMaxLen)
+ UInt32 lenLimit = p->streamPos - p->pos;
+ if (lenLimit > p->matchMaxLen) {
lenLimit = p->matchMaxLen;
+ }
+
p->lenLimit = lenLimit;
}
p->posLimit = p->pos + limit;
}
-
-void MatchFinder_Init_LowHash(CMatchFinder *p)
+void
+MatchFinder_Init_LowHash (
+ CMatchFinder *p
+ )
{
- size_t i;
- CLzRef *items = p->hash;
- size_t numItems = p->fixedHashSize;
- for (i = 0; i < numItems; i++)
+ size_t i;
+ CLzRef *items = p->hash;
+ size_t numItems = p->fixedHashSize;
+
+ for (i = 0; i < numItems; i++) {
items[i] = kEmptyHashValue;
+ }
}
-
-void MatchFinder_Init_HighHash(CMatchFinder *p)
+void
+MatchFinder_Init_HighHash (
+ CMatchFinder *p
+ )
{
- size_t i;
- CLzRef *items = p->hash + p->fixedHashSize;
- size_t numItems = (size_t)p->hashMask + 1;
- for (i = 0; i < numItems; i++)
+ size_t i;
+ CLzRef *items = p->hash + p->fixedHashSize;
+ size_t numItems = (size_t)p->hashMask + 1;
+
+ for (i = 0; i < numItems; i++) {
items[i] = kEmptyHashValue;
+ }
}
-
-void MatchFinder_Init_3(CMatchFinder *p, int readData)
+void
+MatchFinder_Init_3 (
+ CMatchFinder *p,
+ int readData
+ )
{
- p->cyclicBufferPos = 0;
- p->buffer = p->bufferBase;
- p->pos =
- p->streamPos = p->cyclicBufferSize;
- p->result = SZ_OK;
+ p->cyclicBufferPos = 0;
+ p->buffer = p->bufferBase;
+ p->pos =
+ p->streamPos = p->cyclicBufferSize;
+ p->result = SZ_OK;
p->streamEndWasReached = 0;
- if (readData)
- MatchFinder_ReadBlock(p);
+ if (readData) {
+ MatchFinder_ReadBlock (p);
+ }
- MatchFinder_SetLimits(p);
+ MatchFinder_SetLimits (p);
}
-
-void MatchFinder_Init(CMatchFinder *p)
+void
+MatchFinder_Init (
+ CMatchFinder *p
+ )
{
- MatchFinder_Init_HighHash(p);
- MatchFinder_Init_LowHash(p);
- MatchFinder_Init_3(p, True);
+ MatchFinder_Init_HighHash (p);
+ MatchFinder_Init_LowHash (p);
+ MatchFinder_Init_3 (p, True);
}
-
-static UInt32 MatchFinder_GetSubValue(CMatchFinder *p)
+static UInt32
+MatchFinder_GetSubValue (
+ CMatchFinder *p
+ )
{
return (p->pos - p->historySize - 1) & kNormalizeMask;
}
-void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, size_t numItems)
+void
+MatchFinder_Normalize3 (
+ UInt32 subValue,
+ CLzRef *items,
+ size_t numItems
+ )
{
- size_t i;
- for (i = 0; i < numItems; i++)
- {
- UInt32 value = items[i];
- if (value <= subValue)
+ size_t i;
+
+ for (i = 0; i < numItems; i++) {
+ UInt32 value = items[i];
+ if (value <= subValue) {
value = kEmptyHashValue;
- else
+ } else {
value -= subValue;
+ }
+
items[i] = value;
}
}
-static void MatchFinder_Normalize(CMatchFinder *p)
+static void
+MatchFinder_Normalize (
+ CMatchFinder *p
+ )
{
- UInt32 subValue = MatchFinder_GetSubValue(p);
- MatchFinder_Normalize3(subValue, p->hash, p->numRefs);
- MatchFinder_ReduceOffsets(p, subValue);
-}
+ UInt32 subValue = MatchFinder_GetSubValue (p);
+ MatchFinder_Normalize3 (subValue, p->hash, p->numRefs);
+ MatchFinder_ReduceOffsets (p, subValue);
+}
MY_NO_INLINE
-static void MatchFinder_CheckLimits(CMatchFinder *p)
+static void
+MatchFinder_CheckLimits (
+ CMatchFinder *p
+ )
{
- if (p->pos == kMaxValForNormalize)
- MatchFinder_Normalize(p);
- if (!p->streamEndWasReached && p->keepSizeAfter == p->streamPos - p->pos)
- MatchFinder_CheckAndMoveAndRead(p);
- if (p->cyclicBufferPos == p->cyclicBufferSize)
+ if (p->pos == kMaxValForNormalize) {
+ MatchFinder_Normalize (p);
+ }
+
+ if (!p->streamEndWasReached && (p->keepSizeAfter == p->streamPos - p->pos)) {
+ MatchFinder_CheckAndMoveAndRead (p);
+ }
+
+ if (p->cyclicBufferPos == p->cyclicBufferSize) {
p->cyclicBufferPos = 0;
- MatchFinder_SetLimits(p);
-}
+ }
+ MatchFinder_SetLimits (p);
+}
/*
(lenLimit > maxLen)
*/
MY_FORCE_INLINE
-static UInt32 * Hc_GetMatchesSpec(unsigned lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
- UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
- UInt32 *distances, unsigned maxLen)
+static UInt32 *
+Hc_GetMatchesSpec (
+ unsigned lenLimit,
+ UInt32 curMatch,
+ UInt32 pos,
+ const Byte *cur,
+ CLzRef *son,
+ UInt32 _cyclicBufferPos,
+ UInt32 _cyclicBufferSize,
+ UInt32 cutValue,
+ UInt32 *distances,
+ unsigned maxLen
+ )
{
/*
son[_cyclicBufferPos] = curMatch;
@@ -421,151 +575,165 @@ static UInt32 * Hc_GetMatchesSpec(unsigned lenLimit, UInt32 curMatch, UInt32 pos
}
*/
- const Byte *lim = cur + lenLimit;
+ const Byte *lim = cur + lenLimit;
+
son[_cyclicBufferPos] = curMatch;
- do
- {
- UInt32 delta = pos - curMatch;
- if (delta >= _cyclicBufferSize)
+ do {
+ UInt32 delta = pos - curMatch;
+ if (delta >= _cyclicBufferSize) {
break;
+ }
+
{
- ptrdiff_t diff;
+ ptrdiff_t diff;
curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)];
- diff = (ptrdiff_t)0 - delta;
- if (cur[maxLen] == cur[maxLen + diff])
- {
- const Byte *c = cur;
- while (*c == c[diff])
- {
- if (++c == lim)
- {
+ diff = (ptrdiff_t)0 - delta;
+ if (cur[maxLen] == cur[maxLen + diff]) {
+ const Byte *c = cur;
+ while (*c == c[diff]) {
+ if (++c == lim) {
distances[0] = (UInt32)(lim - cur);
distances[1] = delta - 1;
return distances + 2;
}
}
+
{
- unsigned len = (unsigned)(c - cur);
- if (maxLen < len)
- {
- maxLen = len;
+ unsigned len = (unsigned)(c - cur);
+ if (maxLen < len) {
+ maxLen = len;
distances[0] = (UInt32)len;
distances[1] = delta - 1;
- distances += 2;
+ distances += 2;
}
}
}
}
- }
- while (--cutValue);
+ } while (--cutValue);
return distances;
}
-
MY_FORCE_INLINE
-UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
- UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
- UInt32 *distances, UInt32 maxLen)
+UInt32 *
+GetMatchesSpec1 (
+ UInt32 lenLimit,
+ UInt32 curMatch,
+ UInt32 pos,
+ const Byte *cur,
+ CLzRef *son,
+ UInt32 _cyclicBufferPos,
+ UInt32 _cyclicBufferSize,
+ UInt32 cutValue,
+ UInt32 *distances,
+ UInt32 maxLen
+ )
{
- CLzRef *ptr0 = son + ((size_t)_cyclicBufferPos << 1) + 1;
- CLzRef *ptr1 = son + ((size_t)_cyclicBufferPos << 1);
- unsigned len0 = 0, len1 = 0;
- for (;;)
- {
- UInt32 delta = pos - curMatch;
- if (cutValue-- == 0 || delta >= _cyclicBufferSize)
- {
+ CLzRef *ptr0 = son + ((size_t)_cyclicBufferPos << 1) + 1;
+ CLzRef *ptr1 = son + ((size_t)_cyclicBufferPos << 1);
+ unsigned len0 = 0, len1 = 0;
+
+ for ( ; ;) {
+ UInt32 delta = pos - curMatch;
+ if ((cutValue-- == 0) || (delta >= _cyclicBufferSize)) {
*ptr0 = *ptr1 = kEmptyHashValue;
return distances;
}
+
{
- CLzRef *pair = son + ((size_t)(_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);
- const Byte *pb = cur - delta;
- unsigned len = (len0 < len1 ? len0 : len1);
- UInt32 pair0 = pair[0];
- if (pb[len] == cur[len])
- {
- if (++len != lenLimit && pb[len] == cur[len])
- while (++len != lenLimit)
- if (pb[len] != cur[len])
+ CLzRef *pair = son + ((size_t)(_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);
+ const Byte *pb = cur - delta;
+ unsigned len = (len0 < len1 ? len0 : len1);
+ UInt32 pair0 = pair[0];
+ if (pb[len] == cur[len]) {
+ if ((++len != lenLimit) && (pb[len] == cur[len])) {
+ while (++len != lenLimit) {
+ if (pb[len] != cur[len]) {
break;
- if (maxLen < len)
- {
- maxLen = (UInt32)len;
+ }
+ }
+ }
+
+ if (maxLen < len) {
+ maxLen = (UInt32)len;
*distances++ = (UInt32)len;
*distances++ = delta - 1;
- if (len == lenLimit)
- {
+ if (len == lenLimit) {
*ptr1 = pair0;
*ptr0 = pair[1];
return distances;
}
}
}
- if (pb[len] < cur[len])
- {
- *ptr1 = curMatch;
- ptr1 = pair + 1;
+
+ if (pb[len] < cur[len]) {
+ *ptr1 = curMatch;
+ ptr1 = pair + 1;
curMatch = *ptr1;
- len1 = len;
- }
- else
- {
- *ptr0 = curMatch;
- ptr0 = pair;
+ len1 = len;
+ } else {
+ *ptr0 = curMatch;
+ ptr0 = pair;
curMatch = *ptr0;
- len0 = len;
+ len0 = len;
}
}
}
}
-static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
- UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue)
+static void
+SkipMatchesSpec (
+ UInt32 lenLimit,
+ UInt32 curMatch,
+ UInt32 pos,
+ const Byte *cur,
+ CLzRef *son,
+ UInt32 _cyclicBufferPos,
+ UInt32 _cyclicBufferSize,
+ UInt32 cutValue
+ )
{
- CLzRef *ptr0 = son + ((size_t)_cyclicBufferPos << 1) + 1;
- CLzRef *ptr1 = son + ((size_t)_cyclicBufferPos << 1);
- unsigned len0 = 0, len1 = 0;
- for (;;)
- {
- UInt32 delta = pos - curMatch;
- if (cutValue-- == 0 || delta >= _cyclicBufferSize)
- {
+ CLzRef *ptr0 = son + ((size_t)_cyclicBufferPos << 1) + 1;
+ CLzRef *ptr1 = son + ((size_t)_cyclicBufferPos << 1);
+ unsigned len0 = 0, len1 = 0;
+
+ for ( ; ;) {
+ UInt32 delta = pos - curMatch;
+ if ((cutValue-- == 0) || (delta >= _cyclicBufferSize)) {
*ptr0 = *ptr1 = kEmptyHashValue;
return;
}
+
{
- CLzRef *pair = son + ((size_t)(_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);
- const Byte *pb = cur - delta;
- unsigned len = (len0 < len1 ? len0 : len1);
- if (pb[len] == cur[len])
- {
- while (++len != lenLimit)
- if (pb[len] != cur[len])
+ CLzRef *pair = son + ((size_t)(_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);
+ const Byte *pb = cur - delta;
+ unsigned len = (len0 < len1 ? len0 : len1);
+ if (pb[len] == cur[len]) {
+ while (++len != lenLimit) {
+ if (pb[len] != cur[len]) {
break;
+ }
+ }
+
{
- if (len == lenLimit)
- {
+ if (len == lenLimit) {
*ptr1 = pair[0];
*ptr0 = pair[1];
return;
}
}
}
- if (pb[len] < cur[len])
- {
- *ptr1 = curMatch;
- ptr1 = pair + 1;
+
+ if (pb[len] < cur[len]) {
+ *ptr1 = curMatch;
+ ptr1 = pair + 1;
curMatch = *ptr1;
- len1 = len;
- }
- else
- {
- *ptr0 = curMatch;
- ptr0 = pair;
+ len1 = len;
+ } else {
+ *ptr0 = curMatch;
+ ptr0 = pair;
curMatch = *ptr0;
- len0 = len;
+ len0 = len;
}
}
}
@@ -576,19 +744,25 @@ static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const
p->buffer++; \
if (++p->pos == p->posLimit) MatchFinder_CheckLimits(p);
-#define MOVE_POS_RET MOVE_POS return (UInt32)offset;
+#define MOVE_POS_RET MOVE_POS return (UInt32)offset;
-static void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }
+static void
+MatchFinder_MovePos (
+ CMatchFinder *p
+ )
+{
+ MOVE_POS;
+}
#define GET_MATCHES_HEADER2(minLen, ret_op) \
unsigned lenLimit; UInt32 hv; const Byte *cur; UInt32 curMatch; \
lenLimit = (unsigned)p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \
cur = p->buffer;
-#define GET_MATCHES_HEADER(minLen) GET_MATCHES_HEADER2(minLen, return 0)
-#define SKIP_HEADER(minLen) GET_MATCHES_HEADER2(minLen, continue)
+#define GET_MATCHES_HEADER(minLen) GET_MATCHES_HEADER2(minLen, return 0)
+#define SKIP_HEADER(minLen) GET_MATCHES_HEADER2(minLen, continue)
-#define MF_PARAMS(p) p->pos, p->buffer, p->son, p->cyclicBufferPos, p->cyclicBufferSize, p->cutValue
+#define MF_PARAMS(p) p->pos, p->buffer, p->son, p->cyclicBufferPos, p->cyclicBufferSize, p->cutValue
#define GET_MATCHES_FOOTER(offset, maxLen) \
offset = (unsigned)(GetMatchesSpec1((UInt32)lenLimit, curMatch, MF_PARAMS(p), \
@@ -597,128 +771,143 @@ static void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }
#define SKIP_FOOTER \
SkipMatchesSpec((UInt32)lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS;
-#define UPDATE_maxLen { \
+#define UPDATE_maxLen {\
ptrdiff_t diff = (ptrdiff_t)0 - d2; \
const Byte *c = cur + maxLen; \
const Byte *lim = cur + lenLimit; \
for (; c != lim; c++) if (*(c + diff) != *c) break; \
maxLen = (unsigned)(c - cur); }
-static UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
+static UInt32
+Bt2_MatchFinder_GetMatches (
+ CMatchFinder *p,
+ UInt32 *distances
+ )
{
- unsigned offset;
- GET_MATCHES_HEADER(2)
+ unsigned offset;
+
+ GET_MATCHES_HEADER (2)
HASH2_CALC;
- curMatch = p->hash[hv];
+ curMatch = p->hash[hv];
p->hash[hv] = p->pos;
- offset = 0;
- GET_MATCHES_FOOTER(offset, 1)
+ offset = 0;
+ GET_MATCHES_FOOTER (offset, 1)
}
-UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
+UInt32
+Bt3Zip_MatchFinder_GetMatches (
+ CMatchFinder *p,
+ UInt32 *distances
+ )
{
- unsigned offset;
- GET_MATCHES_HEADER(3)
+ unsigned offset;
+
+ GET_MATCHES_HEADER (3)
HASH_ZIP_CALC;
- curMatch = p->hash[hv];
+ curMatch = p->hash[hv];
p->hash[hv] = p->pos;
- offset = 0;
- GET_MATCHES_FOOTER(offset, 2)
+ offset = 0;
+ GET_MATCHES_FOOTER (offset, 2)
}
-static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
+static UInt32
+Bt3_MatchFinder_GetMatches (
+ CMatchFinder *p,
+ UInt32 *distances
+ )
{
- UInt32 h2, d2, pos;
- unsigned maxLen, offset;
- UInt32 *hash;
- GET_MATCHES_HEADER(3)
+ UInt32 h2, d2, pos;
+ unsigned maxLen, offset;
+ UInt32 *hash;
+
+ GET_MATCHES_HEADER (3)
HASH3_CALC;
hash = p->hash;
- pos = p->pos;
+ pos = p->pos;
d2 = pos - hash[h2];
curMatch = (hash + kFix3HashSize)[hv];
- hash[h2] = pos;
+ hash[h2] = pos;
(hash + kFix3HashSize)[hv] = pos;
maxLen = 2;
offset = 0;
- if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur)
- {
+ if ((d2 < p->cyclicBufferSize) && (*(cur - d2) == *cur)) {
UPDATE_maxLen
- distances[0] = (UInt32)maxLen;
+ distances[0] = (UInt32)maxLen;
distances[1] = d2 - 1;
- offset = 2;
- if (maxLen == lenLimit)
- {
- SkipMatchesSpec((UInt32)lenLimit, curMatch, MF_PARAMS(p));
+ offset = 2;
+ if (maxLen == lenLimit) {
+ SkipMatchesSpec ((UInt32)lenLimit, curMatch, MF_PARAMS (p));
MOVE_POS_RET;
}
}
- GET_MATCHES_FOOTER(offset, maxLen)
+ GET_MATCHES_FOOTER (offset, maxLen)
}
-static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
+static UInt32
+Bt4_MatchFinder_GetMatches (
+ CMatchFinder *p,
+ UInt32 *distances
+ )
{
- UInt32 h2, h3, d2, d3, pos;
- unsigned maxLen, offset;
- UInt32 *hash;
- GET_MATCHES_HEADER(4)
+ UInt32 h2, h3, d2, d3, pos;
+ unsigned maxLen, offset;
+ UInt32 *hash;
+
+ GET_MATCHES_HEADER (4)
HASH4_CALC;
hash = p->hash;
- pos = p->pos;
+ pos = p->pos;
- d2 = pos - hash[ h2];
+ d2 = pos - hash[h2];
d3 = pos - (hash + kFix3HashSize)[h3];
curMatch = (hash + kFix4HashSize)[hv];
- hash[ h2] = pos;
+ hash[h2] = pos;
(hash + kFix3HashSize)[h3] = pos;
(hash + kFix4HashSize)[hv] = pos;
maxLen = 0;
offset = 0;
- if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur)
- {
- maxLen = 2;
+ if ((d2 < p->cyclicBufferSize) && (*(cur - d2) == *cur)) {
+ maxLen = 2;
distances[0] = 2;
distances[1] = d2 - 1;
- offset = 2;
+ offset = 2;
}
- if (d2 != d3 && d3 < p->cyclicBufferSize && *(cur - d3) == *cur)
- {
- maxLen = 3;
+ if ((d2 != d3) && (d3 < p->cyclicBufferSize) && (*(cur - d3) == *cur)) {
+ maxLen = 3;
distances[(size_t)offset + 1] = d3 - 1;
- offset += 2;
- d2 = d3;
+ offset += 2;
+ d2 = d3;
}
- if (offset != 0)
- {
+ if (offset != 0) {
UPDATE_maxLen
- distances[(size_t)offset - 2] = (UInt32)maxLen;
- if (maxLen == lenLimit)
- {
- SkipMatchesSpec((UInt32)lenLimit, curMatch, MF_PARAMS(p));
+ distances[(size_t)offset - 2] = (UInt32)maxLen;
+ if (maxLen == lenLimit) {
+ SkipMatchesSpec ((UInt32)lenLimit, curMatch, MF_PARAMS (p));
MOVE_POS_RET;
}
}
- if (maxLen < 3)
+ if (maxLen < 3) {
maxLen = 3;
+ }
- GET_MATCHES_FOOTER(offset, maxLen)
+ GET_MATCHES_FOOTER (offset, maxLen)
}
/*
@@ -797,63 +986,69 @@ static UInt32 Bt5_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
GET_MATCHES_FOOTER(offset, maxLen)
}
*/
-
-static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
+static UInt32
+Hc4_MatchFinder_GetMatches (
+ CMatchFinder *p,
+ UInt32 *distances
+ )
{
- UInt32 h2, h3, d2, d3, pos;
- unsigned maxLen, offset;
- UInt32 *hash;
- GET_MATCHES_HEADER(4)
+ UInt32 h2, h3, d2, d3, pos;
+ unsigned maxLen, offset;
+ UInt32 *hash;
+
+ GET_MATCHES_HEADER (4)
HASH4_CALC;
hash = p->hash;
- pos = p->pos;
+ pos = p->pos;
- d2 = pos - hash[ h2];
+ d2 = pos - hash[h2];
d3 = pos - (hash + kFix3HashSize)[h3];
curMatch = (hash + kFix4HashSize)[hv];
- hash[ h2] = pos;
+ hash[h2] = pos;
(hash + kFix3HashSize)[h3] = pos;
(hash + kFix4HashSize)[hv] = pos;
maxLen = 0;
offset = 0;
- if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur)
- {
- maxLen = 2;
+ if ((d2 < p->cyclicBufferSize) && (*(cur - d2) == *cur)) {
+ maxLen = 2;
distances[0] = 2;
distances[1] = d2 - 1;
- offset = 2;
+ offset = 2;
}
- if (d2 != d3 && d3 < p->cyclicBufferSize && *(cur - d3) == *cur)
- {
- maxLen = 3;
+ if ((d2 != d3) && (d3 < p->cyclicBufferSize) && (*(cur - d3) == *cur)) {
+ maxLen = 3;
distances[(size_t)offset + 1] = d3 - 1;
- offset += 2;
- d2 = d3;
+ offset += 2;
+ d2 = d3;
}
- if (offset != 0)
- {
+ if (offset != 0) {
UPDATE_maxLen
- distances[(size_t)offset - 2] = (UInt32)maxLen;
- if (maxLen == lenLimit)
- {
+ distances[(size_t)offset - 2] = (UInt32)maxLen;
+ if (maxLen == lenLimit) {
p->son[p->cyclicBufferPos] = curMatch;
MOVE_POS_RET;
}
}
- if (maxLen < 3)
+ if (maxLen < 3) {
maxLen = 3;
+ }
- offset = (unsigned)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
- distances + offset, maxLen) - (distances));
+ offset = (unsigned)(Hc_GetMatchesSpec (
+ lenLimit,
+ curMatch,
+ MF_PARAMS (p),
+ distances + offset,
+ maxLen
+ ) - (distances));
MOVE_POS_RET
}
@@ -935,78 +1130,95 @@ static UInt32 Hc5_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
MOVE_POS_RET
}
*/
-
-UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
+UInt32
+Hc3Zip_MatchFinder_GetMatches (
+ CMatchFinder *p,
+ UInt32 *distances
+ )
{
- unsigned offset;
- GET_MATCHES_HEADER(3)
+ unsigned offset;
+
+ GET_MATCHES_HEADER (3)
HASH_ZIP_CALC;
- curMatch = p->hash[hv];
+ curMatch = p->hash[hv];
p->hash[hv] = p->pos;
- offset = (unsigned)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
- distances, 2) - (distances));
+ offset = (unsigned)(Hc_GetMatchesSpec (
+ lenLimit,
+ curMatch,
+ MF_PARAMS (p),
+ distances,
+ 2
+ ) - (distances));
MOVE_POS_RET
}
-static void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
+static void
+Bt2_MatchFinder_Skip (
+ CMatchFinder *p,
+ UInt32 num
+ )
{
- do
- {
- SKIP_HEADER(2)
+ do {
+ SKIP_HEADER (2)
HASH2_CALC;
- curMatch = p->hash[hv];
+ curMatch = p->hash[hv];
p->hash[hv] = p->pos;
SKIP_FOOTER
- }
- while (--num != 0);
+ } while (--num != 0);
}
-void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
+void
+Bt3Zip_MatchFinder_Skip (
+ CMatchFinder *p,
+ UInt32 num
+ )
{
- do
- {
- SKIP_HEADER(3)
+ do {
+ SKIP_HEADER (3)
HASH_ZIP_CALC;
- curMatch = p->hash[hv];
+ curMatch = p->hash[hv];
p->hash[hv] = p->pos;
SKIP_FOOTER
- }
- while (--num != 0);
+ } while (--num != 0);
}
-static void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
+static void
+Bt3_MatchFinder_Skip (
+ CMatchFinder *p,
+ UInt32 num
+ )
{
- do
- {
- UInt32 h2;
- UInt32 *hash;
- SKIP_HEADER(3)
+ do {
+ UInt32 h2;
+ UInt32 *hash;
+ SKIP_HEADER (3)
HASH3_CALC;
- hash = p->hash;
- curMatch = (hash + kFix3HashSize)[hv];
- hash[h2] =
- (hash + kFix3HashSize)[hv] = p->pos;
+ hash = p->hash;
+ curMatch = (hash + kFix3HashSize)[hv];
+ hash[h2] =
+ (hash + kFix3HashSize)[hv] = p->pos;
SKIP_FOOTER
- }
- while (--num != 0);
+ } while (--num != 0);
}
-static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
+static void
+Bt4_MatchFinder_Skip (
+ CMatchFinder *p,
+ UInt32 num
+ )
{
- do
- {
- UInt32 h2, h3;
- UInt32 *hash;
- SKIP_HEADER(4)
+ do {
+ UInt32 h2, h3;
+ UInt32 *hash;
+ SKIP_HEADER (4)
HASH4_CALC;
- hash = p->hash;
- curMatch = (hash + kFix4HashSize)[hv];
- hash[ h2] =
- (hash + kFix3HashSize)[h3] =
- (hash + kFix4HashSize)[hv] = p->pos;
+ hash = p->hash;
+ curMatch = (hash + kFix4HashSize)[hv];
+ hash[h2] =
+ (hash + kFix3HashSize)[h3] =
+ (hash + kFix4HashSize)[hv] = p->pos;
SKIP_FOOTER
- }
- while (--num != 0);
+ } while (--num != 0);
}
/*
@@ -1029,24 +1241,25 @@ static void Bt5_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
while (--num != 0);
}
*/
-
-static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
+static void
+Hc4_MatchFinder_Skip (
+ CMatchFinder *p,
+ UInt32 num
+ )
{
- do
- {
- UInt32 h2, h3;
- UInt32 *hash;
- SKIP_HEADER(4)
+ do {
+ UInt32 h2, h3;
+ UInt32 *hash;
+ SKIP_HEADER (4)
HASH4_CALC;
- hash = p->hash;
- curMatch = (hash + kFix4HashSize)[hv];
- hash[ h2] =
- (hash + kFix3HashSize)[h3] =
- (hash + kFix4HashSize)[hv] = p->pos;
- p->son[p->cyclicBufferPos] = curMatch;
+ hash = p->hash;
+ curMatch = (hash + kFix4HashSize)[hv];
+ hash[h2] =
+ (hash + kFix3HashSize)[h3] =
+ (hash + kFix4HashSize)[hv] = p->pos;
+ p->son[p->cyclicBufferPos] = curMatch;
MOVE_POS
- }
- while (--num != 0);
+ } while (--num != 0);
}
/*
@@ -1070,33 +1283,38 @@ static void Hc5_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
while (--num != 0);
}
*/
-
-void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
+void
+Hc3Zip_MatchFinder_Skip (
+ CMatchFinder *p,
+ UInt32 num
+ )
{
- do
- {
- SKIP_HEADER(3)
+ do {
+ SKIP_HEADER (3)
HASH_ZIP_CALC;
- curMatch = p->hash[hv];
- p->hash[hv] = p->pos;
+ curMatch = p->hash[hv];
+ p->hash[hv] = p->pos;
p->son[p->cyclicBufferPos] = curMatch;
MOVE_POS
- }
- while (--num != 0);
+ } while (--num != 0);
}
-void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable)
+void
+MatchFinder_CreateVTable (
+ CMatchFinder *p,
+ IMatchFinder *vTable
+ )
{
- vTable->Init = (Mf_Init_Func)MatchFinder_Init;
- vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinder_GetNumAvailableBytes;
+ vTable->Init = (Mf_Init_Func)MatchFinder_Init;
+ vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinder_GetNumAvailableBytes;
vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinder_GetPointerToCurrentPos;
- if (!p->btMode)
- {
+ if (!p->btMode) {
/* if (p->numHashBytes <= 4) */
{
vTable->GetMatches = (Mf_GetMatches_Func)Hc4_MatchFinder_GetMatches;
- vTable->Skip = (Mf_Skip_Func)Hc4_MatchFinder_Skip;
+ vTable->Skip = (Mf_Skip_Func)Hc4_MatchFinder_Skip;
}
+
/*
else
{
@@ -1104,22 +1322,18 @@ void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable)
vTable->Skip = (Mf_Skip_Func)Hc5_MatchFinder_Skip;
}
*/
- }
- else if (p->numHashBytes == 2)
- {
+ } else if (p->numHashBytes == 2) {
vTable->GetMatches = (Mf_GetMatches_Func)Bt2_MatchFinder_GetMatches;
- vTable->Skip = (Mf_Skip_Func)Bt2_MatchFinder_Skip;
- }
- else if (p->numHashBytes == 3)
- {
+ vTable->Skip = (Mf_Skip_Func)Bt2_MatchFinder_Skip;
+ } else if (p->numHashBytes == 3) {
vTable->GetMatches = (Mf_GetMatches_Func)Bt3_MatchFinder_GetMatches;
- vTable->Skip = (Mf_Skip_Func)Bt3_MatchFinder_Skip;
- }
- else /* if (p->numHashBytes == 4) */
- {
+ vTable->Skip = (Mf_Skip_Func)Bt3_MatchFinder_Skip;
+ } else {
+ /* if (p->numHashBytes == 4) */
vTable->GetMatches = (Mf_GetMatches_Func)Bt4_MatchFinder_GetMatches;
- vTable->Skip = (Mf_Skip_Func)Bt4_MatchFinder_Skip;
+ vTable->Skip = (Mf_Skip_Func)Bt4_MatchFinder_Skip;
}
+
/*
else
{
diff --git a/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzFind.h b/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzFind.h
index 61bb9dd302..923d3e3d95 100644
--- a/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzFind.h
+++ b/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzFind.h
@@ -10,77 +10,126 @@ EXTERN_C_BEGIN
typedef UInt32 CLzRef;
-typedef struct _CMatchFinder
-{
- Byte *buffer;
- UInt32 pos;
- UInt32 posLimit;
- UInt32 streamPos;
- UInt32 lenLimit;
-
- UInt32 cyclicBufferPos;
- UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */
-
- Byte streamEndWasReached;
- Byte btMode;
- Byte bigHash;
- Byte directInput;
-
- UInt32 matchMaxLen;
- CLzRef *hash;
- CLzRef *son;
- UInt32 hashMask;
- UInt32 cutValue;
-
- Byte *bufferBase;
- ISeqInStream *stream;
-
- UInt32 blockSize;
- UInt32 keepSizeBefore;
- UInt32 keepSizeAfter;
-
- UInt32 numHashBytes;
- size_t directInputRem;
- UInt32 historySize;
- UInt32 fixedHashSize;
- UInt32 hashSizeSum;
- SRes result;
- UInt32 crc[256];
- size_t numRefs;
-
- UInt64 expectedDataSize;
+typedef struct _CMatchFinder {
+ Byte *buffer;
+ UInt32 pos;
+ UInt32 posLimit;
+ UInt32 streamPos;
+ UInt32 lenLimit;
+
+ UInt32 cyclicBufferPos;
+ UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */
+
+ Byte streamEndWasReached;
+ Byte btMode;
+ Byte bigHash;
+ Byte directInput;
+
+ UInt32 matchMaxLen;
+ CLzRef *hash;
+ CLzRef *son;
+ UInt32 hashMask;
+ UInt32 cutValue;
+
+ Byte *bufferBase;
+ ISeqInStream *stream;
+
+ UInt32 blockSize;
+ UInt32 keepSizeBefore;
+ UInt32 keepSizeAfter;
+
+ UInt32 numHashBytes;
+ size_t directInputRem;
+ UInt32 historySize;
+ UInt32 fixedHashSize;
+ UInt32 hashSizeSum;
+ SRes result;
+ UInt32 crc[256];
+ size_t numRefs;
+
+ UInt64 expectedDataSize;
} CMatchFinder;
-#define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer)
+#define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer)
-#define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos)
+#define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos)
#define Inline_MatchFinder_IsFinishedOK(p) \
((p)->streamEndWasReached \
&& (p)->streamPos == (p)->pos \
&& (!(p)->directInput || (p)->directInputRem == 0))
-int MatchFinder_NeedMove(CMatchFinder *p);
-Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p);
-void MatchFinder_MoveBlock(CMatchFinder *p);
-void MatchFinder_ReadIfRequired(CMatchFinder *p);
+int
+MatchFinder_NeedMove (
+ CMatchFinder *p
+ );
-void MatchFinder_Construct(CMatchFinder *p);
+Byte *
+MatchFinder_GetPointerToCurrentPos (
+ CMatchFinder *p
+ );
+
+void
+MatchFinder_MoveBlock (
+ CMatchFinder *p
+ );
+
+void
+MatchFinder_ReadIfRequired (
+ CMatchFinder *p
+ );
+
+void
+MatchFinder_Construct (
+ CMatchFinder *p
+ );
/* Conditions:
historySize <= 3 GB
keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB
*/
-int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
- UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,
- ISzAllocPtr alloc);
-void MatchFinder_Free(CMatchFinder *p, ISzAllocPtr alloc);
-void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, size_t numItems);
-void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue);
-
-UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son,
- UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,
- UInt32 *distances, UInt32 maxLen);
+int
+MatchFinder_Create (
+ CMatchFinder *p,
+ UInt32 historySize,
+ UInt32 keepAddBufferBefore,
+ UInt32 matchMaxLen,
+ UInt32 keepAddBufferAfter,
+ ISzAllocPtr alloc
+ );
+
+void
+MatchFinder_Free (
+ CMatchFinder *p,
+ ISzAllocPtr alloc
+ );
+
+void
+MatchFinder_Normalize3 (
+ UInt32 subValue,
+ CLzRef *items,
+ size_t numItems
+ );
+
+void
+MatchFinder_ReduceOffsets (
+ CMatchFinder *p,
+ UInt32 subValue
+ );
+
+UInt32 *
+GetMatchesSpec1 (
+ UInt32 lenLimit,
+ UInt32 curMatch,
+ UInt32 pos,
+ const Byte *buffer,
+ CLzRef *son,
+ UInt32 _cyclicBufferPos,
+ UInt32 _cyclicBufferSize,
+ UInt32 _cutValue,
+ UInt32 *distances,
+ UInt32 maxLen
+ );
/*
Conditions:
@@ -88,33 +137,82 @@ Conditions:
Mf_GetPointerToCurrentPos_Func's result must be used only before any other function
*/
-typedef void (*Mf_Init_Func)(void *object);
-typedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object);
-typedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object);
-typedef UInt32 (*Mf_GetMatches_Func)(void *object, UInt32 *distances);
-typedef void (*Mf_Skip_Func)(void *object, UInt32);
-
-typedef struct _IMatchFinder
-{
- Mf_Init_Func Init;
- Mf_GetNumAvailableBytes_Func GetNumAvailableBytes;
- Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos;
- Mf_GetMatches_Func GetMatches;
- Mf_Skip_Func Skip;
+typedef void (*Mf_Init_Func)(
+ void *object
+ );
+typedef UInt32 (*Mf_GetNumAvailableBytes_Func)(
+ void *object
+ );
+typedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(
+ void *object
+ );
+typedef UInt32 (*Mf_GetMatches_Func)(
+ void *object,
+ UInt32 *distances
+ );
+typedef void (*Mf_Skip_Func)(
+ void *object,
+ UInt32
+ );
+
+typedef struct _IMatchFinder {
+ Mf_Init_Func Init;
+ Mf_GetNumAvailableBytes_Func GetNumAvailableBytes;
+ Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos;
+ Mf_GetMatches_Func GetMatches;
+ Mf_Skip_Func Skip;
} IMatchFinder;
-void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable);
-
-void MatchFinder_Init_LowHash(CMatchFinder *p);
-void MatchFinder_Init_HighHash(CMatchFinder *p);
-void MatchFinder_Init_3(CMatchFinder *p, int readData);
-void MatchFinder_Init(CMatchFinder *p);
-
-UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
-UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
-
-void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
-void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
+void
+MatchFinder_CreateVTable (
+ CMatchFinder *p,
+ IMatchFinder *vTable
+ );
+
+void
+MatchFinder_Init_LowHash (
+ CMatchFinder *p
+ );
+
+void
+MatchFinder_Init_HighHash (
+ CMatchFinder *p
+ );
+
+void
+MatchFinder_Init_3 (
+ CMatchFinder *p,
+ int readData
+ );
+
+void
+MatchFinder_Init (
+ CMatchFinder *p
+ );
+
+UInt32
+Bt3Zip_MatchFinder_GetMatches (
+ CMatchFinder *p,
+ UInt32 *distances
+ );
+
+UInt32
+Hc3Zip_MatchFinder_GetMatches (
+ CMatchFinder *p,
+ UInt32 *distances
+ );
+
+void
+Bt3Zip_MatchFinder_Skip (
+ CMatchFinder *p,
+ UInt32 num
+ );
+
+void
+Hc3Zip_MatchFinder_Skip (
+ CMatchFinder *p,
+ UInt32 num
+ );
EXTERN_C_END
diff --git a/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzHash.h b/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzHash.h
index 2191444072..eec8bb13bd 100644
--- a/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzHash.h
+++ b/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzHash.h
@@ -4,29 +4,29 @@
#ifndef __LZ_HASH_H
#define __LZ_HASH_H
-#define kHash2Size (1 << 10)
-#define kHash3Size (1 << 16)
-#define kHash4Size (1 << 20)
+#define kHash2Size (1 << 10)
+#define kHash3Size (1 << 16)
+#define kHash4Size (1 << 20)
-#define kFix3HashSize (kHash2Size)
-#define kFix4HashSize (kHash2Size + kHash3Size)
-#define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size)
+#define kFix3HashSize (kHash2Size)
+#define kFix4HashSize (kHash2Size + kHash3Size)
+#define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size)
-#define HASH2_CALC hv = cur[0] | ((UInt32)cur[1] << 8);
+#define HASH2_CALC hv = cur[0] | ((UInt32)cur[1] << 8);
-#define HASH3_CALC { \
+#define HASH3_CALC {\
UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
h2 = temp & (kHash2Size - 1); \
hv = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; }
-#define HASH4_CALC { \
+#define HASH4_CALC {\
UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
h2 = temp & (kHash2Size - 1); \
temp ^= ((UInt32)cur[2] << 8); \
h3 = temp & (kHash3Size - 1); \
hv = (temp ^ (p->crc[cur[3]] << 5)) & p->hashMask; }
-#define HASH5_CALC { \
+#define HASH5_CALC {\
UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
h2 = temp & (kHash2Size - 1); \
temp ^= ((UInt32)cur[2] << 8); \
@@ -36,18 +36,17 @@
hv = (temp ^ (p->crc[cur[4]] << 3)) & p->hashMask; }
/* #define HASH_ZIP_CALC hv = ((cur[0] | ((UInt32)cur[1] << 8)) ^ p->crc[cur[2]]) & 0xFFFF; */
-#define HASH_ZIP_CALC hv = ((cur[2] | ((UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF;
-
+#define HASH_ZIP_CALC hv = ((cur[2] | ((UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF;
#define MT_HASH2_CALC \
h2 = (p->crc[cur[0]] ^ cur[1]) & (kHash2Size - 1);
-#define MT_HASH3_CALC { \
+#define MT_HASH3_CALC {\
UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
h2 = temp & (kHash2Size - 1); \
h3 = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); }
-#define MT_HASH4_CALC { \
+#define MT_HASH4_CALC {\
UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
h2 = temp & (kHash2Size - 1); \
temp ^= ((UInt32)cur[2] << 8); \
diff --git a/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzmaDec.c b/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzmaDec.c
index 80fb74525a..54c7077984 100644
--- a/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzmaDec.c
+++ b/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzmaDec.c
@@ -4,38 +4,38 @@
#include "Precomp.h"
#ifndef EFIAPI
-#include <string.h>
+ #include <string.h>
#endif
/* #include "CpuArch.h" */
#include "LzmaDec.h"
-#define kNumTopBits 24
-#define kTopValue ((UInt32)1 << kNumTopBits)
+#define kNumTopBits 24
+#define kTopValue ((UInt32)1 << kNumTopBits)
-#define kNumBitModelTotalBits 11
-#define kBitModelTotal (1 << kNumBitModelTotalBits)
-#define kNumMoveBits 5
+#define kNumBitModelTotalBits 11
+#define kBitModelTotal (1 << kNumBitModelTotalBits)
+#define kNumMoveBits 5
-#define RC_INIT_SIZE 5
+#define RC_INIT_SIZE 5
-#define NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | (*buf++); }
+#define NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | (*buf++); }
-#define IF_BIT_0(p) ttt = *(p); NORMALIZE; bound = (range >> kNumBitModelTotalBits) * (UInt32)ttt; if (code < bound)
-#define UPDATE_0(p) range = bound; *(p) = (CLzmaProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits));
-#define UPDATE_1(p) range -= bound; code -= bound; *(p) = (CLzmaProb)(ttt - (ttt >> kNumMoveBits));
-#define GET_BIT2(p, i, A0, A1) IF_BIT_0(p) \
+#define IF_BIT_0(p) ttt = *(p); NORMALIZE; bound = (range >> kNumBitModelTotalBits) * (UInt32)ttt; if (code < bound)
+#define UPDATE_0(p) range = bound; *(p) = (CLzmaProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits));
+#define UPDATE_1(p) range -= bound; code -= bound; *(p) = (CLzmaProb)(ttt - (ttt >> kNumMoveBits));
+#define GET_BIT2(p, i, A0, A1) IF_BIT_0(p)\
{ UPDATE_0(p); i = (i + i); A0; } else \
{ UPDATE_1(p); i = (i + i) + 1; A1; }
-#define TREE_GET_BIT(probs, i) { GET_BIT2(probs + i, i, ;, ;); }
+#define TREE_GET_BIT(probs, i) { GET_BIT2(probs + i, i, ;, ;); }
-#define REV_BIT(p, i, A0, A1) IF_BIT_0(p + i) \
+#define REV_BIT(p, i, A0, A1) IF_BIT_0(p + i)\
{ UPDATE_0(p + i); A0; } else \
{ UPDATE_1(p + i); A1; }
-#define REV_BIT_VAR( p, i, m) REV_BIT(p, i, i += m; m += m, m += m; i += m; )
-#define REV_BIT_CONST(p, i, m) REV_BIT(p, i, i += m; , i += m * 2; )
-#define REV_BIT_LAST( p, i, m) REV_BIT(p, i, i -= m , ; )
+#define REV_BIT_VAR(p, i, m) REV_BIT(p, i, i += m; m += m, m += m; i += m; )
+#define REV_BIT_CONST(p, i, m) REV_BIT(p, i, i += m; , i += m * 2; )
+#define REV_BIT_LAST(p, i, m) REV_BIT(p, i, i -= m , ; )
#define TREE_DECODE(probs, limit, i) \
{ i = 1; do { TREE_GET_BIT(probs, i); } while (i < limit); i -= limit; }
@@ -43,7 +43,7 @@
/* #define _LZMA_SIZE_OPT */
#ifdef _LZMA_SIZE_OPT
-#define TREE_6_DECODE(probs, i) TREE_DECODE(probs, (1 << 6), i)
+#define TREE_6_DECODE(probs, i) TREE_DECODE(probs, (1 << 6), i)
#else
#define TREE_6_DECODE(probs, i) \
{ i = 1; \
@@ -56,7 +56,7 @@
i -= 0x40; }
#endif
-#define NORMAL_LITER_DEC TREE_GET_BIT(prob, symbol)
+#define NORMAL_LITER_DEC TREE_GET_BIT(prob, symbol)
#define MATCHED_LITER_DEC \
matchByte += matchByte; \
bit = offs; \
@@ -64,66 +64,64 @@
probLit = prob + (offs + bit + symbol); \
GET_BIT2(probLit, symbol, offs ^= bit; , ;)
+#define NORMALIZE_CHECK if (range < kTopValue) { if (buf >= bufLimit) return DUMMY_ERROR; range <<= 8; code = (code << 8) | (*buf++); }
-
-#define NORMALIZE_CHECK if (range < kTopValue) { if (buf >= bufLimit) return DUMMY_ERROR; range <<= 8; code = (code << 8) | (*buf++); }
-
-#define IF_BIT_0_CHECK(p) ttt = *(p); NORMALIZE_CHECK; bound = (range >> kNumBitModelTotalBits) * (UInt32)ttt; if (code < bound)
-#define UPDATE_0_CHECK range = bound;
-#define UPDATE_1_CHECK range -= bound; code -= bound;
-#define GET_BIT2_CHECK(p, i, A0, A1) IF_BIT_0_CHECK(p) \
+#define IF_BIT_0_CHECK(p) ttt = *(p); NORMALIZE_CHECK; bound = (range >> kNumBitModelTotalBits) * (UInt32)ttt; if (code < bound)
+#define UPDATE_0_CHECK range = bound;
+#define UPDATE_1_CHECK range -= bound; code -= bound;
+#define GET_BIT2_CHECK(p, i, A0, A1) IF_BIT_0_CHECK(p)\
{ UPDATE_0_CHECK; i = (i + i); A0; } else \
{ UPDATE_1_CHECK; i = (i + i) + 1; A1; }
-#define GET_BIT_CHECK(p, i) GET_BIT2_CHECK(p, i, ; , ;)
+#define GET_BIT_CHECK(p, i) GET_BIT2_CHECK(p, i, ; , ;)
#define TREE_DECODE_CHECK(probs, limit, i) \
{ i = 1; do { GET_BIT_CHECK(probs + i, i) } while (i < limit); i -= limit; }
-
-#define REV_BIT_CHECK(p, i, m) IF_BIT_0_CHECK(p + i) \
+#define REV_BIT_CHECK(p, i, m) IF_BIT_0_CHECK(p + i)\
{ UPDATE_0_CHECK; i += m; m += m; } else \
{ UPDATE_1_CHECK; m += m; i += m; }
+#define kNumPosBitsMax 4
+#define kNumPosStatesMax (1 << kNumPosBitsMax)
-#define kNumPosBitsMax 4
-#define kNumPosStatesMax (1 << kNumPosBitsMax)
-
-#define kLenNumLowBits 3
-#define kLenNumLowSymbols (1 << kLenNumLowBits)
-#define kLenNumHighBits 8
-#define kLenNumHighSymbols (1 << kLenNumHighBits)
+#define kLenNumLowBits 3
+#define kLenNumLowSymbols (1 << kLenNumLowBits)
+#define kLenNumHighBits 8
+#define kLenNumHighSymbols (1 << kLenNumHighBits)
-#define LenLow 0
-#define LenHigh (LenLow + 2 * (kNumPosStatesMax << kLenNumLowBits))
-#define kNumLenProbs (LenHigh + kLenNumHighSymbols)
+#define LenLow 0
+#define LenHigh (LenLow + 2 * (kNumPosStatesMax << kLenNumLowBits))
+#define kNumLenProbs (LenHigh + kLenNumHighSymbols)
-#define LenChoice LenLow
-#define LenChoice2 (LenLow + (1 << kLenNumLowBits))
+#define LenChoice LenLow
+#define LenChoice2 (LenLow + (1 << kLenNumLowBits))
-#define kNumStates 12
-#define kNumStates2 16
-#define kNumLitStates 7
+#define kNumStates 12
+#define kNumStates2 16
+#define kNumLitStates 7
-#define kStartPosModelIndex 4
-#define kEndPosModelIndex 14
-#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))
+#define kStartPosModelIndex 4
+#define kEndPosModelIndex 14
+#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))
-#define kNumPosSlotBits 6
-#define kNumLenToPosStates 4
+#define kNumPosSlotBits 6
+#define kNumLenToPosStates 4
-#define kNumAlignBits 4
-#define kAlignTableSize (1 << kNumAlignBits)
+#define kNumAlignBits 4
+#define kAlignTableSize (1 << kNumAlignBits)
-#define kMatchMinLen 2
-#define kMatchSpecLenStart (kMatchMinLen + kLenNumLowSymbols * 2 + kLenNumHighSymbols)
+#define kMatchMinLen 2
+#define kMatchSpecLenStart (kMatchMinLen + kLenNumLowSymbols * 2 + kLenNumHighSymbols)
/* External ASM code needs same CLzmaProb array layout. So don't change it. */
/* (probs_1664) is faster and better for code size at some platforms */
+
/*
#ifdef MY_CPU_X86_OR_AMD64
*/
-#define kStartOffset 1664
-#define GET_PROBS p->probs_1664
+#define kStartOffset 1664
+#define GET_PROBS p->probs_1664
+
/*
#define GET_PROBS p->probs + kStartOffset
#else
@@ -132,19 +130,19 @@
#endif
*/
-#define SpecPos (-kStartOffset)
-#define IsRep0Long (SpecPos + kNumFullDistances)
-#define RepLenCoder (IsRep0Long + (kNumStates2 << kNumPosBitsMax))
-#define LenCoder (RepLenCoder + kNumLenProbs)
-#define IsMatch (LenCoder + kNumLenProbs)
-#define Align (IsMatch + (kNumStates2 << kNumPosBitsMax))
-#define IsRep (Align + kAlignTableSize)
-#define IsRepG0 (IsRep + kNumStates)
-#define IsRepG1 (IsRepG0 + kNumStates)
-#define IsRepG2 (IsRepG1 + kNumStates)
-#define PosSlot (IsRepG2 + kNumStates)
-#define Literal (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))
-#define NUM_BASE_PROBS (Literal + kStartOffset)
+#define SpecPos (-kStartOffset)
+#define IsRep0Long (SpecPos + kNumFullDistances)
+#define RepLenCoder (IsRep0Long + (kNumStates2 << kNumPosBitsMax))
+#define LenCoder (RepLenCoder + kNumLenProbs)
+#define IsMatch (LenCoder + kNumLenProbs)
+#define Align (IsMatch + (kNumStates2 << kNumPosBitsMax))
+#define IsRep (Align + kAlignTableSize)
+#define IsRepG0 (IsRep + kNumStates)
+#define IsRepG1 (IsRepG0 + kNumStates)
+#define IsRepG2 (IsRepG1 + kNumStates)
+#define PosSlot (IsRepG2 + kNumStates)
+#define Literal (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))
+#define NUM_BASE_PROBS (Literal + kStartOffset)
#if Align != 0 && kStartOffset != 0
#error Stop_Compiling_Bad_LZMA_kAlign
@@ -154,17 +152,15 @@
#error Stop_Compiling_Bad_LZMA_PROBS
#endif
+#define LZMA_LIT_SIZE 0x300
-#define LZMA_LIT_SIZE 0x300
-
-#define LzmaProps_GetNumProbs(p) (NUM_BASE_PROBS + ((UInt32)LZMA_LIT_SIZE << ((p)->lc + (p)->lp)))
-
+#define LzmaProps_GetNumProbs(p) (NUM_BASE_PROBS + ((UInt32)LZMA_LIT_SIZE << ((p)->lc + (p)->lp)))
-#define CALC_POS_STATE(processedPos, pbMask) (((processedPos) & (pbMask)) << 4)
-#define COMBINED_PS_STATE (posState + state)
-#define GET_LEN_STATE (posState)
+#define CALC_POS_STATE(processedPos, pbMask) (((processedPos) & (pbMask)) << 4)
+#define COMBINED_PS_STATE (posState + state)
+#define GET_LEN_STATE (posState)
-#define LZMA_DIC_MIN (1 << 12)
+#define LZMA_DIC_MIN (1 << 12)
/*
p->remainLen : shows status of LZMA decoder:
@@ -175,12 +171,13 @@ p->remainLen : shows status of LZMA decoder:
*/
/* ---------- LZMA_DECODE_REAL ---------- */
+
/*
LzmaDec_DecodeReal_3() can be implemented in external ASM file.
3 - is the code compatibility version of that function for check at link time.
*/
-#define LZMA_DECODE_REAL LzmaDec_DecodeReal_3
+#define LZMA_DECODE_REAL LzmaDec_DecodeReal_3
/*
LZMA_DECODE_REAL()
@@ -209,60 +206,71 @@ Out:
= kMatchSpecLenStart : finished
*/
-
#ifdef _LZMA_DEC_OPT
-int MY_FAST_CALL LZMA_DECODE_REAL(CLzmaDec *p, SizeT limit, const Byte *bufLimit);
+int MY_FAST_CALL
+LZMA_DECODE_REAL (
+ CLzmaDec *p,
+ SizeT limit,
+ const Byte *bufLimit
+ );
#else
static
-int MY_FAST_CALL LZMA_DECODE_REAL(CLzmaDec *p, SizeT limit, const Byte *bufLimit)
+int MY_FAST_CALL
+LZMA_DECODE_REAL (
+ CLzmaDec *p,
+ SizeT limit,
+ const Byte *bufLimit
+ )
{
- CLzmaProb *probs = GET_PROBS;
- unsigned state = (unsigned)p->state;
- UInt32 rep0 = p->reps[0], rep1 = p->reps[1], rep2 = p->reps[2], rep3 = p->reps[3];
- unsigned pbMask = ((unsigned)1 << (p->prop.pb)) - 1;
- unsigned lc = p->prop.lc;
- unsigned lpMask = ((unsigned)0x100 << p->prop.lp) - ((unsigned)0x100 >> lc);
-
- Byte *dic = p->dic;
- SizeT dicBufSize = p->dicBufSize;
- SizeT dicPos = p->dicPos;
-
- UInt32 processedPos = p->processedPos;
- UInt32 checkDicSize = p->checkDicSize;
- unsigned len = 0;
-
- const Byte *buf = p->buf;
- UInt32 range = p->range;
- UInt32 code = p->code;
-
- do
- {
- CLzmaProb *prob;
- UInt32 bound;
- unsigned ttt;
- unsigned posState = CALC_POS_STATE(processedPos, pbMask);
+ CLzmaProb *probs = GET_PROBS;
+ unsigned state = (unsigned)p->state;
+ UInt32 rep0 = p->reps[0], rep1 = p->reps[1], rep2 = p->reps[2], rep3 = p->reps[3];
+ unsigned pbMask = ((unsigned)1 << (p->prop.pb)) - 1;
+ unsigned lc = p->prop.lc;
+ unsigned lpMask = ((unsigned)0x100 << p->prop.lp) - ((unsigned)0x100 >> lc);
+
+ Byte *dic = p->dic;
+ SizeT dicBufSize = p->dicBufSize;
+ SizeT dicPos = p->dicPos;
+
+ UInt32 processedPos = p->processedPos;
+ UInt32 checkDicSize = p->checkDicSize;
+ unsigned len = 0;
+
+ const Byte *buf = p->buf;
+ UInt32 range = p->range;
+ UInt32 code = p->code;
+
+ do {
+ CLzmaProb *prob;
+ UInt32 bound;
+ unsigned ttt;
+ unsigned posState = CALC_POS_STATE (processedPos, pbMask);
prob = probs + IsMatch + COMBINED_PS_STATE;
- IF_BIT_0(prob)
- {
- unsigned symbol;
- UPDATE_0(prob);
+ IF_BIT_0 (prob) {
+ unsigned symbol;
+
+ UPDATE_0 (prob);
prob = probs + Literal;
- if (processedPos != 0 || checkDicSize != 0)
+ if ((processedPos != 0) || (checkDicSize != 0)) {
prob += (UInt32)3 * ((((processedPos << 8) + dic[(dicPos == 0 ? dicBufSize : dicPos) - 1]) & lpMask) << lc);
+ }
+
processedPos++;
- if (state < kNumLitStates)
- {
+ if (state < kNumLitStates) {
state -= (state < 4) ? state : 3;
symbol = 1;
- #ifdef _LZMA_SIZE_OPT
- do { NORMAL_LITER_DEC } while (symbol < 0x100);
- #else
- NORMAL_LITER_DEC
+ #ifdef _LZMA_SIZE_OPT
+ do {
+ NORMAL_LITER_DEC
+ } while (symbol < 0x100);
+
+ #else
NORMAL_LITER_DEC
NORMAL_LITER_DEC
NORMAL_LITER_DEC
@@ -270,27 +278,24 @@ int MY_FAST_CALL LZMA_DECODE_REAL(CLzmaDec *p, SizeT limit, const Byte *bufLimit
NORMAL_LITER_DEC
NORMAL_LITER_DEC
NORMAL_LITER_DEC
- #endif
- }
- else
- {
- unsigned matchByte = dic[dicPos - rep0 + (dicPos < rep0 ? dicBufSize : 0)];
- unsigned offs = 0x100;
+ NORMAL_LITER_DEC
+ #endif
+ } else {
+ unsigned matchByte = dic[dicPos - rep0 + (dicPos < rep0 ? dicBufSize : 0)];
+ unsigned offs = 0x100;
state -= (state < 10) ? 3 : 6;
symbol = 1;
- #ifdef _LZMA_SIZE_OPT
- do
- {
- unsigned bit;
- CLzmaProb *probLit;
+ #ifdef _LZMA_SIZE_OPT
+ do {
+ unsigned bit;
+ CLzmaProb *probLit;
MATCHED_LITER_DEC
- }
- while (symbol < 0x100);
- #else
+ } while (symbol < 0x100);
+
+ #else
{
- unsigned bit;
- CLzmaProb *probLit;
- MATCHED_LITER_DEC
+ unsigned bit;
+ CLzmaProb *probLit;
MATCHED_LITER_DEC
MATCHED_LITER_DEC
MATCHED_LITER_DEC
@@ -298,8 +303,9 @@ int MY_FAST_CALL LZMA_DECODE_REAL(CLzmaDec *p, SizeT limit, const Byte *bufLimit
MATCHED_LITER_DEC
MATCHED_LITER_DEC
MATCHED_LITER_DEC
+ MATCHED_LITER_DEC
}
- #endif
+ #endif
}
dic[dicPos++] = (Byte)symbol;
@@ -307,62 +313,50 @@ int MY_FAST_CALL LZMA_DECODE_REAL(CLzmaDec *p, SizeT limit, const Byte *bufLimit
}
{
- UPDATE_1(prob);
+ UPDATE_1 (prob);
prob = probs + IsRep + state;
- IF_BIT_0(prob)
- {
- UPDATE_0(prob);
+ IF_BIT_0 (prob) {
+ UPDATE_0 (prob);
state += kNumStates;
- prob = probs + LenCoder;
- }
- else
- {
- UPDATE_1(prob);
+ prob = probs + LenCoder;
+ } else {
+ UPDATE_1 (prob);
+
/*
// that case was checked before with kBadRepCode
if (checkDicSize == 0 && processedPos == 0)
return SZ_ERROR_DATA;
*/
prob = probs + IsRepG0 + state;
- IF_BIT_0(prob)
- {
- UPDATE_0(prob);
+ IF_BIT_0 (prob) {
+ UPDATE_0 (prob);
prob = probs + IsRep0Long + COMBINED_PS_STATE;
- IF_BIT_0(prob)
- {
- UPDATE_0(prob);
+ IF_BIT_0 (prob) {
+ UPDATE_0 (prob);
dic[dicPos] = dic[dicPos - rep0 + (dicPos < rep0 ? dicBufSize : 0)];
dicPos++;
processedPos++;
state = state < kNumLitStates ? 9 : 11;
continue;
}
- UPDATE_1(prob);
- }
- else
- {
- UInt32 distance;
- UPDATE_1(prob);
+ UPDATE_1 (prob);
+ } else {
+ UInt32 distance;
+ UPDATE_1 (prob);
prob = probs + IsRepG1 + state;
- IF_BIT_0(prob)
- {
- UPDATE_0(prob);
+ IF_BIT_0 (prob) {
+ UPDATE_0 (prob);
distance = rep1;
- }
- else
- {
- UPDATE_1(prob);
+ } else {
+ UPDATE_1 (prob);
prob = probs + IsRepG2 + state;
- IF_BIT_0(prob)
- {
- UPDATE_0(prob);
+ IF_BIT_0 (prob) {
+ UPDATE_0 (prob);
distance = rep2;
- }
- else
- {
- UPDATE_1(prob);
+ } else {
+ UPDATE_1 (prob);
distance = rep3;
- rep3 = rep2;
+ rep3 = rep2;
}
rep2 = rep1;
}
@@ -370,120 +364,102 @@ int MY_FAST_CALL LZMA_DECODE_REAL(CLzmaDec *p, SizeT limit, const Byte *bufLimit
rep0 = distance;
}
state = state < kNumLitStates ? 8 : 11;
- prob = probs + RepLenCoder;
+ prob = probs + RepLenCoder;
}
- #ifdef _LZMA_SIZE_OPT
+ #ifdef _LZMA_SIZE_OPT
{
- unsigned lim, offset;
- CLzmaProb *probLen = prob + LenChoice;
- IF_BIT_0(probLen)
- {
- UPDATE_0(probLen);
+ unsigned lim, offset;
+ CLzmaProb *probLen = prob + LenChoice;
+ IF_BIT_0 (probLen) {
+ UPDATE_0 (probLen);
probLen = prob + LenLow + GET_LEN_STATE;
- offset = 0;
- lim = (1 << kLenNumLowBits);
- }
- else
- {
- UPDATE_1(probLen);
+ offset = 0;
+ lim = (1 << kLenNumLowBits);
+ } else {
+ UPDATE_1 (probLen);
probLen = prob + LenChoice2;
- IF_BIT_0(probLen)
- {
- UPDATE_0(probLen);
+ IF_BIT_0 (probLen) {
+ UPDATE_0 (probLen);
probLen = prob + LenLow + GET_LEN_STATE + (1 << kLenNumLowBits);
- offset = kLenNumLowSymbols;
- lim = (1 << kLenNumLowBits);
- }
- else
- {
- UPDATE_1(probLen);
+ offset = kLenNumLowSymbols;
+ lim = (1 << kLenNumLowBits);
+ } else {
+ UPDATE_1 (probLen);
probLen = prob + LenHigh;
- offset = kLenNumLowSymbols * 2;
- lim = (1 << kLenNumHighBits);
+ offset = kLenNumLowSymbols * 2;
+ lim = (1 << kLenNumHighBits);
}
}
- TREE_DECODE(probLen, lim, len);
+ TREE_DECODE (probLen, lim, len);
len += offset;
}
- #else
+ #else
{
- CLzmaProb *probLen = prob + LenChoice;
- IF_BIT_0(probLen)
- {
- UPDATE_0(probLen);
+ CLzmaProb *probLen = prob + LenChoice;
+ IF_BIT_0 (probLen) {
+ UPDATE_0 (probLen);
probLen = prob + LenLow + GET_LEN_STATE;
- len = 1;
- TREE_GET_BIT(probLen, len);
- TREE_GET_BIT(probLen, len);
- TREE_GET_BIT(probLen, len);
+ len = 1;
+ TREE_GET_BIT (probLen, len);
+ TREE_GET_BIT (probLen, len);
+ TREE_GET_BIT (probLen, len);
len -= 8;
- }
- else
- {
- UPDATE_1(probLen);
+ } else {
+ UPDATE_1 (probLen);
probLen = prob + LenChoice2;
- IF_BIT_0(probLen)
- {
- UPDATE_0(probLen);
+ IF_BIT_0 (probLen) {
+ UPDATE_0 (probLen);
probLen = prob + LenLow + GET_LEN_STATE + (1 << kLenNumLowBits);
- len = 1;
- TREE_GET_BIT(probLen, len);
- TREE_GET_BIT(probLen, len);
- TREE_GET_BIT(probLen, len);
- }
- else
- {
- UPDATE_1(probLen);
+ len = 1;
+ TREE_GET_BIT (probLen, len);
+ TREE_GET_BIT (probLen, len);
+ TREE_GET_BIT (probLen, len);
+ } else {
+ UPDATE_1 (probLen);
probLen = prob + LenHigh;
- TREE_DECODE(probLen, (1 << kLenNumHighBits), len);
+ TREE_DECODE (probLen, (1 << kLenNumHighBits), len);
len += kLenNumLowSymbols * 2;
}
}
}
- #endif
+ #endif
- if (state >= kNumStates)
- {
- UInt32 distance;
+ if (state >= kNumStates) {
+ UInt32 distance;
prob = probs + PosSlot +
- ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << kNumPosSlotBits);
- TREE_6_DECODE(prob, distance);
- if (distance >= kStartPosModelIndex)
- {
- unsigned posSlot = (unsigned)distance;
- unsigned numDirectBits = (unsigned)(((distance >> 1) - 1));
+ ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << kNumPosSlotBits);
+ TREE_6_DECODE (prob, distance);
+ if (distance >= kStartPosModelIndex) {
+ unsigned posSlot = (unsigned)distance;
+ unsigned numDirectBits = (unsigned)(((distance >> 1) - 1));
distance = (2 | (distance & 1));
- if (posSlot < kEndPosModelIndex)
- {
+ if (posSlot < kEndPosModelIndex) {
distance <<= numDirectBits;
- prob = probs + SpecPos;
+ prob = probs + SpecPos;
{
- UInt32 m = 1;
+ UInt32 m = 1;
distance++;
- do
- {
- REV_BIT_VAR(prob, distance, m);
- }
- while (--numDirectBits);
+ do {
+ REV_BIT_VAR (prob, distance, m);
+ } while (--numDirectBits);
+
distance -= m;
}
- }
- else
- {
+ } else {
numDirectBits -= kNumAlignBits;
- do
- {
+ do {
NORMALIZE
- range >>= 1;
+ range >>= 1;
{
- UInt32 t;
- code -= range;
- t = (0 - ((UInt32)code >> 31)); /* (UInt32)((Int32)code >> 31) */
+ UInt32 t;
+ code -= range;
+ t = (0 - ((UInt32)code >> 31)); /* (UInt32)((Int32)code >> 31) */
distance = (distance << 1) + (t + 1);
- code += range & t;
+ code += range & t;
}
+
/*
distance <<= 1;
if (code >= range)
@@ -492,34 +468,32 @@ int MY_FAST_CALL LZMA_DECODE_REAL(CLzmaDec *p, SizeT limit, const Byte *bufLimit
distance |= 1;
}
*/
- }
- while (--numDirectBits);
- prob = probs + Align;
+ } while (--numDirectBits);
+
+ prob = probs + Align;
distance <<= kNumAlignBits;
{
- unsigned i = 1;
- REV_BIT_CONST(prob, i, 1);
- REV_BIT_CONST(prob, i, 2);
- REV_BIT_CONST(prob, i, 4);
+ unsigned i = 1;
+ REV_BIT_CONST (prob, i, 1);
+ REV_BIT_CONST (prob, i, 2);
+ REV_BIT_CONST (prob, i, 4);
REV_BIT_LAST (prob, i, 8);
distance |= i;
}
- if (distance == (UInt32)0xFFFFFFFF)
- {
- len = kMatchSpecLenStart;
+ if (distance == (UInt32)0xFFFFFFFF) {
+ len = kMatchSpecLenStart;
state -= kNumStates;
break;
}
}
}
- rep3 = rep2;
- rep2 = rep1;
- rep1 = rep0;
- rep0 = distance + 1;
+ rep3 = rep2;
+ rep2 = rep1;
+ rep1 = rep0;
+ rep0 = distance + 1;
state = (state < kNumStates + kNumLitStates) ? kNumLitStates : kNumLitStates + 3;
- if (distance >= (checkDicSize == 0 ? processedPos: checkDicSize))
- {
+ if (distance >= ((checkDicSize == 0) ? processedPos : checkDicSize)) {
p->dicPos = dicPos;
return SZ_ERROR_DATA;
}
@@ -528,660 +502,740 @@ int MY_FAST_CALL LZMA_DECODE_REAL(CLzmaDec *p, SizeT limit, const Byte *bufLimit
len += kMatchMinLen;
{
- SizeT rem;
- unsigned curLen;
- SizeT pos;
+ SizeT rem;
+ unsigned curLen;
+ SizeT pos;
- if ((rem = limit - dicPos) == 0)
- {
+ if ((rem = limit - dicPos) == 0) {
p->dicPos = dicPos;
return SZ_ERROR_DATA;
}
curLen = ((rem < len) ? (unsigned)rem : len);
- pos = dicPos - rep0 + (dicPos < rep0 ? dicBufSize : 0);
+ pos = dicPos - rep0 + (dicPos < rep0 ? dicBufSize : 0);
processedPos += (UInt32)curLen;
len -= curLen;
- if (curLen <= dicBufSize - pos)
- {
- Byte *dest = dic + dicPos;
- ptrdiff_t src = (ptrdiff_t)pos - (ptrdiff_t)dicPos;
- const Byte *lim = dest + curLen;
+ if (curLen <= dicBufSize - pos) {
+ Byte *dest = dic + dicPos;
+ ptrdiff_t src = (ptrdiff_t)pos - (ptrdiff_t)dicPos;
+ const Byte *lim = dest + curLen;
dicPos += (SizeT)curLen;
- do
+ do {
*(dest) = (Byte)*(dest + src);
- while (++dest != lim);
- }
- else
- {
- do
- {
+ } while (++dest != lim);
+ } else {
+ do {
dic[dicPos++] = dic[pos];
- if (++pos == dicBufSize)
+ if (++pos == dicBufSize) {
pos = 0;
- }
- while (--curLen != 0);
+ }
+ } while (--curLen != 0);
}
}
}
- }
- while (dicPos < limit && buf < bufLimit);
+ } while (dicPos < limit && buf < bufLimit);
NORMALIZE;
- p->buf = buf;
- p->range = range;
- p->code = code;
- p->remainLen = (UInt32)len;
- p->dicPos = dicPos;
+ p->buf = buf;
+ p->range = range;
+ p->code = code;
+ p->remainLen = (UInt32)len;
+ p->dicPos = dicPos;
p->processedPos = processedPos;
- p->reps[0] = rep0;
- p->reps[1] = rep1;
- p->reps[2] = rep2;
- p->reps[3] = rep3;
- p->state = (UInt32)state;
+ p->reps[0] = rep0;
+ p->reps[1] = rep1;
+ p->reps[2] = rep2;
+ p->reps[3] = rep3;
+ p->state = (UInt32)state;
return SZ_OK;
}
+
#endif
-static void MY_FAST_CALL LzmaDec_WriteRem(CLzmaDec *p, SizeT limit)
+static void MY_FAST_CALL
+LzmaDec_WriteRem (
+ CLzmaDec *p,
+ SizeT limit
+ )
{
- if (p->remainLen != 0 && p->remainLen < kMatchSpecLenStart)
- {
- Byte *dic = p->dic;
- SizeT dicPos = p->dicPos;
- SizeT dicBufSize = p->dicBufSize;
- unsigned len = (unsigned)p->remainLen;
- SizeT rep0 = p->reps[0]; /* we use SizeT to avoid the BUG of VC14 for AMD64 */
- SizeT rem = limit - dicPos;
- if (rem < len)
+ if ((p->remainLen != 0) && (p->remainLen < kMatchSpecLenStart)) {
+ Byte *dic = p->dic;
+ SizeT dicPos = p->dicPos;
+ SizeT dicBufSize = p->dicBufSize;
+ unsigned len = (unsigned)p->remainLen;
+ SizeT rep0 = p->reps[0]; /* we use SizeT to avoid the BUG of VC14 for AMD64 */
+ SizeT rem = limit - dicPos;
+ if (rem < len) {
len = (unsigned)(rem);
+ }
- if (p->checkDicSize == 0 && p->prop.dicSize - p->processedPos <= len)
+ if ((p->checkDicSize == 0) && (p->prop.dicSize - p->processedPos <= len)) {
p->checkDicSize = p->prop.dicSize;
+ }
p->processedPos += (UInt32)len;
- p->remainLen -= (UInt32)len;
- while (len != 0)
- {
+ p->remainLen -= (UInt32)len;
+ while (len != 0) {
len--;
dic[dicPos] = dic[dicPos - rep0 + (dicPos < rep0 ? dicBufSize : 0)];
dicPos++;
}
+
p->dicPos = dicPos;
}
}
-
-#define kRange0 0xFFFFFFFF
-#define kBound0 ((kRange0 >> kNumBitModelTotalBits) << (kNumBitModelTotalBits - 1))
-#define kBadRepCode (kBound0 + (((kRange0 - kBound0) >> kNumBitModelTotalBits) << (kNumBitModelTotalBits - 1)))
+#define kRange0 0xFFFFFFFF
+#define kBound0 ((kRange0 >> kNumBitModelTotalBits) << (kNumBitModelTotalBits - 1))
+#define kBadRepCode (kBound0 + (((kRange0 - kBound0) >> kNumBitModelTotalBits) << (kNumBitModelTotalBits - 1)))
#if kBadRepCode != (0xC0000000 - 0x400)
#error Stop_Compiling_Bad_LZMA_Check
#endif
-static int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte *bufLimit)
+static int MY_FAST_CALL
+LzmaDec_DecodeReal2 (
+ CLzmaDec *p,
+ SizeT limit,
+ const Byte *bufLimit
+ )
{
- do
- {
- SizeT limit2 = limit;
- if (p->checkDicSize == 0)
- {
- UInt32 rem = p->prop.dicSize - p->processedPos;
- if (limit - p->dicPos > rem)
+ do {
+ SizeT limit2 = limit;
+ if (p->checkDicSize == 0) {
+ UInt32 rem = p->prop.dicSize - p->processedPos;
+ if (limit - p->dicPos > rem) {
limit2 = p->dicPos + rem;
+ }
- if (p->processedPos == 0)
- if (p->code >= kBadRepCode)
+ if (p->processedPos == 0) {
+ if (p->code >= kBadRepCode) {
return SZ_ERROR_DATA;
+ }
+ }
}
- RINOK(LZMA_DECODE_REAL(p, limit2, bufLimit));
+ RINOK (LZMA_DECODE_REAL (p, limit2, bufLimit));
- if (p->checkDicSize == 0 && p->processedPos >= p->prop.dicSize)
+ if ((p->checkDicSize == 0) && (p->processedPos >= p->prop.dicSize)) {
p->checkDicSize = p->prop.dicSize;
+ }
- LzmaDec_WriteRem(p, limit);
- }
- while (p->dicPos < limit && p->buf < bufLimit && p->remainLen < kMatchSpecLenStart);
+ LzmaDec_WriteRem (p, limit);
+ } while (p->dicPos < limit && p->buf < bufLimit && p->remainLen < kMatchSpecLenStart);
return 0;
}
-typedef enum
-{
+typedef enum {
DUMMY_ERROR, /* unexpected end of input stream */
DUMMY_LIT,
DUMMY_MATCH,
DUMMY_REP
} ELzmaDummy;
-static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inSize)
+static ELzmaDummy
+LzmaDec_TryDummy (
+ const CLzmaDec *p,
+ const Byte *buf,
+ SizeT inSize
+ )
{
- UInt32 range = p->range;
- UInt32 code = p->code;
- const Byte *bufLimit = buf + inSize;
- const CLzmaProb *probs = GET_PROBS;
- unsigned state = (unsigned)p->state;
- ELzmaDummy res;
+ UInt32 range = p->range;
+ UInt32 code = p->code;
+ const Byte *bufLimit = buf + inSize;
+ const CLzmaProb *probs = GET_PROBS;
+ unsigned state = (unsigned)p->state;
+ ELzmaDummy res;
{
- const CLzmaProb *prob;
- UInt32 bound;
- unsigned ttt;
- unsigned posState = CALC_POS_STATE(p->processedPos, (1 << p->prop.pb) - 1);
+ const CLzmaProb *prob;
+ UInt32 bound;
+ unsigned ttt;
+ unsigned posState = CALC_POS_STATE (p->processedPos, (1 << p->prop.pb) - 1);
prob = probs + IsMatch + COMBINED_PS_STATE;
- IF_BIT_0_CHECK(prob)
- {
+ IF_BIT_0_CHECK (prob) {
UPDATE_0_CHECK
/* if (bufLimit - buf >= 7) return DUMMY_LIT; */
- prob = probs + Literal;
- if (p->checkDicSize != 0 || p->processedPos != 0)
- prob += ((UInt32)LZMA_LIT_SIZE *
- ((((p->processedPos) & ((1 << (p->prop.lp)) - 1)) << p->prop.lc) +
- (p->dic[(p->dicPos == 0 ? p->dicBufSize : p->dicPos) - 1] >> (8 - p->prop.lc))));
+ prob = probs + Literal;
- if (state < kNumLitStates)
- {
- unsigned symbol = 1;
- do { GET_BIT_CHECK(prob + symbol, symbol) } while (symbol < 0x100);
+ if ((p->checkDicSize != 0) || (p->processedPos != 0)) {
+ prob += ((UInt32)LZMA_LIT_SIZE *
+ ((((p->processedPos) & ((1 << (p->prop.lp)) - 1)) << p->prop.lc) +
+ (p->dic[(p->dicPos == 0 ? p->dicBufSize : p->dicPos) - 1] >> (8 - p->prop.lc))));
}
- else
- {
- unsigned matchByte = p->dic[p->dicPos - p->reps[0] +
- (p->dicPos < p->reps[0] ? p->dicBufSize : 0)];
- unsigned offs = 0x100;
- unsigned symbol = 1;
- do
- {
- unsigned bit;
- const CLzmaProb *probLit;
+
+ if (state < kNumLitStates) {
+ unsigned symbol = 1;
+ do {
+ GET_BIT_CHECK (prob + symbol, symbol)
+ } while (symbol < 0x100);
+ } else {
+ unsigned matchByte = p->dic[p->dicPos - p->reps[0] +
+ (p->dicPos < p->reps[0] ? p->dicBufSize : 0)];
+ unsigned offs = 0x100;
+ unsigned symbol = 1;
+ do {
+ unsigned bit;
+ const CLzmaProb *probLit;
matchByte += matchByte;
- bit = offs;
- offs &= matchByte;
- probLit = prob + (offs + bit + symbol);
- GET_BIT2_CHECK(probLit, symbol, offs ^= bit; , ; )
- }
- while (symbol < 0x100);
+ bit = offs;
+ offs &= matchByte;
+ probLit = prob + (offs + bit + symbol);
+ GET_BIT2_CHECK (
+ probLit,
+ symbol,
+ offs ^= bit;
+ ,
+ ;
+ )
+ } while (symbol < 0x100);
}
+
res = DUMMY_LIT;
- }
- else
- {
- unsigned len;
+ } else {
+ unsigned len;
UPDATE_1_CHECK;
prob = probs + IsRep + state;
- IF_BIT_0_CHECK(prob)
- {
+ IF_BIT_0_CHECK (prob) {
UPDATE_0_CHECK;
state = 0;
- prob = probs + LenCoder;
- res = DUMMY_MATCH;
- }
- else
- {
+ prob = probs + LenCoder;
+ res = DUMMY_MATCH;
+ } else {
UPDATE_1_CHECK;
- res = DUMMY_REP;
+ res = DUMMY_REP;
prob = probs + IsRepG0 + state;
- IF_BIT_0_CHECK(prob)
- {
+ IF_BIT_0_CHECK (prob) {
UPDATE_0_CHECK;
prob = probs + IsRep0Long + COMBINED_PS_STATE;
- IF_BIT_0_CHECK(prob)
- {
+ IF_BIT_0_CHECK (prob) {
UPDATE_0_CHECK;
NORMALIZE_CHECK;
return DUMMY_REP;
- }
- else
- {
+ } else {
UPDATE_1_CHECK;
}
- }
- else
- {
+ } else {
UPDATE_1_CHECK;
prob = probs + IsRepG1 + state;
- IF_BIT_0_CHECK(prob)
- {
+ IF_BIT_0_CHECK (prob) {
UPDATE_0_CHECK;
- }
- else
- {
+ } else {
UPDATE_1_CHECK;
prob = probs + IsRepG2 + state;
- IF_BIT_0_CHECK(prob)
- {
+ IF_BIT_0_CHECK (prob) {
UPDATE_0_CHECK;
- }
- else
- {
+ } else {
UPDATE_1_CHECK;
}
}
}
state = kNumStates;
- prob = probs + RepLenCoder;
+ prob = probs + RepLenCoder;
}
{
- unsigned limit, offset;
- const CLzmaProb *probLen = prob + LenChoice;
- IF_BIT_0_CHECK(probLen)
- {
+ unsigned limit, offset;
+ const CLzmaProb *probLen = prob + LenChoice;
+ IF_BIT_0_CHECK (probLen) {
UPDATE_0_CHECK;
probLen = prob + LenLow + GET_LEN_STATE;
- offset = 0;
- limit = 1 << kLenNumLowBits;
- }
- else
- {
+ offset = 0;
+ limit = 1 << kLenNumLowBits;
+ } else {
UPDATE_1_CHECK;
probLen = prob + LenChoice2;
- IF_BIT_0_CHECK(probLen)
- {
+ IF_BIT_0_CHECK (probLen) {
UPDATE_0_CHECK;
probLen = prob + LenLow + GET_LEN_STATE + (1 << kLenNumLowBits);
- offset = kLenNumLowSymbols;
- limit = 1 << kLenNumLowBits;
- }
- else
- {
+ offset = kLenNumLowSymbols;
+ limit = 1 << kLenNumLowBits;
+ } else {
UPDATE_1_CHECK;
probLen = prob + LenHigh;
- offset = kLenNumLowSymbols * 2;
- limit = 1 << kLenNumHighBits;
+ offset = kLenNumLowSymbols * 2;
+ limit = 1 << kLenNumHighBits;
}
}
- TREE_DECODE_CHECK(probLen, limit, len);
+ TREE_DECODE_CHECK (probLen, limit, len);
len += offset;
}
- if (state < 4)
- {
- unsigned posSlot;
+ if (state < 4) {
+ unsigned posSlot;
prob = probs + PosSlot +
- ((len < kNumLenToPosStates - 1 ? len : kNumLenToPosStates - 1) <<
- kNumPosSlotBits);
- TREE_DECODE_CHECK(prob, 1 << kNumPosSlotBits, posSlot);
- if (posSlot >= kStartPosModelIndex)
- {
- unsigned numDirectBits = ((posSlot >> 1) - 1);
+ ((len < kNumLenToPosStates - 1 ? len : kNumLenToPosStates - 1) <<
+ kNumPosSlotBits);
+ TREE_DECODE_CHECK (prob, 1 << kNumPosSlotBits, posSlot);
+ if (posSlot >= kStartPosModelIndex) {
+ unsigned numDirectBits = ((posSlot >> 1) - 1);
/* if (bufLimit - buf >= 8) return DUMMY_MATCH; */
- if (posSlot < kEndPosModelIndex)
- {
+ if (posSlot < kEndPosModelIndex) {
prob = probs + SpecPos + ((2 | (posSlot & 1)) << numDirectBits);
- }
- else
- {
+ } else {
numDirectBits -= kNumAlignBits;
- do
- {
+ do {
NORMALIZE_CHECK
- range >>= 1;
+ range >>= 1;
code -= range & (((code - range) >> 31) - 1);
/* if (code >= range) code -= range; */
- }
- while (--numDirectBits);
- prob = probs + Align;
+ } while (--numDirectBits);
+
+ prob = probs + Align;
numDirectBits = kNumAlignBits;
}
+
{
- unsigned i = 1;
- unsigned m = 1;
- do
- {
- REV_BIT_CHECK(prob, i, m);
- }
- while (--numDirectBits);
+ unsigned i = 1;
+ unsigned m = 1;
+ do {
+ REV_BIT_CHECK (prob, i, m);
+ } while (--numDirectBits);
}
}
}
}
}
+
NORMALIZE_CHECK;
return res;
}
-
-void LzmaDec_InitDicAndState(CLzmaDec *p, BoolInt initDic, BoolInt initState)
+void
+LzmaDec_InitDicAndState (
+ CLzmaDec *p,
+ BoolInt initDic,
+ BoolInt initState
+ )
{
- p->remainLen = kMatchSpecLenStart + 1;
+ p->remainLen = kMatchSpecLenStart + 1;
p->tempBufSize = 0;
- if (initDic)
- {
+ if (initDic) {
p->processedPos = 0;
p->checkDicSize = 0;
- p->remainLen = kMatchSpecLenStart + 2;
+ p->remainLen = kMatchSpecLenStart + 2;
}
- if (initState)
+
+ if (initState) {
p->remainLen = kMatchSpecLenStart + 2;
+ }
}
-void LzmaDec_Init(CLzmaDec *p)
+void
+LzmaDec_Init (
+ CLzmaDec *p
+ )
{
p->dicPos = 0;
- LzmaDec_InitDicAndState(p, True, True);
+ LzmaDec_InitDicAndState (p, True, True);
}
-
-SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen,
- ELzmaFinishMode finishMode, ELzmaStatus *status)
+SRes
+LzmaDec_DecodeToDic (
+ CLzmaDec *p,
+ SizeT dicLimit,
+ const Byte *src,
+ SizeT *srcLen,
+ ELzmaFinishMode finishMode,
+ ELzmaStatus *status
+ )
{
- SizeT inSize = *srcLen;
+ SizeT inSize = *srcLen;
+
(*srcLen) = 0;
*status = LZMA_STATUS_NOT_SPECIFIED;
- if (p->remainLen > kMatchSpecLenStart)
- {
- for (; inSize > 0 && p->tempBufSize < RC_INIT_SIZE; (*srcLen)++, inSize--)
+ if (p->remainLen > kMatchSpecLenStart) {
+ for ( ; inSize > 0 && p->tempBufSize < RC_INIT_SIZE; (*srcLen)++, inSize--) {
p->tempBuf[p->tempBufSize++] = *src++;
- if (p->tempBufSize != 0 && p->tempBuf[0] != 0)
+ }
+
+ if ((p->tempBufSize != 0) && (p->tempBuf[0] != 0)) {
return SZ_ERROR_DATA;
- if (p->tempBufSize < RC_INIT_SIZE)
- {
+ }
+
+ if (p->tempBufSize < RC_INIT_SIZE) {
*status = LZMA_STATUS_NEEDS_MORE_INPUT;
return SZ_OK;
}
+
p->code =
- ((UInt32)p->tempBuf[1] << 24)
+ ((UInt32)p->tempBuf[1] << 24)
| ((UInt32)p->tempBuf[2] << 16)
| ((UInt32)p->tempBuf[3] << 8)
| ((UInt32)p->tempBuf[4]);
- p->range = 0xFFFFFFFF;
+ p->range = 0xFFFFFFFF;
p->tempBufSize = 0;
- if (p->remainLen > kMatchSpecLenStart + 1)
- {
- SizeT numProbs = LzmaProps_GetNumProbs(&p->prop);
- SizeT i;
- CLzmaProb *probs = p->probs;
- for (i = 0; i < numProbs; i++)
+ if (p->remainLen > kMatchSpecLenStart + 1) {
+ SizeT numProbs = LzmaProps_GetNumProbs (&p->prop);
+ SizeT i;
+ CLzmaProb *probs = p->probs;
+ for (i = 0; i < numProbs; i++) {
probs[i] = kBitModelTotal >> 1;
+ }
+
p->reps[0] = p->reps[1] = p->reps[2] = p->reps[3] = 1;
- p->state = 0;
+ p->state = 0;
}
p->remainLen = 0;
}
- LzmaDec_WriteRem(p, dicLimit);
+ LzmaDec_WriteRem (p, dicLimit);
- while (p->remainLen != kMatchSpecLenStart)
- {
- int checkEndMarkNow = 0;
+ while (p->remainLen != kMatchSpecLenStart) {
+ int checkEndMarkNow = 0;
- if (p->dicPos >= dicLimit)
- {
- if (p->remainLen == 0 && p->code == 0)
- {
- *status = LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK;
+ if (p->dicPos >= dicLimit) {
+ if ((p->remainLen == 0) && (p->code == 0)) {
+ *status = LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK;
+ return SZ_OK;
+ }
+
+ if (finishMode == LZMA_FINISH_ANY) {
+ *status = LZMA_STATUS_NOT_FINISHED;
+ return SZ_OK;
+ }
+
+ if (p->remainLen != 0) {
+ *status = LZMA_STATUS_NOT_FINISHED;
+ return SZ_ERROR_DATA;
+ }
+
+ checkEndMarkNow = 1;
+ }
+
+ if (p->tempBufSize == 0) {
+ SizeT processed;
+ const Byte *bufLimit;
+ if ((inSize < LZMA_REQUIRED_INPUT_MAX) || checkEndMarkNow) {
+ int dummyRes = LzmaDec_TryDummy (p, src, inSize);
+ if (dummyRes == DUMMY_ERROR) {
+ memcpy (p->tempBuf, src, inSize);
+ p->tempBufSize = (unsigned)inSize;
+ (*srcLen) += inSize;
+ *status = LZMA_STATUS_NEEDS_MORE_INPUT;
return SZ_OK;
}
- if (finishMode == LZMA_FINISH_ANY)
- {
+
+ if (checkEndMarkNow && (dummyRes != DUMMY_MATCH)) {
*status = LZMA_STATUS_NOT_FINISHED;
+ return SZ_ERROR_DATA;
+ }
+
+ bufLimit = src;
+ } else {
+ bufLimit = src + inSize - LZMA_REQUIRED_INPUT_MAX;
+ }
+
+ p->buf = src;
+ if (LzmaDec_DecodeReal2 (p, dicLimit, bufLimit) != 0) {
+ return SZ_ERROR_DATA;
+ }
+
+ processed = (SizeT)(p->buf - src);
+ (*srcLen) += processed;
+ src += processed;
+ inSize -= processed;
+ } else {
+ unsigned rem = p->tempBufSize, lookAhead = 0;
+ while (rem < LZMA_REQUIRED_INPUT_MAX && lookAhead < inSize) {
+ p->tempBuf[rem++] = src[lookAhead++];
+ }
+
+ p->tempBufSize = rem;
+ if ((rem < LZMA_REQUIRED_INPUT_MAX) || checkEndMarkNow) {
+ int dummyRes = LzmaDec_TryDummy (p, p->tempBuf, (SizeT)rem);
+ if (dummyRes == DUMMY_ERROR) {
+ (*srcLen) += (SizeT)lookAhead;
+ *status = LZMA_STATUS_NEEDS_MORE_INPUT;
return SZ_OK;
}
- if (p->remainLen != 0)
- {
+
+ if (checkEndMarkNow && (dummyRes != DUMMY_MATCH)) {
*status = LZMA_STATUS_NOT_FINISHED;
return SZ_ERROR_DATA;
}
- checkEndMarkNow = 1;
}
- if (p->tempBufSize == 0)
- {
- SizeT processed;
- const Byte *bufLimit;
- if (inSize < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)
- {
- int dummyRes = LzmaDec_TryDummy(p, src, inSize);
- if (dummyRes == DUMMY_ERROR)
- {
- memcpy(p->tempBuf, src, inSize);
- p->tempBufSize = (unsigned)inSize;
- (*srcLen) += inSize;
- *status = LZMA_STATUS_NEEDS_MORE_INPUT;
- return SZ_OK;
- }
- if (checkEndMarkNow && dummyRes != DUMMY_MATCH)
- {
- *status = LZMA_STATUS_NOT_FINISHED;
- return SZ_ERROR_DATA;
- }
- bufLimit = src;
- }
- else
- bufLimit = src + inSize - LZMA_REQUIRED_INPUT_MAX;
- p->buf = src;
- if (LzmaDec_DecodeReal2(p, dicLimit, bufLimit) != 0)
- return SZ_ERROR_DATA;
- processed = (SizeT)(p->buf - src);
- (*srcLen) += processed;
- src += processed;
- inSize -= processed;
+ p->buf = p->tempBuf;
+ if (LzmaDec_DecodeReal2 (p, dicLimit, p->buf) != 0) {
+ return SZ_ERROR_DATA;
}
- else
+
{
- unsigned rem = p->tempBufSize, lookAhead = 0;
- while (rem < LZMA_REQUIRED_INPUT_MAX && lookAhead < inSize)
- p->tempBuf[rem++] = src[lookAhead++];
- p->tempBufSize = rem;
- if (rem < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)
- {
- int dummyRes = LzmaDec_TryDummy(p, p->tempBuf, (SizeT)rem);
- if (dummyRes == DUMMY_ERROR)
- {
- (*srcLen) += (SizeT)lookAhead;
- *status = LZMA_STATUS_NEEDS_MORE_INPUT;
- return SZ_OK;
- }
- if (checkEndMarkNow && dummyRes != DUMMY_MATCH)
- {
- *status = LZMA_STATUS_NOT_FINISHED;
- return SZ_ERROR_DATA;
- }
+ unsigned kkk = (unsigned)(p->buf - p->tempBuf);
+ if (rem < kkk) {
+ return SZ_ERROR_FAIL; /* some internal error */
}
- p->buf = p->tempBuf;
- if (LzmaDec_DecodeReal2(p, dicLimit, p->buf) != 0)
- return SZ_ERROR_DATA;
- {
- unsigned kkk = (unsigned)(p->buf - p->tempBuf);
- if (rem < kkk)
- return SZ_ERROR_FAIL; /* some internal error */
- rem -= kkk;
- if (lookAhead < rem)
- return SZ_ERROR_FAIL; /* some internal error */
- lookAhead -= rem;
+ rem -= kkk;
+ if (lookAhead < rem) {
+ return SZ_ERROR_FAIL; /* some internal error */
}
- (*srcLen) += (SizeT)lookAhead;
- src += lookAhead;
- inSize -= (SizeT)lookAhead;
- p->tempBufSize = 0;
+
+ lookAhead -= rem;
}
+ (*srcLen) += (SizeT)lookAhead;
+ src += lookAhead;
+ inSize -= (SizeT)lookAhead;
+ p->tempBufSize = 0;
+ }
}
- if (p->code != 0)
+ if (p->code != 0) {
return SZ_ERROR_DATA;
+ }
+
*status = LZMA_STATUS_FINISHED_WITH_MARK;
return SZ_OK;
}
-
-SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
+SRes
+LzmaDec_DecodeToBuf (
+ CLzmaDec *p,
+ Byte *dest,
+ SizeT *destLen,
+ const Byte *src,
+ SizeT *srcLen,
+ ELzmaFinishMode finishMode,
+ ELzmaStatus *status
+ )
{
- SizeT outSize = *destLen;
- SizeT inSize = *srcLen;
+ SizeT outSize = *destLen;
+ SizeT inSize = *srcLen;
+
*srcLen = *destLen = 0;
- for (;;)
- {
- SizeT inSizeCur = inSize, outSizeCur, dicPos;
- ELzmaFinishMode curFinishMode;
- SRes res;
- if (p->dicPos == p->dicBufSize)
+ for ( ; ;) {
+ SizeT inSizeCur = inSize, outSizeCur, dicPos;
+ ELzmaFinishMode curFinishMode;
+ SRes res;
+ if (p->dicPos == p->dicBufSize) {
p->dicPos = 0;
+ }
+
dicPos = p->dicPos;
- if (outSize > p->dicBufSize - dicPos)
- {
- outSizeCur = p->dicBufSize;
+ if (outSize > p->dicBufSize - dicPos) {
+ outSizeCur = p->dicBufSize;
curFinishMode = LZMA_FINISH_ANY;
- }
- else
- {
- outSizeCur = dicPos + outSize;
+ } else {
+ outSizeCur = dicPos + outSize;
curFinishMode = finishMode;
}
- res = LzmaDec_DecodeToDic(p, outSizeCur, src, &inSizeCur, curFinishMode, status);
- src += inSizeCur;
- inSize -= inSizeCur;
- *srcLen += inSizeCur;
+ res = LzmaDec_DecodeToDic (p, outSizeCur, src, &inSizeCur, curFinishMode, status);
+ src += inSizeCur;
+ inSize -= inSizeCur;
+ *srcLen += inSizeCur;
outSizeCur = p->dicPos - dicPos;
- memcpy(dest, p->dic + dicPos, outSizeCur);
- dest += outSizeCur;
- outSize -= outSizeCur;
+ memcpy (dest, p->dic + dicPos, outSizeCur);
+ dest += outSizeCur;
+ outSize -= outSizeCur;
*destLen += outSizeCur;
- if (res != 0)
+ if (res != 0) {
return res;
- if (outSizeCur == 0 || outSize == 0)
+ }
+
+ if ((outSizeCur == 0) || (outSize == 0)) {
return SZ_OK;
+ }
}
}
-void LzmaDec_FreeProbs(CLzmaDec *p, ISzAllocPtr alloc)
+void
+LzmaDec_FreeProbs (
+ CLzmaDec *p,
+ ISzAllocPtr alloc
+ )
{
- ISzAlloc_Free(alloc, p->probs);
+ ISzAlloc_Free (alloc, p->probs);
p->probs = NULL;
}
-static void LzmaDec_FreeDict(CLzmaDec *p, ISzAllocPtr alloc)
+static void
+LzmaDec_FreeDict (
+ CLzmaDec *p,
+ ISzAllocPtr alloc
+ )
{
- ISzAlloc_Free(alloc, p->dic);
+ ISzAlloc_Free (alloc, p->dic);
p->dic = NULL;
}
-void LzmaDec_Free(CLzmaDec *p, ISzAllocPtr alloc)
+void
+LzmaDec_Free (
+ CLzmaDec *p,
+ ISzAllocPtr alloc
+ )
{
- LzmaDec_FreeProbs(p, alloc);
- LzmaDec_FreeDict(p, alloc);
+ LzmaDec_FreeProbs (p, alloc);
+ LzmaDec_FreeDict (p, alloc);
}
-SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)
+SRes
+LzmaProps_Decode (
+ CLzmaProps *p,
+ const Byte *data,
+ unsigned size
+ )
{
- UInt32 dicSize;
- Byte d;
+ UInt32 dicSize;
+ Byte d;
- if (size < LZMA_PROPS_SIZE)
+ if (size < LZMA_PROPS_SIZE) {
return SZ_ERROR_UNSUPPORTED;
- else
+ } else {
dicSize = data[1] | ((UInt32)data[2] << 8) | ((UInt32)data[3] << 16) | ((UInt32)data[4] << 24);
+ }
- if (dicSize < LZMA_DIC_MIN)
+ if (dicSize < LZMA_DIC_MIN) {
dicSize = LZMA_DIC_MIN;
+ }
+
p->dicSize = dicSize;
d = data[0];
- if (d >= (9 * 5 * 5))
+ if (d >= (9 * 5 * 5)) {
return SZ_ERROR_UNSUPPORTED;
+ }
p->lc = (Byte)(d % 9);
- d /= 9;
+ d /= 9;
p->pb = (Byte)(d / 5);
p->lp = (Byte)(d % 5);
return SZ_OK;
}
-static SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAllocPtr alloc)
+static SRes
+LzmaDec_AllocateProbs2 (
+ CLzmaDec *p,
+ const CLzmaProps *propNew,
+ ISzAllocPtr alloc
+ )
{
- UInt32 numProbs = LzmaProps_GetNumProbs(propNew);
- if (!p->probs || numProbs != p->numProbs)
- {
- LzmaDec_FreeProbs(p, alloc);
- p->probs = (CLzmaProb *)ISzAlloc_Alloc(alloc, numProbs * sizeof(CLzmaProb));
- if (!p->probs)
+ UInt32 numProbs = LzmaProps_GetNumProbs (propNew);
+
+ if (!p->probs || (numProbs != p->numProbs)) {
+ LzmaDec_FreeProbs (p, alloc);
+ p->probs = (CLzmaProb *)ISzAlloc_Alloc (alloc, numProbs * sizeof (CLzmaProb));
+ if (!p->probs) {
return SZ_ERROR_MEM;
+ }
+
p->probs_1664 = p->probs + 1664;
- p->numProbs = numProbs;
+ p->numProbs = numProbs;
}
+
return SZ_OK;
}
-SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAllocPtr alloc)
+SRes
+LzmaDec_AllocateProbs (
+ CLzmaDec *p,
+ const Byte *props,
+ unsigned propsSize,
+ ISzAllocPtr alloc
+ )
{
- CLzmaProps propNew;
- RINOK(LzmaProps_Decode(&propNew, props, propsSize));
- RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));
+ CLzmaProps propNew;
+
+ RINOK (LzmaProps_Decode (&propNew, props, propsSize));
+ RINOK (LzmaDec_AllocateProbs2 (p, &propNew, alloc));
p->prop = propNew;
return SZ_OK;
}
-SRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAllocPtr alloc)
+SRes
+LzmaDec_Allocate (
+ CLzmaDec *p,
+ const Byte *props,
+ unsigned propsSize,
+ ISzAllocPtr alloc
+ )
{
- CLzmaProps propNew;
- SizeT dicBufSize;
- RINOK(LzmaProps_Decode(&propNew, props, propsSize));
- RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));
+ CLzmaProps propNew;
+ SizeT dicBufSize;
+
+ RINOK (LzmaProps_Decode (&propNew, props, propsSize));
+ RINOK (LzmaDec_AllocateProbs2 (p, &propNew, alloc));
{
- UInt32 dictSize = propNew.dicSize;
- SizeT mask = ((UInt32)1 << 12) - 1;
- if (dictSize >= ((UInt32)1 << 30)) mask = ((UInt32)1 << 22) - 1;
- else if (dictSize >= ((UInt32)1 << 22)) mask = ((UInt32)1 << 20) - 1;;
+ UInt32 dictSize = propNew.dicSize;
+ SizeT mask = ((UInt32)1 << 12) - 1;
+ if (dictSize >= ((UInt32)1 << 30)) {
+ mask = ((UInt32)1 << 22) - 1;
+ } else if (dictSize >= ((UInt32)1 << 22)) {
+ mask = ((UInt32)1 << 20) - 1;
+ }
+
dicBufSize = ((SizeT)dictSize + mask) & ~mask;
- if (dicBufSize < dictSize)
+ if (dicBufSize < dictSize) {
dicBufSize = dictSize;
+ }
}
- if (!p->dic || dicBufSize != p->dicBufSize)
- {
- LzmaDec_FreeDict(p, alloc);
- p->dic = (Byte *)ISzAlloc_Alloc(alloc, dicBufSize);
- if (!p->dic)
- {
- LzmaDec_FreeProbs(p, alloc);
+ if (!p->dic || (dicBufSize != p->dicBufSize)) {
+ LzmaDec_FreeDict (p, alloc);
+ p->dic = (Byte *)ISzAlloc_Alloc (alloc, dicBufSize);
+ if (!p->dic) {
+ LzmaDec_FreeProbs (p, alloc);
return SZ_ERROR_MEM;
}
}
+
p->dicBufSize = dicBufSize;
- p->prop = propNew;
+ p->prop = propNew;
return SZ_OK;
}
-SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
- const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,
- ELzmaStatus *status, ISzAllocPtr alloc)
+SRes
+LzmaDecode (
+ Byte *dest,
+ SizeT *destLen,
+ const Byte *src,
+ SizeT *srcLen,
+ const Byte *propData,
+ unsigned propSize,
+ ELzmaFinishMode finishMode,
+ ELzmaStatus *status,
+ ISzAllocPtr alloc
+ )
{
- CLzmaDec p;
- SRes res;
- SizeT outSize = *destLen, inSize = *srcLen;
+ CLzmaDec p;
+ SRes res;
+ SizeT outSize = *destLen, inSize = *srcLen;
+
*destLen = *srcLen = 0;
- *status = LZMA_STATUS_NOT_SPECIFIED;
- if (inSize < RC_INIT_SIZE)
+ *status = LZMA_STATUS_NOT_SPECIFIED;
+ if (inSize < RC_INIT_SIZE) {
return SZ_ERROR_INPUT_EOF;
- LzmaDec_Construct(&p);
- RINOK(LzmaDec_AllocateProbs(&p, propData, propSize, alloc));
- p.dic = dest;
+ }
+
+ LzmaDec_Construct (&p);
+ RINOK (LzmaDec_AllocateProbs (&p, propData, propSize, alloc));
+ p.dic = dest;
p.dicBufSize = outSize;
- LzmaDec_Init(&p);
- *srcLen = inSize;
- res = LzmaDec_DecodeToDic(&p, outSize, src, srcLen, finishMode, status);
+ LzmaDec_Init (&p);
+ *srcLen = inSize;
+ res = LzmaDec_DecodeToDic (&p, outSize, src, srcLen, finishMode, status);
*destLen = p.dicPos;
- if (res == SZ_OK && *status == LZMA_STATUS_NEEDS_MORE_INPUT)
+ if ((res == SZ_OK) && (*status == LZMA_STATUS_NEEDS_MORE_INPUT)) {
res = SZ_ERROR_INPUT_EOF;
- LzmaDec_FreeProbs(&p, alloc);
+ }
+
+ LzmaDec_FreeProbs (&p, alloc);
return res;
}
diff --git a/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzmaDec.h b/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzmaDec.h
index ebc568cb4f..11f028876f 100644
--- a/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzmaDec.h
+++ b/MdeModulePkg/Library/LzmaCustomDecompressLib/Sdk/C/LzmaDec.h
@@ -9,6 +9,7 @@
EXTERN_C_BEGIN
/* #define _LZMA_PROB32 */
+
/* _LZMA_PROB32 can increase the speed on some CPUs,
but memory usage for CLzmaDec::probs will be doubled in that case */
@@ -20,18 +21,16 @@ typedef
#endif
CLzmaProb;
-
/* ---------- LZMA Properties ---------- */
-#define LZMA_PROPS_SIZE 5
+#define LZMA_PROPS_SIZE 5
-typedef struct _CLzmaProps
-{
- Byte lc;
- Byte lp;
- Byte pb;
- Byte _pad_;
- UInt32 dicSize;
+typedef struct _CLzmaProps {
+ Byte lc;
+ Byte lp;
+ Byte pb;
+ Byte _pad_;
+ UInt32 dicSize;
} CLzmaProps;
/* LzmaProps_Decode - decodes properties
@@ -40,49 +39,54 @@ Returns:
SZ_ERROR_UNSUPPORTED - Unsupported properties
*/
-SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size);
-
+SRes
+LzmaProps_Decode (
+ CLzmaProps *p,
+ const Byte *data,
+ unsigned size
+ );
/* ---------- LZMA Decoder state ---------- */
/* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case.
Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */
-#define LZMA_REQUIRED_INPUT_MAX 20
+#define LZMA_REQUIRED_INPUT_MAX 20
-typedef struct
-{
+typedef struct {
/* Don't change this structure. ASM code can use it. */
- CLzmaProps prop;
- CLzmaProb *probs;
- CLzmaProb *probs_1664;
- Byte *dic;
- SizeT dicBufSize;
- SizeT dicPos;
- const Byte *buf;
- UInt32 range;
- UInt32 code;
- UInt32 processedPos;
- UInt32 checkDicSize;
- UInt32 reps[4];
- UInt32 state;
- UInt32 remainLen;
-
- UInt32 numProbs;
- unsigned tempBufSize;
- Byte tempBuf[LZMA_REQUIRED_INPUT_MAX];
+ CLzmaProps prop;
+ CLzmaProb *probs;
+ CLzmaProb *probs_1664;
+ Byte *dic;
+ SizeT dicBufSize;
+ SizeT dicPos;
+ const Byte *buf;
+ UInt32 range;
+ UInt32 code;
+ UInt32 processedPos;
+ UInt32 checkDicSize;
+ UInt32 reps[4];
+ UInt32 state;
+ UInt32 remainLen;
+
+ UInt32 numProbs;
+ unsigned tempBufSize;
+ Byte tempBuf[LZMA_REQUIRED_INPUT_MAX];
} CLzmaDec;
-#define LzmaDec_Construct(p) { (p)->dic = NULL; (p)->probs = NULL; }
+#define LzmaDec_Construct(p) { (p)->dic = NULL; (p)->probs = NULL; }
-void LzmaDec_Init(CLzmaDec *p);
+void
+LzmaDec_Init (
+ CLzmaDec *p
+ );
/* There are two types of LZMA streams:
- Stream with end mark. That end mark adds about 6 bytes to compressed size.
- Stream without end mark. You must know exact uncompressed size to decompress such stream. */
-typedef enum
-{
+typedef enum {
LZMA_FINISH_ANY, /* finish at any point */
LZMA_FINISH_END /* block must be finished at the end */
} ELzmaFinishMode;
@@ -102,8 +106,7 @@ typedef enum
3) Check that output(srcLen) = compressedSize, if you know real compressedSize.
You must use correct finish mode in that case. */
-typedef enum
-{
+typedef enum {
LZMA_STATUS_NOT_SPECIFIED, /* use main error code instead */
LZMA_STATUS_FINISHED_WITH_MARK, /* stream was finished with end mark. */
LZMA_STATUS_NOT_FINISHED, /* stream was not finished */
@@ -113,7 +116,6 @@ typedef enum
/* ELzmaStatus is used only as output value for function call */
-
/* ---------- Interfaces ---------- */
/* There are 3 levels of interfaces:
@@ -123,7 +125,6 @@ typedef enum
You can select any of these interfaces, but don't mix functions from different
groups for same object. */
-
/* There are two variants to allocate state for Dictionary Interface:
1) LzmaDec_Allocate / LzmaDec_Free
2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs
@@ -136,11 +137,33 @@ LzmaDec_Allocate* can return:
SZ_ERROR_UNSUPPORTED - Unsupported properties
*/
-SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAllocPtr alloc);
-void LzmaDec_FreeProbs(CLzmaDec *p, ISzAllocPtr alloc);
-
-SRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAllocPtr alloc);
-void LzmaDec_Free(CLzmaDec *p, ISzAllocPtr alloc);
+SRes
+LzmaDec_AllocateProbs (
+ CLzmaDec *p,
+ const Byte *props,
+ unsigned propsSize,
+ ISzAllocPtr alloc
+ );
+
+void
+LzmaDec_FreeProbs (
+ CLzmaDec *p,
+ ISzAllocPtr alloc
+ );
+
+SRes
+LzmaDec_Allocate (
+ CLzmaDec *p,
+ const Byte *props,
+ unsigned propsSize,
+ ISzAllocPtr alloc
+ );
+
+void
+LzmaDec_Free (
+ CLzmaDec *p,
+ ISzAllocPtr alloc
+ );
/* ---------- Dictionary Interface ---------- */
@@ -183,9 +206,15 @@ Returns:
SZ_ERROR_DATA - Data error
*/
-SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit,
- const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
-
+SRes
+LzmaDec_DecodeToDic (
+ CLzmaDec *p,
+ SizeT dicLimit,
+ const Byte *src,
+ SizeT *srcLen,
+ ELzmaFinishMode finishMode,
+ ELzmaStatus *status
+ );
/* ---------- Buffer Interface ---------- */
@@ -200,9 +229,16 @@ finishMode:
LZMA_FINISH_END - Stream must be finished after (*destLen).
*/
-SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen,
- const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
-
+SRes
+LzmaDec_DecodeToBuf (
+ CLzmaDec *p,
+ Byte *dest,
+ SizeT *destLen,
+ const Byte *src,
+ SizeT *srcLen,
+ ELzmaFinishMode finishMode,
+ ELzmaStatus *status
+ );
/* ---------- One Call Interface ---------- */
@@ -225,9 +261,18 @@ Returns:
SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).
*/
-SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
- const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,
- ELzmaStatus *status, ISzAllocPtr alloc);
+SRes
+LzmaDecode (
+ Byte *dest,
+ SizeT *destLen,
+ const Byte *src,
+ SizeT *srcLen,
+ const Byte *propData,
+ unsigned propSize,
+ ELzmaFinishMode finishMode,
+ ELzmaStatus *status,
+ ISzAllocPtr alloc
+ );
EXTERN_C_END