From: notaz
Date: Mon, 20 May 2024 22:16:38 +0000 (+0300)
Subject: git subrepo pull (merge) --force deps/libchdr
X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f535537faaef474f7d31e50949eea1f15a58ee09;p=pcsx_rearmed.git
git subrepo pull (merge) --force deps/libchdr
subrepo:
subdir: "deps/libchdr"
merged: "86b27207"
upstream:
origin: "https://github.com/rtissera/libchdr"
branch: "master"
commit: "86b27207"
git-subrepo:
version: "0.4.6"
origin: "https://github.com/ingydotnet/git-subrepo.git"
commit: "73a0129"
---
diff --git a/deps/libchdr/.github/workflows/bsd.yml b/deps/libchdr/.github/workflows/bsd.yml
new file mode 100644
index 00000000..e2082522
--- /dev/null
+++ b/deps/libchdr/.github/workflows/bsd.yml
@@ -0,0 +1,34 @@
+name: BSD
+
+on: [push, pull_request]
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ operating_system: [ freebsd, netbsd, openbsd ]
+ architecture: [ arm64, x86-64 ]
+ include:
+ - operating_system: freebsd
+ version: '14.0'
+ pkginstall: sudo pkg install -y cmake git ninja pkgconf
+ - operating_system: netbsd
+ version: '10.0'
+ pkginstall: sudo pkgin update && sudo pkgin -y install cmake gcc12 git ninja-build pkgconf && export PATH=/usr/pkg/gcc12/bin:$PATH
+ - operating_system: openbsd
+ version: '7.5'
+ pkginstall: sudo pkg_add cmake git ninja pkgconf
+
+ steps:
+ - uses: actions/checkout@v4
+
+ - uses: cross-platform-actions/action@v0.24.0
+ with:
+ operating_system: ${{ matrix.operating_system }}
+ architecture: ${{ matrix.architecture }}
+ version: ${{ matrix.version }}
+ run: |
+ ${{ matrix.pkginstall }}
+ cmake -B build -DCMAKE_BUILD_TYPE=Release -G Ninja
+ cmake --build build --config Release
diff --git a/deps/libchdr/.gitrepo b/deps/libchdr/.gitrepo
index b49eb492..942a6b12 100644
--- a/deps/libchdr/.gitrepo
+++ b/deps/libchdr/.gitrepo
@@ -6,7 +6,7 @@
[subrepo]
remote = https://github.com/rtissera/libchdr
branch = master
- commit = 5c598c2df3a7717552a76410d79f5af01ff51b1d
- parent = e2fb1389dc12376acb84e4993ed3b08760257252
+ commit = 86b272076d542287d3f03952e7d4efe283e815bf
+ parent = db02598e737b8d50cd347fe2ef13cb85ade051dd
method = merge
cmdver = 0.4.6
diff --git a/deps/libchdr/CMakeLists.txt b/deps/libchdr/CMakeLists.txt
index bbb8be5d..164825a4 100644
--- a/deps/libchdr/CMakeLists.txt
+++ b/deps/libchdr/CMakeLists.txt
@@ -25,7 +25,7 @@ include(GNUInstallDirs)
# lzma
-add_subdirectory(deps/lzma-22.01 EXCLUDE_FROM_ALL)
+add_subdirectory(deps/lzma-24.05 EXCLUDE_FROM_ALL)
list(APPEND CHDR_LIBS lzma)
list(APPEND CHDR_INCLUDES lzma)
@@ -40,10 +40,11 @@ else()
list(APPEND CHDR_LIBS zlibstatic)
endif()
-# zstd
-add_subdirectory(deps/zstd-1.5.5 EXCLUDE_FROM_ALL)
-list(APPEND CHDR_LIBS zstd)
-list(APPEND CHDR_INCLUDES zstd)
+# zstd
+option(ZSTD_BUILD_SHARED "BUILD SHARED LIBRARIES" OFF)
+option(ZSTD_BUILD_PROGRAMS "BUILD PROGRAMS" OFF)
+add_subdirectory(deps/zstd-1.5.6/build/cmake EXCLUDE_FROM_ALL)
+list(APPEND CHDR_LIBS libzstd_static)
#--------------------------------------------------
# chdr
#--------------------------------------------------
@@ -83,6 +84,8 @@ if (BUILD_SHARED_LIBS)
target_compile_definitions(chdr PRIVATE _CRT_SECURE_NO_WARNINGS)
elseif(APPLE)
target_link_libraries(chdr PRIVATE -Wl,-dead_strip -Wl,-exported_symbol,_chd_*)
+ elseif(CMAKE_SYSTEM_NAME STREQUAL OpenBSD)
+ target_link_libraries(chdr PRIVATE -Wl,--version-script ${CMAKE_CURRENT_SOURCE_DIR}/src/link.T)
else()
target_link_libraries(chdr PRIVATE -Wl,--version-script ${CMAKE_CURRENT_SOURCE_DIR}/src/link.T -Wl,--no-undefined)
endif()
diff --git a/deps/libchdr/deps/lzma-19.00/CMakeLists.txt b/deps/libchdr/deps/lzma-19.00/CMakeLists.txt
deleted file mode 100644
index 291b253d..00000000
--- a/deps/libchdr/deps/lzma-19.00/CMakeLists.txt
+++ /dev/null
@@ -1,33 +0,0 @@
-add_library(lzma STATIC
- include/7zTypes.h
- include/Alloc.h
- include/Bra.h
- include/Compiler.h
- include/CpuArch.h
- include/Delta.h
- include/LzFind.h
- include/LzHash.h
- include/Lzma86.h
- include/LzmaDec.h
- include/LzmaEnc.h
- include/LzmaLib.h
- include/Precomp.h
- include/Sort.h
- src/Alloc.c
- src/Bra86.c
- src/BraIA64.c
- src/CpuArch.c
- src/Delta.c
- src/LzFind.c
- src/Lzma86Dec.c
- src/LzmaDec.c
- src/LzmaEnc.c
- src/Sort.c
-)
-
-target_compile_definitions(lzma PRIVATE _7ZIP_ST)
-
-target_include_directories(lzma PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include")
-target_include_directories(lzma INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include")
-
-set_target_properties(lzma PROPERTIES POSITION_INDEPENDENT_CODE ON)
diff --git a/deps/libchdr/deps/lzma-19.00/include/7zTypes.h b/deps/libchdr/deps/lzma-19.00/include/7zTypes.h
deleted file mode 100644
index 65b3af63..00000000
--- a/deps/libchdr/deps/lzma-19.00/include/7zTypes.h
+++ /dev/null
@@ -1,375 +0,0 @@
-/* 7zTypes.h -- Basic types
-2018-08-04 : Igor Pavlov : Public domain */
-
-#ifndef __7Z_TYPES_H
-#define __7Z_TYPES_H
-
-#ifdef _WIN32
-/* #include */
-#endif
-
-#include
-
-#ifndef EXTERN_C_BEGIN
-#ifdef __cplusplus
-#define EXTERN_C_BEGIN extern "C" {
-#define EXTERN_C_END }
-#else
-#define EXTERN_C_BEGIN
-#define EXTERN_C_END
-#endif
-#endif
-
-EXTERN_C_BEGIN
-
-#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_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)
-
-#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)))
-
-#endif
-
-
-#ifndef RINOK
-#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }
-#endif
-
-typedef unsigned char Byte;
-typedef short Int16;
-typedef unsigned short UInt16;
-
-#ifdef _LZMA_UINT32_IS_ULONG
-typedef long Int32;
-typedef unsigned long UInt32;
-#else
-typedef int Int32;
-typedef unsigned int UInt32;
-#endif
-
-#ifdef _SZ_NO_INT_64
-
-/* 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 unsigned long UInt64;
-
-#else
-
-#if defined(_MSC_VER) || defined(__BORLANDC__)
-typedef __int64 Int64;
-typedef unsigned __int64 UInt64;
-#define UINT64_CONST(n) n
-#else
-typedef long long int Int64;
-typedef unsigned long long int UInt64;
-#define UINT64_CONST(n) n ## ULL
-#endif
-
-#endif
-
-#ifdef _LZMA_NO_SYSTEM_SIZE_T
-typedef UInt32 SizeT;
-#else
-typedef size_t SizeT;
-#endif
-
-typedef int BoolInt;
-/* typedef BoolInt Bool; */
-#define True 1
-#define False 0
-
-
-#ifdef _WIN32
-#define MY_STD_CALL __stdcall
-#else
-#define MY_STD_CALL
-#endif
-
-#ifdef _MSC_VER
-
-#if _MSC_VER >= 1300
-#define MY_NO_INLINE __declspec(noinline)
-#else
-#define MY_NO_INLINE
-#endif
-
-#define MY_FORCE_INLINE __forceinline
-
-#define MY_CDECL __cdecl
-#define MY_FAST_CALL __fastcall
-
-#else
-
-#define MY_NO_INLINE
-#define MY_FORCE_INLINE
-#define MY_CDECL
-#define MY_FAST_CALL
-
-/* inline keyword : for C++ / C99 */
-
-/* GCC, clang: */
-/*
-#if defined (__GNUC__) && (__GNUC__ >= 4)
-#define MY_FORCE_INLINE __attribute__((always_inline))
-#define MY_NO_INLINE __attribute__((noinline))
-#endif
-*/
-
-#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 */
-};
-#define IByteIn_Read(p) (p)->Read(p)
-
-
-typedef struct IByteOut IByteOut;
-struct IByteOut
-{
- void (*Write)(const IByteOut *p, Byte 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 */
-};
-#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 */
-};
-#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);
-};
-#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);
-};
-
-#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_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 */
-
- /* the following variables must be set outside */
- Byte *buf;
- size_t bufSize;
-} CLookToRead2;
-
-void LookToRead2_CreateVTable(CLookToRead2 *p, int lookahead);
-
-#define LookToRead2_Init(p) { (p)->pos = (p)->size = 0; }
-
-
-typedef struct
-{
- ISeqInStream vt;
- const ILookInStream *realStream;
-} CSecToLook;
-
-void SecToLook_CreateVTable(CSecToLook *p);
-
-
-
-typedef struct
-{
- ISeqInStream vt;
- const ILookInStream *realStream;
-} CSecToRead;
-
-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)
-
-
-
-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 */
-};
-
-#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)
-
-
-
-
-
-#ifndef MY_offsetof
- #ifdef offsetof
- #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))
- #endif
-#endif
-
-
-
-#ifndef MY_container_of
-
-/*
-#define MY_container_of(ptr, type, m) container_of(ptr, type, m)
-#define MY_container_of(ptr, type, m) CONTAINING_RECORD(ptr, type, m)
-#define MY_container_of(ptr, type, m) ((type *)((char *)(ptr) - offsetof(type, m)))
-#define MY_container_of(ptr, type, m) (&((type *)0)->m == (ptr), ((type *)(((char *)(ptr)) - MY_offsetof(type, m))))
-*/
-
-/*
- GCC shows warning: "perhaps the 'offsetof' macro was used incorrectly"
- GCC 3.4.4 : classes with constructor
- 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)))
-
-
-#endif
-
-#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_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"\\"
-
-#else
-
-#define CHAR_PATH_SEPARATOR '/'
-#define WCHAR_PATH_SEPARATOR L'/'
-#define STRING_PATH_SEPARATOR "/"
-#define WSTRING_PATH_SEPARATOR L"/"
-
-#endif
-
-EXTERN_C_END
-
-#endif
diff --git a/deps/libchdr/deps/lzma-19.00/include/Alloc.h b/deps/libchdr/deps/lzma-19.00/include/Alloc.h
deleted file mode 100644
index 64823764..00000000
--- a/deps/libchdr/deps/lzma-19.00/include/Alloc.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/* Alloc.h -- Memory allocation functions
-2018-02-19 : Igor Pavlov : Public domain */
-
-#ifndef __COMMON_ALLOC_H
-#define __COMMON_ALLOC_H
-
-#include "7zTypes.h"
-
-EXTERN_C_BEGIN
-
-void *MyAlloc(size_t size);
-void MyFree(void *address);
-
-#ifdef _WIN32
-
-void SetLargePageSize();
-
-void *MidAlloc(size_t size);
-void MidFree(void *address);
-void *BigAlloc(size_t size);
-void BigFree(void *address);
-
-#else
-
-#define MidAlloc(size) MyAlloc(size)
-#define MidFree(address) MyFree(address)
-#define BigAlloc(size) MyAlloc(size)
-#define BigFree(address) MyFree(address)
-
-#endif
-
-extern const ISzAlloc g_Alloc;
-extern const ISzAlloc g_BigAlloc;
-extern const ISzAlloc g_MidAlloc;
-extern const ISzAlloc g_AlignedAlloc;
-
-
-typedef struct
-{
- ISzAlloc vt;
- ISzAllocPtr baseAlloc;
- unsigned numAlignBits; /* ((1 << numAlignBits) >= sizeof(void *)) */
- size_t offset; /* (offset == (k * sizeof(void *)) && offset < (1 << numAlignBits) */
-} CAlignOffsetAlloc;
-
-void AlignOffsetAlloc_CreateVTable(CAlignOffsetAlloc *p);
-
-
-EXTERN_C_END
-
-#endif
diff --git a/deps/libchdr/deps/lzma-19.00/include/Bra.h b/deps/libchdr/deps/lzma-19.00/include/Bra.h
deleted file mode 100644
index 855e37a6..00000000
--- a/deps/libchdr/deps/lzma-19.00/include/Bra.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/* Bra.h -- Branch converters for executables
-2013-01-18 : Igor Pavlov : Public domain */
-
-#ifndef __BRA_H
-#define __BRA_H
-
-#include "7zTypes.h"
-
-EXTERN_C_BEGIN
-
-/*
-These functions convert relative addresses to absolute addresses
-in CALL instructions to increase the compression ratio.
-
- In:
- data - data buffer
- size - size of data
- ip - current virtual Instruction Pinter (IP) value
- state - state variable for x86 converter
- encoding - 0 (for decoding), 1 (for encoding)
-
- Out:
- state - state variable for x86 converter
-
- Returns:
- The number of processed bytes. If you call these functions with multiple calls,
- you must start next call with first byte after block of processed bytes.
-
- Type Endian Alignment LookAhead
-
- x86 little 1 4
- ARMT little 2 2
- ARM little 4 0
- PPC big 4 0
- SPARC big 4 0
- IA64 little 16 0
-
- size must be >= Alignment + LookAhead, if it's not last block.
- If (size < Alignment + LookAhead), converter returns 0.
-
- Example:
-
- UInt32 ip = 0;
- for ()
- {
- ; size must be >= Alignment + LookAhead, if it's not last block
- SizeT processed = Convert(data, size, ip, 1);
- data += processed;
- size -= processed;
- ip += processed;
- }
-*/
-
-#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
-
-#endif
diff --git a/deps/libchdr/deps/lzma-19.00/include/Compiler.h b/deps/libchdr/deps/lzma-19.00/include/Compiler.h
deleted file mode 100644
index 0cc409d8..00000000
--- a/deps/libchdr/deps/lzma-19.00/include/Compiler.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/* Compiler.h
-2017-04-03 : Igor Pavlov : Public domain */
-
-#ifndef __7Z_COMPILER_H
-#define __7Z_COMPILER_H
-
-#ifdef _MSC_VER
-
- #ifdef UNDER_CE
- #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
-
- #if _MSC_VER >= 1300
- #pragma warning(disable : 4996) // This function or variable may be unsafe
- #else
- #pragma warning(disable : 4511) // copy constructor could not be generated
- #pragma warning(disable : 4512) // assignment operator could not be generated
- #pragma warning(disable : 4514) // unreferenced inline function has been removed
- #pragma warning(disable : 4702) // unreachable code
- #pragma warning(disable : 4710) // not inlined
- #pragma warning(disable : 4714) // function marked as __forceinline not inlined
- #pragma warning(disable : 4786) // identifier was truncated to '255' characters in the debug information
- #endif
-
-#endif
-
-#define UNUSED_VAR(x) (void)x;
-/* #define UNUSED_VAR(x) x=x; */
-
-#endif
diff --git a/deps/libchdr/deps/lzma-19.00/include/CpuArch.h b/deps/libchdr/deps/lzma-19.00/include/CpuArch.h
deleted file mode 100644
index bd429388..00000000
--- a/deps/libchdr/deps/lzma-19.00/include/CpuArch.h
+++ /dev/null
@@ -1,336 +0,0 @@
-/* CpuArch.h -- CPU specific code
-2018-02-18 : Igor Pavlov : Public domain */
-
-#ifndef __CPU_ARCH_H
-#define __CPU_ARCH_H
-
-#include "7zTypes.h"
-
-EXTERN_C_BEGIN
-
-/*
-MY_CPU_LE means that CPU is LITTLE ENDIAN.
-MY_CPU_BE means that CPU is BIG ENDIAN.
-If MY_CPU_LE and MY_CPU_BE are not defined, we don't know about ENDIANNESS of platform.
-
-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
- #ifdef __ILP32__
- #define MY_CPU_NAME "x32"
- #else
- #define MY_CPU_NAME "x64"
- #endif
- #define MY_CPU_64BIT
-#endif
-
-
-#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
-#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
-#endif
-
-
-#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 */
-#endif
-
-
-#if defined(__ppc64__) \
- || defined(__powerpc64__)
- #ifdef __ILP32__
- #define MY_CPU_NAME "ppc64-32"
- #else
- #define MY_CPU_NAME "ppc64"
- #endif
- #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 */
-#endif
-
-
-#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
- #endif
-
- #ifdef MY_CPU_ARM64
- #define MY_CPU_ARM64_LE
- #endif
-
- #ifdef _M_IA64
- #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
-#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
-#endif
-
-
-#if defined(MY_CPU_LE) && defined(MY_CPU_BE)
- #error Stop_Compiling_Bad_Endian
-#endif
-
-
-#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"
- #else
- /*
- #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
- #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 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) ( \
- ((const Byte *)(p))[0] | \
- ((UInt16)((const Byte *)(p))[1] << 8) ))
-
-#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 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); \
- _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); \
- SetUi32(_ppp2_ , (UInt32)_vvv2_); \
- SetUi32(_ppp2_ + 4, (UInt32)(_vvv2_ >> 32)); }
-
-#endif
-
-#ifdef __has_builtin
- #define MY__has_builtin(x) __has_builtin(x)
-#else
- #define MY__has_builtin(x) 0
-#endif
-
-#if defined(MY_CPU_LE_UNALIGN) && /* defined(_WIN64) && */ (_MSC_VER >= 1300)
-
-/* Note: we use bswap instruction, that is unsupported in 386 cpu */
-
-#include
-
-#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 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)) )
-
-/* #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 SetBe32(p, v) (*(UInt32 *)(void *)(p)) = __builtin_bswap32(v)
-
-#else
-
-#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 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); \
- _ppp_[3] = (Byte)_vvv_; }
-
-#endif
-
-
-#ifndef GetBe16
-
-#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;
-} Cx86cpuid;
-
-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();
-
-#endif
-
-EXTERN_C_END
-
-#endif
diff --git a/deps/libchdr/deps/lzma-19.00/include/LzFind.h b/deps/libchdr/deps/lzma-19.00/include/LzFind.h
deleted file mode 100644
index 42c13be1..00000000
--- a/deps/libchdr/deps/lzma-19.00/include/LzFind.h
+++ /dev/null
@@ -1,121 +0,0 @@
-/* LzFind.h -- Match finder for LZ algorithms
-2017-06-10 : Igor Pavlov : Public domain */
-
-#ifndef __LZ_FIND_H
-#define __LZ_FIND_H
-
-#include "7zTypes.h"
-
-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;
-} CMatchFinder;
-
-#define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer)
-
-#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);
-
-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);
-
-/*
-Conditions:
- Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func.
- 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;
-} 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);
-
-EXTERN_C_END
-
-#endif
diff --git a/deps/libchdr/deps/lzma-19.00/include/LzHash.h b/deps/libchdr/deps/lzma-19.00/include/LzHash.h
deleted file mode 100644
index e7c94230..00000000
--- a/deps/libchdr/deps/lzma-19.00/include/LzHash.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/* LzHash.h -- HASH functions for LZ algorithms
-2015-04-12 : Igor Pavlov : Public domain */
-
-#ifndef __LZ_HASH_H
-#define __LZ_HASH_H
-
-#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 HASH2_CALC hv = cur[0] | ((UInt32)cur[1] << 8);
-
-#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 { \
- 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 { \
- UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
- h2 = temp & (kHash2Size - 1); \
- temp ^= ((UInt32)cur[2] << 8); \
- h3 = temp & (kHash3Size - 1); \
- temp ^= (p->crc[cur[3]] << 5); \
- h4 = temp & (kHash4Size - 1); \
- 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 MT_HASH2_CALC \
- h2 = (p->crc[cur[0]] ^ cur[1]) & (kHash2Size - 1);
-
-#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 { \
- UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
- h2 = temp & (kHash2Size - 1); \
- temp ^= ((UInt32)cur[2] << 8); \
- h3 = temp & (kHash3Size - 1); \
- h4 = (temp ^ (p->crc[cur[3]] << 5)) & (kHash4Size - 1); }
-
-#endif
diff --git a/deps/libchdr/deps/lzma-19.00/include/LzmaDec.h b/deps/libchdr/deps/lzma-19.00/include/LzmaDec.h
deleted file mode 100644
index 1f0927ab..00000000
--- a/deps/libchdr/deps/lzma-19.00/include/LzmaDec.h
+++ /dev/null
@@ -1,234 +0,0 @@
-/* LzmaDec.h -- LZMA Decoder
-2018-04-21 : Igor Pavlov : Public domain */
-
-#ifndef __LZMA_DEC_H
-#define __LZMA_DEC_H
-
-#include "7zTypes.h"
-
-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 */
-
-typedef
-#ifdef _LZMA_PROB32
- UInt32
-#else
- UInt16
-#endif
- CLzmaProb;
-
-
-/* ---------- LZMA Properties ---------- */
-
-#define LZMA_PROPS_SIZE 5
-
-typedef struct _CLzmaProps
-{
- Byte lc;
- Byte lp;
- Byte pb;
- Byte _pad_;
- UInt32 dicSize;
-} CLzmaProps;
-
-/* LzmaProps_Decode - decodes properties
-Returns:
- SZ_OK
- SZ_ERROR_UNSUPPORTED - Unsupported properties
-*/
-
-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
-
-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];
-} CLzmaDec;
-
-#define LzmaDec_Construct(p) { (p)->dic = NULL; (p)->probs = NULL; }
-
-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
-{
- LZMA_FINISH_ANY, /* finish at any point */
- LZMA_FINISH_END /* block must be finished at the end */
-} ELzmaFinishMode;
-
-/* ELzmaFinishMode has meaning only if the decoding reaches output limit !!!
-
- You must use LZMA_FINISH_END, when you know that current output buffer
- covers last bytes of block. In other cases you must use LZMA_FINISH_ANY.
-
- If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK,
- and output value of destLen will be less than output buffer size limit.
- You can check status result also.
-
- You can use multiple checks to test data integrity after full decompression:
- 1) Check Result and "status" variable.
- 2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.
- 3) Check that output(srcLen) = compressedSize, if you know real compressedSize.
- You must use correct finish mode in that case. */
-
-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 */
- LZMA_STATUS_NEEDS_MORE_INPUT, /* you must provide more input bytes */
- LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK /* there is probability that stream was finished without end mark */
-} ELzmaStatus;
-
-/* ELzmaStatus is used only as output value for function call */
-
-
-/* ---------- Interfaces ---------- */
-
-/* There are 3 levels of interfaces:
- 1) Dictionary Interface
- 2) Buffer Interface
- 3) One Call Interface
- 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
- You can use variant 2, if you set dictionary buffer manually.
- For Buffer Interface you must always use variant 1.
-
-LzmaDec_Allocate* can return:
- SZ_OK
- SZ_ERROR_MEM - Memory allocation error
- 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);
-
-/* ---------- Dictionary Interface ---------- */
-
-/* You can use it, if you want to eliminate the overhead for data copying from
- dictionary to some other external buffer.
- You must work with CLzmaDec variables directly in this interface.
-
- STEPS:
- LzmaDec_Construct()
- LzmaDec_Allocate()
- for (each new stream)
- {
- LzmaDec_Init()
- while (it needs more decompression)
- {
- LzmaDec_DecodeToDic()
- use data from CLzmaDec::dic and update CLzmaDec::dicPos
- }
- }
- LzmaDec_Free()
-*/
-
-/* LzmaDec_DecodeToDic
-
- The decoding to internal dictionary buffer (CLzmaDec::dic).
- You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!!
-
-finishMode:
- It has meaning only if the decoding reaches output limit (dicLimit).
- LZMA_FINISH_ANY - Decode just dicLimit bytes.
- LZMA_FINISH_END - Stream must be finished after dicLimit.
-
-Returns:
- SZ_OK
- status:
- LZMA_STATUS_FINISHED_WITH_MARK
- LZMA_STATUS_NOT_FINISHED
- LZMA_STATUS_NEEDS_MORE_INPUT
- LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
- SZ_ERROR_DATA - Data error
-*/
-
-SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit,
- const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
-
-
-/* ---------- Buffer Interface ---------- */
-
-/* It's zlib-like interface.
- See LzmaDec_DecodeToDic description for information about STEPS and return results,
- but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need
- to work with CLzmaDec variables manually.
-
-finishMode:
- It has meaning only if the decoding reaches output limit (*destLen).
- LZMA_FINISH_ANY - Decode just destLen bytes.
- 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);
-
-
-/* ---------- One Call Interface ---------- */
-
-/* LzmaDecode
-
-finishMode:
- It has meaning only if the decoding reaches output limit (*destLen).
- LZMA_FINISH_ANY - Decode just destLen bytes.
- LZMA_FINISH_END - Stream must be finished after (*destLen).
-
-Returns:
- SZ_OK
- status:
- LZMA_STATUS_FINISHED_WITH_MARK
- LZMA_STATUS_NOT_FINISHED
- LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
- SZ_ERROR_DATA - Data error
- SZ_ERROR_MEM - Memory allocation error
- SZ_ERROR_UNSUPPORTED - Unsupported properties
- 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);
-
-EXTERN_C_END
-
-#endif
diff --git a/deps/libchdr/deps/lzma-19.00/include/LzmaEnc.h b/deps/libchdr/deps/lzma-19.00/include/LzmaEnc.h
deleted file mode 100644
index 9194ee57..00000000
--- a/deps/libchdr/deps/lzma-19.00/include/LzmaEnc.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/* LzmaEnc.h -- LZMA Encoder
-2017-07-27 : Igor Pavlov : Public domain */
-
-#ifndef __LZMA_ENC_H
-#define __LZMA_ENC_H
-
-#include "7zTypes.h"
-
-EXTERN_C_BEGIN
-
-#define LZMA_PROPS_SIZE 5
-
-typedef struct _CLzmaEncProps
-{
- int level; /* 0 <= level <= 9 */
- UInt32 dictSize; /* (1 << 12) <= dictSize <= (1 << 27) for 32-bit version
- (1 << 12) <= dictSize <= (3 << 29) for 64-bit version
- default = (1 << 24) */
- int lc; /* 0 <= lc <= 8, default = 3 */
- int lp; /* 0 <= lp <= 4, default = 0 */
- int pb; /* 0 <= pb <= 4, default = 2 */
- int algo; /* 0 - fast, 1 - normal, default = 1 */
- int fb; /* 5 <= fb <= 273, default = 32 */
- int btMode; /* 0 - hashChain Mode, 1 - binTree mode - normal, default = 1 */
- int numHashBytes; /* 2, 3 or 4, default = 4 */
- UInt32 mc; /* 1 <= mc <= (1 << 30), default = 32 */
- unsigned writeEndMark; /* 0 - do not write EOPM, 1 - write EOPM, default = 0 */
- int numThreads; /* 1 or 2, default = 2 */
-
- UInt64 reduceSize; /* estimated size of data that will be compressed. default = (UInt64)(Int64)-1.
- Encoder uses this value to reduce dictionary size */
-} CLzmaEncProps;
-
-void LzmaEncProps_Init(CLzmaEncProps *p);
-void LzmaEncProps_Normalize(CLzmaEncProps *p);
-UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2);
-
-
-/* ---------- CLzmaEncHandle Interface ---------- */
-
-/* LzmaEnc* functions can return the following exit codes:
-SRes:
- SZ_OK - OK
- SZ_ERROR_MEM - Memory allocation error
- SZ_ERROR_PARAM - Incorrect paramater in props
- SZ_ERROR_WRITE - ISeqOutStream write callback error
- SZ_ERROR_OUTPUT_EOF - output buffer overflow - version with (Byte *) output
- SZ_ERROR_PROGRESS - some break from progress callback
- SZ_ERROR_THREAD - error in multithreading functions (only for Mt version)
-*/
-
-typedef void * CLzmaEncHandle;
-
-CLzmaEncHandle LzmaEnc_Create(ISzAllocPtr alloc);
-void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAllocPtr alloc, ISzAllocPtr allocBig);
-
-SRes LzmaEnc_SetProps(CLzmaEncHandle p, const CLzmaEncProps *props);
-void LzmaEnc_SetDataSize(CLzmaEncHandle p, UInt64 expectedDataSiize);
-SRes LzmaEnc_WriteProperties(CLzmaEncHandle p, Byte *properties, SizeT *size);
-unsigned LzmaEnc_IsWriteEndMark(CLzmaEncHandle p);
-
-SRes LzmaEnc_Encode(CLzmaEncHandle p, ISeqOutStream *outStream, ISeqInStream *inStream,
- ICompressProgress *progress, ISzAllocPtr alloc, ISzAllocPtr allocBig);
-SRes LzmaEnc_MemEncode(CLzmaEncHandle p, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
- int writeEndMark, ICompressProgress *progress, ISzAllocPtr alloc, ISzAllocPtr allocBig);
-
-
-/* ---------- One Call Interface ---------- */
-
-SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
- const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
- ICompressProgress *progress, ISzAllocPtr alloc, ISzAllocPtr allocBig);
-
-EXTERN_C_END
-
-#endif
diff --git a/deps/libchdr/deps/lzma-19.00/include/LzmaLib.h b/deps/libchdr/deps/lzma-19.00/include/LzmaLib.h
deleted file mode 100644
index 88fa87d3..00000000
--- a/deps/libchdr/deps/lzma-19.00/include/LzmaLib.h
+++ /dev/null
@@ -1,131 +0,0 @@
-/* LzmaLib.h -- LZMA library interface
-2013-01-18 : Igor Pavlov : Public domain */
-
-#ifndef __LZMA_LIB_H
-#define __LZMA_LIB_H
-
-#include "7zTypes.h"
-
-EXTERN_C_BEGIN
-
-#define MY_STDAPI int MY_STD_CALL
-
-#define LZMA_PROPS_SIZE 5
-
-/*
-RAM requirements for LZMA:
- for compression: (dictSize * 11.5 + 6 MB) + state_size
- for decompression: dictSize + state_size
- state_size = (4 + (1.5 << (lc + lp))) KB
- by default (lc=3, lp=0), state_size = 16 KB.
-
-LZMA properties (5 bytes) format
- Offset Size Description
- 0 1 lc, lp and pb in encoded form.
- 1 4 dictSize (little endian).
-*/
-
-/*
-LzmaCompress
-------------
-
-outPropsSize -
- In: the pointer to the size of outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5.
- Out: the pointer to the size of written properties in outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5.
-
- LZMA Encoder will use defult values for any parameter, if it is
- -1 for any from: level, loc, lp, pb, fb, numThreads
- 0 for dictSize
-
-level - compression level: 0 <= level <= 9;
-
- level dictSize algo fb
- 0: 16 KB 0 32
- 1: 64 KB 0 32
- 2: 256 KB 0 32
- 3: 1 MB 0 32
- 4: 4 MB 0 32
- 5: 16 MB 1 32
- 6: 32 MB 1 32
- 7+: 64 MB 1 64
-
- The default value for "level" is 5.
-
- algo = 0 means fast method
- algo = 1 means normal method
-
-dictSize - The dictionary size in bytes. The maximum value is
- 128 MB = (1 << 27) bytes for 32-bit version
- 1 GB = (1 << 30) bytes for 64-bit version
- The default value is 16 MB = (1 << 24) bytes.
- It's recommended to use the dictionary that is larger than 4 KB and
- that can be calculated as (1 << N) or (3 << N) sizes.
-
-lc - The number of literal context bits (high bits of previous literal).
- It can be in the range from 0 to 8. The default value is 3.
- Sometimes lc=4 gives the gain for big files.
-
-lp - The number of literal pos bits (low bits of current position for literals).
- It can be in the range from 0 to 4. The default value is 0.
- The lp switch is intended for periodical data when the period is equal to 2^lp.
- For example, for 32-bit (4 bytes) periodical data you can use lp=2. Often it's
- better to set lc=0, if you change lp switch.
-
-pb - The number of pos bits (low bits of current position).
- It can be in the range from 0 to 4. The default value is 2.
- The pb switch is intended for periodical data when the period is equal 2^pb.
-
-fb - Word size (the number of fast bytes).
- It can be in the range from 5 to 273. The default value is 32.
- Usually, a big number gives a little bit better compression ratio and
- slower compression process.
-
-numThreads - The number of thereads. 1 or 2. The default value is 2.
- Fast mode (algo = 0) can use only 1 thread.
-
-Out:
- destLen - processed output size
-Returns:
- SZ_OK - OK
- SZ_ERROR_MEM - Memory allocation error
- SZ_ERROR_PARAM - Incorrect paramater
- SZ_ERROR_OUTPUT_EOF - output buffer overflow
- SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)
-*/
-
-MY_STDAPI LzmaCompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t srcLen,
- unsigned char *outProps, size_t *outPropsSize, /* *outPropsSize must be = 5 */
- int level, /* 0 <= level <= 9, default = 5 */
- unsigned dictSize, /* default = (1 << 24) */
- int lc, /* 0 <= lc <= 8, default = 3 */
- int lp, /* 0 <= lp <= 4, default = 0 */
- int pb, /* 0 <= pb <= 4, default = 2 */
- int fb, /* 5 <= fb <= 273, default = 32 */
- int numThreads /* 1 or 2, default = 2 */
- );
-
-/*
-LzmaUncompress
---------------
-In:
- dest - output data
- destLen - output data size
- src - input data
- srcLen - input data size
-Out:
- destLen - processed output size
- srcLen - processed input size
-Returns:
- SZ_OK - OK
- SZ_ERROR_DATA - Data error
- SZ_ERROR_MEM - Memory allocation arror
- SZ_ERROR_UNSUPPORTED - Unsupported properties
- SZ_ERROR_INPUT_EOF - it needs more bytes in input buffer (src)
-*/
-
-MY_STDAPI LzmaUncompress(unsigned char *dest, size_t *destLen, const unsigned char *src, SizeT *srcLen,
- const unsigned char *props, size_t propsSize);
-
-EXTERN_C_END
-
-#endif
diff --git a/deps/libchdr/deps/lzma-19.00/include/Precomp.h b/deps/libchdr/deps/lzma-19.00/include/Precomp.h
deleted file mode 100644
index e8ff8b40..00000000
--- a/deps/libchdr/deps/lzma-19.00/include/Precomp.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/* Precomp.h -- StdAfx
-2013-11-12 : Igor Pavlov : Public domain */
-
-#ifndef __7Z_PRECOMP_H
-#define __7Z_PRECOMP_H
-
-#include "Compiler.h"
-/* #include "7zTypes.h" */
-
-#endif
diff --git a/deps/libchdr/deps/lzma-19.00/lzma-history.txt b/deps/libchdr/deps/lzma-19.00/lzma-history.txt
deleted file mode 100644
index 48ee7481..00000000
--- a/deps/libchdr/deps/lzma-19.00/lzma-history.txt
+++ /dev/null
@@ -1,446 +0,0 @@
-HISTORY of the LZMA SDK
------------------------
-
-19.00 2019-02-21
--------------------------
-- Encryption strength for 7z archives was increased:
- the size of random initialization vector was increased from 64-bit to 128-bit,
- and the pseudo-random number generator was improved.
-- The bug in 7zIn.c code was fixed.
-
-
-18.06 2018-12-30
--------------------------
-- The speed for LZMA/LZMA2 compressing was increased by 3-10%,
- and there are minor changes in compression ratio.
-- Some bugs were fixed.
-- The bug in 7-Zip 18.02-18.05 was fixed:
- There was memory leak in multithreading xz decoder - XzDecMt_Decode(),
- if xz stream contains only one block.
-- The changes for MSVS compiler makefiles:
- - the makefiles now use "PLATFORM" macroname with values (x64, x86, arm64)
- instead of "CPU" macroname with values (AMD64, ARM64).
- - the makefiles by default now use static version of the run-time library.
-
-
-18.05 2018-04-30
--------------------------
-- The speed for LZMA/LZMA2 compressing was increased
- by 8% for fastest/fast compression levels and
- by 3% for normal/maximum compression levels.
-- Previous versions of 7-Zip could work incorrectly in "Large memory pages" mode in
- Windows 10 because of some BUG with "Large Pages" in Windows 10.
- Now 7-Zip doesn't use "Large Pages" on Windows 10 up to revision 1709 (16299).
-- The BUG was fixed in Lzma2Enc.c
- Lzma2Enc_Encode2() function worked incorretly,
- if (inStream == NULL) and the number of block threads is more than 1.
-
-
-18.03 beta 2018-03-04
--------------------------
-- Asm\x86\LzmaDecOpt.asm: new optimized LZMA decoder written in asm
- for x64 with about 30% higher speed than main version of LZMA decoder written in C.
-- The speed for single-thread LZMA/LZMA2 decoder written in C was increased by 3%.
-- 7-Zip now can use multi-threading for 7z/LZMA2 decoding,
- if there are multiple independent data chunks in LZMA2 stream.
-- 7-Zip now can use multi-threading for xz decoding,
- if there are multiple blocks in xz stream.
-
-
-18.01 2019-01-28
--------------------------
-- The BUG in 17.01 - 18.00 beta was fixed:
- XzDec.c : random block unpacking and XzUnpacker_IsBlockFinished()
- didn't work correctly for xz archives without checksum (CRC).
-
-
-18.00 beta 2019-01-10
--------------------------
-- The BUG in xz encoder was fixed:
- There was memory leak of 16 KB for each file compressed with
- xz compression method, if additional filter was used.
-
-
-17.01 beta 2017-08-28
--------------------------
-- Minor speed optimization for LZMA2 (xz and 7z) multi-threading compression.
- 7-Zip now uses additional memory buffers for multi-block LZMA2 compression.
- CPU utilization was slightly improved.
-- 7-zip now creates multi-block xz archives by default. Block size can be
- specified with -ms[Size]{m|g} switch.
-- xz decoder now can unpack random block from multi-block xz archives.
-- 7-Zip command line: @listfile now doesn't work after -- switch.
- Use -i@listfile before -- switch instead.
-- The BUGs were fixed:
- 7-Zip 17.00 beta crashed for commands that write anti-item to 7z archive.
-
-
-17.00 beta 2017-04-29
--------------------------
-- NewHandler.h / NewHandler.cpp:
- now it redefines operator new() only for old MSVC compilers (_MSC_VER < 1900).
-- C/7zTypes.h : the names of variables in interface structures were changed (vt).
-- Some bugs were fixed. 7-Zip could crash in some cases.
-- Some internal changes in code.
-
-
-16.04 2016-10-04
--------------------------
-- The bug was fixed in DllSecur.c.
-
-
-16.03 2016-09-28
--------------------------
-- SFX modules now use some protection against DLL preloading attack.
-- Some bugs in 7z code were fixed.
-
-
-16.02 2016-05-21
--------------------------
-- The BUG in 16.00 - 16.01 was fixed:
- Split Handler (SplitHandler.cpp) returned incorrect
- total size value (kpidSize) for split archives.
-
-
-16.01 2016-05-19
--------------------------
-- Some internal changes to reduce the number of compiler warnings.
-
-
-16.00 2016-05-10
--------------------------
-- Some bugs were fixed.
-
-
-15.12 2015-11-19
--------------------------
-- The BUG in C version of 7z decoder was fixed:
- 7zDec.c : SzDecodeLzma2()
- 7z decoder could mistakenly report about decoding error for some 7z archives
- that use LZMA2 compression method.
- The probability to get that mistaken decoding error report was about
- one error per 16384 solid blocks for solid blocks larger than 16 KB (compressed size).
-- The BUG (in 9.26-15.11) in C version of 7z decoder was fixed:
- 7zArcIn.c : SzReadHeader2()
- 7z decoder worked incorrectly for 7z archives that contain
- empty solid blocks, that can be placed to 7z archive, if some file is
- unavailable for reading during archive creation.
-
-
-15.09 beta 2015-10-16
--------------------------
-- The BUG in LZMA / LZMA2 encoding code was fixed.
- The BUG in LzFind.c::MatchFinder_ReadBlock() function.
- If input data size is larger than (4 GiB - dictionary_size),
- the following code worked incorrectly:
- - LZMA : LzmaEnc_MemEncode(), LzmaEncode() : LZMA encoding functions
- for compressing from memory to memory.
- That BUG is not related to LZMA encoder version that works via streams.
- - LZMA2 : multi-threaded version of LZMA2 encoder worked incorrectly, if
- default value of chunk size (CLzma2EncProps::blockSize) is changed
- to value larger than (4 GiB - dictionary_size).
-
-
-9.38 beta 2015-01-03
--------------------------
-- The BUG in 9.31-9.37 was fixed:
- IArchiveGetRawProps interface was disabled for 7z archives.
-- The BUG in 9.26-9.36 was fixed:
- Some code in CPP\7zip\Archive\7z\ worked correctly only under Windows.
-
-
-9.36 beta 2014-12-26
--------------------------
-- The BUG in command line version was fixed:
- 7-Zip created temporary archive in current folder during update archive
- operation, if -w{Path} switch was not specified.
- The fixed 7-Zip creates temporary archive in folder that contains updated archive.
-- The BUG in 9.33-9.35 was fixed:
- 7-Zip silently ignored file reading errors during 7z or gz archive creation,
- and the created archive contained only part of file that was read before error.
- The fixed 7-Zip stops archive creation and it reports about error.
-
-
-9.35 beta 2014-12-07
--------------------------
-- 7zr.exe now support AES encryption.
-- SFX mudules were added to LZMA SDK
-- Some bugs were fixed.
-
-
-9.21 beta 2011-04-11
--------------------------
-- New class FString for file names at file systems.
-- Speed optimization in CRC code for big-endian CPUs.
-- The BUG in Lzma2Dec.c was fixed:
- Lzma2Decode function didn't work.
-
-
-9.18 beta 2010-11-02
--------------------------
-- New small SFX module for installers (SfxSetup).
-
-
-9.12 beta 2010-03-24
--------------------------
-- The BUG in LZMA SDK 9.* was fixed: LZMA2 codec didn't work,
- if more than 10 threads were used (or more than 20 threads in some modes).
-
-
-9.11 beta 2010-03-15
--------------------------
-- PPMd compression method support
-
-
-9.09 2009-12-12
--------------------------
-- The bug was fixed:
- Utf16_To_Utf8 funstions in UTFConvert.cpp and 7zMain.c
- incorrectly converted surrogate characters (the code >= 0x10000) to UTF-8.
-- Some bugs were fixed
-
-
-9.06 2009-08-17
--------------------------
-- Some changes in ANSI-C 7z Decoder interfaces.
-
-
-9.04 2009-05-30
--------------------------
-- LZMA2 compression method support
-- xz format support
-
-
-4.65 2009-02-03
--------------------------
-- Some minor fixes
-
-
-4.63 2008-12-31
--------------------------
-- Some minor fixes
-
-
-4.61 beta 2008-11-23
--------------------------
-- The bug in ANSI-C LZMA Decoder was fixed:
- If encoded stream was corrupted, decoder could access memory
- outside of allocated range.
-- Some changes in ANSI-C 7z Decoder interfaces.
-- LZMA SDK is placed in the public domain.
-
-
-4.60 beta 2008-08-19
--------------------------
-- Some minor fixes.
-
-
-4.59 beta 2008-08-13
--------------------------
-- The bug was fixed:
- LZMA Encoder in fast compression mode could access memory outside of
- allocated range in some rare cases.
-
-
-4.58 beta 2008-05-05
--------------------------
-- ANSI-C LZMA Decoder was rewritten for speed optimizations.
-- ANSI-C LZMA Encoder was included to LZMA SDK.
-- C++ LZMA code now is just wrapper over ANSI-C code.
-
-
-4.57 2007-12-12
--------------------------
-- Speed optimizations in Ñ++ LZMA Decoder.
-- Small changes for more compatibility with some C/C++ compilers.
-
-
-4.49 beta 2007-07-05
--------------------------
-- .7z ANSI-C Decoder:
- - now it supports BCJ and BCJ2 filters
- - now it supports files larger than 4 GB.
- - now it supports "Last Write Time" field for files.
-- C++ code for .7z archives compressing/decompressing from 7-zip
- was included to LZMA SDK.
-
-
-4.43 2006-06-04
--------------------------
-- Small changes for more compatibility with some C/C++ compilers.
-
-
-4.42 2006-05-15
--------------------------
-- Small changes in .h files in ANSI-C version.
-
-
-4.39 beta 2006-04-14
--------------------------
-- The bug in versions 4.33b:4.38b was fixed:
- C++ version of LZMA encoder could not correctly compress
- files larger than 2 GB with HC4 match finder (-mfhc4).
-
-
-4.37 beta 2005-04-06
--------------------------
-- Fixes in C++ code: code could no be compiled if _NO_EXCEPTIONS was defined.
-
-
-4.35 beta 2005-03-02
--------------------------
-- The bug was fixed in C++ version of LZMA Decoder:
- If encoded stream was corrupted, decoder could access memory
- outside of allocated range.
-
-
-4.34 beta 2006-02-27
--------------------------
-- Compressing speed and memory requirements for compressing were increased
-- LZMA now can use only these match finders: HC4, BT2, BT3, BT4
-
-
-4.32 2005-12-09
--------------------------
-- Java version of LZMA SDK was included
-
-
-4.30 2005-11-20
--------------------------
-- Compression ratio was improved in -a2 mode
-- Speed optimizations for compressing in -a2 mode
-- -fb switch now supports values up to 273
-- The bug in 7z_C (7zIn.c) was fixed:
- It used Alloc/Free functions from different memory pools.
- So if program used two memory pools, it worked incorrectly.
-- 7z_C: .7z format supporting was improved
-- LZMA# SDK (C#.NET version) was included
-
-
-4.27 (Updated) 2005-09-21
--------------------------
-- Some GUIDs/interfaces in C++ were changed.
- IStream.h:
- ISequentialInStream::Read now works as old ReadPart
- ISequentialOutStream::Write now works as old WritePart
-
-
-4.27 2005-08-07
--------------------------
-- The bug in LzmaDecodeSize.c was fixed:
- if _LZMA_IN_CB and _LZMA_OUT_READ were defined,
- decompressing worked incorrectly.
-
-
-4.26 2005-08-05
--------------------------
-- Fixes in 7z_C code and LzmaTest.c:
- previous versions could work incorrectly,
- if malloc(0) returns 0
-
-
-4.23 2005-06-29
--------------------------
-- Small fixes in C++ code
-
-
-4.22 2005-06-10
--------------------------
-- Small fixes
-
-
-4.21 2005-06-08
--------------------------
-- Interfaces for ANSI-C LZMA Decoder (LzmaDecode.c) were changed
-- New additional version of ANSI-C LZMA Decoder with zlib-like interface:
- - LzmaStateDecode.h
- - LzmaStateDecode.c
- - LzmaStateTest.c
-- ANSI-C LZMA Decoder now can decompress files larger than 4 GB
-
-
-4.17 2005-04-18
--------------------------
-- New example for RAM->RAM compressing/decompressing:
- LZMA + BCJ (filter for x86 code):
- - LzmaRam.h
- - LzmaRam.cpp
- - LzmaRamDecode.h
- - LzmaRamDecode.c
- - -f86 switch for lzma.exe
-
-
-4.16 2005-03-29
--------------------------
-- The bug was fixed in LzmaDecode.c (ANSI-C LZMA Decoder):
- If _LZMA_OUT_READ was defined, and if encoded stream was corrupted,
- decoder could access memory outside of allocated range.
-- Speed optimization of ANSI-C LZMA Decoder (now it's about 20% faster).
- Old version of LZMA Decoder now is in file LzmaDecodeSize.c.
- LzmaDecodeSize.c can provide slightly smaller code than LzmaDecode.c
-- Small speed optimization in LZMA C++ code
-- filter for SPARC's code was added
-- Simplified version of .7z ANSI-C Decoder was included
-
-
-4.06 2004-09-05
--------------------------
-- The bug in v4.05 was fixed:
- LZMA-Encoder didn't release output stream in some cases.
-
-
-4.05 2004-08-25
--------------------------
-- Source code of filters for x86, IA-64, ARM, ARM-Thumb
- and PowerPC code was included to SDK
-- Some internal minor changes
-
-
-4.04 2004-07-28
--------------------------
-- More compatibility with some C++ compilers
-
-
-4.03 2004-06-18
--------------------------
-- "Benchmark" command was added. It measures compressing
- and decompressing speed and shows rating values.
- Also it checks hardware errors.
-
-
-4.02 2004-06-10
--------------------------
-- C++ LZMA Encoder/Decoder code now is more portable
- and it can be compiled by GCC on Linux.
-
-
-4.01 2004-02-15
--------------------------
-- Some detection of data corruption was enabled.
- LzmaDecode.c / RangeDecoderReadByte
- .....
- {
- rd->ExtraBytes = 1;
- return 0xFF;
- }
-
-
-4.00 2004-02-13
--------------------------
-- Original version of LZMA SDK
-
-
-
-HISTORY of the LZMA
--------------------
- 2001-2008: Improvements to LZMA compressing/decompressing code,
- keeping compatibility with original LZMA format
- 1996-2001: Development of LZMA compression format
-
- Some milestones:
-
- 2001-08-30: LZMA compression was added to 7-Zip
- 1999-01-02: First version of 7-Zip was released
-
-
-End of document
diff --git a/deps/libchdr/deps/lzma-19.00/lzma.txt b/deps/libchdr/deps/lzma-19.00/lzma.txt
deleted file mode 100644
index a65988fe..00000000
--- a/deps/libchdr/deps/lzma-19.00/lzma.txt
+++ /dev/null
@@ -1,328 +0,0 @@
-LZMA compression
-----------------
-Version: 9.35
-
-This file describes LZMA encoding and decoding functions written in C language.
-
-LZMA is an improved version of famous LZ77 compression algorithm.
-It was improved in way of maximum increasing of compression ratio,
-keeping high decompression speed and low memory requirements for
-decompressing.
-
-Note: you can read also LZMA Specification (lzma-specification.txt from LZMA SDK)
-
-Also you can look source code for LZMA encoding and decoding:
- C/Util/Lzma/LzmaUtil.c
-
-
-LZMA compressed file format
----------------------------
-Offset Size Description
- 0 1 Special LZMA properties (lc,lp, pb in encoded form)
- 1 4 Dictionary size (little endian)
- 5 8 Uncompressed size (little endian). -1 means unknown size
- 13 Compressed data
-
-
-
-ANSI-C LZMA Decoder
-~~~~~~~~~~~~~~~~~~~
-
-Please note that interfaces for ANSI-C code were changed in LZMA SDK 4.58.
-If you want to use old interfaces you can download previous version of LZMA SDK
-from sourceforge.net site.
-
-To use ANSI-C LZMA Decoder you need the following files:
-1) LzmaDec.h + LzmaDec.c + 7zTypes.h + Precomp.h + Compiler.h
-
-Look example code:
- C/Util/Lzma/LzmaUtil.c
-
-
-Memory requirements for LZMA decoding
--------------------------------------
-
-Stack usage of LZMA decoding function for local variables is not
-larger than 200-400 bytes.
-
-LZMA Decoder uses dictionary buffer and internal state structure.
-Internal state structure consumes
- state_size = (4 + (1.5 << (lc + lp))) KB
-by default (lc=3, lp=0), state_size = 16 KB.
-
-
-How To decompress data
-----------------------
-
-LZMA Decoder (ANSI-C version) now supports 2 interfaces:
-1) Single-call Decompressing
-2) Multi-call State Decompressing (zlib-like interface)
-
-You must use external allocator:
-Example:
-void *SzAlloc(void *p, size_t size) { p = p; return malloc(size); }
-void SzFree(void *p, void *address) { p = p; free(address); }
-ISzAlloc alloc = { SzAlloc, SzFree };
-
-You can use p = p; operator to disable compiler warnings.
-
-
-Single-call Decompressing
--------------------------
-When to use: RAM->RAM decompressing
-Compile files: LzmaDec.h + LzmaDec.c + 7zTypes.h
-Compile defines: no defines
-Memory Requirements:
- - Input buffer: compressed size
- - Output buffer: uncompressed size
- - LZMA Internal Structures: state_size (16 KB for default settings)
-
-Interface:
- int LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
- const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,
- ELzmaStatus *status, ISzAlloc *alloc);
- In:
- dest - output data
- destLen - output data size
- src - input data
- srcLen - input data size
- propData - LZMA properties (5 bytes)
- propSize - size of propData buffer (5 bytes)
- finishMode - It has meaning only if the decoding reaches output limit (*destLen).
- LZMA_FINISH_ANY - Decode just destLen bytes.
- LZMA_FINISH_END - Stream must be finished after (*destLen).
- You can use LZMA_FINISH_END, when you know that
- current output buffer covers last bytes of stream.
- alloc - Memory allocator.
-
- Out:
- destLen - processed output size
- srcLen - processed input size
-
- Output:
- SZ_OK
- status:
- LZMA_STATUS_FINISHED_WITH_MARK
- LZMA_STATUS_NOT_FINISHED
- LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
- SZ_ERROR_DATA - Data error
- SZ_ERROR_MEM - Memory allocation error
- SZ_ERROR_UNSUPPORTED - Unsupported properties
- SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).
-
- If LZMA decoder sees end_marker before reaching output limit, it returns OK result,
- and output value of destLen will be less than output buffer size limit.
-
- You can use multiple checks to test data integrity after full decompression:
- 1) Check Result and "status" variable.
- 2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.
- 3) Check that output(srcLen) = compressedSize, if you know real compressedSize.
- You must use correct finish mode in that case. */
-
-
-Multi-call State Decompressing (zlib-like interface)
-----------------------------------------------------
-
-When to use: file->file decompressing
-Compile files: LzmaDec.h + LzmaDec.c + 7zTypes.h
-
-Memory Requirements:
- - Buffer for input stream: any size (for example, 16 KB)
- - Buffer for output stream: any size (for example, 16 KB)
- - LZMA Internal Structures: state_size (16 KB for default settings)
- - LZMA dictionary (dictionary size is encoded in LZMA properties header)
-
-1) read LZMA properties (5 bytes) and uncompressed size (8 bytes, little-endian) to header:
- unsigned char header[LZMA_PROPS_SIZE + 8];
- ReadFile(inFile, header, sizeof(header)
-
-2) Allocate CLzmaDec structures (state + dictionary) using LZMA properties
-
- CLzmaDec state;
- LzmaDec_Constr(&state);
- res = LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc);
- if (res != SZ_OK)
- return res;
-
-3) Init LzmaDec structure before any new LZMA stream. And call LzmaDec_DecodeToBuf in loop
-
- LzmaDec_Init(&state);
- for (;;)
- {
- ...
- int res = LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen,
- const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode);
- ...
- }
-
-
-4) Free all allocated structures
- LzmaDec_Free(&state, &g_Alloc);
-
-Look example code:
- C/Util/Lzma/LzmaUtil.c
-
-
-How To compress data
---------------------
-
-Compile files:
- 7zTypes.h
- Threads.h
- LzmaEnc.h
- LzmaEnc.c
- LzFind.h
- LzFind.c
- LzFindMt.h
- LzFindMt.c
- LzHash.h
-
-Memory Requirements:
- - (dictSize * 11.5 + 6 MB) + state_size
-
-Lzma Encoder can use two memory allocators:
-1) alloc - for small arrays.
-2) allocBig - for big arrays.
-
-For example, you can use Large RAM Pages (2 MB) in allocBig allocator for
-better compression speed. Note that Windows has bad implementation for
-Large RAM Pages.
-It's OK to use same allocator for alloc and allocBig.
-
-
-Single-call Compression with callbacks
---------------------------------------
-
-Look example code:
- C/Util/Lzma/LzmaUtil.c
-
-When to use: file->file compressing
-
-1) you must implement callback structures for interfaces:
-ISeqInStream
-ISeqOutStream
-ICompressProgress
-ISzAlloc
-
-static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }
-static void SzFree(void *p, void *address) { p = p; MyFree(address); }
-static ISzAlloc g_Alloc = { SzAlloc, SzFree };
-
- CFileSeqInStream inStream;
- CFileSeqOutStream outStream;
-
- inStream.funcTable.Read = MyRead;
- inStream.file = inFile;
- outStream.funcTable.Write = MyWrite;
- outStream.file = outFile;
-
-
-2) Create CLzmaEncHandle object;
-
- CLzmaEncHandle enc;
-
- enc = LzmaEnc_Create(&g_Alloc);
- if (enc == 0)
- return SZ_ERROR_MEM;
-
-
-3) initialize CLzmaEncProps properties;
-
- LzmaEncProps_Init(&props);
-
- Then you can change some properties in that structure.
-
-4) Send LZMA properties to LZMA Encoder
-
- res = LzmaEnc_SetProps(enc, &props);
-
-5) Write encoded properties to header
-
- Byte header[LZMA_PROPS_SIZE + 8];
- size_t headerSize = LZMA_PROPS_SIZE;
- UInt64 fileSize;
- int i;
-
- res = LzmaEnc_WriteProperties(enc, header, &headerSize);
- fileSize = MyGetFileLength(inFile);
- for (i = 0; i < 8; i++)
- header[headerSize++] = (Byte)(fileSize >> (8 * i));
- MyWriteFileAndCheck(outFile, header, headerSize)
-
-6) Call encoding function:
- res = LzmaEnc_Encode(enc, &outStream.funcTable, &inStream.funcTable,
- NULL, &g_Alloc, &g_Alloc);
-
-7) Destroy LZMA Encoder Object
- LzmaEnc_Destroy(enc, &g_Alloc, &g_Alloc);
-
-
-If callback function return some error code, LzmaEnc_Encode also returns that code
-or it can return the code like SZ_ERROR_READ, SZ_ERROR_WRITE or SZ_ERROR_PROGRESS.
-
-
-Single-call RAM->RAM Compression
---------------------------------
-
-Single-call RAM->RAM Compression is similar to Compression with callbacks,
-but you provide pointers to buffers instead of pointers to stream callbacks:
-
-SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
- const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
- ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
-
-Return code:
- SZ_OK - OK
- SZ_ERROR_MEM - Memory allocation error
- SZ_ERROR_PARAM - Incorrect paramater
- SZ_ERROR_OUTPUT_EOF - output buffer overflow
- SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)
-
-
-
-Defines
--------
-
-_LZMA_SIZE_OPT - Enable some optimizations in LZMA Decoder to get smaller executable code.
-
-_LZMA_PROB32 - It can increase the speed on some 32-bit CPUs, but memory usage for
- some structures will be doubled in that case.
-
-_LZMA_UINT32_IS_ULONG - Define it if int is 16-bit on your compiler and long is 32-bit.
-
-_LZMA_NO_SYSTEM_SIZE_T - Define it if you don't want to use size_t type.
-
-
-_7ZIP_PPMD_SUPPPORT - Define it if you don't want to support PPMD method in AMSI-C .7z decoder.
-
-
-C++ LZMA Encoder/Decoder
-~~~~~~~~~~~~~~~~~~~~~~~~
-C++ LZMA code use COM-like interfaces. So if you want to use it,
-you can study basics of COM/OLE.
-C++ LZMA code is just wrapper over ANSI-C code.
-
-
-C++ Notes
-~~~~~~~~~~~~~~~~~~~~~~~~
-If you use some C++ code folders in 7-Zip (for example, C++ code for .7z handling),
-you must check that you correctly work with "new" operator.
-7-Zip can be compiled with MSVC 6.0 that doesn't throw "exception" from "new" operator.
-So 7-Zip uses "CPP\Common\NewHandler.cpp" that redefines "new" operator:
-operator new(size_t size)
-{
- void *p = ::malloc(size);
- if (p == 0)
- throw CNewException();
- return p;
-}
-If you use MSCV that throws exception for "new" operator, you can compile without
-"NewHandler.cpp". So standard exception will be used. Actually some code of
-7-Zip catches any exception in internal code and converts it to HRESULT code.
-So you don't need to catch CNewException, if you call COM interfaces of 7-Zip.
-
----
-
-http://www.7-zip.org
-http://www.7-zip.org/sdk.html
-http://www.7-zip.org/support.html
diff --git a/deps/libchdr/deps/lzma-19.00/lzma.vcxproj b/deps/libchdr/deps/lzma-19.00/lzma.vcxproj
deleted file mode 100644
index a4210356..00000000
--- a/deps/libchdr/deps/lzma-19.00/lzma.vcxproj
+++ /dev/null
@@ -1,543 +0,0 @@
-
-
-
-
- DebugFast
- ARM64
-
-
- DebugFast
- Win32
-
-
- DebugFast
- x64
-
-
- Debug
- ARM64
-
-
- Debug
- Win32
-
-
- Debug
- x64
-
-
- ReleaseLTCG
- ARM64
-
-
- ReleaseLTCG
- Win32
-
-
- ReleaseLTCG
- x64
-
-
- Release
- ARM64
-
-
- Release
- Win32
-
-
- Release
- x64
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {DD944834-7899-4C1C-A4C1-064B5009D239}
- Win32Proj
- lzma
- 10.0
-
-
-
- StaticLibrary
- true
- v142
- NotSet
-
-
- StaticLibrary
- true
- v142
- NotSet
-
-
- StaticLibrary
- true
- v142
- NotSet
-
-
- StaticLibrary
- true
- v142
- NotSet
-
-
- StaticLibrary
- true
- v142
- NotSet
-
-
- StaticLibrary
- true
- v142
- NotSet
-
-
- StaticLibrary
- false
- v142
- true
- NotSet
- false
-
-
- StaticLibrary
- false
- v142
- true
- NotSet
- false
-
-
- StaticLibrary
- false
- v142
- true
- NotSet
- false
-
-
- StaticLibrary
- false
- v142
- true
- NotSet
- false
-
-
- StaticLibrary
- false
- v142
- true
- NotSet
- false
-
-
- StaticLibrary
- false
- v142
- true
- NotSet
- false
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- true
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
- $(ProjectName)-$(Platform)-$(Configuration)
-
-
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
- $(ProjectName)-$(Platform)-$(Configuration)
- true
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
-
-
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
- $(ProjectName)-$(Platform)-$(Configuration)
- true
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
-
-
- true
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
- $(ProjectName)-$(Platform)-$(Configuration)
-
-
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
- $(ProjectName)-$(Platform)-$(Configuration)
- true
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
-
-
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
- $(ProjectName)-$(Platform)-$(Configuration)
- true
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
-
-
- false
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
- $(ProjectName)-$(Platform)-$(Configuration)
-
-
- false
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
- $(ProjectName)-$(Platform)-$(Configuration)
-
-
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
- $(ProjectName)-$(Platform)-$(Configuration)
- false
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
-
-
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
- $(ProjectName)-$(Platform)-$(Configuration)
- false
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
-
-
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
- $(ProjectName)-$(Platform)-$(Configuration)
- false
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
-
-
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
- $(ProjectName)-$(Platform)-$(Configuration)
- false
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
-
-
-
-
-
- Level2
- Disabled
- _7ZIP_ST;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
- true
- ProgramDatabase
- $(ProjectDir)include;%(AdditionalIncludeDirectories)
- false
- stdcpp17
- true
- true
- /Zo /utf-8 %(AdditionalOptions)
-
-
- Windows
- true
-
-
-
-
-
-
- Level2
- Disabled
- _7ZIP_ST;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
- true
- ProgramDatabase
- $(ProjectDir)include;%(AdditionalIncludeDirectories)
- false
- stdcpp17
- true
- true
- /Zo /utf-8 %(AdditionalOptions)
-
-
- Windows
- true
-
-
-
-
-
-
- Level2
- Disabled
- _7ZIP_ST;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
- true
- ProgramDatabase
- $(ProjectDir)include;%(AdditionalIncludeDirectories)
- false
- stdcpp17
- true
- true
- /Zo /utf-8 %(AdditionalOptions)
-
-
- Windows
- true
-
-
-
-
-
-
- Level2
- Disabled
- _7ZIP_ST;_ITERATOR_DEBUG_LEVEL=1;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUGFAST;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
- true
- ProgramDatabase
- $(ProjectDir)include;%(AdditionalIncludeDirectories)
- Default
- false
- stdcpp17
- false
- true
- OnlyExplicitInline
- true
- /Zo /utf-8 %(AdditionalOptions)
-
-
- Windows
- true
-
-
-
-
-
-
- Level2
- Disabled
- _7ZIP_ST;_ITERATOR_DEBUG_LEVEL=1;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUGFAST;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
- true
- ProgramDatabase
- $(ProjectDir)include;%(AdditionalIncludeDirectories)
- Default
- false
- stdcpp17
- false
- true
- OnlyExplicitInline
- true
- /Zo /utf-8 %(AdditionalOptions)
-
-
- Windows
- true
-
-
-
-
-
-
- Level2
- Disabled
- _7ZIP_ST;_ITERATOR_DEBUG_LEVEL=1;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUGFAST;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
- true
- ProgramDatabase
- $(ProjectDir)include;%(AdditionalIncludeDirectories)
- Default
- false
- stdcpp17
- false
- true
- OnlyExplicitInline
- true
- /Zo /utf-8 %(AdditionalOptions)
-
-
- Windows
- true
-
-
-
-
- Level2
-
-
- MaxSpeed
- true
- _7ZIP_ST;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
- $(ProjectDir)include;%(AdditionalIncludeDirectories)
- false
- stdcpp17
- true
- true
- /Zo /utf-8 %(AdditionalOptions)
-
-
- Windows
- true
- true
- true
-
-
-
-
- Level2
-
-
- MaxSpeed
- true
- _7ZIP_ST;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
- $(ProjectDir)include;%(AdditionalIncludeDirectories)
- true
- stdcpp17
- true
- true
- true
- /Zo /utf-8 %(AdditionalOptions)
-
-
- Windows
- true
- true
- true
-
-
-
-
- Level2
-
-
- MaxSpeed
- true
- _7ZIP_ST;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
- $(ProjectDir)include;%(AdditionalIncludeDirectories)
- false
- stdcpp17
- true
- true
- /Zo /utf-8 %(AdditionalOptions)
-
-
- Windows
- true
- true
- true
-
-
-
-
- Level2
-
-
- MaxSpeed
- true
- _7ZIP_ST;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
- $(ProjectDir)include;%(AdditionalIncludeDirectories)
- false
- stdcpp17
- true
- true
- /Zo /utf-8 %(AdditionalOptions)
-
-
- Windows
- true
- true
- true
-
-
-
-
- Level2
-
-
- MaxSpeed
- true
- _7ZIP_ST;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
- $(ProjectDir)include;%(AdditionalIncludeDirectories)
- true
- stdcpp17
- true
- true
- true
- /Zo /utf-8 %(AdditionalOptions)
-
-
- Windows
- true
- true
- true
-
-
-
-
- Level2
-
-
- MaxSpeed
- true
- _7ZIP_ST;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
- $(ProjectDir)include;%(AdditionalIncludeDirectories)
- true
- stdcpp17
- true
- true
- true
- /Zo /utf-8 %(AdditionalOptions)
-
-
- Windows
- true
- true
- true
-
-
-
-
-
-
\ No newline at end of file
diff --git a/deps/libchdr/deps/lzma-19.00/lzma.vcxproj.filters b/deps/libchdr/deps/lzma-19.00/lzma.vcxproj.filters
deleted file mode 100644
index 8725b394..00000000
--- a/deps/libchdr/deps/lzma-19.00/lzma.vcxproj.filters
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/deps/libchdr/deps/lzma-19.00/src/Alloc.c b/deps/libchdr/deps/lzma-19.00/src/Alloc.c
deleted file mode 100644
index bcede4b8..00000000
--- a/deps/libchdr/deps/lzma-19.00/src/Alloc.c
+++ /dev/null
@@ -1,455 +0,0 @@
-/* Alloc.c -- Memory allocation functions
-2018-04-27 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#include
-
-#ifdef _WIN32
-#include
-#endif
-#include
-
-#include "Alloc.h"
-
-/* #define _SZ_ALLOC_DEBUG */
-
-/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */
-#ifdef _SZ_ALLOC_DEBUG
-
-#include
-int g_allocCount = 0;
-int g_allocCountMid = 0;
-int g_allocCountBig = 0;
-
-
-#define CONVERT_INT_TO_STR(charType, tempSize) \
- unsigned char temp[tempSize]; unsigned i = 0; \
- while (val >= 10) { temp[i++] = (unsigned char)('0' + (unsigned)(val % 10)); val /= 10; } \
- *s++ = (charType)('0' + (unsigned)val); \
- while (i != 0) { i--; *s++ = temp[i]; } \
- *s = 0;
-
-static void ConvertUInt64ToString(UInt64 val, char *s)
-{
- CONVERT_INT_TO_STR(char, 24);
-}
-
-#define GET_HEX_CHAR(t) ((char)(((t < 10) ? ('0' + t) : ('A' + (t - 10)))))
-
-static void ConvertUInt64ToHex(UInt64 val, char *s)
-{
- UInt64 v = val;
- unsigned i;
- for (i = 1;; i++)
- {
- v >>= 4;
- if (v == 0)
- break;
- }
- s[i] = 0;
- do
- {
- unsigned t = (unsigned)(val & 0xF);
- val >>= 4;
- s[--i] = GET_HEX_CHAR(t);
- }
- while (i);
-}
-
-#define DEBUG_OUT_STREAM stderr
-
-static void Print(const char *s)
-{
- fputs(s, DEBUG_OUT_STREAM);
-}
-
-static void PrintAligned(const char *s, size_t align)
-{
- size_t len = strlen(s);
- for(;;)
- {
- fputc(' ', DEBUG_OUT_STREAM);
- if (len >= align)
- break;
- ++len;
- }
- Print(s);
-}
-
-static void PrintLn()
-{
- Print("\n");
-}
-
-static void PrintHex(UInt64 v, size_t align)
-{
- char s[32];
- ConvertUInt64ToHex(v, s);
- PrintAligned(s, align);
-}
-
-static void PrintDec(UInt64 v, size_t align)
-{
- char s[32];
- ConvertUInt64ToString(v, s);
- PrintAligned(s, align);
-}
-
-static void PrintAddr(void *p)
-{
- PrintHex((UInt64)(size_t)(ptrdiff_t)p, 12);
-}
-
-
-#define PRINT_ALLOC(name, cnt, size, ptr) \
- Print(name " "); \
- PrintDec(cnt++, 10); \
- PrintHex(size, 10); \
- PrintAddr(ptr); \
- PrintLn();
-
-#define PRINT_FREE(name, cnt, ptr) if (ptr) { \
- Print(name " "); \
- PrintDec(--cnt, 10); \
- PrintAddr(ptr); \
- PrintLn(); }
-
-#else
-
-#define PRINT_ALLOC(name, cnt, size, ptr)
-#define PRINT_FREE(name, cnt, ptr)
-#define Print(s)
-#define PrintLn()
-#define PrintHex(v, align)
-#define PrintDec(v, align)
-#define PrintAddr(p)
-
-#endif
-
-
-
-void *MyAlloc(size_t size)
-{
- if (size == 0)
- return NULL;
- #ifdef _SZ_ALLOC_DEBUG
- {
- void *p = malloc(size);
- PRINT_ALLOC("Alloc ", g_allocCount, size, p);
- return p;
- }
- #else
- return malloc(size);
- #endif
-}
-
-void MyFree(void *address)
-{
- PRINT_FREE("Free ", g_allocCount, address);
-
- free(address);
-}
-
-#ifdef _WIN32
-
-void *MidAlloc(size_t size)
-{
- if (size == 0)
- return NULL;
-
- PRINT_ALLOC("Alloc-Mid", g_allocCountMid, size, NULL);
-
- return VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE);
-}
-
-void MidFree(void *address)
-{
- PRINT_FREE("Free-Mid", g_allocCountMid, address);
-
- if (!address)
- return;
- VirtualFree(address, 0, MEM_RELEASE);
-}
-
-#ifndef MEM_LARGE_PAGES
-#undef _7ZIP_LARGE_PAGES
-#endif
-
-#ifdef _7ZIP_LARGE_PAGES
-SIZE_T g_LargePageSize = 0;
-typedef SIZE_T (WINAPI *GetLargePageMinimumP)();
-#endif
-
-void SetLargePageSize()
-{
- #ifdef _7ZIP_LARGE_PAGES
- SIZE_T size;
- GetLargePageMinimumP largePageMinimum = (GetLargePageMinimumP)
- GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetLargePageMinimum");
- if (!largePageMinimum)
- return;
- size = largePageMinimum();
- if (size == 0 || (size & (size - 1)) != 0)
- return;
- g_LargePageSize = size;
- #endif
-}
-
-
-void *BigAlloc(size_t size)
-{
- if (size == 0)
- return NULL;
-
- PRINT_ALLOC("Alloc-Big", g_allocCountBig, size, NULL);
-
- #ifdef _7ZIP_LARGE_PAGES
- {
- SIZE_T ps = g_LargePageSize;
- if (ps != 0 && ps <= (1 << 30) && size > (ps / 2))
- {
- size_t size2;
- ps--;
- size2 = (size + ps) & ~ps;
- if (size2 >= size)
- {
- void *res = VirtualAlloc(NULL, size2, MEM_COMMIT | MEM_LARGE_PAGES, PAGE_READWRITE);
- if (res)
- return res;
- }
- }
- }
- #endif
-
- return VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE);
-}
-
-void BigFree(void *address)
-{
- PRINT_FREE("Free-Big", g_allocCountBig, address);
-
- if (!address)
- return;
- VirtualFree(address, 0, MEM_RELEASE);
-}
-
-#endif
-
-
-static void *SzAlloc(ISzAllocPtr p, size_t size) { UNUSED_VAR(p); return MyAlloc(size); }
-static void SzFree(ISzAllocPtr p, void *address) { UNUSED_VAR(p); MyFree(address); }
-const ISzAlloc g_Alloc = { SzAlloc, SzFree };
-
-static void *SzMidAlloc(ISzAllocPtr p, size_t size) { UNUSED_VAR(p); return MidAlloc(size); }
-static void SzMidFree(ISzAllocPtr p, void *address) { UNUSED_VAR(p); MidFree(address); }
-const ISzAlloc g_MidAlloc = { SzMidAlloc, SzMidFree };
-
-static void *SzBigAlloc(ISzAllocPtr p, size_t size) { UNUSED_VAR(p); return BigAlloc(size); }
-static void SzBigFree(ISzAllocPtr p, void *address) { UNUSED_VAR(p); BigFree(address); }
-const ISzAlloc g_BigAlloc = { SzBigAlloc, SzBigFree };
-
-
-/*
- uintptr_t : C99 (optional)
- : unsupported in VS6
-*/
-
-#ifdef _WIN32
- typedef UINT_PTR UIntPtr;
-#else
- /*
- typedef uintptr_t UIntPtr;
- */
- typedef ptrdiff_t UIntPtr;
-#endif
-
-
-#define ADJUST_ALLOC_SIZE 0
-/*
-#define ADJUST_ALLOC_SIZE (sizeof(void *) - 1)
-*/
-/*
- Use (ADJUST_ALLOC_SIZE = (sizeof(void *) - 1)), if
- MyAlloc() can return address that is NOT multiple of sizeof(void *).
-*/
-
-
-/*
-#define MY_ALIGN_PTR_DOWN(p, align) ((void *)((char *)(p) - ((size_t)(UIntPtr)(p) & ((align) - 1))))
-*/
-#define MY_ALIGN_PTR_DOWN(p, align) ((void *)((((UIntPtr)(p)) & ~((UIntPtr)(align) - 1))))
-
-#define MY_ALIGN_PTR_UP_PLUS(p, align) MY_ALIGN_PTR_DOWN(((char *)(p) + (align) + ADJUST_ALLOC_SIZE), align)
-
-
-#if (_POSIX_C_SOURCE >= 200112L) && !defined(_WIN32)
- #define USE_posix_memalign
-#endif
-
-/*
- This posix_memalign() is for test purposes only.
- We also need special Free() function instead of free(),
- if this posix_memalign() is used.
-*/
-
-/*
-static int posix_memalign(void **ptr, size_t align, size_t size)
-{
- size_t newSize = size + align;
- void *p;
- void *pAligned;
- *ptr = NULL;
- if (newSize < size)
- return 12; // ENOMEM
- p = MyAlloc(newSize);
- if (!p)
- return 12; // ENOMEM
- pAligned = MY_ALIGN_PTR_UP_PLUS(p, align);
- ((void **)pAligned)[-1] = p;
- *ptr = pAligned;
- return 0;
-}
-*/
-
-/*
- ALLOC_ALIGN_SIZE >= sizeof(void *)
- ALLOC_ALIGN_SIZE >= cache_line_size
-*/
-
-#define ALLOC_ALIGN_SIZE ((size_t)1 << 7)
-
-static void *SzAlignedAlloc(ISzAllocPtr pp, size_t size)
-{
- #ifndef USE_posix_memalign
-
- void *p;
- void *pAligned;
- size_t newSize;
- UNUSED_VAR(pp);
-
- /* also we can allocate additional dummy ALLOC_ALIGN_SIZE bytes after aligned
- block to prevent cache line sharing with another allocated blocks */
-
- newSize = size + ALLOC_ALIGN_SIZE * 1 + ADJUST_ALLOC_SIZE;
- if (newSize < size)
- return NULL;
-
- p = MyAlloc(newSize);
-
- if (!p)
- return NULL;
- pAligned = MY_ALIGN_PTR_UP_PLUS(p, ALLOC_ALIGN_SIZE);
-
- Print(" size="); PrintHex(size, 8);
- Print(" a_size="); PrintHex(newSize, 8);
- Print(" ptr="); PrintAddr(p);
- Print(" a_ptr="); PrintAddr(pAligned);
- PrintLn();
-
- ((void **)pAligned)[-1] = p;
-
- return pAligned;
-
- #else
-
- void *p;
- UNUSED_VAR(pp);
- if (posix_memalign(&p, ALLOC_ALIGN_SIZE, size))
- return NULL;
-
- Print(" posix_memalign="); PrintAddr(p);
- PrintLn();
-
- return p;
-
- #endif
-}
-
-
-static void SzAlignedFree(ISzAllocPtr pp, void *address)
-{
- UNUSED_VAR(pp);
- #ifndef USE_posix_memalign
- if (address)
- MyFree(((void **)address)[-1]);
- #else
- free(address);
- #endif
-}
-
-
-const ISzAlloc g_AlignedAlloc = { SzAlignedAlloc, SzAlignedFree };
-
-
-
-#define MY_ALIGN_PTR_DOWN_1(p) MY_ALIGN_PTR_DOWN(p, sizeof(void *))
-
-/* we align ptr to support cases where CAlignOffsetAlloc::offset is not multiply of sizeof(void *) */
-#define REAL_BLOCK_PTR_VAR(p) ((void **)MY_ALIGN_PTR_DOWN_1(p))[-1]
-/*
-#define REAL_BLOCK_PTR_VAR(p) ((void **)(p))[-1]
-*/
-
-static void *AlignOffsetAlloc_Alloc(ISzAllocPtr pp, size_t size)
-{
- CAlignOffsetAlloc *p = CONTAINER_FROM_VTBL(pp, CAlignOffsetAlloc, vt);
- void *adr;
- void *pAligned;
- size_t newSize;
- size_t extra;
- size_t alignSize = (size_t)1 << p->numAlignBits;
-
- if (alignSize < sizeof(void *))
- alignSize = sizeof(void *);
-
- if (p->offset >= alignSize)
- return NULL;
-
- /* also we can allocate additional dummy ALLOC_ALIGN_SIZE bytes after aligned
- block to prevent cache line sharing with another allocated blocks */
- extra = p->offset & (sizeof(void *) - 1);
- newSize = size + alignSize + extra + ADJUST_ALLOC_SIZE;
- if (newSize < size)
- return NULL;
-
- adr = ISzAlloc_Alloc(p->baseAlloc, newSize);
-
- if (!adr)
- return NULL;
-
- pAligned = (char *)MY_ALIGN_PTR_DOWN((char *)adr +
- alignSize - p->offset + extra + ADJUST_ALLOC_SIZE, alignSize) + p->offset;
-
- PrintLn();
- Print("- Aligned: ");
- Print(" size="); PrintHex(size, 8);
- Print(" a_size="); PrintHex(newSize, 8);
- Print(" ptr="); PrintAddr(adr);
- Print(" a_ptr="); PrintAddr(pAligned);
- PrintLn();
-
- REAL_BLOCK_PTR_VAR(pAligned) = adr;
-
- return pAligned;
-}
-
-
-static void AlignOffsetAlloc_Free(ISzAllocPtr pp, void *address)
-{
- if (address)
- {
- CAlignOffsetAlloc *p = CONTAINER_FROM_VTBL(pp, CAlignOffsetAlloc, vt);
- PrintLn();
- Print("- Aligned Free: ");
- PrintLn();
- ISzAlloc_Free(p->baseAlloc, REAL_BLOCK_PTR_VAR(address));
- }
-}
-
-
-void AlignOffsetAlloc_CreateVTable(CAlignOffsetAlloc *p)
-{
- p->vt.Alloc = AlignOffsetAlloc_Alloc;
- p->vt.Free = AlignOffsetAlloc_Free;
-}
diff --git a/deps/libchdr/deps/lzma-19.00/src/Bra86.c b/deps/libchdr/deps/lzma-19.00/src/Bra86.c
deleted file mode 100644
index 93ed4d76..00000000
--- a/deps/libchdr/deps/lzma-19.00/src/Bra86.c
+++ /dev/null
@@ -1,82 +0,0 @@
-/* Bra86.c -- Converter for x86 code (BCJ)
-2017-04-03 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#include "Bra.h"
-
-#define Test86MSByte(b) ((((b) + 1) & 0xFE) == 0)
-
-SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding)
-{
- SizeT pos = 0;
- UInt32 mask = *state & 7;
- if (size < 5)
- return 0;
- size -= 4;
- ip += 5;
-
- 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);
- pos = (SizeT)(p - data);
- if (p >= limit)
- {
- *state = (d > 2 ? 0 : mask >> (unsigned)d);
- return pos;
- }
- if (d > 2)
- mask = 0;
- else
- {
- mask >>= (unsigned)d;
- if (mask != 0 && (mask > 4 || mask == 3 || Test86MSByte(p[(size_t)(mask >> 1) + 1])))
- {
- mask = (mask >> 1) | 4;
- pos++;
- continue;
- }
- }
- }
-
- 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)
- v += cur;
- else
- v -= cur;
- if (mask != 0)
- {
- unsigned sh = (mask & 6) << 2;
- if (Test86MSByte((Byte)(v >> sh)))
- {
- v ^= (((UInt32)0x100 << sh) - 1);
- if (encoding)
- v += cur;
- 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
- {
- mask = (mask >> 1) | 4;
- pos++;
- }
- }
-}
diff --git a/deps/libchdr/deps/lzma-19.00/src/BraIA64.c b/deps/libchdr/deps/lzma-19.00/src/BraIA64.c
deleted file mode 100644
index d1dbc62c..00000000
--- a/deps/libchdr/deps/lzma-19.00/src/BraIA64.c
+++ /dev/null
@@ -1,53 +0,0 @@
-/* BraIA64.c -- Converter for IA-64 code
-2017-01-26 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#include "CpuArch.h"
-#include "Bra.h"
-
-SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
-{
- SizeT i;
- if (size < 16)
- return 0;
- size -= 16;
- i = 0;
- do
- {
- unsigned m = ((UInt32)0x334B0000 >> (data[i] & 0x1E)) & 3;
- if (m)
- {
- m++;
- do
- {
- Byte *p = data + (i + (size_t)m * 5 - 8);
- if (((p[3] >> m) & 15) == 5
- && (((p[-1] | ((UInt32)p[0] << 8)) >> m) & 0x70) == 0)
- {
- unsigned raw = GetUi32(p);
- unsigned v = raw >> m;
- v = (v & 0xFFFFF) | ((v & (1 << 23)) >> 3);
-
- v <<= 4;
- if (encoding)
- v += ip + (UInt32)i;
- else
- v -= ip + (UInt32)i;
- v >>= 4;
-
- v &= 0x1FFFFF;
- v += 0x700000;
- v &= 0x8FFFFF;
- raw &= ~((UInt32)0x8FFFFF << m);
- raw |= (v << m);
- SetUi32(p, raw);
- }
- }
- while (++m <= 4);
- }
- i += 16;
- }
- while (i <= size);
- return i;
-}
diff --git a/deps/libchdr/deps/lzma-19.00/src/CpuArch.c b/deps/libchdr/deps/lzma-19.00/src/CpuArch.c
deleted file mode 100644
index 02e482e0..00000000
--- a/deps/libchdr/deps/lzma-19.00/src/CpuArch.c
+++ /dev/null
@@ -1,218 +0,0 @@
-/* CpuArch.c -- CPU specific code
-2018-02-18: Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#include "CpuArch.h"
-
-#ifdef MY_CPU_X86_OR_AMD64
-
-#if (defined(_MSC_VER) && !defined(MY_CPU_AMD64)) || defined(__GNUC__)
-#define USE_ASM
-#endif
-
-#if !defined(USE_ASM) && _MSC_VER >= 1500
-#include
-#endif
-
-#if defined(USE_ASM) && !defined(MY_CPU_AMD64)
-static UInt32 CheckFlag(UInt32 flag)
-{
- #ifdef _MSC_VER
- __asm pushfd;
- __asm pop EAX;
- __asm mov EDX, EAX;
- __asm xor EAX, flag;
- __asm push EAX;
- __asm popfd;
- __asm pushfd;
- __asm pop EAX;
- __asm xor EAX, EDX;
- __asm push EDX;
- __asm popfd;
- __asm and flag, EAX;
- #else
- __asm__ __volatile__ (
- "pushf\n\t"
- "pop %%EAX\n\t"
- "movl %%EAX,%%EDX\n\t"
- "xorl %0,%%EAX\n\t"
- "push %%EAX\n\t"
- "popf\n\t"
- "pushf\n\t"
- "pop %%EAX\n\t"
- "xorl %%EDX,%%EAX\n\t"
- "push %%EDX\n\t"
- "popf\n\t"
- "andl %%EAX, %0\n\t":
- "=c" (flag) : "c" (flag) :
- "%eax", "%edx");
- #endif
- return flag;
-}
-#define CHECK_CPUID_IS_SUPPORTED if (CheckFlag(1 << 18) == 0 || CheckFlag(1 << 21) == 0) return False;
-#else
-#define CHECK_CPUID_IS_SUPPORTED
-#endif
-
-void MyCPUID(UInt32 function, UInt32 *a, UInt32 *b, UInt32 *c, UInt32 *d)
-{
- #ifdef USE_ASM
-
- #ifdef _MSC_VER
-
- UInt32 a2, b2, c2, d2;
- __asm xor EBX, EBX;
- __asm xor ECX, ECX;
- __asm xor EDX, EDX;
- __asm mov EAX, function;
- __asm cpuid;
- __asm mov a2, EAX;
- __asm mov b2, EBX;
- __asm mov c2, ECX;
- __asm mov d2, EDX;
-
- *a = a2;
- *b = b2;
- *c = c2;
- *d = d2;
-
- #else
-
- __asm__ __volatile__ (
- #if defined(MY_CPU_AMD64) && defined(__PIC__)
- "mov %%rbx, %%rdi;"
- "cpuid;"
- "xchg %%rbx, %%rdi;"
- : "=a" (*a) ,
- "=D" (*b) ,
- #elif defined(MY_CPU_X86) && defined(__PIC__)
- "mov %%ebx, %%edi;"
- "cpuid;"
- "xchgl %%ebx, %%edi;"
- : "=a" (*a) ,
- "=D" (*b) ,
- #else
- "cpuid"
- : "=a" (*a) ,
- "=b" (*b) ,
- #endif
- "=c" (*c) ,
- "=d" (*d)
- : "0" (function)) ;
-
- #endif
-
- #else
-
- int CPUInfo[4];
- __cpuid(CPUInfo, function);
- *a = CPUInfo[0];
- *b = CPUInfo[1];
- *c = CPUInfo[2];
- *d = CPUInfo[3];
-
- #endif
-}
-
-BoolInt x86cpuid_CheckAndRead(Cx86cpuid *p)
-{
- CHECK_CPUID_IS_SUPPORTED
- MyCPUID(0, &p->maxFunc, &p->vendor[0], &p->vendor[2], &p->vendor[1]);
- MyCPUID(1, &p->ver, &p->b, &p->c, &p->d);
- return True;
-}
-
-static const UInt32 kVendors[][3] =
-{
- { 0x756E6547, 0x49656E69, 0x6C65746E},
- { 0x68747541, 0x69746E65, 0x444D4163},
- { 0x746E6543, 0x48727561, 0x736C7561}
-};
-
-int x86cpuid_GetFirm(const Cx86cpuid *p)
-{
- unsigned i;
- for (i = 0; i < sizeof(kVendors) / sizeof(kVendors[i]); i++)
- {
- const UInt32 *v = kVendors[i];
- if (v[0] == p->vendor[0] &&
- v[1] == p->vendor[1] &&
- v[2] == p->vendor[2])
- return (int)i;
- }
- return -1;
-}
-
-BoolInt CPU_Is_InOrder()
-{
- Cx86cpuid p;
- int firm;
- UInt32 family, model;
- if (!x86cpuid_CheckAndRead(&p))
- return True;
-
- family = x86cpuid_GetFamily(p.ver);
- model = x86cpuid_GetModel(p.ver);
-
- firm = x86cpuid_GetFirm(&p);
-
- switch (firm)
- {
- case CPU_FIRM_INTEL: return (family < 6 || (family == 6 && (
- /* In-Order Atom CPU */
- model == 0x1C /* 45 nm, N4xx, D4xx, N5xx, D5xx, 230, 330 */
- || model == 0x26 /* 45 nm, Z6xx */
- || model == 0x27 /* 32 nm, Z2460 */
- || model == 0x35 /* 32 nm, Z2760 */
- || model == 0x36 /* 32 nm, N2xxx, D2xxx */
- )));
- case CPU_FIRM_AMD: return (family < 5 || (family == 5 && (model < 6 || model == 0xA)));
- case CPU_FIRM_VIA: return (family < 6 || (family == 6 && model < 0xF));
- }
- return True;
-}
-
-#if !defined(MY_CPU_AMD64) && defined(_WIN32)
-#include
-static BoolInt CPU_Sys_Is_SSE_Supported()
-{
- OSVERSIONINFO vi;
- vi.dwOSVersionInfoSize = sizeof(vi);
- if (!GetVersionEx(&vi))
- return False;
- return (vi.dwMajorVersion >= 5);
-}
-#define CHECK_SYS_SSE_SUPPORT if (!CPU_Sys_Is_SSE_Supported()) return False;
-#else
-#define CHECK_SYS_SSE_SUPPORT
-#endif
-
-BoolInt CPU_Is_Aes_Supported()
-{
- Cx86cpuid p;
- CHECK_SYS_SSE_SUPPORT
- if (!x86cpuid_CheckAndRead(&p))
- return False;
- return (p.c >> 25) & 1;
-}
-
-BoolInt CPU_IsSupported_PageGB()
-{
- Cx86cpuid cpuid;
- if (!x86cpuid_CheckAndRead(&cpuid))
- return False;
- {
- UInt32 d[4] = { 0 };
- MyCPUID(0x80000000, &d[0], &d[1], &d[2], &d[3]);
- if (d[0] < 0x80000001)
- return False;
- }
- {
- UInt32 d[4] = { 0 };
- MyCPUID(0x80000001, &d[0], &d[1], &d[2], &d[3]);
- return (d[3] >> 26) & 1;
- }
-}
-
-#endif
diff --git a/deps/libchdr/deps/lzma-19.00/src/Delta.c b/deps/libchdr/deps/lzma-19.00/src/Delta.c
deleted file mode 100644
index e3edd21e..00000000
--- a/deps/libchdr/deps/lzma-19.00/src/Delta.c
+++ /dev/null
@@ -1,64 +0,0 @@
-/* Delta.c -- Delta converter
-2009-05-26 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#include "Delta.h"
-
-void Delta_Init(Byte *state)
-{
- unsigned i;
- for (i = 0; i < DELTA_STATE_SIZE; i++)
- state[i] = 0;
-}
-
-static void MyMemCpy(Byte *dest, const Byte *src, unsigned size)
-{
- unsigned i;
- for (i = 0; i < size; i++)
- dest[i] = src[i];
-}
-
-void Delta_Encode(Byte *state, unsigned delta, Byte *data, SizeT size)
-{
- Byte buf[DELTA_STATE_SIZE];
- unsigned j = 0;
- MyMemCpy(buf, state, delta);
- {
- SizeT i;
- for (i = 0; i < size;)
- {
- for (j = 0; j < delta && i < size; i++, j++)
- {
- Byte b = data[i];
- data[i] = (Byte)(b - buf[j]);
- buf[j] = b;
- }
- }
- }
- if (j == delta)
- j = 0;
- MyMemCpy(state, buf + j, delta - j);
- MyMemCpy(state + delta - j, buf, j);
-}
-
-void Delta_Decode(Byte *state, unsigned delta, Byte *data, SizeT size)
-{
- Byte buf[DELTA_STATE_SIZE];
- unsigned j = 0;
- MyMemCpy(buf, state, delta);
- {
- SizeT i;
- for (i = 0; i < size;)
- {
- for (j = 0; j < delta && i < size; i++, j++)
- {
- buf[j] = data[i] = (Byte)(buf[j] + data[i]);
- }
- }
- }
- if (j == delta)
- j = 0;
- MyMemCpy(state, buf + j, delta - j);
- MyMemCpy(state + delta - j, buf, j);
-}
diff --git a/deps/libchdr/deps/lzma-19.00/src/LzFind.c b/deps/libchdr/deps/lzma-19.00/src/LzFind.c
deleted file mode 100644
index df55e86c..00000000
--- a/deps/libchdr/deps/lzma-19.00/src/LzFind.c
+++ /dev/null
@@ -1,1127 +0,0 @@
-/* LzFind.c -- Match finder for LZ algorithms
-2018-07-08 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#include
-
-#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 kStartMaxLen 3
-
-static void LzInWindow_Free(CMatchFinder *p, ISzAllocPtr alloc)
-{
- 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)
-{
- 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);
- }
- return (p->bufferBase != NULL);
-}
-
-Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; }
-
-UInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }
-
-void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue)
-{
- p->posLimit -= subValue;
- p->pos -= subValue;
- p->streamPos -= subValue;
-}
-
-static void MatchFinder_ReadBlock(CMatchFinder *p)
-{
- 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)
- curSize = (UInt32)p->directInputRem;
- p->directInputRem -= curSize;
- 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)
- return;
-
- p->result = ISeqInStream_Read(p->stream, dest, &size);
- if (p->result != SZ_OK)
- return;
- if (size == 0)
- {
- p->streamEndWasReached = 1;
- return;
- }
- p->streamPos += (UInt32)size;
- if (p->streamPos - p->pos > p->keepSizeAfter)
- return;
- }
-}
-
-void MatchFinder_MoveBlock(CMatchFinder *p)
-{
- 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)
-{
- 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)
-{
- if (p->streamEndWasReached)
- return;
- if (p->keepSizeAfter >= p->streamPos - p->pos)
- MatchFinder_ReadBlock(p);
-}
-
-static void MatchFinder_CheckAndMoveAndRead(CMatchFinder *p)
-{
- if (MatchFinder_NeedMove(p))
- MatchFinder_MoveBlock(p);
- MatchFinder_ReadBlock(p);
-}
-
-static void MatchFinder_SetDefaultSettings(CMatchFinder *p)
-{
- p->cutValue = 32;
- p->btMode = 1;
- p->numHashBytes = 4;
- p->bigHash = 0;
-}
-
-#define kCrcPoly 0xEDB88320
-
-void MatchFinder_Construct(CMatchFinder *p)
-{
- unsigned i;
- p->bufferBase = NULL;
- p->directInput = 0;
- p->hash = NULL;
- p->expectedDataSize = (UInt64)(Int64)-1;
- MatchFinder_SetDefaultSettings(p);
-
- 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)
-{
- ISzAlloc_Free(alloc, p->hash);
- p->hash = NULL;
-}
-
-void MatchFinder_Free(CMatchFinder *p, ISzAllocPtr alloc)
-{
- MatchFinder_FreeThisClassMemory(p, alloc);
- LzInWindow_Free(p, alloc);
-}
-
-static CLzRef* AllocRefs(size_t num, ISzAllocPtr alloc)
-{
- size_t sizeInBytes = (size_t)num * sizeof(CLzRef);
- if (sizeInBytes / sizeof(CLzRef) != num)
- return NULL;
- return (CLzRef *)ISzAlloc_Alloc(alloc, sizeInBytes);
-}
-
-int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
- UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,
- ISzAllocPtr alloc)
-{
- UInt32 sizeReserv;
-
- 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;
-
- sizeReserv += (keepAddBufferBefore + matchMaxLen + keepAddBufferAfter) / 2 + (1 << 19);
-
- p->keepSizeBefore = historySize + keepAddBufferBefore + 1;
- 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;
- p->matchMaxLen = matchMaxLen;
- {
- p->fixedHashSize = 0;
- if (p->numHashBytes == 2)
- hs = (1 << 16) - 1;
- else
- {
- hs = historySize;
- if (hs > p->expectedDataSize)
- hs = (UInt32)p->expectedDataSize;
- if (hs != 0)
- hs--;
- 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 = (1 << 24) - 1;
- 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;
- hs += p->fixedHashSize;
- }
-
- {
- size_t newSize;
- size_t numSons;
- p->historySize = historySize;
- p->hashSizeSum = hs;
- p->cyclicBufferSize = newCyclicBufferSize;
-
- numSons = newCyclicBufferSize;
- if (p->btMode)
- numSons <<= 1;
- newSize = hs + numSons;
-
- if (p->hash && p->numRefs == newSize)
- return 1;
-
- MatchFinder_FreeThisClassMemory(p, alloc);
- p->numRefs = newSize;
- p->hash = AllocRefs(newSize, alloc);
-
- if (p->hash)
- {
- p->son = p->hash + p->hashSizeSum;
- return 1;
- }
- }
- }
-
- MatchFinder_Free(p, alloc);
- return 0;
-}
-
-static void MatchFinder_SetLimits(CMatchFinder *p)
-{
- UInt32 limit = kMaxValForNormalize - p->pos;
- UInt32 limit2 = p->cyclicBufferSize - p->cyclicBufferPos;
-
- if (limit2 < limit)
- limit = limit2;
- limit2 = p->streamPos - p->pos;
-
- if (limit2 <= p->keepSizeAfter)
- {
- if (limit2 > 0)
- limit2 = 1;
- }
- else
- limit2 -= p->keepSizeAfter;
-
- if (limit2 < limit)
- limit = limit2;
-
- {
- 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)
-{
- 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)
-{
- 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)
-{
- 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);
-
- MatchFinder_SetLimits(p);
-}
-
-
-void MatchFinder_Init(CMatchFinder *p)
-{
- MatchFinder_Init_HighHash(p);
- MatchFinder_Init_LowHash(p);
- MatchFinder_Init_3(p, True);
-}
-
-
-static UInt32 MatchFinder_GetSubValue(CMatchFinder *p)
-{
- return (p->pos - p->historySize - 1) & kNormalizeMask;
-}
-
-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)
- value = kEmptyHashValue;
- else
- value -= subValue;
- items[i] = value;
- }
-}
-
-static void MatchFinder_Normalize(CMatchFinder *p)
-{
- 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)
-{
- 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);
-}
-
-
-/*
- (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)
-{
- /*
- son[_cyclicBufferPos] = curMatch;
- for (;;)
- {
- UInt32 delta = pos - curMatch;
- if (cutValue-- == 0 || delta >= _cyclicBufferSize)
- return distances;
- {
- const Byte *pb = cur - delta;
- curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)];
- if (pb[maxLen] == cur[maxLen] && *pb == *cur)
- {
- UInt32 len = 0;
- while (++len != lenLimit)
- if (pb[len] != cur[len])
- break;
- if (maxLen < len)
- {
- maxLen = len;
- *distances++ = len;
- *distances++ = delta - 1;
- if (len == lenLimit)
- return distances;
- }
- }
- }
- }
- */
-
- const Byte *lim = cur + lenLimit;
- son[_cyclicBufferPos] = curMatch;
- do
- {
- UInt32 delta = pos - curMatch;
- if (delta >= _cyclicBufferSize)
- break;
- {
- 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)
- {
- distances[0] = (UInt32)(lim - cur);
- distances[1] = delta - 1;
- return distances + 2;
- }
- }
- {
- unsigned len = (unsigned)(c - cur);
- if (maxLen < len)
- {
- maxLen = len;
- distances[0] = (UInt32)len;
- distances[1] = delta - 1;
- distances += 2;
- }
- }
- }
- }
- }
- 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)
-{
- 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])
- break;
- if (maxLen < len)
- {
- maxLen = (UInt32)len;
- *distances++ = (UInt32)len;
- *distances++ = delta - 1;
- if (len == lenLimit)
- {
- *ptr1 = pair0;
- *ptr0 = pair[1];
- return distances;
- }
- }
- }
- if (pb[len] < cur[len])
- {
- *ptr1 = curMatch;
- ptr1 = pair + 1;
- curMatch = *ptr1;
- len1 = len;
- }
- else
- {
- *ptr0 = curMatch;
- ptr0 = pair;
- curMatch = *ptr0;
- len0 = len;
- }
- }
- }
-}
-
-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)
- {
- *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])
- break;
- {
- if (len == lenLimit)
- {
- *ptr1 = pair[0];
- *ptr0 = pair[1];
- return;
- }
- }
- }
- if (pb[len] < cur[len])
- {
- *ptr1 = curMatch;
- ptr1 = pair + 1;
- curMatch = *ptr1;
- len1 = len;
- }
- else
- {
- *ptr0 = curMatch;
- ptr0 = pair;
- curMatch = *ptr0;
- len0 = len;
- }
- }
- }
-}
-
-#define MOVE_POS \
- ++p->cyclicBufferPos; \
- p->buffer++; \
- if (++p->pos == p->posLimit) MatchFinder_CheckLimits(p);
-
-#define MOVE_POS_RET MOVE_POS return (UInt32)offset;
-
-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 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), \
- distances + offset, (UInt32)maxLen) - distances); MOVE_POS_RET;
-
-#define SKIP_FOOTER \
- SkipMatchesSpec((UInt32)lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS;
-
-#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)
-{
- unsigned offset;
- GET_MATCHES_HEADER(2)
- HASH2_CALC;
- curMatch = p->hash[hv];
- p->hash[hv] = p->pos;
- offset = 0;
- GET_MATCHES_FOOTER(offset, 1)
-}
-
-UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
-{
- unsigned offset;
- GET_MATCHES_HEADER(3)
- HASH_ZIP_CALC;
- curMatch = p->hash[hv];
- p->hash[hv] = p->pos;
- offset = 0;
- GET_MATCHES_FOOTER(offset, 2)
-}
-
-static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
-{
- UInt32 h2, d2, pos;
- unsigned maxLen, offset;
- UInt32 *hash;
- GET_MATCHES_HEADER(3)
-
- HASH3_CALC;
-
- hash = p->hash;
- pos = p->pos;
-
- d2 = pos - hash[h2];
-
- curMatch = (hash + kFix3HashSize)[hv];
-
- hash[h2] = pos;
- (hash + kFix3HashSize)[hv] = pos;
-
- maxLen = 2;
- offset = 0;
-
- if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur)
- {
- UPDATE_maxLen
- distances[0] = (UInt32)maxLen;
- distances[1] = d2 - 1;
- offset = 2;
- if (maxLen == lenLimit)
- {
- SkipMatchesSpec((UInt32)lenLimit, curMatch, MF_PARAMS(p));
- MOVE_POS_RET;
- }
- }
-
- GET_MATCHES_FOOTER(offset, maxLen)
-}
-
-static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
-{
- UInt32 h2, h3, d2, d3, pos;
- unsigned maxLen, offset;
- UInt32 *hash;
- GET_MATCHES_HEADER(4)
-
- HASH4_CALC;
-
- hash = p->hash;
- pos = p->pos;
-
- d2 = pos - hash [h2];
- d3 = pos - (hash + kFix3HashSize)[h3];
-
- curMatch = (hash + kFix4HashSize)[hv];
-
- hash [h2] = pos;
- (hash + kFix3HashSize)[h3] = pos;
- (hash + kFix4HashSize)[hv] = pos;
-
- maxLen = 0;
- offset = 0;
-
- if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur)
- {
- maxLen = 2;
- distances[0] = 2;
- distances[1] = d2 - 1;
- offset = 2;
- }
-
- if (d2 != d3 && d3 < p->cyclicBufferSize && *(cur - d3) == *cur)
- {
- maxLen = 3;
- distances[(size_t)offset + 1] = d3 - 1;
- offset += 2;
- d2 = d3;
- }
-
- if (offset != 0)
- {
- UPDATE_maxLen
- distances[(size_t)offset - 2] = (UInt32)maxLen;
- if (maxLen == lenLimit)
- {
- SkipMatchesSpec((UInt32)lenLimit, curMatch, MF_PARAMS(p));
- MOVE_POS_RET;
- }
- }
-
- if (maxLen < 3)
- maxLen = 3;
-
- GET_MATCHES_FOOTER(offset, maxLen)
-}
-
-/*
-static UInt32 Bt5_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
-{
- UInt32 h2, h3, h4, d2, d3, d4, maxLen, offset, pos;
- UInt32 *hash;
- GET_MATCHES_HEADER(5)
-
- HASH5_CALC;
-
- hash = p->hash;
- pos = p->pos;
-
- d2 = pos - hash [h2];
- d3 = pos - (hash + kFix3HashSize)[h3];
- d4 = pos - (hash + kFix4HashSize)[h4];
-
- curMatch = (hash + kFix5HashSize)[hv];
-
- hash [h2] = pos;
- (hash + kFix3HashSize)[h3] = pos;
- (hash + kFix4HashSize)[h4] = pos;
- (hash + kFix5HashSize)[hv] = pos;
-
- maxLen = 0;
- offset = 0;
-
- if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur)
- {
- distances[0] = maxLen = 2;
- distances[1] = d2 - 1;
- offset = 2;
- if (*(cur - d2 + 2) == cur[2])
- distances[0] = maxLen = 3;
- else if (d3 < p->cyclicBufferSize && *(cur - d3) == *cur)
- {
- distances[2] = maxLen = 3;
- distances[3] = d3 - 1;
- offset = 4;
- d2 = d3;
- }
- }
- else if (d3 < p->cyclicBufferSize && *(cur - d3) == *cur)
- {
- distances[0] = maxLen = 3;
- distances[1] = d3 - 1;
- offset = 2;
- d2 = d3;
- }
-
- if (d2 != d4 && d4 < p->cyclicBufferSize
- && *(cur - d4) == *cur
- && *(cur - d4 + 3) == *(cur + 3))
- {
- maxLen = 4;
- distances[(size_t)offset + 1] = d4 - 1;
- offset += 2;
- d2 = d4;
- }
-
- if (offset != 0)
- {
- UPDATE_maxLen
- distances[(size_t)offset - 2] = maxLen;
- if (maxLen == lenLimit)
- {
- SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));
- MOVE_POS_RET;
- }
- }
-
- if (maxLen < 4)
- maxLen = 4;
-
- GET_MATCHES_FOOTER(offset, maxLen)
-}
-*/
-
-static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
-{
- UInt32 h2, h3, d2, d3, pos;
- unsigned maxLen, offset;
- UInt32 *hash;
- GET_MATCHES_HEADER(4)
-
- HASH4_CALC;
-
- hash = p->hash;
- pos = p->pos;
-
- d2 = pos - hash [h2];
- d3 = pos - (hash + kFix3HashSize)[h3];
- curMatch = (hash + kFix4HashSize)[hv];
-
- hash [h2] = pos;
- (hash + kFix3HashSize)[h3] = pos;
- (hash + kFix4HashSize)[hv] = pos;
-
- maxLen = 0;
- offset = 0;
-
- if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur)
- {
- maxLen = 2;
- distances[0] = 2;
- distances[1] = d2 - 1;
- offset = 2;
- }
-
- if (d2 != d3 && d3 < p->cyclicBufferSize && *(cur - d3) == *cur)
- {
- maxLen = 3;
- distances[(size_t)offset + 1] = d3 - 1;
- offset += 2;
- d2 = d3;
- }
-
- if (offset != 0)
- {
- UPDATE_maxLen
- distances[(size_t)offset - 2] = (UInt32)maxLen;
- if (maxLen == lenLimit)
- {
- p->son[p->cyclicBufferPos] = curMatch;
- MOVE_POS_RET;
- }
- }
-
- if (maxLen < 3)
- maxLen = 3;
-
- offset = (unsigned)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
- distances + offset, maxLen) - (distances));
- MOVE_POS_RET
-}
-
-/*
-static UInt32 Hc5_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
-{
- UInt32 h2, h3, h4, d2, d3, d4, maxLen, offset, pos
- UInt32 *hash;
- GET_MATCHES_HEADER(5)
-
- HASH5_CALC;
-
- hash = p->hash;
- pos = p->pos;
-
- d2 = pos - hash [h2];
- d3 = pos - (hash + kFix3HashSize)[h3];
- d4 = pos - (hash + kFix4HashSize)[h4];
-
- curMatch = (hash + kFix5HashSize)[hv];
-
- hash [h2] = pos;
- (hash + kFix3HashSize)[h3] = pos;
- (hash + kFix4HashSize)[h4] = pos;
- (hash + kFix5HashSize)[hv] = pos;
-
- maxLen = 0;
- offset = 0;
-
- if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur)
- {
- distances[0] = maxLen = 2;
- distances[1] = d2 - 1;
- offset = 2;
- if (*(cur - d2 + 2) == cur[2])
- distances[0] = maxLen = 3;
- else if (d3 < p->cyclicBufferSize && *(cur - d3) == *cur)
- {
- distances[2] = maxLen = 3;
- distances[3] = d3 - 1;
- offset = 4;
- d2 = d3;
- }
- }
- else if (d3 < p->cyclicBufferSize && *(cur - d3) == *cur)
- {
- distances[0] = maxLen = 3;
- distances[1] = d3 - 1;
- offset = 2;
- d2 = d3;
- }
-
- if (d2 != d4 && d4 < p->cyclicBufferSize
- && *(cur - d4) == *cur
- && *(cur - d4 + 3) == *(cur + 3))
- {
- maxLen = 4;
- distances[(size_t)offset + 1] = d4 - 1;
- offset += 2;
- d2 = d4;
- }
-
- if (offset != 0)
- {
- UPDATE_maxLen
- distances[(size_t)offset - 2] = maxLen;
- if (maxLen == lenLimit)
- {
- p->son[p->cyclicBufferPos] = curMatch;
- MOVE_POS_RET;
- }
- }
-
- if (maxLen < 4)
- maxLen = 4;
-
- offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
- distances + offset, maxLen) - (distances));
- MOVE_POS_RET
-}
-*/
-
-UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
-{
- unsigned offset;
- GET_MATCHES_HEADER(3)
- HASH_ZIP_CALC;
- curMatch = p->hash[hv];
- p->hash[hv] = p->pos;
- offset = (unsigned)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
- distances, 2) - (distances));
- MOVE_POS_RET
-}
-
-static void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
-{
- do
- {
- SKIP_HEADER(2)
- HASH2_CALC;
- curMatch = p->hash[hv];
- p->hash[hv] = p->pos;
- SKIP_FOOTER
- }
- while (--num != 0);
-}
-
-void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
-{
- do
- {
- SKIP_HEADER(3)
- HASH_ZIP_CALC;
- curMatch = p->hash[hv];
- p->hash[hv] = p->pos;
- SKIP_FOOTER
- }
- while (--num != 0);
-}
-
-static void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
-{
- do
- {
- UInt32 h2;
- UInt32 *hash;
- SKIP_HEADER(3)
- HASH3_CALC;
- hash = p->hash;
- curMatch = (hash + kFix3HashSize)[hv];
- hash[h2] =
- (hash + kFix3HashSize)[hv] = p->pos;
- SKIP_FOOTER
- }
- while (--num != 0);
-}
-
-static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
-{
- 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;
- SKIP_FOOTER
- }
- while (--num != 0);
-}
-
-/*
-static void Bt5_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
-{
- do
- {
- UInt32 h2, h3, h4;
- UInt32 *hash;
- SKIP_HEADER(5)
- HASH5_CALC;
- hash = p->hash;
- curMatch = (hash + kFix5HashSize)[hv];
- hash [h2] =
- (hash + kFix3HashSize)[h3] =
- (hash + kFix4HashSize)[h4] =
- (hash + kFix5HashSize)[hv] = p->pos;
- SKIP_FOOTER
- }
- while (--num != 0);
-}
-*/
-
-static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
-{
- 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;
- MOVE_POS
- }
- while (--num != 0);
-}
-
-/*
-static void Hc5_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
-{
- do
- {
- UInt32 h2, h3, h4;
- UInt32 *hash;
- SKIP_HEADER(5)
- HASH5_CALC;
- hash = p->hash;
- curMatch = hash + kFix5HashSize)[hv];
- hash [h2] =
- (hash + kFix3HashSize)[h3] =
- (hash + kFix4HashSize)[h4] =
- (hash + kFix5HashSize)[hv] = p->pos;
- p->son[p->cyclicBufferPos] = curMatch;
- MOVE_POS
- }
- while (--num != 0);
-}
-*/
-
-void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
-{
- do
- {
- SKIP_HEADER(3)
- HASH_ZIP_CALC;
- curMatch = p->hash[hv];
- p->hash[hv] = p->pos;
- p->son[p->cyclicBufferPos] = curMatch;
- MOVE_POS
- }
- while (--num != 0);
-}
-
-void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable)
-{
- 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->numHashBytes <= 4) */
- {
- vTable->GetMatches = (Mf_GetMatches_Func)Hc4_MatchFinder_GetMatches;
- vTable->Skip = (Mf_Skip_Func)Hc4_MatchFinder_Skip;
- }
- /*
- else
- {
- vTable->GetMatches = (Mf_GetMatches_Func)Hc5_MatchFinder_GetMatches;
- vTable->Skip = (Mf_Skip_Func)Hc5_MatchFinder_Skip;
- }
- */
- }
- 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->GetMatches = (Mf_GetMatches_Func)Bt3_MatchFinder_GetMatches;
- 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;
- }
- /*
- else
- {
- vTable->GetMatches = (Mf_GetMatches_Func)Bt5_MatchFinder_GetMatches;
- vTable->Skip = (Mf_Skip_Func)Bt5_MatchFinder_Skip;
- }
- */
-}
diff --git a/deps/libchdr/deps/lzma-19.00/src/LzmaDec.c b/deps/libchdr/deps/lzma-19.00/src/LzmaDec.c
deleted file mode 100644
index ba3e1dd5..00000000
--- a/deps/libchdr/deps/lzma-19.00/src/LzmaDec.c
+++ /dev/null
@@ -1,1185 +0,0 @@
-/* LzmaDec.c -- LZMA Decoder
-2018-07-04 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#include
-
-/* #include "CpuArch.h" */
-#include "LzmaDec.h"
-
-#define kNumTopBits 24
-#define kTopValue ((UInt32)1 << kNumTopBits)
-
-#define kNumBitModelTotalBits 11
-#define kBitModelTotal (1 << kNumBitModelTotalBits)
-#define kNumMoveBits 5
-
-#define RC_INIT_SIZE 5
-
-#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) \
- { 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 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 TREE_DECODE(probs, limit, i) \
- { i = 1; do { TREE_GET_BIT(probs, i); } while (i < limit); i -= limit; }
-
-/* #define _LZMA_SIZE_OPT */
-
-#ifdef _LZMA_SIZE_OPT
-#define TREE_6_DECODE(probs, i) TREE_DECODE(probs, (1 << 6), i)
-#else
-#define TREE_6_DECODE(probs, i) \
- { i = 1; \
- TREE_GET_BIT(probs, i); \
- TREE_GET_BIT(probs, i); \
- TREE_GET_BIT(probs, i); \
- TREE_GET_BIT(probs, i); \
- TREE_GET_BIT(probs, i); \
- TREE_GET_BIT(probs, i); \
- i -= 0x40; }
-#endif
-
-#define NORMAL_LITER_DEC TREE_GET_BIT(prob, symbol)
-#define MATCHED_LITER_DEC \
- matchByte += matchByte; \
- bit = offs; \
- offs &= matchByte; \
- 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 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 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) \
- { UPDATE_0_CHECK; i += m; m += m; } else \
- { UPDATE_1_CHECK; m += m; i += m; }
-
-
-#define kNumPosBitsMax 4
-#define kNumPosStatesMax (1 << kNumPosBitsMax)
-
-#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 LenChoice LenLow
-#define LenChoice2 (LenLow + (1 << kLenNumLowBits))
-
-#define kNumStates 12
-#define kNumStates2 16
-#define kNumLitStates 7
-
-#define kStartPosModelIndex 4
-#define kEndPosModelIndex 14
-#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))
-
-#define kNumPosSlotBits 6
-#define kNumLenToPosStates 4
-
-#define kNumAlignBits 4
-#define kAlignTableSize (1 << kNumAlignBits)
-
-#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 GET_PROBS p->probs + kStartOffset
-#else
-#define kStartOffset 0
-#define GET_PROBS p->probs
-#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)
-
-#if Align != 0 && kStartOffset != 0
- #error Stop_Compiling_Bad_LZMA_kAlign
-#endif
-
-#if NUM_BASE_PROBS != 1984
- #error Stop_Compiling_Bad_LZMA_PROBS
-#endif
-
-
-#define LZMA_LIT_SIZE 0x300
-
-#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 LZMA_DIC_MIN (1 << 12)
-
-/*
-p->remainLen : shows status of LZMA decoder:
- < kMatchSpecLenStart : normal remain
- = kMatchSpecLenStart : finished
- = kMatchSpecLenStart + 1 : need init range coder
- = kMatchSpecLenStart + 2 : need init range coder and state
-*/
-
-/* ---------- 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
-
-/*
-LZMA_DECODE_REAL()
-In:
- RangeCoder is normalized
- if (p->dicPos == limit)
- {
- LzmaDec_TryDummy() was called before to exclude LITERAL and MATCH-REP cases.
- So first symbol can be only MATCH-NON-REP. And if that MATCH-NON-REP symbol
- is not END_OF_PAYALOAD_MARKER, then function returns error code.
- }
-
-Processing:
- first LZMA symbol will be decoded in any case
- All checks for limits are at the end of main loop,
- It will decode new LZMA-symbols while (p->buf < bufLimit && dicPos < limit),
- RangeCoder is still without last normalization when (p->buf < bufLimit) is being checked.
-
-Out:
- RangeCoder is normalized
- Result:
- SZ_OK - OK
- SZ_ERROR_DATA - Error
- p->remainLen:
- < kMatchSpecLenStart : normal remain
- = kMatchSpecLenStart : finished
-*/
-
-
-#ifdef _LZMA_DEC_OPT
-
-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)
-{
- 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);
- prob = probs + Literal;
- if (processedPos != 0 || checkDicSize != 0)
- prob += (UInt32)3 * ((((processedPos << 8) + dic[(dicPos == 0 ? dicBufSize : dicPos) - 1]) & lpMask) << lc);
- processedPos++;
-
- 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
- NORMAL_LITER_DEC
- NORMAL_LITER_DEC
- NORMAL_LITER_DEC
- NORMAL_LITER_DEC
- NORMAL_LITER_DEC
- NORMAL_LITER_DEC
- 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;
- MATCHED_LITER_DEC
- }
- while (symbol < 0x100);
- #else
- {
- unsigned bit;
- CLzmaProb *probLit;
- MATCHED_LITER_DEC
- MATCHED_LITER_DEC
- MATCHED_LITER_DEC
- MATCHED_LITER_DEC
- MATCHED_LITER_DEC
- MATCHED_LITER_DEC
- MATCHED_LITER_DEC
- MATCHED_LITER_DEC
- }
- #endif
- }
-
- dic[dicPos++] = (Byte)symbol;
- continue;
- }
-
- {
- UPDATE_1(prob);
- prob = probs + IsRep + state;
- IF_BIT_0(prob)
- {
- UPDATE_0(prob);
- state += kNumStates;
- 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);
- prob = probs + IsRep0Long + COMBINED_PS_STATE;
- 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);
- prob = probs + IsRepG1 + state;
- IF_BIT_0(prob)
- {
- UPDATE_0(prob);
- distance = rep1;
- }
- else
- {
- UPDATE_1(prob);
- prob = probs + IsRepG2 + state;
- IF_BIT_0(prob)
- {
- UPDATE_0(prob);
- distance = rep2;
- }
- else
- {
- UPDATE_1(prob);
- distance = rep3;
- rep3 = rep2;
- }
- rep2 = rep1;
- }
- rep1 = rep0;
- rep0 = distance;
- }
- state = state < kNumLitStates ? 8 : 11;
- prob = probs + RepLenCoder;
- }
-
- #ifdef _LZMA_SIZE_OPT
- {
- 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);
- probLen = prob + LenChoice2;
- IF_BIT_0(probLen)
- {
- UPDATE_0(probLen);
- probLen = prob + LenLow + GET_LEN_STATE + (1 << kLenNumLowBits);
- offset = kLenNumLowSymbols;
- lim = (1 << kLenNumLowBits);
- }
- else
- {
- UPDATE_1(probLen);
- probLen = prob + LenHigh;
- offset = kLenNumLowSymbols * 2;
- lim = (1 << kLenNumHighBits);
- }
- }
- TREE_DECODE(probLen, lim, len);
- len += offset;
- }
- #else
- {
- 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 -= 8;
- }
- else
- {
- UPDATE_1(probLen);
- probLen = prob + LenChoice2;
- 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);
- probLen = prob + LenHigh;
- TREE_DECODE(probLen, (1 << kLenNumHighBits), len);
- len += kLenNumLowSymbols * 2;
- }
- }
- }
- #endif
-
- 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));
- distance = (2 | (distance & 1));
- if (posSlot < kEndPosModelIndex)
- {
- distance <<= numDirectBits;
- prob = probs + SpecPos;
- {
- UInt32 m = 1;
- distance++;
- do
- {
- REV_BIT_VAR(prob, distance, m);
- }
- while (--numDirectBits);
- distance -= m;
- }
- }
- else
- {
- numDirectBits -= kNumAlignBits;
- do
- {
- NORMALIZE
- range >>= 1;
-
- {
- UInt32 t;
- code -= range;
- t = (0 - ((UInt32)code >> 31)); /* (UInt32)((Int32)code >> 31) */
- distance = (distance << 1) + (t + 1);
- code += range & t;
- }
- /*
- distance <<= 1;
- if (code >= range)
- {
- code -= range;
- distance |= 1;
- }
- */
- }
- 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);
- REV_BIT_LAST (prob, i, 8);
- distance |= i;
- }
- if (distance == (UInt32)0xFFFFFFFF)
- {
- len = kMatchSpecLenStart;
- state -= kNumStates;
- break;
- }
- }
- }
-
- rep3 = rep2;
- rep2 = rep1;
- rep1 = rep0;
- rep0 = distance + 1;
- state = (state < kNumStates + kNumLitStates) ? kNumLitStates : kNumLitStates + 3;
- if (distance >= (checkDicSize == 0 ? processedPos: checkDicSize))
- {
- p->dicPos = dicPos;
- return SZ_ERROR_DATA;
- }
- }
-
- len += kMatchMinLen;
-
- {
- SizeT rem;
- unsigned curLen;
- SizeT pos;
-
- 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);
-
- 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;
- dicPos += (SizeT)curLen;
- do
- *(dest) = (Byte)*(dest + src);
- while (++dest != lim);
- }
- else
- {
- do
- {
- dic[dicPos++] = dic[pos];
- if (++pos == dicBufSize)
- pos = 0;
- }
- while (--curLen != 0);
- }
- }
- }
- }
- while (dicPos < limit && buf < bufLimit);
-
- NORMALIZE;
-
- 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;
-
- return SZ_OK;
-}
-#endif
-
-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)
- len = (unsigned)(rem);
-
- 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)
- {
- 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)))
-#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)
-{
- 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)
- return SZ_ERROR_DATA;
- }
-
- RINOK(LZMA_DECODE_REAL(p, limit2, bufLimit));
-
- 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);
-
- return 0;
-}
-
-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)
-{
- 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);
-
- prob = probs + IsMatch + COMBINED_PS_STATE;
- 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))));
-
- 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);
- }
- res = DUMMY_LIT;
- }
- else
- {
- unsigned len;
- UPDATE_1_CHECK;
-
- prob = probs + IsRep + state;
- IF_BIT_0_CHECK(prob)
- {
- UPDATE_0_CHECK;
- state = 0;
- prob = probs + LenCoder;
- res = DUMMY_MATCH;
- }
- else
- {
- UPDATE_1_CHECK;
- res = DUMMY_REP;
- prob = probs + IsRepG0 + state;
- IF_BIT_0_CHECK(prob)
- {
- UPDATE_0_CHECK;
- prob = probs + IsRep0Long + COMBINED_PS_STATE;
- IF_BIT_0_CHECK(prob)
- {
- UPDATE_0_CHECK;
- NORMALIZE_CHECK;
- return DUMMY_REP;
- }
- else
- {
- UPDATE_1_CHECK;
- }
- }
- else
- {
- UPDATE_1_CHECK;
- prob = probs + IsRepG1 + state;
- IF_BIT_0_CHECK(prob)
- {
- UPDATE_0_CHECK;
- }
- else
- {
- UPDATE_1_CHECK;
- prob = probs + IsRepG2 + state;
- IF_BIT_0_CHECK(prob)
- {
- UPDATE_0_CHECK;
- }
- else
- {
- UPDATE_1_CHECK;
- }
- }
- }
- state = kNumStates;
- prob = probs + RepLenCoder;
- }
- {
- 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
- {
- UPDATE_1_CHECK;
- probLen = prob + LenChoice2;
- IF_BIT_0_CHECK(probLen)
- {
- UPDATE_0_CHECK;
- probLen = prob + LenLow + GET_LEN_STATE + (1 << kLenNumLowBits);
- offset = kLenNumLowSymbols;
- limit = 1 << kLenNumLowBits;
- }
- else
- {
- UPDATE_1_CHECK;
- probLen = prob + LenHigh;
- offset = kLenNumLowSymbols * 2;
- limit = 1 << kLenNumHighBits;
- }
- }
- TREE_DECODE_CHECK(probLen, limit, len);
- len += offset;
- }
-
- 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);
-
- /* if (bufLimit - buf >= 8) return DUMMY_MATCH; */
-
- if (posSlot < kEndPosModelIndex)
- {
- prob = probs + SpecPos + ((2 | (posSlot & 1)) << numDirectBits);
- }
- else
- {
- numDirectBits -= kNumAlignBits;
- do
- {
- NORMALIZE_CHECK
- range >>= 1;
- code -= range & (((code - range) >> 31) - 1);
- /* if (code >= range) code -= range; */
- }
- while (--numDirectBits);
- prob = probs + Align;
- numDirectBits = kNumAlignBits;
- }
- {
- 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)
-{
- p->remainLen = kMatchSpecLenStart + 1;
- p->tempBufSize = 0;
-
- if (initDic)
- {
- p->processedPos = 0;
- p->checkDicSize = 0;
- p->remainLen = kMatchSpecLenStart + 2;
- }
- if (initState)
- p->remainLen = kMatchSpecLenStart + 2;
-}
-
-void LzmaDec_Init(CLzmaDec *p)
-{
- p->dicPos = 0;
- LzmaDec_InitDicAndState(p, True, True);
-}
-
-
-SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen,
- ELzmaFinishMode finishMode, ELzmaStatus *status)
-{
- SizeT inSize = *srcLen;
- (*srcLen) = 0;
-
- *status = LZMA_STATUS_NOT_SPECIFIED;
-
- 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)
- return SZ_ERROR_DATA;
- 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[2] << 16)
- | ((UInt32)p->tempBuf[3] << 8)
- | ((UInt32)p->tempBuf[4]);
- 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++)
- probs[i] = kBitModelTotal >> 1;
- p->reps[0] = p->reps[1] = p->reps[2] = p->reps[3] = 1;
- p->state = 0;
- }
-
- p->remainLen = 0;
- }
-
- LzmaDec_WriteRem(p, dicLimit);
-
- 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;
- 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 (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 (checkEndMarkNow && dummyRes != DUMMY_MATCH)
- {
- *status = LZMA_STATUS_NOT_FINISHED;
- return SZ_ERROR_DATA;
- }
- }
- 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;
- }
- (*srcLen) += (SizeT)lookAhead;
- src += lookAhead;
- inSize -= (SizeT)lookAhead;
- p->tempBufSize = 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)
-{
- SizeT outSize = *destLen;
- SizeT inSize = *srcLen;
- *srcLen = *destLen = 0;
- 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;
- curFinishMode = LZMA_FINISH_ANY;
- }
- else
- {
- outSizeCur = dicPos + outSize;
- curFinishMode = finishMode;
- }
-
- 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;
- *destLen += outSizeCur;
- if (res != 0)
- return res;
- if (outSizeCur == 0 || outSize == 0)
- return SZ_OK;
- }
-}
-
-void LzmaDec_FreeProbs(CLzmaDec *p, ISzAllocPtr alloc)
-{
- ISzAlloc_Free(alloc, p->probs);
- p->probs = NULL;
-}
-
-static void LzmaDec_FreeDict(CLzmaDec *p, ISzAllocPtr alloc)
-{
- ISzAlloc_Free(alloc, p->dic);
- p->dic = NULL;
-}
-
-void LzmaDec_Free(CLzmaDec *p, ISzAllocPtr alloc)
-{
- LzmaDec_FreeProbs(p, alloc);
- LzmaDec_FreeDict(p, alloc);
-}
-
-SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)
-{
- UInt32 dicSize;
- Byte d;
-
- if (size < LZMA_PROPS_SIZE)
- return SZ_ERROR_UNSUPPORTED;
- else
- dicSize = data[1] | ((UInt32)data[2] << 8) | ((UInt32)data[3] << 16) | ((UInt32)data[4] << 24);
-
- if (dicSize < LZMA_DIC_MIN)
- dicSize = LZMA_DIC_MIN;
- p->dicSize = dicSize;
-
- d = data[0];
- if (d >= (9 * 5 * 5))
- return SZ_ERROR_UNSUPPORTED;
-
- p->lc = (Byte)(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)
-{
- 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;
- }
- return SZ_OK;
-}
-
-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));
- p->prop = propNew;
- return SZ_OK;
-}
-
-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));
-
- {
- 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)
- 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);
- return SZ_ERROR_MEM;
- }
- }
- p->dicBufSize = dicBufSize;
- 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)
-{
- CLzmaDec p;
- SRes res;
- SizeT outSize = *destLen, inSize = *srcLen;
- *destLen = *srcLen = 0;
- *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;
- p.dicBufSize = outSize;
- 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)
- res = SZ_ERROR_INPUT_EOF;
- LzmaDec_FreeProbs(&p, alloc);
- return res;
-}
diff --git a/deps/libchdr/deps/lzma-19.00/src/LzmaEnc.c b/deps/libchdr/deps/lzma-19.00/src/LzmaEnc.c
deleted file mode 100644
index 2d3839df..00000000
--- a/deps/libchdr/deps/lzma-19.00/src/LzmaEnc.c
+++ /dev/null
@@ -1,1330 +0,0 @@
-/* LzmaEnc.c -- LZMA Encoder
-2019-01-10: Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#include
-
-/* #define SHOW_STAT */
-/* #define SHOW_STAT2 */
-
-#if defined(SHOW_STAT) || defined(SHOW_STAT2)
-#include
-#endif
-
-#include "LzmaEnc.h"
-
-#include "LzFind.h"
-#ifndef _7ZIP_ST
-#include "LzFindMt.h"
-#endif
-
-#ifdef SHOW_STAT
-static unsigned g_STAT_OFFSET = 0;
-#endif
-
-#define kLzmaMaxHistorySize ((UInt32)3 << 29)
-/* #define kLzmaMaxHistorySize ((UInt32)7 << 29) */
-
-#define kNumTopBits 24
-#define kTopValue ((UInt32)1 << kNumTopBits)
-
-#define kNumBitModelTotalBits 11
-#define kBitModelTotal (1 << kNumBitModelTotalBits)
-#define kNumMoveBits 5
-#define kProbInitValue (kBitModelTotal >> 1)
-
-#define kNumMoveReducingBits 4
-#define kNumBitPriceShiftBits 4
-#define kBitPrice (1 << kNumBitPriceShiftBits)
-
-#define REP_LEN_COUNT 64
-
-void LzmaEncProps_Init(CLzmaEncProps *p)
-{
- p->level = 5;
- p->dictSize = p->mc = 0;
- p->reduceSize = (UInt64)(Int64)-1;
- p->lc = p->lp = p->pb = p->algo = p->fb = p->btMode = p->numHashBytes = p->numThreads = -1;
- p->writeEndMark = 0;
-}
-
-void LzmaEncProps_Normalize(CLzmaEncProps *p)
-{
- int level = p->level;
- if (level < 0) level = 5;
- p->level = level;
-
- if (p->dictSize == 0) p->dictSize = (level <= 5 ? (1 << (level * 2 + 14)) : (level <= 7 ? (1 << 25) : (1 << 26)));
- if (p->dictSize > p->reduceSize)
- {
- unsigned i;
- UInt32 reduceSize = (UInt32)p->reduceSize;
- for (i = 11; i <= 30; i++)
- {
- if (reduceSize <= ((UInt32)2 << i)) { p->dictSize = ((UInt32)2 << i); break; }
- if (reduceSize <= ((UInt32)3 << i)) { p->dictSize = ((UInt32)3 << i); break; }
- }
- }
-
- if (p->lc < 0) p->lc = 3;
- if (p->lp < 0) p->lp = 0;
- if (p->pb < 0) p->pb = 2;
-
- if (p->algo < 0) p->algo = (level < 5 ? 0 : 1);
- if (p->fb < 0) p->fb = (level < 7 ? 32 : 64);
- if (p->btMode < 0) p->btMode = (p->algo == 0 ? 0 : 1);
- if (p->numHashBytes < 0) p->numHashBytes = 4;
- if (p->mc == 0) p->mc = (16 + (p->fb >> 1)) >> (p->btMode ? 0 : 1);
-
- if (p->numThreads < 0)
- p->numThreads =
- #ifndef _7ZIP_ST
- ((p->btMode && p->algo) ? 2 : 1);
- #else
- 1;
- #endif
-}
-
-UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2)
-{
- CLzmaEncProps props = *props2;
- LzmaEncProps_Normalize(&props);
- return props.dictSize;
-}
-
-#if (_MSC_VER >= 1400)
-/* BSR code is fast for some new CPUs */
-/* #define LZMA_LOG_BSR */
-#endif
-
-#ifdef LZMA_LOG_BSR
-
-#define kDicLogSizeMaxCompress 32
-
-#define BSR2_RET(pos, res) { unsigned long zz; _BitScanReverse(&zz, (pos)); res = (zz + zz) + ((pos >> (zz - 1)) & 1); }
-
-static unsigned GetPosSlot1(UInt32 pos)
-{
- unsigned res;
- BSR2_RET(pos, res);
- return res;
-}
-#define GetPosSlot2(pos, res) { BSR2_RET(pos, res); }
-#define GetPosSlot(pos, res) { if (pos < 2) res = pos; else BSR2_RET(pos, res); }
-
-#else
-
-#define kNumLogBits (9 + sizeof(size_t) / 2)
-/* #define kNumLogBits (11 + sizeof(size_t) / 8 * 3) */
-
-#define kDicLogSizeMaxCompress ((kNumLogBits - 1) * 2 + 7)
-
-static void LzmaEnc_FastPosInit(Byte *g_FastPos)
-{
- unsigned slot;
- g_FastPos[0] = 0;
- g_FastPos[1] = 1;
- g_FastPos += 2;
-
- for (slot = 2; slot < kNumLogBits * 2; slot++)
- {
- size_t k = ((size_t)1 << ((slot >> 1) - 1));
- size_t j;
- for (j = 0; j < k; j++)
- g_FastPos[j] = (Byte)slot;
- g_FastPos += k;
- }
-}
-
-/* we can use ((limit - pos) >> 31) only if (pos < ((UInt32)1 << 31)) */
-/*
-#define BSR2_RET(pos, res) { unsigned zz = 6 + ((kNumLogBits - 1) & \
- (0 - (((((UInt32)1 << (kNumLogBits + 6)) - 1) - pos) >> 31))); \
- res = p->g_FastPos[pos >> zz] + (zz * 2); }
-*/
-
-/*
-#define BSR2_RET(pos, res) { unsigned zz = 6 + ((kNumLogBits - 1) & \
- (0 - (((((UInt32)1 << (kNumLogBits)) - 1) - (pos >> 6)) >> 31))); \
- res = p->g_FastPos[pos >> zz] + (zz * 2); }
-*/
-
-#define BSR2_RET(pos, res) { unsigned zz = (pos < (1 << (kNumLogBits + 6))) ? 6 : 6 + kNumLogBits - 1; \
- res = p->g_FastPos[pos >> zz] + (zz * 2); }
-
-/*
-#define BSR2_RET(pos, res) { res = (pos < (1 << (kNumLogBits + 6))) ? \
- p->g_FastPos[pos >> 6] + 12 : \
- p->g_FastPos[pos >> (6 + kNumLogBits - 1)] + (6 + (kNumLogBits - 1)) * 2; }
-*/
-
-#define GetPosSlot1(pos) p->g_FastPos[pos]
-#define GetPosSlot2(pos, res) { BSR2_RET(pos, res); }
-#define GetPosSlot(pos, res) { if (pos < kNumFullDistances) res = p->g_FastPos[pos & (kNumFullDistances - 1)]; else BSR2_RET(pos, res); }
-
-#endif
-
-
-#define LZMA_NUM_REPS 4
-
-typedef UInt16 CState;
-typedef UInt16 CExtra;
-
-typedef struct
-{
- UInt32 price;
- CState state;
- CExtra extra;
- // 0 : normal
- // 1 : LIT : MATCH
- // > 1 : MATCH (extra-1) : LIT : REP0 (len)
- UInt32 len;
- UInt32 dist;
- UInt32 reps[LZMA_NUM_REPS];
-} COptimal;
-
-
-// 18.06
-#define kNumOpts (1 << 11)
-#define kPackReserve (kNumOpts * 8)
-// #define kNumOpts (1 << 12)
-// #define kPackReserve (1 + kNumOpts * 2)
-
-#define kNumLenToPosStates 4
-#define kNumPosSlotBits 6
-#define kDicLogSizeMin 0
-#define kDicLogSizeMax 32
-#define kDistTableSizeMax (kDicLogSizeMax * 2)
-
-#define kNumAlignBits 4
-#define kAlignTableSize (1 << kNumAlignBits)
-#define kAlignMask (kAlignTableSize - 1)
-
-#define kStartPosModelIndex 4
-#define kEndPosModelIndex 14
-#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))
-
-typedef
-#ifdef _LZMA_PROB32
- UInt32
-#else
- UInt16
-#endif
- CLzmaProb;
-
-#define LZMA_PB_MAX 4
-#define LZMA_LC_MAX 8
-#define LZMA_LP_MAX 4
-
-#define LZMA_NUM_PB_STATES_MAX (1 << LZMA_PB_MAX)
-
-#define kLenNumLowBits 3
-#define kLenNumLowSymbols (1 << kLenNumLowBits)
-#define kLenNumHighBits 8
-#define kLenNumHighSymbols (1 << kLenNumHighBits)
-#define kLenNumSymbolsTotal (kLenNumLowSymbols * 2 + kLenNumHighSymbols)
-
-#define LZMA_MATCH_LEN_MIN 2
-#define LZMA_MATCH_LEN_MAX (LZMA_MATCH_LEN_MIN + kLenNumSymbolsTotal - 1)
-
-#define kNumStates 12
-
-
-typedef struct
-{
- CLzmaProb low[LZMA_NUM_PB_STATES_MAX << (kLenNumLowBits + 1)];
- CLzmaProb high[kLenNumHighSymbols];
-} CLenEnc;
-
-
-typedef struct
-{
- unsigned tableSize;
- UInt32 prices[LZMA_NUM_PB_STATES_MAX][kLenNumSymbolsTotal];
- // UInt32 prices1[LZMA_NUM_PB_STATES_MAX][kLenNumLowSymbols * 2];
- // UInt32 prices2[kLenNumSymbolsTotal];
-} CLenPriceEnc;
-
-#define GET_PRICE_LEN(p, posState, len) \
- ((p)->prices[posState][(size_t)(len) - LZMA_MATCH_LEN_MIN])
-
-/*
-#define GET_PRICE_LEN(p, posState, len) \
- ((p)->prices2[(size_t)(len) - 2] + ((p)->prices1[posState][((len) - 2) & (kLenNumLowSymbols * 2 - 1)] & (((len) - 2 - kLenNumLowSymbols * 2) >> 9)))
-*/
-
-typedef struct
-{
- UInt32 range;
- unsigned cache;
- UInt64 low;
- UInt64 cacheSize;
- Byte *buf;
- Byte *bufLim;
- Byte *bufBase;
- ISeqOutStream *outStream;
- UInt64 processed;
- SRes res;
-} CRangeEnc;
-
-
-typedef struct
-{
- CLzmaProb *litProbs;
-
- unsigned state;
- UInt32 reps[LZMA_NUM_REPS];
-
- CLzmaProb posAlignEncoder[1 << kNumAlignBits];
- CLzmaProb isRep[kNumStates];
- CLzmaProb isRepG0[kNumStates];
- CLzmaProb isRepG1[kNumStates];
- CLzmaProb isRepG2[kNumStates];
- CLzmaProb isMatch[kNumStates][LZMA_NUM_PB_STATES_MAX];
- CLzmaProb isRep0Long[kNumStates][LZMA_NUM_PB_STATES_MAX];
-
- CLzmaProb posSlotEncoder[kNumLenToPosStates][1 << kNumPosSlotBits];
- CLzmaProb posEncoders[kNumFullDistances];
-
- CLenEnc lenProbs;
- CLenEnc repLenProbs;
-
-} CSaveState;
-
-
-typedef UInt32 CProbPrice;
-
-
-typedef struct
-{
- void *matchFinderObj;
- IMatchFinder matchFinder;
-
- unsigned optCur;
- unsigned optEnd;
-
- unsigned longestMatchLen;
- unsigned numPairs;
- UInt32 numAvail;
-
- unsigned state;
- unsigned numFastBytes;
- unsigned additionalOffset;
- UInt32 reps[LZMA_NUM_REPS];
- unsigned lpMask, pbMask;
- CLzmaProb *litProbs;
- CRangeEnc rc;
-
- UInt32 backRes;
-
- unsigned lc, lp, pb;
- unsigned lclp;
-
- BoolInt fastMode;
- BoolInt writeEndMark;
- BoolInt finished;
- BoolInt multiThread;
- BoolInt needInit;
- // BoolInt _maxMode;
-
- UInt64 nowPos64;
-
- unsigned matchPriceCount;
- // unsigned alignPriceCount;
- int repLenEncCounter;
-
- unsigned distTableSize;
-
- UInt32 dictSize;
- SRes result;
-
- #ifndef _7ZIP_ST
- BoolInt mtMode;
- // begin of CMatchFinderMt is used in LZ thread
- CMatchFinderMt matchFinderMt;
- // end of CMatchFinderMt is used in BT and HASH threads
- #endif
-
- CMatchFinder matchFinderBase;
-
- #ifndef _7ZIP_ST
- Byte pad[128];
- #endif
-
- // LZ thread
- CProbPrice ProbPrices[kBitModelTotal >> kNumMoveReducingBits];
-
- UInt32 matches[LZMA_MATCH_LEN_MAX * 2 + 2 + 1];
-
- UInt32 alignPrices[kAlignTableSize];
- UInt32 posSlotPrices[kNumLenToPosStates][kDistTableSizeMax];
- UInt32 distancesPrices[kNumLenToPosStates][kNumFullDistances];
-
- CLzmaProb posAlignEncoder[1 << kNumAlignBits];
- CLzmaProb isRep[kNumStates];
- CLzmaProb isRepG0[kNumStates];
- CLzmaProb isRepG1[kNumStates];
- CLzmaProb isRepG2[kNumStates];
- CLzmaProb isMatch[kNumStates][LZMA_NUM_PB_STATES_MAX];
- CLzmaProb isRep0Long[kNumStates][LZMA_NUM_PB_STATES_MAX];
- CLzmaProb posSlotEncoder[kNumLenToPosStates][1 << kNumPosSlotBits];
- CLzmaProb posEncoders[kNumFullDistances];
-
- CLenEnc lenProbs;
- CLenEnc repLenProbs;
-
- #ifndef LZMA_LOG_BSR
- Byte g_FastPos[1 << kNumLogBits];
- #endif
-
- CLenPriceEnc lenEnc;
- CLenPriceEnc repLenEnc;
-
- COptimal opt[kNumOpts];
-
- CSaveState saveState;
-
- #ifndef _7ZIP_ST
- Byte pad2[128];
- #endif
-} CLzmaEnc;
-
-
-SRes LzmaEnc_SetProps(CLzmaEncHandle pp, const CLzmaEncProps *props2)
-{
- CLzmaEnc *p = (CLzmaEnc *)pp;
- CLzmaEncProps props = *props2;
- LzmaEncProps_Normalize(&props);
-
- if (props.lc > LZMA_LC_MAX
- || props.lp > LZMA_LP_MAX
- || props.pb > LZMA_PB_MAX
- || props.dictSize > ((UInt64)1 << kDicLogSizeMaxCompress)
- || props.dictSize > kLzmaMaxHistorySize)
- return SZ_ERROR_PARAM;
-
- p->dictSize = props.dictSize;
- {
- unsigned fb = props.fb;
- if (fb < 5)
- fb = 5;
- if (fb > LZMA_MATCH_LEN_MAX)
- fb = LZMA_MATCH_LEN_MAX;
- p->numFastBytes = fb;
- }
- p->lc = props.lc;
- p->lp = props.lp;
- p->pb = props.pb;
- p->fastMode = (props.algo == 0);
- // p->_maxMode = True;
- p->matchFinderBase.btMode = (Byte)(props.btMode ? 1 : 0);
- {
- unsigned numHashBytes = 4;
- if (props.btMode)
- {
- if (props.numHashBytes < 2)
- numHashBytes = 2;
- else if (props.numHashBytes < 4)
- numHashBytes = props.numHashBytes;
- }
- p->matchFinderBase.numHashBytes = numHashBytes;
- }
-
- p->matchFinderBase.cutValue = props.mc;
-
- p->writeEndMark = props.writeEndMark;
-
- #ifndef _7ZIP_ST
- /*
- if (newMultiThread != _multiThread)
- {
- ReleaseMatchFinder();
- _multiThread = newMultiThread;
- }
- */
- p->multiThread = (props.numThreads > 1);
- #endif
-
- return SZ_OK;
-}
-
-
-void LzmaEnc_SetDataSize(CLzmaEncHandle pp, UInt64 expectedDataSiize)
-{
- CLzmaEnc *p = (CLzmaEnc *)pp;
- p->matchFinderBase.expectedDataSize = expectedDataSiize;
-}
-
-
-#define kState_Start 0
-#define kState_LitAfterMatch 4
-#define kState_LitAfterRep 5
-#define kState_MatchAfterLit 7
-#define kState_RepAfterLit 8
-
-static const Byte kLiteralNextStates[kNumStates] = {0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5};
-static const Byte kMatchNextStates[kNumStates] = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};
-static const Byte kRepNextStates[kNumStates] = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};
-static const Byte kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};
-
-#define IsLitState(s) ((s) < 7)
-#define GetLenToPosState2(len) (((len) < kNumLenToPosStates - 1) ? (len) : kNumLenToPosStates - 1)
-#define GetLenToPosState(len) (((len) < kNumLenToPosStates + 1) ? (len) - 2 : kNumLenToPosStates - 1)
-
-#define kInfinityPrice (1 << 30)
-
-static void RangeEnc_Construct(CRangeEnc *p)
-{
- p->outStream = NULL;
- p->bufBase = NULL;
-}
-
-#define RangeEnc_GetProcessed(p) ((p)->processed + ((p)->buf - (p)->bufBase) + (p)->cacheSize)
-#define RangeEnc_GetProcessed_sizet(p) ((size_t)(p)->processed + ((p)->buf - (p)->bufBase) + (size_t)(p)->cacheSize)
-
-#define RC_BUF_SIZE (1 << 16)
-
-static int RangeEnc_Alloc(CRangeEnc *p, ISzAllocPtr alloc)
-{
- if (!p->bufBase)
- {
- p->bufBase = (Byte *)ISzAlloc_Alloc(alloc, RC_BUF_SIZE);
- if (!p->bufBase)
- return 0;
- p->bufLim = p->bufBase + RC_BUF_SIZE;
- }
- return 1;
-}
-
-static void RangeEnc_Free(CRangeEnc *p, ISzAllocPtr alloc)
-{
- ISzAlloc_Free(alloc, p->bufBase);
- p->bufBase = 0;
-}
-
-static void RangeEnc_Init(CRangeEnc *p)
-{
- /* Stream.Init(); */
- p->range = 0xFFFFFFFF;
- p->cache = 0;
- p->low = 0;
- p->cacheSize = 0;
-
- p->buf = p->bufBase;
-
- p->processed = 0;
- p->res = SZ_OK;
-}
-
-MY_NO_INLINE static void RangeEnc_FlushStream(CRangeEnc *p)
-{
- size_t num;
- if (p->res != SZ_OK)
- return;
- num = p->buf - p->bufBase;
- if (num != ISeqOutStream_Write(p->outStream, p->bufBase, num))
- p->res = SZ_ERROR_WRITE;
- p->processed += num;
- p->buf = p->bufBase;
-}
-
-MY_NO_INLINE static void MY_FAST_CALL RangeEnc_ShiftLow(CRangeEnc *p)
-{
- UInt32 low = (UInt32)p->low;
- unsigned high = (unsigned)(p->low >> 32);
- p->low = (UInt32)(low << 8);
- if (low < (UInt32)0xFF000000 || high != 0)
- {
- {
- Byte *buf = p->buf;
- *buf++ = (Byte)(p->cache + high);
- p->cache = (unsigned)(low >> 24);
- p->buf = buf;
- if (buf == p->bufLim)
- RangeEnc_FlushStream(p);
- if (p->cacheSize == 0)
- return;
- }
- high += 0xFF;
- for (;;)
- {
- Byte *buf = p->buf;
- *buf++ = (Byte)(high);
- p->buf = buf;
- if (buf == p->bufLim)
- RangeEnc_FlushStream(p);
- if (--p->cacheSize == 0)
- return;
- }
- }
- p->cacheSize++;
-}
-
-static void RangeEnc_FlushData(CRangeEnc *p)
-{
- int i;
- for (i = 0; i < 5; i++)
- RangeEnc_ShiftLow(p);
-}
-
-#define RC_NORM(p) if (range < kTopValue) { range <<= 8; RangeEnc_ShiftLow(p); }
-
-#define RC_BIT_PRE(p, prob) \
- ttt = *(prob); \
- newBound = (range >> kNumBitModelTotalBits) * ttt;
-
-// #define _LZMA_ENC_USE_BRANCH
-
-#ifdef _LZMA_ENC_USE_BRANCH
-
-#define RC_BIT(p, prob, bit) { \
- RC_BIT_PRE(p, prob) \
- if (bit == 0) { range = newBound; ttt += (kBitModelTotal - ttt) >> kNumMoveBits; } \
- else { (p)->low += newBound; range -= newBound; ttt -= ttt >> kNumMoveBits; } \
- *(prob) = (CLzmaProb)ttt; \
- RC_NORM(p) \
- }
-
-#else
-
-#define RC_BIT(p, prob, bit) { \
- UInt32 mask; \
- RC_BIT_PRE(p, prob) \
- mask = 0 - (UInt32)bit; \
- range &= mask; \
- mask &= newBound; \
- range -= mask; \
- (p)->low += mask; \
- mask = (UInt32)bit - 1; \
- range += newBound & mask; \
- mask &= (kBitModelTotal - ((1 << kNumMoveBits) - 1)); \
- mask += ((1 << kNumMoveBits) - 1); \
- ttt += (Int32)(mask - ttt) >> kNumMoveBits; \
- *(prob) = (CLzmaProb)ttt; \
- RC_NORM(p) \
- }
-
-#endif
-
-
-
-
-#define RC_BIT_0_BASE(p, prob) \
- range = newBound; *(prob) = (CLzmaProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits));
-
-#define RC_BIT_1_BASE(p, prob) \
- range -= newBound; (p)->low += newBound; *(prob) = (CLzmaProb)(ttt - (ttt >> kNumMoveBits)); \
-
-#define RC_BIT_0(p, prob) \
- RC_BIT_0_BASE(p, prob) \
- RC_NORM(p)
-
-#define RC_BIT_1(p, prob) \
- RC_BIT_1_BASE(p, prob) \
- RC_NORM(p)
-
-static void RangeEnc_EncodeBit_0(CRangeEnc *p, CLzmaProb *prob)
-{
- UInt32 range, ttt, newBound;
- range = p->range;
- RC_BIT_PRE(p, prob)
- RC_BIT_0(p, prob)
- p->range = range;
-}
-
-static void LitEnc_Encode(CRangeEnc *p, CLzmaProb *probs, UInt32 sym)
-{
- UInt32 range = p->range;
- sym |= 0x100;
- do
- {
- UInt32 ttt, newBound;
- // RangeEnc_EncodeBit(p, probs + (sym >> 8), (sym >> 7) & 1);
- CLzmaProb *prob = probs + (sym >> 8);
- UInt32 bit = (sym >> 7) & 1;
- sym <<= 1;
- RC_BIT(p, prob, bit);
- }
- while (sym < 0x10000);
- p->range = range;
-}
-
-static void LzmaEnc_InitPriceTables(CProbPrice *ProbPrices)
-{
- UInt32 i;
- for (i = 0; i < (kBitModelTotal >> kNumMoveReducingBits); i++)
- {
- const unsigned kCyclesBits = kNumBitPriceShiftBits;
- UInt32 w = (i << kNumMoveReducingBits) + (1 << (kNumMoveReducingBits - 1));
- unsigned bitCount = 0;
- unsigned j;
- for (j = 0; j < kCyclesBits; j++)
- {
- w = w * w;
- bitCount <<= 1;
- while (w >= ((UInt32)1 << 16))
- {
- w >>= 1;
- bitCount++;
- }
- }
- ProbPrices[i] = (CProbPrice)((kNumBitModelTotalBits << kCyclesBits) - 15 - bitCount);
- // printf("\n%3d: %5d", i, ProbPrices[i]);
- }
-}
-
-
-#define GET_PRICE(prob, bit) \
- p->ProbPrices[((prob) ^ (unsigned)(((-(int)(bit))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits];
-
-#define GET_PRICEa(prob, bit) \
- ProbPrices[((prob) ^ (unsigned)((-((int)(bit))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits];
-
-#define GET_PRICE_0(prob) p->ProbPrices[(prob) >> kNumMoveReducingBits]
-#define GET_PRICE_1(prob) p->ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]
-
-#define GET_PRICEa_0(prob) ProbPrices[(prob) >> kNumMoveReducingBits]
-#define GET_PRICEa_1(prob) ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]
-
-
-static UInt32 LitEnc_GetPrice(const CLzmaProb *probs, UInt32 sym, const CProbPrice *ProbPrices)
-{
- UInt32 price = 0;
- sym |= 0x100;
- do
- {
- unsigned bit = sym & 1;
- sym >>= 1;
- price += GET_PRICEa(probs[sym], bit);
- }
- while (sym >= 2);
- return price;
-}
-
-
-static UInt32 LitEnc_Matched_GetPrice(const CLzmaProb *probs, UInt32 sym, UInt32 matchByte, const CProbPrice *ProbPrices)
-{
- UInt32 price = 0;
- UInt32 offs = 0x100;
- sym |= 0x100;
- do
- {
- matchByte <<= 1;
- price += GET_PRICEa(probs[offs + (matchByte & offs) + (sym >> 8)], (sym >> 7) & 1);
- sym <<= 1;
- offs &= ~(matchByte ^ sym);
- }
- while (sym < 0x10000);
- return price;
-}
-
-
-
-static void LenEnc_Init(CLenEnc *p)
-{
- unsigned i;
- for (i = 0; i < (LZMA_NUM_PB_STATES_MAX << (kLenNumLowBits + 1)); i++)
- p->low[i] = kProbInitValue;
- for (i = 0; i < kLenNumHighSymbols; i++)
- p->high[i] = kProbInitValue;
-}
-
-static void LenEnc_Encode(CLenEnc *p, CRangeEnc *rc, unsigned sym, unsigned posState)
-{
- UInt32 range, ttt, newBound;
- CLzmaProb *probs = p->low;
- range = rc->range;
- RC_BIT_PRE(rc, probs);
- if (sym >= kLenNumLowSymbols)
- {
- RC_BIT_1(rc, probs);
- probs += kLenNumLowSymbols;
- RC_BIT_PRE(rc, probs);
- if (sym >= kLenNumLowSymbols * 2)
- {
- RC_BIT_1(rc, probs);
- rc->range = range;
- // RcTree_Encode(rc, p->high, kLenNumHighBits, sym - kLenNumLowSymbols * 2);
- LitEnc_Encode(rc, p->high, sym - kLenNumLowSymbols * 2);
- return;
- }
- sym -= kLenNumLowSymbols;
- }
-
- // RcTree_Encode(rc, probs + (posState << kLenNumLowBits), kLenNumLowBits, sym);
- {
- unsigned m;
- unsigned bit;
- RC_BIT_0(rc, probs);
- probs += (posState << (1 + kLenNumLowBits));
- bit = (sym >> 2) ; RC_BIT(rc, probs + 1, bit); m = (1 << 1) + bit;
- bit = (sym >> 1) & 1; RC_BIT(rc, probs + m, bit); m = (m << 1) + bit;
- bit = sym & 1; RC_BIT(rc, probs + m, bit);
- rc->range = range;
- }
-}
-
-static void SetPrices_3(const CLzmaProb *probs, UInt32 startPrice, UInt32 *prices, const CProbPrice *ProbPrices)
-{
- unsigned i;
- for (i = 0; i < 8; i += 2)
- {
- UInt32 price = startPrice;
- UInt32 prob;
- price += GET_PRICEa(probs[1 ], (i >> 2));
- price += GET_PRICEa(probs[2 + (i >> 2)], (i >> 1) & 1);
- prob = probs[4 + (i >> 1)];
- prices[i ] = price + GET_PRICEa_0(prob);
- prices[i + 1] = price + GET_PRICEa_1(prob);
- }
-}
-
-
-MY_NO_INLINE static void MY_FAST_CALL LenPriceEnc_UpdateTables(
- CLenPriceEnc *p,
- unsigned numPosStates,
- const CLenEnc *enc,
- const CProbPrice *ProbPrices)
-{
- UInt32 b;
-
- {
- unsigned prob = enc->low[0];
- UInt32 a, c;
- unsigned posState;
- b = GET_PRICEa_1(prob);
- a = GET_PRICEa_0(prob);
- c = b + GET_PRICEa_0(enc->low[kLenNumLowSymbols]);
- for (posState = 0; posState < numPosStates; posState++)
- {
- UInt32 *prices = p->prices[posState];
- const CLzmaProb *probs = enc->low + (posState << (1 + kLenNumLowBits));
- SetPrices_3(probs, a, prices, ProbPrices);
- SetPrices_3(probs + kLenNumLowSymbols, c, prices + kLenNumLowSymbols, ProbPrices);
- }
- }
-
- /*
- {
- unsigned i;
- UInt32 b;
- a = GET_PRICEa_0(enc->low[0]);
- for (i = 0; i < kLenNumLowSymbols; i++)
- p->prices2[i] = a;
- a = GET_PRICEa_1(enc->low[0]);
- b = a + GET_PRICEa_0(enc->low[kLenNumLowSymbols]);
- for (i = kLenNumLowSymbols; i < kLenNumLowSymbols * 2; i++)
- p->prices2[i] = b;
- a += GET_PRICEa_1(enc->low[kLenNumLowSymbols]);
- }
- */
-
- // p->counter = numSymbols;
- // p->counter = 64;
-
- {
- unsigned i = p->tableSize;
-
- if (i > kLenNumLowSymbols * 2)
- {
- const CLzmaProb *probs = enc->high;
- UInt32 *prices = p->prices[0] + kLenNumLowSymbols * 2;
- i -= kLenNumLowSymbols * 2 - 1;
- i >>= 1;
- b += GET_PRICEa_1(enc->low[kLenNumLowSymbols]);
- do
- {
- /*
- p->prices2[i] = a +
- // RcTree_GetPrice(enc->high, kLenNumHighBits, i - kLenNumLowSymbols * 2, ProbPrices);
- LitEnc_GetPrice(probs, i - kLenNumLowSymbols * 2, ProbPrices);
- */
- // UInt32 price = a + RcTree_GetPrice(probs, kLenNumHighBits - 1, sym, ProbPrices);
- unsigned sym = --i + (1 << (kLenNumHighBits - 1));
- UInt32 price = b;
- do
- {
- unsigned bit = sym & 1;
- sym >>= 1;
- price += GET_PRICEa(probs[sym], bit);
- }
- while (sym >= 2);
-
- {
- unsigned prob = probs[(size_t)i + (1 << (kLenNumHighBits - 1))];
- prices[(size_t)i * 2 ] = price + GET_PRICEa_0(prob);
- prices[(size_t)i * 2 + 1] = price + GET_PRICEa_1(prob);
- }
- }
- while (i);
-
- {
- unsigned posState;
- size_t num = (p->tableSize - kLenNumLowSymbols * 2) * sizeof(p->prices[0][0]);
- for (posState = 1; posState < numPosStates; posState++)
- memcpy(p->prices[posState] + kLenNumLowSymbols * 2, p->prices[0] + kLenNumLowSymbols * 2, num);
- }
- }
- }
-}
-
-/*
- #ifdef SHOW_STAT
- g_STAT_OFFSET += num;
- printf("\n MovePos %u", num);
- #endif
-*/
-
-#define MOVE_POS(p, num) { \
- p->additionalOffset += (num); \
- p->matchFinder.Skip(p->matchFinderObj, (UInt32)(num)); }
-
-
-#define MARK_LIT ((UInt32)(Int32)-1)
-
-#define MakeAs_Lit(p) { (p)->dist = MARK_LIT; (p)->extra = 0; }
-#define MakeAs_ShortRep(p) { (p)->dist = 0; (p)->extra = 0; }
-#define IsShortRep(p) ((p)->dist == 0)
-
-
-#define GetPrice_ShortRep(p, state, posState) \
- ( GET_PRICE_0(p->isRepG0[state]) + GET_PRICE_0(p->isRep0Long[state][posState]))
-
-#define GetPrice_Rep_0(p, state, posState) ( \
- GET_PRICE_1(p->isMatch[state][posState]) \
- + GET_PRICE_1(p->isRep0Long[state][posState])) \
- + GET_PRICE_1(p->isRep[state]) \
- + GET_PRICE_0(p->isRepG0[state])
-
-MY_FORCE_INLINE
-static UInt32 GetPrice_PureRep(const CLzmaEnc *p, unsigned repIndex, size_t state, size_t posState)
-{
- UInt32 price;
- UInt32 prob = p->isRepG0[state];
- if (repIndex == 0)
- {
- price = GET_PRICE_0(prob);
- price += GET_PRICE_1(p->isRep0Long[state][posState]);
- }
- else
- {
- price = GET_PRICE_1(prob);
- prob = p->isRepG1[state];
- if (repIndex == 1)
- price += GET_PRICE_0(prob);
- else
- {
- price += GET_PRICE_1(prob);
- price += GET_PRICE(p->isRepG2[state], repIndex - 2);
- }
- }
- return price;
-}
-
-
-static SRes CheckErrors(CLzmaEnc *p)
-{
- if (p->result != SZ_OK)
- return p->result;
- if (p->rc.res != SZ_OK)
- p->result = SZ_ERROR_WRITE;
- if (p->matchFinderBase.result != SZ_OK)
- p->result = SZ_ERROR_READ;
- if (p->result != SZ_OK)
- p->finished = True;
- return p->result;
-}
-
-
-MY_NO_INLINE static void FillAlignPrices(CLzmaEnc *p)
-{
- unsigned i;
- const CProbPrice *ProbPrices = p->ProbPrices;
- const CLzmaProb *probs = p->posAlignEncoder;
- // p->alignPriceCount = 0;
- for (i = 0; i < kAlignTableSize / 2; i++)
- {
- UInt32 price = 0;
- unsigned sym = i;
- unsigned m = 1;
- unsigned bit;
- UInt32 prob;
- bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[m], bit); m = (m << 1) + bit;
- bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[m], bit); m = (m << 1) + bit;
- bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[m], bit); m = (m << 1) + bit;
- prob = probs[m];
- p->alignPrices[i ] = price + GET_PRICEa_0(prob);
- p->alignPrices[i + 8] = price + GET_PRICEa_1(prob);
- // p->alignPrices[i] = RcTree_ReverseGetPrice(p->posAlignEncoder, kNumAlignBits, i, p->ProbPrices);
- }
-}
-
-
-MY_NO_INLINE static void FillDistancesPrices(CLzmaEnc *p)
-{
- // int y; for (y = 0; y < 100; y++) {
-
- UInt32 tempPrices[kNumFullDistances];
- unsigned i, lps;
-
- const CProbPrice *ProbPrices = p->ProbPrices;
- p->matchPriceCount = 0;
-
- for (i = kStartPosModelIndex / 2; i < kNumFullDistances / 2; i++)
- {
- unsigned posSlot = GetPosSlot1(i);
- unsigned footerBits = (posSlot >> 1) - 1;
- unsigned base = ((2 | (posSlot & 1)) << footerBits);
- const CLzmaProb *probs = p->posEncoders + (size_t)base * 2;
- // tempPrices[i] = RcTree_ReverseGetPrice(p->posEncoders + base, footerBits, i - base, p->ProbPrices);
- UInt32 price = 0;
- unsigned m = 1;
- unsigned sym = i;
- unsigned offset = (unsigned)1 << footerBits;
- base += i;
-
- if (footerBits)
- do
- {
- unsigned bit = sym & 1;
- sym >>= 1;
- price += GET_PRICEa(probs[m], bit);
- m = (m << 1) + bit;
- }
- while (--footerBits);
-
- {
- unsigned prob = probs[m];
- tempPrices[base ] = price + GET_PRICEa_0(prob);
- tempPrices[base + offset] = price + GET_PRICEa_1(prob);
- }
- }
-
- for (lps = 0; lps < kNumLenToPosStates; lps++)
- {
- unsigned slot;
- unsigned distTableSize2 = (p->distTableSize + 1) >> 1;
- UInt32 *posSlotPrices = p->posSlotPrices[lps];
- const CLzmaProb *probs = p->posSlotEncoder[lps];
-
- for (slot = 0; slot < distTableSize2; slot++)
- {
- // posSlotPrices[slot] = RcTree_GetPrice(encoder, kNumPosSlotBits, slot, p->ProbPrices);
- UInt32 price;
- unsigned bit;
- unsigned sym = slot + (1 << (kNumPosSlotBits - 1));
- unsigned prob;
- bit = sym & 1; sym >>= 1; price = GET_PRICEa(probs[sym], bit);
- bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[sym], bit);
- bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[sym], bit);
- bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[sym], bit);
- bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[sym], bit);
- prob = probs[(size_t)slot + (1 << (kNumPosSlotBits - 1))];
- posSlotPrices[(size_t)slot * 2 ] = price + GET_PRICEa_0(prob);
- posSlotPrices[(size_t)slot * 2 + 1] = price + GET_PRICEa_1(prob);
- }
-
- {
- UInt32 delta = ((UInt32)((kEndPosModelIndex / 2 - 1) - kNumAlignBits) << kNumBitPriceShiftBits);
- for (slot = kEndPosModelIndex / 2; slot < distTableSize2; slot++)
- {
- posSlotPrices[(size_t)slot * 2 ] += delta;
- posSlotPrices[(size_t)slot * 2 + 1] += delta;
- delta += ((UInt32)1 << kNumBitPriceShiftBits);
- }
- }
-
- {
- UInt32 *dp = p->distancesPrices[lps];
-
- dp[0] = posSlotPrices[0];
- dp[1] = posSlotPrices[1];
- dp[2] = posSlotPrices[2];
- dp[3] = posSlotPrices[3];
-
- for (i = 4; i < kNumFullDistances; i += 2)
- {
- UInt32 slotPrice = posSlotPrices[GetPosSlot1(i)];
- dp[i ] = slotPrice + tempPrices[i];
- dp[i + 1] = slotPrice + tempPrices[i + 1];
- }
- }
- }
- // }
-}
-
-
-
-void LzmaEnc_Construct(CLzmaEnc *p)
-{
- RangeEnc_Construct(&p->rc);
- MatchFinder_Construct(&p->matchFinderBase);
-
- #ifndef _7ZIP_ST
- MatchFinderMt_Construct(&p->matchFinderMt);
- p->matchFinderMt.MatchFinder = &p->matchFinderBase;
- #endif
-
- {
- CLzmaEncProps props;
- LzmaEncProps_Init(&props);
- LzmaEnc_SetProps(p, &props);
- }
-
- #ifndef LZMA_LOG_BSR
- LzmaEnc_FastPosInit(p->g_FastPos);
- #endif
-
- LzmaEnc_InitPriceTables(p->ProbPrices);
- p->litProbs = NULL;
- p->saveState.litProbs = NULL;
-
-}
-
-CLzmaEncHandle LzmaEnc_Create(ISzAllocPtr alloc)
-{
- void *p;
- p = ISzAlloc_Alloc(alloc, sizeof(CLzmaEnc));
- if (p)
- LzmaEnc_Construct((CLzmaEnc *)p);
- return p;
-}
-
-void LzmaEnc_FreeLits(CLzmaEnc *p, ISzAllocPtr alloc)
-{
- ISzAlloc_Free(alloc, p->litProbs);
- ISzAlloc_Free(alloc, p->saveState.litProbs);
- p->litProbs = NULL;
- p->saveState.litProbs = NULL;
-}
-
-void LzmaEnc_Destruct(CLzmaEnc *p, ISzAllocPtr alloc, ISzAllocPtr allocBig)
-{
- #ifndef _7ZIP_ST
- MatchFinderMt_Destruct(&p->matchFinderMt, allocBig);
- #endif
-
- MatchFinder_Free(&p->matchFinderBase, allocBig);
- LzmaEnc_FreeLits(p, alloc);
- RangeEnc_Free(&p->rc, alloc);
-}
-
-void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAllocPtr alloc, ISzAllocPtr allocBig)
-{
- LzmaEnc_Destruct((CLzmaEnc *)p, alloc, allocBig);
- ISzAlloc_Free(alloc, p);
-}
-
-
-#define kBigHashDicLimit ((UInt32)1 << 24)
-
-static SRes LzmaEnc_Alloc(CLzmaEnc *p, UInt32 keepWindowSize, ISzAllocPtr alloc, ISzAllocPtr allocBig)
-{
- UInt32 beforeSize = kNumOpts;
- if (!RangeEnc_Alloc(&p->rc, alloc))
- return SZ_ERROR_MEM;
-
- #ifndef _7ZIP_ST
- p->mtMode = (p->multiThread && !p->fastMode && (p->matchFinderBase.btMode != 0));
- #endif
-
- {
- unsigned lclp = p->lc + p->lp;
- if (!p->litProbs || !p->saveState.litProbs || p->lclp != lclp)
- {
- LzmaEnc_FreeLits(p, alloc);
- p->litProbs = (CLzmaProb *)ISzAlloc_Alloc(alloc, ((UInt32)0x300 << lclp) * sizeof(CLzmaProb));
- p->saveState.litProbs = (CLzmaProb *)ISzAlloc_Alloc(alloc, ((UInt32)0x300 << lclp) * sizeof(CLzmaProb));
- if (!p->litProbs || !p->saveState.litProbs)
- {
- LzmaEnc_FreeLits(p, alloc);
- return SZ_ERROR_MEM;
- }
- p->lclp = lclp;
- }
- }
-
- p->matchFinderBase.bigHash = (Byte)(p->dictSize > kBigHashDicLimit ? 1 : 0);
-
- if (beforeSize + p->dictSize < keepWindowSize)
- beforeSize = keepWindowSize - p->dictSize;
-
- #ifndef _7ZIP_ST
- if (p->mtMode)
- {
- RINOK(MatchFinderMt_Create(&p->matchFinderMt, p->dictSize, beforeSize, p->numFastBytes,
- LZMA_MATCH_LEN_MAX
- + 1 /* 18.04 */
- , allocBig));
- p->matchFinderObj = &p->matchFinderMt;
- p->matchFinderBase.bigHash = (Byte)(
- (p->dictSize > kBigHashDicLimit && p->matchFinderBase.hashMask >= 0xFFFFFF) ? 1 : 0);
- MatchFinderMt_CreateVTable(&p->matchFinderMt, &p->matchFinder);
- }
- else
- #endif
- {
- if (!MatchFinder_Create(&p->matchFinderBase, p->dictSize, beforeSize, p->numFastBytes, LZMA_MATCH_LEN_MAX, allocBig))
- return SZ_ERROR_MEM;
- p->matchFinderObj = &p->matchFinderBase;
- MatchFinder_CreateVTable(&p->matchFinderBase, &p->matchFinder);
- }
-
- return SZ_OK;
-}
-
-void LzmaEnc_Init(CLzmaEnc *p)
-{
- unsigned i;
- p->state = 0;
- p->reps[0] =
- p->reps[1] =
- p->reps[2] =
- p->reps[3] = 1;
-
- RangeEnc_Init(&p->rc);
-
- for (i = 0; i < (1 << kNumAlignBits); i++)
- p->posAlignEncoder[i] = kProbInitValue;
-
- for (i = 0; i < kNumStates; i++)
- {
- unsigned j;
- for (j = 0; j < LZMA_NUM_PB_STATES_MAX; j++)
- {
- p->isMatch[i][j] = kProbInitValue;
- p->isRep0Long[i][j] = kProbInitValue;
- }
- p->isRep[i] = kProbInitValue;
- p->isRepG0[i] = kProbInitValue;
- p->isRepG1[i] = kProbInitValue;
- p->isRepG2[i] = kProbInitValue;
- }
-
- {
- for (i = 0; i < kNumLenToPosStates; i++)
- {
- CLzmaProb *probs = p->posSlotEncoder[i];
- unsigned j;
- for (j = 0; j < (1 << kNumPosSlotBits); j++)
- probs[j] = kProbInitValue;
- }
- }
- {
- for (i = 0; i < kNumFullDistances; i++)
- p->posEncoders[i] = kProbInitValue;
- }
-
- {
- UInt32 num = (UInt32)0x300 << (p->lp + p->lc);
- UInt32 k;
- CLzmaProb *probs = p->litProbs;
- for (k = 0; k < num; k++)
- probs[k] = kProbInitValue;
- }
-
-
- LenEnc_Init(&p->lenProbs);
- LenEnc_Init(&p->repLenProbs);
-
- p->optEnd = 0;
- p->optCur = 0;
-
- {
- for (i = 0; i < kNumOpts; i++)
- p->opt[i].price = kInfinityPrice;
- }
-
- p->additionalOffset = 0;
-
- p->pbMask = (1 << p->pb) - 1;
- p->lpMask = ((UInt32)0x100 << p->lp) - ((unsigned)0x100 >> p->lc);
-}
-
-
-void LzmaEnc_InitPrices(CLzmaEnc *p)
-{
- if (!p->fastMode)
- {
- FillDistancesPrices(p);
- FillAlignPrices(p);
- }
-
- p->lenEnc.tableSize =
- p->repLenEnc.tableSize =
- p->numFastBytes + 1 - LZMA_MATCH_LEN_MIN;
-
- p->repLenEncCounter = REP_LEN_COUNT;
-
- LenPriceEnc_UpdateTables(&p->lenEnc, 1 << p->pb, &p->lenProbs, p->ProbPrices);
- LenPriceEnc_UpdateTables(&p->repLenEnc, 1 << p->pb, &p->repLenProbs, p->ProbPrices);
-}
-
-typedef struct
-{
- ISeqOutStream vt;
- Byte *data;
- SizeT rem;
- BoolInt overflow;
-} CLzmaEnc_SeqOutStreamBuf;
-
-static size_t SeqOutStreamBuf_Write(const ISeqOutStream *pp, const void *data, size_t size)
-{
- CLzmaEnc_SeqOutStreamBuf *p = CONTAINER_FROM_VTBL(pp, CLzmaEnc_SeqOutStreamBuf, vt);
- if (p->rem < size)
- {
- size = p->rem;
- p->overflow = True;
- }
- memcpy(p->data, data, size);
- p->rem -= size;
- p->data += size;
- return size;
-}
-
-
-UInt32 LzmaEnc_GetNumAvailableBytes(CLzmaEncHandle pp)
-{
- const CLzmaEnc *p = (CLzmaEnc *)pp;
- return p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);
-}
-
-
-const Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp)
-{
- const CLzmaEnc *p = (CLzmaEnc *)pp;
- return p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;
-}
-
-
-SRes LzmaEnc_WriteProperties(CLzmaEncHandle pp, Byte *props, SizeT *size)
-{
- CLzmaEnc *p = (CLzmaEnc *)pp;
- unsigned i;
- UInt32 dictSize = p->dictSize;
- if (*size < LZMA_PROPS_SIZE)
- return SZ_ERROR_PARAM;
- *size = LZMA_PROPS_SIZE;
- props[0] = (Byte)((p->pb * 5 + p->lp) * 9 + p->lc);
-
- if (dictSize >= ((UInt32)1 << 22))
- {
- UInt32 kDictMask = ((UInt32)1 << 20) - 1;
- if (dictSize < (UInt32)0xFFFFFFFF - kDictMask)
- dictSize = (dictSize + kDictMask) & ~kDictMask;
- }
- else for (i = 11; i <= 30; i++)
- {
- if (dictSize <= ((UInt32)2 << i)) { dictSize = (2 << i); break; }
- if (dictSize <= ((UInt32)3 << i)) { dictSize = (3 << i); break; }
- }
-
- for (i = 0; i < 4; i++)
- props[1 + i] = (Byte)(dictSize >> (8 * i));
- return SZ_OK;
-}
-
-
-
-
diff --git a/deps/libchdr/deps/lzma-22.01/7zC.txt b/deps/libchdr/deps/lzma-22.01/7zC.txt
deleted file mode 100644
index 49276787..00000000
--- a/deps/libchdr/deps/lzma-22.01/7zC.txt
+++ /dev/null
@@ -1,187 +0,0 @@
-7z ANSI-C Decoder 9.35
-----------------------
-
-7z ANSI-C provides 7z/LZMA decoding.
-7z ANSI-C version is simplified version ported from C++ code.
-
-LZMA is default and general compression method of 7z format
-in 7-Zip compression program (www.7-zip.org). LZMA provides high
-compression ratio and very fast decompression.
-
-
-LICENSE
--------
-
-7z ANSI-C Decoder is part of the LZMA SDK.
-LZMA SDK is written and placed in the public domain by Igor Pavlov.
-
-Files
----------------------
-
-7zDecode.* - Low level 7z decoding
-7zExtract.* - High level 7z decoding
-7zHeader.* - .7z format constants
-7zIn.* - .7z archive opening
-7zItem.* - .7z structures
-7zMain.c - Test application
-
-
-How To Use
-----------
-
-You can create .7z archive with 7z.exe, 7za.exe or 7zr.exe:
-
- 7z.exe a archive.7z *.htm -r -mx -m0fb=255
-
-If you have big number of files in archive, and you need fast extracting,
-you can use partly-solid archives:
-
- 7za.exe a archive.7z *.htm -ms=512K -r -mx -m0fb=255 -m0d=512K
-
-In that example 7-Zip will use 512KB solid blocks. So it needs to decompress only
-512KB for extracting one file from such archive.
-
-
-Limitations of current version of 7z ANSI-C Decoder
----------------------------------------------------
-
- - It reads only "FileName", "Size", "LastWriteTime" and "CRC" information for each file in archive.
- - It supports only LZMA and Copy (no compression) methods with BCJ or BCJ2 filters.
- - It converts original UTF-16 Unicode file names to UTF-8 Unicode file names.
-
-These limitations will be fixed in future versions.
-
-
-Using 7z ANSI-C Decoder Test application:
------------------------------------------
-
-Usage: 7zDec
-
-:
- e: Extract files from archive
- l: List contents of archive
- t: Test integrity of archive
-
-Example:
-
- 7zDec l archive.7z
-
-lists contents of archive.7z
-
- 7zDec e archive.7z
-
-extracts files from archive.7z to current folder.
-
-
-How to use .7z Decoder
-----------------------
-
-Memory allocation
-~~~~~~~~~~~~~~~~~
-
-7z Decoder uses two memory pools:
-1) Temporary pool
-2) Main pool
-Such scheme can allow you to avoid fragmentation of allocated blocks.
-
-
-Steps for using 7z decoder
---------------------------
-
-Use code at 7zMain.c as example.
-
-1) Declare variables:
- inStream /* implements ILookInStream interface */
- CSzArEx db; /* 7z archive database structure */
- ISzAlloc allocImp; /* memory functions for main pool */
- ISzAlloc allocTempImp; /* memory functions for temporary pool */
-
-2) call CrcGenerateTable(); function to initialize CRC structures.
-
-3) call SzArEx_Init(&db); function to initialize db structures.
-
-4) call SzArEx_Open(&db, inStream, &allocMain, &allocTemp) to open archive
-
-This function opens archive "inStream" and reads headers to "db".
-All items in "db" will be allocated with "allocMain" functions.
-SzArEx_Open function allocates and frees temporary structures by "allocTemp" functions.
-
-5) List items or Extract items
-
- Listing code:
- ~~~~~~~~~~~~~
-
- Use SzArEx_GetFileNameUtf16 function. Look example code in C\Util\7z\7zMain.c file.
-
-
- Extracting code:
- ~~~~~~~~~~~~~~~~
-
- SZ_RESULT SzAr_Extract(
- CArchiveDatabaseEx *db,
- ILookInStream *inStream,
- UInt32 fileIndex, /* index of file */
- UInt32 *blockIndex, /* index of solid block */
- Byte **outBuffer, /* pointer to pointer to output buffer (allocated with allocMain) */
- size_t *outBufferSize, /* buffer size for output buffer */
- size_t *offset, /* offset of stream for required file in *outBuffer */
- size_t *outSizeProcessed, /* size of file in *outBuffer */
- ISzAlloc *allocMain,
- ISzAlloc *allocTemp);
-
- If you need to decompress more than one file, you can send these values from previous call:
- blockIndex,
- outBuffer,
- outBufferSize,
- You can consider "outBuffer" as cache of solid block. If your archive is solid,
- it will increase decompression speed.
-
- After decompressing you must free "outBuffer":
- allocImp.Free(outBuffer);
-
-6) call SzArEx_Free(&db, allocImp.Free) to free allocated items in "db".
-
-
-
-
-Memory requirements for .7z decoding
-------------------------------------
-
-Memory usage for Archive opening:
- - Temporary pool:
- - Memory for uncompressed .7z headers
- - some other temporary blocks
- - Main pool:
- - Memory for database:
- Estimated size of one file structures in solid archive:
- - Size (4 or 8 Bytes)
- - CRC32 (4 bytes)
- - LastWriteTime (8 bytes)
- - Some file information (4 bytes)
- - File Name (variable length) + pointer + allocation structures
-
-Memory usage for archive Decompressing:
- - Temporary pool:
- - Memory for LZMA decompressing structures
- - Main pool:
- - Memory for decompressed solid block
- - Memory for temprorary buffers, if BCJ2 fileter is used. Usually these
- temprorary buffers can be about 15% of solid block size.
-
-
-7z Decoder doesn't allocate memory for compressed blocks.
-Instead of this, you must allocate buffer with desired
-size before calling 7z Decoder. Use 7zMain.c as example.
-
-
-Defines
--------
-
-_SZ_ALLOC_DEBUG - define it if you want to debug alloc/free operations to stderr.
-
-
----
-
-http://www.7-zip.org
-http://www.7-zip.org/sdk.html
-http://www.7-zip.org/support.html
diff --git a/deps/libchdr/deps/lzma-22.01/7zFormat.txt b/deps/libchdr/deps/lzma-22.01/7zFormat.txt
deleted file mode 100644
index 9239e935..00000000
--- a/deps/libchdr/deps/lzma-22.01/7zFormat.txt
+++ /dev/null
@@ -1,469 +0,0 @@
-7z Format description (18.06)
-----------------------------
-
-This file contains description of 7z archive format.
-7z archive can contain files compressed with any method.
-See "Methods.txt" for description for defined compressing methods.
-
-
-Format structure Overview
--------------------------
-
-Some fields can be optional.
-
-Archive structure
-~~~~~~~~~~~~~~~~~
-SignatureHeader
-[PackedStreams]
-[PackedStreamsForHeaders]
-[
- Header
- or
- {
- Packed Header
- HeaderInfo
- }
-]
-
-
-
-Header structure
-~~~~~~~~~~~~~~~~
-{
- ArchiveProperties
- AdditionalStreams
- {
- PackInfo
- {
- PackPos
- NumPackStreams
- Sizes[NumPackStreams]
- CRCs[NumPackStreams]
- }
- CodersInfo
- {
- NumFolders
- Folders[NumFolders]
- {
- NumCoders
- CodersInfo[NumCoders]
- {
- ID
- NumInStreams;
- NumOutStreams;
- PropertiesSize
- Properties[PropertiesSize]
- }
- NumBindPairs
- BindPairsInfo[NumBindPairs]
- {
- InIndex;
- OutIndex;
- }
- PackedIndices
- }
- UnPackSize[Folders][Folders.NumOutstreams]
- CRCs[NumFolders]
- }
- SubStreamsInfo
- {
- NumUnPackStreamsInFolders[NumFolders];
- UnPackSizes[]
- CRCs[]
- }
- }
- MainStreamsInfo
- {
- (Same as in AdditionalStreams)
- }
- FilesInfo
- {
- NumFiles
- Properties[]
- {
- ID
- Size
- Data
- }
- }
-}
-
-HeaderInfo structure
-~~~~~~~~~~~~~~~~~~~~
-{
- (Same as in AdditionalStreams)
-}
-
-
-
-Notes about Notation and encoding
----------------------------------
-
-7z uses little endian encoding.
-
-7z archive format has optional headers that are marked as
-[]
-Header
-[]
-
-REAL_UINT64 means real UINT64.
-
-UINT64 means real UINT64 encoded with the following scheme:
-
- Size of encoding sequence depends from first byte:
- First_Byte Extra_Bytes Value
- (binary)
- 0xxxxxxx : ( xxxxxxx )
- 10xxxxxx BYTE y[1] : ( xxxxxx << (8 * 1)) + y
- 110xxxxx BYTE y[2] : ( xxxxx << (8 * 2)) + y
- ...
- 1111110x BYTE y[6] : ( x << (8 * 6)) + y
- 11111110 BYTE y[7] : y
- 11111111 BYTE y[8] : y
-
-
-
-Property IDs
-------------
-
-0x00 = kEnd
-
-0x01 = kHeader
-
-0x02 = kArchiveProperties
-
-0x03 = kAdditionalStreamsInfo
-0x04 = kMainStreamsInfo
-0x05 = kFilesInfo
-
-0x06 = kPackInfo
-0x07 = kUnPackInfo
-0x08 = kSubStreamsInfo
-
-0x09 = kSize
-0x0A = kCRC
-
-0x0B = kFolder
-
-0x0C = kCodersUnPackSize
-0x0D = kNumUnPackStream
-
-0x0E = kEmptyStream
-0x0F = kEmptyFile
-0x10 = kAnti
-
-0x11 = kName
-0x12 = kCTime
-0x13 = kATime
-0x14 = kMTime
-0x15 = kWinAttributes
-0x16 = kComment
-
-0x17 = kEncodedHeader
-
-0x18 = kStartPos
-0x19 = kDummy
-
-
-7z format headers
------------------
-
-SignatureHeader
-~~~~~~~~~~~~~~~
- BYTE kSignature[6] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C};
-
- ArchiveVersion
- {
- BYTE Major; // now = 0
- BYTE Minor; // now = 4
- };
-
- UINT32 StartHeaderCRC;
-
- StartHeader
- {
- REAL_UINT64 NextHeaderOffset
- REAL_UINT64 NextHeaderSize
- UINT32 NextHeaderCRC
- }
-
-
-...........................
-
-
-ArchiveProperties
-~~~~~~~~~~~~~~~~~
-BYTE NID::kArchiveProperties (0x02)
-for (;;)
-{
- BYTE PropertyType;
- if (aType == 0)
- break;
- UINT64 PropertySize;
- BYTE PropertyData[PropertySize];
-}
-
-
-Digests (NumStreams)
-~~~~~~~~~~~~~~~~~~~~~
- BYTE AllAreDefined
- if (AllAreDefined == 0)
- {
- for(NumStreams)
- BIT Defined
- }
- UINT32 CRCs[NumDefined]
-
-
-PackInfo
-~~~~~~~~~~~~
- BYTE NID::kPackInfo (0x06)
- UINT64 PackPos
- UINT64 NumPackStreams
-
- []
- BYTE NID::kSize (0x09)
- UINT64 PackSizes[NumPackStreams]
- []
-
- []
- BYTE NID::kCRC (0x0A)
- PackStreamDigests[NumPackStreams]
- []
-
- BYTE NID::kEnd
-
-
-Folder
-~~~~~~
- UINT64 NumCoders;
- for (NumCoders)
- {
- BYTE
- {
- 0:3 CodecIdSize
- 4: Is Complex Coder
- 5: There Are Attributes
- 6: Reserved
- 7: There are more alternative methods. (Not used anymore, must be 0).
- }
- BYTE CodecId[CodecIdSize]
- if (Is Complex Coder)
- {
- UINT64 NumInStreams;
- UINT64 NumOutStreams;
- }
- if (There Are Attributes)
- {
- UINT64 PropertiesSize
- BYTE Properties[PropertiesSize]
- }
- }
-
- NumBindPairs = NumOutStreamsTotal - 1;
-
- for (NumBindPairs)
- {
- UINT64 InIndex;
- UINT64 OutIndex;
- }
-
- NumPackedStreams = NumInStreamsTotal - NumBindPairs;
- if (NumPackedStreams > 1)
- for(NumPackedStreams)
- {
- UINT64 Index;
- };
-
-
-
-
-Coders Info
-~~~~~~~~~~~
-
- BYTE NID::kUnPackInfo (0x07)
-
-
- BYTE NID::kFolder (0x0B)
- UINT64 NumFolders
- BYTE External
- switch(External)
- {
- case 0:
- Folders[NumFolders]
- case 1:
- UINT64 DataStreamIndex
- }
-
-
- BYTE ID::kCodersUnPackSize (0x0C)
- for(Folders)
- for(Folder.NumOutStreams)
- UINT64 UnPackSize;
-
-
- []
- BYTE NID::kCRC (0x0A)
- UnPackDigests[NumFolders]
- []
-
-
-
- BYTE NID::kEnd
-
-
-
-SubStreams Info
-~~~~~~~~~~~~~~
- BYTE NID::kSubStreamsInfo; (0x08)
-
- []
- BYTE NID::kNumUnPackStream; (0x0D)
- UINT64 NumUnPackStreamsInFolders[NumFolders];
- []
-
-
- []
- BYTE NID::kSize (0x09)
- UINT64 UnPackSizes[]
- []
-
-
- []
- BYTE NID::kCRC (0x0A)
- Digests[Number of streams with unknown CRC]
- []
-
-
- BYTE NID::kEnd
-
-
-Streams Info
-~~~~~~~~~~~~
-
- []
- PackInfo
- []
-
-
- []
- CodersInfo
- []
-
-
- []
- SubStreamsInfo
- []
-
- BYTE NID::kEnd
-
-
-FilesInfo
-~~~~~~~~~
- BYTE NID::kFilesInfo; (0x05)
- UINT64 NumFiles
-
- for (;;)
- {
- BYTE PropertyType;
- if (aType == 0)
- break;
-
- UINT64 Size;
-
- switch(PropertyType)
- {
- kEmptyStream: (0x0E)
- for(NumFiles)
- BIT IsEmptyStream
-
- kEmptyFile: (0x0F)
- for(EmptyStreams)
- BIT IsEmptyFile
-
- kAnti: (0x10)
- for(EmptyStreams)
- BIT IsAntiFile
-
- case kCTime: (0x12)
- case kATime: (0x13)
- case kMTime: (0x14)
- BYTE AllAreDefined
- if (AllAreDefined == 0)
- {
- for(NumFiles)
- BIT TimeDefined
- }
- BYTE External;
- if(External != 0)
- UINT64 DataIndex
- []
- for(Definded Items)
- REAL_UINT64 Time
- []
-
- kNames: (0x11)
- BYTE External;
- if(External != 0)
- UINT64 DataIndex
- []
- for(Files)
- {
- wchar_t Names[NameSize];
- wchar_t 0;
- }
- []
-
- kAttributes: (0x15)
- BYTE AllAreDefined
- if (AllAreDefined == 0)
- {
- for(NumFiles)
- BIT AttributesAreDefined
- }
- BYTE External;
- if(External != 0)
- UINT64 DataIndex
- []
- for(Definded Attributes)
- UINT32 Attributes
- []
- }
- }
-
-
-Header
-~~~~~~
- BYTE NID::kHeader (0x01)
-
- []
- ArchiveProperties
- []
-
- []
- BYTE NID::kAdditionalStreamsInfo; (0x03)
- StreamsInfo
- []
-
- []
- BYTE NID::kMainStreamsInfo; (0x04)
- StreamsInfo
- []
-
- []
- FilesInfo
- []
-
- BYTE NID::kEnd
-
-
-HeaderInfo
-~~~~~~~~~~
- []
- BYTE NID::kEncodedHeader; (0x17)
- StreamsInfo for Encoded Header
- []
-
-
----
-End of document
diff --git a/deps/libchdr/deps/lzma-22.01/CMakeLists.txt b/deps/libchdr/deps/lzma-22.01/CMakeLists.txt
deleted file mode 100644
index 291b253d..00000000
--- a/deps/libchdr/deps/lzma-22.01/CMakeLists.txt
+++ /dev/null
@@ -1,33 +0,0 @@
-add_library(lzma STATIC
- include/7zTypes.h
- include/Alloc.h
- include/Bra.h
- include/Compiler.h
- include/CpuArch.h
- include/Delta.h
- include/LzFind.h
- include/LzHash.h
- include/Lzma86.h
- include/LzmaDec.h
- include/LzmaEnc.h
- include/LzmaLib.h
- include/Precomp.h
- include/Sort.h
- src/Alloc.c
- src/Bra86.c
- src/BraIA64.c
- src/CpuArch.c
- src/Delta.c
- src/LzFind.c
- src/Lzma86Dec.c
- src/LzmaDec.c
- src/LzmaEnc.c
- src/Sort.c
-)
-
-target_compile_definitions(lzma PRIVATE _7ZIP_ST)
-
-target_include_directories(lzma PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include")
-target_include_directories(lzma INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include")
-
-set_target_properties(lzma PROPERTIES POSITION_INDEPENDENT_CODE ON)
diff --git a/deps/libchdr/deps/lzma-22.01/LICENSE b/deps/libchdr/deps/lzma-22.01/LICENSE
deleted file mode 100644
index 5f570516..00000000
--- a/deps/libchdr/deps/lzma-22.01/LICENSE
+++ /dev/null
@@ -1,3 +0,0 @@
-LZMA SDK is placed in the public domain.
-
-Anyone is free to copy, modify, publish, use, compile, sell, or distribute the original LZMA SDK code, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.
\ No newline at end of file
diff --git a/deps/libchdr/deps/lzma-22.01/Methods.txt b/deps/libchdr/deps/lzma-22.01/Methods.txt
deleted file mode 100644
index 6d0641ba..00000000
--- a/deps/libchdr/deps/lzma-22.01/Methods.txt
+++ /dev/null
@@ -1,173 +0,0 @@
-7-Zip method IDs for 7z and xz archives
----------------------------------------
-
-Version: 18.06
-Date: 2018-06-30
-
-Each compression or crypto method in 7z is associated with unique binary value (ID).
-The length of ID in bytes is arbitrary but it can not exceed 63 bits (8 bytes).
-
-xz and 7z formats use same ID map.
-
-If you want to add some new ID, you have two ways:
- 1) Write request for allocating IDs to 7-Zip developers.
- 2) Generate 8-bytes ID:
-
- 3F ZZ ZZ ZZ ZZ ZZ MM MM
-
- 3F - Prefix for random IDs (1 byte)
- ZZ ZZ ZZ ZZ ZZ - Developer ID (5 bytes). Use real random bytes.
-
- MM MM - Method ID (2 bytes)
-
- You can notify 7-Zip developers about your Developer ID / Method ID.
-
- Note: Use new ID, if old codec can not decode data encoded with new version.
-
-
-List of defined IDs
--------------------
-
-00 - Copy
-
-03 - Delta
-04 - BCJ (x86)
-05 - PPC (big-endian)
-06 - IA64
-07 - ARM (little-endian)
-08 - ARMT (little-endian)
-09 - SPARC
-
-21 - LZMA2
-
-02.. - Common
- 03 [Swap]
- - 2 Swap2
- - 4 Swap4
-
-03.. - 7z
- 01 -
- 01 - LZMA
-
- 03 - [Branch Codecs]
- 01 - [x86 Codecs]
- 03 - BCJ
- 1B - BCJ2 (4 packed streams)
- 02 -
- 05 - PPC (big-endian)
- 03 -
- 01 - Alpha
- 04 -
- 01 - IA64
- 05 -
- 01 - ARM (little-endian)
- 06 -
- 05 - M68 (big-endian)
- 07 -
- 01 - ARMT (little-endian)
- 08 -
- 05 - SPARC
-
- 04 -
- 01 - PPMD
-
- 7F -
- 01 - experimental method.
-
-
-04.. - Misc codecs
-
- 00 - Reserved
-
- 01 - [Zip]
- 00 - Copy (not used. Use {00} instead)
- 01 - Shrink
- 06 - Implode
- 08 - Deflate
- 09 - Deflate64
- 0A - Imploding
- 0C - BZip2 (not used. Use {040202} instead)
- 0E - LZMA (LZMA-zip)
- 5F - xz
- 60 - Jpeg
- 61 - WavPack
- 62 - PPMd (PPMd-zip)
- 63 - wzAES
-
- 02 -
- 02 - BZip2
-
- 03 - [Rar]
- 01 - Rar1
- 02 - Rar2
- 03 - Rar3
- 05 - Rar5
-
- 04 - [Arj]
- 01 - Arj(1,2,3)
- 02 - Arj4
-
- 05 - [Z]
-
- 06 - [Lzh]
-
- 07 - Reserved for 7z
-
- 08 - [Cab]
-
- 09 - [NSIS]
- 01 - DeflateNSIS
- 02 - BZip2NSIS
-
- F7 - External codecs (that are not included to 7-Zip)
-
- 0x xx - reserved
-
- 10 xx - reserved (LZHAM)
- 01 - LZHAM
-
- 11 xx - reserved (Tino Reichardt)
- 01 - ZSTD
- 02 - BROTLI
- 04 - LZ4
- 05 - LZ5
- 06 - LIZARD
-
- 12 xx - reserverd (Denis Anisimov)
-
- 01 - WavPack2
- FE - eSplitter
- FF - RawSplitter
-
-
-06.. - Crypto
-
- F0 - Ciphers without hashing algo
-
- 01 - [AES]
- 0x - AES-128
- 4x - AES-192
- 8x - AES-256
- Cx - AES
-
- x0 - ECB
- x1 - CBC
- x2 - CFB
- x3 - OFB
- x4 - CTR
-
- F1 - Combine Ciphers
-
- 01 - [Zip]
- 01 - ZipCrypto (Main Zip crypto algo)
-
- 03 - [RAR]
- 02 -
- 03 - Rar29AES (AES-128 + modified SHA-1)
-
- 07 - [7z]
- 01 - 7zAES (AES-256 + SHA-256)
-
-
----
-End of document
diff --git a/deps/libchdr/deps/lzma-22.01/include/7z.h b/deps/libchdr/deps/lzma-22.01/include/7z.h
deleted file mode 100644
index 969523cd..00000000
--- a/deps/libchdr/deps/lzma-22.01/include/7z.h
+++ /dev/null
@@ -1,204 +0,0 @@
-/* 7z.h -- 7z interface
-2018-07-02 : Igor Pavlov : Public domain */
-
-#ifndef __7Z_H
-#define __7Z_H
-
-#include "7zTypes.h"
-
-EXTERN_C_BEGIN
-
-#define k7zStartHeaderSize 0x20
-#define k7zSignatureSize 6
-
-extern const Byte k7zSignature[k7zSignatureSize];
-
-typedef struct
-{
- const Byte *Data;
- size_t Size;
-} CSzData;
-
-/* CSzCoderInfo & CSzFolder support only default methods */
-
-typedef struct
-{
- size_t PropsOffset;
- UInt32 MethodID;
- Byte NumStreams;
- Byte PropsSize;
-} CSzCoderInfo;
-
-typedef struct
-{
- UInt32 InIndex;
- UInt32 OutIndex;
-} CSzBond;
-
-#define SZ_NUM_CODERS_IN_FOLDER_MAX 4
-#define SZ_NUM_BONDS_IN_FOLDER_MAX 3
-#define SZ_NUM_PACK_STREAMS_IN_FOLDER_MAX 4
-
-typedef struct
-{
- UInt32 NumCoders;
- UInt32 NumBonds;
- UInt32 NumPackStreams;
- UInt32 UnpackStream;
- UInt32 PackStreams[SZ_NUM_PACK_STREAMS_IN_FOLDER_MAX];
- CSzBond Bonds[SZ_NUM_BONDS_IN_FOLDER_MAX];
- CSzCoderInfo Coders[SZ_NUM_CODERS_IN_FOLDER_MAX];
-} CSzFolder;
-
-
-SRes SzGetNextFolderItem(CSzFolder *f, CSzData *sd);
-
-typedef struct
-{
- UInt32 Low;
- UInt32 High;
-} CNtfsFileTime;
-
-typedef struct
-{
- Byte *Defs; /* MSB 0 bit numbering */
- UInt32 *Vals;
-} CSzBitUi32s;
-
-typedef struct
-{
- Byte *Defs; /* MSB 0 bit numbering */
- // UInt64 *Vals;
- CNtfsFileTime *Vals;
-} CSzBitUi64s;
-
-#define SzBitArray_Check(p, i) (((p)[(i) >> 3] & (0x80 >> ((i) & 7))) != 0)
-
-#define SzBitWithVals_Check(p, i) ((p)->Defs && ((p)->Defs[(i) >> 3] & (0x80 >> ((i) & 7))) != 0)
-
-typedef struct
-{
- UInt32 NumPackStreams;
- UInt32 NumFolders;
-
- UInt64 *PackPositions; // NumPackStreams + 1
- CSzBitUi32s FolderCRCs; // NumFolders
-
- size_t *FoCodersOffsets; // NumFolders + 1
- UInt32 *FoStartPackStreamIndex; // NumFolders + 1
- UInt32 *FoToCoderUnpackSizes; // NumFolders + 1
- Byte *FoToMainUnpackSizeIndex; // NumFolders
- UInt64 *CoderUnpackSizes; // for all coders in all folders
-
- Byte *CodersData;
-
- UInt64 RangeLimit;
-} CSzAr;
-
-UInt64 SzAr_GetFolderUnpackSize(const CSzAr *p, UInt32 folderIndex);
-
-SRes SzAr_DecodeFolder(const CSzAr *p, UInt32 folderIndex,
- ILookInStream *stream, UInt64 startPos,
- Byte *outBuffer, size_t outSize,
- ISzAllocPtr allocMain);
-
-typedef struct
-{
- CSzAr db;
-
- UInt64 startPosAfterHeader;
- UInt64 dataPos;
-
- UInt32 NumFiles;
-
- UInt64 *UnpackPositions; // NumFiles + 1
- // Byte *IsEmptyFiles;
- Byte *IsDirs;
- CSzBitUi32s CRCs;
-
- CSzBitUi32s Attribs;
- // CSzBitUi32s Parents;
- CSzBitUi64s MTime;
- CSzBitUi64s CTime;
-
- UInt32 *FolderToFile; // NumFolders + 1
- UInt32 *FileToFolder; // NumFiles
-
- size_t *FileNameOffsets; /* in 2-byte steps */
- Byte *FileNames; /* UTF-16-LE */
-} CSzArEx;
-
-#define SzArEx_IsDir(p, i) (SzBitArray_Check((p)->IsDirs, i))
-
-#define SzArEx_GetFileSize(p, i) ((p)->UnpackPositions[(i) + 1] - (p)->UnpackPositions[i])
-
-void SzArEx_Init(CSzArEx *p);
-void SzArEx_Free(CSzArEx *p, ISzAllocPtr alloc);
-UInt64 SzArEx_GetFolderStreamPos(const CSzArEx *p, UInt32 folderIndex, UInt32 indexInFolder);
-int SzArEx_GetFolderFullPackSize(const CSzArEx *p, UInt32 folderIndex, UInt64 *resSize);
-
-/*
-if dest == NULL, the return value specifies the required size of the buffer,
- in 16-bit characters, including the null-terminating character.
-if dest != NULL, the return value specifies the number of 16-bit characters that
- are written to the dest, including the null-terminating character. */
-
-size_t SzArEx_GetFileNameUtf16(const CSzArEx *p, size_t fileIndex, UInt16 *dest);
-
-/*
-size_t SzArEx_GetFullNameLen(const CSzArEx *p, size_t fileIndex);
-UInt16 *SzArEx_GetFullNameUtf16_Back(const CSzArEx *p, size_t fileIndex, UInt16 *dest);
-*/
-
-
-
-/*
- SzArEx_Extract extracts file from archive
-
- *outBuffer must be 0 before first call for each new archive.
-
- Extracting cache:
- If you need to decompress more than one file, you can send
- these values from previous call:
- *blockIndex,
- *outBuffer,
- *outBufferSize
- You can consider "*outBuffer" as cache of solid block. If your archive is solid,
- it will increase decompression speed.
-
- If you use external function, you can declare these 3 cache variables
- (blockIndex, outBuffer, outBufferSize) as static in that external function.
-
- Free *outBuffer and set *outBuffer to 0, if you want to flush cache.
-*/
-
-SRes SzArEx_Extract(
- const CSzArEx *db,
- ILookInStream *inStream,
- UInt32 fileIndex, /* index of file */
- UInt32 *blockIndex, /* index of solid block */
- Byte **outBuffer, /* pointer to pointer to output buffer (allocated with allocMain) */
- size_t *outBufferSize, /* buffer size for output buffer */
- size_t *offset, /* offset of stream for required file in *outBuffer */
- size_t *outSizeProcessed, /* size of file in *outBuffer */
- ISzAllocPtr allocMain,
- ISzAllocPtr allocTemp);
-
-
-/*
-SzArEx_Open Errors:
-SZ_ERROR_NO_ARCHIVE
-SZ_ERROR_ARCHIVE
-SZ_ERROR_UNSUPPORTED
-SZ_ERROR_MEM
-SZ_ERROR_CRC
-SZ_ERROR_INPUT_EOF
-SZ_ERROR_FAIL
-*/
-
-SRes SzArEx_Open(CSzArEx *p, ILookInStream *inStream,
- ISzAllocPtr allocMain, ISzAllocPtr allocTemp);
-
-EXTERN_C_END
-
-#endif
diff --git a/deps/libchdr/deps/lzma-22.01/include/7zAlloc.h b/deps/libchdr/deps/lzma-22.01/include/7zAlloc.h
deleted file mode 100644
index c0f89d73..00000000
--- a/deps/libchdr/deps/lzma-22.01/include/7zAlloc.h
+++ /dev/null
@@ -1,19 +0,0 @@
-/* 7zAlloc.h -- Allocation functions
-2017-04-03 : Igor Pavlov : Public domain */
-
-#ifndef __7Z_ALLOC_H
-#define __7Z_ALLOC_H
-
-#include "7zTypes.h"
-
-EXTERN_C_BEGIN
-
-void *SzAlloc(ISzAllocPtr p, size_t size);
-void SzFree(ISzAllocPtr p, void *address);
-
-void *SzAllocTemp(ISzAllocPtr p, size_t size);
-void SzFreeTemp(ISzAllocPtr p, void *address);
-
-EXTERN_C_END
-
-#endif
diff --git a/deps/libchdr/deps/lzma-22.01/include/7zBuf.h b/deps/libchdr/deps/lzma-22.01/include/7zBuf.h
deleted file mode 100644
index 5942d6e6..00000000
--- a/deps/libchdr/deps/lzma-22.01/include/7zBuf.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/* 7zBuf.h -- Byte Buffer
-2017-04-03 : Igor Pavlov : Public domain */
-
-#ifndef __7Z_BUF_H
-#define __7Z_BUF_H
-
-#include "7zTypes.h"
-
-EXTERN_C_BEGIN
-
-typedef struct
-{
- Byte *data;
- size_t size;
-} CBuf;
-
-void Buf_Init(CBuf *p);
-int Buf_Create(CBuf *p, size_t size, ISzAllocPtr alloc);
-void Buf_Free(CBuf *p, ISzAllocPtr alloc);
-
-typedef struct
-{
- Byte *data;
- size_t size;
- size_t pos;
-} CDynBuf;
-
-void DynBuf_Construct(CDynBuf *p);
-void DynBuf_SeekToBeg(CDynBuf *p);
-int DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAllocPtr alloc);
-void DynBuf_Free(CDynBuf *p, ISzAllocPtr alloc);
-
-EXTERN_C_END
-
-#endif
diff --git a/deps/libchdr/deps/lzma-22.01/include/7zCrc.h b/deps/libchdr/deps/lzma-22.01/include/7zCrc.h
deleted file mode 100644
index 3b045940..00000000
--- a/deps/libchdr/deps/lzma-22.01/include/7zCrc.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/* 7zCrc.h -- CRC32 calculation
-2013-01-18 : Igor Pavlov : Public domain */
-
-#ifndef __7Z_CRC_H
-#define __7Z_CRC_H
-
-#include "7zTypes.h"
-
-EXTERN_C_BEGIN
-
-extern UInt32 g_CrcTable[];
-
-/* Call CrcGenerateTable one time before other CRC functions */
-void MY_FAST_CALL CrcGenerateTable(void);
-
-#define CRC_INIT_VAL 0xFFFFFFFF
-#define CRC_GET_DIGEST(crc) ((crc) ^ CRC_INIT_VAL)
-#define CRC_UPDATE_BYTE(crc, b) (g_CrcTable[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))
-
-UInt32 MY_FAST_CALL CrcUpdate(UInt32 crc, const void *data, size_t size);
-UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size);
-
-EXTERN_C_END
-
-#endif
diff --git a/deps/libchdr/deps/lzma-22.01/include/7zFile.h b/deps/libchdr/deps/lzma-22.01/include/7zFile.h
deleted file mode 100644
index c7a30fc2..00000000
--- a/deps/libchdr/deps/lzma-22.01/include/7zFile.h
+++ /dev/null
@@ -1,91 +0,0 @@
-/* 7zFile.h -- File IO
-2021-02-15 : Igor Pavlov : Public domain */
-
-#ifndef __7Z_FILE_H
-#define __7Z_FILE_H
-
-#ifdef _WIN32
-#define USE_WINDOWS_FILE
-// #include
-#endif
-
-#ifdef USE_WINDOWS_FILE
-#include
-#else
-// note: USE_FOPEN mode is limited to 32-bit file size
-// #define USE_FOPEN
-// #include
-#endif
-
-#include "7zTypes.h"
-
-EXTERN_C_BEGIN
-
-/* ---------- File ---------- */
-
-typedef struct
-{
- #ifdef USE_WINDOWS_FILE
- HANDLE handle;
- #elif defined(USE_FOPEN)
- FILE *file;
- #else
- int fd;
- #endif
-} CSzFile;
-
-void File_Construct(CSzFile *p);
-#if !defined(UNDER_CE) || !defined(USE_WINDOWS_FILE)
-WRes InFile_Open(CSzFile *p, const char *name);
-WRes OutFile_Open(CSzFile *p, const char *name);
-#endif
-#ifdef USE_WINDOWS_FILE
-WRes InFile_OpenW(CSzFile *p, const WCHAR *name);
-WRes OutFile_OpenW(CSzFile *p, const WCHAR *name);
-#endif
-WRes File_Close(CSzFile *p);
-
-/* reads max(*size, remain file's size) bytes */
-WRes File_Read(CSzFile *p, void *data, size_t *size);
-
-/* writes *size bytes */
-WRes File_Write(CSzFile *p, const void *data, size_t *size);
-
-WRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin);
-WRes File_GetLength(CSzFile *p, UInt64 *length);
-
-
-/* ---------- FileInStream ---------- */
-
-typedef struct
-{
- ISeqInStream vt;
- CSzFile file;
- WRes wres;
-} CFileSeqInStream;
-
-void FileSeqInStream_CreateVTable(CFileSeqInStream *p);
-
-
-typedef struct
-{
- ISeekInStream vt;
- CSzFile file;
- WRes wres;
-} CFileInStream;
-
-void FileInStream_CreateVTable(CFileInStream *p);
-
-
-typedef struct
-{
- ISeqOutStream vt;
- CSzFile file;
- WRes wres;
-} CFileOutStream;
-
-void FileOutStream_CreateVTable(CFileOutStream *p);
-
-EXTERN_C_END
-
-#endif
diff --git a/deps/libchdr/deps/lzma-22.01/include/7zVersion.h b/deps/libchdr/deps/lzma-22.01/include/7zVersion.h
deleted file mode 100644
index fa9e6fc5..00000000
--- a/deps/libchdr/deps/lzma-22.01/include/7zVersion.h
+++ /dev/null
@@ -1,27 +0,0 @@
-#define MY_VER_MAJOR 22
-#define MY_VER_MINOR 01
-#define MY_VER_BUILD 0
-#define MY_VERSION_NUMBERS "22.01"
-#define MY_VERSION MY_VERSION_NUMBERS
-
-#ifdef MY_CPU_NAME
- #define MY_VERSION_CPU MY_VERSION " (" MY_CPU_NAME ")"
-#else
- #define MY_VERSION_CPU MY_VERSION
-#endif
-
-#define MY_DATE "2022-07-15"
-#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-2022 Igor Pavlov"
-
-#ifdef USE_COPYRIGHT_CR
- #define MY_COPYRIGHT MY_COPYRIGHT_CR
-#else
- #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
diff --git a/deps/libchdr/deps/lzma-22.01/include/Aes.h b/deps/libchdr/deps/lzma-22.01/include/Aes.h
deleted file mode 100644
index 602e25ea..00000000
--- a/deps/libchdr/deps/lzma-22.01/include/Aes.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/* Aes.h -- AES encryption / decryption
-2018-04-28 : Igor Pavlov : Public domain */
-
-#ifndef __AES_H
-#define __AES_H
-
-#include "7zTypes.h"
-
-EXTERN_C_BEGIN
-
-#define AES_BLOCK_SIZE 16
-
-/* Call AesGenTables one time before other AES functions */
-void AesGenTables(void);
-
-/* UInt32 pointers must be 16-byte aligned */
-
-/* 16-byte (4 * 32-bit words) blocks: 1 (IV) + 1 (keyMode) + 15 (AES-256 roundKeys) */
-#define AES_NUM_IVMRK_WORDS ((1 + 1 + 15) * 4)
-
-/* aes - 16-byte aligned pointer to keyMode+roundKeys sequence */
-/* keySize = 16 or 24 or 32 (bytes) */
-typedef void (MY_FAST_CALL *AES_SET_KEY_FUNC)(UInt32 *aes, const Byte *key, unsigned keySize);
-void MY_FAST_CALL Aes_SetKey_Enc(UInt32 *aes, const Byte *key, unsigned keySize);
-void MY_FAST_CALL Aes_SetKey_Dec(UInt32 *aes, const Byte *key, unsigned keySize);
-
-/* ivAes - 16-byte aligned pointer to iv+keyMode+roundKeys sequence: UInt32[AES_NUM_IVMRK_WORDS] */
-void AesCbc_Init(UInt32 *ivAes, const Byte *iv); /* iv size is AES_BLOCK_SIZE */
-
-/* data - 16-byte aligned pointer to data */
-/* numBlocks - the number of 16-byte blocks in data array */
-typedef void (MY_FAST_CALL *AES_CODE_FUNC)(UInt32 *ivAes, Byte *data, size_t numBlocks);
-
-extern AES_CODE_FUNC g_AesCbc_Decode;
-#ifndef _SFX
-extern AES_CODE_FUNC g_AesCbc_Encode;
-extern AES_CODE_FUNC g_AesCtr_Code;
-#define k_Aes_SupportedFunctions_HW (1 << 2)
-#define k_Aes_SupportedFunctions_HW_256 (1 << 3)
-extern UInt32 g_Aes_SupportedFunctions_Flags;
-#endif
-
-
-#define DECLARE__AES_CODE_FUNC(funcName) \
- void MY_FAST_CALL funcName(UInt32 *ivAes, Byte *data, size_t numBlocks);
-
-DECLARE__AES_CODE_FUNC (AesCbc_Encode)
-DECLARE__AES_CODE_FUNC (AesCbc_Decode)
-DECLARE__AES_CODE_FUNC (AesCtr_Code)
-
-DECLARE__AES_CODE_FUNC (AesCbc_Encode_HW)
-DECLARE__AES_CODE_FUNC (AesCbc_Decode_HW)
-DECLARE__AES_CODE_FUNC (AesCtr_Code_HW)
-
-DECLARE__AES_CODE_FUNC (AesCbc_Decode_HW_256)
-DECLARE__AES_CODE_FUNC (AesCtr_Code_HW_256)
-
-EXTERN_C_END
-
-#endif
diff --git a/deps/libchdr/deps/lzma-22.01/include/Alloc.h b/deps/libchdr/deps/lzma-22.01/include/Alloc.h
deleted file mode 100644
index 59de1076..00000000
--- a/deps/libchdr/deps/lzma-22.01/include/Alloc.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/* Alloc.h -- Memory allocation functions
-2021-07-13 : Igor Pavlov : Public domain */
-
-#ifndef __COMMON_ALLOC_H
-#define __COMMON_ALLOC_H
-
-#include "7zTypes.h"
-
-EXTERN_C_BEGIN
-
-void *MyAlloc(size_t size);
-void MyFree(void *address);
-
-#ifdef _WIN32
-
-void SetLargePageSize(void);
-
-void *MidAlloc(size_t size);
-void MidFree(void *address);
-void *BigAlloc(size_t size);
-void BigFree(void *address);
-
-#else
-
-#define MidAlloc(size) MyAlloc(size)
-#define MidFree(address) MyFree(address)
-#define BigAlloc(size) MyAlloc(size)
-#define BigFree(address) MyFree(address)
-
-#endif
-
-extern const ISzAlloc g_Alloc;
-
-#ifdef _WIN32
-extern const ISzAlloc g_BigAlloc;
-extern const ISzAlloc g_MidAlloc;
-#else
-#define g_BigAlloc g_AlignedAlloc
-#define g_MidAlloc g_AlignedAlloc
-#endif
-
-extern const ISzAlloc g_AlignedAlloc;
-
-
-typedef struct
-{
- ISzAlloc vt;
- ISzAllocPtr baseAlloc;
- unsigned numAlignBits; /* ((1 << numAlignBits) >= sizeof(void *)) */
- size_t offset; /* (offset == (k * sizeof(void *)) && offset < (1 << numAlignBits) */
-} CAlignOffsetAlloc;
-
-void AlignOffsetAlloc_CreateVTable(CAlignOffsetAlloc *p);
-
-
-EXTERN_C_END
-
-#endif
diff --git a/deps/libchdr/deps/lzma-22.01/include/Bcj2.h b/deps/libchdr/deps/lzma-22.01/include/Bcj2.h
deleted file mode 100644
index 68893d2d..00000000
--- a/deps/libchdr/deps/lzma-22.01/include/Bcj2.h
+++ /dev/null
@@ -1,146 +0,0 @@
-/* Bcj2.h -- BCJ2 Converter for x86 code
-2014-11-10 : Igor Pavlov : Public domain */
-
-#ifndef __BCJ2_H
-#define __BCJ2_H
-
-#include "7zTypes.h"
-
-EXTERN_C_BEGIN
-
-#define BCJ2_NUM_STREAMS 4
-
-enum
-{
- BCJ2_STREAM_MAIN,
- BCJ2_STREAM_CALL,
- BCJ2_STREAM_JUMP,
- BCJ2_STREAM_RC
-};
-
-enum
-{
- BCJ2_DEC_STATE_ORIG_0 = BCJ2_NUM_STREAMS,
- BCJ2_DEC_STATE_ORIG_1,
- BCJ2_DEC_STATE_ORIG_2,
- BCJ2_DEC_STATE_ORIG_3,
-
- BCJ2_DEC_STATE_ORIG,
- BCJ2_DEC_STATE_OK
-};
-
-enum
-{
- BCJ2_ENC_STATE_ORIG = BCJ2_NUM_STREAMS,
- BCJ2_ENC_STATE_OK
-};
-
-
-#define BCJ2_IS_32BIT_STREAM(s) ((s) == BCJ2_STREAM_CALL || (s) == BCJ2_STREAM_JUMP)
-
-/*
-CBcj2Dec / CBcj2Enc
-bufs sizes:
- BUF_SIZE(n) = lims[n] - bufs[n]
-bufs sizes for BCJ2_STREAM_CALL and BCJ2_STREAM_JUMP must be mutliply of 4:
- (BUF_SIZE(BCJ2_STREAM_CALL) & 3) == 0
- (BUF_SIZE(BCJ2_STREAM_JUMP) & 3) == 0
-*/
-
-/*
-CBcj2Dec:
-dest is allowed to overlap with bufs[BCJ2_STREAM_MAIN], with the following conditions:
- bufs[BCJ2_STREAM_MAIN] >= dest &&
- bufs[BCJ2_STREAM_MAIN] - dest >= tempReserv +
- BUF_SIZE(BCJ2_STREAM_CALL) +
- BUF_SIZE(BCJ2_STREAM_JUMP)
- tempReserv = 0 : for first call of Bcj2Dec_Decode
- tempReserv = 4 : for any other calls of Bcj2Dec_Decode
- overlap with offset = 1 is not allowed
-*/
-
-typedef struct
-{
- const Byte *bufs[BCJ2_NUM_STREAMS];
- const Byte *lims[BCJ2_NUM_STREAMS];
- Byte *dest;
- const Byte *destLim;
-
- unsigned state; /* BCJ2_STREAM_MAIN has more priority than BCJ2_STATE_ORIG */
-
- UInt32 ip;
- Byte temp[4];
- UInt32 range;
- UInt32 code;
- UInt16 probs[2 + 256];
-} CBcj2Dec;
-
-void Bcj2Dec_Init(CBcj2Dec *p);
-
-/* Returns: SZ_OK or SZ_ERROR_DATA */
-SRes Bcj2Dec_Decode(CBcj2Dec *p);
-
-#define Bcj2Dec_IsFinished(_p_) ((_p_)->code == 0)
-
-
-
-typedef enum
-{
- BCJ2_ENC_FINISH_MODE_CONTINUE,
- BCJ2_ENC_FINISH_MODE_END_BLOCK,
- BCJ2_ENC_FINISH_MODE_END_STREAM
-} EBcj2Enc_FinishMode;
-
-typedef struct
-{
- Byte *bufs[BCJ2_NUM_STREAMS];
- const Byte *lims[BCJ2_NUM_STREAMS];
- const Byte *src;
- const Byte *srcLim;
-
- unsigned state;
- EBcj2Enc_FinishMode finishMode;
-
- Byte prevByte;
-
- Byte cache;
- UInt32 range;
- UInt64 low;
- UInt64 cacheSize;
-
- UInt32 ip;
-
- /* 32-bit ralative offset in JUMP/CALL commands is
- - (mod 4 GB) in 32-bit mode
- - signed Int32 in 64-bit mode
- We use (mod 4 GB) check for fileSize.
- Use fileSize up to 2 GB, if you want to support 32-bit and 64-bit code conversion. */
- UInt32 fileIp;
- UInt32 fileSize; /* (fileSize <= ((UInt32)1 << 31)), 0 means no_limit */
- UInt32 relatLimit; /* (relatLimit <= ((UInt32)1 << 31)), 0 means desable_conversion */
-
- UInt32 tempTarget;
- unsigned tempPos;
- Byte temp[4 * 2];
-
- unsigned flushPos;
-
- UInt16 probs[2 + 256];
-} CBcj2Enc;
-
-void Bcj2Enc_Init(CBcj2Enc *p);
-void Bcj2Enc_Encode(CBcj2Enc *p);
-
-#define Bcj2Enc_Get_InputData_Size(p) ((SizeT)((p)->srcLim - (p)->src) + (p)->tempPos)
-#define Bcj2Enc_IsFinished(p) ((p)->flushPos == 5)
-
-
-#define BCJ2_RELAT_LIMIT_NUM_BITS 26
-#define BCJ2_RELAT_LIMIT ((UInt32)1 << BCJ2_RELAT_LIMIT_NUM_BITS)
-
-/* limit for CBcj2Enc::fileSize variable */
-#define BCJ2_FileSize_MAX ((UInt32)1 << 31)
-
-EXTERN_C_END
-
-#endif
diff --git a/deps/libchdr/deps/lzma-22.01/include/Bra.h b/deps/libchdr/deps/lzma-22.01/include/Bra.h
deleted file mode 100644
index aba8dce1..00000000
--- a/deps/libchdr/deps/lzma-22.01/include/Bra.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/* Bra.h -- Branch converters for executables
-2013-01-18 : Igor Pavlov : Public domain */
-
-#ifndef __BRA_H
-#define __BRA_H
-
-#include "7zTypes.h"
-
-EXTERN_C_BEGIN
-
-/*
-These functions convert relative addresses to absolute addresses
-in CALL instructions to increase the compression ratio.
-
- In:
- data - data buffer
- size - size of data
- ip - current virtual Instruction Pinter (IP) value
- state - state variable for x86 converter
- encoding - 0 (for decoding), 1 (for encoding)
-
- Out:
- state - state variable for x86 converter
-
- Returns:
- The number of processed bytes. If you call these functions with multiple calls,
- you must start next call with first byte after block of processed bytes.
-
- Type Endian Alignment LookAhead
-
- x86 little 1 4
- ARMT little 2 2
- ARM little 4 0
- PPC big 4 0
- SPARC big 4 0
- IA64 little 16 0
-
- size must be >= Alignment + LookAhead, if it's not last block.
- If (size < Alignment + LookAhead), converter returns 0.
-
- Example:
-
- UInt32 ip = 0;
- for ()
- {
- ; size must be >= Alignment + LookAhead, if it's not last block
- SizeT processed = Convert(data, size, ip, 1);
- data += processed;
- size -= processed;
- ip += processed;
- }
-*/
-
-#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
-
-#endif
diff --git a/deps/libchdr/deps/lzma-22.01/include/Compiler.h b/deps/libchdr/deps/lzma-22.01/include/Compiler.h
deleted file mode 100644
index eba37429..00000000
--- a/deps/libchdr/deps/lzma-22.01/include/Compiler.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/* Compiler.h
-2021-01-05 : Igor Pavlov : Public domain */
-
-#ifndef __7Z_COMPILER_H
-#define __7Z_COMPILER_H
-
- #ifdef __clang__
- #pragma clang diagnostic ignored "-Wunused-private-field"
- #endif
-
-#ifdef _MSC_VER
-
- #ifdef UNDER_CE
- #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
-
- #if _MSC_VER >= 1300
- #pragma warning(disable : 4996) // This function or variable may be unsafe
- #else
- #pragma warning(disable : 4511) // copy constructor could not be generated
- #pragma warning(disable : 4512) // assignment operator could not be generated
- #pragma warning(disable : 4514) // unreferenced inline function has been removed
- #pragma warning(disable : 4702) // unreachable code
- #pragma warning(disable : 4710) // not inlined
- #pragma warning(disable : 4714) // function marked as __forceinline not inlined
- #pragma warning(disable : 4786) // identifier was truncated to '255' characters in the debug information
- #endif
-
- #ifdef __clang__
- #pragma clang diagnostic ignored "-Wdeprecated-declarations"
- #pragma clang diagnostic ignored "-Wmicrosoft-exception-spec"
- // #pragma clang diagnostic ignored "-Wreserved-id-macro"
- #endif
-
-#endif
-
-#define UNUSED_VAR(x) (void)x;
-/* #define UNUSED_VAR(x) x=x; */
-
-#endif
diff --git a/deps/libchdr/deps/lzma-22.01/include/CpuArch.h b/deps/libchdr/deps/lzma-22.01/include/CpuArch.h
deleted file mode 100644
index ba878271..00000000
--- a/deps/libchdr/deps/lzma-22.01/include/CpuArch.h
+++ /dev/null
@@ -1,445 +0,0 @@
-/* CpuArch.h -- CPU specific code
-2022-07-15 : Igor Pavlov : Public domain */
-
-#ifndef __CPU_ARCH_H
-#define __CPU_ARCH_H
-
-#include "7zTypes.h"
-
-EXTERN_C_BEGIN
-
-/*
-MY_CPU_LE means that CPU is LITTLE ENDIAN.
-MY_CPU_BE means that CPU is BIG ENDIAN.
-If MY_CPU_LE and MY_CPU_BE are not defined, we don't know about ENDIANNESS of platform.
-
-MY_CPU_LE_UNALIGN means that CPU is LITTLE ENDIAN and CPU supports unaligned memory accesses.
-
-MY_CPU_64BIT means that processor can work with 64-bit registers.
- MY_CPU_64BIT can be used to select fast code branch
- MY_CPU_64BIT doesn't mean that (sizeof(void *) == 8)
-*/
-
-#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_SIZEOF_POINTER 4
- #else
- #define MY_CPU_NAME "x64"
- #define MY_CPU_SIZEOF_POINTER 8
- #endif
- #define MY_CPU_64BIT
-#endif
-
-
-#if defined(_M_IX86) \
- || defined(__i386__)
- #define MY_CPU_X86
- #define MY_CPU_NAME "x86"
- /* #define MY_CPU_32BIT */
- #define MY_CPU_SIZEOF_POINTER 4
-#endif
-
-
-#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
-
- #if defined(__thumb__) || defined(__THUMBEL__) || defined(_M_ARMT)
- #define MY_CPU_NAME "armt"
- #else
- #define MY_CPU_NAME "arm"
- #endif
- /* #define MY_CPU_32BIT */
- #define MY_CPU_SIZEOF_POINTER 4
-#endif
-
-
-#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 */
-#endif
-
-
-#if defined(__ppc64__) \
- || defined(__powerpc64__) \
- || defined(__ppc__) \
- || defined(__powerpc__) \
- || defined(__PPC__) \
- || defined(_POWER)
-
-#if defined(__ppc64__) \
- || defined(__powerpc64__) \
- || defined(_LP64) \
- || defined(__64BIT__)
- #ifdef __ILP32__
- #define MY_CPU_NAME "ppc64-32"
- #define MY_CPU_SIZEOF_POINTER 4
- #else
- #define MY_CPU_NAME "ppc64"
- #define MY_CPU_SIZEOF_POINTER 8
- #endif
- #define MY_CPU_64BIT
-#else
- #define MY_CPU_NAME "ppc"
- #define MY_CPU_SIZEOF_POINTER 4
- /* #define MY_CPU_32BIT */
-#endif
-#endif
-
-
-#if defined(__riscv) \
- || defined(__riscv__)
- #if __riscv_xlen == 32
- #define MY_CPU_NAME "riscv32"
- #elif __riscv_xlen == 64
- #define MY_CPU_NAME "riscv64"
- #else
- #define MY_CPU_NAME "riscv"
- #endif
-#endif
-
-
-#if defined(MY_CPU_X86) || defined(MY_CPU_AMD64)
-#define MY_CPU_X86_OR_AMD64
-#endif
-
-#if defined(MY_CPU_ARM) || defined(MY_CPU_ARM64)
-#define MY_CPU_ARM_OR_ARM64
-#endif
-
-
-#ifdef _WIN32
-
- #ifdef MY_CPU_ARM
- #define MY_CPU_ARM_LE
- #endif
-
- #ifdef MY_CPU_ARM64
- #define MY_CPU_ARM64_LE
- #endif
-
- #ifdef _M_IA64
- #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
-#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
-#endif
-
-
-#if defined(MY_CPU_LE) && defined(MY_CPU_BE)
- #error Stop_Compiling_Bad_Endian
-#endif
-
-
-#if defined(MY_CPU_32BIT) && defined(MY_CPU_64BIT)
- #error Stop_Compiling_Bad_32_64_BIT
-#endif
-
-#ifdef __SIZEOF_POINTER__
- #ifdef MY_CPU_SIZEOF_POINTER
- #if MY_CPU_SIZEOF_POINTER != __SIZEOF_POINTER__
- #error Stop_Compiling_Bad_MY_CPU_PTR_SIZE
- #endif
- #else
- #define MY_CPU_SIZEOF_POINTER __SIZEOF_POINTER__
- #endif
-#endif
-
-#if defined(MY_CPU_SIZEOF_POINTER) && (MY_CPU_SIZEOF_POINTER == 4)
-#if defined (_LP64)
- #error Stop_Compiling_Bad_MY_CPU_PTR_SIZE
-#endif
-#endif
-
-#ifdef _MSC_VER
- #if _MSC_VER >= 1300
- #define MY_CPU_pragma_pack_push_1 __pragma(pack(push, 1))
- #define MY_CPU_pragma_pop __pragma(pack(pop))
- #else
- #define MY_CPU_pragma_pack_push_1
- #define MY_CPU_pragma_pop
- #endif
-#else
- #ifdef __xlC__
- #define MY_CPU_pragma_pack_push_1 _Pragma("pack(1)")
- #define MY_CPU_pragma_pop _Pragma("pack()")
- #else
- #define MY_CPU_pragma_pack_push_1 _Pragma("pack(push, 1)")
- #define MY_CPU_pragma_pop _Pragma("pack(pop)")
- #endif
-#endif
-
-
-#ifndef MY_CPU_NAME
- #ifdef MY_CPU_LE
- #define MY_CPU_NAME "LE"
- #elif defined(MY_CPU_BE)
- #define MY_CPU_NAME "BE"
- #else
- /*
- #define MY_CPU_NAME ""
- */
- #endif
-#endif
-
-
-
-
-
-#ifdef MY_CPU_LE
- #if defined(MY_CPU_X86_OR_AMD64) \
- || defined(MY_CPU_ARM64)
- #define MY_CPU_LE_UNALIGN
- #define MY_CPU_LE_UNALIGN_64
- #elif defined(__ARM_FEATURE_UNALIGNED)
- /* gcc9 for 32-bit arm can use LDRD instruction that requires 32-bit alignment.
- So we can't use unaligned 64-bit operations. */
- #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))
-#ifdef MY_CPU_LE_UNALIGN_64
-#define GetUi64(p) (*(const UInt64 *)(const void *)(p))
-#endif
-
-#define SetUi16(p, v) { *(UInt16 *)(void *)(p) = (v); }
-#define SetUi32(p, v) { *(UInt32 *)(void *)(p) = (v); }
-#ifdef MY_CPU_LE_UNALIGN_64
-#define SetUi64(p, v) { *(UInt64 *)(void *)(p) = (v); }
-#endif
-
-#else
-
-#define GetUi16(p) ( (UInt16) ( \
- ((const Byte *)(p))[0] | \
- ((UInt16)((const Byte *)(p))[1] << 8) ))
-
-#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 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); \
- _ppp_[0] = (Byte)_vvv_; \
- _ppp_[1] = (Byte)(_vvv_ >> 8); \
- _ppp_[2] = (Byte)(_vvv_ >> 16); \
- _ppp_[3] = (Byte)(_vvv_ >> 24); }
-
-#endif
-
-
-#ifndef MY_CPU_LE_UNALIGN_64
-
-#define GetUi64(p) (GetUi32(p) | ((UInt64)GetUi32(((const Byte *)(p)) + 4) << 32))
-
-#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)
-#else
- #define MY__has_builtin(x) 0
-#endif
-
-#if defined(MY_CPU_LE_UNALIGN) && /* defined(_WIN64) && */ defined(_MSC_VER) && (_MSC_VER >= 1300)
-
-/* Note: we use bswap instruction, that is unsupported in 386 cpu */
-
-#include
-
-#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 void *)(p))
-#define GetBe64(p) _byteswap_uint64(*(const UInt64 *)(const void *)(p))
-
-#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)) )
-
-/* #define GetBe16(p) __builtin_bswap16(*(const UInt16 *)(const void *)(p)) */
-#define GetBe32(p) __builtin_bswap32(*(const UInt32 *)(const void *)(p))
-#define GetBe64(p) __builtin_bswap64(*(const UInt64 *)(const void *)(p))
-
-#define SetBe32(p, v) (*(UInt32 *)(void *)(p)) = __builtin_bswap32(v)
-
-#else
-
-#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 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); \
- _ppp_[3] = (Byte)_vvv_; }
-
-#endif
-
-
-#ifndef GetBe16
-
-#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;
-} Cx86cpuid;
-
-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(void);
-
-BoolInt CPU_IsSupported_AES(void);
-BoolInt CPU_IsSupported_AVX2(void);
-BoolInt CPU_IsSupported_VAES_AVX2(void);
-BoolInt CPU_IsSupported_SSSE3(void);
-BoolInt CPU_IsSupported_SSE41(void);
-BoolInt CPU_IsSupported_SHA(void);
-BoolInt CPU_IsSupported_PageGB(void);
-
-#elif defined(MY_CPU_ARM_OR_ARM64)
-
-BoolInt CPU_IsSupported_CRC32(void);
-BoolInt CPU_IsSupported_NEON(void);
-
-#if defined(_WIN32)
-BoolInt CPU_IsSupported_CRYPTO(void);
-#define CPU_IsSupported_SHA1 CPU_IsSupported_CRYPTO
-#define CPU_IsSupported_SHA2 CPU_IsSupported_CRYPTO
-#define CPU_IsSupported_AES CPU_IsSupported_CRYPTO
-#else
-BoolInt CPU_IsSupported_SHA1(void);
-BoolInt CPU_IsSupported_SHA2(void);
-BoolInt CPU_IsSupported_AES(void);
-#endif
-
-#endif
-
-#if defined(__APPLE__)
-int My_sysctlbyname_Get(const char *name, void *buf, size_t *bufSize);
-int My_sysctlbyname_Get_UInt32(const char *name, UInt32 *val);
-#endif
-
-EXTERN_C_END
-
-#endif
diff --git a/deps/libchdr/deps/lzma-22.01/include/Delta.h b/deps/libchdr/deps/lzma-22.01/include/Delta.h
deleted file mode 100644
index e59d5a25..00000000
--- a/deps/libchdr/deps/lzma-22.01/include/Delta.h
+++ /dev/null
@@ -1,19 +0,0 @@
-/* Delta.h -- Delta converter
-2013-01-18 : Igor Pavlov : Public domain */
-
-#ifndef __DELTA_H
-#define __DELTA_H
-
-#include "7zTypes.h"
-
-EXTERN_C_BEGIN
-
-#define DELTA_STATE_SIZE 256
-
-void Delta_Init(Byte *state);
-void Delta_Encode(Byte *state, unsigned delta, Byte *data, SizeT size);
-void Delta_Decode(Byte *state, unsigned delta, Byte *data, SizeT size);
-
-EXTERN_C_END
-
-#endif
diff --git a/deps/libchdr/deps/lzma-22.01/include/DllSecur.h b/deps/libchdr/deps/lzma-22.01/include/DllSecur.h
deleted file mode 100644
index 0fd8070e..00000000
--- a/deps/libchdr/deps/lzma-22.01/include/DllSecur.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/* DllSecur.h -- DLL loading for security
-2018-02-19 : Igor Pavlov : Public domain */
-
-#ifndef __DLL_SECUR_H
-#define __DLL_SECUR_H
-
-#include "7zTypes.h"
-
-EXTERN_C_BEGIN
-
-#ifdef _WIN32
-
-void My_SetDefaultDllDirectories(void);
-void LoadSecurityDlls(void);
-
-#endif
-
-EXTERN_C_END
-
-#endif
diff --git a/deps/libchdr/deps/lzma-22.01/include/LzFindMt.h b/deps/libchdr/deps/lzma-22.01/include/LzFindMt.h
deleted file mode 100644
index ee9a1b6f..00000000
--- a/deps/libchdr/deps/lzma-22.01/include/LzFindMt.h
+++ /dev/null
@@ -1,109 +0,0 @@
-/* LzFindMt.h -- multithreaded Match finder for LZ algorithms
-2021-07-12 : Igor Pavlov : Public domain */
-
-#ifndef __LZ_FIND_MT_H
-#define __LZ_FIND_MT_H
-
-#include "LzFind.h"
-#include "Threads.h"
-
-EXTERN_C_BEGIN
-
-typedef struct _CMtSync
-{
- UInt32 numProcessedBlocks;
- CThread thread;
- UInt64 affinity;
-
- BoolInt wasCreated;
- BoolInt needStart;
- BoolInt csWasInitialized;
- BoolInt csWasEntered;
-
- BoolInt exit;
- BoolInt stopWriting;
-
- CAutoResetEvent canStart;
- CAutoResetEvent wasStopped;
- CSemaphore freeSemaphore;
- CSemaphore filledSemaphore;
- CCriticalSection cs;
- // UInt32 numBlocks_Sent;
-} CMtSync;
-
-typedef UInt32 * (*Mf_Mix_Matches)(void *p, UInt32 matchMinPos, UInt32 *distances);
-
-/* kMtCacheLineDummy must be >= size_of_CPU_cache_line */
-#define kMtCacheLineDummy 128
-
-typedef void (*Mf_GetHeads)(const Byte *buffer, UInt32 pos,
- UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc);
-
-typedef struct _CMatchFinderMt
-{
- /* LZ */
- const Byte *pointerToCurPos;
- UInt32 *btBuf;
- const UInt32 *btBufPos;
- const UInt32 *btBufPosLimit;
- UInt32 lzPos;
- UInt32 btNumAvailBytes;
-
- UInt32 *hash;
- UInt32 fixedHashSize;
- // UInt32 hash4Mask;
- UInt32 historySize;
- const UInt32 *crc;
-
- Mf_Mix_Matches MixMatchesFunc;
- UInt32 failure_LZ_BT; // failure in BT transfered to LZ
- // UInt32 failure_LZ_LZ; // failure in LZ tables
- UInt32 failureBuf[1];
- // UInt32 crc[256];
-
- /* LZ + BT */
- CMtSync btSync;
- Byte btDummy[kMtCacheLineDummy];
-
- /* BT */
- UInt32 *hashBuf;
- UInt32 hashBufPos;
- UInt32 hashBufPosLimit;
- UInt32 hashNumAvail;
- UInt32 failure_BT;
-
-
- CLzRef *son;
- UInt32 matchMaxLen;
- UInt32 numHashBytes;
- UInt32 pos;
- const Byte *buffer;
- UInt32 cyclicBufferPos;
- UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */
- UInt32 cutValue;
-
- /* BT + Hash */
- CMtSync hashSync;
- /* Byte hashDummy[kMtCacheLineDummy]; */
-
- /* Hash */
- Mf_GetHeads GetHeadsFunc;
- CMatchFinder *MatchFinder;
- // CMatchFinder MatchFinder;
-} CMatchFinderMt;
-
-// only for Mt part
-void MatchFinderMt_Construct(CMatchFinderMt *p);
-void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAllocPtr alloc);
-
-SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore,
- UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAllocPtr alloc);
-void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder2 *vTable);
-
-/* call MatchFinderMt_InitMt() before IMatchFinder::Init() */
-SRes MatchFinderMt_InitMt(CMatchFinderMt *p);
-void MatchFinderMt_ReleaseStream(CMatchFinderMt *p);
-
-EXTERN_C_END
-
-#endif
diff --git a/deps/libchdr/deps/lzma-22.01/include/Lzma86.h b/deps/libchdr/deps/lzma-22.01/include/Lzma86.h
deleted file mode 100644
index 83057e59..00000000
--- a/deps/libchdr/deps/lzma-22.01/include/Lzma86.h
+++ /dev/null
@@ -1,111 +0,0 @@
-/* Lzma86.h -- LZMA + x86 (BCJ) Filter
-2013-01-18 : Igor Pavlov : Public domain */
-
-#ifndef __LZMA86_H
-#define __LZMA86_H
-
-#include "7zTypes.h"
-
-EXTERN_C_BEGIN
-
-#define LZMA86_SIZE_OFFSET (1 + 5)
-#define LZMA86_HEADER_SIZE (LZMA86_SIZE_OFFSET + 8)
-
-/*
-It's an example for LZMA + x86 Filter use.
-You can use .lzma86 extension, if you write that stream to file.
-.lzma86 header adds one additional byte to standard .lzma header.
-.lzma86 header (14 bytes):
- Offset Size Description
- 0 1 = 0 - no filter, pure LZMA
- = 1 - x86 filter + LZMA
- 1 1 lc, lp and pb in encoded form
- 2 4 dictSize (little endian)
- 6 8 uncompressed size (little endian)
-
-
-Lzma86_Encode
--------------
-level - compression level: 0 <= level <= 9, the default value for "level" is 5.
-
-dictSize - The dictionary size in bytes. The maximum value is
- 128 MB = (1 << 27) bytes for 32-bit version
- 1 GB = (1 << 30) bytes for 64-bit version
- The default value is 16 MB = (1 << 24) bytes, for level = 5.
- It's recommended to use the dictionary that is larger than 4 KB and
- that can be calculated as (1 << N) or (3 << N) sizes.
- For better compression ratio dictSize must be >= inSize.
-
-filterMode:
- SZ_FILTER_NO - no Filter
- SZ_FILTER_YES - x86 Filter
- SZ_FILTER_AUTO - it tries both alternatives to select best.
- Encoder will use 2 or 3 passes:
- 2 passes when FILTER_NO provides better compression.
- 3 passes when FILTER_YES provides better compression.
-
-Lzma86Encode allocates Data with MyAlloc functions.
-RAM Requirements for compressing:
- RamSize = dictionarySize * 11.5 + 6MB + FilterBlockSize
- filterMode FilterBlockSize
- SZ_FILTER_NO 0
- SZ_FILTER_YES inSize
- SZ_FILTER_AUTO inSize
-
-
-Return code:
- SZ_OK - OK
- SZ_ERROR_MEM - Memory allocation error
- SZ_ERROR_PARAM - Incorrect paramater
- SZ_ERROR_OUTPUT_EOF - output buffer overflow
- SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)
-*/
-
-enum ESzFilterMode
-{
- SZ_FILTER_NO,
- SZ_FILTER_YES,
- SZ_FILTER_AUTO
-};
-
-SRes Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen,
- int level, UInt32 dictSize, int filterMode);
-
-
-/*
-Lzma86_GetUnpackSize:
- In:
- src - input data
- srcLen - input data size
- Out:
- unpackSize - size of uncompressed stream
- Return code:
- SZ_OK - OK
- SZ_ERROR_INPUT_EOF - Error in headers
-*/
-
-SRes Lzma86_GetUnpackSize(const Byte *src, SizeT srcLen, UInt64 *unpackSize);
-
-/*
-Lzma86_Decode:
- In:
- dest - output data
- destLen - output data size
- src - input data
- srcLen - input data size
- Out:
- destLen - processed output size
- srcLen - processed input size
- Return code:
- SZ_OK - OK
- SZ_ERROR_DATA - Data error
- SZ_ERROR_MEM - Memory allocation error
- SZ_ERROR_UNSUPPORTED - unsupported file
- SZ_ERROR_INPUT_EOF - it needs more bytes in input buffer
-*/
-
-SRes Lzma86_Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen);
-
-EXTERN_C_END
-
-#endif
diff --git a/deps/libchdr/deps/lzma-22.01/include/LzmaLib.h b/deps/libchdr/deps/lzma-22.01/include/LzmaLib.h
deleted file mode 100644
index 4103e224..00000000
--- a/deps/libchdr/deps/lzma-22.01/include/LzmaLib.h
+++ /dev/null
@@ -1,138 +0,0 @@
-/* LzmaLib.h -- LZMA library interface
-2021-04-03 : Igor Pavlov : Public domain */
-
-#ifndef __LZMA_LIB_H
-#define __LZMA_LIB_H
-
-#include "7zTypes.h"
-
-EXTERN_C_BEGIN
-
-#define MY_STDAPI int MY_STD_CALL
-
-#define LZMA_PROPS_SIZE 5
-
-/*
-RAM requirements for LZMA:
- for compression: (dictSize * 11.5 + 6 MB) + state_size
- for decompression: dictSize + state_size
- state_size = (4 + (1.5 << (lc + lp))) KB
- by default (lc=3, lp=0), state_size = 16 KB.
-
-LZMA properties (5 bytes) format
- Offset Size Description
- 0 1 lc, lp and pb in encoded form.
- 1 4 dictSize (little endian).
-*/
-
-/*
-LzmaCompress
-------------
-
-outPropsSize -
- In: the pointer to the size of outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5.
- Out: the pointer to the size of written properties in outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5.
-
- LZMA Encoder will use defult values for any parameter, if it is
- -1 for any from: level, loc, lp, pb, fb, numThreads
- 0 for dictSize
-
-level - compression level: 0 <= level <= 9;
-
- level dictSize algo fb
- 0: 64 KB 0 32
- 1: 256 KB 0 32
- 2: 1 MB 0 32
- 3: 4 MB 0 32
- 4: 16 MB 0 32
- 5: 16 MB 1 32
- 6: 32 MB 1 32
- 7: 32 MB 1 64
- 8: 64 MB 1 64
- 9: 64 MB 1 64
-
- The default value for "level" is 5.
-
- algo = 0 means fast method
- algo = 1 means normal method
-
-dictSize - The dictionary size in bytes. The maximum value is
- 128 MB = (1 << 27) bytes for 32-bit version
- 1 GB = (1 << 30) bytes for 64-bit version
- The default value is 16 MB = (1 << 24) bytes.
- It's recommended to use the dictionary that is larger than 4 KB and
- that can be calculated as (1 << N) or (3 << N) sizes.
-
-lc - The number of literal context bits (high bits of previous literal).
- It can be in the range from 0 to 8. The default value is 3.
- Sometimes lc=4 gives the gain for big files.
-
-lp - The number of literal pos bits (low bits of current position for literals).
- It can be in the range from 0 to 4. The default value is 0.
- The lp switch is intended for periodical data when the period is equal to 2^lp.
- For example, for 32-bit (4 bytes) periodical data you can use lp=2. Often it's
- better to set lc=0, if you change lp switch.
-
-pb - The number of pos bits (low bits of current position).
- It can be in the range from 0 to 4. The default value is 2.
- The pb switch is intended for periodical data when the period is equal 2^pb.
-
-fb - Word size (the number of fast bytes).
- It can be in the range from 5 to 273. The default value is 32.
- Usually, a big number gives a little bit better compression ratio and
- slower compression process.
-
-numThreads - The number of thereads. 1 or 2. The default value is 2.
- Fast mode (algo = 0) can use only 1 thread.
-
-In:
- dest - output data buffer
- destLen - output data buffer size
- src - input data
- srcLen - input data size
-Out:
- destLen - processed output size
-Returns:
- SZ_OK - OK
- SZ_ERROR_MEM - Memory allocation error
- SZ_ERROR_PARAM - Incorrect paramater
- SZ_ERROR_OUTPUT_EOF - output buffer overflow
- SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)
-*/
-
-MY_STDAPI LzmaCompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t srcLen,
- unsigned char *outProps, size_t *outPropsSize, /* *outPropsSize must be = 5 */
- int level, /* 0 <= level <= 9, default = 5 */
- unsigned dictSize, /* default = (1 << 24) */
- int lc, /* 0 <= lc <= 8, default = 3 */
- int lp, /* 0 <= lp <= 4, default = 0 */
- int pb, /* 0 <= pb <= 4, default = 2 */
- int fb, /* 5 <= fb <= 273, default = 32 */
- int numThreads /* 1 or 2, default = 2 */
- );
-
-/*
-LzmaUncompress
---------------
-In:
- dest - output data buffer
- destLen - output data buffer size
- src - input data
- srcLen - input data size
-Out:
- destLen - processed output size
- srcLen - processed input size
-Returns:
- SZ_OK - OK
- SZ_ERROR_DATA - Data error
- SZ_ERROR_MEM - Memory allocation arror
- SZ_ERROR_UNSUPPORTED - Unsupported properties
- SZ_ERROR_INPUT_EOF - it needs more bytes in input buffer (src)
-*/
-
-MY_STDAPI LzmaUncompress(unsigned char *dest, size_t *destLen, const unsigned char *src, SizeT *srcLen,
- const unsigned char *props, size_t propsSize);
-
-EXTERN_C_END
-
-#endif
diff --git a/deps/libchdr/deps/lzma-22.01/include/MtCoder.h b/deps/libchdr/deps/lzma-22.01/include/MtCoder.h
deleted file mode 100644
index 603329d3..00000000
--- a/deps/libchdr/deps/lzma-22.01/include/MtCoder.h
+++ /dev/null
@@ -1,141 +0,0 @@
-/* MtCoder.h -- Multi-thread Coder
-2018-07-04 : Igor Pavlov : Public domain */
-
-#ifndef __MT_CODER_H
-#define __MT_CODER_H
-
-#include "MtDec.h"
-
-EXTERN_C_BEGIN
-
-/*
- if ( defined MTCODER__USE_WRITE_THREAD) : main thread writes all data blocks to output stream
- if (not defined MTCODER__USE_WRITE_THREAD) : any coder thread can write data blocks to output stream
-*/
-/* #define MTCODER__USE_WRITE_THREAD */
-
-#ifndef _7ZIP_ST
- #define MTCODER__GET_NUM_BLOCKS_FROM_THREADS(numThreads) ((numThreads) + (numThreads) / 8 + 1)
- #define MTCODER__THREADS_MAX 64
- #define MTCODER__BLOCKS_MAX (MTCODER__GET_NUM_BLOCKS_FROM_THREADS(MTCODER__THREADS_MAX) + 3)
-#else
- #define MTCODER__THREADS_MAX 1
- #define MTCODER__BLOCKS_MAX 1
-#endif
-
-
-#ifndef _7ZIP_ST
-
-
-typedef struct
-{
- ICompressProgress vt;
- CMtProgress *mtProgress;
- UInt64 inSize;
- UInt64 outSize;
-} CMtProgressThunk;
-
-void MtProgressThunk_CreateVTable(CMtProgressThunk *p);
-
-#define MtProgressThunk_Init(p) { (p)->inSize = 0; (p)->outSize = 0; }
-
-
-struct _CMtCoder;
-
-
-typedef struct
-{
- struct _CMtCoder *mtCoder;
- unsigned index;
- int stop;
- Byte *inBuf;
-
- CAutoResetEvent startEvent;
- CThread thread;
-} CMtCoderThread;
-
-
-typedef struct
-{
- SRes (*Code)(void *p, unsigned coderIndex, unsigned outBufIndex,
- const Byte *src, size_t srcSize, int finished);
- SRes (*Write)(void *p, unsigned outBufIndex);
-} IMtCoderCallback2;
-
-
-typedef struct
-{
- SRes res;
- unsigned bufIndex;
- BoolInt finished;
-} CMtCoderBlock;
-
-
-typedef struct _CMtCoder
-{
- /* input variables */
-
- size_t blockSize; /* size of input block */
- unsigned numThreadsMax;
- UInt64 expectedDataSize;
-
- ISeqInStream *inStream;
- const Byte *inData;
- size_t inDataSize;
-
- ICompressProgress *progress;
- ISzAllocPtr allocBig;
-
- IMtCoderCallback2 *mtCallback;
- void *mtCallbackObject;
-
-
- /* internal variables */
-
- size_t allocatedBufsSize;
-
- CAutoResetEvent readEvent;
- CSemaphore blocksSemaphore;
-
- BoolInt stopReading;
- SRes readRes;
-
- #ifdef MTCODER__USE_WRITE_THREAD
- CAutoResetEvent writeEvents[MTCODER__BLOCKS_MAX];
- #else
- CAutoResetEvent finishedEvent;
- SRes writeRes;
- unsigned writeIndex;
- Byte ReadyBlocks[MTCODER__BLOCKS_MAX];
- LONG numFinishedThreads;
- #endif
-
- unsigned numStartedThreadsLimit;
- unsigned numStartedThreads;
-
- unsigned numBlocksMax;
- unsigned blockIndex;
- UInt64 readProcessed;
-
- CCriticalSection cs;
-
- unsigned freeBlockHead;
- unsigned freeBlockList[MTCODER__BLOCKS_MAX];
-
- CMtProgress mtProgress;
- CMtCoderBlock blocks[MTCODER__BLOCKS_MAX];
- CMtCoderThread threads[MTCODER__THREADS_MAX];
-} CMtCoder;
-
-
-void MtCoder_Construct(CMtCoder *p);
-void MtCoder_Destruct(CMtCoder *p);
-SRes MtCoder_Code(CMtCoder *p);
-
-
-#endif
-
-
-EXTERN_C_END
-
-#endif
diff --git a/deps/libchdr/deps/lzma-22.01/include/MtDec.h b/deps/libchdr/deps/lzma-22.01/include/MtDec.h
deleted file mode 100644
index 7a30b6a9..00000000
--- a/deps/libchdr/deps/lzma-22.01/include/MtDec.h
+++ /dev/null
@@ -1,202 +0,0 @@
-/* MtDec.h -- Multi-thread Decoder
-2020-03-05 : Igor Pavlov : Public domain */
-
-#ifndef __MT_DEC_H
-#define __MT_DEC_H
-
-#include "7zTypes.h"
-
-#ifndef _7ZIP_ST
-#include "Threads.h"
-#endif
-
-EXTERN_C_BEGIN
-
-#ifndef _7ZIP_ST
-
-#ifndef _7ZIP_ST
- #define MTDEC__THREADS_MAX 32
-#else
- #define MTDEC__THREADS_MAX 1
-#endif
-
-
-typedef struct
-{
- ICompressProgress *progress;
- SRes res;
- UInt64 totalInSize;
- UInt64 totalOutSize;
- CCriticalSection cs;
-} CMtProgress;
-
-void MtProgress_Init(CMtProgress *p, ICompressProgress *progress);
-SRes MtProgress_Progress_ST(CMtProgress *p);
-SRes MtProgress_ProgressAdd(CMtProgress *p, UInt64 inSize, UInt64 outSize);
-SRes MtProgress_GetError(CMtProgress *p);
-void MtProgress_SetError(CMtProgress *p, SRes res);
-
-struct _CMtDec;
-
-typedef struct
-{
- struct _CMtDec *mtDec;
- unsigned index;
- void *inBuf;
-
- size_t inDataSize_Start; // size of input data in start block
- UInt64 inDataSize; // total size of input data in all blocks
-
- CThread thread;
- CAutoResetEvent canRead;
- CAutoResetEvent canWrite;
- void *allocaPtr;
-} CMtDecThread;
-
-void MtDecThread_FreeInBufs(CMtDecThread *t);
-
-
-typedef enum
-{
- MTDEC_PARSE_CONTINUE, // continue this block with more input data
- MTDEC_PARSE_OVERFLOW, // MT buffers overflow, need switch to single-thread
- MTDEC_PARSE_NEW, // new block
- MTDEC_PARSE_END // end of block threading. But we still can return to threading after Write(&needContinue)
-} EMtDecParseState;
-
-typedef struct
-{
- // in
- int startCall;
- const Byte *src;
- size_t srcSize;
- // in : (srcSize == 0) is allowed
- // out : it's allowed to return less that actually was used ?
- int srcFinished;
-
- // out
- EMtDecParseState state;
- BoolInt canCreateNewThread;
- UInt64 outPos; // check it (size_t)
-} CMtDecCallbackInfo;
-
-
-typedef struct
-{
- void (*Parse)(void *p, unsigned coderIndex, CMtDecCallbackInfo *ci);
-
- // PreCode() and Code():
- // (SRes_return_result != SZ_OK) means stop decoding, no need another blocks
- SRes (*PreCode)(void *p, unsigned coderIndex);
- SRes (*Code)(void *p, unsigned coderIndex,
- const Byte *src, size_t srcSize, int srcFinished,
- UInt64 *inCodePos, UInt64 *outCodePos, int *stop);
- // stop - means stop another Code calls
-
-
- /* Write() must be called, if Parse() was called
- set (needWrite) if
- {
- && (was not interrupted by progress)
- && (was not interrupted in previous block)
- }
-
- out:
- if (*needContinue), decoder still need to continue decoding with new iteration,
- even after MTDEC_PARSE_END
- if (*canRecode), we didn't flush current block data, so we still can decode current block later.
- */
- SRes (*Write)(void *p, unsigned coderIndex,
- BoolInt needWriteToStream,
- const Byte *src, size_t srcSize, BoolInt isCross,
- // int srcFinished,
- BoolInt *needContinue,
- BoolInt *canRecode);
-
-} IMtDecCallback2;
-
-
-
-typedef struct _CMtDec
-{
- /* input variables */
-
- size_t inBufSize; /* size of input block */
- unsigned numThreadsMax;
- // size_t inBlockMax;
- unsigned numThreadsMax_2;
-
- ISeqInStream *inStream;
- // const Byte *inData;
- // size_t inDataSize;
-
- ICompressProgress *progress;
- ISzAllocPtr alloc;
-
- IMtDecCallback2 *mtCallback;
- void *mtCallbackObject;
-
-
- /* internal variables */
-
- size_t allocatedBufsSize;
-
- BoolInt exitThread;
- WRes exitThreadWRes;
-
- UInt64 blockIndex;
- BoolInt isAllocError;
- BoolInt overflow;
- SRes threadingErrorSRes;
-
- BoolInt needContinue;
-
- // CAutoResetEvent finishedEvent;
-
- SRes readRes;
- SRes codeRes;
-
- BoolInt wasInterrupted;
-
- unsigned numStartedThreads_Limit;
- unsigned numStartedThreads;
-
- Byte *crossBlock;
- size_t crossStart;
- size_t crossEnd;
- UInt64 readProcessed;
- BoolInt readWasFinished;
- UInt64 inProcessed;
-
- unsigned filledThreadStart;
- unsigned numFilledThreads;
-
- #ifndef _7ZIP_ST
- BoolInt needInterrupt;
- UInt64 interruptIndex;
- CMtProgress mtProgress;
- CMtDecThread threads[MTDEC__THREADS_MAX];
- #endif
-} CMtDec;
-
-
-void MtDec_Construct(CMtDec *p);
-void MtDec_Destruct(CMtDec *p);
-
-/*
-MtDec_Code() returns:
- SZ_OK - in most cases
- MY_SRes_HRESULT_FROM_WRes(WRes_error) - in case of unexpected error in threading function
-*/
-
-SRes MtDec_Code(CMtDec *p);
-Byte *MtDec_GetCrossBuff(CMtDec *p);
-
-int MtDec_PrepareRead(CMtDec *p);
-const Byte *MtDec_Read(CMtDec *p, size_t *inLim);
-
-#endif
-
-EXTERN_C_END
-
-#endif
diff --git a/deps/libchdr/deps/lzma-22.01/include/Precomp.h b/deps/libchdr/deps/lzma-22.01/include/Precomp.h
deleted file mode 100644
index edb58144..00000000
--- a/deps/libchdr/deps/lzma-22.01/include/Precomp.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/* Precomp.h -- StdAfx
-2013-11-12 : Igor Pavlov : Public domain */
-
-#ifndef __7Z_PRECOMP_H
-#define __7Z_PRECOMP_H
-
-#include "Compiler.h"
-/* #include "7zTypes.h" */
-
-#endif
diff --git a/deps/libchdr/deps/lzma-22.01/include/RotateDefs.h b/deps/libchdr/deps/lzma-22.01/include/RotateDefs.h
deleted file mode 100644
index 6c790e79..00000000
--- a/deps/libchdr/deps/lzma-22.01/include/RotateDefs.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/* RotateDefs.h -- Rotate functions
-2015-03-25 : Igor Pavlov : Public domain */
-
-#ifndef __ROTATE_DEFS_H
-#define __ROTATE_DEFS_H
-
-#ifdef _MSC_VER
-
-#include
-
-/* don't use _rotl with MINGW. It can insert slow call to function. */
-
-/* #if (_MSC_VER >= 1200) */
-#pragma intrinsic(_rotl)
-#pragma intrinsic(_rotr)
-/* #endif */
-
-#define rotlFixed(x, n) _rotl((x), (n))
-#define rotrFixed(x, n) _rotr((x), (n))
-
-#else
-
-/* new compilers can translate these macros to fast commands. */
-
-#define rotlFixed(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
-#define rotrFixed(x, n) (((x) >> (n)) | ((x) << (32 - (n))))
-
-#endif
-
-#endif
diff --git a/deps/libchdr/deps/lzma-22.01/include/Sha256.h b/deps/libchdr/deps/lzma-22.01/include/Sha256.h
deleted file mode 100644
index f5293398..00000000
--- a/deps/libchdr/deps/lzma-22.01/include/Sha256.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/* Sha256.h -- SHA-256 Hash
-2021-01-01 : Igor Pavlov : Public domain */
-
-#ifndef __7Z_SHA256_H
-#define __7Z_SHA256_H
-
-#include "7zTypes.h"
-
-EXTERN_C_BEGIN
-
-#define SHA256_NUM_BLOCK_WORDS 16
-#define SHA256_NUM_DIGEST_WORDS 8
-
-#define SHA256_BLOCK_SIZE (SHA256_NUM_BLOCK_WORDS * 4)
-#define SHA256_DIGEST_SIZE (SHA256_NUM_DIGEST_WORDS * 4)
-
-typedef void (MY_FAST_CALL *SHA256_FUNC_UPDATE_BLOCKS)(UInt32 state[8], const Byte *data, size_t numBlocks);
-
-/*
- if (the system supports different SHA256 code implementations)
- {
- (CSha256::func_UpdateBlocks) will be used
- (CSha256::func_UpdateBlocks) can be set by
- Sha256_Init() - to default (fastest)
- Sha256_SetFunction() - to any algo
- }
- else
- {
- (CSha256::func_UpdateBlocks) is ignored.
- }
-*/
-
-typedef struct
-{
- SHA256_FUNC_UPDATE_BLOCKS func_UpdateBlocks;
- UInt64 count;
- UInt64 __pad_2[2];
- UInt32 state[SHA256_NUM_DIGEST_WORDS];
-
- Byte buffer[SHA256_BLOCK_SIZE];
-} CSha256;
-
-
-#define SHA256_ALGO_DEFAULT 0
-#define SHA256_ALGO_SW 1
-#define SHA256_ALGO_HW 2
-
-/*
-Sha256_SetFunction()
-return:
- 0 - (algo) value is not supported, and func_UpdateBlocks was not changed
- 1 - func_UpdateBlocks was set according (algo) value.
-*/
-
-BoolInt Sha256_SetFunction(CSha256 *p, unsigned algo);
-
-void Sha256_InitState(CSha256 *p);
-void Sha256_Init(CSha256 *p);
-void Sha256_Update(CSha256 *p, const Byte *data, size_t size);
-void Sha256_Final(CSha256 *p, Byte *digest);
-
-
-
-
-// void MY_FAST_CALL Sha256_UpdateBlocks(UInt32 state[8], const Byte *data, size_t numBlocks);
-
-/*
-call Sha256Prepare() once at program start.
-It prepares all supported implementations, and detects the fastest implementation.
-*/
-
-void Sha256Prepare(void);
-
-EXTERN_C_END
-
-#endif
diff --git a/deps/libchdr/deps/lzma-22.01/include/Sort.h b/deps/libchdr/deps/lzma-22.01/include/Sort.h
deleted file mode 100644
index 7209d782..00000000
--- a/deps/libchdr/deps/lzma-22.01/include/Sort.h
+++ /dev/null
@@ -1,18 +0,0 @@
-/* Sort.h -- Sort functions
-2014-04-05 : Igor Pavlov : Public domain */
-
-#ifndef __7Z_SORT_H
-#define __7Z_SORT_H
-
-#include "7zTypes.h"
-
-EXTERN_C_BEGIN
-
-void HeapSort(UInt32 *p, size_t size);
-void HeapSort64(UInt64 *p, size_t size);
-
-/* void HeapSortRef(UInt32 *p, UInt32 *vals, size_t size); */
-
-EXTERN_C_END
-
-#endif
diff --git a/deps/libchdr/deps/lzma-22.01/include/Threads.h b/deps/libchdr/deps/lzma-22.01/include/Threads.h
deleted file mode 100644
index 71972558..00000000
--- a/deps/libchdr/deps/lzma-22.01/include/Threads.h
+++ /dev/null
@@ -1,232 +0,0 @@
-/* Threads.h -- multithreading library
-2021-12-21 : Igor Pavlov : Public domain */
-
-#ifndef __7Z_THREADS_H
-#define __7Z_THREADS_H
-
-#ifdef _WIN32
-#include
-#else
-
-#if defined(__linux__)
-#if !defined(__APPLE__) && !defined(_AIX) && !defined(__ANDROID__)
-#ifndef _7ZIP_AFFINITY_DISABLE
-#define _7ZIP_AFFINITY_SUPPORTED
-// #pragma message(" ==== _7ZIP_AFFINITY_SUPPORTED")
-// #define _GNU_SOURCE
-#endif
-#endif
-#endif
-
-#include
-
-#endif
-
-#include "7zTypes.h"
-
-EXTERN_C_BEGIN
-
-#ifdef _WIN32
-
-WRes HandlePtr_Close(HANDLE *h);
-WRes Handle_WaitObject(HANDLE h);
-
-typedef HANDLE CThread;
-
-#define Thread_Construct(p) { *(p) = NULL; }
-#define Thread_WasCreated(p) (*(p) != NULL)
-#define Thread_Close(p) HandlePtr_Close(p)
-// #define Thread_Wait(p) Handle_WaitObject(*(p))
-
-#ifdef UNDER_CE
- // if (USE_THREADS_CreateThread is defined), we use _beginthreadex()
- // if (USE_THREADS_CreateThread is not definned), we use CreateThread()
- #define USE_THREADS_CreateThread
-#endif
-
-typedef
- #ifdef USE_THREADS_CreateThread
- DWORD
- #else
- unsigned
- #endif
- THREAD_FUNC_RET_TYPE;
-
-typedef DWORD_PTR CAffinityMask;
-typedef DWORD_PTR CCpuSet;
-
-#define CpuSet_Zero(p) { *(p) = 0; }
-#define CpuSet_Set(p, cpu) { *(p) |= ((DWORD_PTR)1 << (cpu)); }
-
-#else // _WIN32
-
-typedef struct _CThread
-{
- pthread_t _tid;
- int _created;
-} CThread;
-
-#define Thread_Construct(p) { (p)->_tid = 0; (p)->_created = 0; }
-#define Thread_WasCreated(p) ((p)->_created != 0)
-WRes Thread_Close(CThread *p);
-// #define Thread_Wait Thread_Wait_Close
-
-typedef void * THREAD_FUNC_RET_TYPE;
-
-typedef UInt64 CAffinityMask;
-
-#ifdef _7ZIP_AFFINITY_SUPPORTED
-
-typedef cpu_set_t CCpuSet;
-#define CpuSet_Zero(p) CPU_ZERO(p)
-#define CpuSet_Set(p, cpu) CPU_SET(cpu, p)
-#define CpuSet_IsSet(p, cpu) CPU_ISSET(cpu, p)
-
-#else
-
-typedef UInt64 CCpuSet;
-#define CpuSet_Zero(p) { *(p) = 0; }
-#define CpuSet_Set(p, cpu) { *(p) |= ((UInt64)1 << (cpu)); }
-#define CpuSet_IsSet(p, cpu) ((*(p) & ((UInt64)1 << (cpu))) != 0)
-
-#endif
-
-
-#endif // _WIN32
-
-
-#define THREAD_FUNC_CALL_TYPE MY_STD_CALL
-
-#if defined(_WIN32) && defined(__GNUC__)
-/* GCC compiler for x86 32-bit uses the rule:
- the stack is 16-byte aligned before CALL instruction for function calling.
- But only root function main() contains instructions that
- set 16-byte alignment for stack pointer. And another functions
- just keep alignment, if it was set in some parent function.
-
- The problem:
- if we create new thread in MinGW (GCC) 32-bit x86 via _beginthreadex() or CreateThread(),
- the root function of thread doesn't set 16-byte alignment.
- And stack frames in all child functions also will be unaligned in that case.
-
- Here we set (force_align_arg_pointer) attribute for root function of new thread.
- Do we need (force_align_arg_pointer) also for another systems? */
-
- #define THREAD_FUNC_ATTRIB_ALIGN_ARG __attribute__((force_align_arg_pointer))
- // #define THREAD_FUNC_ATTRIB_ALIGN_ARG // for debug : bad alignment in SSE functions
-#else
- #define THREAD_FUNC_ATTRIB_ALIGN_ARG
-#endif
-
-#define THREAD_FUNC_DECL THREAD_FUNC_ATTRIB_ALIGN_ARG THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE
-
-typedef THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE * THREAD_FUNC_TYPE)(void *);
-WRes Thread_Create(CThread *p, THREAD_FUNC_TYPE func, LPVOID param);
-WRes Thread_Create_With_Affinity(CThread *p, THREAD_FUNC_TYPE func, LPVOID param, CAffinityMask affinity);
-WRes Thread_Wait_Close(CThread *p);
-
-#ifdef _WIN32
-#define Thread_Create_With_CpuSet(p, func, param, cs) \
- Thread_Create_With_Affinity(p, func, param, *cs)
-#else
-WRes Thread_Create_With_CpuSet(CThread *p, THREAD_FUNC_TYPE func, LPVOID param, const CCpuSet *cpuSet);
-#endif
-
-
-#ifdef _WIN32
-
-typedef HANDLE CEvent;
-typedef CEvent CAutoResetEvent;
-typedef CEvent CManualResetEvent;
-#define Event_Construct(p) *(p) = NULL
-#define Event_IsCreated(p) (*(p) != NULL)
-#define Event_Close(p) HandlePtr_Close(p)
-#define Event_Wait(p) Handle_WaitObject(*(p))
-WRes Event_Set(CEvent *p);
-WRes Event_Reset(CEvent *p);
-WRes ManualResetEvent_Create(CManualResetEvent *p, int signaled);
-WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p);
-WRes AutoResetEvent_Create(CAutoResetEvent *p, int signaled);
-WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p);
-
-typedef HANDLE CSemaphore;
-#define Semaphore_Construct(p) *(p) = NULL
-#define Semaphore_IsCreated(p) (*(p) != NULL)
-#define Semaphore_Close(p) HandlePtr_Close(p)
-#define Semaphore_Wait(p) Handle_WaitObject(*(p))
-WRes Semaphore_Create(CSemaphore *p, UInt32 initCount, UInt32 maxCount);
-WRes Semaphore_OptCreateInit(CSemaphore *p, UInt32 initCount, UInt32 maxCount);
-WRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num);
-WRes Semaphore_Release1(CSemaphore *p);
-
-typedef CRITICAL_SECTION CCriticalSection;
-WRes CriticalSection_Init(CCriticalSection *p);
-#define CriticalSection_Delete(p) DeleteCriticalSection(p)
-#define CriticalSection_Enter(p) EnterCriticalSection(p)
-#define CriticalSection_Leave(p) LeaveCriticalSection(p)
-
-
-#else // _WIN32
-
-typedef struct _CEvent
-{
- int _created;
- int _manual_reset;
- int _state;
- pthread_mutex_t _mutex;
- pthread_cond_t _cond;
-} CEvent;
-
-typedef CEvent CAutoResetEvent;
-typedef CEvent CManualResetEvent;
-
-#define Event_Construct(p) (p)->_created = 0
-#define Event_IsCreated(p) ((p)->_created)
-
-WRes ManualResetEvent_Create(CManualResetEvent *p, int signaled);
-WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p);
-WRes AutoResetEvent_Create(CAutoResetEvent *p, int signaled);
-WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p);
-WRes Event_Set(CEvent *p);
-WRes Event_Reset(CEvent *p);
-WRes Event_Wait(CEvent *p);
-WRes Event_Close(CEvent *p);
-
-
-typedef struct _CSemaphore
-{
- int _created;
- UInt32 _count;
- UInt32 _maxCount;
- pthread_mutex_t _mutex;
- pthread_cond_t _cond;
-} CSemaphore;
-
-#define Semaphore_Construct(p) (p)->_created = 0
-#define Semaphore_IsCreated(p) ((p)->_created)
-
-WRes Semaphore_Create(CSemaphore *p, UInt32 initCount, UInt32 maxCount);
-WRes Semaphore_OptCreateInit(CSemaphore *p, UInt32 initCount, UInt32 maxCount);
-WRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num);
-#define Semaphore_Release1(p) Semaphore_ReleaseN(p, 1)
-WRes Semaphore_Wait(CSemaphore *p);
-WRes Semaphore_Close(CSemaphore *p);
-
-
-typedef struct _CCriticalSection
-{
- pthread_mutex_t _mutex;
-} CCriticalSection;
-
-WRes CriticalSection_Init(CCriticalSection *p);
-void CriticalSection_Delete(CCriticalSection *cs);
-void CriticalSection_Enter(CCriticalSection *cs);
-void CriticalSection_Leave(CCriticalSection *cs);
-
-LONG InterlockedIncrement(LONG volatile *addend);
-
-#endif // _WIN32
-
-EXTERN_C_END
-
-#endif
diff --git a/deps/libchdr/deps/lzma-22.01/installer.txt b/deps/libchdr/deps/lzma-22.01/installer.txt
deleted file mode 100644
index 70ad7dc6..00000000
--- a/deps/libchdr/deps/lzma-22.01/installer.txt
+++ /dev/null
@@ -1,166 +0,0 @@
-7-Zip for installers 9.38
--------------------------
-
-7-Zip is a file archiver for Windows NT/2000/2003/2008/XP/Vista/7/8/10.
-
-7-Zip for installers is part of LZMA SDK.
-LZMA SDK is written and placed in the public domain by Igor Pavlov.
-
-It's allowed to join 7-Zip SFX module with another software.
-It's allowed to change resources of 7-Zip's SFX modules.
-
-
-HOW to use
------------
-
-7zr.exe is reduced version of 7za.exe of 7-Zip.
-7zr.exe supports only format with these codecs: LZMA, LZMA2, BCJ, BCJ2, ARM, Copy.
-
-Example of compressing command for installation packages:
-
-7zr a archive.7z files
-
-7zSD.sfx is SFX module for installers. 7zSD.sfx uses msvcrt.dll.
-
-SFX modules for installers allow to create installation program.
-Such module extracts archive to temp folder and then runs specified program and removes
-temp files after program finishing. Self-extract archive for installers must be created
-as joining 3 files: SFX_Module, Installer_Config, 7z_Archive.
-Installer_Config is optional file. You can use the following command to create installer
-self-extract archive:
-
-copy /b 7zSD.sfx + config.txt + archive.7z archive.exe
-
-The smallest installation package size can be achieved, if installation files was
-uncompressed before including to 7z archive.
-
--y switch for installer module (at runtime) specifies quiet mode for extracting.
-
-Installer Config file format
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Config file contains commands for Installer. File begins from string
-;!@Install@!UTF-8! and ends with ;!@InstallEnd@!. File must be written
-in UTF-8 encoding. File contains string pairs:
-
-ID_String="Value"
-
-ID_String Description
-
-Title Title for messages
-BeginPrompt Begin Prompt message
-Progress Value can be "yes" or "no". Default value is "yes".
-RunProgram Command for executing. Default value is "setup.exe".
- Substring %%T will be replaced with path to temporary
- folder, where files were extracted
-Directory Directory prefix for "RunProgram". Default value is ".\\"
-ExecuteFile Name of file for executing
-ExecuteParameters Parameters for "ExecuteFile"
-
-
-You can omit any string pair.
-
-There are two ways to run program: RunProgram and ExecuteFile.
-Use RunProgram, if you want to run some program from .7z archive.
-Use ExecuteFile, if you want to open some document from .7z archive or
-if you want to execute some command from Windows.
-
-If you use RunProgram and if you specify empty directory prefix: Directory="",
-the system searches for the executable file in the following sequence:
-
-1. The directory from which the application (installer) loaded.
-2. The temporary folder, where files were extracted.
-3. The Windows system directory.
-
-
-Config file Examples
-~~~~~~~~~~~~~~~~~~~~
-
-;!@Install@!UTF-8!
-Title="7-Zip 4.00"
-BeginPrompt="Do you want to install the 7-Zip 4.00?"
-RunProgram="setup.exe"
-;!@InstallEnd@!
-
-
-
-;!@Install@!UTF-8!
-Title="7-Zip 4.00"
-BeginPrompt="Do you want to install the 7-Zip 4.00?"
-ExecuteFile="7zip.msi"
-;!@InstallEnd@!
-
-
-
-;!@Install@!UTF-8!
-Title="7-Zip 4.01 Update"
-BeginPrompt="Do you want to install the 7-Zip 4.01 Update?"
-ExecuteFile="msiexec.exe"
-ExecuteParameters="/i 7zip.msi REINSTALL=ALL REINSTALLMODE=vomus"
-;!@InstallEnd@!
-
-
-
-Small SFX modules for installers
---------------------------------
-
-7zS2.sfx - small SFX module (GUI version)
-7zS2con.sfx - small SFX module (Console version)
-
-Small SFX modules support this codecs: LZMA, LZMA2, BCJ, BCJ2, ARM, COPY
-
-Small SFX module is similar to common SFX module for installers.
-The difference (what's new in small version):
- - Smaller size (30 KB vs 100 KB)
- - C source code instead of Ñ++
- - No installer Configuration file
- - No extracting progress window
- - It decompresses solid 7z blocks (it can be whole 7z archive) to RAM.
- So user that calls SFX installer must have free RAM of size of largest
- solid 7z block (size of 7z archive at simplest case).
-
-How to use
-----------
-
-copy /b 7zS2.sfx + archive.7z sfx.exe
-
-When you run installer sfx module (sfx.exe)
-1) It creates "7zNNNNNNNN" temp folder in system temp folder.
-2) It extracts .7z archive to that folder
-3) It executes one file from "7zNNNNNNNN" temp folder.
-4) It removes "7zNNNNNNNN" temp folder
-
-You can send parameters to installer, and installer will transfer them to extracted .exe file.
-
-Small SFX uses 3 levels of priorities to select file to execute:
-
- 1) Files in root folder have higher priority than files in subfolders.
- 2) File extension priorities (from high to low priority order):
- bat, cmd, exe, inf, msi, cab (under Windows CE), html, htm
- 3) File name priorities (from high to low priority order):
- setup, install, run, start
-
-Windows CE (ARM) version of 7zS2.sfx is included to 7-Zip for Windows Mobile package.
-
-
-Examples
---------
-
-1) To create compressed console 7-Zip:
-
-7zr a c.7z 7z.exe 7z.dll -mx
-copy /b 7zS2con.sfx + c.7z 7zCompr.exe
-7zCompr.exe b -md22
-
-
-2) To create compressed GUI 7-Zip:
-
-7zr a g.7z 7zg.exe 7z.dll -mx
-copy /b 7zS2.sfx + g.7z 7zgCompr.exe
-7zgCompr.exe b -md22
-
-
-3) To open some file:
-
-7zr a h.7z readme.txt -mx
-copy /b 7zS2.sfx + h.7z 7zTxt.exe
-7zTxt.exe
diff --git a/deps/libchdr/deps/lzma-22.01/lzma-history.txt b/deps/libchdr/deps/lzma-22.01/lzma-history.txt
deleted file mode 100644
index 9c5a2416..00000000
--- a/deps/libchdr/deps/lzma-22.01/lzma-history.txt
+++ /dev/null
@@ -1,520 +0,0 @@
-HISTORY of the LZMA SDK
------------------------
-
-21.07 2021-12-26
--------------------------
-- New switches: -spm and -im!{file_path} to exclude directories from processing
- for specified paths that don't contain path separator character at the end of path.
-- The sorting order of files in archives was slightly changed to be more consistent
- for cases where the name of some directory is the same as the prefix part of the name
- of another directory or file.
-
-
-21.06 2021-11-24
--------------------------
-- Bug in LZMA encoder in file LzmaEnc.c was fixed:
- LzmaEnc_MemEncode(), LzmaEncode() and LzmaCompress() could work incorrectly,
- if size value for output buffer is smaller than size required for all compressed data.
- LzmaEnc_Encode() could work incorrectly,
- if callback ISeqOutStream::Write() doesn't write all compressed data.
- NCompress::NLzma::CEncoder::Code() could work incorrectly,
- if callback ISequentialOutStream::Write() returns error code.
-- Bug in versions 21.00-21.05 was fixed:
- 7-Zip didn't set attributes of directories during archive extracting.
-
-
-21.04 beta 2021-11-02
--------------------------
-- 7-Zip now reduces the number of working CPU threads for compression,
- if RAM size is not enough for compression with big LZMA2 dictionary.
-- 7-Zip now can create and check "file.sha256" text files that contain the list
- of file names and SHA-256 checksums in format compatible with sha256sum program.
-
-
-21.03 beta 2021-07-20
--------------------------
-- The maximum dictionary size for LZMA/LZMA2 compressing was increased to 4 GB (3840 MiB).
-- Minor speed optimizations in LZMA/LZMA2 compressing.
-
-
-21.02 alpha 2021-05-06
--------------------------
-- The command line version of 7-Zip for macOS was released.
-- The speed for LZMA and LZMA2 decompression in arm64 versions for macOS and Linux
- was increased by 20%-60%.
-
-
-21.01 alpha 2021-03-09
--------------------------
-- The command line version of 7-Zip for Linux was released.
-- The improvements for speed of ARM64 version using hardware CPU instructions
- for AES, CRC-32, SHA-1 and SHA-256.
-- Some bugs were fixed.
-
-
-20.02 alpha 2020-08-08
--------------------------
-- The default number of LZMA2 chunks per solid block in 7z archive was increased to 64.
- It allows to increase the compression speed for big 7z archives, if there is a big number
- of CPU cores and threads.
-- The speed of PPMd compressing/decompressing was increased for 7z archives.
-- The new -ssp switch. If the switch -ssp is specified, 7-Zip doesn't allow the system
- to modify "Last Access Time" property of source files for archiving and hashing operations.
-- Some bugs were fixed.
-
-
-20.00 alpha 2020-02-06
--------------------------
-- 7-Zip now supports new optional match finders for LZMA/LZMA2 compression: bt5 and hc5,
- that can work faster than bt4 and hc4 match finders for the data with big redundancy.
-- The compression ratio was improved for Fast and Fastest compression levels with the
- following default settings:
- - Fastest level (-mx1) : hc5 match finder with 256 KB dictionary.
- - Fast level (-mx3) : hc5 match finder with 4 MB dictionary.
-- Minor speed optimizations in multithreaded LZMA/LZMA2 compression for Normal/Maximum/Ultra
- compression levels.
-
-
-19.00 2019-02-21
--------------------------
-- Encryption strength for 7z archives was increased:
- the size of random initialization vector was increased from 64-bit to 128-bit,
- and the pseudo-random number generator was improved.
-- The bug in 7zIn.c code was fixed.
-
-
-18.06 2018-12-30
--------------------------
-- The speed for LZMA/LZMA2 compressing was increased by 3-10%,
- and there are minor changes in compression ratio.
-- Some bugs were fixed.
-- The bug in 7-Zip 18.02-18.05 was fixed:
- There was memory leak in multithreading xz decoder - XzDecMt_Decode(),
- if xz stream contains only one block.
-- The changes for MSVS compiler makefiles:
- - the makefiles now use "PLATFORM" macroname with values (x64, x86, arm64)
- instead of "CPU" macroname with values (AMD64, ARM64).
- - the makefiles by default now use static version of the run-time library.
-
-
-18.05 2018-04-30
--------------------------
-- The speed for LZMA/LZMA2 compressing was increased
- by 8% for fastest/fast compression levels and
- by 3% for normal/maximum compression levels.
-- Previous versions of 7-Zip could work incorrectly in "Large memory pages" mode in
- Windows 10 because of some BUG with "Large Pages" in Windows 10.
- Now 7-Zip doesn't use "Large Pages" on Windows 10 up to revision 1709 (16299).
-- The BUG was fixed in Lzma2Enc.c
- Lzma2Enc_Encode2() function worked incorretly,
- if (inStream == NULL) and the number of block threads is more than 1.
-
-
-18.03 beta 2018-03-04
--------------------------
-- Asm\x86\LzmaDecOpt.asm: new optimized LZMA decoder written in asm
- for x64 with about 30% higher speed than main version of LZMA decoder written in C.
-- The speed for single-thread LZMA/LZMA2 decoder written in C was increased by 3%.
-- 7-Zip now can use multi-threading for 7z/LZMA2 decoding,
- if there are multiple independent data chunks in LZMA2 stream.
-- 7-Zip now can use multi-threading for xz decoding,
- if there are multiple blocks in xz stream.
-
-
-18.01 2019-01-28
--------------------------
-- The BUG in 17.01 - 18.00 beta was fixed:
- XzDec.c : random block unpacking and XzUnpacker_IsBlockFinished()
- didn't work correctly for xz archives without checksum (CRC).
-
-
-18.00 beta 2019-01-10
--------------------------
-- The BUG in xz encoder was fixed:
- There was memory leak of 16 KB for each file compressed with
- xz compression method, if additional filter was used.
-
-
-17.01 beta 2017-08-28
--------------------------
-- Minor speed optimization for LZMA2 (xz and 7z) multi-threading compression.
- 7-Zip now uses additional memory buffers for multi-block LZMA2 compression.
- CPU utilization was slightly improved.
-- 7-zip now creates multi-block xz archives by default. Block size can be
- specified with -ms[Size]{m|g} switch.
-- xz decoder now can unpack random block from multi-block xz archives.
-- 7-Zip command line: @listfile now doesn't work after -- switch.
- Use -i@listfile before -- switch instead.
-- The BUGs were fixed:
- 7-Zip 17.00 beta crashed for commands that write anti-item to 7z archive.
-
-
-17.00 beta 2017-04-29
--------------------------
-- NewHandler.h / NewHandler.cpp:
- now it redefines operator new() only for old MSVC compilers (_MSC_VER < 1900).
-- C/7zTypes.h : the names of variables in interface structures were changed (vt).
-- Some bugs were fixed. 7-Zip could crash in some cases.
-- Some internal changes in code.
-
-
-16.04 2016-10-04
--------------------------
-- The bug was fixed in DllSecur.c.
-
-
-16.03 2016-09-28
--------------------------
-- SFX modules now use some protection against DLL preloading attack.
-- Some bugs in 7z code were fixed.
-
-
-16.02 2016-05-21
--------------------------
-- The BUG in 16.00 - 16.01 was fixed:
- Split Handler (SplitHandler.cpp) returned incorrect
- total size value (kpidSize) for split archives.
-
-
-16.01 2016-05-19
--------------------------
-- Some internal changes to reduce the number of compiler warnings.
-
-
-16.00 2016-05-10
--------------------------
-- Some bugs were fixed.
-
-
-15.12 2015-11-19
--------------------------
-- The BUG in C version of 7z decoder was fixed:
- 7zDec.c : SzDecodeLzma2()
- 7z decoder could mistakenly report about decoding error for some 7z archives
- that use LZMA2 compression method.
- The probability to get that mistaken decoding error report was about
- one error per 16384 solid blocks for solid blocks larger than 16 KB (compressed size).
-- The BUG (in 9.26-15.11) in C version of 7z decoder was fixed:
- 7zArcIn.c : SzReadHeader2()
- 7z decoder worked incorrectly for 7z archives that contain
- empty solid blocks, that can be placed to 7z archive, if some file is
- unavailable for reading during archive creation.
-
-
-15.09 beta 2015-10-16
--------------------------
-- The BUG in LZMA / LZMA2 encoding code was fixed.
- The BUG in LzFind.c::MatchFinder_ReadBlock() function.
- If input data size is larger than (4 GiB - dictionary_size),
- the following code worked incorrectly:
- - LZMA : LzmaEnc_MemEncode(), LzmaEncode() : LZMA encoding functions
- for compressing from memory to memory.
- That BUG is not related to LZMA encoder version that works via streams.
- - LZMA2 : multi-threaded version of LZMA2 encoder worked incorrectly, if
- default value of chunk size (CLzma2EncProps::blockSize) is changed
- to value larger than (4 GiB - dictionary_size).
-
-
-9.38 beta 2015-01-03
--------------------------
-- The BUG in 9.31-9.37 was fixed:
- IArchiveGetRawProps interface was disabled for 7z archives.
-- The BUG in 9.26-9.36 was fixed:
- Some code in CPP\7zip\Archive\7z\ worked correctly only under Windows.
-
-
-9.36 beta 2014-12-26
--------------------------
-- The BUG in command line version was fixed:
- 7-Zip created temporary archive in current folder during update archive
- operation, if -w{Path} switch was not specified.
- The fixed 7-Zip creates temporary archive in folder that contains updated archive.
-- The BUG in 9.33-9.35 was fixed:
- 7-Zip silently ignored file reading errors during 7z or gz archive creation,
- and the created archive contained only part of file that was read before error.
- The fixed 7-Zip stops archive creation and it reports about error.
-
-
-9.35 beta 2014-12-07
--------------------------
-- 7zr.exe now support AES encryption.
-- SFX mudules were added to LZMA SDK
-- Some bugs were fixed.
-
-
-9.21 beta 2011-04-11
--------------------------
-- New class FString for file names at file systems.
-- Speed optimization in CRC code for big-endian CPUs.
-- The BUG in Lzma2Dec.c was fixed:
- Lzma2Decode function didn't work.
-
-
-9.18 beta 2010-11-02
--------------------------
-- New small SFX module for installers (SfxSetup).
-
-
-9.12 beta 2010-03-24
--------------------------
-- The BUG in LZMA SDK 9.* was fixed: LZMA2 codec didn't work,
- if more than 10 threads were used (or more than 20 threads in some modes).
-
-
-9.11 beta 2010-03-15
--------------------------
-- PPMd compression method support
-
-
-9.09 2009-12-12
--------------------------
-- The bug was fixed:
- Utf16_To_Utf8 funstions in UTFConvert.cpp and 7zMain.c
- incorrectly converted surrogate characters (the code >= 0x10000) to UTF-8.
-- Some bugs were fixed
-
-
-9.06 2009-08-17
--------------------------
-- Some changes in ANSI-C 7z Decoder interfaces.
-
-
-9.04 2009-05-30
--------------------------
-- LZMA2 compression method support
-- xz format support
-
-
-4.65 2009-02-03
--------------------------
-- Some minor fixes
-
-
-4.63 2008-12-31
--------------------------
-- Some minor fixes
-
-
-4.61 beta 2008-11-23
--------------------------
-- The bug in ANSI-C LZMA Decoder was fixed:
- If encoded stream was corrupted, decoder could access memory
- outside of allocated range.
-- Some changes in ANSI-C 7z Decoder interfaces.
-- LZMA SDK is placed in the public domain.
-
-
-4.60 beta 2008-08-19
--------------------------
-- Some minor fixes.
-
-
-4.59 beta 2008-08-13
--------------------------
-- The bug was fixed:
- LZMA Encoder in fast compression mode could access memory outside of
- allocated range in some rare cases.
-
-
-4.58 beta 2008-05-05
--------------------------
-- ANSI-C LZMA Decoder was rewritten for speed optimizations.
-- ANSI-C LZMA Encoder was included to LZMA SDK.
-- C++ LZMA code now is just wrapper over ANSI-C code.
-
-
-4.57 2007-12-12
--------------------------
-- Speed optimizations in Ñ++ LZMA Decoder.
-- Small changes for more compatibility with some C/C++ compilers.
-
-
-4.49 beta 2007-07-05
--------------------------
-- .7z ANSI-C Decoder:
- - now it supports BCJ and BCJ2 filters
- - now it supports files larger than 4 GB.
- - now it supports "Last Write Time" field for files.
-- C++ code for .7z archives compressing/decompressing from 7-zip
- was included to LZMA SDK.
-
-
-4.43 2006-06-04
--------------------------
-- Small changes for more compatibility with some C/C++ compilers.
-
-
-4.42 2006-05-15
--------------------------
-- Small changes in .h files in ANSI-C version.
-
-
-4.39 beta 2006-04-14
--------------------------
-- The bug in versions 4.33b:4.38b was fixed:
- C++ version of LZMA encoder could not correctly compress
- files larger than 2 GB with HC4 match finder (-mfhc4).
-
-
-4.37 beta 2005-04-06
--------------------------
-- Fixes in C++ code: code could no be compiled if _NO_EXCEPTIONS was defined.
-
-
-4.35 beta 2005-03-02
--------------------------
-- The bug was fixed in C++ version of LZMA Decoder:
- If encoded stream was corrupted, decoder could access memory
- outside of allocated range.
-
-
-4.34 beta 2006-02-27
--------------------------
-- Compressing speed and memory requirements for compressing were increased
-- LZMA now can use only these match finders: HC4, BT2, BT3, BT4
-
-
-4.32 2005-12-09
--------------------------
-- Java version of LZMA SDK was included
-
-
-4.30 2005-11-20
--------------------------
-- Compression ratio was improved in -a2 mode
-- Speed optimizations for compressing in -a2 mode
-- -fb switch now supports values up to 273
-- The bug in 7z_C (7zIn.c) was fixed:
- It used Alloc/Free functions from different memory pools.
- So if program used two memory pools, it worked incorrectly.
-- 7z_C: .7z format supporting was improved
-- LZMA# SDK (C#.NET version) was included
-
-
-4.27 (Updated) 2005-09-21
--------------------------
-- Some GUIDs/interfaces in C++ were changed.
- IStream.h:
- ISequentialInStream::Read now works as old ReadPart
- ISequentialOutStream::Write now works as old WritePart
-
-
-4.27 2005-08-07
--------------------------
-- The bug in LzmaDecodeSize.c was fixed:
- if _LZMA_IN_CB and _LZMA_OUT_READ were defined,
- decompressing worked incorrectly.
-
-
-4.26 2005-08-05
--------------------------
-- Fixes in 7z_C code and LzmaTest.c:
- previous versions could work incorrectly,
- if malloc(0) returns 0
-
-
-4.23 2005-06-29
--------------------------
-- Small fixes in C++ code
-
-
-4.22 2005-06-10
--------------------------
-- Small fixes
-
-
-4.21 2005-06-08
--------------------------
-- Interfaces for ANSI-C LZMA Decoder (LzmaDecode.c) were changed
-- New additional version of ANSI-C LZMA Decoder with zlib-like interface:
- - LzmaStateDecode.h
- - LzmaStateDecode.c
- - LzmaStateTest.c
-- ANSI-C LZMA Decoder now can decompress files larger than 4 GB
-
-
-4.17 2005-04-18
--------------------------
-- New example for RAM->RAM compressing/decompressing:
- LZMA + BCJ (filter for x86 code):
- - LzmaRam.h
- - LzmaRam.cpp
- - LzmaRamDecode.h
- - LzmaRamDecode.c
- - -f86 switch for lzma.exe
-
-
-4.16 2005-03-29
--------------------------
-- The bug was fixed in LzmaDecode.c (ANSI-C LZMA Decoder):
- If _LZMA_OUT_READ was defined, and if encoded stream was corrupted,
- decoder could access memory outside of allocated range.
-- Speed optimization of ANSI-C LZMA Decoder (now it's about 20% faster).
- Old version of LZMA Decoder now is in file LzmaDecodeSize.c.
- LzmaDecodeSize.c can provide slightly smaller code than LzmaDecode.c
-- Small speed optimization in LZMA C++ code
-- filter for SPARC's code was added
-- Simplified version of .7z ANSI-C Decoder was included
-
-
-4.06 2004-09-05
--------------------------
-- The bug in v4.05 was fixed:
- LZMA-Encoder didn't release output stream in some cases.
-
-
-4.05 2004-08-25
--------------------------
-- Source code of filters for x86, IA-64, ARM, ARM-Thumb
- and PowerPC code was included to SDK
-- Some internal minor changes
-
-
-4.04 2004-07-28
--------------------------
-- More compatibility with some C++ compilers
-
-
-4.03 2004-06-18
--------------------------
-- "Benchmark" command was added. It measures compressing
- and decompressing speed and shows rating values.
- Also it checks hardware errors.
-
-
-4.02 2004-06-10
--------------------------
-- C++ LZMA Encoder/Decoder code now is more portable
- and it can be compiled by GCC on Linux.
-
-
-4.01 2004-02-15
--------------------------
-- Some detection of data corruption was enabled.
- LzmaDecode.c / RangeDecoderReadByte
- .....
- {
- rd->ExtraBytes = 1;
- return 0xFF;
- }
-
-
-4.00 2004-02-13
--------------------------
-- Original version of LZMA SDK
-
-
-
-HISTORY of the LZMA
--------------------
- 2001-2008: Improvements to LZMA compressing/decompressing code,
- keeping compatibility with original LZMA format
- 1996-2001: Development of LZMA compression format
-
- Some milestones:
-
- 2001-08-30: LZMA compression was added to 7-Zip
- 1999-01-02: First version of 7-Zip was released
-
-
-End of document
diff --git a/deps/libchdr/deps/lzma-22.01/lzma-sdk.txt b/deps/libchdr/deps/lzma-22.01/lzma-sdk.txt
deleted file mode 100644
index d54aad32..00000000
--- a/deps/libchdr/deps/lzma-22.01/lzma-sdk.txt
+++ /dev/null
@@ -1,404 +0,0 @@
-LZMA SDK 22.01
---------------
-
-LZMA SDK provides the documentation, samples, header files,
-libraries, and tools you need to develop applications that
-use 7z / LZMA / LZMA2 / XZ compression.
-
-LZMA is an improved version of famous LZ77 compression algorithm.
-It was improved in way of maximum increasing of compression ratio,
-keeping high decompression speed and low memory requirements for
-decompressing.
-
-LZMA2 is a LZMA based compression method. LZMA2 provides better
-multithreading support for compression than LZMA and some other improvements.
-
-7z is a file format for data compression and file archiving.
-7z is a main file format for 7-Zip compression program (www.7-zip.org).
-7z format supports different compression methods: LZMA, LZMA2 and others.
-7z also supports AES-256 based encryption.
-
-XZ is a file format for data compression that uses LZMA2 compression.
-XZ format provides additional features: SHA/CRC check, filters for
-improved compression ratio, splitting to blocks and streams,
-
-
-
-LICENSE
--------
-
-LZMA SDK is written and placed in the public domain by Igor Pavlov.
-
-Some code in LZMA SDK is based on public domain code from another developers:
- 1) PPMd var.H (2001): Dmitry Shkarin
- 2) SHA-256: Wei Dai (Crypto++ library)
-
-Anyone is free to copy, modify, publish, use, compile, sell, or distribute the
-original LZMA SDK code, either in source code form or as a compiled binary, for
-any purpose, commercial or non-commercial, and by any means.
-
-LZMA SDK code is compatible with open source licenses, for example, you can
-include it to GNU GPL or GNU LGPL code.
-
-
-LZMA SDK Contents
------------------
-
- Source code:
-
- - C / C++ / C# / Java - LZMA compression and decompression
- - C / C++ - LZMA2 compression and decompression
- - C / C++ - XZ compression and decompression
- - C - 7z decompression
- - C++ - 7z compression and decompression
- - C - small SFXs for installers (7z decompression)
- - C++ - SFXs and SFXs for installers (7z decompression)
-
- Precomiled binaries:
-
- - console programs for lzma / 7z / xz compression and decompression
- - SFX modules for installers.
-
-
-UNIX/Linux version
-------------------
-There are several otpions to compile 7-Zip with different compilers: gcc and clang.
-Also 7-Zip code contains two versions for some critical parts of code: in C and in Assembeler.
-So if you compile the version with Assembeler code, you will get faster 7-Zip binary.
-
-7-Zip's assembler code uses the following syntax for different platforms:
-
-1) x86 and x86-64 (AMD64): MASM syntax.
- There are 2 programs that supports MASM syntax in Linux.
-' 'Asmc Macro Assembler and JWasm. But JWasm now doesn't support some
- cpu instructions used in 7-Zip.
- So you must install Asmc Macro Assembler in Linux, if you want to compile fastest version
- of 7-Zip x86 and x86-64:
- https://github.com/nidud/asmc
-
-2) arm64: GNU assembler for ARM64 with preprocessor.
- That systax of that arm64 assembler code in 7-Zip is supported by GCC and CLANG for ARM64.
-
-There are different binaries that can be compiled from 7-Zip source.
-There are 2 main files in folder for compiling:
- makefile - that can be used for compiling Windows version of 7-Zip with nmake command
- makefile.gcc - that can be used for compiling Linux/macOS versions of 7-Zip with make command
-
-At first you must change the current folder to folder that contains `makefile.gcc`:
-
- cd CPP/7zip/Bundles/Alone7z
-
-Then you can compile `makefile.gcc` with the command:
-
- make -j -f makefile.gcc
-
-Also there are additional "*.mak" files in folder "CPP/7zip/" that can be used to compile
-7-Zip binaries with optimized code and optimzing options.
-
-To compile with GCC without assembler:
- cd CPP/7zip/Bundles/Alone7z
- make -j -f ../../cmpl_gcc.mak
-
-To compile with CLANG without assembler:
- make -j -f ../../cmpl_clang.mak
-
-To compile 7-Zip for x86-64 with asmc assembler:
- make -j -f ../../cmpl_gcc_x64.mak
-
-To compile 7-Zip for arm64 with assembler:
- make -j -f ../../cmpl_gcc_arm64.mak
-
-To compile 7-Zip for arm64 for macOS:
- make -j -f ../../cmpl_mac_arm64.mak
-
-Also you can change some compiler options in the mak files:
- cmpl_gcc.mak
- var_gcc.mak
- warn_gcc.mak
-
-
-
-Also you can use p7zip (port of 7-Zip for POSIX systems like Unix or Linux):
-
- http://p7zip.sourceforge.net/
-
-
-Files
------
-
-DOC/7zC.txt - 7z ANSI-C Decoder description
-DOC/7zFormat.txt - 7z Format description
-DOC/installer.txt - information about 7-Zip for installers
-DOC/lzma.txt - LZMA compression description
-DOC/lzma-sdk.txt - LZMA SDK description (this file)
-DOC/lzma-history.txt - history of LZMA SDK
-DOC/lzma-specification.txt - Specification of LZMA
-DOC/Methods.txt - Compression method IDs for .7z
-
-bin/installer/ - example script to create installer that uses SFX module,
-
-bin/7zdec.exe - simplified 7z archive decoder
-bin/7zr.exe - 7-Zip console program (reduced version)
-bin/x64/7zr.exe - 7-Zip console program (reduced version) (x64 version)
-bin/lzma.exe - file->file LZMA encoder/decoder for Windows
-bin/7zS2.sfx - small SFX module for installers (GUI version)
-bin/7zS2con.sfx - small SFX module for installers (Console version)
-bin/7zSD.sfx - SFX module for installers.
-
-
-7zDec.exe
----------
-7zDec.exe is simplified 7z archive decoder.
-It supports only LZMA, LZMA2, and PPMd methods.
-7zDec decodes whole solid block from 7z archive to RAM.
-The RAM consumption can be high.
-
-
-
-
-Source code structure
----------------------
-
-
-Asm/ - asm files (optimized code for CRC calculation and Intel-AES encryption)
-
-C/ - C files (compression / decompression and other)
- Util/
- 7z - 7z decoder program (decoding 7z files)
- Lzma - LZMA program (file->file LZMA encoder/decoder).
- LzmaLib - LZMA library (.DLL for Windows)
- SfxSetup - small SFX module for installers
-
-CPP/ -- CPP files
-
- Common - common files for C++ projects
- Windows - common files for Windows related code
-
- 7zip - files related to 7-Zip
-
- Archive - files related to archiving
-
- Common - common files for archive handling
- 7z - 7z C++ Encoder/Decoder
-
- Bundles - Modules that are bundles of other modules (files)
-
- Alone7z - 7zr.exe: Standalone 7-Zip console program (reduced version)
- Format7zExtractR - 7zxr.dll: Reduced version of 7z DLL: extracting from 7z/LZMA/BCJ/BCJ2.
- Format7zR - 7zr.dll: Reduced version of 7z DLL: extracting/compressing to 7z/LZMA/BCJ/BCJ2
- LzmaCon - lzma.exe: LZMA compression/decompression
- LzmaSpec - example code for LZMA Specification
- SFXCon - 7zCon.sfx: Console 7z SFX module
- SFXSetup - 7zS.sfx: 7z SFX module for installers
- SFXWin - 7z.sfx: GUI 7z SFX module
-
- Common - common files for 7-Zip
-
- Compress - files for compression/decompression
-
- Crypto - files for encryption / decompression
-
- UI - User Interface files
-
- Client7z - Test application for 7za.dll, 7zr.dll, 7zxr.dll
- Common - Common UI files
- Console - Code for console program (7z.exe)
- Explorer - Some code from 7-Zip Shell extension
- FileManager - Some GUI code from 7-Zip File Manager
- GUI - Some GUI code from 7-Zip
-
-
-CS/ - C# files
- 7zip
- Common - some common files for 7-Zip
- Compress - files related to compression/decompression
- LZ - files related to LZ (Lempel-Ziv) compression algorithm
- LZMA - LZMA compression/decompression
- LzmaAlone - file->file LZMA compression/decompression
- RangeCoder - Range Coder (special code of compression/decompression)
-
-Java/ - Java files
- SevenZip
- Compression - files related to compression/decompression
- LZ - files related to LZ (Lempel-Ziv) compression algorithm
- LZMA - LZMA compression/decompression
- RangeCoder - Range Coder (special code of compression/decompression)
-
-
-Note:
- Asm / C / C++ source code of LZMA SDK is part of 7-Zip's source code.
- 7-Zip's source code can be downloaded from 7-Zip's SourceForge page:
-
- http://sourceforge.net/projects/sevenzip/
-
-
-
-LZMA features
--------------
- - Variable dictionary size (up to 1 GB)
- - Estimated compressing speed: about 2 MB/s on 2 GHz CPU
- - Estimated decompressing speed:
- - 20-30 MB/s on modern 2 GHz cpu
- - 1-2 MB/s on 200 MHz simple RISC cpu: (ARM, MIPS, PowerPC)
- - Small memory requirements for decompressing (16 KB + DictionarySize)
- - Small code size for decompressing: 5-8 KB
-
-LZMA decoder uses only integer operations and can be
-implemented in any modern 32-bit CPU (or on 16-bit CPU with some conditions).
-
-Some critical operations that affect the speed of LZMA decompression:
- 1) 32*16 bit integer multiply
- 2) Mispredicted branches (penalty mostly depends from pipeline length)
- 3) 32-bit shift and arithmetic operations
-
-The speed of LZMA decompressing mostly depends from CPU speed.
-Memory speed has no big meaning. But if your CPU has small data cache,
-overall weight of memory speed will slightly increase.
-
-
-How To Use
-----------
-
-Using LZMA encoder/decoder executable
---------------------------------------
-
-Usage: LZMA inputFile outputFile [...]
-
- e: encode file
-
- d: decode file
-
- b: Benchmark. There are two tests: compressing and decompressing
- with LZMA method. Benchmark shows rating in MIPS (million
- instructions per second). Rating value is calculated from
- measured speed and it is normalized with Intel's Core 2 results.
- Also Benchmark checks possible hardware errors (RAM
- errors in most cases). Benchmark uses these settings:
- (-a1, -d21, -fb32, -mfbt4). You can change only -d parameter.
- Also you can change the number of iterations. Example for 30 iterations:
- LZMA b 30
- Default number of iterations is 10.
-
-
-
-
- -a{N}: set compression mode 0 = fast, 1 = normal
- default: 1 (normal)
-
- d{N}: Sets Dictionary size - [0, 30], default: 23 (8MB)
- The maximum value for dictionary size is 1 GB = 2^30 bytes.
- Dictionary size is calculated as DictionarySize = 2^N bytes.
- For decompressing file compressed by LZMA method with dictionary
- size D = 2^N you need about D bytes of memory (RAM).
-
- -fb{N}: set number of fast bytes - [5, 273], default: 128
- Usually big number gives a little bit better compression ratio
- and slower compression process.
-
- -lc{N}: set number of literal context bits - [0, 8], default: 3
- Sometimes lc=4 gives gain for big files.
-
- -lp{N}: set number of literal pos bits - [0, 4], default: 0
- lp switch is intended for periodical data when period is
- equal 2^N. For example, for 32-bit (4 bytes)
- periodical data you can use lp=2. Often it's better to set lc0,
- if you change lp switch.
-
- -pb{N}: set number of pos bits - [0, 4], default: 2
- pb switch is intended for periodical data
- when period is equal 2^N.
-
- -mf{MF_ID}: set Match Finder. Default: bt4.
- Algorithms from hc* group doesn't provide good compression
- ratio, but they often works pretty fast in combination with
- fast mode (-a0).
-
- Memory requirements depend from dictionary size
- (parameter "d" in table below).
-
- MF_ID Memory Description
-
- bt2 d * 9.5 + 4MB Binary Tree with 2 bytes hashing.
- bt3 d * 11.5 + 4MB Binary Tree with 3 bytes hashing.
- bt4 d * 11.5 + 4MB Binary Tree with 4 bytes hashing.
- hc4 d * 7.5 + 4MB Hash Chain with 4 bytes hashing.
-
- -eos: write End Of Stream marker. By default LZMA doesn't write
- eos marker, since LZMA decoder knows uncompressed size
- stored in .lzma file header.
-
- -si: Read data from stdin (it will write End Of Stream marker).
- -so: Write data to stdout
-
-
-Examples:
-
-1) LZMA e file.bin file.lzma -d16 -lc0
-
-compresses file.bin to file.lzma with 64 KB dictionary (2^16=64K)
-and 0 literal context bits. -lc0 allows to reduce memory requirements
-for decompression.
-
-
-2) LZMA e file.bin file.lzma -lc0 -lp2
-
-compresses file.bin to file.lzma with settings suitable
-for 32-bit periodical data (for example, ARM or MIPS code).
-
-3) LZMA d file.lzma file.bin
-
-decompresses file.lzma to file.bin.
-
-
-Compression ratio hints
------------------------
-
-Recommendations
----------------
-
-To increase the compression ratio for LZMA compressing it's desirable
-to have aligned data (if it's possible) and also it's desirable to locate
-data in such order, where code is grouped in one place and data is
-grouped in other place (it's better than such mixing: code, data, code,
-data, ...).
-
-
-Filters
--------
-You can increase the compression ratio for some data types, using
-special filters before compressing. For example, it's possible to
-increase the compression ratio on 5-10% for code for those CPU ISAs:
-x86, IA-64, ARM, ARM-Thumb, PowerPC, SPARC.
-
-You can find C source code of such filters in C/Bra*.* files
-
-You can check the compression ratio gain of these filters with such
-7-Zip commands (example for ARM code):
-No filter:
- 7z a a1.7z a.bin -m0=lzma
-
-With filter for little-endian ARM code:
- 7z a a2.7z a.bin -m0=arm -m1=lzma
-
-It works in such manner:
-Compressing = Filter_encoding + LZMA_encoding
-Decompressing = LZMA_decoding + Filter_decoding
-
-Compressing and decompressing speed of such filters is very high,
-so it will not increase decompressing time too much.
-Moreover, it reduces decompression time for LZMA_decoding,
-since compression ratio with filtering is higher.
-
-These filters convert CALL (calling procedure) instructions
-from relative offsets to absolute addresses, so such data becomes more
-compressible.
-
-For some ISAs (for example, for MIPS) it's impossible to get gain from such filter.
-
-
-
----
-
-http://www.7-zip.org
-http://www.7-zip.org/sdk.html
-http://www.7-zip.org/support.html
diff --git a/deps/libchdr/deps/lzma-22.01/lzma-specification.txt b/deps/libchdr/deps/lzma-22.01/lzma-specification.txt
deleted file mode 100644
index b6796df7..00000000
--- a/deps/libchdr/deps/lzma-22.01/lzma-specification.txt
+++ /dev/null
@@ -1,1176 +0,0 @@
-LZMA specification (DRAFT version)
-----------------------------------
-
-Author: Igor Pavlov
-Date: 2015-06-14
-
-This specification defines the format of LZMA compressed data and lzma file format.
-
-Notation
---------
-
-We use the syntax of C++ programming language.
-We use the following types in C++ code:
- unsigned - unsigned integer, at least 16 bits in size
- int - signed integer, at least 16 bits in size
- UInt64 - 64-bit unsigned integer
- UInt32 - 32-bit unsigned integer
- UInt16 - 16-bit unsigned integer
- Byte - 8-bit unsigned integer
- bool - boolean type with two possible values: false, true
-
-
-lzma file format
-================
-
-The lzma file contains the raw LZMA stream and the header with related properties.
-
-The files in that format use ".lzma" extension.
-
-The lzma file format layout:
-
-Offset Size Description
-
- 0 1 LZMA model properties (lc, lp, pb) in encoded form
- 1 4 Dictionary size (32-bit unsigned integer, little-endian)
- 5 8 Uncompressed size (64-bit unsigned integer, little-endian)
- 13 Compressed data (LZMA stream)
-
-LZMA properties:
-
- name Range Description
-
- lc [0, 8] the number of "literal context" bits
- lp [0, 4] the number of "literal pos" bits
- pb [0, 4] the number of "pos" bits
-dictSize [0, 2^32 - 1] the dictionary size
-
-The following code encodes LZMA properties:
-
-void EncodeProperties(Byte *properties)
-{
- properties[0] = (Byte)((pb * 5 + lp) * 9 + lc);
- Set_UInt32_LittleEndian(properties + 1, dictSize);
-}
-
-If the value of dictionary size in properties is smaller than (1 << 12),
-the LZMA decoder must set the dictionary size variable to (1 << 12).
-
-#define LZMA_DIC_MIN (1 << 12)
-
- unsigned lc, pb, lp;
- UInt32 dictSize;
- UInt32 dictSizeInProperties;
-
- void DecodeProperties(const Byte *properties)
- {
- unsigned d = properties[0];
- if (d >= (9 * 5 * 5))
- throw "Incorrect LZMA properties";
- lc = d % 9;
- d /= 9;
- pb = d / 5;
- lp = d % 5;
- dictSizeInProperties = 0;
- for (int i = 0; i < 4; i++)
- dictSizeInProperties |= (UInt32)properties[i + 1] << (8 * i);
- dictSize = dictSizeInProperties;
- if (dictSize < LZMA_DIC_MIN)
- dictSize = LZMA_DIC_MIN;
- }
-
-If "Uncompressed size" field contains ones in all 64 bits, it means that
-uncompressed size is unknown and there is the "end marker" in stream,
-that indicates the end of decoding point.
-In opposite case, if the value from "Uncompressed size" field is not
-equal to ((2^64) - 1), the LZMA stream decoding must be finished after
-specified number of bytes (Uncompressed size) is decoded. And if there
-is the "end marker", the LZMA decoder must read that marker also.
-
-
-The new scheme to encode LZMA properties
-----------------------------------------
-
-If LZMA compression is used for some another format, it's recommended to
-use a new improved scheme to encode LZMA properties. That new scheme was
-used in xz format that uses the LZMA2 compression algorithm.
-The LZMA2 is a new compression algorithm that is based on the LZMA algorithm.
-
-The dictionary size in LZMA2 is encoded with just one byte and LZMA2 supports
-only reduced set of dictionary sizes:
- (2 << 11), (3 << 11),
- (2 << 12), (3 << 12),
- ...
- (2 << 30), (3 << 30),
- (2 << 31) - 1
-
-The dictionary size can be extracted from encoded value with the following code:
-
- dictSize = (p == 40) ? 0xFFFFFFFF : (((UInt32)2 | ((p) & 1)) << ((p) / 2 + 11));
-
-Also there is additional limitation (lc + lp <= 4) in LZMA2 for values of
-"lc" and "lp" properties:
-
- if (lc + lp > 4)
- throw "Unsupported properties: (lc + lp) > 4";
-
-There are some advantages for LZMA decoder with such (lc + lp) value
-limitation. It reduces the maximum size of tables allocated by decoder.
-And it reduces the complexity of initialization procedure, that can be
-important to keep high speed of decoding of big number of small LZMA streams.
-
-It's recommended to use that limitation (lc + lp <= 4) for any new format
-that uses LZMA compression. Note that the combinations of "lc" and "lp"
-parameters, where (lc + lp > 4), can provide significant improvement in
-compression ratio only in some rare cases.
-
-The LZMA properties can be encoded into two bytes in new scheme:
-
-Offset Size Description
-
- 0 1 The dictionary size encoded with LZMA2 scheme
- 1 1 LZMA model properties (lc, lp, pb) in encoded form
-
-
-The RAM usage
-=============
-
-The RAM usage for LZMA decoder is determined by the following parts:
-
-1) The Sliding Window (from 4 KiB to 4 GiB).
-2) The probability model counter arrays (arrays of 16-bit variables).
-3) Some additional state variables (about 10 variables of 32-bit integers).
-
-
-The RAM usage for Sliding Window
---------------------------------
-
-There are two main scenarios of decoding:
-
-1) The decoding of full stream to one RAM buffer.
-
- If we decode full LZMA stream to one output buffer in RAM, the decoder
- can use that output buffer as sliding window. So the decoder doesn't
- need additional buffer allocated for sliding window.
-
-2) The decoding to some external storage.
-
- If we decode LZMA stream to external storage, the decoder must allocate
- the buffer for sliding window. The size of that buffer must be equal
- or larger than the value of dictionary size from properties of LZMA stream.
-
-In this specification we describe the code for decoding to some external
-storage. The optimized version of code for decoding of full stream to one
-output RAM buffer can require some minor changes in code.
-
-
-The RAM usage for the probability model counters
-------------------------------------------------
-
-The size of the probability model counter arrays is calculated with the
-following formula:
-
-size_of_prob_arrays = 1846 + 768 * (1 << (lp + lc))
-
-Each probability model counter is 11-bit unsigned integer.
-If we use 16-bit integer variables (2-byte integers) for these probability
-model counters, the RAM usage required by probability model counter arrays
-can be estimated with the following formula:
-
- RAM = 4 KiB + 1.5 KiB * (1 << (lp + lc))
-
-For example, for default LZMA parameters (lp = 0 and lc = 3), the RAM usage is
-
- RAM_lc3_lp0 = 4 KiB + 1.5 KiB * 8 = 16 KiB
-
-The maximum RAM state usage is required for decoding the stream with lp = 4
-and lc = 8:
-
- RAM_lc8_lp4 = 4 KiB + 1.5 KiB * 4096 = 6148 KiB
-
-If the decoder uses LZMA2's limited property condition
-(lc + lp <= 4), the RAM usage will be not larger than
-
- RAM_lc_lp_4 = 4 KiB + 1.5 KiB * 16 = 28 KiB
-
-
-The RAM usage for encoder
--------------------------
-
-There are many variants for LZMA encoding code.
-These variants have different values for memory consumption.
-Note that memory consumption for LZMA Encoder can not be
-smaller than memory consumption of LZMA Decoder for same stream.
-
-The RAM usage required by modern effective implementation of
-LZMA Encoder can be estimated with the following formula:
-
- Encoder_RAM_Usage = 4 MiB + 11 * dictionarySize.
-
-But there are some modes of the encoder that require less memory.
-
-
-LZMA Decoding
-=============
-
-The LZMA compression algorithm uses LZ-based compression with Sliding Window
-and Range Encoding as entropy coding method.
-
-
-Sliding Window
---------------
-
-LZMA uses Sliding Window compression similar to LZ77 algorithm.
-
-LZMA stream must be decoded to the sequence that consists
-of MATCHES and LITERALS:
-
- - a LITERAL is a 8-bit character (one byte).
- The decoder just puts that LITERAL to the uncompressed stream.
-
- - a MATCH is a pair of two numbers (DISTANCE-LENGTH pair).
- The decoder takes one byte exactly "DISTANCE" characters behind
- current position in the uncompressed stream and puts it to
- uncompressed stream. The decoder must repeat it "LENGTH" times.
-
-The "DISTANCE" can not be larger than dictionary size.
-And the "DISTANCE" can not be larger than the number of bytes in
-the uncompressed stream that were decoded before that match.
-
-In this specification we use cyclic buffer to implement Sliding Window
-for LZMA decoder:
-
-class COutWindow
-{
- Byte *Buf;
- UInt32 Pos;
- UInt32 Size;
- bool IsFull;
-
-public:
- unsigned TotalPos;
- COutStream OutStream;
-
- COutWindow(): Buf(NULL) {}
- ~COutWindow() { delete []Buf; }
-
- void Create(UInt32 dictSize)
- {
- Buf = new Byte[dictSize];
- Pos = 0;
- Size = dictSize;
- IsFull = false;
- TotalPos = 0;
- }
-
- void PutByte(Byte b)
- {
- TotalPos++;
- Buf[Pos++] = b;
- if (Pos == Size)
- {
- Pos = 0;
- IsFull = true;
- }
- OutStream.WriteByte(b);
- }
-
- Byte GetByte(UInt32 dist) const
- {
- return Buf[dist <= Pos ? Pos - dist : Size - dist + Pos];
- }
-
- void CopyMatch(UInt32 dist, unsigned len)
- {
- for (; len > 0; len--)
- PutByte(GetByte(dist));
- }
-
- bool CheckDistance(UInt32 dist) const
- {
- return dist <= Pos || IsFull;
- }
-
- bool IsEmpty() const
- {
- return Pos == 0 && !IsFull;
- }
-};
-
-
-In another implementation it's possible to use one buffer that contains
-Sliding Window and the whole data stream after uncompressing.
-
-
-Range Decoder
--------------
-
-LZMA algorithm uses Range Encoding (1) as entropy coding method.
-
-LZMA stream contains just one very big number in big-endian encoding.
-LZMA decoder uses the Range Decoder to extract a sequence of binary
-symbols from that big number.
-
-The state of the Range Decoder:
-
-struct CRangeDecoder
-{
- UInt32 Range;
- UInt32 Code;
- InputStream *InStream;
-
- bool Corrupted;
-}
-
-The notes about UInt32 type for the "Range" and "Code" variables:
-
- It's possible to use 64-bit (unsigned or signed) integer type
- for the "Range" and the "Code" variables instead of 32-bit unsigned,
- but some additional code must be used to truncate the values to
- low 32-bits after some operations.
-
- If the programming language does not support 32-bit unsigned integer type
- (like in case of JAVA language), it's possible to use 32-bit signed integer,
- but some code must be changed. For example, it's required to change the code
- that uses comparison operations for UInt32 variables in this specification.
-
-The Range Decoder can be in some states that can be treated as
-"Corruption" in LZMA stream. The Range Decoder uses the variable "Corrupted":
-
- (Corrupted == false), if the Range Decoder has not detected any corruption.
- (Corrupted == true), if the Range Decoder has detected some corruption.
-
-The reference LZMA Decoder ignores the value of the "Corrupted" variable.
-So it continues to decode the stream, even if the corruption can be detected
-in the Range Decoder. To provide the full compatibility with output of the
-reference LZMA Decoder, another LZMA Decoder implementations must also
-ignore the value of the "Corrupted" variable.
-
-The LZMA Encoder is required to create only such LZMA streams, that will not
-lead the Range Decoder to states, where the "Corrupted" variable is set to true.
-
-The Range Decoder reads first 5 bytes from input stream to initialize
-the state:
-
-bool CRangeDecoder::Init()
-{
- Corrupted = false;
- Range = 0xFFFFFFFF;
- Code = 0;
-
- Byte b = InStream->ReadByte();
-
- for (int i = 0; i < 4; i++)
- Code = (Code << 8) | InStream->ReadByte();
-
- if (b != 0 || Code == Range)
- Corrupted = true;
- return b == 0;
-}
-
-The LZMA Encoder always writes ZERO in initial byte of compressed stream.
-That scheme allows to simplify the code of the Range Encoder in the
-LZMA Encoder. If initial byte is not equal to ZERO, the LZMA Decoder must
-stop decoding and report error.
-
-After the last bit of data was decoded by Range Decoder, the value of the
-"Code" variable must be equal to 0. The LZMA Decoder must check it by
-calling the IsFinishedOK() function:
-
- bool IsFinishedOK() const { return Code == 0; }
-
-If there is corruption in data stream, there is big probability that
-the "Code" value will be not equal to 0 in the Finish() function. So that
-check in the IsFinishedOK() function provides very good feature for
-corruption detection.
-
-The value of the "Range" variable before each bit decoding can not be smaller
-than ((UInt32)1 << 24). The Normalize() function keeps the "Range" value in
-described range.
-
-#define kTopValue ((UInt32)1 << 24)
-
-void CRangeDecoder::Normalize()
-{
- if (Range < kTopValue)
- {
- Range <<= 8;
- Code = (Code << 8) | InStream->ReadByte();
- }
-}
-
-Notes: if the size of the "Code" variable is larger than 32 bits, it's
-required to keep only low 32 bits of the "Code" variable after the change
-in Normalize() function.
-
-If the LZMA Stream is not corrupted, the value of the "Code" variable is
-always smaller than value of the "Range" variable.
-But the Range Decoder ignores some types of corruptions, so the value of
-the "Code" variable can be equal or larger than value of the "Range" variable
-for some "Corrupted" archives.
-
-
-LZMA uses Range Encoding only with binary symbols of two types:
- 1) binary symbols with fixed and equal probabilities (direct bits)
- 2) binary symbols with predicted probabilities
-
-The DecodeDirectBits() function decodes the sequence of direct bits:
-
-UInt32 CRangeDecoder::DecodeDirectBits(unsigned numBits)
-{
- UInt32 res = 0;
- do
- {
- Range >>= 1;
- Code -= Range;
- UInt32 t = 0 - ((UInt32)Code >> 31);
- Code += Range & t;
-
- if (Code == Range)
- Corrupted = true;
-
- Normalize();
- res <<= 1;
- res += t + 1;
- }
- while (--numBits);
- return res;
-}
-
-
-The Bit Decoding with Probability Model
----------------------------------------
-
-The task of Bit Probability Model is to estimate probabilities of binary
-symbols. And then it provides the Range Decoder with that information.
-The better prediction provides better compression ratio.
-The Bit Probability Model uses statistical data of previous decoded
-symbols.
-
-That estimated probability is presented as 11-bit unsigned integer value
-that represents the probability of symbol "0".
-
-#define kNumBitModelTotalBits 11
-
-Mathematical probabilities can be presented with the following formulas:
- probability(symbol_0) = prob / 2048.
- probability(symbol_1) = 1 - Probability(symbol_0) =
- = 1 - prob / 2048 =
- = (2048 - prob) / 2048
-where the "prob" variable contains 11-bit integer probability counter.
-
-It's recommended to use 16-bit unsigned integer type, to store these 11-bit
-probability values:
-
-typedef UInt16 CProb;
-
-Each probability value must be initialized with value ((1 << 11) / 2),
-that represents the state, where probabilities of symbols 0 and 1
-are equal to 0.5:
-
-#define PROB_INIT_VAL ((1 << kNumBitModelTotalBits) / 2)
-
-The INIT_PROBS macro is used to initialize the array of CProb variables:
-
-#define INIT_PROBS(p) \
- { for (unsigned i = 0; i < sizeof(p) / sizeof(p[0]); i++) p[i] = PROB_INIT_VAL; }
-
-
-The DecodeBit() function decodes one bit.
-The LZMA decoder provides the pointer to CProb variable that contains
-information about estimated probability for symbol 0 and the Range Decoder
-updates that CProb variable after decoding. The Range Decoder increases
-estimated probability of the symbol that was decoded:
-
-#define kNumMoveBits 5
-
-unsigned CRangeDecoder::DecodeBit(CProb *prob)
-{
- unsigned v = *prob;
- UInt32 bound = (Range >> kNumBitModelTotalBits) * v;
- unsigned symbol;
- if (Code < bound)
- {
- v += ((1 << kNumBitModelTotalBits) - v) >> kNumMoveBits;
- Range = bound;
- symbol = 0;
- }
- else
- {
- v -= v >> kNumMoveBits;
- Code -= bound;
- Range -= bound;
- symbol = 1;
- }
- *prob = (CProb)v;
- Normalize();
- return symbol;
-}
-
-
-The Binary Tree of bit model counters
--------------------------------------
-
-LZMA uses a tree of Bit model variables to decode symbol that needs
-several bits for storing. There are two versions of such trees in LZMA:
- 1) the tree that decodes bits from high bit to low bit (the normal scheme).
- 2) the tree that decodes bits from low bit to high bit (the reverse scheme).
-
-Each binary tree structure supports different size of decoded symbol
-(the size of binary sequence that contains value of symbol).
-If that size of decoded symbol is "NumBits" bits, the tree structure
-uses the array of (2 << NumBits) counters of CProb type.
-But only ((2 << NumBits) - 1) items are used by encoder and decoder.
-The first item (the item with index equal to 0) in array is unused.
-That scheme with unused array's item allows to simplify the code.
-
-unsigned BitTreeReverseDecode(CProb *probs, unsigned numBits, CRangeDecoder *rc)
-{
- unsigned m = 1;
- unsigned symbol = 0;
- for (unsigned i = 0; i < numBits; i++)
- {
- unsigned bit = rc->DecodeBit(&probs[m]);
- m <<= 1;
- m += bit;
- symbol |= (bit << i);
- }
- return symbol;
-}
-
-template
-class CBitTreeDecoder
-{
- CProb Probs[(unsigned)1 << NumBits];
-
-public:
-
- void Init()
- {
- INIT_PROBS(Probs);
- }
-
- unsigned Decode(CRangeDecoder *rc)
- {
- unsigned m = 1;
- for (unsigned i = 0; i < NumBits; i++)
- m = (m << 1) + rc->DecodeBit(&Probs[m]);
- return m - ((unsigned)1 << NumBits);
- }
-
- unsigned ReverseDecode(CRangeDecoder *rc)
- {
- return BitTreeReverseDecode(Probs, NumBits, rc);
- }
-};
-
-
-LZ part of LZMA
----------------
-
-LZ part of LZMA describes details about the decoding of MATCHES and LITERALS.
-
-
-The Literal Decoding
---------------------
-
-The LZMA Decoder uses (1 << (lc + lp)) tables with CProb values, where
-each table contains 0x300 CProb values:
-
- CProb *LitProbs;
-
- void CreateLiterals()
- {
- LitProbs = new CProb[(UInt32)0x300 << (lc + lp)];
- }
-
- void InitLiterals()
- {
- UInt32 num = (UInt32)0x300 << (lc + lp);
- for (UInt32 i = 0; i < num; i++)
- LitProbs[i] = PROB_INIT_VAL;
- }
-
-To select the table for decoding it uses the context that consists of
-(lc) high bits from previous literal and (lp) low bits from value that
-represents current position in outputStream.
-
-If (State > 7), the Literal Decoder also uses "matchByte" that represents
-the byte in OutputStream at position the is the DISTANCE bytes before
-current position, where the DISTANCE is the distance in DISTANCE-LENGTH pair
-of latest decoded match.
-
-The following code decodes one literal and puts it to Sliding Window buffer:
-
- void DecodeLiteral(unsigned state, UInt32 rep0)
- {
- unsigned prevByte = 0;
- if (!OutWindow.IsEmpty())
- prevByte = OutWindow.GetByte(1);
-
- unsigned symbol = 1;
- unsigned litState = ((OutWindow.TotalPos & ((1 << lp) - 1)) << lc) + (prevByte >> (8 - lc));
- CProb *probs = &LitProbs[(UInt32)0x300 * litState];
-
- if (state >= 7)
- {
- unsigned matchByte = OutWindow.GetByte(rep0 + 1);
- do
- {
- unsigned matchBit = (matchByte >> 7) & 1;
- matchByte <<= 1;
- unsigned bit = RangeDec.DecodeBit(&probs[((1 + matchBit) << 8) + symbol]);
- symbol = (symbol << 1) | bit;
- if (matchBit != bit)
- break;
- }
- while (symbol < 0x100);
- }
- while (symbol < 0x100)
- symbol = (symbol << 1) | RangeDec.DecodeBit(&probs[symbol]);
- OutWindow.PutByte((Byte)(symbol - 0x100));
- }
-
-
-The match length decoding
--------------------------
-
-The match length decoder returns normalized (zero-based value)
-length of match. That value can be converted to real length of the match
-with the following code:
-
-#define kMatchMinLen 2
-
- matchLen = len + kMatchMinLen;
-
-The match length decoder can return the values from 0 to 271.
-And the corresponded real match length values can be in the range
-from 2 to 273.
-
-The following scheme is used for the match length encoding:
-
- Binary encoding Binary Tree structure Zero-based match length
- sequence (binary + decimal):
-
- 0 xxx LowCoder[posState] xxx
- 1 0 yyy MidCoder[posState] yyy + 8
- 1 1 zzzzzzzz HighCoder zzzzzzzz + 16
-
-LZMA uses bit model variable "Choice" to decode the first selection bit.
-
-If the first selection bit is equal to 0, the decoder uses binary tree
- LowCoder[posState] to decode 3-bit zero-based match length (xxx).
-
-If the first selection bit is equal to 1, the decoder uses bit model
- variable "Choice2" to decode the second selection bit.
-
- If the second selection bit is equal to 0, the decoder uses binary tree
- MidCoder[posState] to decode 3-bit "yyy" value, and zero-based match
- length is equal to (yyy + 8).
-
- If the second selection bit is equal to 1, the decoder uses binary tree
- HighCoder to decode 8-bit "zzzzzzzz" value, and zero-based
- match length is equal to (zzzzzzzz + 16).
-
-LZMA uses "posState" value as context to select the binary tree
-from LowCoder and MidCoder binary tree arrays:
-
- unsigned posState = OutWindow.TotalPos & ((1 << pb) - 1);
-
-The full code of the length decoder:
-
-class CLenDecoder
-{
- CProb Choice;
- CProb Choice2;
- CBitTreeDecoder<3> LowCoder[1 << kNumPosBitsMax];
- CBitTreeDecoder<3> MidCoder[1 << kNumPosBitsMax];
- CBitTreeDecoder<8> HighCoder;
-
-public:
-
- void Init()
- {
- Choice = PROB_INIT_VAL;
- Choice2 = PROB_INIT_VAL;
- HighCoder.Init();
- for (unsigned i = 0; i < (1 << kNumPosBitsMax); i++)
- {
- LowCoder[i].Init();
- MidCoder[i].Init();
- }
- }
-
- unsigned Decode(CRangeDecoder *rc, unsigned posState)
- {
- if (rc->DecodeBit(&Choice) == 0)
- return LowCoder[posState].Decode(rc);
- if (rc->DecodeBit(&Choice2) == 0)
- return 8 + MidCoder[posState].Decode(rc);
- return 16 + HighCoder.Decode(rc);
- }
-};
-
-The LZMA decoder uses two instances of CLenDecoder class.
-The first instance is for the matches of "Simple Match" type,
-and the second instance is for the matches of "Rep Match" type:
-
- CLenDecoder LenDecoder;
- CLenDecoder RepLenDecoder;
-
-
-The match distance decoding
----------------------------
-
-LZMA supports dictionary sizes up to 4 GiB minus 1.
-The value of match distance (decoded by distance decoder) can be
-from 1 to 2^32. But the distance value that is equal to 2^32 is used to
-indicate the "End of stream" marker. So real largest match distance
-that is used for LZ-window match is (2^32 - 1).
-
-LZMA uses normalized match length (zero-based length)
-to calculate the context state "lenState" do decode the distance value:
-
-#define kNumLenToPosStates 4
-
- unsigned lenState = len;
- if (lenState > kNumLenToPosStates - 1)
- lenState = kNumLenToPosStates - 1;
-
-The distance decoder returns the "dist" value that is zero-based value
-of match distance. The real match distance can be calculated with the
-following code:
-
- matchDistance = dist + 1;
-
-The state of the distance decoder and the initialization code:
-
- #define kEndPosModelIndex 14
- #define kNumFullDistances (1 << (kEndPosModelIndex >> 1))
- #define kNumAlignBits 4
-
- CBitTreeDecoder<6> PosSlotDecoder[kNumLenToPosStates];
- CProb PosDecoders[1 + kNumFullDistances - kEndPosModelIndex];
- CBitTreeDecoder AlignDecoder;
-
- void InitDist()
- {
- for (unsigned i = 0; i < kNumLenToPosStates; i++)
- PosSlotDecoder[i].Init();
- AlignDecoder.Init();
- INIT_PROBS(PosDecoders);
- }
-
-At first stage the distance decoder decodes 6-bit "posSlot" value with bit
-tree decoder from PosSlotDecoder array. It's possible to get 2^6=64 different
-"posSlot" values.
-
- unsigned posSlot = PosSlotDecoder[lenState].Decode(&RangeDec);
-
-The encoding scheme for distance value is shown in the following table:
-
-posSlot (decimal) /
- zero-based distance (binary)
- 0 0
- 1 1
- 2 10
- 3 11
-
- 4 10 x
- 5 11 x
- 6 10 xx
- 7 11 xx
- 8 10 xxx
- 9 11 xxx
-10 10 xxxx
-11 11 xxxx
-12 10 xxxxx
-13 11 xxxxx
-
-14 10 yy zzzz
-15 11 yy zzzz
-16 10 yyy zzzz
-17 11 yyy zzzz
-...
-62 10 yyyyyyyyyyyyyyyyyyyyyyyyyy zzzz
-63 11 yyyyyyyyyyyyyyyyyyyyyyyyyy zzzz
-
-where
- "x ... x" means the sequence of binary symbols encoded with binary tree and
- "Reverse" scheme. It uses separated binary tree for each posSlot from 4 to 13.
- "y" means direct bit encoded with range coder.
- "zzzz" means the sequence of four binary symbols encoded with binary
- tree with "Reverse" scheme, where one common binary tree "AlignDecoder"
- is used for all posSlot values.
-
-If (posSlot < 4), the "dist" value is equal to posSlot value.
-
-If (posSlot >= 4), the decoder uses "posSlot" value to calculate the value of
- the high bits of "dist" value and the number of the low bits.
-
- If (4 <= posSlot < kEndPosModelIndex), the decoder uses bit tree decoders.
- (one separated bit tree decoder per one posSlot value) and "Reverse" scheme.
- In this implementation we use one CProb array "PosDecoders" that contains
- all CProb variables for all these bit decoders.
-
- if (posSlot >= kEndPosModelIndex), the middle bits are decoded as direct
- bits from RangeDecoder and the low 4 bits are decoded with a bit tree
- decoder "AlignDecoder" with "Reverse" scheme.
-
-The code to decode zero-based match distance:
-
- unsigned DecodeDistance(unsigned len)
- {
- unsigned lenState = len;
- if (lenState > kNumLenToPosStates - 1)
- lenState = kNumLenToPosStates - 1;
-
- unsigned posSlot = PosSlotDecoder[lenState].Decode(&RangeDec);
- if (posSlot < 4)
- return posSlot;
-
- unsigned numDirectBits = (unsigned)((posSlot >> 1) - 1);
- UInt32 dist = ((2 | (posSlot & 1)) << numDirectBits);
- if (posSlot < kEndPosModelIndex)
- dist += BitTreeReverseDecode(PosDecoders + dist - posSlot, numDirectBits, &RangeDec);
- else
- {
- dist += RangeDec.DecodeDirectBits(numDirectBits - kNumAlignBits) << kNumAlignBits;
- dist += AlignDecoder.ReverseDecode(&RangeDec);
- }
- return dist;
- }
-
-
-
-LZMA Decoding modes
--------------------
-
-There are 2 types of LZMA streams:
-
-1) The stream with "End of stream" marker.
-2) The stream without "End of stream" marker.
-
-And the LZMA Decoder supports 3 modes of decoding:
-
-1) The unpack size is undefined. The LZMA decoder stops decoding after
- getting "End of stream" marker.
- The input variables for that case:
-
- markerIsMandatory = true
- unpackSizeDefined = false
- unpackSize contains any value
-
-2) The unpack size is defined and LZMA decoder supports both variants,
- where the stream can contain "End of stream" marker or the stream is
- finished without "End of stream" marker. The LZMA decoder must detect
- any of these situations.
- The input variables for that case:
-
- markerIsMandatory = false
- unpackSizeDefined = true
- unpackSize contains unpack size
-
-3) The unpack size is defined and the LZMA stream must contain
- "End of stream" marker
- The input variables for that case:
-
- markerIsMandatory = true
- unpackSizeDefined = true
- unpackSize contains unpack size
-
-
-The main loop of decoder
-------------------------
-
-The main loop of LZMA decoder:
-
-Initialize the LZMA state.
-loop
-{
- // begin of loop
- Check "end of stream" conditions.
- Decode Type of MATCH / LITERAL.
- If it's LITERAL, decode LITERAL value and put the LITERAL to Window.
- If it's MATCH, decode the length of match and the match distance.
- Check error conditions, check end of stream conditions and copy
- the sequence of match bytes from sliding window to current position
- in window.
- Go to begin of loop
-}
-
-The reference implementation of LZMA decoder uses "unpackSize" variable
-to keep the number of remaining bytes in output stream. So it reduces
-"unpackSize" value after each decoded LITERAL or MATCH.
-
-The following code contains the "end of stream" condition check at the start
-of the loop:
-
- if (unpackSizeDefined && unpackSize == 0 && !markerIsMandatory)
- if (RangeDec.IsFinishedOK())
- return LZMA_RES_FINISHED_WITHOUT_MARKER;
-
-LZMA uses three types of matches:
-
-1) "Simple Match" - the match with distance value encoded with bit models.
-
-2) "Rep Match" - the match that uses the distance from distance
- history table.
-
-3) "Short Rep Match" - the match of single byte length, that uses the latest
- distance from distance history table.
-
-The LZMA decoder keeps the history of latest 4 match distances that were used
-by decoder. That set of 4 variables contains zero-based match distances and
-these variables are initialized with zero values:
-
- UInt32 rep0 = 0, rep1 = 0, rep2 = 0, rep3 = 0;
-
-The LZMA decoder uses binary model variables to select type of MATCH or LITERAL:
-
-#define kNumStates 12
-#define kNumPosBitsMax 4
-
- CProb IsMatch[kNumStates << kNumPosBitsMax];
- CProb IsRep[kNumStates];
- CProb IsRepG0[kNumStates];
- CProb IsRepG1[kNumStates];
- CProb IsRepG2[kNumStates];
- CProb IsRep0Long[kNumStates << kNumPosBitsMax];
-
-The decoder uses "state" variable value to select exact variable
-from "IsRep", "IsRepG0", "IsRepG1" and "IsRepG2" arrays.
-The "state" variable can get the value from 0 to 11.
-Initial value for "state" variable is zero:
-
- unsigned state = 0;
-
-The "state" variable is updated after each LITERAL or MATCH with one of the
-following functions:
-
-unsigned UpdateState_Literal(unsigned state)
-{
- if (state < 4) return 0;
- else if (state < 10) return state - 3;
- else return state - 6;
-}
-unsigned UpdateState_Match (unsigned state) { return state < 7 ? 7 : 10; }
-unsigned UpdateState_Rep (unsigned state) { return state < 7 ? 8 : 11; }
-unsigned UpdateState_ShortRep(unsigned state) { return state < 7 ? 9 : 11; }
-
-The decoder calculates "state2" variable value to select exact variable from
-"IsMatch" and "IsRep0Long" arrays:
-
-unsigned posState = OutWindow.TotalPos & ((1 << pb) - 1);
-unsigned state2 = (state << kNumPosBitsMax) + posState;
-
-The decoder uses the following code flow scheme to select exact
-type of LITERAL or MATCH:
-
-IsMatch[state2] decode
- 0 - the Literal
- 1 - the Match
- IsRep[state] decode
- 0 - Simple Match
- 1 - Rep Match
- IsRepG0[state] decode
- 0 - the distance is rep0
- IsRep0Long[state2] decode
- 0 - Short Rep Match
- 1 - Rep Match 0
- 1 -
- IsRepG1[state] decode
- 0 - Rep Match 1
- 1 -
- IsRepG2[state] decode
- 0 - Rep Match 2
- 1 - Rep Match 3
-
-
-LITERAL symbol
---------------
-If the value "0" was decoded with IsMatch[state2] decoding, we have "LITERAL" type.
-
-At first the LZMA decoder must check that it doesn't exceed
-specified uncompressed size:
-
- if (unpackSizeDefined && unpackSize == 0)
- return LZMA_RES_ERROR;
-
-Then it decodes literal value and puts it to sliding window:
-
- DecodeLiteral(state, rep0);
-
-Then the decoder must update the "state" value and "unpackSize" value;
-
- state = UpdateState_Literal(state);
- unpackSize--;
-
-Then the decoder must go to the begin of main loop to decode next Match or Literal.
-
-
-Simple Match
-------------
-
-If the value "1" was decoded with IsMatch[state2] decoding,
-we have the "Simple Match" type.
-
-The distance history table is updated with the following scheme:
-
- rep3 = rep2;
- rep2 = rep1;
- rep1 = rep0;
-
-The zero-based length is decoded with "LenDecoder":
-
- len = LenDecoder.Decode(&RangeDec, posState);
-
-The state is update with UpdateState_Match function:
-
- state = UpdateState_Match(state);
-
-and the new "rep0" value is decoded with DecodeDistance:
-
- rep0 = DecodeDistance(len);
-
-That "rep0" will be used as zero-based distance for current match.
-
-If the value of "rep0" is equal to 0xFFFFFFFF, it means that we have
-"End of stream" marker, so we can stop decoding and check finishing
-condition in Range Decoder:
-
- if (rep0 == 0xFFFFFFFF)
- return RangeDec.IsFinishedOK() ?
- LZMA_RES_FINISHED_WITH_MARKER :
- LZMA_RES_ERROR;
-
-If uncompressed size is defined, LZMA decoder must check that it doesn't
-exceed that specified uncompressed size:
-
- if (unpackSizeDefined && unpackSize == 0)
- return LZMA_RES_ERROR;
-
-Also the decoder must check that "rep0" value is not larger than dictionary size
-and is not larger than the number of already decoded bytes:
-
- if (rep0 >= dictSize || !OutWindow.CheckDistance(rep0))
- return LZMA_RES_ERROR;
-
-Then the decoder must copy match bytes as described in
-"The match symbols copying" section.
-
-
-Rep Match
----------
-
-If the LZMA decoder has decoded the value "1" with IsRep[state] variable,
-we have "Rep Match" type.
-
-At first the LZMA decoder must check that it doesn't exceed
-specified uncompressed size:
-
- if (unpackSizeDefined && unpackSize == 0)
- return LZMA_RES_ERROR;
-
-Also the decoder must return error, if the LZ window is empty:
-
- if (OutWindow.IsEmpty())
- return LZMA_RES_ERROR;
-
-If the match type is "Rep Match", the decoder uses one of the 4 variables of
-distance history table to get the value of distance for current match.
-And there are 4 corresponding ways of decoding flow.
-
-The decoder updates the distance history with the following scheme
-depending from type of match:
-
-- "Rep Match 0" or "Short Rep Match":
- ; LZMA doesn't update the distance history
-
-- "Rep Match 1":
- UInt32 dist = rep1;
- rep1 = rep0;
- rep0 = dist;
-
-- "Rep Match 2":
- UInt32 dist = rep2;
- rep2 = rep1;
- rep1 = rep0;
- rep0 = dist;
-
-- "Rep Match 3":
- UInt32 dist = rep3;
- rep3 = rep2;
- rep2 = rep1;
- rep1 = rep0;
- rep0 = dist;
-
-Then the decoder decodes exact subtype of "Rep Match" using "IsRepG0", "IsRep0Long",
-"IsRepG1", "IsRepG2".
-
-If the subtype is "Short Rep Match", the decoder updates the state, puts
-the one byte from window to current position in window and goes to next
-MATCH/LITERAL symbol (the begin of main loop):
-
- state = UpdateState_ShortRep(state);
- OutWindow.PutByte(OutWindow.GetByte(rep0 + 1));
- unpackSize--;
- continue;
-
-In other cases (Rep Match 0/1/2/3), it decodes the zero-based
-length of match with "RepLenDecoder" decoder:
-
- len = RepLenDecoder.Decode(&RangeDec, posState);
-
-Then it updates the state:
-
- state = UpdateState_Rep(state);
-
-Then the decoder must copy match bytes as described in
-"The Match symbols copying" section.
-
-
-The match symbols copying
--------------------------
-
-If we have the match (Simple Match or Rep Match 0/1/2/3), the decoder must
-copy the sequence of bytes with calculated match distance and match length.
-If uncompressed size is defined, LZMA decoder must check that it doesn't
-exceed that specified uncompressed size:
-
- len += kMatchMinLen;
- bool isError = false;
- if (unpackSizeDefined && unpackSize < len)
- {
- len = (unsigned)unpackSize;
- isError = true;
- }
- OutWindow.CopyMatch(rep0 + 1, len);
- unpackSize -= len;
- if (isError)
- return LZMA_RES_ERROR;
-
-Then the decoder must go to the begin of main loop to decode next MATCH or LITERAL.
-
-
-
-NOTES
------
-
-This specification doesn't describe the variant of decoder implementation
-that supports partial decoding. Such partial decoding case can require some
-changes in "end of stream" condition checks code. Also such code
-can use additional status codes, returned by decoder.
-
-This specification uses C++ code with templates to simplify describing.
-The optimized version of LZMA decoder doesn't need templates.
-Such optimized version can use just two arrays of CProb variables:
- 1) The dynamic array of CProb variables allocated for the Literal Decoder.
- 2) The one common array that contains all other CProb variables.
-
-
-References:
-
-1. G. N. N. Martin, Range encoding: an algorithm for removing redundancy
- from a digitized message, Video & Data Recording Conference,
- Southampton, UK, July 24-27, 1979.
diff --git a/deps/libchdr/deps/lzma-22.01/lzma.txt b/deps/libchdr/deps/lzma-22.01/lzma.txt
deleted file mode 100644
index 1f92142e..00000000
--- a/deps/libchdr/deps/lzma-22.01/lzma.txt
+++ /dev/null
@@ -1,328 +0,0 @@
-LZMA compression
-----------------
-Version: 9.35
-
-This file describes LZMA encoding and decoding functions written in C language.
-
-LZMA is an improved version of famous LZ77 compression algorithm.
-It was improved in way of maximum increasing of compression ratio,
-keeping high decompression speed and low memory requirements for
-decompressing.
-
-Note: you can read also LZMA Specification (lzma-specification.txt from LZMA SDK)
-
-Also you can look source code for LZMA encoding and decoding:
- C/Util/Lzma/LzmaUtil.c
-
-
-LZMA compressed file format
----------------------------
-Offset Size Description
- 0 1 Special LZMA properties (lc,lp, pb in encoded form)
- 1 4 Dictionary size (little endian)
- 5 8 Uncompressed size (little endian). -1 means unknown size
- 13 Compressed data
-
-
-
-ANSI-C LZMA Decoder
-~~~~~~~~~~~~~~~~~~~
-
-Please note that interfaces for ANSI-C code were changed in LZMA SDK 4.58.
-If you want to use old interfaces you can download previous version of LZMA SDK
-from sourceforge.net site.
-
-To use ANSI-C LZMA Decoder you need the following files:
-1) LzmaDec.h + LzmaDec.c + 7zTypes.h + Precomp.h + Compiler.h
-
-Look example code:
- C/Util/Lzma/LzmaUtil.c
-
-
-Memory requirements for LZMA decoding
--------------------------------------
-
-Stack usage of LZMA decoding function for local variables is not
-larger than 200-400 bytes.
-
-LZMA Decoder uses dictionary buffer and internal state structure.
-Internal state structure consumes
- state_size = (4 + (1.5 << (lc + lp))) KB
-by default (lc=3, lp=0), state_size = 16 KB.
-
-
-How To decompress data
-----------------------
-
-LZMA Decoder (ANSI-C version) now supports 2 interfaces:
-1) Single-call Decompressing
-2) Multi-call State Decompressing (zlib-like interface)
-
-You must use external allocator:
-Example:
-void *SzAlloc(void *p, size_t size) { p = p; return malloc(size); }
-void SzFree(void *p, void *address) { p = p; free(address); }
-ISzAlloc alloc = { SzAlloc, SzFree };
-
-You can use p = p; operator to disable compiler warnings.
-
-
-Single-call Decompressing
--------------------------
-When to use: RAM->RAM decompressing
-Compile files: LzmaDec.h + LzmaDec.c + 7zTypes.h
-Compile defines: no defines
-Memory Requirements:
- - Input buffer: compressed size
- - Output buffer: uncompressed size
- - LZMA Internal Structures: state_size (16 KB for default settings)
-
-Interface:
- int LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
- const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,
- ELzmaStatus *status, ISzAlloc *alloc);
- In:
- dest - output data
- destLen - output data size
- src - input data
- srcLen - input data size
- propData - LZMA properties (5 bytes)
- propSize - size of propData buffer (5 bytes)
- finishMode - It has meaning only if the decoding reaches output limit (*destLen).
- LZMA_FINISH_ANY - Decode just destLen bytes.
- LZMA_FINISH_END - Stream must be finished after (*destLen).
- You can use LZMA_FINISH_END, when you know that
- current output buffer covers last bytes of stream.
- alloc - Memory allocator.
-
- Out:
- destLen - processed output size
- srcLen - processed input size
-
- Output:
- SZ_OK
- status:
- LZMA_STATUS_FINISHED_WITH_MARK
- LZMA_STATUS_NOT_FINISHED
- LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
- SZ_ERROR_DATA - Data error
- SZ_ERROR_MEM - Memory allocation error
- SZ_ERROR_UNSUPPORTED - Unsupported properties
- SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).
-
- If LZMA decoder sees end_marker before reaching output limit, it returns OK result,
- and output value of destLen will be less than output buffer size limit.
-
- You can use multiple checks to test data integrity after full decompression:
- 1) Check Result and "status" variable.
- 2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.
- 3) Check that output(srcLen) = compressedSize, if you know real compressedSize.
- You must use correct finish mode in that case. */
-
-
-Multi-call State Decompressing (zlib-like interface)
-----------------------------------------------------
-
-When to use: file->file decompressing
-Compile files: LzmaDec.h + LzmaDec.c + 7zTypes.h
-
-Memory Requirements:
- - Buffer for input stream: any size (for example, 16 KB)
- - Buffer for output stream: any size (for example, 16 KB)
- - LZMA Internal Structures: state_size (16 KB for default settings)
- - LZMA dictionary (dictionary size is encoded in LZMA properties header)
-
-1) read LZMA properties (5 bytes) and uncompressed size (8 bytes, little-endian) to header:
- unsigned char header[LZMA_PROPS_SIZE + 8];
- ReadFile(inFile, header, sizeof(header)
-
-2) Allocate CLzmaDec structures (state + dictionary) using LZMA properties
-
- CLzmaDec state;
- LzmaDec_Constr(&state);
- res = LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc);
- if (res != SZ_OK)
- return res;
-
-3) Init LzmaDec structure before any new LZMA stream. And call LzmaDec_DecodeToBuf in loop
-
- LzmaDec_Init(&state);
- for (;;)
- {
- ...
- int res = LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen,
- const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode);
- ...
- }
-
-
-4) Free all allocated structures
- LzmaDec_Free(&state, &g_Alloc);
-
-Look example code:
- C/Util/Lzma/LzmaUtil.c
-
-
-How To compress data
---------------------
-
-Compile files:
- 7zTypes.h
- Threads.h
- LzmaEnc.h
- LzmaEnc.c
- LzFind.h
- LzFind.c
- LzFindMt.h
- LzFindMt.c
- LzHash.h
-
-Memory Requirements:
- - (dictSize * 11.5 + 6 MB) + state_size
-
-Lzma Encoder can use two memory allocators:
-1) alloc - for small arrays.
-2) allocBig - for big arrays.
-
-For example, you can use Large RAM Pages (2 MB) in allocBig allocator for
-better compression speed. Note that Windows has bad implementation for
-Large RAM Pages.
-It's OK to use same allocator for alloc and allocBig.
-
-
-Single-call Compression with callbacks
---------------------------------------
-
-Look example code:
- C/Util/Lzma/LzmaUtil.c
-
-When to use: file->file compressing
-
-1) you must implement callback structures for interfaces:
-ISeqInStream
-ISeqOutStream
-ICompressProgress
-ISzAlloc
-
-static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }
-static void SzFree(void *p, void *address) { p = p; MyFree(address); }
-static ISzAlloc g_Alloc = { SzAlloc, SzFree };
-
- CFileSeqInStream inStream;
- CFileSeqOutStream outStream;
-
- inStream.funcTable.Read = MyRead;
- inStream.file = inFile;
- outStream.funcTable.Write = MyWrite;
- outStream.file = outFile;
-
-
-2) Create CLzmaEncHandle object;
-
- CLzmaEncHandle enc;
-
- enc = LzmaEnc_Create(&g_Alloc);
- if (enc == 0)
- return SZ_ERROR_MEM;
-
-
-3) initialize CLzmaEncProps properties;
-
- LzmaEncProps_Init(&props);
-
- Then you can change some properties in that structure.
-
-4) Send LZMA properties to LZMA Encoder
-
- res = LzmaEnc_SetProps(enc, &props);
-
-5) Write encoded properties to header
-
- Byte header[LZMA_PROPS_SIZE + 8];
- size_t headerSize = LZMA_PROPS_SIZE;
- UInt64 fileSize;
- int i;
-
- res = LzmaEnc_WriteProperties(enc, header, &headerSize);
- fileSize = MyGetFileLength(inFile);
- for (i = 0; i < 8; i++)
- header[headerSize++] = (Byte)(fileSize >> (8 * i));
- MyWriteFileAndCheck(outFile, header, headerSize)
-
-6) Call encoding function:
- res = LzmaEnc_Encode(enc, &outStream.funcTable, &inStream.funcTable,
- NULL, &g_Alloc, &g_Alloc);
-
-7) Destroy LZMA Encoder Object
- LzmaEnc_Destroy(enc, &g_Alloc, &g_Alloc);
-
-
-If callback function return some error code, LzmaEnc_Encode also returns that code
-or it can return the code like SZ_ERROR_READ, SZ_ERROR_WRITE or SZ_ERROR_PROGRESS.
-
-
-Single-call RAM->RAM Compression
---------------------------------
-
-Single-call RAM->RAM Compression is similar to Compression with callbacks,
-but you provide pointers to buffers instead of pointers to stream callbacks:
-
-SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
- const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
- ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
-
-Return code:
- SZ_OK - OK
- SZ_ERROR_MEM - Memory allocation error
- SZ_ERROR_PARAM - Incorrect paramater
- SZ_ERROR_OUTPUT_EOF - output buffer overflow
- SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)
-
-
-
-Defines
--------
-
-_LZMA_SIZE_OPT - Enable some optimizations in LZMA Decoder to get smaller executable code.
-
-_LZMA_PROB32 - It can increase the speed on some 32-bit CPUs, but memory usage for
- some structures will be doubled in that case.
-
-_LZMA_UINT32_IS_ULONG - Define it if int is 16-bit on your compiler and long is 32-bit.
-
-_LZMA_NO_SYSTEM_SIZE_T - Define it if you don't want to use size_t type.
-
-
-_7ZIP_PPMD_SUPPPORT - Define it if you don't want to support PPMD method in AMSI-C .7z decoder.
-
-
-C++ LZMA Encoder/Decoder
-~~~~~~~~~~~~~~~~~~~~~~~~
-C++ LZMA code use COM-like interfaces. So if you want to use it,
-you can study basics of COM/OLE.
-C++ LZMA code is just wrapper over ANSI-C code.
-
-
-C++ Notes
-~~~~~~~~~~~~~~~~~~~~~~~~
-If you use some C++ code folders in 7-Zip (for example, C++ code for .7z handling),
-you must check that you correctly work with "new" operator.
-7-Zip can be compiled with MSVC 6.0 that doesn't throw "exception" from "new" operator.
-So 7-Zip uses "CPP\Common\NewHandler.cpp" that redefines "new" operator:
-operator new(size_t size)
-{
- void *p = ::malloc(size);
- if (p == 0)
- throw CNewException();
- return p;
-}
-If you use MSCV that throws exception for "new" operator, you can compile without
-"NewHandler.cpp". So standard exception will be used. Actually some code of
-7-Zip catches any exception in internal code and converts it to HRESULT code.
-So you don't need to catch CNewException, if you call COM interfaces of 7-Zip.
-
----
-
-http://www.7-zip.org
-http://www.7-zip.org/sdk.html
-http://www.7-zip.org/support.html
diff --git a/deps/libchdr/deps/lzma-22.01/lzma.vcxproj b/deps/libchdr/deps/lzma-22.01/lzma.vcxproj
deleted file mode 100644
index a4210356..00000000
--- a/deps/libchdr/deps/lzma-22.01/lzma.vcxproj
+++ /dev/null
@@ -1,543 +0,0 @@
-
-
-
-
- DebugFast
- ARM64
-
-
- DebugFast
- Win32
-
-
- DebugFast
- x64
-
-
- Debug
- ARM64
-
-
- Debug
- Win32
-
-
- Debug
- x64
-
-
- ReleaseLTCG
- ARM64
-
-
- ReleaseLTCG
- Win32
-
-
- ReleaseLTCG
- x64
-
-
- Release
- ARM64
-
-
- Release
- Win32
-
-
- Release
- x64
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {DD944834-7899-4C1C-A4C1-064B5009D239}
- Win32Proj
- lzma
- 10.0
-
-
-
- StaticLibrary
- true
- v142
- NotSet
-
-
- StaticLibrary
- true
- v142
- NotSet
-
-
- StaticLibrary
- true
- v142
- NotSet
-
-
- StaticLibrary
- true
- v142
- NotSet
-
-
- StaticLibrary
- true
- v142
- NotSet
-
-
- StaticLibrary
- true
- v142
- NotSet
-
-
- StaticLibrary
- false
- v142
- true
- NotSet
- false
-
-
- StaticLibrary
- false
- v142
- true
- NotSet
- false
-
-
- StaticLibrary
- false
- v142
- true
- NotSet
- false
-
-
- StaticLibrary
- false
- v142
- true
- NotSet
- false
-
-
- StaticLibrary
- false
- v142
- true
- NotSet
- false
-
-
- StaticLibrary
- false
- v142
- true
- NotSet
- false
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- true
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
- $(ProjectName)-$(Platform)-$(Configuration)
-
-
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
- $(ProjectName)-$(Platform)-$(Configuration)
- true
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
-
-
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
- $(ProjectName)-$(Platform)-$(Configuration)
- true
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
-
-
- true
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
- $(ProjectName)-$(Platform)-$(Configuration)
-
-
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
- $(ProjectName)-$(Platform)-$(Configuration)
- true
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
-
-
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
- $(ProjectName)-$(Platform)-$(Configuration)
- true
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
-
-
- false
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
- $(ProjectName)-$(Platform)-$(Configuration)
-
-
- false
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
- $(ProjectName)-$(Platform)-$(Configuration)
-
-
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
- $(ProjectName)-$(Platform)-$(Configuration)
- false
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
-
-
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
- $(ProjectName)-$(Platform)-$(Configuration)
- false
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
-
-
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
- $(ProjectName)-$(Platform)-$(Configuration)
- false
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
-
-
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
- $(ProjectName)-$(Platform)-$(Configuration)
- false
- $(SolutionDir)build\$(ProjectName)-$(Platform)-$(Configuration)\
-
-
-
-
-
- Level2
- Disabled
- _7ZIP_ST;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
- true
- ProgramDatabase
- $(ProjectDir)include;%(AdditionalIncludeDirectories)
- false
- stdcpp17
- true
- true
- /Zo /utf-8 %(AdditionalOptions)
-
-
- Windows
- true
-
-
-
-
-
-
- Level2
- Disabled
- _7ZIP_ST;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
- true
- ProgramDatabase
- $(ProjectDir)include;%(AdditionalIncludeDirectories)
- false
- stdcpp17
- true
- true
- /Zo /utf-8 %(AdditionalOptions)
-
-
- Windows
- true
-
-
-
-
-
-
- Level2
- Disabled
- _7ZIP_ST;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
- true
- ProgramDatabase
- $(ProjectDir)include;%(AdditionalIncludeDirectories)
- false
- stdcpp17
- true
- true
- /Zo /utf-8 %(AdditionalOptions)
-
-
- Windows
- true
-
-
-
-
-
-
- Level2
- Disabled
- _7ZIP_ST;_ITERATOR_DEBUG_LEVEL=1;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUGFAST;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
- true
- ProgramDatabase
- $(ProjectDir)include;%(AdditionalIncludeDirectories)
- Default
- false
- stdcpp17
- false
- true
- OnlyExplicitInline
- true
- /Zo /utf-8 %(AdditionalOptions)
-
-
- Windows
- true
-
-
-
-
-
-
- Level2
- Disabled
- _7ZIP_ST;_ITERATOR_DEBUG_LEVEL=1;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUGFAST;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
- true
- ProgramDatabase
- $(ProjectDir)include;%(AdditionalIncludeDirectories)
- Default
- false
- stdcpp17
- false
- true
- OnlyExplicitInline
- true
- /Zo /utf-8 %(AdditionalOptions)
-
-
- Windows
- true
-
-
-
-
-
-
- Level2
- Disabled
- _7ZIP_ST;_ITERATOR_DEBUG_LEVEL=1;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUGFAST;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
- true
- ProgramDatabase
- $(ProjectDir)include;%(AdditionalIncludeDirectories)
- Default
- false
- stdcpp17
- false
- true
- OnlyExplicitInline
- true
- /Zo /utf-8 %(AdditionalOptions)
-
-
- Windows
- true
-
-
-
-
- Level2
-
-
- MaxSpeed
- true
- _7ZIP_ST;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
- $(ProjectDir)include;%(AdditionalIncludeDirectories)
- false
- stdcpp17
- true
- true
- /Zo /utf-8 %(AdditionalOptions)
-
-
- Windows
- true
- true
- true
-
-
-
-
- Level2
-
-
- MaxSpeed
- true
- _7ZIP_ST;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
- $(ProjectDir)include;%(AdditionalIncludeDirectories)
- true
- stdcpp17
- true
- true
- true
- /Zo /utf-8 %(AdditionalOptions)
-
-
- Windows
- true
- true
- true
-
-
-
-
- Level2
-
-
- MaxSpeed
- true
- _7ZIP_ST;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
- $(ProjectDir)include;%(AdditionalIncludeDirectories)
- false
- stdcpp17
- true
- true
- /Zo /utf-8 %(AdditionalOptions)
-
-
- Windows
- true
- true
- true
-
-
-
-
- Level2
-
-
- MaxSpeed
- true
- _7ZIP_ST;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
- $(ProjectDir)include;%(AdditionalIncludeDirectories)
- false
- stdcpp17
- true
- true
- /Zo /utf-8 %(AdditionalOptions)
-
-
- Windows
- true
- true
- true
-
-
-
-
- Level2
-
-
- MaxSpeed
- true
- _7ZIP_ST;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
- $(ProjectDir)include;%(AdditionalIncludeDirectories)
- true
- stdcpp17
- true
- true
- true
- /Zo /utf-8 %(AdditionalOptions)
-
-
- Windows
- true
- true
- true
-
-
-
-
- Level2
-
-
- MaxSpeed
- true
- _7ZIP_ST;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
- $(ProjectDir)include;%(AdditionalIncludeDirectories)
- true
- stdcpp17
- true
- true
- true
- /Zo /utf-8 %(AdditionalOptions)
-
-
- Windows
- true
- true
- true
-
-
-
-
-
-
\ No newline at end of file
diff --git a/deps/libchdr/deps/lzma-22.01/lzma.vcxproj.filters b/deps/libchdr/deps/lzma-22.01/lzma.vcxproj.filters
deleted file mode 100644
index 8725b394..00000000
--- a/deps/libchdr/deps/lzma-22.01/lzma.vcxproj.filters
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/deps/libchdr/deps/lzma-22.01/src/Asm/arm/7zCrcOpt.asm b/deps/libchdr/deps/lzma-22.01/src/Asm/arm/7zCrcOpt.asm
deleted file mode 100644
index f008d658..00000000
--- a/deps/libchdr/deps/lzma-22.01/src/Asm/arm/7zCrcOpt.asm
+++ /dev/null
@@ -1,100 +0,0 @@
- CODE32
-
- EXPORT |CrcUpdateT4@16|
-
- AREA |.text|, CODE, ARM
-
- MACRO
- CRC32_STEP_1
-
- ldrb r4, [r1], #1
- subs r2, r2, #1
- eor r4, r4, r0
- and r4, r4, #0xFF
- ldr r4, [r3, +r4, lsl #2]
- eor r0, r4, r0, lsr #8
-
- MEND
-
-
- MACRO
- CRC32_STEP_4 $STREAM_WORD
-
- eor r7, r7, r8
- eor r7, r7, r9
- eor r0, r0, r7
- eor r0, r0, $STREAM_WORD
- ldr $STREAM_WORD, [r1], #4
-
- and r7, r0, #0xFF
- and r8, r0, #0xFF00
- and r9, r0, #0xFF0000
- and r0, r0, #0xFF000000
-
- ldr r7, [r6, +r7, lsl #2]
- ldr r8, [r5, +r8, lsr #6]
- ldr r9, [r4, +r9, lsr #14]
- ldr r0, [r3, +r0, lsr #22]
-
- MEND
-
-
-|CrcUpdateT4@16| PROC
-
- stmdb sp!, {r4-r11, lr}
- cmp r2, #0
- beq |$fin|
-
-|$v1|
- tst r1, #7
- beq |$v2|
- CRC32_STEP_1
- bne |$v1|
-
-|$v2|
- cmp r2, #16
- blo |$v3|
-
- ldr r10, [r1], #4
- ldr r11, [r1], #4
-
- add r4, r3, #0x400
- add r5, r3, #0x800
- add r6, r3, #0xC00
-
- mov r7, #0
- mov r8, #0
- mov r9, #0
-
- sub r2, r2, #16
-
-|$loop|
- ; pld [r1, #0x40]
-
- CRC32_STEP_4 r10
- CRC32_STEP_4 r11
-
- subs r2, r2, #8
- bhs |$loop|
-
- sub r1, r1, #8
- add r2, r2, #16
-
- eor r7, r7, r8
- eor r7, r7, r9
- eor r0, r0, r7
-
-|$v3|
- cmp r2, #0
- beq |$fin|
-
-|$v4|
- CRC32_STEP_1
- bne |$v4|
-
-|$fin|
- ldmia sp!, {r4-r11, pc}
-
-|CrcUpdateT4@16| ENDP
-
- END
diff --git a/deps/libchdr/deps/lzma-22.01/src/Asm/x86/7zCrcOpt.asm b/deps/libchdr/deps/lzma-22.01/src/Asm/x86/7zCrcOpt.asm
deleted file mode 100644
index 97a6b9aa..00000000
--- a/deps/libchdr/deps/lzma-22.01/src/Asm/x86/7zCrcOpt.asm
+++ /dev/null
@@ -1,180 +0,0 @@
-; 7zCrcOpt.asm -- CRC32 calculation : optimized version
-; 2021-02-07 : Igor Pavlov : Public domain
-
-include 7zAsm.asm
-
-MY_ASM_START
-
-rD equ r2
-rN equ r7
-rT equ r5
-
-ifdef x64
- num_VAR equ r8
- table_VAR equ r9
-else
- if (IS_CDECL gt 0)
- crc_OFFS equ (REG_SIZE * 5)
- data_OFFS equ (REG_SIZE + crc_OFFS)
- size_OFFS equ (REG_SIZE + data_OFFS)
- else
- size_OFFS equ (REG_SIZE * 5)
- endif
- table_OFFS equ (REG_SIZE + size_OFFS)
- num_VAR equ [r4 + size_OFFS]
- table_VAR equ [r4 + table_OFFS]
-endif
-
-SRCDAT equ rD + rN * 1 + 4 *
-
-CRC macro op:req, dest:req, src:req, t:req
- op dest, DWORD PTR [rT + src * 4 + 0400h * t]
-endm
-
-CRC_XOR macro dest:req, src:req, t:req
- CRC xor, dest, src, t
-endm
-
-CRC_MOV macro dest:req, src:req, t:req
- CRC mov, dest, src, t
-endm
-
-CRC1b macro
- movzx x6, BYTE PTR [rD]
- inc rD
- movzx x3, x0_L
- xor x6, x3
- shr x0, 8
- CRC xor, x0, r6, 0
- dec rN
-endm
-
-MY_PROLOG macro crc_end:req
-
- ifdef x64
- if (IS_LINUX gt 0)
- MY_PUSH_2_REGS
- mov x0, REG_ABI_PARAM_0_x ; x0 = x7
- mov rT, REG_ABI_PARAM_3 ; r5 = r1
- mov rN, REG_ABI_PARAM_2 ; r7 = r2
- mov rD, REG_ABI_PARAM_1 ; r2 = r6
- else
- MY_PUSH_4_REGS
- mov x0, REG_ABI_PARAM_0_x ; x0 = x1
- mov rT, REG_ABI_PARAM_3 ; r5 = r9
- mov rN, REG_ABI_PARAM_2 ; r7 = r8
- ; mov rD, REG_ABI_PARAM_1 ; r2 = r2
- endif
- else
- MY_PUSH_4_REGS
- if (IS_CDECL gt 0)
- mov x0, [r4 + crc_OFFS]
- mov rD, [r4 + data_OFFS]
- else
- mov x0, REG_ABI_PARAM_0_x
- endif
- mov rN, num_VAR
- mov rT, table_VAR
- endif
-
- test rN, rN
- jz crc_end
- @@:
- test rD, 7
- jz @F
- CRC1b
- jnz @B
- @@:
- cmp rN, 16
- jb crc_end
- add rN, rD
- mov num_VAR, rN
- sub rN, 8
- and rN, NOT 7
- sub rD, rN
- xor x0, [SRCDAT 0]
-endm
-
-MY_EPILOG macro crc_end:req
- xor x0, [SRCDAT 0]
- mov rD, rN
- mov rN, num_VAR
- sub rN, rD
- crc_end:
- test rN, rN
- jz @F
- CRC1b
- jmp crc_end
- @@:
- if (IS_X64 gt 0) and (IS_LINUX gt 0)
- MY_POP_2_REGS
- else
- MY_POP_4_REGS
- endif
-endm
-
-MY_PROC CrcUpdateT8, 4
- MY_PROLOG crc_end_8
- mov x1, [SRCDAT 1]
- align 16
- main_loop_8:
- mov x6, [SRCDAT 2]
- movzx x3, x1_L
- CRC_XOR x6, r3, 3
- movzx x3, x1_H
- CRC_XOR x6, r3, 2
- shr x1, 16
- movzx x3, x1_L
- movzx x1, x1_H
- CRC_XOR x6, r3, 1
- movzx x3, x0_L
- CRC_XOR x6, r1, 0
-
- mov x1, [SRCDAT 3]
- CRC_XOR x6, r3, 7
- movzx x3, x0_H
- shr x0, 16
- CRC_XOR x6, r3, 6
- movzx x3, x0_L
- CRC_XOR x6, r3, 5
- movzx x3, x0_H
- CRC_MOV x0, r3, 4
- xor x0, x6
- add rD, 8
- jnz main_loop_8
-
- MY_EPILOG crc_end_8
-MY_ENDP
-
-MY_PROC CrcUpdateT4, 4
- MY_PROLOG crc_end_4
- align 16
- main_loop_4:
- movzx x1, x0_L
- movzx x3, x0_H
- shr x0, 16
- movzx x6, x0_H
- and x0, 0FFh
- CRC_MOV x1, r1, 3
- xor x1, [SRCDAT 1]
- CRC_XOR x1, r3, 2
- CRC_XOR x1, r6, 0
- CRC_XOR x1, r0, 1
-
- movzx x0, x1_L
- movzx x3, x1_H
- shr x1, 16
- movzx x6, x1_H
- and x1, 0FFh
- CRC_MOV x0, r0, 3
- xor x0, [SRCDAT 2]
- CRC_XOR x0, r3, 2
- CRC_XOR x0, r6, 0
- CRC_XOR x0, r1, 1
- add rD, 8
- jnz main_loop_4
-
- MY_EPILOG crc_end_4
-MY_ENDP
-
-end
diff --git a/deps/libchdr/deps/lzma-22.01/src/Asm/x86/AesOpt.asm b/deps/libchdr/deps/lzma-22.01/src/Asm/x86/AesOpt.asm
deleted file mode 100644
index 1b7b5d45..00000000
--- a/deps/libchdr/deps/lzma-22.01/src/Asm/x86/AesOpt.asm
+++ /dev/null
@@ -1,742 +0,0 @@
-; AesOpt.asm -- AES optimized code for x86 AES hardware instructions
-; 2021-12-25 : Igor Pavlov : Public domain
-
-include 7zAsm.asm
-
-ifdef __ASMC__
- use_vaes_256 equ 1
-else
-ifdef ymm0
- use_vaes_256 equ 1
-endif
-endif
-
-
-ifdef use_vaes_256
- ECHO "++ VAES 256"
-else
- ECHO "-- NO VAES 256"
-endif
-
-ifdef x64
- ECHO "x86-64"
-else
- ECHO "x86"
-if (IS_CDECL gt 0)
- ECHO "ABI : CDECL"
-else
- ECHO "ABI : no CDECL : FASTCALL"
-endif
-endif
-
-if (IS_LINUX gt 0)
- ECHO "ABI : LINUX"
-else
- ECHO "ABI : WINDOWS"
-endif
-
-MY_ASM_START
-
-ifndef x64
- .686
- .xmm
-endif
-
-
-; MY_ALIGN EQU ALIGN(64)
-MY_ALIGN EQU
-
-SEG_ALIGN EQU MY_ALIGN
-
-MY_SEG_PROC macro name:req, numParams:req
- ; seg_name equ @CatStr(_TEXT$, name)
- ; seg_name SEGMENT SEG_ALIGN 'CODE'
- MY_PROC name, numParams
-endm
-
-MY_SEG_ENDP macro
- ; seg_name ENDS
-endm
-
-
-NUM_AES_KEYS_MAX equ 15
-
-; the number of push operators in function PROLOG
-if (IS_LINUX eq 0) or (IS_X64 eq 0)
-num_regs_push equ 2
-stack_param_offset equ (REG_SIZE * (1 + num_regs_push))
-endif
-
-ifdef x64
- num_param equ REG_ABI_PARAM_2
-else
- if (IS_CDECL gt 0)
- ; size_t size
- ; void * data
- ; UInt32 * aes
- ; ret-ip <- (r4)
- aes_OFFS equ (stack_param_offset)
- data_OFFS equ (REG_SIZE + aes_OFFS)
- size_OFFS equ (REG_SIZE + data_OFFS)
- num_param equ [r4 + size_OFFS]
- else
- num_param equ [r4 + stack_param_offset]
- endif
-endif
-
-keys equ REG_PARAM_0 ; r1
-rD equ REG_PARAM_1 ; r2
-rN equ r0
-
-koffs_x equ x7
-koffs_r equ r7
-
-ksize_x equ x6
-ksize_r equ r6
-
-keys2 equ r3
-
-state equ xmm0
-key equ xmm0
-key_ymm equ ymm0
-key_ymm_n equ 0
-
-ifdef x64
- ways = 11
-else
- ways = 4
-endif
-
-ways_start_reg equ 1
-
-iv equ @CatStr(xmm, %(ways_start_reg + ways))
-iv_ymm equ @CatStr(ymm, %(ways_start_reg + ways))
-
-
-WOP macro op, op2
- i = 0
- rept ways
- op @CatStr(xmm, %(ways_start_reg + i)), op2
- i = i + 1
- endm
-endm
-
-
-ifndef ABI_LINUX
-ifdef x64
-
-; we use 32 bytes of home space in stack in WIN64-x64
-NUM_HOME_MM_REGS equ (32 / 16)
-; we preserve xmm registers starting from xmm6 in WIN64-x64
-MM_START_SAVE_REG equ 6
-
-SAVE_XMM macro num_used_mm_regs:req
- num_save_mm_regs = num_used_mm_regs - MM_START_SAVE_REG
- if num_save_mm_regs GT 0
- num_save_mm_regs2 = num_save_mm_regs - NUM_HOME_MM_REGS
- ; RSP is (16*x + 8) after entering the function in WIN64-x64
- stack_offset = 16 * num_save_mm_regs2 + (stack_param_offset mod 16)
-
- i = 0
- rept num_save_mm_regs
-
- if i eq NUM_HOME_MM_REGS
- sub r4, stack_offset
- endif
-
- if i lt NUM_HOME_MM_REGS
- movdqa [r4 + stack_param_offset + i * 16], @CatStr(xmm, %(MM_START_SAVE_REG + i))
- else
- movdqa [r4 + (i - NUM_HOME_MM_REGS) * 16], @CatStr(xmm, %(MM_START_SAVE_REG + i))
- endif
-
- i = i + 1
- endm
- endif
-endm
-
-RESTORE_XMM macro num_used_mm_regs:req
- if num_save_mm_regs GT 0
- i = 0
- if num_save_mm_regs2 GT 0
- rept num_save_mm_regs2
- movdqa @CatStr(xmm, %(MM_START_SAVE_REG + NUM_HOME_MM_REGS + i)), [r4 + i * 16]
- i = i + 1
- endm
- add r4, stack_offset
- endif
-
- num_low_regs = num_save_mm_regs - i
- i = 0
- rept num_low_regs
- movdqa @CatStr(xmm, %(MM_START_SAVE_REG + i)), [r4 + stack_param_offset + i * 16]
- i = i + 1
- endm
- endif
-endm
-
-endif ; x64
-endif ; ABI_LINUX
-
-
-MY_PROLOG macro num_used_mm_regs:req
- ; num_regs_push: must be equal to the number of push operators
- ; push r3
- ; push r5
- if (IS_LINUX eq 0) or (IS_X64 eq 0)
- push r6
- push r7
- endif
-
- mov rN, num_param ; don't move it; num_param can use stack pointer (r4)
-
- if (IS_X64 eq 0)
- if (IS_CDECL gt 0)
- mov rD, [r4 + data_OFFS]
- mov keys, [r4 + aes_OFFS]
- endif
- elseif (IS_LINUX gt 0)
- MY_ABI_LINUX_TO_WIN_2
- endif
-
-
- ifndef ABI_LINUX
- ifdef x64
- SAVE_XMM num_used_mm_regs
- endif
- endif
-
- mov ksize_x, [keys + 16]
- shl ksize_x, 5
-endm
-
-
-MY_EPILOG macro
- ifndef ABI_LINUX
- ifdef x64
- RESTORE_XMM num_save_mm_regs
- endif
- endif
-
- if (IS_LINUX eq 0) or (IS_X64 eq 0)
- pop r7
- pop r6
- endif
- ; pop r5
- ; pop r3
- MY_ENDP
-endm
-
-
-OP_KEY macro op:req, offs:req
- op state, [keys + offs]
-endm
-
-
-WOP_KEY macro op:req, offs:req
- movdqa key, [keys + offs]
- WOP op, key
-endm
-
-
-; ---------- AES-CBC Decode ----------
-
-
-XOR_WITH_DATA macro reg, _ppp_
- pxor reg, [rD + i * 16]
-endm
-
-WRITE_TO_DATA macro reg, _ppp_
- movdqa [rD + i * 16], reg
-endm
-
-
-; state0 equ @CatStr(xmm, %(ways_start_reg))
-
-key0 equ @CatStr(xmm, %(ways_start_reg + ways + 1))
-key0_ymm equ @CatStr(ymm, %(ways_start_reg + ways + 1))
-
-key_last equ @CatStr(xmm, %(ways_start_reg + ways + 2))
-key_last_ymm equ @CatStr(ymm, %(ways_start_reg + ways + 2))
-key_last_ymm_n equ (ways_start_reg + ways + 2)
-
-NUM_CBC_REGS equ (ways_start_reg + ways + 3)
-
-
-MY_SEG_PROC AesCbc_Decode_HW, 3
-
- AesCbc_Decode_HW_start::
- MY_PROLOG NUM_CBC_REGS
-
- AesCbc_Decode_HW_start_2::
- movdqa iv, [keys]
- add keys, 32
-
- movdqa key0, [keys + 1 * ksize_r]
- movdqa key_last, [keys]
- sub ksize_x, 16
-
- jmp check2
- align 16
- nextBlocks2:
- WOP movdqa, [rD + i * 16]
- mov koffs_x, ksize_x
- ; WOP_KEY pxor, ksize_r + 16
- WOP pxor, key0
- ; align 16
- @@:
- WOP_KEY aesdec, 1 * koffs_r
- sub koffs_r, 16
- jnz @B
- ; WOP_KEY aesdeclast, 0
- WOP aesdeclast, key_last
-
- pxor @CatStr(xmm, %(ways_start_reg)), iv
- i = 1
- rept ways - 1
- pxor @CatStr(xmm, %(ways_start_reg + i)), [rD + i * 16 - 16]
- i = i + 1
- endm
- movdqa iv, [rD + ways * 16 - 16]
- WOP WRITE_TO_DATA
-
- add rD, ways * 16
- AesCbc_Decode_HW_start_3::
- check2:
- sub rN, ways
- jnc nextBlocks2
- add rN, ways
-
- sub ksize_x, 16
-
- jmp check
- nextBlock:
- movdqa state, [rD]
- mov koffs_x, ksize_x
- ; OP_KEY pxor, 1 * ksize_r + 32
- pxor state, key0
- ; movdqa state0, [rD]
- ; movdqa state, key0
- ; pxor state, state0
- @@:
- OP_KEY aesdec, 1 * koffs_r + 16
- OP_KEY aesdec, 1 * koffs_r
- sub koffs_r, 32
- jnz @B
- OP_KEY aesdec, 16
- ; OP_KEY aesdeclast, 0
- aesdeclast state, key_last
-
- pxor state, iv
- movdqa iv, [rD]
- ; movdqa iv, state0
- movdqa [rD], state
-
- add rD, 16
- check:
- sub rN, 1
- jnc nextBlock
-
- movdqa [keys - 32], iv
-MY_EPILOG
-
-
-
-
-; ---------- AVX ----------
-
-
-AVX__WOP_n macro op
- i = 0
- rept ways
- op (ways_start_reg + i)
- i = i + 1
- endm
-endm
-
-AVX__WOP macro op
- i = 0
- rept ways
- op @CatStr(ymm, %(ways_start_reg + i))
- i = i + 1
- endm
-endm
-
-
-AVX__WOP_KEY macro op:req, offs:req
- vmovdqa key_ymm, ymmword ptr [keys2 + offs]
- AVX__WOP_n op
-endm
-
-
-AVX__CBC_START macro reg
- ; vpxor reg, key_ymm, ymmword ptr [rD + 32 * i]
- vpxor reg, key0_ymm, ymmword ptr [rD + 32 * i]
-endm
-
-AVX__CBC_END macro reg
- if i eq 0
- vpxor reg, reg, iv_ymm
- else
- vpxor reg, reg, ymmword ptr [rD + i * 32 - 16]
- endif
-endm
-
-
-AVX__WRITE_TO_DATA macro reg
- vmovdqu ymmword ptr [rD + 32 * i], reg
-endm
-
-AVX__XOR_WITH_DATA macro reg
- vpxor reg, reg, ymmword ptr [rD + 32 * i]
-endm
-
-AVX__CTR_START macro reg
- vpaddq iv_ymm, iv_ymm, one_ymm
- ; vpxor reg, iv_ymm, key_ymm
- vpxor reg, iv_ymm, key0_ymm
-endm
-
-
-MY_VAES_INSTR_2 macro cmd, dest, a1, a2
- db 0c4H
- db 2 + 040H + 020h * (1 - (a2) / 8) + 080h * (1 - (dest) / 8)
- db 5 + 8 * ((not (a1)) and 15)
- db cmd
- db 0c0H + 8 * ((dest) and 7) + ((a2) and 7)
-endm
-
-MY_VAES_INSTR macro cmd, dest, a
- MY_VAES_INSTR_2 cmd, dest, dest, a
-endm
-
-MY_vaesenc macro dest, a
- MY_VAES_INSTR 0dcH, dest, a
-endm
-MY_vaesenclast macro dest, a
- MY_VAES_INSTR 0ddH, dest, a
-endm
-MY_vaesdec macro dest, a
- MY_VAES_INSTR 0deH, dest, a
-endm
-MY_vaesdeclast macro dest, a
- MY_VAES_INSTR 0dfH, dest, a
-endm
-
-
-AVX__VAES_DEC macro reg
- MY_vaesdec reg, key_ymm_n
-endm
-
-AVX__VAES_DEC_LAST_key_last macro reg
- ; MY_vaesdeclast reg, key_ymm_n
- MY_vaesdeclast reg, key_last_ymm_n
-endm
-
-AVX__VAES_ENC macro reg
- MY_vaesenc reg, key_ymm_n
-endm
-
-AVX__VAES_ENC_LAST macro reg
- MY_vaesenclast reg, key_ymm_n
-endm
-
-AVX__vinserti128_TO_HIGH macro dest, src
- vinserti128 dest, dest, src, 1
-endm
-
-
-MY_PROC AesCbc_Decode_HW_256, 3
- ifdef use_vaes_256
- MY_PROLOG NUM_CBC_REGS
-
- cmp rN, ways * 2
- jb AesCbc_Decode_HW_start_2
-
- vmovdqa iv, xmmword ptr [keys]
- add keys, 32
-
- vbroadcasti128 key0_ymm, xmmword ptr [keys + 1 * ksize_r]
- vbroadcasti128 key_last_ymm, xmmword ptr [keys]
- sub ksize_x, 16
- mov koffs_x, ksize_x
- add ksize_x, ksize_x
-
- AVX_STACK_SUB = ((NUM_AES_KEYS_MAX + 1 - 2) * 32)
- push keys2
- sub r4, AVX_STACK_SUB
- ; sub r4, 32
- ; sub r4, ksize_r
- ; lea keys2, [r4 + 32]
- mov keys2, r4
- and keys2, -32
- broad:
- vbroadcasti128 key_ymm, xmmword ptr [keys + 1 * koffs_r]
- vmovdqa ymmword ptr [keys2 + koffs_r * 2], key_ymm
- sub koffs_r, 16
- ; jnc broad
- jnz broad
-
- sub rN, ways * 2
-
- align 16
- avx_cbcdec_nextBlock2:
- mov koffs_x, ksize_x
- ; AVX__WOP_KEY AVX__CBC_START, 1 * koffs_r + 32
- AVX__WOP AVX__CBC_START
- @@:
- AVX__WOP_KEY AVX__VAES_DEC, 1 * koffs_r
- sub koffs_r, 32
- jnz @B
- ; AVX__WOP_KEY AVX__VAES_DEC_LAST, 0
- AVX__WOP_n AVX__VAES_DEC_LAST_key_last
-
- AVX__vinserti128_TO_HIGH iv_ymm, xmmword ptr [rD]
- AVX__WOP AVX__CBC_END
-
- vmovdqa iv, xmmword ptr [rD + ways * 32 - 16]
- AVX__WOP AVX__WRITE_TO_DATA
-
- add rD, ways * 32
- sub rN, ways * 2
- jnc avx_cbcdec_nextBlock2
- add rN, ways * 2
-
- shr ksize_x, 1
-
- ; lea r4, [r4 + 1 * ksize_r + 32]
- add r4, AVX_STACK_SUB
- pop keys2
-
- vzeroupper
- jmp AesCbc_Decode_HW_start_3
- else
- jmp AesCbc_Decode_HW_start
- endif
-MY_ENDP
-MY_SEG_ENDP
-
-
-
-
-; ---------- AES-CBC Encode ----------
-
-e0 equ xmm1
-
-CENC_START_KEY equ 2
-CENC_NUM_REG_KEYS equ (3 * 2)
-; last_key equ @CatStr(xmm, %(CENC_START_KEY + CENC_NUM_REG_KEYS))
-
-MY_SEG_PROC AesCbc_Encode_HW, 3
- MY_PROLOG (CENC_START_KEY + CENC_NUM_REG_KEYS + 0)
-
- movdqa state, [keys]
- add keys, 32
-
- i = 0
- rept CENC_NUM_REG_KEYS
- movdqa @CatStr(xmm, %(CENC_START_KEY + i)), [keys + i * 16]
- i = i + 1
- endm
-
- add keys, ksize_r
- neg ksize_r
- add ksize_r, (16 * CENC_NUM_REG_KEYS)
- ; movdqa last_key, [keys]
- jmp check_e
-
- align 16
- nextBlock_e:
- movdqa e0, [rD]
- mov koffs_r, ksize_r
- pxor e0, @CatStr(xmm, %(CENC_START_KEY))
- pxor state, e0
-
- i = 1
- rept (CENC_NUM_REG_KEYS - 1)
- aesenc state, @CatStr(xmm, %(CENC_START_KEY + i))
- i = i + 1
- endm
-
- @@:
- OP_KEY aesenc, 1 * koffs_r
- OP_KEY aesenc, 1 * koffs_r + 16
- add koffs_r, 32
- jnz @B
- OP_KEY aesenclast, 0
- ; aesenclast state, last_key
-
- movdqa [rD], state
- add rD, 16
- check_e:
- sub rN, 1
- jnc nextBlock_e
-
- ; movdqa [keys - 32], state
- movdqa [keys + 1 * ksize_r - (16 * CENC_NUM_REG_KEYS) - 32], state
-MY_EPILOG
-MY_SEG_ENDP
-
-
-
-; ---------- AES-CTR ----------
-
-ifdef x64
- ; ways = 11
-endif
-
-
-one equ @CatStr(xmm, %(ways_start_reg + ways + 1))
-one_ymm equ @CatStr(ymm, %(ways_start_reg + ways + 1))
-key0 equ @CatStr(xmm, %(ways_start_reg + ways + 2))
-key0_ymm equ @CatStr(ymm, %(ways_start_reg + ways + 2))
-NUM_CTR_REGS equ (ways_start_reg + ways + 3)
-
-INIT_CTR macro reg, _ppp_
- paddq iv, one
- movdqa reg, iv
-endm
-
-
-MY_SEG_PROC AesCtr_Code_HW, 3
- Ctr_start::
- MY_PROLOG NUM_CTR_REGS
-
- Ctr_start_2::
- movdqa iv, [keys]
- add keys, 32
- movdqa key0, [keys]
-
- add keys, ksize_r
- neg ksize_r
- add ksize_r, 16
-
- Ctr_start_3::
- mov koffs_x, 1
- movd one, koffs_x
- jmp check2_c
-
- align 16
- nextBlocks2_c:
- WOP INIT_CTR, 0
- mov koffs_r, ksize_r
- ; WOP_KEY pxor, 1 * koffs_r -16
- WOP pxor, key0
- @@:
- WOP_KEY aesenc, 1 * koffs_r
- add koffs_r, 16
- jnz @B
- WOP_KEY aesenclast, 0
-
- WOP XOR_WITH_DATA
- WOP WRITE_TO_DATA
- add rD, ways * 16
- check2_c:
- sub rN, ways
- jnc nextBlocks2_c
- add rN, ways
-
- sub keys, 16
- add ksize_r, 16
-
- jmp check_c
-
- ; align 16
- nextBlock_c:
- paddq iv, one
- ; movdqa state, [keys + 1 * koffs_r - 16]
- movdqa state, key0
- mov koffs_r, ksize_r
- pxor state, iv
-
- @@:
- OP_KEY aesenc, 1 * koffs_r
- OP_KEY aesenc, 1 * koffs_r + 16
- add koffs_r, 32
- jnz @B
- OP_KEY aesenc, 0
- OP_KEY aesenclast, 16
-
- pxor state, [rD]
- movdqa [rD], state
- add rD, 16
- check_c:
- sub rN, 1
- jnc nextBlock_c
-
- ; movdqa [keys - 32], iv
- movdqa [keys + 1 * ksize_r - 16 - 32], iv
-MY_EPILOG
-
-
-MY_PROC AesCtr_Code_HW_256, 3
- ifdef use_vaes_256
- MY_PROLOG NUM_CTR_REGS
-
- cmp rN, ways * 2
- jb Ctr_start_2
-
- vbroadcasti128 iv_ymm, xmmword ptr [keys]
- add keys, 32
- vbroadcasti128 key0_ymm, xmmword ptr [keys]
- mov koffs_x, 1
- vmovd one, koffs_x
- vpsubq iv_ymm, iv_ymm, one_ymm
- vpaddq one, one, one
- AVX__vinserti128_TO_HIGH one_ymm, one
-
- add keys, ksize_r
- sub ksize_x, 16
- neg ksize_r
- mov koffs_r, ksize_r
- add ksize_r, ksize_r
-
- AVX_STACK_SUB = ((NUM_AES_KEYS_MAX + 1 - 1) * 32)
- push keys2
- lea keys2, [r4 - 32]
- sub r4, AVX_STACK_SUB
- and keys2, -32
- vbroadcasti128 key_ymm, xmmword ptr [keys]
- vmovdqa ymmword ptr [keys2], key_ymm
- @@:
- vbroadcasti128 key_ymm, xmmword ptr [keys + 1 * koffs_r]
- vmovdqa ymmword ptr [keys2 + koffs_r * 2], key_ymm
- add koffs_r, 16
- jnz @B
-
- sub rN, ways * 2
-
- align 16
- avx_ctr_nextBlock2:
- mov koffs_r, ksize_r
- AVX__WOP AVX__CTR_START
- ; AVX__WOP_KEY AVX__CTR_START, 1 * koffs_r - 32
- @@:
- AVX__WOP_KEY AVX__VAES_ENC, 1 * koffs_r
- add koffs_r, 32
- jnz @B
- AVX__WOP_KEY AVX__VAES_ENC_LAST, 0
-
- AVX__WOP AVX__XOR_WITH_DATA
- AVX__WOP AVX__WRITE_TO_DATA
-
- add rD, ways * 32
- sub rN, ways * 2
- jnc avx_ctr_nextBlock2
- add rN, ways * 2
-
- vextracti128 iv, iv_ymm, 1
- sar ksize_r, 1
-
- add r4, AVX_STACK_SUB
- pop keys2
-
- vzeroupper
- jmp Ctr_start_3
- else
- jmp Ctr_start
- endif
-MY_ENDP
-MY_SEG_ENDP
-
-end
diff --git a/deps/libchdr/deps/lzma-22.01/src/Asm/x86/LzFindOpt.asm b/deps/libchdr/deps/lzma-22.01/src/Asm/x86/LzFindOpt.asm
deleted file mode 100644
index 9e66f191..00000000
--- a/deps/libchdr/deps/lzma-22.01/src/Asm/x86/LzFindOpt.asm
+++ /dev/null
@@ -1,513 +0,0 @@
-; LzFindOpt.asm -- ASM version of GetMatchesSpecN_2() function
-; 2021-07-21: Igor Pavlov : Public domain
-;
-
-ifndef x64
-; x64=1
-; .err
-endif
-
-include 7zAsm.asm
-
-MY_ASM_START
-
-_TEXT$LZFINDOPT SEGMENT ALIGN(64) 'CODE'
-
-MY_ALIGN macro num:req
- align num
-endm
-
-MY_ALIGN_32 macro
- MY_ALIGN 32
-endm
-
-MY_ALIGN_64 macro
- MY_ALIGN 64
-endm
-
-
-t0_L equ x0_L
-t0_x equ x0
-t0 equ r0
-t1_x equ x3
-t1 equ r3
-
-cp_x equ t1_x
-cp_r equ t1
-m equ x5
-m_r equ r5
-len_x equ x6
-len equ r6
-diff_x equ x7
-diff equ r7
-len0 equ r10
-len1_x equ x11
-len1 equ r11
-maxLen_x equ x12
-maxLen equ r12
-d equ r13
-ptr0 equ r14
-ptr1 equ r15
-
-d_lim equ m_r
-cycSize equ len_x
-hash_lim equ len0
-delta1_x equ len1_x
-delta1_r equ len1
-delta_x equ maxLen_x
-delta_r equ maxLen
-hash equ ptr0
-src equ ptr1
-
-
-
-if (IS_LINUX gt 0)
-
-; r1 r2 r8 r9 : win32
-; r7 r6 r2 r1 r8 r9 : linux
-
-lenLimit equ r8
-lenLimit_x equ x8
-; pos_r equ r2
-pos equ x2
-cur equ r1
-son equ r9
-
-else
-
-lenLimit equ REG_ABI_PARAM_2
-lenLimit_x equ REG_ABI_PARAM_2_x
-pos equ REG_ABI_PARAM_1_x
-cur equ REG_ABI_PARAM_0
-son equ REG_ABI_PARAM_3
-
-endif
-
-
-if (IS_LINUX gt 0)
- maxLen_OFFS equ (REG_SIZE * (6 + 1))
-else
- cutValue_OFFS equ (REG_SIZE * (8 + 1 + 4))
- d_OFFS equ (REG_SIZE + cutValue_OFFS)
- maxLen_OFFS equ (REG_SIZE + d_OFFS)
-endif
- hash_OFFS equ (REG_SIZE + maxLen_OFFS)
- limit_OFFS equ (REG_SIZE + hash_OFFS)
- size_OFFS equ (REG_SIZE + limit_OFFS)
- cycPos_OFFS equ (REG_SIZE + size_OFFS)
- cycSize_OFFS equ (REG_SIZE + cycPos_OFFS)
- posRes_OFFS equ (REG_SIZE + cycSize_OFFS)
-
-if (IS_LINUX gt 0)
-else
- cutValue_PAR equ [r0 + cutValue_OFFS]
- d_PAR equ [r0 + d_OFFS]
-endif
- maxLen_PAR equ [r0 + maxLen_OFFS]
- hash_PAR equ [r0 + hash_OFFS]
- limit_PAR equ [r0 + limit_OFFS]
- size_PAR equ [r0 + size_OFFS]
- cycPos_PAR equ [r0 + cycPos_OFFS]
- cycSize_PAR equ [r0 + cycSize_OFFS]
- posRes_PAR equ [r0 + posRes_OFFS]
-
-
- cutValue_VAR equ DWORD PTR [r4 + 8 * 0]
- cutValueCur_VAR equ DWORD PTR [r4 + 8 * 0 + 4]
- cycPos_VAR equ DWORD PTR [r4 + 8 * 1 + 0]
- cycSize_VAR equ DWORD PTR [r4 + 8 * 1 + 4]
- hash_VAR equ QWORD PTR [r4 + 8 * 2]
- limit_VAR equ QWORD PTR [r4 + 8 * 3]
- size_VAR equ QWORD PTR [r4 + 8 * 4]
- distances equ QWORD PTR [r4 + 8 * 5]
- maxLen_VAR equ QWORD PTR [r4 + 8 * 6]
-
- Old_RSP equ QWORD PTR [r4 + 8 * 7]
- LOCAL_SIZE equ 8 * 8
-
-COPY_VAR_32 macro dest_var, src_var
- mov x3, src_var
- mov dest_var, x3
-endm
-
-COPY_VAR_64 macro dest_var, src_var
- mov r3, src_var
- mov dest_var, r3
-endm
-
-
-; MY_ALIGN_64
-MY_PROC GetMatchesSpecN_2, 13
-MY_PUSH_PRESERVED_ABI_REGS
- mov r0, RSP
- lea r3, [r0 - LOCAL_SIZE]
- and r3, -64
- mov RSP, r3
- mov Old_RSP, r0
-
-if (IS_LINUX gt 0)
- mov d, REG_ABI_PARAM_5 ; r13 = r9
- mov cutValue_VAR, REG_ABI_PARAM_4_x ; = r8
- mov son, REG_ABI_PARAM_3 ; r9 = r1
- mov r8, REG_ABI_PARAM_2 ; r8 = r2
- mov pos, REG_ABI_PARAM_1_x ; r2 = x6
- mov r1, REG_ABI_PARAM_0 ; r1 = r7
-else
- COPY_VAR_32 cutValue_VAR, cutValue_PAR
- mov d, d_PAR
-endif
-
- COPY_VAR_64 limit_VAR, limit_PAR
-
- mov hash_lim, size_PAR
- mov size_VAR, hash_lim
-
- mov cp_x, cycPos_PAR
- mov hash, hash_PAR
-
- mov cycSize, cycSize_PAR
- mov cycSize_VAR, cycSize
-
- ; we want cur in (rcx). So we change the cur and lenLimit variables
- sub lenLimit, cur
- neg lenLimit_x
- inc lenLimit_x
-
- mov t0_x, maxLen_PAR
- sub t0, lenLimit
- mov maxLen_VAR, t0
-
- jmp main_loop
-
-MY_ALIGN_64
-fill_empty:
- ; ptr0 = *ptr1 = kEmptyHashValue;
- mov QWORD PTR [ptr1], 0
- inc pos
- inc cp_x
- mov DWORD PTR [d - 4], 0
- cmp d, limit_VAR
- jae fin
- cmp hash, hash_lim
- je fin
-
-; MY_ALIGN_64
-main_loop:
- ; UInt32 delta = *hash++;
- mov diff_x, [hash] ; delta
- add hash, 4
- ; mov cycPos_VAR, cp_x
-
- inc cur
- add d, 4
- mov m, pos
- sub m, diff_x; ; matchPos
-
- ; CLzRef *ptr1 = son + ((size_t)(pos) << 1) - CYC_TO_POS_OFFSET * 2;
- lea ptr1, [son + 8 * cp_r]
- ; mov cycSize, cycSize_VAR
- cmp pos, cycSize
- jb directMode ; if (pos < cycSize_VAR)
-
- ; CYC MODE
-
- cmp diff_x, cycSize
- jae fill_empty ; if (delta >= cycSize_VAR)
-
- xor t0_x, t0_x
- mov cycPos_VAR, cp_x
- sub cp_x, diff_x
- ; jae prepare_for_tree_loop
- ; add cp_x, cycSize
- cmovb t0_x, cycSize
- add cp_x, t0_x ; cp_x += (cycPos < delta ? cycSize : 0)
- jmp prepare_for_tree_loop
-
-
-directMode:
- cmp diff_x, pos
- je fill_empty ; if (delta == pos)
- jae fin_error ; if (delta >= pos)
-
- mov cycPos_VAR, cp_x
- mov cp_x, m
-
-prepare_for_tree_loop:
- mov len0, lenLimit
- mov hash_VAR, hash
- ; CLzRef *ptr0 = son + ((size_t)(pos) << 1) - CYC_TO_POS_OFFSET * 2 + 1;
- lea ptr0, [ptr1 + 4]
- ; UInt32 *_distances = ++d;
- mov distances, d
-
- neg len0
- mov len1, len0
-
- mov t0_x, cutValue_VAR
- mov maxLen, maxLen_VAR
- mov cutValueCur_VAR, t0_x
-
-MY_ALIGN_32
-tree_loop:
- neg diff
- mov len, len0
- cmp len1, len0
- cmovb len, len1 ; len = (len1 < len0 ? len1 : len0);
- add diff, cur
-
- mov t0_x, [son + cp_r * 8] ; prefetch
- movzx t0_x, BYTE PTR [diff + 1 * len]
- lea cp_r, [son + cp_r * 8]
- cmp [cur + 1 * len], t0_L
- je matched_1
-
- jb left_0
-
- mov [ptr1], m
- mov m, [cp_r + 4]
- lea ptr1, [cp_r + 4]
- sub diff, cur ; FIX32
- jmp next_node
-
-MY_ALIGN_32
-left_0:
- mov [ptr0], m
- mov m, [cp_r]
- mov ptr0, cp_r
- sub diff, cur ; FIX32
- ; jmp next_node
-
-; ------------ NEXT NODE ------------
-; MY_ALIGN_32
-next_node:
- mov cycSize, cycSize_VAR
- dec cutValueCur_VAR
- je finish_tree
-
- add diff_x, pos ; prev_match = pos + diff
- cmp m, diff_x
- jae fin_error ; if (new_match >= prev_match)
-
- mov diff_x, pos
- sub diff_x, m ; delta = pos - new_match
- cmp pos, cycSize
- jae cyc_mode_2 ; if (pos >= cycSize)
-
- mov cp_x, m
- test m, m
- jne tree_loop ; if (m != 0)
-
-finish_tree:
- ; ptr0 = *ptr1 = kEmptyHashValue;
- mov DWORD PTR [ptr0], 0
- mov DWORD PTR [ptr1], 0
-
- inc pos
-
- ; _distances[-1] = (UInt32)(d - _distances);
- mov t0, distances
- mov t1, d
- sub t1, t0
- shr t1_x, 2
- mov [t0 - 4], t1_x
-
- cmp d, limit_VAR
- jae fin ; if (d >= limit)
-
- mov cp_x, cycPos_VAR
- mov hash, hash_VAR
- mov hash_lim, size_VAR
- inc cp_x
- cmp hash, hash_lim
- jne main_loop ; if (hash != size)
- jmp fin
-
-
-MY_ALIGN_32
-cyc_mode_2:
- cmp diff_x, cycSize
- jae finish_tree ; if (delta >= cycSize)
-
- mov cp_x, cycPos_VAR
- xor t0_x, t0_x
- sub cp_x, diff_x ; cp_x = cycPos - delta
- cmovb t0_x, cycSize
- add cp_x, t0_x ; cp_x += (cycPos < delta ? cycSize : 0)
- jmp tree_loop
-
-
-MY_ALIGN_32
-matched_1:
-
- inc len
- ; cmp len_x, lenLimit_x
- je short lenLimit_reach
- movzx t0_x, BYTE PTR [diff + 1 * len]
- cmp [cur + 1 * len], t0_L
- jne mismatch
-
-
-MY_ALIGN_32
-match_loop:
- ; while (++len != lenLimit) (len[diff] != len[0]) ;
-
- inc len
- ; cmp len_x, lenLimit_x
- je short lenLimit_reach
- movzx t0_x, BYTE PTR [diff + 1 * len]
- cmp BYTE PTR [cur + 1 * len], t0_L
- je match_loop
-
-mismatch:
- jb left_2
-
- mov [ptr1], m
- mov m, [cp_r + 4]
- lea ptr1, [cp_r + 4]
- mov len1, len
-
- jmp max_update
-
-MY_ALIGN_32
-left_2:
- mov [ptr0], m
- mov m, [cp_r]
- mov ptr0, cp_r
- mov len0, len
-
-max_update:
- sub diff, cur ; restore diff
-
- cmp maxLen, len
- jae next_node
-
- mov maxLen, len
- add len, lenLimit
- mov [d], len_x
- mov t0_x, diff_x
- not t0_x
- mov [d + 4], t0_x
- add d, 8
-
- jmp next_node
-
-
-
-MY_ALIGN_32
-lenLimit_reach:
-
- mov delta_r, cur
- sub delta_r, diff
- lea delta1_r, [delta_r - 1]
-
- mov t0_x, [cp_r]
- mov [ptr1], t0_x
- mov t0_x, [cp_r + 4]
- mov [ptr0], t0_x
-
- mov [d], lenLimit_x
- mov [d + 4], delta1_x
- add d, 8
-
- ; _distances[-1] = (UInt32)(d - _distances);
- mov t0, distances
- mov t1, d
- sub t1, t0
- shr t1_x, 2
- mov [t0 - 4], t1_x
-
- mov hash, hash_VAR
- mov hash_lim, size_VAR
-
- inc pos
- mov cp_x, cycPos_VAR
- inc cp_x
-
- mov d_lim, limit_VAR
- mov cycSize, cycSize_VAR
- ; if (hash == size || *hash != delta || lenLimit[diff] != lenLimit[0] || d >= limit)
- ; break;
- cmp hash, hash_lim
- je fin
- cmp d, d_lim
- jae fin
- cmp delta_x, [hash]
- jne main_loop
- movzx t0_x, BYTE PTR [diff]
- cmp [cur], t0_L
- jne main_loop
-
- ; jmp main_loop ; bypass for debug
-
- mov cycPos_VAR, cp_x
- shl len, 3 ; cycSize * 8
- sub diff, cur ; restore diff
- xor t0_x, t0_x
- cmp cp_x, delta_x ; cmp (cycPos_VAR, delta)
- lea cp_r, [son + 8 * cp_r] ; dest
- lea src, [cp_r + 8 * diff]
- cmovb t0, len ; t0 = (cycPos_VAR < delta ? cycSize * 8 : 0)
- add src, t0
- add len, son ; len = son + cycSize * 8
-
-
-MY_ALIGN_32
-long_loop:
- add hash, 4
-
- ; *(UInt64 *)(void *)ptr = ((const UInt64 *)(const void *)ptr)[diff];
-
- mov t0, [src]
- add src, 8
- mov [cp_r], t0
- add cp_r, 8
- cmp src, len
- cmove src, son ; if end of (son) buffer is reached, we wrap to begin
-
- mov DWORD PTR [d], 2
- mov [d + 4], lenLimit_x
- mov [d + 8], delta1_x
- add d, 12
-
- inc cur
-
- cmp hash, hash_lim
- je long_footer
- cmp delta_x, [hash]
- jne long_footer
- movzx t0_x, BYTE PTR [diff + 1 * cur]
- cmp [cur], t0_L
- jne long_footer
- cmp d, d_lim
- jb long_loop
-
-long_footer:
- sub cp_r, son
- shr cp_r, 3
- add pos, cp_x
- sub pos, cycPos_VAR
- mov cycSize, cycSize_VAR
-
- cmp d, d_lim
- jae fin
- cmp hash, hash_lim
- jne main_loop
- jmp fin
-
-
-
-fin_error:
- xor d, d
-
-fin:
- mov RSP, Old_RSP
- mov t0, [r4 + posRes_OFFS]
- mov [t0], pos
- mov r0, d
-
-MY_POP_PRESERVED_ABI_REGS
-MY_ENDP
-
-_TEXT$LZFINDOPT ENDS
-
-end
diff --git a/deps/libchdr/deps/lzma-22.01/src/Asm/x86/Sha256Opt.asm b/deps/libchdr/deps/lzma-22.01/src/Asm/x86/Sha256Opt.asm
deleted file mode 100644
index 116153b6..00000000
--- a/deps/libchdr/deps/lzma-22.01/src/Asm/x86/Sha256Opt.asm
+++ /dev/null
@@ -1,275 +0,0 @@
-; Sha256Opt.asm -- SHA-256 optimized code for SHA-256 x86 hardware instructions
-; 2022-04-17 : Igor Pavlov : Public domain
-
-include 7zAsm.asm
-
-MY_ASM_START
-
-; .data
-; public K
-
-; we can use external SHA256_K_ARRAY defined in Sha256.c
-; but we must guarantee that SHA256_K_ARRAY is aligned for 16-bytes
-
-COMMENT @
-ifdef x64
-K_CONST equ SHA256_K_ARRAY
-else
-K_CONST equ _SHA256_K_ARRAY
-endif
-EXTRN K_CONST:xmmword
-@
-
-CONST SEGMENT
-
-align 16
-Reverse_Endian_Mask db 3,2,1,0, 7,6,5,4, 11,10,9,8, 15,14,13,12
-
-; COMMENT @
-align 16
-K_CONST \
-DD 0428a2f98H, 071374491H, 0b5c0fbcfH, 0e9b5dba5H
-DD 03956c25bH, 059f111f1H, 0923f82a4H, 0ab1c5ed5H
-DD 0d807aa98H, 012835b01H, 0243185beH, 0550c7dc3H
-DD 072be5d74H, 080deb1feH, 09bdc06a7H, 0c19bf174H
-DD 0e49b69c1H, 0efbe4786H, 00fc19dc6H, 0240ca1ccH
-DD 02de92c6fH, 04a7484aaH, 05cb0a9dcH, 076f988daH
-DD 0983e5152H, 0a831c66dH, 0b00327c8H, 0bf597fc7H
-DD 0c6e00bf3H, 0d5a79147H, 006ca6351H, 014292967H
-DD 027b70a85H, 02e1b2138H, 04d2c6dfcH, 053380d13H
-DD 0650a7354H, 0766a0abbH, 081c2c92eH, 092722c85H
-DD 0a2bfe8a1H, 0a81a664bH, 0c24b8b70H, 0c76c51a3H
-DD 0d192e819H, 0d6990624H, 0f40e3585H, 0106aa070H
-DD 019a4c116H, 01e376c08H, 02748774cH, 034b0bcb5H
-DD 0391c0cb3H, 04ed8aa4aH, 05b9cca4fH, 0682e6ff3H
-DD 0748f82eeH, 078a5636fH, 084c87814H, 08cc70208H
-DD 090befffaH, 0a4506cebH, 0bef9a3f7H, 0c67178f2H
-; @
-
-CONST ENDS
-
-; _TEXT$SHA256OPT SEGMENT 'CODE'
-
-ifndef x64
- .686
- .xmm
-endif
-
-; jwasm-based assemblers for linux and linker from new versions of binutils
-; can generate incorrect code for load [ARRAY + offset] instructions.
-; 22.00: we load K_CONST offset to (rTable) register to avoid jwasm+binutils problem
- rTable equ r0
- ; rTable equ K_CONST
-
-ifdef x64
- rNum equ REG_ABI_PARAM_2
- if (IS_LINUX eq 0)
- LOCAL_SIZE equ (16 * 2)
- endif
-else
- rNum equ r3
- LOCAL_SIZE equ (16 * 1)
-endif
-
-rState equ REG_ABI_PARAM_0
-rData equ REG_ABI_PARAM_1
-
-
-
-
-
-
-MY_SHA_INSTR macro cmd, a1, a2
- db 0fH, 038H, cmd, (0c0H + a1 * 8 + a2)
-endm
-
-cmd_sha256rnds2 equ 0cbH
-cmd_sha256msg1 equ 0ccH
-cmd_sha256msg2 equ 0cdH
-
-MY_sha256rnds2 macro a1, a2
- MY_SHA_INSTR cmd_sha256rnds2, a1, a2
-endm
-
-MY_sha256msg1 macro a1, a2
- MY_SHA_INSTR cmd_sha256msg1, a1, a2
-endm
-
-MY_sha256msg2 macro a1, a2
- MY_SHA_INSTR cmd_sha256msg2, a1, a2
-endm
-
-MY_PROLOG macro
- ifdef x64
- if (IS_LINUX eq 0)
- movdqa [r4 + 8], xmm6
- movdqa [r4 + 8 + 16], xmm7
- sub r4, LOCAL_SIZE + 8
- movdqa [r4 ], xmm8
- movdqa [r4 + 16], xmm9
- endif
- else ; x86
- push r3
- push r5
- mov r5, r4
- NUM_PUSH_REGS equ 2
- PARAM_OFFSET equ (REG_SIZE * (1 + NUM_PUSH_REGS))
- if (IS_CDECL gt 0)
- mov rState, [r4 + PARAM_OFFSET]
- mov rData, [r4 + PARAM_OFFSET + REG_SIZE * 1]
- mov rNum, [r4 + PARAM_OFFSET + REG_SIZE * 2]
- else ; fastcall
- mov rNum, [r4 + PARAM_OFFSET]
- endif
- and r4, -16
- sub r4, LOCAL_SIZE
- endif
-endm
-
-MY_EPILOG macro
- ifdef x64
- if (IS_LINUX eq 0)
- movdqa xmm8, [r4]
- movdqa xmm9, [r4 + 16]
- add r4, LOCAL_SIZE + 8
- movdqa xmm6, [r4 + 8]
- movdqa xmm7, [r4 + 8 + 16]
- endif
- else ; x86
- mov r4, r5
- pop r5
- pop r3
- endif
- MY_ENDP
-endm
-
-
-msg equ xmm0
-tmp equ xmm0
-state0_N equ 2
-state1_N equ 3
-w_regs equ 4
-
-
-state1_save equ xmm1
-state0 equ @CatStr(xmm, %state0_N)
-state1 equ @CatStr(xmm, %state1_N)
-
-
-ifdef x64
- state0_save equ xmm8
- mask2 equ xmm9
-else
- state0_save equ [r4]
- mask2 equ xmm0
-endif
-
-LOAD_MASK macro
- movdqa mask2, XMMWORD PTR Reverse_Endian_Mask
-endm
-
-LOAD_W macro k:req
- movdqu @CatStr(xmm, %(w_regs + k)), [rData + (16 * (k))]
- pshufb @CatStr(xmm, %(w_regs + k)), mask2
-endm
-
-
-; pre1 <= 4 && pre2 >= 1 && pre1 > pre2 && (pre1 - pre2) <= 1
-pre1 equ 3
-pre2 equ 2
-
-
-
-RND4 macro k
- movdqa msg, xmmword ptr [rTable + (k) * 16]
- paddd msg, @CatStr(xmm, %(w_regs + ((k + 0) mod 4)))
- MY_sha256rnds2 state0_N, state1_N
- pshufd msg, msg, 0eH
-
- if (k GE (4 - pre1)) AND (k LT (16 - pre1))
- ; w4[0] = msg1(w4[-4], w4[-3])
- MY_sha256msg1 (w_regs + ((k + pre1) mod 4)), (w_regs + ((k + pre1 - 3) mod 4))
- endif
-
- MY_sha256rnds2 state1_N, state0_N
-
- if (k GE (4 - pre2)) AND (k LT (16 - pre2))
- movdqa tmp, @CatStr(xmm, %(w_regs + ((k + pre2 - 1) mod 4)))
- palignr tmp, @CatStr(xmm, %(w_regs + ((k + pre2 - 2) mod 4))), 4
- paddd @CatStr(xmm, %(w_regs + ((k + pre2) mod 4))), tmp
- ; w4[0] = msg2(w4[0], w4[-1])
- MY_sha256msg2 %(w_regs + ((k + pre2) mod 4)), %(w_regs + ((k + pre2 - 1) mod 4))
- endif
-endm
-
-
-
-
-
-REVERSE_STATE macro
- ; state0 ; dcba
- ; state1 ; hgfe
- pshufd tmp, state0, 01bH ; abcd
- pshufd state0, state1, 01bH ; efgh
- movdqa state1, state0 ; efgh
- punpcklqdq state0, tmp ; cdgh
- punpckhqdq state1, tmp ; abef
-endm
-
-
-MY_PROC Sha256_UpdateBlocks_HW, 3
- MY_PROLOG
-
- lea rTable, [K_CONST]
-
- cmp rNum, 0
- je end_c
-
- movdqu state0, [rState] ; dcba
- movdqu state1, [rState + 16] ; hgfe
-
- REVERSE_STATE
-
- ifdef x64
- LOAD_MASK
- endif
-
- align 16
- nextBlock:
- movdqa state0_save, state0
- movdqa state1_save, state1
-
- ifndef x64
- LOAD_MASK
- endif
-
- LOAD_W 0
- LOAD_W 1
- LOAD_W 2
- LOAD_W 3
-
-
- k = 0
- rept 16
- RND4 k
- k = k + 1
- endm
-
- paddd state0, state0_save
- paddd state1, state1_save
-
- add rData, 64
- sub rNum, 1
- jnz nextBlock
-
- REVERSE_STATE
-
- movdqu [rState], state0
- movdqu [rState + 16], state1
-
- end_c:
-MY_EPILOG
-
-; _TEXT$SHA256OPT ENDS
-
-end
diff --git a/deps/libchdr/deps/lzma-22.01/src/Asm/x86/XzCrc64Opt.asm b/deps/libchdr/deps/lzma-22.01/src/Asm/x86/XzCrc64Opt.asm
deleted file mode 100644
index 1c67037b..00000000
--- a/deps/libchdr/deps/lzma-22.01/src/Asm/x86/XzCrc64Opt.asm
+++ /dev/null
@@ -1,239 +0,0 @@
-; XzCrc64Opt.asm -- CRC64 calculation : optimized version
-; 2021-02-06 : Igor Pavlov : Public domain
-
-include 7zAsm.asm
-
-MY_ASM_START
-
-ifdef x64
-
-rD equ r9
-rN equ r10
-rT equ r5
-num_VAR equ r8
-
-SRCDAT4 equ dword ptr [rD + rN * 1]
-
-CRC_XOR macro dest:req, src:req, t:req
- xor dest, QWORD PTR [rT + src * 8 + 0800h * t]
-endm
-
-CRC1b macro
- movzx x6, BYTE PTR [rD]
- inc rD
- movzx x3, x0_L
- xor x6, x3
- shr r0, 8
- CRC_XOR r0, r6, 0
- dec rN
-endm
-
-MY_PROLOG macro crc_end:req
- ifdef ABI_LINUX
- MY_PUSH_2_REGS
- else
- MY_PUSH_4_REGS
- endif
- mov r0, REG_ABI_PARAM_0
- mov rN, REG_ABI_PARAM_2
- mov rT, REG_ABI_PARAM_3
- mov rD, REG_ABI_PARAM_1
- test rN, rN
- jz crc_end
- @@:
- test rD, 3
- jz @F
- CRC1b
- jnz @B
- @@:
- cmp rN, 8
- jb crc_end
- add rN, rD
- mov num_VAR, rN
- sub rN, 4
- and rN, NOT 3
- sub rD, rN
- mov x1, SRCDAT4
- xor r0, r1
- add rN, 4
-endm
-
-MY_EPILOG macro crc_end:req
- sub rN, 4
- mov x1, SRCDAT4
- xor r0, r1
- mov rD, rN
- mov rN, num_VAR
- sub rN, rD
- crc_end:
- test rN, rN
- jz @F
- CRC1b
- jmp crc_end
- @@:
- ifdef ABI_LINUX
- MY_POP_2_REGS
- else
- MY_POP_4_REGS
- endif
-endm
-
-MY_PROC XzCrc64UpdateT4, 4
- MY_PROLOG crc_end_4
- align 16
- main_loop_4:
- mov x1, SRCDAT4
- movzx x2, x0_L
- movzx x3, x0_H
- shr r0, 16
- movzx x6, x0_L
- movzx x7, x0_H
- shr r0, 16
- CRC_XOR r1, r2, 3
- CRC_XOR r0, r3, 2
- CRC_XOR r1, r6, 1
- CRC_XOR r0, r7, 0
- xor r0, r1
-
- add rD, 4
- jnz main_loop_4
-
- MY_EPILOG crc_end_4
-MY_ENDP
-
-else
-; x86 (32-bit)
-
-rD equ r1
-rN equ r7
-rT equ r5
-
-crc_OFFS equ (REG_SIZE * 5)
-
-if (IS_CDECL gt 0) or (IS_LINUX gt 0)
- ; cdecl or (GNU fastcall) stack:
- ; (UInt32 *) table
- ; size_t size
- ; void * data
- ; (UInt64) crc
- ; ret-ip <-(r4)
- data_OFFS equ (8 + crc_OFFS)
- size_OFFS equ (REG_SIZE + data_OFFS)
- table_OFFS equ (REG_SIZE + size_OFFS)
- num_VAR equ [r4 + size_OFFS]
- table_VAR equ [r4 + table_OFFS]
-else
- ; Windows fastcall:
- ; r1 = data, r2 = size
- ; stack:
- ; (UInt32 *) table
- ; (UInt64) crc
- ; ret-ip <-(r4)
- table_OFFS equ (8 + crc_OFFS)
- table_VAR equ [r4 + table_OFFS]
- num_VAR equ table_VAR
-endif
-
-SRCDAT4 equ dword ptr [rD + rN * 1]
-
-CRC macro op0:req, op1:req, dest0:req, dest1:req, src:req, t:req
- op0 dest0, DWORD PTR [rT + src * 8 + 0800h * t]
- op1 dest1, DWORD PTR [rT + src * 8 + 0800h * t + 4]
-endm
-
-CRC_XOR macro dest0:req, dest1:req, src:req, t:req
- CRC xor, xor, dest0, dest1, src, t
-endm
-
-
-CRC1b macro
- movzx x6, BYTE PTR [rD]
- inc rD
- movzx x3, x0_L
- xor x6, x3
- shrd r0, r2, 8
- shr r2, 8
- CRC_XOR r0, r2, r6, 0
- dec rN
-endm
-
-MY_PROLOG macro crc_end:req
- MY_PUSH_4_REGS
-
- if (IS_CDECL gt 0) or (IS_LINUX gt 0)
- proc_numParams = proc_numParams + 2 ; for ABI_LINUX
- mov rN, [r4 + size_OFFS]
- mov rD, [r4 + data_OFFS]
- else
- mov rN, r2
- endif
-
- mov x0, [r4 + crc_OFFS]
- mov x2, [r4 + crc_OFFS + 4]
- mov rT, table_VAR
- test rN, rN
- jz crc_end
- @@:
- test rD, 3
- jz @F
- CRC1b
- jnz @B
- @@:
- cmp rN, 8
- jb crc_end
- add rN, rD
-
- mov num_VAR, rN
-
- sub rN, 4
- and rN, NOT 3
- sub rD, rN
- xor r0, SRCDAT4
- add rN, 4
-endm
-
-MY_EPILOG macro crc_end:req
- sub rN, 4
- xor r0, SRCDAT4
-
- mov rD, rN
- mov rN, num_VAR
- sub rN, rD
- crc_end:
- test rN, rN
- jz @F
- CRC1b
- jmp crc_end
- @@:
- MY_POP_4_REGS
-endm
-
-MY_PROC XzCrc64UpdateT4, 5
- MY_PROLOG crc_end_4
- movzx x6, x0_L
- align 16
- main_loop_4:
- mov r3, SRCDAT4
- xor r3, r2
-
- CRC xor, mov, r3, r2, r6, 3
- movzx x6, x0_H
- shr r0, 16
- CRC_XOR r3, r2, r6, 2
-
- movzx x6, x0_L
- movzx x0, x0_H
- CRC_XOR r3, r2, r6, 1
- CRC_XOR r3, r2, r0, 0
- movzx x6, x3_L
- mov r0, r3
-
- add rD, 4
- jnz main_loop_4
-
- MY_EPILOG crc_end_4
-MY_ENDP
-
-endif ; ! x64
-
-end
diff --git a/deps/libchdr/deps/lzma-22.01/src/Bcj2.c b/deps/libchdr/deps/lzma-22.01/src/Bcj2.c
deleted file mode 100644
index c1772f23..00000000
--- a/deps/libchdr/deps/lzma-22.01/src/Bcj2.c
+++ /dev/null
@@ -1,257 +0,0 @@
-/* Bcj2.c -- BCJ2 Decoder (Converter for x86 code)
-2021-02-09 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#include "Bcj2.h"
-#include "CpuArch.h"
-
-#define CProb UInt16
-
-#define kTopValue ((UInt32)1 << 24)
-#define kNumModelBits 11
-#define kBitModelTotal (1 << kNumModelBits)
-#define kNumMoveBits 5
-
-#define _IF_BIT_0 ttt = *prob; bound = (p->range >> kNumModelBits) * ttt; if (p->code < bound)
-#define _UPDATE_0 p->range = bound; *prob = (CProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits));
-#define _UPDATE_1 p->range -= bound; p->code -= bound; *prob = (CProb)(ttt - (ttt >> kNumMoveBits));
-
-void Bcj2Dec_Init(CBcj2Dec *p)
-{
- unsigned i;
-
- p->state = BCJ2_DEC_STATE_OK;
- p->ip = 0;
- p->temp[3] = 0;
- p->range = 0;
- p->code = 0;
- for (i = 0; i < sizeof(p->probs) / sizeof(p->probs[0]); i++)
- p->probs[i] = kBitModelTotal >> 1;
-}
-
-SRes Bcj2Dec_Decode(CBcj2Dec *p)
-{
- if (p->range <= 5)
- {
- p->state = BCJ2_DEC_STATE_OK;
- for (; p->range != 5; p->range++)
- {
- if (p->range == 1 && p->code != 0)
- return SZ_ERROR_DATA;
-
- if (p->bufs[BCJ2_STREAM_RC] == p->lims[BCJ2_STREAM_RC])
- {
- p->state = BCJ2_STREAM_RC;
- return SZ_OK;
- }
-
- p->code = (p->code << 8) | *(p->bufs[BCJ2_STREAM_RC])++;
- }
-
- if (p->code == 0xFFFFFFFF)
- return SZ_ERROR_DATA;
-
- p->range = 0xFFFFFFFF;
- }
- else if (p->state >= BCJ2_DEC_STATE_ORIG_0)
- {
- while (p->state <= BCJ2_DEC_STATE_ORIG_3)
- {
- Byte *dest = p->dest;
- if (dest == p->destLim)
- return SZ_OK;
- *dest = p->temp[(size_t)p->state - BCJ2_DEC_STATE_ORIG_0];
- p->state++;
- p->dest = dest + 1;
- }
- }
-
- /*
- if (BCJ2_IS_32BIT_STREAM(p->state))
- {
- const Byte *cur = p->bufs[p->state];
- if (cur == p->lims[p->state])
- return SZ_OK;
- p->bufs[p->state] = cur + 4;
-
- {
- UInt32 val;
- Byte *dest;
- SizeT rem;
-
- p->ip += 4;
- val = GetBe32(cur) - p->ip;
- dest = p->dest;
- rem = p->destLim - dest;
- if (rem < 4)
- {
- SizeT i;
- SetUi32(p->temp, val);
- for (i = 0; i < rem; i++)
- dest[i] = p->temp[i];
- p->dest = dest + rem;
- p->state = BCJ2_DEC_STATE_ORIG_0 + (unsigned)rem;
- return SZ_OK;
- }
- SetUi32(dest, val);
- p->temp[3] = (Byte)(val >> 24);
- p->dest = dest + 4;
- p->state = BCJ2_DEC_STATE_OK;
- }
- }
- */
-
- for (;;)
- {
- if (BCJ2_IS_32BIT_STREAM(p->state))
- p->state = BCJ2_DEC_STATE_OK;
- else
- {
- if (p->range < kTopValue)
- {
- if (p->bufs[BCJ2_STREAM_RC] == p->lims[BCJ2_STREAM_RC])
- {
- p->state = BCJ2_STREAM_RC;
- return SZ_OK;
- }
- p->range <<= 8;
- p->code = (p->code << 8) | *(p->bufs[BCJ2_STREAM_RC])++;
- }
-
- {
- const Byte *src = p->bufs[BCJ2_STREAM_MAIN];
- const Byte *srcLim;
- Byte *dest;
- SizeT num = (SizeT)(p->lims[BCJ2_STREAM_MAIN] - src);
-
- if (num == 0)
- {
- p->state = BCJ2_STREAM_MAIN;
- return SZ_OK;
- }
-
- dest = p->dest;
- if (num > (SizeT)(p->destLim - dest))
- {
- num = (SizeT)(p->destLim - dest);
- if (num == 0)
- {
- p->state = BCJ2_DEC_STATE_ORIG;
- return SZ_OK;
- }
- }
-
- srcLim = src + num;
-
- if (p->temp[3] == 0x0F && (src[0] & 0xF0) == 0x80)
- *dest = src[0];
- else for (;;)
- {
- Byte b = *src;
- *dest = b;
- if (b != 0x0F)
- {
- if ((b & 0xFE) == 0xE8)
- break;
- dest++;
- if (++src != srcLim)
- continue;
- break;
- }
- dest++;
- if (++src == srcLim)
- break;
- if ((*src & 0xF0) != 0x80)
- continue;
- *dest = *src;
- break;
- }
-
- num = (SizeT)(src - p->bufs[BCJ2_STREAM_MAIN]);
-
- if (src == srcLim)
- {
- p->temp[3] = src[-1];
- p->bufs[BCJ2_STREAM_MAIN] = src;
- p->ip += (UInt32)num;
- p->dest += num;
- p->state =
- p->bufs[BCJ2_STREAM_MAIN] ==
- p->lims[BCJ2_STREAM_MAIN] ?
- (unsigned)BCJ2_STREAM_MAIN :
- (unsigned)BCJ2_DEC_STATE_ORIG;
- return SZ_OK;
- }
-
- {
- UInt32 bound, ttt;
- CProb *prob;
- Byte b = src[0];
- Byte prev = (Byte)(num == 0 ? p->temp[3] : src[-1]);
-
- p->temp[3] = b;
- p->bufs[BCJ2_STREAM_MAIN] = src + 1;
- num++;
- p->ip += (UInt32)num;
- p->dest += num;
-
- prob = p->probs + (unsigned)(b == 0xE8 ? 2 + (unsigned)prev : (b == 0xE9 ? 1 : 0));
-
- _IF_BIT_0
- {
- _UPDATE_0
- continue;
- }
- _UPDATE_1
-
- }
- }
- }
-
- {
- UInt32 val;
- unsigned cj = (p->temp[3] == 0xE8) ? BCJ2_STREAM_CALL : BCJ2_STREAM_JUMP;
- const Byte *cur = p->bufs[cj];
- Byte *dest;
- SizeT rem;
-
- if (cur == p->lims[cj])
- {
- p->state = cj;
- break;
- }
-
- val = GetBe32(cur);
- p->bufs[cj] = cur + 4;
-
- p->ip += 4;
- val -= p->ip;
- dest = p->dest;
- rem = (SizeT)(p->destLim - dest);
-
- if (rem < 4)
- {
- p->temp[0] = (Byte)val; if (rem > 0) dest[0] = (Byte)val; val >>= 8;
- p->temp[1] = (Byte)val; if (rem > 1) dest[1] = (Byte)val; val >>= 8;
- p->temp[2] = (Byte)val; if (rem > 2) dest[2] = (Byte)val; val >>= 8;
- p->temp[3] = (Byte)val;
- p->dest = dest + rem;
- p->state = BCJ2_DEC_STATE_ORIG_0 + (unsigned)rem;
- break;
- }
-
- SetUi32(dest, val);
- p->temp[3] = (Byte)(val >> 24);
- p->dest = dest + 4;
- }
- }
-
- if (p->range < kTopValue && p->bufs[BCJ2_STREAM_RC] != p->lims[BCJ2_STREAM_RC])
- {
- p->range <<= 8;
- p->code = (p->code << 8) | *(p->bufs[BCJ2_STREAM_RC])++;
- }
-
- return SZ_OK;
-}
diff --git a/deps/libchdr/deps/lzma-22.01/src/Bcj2Enc.c b/deps/libchdr/deps/lzma-22.01/src/Bcj2Enc.c
deleted file mode 100644
index 71ac5091..00000000
--- a/deps/libchdr/deps/lzma-22.01/src/Bcj2Enc.c
+++ /dev/null
@@ -1,311 +0,0 @@
-/* Bcj2Enc.c -- BCJ2 Encoder (Converter for x86 code)
-2021-02-09 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-/* #define SHOW_STAT */
-
-#ifdef SHOW_STAT
-#include
-#define PRF(x) x
-#else
-#define PRF(x)
-#endif
-
-#include
-
-#include "Bcj2.h"
-#include "CpuArch.h"
-
-#define CProb UInt16
-
-#define kTopValue ((UInt32)1 << 24)
-#define kNumModelBits 11
-#define kBitModelTotal (1 << kNumModelBits)
-#define kNumMoveBits 5
-
-void Bcj2Enc_Init(CBcj2Enc *p)
-{
- unsigned i;
-
- p->state = BCJ2_ENC_STATE_OK;
- p->finishMode = BCJ2_ENC_FINISH_MODE_CONTINUE;
-
- p->prevByte = 0;
-
- p->cache = 0;
- p->range = 0xFFFFFFFF;
- p->low = 0;
- p->cacheSize = 1;
-
- p->ip = 0;
-
- p->fileIp = 0;
- p->fileSize = 0;
- p->relatLimit = BCJ2_RELAT_LIMIT;
-
- p->tempPos = 0;
-
- p->flushPos = 0;
-
- for (i = 0; i < sizeof(p->probs) / sizeof(p->probs[0]); i++)
- p->probs[i] = kBitModelTotal >> 1;
-}
-
-static BoolInt MY_FAST_CALL RangeEnc_ShiftLow(CBcj2Enc *p)
-{
- if ((UInt32)p->low < (UInt32)0xFF000000 || (UInt32)(p->low >> 32) != 0)
- {
- Byte *buf = p->bufs[BCJ2_STREAM_RC];
- do
- {
- if (buf == p->lims[BCJ2_STREAM_RC])
- {
- p->state = BCJ2_STREAM_RC;
- p->bufs[BCJ2_STREAM_RC] = buf;
- return True;
- }
- *buf++ = (Byte)(p->cache + (Byte)(p->low >> 32));
- p->cache = 0xFF;
- }
- while (--p->cacheSize);
- p->bufs[BCJ2_STREAM_RC] = buf;
- p->cache = (Byte)((UInt32)p->low >> 24);
- }
- p->cacheSize++;
- p->low = (UInt32)p->low << 8;
- return False;
-}
-
-static void Bcj2Enc_Encode_2(CBcj2Enc *p)
-{
- if (BCJ2_IS_32BIT_STREAM(p->state))
- {
- Byte *cur = p->bufs[p->state];
- if (cur == p->lims[p->state])
- return;
- SetBe32(cur, p->tempTarget);
- p->bufs[p->state] = cur + 4;
- }
-
- p->state = BCJ2_ENC_STATE_ORIG;
-
- for (;;)
- {
- if (p->range < kTopValue)
- {
- if (RangeEnc_ShiftLow(p))
- return;
- p->range <<= 8;
- }
-
- {
- {
- const Byte *src = p->src;
- const Byte *srcLim;
- Byte *dest;
- SizeT num = (SizeT)(p->srcLim - src);
-
- if (p->finishMode == BCJ2_ENC_FINISH_MODE_CONTINUE)
- {
- if (num <= 4)
- return;
- num -= 4;
- }
- else if (num == 0)
- break;
-
- dest = p->bufs[BCJ2_STREAM_MAIN];
- if (num > (SizeT)(p->lims[BCJ2_STREAM_MAIN] - dest))
- {
- num = (SizeT)(p->lims[BCJ2_STREAM_MAIN] - dest);
- if (num == 0)
- {
- p->state = BCJ2_STREAM_MAIN;
- return;
- }
- }
-
- srcLim = src + num;
-
- if (p->prevByte == 0x0F && (src[0] & 0xF0) == 0x80)
- *dest = src[0];
- else for (;;)
- {
- Byte b = *src;
- *dest = b;
- if (b != 0x0F)
- {
- if ((b & 0xFE) == 0xE8)
- break;
- dest++;
- if (++src != srcLim)
- continue;
- break;
- }
- dest++;
- if (++src == srcLim)
- break;
- if ((*src & 0xF0) != 0x80)
- continue;
- *dest = *src;
- break;
- }
-
- num = (SizeT)(src - p->src);
-
- if (src == srcLim)
- {
- p->prevByte = src[-1];
- p->bufs[BCJ2_STREAM_MAIN] = dest;
- p->src = src;
- p->ip += (UInt32)num;
- continue;
- }
-
- {
- Byte context = (Byte)(num == 0 ? p->prevByte : src[-1]);
- BoolInt needConvert;
-
- p->bufs[BCJ2_STREAM_MAIN] = dest + 1;
- p->ip += (UInt32)num + 1;
- src++;
-
- needConvert = False;
-
- if ((SizeT)(p->srcLim - src) >= 4)
- {
- UInt32 relatVal = GetUi32(src);
- if ((p->fileSize == 0 || (UInt32)(p->ip + 4 + relatVal - p->fileIp) < p->fileSize)
- && ((relatVal + p->relatLimit) >> 1) < p->relatLimit)
- needConvert = True;
- }
-
- {
- UInt32 bound;
- unsigned ttt;
- Byte b = src[-1];
- CProb *prob = p->probs + (unsigned)(b == 0xE8 ? 2 + (unsigned)context : (b == 0xE9 ? 1 : 0));
-
- ttt = *prob;
- bound = (p->range >> kNumModelBits) * ttt;
-
- if (!needConvert)
- {
- p->range = bound;
- *prob = (CProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits));
- p->src = src;
- p->prevByte = b;
- continue;
- }
-
- p->low += bound;
- p->range -= bound;
- *prob = (CProb)(ttt - (ttt >> kNumMoveBits));
-
- {
- UInt32 relatVal = GetUi32(src);
- UInt32 absVal;
- p->ip += 4;
- absVal = p->ip + relatVal;
- p->prevByte = src[3];
- src += 4;
- p->src = src;
- {
- unsigned cj = (b == 0xE8) ? BCJ2_STREAM_CALL : BCJ2_STREAM_JUMP;
- Byte *cur = p->bufs[cj];
- if (cur == p->lims[cj])
- {
- p->state = cj;
- p->tempTarget = absVal;
- return;
- }
- SetBe32(cur, absVal);
- p->bufs[cj] = cur + 4;
- }
- }
- }
- }
- }
- }
- }
-
- if (p->finishMode != BCJ2_ENC_FINISH_MODE_END_STREAM)
- return;
-
- for (; p->flushPos < 5; p->flushPos++)
- if (RangeEnc_ShiftLow(p))
- return;
- p->state = BCJ2_ENC_STATE_OK;
-}
-
-
-void Bcj2Enc_Encode(CBcj2Enc *p)
-{
- PRF(printf("\n"));
- PRF(printf("---- ip = %8d tempPos = %8d src = %8d\n", p->ip, p->tempPos, p->srcLim - p->src));
-
- if (p->tempPos != 0)
- {
- unsigned extra = 0;
-
- for (;;)
- {
- const Byte *src = p->src;
- const Byte *srcLim = p->srcLim;
- EBcj2Enc_FinishMode finishMode = p->finishMode;
-
- p->src = p->temp;
- p->srcLim = p->temp + p->tempPos;
- if (src != srcLim)
- p->finishMode = BCJ2_ENC_FINISH_MODE_CONTINUE;
-
- PRF(printf(" ip = %8d tempPos = %8d src = %8d\n", p->ip, p->tempPos, p->srcLim - p->src));
-
- Bcj2Enc_Encode_2(p);
-
- {
- unsigned num = (unsigned)(p->src - p->temp);
- unsigned tempPos = p->tempPos - num;
- unsigned i;
- p->tempPos = tempPos;
- for (i = 0; i < tempPos; i++)
- p->temp[i] = p->temp[(size_t)i + num];
-
- p->src = src;
- p->srcLim = srcLim;
- p->finishMode = finishMode;
-
- if (p->state != BCJ2_ENC_STATE_ORIG || src == srcLim)
- return;
-
- if (extra >= tempPos)
- {
- p->src = src - tempPos;
- p->tempPos = 0;
- break;
- }
-
- p->temp[tempPos] = src[0];
- p->tempPos = tempPos + 1;
- p->src = src + 1;
- extra++;
- }
- }
- }
-
- PRF(printf("++++ ip = %8d tempPos = %8d src = %8d\n", p->ip, p->tempPos, p->srcLim - p->src));
-
- Bcj2Enc_Encode_2(p);
-
- if (p->state == BCJ2_ENC_STATE_ORIG)
- {
- const Byte *src = p->src;
- unsigned rem = (unsigned)(p->srcLim - src);
- unsigned i;
- for (i = 0; i < rem; i++)
- p->temp[i] = src[i];
- p->tempPos = rem;
- p->src = src + rem;
- }
-}
diff --git a/deps/libchdr/deps/lzma-22.01/src/Bra.c b/deps/libchdr/deps/lzma-22.01/src/Bra.c
deleted file mode 100644
index cdefa4d2..00000000
--- a/deps/libchdr/deps/lzma-22.01/src/Bra.c
+++ /dev/null
@@ -1,230 +0,0 @@
-/* Bra.c -- Converters for RISC code
-2021-02-09 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#include "CpuArch.h"
-#include "Bra.h"
-
-SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
-{
- Byte *p;
- const Byte *lim;
- size &= ~(size_t)3;
- ip += 4;
- p = data;
- lim = data + size;
-
- if (encoding)
-
- for (;;)
- {
- for (;;)
- {
- if (p >= lim)
- return (SizeT)(p - data);
- p += 4;
- if (p[-1] == 0xEB)
- break;
- }
- {
- UInt32 v = GetUi32(p - 4);
- v <<= 2;
- v += ip + (UInt32)(p - data);
- v >>= 2;
- v &= 0x00FFFFFF;
- v |= 0xEB000000;
- SetUi32(p - 4, v);
- }
- }
-
- for (;;)
- {
- for (;;)
- {
- if (p >= lim)
- return (SizeT)(p - data);
- p += 4;
- if (p[-1] == 0xEB)
- break;
- }
- {
- UInt32 v = GetUi32(p - 4);
- v <<= 2;
- v -= ip + (UInt32)(p - data);
- v >>= 2;
- v &= 0x00FFFFFF;
- v |= 0xEB000000;
- SetUi32(p - 4, v);
- }
- }
-}
-
-
-SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
-{
- Byte *p;
- const Byte *lim;
- size &= ~(size_t)1;
- p = data;
- lim = data + size - 4;
-
- if (encoding)
-
- for (;;)
- {
- UInt32 b1;
- for (;;)
- {
- UInt32 b3;
- if (p > lim)
- return (SizeT)(p - data);
- b1 = p[1];
- b3 = p[3];
- p += 2;
- b1 ^= 8;
- if ((b3 & b1) >= 0xF8)
- break;
- }
- {
- UInt32 v =
- ((UInt32)b1 << 19)
- + (((UInt32)p[1] & 0x7) << 8)
- + (((UInt32)p[-2] << 11))
- + (p[0]);
-
- p += 2;
- {
- UInt32 cur = (ip + (UInt32)(p - data)) >> 1;
- v += cur;
- }
-
- p[-4] = (Byte)(v >> 11);
- p[-3] = (Byte)(0xF0 | ((v >> 19) & 0x7));
- p[-2] = (Byte)v;
- p[-1] = (Byte)(0xF8 | (v >> 8));
- }
- }
-
- for (;;)
- {
- UInt32 b1;
- for (;;)
- {
- UInt32 b3;
- if (p > lim)
- return (SizeT)(p - data);
- b1 = p[1];
- b3 = p[3];
- p += 2;
- b1 ^= 8;
- if ((b3 & b1) >= 0xF8)
- break;
- }
- {
- UInt32 v =
- ((UInt32)b1 << 19)
- + (((UInt32)p[1] & 0x7) << 8)
- + (((UInt32)p[-2] << 11))
- + (p[0]);
-
- p += 2;
- {
- UInt32 cur = (ip + (UInt32)(p - data)) >> 1;
- v -= cur;
- }
-
- /*
- SetUi16(p - 4, (UInt16)(((v >> 11) & 0x7FF) | 0xF000));
- SetUi16(p - 2, (UInt16)(v | 0xF800));
- */
-
- p[-4] = (Byte)(v >> 11);
- p[-3] = (Byte)(0xF0 | ((v >> 19) & 0x7));
- p[-2] = (Byte)v;
- p[-1] = (Byte)(0xF8 | (v >> 8));
- }
- }
-}
-
-
-SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
-{
- Byte *p;
- const Byte *lim;
- size &= ~(size_t)3;
- ip -= 4;
- p = data;
- lim = data + size;
-
- for (;;)
- {
- for (;;)
- {
- if (p >= lim)
- return (SizeT)(p - data);
- p += 4;
- /* if ((v & 0xFC000003) == 0x48000001) */
- if ((p[-4] & 0xFC) == 0x48 && (p[-1] & 3) == 1)
- break;
- }
- {
- UInt32 v = GetBe32(p - 4);
- if (encoding)
- v += ip + (UInt32)(p - data);
- else
- v -= ip + (UInt32)(p - data);
- v &= 0x03FFFFFF;
- v |= 0x48000000;
- SetBe32(p - 4, v);
- }
- }
-}
-
-
-SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
-{
- Byte *p;
- const Byte *lim;
- size &= ~(size_t)3;
- ip -= 4;
- p = data;
- lim = data + size;
-
- for (;;)
- {
- for (;;)
- {
- if (p >= lim)
- return (SizeT)(p - data);
- /*
- v = GetBe32(p);
- p += 4;
- m = v + ((UInt32)5 << 29);
- m ^= (UInt32)7 << 29;
- m += (UInt32)1 << 22;
- if ((m & ((UInt32)0x1FF << 23)) == 0)
- break;
- */
- p += 4;
- if ((p[-4] == 0x40 && (p[-3] & 0xC0) == 0) ||
- (p[-4] == 0x7F && (p[-3] >= 0xC0)))
- break;
- }
- {
- UInt32 v = GetBe32(p - 4);
- v <<= 2;
- if (encoding)
- v += ip + (UInt32)(p - data);
- else
- v -= ip + (UInt32)(p - data);
-
- v &= 0x01FFFFFF;
- v -= (UInt32)1 << 24;
- v ^= 0xFF000000;
- v >>= 2;
- v |= 0x40000000;
- SetBe32(p - 4, v);
- }
- }
-}
diff --git a/deps/libchdr/deps/lzma-22.01/src/Bra86.c b/deps/libchdr/deps/lzma-22.01/src/Bra86.c
deleted file mode 100644
index d857dac6..00000000
--- a/deps/libchdr/deps/lzma-22.01/src/Bra86.c
+++ /dev/null
@@ -1,82 +0,0 @@
-/* Bra86.c -- Converter for x86 code (BCJ)
-2021-02-09 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#include "Bra.h"
-
-#define Test86MSByte(b) ((((b) + 1) & 0xFE) == 0)
-
-SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding)
-{
- SizeT pos = 0;
- UInt32 mask = *state & 7;
- if (size < 5)
- return 0;
- size -= 4;
- ip += 5;
-
- 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;
- pos = (SizeT)(p - data);
- if (p >= limit)
- {
- *state = (d > 2 ? 0 : mask >> (unsigned)d);
- return pos;
- }
- if (d > 2)
- mask = 0;
- else
- {
- mask >>= (unsigned)d;
- if (mask != 0 && (mask > 4 || mask == 3 || Test86MSByte(p[(size_t)(mask >> 1) + 1])))
- {
- mask = (mask >> 1) | 4;
- pos++;
- continue;
- }
- }
- }
-
- 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)
- v += cur;
- else
- v -= cur;
- if (mask != 0)
- {
- unsigned sh = (mask & 6) << 2;
- if (Test86MSByte((Byte)(v >> sh)))
- {
- v ^= (((UInt32)0x100 << sh) - 1);
- if (encoding)
- v += cur;
- 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
- {
- mask = (mask >> 1) | 4;
- pos++;
- }
- }
-}
diff --git a/deps/libchdr/deps/lzma-22.01/src/BraIA64.c b/deps/libchdr/deps/lzma-22.01/src/BraIA64.c
deleted file mode 100644
index 2656907a..00000000
--- a/deps/libchdr/deps/lzma-22.01/src/BraIA64.c
+++ /dev/null
@@ -1,53 +0,0 @@
-/* BraIA64.c -- Converter for IA-64 code
-2017-01-26 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#include "CpuArch.h"
-#include "Bra.h"
-
-SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
-{
- SizeT i;
- if (size < 16)
- return 0;
- size -= 16;
- i = 0;
- do
- {
- unsigned m = ((UInt32)0x334B0000 >> (data[i] & 0x1E)) & 3;
- if (m)
- {
- m++;
- do
- {
- Byte *p = data + (i + (size_t)m * 5 - 8);
- if (((p[3] >> m) & 15) == 5
- && (((p[-1] | ((UInt32)p[0] << 8)) >> m) & 0x70) == 0)
- {
- unsigned raw = GetUi32(p);
- unsigned v = raw >> m;
- v = (v & 0xFFFFF) | ((v & (1 << 23)) >> 3);
-
- v <<= 4;
- if (encoding)
- v += ip + (UInt32)i;
- else
- v -= ip + (UInt32)i;
- v >>= 4;
-
- v &= 0x1FFFFF;
- v += 0x700000;
- v &= 0x8FFFFF;
- raw &= ~((UInt32)0x8FFFFF << m);
- raw |= (v << m);
- SetUi32(p, raw);
- }
- }
- while (++m <= 4);
- }
- i += 16;
- }
- while (i <= size);
- return i;
-}
diff --git a/deps/libchdr/deps/lzma-22.01/src/CpuArch.c b/deps/libchdr/deps/lzma-22.01/src/CpuArch.c
deleted file mode 100644
index 142db135..00000000
--- a/deps/libchdr/deps/lzma-22.01/src/CpuArch.c
+++ /dev/null
@@ -1,493 +0,0 @@
-/* CpuArch.c -- CPU specific code
-2021-07-13 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#include "CpuArch.h"
-
-#ifdef MY_CPU_X86_OR_AMD64
-
-#if (defined(_MSC_VER) && !defined(MY_CPU_AMD64)) || defined(__GNUC__)
-#define USE_ASM
-#endif
-
-#if !defined(USE_ASM) && _MSC_VER >= 1500
-#include
-#endif
-
-#if defined(USE_ASM) && !defined(MY_CPU_AMD64)
-static UInt32 CheckFlag(UInt32 flag)
-{
- #ifdef _MSC_VER
- __asm pushfd;
- __asm pop EAX;
- __asm mov EDX, EAX;
- __asm xor EAX, flag;
- __asm push EAX;
- __asm popfd;
- __asm pushfd;
- __asm pop EAX;
- __asm xor EAX, EDX;
- __asm push EDX;
- __asm popfd;
- __asm and flag, EAX;
- #else
- __asm__ __volatile__ (
- "pushf\n\t"
- "pop %%EAX\n\t"
- "movl %%EAX,%%EDX\n\t"
- "xorl %0,%%EAX\n\t"
- "push %%EAX\n\t"
- "popf\n\t"
- "pushf\n\t"
- "pop %%EAX\n\t"
- "xorl %%EDX,%%EAX\n\t"
- "push %%EDX\n\t"
- "popf\n\t"
- "andl %%EAX, %0\n\t":
- "=c" (flag) : "c" (flag) :
- "%eax", "%edx");
- #endif
- return flag;
-}
-#define CHECK_CPUID_IS_SUPPORTED if (CheckFlag(1 << 18) == 0 || CheckFlag(1 << 21) == 0) return False;
-#else
-#define CHECK_CPUID_IS_SUPPORTED
-#endif
-
-#ifndef USE_ASM
- #ifdef _MSC_VER
- #if _MSC_VER >= 1600
- #define MY__cpuidex __cpuidex
- #else
-
-/*
- __cpuid (function == 4) requires subfunction number in ECX.
- MSDN: The __cpuid intrinsic clears the ECX register before calling the cpuid instruction.
- __cpuid() in new MSVC clears ECX.
- __cpuid() in old MSVC (14.00) doesn't clear ECX
- We still can use __cpuid for low (function) values that don't require ECX,
- but __cpuid() in old MSVC will be incorrect for some function values: (function == 4).
- So here we use the hack for old MSVC to send (subFunction) in ECX register to cpuid instruction,
- where ECX value is first parameter for FAST_CALL / NO_INLINE function,
- So the caller of MY__cpuidex_HACK() sets ECX as subFunction, and
- old MSVC for __cpuid() doesn't change ECX and cpuid instruction gets (subFunction) value.
-
- DON'T remove MY_NO_INLINE and MY_FAST_CALL for MY__cpuidex_HACK() !!!
-*/
-
-static
-MY_NO_INLINE
-void MY_FAST_CALL MY__cpuidex_HACK(UInt32 subFunction, int *CPUInfo, UInt32 function)
-{
- UNUSED_VAR(subFunction);
- __cpuid(CPUInfo, function);
-}
-
- #define MY__cpuidex(info, func, func2) MY__cpuidex_HACK(func2, info, func)
- #pragma message("======== MY__cpuidex_HACK WAS USED ========")
- #endif
- #else
- #define MY__cpuidex(info, func, func2) __cpuid(info, func)
- #pragma message("======== (INCORRECT ?) cpuid WAS USED ========")
- #endif
-#endif
-
-
-
-
-void MyCPUID(UInt32 function, UInt32 *a, UInt32 *b, UInt32 *c, UInt32 *d)
-{
- #ifdef USE_ASM
-
- #ifdef _MSC_VER
-
- UInt32 a2, b2, c2, d2;
- __asm xor EBX, EBX;
- __asm xor ECX, ECX;
- __asm xor EDX, EDX;
- __asm mov EAX, function;
- __asm cpuid;
- __asm mov a2, EAX;
- __asm mov b2, EBX;
- __asm mov c2, ECX;
- __asm mov d2, EDX;
-
- *a = a2;
- *b = b2;
- *c = c2;
- *d = d2;
-
- #else
-
- __asm__ __volatile__ (
- #if defined(MY_CPU_AMD64) && defined(__PIC__)
- "mov %%rbx, %%rdi;"
- "cpuid;"
- "xchg %%rbx, %%rdi;"
- : "=a" (*a) ,
- "=D" (*b) ,
- #elif defined(MY_CPU_X86) && defined(__PIC__)
- "mov %%ebx, %%edi;"
- "cpuid;"
- "xchgl %%ebx, %%edi;"
- : "=a" (*a) ,
- "=D" (*b) ,
- #else
- "cpuid"
- : "=a" (*a) ,
- "=b" (*b) ,
- #endif
- "=c" (*c) ,
- "=d" (*d)
- : "0" (function), "c"(0) ) ;
-
- #endif
-
- #else
-
- int CPUInfo[4];
-
- MY__cpuidex(CPUInfo, (int)function, 0);
-
- *a = (UInt32)CPUInfo[0];
- *b = (UInt32)CPUInfo[1];
- *c = (UInt32)CPUInfo[2];
- *d = (UInt32)CPUInfo[3];
-
- #endif
-}
-
-BoolInt x86cpuid_CheckAndRead(Cx86cpuid *p)
-{
- CHECK_CPUID_IS_SUPPORTED
- MyCPUID(0, &p->maxFunc, &p->vendor[0], &p->vendor[2], &p->vendor[1]);
- MyCPUID(1, &p->ver, &p->b, &p->c, &p->d);
- return True;
-}
-
-static const UInt32 kVendors[][3] =
-{
- { 0x756E6547, 0x49656E69, 0x6C65746E},
- { 0x68747541, 0x69746E65, 0x444D4163},
- { 0x746E6543, 0x48727561, 0x736C7561}
-};
-
-int x86cpuid_GetFirm(const Cx86cpuid *p)
-{
- unsigned i;
- for (i = 0; i < sizeof(kVendors) / sizeof(kVendors[i]); i++)
- {
- const UInt32 *v = kVendors[i];
- if (v[0] == p->vendor[0] &&
- v[1] == p->vendor[1] &&
- v[2] == p->vendor[2])
- return (int)i;
- }
- return -1;
-}
-
-BoolInt CPU_Is_InOrder()
-{
- Cx86cpuid p;
- int firm;
- UInt32 family, model;
- if (!x86cpuid_CheckAndRead(&p))
- return True;
-
- family = x86cpuid_GetFamily(p.ver);
- model = x86cpuid_GetModel(p.ver);
-
- firm = x86cpuid_GetFirm(&p);
-
- switch (firm)
- {
- case CPU_FIRM_INTEL: return (family < 6 || (family == 6 && (
- /* In-Order Atom CPU */
- model == 0x1C /* 45 nm, N4xx, D4xx, N5xx, D5xx, 230, 330 */
- || model == 0x26 /* 45 nm, Z6xx */
- || model == 0x27 /* 32 nm, Z2460 */
- || model == 0x35 /* 32 nm, Z2760 */
- || model == 0x36 /* 32 nm, N2xxx, D2xxx */
- )));
- case CPU_FIRM_AMD: return (family < 5 || (family == 5 && (model < 6 || model == 0xA)));
- case CPU_FIRM_VIA: return (family < 6 || (family == 6 && model < 0xF));
- }
- return True;
-}
-
-#if !defined(MY_CPU_AMD64) && defined(_WIN32)
-#include
-static BoolInt CPU_Sys_Is_SSE_Supported()
-{
- OSVERSIONINFO vi;
- vi.dwOSVersionInfoSize = sizeof(vi);
- if (!GetVersionEx(&vi))
- return False;
- return (vi.dwMajorVersion >= 5);
-}
-#define CHECK_SYS_SSE_SUPPORT if (!CPU_Sys_Is_SSE_Supported()) return False;
-#else
-#define CHECK_SYS_SSE_SUPPORT
-#endif
-
-
-static UInt32 X86_CPUID_ECX_Get_Flags()
-{
- Cx86cpuid p;
- CHECK_SYS_SSE_SUPPORT
- if (!x86cpuid_CheckAndRead(&p))
- return 0;
- return p.c;
-}
-
-BoolInt CPU_IsSupported_AES()
-{
- return (X86_CPUID_ECX_Get_Flags() >> 25) & 1;
-}
-
-BoolInt CPU_IsSupported_SSSE3()
-{
- return (X86_CPUID_ECX_Get_Flags() >> 9) & 1;
-}
-
-BoolInt CPU_IsSupported_SSE41()
-{
- return (X86_CPUID_ECX_Get_Flags() >> 19) & 1;
-}
-
-BoolInt CPU_IsSupported_SHA()
-{
- Cx86cpuid p;
- CHECK_SYS_SSE_SUPPORT
- if (!x86cpuid_CheckAndRead(&p))
- return False;
-
- if (p.maxFunc < 7)
- return False;
- {
- UInt32 d[4] = { 0 };
- MyCPUID(7, &d[0], &d[1], &d[2], &d[3]);
- return (d[1] >> 29) & 1;
- }
-}
-
-// #include
-
-#ifdef _WIN32
-#include
-#endif
-
-BoolInt CPU_IsSupported_AVX2()
-{
- Cx86cpuid p;
- CHECK_SYS_SSE_SUPPORT
-
- #ifdef _WIN32
- #define MY__PF_XSAVE_ENABLED 17
- if (!IsProcessorFeaturePresent(MY__PF_XSAVE_ENABLED))
- return False;
- #endif
-
- if (!x86cpuid_CheckAndRead(&p))
- return False;
- if (p.maxFunc < 7)
- return False;
- {
- UInt32 d[4] = { 0 };
- MyCPUID(7, &d[0], &d[1], &d[2], &d[3]);
- // printf("\ncpuid(7): ebx=%8x ecx=%8x\n", d[1], d[2]);
- return 1
- & (d[1] >> 5); // avx2
- }
-}
-
-BoolInt CPU_IsSupported_VAES_AVX2()
-{
- Cx86cpuid p;
- CHECK_SYS_SSE_SUPPORT
-
- #ifdef _WIN32
- #define MY__PF_XSAVE_ENABLED 17
- if (!IsProcessorFeaturePresent(MY__PF_XSAVE_ENABLED))
- return False;
- #endif
-
- if (!x86cpuid_CheckAndRead(&p))
- return False;
- if (p.maxFunc < 7)
- return False;
- {
- UInt32 d[4] = { 0 };
- MyCPUID(7, &d[0], &d[1], &d[2], &d[3]);
- // printf("\ncpuid(7): ebx=%8x ecx=%8x\n", d[1], d[2]);
- return 1
- & (d[1] >> 5) // avx2
- // & (d[1] >> 31) // avx512vl
- & (d[2] >> 9); // vaes // VEX-256/EVEX
- }
-}
-
-BoolInt CPU_IsSupported_PageGB()
-{
- Cx86cpuid cpuid;
- if (!x86cpuid_CheckAndRead(&cpuid))
- return False;
- {
- UInt32 d[4] = { 0 };
- MyCPUID(0x80000000, &d[0], &d[1], &d[2], &d[3]);
- if (d[0] < 0x80000001)
- return False;
- }
- {
- UInt32 d[4] = { 0 };
- MyCPUID(0x80000001, &d[0], &d[1], &d[2], &d[3]);
- return (d[3] >> 26) & 1;
- }
-}
-
-
-#elif defined(MY_CPU_ARM_OR_ARM64)
-
-#ifdef _WIN32
-
-#include
-
-BoolInt CPU_IsSupported_CRC32() { return IsProcessorFeaturePresent(PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE) ? 1 : 0; }
-BoolInt CPU_IsSupported_CRYPTO() { return IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE) ? 1 : 0; }
-BoolInt CPU_IsSupported_NEON() { return IsProcessorFeaturePresent(PF_ARM_NEON_INSTRUCTIONS_AVAILABLE) ? 1 : 0; }
-
-#else
-
-#if defined(__APPLE__)
-
-/*
-#include
-#include
-static void Print_sysctlbyname(const char *name)
-{
- size_t bufSize = 256;
- char buf[256];
- int res = sysctlbyname(name, &buf, &bufSize, NULL, 0);
- {
- int i;
- printf("\nres = %d : %s : '%s' : bufSize = %d, numeric", res, name, buf, (unsigned)bufSize);
- for (i = 0; i < 20; i++)
- printf(" %2x", (unsigned)(Byte)buf[i]);
-
- }
-}
-*/
-
-static BoolInt My_sysctlbyname_Get_BoolInt(const char *name)
-{
- UInt32 val = 0;
- if (My_sysctlbyname_Get_UInt32(name, &val) == 0 && val == 1)
- return 1;
- return 0;
-}
-
- /*
- Print_sysctlbyname("hw.pagesize");
- Print_sysctlbyname("machdep.cpu.brand_string");
- */
-
-BoolInt CPU_IsSupported_CRC32(void)
-{
- return My_sysctlbyname_Get_BoolInt("hw.optional.armv8_crc32");
-}
-
-BoolInt CPU_IsSupported_NEON(void)
-{
- return My_sysctlbyname_Get_BoolInt("hw.optional.neon");
-}
-
-#ifdef MY_CPU_ARM64
-#define APPLE_CRYPTO_SUPPORT_VAL 1
-#else
-#define APPLE_CRYPTO_SUPPORT_VAL 0
-#endif
-
-BoolInt CPU_IsSupported_SHA1(void) { return APPLE_CRYPTO_SUPPORT_VAL; }
-BoolInt CPU_IsSupported_SHA2(void) { return APPLE_CRYPTO_SUPPORT_VAL; }
-BoolInt CPU_IsSupported_AES (void) { return APPLE_CRYPTO_SUPPORT_VAL; }
-
-
-#else // __APPLE__
-
-#if defined(__SWITCH__) || defined(__vita__)
-
-BoolInt CPU_IsSupported_CRC32(void) { return 0; }
-BoolInt CPU_IsSupported_NEON(void) { return 1; }
-BoolInt CPU_IsSupported_SHA1(void) { return 0; }
-BoolInt CPU_IsSupported_SHA2(void) { return 0; }
-BoolInt CPU_IsSupported_AES (void) { return 0; }
-
-#else
-
-#if (defined(__ANDROID_API__) && __ANDROID_API__ < 18) || \
- defined(_MIYOO) || defined(_3DS) || defined(NO_HWCAP)
-// no getauxval/AT_HWCAP
-#else
-#define USE_HWCAP
-#endif
-
-#ifdef USE_HWCAP
-
-#include
-#include
-
- #define MY_HWCAP_CHECK_FUNC_2(name1, name2) \
- BoolInt CPU_IsSupported_ ## name1() { return (getauxval(AT_HWCAP) & (HWCAP_ ## name2)) ? 1 : 0; }
-
-#ifdef MY_CPU_ARM64
- #define MY_HWCAP_CHECK_FUNC(name) \
- MY_HWCAP_CHECK_FUNC_2(name, name)
- MY_HWCAP_CHECK_FUNC_2(NEON, ASIMD)
-// MY_HWCAP_CHECK_FUNC (ASIMD)
-#elif defined(MY_CPU_ARM)
- #define MY_HWCAP_CHECK_FUNC(name) \
- BoolInt CPU_IsSupported_ ## name() { return (getauxval(AT_HWCAP2) & (HWCAP2_ ## name)) ? 1 : 0; }
- MY_HWCAP_CHECK_FUNC_2(NEON, NEON)
-#endif
-
-#else // USE_HWCAP
-
- #define MY_HWCAP_CHECK_FUNC(name) \
- BoolInt CPU_IsSupported_ ## name() { return 0; }
- MY_HWCAP_CHECK_FUNC(NEON)
-
-#endif // USE_HWCAP
-
-MY_HWCAP_CHECK_FUNC (CRC32)
-MY_HWCAP_CHECK_FUNC (SHA1)
-MY_HWCAP_CHECK_FUNC (SHA2)
-MY_HWCAP_CHECK_FUNC (AES)
-
-#endif
-#endif // __APPLE__
-#endif // _WIN32
-
-#endif // MY_CPU_ARM_OR_ARM64
-
-
-
-#ifdef __APPLE__
-
-#include
-
-int My_sysctlbyname_Get(const char *name, void *buf, size_t *bufSize)
-{
- return sysctlbyname(name, buf, bufSize, NULL, 0);
-}
-
-int My_sysctlbyname_Get_UInt32(const char *name, UInt32 *val)
-{
- size_t bufSize = sizeof(*val);
- int res = My_sysctlbyname_Get(name, val, &bufSize);
- if (res == 0 && bufSize != sizeof(*val))
- return EFAULT;
- return res;
-}
-
-#endif
diff --git a/deps/libchdr/deps/lzma-22.01/src/LzFindMt.c b/deps/libchdr/deps/lzma-22.01/src/LzFindMt.c
deleted file mode 100644
index 3865263b..00000000
--- a/deps/libchdr/deps/lzma-22.01/src/LzFindMt.c
+++ /dev/null
@@ -1,1400 +0,0 @@
-/* LzFindMt.c -- multithreaded Match finder for LZ algorithms
-2021-12-21 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-// #include
-
-#include "CpuArch.h"
-
-#include "LzHash.h"
-#include "LzFindMt.h"
-
-// #define LOG_ITERS
-
-// #define LOG_THREAD
-
-#ifdef LOG_THREAD
-#include
-#define PRF(x) x
-#else
-#define PRF(x)
-#endif
-
-#ifdef LOG_ITERS
-#include
-extern UInt64 g_NumIters_Tree;
-extern UInt64 g_NumIters_Loop;
-extern UInt64 g_NumIters_Bytes;
-#define LOG_ITER(x) x
-#else
-#define LOG_ITER(x)
-#endif
-
-#define kMtHashBlockSize ((UInt32)1 << 17)
-#define kMtHashNumBlocks (1 << 1)
-
-#define GET_HASH_BLOCK_OFFSET(i) (((i) & (kMtHashNumBlocks - 1)) * kMtHashBlockSize)
-
-#define kMtBtBlockSize ((UInt32)1 << 16)
-#define kMtBtNumBlocks (1 << 4)
-
-#define GET_BT_BLOCK_OFFSET(i) (((i) & (kMtBtNumBlocks - 1)) * (size_t)kMtBtBlockSize)
-
-/*
- HASH functions:
- We use raw 8/16 bits from a[1] and a[2],
- xored with crc(a[0]) and crc(a[3]).
- We check a[0], a[3] only. We don't need to compare a[1] and a[2] in matches.
- our crc() function provides one-to-one correspondence for low 8-bit values:
- (crc[0...0xFF] & 0xFF) <-> [0...0xFF]
-*/
-
-#define MF(mt) ((mt)->MatchFinder)
-#define MF_CRC (p->crc)
-
-// #define MF(mt) (&(mt)->MatchFinder)
-// #define MF_CRC (p->MatchFinder.crc)
-
-#define MT_HASH2_CALC \
- h2 = (MF_CRC[cur[0]] ^ cur[1]) & (kHash2Size - 1);
-
-#define MT_HASH3_CALC { \
- UInt32 temp = MF_CRC[cur[0]] ^ cur[1]; \
- h2 = temp & (kHash2Size - 1); \
- h3 = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); }
-
-/*
-#define MT_HASH3_CALC__NO_2 { \
- UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
- h3 = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); }
-
-#define __MT_HASH4_CALC { \
- UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
- h2 = temp & (kHash2Size - 1); \
- temp ^= ((UInt32)cur[2] << 8); \
- h3 = temp & (kHash3Size - 1); \
- h4 = (temp ^ (p->crc[cur[3]] << kLzHash_CrcShift_1)) & p->hash4Mask; }
- // (kHash4Size - 1);
-*/
-
-
-MY_NO_INLINE
-static void MtSync_Construct(CMtSync *p)
-{
- p->affinity = 0;
- p->wasCreated = False;
- p->csWasInitialized = False;
- p->csWasEntered = False;
- Thread_Construct(&p->thread);
- Event_Construct(&p->canStart);
- Event_Construct(&p->wasStopped);
- Semaphore_Construct(&p->freeSemaphore);
- Semaphore_Construct(&p->filledSemaphore);
-}
-
-
-#define DEBUG_BUFFER_LOCK // define it to debug lock state
-
-#ifdef DEBUG_BUFFER_LOCK
-#include
-#define BUFFER_MUST_BE_LOCKED(p) if (!(p)->csWasEntered) exit(1);
-#define BUFFER_MUST_BE_UNLOCKED(p) if ( (p)->csWasEntered) exit(1);
-#else
-#define BUFFER_MUST_BE_LOCKED(p)
-#define BUFFER_MUST_BE_UNLOCKED(p)
-#endif
-
-#define LOCK_BUFFER(p) { \
- BUFFER_MUST_BE_UNLOCKED(p); \
- CriticalSection_Enter(&(p)->cs); \
- (p)->csWasEntered = True; }
-
-#define UNLOCK_BUFFER(p) { \
- BUFFER_MUST_BE_LOCKED(p); \
- CriticalSection_Leave(&(p)->cs); \
- (p)->csWasEntered = False; }
-
-
-MY_NO_INLINE
-static UInt32 MtSync_GetNextBlock(CMtSync *p)
-{
- UInt32 numBlocks = 0;
- if (p->needStart)
- {
- BUFFER_MUST_BE_UNLOCKED(p)
- p->numProcessedBlocks = 1;
- p->needStart = False;
- p->stopWriting = False;
- p->exit = False;
- Event_Reset(&p->wasStopped);
- Event_Set(&p->canStart);
- }
- else
- {
- UNLOCK_BUFFER(p)
- // we free current block
- numBlocks = p->numProcessedBlocks++;
- Semaphore_Release1(&p->freeSemaphore);
- }
-
- // buffer is UNLOCKED here
- Semaphore_Wait(&p->filledSemaphore);
- LOCK_BUFFER(p);
- return numBlocks;
-}
-
-
-/* if Writing (Processing) thread was started, we must call MtSync_StopWriting() */
-
-MY_NO_INLINE
-static void MtSync_StopWriting(CMtSync *p)
-{
- if (!Thread_WasCreated(&p->thread) || p->needStart)
- return;
-
- PRF(printf("\nMtSync_StopWriting %p\n", p));
-
- if (p->csWasEntered)
- {
- /* we don't use buffer in this thread after StopWriting().
- So we UNLOCK buffer.
- And we restore default UNLOCKED state for stopped thread */
- UNLOCK_BUFFER(p)
- }
-
- /* We send (p->stopWriting) message and release freeSemaphore
- to free current block.
- So the thread will see (p->stopWriting) at some
- iteration after Wait(freeSemaphore).
- The thread doesn't need to fill all avail free blocks,
- so we can get fast thread stop.
- */
-
- p->stopWriting = True;
- Semaphore_Release1(&p->freeSemaphore); // check semaphore count !!!
-
- PRF(printf("\nMtSync_StopWriting %p : Event_Wait(&p->wasStopped)\n", p));
- Event_Wait(&p->wasStopped);
- PRF(printf("\nMtSync_StopWriting %p : Event_Wait() finsihed\n", p));
-
- /* 21.03 : we don't restore samaphore counters here.
- We will recreate and reinit samaphores in next start */
-
- p->needStart = True;
-}
-
-
-MY_NO_INLINE
-static void MtSync_Destruct(CMtSync *p)
-{
- PRF(printf("\nMtSync_Destruct %p\n", p));
-
- if (Thread_WasCreated(&p->thread))
- {
- /* we want thread to be in Stopped state before sending EXIT command.
- note: stop(btSync) will stop (htSync) also */
- MtSync_StopWriting(p);
- /* thread in Stopped state here : (p->needStart == true) */
- p->exit = True;
- // if (p->needStart) // it's (true)
- Event_Set(&p->canStart); // we send EXIT command to thread
- Thread_Wait_Close(&p->thread); // we wait thread finishing
- }
-
- if (p->csWasInitialized)
- {
- CriticalSection_Delete(&p->cs);
- p->csWasInitialized = False;
- }
- p->csWasEntered = False;
-
- Event_Close(&p->canStart);
- Event_Close(&p->wasStopped);
- Semaphore_Close(&p->freeSemaphore);
- Semaphore_Close(&p->filledSemaphore);
-
- p->wasCreated = False;
-}
-
-
-// #define RINOK_THREAD(x) { if ((x) != 0) return SZ_ERROR_THREAD; }
-// we want to get real system error codes here instead of SZ_ERROR_THREAD
-#define RINOK_THREAD(x) RINOK(x)
-
-
-// call it before each new file (when new starting is required):
-MY_NO_INLINE
-static SRes MtSync_Init(CMtSync *p, UInt32 numBlocks)
-{
- WRes wres;
- // BUFFER_MUST_BE_UNLOCKED(p)
- if (!p->needStart || p->csWasEntered)
- return SZ_ERROR_FAIL;
- wres = Semaphore_OptCreateInit(&p->freeSemaphore, numBlocks, numBlocks);
- if (wres == 0)
- wres = Semaphore_OptCreateInit(&p->filledSemaphore, 0, numBlocks);
- return MY_SRes_HRESULT_FROM_WRes(wres);
-}
-
-
-static WRes MtSync_Create_WRes(CMtSync *p, THREAD_FUNC_TYPE startAddress, void *obj)
-{
- WRes wres;
-
- if (p->wasCreated)
- return SZ_OK;
-
- RINOK_THREAD(CriticalSection_Init(&p->cs));
- p->csWasInitialized = True;
- p->csWasEntered = False;
-
- RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->canStart));
- RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->wasStopped));
-
- p->needStart = True;
- p->exit = True; /* p->exit is unused before (canStart) Event.
- But in case of some unexpected code failure we will get fast exit from thread */
-
- // return ERROR_TOO_MANY_POSTS; // for debug
- // return EINVAL; // for debug
-
- if (p->affinity != 0)
- wres = Thread_Create_With_Affinity(&p->thread, startAddress, obj, (CAffinityMask)p->affinity);
- else
- wres = Thread_Create(&p->thread, startAddress, obj);
-
- RINOK_THREAD(wres);
- p->wasCreated = True;
- return SZ_OK;
-}
-
-
-MY_NO_INLINE
-static SRes MtSync_Create(CMtSync *p, THREAD_FUNC_TYPE startAddress, void *obj)
-{
- const WRes wres = MtSync_Create_WRes(p, startAddress, obj);
- if (wres == 0)
- return 0;
- MtSync_Destruct(p);
- return MY_SRes_HRESULT_FROM_WRes(wres);
-}
-
-
-// ---------- HASH THREAD ----------
-
-#define kMtMaxValForNormalize 0xFFFFFFFF
-// #define kMtMaxValForNormalize ((1 << 21)) // for debug
-// #define kNormalizeAlign (1 << 7) // alignment for speculated accesses
-
-#ifdef MY_CPU_LE_UNALIGN
- #define GetUi24hi_from32(p) ((UInt32)GetUi32(p) >> 8)
-#else
- #define GetUi24hi_from32(p) ((p)[1] ^ ((UInt32)(p)[2] << 8) ^ ((UInt32)(p)[3] << 16))
-#endif
-
-#define GetHeads_DECL(name) \
- static void GetHeads ## name(const Byte *p, UInt32 pos, \
- UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc)
-
-#define GetHeads_LOOP(v) \
- for (; numHeads != 0; numHeads--) { \
- const UInt32 value = (v); \
- p++; \
- *heads++ = pos - hash[value]; \
- hash[value] = pos++; }
-
-#define DEF_GetHeads2(name, v, action) \
- GetHeads_DECL(name) { action \
- GetHeads_LOOP(v) }
-
-#define DEF_GetHeads(name, v) DEF_GetHeads2(name, v, ;)
-
-DEF_GetHeads2(2, GetUi16(p), UNUSED_VAR(hashMask); UNUSED_VAR(crc); )
-DEF_GetHeads(3, (crc[p[0]] ^ GetUi16(p + 1)) & hashMask)
-DEF_GetHeads2(3b, GetUi16(p) ^ ((UInt32)(p)[2] << 16), UNUSED_VAR(hashMask); UNUSED_VAR(crc); )
-// BT3 is not good for crc collisions for big hashMask values.
-
-/*
-GetHeads_DECL(3b)
-{
- UNUSED_VAR(hashMask);
- UNUSED_VAR(crc);
- {
- const Byte *pLim = p + numHeads;
- if (numHeads == 0)
- return;
- pLim--;
- while (p < pLim)
- {
- UInt32 v1 = GetUi32(p);
- UInt32 v0 = v1 & 0xFFFFFF;
- UInt32 h0, h1;
- p += 2;
- v1 >>= 8;
- h0 = hash[v0]; hash[v0] = pos; heads[0] = pos - h0; pos++;
- h1 = hash[v1]; hash[v1] = pos; heads[1] = pos - h1; pos++;
- heads += 2;
- }
- if (p == pLim)
- {
- UInt32 v0 = GetUi16(p) ^ ((UInt32)(p)[2] << 16);
- *heads = pos - hash[v0];
- hash[v0] = pos;
- }
- }
-}
-*/
-
-/*
-GetHeads_DECL(4)
-{
- unsigned sh = 0;
- UNUSED_VAR(crc)
- while ((hashMask & 0x80000000) == 0)
- {
- hashMask <<= 1;
- sh++;
- }
- GetHeads_LOOP((GetUi32(p) * 0xa54a1) >> sh)
-}
-#define GetHeads4b GetHeads4
-*/
-
-#define USE_GetHeads_LOCAL_CRC
-
-#ifdef USE_GetHeads_LOCAL_CRC
-
-GetHeads_DECL(4)
-{
- UInt32 crc0[256];
- UInt32 crc1[256];
- {
- unsigned i;
- for (i = 0; i < 256; i++)
- {
- UInt32 v = crc[i];
- crc0[i] = v & hashMask;
- crc1[i] = (v << kLzHash_CrcShift_1) & hashMask;
- // crc1[i] = rotlFixed(v, 8) & hashMask;
- }
- }
- GetHeads_LOOP(crc0[p[0]] ^ crc1[p[3]] ^ (UInt32)GetUi16(p+1))
-}
-
-GetHeads_DECL(4b)
-{
- UInt32 crc0[256];
- {
- unsigned i;
- for (i = 0; i < 256; i++)
- crc0[i] = crc[i] & hashMask;
- }
- GetHeads_LOOP(crc0[p[0]] ^ GetUi24hi_from32(p))
-}
-
-GetHeads_DECL(5)
-{
- UInt32 crc0[256];
- UInt32 crc1[256];
- UInt32 crc2[256];
- {
- unsigned i;
- for (i = 0; i < 256; i++)
- {
- UInt32 v = crc[i];
- crc0[i] = v & hashMask;
- crc1[i] = (v << kLzHash_CrcShift_1) & hashMask;
- crc2[i] = (v << kLzHash_CrcShift_2) & hashMask;
- }
- }
- GetHeads_LOOP(crc0[p[0]] ^ crc1[p[3]] ^ crc2[p[4]] ^ (UInt32)GetUi16(p+1))
-}
-
-GetHeads_DECL(5b)
-{
- UInt32 crc0[256];
- UInt32 crc1[256];
- {
- unsigned i;
- for (i = 0; i < 256; i++)
- {
- UInt32 v = crc[i];
- crc0[i] = v & hashMask;
- crc1[i] = (v << kLzHash_CrcShift_1) & hashMask;
- }
- }
- GetHeads_LOOP(crc0[p[0]] ^ crc1[p[4]] ^ GetUi24hi_from32(p))
-}
-
-#else
-
-DEF_GetHeads(4, (crc[p[0]] ^ (crc[p[3]] << kLzHash_CrcShift_1) ^ (UInt32)GetUi16(p+1)) & hashMask)
-DEF_GetHeads(4b, (crc[p[0]] ^ GetUi24hi_from32(p)) & hashMask)
-DEF_GetHeads(5, (crc[p[0]] ^ (crc[p[3]] << kLzHash_CrcShift_1) ^ (crc[p[4]] << kLzHash_CrcShift_2) ^ (UInt32)GetUi16(p + 1)) & hashMask)
-DEF_GetHeads(5b, (crc[p[0]] ^ (crc[p[4]] << kLzHash_CrcShift_1) ^ GetUi24hi_from32(p)) & hashMask)
-
-#endif
-
-
-static void HashThreadFunc(CMatchFinderMt *mt)
-{
- CMtSync *p = &mt->hashSync;
- PRF(printf("\nHashThreadFunc\n"));
-
- for (;;)
- {
- UInt32 blockIndex = 0;
- PRF(printf("\nHashThreadFunc : Event_Wait(&p->canStart)\n"));
- Event_Wait(&p->canStart);
- PRF(printf("\nHashThreadFunc : Event_Wait(&p->canStart) : after \n"));
- if (p->exit)
- {
- PRF(printf("\nHashThreadFunc : exit \n"));
- return;
- }
-
- MatchFinder_Init_HighHash(MF(mt));
-
- for (;;)
- {
- PRF(printf("Hash thread block = %d pos = %d\n", (unsigned)blockIndex, mt->MatchFinder->pos));
-
- {
- CMatchFinder *mf = MF(mt);
- if (MatchFinder_NeedMove(mf))
- {
- CriticalSection_Enter(&mt->btSync.cs);
- CriticalSection_Enter(&mt->hashSync.cs);
- {
- const Byte *beforePtr = Inline_MatchFinder_GetPointerToCurrentPos(mf);
- ptrdiff_t offset;
- MatchFinder_MoveBlock(mf);
- offset = beforePtr - Inline_MatchFinder_GetPointerToCurrentPos(mf);
- mt->pointerToCurPos -= offset;
- mt->buffer -= offset;
- }
- CriticalSection_Leave(&mt->hashSync.cs);
- CriticalSection_Leave(&mt->btSync.cs);
- continue;
- }
-
- Semaphore_Wait(&p->freeSemaphore);
-
- if (p->exit) // exit is unexpected here. But we check it here for some failure case
- return;
-
- // for faster stop : we check (p->stopWriting) after Wait(freeSemaphore)
- if (p->stopWriting)
- break;
-
- MatchFinder_ReadIfRequired(mf);
- {
- UInt32 *heads = mt->hashBuf + GET_HASH_BLOCK_OFFSET(blockIndex++);
- UInt32 num = Inline_MatchFinder_GetNumAvailableBytes(mf);
- heads[0] = 2;
- heads[1] = num;
-
- /* heads[1] contains the number of avail bytes:
- if (avail < mf->numHashBytes) :
- {
- it means that stream was finished
- HASH_THREAD and BT_TREAD must move position for heads[1] (avail) bytes.
- HASH_THREAD doesn't stop,
- HASH_THREAD fills only the header (2 numbers) for all next blocks:
- {2, NumHashBytes - 1}, {2,0}, {2,0}, ... , {2,0}
- }
- else
- {
- HASH_THREAD and BT_TREAD must move position for (heads[0] - 2) bytes;
- }
- */
-
- if (num >= mf->numHashBytes)
- {
- num = num - mf->numHashBytes + 1;
- if (num > kMtHashBlockSize - 2)
- num = kMtHashBlockSize - 2;
-
- if (mf->pos > (UInt32)kMtMaxValForNormalize - num)
- {
- const UInt32 subValue = (mf->pos - mf->historySize - 1); // & ~(UInt32)(kNormalizeAlign - 1);
- Inline_MatchFinder_ReduceOffsets(mf, subValue);
- MatchFinder_Normalize3(subValue, mf->hash + mf->fixedHashSize, (size_t)mf->hashMask + 1);
- }
-
- heads[0] = 2 + num;
- mt->GetHeadsFunc(mf->buffer, mf->pos, mf->hash + mf->fixedHashSize, mf->hashMask, heads + 2, num, mf->crc);
- }
-
- mf->pos += num; // wrap over zero is allowed at the end of stream
- mf->buffer += num;
- }
- }
-
- Semaphore_Release1(&p->filledSemaphore);
- } // for() processing end
-
- // p->numBlocks_Sent = blockIndex;
- Event_Set(&p->wasStopped);
- } // for() thread end
-}
-
-
-
-
-// ---------- BT THREAD ----------
-
-/* we use one variable instead of two (cyclicBufferPos == pos) before CyclicBuf wrap.
- here we define fixed offset of (p->pos) from (p->cyclicBufferPos) */
-#define CYC_TO_POS_OFFSET 0
-// #define CYC_TO_POS_OFFSET 1 // for debug
-
-#define MFMT_GM_INLINE
-
-#ifdef MFMT_GM_INLINE
-
-/*
- we use size_t for (pos) instead of UInt32
- to eliminate "movsx" BUG in old MSVC x64 compiler.
-*/
-
-
-UInt32 * MY_FAST_CALL GetMatchesSpecN_2(const Byte *lenLimit, size_t pos, const Byte *cur, CLzRef *son,
- UInt32 _cutValue, UInt32 *d, size_t _maxLen, const UInt32 *hash, const UInt32 *limit, const UInt32 *size,
- size_t _cyclicBufferPos, UInt32 _cyclicBufferSize,
- UInt32 *posRes);
-
-#endif
-
-
-static void BtGetMatches(CMatchFinderMt *p, UInt32 *d)
-{
- UInt32 numProcessed = 0;
- UInt32 curPos = 2;
-
- /* GetMatchesSpec() functions don't create (len = 1)
- in [len, dist] match pairs, if (p->numHashBytes >= 2)
- Also we suppose here that (matchMaxLen >= 2).
- So the following code for (reserve) is not required
- UInt32 reserve = (p->matchMaxLen * 2);
- const UInt32 kNumHashBytes_Max = 5; // BT_HASH_BYTES_MAX
- if (reserve < kNumHashBytes_Max - 1)
- reserve = kNumHashBytes_Max - 1;
- const UInt32 limit = kMtBtBlockSize - (reserve);
- */
-
- const UInt32 limit = kMtBtBlockSize - (p->matchMaxLen * 2);
-
- d[1] = p->hashNumAvail;
-
- if (p->failure_BT)
- {
- // printf("\n == 1 BtGetMatches() p->failure_BT\n");
- d[0] = 0;
- // d[1] = 0;
- return;
- }
-
- while (curPos < limit)
- {
- if (p->hashBufPos == p->hashBufPosLimit)
- {
- // MatchFinderMt_GetNextBlock_Hash(p);
- UInt32 avail;
- {
- const UInt32 bi = MtSync_GetNextBlock(&p->hashSync);
- const UInt32 k = GET_HASH_BLOCK_OFFSET(bi);
- const UInt32 *h = p->hashBuf + k;
- avail = h[1];
- p->hashBufPosLimit = k + h[0];
- p->hashNumAvail = avail;
- p->hashBufPos = k + 2;
- }
-
- {
- /* we must prevent UInt32 overflow for avail total value,
- if avail was increased with new hash block */
- UInt32 availSum = numProcessed + avail;
- if (availSum < numProcessed)
- availSum = (UInt32)(Int32)-1;
- d[1] = availSum;
- }
-
- if (avail >= p->numHashBytes)
- continue;
-
- // if (p->hashBufPos != p->hashBufPosLimit) exit(1);
-
- /* (avail < p->numHashBytes)
- It means that stream was finished.
- And (avail) - is a number of remaining bytes,
- we fill (d) for (avail) bytes for LZ_THREAD (receiver).
- but we don't update (p->pos) and (p->cyclicBufferPos) here in BT_THREAD */
-
- /* here we suppose that we have space enough:
- (kMtBtBlockSize - curPos >= p->hashNumAvail) */
- p->hashNumAvail = 0;
- d[0] = curPos + avail;
- d += curPos;
- for (; avail != 0; avail--)
- *d++ = 0;
- return;
- }
- {
- UInt32 size = p->hashBufPosLimit - p->hashBufPos;
- UInt32 pos = p->pos;
- UInt32 cyclicBufferPos = p->cyclicBufferPos;
- UInt32 lenLimit = p->matchMaxLen;
- if (lenLimit >= p->hashNumAvail)
- lenLimit = p->hashNumAvail;
- {
- UInt32 size2 = p->hashNumAvail - lenLimit + 1;
- if (size2 < size)
- size = size2;
- size2 = p->cyclicBufferSize - cyclicBufferPos;
- if (size2 < size)
- size = size2;
- }
-
- if (pos > (UInt32)kMtMaxValForNormalize - size)
- {
- const UInt32 subValue = (pos - p->cyclicBufferSize); // & ~(UInt32)(kNormalizeAlign - 1);
- pos -= subValue;
- p->pos = pos;
- MatchFinder_Normalize3(subValue, p->son, (size_t)p->cyclicBufferSize * 2);
- }
-
- #ifndef MFMT_GM_INLINE
- while (curPos < limit && size-- != 0)
- {
- UInt32 *startDistances = d + curPos;
- UInt32 num = (UInt32)(GetMatchesSpec1(lenLimit, pos - p->hashBuf[p->hashBufPos++],
- pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue,
- startDistances + 1, p->numHashBytes - 1) - startDistances);
- *startDistances = num - 1;
- curPos += num;
- cyclicBufferPos++;
- pos++;
- p->buffer++;
- }
- #else
- {
- UInt32 posRes = pos;
- const UInt32 *d_end;
- {
- d_end = GetMatchesSpecN_2(
- p->buffer + lenLimit - 1,
- pos, p->buffer, p->son, p->cutValue, d + curPos,
- p->numHashBytes - 1, p->hashBuf + p->hashBufPos,
- d + limit, p->hashBuf + p->hashBufPos + size,
- cyclicBufferPos, p->cyclicBufferSize,
- &posRes);
- }
- {
- if (!d_end)
- {
- // printf("\n == 2 BtGetMatches() p->failure_BT\n");
- // internal data failure
- p->failure_BT = True;
- d[0] = 0;
- // d[1] = 0;
- return;
- }
- }
- curPos = (UInt32)(d_end - d);
- {
- const UInt32 processed = posRes - pos;
- pos = posRes;
- p->hashBufPos += processed;
- cyclicBufferPos += processed;
- p->buffer += processed;
- }
- }
- #endif
-
- {
- const UInt32 processed = pos - p->pos;
- numProcessed += processed;
- p->hashNumAvail -= processed;
- p->pos = pos;
- }
- if (cyclicBufferPos == p->cyclicBufferSize)
- cyclicBufferPos = 0;
- p->cyclicBufferPos = cyclicBufferPos;
- }
- }
-
- d[0] = curPos;
-}
-
-
-static void BtFillBlock(CMatchFinderMt *p, UInt32 globalBlockIndex)
-{
- CMtSync *sync = &p->hashSync;
-
- BUFFER_MUST_BE_UNLOCKED(sync)
-
- if (!sync->needStart)
- {
- LOCK_BUFFER(sync)
- }
-
- BtGetMatches(p, p->btBuf + GET_BT_BLOCK_OFFSET(globalBlockIndex));
-
- /* We suppose that we have called GetNextBlock() from start.
- So buffer is LOCKED */
-
- UNLOCK_BUFFER(sync)
-}
-
-
-MY_NO_INLINE
-static void BtThreadFunc(CMatchFinderMt *mt)
-{
- CMtSync *p = &mt->btSync;
- for (;;)
- {
- UInt32 blockIndex = 0;
- Event_Wait(&p->canStart);
-
- for (;;)
- {
- PRF(printf(" BT thread block = %d pos = %d\n", (unsigned)blockIndex, mt->pos));
- /* (p->exit == true) is possible after (p->canStart) at first loop iteration
- and is unexpected after more Wait(freeSemaphore) iterations */
- if (p->exit)
- return;
-
- Semaphore_Wait(&p->freeSemaphore);
-
- // for faster stop : we check (p->stopWriting) after Wait(freeSemaphore)
- if (p->stopWriting)
- break;
-
- BtFillBlock(mt, blockIndex++);
-
- Semaphore_Release1(&p->filledSemaphore);
- }
-
- // we stop HASH_THREAD here
- MtSync_StopWriting(&mt->hashSync);
-
- // p->numBlocks_Sent = blockIndex;
- Event_Set(&p->wasStopped);
- }
-}
-
-
-void MatchFinderMt_Construct(CMatchFinderMt *p)
-{
- p->hashBuf = NULL;
- MtSync_Construct(&p->hashSync);
- MtSync_Construct(&p->btSync);
-}
-
-static void MatchFinderMt_FreeMem(CMatchFinderMt *p, ISzAllocPtr alloc)
-{
- ISzAlloc_Free(alloc, p->hashBuf);
- p->hashBuf = NULL;
-}
-
-void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAllocPtr alloc)
-{
- /*
- HASH_THREAD can use CriticalSection(s) btSync.cs and hashSync.cs.
- So we must be sure that HASH_THREAD will not use CriticalSection(s)
- after deleting CriticalSection here.
-
- we call ReleaseStream(p)
- that calls StopWriting(btSync)
- that calls StopWriting(hashSync), if it's required to stop HASH_THREAD.
- after StopWriting() it's safe to destruct MtSync(s) in any order */
-
- MatchFinderMt_ReleaseStream(p);
-
- MtSync_Destruct(&p->btSync);
- MtSync_Destruct(&p->hashSync);
-
- LOG_ITER(
- printf("\nTree %9d * %7d iter = %9d = sum : bytes = %9d\n",
- (UInt32)(g_NumIters_Tree / 1000),
- (UInt32)(((UInt64)g_NumIters_Loop * 1000) / (g_NumIters_Tree + 1)),
- (UInt32)(g_NumIters_Loop / 1000),
- (UInt32)(g_NumIters_Bytes / 1000)
- ));
-
- MatchFinderMt_FreeMem(p, alloc);
-}
-
-
-#define kHashBufferSize (kMtHashBlockSize * kMtHashNumBlocks)
-#define kBtBufferSize (kMtBtBlockSize * kMtBtNumBlocks)
-
-
-static THREAD_FUNC_DECL HashThreadFunc2(void *p) { HashThreadFunc((CMatchFinderMt *)p); return 0; }
-static THREAD_FUNC_DECL BtThreadFunc2(void *p)
-{
- Byte allocaDummy[0x180];
- unsigned i = 0;
- for (i = 0; i < 16; i++)
- allocaDummy[i] = (Byte)0;
- if (allocaDummy[0] == 0)
- BtThreadFunc((CMatchFinderMt *)p);
- return 0;
-}
-
-
-SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore,
- UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAllocPtr alloc)
-{
- CMatchFinder *mf = MF(p);
- p->historySize = historySize;
- if (kMtBtBlockSize <= matchMaxLen * 4)
- return SZ_ERROR_PARAM;
- if (!p->hashBuf)
- {
- p->hashBuf = (UInt32 *)ISzAlloc_Alloc(alloc, ((size_t)kHashBufferSize + (size_t)kBtBufferSize) * sizeof(UInt32));
- if (!p->hashBuf)
- return SZ_ERROR_MEM;
- p->btBuf = p->hashBuf + kHashBufferSize;
- }
- keepAddBufferBefore += (kHashBufferSize + kBtBufferSize);
- keepAddBufferAfter += kMtHashBlockSize;
- if (!MatchFinder_Create(mf, historySize, keepAddBufferBefore, matchMaxLen, keepAddBufferAfter, alloc))
- return SZ_ERROR_MEM;
-
- RINOK(MtSync_Create(&p->hashSync, HashThreadFunc2, p));
- RINOK(MtSync_Create(&p->btSync, BtThreadFunc2, p));
- return SZ_OK;
-}
-
-
-SRes MatchFinderMt_InitMt(CMatchFinderMt *p)
-{
- RINOK(MtSync_Init(&p->hashSync, kMtHashNumBlocks));
- return MtSync_Init(&p->btSync, kMtBtNumBlocks);
-}
-
-
-static void MatchFinderMt_Init(CMatchFinderMt *p)
-{
- CMatchFinder *mf = MF(p);
-
- p->btBufPos =
- p->btBufPosLimit = NULL;
- p->hashBufPos =
- p->hashBufPosLimit = 0;
- p->hashNumAvail = 0; // 21.03
-
- p->failure_BT = False;
-
- /* Init without data reading. We don't want to read data in this thread */
- MatchFinder_Init_4(mf);
-
- MatchFinder_Init_LowHash(mf);
-
- p->pointerToCurPos = Inline_MatchFinder_GetPointerToCurrentPos(mf);
- p->btNumAvailBytes = 0;
- p->failure_LZ_BT = False;
- // p->failure_LZ_LZ = False;
-
- p->lzPos =
- 1; // optimal smallest value
- // 0; // for debug: ignores match to start
- // kNormalizeAlign; // for debug
-
- p->hash = mf->hash;
- p->fixedHashSize = mf->fixedHashSize;
- // p->hash4Mask = mf->hash4Mask;
- p->crc = mf->crc;
- // memcpy(p->crc, mf->crc, sizeof(mf->crc));
-
- p->son = mf->son;
- p->matchMaxLen = mf->matchMaxLen;
- p->numHashBytes = mf->numHashBytes;
-
- /* (mf->pos) and (mf->streamPos) were already initialized to 1 in MatchFinder_Init_4() */
- // mf->streamPos = mf->pos = 1; // optimal smallest value
- // 0; // for debug: ignores match to start
- // kNormalizeAlign; // for debug
-
- /* we must init (p->pos = mf->pos) for BT, because
- BT code needs (p->pos == delta_value_for_empty_hash_record == mf->pos) */
- p->pos = mf->pos; // do not change it
-
- p->cyclicBufferPos = (p->pos - CYC_TO_POS_OFFSET);
- p->cyclicBufferSize = mf->cyclicBufferSize;
- p->buffer = mf->buffer;
- p->cutValue = mf->cutValue;
- // p->son[0] = p->son[1] = 0; // unused: to init skipped record for speculated accesses.
-}
-
-
-/* ReleaseStream is required to finish multithreading */
-void MatchFinderMt_ReleaseStream(CMatchFinderMt *p)
-{
- // Sleep(1); // for debug
- MtSync_StopWriting(&p->btSync);
- // Sleep(200); // for debug
- /* p->MatchFinder->ReleaseStream(); */
-}
-
-
-MY_NO_INLINE
-static UInt32 MatchFinderMt_GetNextBlock_Bt(CMatchFinderMt *p)
-{
- if (p->failure_LZ_BT)
- p->btBufPos = p->failureBuf;
- else
- {
- const UInt32 bi = MtSync_GetNextBlock(&p->btSync);
- const UInt32 *bt = p->btBuf + GET_BT_BLOCK_OFFSET(bi);
- {
- const UInt32 numItems = bt[0];
- p->btBufPosLimit = bt + numItems;
- p->btNumAvailBytes = bt[1];
- p->btBufPos = bt + 2;
- if (numItems < 2 || numItems > kMtBtBlockSize)
- {
- p->failureBuf[0] = 0;
- p->btBufPos = p->failureBuf;
- p->btBufPosLimit = p->failureBuf + 1;
- p->failure_LZ_BT = True;
- // p->btNumAvailBytes = 0;
- /* we don't want to decrease AvailBytes, that was load before.
- that can be unxepected for the code that have loaded anopther value before */
- }
- }
-
- if (p->lzPos >= (UInt32)kMtMaxValForNormalize - (UInt32)kMtBtBlockSize)
- {
- /* we don't check (lzPos) over exact avail bytes in (btBuf).
- (fixedHashSize) is small, so normalization is fast */
- const UInt32 subValue = (p->lzPos - p->historySize - 1); // & ~(UInt32)(kNormalizeAlign - 1);
- p->lzPos -= subValue;
- MatchFinder_Normalize3(subValue, p->hash, p->fixedHashSize);
- }
- }
- return p->btNumAvailBytes;
-}
-
-
-
-static const Byte * MatchFinderMt_GetPointerToCurrentPos(CMatchFinderMt *p)
-{
- return p->pointerToCurPos;
-}
-
-
-#define GET_NEXT_BLOCK_IF_REQUIRED if (p->btBufPos == p->btBufPosLimit) MatchFinderMt_GetNextBlock_Bt(p);
-
-
-static UInt32 MatchFinderMt_GetNumAvailableBytes(CMatchFinderMt *p)
-{
- if (p->btBufPos != p->btBufPosLimit)
- return p->btNumAvailBytes;
- return MatchFinderMt_GetNextBlock_Bt(p);
-}
-
-
-// #define CHECK_FAILURE_LZ(_match_, _pos_) if (_match_ >= _pos_) { p->failure_LZ_LZ = True; return d; }
-#define CHECK_FAILURE_LZ(_match_, _pos_)
-
-static UInt32 * MixMatches2(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *d)
-{
- UInt32 h2, c2;
- UInt32 *hash = p->hash;
- const Byte *cur = p->pointerToCurPos;
- const UInt32 m = p->lzPos;
- MT_HASH2_CALC
-
- c2 = hash[h2];
- hash[h2] = m;
-
- if (c2 >= matchMinPos)
- {
- CHECK_FAILURE_LZ(c2, m)
- if (cur[(ptrdiff_t)c2 - (ptrdiff_t)m] == cur[0])
- {
- *d++ = 2;
- *d++ = m - c2 - 1;
- }
- }
-
- return d;
-}
-
-static UInt32 * MixMatches3(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *d)
-{
- UInt32 h2, h3, c2, c3;
- UInt32 *hash = p->hash;
- const Byte *cur = p->pointerToCurPos;
- const UInt32 m = p->lzPos;
- MT_HASH3_CALC
-
- c2 = hash[h2];
- c3 = (hash + kFix3HashSize)[h3];
-
- hash[h2] = m;
- (hash + kFix3HashSize)[h3] = m;
-
- if (c2 >= matchMinPos)
- {
- CHECK_FAILURE_LZ(c2, m)
- if (cur[(ptrdiff_t)c2 - (ptrdiff_t)m] == cur[0])
- {
- d[1] = m - c2 - 1;
- if (cur[(ptrdiff_t)c2 - (ptrdiff_t)m + 2] == cur[2])
- {
- d[0] = 3;
- return d + 2;
- }
- d[0] = 2;
- d += 2;
- }
- }
-
- if (c3 >= matchMinPos)
- {
- CHECK_FAILURE_LZ(c3, m)
- if (cur[(ptrdiff_t)c3 - (ptrdiff_t)m] == cur[0])
- {
- *d++ = 3;
- *d++ = m - c3 - 1;
- }
- }
-
- return d;
-}
-
-
-#define INCREASE_LZ_POS p->lzPos++; p->pointerToCurPos++;
-
-/*
-static
-UInt32* MatchFinderMt_GetMatches_Bt4(CMatchFinderMt *p, UInt32 *d)
-{
- const UInt32 *bt = p->btBufPos;
- const UInt32 len = *bt++;
- const UInt32 *btLim = bt + len;
- UInt32 matchMinPos;
- UInt32 avail = p->btNumAvailBytes - 1;
- p->btBufPos = btLim;
-
- {
- p->btNumAvailBytes = avail;
-
- #define BT_HASH_BYTES_MAX 5
-
- matchMinPos = p->lzPos;
-
- if (len != 0)
- matchMinPos -= bt[1];
- else if (avail < (BT_HASH_BYTES_MAX - 1) - 1)
- {
- INCREASE_LZ_POS
- return d;
- }
- else
- {
- const UInt32 hs = p->historySize;
- if (matchMinPos > hs)
- matchMinPos -= hs;
- else
- matchMinPos = 1;
- }
- }
-
- for (;;)
- {
-
- UInt32 h2, h3, c2, c3;
- UInt32 *hash = p->hash;
- const Byte *cur = p->pointerToCurPos;
- UInt32 m = p->lzPos;
- MT_HASH3_CALC
-
- c2 = hash[h2];
- c3 = (hash + kFix3HashSize)[h3];
-
- hash[h2] = m;
- (hash + kFix3HashSize)[h3] = m;
-
- if (c2 >= matchMinPos && cur[(ptrdiff_t)c2 - (ptrdiff_t)m] == cur[0])
- {
- d[1] = m - c2 - 1;
- if (cur[(ptrdiff_t)c2 - (ptrdiff_t)m + 2] == cur[2])
- {
- d[0] = 3;
- d += 2;
- break;
- }
- // else
- {
- d[0] = 2;
- d += 2;
- }
- }
- if (c3 >= matchMinPos && cur[(ptrdiff_t)c3 - (ptrdiff_t)m] == cur[0])
- {
- *d++ = 3;
- *d++ = m - c3 - 1;
- }
- break;
- }
-
- if (len != 0)
- {
- do
- {
- const UInt32 v0 = bt[0];
- const UInt32 v1 = bt[1];
- bt += 2;
- d[0] = v0;
- d[1] = v1;
- d += 2;
- }
- while (bt != btLim);
- }
- INCREASE_LZ_POS
- return d;
-}
-*/
-
-
-static UInt32 *MixMatches4(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *d)
-{
- UInt32 h2, h3, /* h4, */ c2, c3 /* , c4 */;
- UInt32 *hash = p->hash;
- const Byte *cur = p->pointerToCurPos;
- const UInt32 m = p->lzPos;
- MT_HASH3_CALC
- // MT_HASH4_CALC
- c2 = hash[h2];
- c3 = (hash + kFix3HashSize)[h3];
- // c4 = (hash + kFix4HashSize)[h4];
-
- hash[h2] = m;
- (hash + kFix3HashSize)[h3] = m;
- // (hash + kFix4HashSize)[h4] = m;
-
- #define _USE_H2
-
- #ifdef _USE_H2
- if (c2 >= matchMinPos && cur[(ptrdiff_t)c2 - (ptrdiff_t)m] == cur[0])
- {
- d[1] = m - c2 - 1;
- if (cur[(ptrdiff_t)c2 - (ptrdiff_t)m + 2] == cur[2])
- {
- // d[0] = (cur[(ptrdiff_t)c2 - (ptrdiff_t)m + 3] == cur[3]) ? 4 : 3;
- // return d + 2;
-
- if (cur[(ptrdiff_t)c2 - (ptrdiff_t)m + 3] == cur[3])
- {
- d[0] = 4;
- return d + 2;
- }
- d[0] = 3;
- d += 2;
-
- #ifdef _USE_H4
- if (c4 >= matchMinPos)
- if (
- cur[(ptrdiff_t)c4 - (ptrdiff_t)m] == cur[0] &&
- cur[(ptrdiff_t)c4 - (ptrdiff_t)m + 3] == cur[3]
- )
- {
- *d++ = 4;
- *d++ = m - c4 - 1;
- }
- #endif
- return d;
- }
- d[0] = 2;
- d += 2;
- }
- #endif
-
- if (c3 >= matchMinPos && cur[(ptrdiff_t)c3 - (ptrdiff_t)m] == cur[0])
- {
- d[1] = m - c3 - 1;
- if (cur[(ptrdiff_t)c3 - (ptrdiff_t)m + 3] == cur[3])
- {
- d[0] = 4;
- return d + 2;
- }
- d[0] = 3;
- d += 2;
- }
-
- #ifdef _USE_H4
- if (c4 >= matchMinPos)
- if (
- cur[(ptrdiff_t)c4 - (ptrdiff_t)m] == cur[0] &&
- cur[(ptrdiff_t)c4 - (ptrdiff_t)m + 3] == cur[3]
- )
- {
- *d++ = 4;
- *d++ = m - c4 - 1;
- }
- #endif
-
- return d;
-}
-
-
-static UInt32* MatchFinderMt2_GetMatches(CMatchFinderMt *p, UInt32 *d)
-{
- const UInt32 *bt = p->btBufPos;
- const UInt32 len = *bt++;
- const UInt32 *btLim = bt + len;
- p->btBufPos = btLim;
- p->btNumAvailBytes--;
- INCREASE_LZ_POS
- {
- while (bt != btLim)
- {
- const UInt32 v0 = bt[0];
- const UInt32 v1 = bt[1];
- bt += 2;
- d[0] = v0;
- d[1] = v1;
- d += 2;
- }
- }
- return d;
-}
-
-
-
-static UInt32* MatchFinderMt_GetMatches(CMatchFinderMt *p, UInt32 *d)
-{
- const UInt32 *bt = p->btBufPos;
- UInt32 len = *bt++;
- const UInt32 avail = p->btNumAvailBytes - 1;
- p->btNumAvailBytes = avail;
- p->btBufPos = bt + len;
- if (len == 0)
- {
- #define BT_HASH_BYTES_MAX 5
- if (avail >= (BT_HASH_BYTES_MAX - 1) - 1)
- {
- UInt32 m = p->lzPos;
- if (m > p->historySize)
- m -= p->historySize;
- else
- m = 1;
- d = p->MixMatchesFunc(p, m, d);
- }
- }
- else
- {
- /*
- first match pair from BinTree: (match_len, match_dist),
- (match_len >= numHashBytes).
- MixMatchesFunc() inserts only hash matches that are nearer than (match_dist)
- */
- d = p->MixMatchesFunc(p, p->lzPos - bt[1], d);
- // if (d) // check for failure
- do
- {
- const UInt32 v0 = bt[0];
- const UInt32 v1 = bt[1];
- bt += 2;
- d[0] = v0;
- d[1] = v1;
- d += 2;
- }
- while (len -= 2);
- }
- INCREASE_LZ_POS
- return d;
-}
-
-#define SKIP_HEADER2_MT do { GET_NEXT_BLOCK_IF_REQUIRED
-#define SKIP_HEADER_MT(n) SKIP_HEADER2_MT if (p->btNumAvailBytes-- >= (n)) { const Byte *cur = p->pointerToCurPos; UInt32 *hash = p->hash;
-#define SKIP_FOOTER_MT } INCREASE_LZ_POS p->btBufPos += (size_t)*p->btBufPos + 1; } while (--num != 0);
-
-static void MatchFinderMt0_Skip(CMatchFinderMt *p, UInt32 num)
-{
- SKIP_HEADER2_MT { p->btNumAvailBytes--;
- SKIP_FOOTER_MT
-}
-
-static void MatchFinderMt2_Skip(CMatchFinderMt *p, UInt32 num)
-{
- SKIP_HEADER_MT(2)
- UInt32 h2;
- MT_HASH2_CALC
- hash[h2] = p->lzPos;
- SKIP_FOOTER_MT
-}
-
-static void MatchFinderMt3_Skip(CMatchFinderMt *p, UInt32 num)
-{
- SKIP_HEADER_MT(3)
- UInt32 h2, h3;
- MT_HASH3_CALC
- (hash + kFix3HashSize)[h3] =
- hash[ h2] =
- p->lzPos;
- SKIP_FOOTER_MT
-}
-
-/*
-// MatchFinderMt4_Skip() is similar to MatchFinderMt3_Skip().
-// The difference is that MatchFinderMt3_Skip() updates hash for last 3 bytes of stream.
-
-static void MatchFinderMt4_Skip(CMatchFinderMt *p, UInt32 num)
-{
- SKIP_HEADER_MT(4)
- UInt32 h2, h3; // h4
- MT_HASH3_CALC
- // MT_HASH4_CALC
- // (hash + kFix4HashSize)[h4] =
- (hash + kFix3HashSize)[h3] =
- hash[ h2] =
- p->lzPos;
- SKIP_FOOTER_MT
-}
-*/
-
-void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder2 *vTable)
-{
- vTable->Init = (Mf_Init_Func)MatchFinderMt_Init;
- vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinderMt_GetNumAvailableBytes;
- vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinderMt_GetPointerToCurrentPos;
- vTable->GetMatches = (Mf_GetMatches_Func)MatchFinderMt_GetMatches;
-
- switch (MF(p)->numHashBytes)
- {
- case 2:
- p->GetHeadsFunc = GetHeads2;
- p->MixMatchesFunc = (Mf_Mix_Matches)NULL;
- vTable->Skip = (Mf_Skip_Func)MatchFinderMt0_Skip;
- vTable->GetMatches = (Mf_GetMatches_Func)MatchFinderMt2_GetMatches;
- break;
- case 3:
- p->GetHeadsFunc = MF(p)->bigHash ? GetHeads3b : GetHeads3;
- p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches2;
- vTable->Skip = (Mf_Skip_Func)MatchFinderMt2_Skip;
- break;
- case 4:
- p->GetHeadsFunc = MF(p)->bigHash ? GetHeads4b : GetHeads4;
-
- // it's fast inline version of GetMatches()
- // vTable->GetMatches = (Mf_GetMatches_Func)MatchFinderMt_GetMatches_Bt4;
-
- p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches3;
- vTable->Skip = (Mf_Skip_Func)MatchFinderMt3_Skip;
- break;
- default:
- p->GetHeadsFunc = MF(p)->bigHash ? GetHeads5b : GetHeads5;
- p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches4;
- vTable->Skip =
- (Mf_Skip_Func)MatchFinderMt3_Skip;
- // (Mf_Skip_Func)MatchFinderMt4_Skip;
- break;
- }
-}
diff --git a/deps/libchdr/deps/lzma-22.01/src/LzFindOpt.c b/deps/libchdr/deps/lzma-22.01/src/LzFindOpt.c
deleted file mode 100644
index dbb6ad9f..00000000
--- a/deps/libchdr/deps/lzma-22.01/src/LzFindOpt.c
+++ /dev/null
@@ -1,578 +0,0 @@
-/* LzFindOpt.c -- multithreaded Match finder for LZ algorithms
-2021-07-13 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#include "CpuArch.h"
-#include "LzFind.h"
-
-// #include "LzFindMt.h"
-
-// #define LOG_ITERS
-
-// #define LOG_THREAD
-
-#ifdef LOG_THREAD
-#include
-#define PRF(x) x
-#else
-// #define PRF(x)
-#endif
-
-#ifdef LOG_ITERS
-#include
-UInt64 g_NumIters_Tree;
-UInt64 g_NumIters_Loop;
-UInt64 g_NumIters_Bytes;
-#define LOG_ITER(x) x
-#else
-#define LOG_ITER(x)
-#endif
-
-// ---------- BT THREAD ----------
-
-#define USE_SON_PREFETCH
-#define USE_LONG_MATCH_OPT
-
-#define kEmptyHashValue 0
-
-// #define CYC_TO_POS_OFFSET 0
-
-// #define CYC_TO_POS_OFFSET 1 // for debug
-
-/*
-MY_NO_INLINE
-UInt32 * MY_FAST_CALL GetMatchesSpecN_1(const Byte *lenLimit, size_t pos, const Byte *cur, CLzRef *son,
- UInt32 _cutValue, UInt32 *d, size_t _maxLen, const UInt32 *hash, const UInt32 *limit, const UInt32 *size, UInt32 *posRes)
-{
- do
- {
- UInt32 delta;
- if (hash == size)
- break;
- delta = *hash++;
-
- if (delta == 0 || delta > (UInt32)pos)
- return NULL;
-
- lenLimit++;
-
- if (delta == (UInt32)pos)
- {
- CLzRef *ptr1 = son + ((size_t)pos << 1) - CYC_TO_POS_OFFSET * 2;
- *d++ = 0;
- ptr1[0] = kEmptyHashValue;
- ptr1[1] = kEmptyHashValue;
- }
-else
-{
- UInt32 *_distances = ++d;
-
- CLzRef *ptr0 = son + ((size_t)(pos) << 1) - CYC_TO_POS_OFFSET * 2 + 1;
- CLzRef *ptr1 = son + ((size_t)(pos) << 1) - CYC_TO_POS_OFFSET * 2;
-
- const Byte *len0 = cur, *len1 = cur;
- UInt32 cutValue = _cutValue;
- const Byte *maxLen = cur + _maxLen;
-
- for (LOG_ITER(g_NumIters_Tree++);;)
- {
- LOG_ITER(g_NumIters_Loop++);
- {
- const ptrdiff_t diff = (ptrdiff_t)0 - (ptrdiff_t)delta;
- CLzRef *pair = son + ((size_t)(((ptrdiff_t)pos - CYC_TO_POS_OFFSET) + diff) << 1);
- const Byte *len = (len0 < len1 ? len0 : len1);
-
- #ifdef USE_SON_PREFETCH
- const UInt32 pair0 = *pair;
- #endif
-
- if (len[diff] == len[0])
- {
- if (++len != lenLimit && len[diff] == len[0])
- while (++len != lenLimit)
- {
- LOG_ITER(g_NumIters_Bytes++);
- if (len[diff] != len[0])
- break;
- }
- if (maxLen < len)
- {
- maxLen = len;
- *d++ = (UInt32)(len - cur);
- *d++ = delta - 1;
-
- if (len == lenLimit)
- {
- const UInt32 pair1 = pair[1];
- *ptr1 =
- #ifdef USE_SON_PREFETCH
- pair0;
- #else
- pair[0];
- #endif
- *ptr0 = pair1;
-
- _distances[-1] = (UInt32)(d - _distances);
-
- #ifdef USE_LONG_MATCH_OPT
-
- if (hash == size || *hash != delta || lenLimit[diff] != lenLimit[0] || d >= limit)
- break;
-
- {
- for (;;)
- {
- hash++;
- pos++;
- cur++;
- lenLimit++;
- {
- CLzRef *ptr = son + ((size_t)(pos) << 1) - CYC_TO_POS_OFFSET * 2;
- #if 0
- *(UInt64 *)(void *)ptr = ((const UInt64 *)(const void *)ptr)[diff];
- #else
- const UInt32 p0 = ptr[0 + (diff * 2)];
- const UInt32 p1 = ptr[1 + (diff * 2)];
- ptr[0] = p0;
- ptr[1] = p1;
- // ptr[0] = ptr[0 + (diff * 2)];
- // ptr[1] = ptr[1 + (diff * 2)];
- #endif
- }
- // PrintSon(son + 2, pos - 1);
- // printf("\npos = %x delta = %x\n", pos, delta);
- len++;
- *d++ = 2;
- *d++ = (UInt32)(len - cur);
- *d++ = delta - 1;
- if (hash == size || *hash != delta || lenLimit[diff] != lenLimit[0] || d >= limit)
- break;
- }
- }
- #endif
-
- break;
- }
- }
- }
-
- {
- const UInt32 curMatch = (UInt32)pos - delta; // (UInt32)(pos + diff);
- if (len[diff] < len[0])
- {
- delta = pair[1];
- if (delta >= curMatch)
- return NULL;
- *ptr1 = curMatch;
- ptr1 = pair + 1;
- len1 = len;
- }
- else
- {
- delta = *pair;
- if (delta >= curMatch)
- return NULL;
- *ptr0 = curMatch;
- ptr0 = pair;
- len0 = len;
- }
-
- delta = (UInt32)pos - delta;
-
- if (--cutValue == 0 || delta >= pos)
- {
- *ptr0 = *ptr1 = kEmptyHashValue;
- _distances[-1] = (UInt32)(d - _distances);
- break;
- }
- }
- }
- } // for (tree iterations)
-}
- pos++;
- cur++;
- }
- while (d < limit);
- *posRes = (UInt32)pos;
- return d;
-}
-*/
-
-/* define cbs if you use 2 functions.
- GetMatchesSpecN_1() : (pos < _cyclicBufferSize)
- GetMatchesSpecN_2() : (pos >= _cyclicBufferSize)
-
- do not define cbs if you use 1 function:
- GetMatchesSpecN_2()
-*/
-
-// #define cbs _cyclicBufferSize
-
-/*
- we use size_t for (pos) and (_cyclicBufferPos_ instead of UInt32
- to eliminate "movsx" BUG in old MSVC x64 compiler.
-*/
-
-UInt32 * MY_FAST_CALL GetMatchesSpecN_2(const Byte *lenLimit, size_t pos, const Byte *cur, CLzRef *son,
- UInt32 _cutValue, UInt32 *d, size_t _maxLen, const UInt32 *hash, const UInt32 *limit, const UInt32 *size,
- size_t _cyclicBufferPos, UInt32 _cyclicBufferSize,
- UInt32 *posRes);
-
-MY_NO_INLINE
-UInt32 * MY_FAST_CALL GetMatchesSpecN_2(const Byte *lenLimit, size_t pos, const Byte *cur, CLzRef *son,
- UInt32 _cutValue, UInt32 *d, size_t _maxLen, const UInt32 *hash, const UInt32 *limit, const UInt32 *size,
- size_t _cyclicBufferPos, UInt32 _cyclicBufferSize,
- UInt32 *posRes)
-{
- do // while (hash != size)
- {
- UInt32 delta;
-
- #ifndef cbs
- UInt32 cbs;
- #endif
-
- if (hash == size)
- break;
-
- delta = *hash++;
-
- if (delta == 0)
- return NULL;
-
- lenLimit++;
-
- #ifndef cbs
- cbs = _cyclicBufferSize;
- if ((UInt32)pos < cbs)
- {
- if (delta > (UInt32)pos)
- return NULL;
- cbs = (UInt32)pos;
- }
- #endif
-
- if (delta >= cbs)
- {
- CLzRef *ptr1 = son + ((size_t)_cyclicBufferPos << 1);
- *d++ = 0;
- ptr1[0] = kEmptyHashValue;
- ptr1[1] = kEmptyHashValue;
- }
-else
-{
- UInt32 *_distances = ++d;
-
- CLzRef *ptr0 = son + ((size_t)_cyclicBufferPos << 1) + 1;
- CLzRef *ptr1 = son + ((size_t)_cyclicBufferPos << 1);
-
- UInt32 cutValue = _cutValue;
- const Byte *len0 = cur, *len1 = cur;
- const Byte *maxLen = cur + _maxLen;
-
- // if (cutValue == 0) { *ptr0 = *ptr1 = kEmptyHashValue; } else
- for (LOG_ITER(g_NumIters_Tree++);;)
- {
- LOG_ITER(g_NumIters_Loop++);
- {
- // SPEC code
- CLzRef *pair = son + ((size_t)((ptrdiff_t)_cyclicBufferPos - (ptrdiff_t)delta
- + (ptrdiff_t)(UInt32)(_cyclicBufferPos < delta ? cbs : 0)
- ) << 1);
-
- const ptrdiff_t diff = (ptrdiff_t)0 - (ptrdiff_t)delta;
- const Byte *len = (len0 < len1 ? len0 : len1);
-
- #ifdef USE_SON_PREFETCH
- const UInt32 pair0 = *pair;
- #endif
-
- if (len[diff] == len[0])
- {
- if (++len != lenLimit && len[diff] == len[0])
- while (++len != lenLimit)
- {
- LOG_ITER(g_NumIters_Bytes++);
- if (len[diff] != len[0])
- break;
- }
- if (maxLen < len)
- {
- maxLen = len;
- *d++ = (UInt32)(len - cur);
- *d++ = delta - 1;
-
- if (len == lenLimit)
- {
- const UInt32 pair1 = pair[1];
- *ptr1 =
- #ifdef USE_SON_PREFETCH
- pair0;
- #else
- pair[0];
- #endif
- *ptr0 = pair1;
-
- _distances[-1] = (UInt32)(d - _distances);
-
- #ifdef USE_LONG_MATCH_OPT
-
- if (hash == size || *hash != delta || lenLimit[diff] != lenLimit[0] || d >= limit)
- break;
-
- {
- for (;;)
- {
- *d++ = 2;
- *d++ = (UInt32)(lenLimit - cur);
- *d++ = delta - 1;
- cur++;
- lenLimit++;
- // SPEC
- _cyclicBufferPos++;
- {
- // SPEC code
- CLzRef *dest = son + ((size_t)(_cyclicBufferPos) << 1);
- const CLzRef *src = dest + ((diff
- + (ptrdiff_t)(UInt32)((_cyclicBufferPos < delta) ? cbs : 0)) << 1);
- // CLzRef *ptr = son + ((size_t)(pos) << 1) - CYC_TO_POS_OFFSET * 2;
- #if 0
- *(UInt64 *)(void *)dest = *((const UInt64 *)(const void *)src);
- #else
- const UInt32 p0 = src[0];
- const UInt32 p1 = src[1];
- dest[0] = p0;
- dest[1] = p1;
- #endif
- }
- pos++;
- hash++;
- if (hash == size || *hash != delta || lenLimit[diff] != lenLimit[0] || d >= limit)
- break;
- } // for() end for long matches
- }
- #endif
-
- break; // break from TREE iterations
- }
- }
- }
- {
- const UInt32 curMatch = (UInt32)pos - delta; // (UInt32)(pos + diff);
- if (len[diff] < len[0])
- {
- delta = pair[1];
- *ptr1 = curMatch;
- ptr1 = pair + 1;
- len1 = len;
- if (delta >= curMatch)
- return NULL;
- }
- else
- {
- delta = *pair;
- *ptr0 = curMatch;
- ptr0 = pair;
- len0 = len;
- if (delta >= curMatch)
- return NULL;
- }
- delta = (UInt32)pos - delta;
-
- if (--cutValue == 0 || delta >= cbs)
- {
- *ptr0 = *ptr1 = kEmptyHashValue;
- _distances[-1] = (UInt32)(d - _distances);
- break;
- }
- }
- }
- } // for (tree iterations)
-}
- pos++;
- _cyclicBufferPos++;
- cur++;
- }
- while (d < limit);
- *posRes = (UInt32)pos;
- return d;
-}
-
-
-
-/*
-typedef UInt32 uint32plus; // size_t
-
-UInt32 * MY_FAST_CALL GetMatchesSpecN_3(uint32plus lenLimit, size_t pos, const Byte *cur, CLzRef *son,
- UInt32 _cutValue, UInt32 *d, uint32plus _maxLen, const UInt32 *hash, const UInt32 *limit, const UInt32 *size,
- size_t _cyclicBufferPos, UInt32 _cyclicBufferSize,
- UInt32 *posRes)
-{
- do // while (hash != size)
- {
- UInt32 delta;
-
- #ifndef cbs
- UInt32 cbs;
- #endif
-
- if (hash == size)
- break;
-
- delta = *hash++;
-
- if (delta == 0)
- return NULL;
-
- #ifndef cbs
- cbs = _cyclicBufferSize;
- if ((UInt32)pos < cbs)
- {
- if (delta > (UInt32)pos)
- return NULL;
- cbs = (UInt32)pos;
- }
- #endif
-
- if (delta >= cbs)
- {
- CLzRef *ptr1 = son + ((size_t)_cyclicBufferPos << 1);
- *d++ = 0;
- ptr1[0] = kEmptyHashValue;
- ptr1[1] = kEmptyHashValue;
- }
-else
-{
- CLzRef *ptr0 = son + ((size_t)_cyclicBufferPos << 1) + 1;
- CLzRef *ptr1 = son + ((size_t)_cyclicBufferPos << 1);
- UInt32 *_distances = ++d;
- uint32plus len0 = 0, len1 = 0;
- UInt32 cutValue = _cutValue;
- uint32plus maxLen = _maxLen;
- // lenLimit++; // const Byte *lenLimit = cur + _lenLimit;
-
- for (LOG_ITER(g_NumIters_Tree++);;)
- {
- LOG_ITER(g_NumIters_Loop++);
- {
- // const ptrdiff_t diff = (ptrdiff_t)0 - (ptrdiff_t)delta;
- CLzRef *pair = son + ((size_t)((ptrdiff_t)_cyclicBufferPos - delta
- + (ptrdiff_t)(UInt32)(_cyclicBufferPos < delta ? cbs : 0)
- ) << 1);
- const Byte *pb = cur - delta;
- uint32plus len = (len0 < len1 ? len0 : len1);
-
- #ifdef USE_SON_PREFETCH
- const UInt32 pair0 = *pair;
- #endif
-
- 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 = len;
- *d++ = (UInt32)len;
- *d++ = delta - 1;
- if (len == lenLimit)
- {
- {
- const UInt32 pair1 = pair[1];
- *ptr0 = pair1;
- *ptr1 =
- #ifdef USE_SON_PREFETCH
- pair0;
- #else
- pair[0];
- #endif
- }
-
- _distances[-1] = (UInt32)(d - _distances);
-
- #ifdef USE_LONG_MATCH_OPT
-
- if (hash == size || *hash != delta || pb[lenLimit] != cur[lenLimit] || d >= limit)
- break;
-
- {
- const ptrdiff_t diff = (ptrdiff_t)0 - (ptrdiff_t)delta;
- for (;;)
- {
- *d++ = 2;
- *d++ = (UInt32)lenLimit;
- *d++ = delta - 1;
- _cyclicBufferPos++;
- {
- CLzRef *dest = son + ((size_t)_cyclicBufferPos << 1);
- const CLzRef *src = dest + ((diff +
- (ptrdiff_t)(UInt32)(_cyclicBufferPos < delta ? cbs : 0)) << 1);
- #if 0
- *(UInt64 *)(void *)dest = *((const UInt64 *)(const void *)src);
- #else
- const UInt32 p0 = src[0];
- const UInt32 p1 = src[1];
- dest[0] = p0;
- dest[1] = p1;
- #endif
- }
- hash++;
- pos++;
- cur++;
- pb++;
- if (hash == size || *hash != delta || pb[lenLimit] != cur[lenLimit] || d >= limit)
- break;
- }
- }
- #endif
-
- break;
- }
- }
- }
- {
- const UInt32 curMatch = (UInt32)pos - delta;
- if (pb[len] < cur[len])
- {
- delta = pair[1];
- *ptr1 = curMatch;
- ptr1 = pair + 1;
- len1 = len;
- }
- else
- {
- delta = *pair;
- *ptr0 = curMatch;
- ptr0 = pair;
- len0 = len;
- }
-
- {
- if (delta >= curMatch)
- return NULL;
- delta = (UInt32)pos - delta;
- if (delta >= cbs
- // delta >= _cyclicBufferSize || delta >= pos
- || --cutValue == 0)
- {
- *ptr0 = *ptr1 = kEmptyHashValue;
- _distances[-1] = (UInt32)(d - _distances);
- break;
- }
- }
- }
- }
- } // for (tree iterations)
-}
- pos++;
- _cyclicBufferPos++;
- cur++;
- }
- while (d < limit);
- *posRes = (UInt32)pos;
- return d;
-}
-*/
diff --git a/deps/libchdr/deps/lzma-22.01/src/Lzma86Dec.c b/deps/libchdr/deps/lzma-22.01/src/Lzma86Dec.c
deleted file mode 100644
index 20ac5e7a..00000000
--- a/deps/libchdr/deps/lzma-22.01/src/Lzma86Dec.c
+++ /dev/null
@@ -1,54 +0,0 @@
-/* Lzma86Dec.c -- LZMA + x86 (BCJ) Filter Decoder
-2016-05-16 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#include "Lzma86.h"
-
-#include "Alloc.h"
-#include "Bra.h"
-#include "LzmaDec.h"
-
-SRes Lzma86_GetUnpackSize(const Byte *src, SizeT srcLen, UInt64 *unpackSize)
-{
- unsigned i;
- if (srcLen < LZMA86_HEADER_SIZE)
- return SZ_ERROR_INPUT_EOF;
- *unpackSize = 0;
- for (i = 0; i < sizeof(UInt64); i++)
- *unpackSize += ((UInt64)src[LZMA86_SIZE_OFFSET + i]) << (8 * i);
- return SZ_OK;
-}
-
-SRes Lzma86_Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen)
-{
- SRes res;
- int useFilter;
- SizeT inSizePure;
- ELzmaStatus status;
-
- if (*srcLen < LZMA86_HEADER_SIZE)
- return SZ_ERROR_INPUT_EOF;
-
- useFilter = src[0];
-
- if (useFilter > 1)
- {
- *destLen = 0;
- return SZ_ERROR_UNSUPPORTED;
- }
-
- inSizePure = *srcLen - LZMA86_HEADER_SIZE;
- res = LzmaDecode(dest, destLen, src + LZMA86_HEADER_SIZE, &inSizePure,
- src + 1, LZMA_PROPS_SIZE, LZMA_FINISH_ANY, &status, &g_Alloc);
- *srcLen = inSizePure + LZMA86_HEADER_SIZE;
- if (res != SZ_OK)
- return res;
- if (useFilter == 1)
- {
- UInt32 x86State;
- x86_Convert_Init(x86State);
- x86_Convert(dest, *destLen, 0, &x86State, 0);
- }
- return SZ_OK;
-}
diff --git a/deps/libchdr/deps/lzma-22.01/src/Lzma86Enc.c b/deps/libchdr/deps/lzma-22.01/src/Lzma86Enc.c
deleted file mode 100644
index 99397bc5..00000000
--- a/deps/libchdr/deps/lzma-22.01/src/Lzma86Enc.c
+++ /dev/null
@@ -1,104 +0,0 @@
-/* Lzma86Enc.c -- LZMA + x86 (BCJ) Filter Encoder
-2018-07-04 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#include
-
-#include "Lzma86.h"
-
-#include "Alloc.h"
-#include "Bra.h"
-#include "LzmaEnc.h"
-
-int Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen,
- int level, UInt32 dictSize, int filterMode)
-{
- size_t outSize2 = *destLen;
- Byte *filteredStream;
- BoolInt useFilter;
- int mainResult = SZ_ERROR_OUTPUT_EOF;
- CLzmaEncProps props;
- LzmaEncProps_Init(&props);
- props.level = level;
- props.dictSize = dictSize;
-
- *destLen = 0;
- if (outSize2 < LZMA86_HEADER_SIZE)
- return SZ_ERROR_OUTPUT_EOF;
-
- {
- int i;
- UInt64 t = srcLen;
- for (i = 0; i < 8; i++, t >>= 8)
- dest[LZMA86_SIZE_OFFSET + i] = (Byte)t;
- }
-
- filteredStream = 0;
- useFilter = (filterMode != SZ_FILTER_NO);
- if (useFilter)
- {
- if (srcLen != 0)
- {
- filteredStream = (Byte *)MyAlloc(srcLen);
- if (filteredStream == 0)
- return SZ_ERROR_MEM;
- memcpy(filteredStream, src, srcLen);
- }
- {
- UInt32 x86State;
- x86_Convert_Init(x86State);
- x86_Convert(filteredStream, srcLen, 0, &x86State, 1);
- }
- }
-
- {
- size_t minSize = 0;
- BoolInt bestIsFiltered = False;
-
- /* passes for SZ_FILTER_AUTO:
- 0 - BCJ + LZMA
- 1 - LZMA
- 2 - BCJ + LZMA agaian, if pass 0 (BCJ + LZMA) is better.
- */
- int numPasses = (filterMode == SZ_FILTER_AUTO) ? 3 : 1;
-
- int i;
- for (i = 0; i < numPasses; i++)
- {
- size_t outSizeProcessed = outSize2 - LZMA86_HEADER_SIZE;
- size_t outPropsSize = 5;
- SRes curRes;
- BoolInt curModeIsFiltered = (numPasses > 1 && i == numPasses - 1);
- if (curModeIsFiltered && !bestIsFiltered)
- break;
- if (useFilter && i == 0)
- curModeIsFiltered = True;
-
- curRes = LzmaEncode(dest + LZMA86_HEADER_SIZE, &outSizeProcessed,
- curModeIsFiltered ? filteredStream : src, srcLen,
- &props, dest + 1, &outPropsSize, 0,
- NULL, &g_Alloc, &g_Alloc);
-
- if (curRes != SZ_ERROR_OUTPUT_EOF)
- {
- if (curRes != SZ_OK)
- {
- mainResult = curRes;
- break;
- }
- if (outSizeProcessed <= minSize || mainResult != SZ_OK)
- {
- minSize = outSizeProcessed;
- bestIsFiltered = curModeIsFiltered;
- mainResult = SZ_OK;
- }
- }
- }
- dest[0] = (Byte)(bestIsFiltered ? 1 : 0);
- *destLen = LZMA86_HEADER_SIZE + minSize;
- }
- if (useFilter)
- MyFree(filteredStream);
- return mainResult;
-}
diff --git a/deps/libchdr/deps/lzma-22.01/src/LzmaLib.c b/deps/libchdr/deps/lzma-22.01/src/LzmaLib.c
deleted file mode 100644
index c10cf1a0..00000000
--- a/deps/libchdr/deps/lzma-22.01/src/LzmaLib.c
+++ /dev/null
@@ -1,40 +0,0 @@
-/* LzmaLib.c -- LZMA library wrapper
-2015-06-13 : Igor Pavlov : Public domain */
-
-#include "Alloc.h"
-#include "LzmaDec.h"
-#include "LzmaEnc.h"
-#include "LzmaLib.h"
-
-MY_STDAPI LzmaCompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t srcLen,
- unsigned char *outProps, size_t *outPropsSize,
- int level, /* 0 <= level <= 9, default = 5 */
- unsigned dictSize, /* use (1 << N) or (3 << N). 4 KB < dictSize <= 128 MB */
- int lc, /* 0 <= lc <= 8, default = 3 */
- int lp, /* 0 <= lp <= 4, default = 0 */
- int pb, /* 0 <= pb <= 4, default = 2 */
- int fb, /* 5 <= fb <= 273, default = 32 */
- int numThreads /* 1 or 2, default = 2 */
-)
-{
- CLzmaEncProps props;
- LzmaEncProps_Init(&props);
- props.level = level;
- props.dictSize = dictSize;
- props.lc = lc;
- props.lp = lp;
- props.pb = pb;
- props.fb = fb;
- props.numThreads = numThreads;
-
- return LzmaEncode(dest, destLen, src, srcLen, &props, outProps, outPropsSize, 0,
- NULL, &g_Alloc, &g_Alloc);
-}
-
-
-MY_STDAPI LzmaUncompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t *srcLen,
- const unsigned char *props, size_t propsSize)
-{
- ELzmaStatus status;
- return LzmaDecode(dest, destLen, src, srcLen, props, (unsigned)propsSize, LZMA_FINISH_ANY, &status, &g_Alloc);
-}
diff --git a/deps/libchdr/deps/lzma-22.01/src/MtCoder.c b/deps/libchdr/deps/lzma-22.01/src/MtCoder.c
deleted file mode 100644
index e39d9cb1..00000000
--- a/deps/libchdr/deps/lzma-22.01/src/MtCoder.c
+++ /dev/null
@@ -1,595 +0,0 @@
-/* MtCoder.c -- Multi-thread Coder
-2021-12-21 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#include "MtCoder.h"
-
-#ifndef _7ZIP_ST
-
-static SRes MtProgressThunk_Progress(const ICompressProgress *pp, UInt64 inSize, UInt64 outSize)
-{
- CMtProgressThunk *thunk = CONTAINER_FROM_VTBL(pp, CMtProgressThunk, vt);
- UInt64 inSize2 = 0;
- UInt64 outSize2 = 0;
- if (inSize != (UInt64)(Int64)-1)
- {
- inSize2 = inSize - thunk->inSize;
- thunk->inSize = inSize;
- }
- if (outSize != (UInt64)(Int64)-1)
- {
- outSize2 = outSize - thunk->outSize;
- thunk->outSize = outSize;
- }
- return MtProgress_ProgressAdd(thunk->mtProgress, inSize2, outSize2);
-}
-
-
-void MtProgressThunk_CreateVTable(CMtProgressThunk *p)
-{
- p->vt.Progress = MtProgressThunk_Progress;
-}
-
-
-
-#define RINOK_THREAD(x) { if ((x) != 0) return SZ_ERROR_THREAD; }
-
-
-static WRes ArEvent_OptCreate_And_Reset(CEvent *p)
-{
- if (Event_IsCreated(p))
- return Event_Reset(p);
- return AutoResetEvent_CreateNotSignaled(p);
-}
-
-
-static THREAD_FUNC_DECL ThreadFunc(void *pp);
-
-
-static SRes MtCoderThread_CreateAndStart(CMtCoderThread *t)
-{
- WRes wres = ArEvent_OptCreate_And_Reset(&t->startEvent);
- if (wres == 0)
- {
- t->stop = False;
- if (!Thread_WasCreated(&t->thread))
- wres = Thread_Create(&t->thread, ThreadFunc, t);
- if (wres == 0)
- wres = Event_Set(&t->startEvent);
- }
- if (wres == 0)
- return SZ_OK;
- return MY_SRes_HRESULT_FROM_WRes(wres);
-}
-
-
-static void MtCoderThread_Destruct(CMtCoderThread *t)
-{
- if (Thread_WasCreated(&t->thread))
- {
- t->stop = 1;
- Event_Set(&t->startEvent);
- Thread_Wait_Close(&t->thread);
- }
-
- Event_Close(&t->startEvent);
-
- if (t->inBuf)
- {
- ISzAlloc_Free(t->mtCoder->allocBig, t->inBuf);
- t->inBuf = NULL;
- }
-}
-
-
-
-static SRes FullRead(ISeqInStream *stream, Byte *data, size_t *processedSize)
-{
- size_t size = *processedSize;
- *processedSize = 0;
- while (size != 0)
- {
- size_t cur = size;
- SRes res = ISeqInStream_Read(stream, data, &cur);
- *processedSize += cur;
- data += cur;
- size -= cur;
- RINOK(res);
- if (cur == 0)
- return SZ_OK;
- }
- return SZ_OK;
-}
-
-
-/*
- ThreadFunc2() returns:
- SZ_OK - in all normal cases (even for stream error or memory allocation error)
- SZ_ERROR_THREAD - in case of failure in system synch function
-*/
-
-static SRes ThreadFunc2(CMtCoderThread *t)
-{
- CMtCoder *mtc = t->mtCoder;
-
- for (;;)
- {
- unsigned bi;
- SRes res;
- SRes res2;
- BoolInt finished;
- unsigned bufIndex;
- size_t size;
- const Byte *inData;
- UInt64 readProcessed = 0;
-
- RINOK_THREAD(Event_Wait(&mtc->readEvent))
-
- /* after Event_Wait(&mtc->readEvent) we must call Event_Set(&mtc->readEvent) in any case to unlock another threads */
-
- if (mtc->stopReading)
- {
- return Event_Set(&mtc->readEvent) == 0 ? SZ_OK : SZ_ERROR_THREAD;
- }
-
- res = MtProgress_GetError(&mtc->mtProgress);
-
- size = 0;
- inData = NULL;
- finished = True;
-
- if (res == SZ_OK)
- {
- size = mtc->blockSize;
- if (mtc->inStream)
- {
- if (!t->inBuf)
- {
- t->inBuf = (Byte *)ISzAlloc_Alloc(mtc->allocBig, mtc->blockSize);
- if (!t->inBuf)
- res = SZ_ERROR_MEM;
- }
- if (res == SZ_OK)
- {
- res = FullRead(mtc->inStream, t->inBuf, &size);
- readProcessed = mtc->readProcessed + size;
- mtc->readProcessed = readProcessed;
- }
- if (res != SZ_OK)
- {
- mtc->readRes = res;
- /* after reading error - we can stop encoding of previous blocks */
- MtProgress_SetError(&mtc->mtProgress, res);
- }
- else
- finished = (size != mtc->blockSize);
- }
- else
- {
- size_t rem;
- readProcessed = mtc->readProcessed;
- rem = mtc->inDataSize - (size_t)readProcessed;
- if (size > rem)
- size = rem;
- inData = mtc->inData + (size_t)readProcessed;
- readProcessed += size;
- mtc->readProcessed = readProcessed;
- finished = (mtc->inDataSize == (size_t)readProcessed);
- }
- }
-
- /* we must get some block from blocksSemaphore before Event_Set(&mtc->readEvent) */
-
- res2 = SZ_OK;
-
- if (Semaphore_Wait(&mtc->blocksSemaphore) != 0)
- {
- res2 = SZ_ERROR_THREAD;
- if (res == SZ_OK)
- {
- res = res2;
- // MtProgress_SetError(&mtc->mtProgress, res);
- }
- }
-
- bi = mtc->blockIndex;
-
- if (++mtc->blockIndex >= mtc->numBlocksMax)
- mtc->blockIndex = 0;
-
- bufIndex = (unsigned)(int)-1;
-
- if (res == SZ_OK)
- res = MtProgress_GetError(&mtc->mtProgress);
-
- if (res != SZ_OK)
- finished = True;
-
- if (!finished)
- {
- if (mtc->numStartedThreads < mtc->numStartedThreadsLimit
- && mtc->expectedDataSize != readProcessed)
- {
- res = MtCoderThread_CreateAndStart(&mtc->threads[mtc->numStartedThreads]);
- if (res == SZ_OK)
- mtc->numStartedThreads++;
- else
- {
- MtProgress_SetError(&mtc->mtProgress, res);
- finished = True;
- }
- }
- }
-
- if (finished)
- mtc->stopReading = True;
-
- RINOK_THREAD(Event_Set(&mtc->readEvent))
-
- if (res2 != SZ_OK)
- return res2;
-
- if (res == SZ_OK)
- {
- CriticalSection_Enter(&mtc->cs);
- bufIndex = mtc->freeBlockHead;
- mtc->freeBlockHead = mtc->freeBlockList[bufIndex];
- CriticalSection_Leave(&mtc->cs);
-
- res = mtc->mtCallback->Code(mtc->mtCallbackObject, t->index, bufIndex,
- mtc->inStream ? t->inBuf : inData, size, finished);
-
- // MtProgress_Reinit(&mtc->mtProgress, t->index);
-
- if (res != SZ_OK)
- MtProgress_SetError(&mtc->mtProgress, res);
- }
-
- {
- CMtCoderBlock *block = &mtc->blocks[bi];
- block->res = res;
- block->bufIndex = bufIndex;
- block->finished = finished;
- }
-
- #ifdef MTCODER__USE_WRITE_THREAD
- RINOK_THREAD(Event_Set(&mtc->writeEvents[bi]))
- #else
- {
- unsigned wi;
- {
- CriticalSection_Enter(&mtc->cs);
- wi = mtc->writeIndex;
- if (wi == bi)
- mtc->writeIndex = (unsigned)(int)-1;
- else
- mtc->ReadyBlocks[bi] = True;
- CriticalSection_Leave(&mtc->cs);
- }
-
- if (wi != bi)
- {
- if (res != SZ_OK || finished)
- return 0;
- continue;
- }
-
- if (mtc->writeRes != SZ_OK)
- res = mtc->writeRes;
-
- for (;;)
- {
- if (res == SZ_OK && bufIndex != (unsigned)(int)-1)
- {
- res = mtc->mtCallback->Write(mtc->mtCallbackObject, bufIndex);
- if (res != SZ_OK)
- {
- mtc->writeRes = res;
- MtProgress_SetError(&mtc->mtProgress, res);
- }
- }
-
- if (++wi >= mtc->numBlocksMax)
- wi = 0;
- {
- BoolInt isReady;
-
- CriticalSection_Enter(&mtc->cs);
-
- if (bufIndex != (unsigned)(int)-1)
- {
- mtc->freeBlockList[bufIndex] = mtc->freeBlockHead;
- mtc->freeBlockHead = bufIndex;
- }
-
- isReady = mtc->ReadyBlocks[wi];
-
- if (isReady)
- mtc->ReadyBlocks[wi] = False;
- else
- mtc->writeIndex = wi;
-
- CriticalSection_Leave(&mtc->cs);
-
- RINOK_THREAD(Semaphore_Release1(&mtc->blocksSemaphore))
-
- if (!isReady)
- break;
- }
-
- {
- CMtCoderBlock *block = &mtc->blocks[wi];
- if (res == SZ_OK && block->res != SZ_OK)
- res = block->res;
- bufIndex = block->bufIndex;
- finished = block->finished;
- }
- }
- }
- #endif
-
- if (finished || res != SZ_OK)
- return 0;
- }
-}
-
-
-static THREAD_FUNC_DECL ThreadFunc(void *pp)
-{
- CMtCoderThread *t = (CMtCoderThread *)pp;
- for (;;)
- {
- if (Event_Wait(&t->startEvent) != 0)
- return (THREAD_FUNC_RET_TYPE)SZ_ERROR_THREAD;
- if (t->stop)
- return 0;
- {
- SRes res = ThreadFunc2(t);
- CMtCoder *mtc = t->mtCoder;
- if (res != SZ_OK)
- {
- MtProgress_SetError(&mtc->mtProgress, res);
- }
-
- #ifndef MTCODER__USE_WRITE_THREAD
- {
- unsigned numFinished = (unsigned)InterlockedIncrement(&mtc->numFinishedThreads);
- if (numFinished == mtc->numStartedThreads)
- if (Event_Set(&mtc->finishedEvent) != 0)
- return (THREAD_FUNC_RET_TYPE)SZ_ERROR_THREAD;
- }
- #endif
- }
- }
-}
-
-
-
-void MtCoder_Construct(CMtCoder *p)
-{
- unsigned i;
-
- p->blockSize = 0;
- p->numThreadsMax = 0;
- p->expectedDataSize = (UInt64)(Int64)-1;
-
- p->inStream = NULL;
- p->inData = NULL;
- p->inDataSize = 0;
-
- p->progress = NULL;
- p->allocBig = NULL;
-
- p->mtCallback = NULL;
- p->mtCallbackObject = NULL;
-
- p->allocatedBufsSize = 0;
-
- Event_Construct(&p->readEvent);
- Semaphore_Construct(&p->blocksSemaphore);
-
- for (i = 0; i < MTCODER__THREADS_MAX; i++)
- {
- CMtCoderThread *t = &p->threads[i];
- t->mtCoder = p;
- t->index = i;
- t->inBuf = NULL;
- t->stop = False;
- Event_Construct(&t->startEvent);
- Thread_Construct(&t->thread);
- }
-
- #ifdef MTCODER__USE_WRITE_THREAD
- for (i = 0; i < MTCODER__BLOCKS_MAX; i++)
- Event_Construct(&p->writeEvents[i]);
- #else
- Event_Construct(&p->finishedEvent);
- #endif
-
- CriticalSection_Init(&p->cs);
- CriticalSection_Init(&p->mtProgress.cs);
-}
-
-
-
-
-static void MtCoder_Free(CMtCoder *p)
-{
- unsigned i;
-
- /*
- p->stopReading = True;
- if (Event_IsCreated(&p->readEvent))
- Event_Set(&p->readEvent);
- */
-
- for (i = 0; i < MTCODER__THREADS_MAX; i++)
- MtCoderThread_Destruct(&p->threads[i]);
-
- Event_Close(&p->readEvent);
- Semaphore_Close(&p->blocksSemaphore);
-
- #ifdef MTCODER__USE_WRITE_THREAD
- for (i = 0; i < MTCODER__BLOCKS_MAX; i++)
- Event_Close(&p->writeEvents[i]);
- #else
- Event_Close(&p->finishedEvent);
- #endif
-}
-
-
-void MtCoder_Destruct(CMtCoder *p)
-{
- MtCoder_Free(p);
-
- CriticalSection_Delete(&p->cs);
- CriticalSection_Delete(&p->mtProgress.cs);
-}
-
-
-SRes MtCoder_Code(CMtCoder *p)
-{
- unsigned numThreads = p->numThreadsMax;
- unsigned numBlocksMax;
- unsigned i;
- SRes res = SZ_OK;
-
- if (numThreads > MTCODER__THREADS_MAX)
- numThreads = MTCODER__THREADS_MAX;
- numBlocksMax = MTCODER__GET_NUM_BLOCKS_FROM_THREADS(numThreads);
-
- if (p->blockSize < ((UInt32)1 << 26)) numBlocksMax++;
- if (p->blockSize < ((UInt32)1 << 24)) numBlocksMax++;
- if (p->blockSize < ((UInt32)1 << 22)) numBlocksMax++;
-
- if (numBlocksMax > MTCODER__BLOCKS_MAX)
- numBlocksMax = MTCODER__BLOCKS_MAX;
-
- if (p->blockSize != p->allocatedBufsSize)
- {
- for (i = 0; i < MTCODER__THREADS_MAX; i++)
- {
- CMtCoderThread *t = &p->threads[i];
- if (t->inBuf)
- {
- ISzAlloc_Free(p->allocBig, t->inBuf);
- t->inBuf = NULL;
- }
- }
- p->allocatedBufsSize = p->blockSize;
- }
-
- p->readRes = SZ_OK;
-
- MtProgress_Init(&p->mtProgress, p->progress);
-
- #ifdef MTCODER__USE_WRITE_THREAD
- for (i = 0; i < numBlocksMax; i++)
- {
- RINOK_THREAD(ArEvent_OptCreate_And_Reset(&p->writeEvents[i]));
- }
- #else
- RINOK_THREAD(ArEvent_OptCreate_And_Reset(&p->finishedEvent));
- #endif
-
- {
- RINOK_THREAD(ArEvent_OptCreate_And_Reset(&p->readEvent));
- RINOK_THREAD(Semaphore_OptCreateInit(&p->blocksSemaphore, numBlocksMax, numBlocksMax));
- }
-
- for (i = 0; i < MTCODER__BLOCKS_MAX - 1; i++)
- p->freeBlockList[i] = i + 1;
- p->freeBlockList[MTCODER__BLOCKS_MAX - 1] = (unsigned)(int)-1;
- p->freeBlockHead = 0;
-
- p->readProcessed = 0;
- p->blockIndex = 0;
- p->numBlocksMax = numBlocksMax;
- p->stopReading = False;
-
- #ifndef MTCODER__USE_WRITE_THREAD
- p->writeIndex = 0;
- p->writeRes = SZ_OK;
- for (i = 0; i < MTCODER__BLOCKS_MAX; i++)
- p->ReadyBlocks[i] = False;
- p->numFinishedThreads = 0;
- #endif
-
- p->numStartedThreadsLimit = numThreads;
- p->numStartedThreads = 0;
-
- // for (i = 0; i < numThreads; i++)
- {
- CMtCoderThread *nextThread = &p->threads[p->numStartedThreads++];
- RINOK(MtCoderThread_CreateAndStart(nextThread));
- }
-
- RINOK_THREAD(Event_Set(&p->readEvent))
-
- #ifdef MTCODER__USE_WRITE_THREAD
- {
- unsigned bi = 0;
-
- for (;; bi++)
- {
- if (bi >= numBlocksMax)
- bi = 0;
-
- RINOK_THREAD(Event_Wait(&p->writeEvents[bi]))
-
- {
- const CMtCoderBlock *block = &p->blocks[bi];
- unsigned bufIndex = block->bufIndex;
- BoolInt finished = block->finished;
- if (res == SZ_OK && block->res != SZ_OK)
- res = block->res;
-
- if (bufIndex != (unsigned)(int)-1)
- {
- if (res == SZ_OK)
- {
- res = p->mtCallback->Write(p->mtCallbackObject, bufIndex);
- if (res != SZ_OK)
- MtProgress_SetError(&p->mtProgress, res);
- }
-
- CriticalSection_Enter(&p->cs);
- {
- p->freeBlockList[bufIndex] = p->freeBlockHead;
- p->freeBlockHead = bufIndex;
- }
- CriticalSection_Leave(&p->cs);
- }
-
- RINOK_THREAD(Semaphore_Release1(&p->blocksSemaphore))
-
- if (finished)
- break;
- }
- }
- }
- #else
- {
- WRes wres = Event_Wait(&p->finishedEvent);
- res = MY_SRes_HRESULT_FROM_WRes(wres);
- }
- #endif
-
- if (res == SZ_OK)
- res = p->readRes;
-
- if (res == SZ_OK)
- res = p->mtProgress.res;
-
- #ifndef MTCODER__USE_WRITE_THREAD
- if (res == SZ_OK)
- res = p->writeRes;
- #endif
-
- if (res != SZ_OK)
- MtCoder_Free(p);
- return res;
-}
-
-#endif
diff --git a/deps/libchdr/deps/lzma-22.01/src/MtDec.c b/deps/libchdr/deps/lzma-22.01/src/MtDec.c
deleted file mode 100644
index 854087b9..00000000
--- a/deps/libchdr/deps/lzma-22.01/src/MtDec.c
+++ /dev/null
@@ -1,1139 +0,0 @@
-/* MtDec.c -- Multi-thread Decoder
-2021-12-21 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-// #define SHOW_DEBUG_INFO
-
-// #include
-#include
-
-#ifdef SHOW_DEBUG_INFO
-#include
-#endif
-
-#include "MtDec.h"
-
-#ifndef _7ZIP_ST
-
-#ifdef SHOW_DEBUG_INFO
-#define PRF(x) x
-#else
-#define PRF(x)
-#endif
-
-#define PRF_STR_INT(s, d) PRF(printf("\n" s " %d\n", (unsigned)d))
-
-void MtProgress_Init(CMtProgress *p, ICompressProgress *progress)
-{
- p->progress = progress;
- p->res = SZ_OK;
- p->totalInSize = 0;
- p->totalOutSize = 0;
-}
-
-
-SRes MtProgress_Progress_ST(CMtProgress *p)
-{
- if (p->res == SZ_OK && p->progress)
- if (ICompressProgress_Progress(p->progress, p->totalInSize, p->totalOutSize) != SZ_OK)
- p->res = SZ_ERROR_PROGRESS;
- return p->res;
-}
-
-
-SRes MtProgress_ProgressAdd(CMtProgress *p, UInt64 inSize, UInt64 outSize)
-{
- SRes res;
- CriticalSection_Enter(&p->cs);
-
- p->totalInSize += inSize;
- p->totalOutSize += outSize;
- if (p->res == SZ_OK && p->progress)
- if (ICompressProgress_Progress(p->progress, p->totalInSize, p->totalOutSize) != SZ_OK)
- p->res = SZ_ERROR_PROGRESS;
- res = p->res;
-
- CriticalSection_Leave(&p->cs);
- return res;
-}
-
-
-SRes MtProgress_GetError(CMtProgress *p)
-{
- SRes res;
- CriticalSection_Enter(&p->cs);
- res = p->res;
- CriticalSection_Leave(&p->cs);
- return res;
-}
-
-
-void MtProgress_SetError(CMtProgress *p, SRes res)
-{
- CriticalSection_Enter(&p->cs);
- if (p->res == SZ_OK)
- p->res = res;
- CriticalSection_Leave(&p->cs);
-}
-
-
-#define RINOK_THREAD(x) RINOK_WRes(x)
-
-
-static WRes ArEvent_OptCreate_And_Reset(CEvent *p)
-{
- if (Event_IsCreated(p))
- return Event_Reset(p);
- return AutoResetEvent_CreateNotSignaled(p);
-}
-
-
-struct __CMtDecBufLink
-{
- struct __CMtDecBufLink *next;
- void *pad[3];
-};
-
-typedef struct __CMtDecBufLink CMtDecBufLink;
-
-#define MTDEC__LINK_DATA_OFFSET sizeof(CMtDecBufLink)
-#define MTDEC__DATA_PTR_FROM_LINK(link) ((Byte *)(link) + MTDEC__LINK_DATA_OFFSET)
-
-
-
-static THREAD_FUNC_DECL ThreadFunc(void *pp);
-
-
-static WRes MtDecThread_CreateEvents(CMtDecThread *t)
-{
- WRes wres = ArEvent_OptCreate_And_Reset(&t->canWrite);
- if (wres == 0)
- {
- wres = ArEvent_OptCreate_And_Reset(&t->canRead);
- if (wres == 0)
- return SZ_OK;
- }
- return wres;
-}
-
-
-static SRes MtDecThread_CreateAndStart(CMtDecThread *t)
-{
- WRes wres = MtDecThread_CreateEvents(t);
- // wres = 17; // for test
- if (wres == 0)
- {
- if (Thread_WasCreated(&t->thread))
- return SZ_OK;
- wres = Thread_Create(&t->thread, ThreadFunc, t);
- if (wres == 0)
- return SZ_OK;
- }
- return MY_SRes_HRESULT_FROM_WRes(wres);
-}
-
-
-void MtDecThread_FreeInBufs(CMtDecThread *t)
-{
- if (t->inBuf)
- {
- void *link = t->inBuf;
- t->inBuf = NULL;
- do
- {
- void *next = ((CMtDecBufLink *)link)->next;
- ISzAlloc_Free(t->mtDec->alloc, link);
- link = next;
- }
- while (link);
- }
-}
-
-
-static void MtDecThread_CloseThread(CMtDecThread *t)
-{
- if (Thread_WasCreated(&t->thread))
- {
- Event_Set(&t->canWrite); /* we can disable it. There are no threads waiting canWrite in normal cases */
- Event_Set(&t->canRead);
- Thread_Wait_Close(&t->thread);
- }
-
- Event_Close(&t->canRead);
- Event_Close(&t->canWrite);
-}
-
-static void MtDec_CloseThreads(CMtDec *p)
-{
- unsigned i;
- for (i = 0; i < MTDEC__THREADS_MAX; i++)
- MtDecThread_CloseThread(&p->threads[i]);
-}
-
-static void MtDecThread_Destruct(CMtDecThread *t)
-{
- MtDecThread_CloseThread(t);
- MtDecThread_FreeInBufs(t);
-}
-
-
-
-static SRes FullRead(ISeqInStream *stream, Byte *data, size_t *processedSize)
-{
- size_t size = *processedSize;
- *processedSize = 0;
- while (size != 0)
- {
- size_t cur = size;
- SRes res = ISeqInStream_Read(stream, data, &cur);
- *processedSize += cur;
- data += cur;
- size -= cur;
- RINOK(res);
- if (cur == 0)
- return SZ_OK;
- }
- return SZ_OK;
-}
-
-
-static SRes MtDec_GetError_Spec(CMtDec *p, UInt64 interruptIndex, BoolInt *wasInterrupted)
-{
- SRes res;
- CriticalSection_Enter(&p->mtProgress.cs);
- *wasInterrupted = (p->needInterrupt && interruptIndex > p->interruptIndex);
- res = p->mtProgress.res;
- CriticalSection_Leave(&p->mtProgress.cs);
- return res;
-}
-
-static SRes MtDec_Progress_GetError_Spec(CMtDec *p, UInt64 inSize, UInt64 outSize, UInt64 interruptIndex, BoolInt *wasInterrupted)
-{
- SRes res;
- CriticalSection_Enter(&p->mtProgress.cs);
-
- p->mtProgress.totalInSize += inSize;
- p->mtProgress.totalOutSize += outSize;
- if (p->mtProgress.res == SZ_OK && p->mtProgress.progress)
- if (ICompressProgress_Progress(p->mtProgress.progress, p->mtProgress.totalInSize, p->mtProgress.totalOutSize) != SZ_OK)
- p->mtProgress.res = SZ_ERROR_PROGRESS;
-
- *wasInterrupted = (p->needInterrupt && interruptIndex > p->interruptIndex);
- res = p->mtProgress.res;
-
- CriticalSection_Leave(&p->mtProgress.cs);
-
- return res;
-}
-
-static void MtDec_Interrupt(CMtDec *p, UInt64 interruptIndex)
-{
- CriticalSection_Enter(&p->mtProgress.cs);
- if (!p->needInterrupt || interruptIndex < p->interruptIndex)
- {
- p->interruptIndex = interruptIndex;
- p->needInterrupt = True;
- }
- CriticalSection_Leave(&p->mtProgress.cs);
-}
-
-Byte *MtDec_GetCrossBuff(CMtDec *p)
-{
- Byte *cr = p->crossBlock;
- if (!cr)
- {
- cr = (Byte *)ISzAlloc_Alloc(p->alloc, MTDEC__LINK_DATA_OFFSET + p->inBufSize);
- if (!cr)
- return NULL;
- p->crossBlock = cr;
- }
- return MTDEC__DATA_PTR_FROM_LINK(cr);
-}
-
-
-/*
- ThreadFunc2() returns:
- 0 - in all normal cases (even for stream error or memory allocation error)
- (!= 0) - WRes error return by system threading function
-*/
-
-// #define MTDEC_ProgessStep (1 << 22)
-#define MTDEC_ProgessStep (1 << 0)
-
-static WRes ThreadFunc2(CMtDecThread *t)
-{
- CMtDec *p = t->mtDec;
-
- PRF_STR_INT("ThreadFunc2", t->index);
-
- // SetThreadAffinityMask(GetCurrentThread(), 1 << t->index);
-
- for (;;)
- {
- SRes res, codeRes;
- BoolInt wasInterrupted, isAllocError, overflow, finish;
- SRes threadingErrorSRes;
- BoolInt needCode, needWrite, needContinue;
-
- size_t inDataSize_Start;
- UInt64 inDataSize;
- // UInt64 inDataSize_Full;
-
- UInt64 blockIndex;
-
- UInt64 inPrev = 0;
- UInt64 outPrev = 0;
- UInt64 inCodePos;
- UInt64 outCodePos;
-
- Byte *afterEndData = NULL;
- size_t afterEndData_Size = 0;
- BoolInt afterEndData_IsCross = False;
-
- BoolInt canCreateNewThread = False;
- // CMtDecCallbackInfo parse;
- CMtDecThread *nextThread;
-
- PRF_STR_INT("=============== Event_Wait(&t->canRead)", t->index);
-
- RINOK_THREAD(Event_Wait(&t->canRead));
- if (p->exitThread)
- return 0;
-
- PRF_STR_INT("after Event_Wait(&t->canRead)", t->index);
-
- // if (t->index == 3) return 19; // for test
-
- blockIndex = p->blockIndex++;
-
- // PRF(printf("\ncanRead\n"))
-
- res = MtDec_Progress_GetError_Spec(p, 0, 0, blockIndex, &wasInterrupted);
-
- finish = p->readWasFinished;
- needCode = False;
- needWrite = False;
- isAllocError = False;
- overflow = False;
-
- inDataSize_Start = 0;
- inDataSize = 0;
- // inDataSize_Full = 0;
-
- if (res == SZ_OK && !wasInterrupted)
- {
- // if (p->inStream)
- {
- CMtDecBufLink *prev = NULL;
- CMtDecBufLink *link = (CMtDecBufLink *)t->inBuf;
- size_t crossSize = p->crossEnd - p->crossStart;
-
- PRF(printf("\ncrossSize = %d\n", crossSize));
-
- for (;;)
- {
- if (!link)
- {
- link = (CMtDecBufLink *)ISzAlloc_Alloc(p->alloc, MTDEC__LINK_DATA_OFFSET + p->inBufSize);
- if (!link)
- {
- finish = True;
- // p->allocError_for_Read_BlockIndex = blockIndex;
- isAllocError = True;
- break;
- }
- link->next = NULL;
- if (prev)
- {
- // static unsigned g_num = 0;
- // printf("\n%6d : %x", ++g_num, (unsigned)(size_t)((Byte *)link - (Byte *)prev));
- prev->next = link;
- }
- else
- t->inBuf = (void *)link;
- }
-
- {
- Byte *data = MTDEC__DATA_PTR_FROM_LINK(link);
- Byte *parseData = data;
- size_t size;
-
- if (crossSize != 0)
- {
- inDataSize = crossSize;
- // inDataSize_Full = inDataSize;
- inDataSize_Start = crossSize;
- size = crossSize;
- parseData = MTDEC__DATA_PTR_FROM_LINK(p->crossBlock) + p->crossStart;
- PRF(printf("\ncross : crossStart = %7d crossEnd = %7d finish = %1d",
- (int)p->crossStart, (int)p->crossEnd, (int)finish));
- }
- else
- {
- size = p->inBufSize;
-
- res = FullRead(p->inStream, data, &size);
-
- // size = 10; // test
-
- inDataSize += size;
- // inDataSize_Full = inDataSize;
- if (!prev)
- inDataSize_Start = size;
-
- p->readProcessed += size;
- finish = (size != p->inBufSize);
- if (finish)
- p->readWasFinished = True;
-
- // res = E_INVALIDARG; // test
-
- if (res != SZ_OK)
- {
- // PRF(printf("\nRead error = %d\n", res))
- // we want to decode all data before error
- p->readRes = res;
- // p->readError_BlockIndex = blockIndex;
- p->readWasFinished = True;
- finish = True;
- res = SZ_OK;
- // break;
- }
-
- if (inDataSize - inPrev >= MTDEC_ProgessStep)
- {
- res = MtDec_Progress_GetError_Spec(p, 0, 0, blockIndex, &wasInterrupted);
- if (res != SZ_OK || wasInterrupted)
- break;
- inPrev = inDataSize;
- }
- }
-
- {
- CMtDecCallbackInfo parse;
-
- parse.startCall = (prev == NULL);
- parse.src = parseData;
- parse.srcSize = size;
- parse.srcFinished = finish;
- parse.canCreateNewThread = True;
-
- PRF(printf("\nParse size = %d\n", (unsigned)size));
-
- p->mtCallback->Parse(p->mtCallbackObject, t->index, &parse);
-
- PRF(printf(" Parse processed = %d, state = %d \n", (unsigned)parse.srcSize, (unsigned)parse.state));
-
- needWrite = True;
- canCreateNewThread = parse.canCreateNewThread;
-
- // printf("\n\n%12I64u %12I64u", (UInt64)p->mtProgress.totalInSize, (UInt64)p->mtProgress.totalOutSize);
-
- if (
- // parseRes != SZ_OK ||
- // inDataSize - (size - parse.srcSize) > p->inBlockMax
- // ||
- parse.state == MTDEC_PARSE_OVERFLOW
- // || wasInterrupted
- )
- {
- // Overflow or Parse error - switch from MT decoding to ST decoding
- finish = True;
- overflow = True;
-
- {
- PRF(printf("\n Overflow"));
- // PRF(printf("\nisBlockFinished = %d", (unsigned)parse.blockWasFinished));
- PRF(printf("\n inDataSize = %d", (unsigned)inDataSize));
- }
-
- if (crossSize != 0)
- memcpy(data, parseData, size);
- p->crossStart = 0;
- p->crossEnd = 0;
- break;
- }
-
- if (crossSize != 0)
- {
- memcpy(data, parseData, parse.srcSize);
- p->crossStart += parse.srcSize;
- }
-
- if (parse.state != MTDEC_PARSE_CONTINUE || finish)
- {
- // we don't need to parse in current thread anymore
-
- if (parse.state == MTDEC_PARSE_END)
- finish = True;
-
- needCode = True;
- // p->crossFinished = finish;
-
- if (parse.srcSize == size)
- {
- // full parsed - no cross transfer
- p->crossStart = 0;
- p->crossEnd = 0;
- break;
- }
-
- if (parse.state == MTDEC_PARSE_END)
- {
- afterEndData = parseData + parse.srcSize;
- afterEndData_Size = size - parse.srcSize;
- if (crossSize != 0)
- afterEndData_IsCross = True;
- // we reduce data size to required bytes (parsed only)
- inDataSize -= afterEndData_Size;
- if (!prev)
- inDataSize_Start = parse.srcSize;
- break;
- }
-
- {
- // partial parsed - need cross transfer
- if (crossSize != 0)
- inDataSize = parse.srcSize; // it's only parsed now
- else
- {
- // partial parsed - is not in initial cross block - we need to copy new data to cross block
- Byte *cr = MtDec_GetCrossBuff(p);
- if (!cr)
- {
- {
- PRF(printf("\ncross alloc error error\n"));
- // res = SZ_ERROR_MEM;
- finish = True;
- // p->allocError_for_Read_BlockIndex = blockIndex;
- isAllocError = True;
- break;
- }
- }
-
- {
- size_t crSize = size - parse.srcSize;
- inDataSize -= crSize;
- p->crossEnd = crSize;
- p->crossStart = 0;
- memcpy(cr, parseData + parse.srcSize, crSize);
- }
- }
-
- // inDataSize_Full = inDataSize;
- if (!prev)
- inDataSize_Start = parse.srcSize; // it's partial size (parsed only)
-
- finish = False;
- break;
- }
- }
-
- if (parse.srcSize != size)
- {
- res = SZ_ERROR_FAIL;
- PRF(printf("\nfinished error SZ_ERROR_FAIL = %d\n", res));
- break;
- }
- }
- }
-
- prev = link;
- link = link->next;
-
- if (crossSize != 0)
- {
- crossSize = 0;
- p->crossStart = 0;
- p->crossEnd = 0;
- }
- }
- }
-
- if (res == SZ_OK)
- res = MtDec_GetError_Spec(p, blockIndex, &wasInterrupted);
- }
-
- codeRes = SZ_OK;
-
- if (res == SZ_OK && needCode && !wasInterrupted)
- {
- codeRes = p->mtCallback->PreCode(p->mtCallbackObject, t->index);
- if (codeRes != SZ_OK)
- {
- needCode = False;
- finish = True;
- // SZ_ERROR_MEM is expected error here.
- // if (codeRes == SZ_ERROR_MEM) - we will try single-thread decoding later.
- // if (codeRes != SZ_ERROR_MEM) - we can stop decoding or try single-thread decoding.
- }
- }
-
- if (res != SZ_OK || wasInterrupted)
- finish = True;
-
- nextThread = NULL;
- threadingErrorSRes = SZ_OK;
-
- if (!finish)
- {
- if (p->numStartedThreads < p->numStartedThreads_Limit && canCreateNewThread)
- {
- SRes res2 = MtDecThread_CreateAndStart(&p->threads[p->numStartedThreads]);
- if (res2 == SZ_OK)
- {
- // if (p->numStartedThreads % 1000 == 0) PRF(printf("\n numStartedThreads=%d\n", p->numStartedThreads));
- p->numStartedThreads++;
- }
- else
- {
- PRF(printf("\nERROR: numStartedThreads=%d\n", p->numStartedThreads));
- if (p->numStartedThreads == 1)
- {
- // if only one thread is possible, we leave muti-threading code
- finish = True;
- needCode = False;
- threadingErrorSRes = res2;
- }
- else
- p->numStartedThreads_Limit = p->numStartedThreads;
- }
- }
-
- if (!finish)
- {
- unsigned nextIndex = t->index + 1;
- nextThread = &p->threads[nextIndex >= p->numStartedThreads ? 0 : nextIndex];
- RINOK_THREAD(Event_Set(&nextThread->canRead))
- // We have started executing for new iteration (with next thread)
- // And that next thread now is responsible for possible exit from decoding (threading_code)
- }
- }
-
- // each call of Event_Set(&nextThread->canRead) must be followed by call of Event_Set(&nextThread->canWrite)
- // if ( !finish ) we must call Event_Set(&nextThread->canWrite) in any case
- // if ( finish ) we switch to single-thread mode and there are 2 ways at the end of current iteration (current block):
- // - if (needContinue) after Write(&needContinue), we restore decoding with new iteration
- // - otherwise we stop decoding and exit from ThreadFunc2()
-
- // Don't change (finish) variable in the further code
-
-
- // ---------- CODE ----------
-
- inPrev = 0;
- outPrev = 0;
- inCodePos = 0;
- outCodePos = 0;
-
- if (res == SZ_OK && needCode && codeRes == SZ_OK)
- {
- BoolInt isStartBlock = True;
- CMtDecBufLink *link = (CMtDecBufLink *)t->inBuf;
-
- for (;;)
- {
- size_t inSize;
- int stop;
-
- if (isStartBlock)
- inSize = inDataSize_Start;
- else
- {
- UInt64 rem = inDataSize - inCodePos;
- inSize = p->inBufSize;
- if (inSize > rem)
- inSize = (size_t)rem;
- }
-
- inCodePos += inSize;
- stop = True;
-
- codeRes = p->mtCallback->Code(p->mtCallbackObject, t->index,
- (const Byte *)MTDEC__DATA_PTR_FROM_LINK(link), inSize,
- (inCodePos == inDataSize), // srcFinished
- &inCodePos, &outCodePos, &stop);
-
- if (codeRes != SZ_OK)
- {
- PRF(printf("\nCode Interrupt error = %x\n", codeRes));
- // we interrupt only later blocks
- MtDec_Interrupt(p, blockIndex);
- break;
- }
-
- if (stop || inCodePos == inDataSize)
- break;
-
- {
- const UInt64 inDelta = inCodePos - inPrev;
- const UInt64 outDelta = outCodePos - outPrev;
- if (inDelta >= MTDEC_ProgessStep || outDelta >= MTDEC_ProgessStep)
- {
- // Sleep(1);
- res = MtDec_Progress_GetError_Spec(p, inDelta, outDelta, blockIndex, &wasInterrupted);
- if (res != SZ_OK || wasInterrupted)
- break;
- inPrev = inCodePos;
- outPrev = outCodePos;
- }
- }
-
- link = link->next;
- isStartBlock = False;
- }
- }
-
-
- // ---------- WRITE ----------
-
- RINOK_THREAD(Event_Wait(&t->canWrite));
-
- {
- BoolInt isErrorMode = False;
- BoolInt canRecode = True;
- BoolInt needWriteToStream = needWrite;
-
- if (p->exitThread) return 0; // it's never executed in normal cases
-
- if (p->wasInterrupted)
- wasInterrupted = True;
- else
- {
- if (codeRes != SZ_OK) // || !needCode // check it !!!
- {
- p->wasInterrupted = True;
- p->codeRes = codeRes;
- if (codeRes == SZ_ERROR_MEM)
- isAllocError = True;
- }
-
- if (threadingErrorSRes)
- {
- p->wasInterrupted = True;
- p->threadingErrorSRes = threadingErrorSRes;
- needWriteToStream = False;
- }
- if (isAllocError)
- {
- p->wasInterrupted = True;
- p->isAllocError = True;
- needWriteToStream = False;
- }
- if (overflow)
- {
- p->wasInterrupted = True;
- p->overflow = True;
- needWriteToStream = False;
- }
- }
-
- if (needCode)
- {
- if (wasInterrupted)
- {
- inCodePos = 0;
- outCodePos = 0;
- }
- {
- const UInt64 inDelta = inCodePos - inPrev;
- const UInt64 outDelta = outCodePos - outPrev;
- // if (inDelta != 0 || outDelta != 0)
- res = MtProgress_ProgressAdd(&p->mtProgress, inDelta, outDelta);
- }
- }
-
- needContinue = (!finish);
-
- // if (res == SZ_OK && needWrite && !wasInterrupted)
- if (needWrite)
- {
- // p->inProcessed += inCodePos;
-
- PRF(printf("\n--Write afterSize = %d\n", (unsigned)afterEndData_Size));
-
- res = p->mtCallback->Write(p->mtCallbackObject, t->index,
- res == SZ_OK && needWriteToStream && !wasInterrupted, // needWrite
- afterEndData, afterEndData_Size, afterEndData_IsCross,
- &needContinue,
- &canRecode);
-
- // res = SZ_ERROR_FAIL; // for test
-
- PRF(printf("\nAfter Write needContinue = %d\n", (unsigned)needContinue));
- PRF(printf("\nprocessed = %d\n", (unsigned)p->inProcessed));
-
- if (res != SZ_OK)
- {
- PRF(printf("\nWrite error = %d\n", res));
- isErrorMode = True;
- p->wasInterrupted = True;
- }
- if (res != SZ_OK
- || (!needContinue && !finish))
- {
- PRF(printf("\nWrite Interrupt error = %x\n", res));
- MtDec_Interrupt(p, blockIndex);
- }
- }
-
- if (canRecode)
- if (!needCode
- || res != SZ_OK
- || p->wasInterrupted
- || codeRes != SZ_OK
- || wasInterrupted
- || p->numFilledThreads != 0
- || isErrorMode)
- {
- if (p->numFilledThreads == 0)
- p->filledThreadStart = t->index;
- if (inDataSize != 0 || !finish)
- {
- t->inDataSize_Start = inDataSize_Start;
- t->inDataSize = inDataSize;
- p->numFilledThreads++;
- }
- PRF(printf("\np->numFilledThreads = %d\n", p->numFilledThreads));
- PRF(printf("p->filledThreadStart = %d\n", p->filledThreadStart));
- }
-
- if (!finish)
- {
- RINOK_THREAD(Event_Set(&nextThread->canWrite));
- }
- else
- {
- if (needContinue)
- {
- // we restore decoding with new iteration
- RINOK_THREAD(Event_Set(&p->threads[0].canWrite));
- }
- else
- {
- // we exit from decoding
- if (t->index == 0)
- return SZ_OK;
- p->exitThread = True;
- }
- RINOK_THREAD(Event_Set(&p->threads[0].canRead));
- }
- }
- }
-}
-
-#ifdef _WIN32
-#define USE_ALLOCA
-#endif
-
-#ifdef USE_ALLOCA
-#ifdef _WIN32
-#include
-#else
-#include
-#endif
-#endif
-
-
-static THREAD_FUNC_DECL ThreadFunc1(void *pp)
-{
- WRes res;
-
- CMtDecThread *t = (CMtDecThread *)pp;
- CMtDec *p;
-
- // fprintf(stdout, "\n%d = %p\n", t->index, &t);
-
- res = ThreadFunc2(t);
- p = t->mtDec;
- if (res == 0)
- return (THREAD_FUNC_RET_TYPE)(UINT_PTR)p->exitThreadWRes;
- {
- // it's unexpected situation for some threading function error
- if (p->exitThreadWRes == 0)
- p->exitThreadWRes = res;
- PRF(printf("\nthread exit error = %d\n", res));
- p->exitThread = True;
- Event_Set(&p->threads[0].canRead);
- Event_Set(&p->threads[0].canWrite);
- MtProgress_SetError(&p->mtProgress, MY_SRes_HRESULT_FROM_WRes(res));
- }
- return (THREAD_FUNC_RET_TYPE)(UINT_PTR)res;
-}
-
-static MY_NO_INLINE THREAD_FUNC_DECL ThreadFunc(void *pp)
-{
- #ifdef USE_ALLOCA
- CMtDecThread *t = (CMtDecThread *)pp;
- // fprintf(stderr, "\n%d = %p - before", t->index, &t);
- t->allocaPtr = alloca(t->index * 128);
- #endif
- return ThreadFunc1(pp);
-}
-
-
-int MtDec_PrepareRead(CMtDec *p)
-{
- if (p->crossBlock && p->crossStart == p->crossEnd)
- {
- ISzAlloc_Free(p->alloc, p->crossBlock);
- p->crossBlock = NULL;
- }
-
- {
- unsigned i;
- for (i = 0; i < MTDEC__THREADS_MAX; i++)
- if (i > p->numStartedThreads
- || p->numFilledThreads <=
- (i >= p->filledThreadStart ?
- i - p->filledThreadStart :
- i + p->numStartedThreads - p->filledThreadStart))
- MtDecThread_FreeInBufs(&p->threads[i]);
- }
-
- return (p->numFilledThreads != 0) || (p->crossStart != p->crossEnd);
-}
-
-
-const Byte *MtDec_Read(CMtDec *p, size_t *inLim)
-{
- while (p->numFilledThreads != 0)
- {
- CMtDecThread *t = &p->threads[p->filledThreadStart];
-
- if (*inLim != 0)
- {
- {
- void *link = t->inBuf;
- void *next = ((CMtDecBufLink *)link)->next;
- ISzAlloc_Free(p->alloc, link);
- t->inBuf = next;
- }
-
- if (t->inDataSize == 0)
- {
- MtDecThread_FreeInBufs(t);
- if (--p->numFilledThreads == 0)
- break;
- if (++p->filledThreadStart == p->numStartedThreads)
- p->filledThreadStart = 0;
- t = &p->threads[p->filledThreadStart];
- }
- }
-
- {
- size_t lim = t->inDataSize_Start;
- if (lim != 0)
- t->inDataSize_Start = 0;
- else
- {
- UInt64 rem = t->inDataSize;
- lim = p->inBufSize;
- if (lim > rem)
- lim = (size_t)rem;
- }
- t->inDataSize -= lim;
- *inLim = lim;
- return (const Byte *)MTDEC__DATA_PTR_FROM_LINK(t->inBuf);
- }
- }
-
- {
- size_t crossSize = p->crossEnd - p->crossStart;
- if (crossSize != 0)
- {
- const Byte *data = MTDEC__DATA_PTR_FROM_LINK(p->crossBlock) + p->crossStart;
- *inLim = crossSize;
- p->crossStart = 0;
- p->crossEnd = 0;
- return data;
- }
- *inLim = 0;
- if (p->crossBlock)
- {
- ISzAlloc_Free(p->alloc, p->crossBlock);
- p->crossBlock = NULL;
- }
- return NULL;
- }
-}
-
-
-void MtDec_Construct(CMtDec *p)
-{
- unsigned i;
-
- p->inBufSize = (size_t)1 << 18;
-
- p->numThreadsMax = 0;
-
- p->inStream = NULL;
-
- // p->inData = NULL;
- // p->inDataSize = 0;
-
- p->crossBlock = NULL;
- p->crossStart = 0;
- p->crossEnd = 0;
-
- p->numFilledThreads = 0;
-
- p->progress = NULL;
- p->alloc = NULL;
-
- p->mtCallback = NULL;
- p->mtCallbackObject = NULL;
-
- p->allocatedBufsSize = 0;
-
- for (i = 0; i < MTDEC__THREADS_MAX; i++)
- {
- CMtDecThread *t = &p->threads[i];
- t->mtDec = p;
- t->index = i;
- t->inBuf = NULL;
- Event_Construct(&t->canRead);
- Event_Construct(&t->canWrite);
- Thread_Construct(&t->thread);
- }
-
- // Event_Construct(&p->finishedEvent);
-
- CriticalSection_Init(&p->mtProgress.cs);
-}
-
-
-static void MtDec_Free(CMtDec *p)
-{
- unsigned i;
-
- p->exitThread = True;
-
- for (i = 0; i < MTDEC__THREADS_MAX; i++)
- MtDecThread_Destruct(&p->threads[i]);
-
- // Event_Close(&p->finishedEvent);
-
- if (p->crossBlock)
- {
- ISzAlloc_Free(p->alloc, p->crossBlock);
- p->crossBlock = NULL;
- }
-}
-
-
-void MtDec_Destruct(CMtDec *p)
-{
- MtDec_Free(p);
-
- CriticalSection_Delete(&p->mtProgress.cs);
-}
-
-
-SRes MtDec_Code(CMtDec *p)
-{
- unsigned i;
-
- p->inProcessed = 0;
-
- p->blockIndex = 1; // it must be larger than not_defined index (0)
- p->isAllocError = False;
- p->overflow = False;
- p->threadingErrorSRes = SZ_OK;
-
- p->needContinue = True;
-
- p->readWasFinished = False;
- p->needInterrupt = False;
- p->interruptIndex = (UInt64)(Int64)-1;
-
- p->readProcessed = 0;
- p->readRes = SZ_OK;
- p->codeRes = SZ_OK;
- p->wasInterrupted = False;
-
- p->crossStart = 0;
- p->crossEnd = 0;
-
- p->filledThreadStart = 0;
- p->numFilledThreads = 0;
-
- {
- unsigned numThreads = p->numThreadsMax;
- if (numThreads > MTDEC__THREADS_MAX)
- numThreads = MTDEC__THREADS_MAX;
- p->numStartedThreads_Limit = numThreads;
- p->numStartedThreads = 0;
- }
-
- if (p->inBufSize != p->allocatedBufsSize)
- {
- for (i = 0; i < MTDEC__THREADS_MAX; i++)
- {
- CMtDecThread *t = &p->threads[i];
- if (t->inBuf)
- MtDecThread_FreeInBufs(t);
- }
- if (p->crossBlock)
- {
- ISzAlloc_Free(p->alloc, p->crossBlock);
- p->crossBlock = NULL;
- }
-
- p->allocatedBufsSize = p->inBufSize;
- }
-
- MtProgress_Init(&p->mtProgress, p->progress);
-
- // RINOK_THREAD(ArEvent_OptCreate_And_Reset(&p->finishedEvent));
- p->exitThread = False;
- p->exitThreadWRes = 0;
-
- {
- WRes wres;
- SRes sres;
- CMtDecThread *nextThread = &p->threads[p->numStartedThreads++];
- // wres = MtDecThread_CreateAndStart(nextThread);
- wres = MtDecThread_CreateEvents(nextThread);
- if (wres == 0) { wres = Event_Set(&nextThread->canWrite);
- if (wres == 0) { wres = Event_Set(&nextThread->canRead);
- if (wres == 0) { THREAD_FUNC_RET_TYPE res = ThreadFunc(nextThread);
- wres = (WRes)(UINT_PTR)res;
- if (wres != 0)
- {
- p->needContinue = False;
- MtDec_CloseThreads(p);
- }}}}
-
- // wres = 17; // for test
- // wres = Event_Wait(&p->finishedEvent);
-
- sres = MY_SRes_HRESULT_FROM_WRes(wres);
-
- if (sres != 0)
- p->threadingErrorSRes = sres;
-
- if (
- // wres == 0
- // wres != 0
- // || p->mtc.codeRes == SZ_ERROR_MEM
- p->isAllocError
- || p->threadingErrorSRes != SZ_OK
- || p->overflow)
- {
- // p->needContinue = True;
- }
- else
- p->needContinue = False;
-
- if (p->needContinue)
- return SZ_OK;
-
- // if (sres != SZ_OK)
- return sres;
- // return SZ_ERROR_FAIL;
- }
-}
-
-#endif
diff --git a/deps/libchdr/deps/lzma-22.01/src/Sort.c b/deps/libchdr/deps/lzma-22.01/src/Sort.c
deleted file mode 100644
index 73dcbf05..00000000
--- a/deps/libchdr/deps/lzma-22.01/src/Sort.c
+++ /dev/null
@@ -1,141 +0,0 @@
-/* Sort.c -- Sort functions
-2014-04-05 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#include "Sort.h"
-
-#define HeapSortDown(p, k, size, temp) \
- { for (;;) { \
- size_t s = (k << 1); \
- if (s > size) break; \
- if (s < size && p[s + 1] > p[s]) s++; \
- if (temp >= p[s]) break; \
- p[k] = p[s]; k = s; \
- } p[k] = temp; }
-
-void HeapSort(UInt32 *p, size_t size)
-{
- if (size <= 1)
- return;
- p--;
- {
- size_t i = size / 2;
- do
- {
- UInt32 temp = p[i];
- size_t k = i;
- HeapSortDown(p, k, size, temp)
- }
- while (--i != 0);
- }
- /*
- do
- {
- size_t k = 1;
- UInt32 temp = p[size];
- p[size--] = p[1];
- HeapSortDown(p, k, size, temp)
- }
- while (size > 1);
- */
- while (size > 3)
- {
- UInt32 temp = p[size];
- size_t k = (p[3] > p[2]) ? 3 : 2;
- p[size--] = p[1];
- p[1] = p[k];
- HeapSortDown(p, k, size, temp)
- }
- {
- UInt32 temp = p[size];
- p[size] = p[1];
- if (size > 2 && p[2] < temp)
- {
- p[1] = p[2];
- p[2] = temp;
- }
- else
- p[1] = temp;
- }
-}
-
-void HeapSort64(UInt64 *p, size_t size)
-{
- if (size <= 1)
- return;
- p--;
- {
- size_t i = size / 2;
- do
- {
- UInt64 temp = p[i];
- size_t k = i;
- HeapSortDown(p, k, size, temp)
- }
- while (--i != 0);
- }
- /*
- do
- {
- size_t k = 1;
- UInt64 temp = p[size];
- p[size--] = p[1];
- HeapSortDown(p, k, size, temp)
- }
- while (size > 1);
- */
- while (size > 3)
- {
- UInt64 temp = p[size];
- size_t k = (p[3] > p[2]) ? 3 : 2;
- p[size--] = p[1];
- p[1] = p[k];
- HeapSortDown(p, k, size, temp)
- }
- {
- UInt64 temp = p[size];
- p[size] = p[1];
- if (size > 2 && p[2] < temp)
- {
- p[1] = p[2];
- p[2] = temp;
- }
- else
- p[1] = temp;
- }
-}
-
-/*
-#define HeapSortRefDown(p, vals, n, size, temp) \
- { size_t k = n; UInt32 val = vals[temp]; for (;;) { \
- size_t s = (k << 1); \
- if (s > size) break; \
- if (s < size && vals[p[s + 1]] > vals[p[s]]) s++; \
- if (val >= vals[p[s]]) break; \
- p[k] = p[s]; k = s; \
- } p[k] = temp; }
-
-void HeapSortRef(UInt32 *p, UInt32 *vals, size_t size)
-{
- if (size <= 1)
- return;
- p--;
- {
- size_t i = size / 2;
- do
- {
- UInt32 temp = p[i];
- HeapSortRefDown(p, vals, i, size, temp);
- }
- while (--i != 0);
- }
- do
- {
- UInt32 temp = p[size];
- p[size--] = p[1];
- HeapSortRefDown(p, vals, 1, size, temp);
- }
- while (size > 1);
-}
-*/
diff --git a/deps/libchdr/deps/lzma-22.01/src/var_clang.mak b/deps/libchdr/deps/lzma-22.01/src/var_clang.mak
deleted file mode 100644
index ee265698..00000000
--- a/deps/libchdr/deps/lzma-22.01/src/var_clang.mak
+++ /dev/null
@@ -1,11 +0,0 @@
-PLATFORM=
-O=b/c
-IS_X64=
-IS_X86=
-IS_ARM64=
-CROSS_COMPILE=
-MY_ARCH=
-USE_ASM=
-CC=$(CROSS_COMPILE)clang
-CXX=$(CROSS_COMPILE)clang++
-USE_CLANG=1
diff --git a/deps/libchdr/deps/lzma-22.01/src/var_clang_arm64.mak b/deps/libchdr/deps/lzma-22.01/src/var_clang_arm64.mak
deleted file mode 100644
index 1e82d2eb..00000000
--- a/deps/libchdr/deps/lzma-22.01/src/var_clang_arm64.mak
+++ /dev/null
@@ -1,11 +0,0 @@
-PLATFORM=arm64
-O=b/c_$(PLATFORM)
-IS_X64=
-IS_X86=
-IS_ARM64=1
-CROSS_COMPILE=
-MY_ARCH=
-USE_ASM=1
-CC=$(CROSS_COMPILE)clang
-CXX=$(CROSS_COMPILE)clang++
-USE_CLANG=1
diff --git a/deps/libchdr/deps/lzma-22.01/src/var_clang_x64.mak b/deps/libchdr/deps/lzma-22.01/src/var_clang_x64.mak
deleted file mode 100644
index b35f0cca..00000000
--- a/deps/libchdr/deps/lzma-22.01/src/var_clang_x64.mak
+++ /dev/null
@@ -1,11 +0,0 @@
-PLATFORM=x64
-O=b/c_$(PLATFORM)
-IS_X64=1
-IS_X86=
-IS_ARM64=
-CROSS_COMPILE=
-MY_ARCH=
-USE_ASM=1
-CC=$(CROSS_COMPILE)clang
-CXX=$(CROSS_COMPILE)clang++
-USE_CLANG=1
diff --git a/deps/libchdr/deps/lzma-22.01/src/var_clang_x86.mak b/deps/libchdr/deps/lzma-22.01/src/var_clang_x86.mak
deleted file mode 100644
index d18f0ae1..00000000
--- a/deps/libchdr/deps/lzma-22.01/src/var_clang_x86.mak
+++ /dev/null
@@ -1,11 +0,0 @@
-PLATFORM=x86
-O=b/c_$(PLATFORM)
-IS_X64=
-IS_X86=1
-IS_ARM64=
-CROSS_COMPILE=
-MY_ARCH=-m32
-USE_ASM=1
-CC=$(CROSS_COMPILE)clang
-CXX=$(CROSS_COMPILE)clang++
-USE_CLANG=1
diff --git a/deps/libchdr/deps/lzma-22.01/src/var_gcc.mak b/deps/libchdr/deps/lzma-22.01/src/var_gcc.mak
deleted file mode 100644
index 803c8de9..00000000
--- a/deps/libchdr/deps/lzma-22.01/src/var_gcc.mak
+++ /dev/null
@@ -1,12 +0,0 @@
-PLATFORM=
-O=b/g
-IS_X64=
-IS_X86=
-IS_ARM64=
-CROSS_COMPILE=
-MY_ARCH=
-USE_ASM=
-CC=$(CROSS_COMPILE)gcc
-CXX=$(CROSS_COMPILE)g++
-
-# -march=armv8-a+crc+crypto
diff --git a/deps/libchdr/deps/lzma-22.01/src/var_gcc_arm64.mak b/deps/libchdr/deps/lzma-22.01/src/var_gcc_arm64.mak
deleted file mode 100644
index 562cfaa6..00000000
--- a/deps/libchdr/deps/lzma-22.01/src/var_gcc_arm64.mak
+++ /dev/null
@@ -1,12 +0,0 @@
-PLATFORM=arm64
-O=b/g_$(PLATFORM)
-IS_X64=
-IS_X86=
-IS_ARM64=1
-CROSS_COMPILE=
-MY_ARCH=-mtune=cortex-a53
-USE_ASM=1
-CC=$(CROSS_COMPILE)gcc
-CXX=$(CROSS_COMPILE)g++
-
-# -march=armv8-a+crc+crypto
diff --git a/deps/libchdr/deps/lzma-22.01/src/var_gcc_x64.mak b/deps/libchdr/deps/lzma-22.01/src/var_gcc_x64.mak
deleted file mode 100644
index 1b965b21..00000000
--- a/deps/libchdr/deps/lzma-22.01/src/var_gcc_x64.mak
+++ /dev/null
@@ -1,10 +0,0 @@
-PLATFORM=x64
-O=b/g_$(PLATFORM)
-IS_X64=1
-IS_X86=
-IS_ARM64=
-CROSS_COMPILE=
-MY_ARCH=
-USE_ASM=1
-CC=$(CROSS_COMPILE)gcc
-CXX=$(CROSS_COMPILE)g++
diff --git a/deps/libchdr/deps/lzma-22.01/src/var_gcc_x86.mak b/deps/libchdr/deps/lzma-22.01/src/var_gcc_x86.mak
deleted file mode 100644
index 3adf4a84..00000000
--- a/deps/libchdr/deps/lzma-22.01/src/var_gcc_x86.mak
+++ /dev/null
@@ -1,10 +0,0 @@
-PLATFORM=x86
-O=b/g_$(PLATFORM)
-IS_X64=
-IS_X86=1
-IS_ARM64=
-CROSS_COMPILE=
-MY_ARCH=-m32
-USE_ASM=1
-CC=$(CROSS_COMPILE)gcc
-CXX=$(CROSS_COMPILE)g++
diff --git a/deps/libchdr/deps/lzma-22.01/src/var_mac_arm64.mak b/deps/libchdr/deps/lzma-22.01/src/var_mac_arm64.mak
deleted file mode 100644
index 0ba41423..00000000
--- a/deps/libchdr/deps/lzma-22.01/src/var_mac_arm64.mak
+++ /dev/null
@@ -1,11 +0,0 @@
-PLATFORM=arm64
-O=b/m_$(PLATFORM)
-IS_X64=
-IS_X86=
-IS_ARM64=1
-CROSS_COMPILE=
-MY_ARCH=-arch arm64
-USE_ASM=1
-CC=$(CROSS_COMPILE)clang
-CXX=$(CROSS_COMPILE)clang++
-USE_CLANG=1
diff --git a/deps/libchdr/deps/lzma-22.01/src/var_mac_x64.mak b/deps/libchdr/deps/lzma-22.01/src/var_mac_x64.mak
deleted file mode 100644
index 92b15c8b..00000000
--- a/deps/libchdr/deps/lzma-22.01/src/var_mac_x64.mak
+++ /dev/null
@@ -1,11 +0,0 @@
-PLATFORM=x64
-O=b/m_$(PLATFORM)
-IS_X64=1
-IS_X86=
-IS_ARM64=
-CROSS_COMPILE=
-MY_ARCH=-arch x86_64
-USE_ASM=
-CC=$(CROSS_COMPILE)clang
-CXX=$(CROSS_COMPILE)clang++
-USE_CLANG=1
diff --git a/deps/libchdr/deps/lzma-22.01/src/warn_clang.mak b/deps/libchdr/deps/lzma-22.01/src/warn_clang.mak
deleted file mode 100644
index a299fbc4..00000000
--- a/deps/libchdr/deps/lzma-22.01/src/warn_clang.mak
+++ /dev/null
@@ -1,37 +0,0 @@
-CFLAGS_WARN_CLANG_3_8_UNIQ = \
- -Wno-reserved-id-macro \
- -Wno-old-style-cast \
- -Wno-c++11-long-long \
- -Wno-unused-macros \
-
-CFLAGS_WARN_CLANG_3_8 = \
- $(CFLAGS_WARN_CLANG_3_8_UNIQ) \
- -Weverything \
- -Wno-extra-semi \
- -Wno-sign-conversion \
- -Wno-language-extension-token \
- -Wno-global-constructors \
- -Wno-non-virtual-dtor \
- -Wno-switch-enum \
- -Wno-covered-switch-default \
- -Wno-cast-qual \
- -Wno-padded \
- -Wno-exit-time-destructors \
- -Wno-weak-vtables \
-
-CFLAGS_WARN_CLANG_12= $(CFLAGS_WARN_CLANG_3_8) \
- -Wno-extra-semi-stmt \
- -Wno-zero-as-null-pointer-constant \
- -Wno-deprecated-dynamic-exception-spec \
- -Wno-c++98-compat-pedantic \
- -Wno-atomic-implicit-seq-cst \
- -Wconversion \
- -Wno-sign-conversion \
-
-CFLAGS_WARN_1 = \
- -Wno-deprecated-copy-dtor \
-
-
-
-
-CFLAGS_WARN = $(CFLAGS_WARN_CLANG_12) $(CFLAGS_WARN_1)
diff --git a/deps/libchdr/deps/lzma-22.01/src/warn_clang_mac.mak b/deps/libchdr/deps/lzma-22.01/src/warn_clang_mac.mak
deleted file mode 100644
index cfbbda07..00000000
--- a/deps/libchdr/deps/lzma-22.01/src/warn_clang_mac.mak
+++ /dev/null
@@ -1,37 +0,0 @@
-CFLAGS_WARN_CLANG_3_8_UNIQ = \
- -Wno-reserved-id-macro \
- -Wno-old-style-cast \
- -Wno-c++11-long-long \
- -Wno-unused-macros \
-
-CFLAGS_WARN_CLANG_3_8 = \
- $(CFLAGS_WARN_CLANG_3_8_UNIQ) \
- -Weverything \
- -Wno-extra-semi \
- -Wno-sign-conversion \
- -Wno-language-extension-token \
- -Wno-global-constructors \
- -Wno-non-virtual-dtor \
- -Wno-switch-enum \
- -Wno-covered-switch-default \
- -Wno-cast-qual \
- -Wno-padded \
- -Wno-exit-time-destructors \
- -Wno-weak-vtables \
-
-CFLAGS_WARN_CLANG_12= $(CFLAGS_WARN_CLANG_3_8) \
- -Wno-extra-semi-stmt \
- -Wno-zero-as-null-pointer-constant \
- -Wno-deprecated-dynamic-exception-spec \
- -Wno-c++98-compat-pedantic \
- -Wno-atomic-implicit-seq-cst \
- -Wconversion \
- -Wno-sign-conversion \
-
-CFLAGS_WARN_MAC = \
- -Wno-poison-system-directories \
- -Wno-c++11-long-long \
- -Wno-atomic-implicit-seq-cst \
-
-
-CFLAGS_WARN = $(CFLAGS_WARN_CLANG_12) $(CFLAGS_WARN_MAC)
diff --git a/deps/libchdr/deps/lzma-22.01/src/warn_gcc.mak b/deps/libchdr/deps/lzma-22.01/src/warn_gcc.mak
deleted file mode 100644
index 8fbdb28f..00000000
--- a/deps/libchdr/deps/lzma-22.01/src/warn_gcc.mak
+++ /dev/null
@@ -1,51 +0,0 @@
-CFLAGS_WARN_GCC_4_5 = \
-
-CFLAGS_WARN_GCC_6 = \
- -Waddress \
- -Waggressive-loop-optimizations \
- -Wattributes \
- -Wbool-compare \
- -Wcast-align \
- -Wcomment \
- -Wdiv-by-zero \
- -Wduplicated-cond \
- -Wformat-contains-nul \
- -Winit-self \
- -Wint-to-pointer-cast \
- -Wunused \
- -Wunused-macros \
-
-# -Wno-strict-aliasing
-
-CFLAGS_WARN_GCC_9 = \
- -Waddress \
- -Waddress-of-packed-member \
- -Waggressive-loop-optimizations \
- -Wattributes \
- -Wbool-compare \
- -Wbool-operation \
- -Wcast-align \
- -Wcast-align=strict \
- -Wcomment \
- -Wdangling-else \
- -Wdiv-by-zero \
- -Wduplicated-branches \
- -Wduplicated-cond \
- -Wformat-contains-nul \
- -Wimplicit-fallthrough=5 \
- -Winit-self \
- -Wint-in-bool-context \
- -Wint-to-pointer-cast \
- -Wunused \
- -Wunused-macros \
- -Wconversion \
-
-# -Wno-sign-conversion \
-
-CFLAGS_WARN_GCC_PPMD_UNALIGNED = \
- -Wno-strict-aliasing \
-
-
-CFLAGS_WARN = $(CFLAGS_WARN_GCC_9) \
-
-# $(CFLAGS_WARN_GCC_PPMD_UNALIGNED)
diff --git a/deps/libchdr/deps/lzma-22.01/src/Asm/arm64/7zAsm.S b/deps/libchdr/deps/lzma-24.05/Asm/arm64/7zAsm.S
similarity index 94%
rename from deps/libchdr/deps/lzma-22.01/src/Asm/arm64/7zAsm.S
rename to deps/libchdr/deps/lzma-24.05/Asm/arm64/7zAsm.S
index 67d650d9..12e950b4 100644
--- a/deps/libchdr/deps/lzma-22.01/src/Asm/arm64/7zAsm.S
+++ b/deps/libchdr/deps/lzma-24.05/Asm/arm64/7zAsm.S
@@ -1,181 +1,181 @@
-// 7zAsm.S -- ASM macros for arm64
-// 2021-04-25 : Igor Pavlov : Public domain
-
-#define r0 x0
-#define r1 x1
-#define r2 x2
-#define r3 x3
-#define r4 x4
-#define r5 x5
-#define r6 x6
-#define r7 x7
-#define r8 x8
-#define r9 x9
-#define r10 x10
-#define r11 x11
-#define r12 x12
-#define r13 x13
-#define r14 x14
-#define r15 x15
-#define r16 x16
-#define r17 x17
-#define r18 x18
-#define r19 x19
-#define r20 x20
-#define r21 x21
-#define r22 x22
-#define r23 x23
-#define r24 x24
-#define r25 x25
-#define r26 x26
-#define r27 x27
-#define r28 x28
-#define r29 x29
-#define r30 x30
-
-#define REG_ABI_PARAM_0 r0
-#define REG_ABI_PARAM_1 r1
-#define REG_ABI_PARAM_2 r2
-
-
-.macro p2_add reg:req, param:req
- add \reg, \reg, \param
-.endm
-
-.macro p2_sub reg:req, param:req
- sub \reg, \reg, \param
-.endm
-
-.macro p2_sub_s reg:req, param:req
- subs \reg, \reg, \param
-.endm
-
-.macro p2_and reg:req, param:req
- and \reg, \reg, \param
-.endm
-
-.macro xor reg:req, param:req
- eor \reg, \reg, \param
-.endm
-
-.macro or reg:req, param:req
- orr \reg, \reg, \param
-.endm
-
-.macro shl reg:req, param:req
- lsl \reg, \reg, \param
-.endm
-
-.macro shr reg:req, param:req
- lsr \reg, \reg, \param
-.endm
-
-.macro sar reg:req, param:req
- asr \reg, \reg, \param
-.endm
-
-.macro p1_neg reg:req
- neg \reg, \reg
-.endm
-
-.macro dec reg:req
- sub \reg, \reg, 1
-.endm
-
-.macro dec_s reg:req
- subs \reg, \reg, 1
-.endm
-
-.macro inc reg:req
- add \reg, \reg, 1
-.endm
-
-.macro inc_s reg:req
- adds \reg, \reg, 1
-.endm
-
-
-.macro imul reg:req, param:req
- mul \reg, \reg, \param
-.endm
-
-/*
-arm64 and arm use reverted c flag after subs/cmp instructions:
- arm64-arm : x86
- b.lo / b.cc : jb / jc
- b.hs / b.cs : jae / jnc
-*/
-
-.macro jmp lab:req
- b \lab
-.endm
-
-.macro je lab:req
- b.eq \lab
-.endm
-
-.macro jz lab:req
- b.eq \lab
-.endm
-
-.macro jnz lab:req
- b.ne \lab
-.endm
-
-.macro jne lab:req
- b.ne \lab
-.endm
-
-.macro jb lab:req
- b.lo \lab
-.endm
-
-.macro jbe lab:req
- b.ls \lab
-.endm
-
-.macro ja lab:req
- b.hi \lab
-.endm
-
-.macro jae lab:req
- b.hs \lab
-.endm
-
-
-.macro cmove dest:req, srcTrue:req
- csel \dest, \srcTrue, \dest, eq
-.endm
-
-.macro cmovne dest:req, srcTrue:req
- csel \dest, \srcTrue, \dest, ne
-.endm
-
-.macro cmovs dest:req, srcTrue:req
- csel \dest, \srcTrue, \dest, mi
-.endm
-
-.macro cmovns dest:req, srcTrue:req
- csel \dest, \srcTrue, \dest, pl
-.endm
-
-.macro cmovb dest:req, srcTrue:req
- csel \dest, \srcTrue, \dest, lo
-.endm
-
-.macro cmovae dest:req, srcTrue:req
- csel \dest, \srcTrue, \dest, hs
-.endm
-
-
-.macro MY_ALIGN_16 macro
- .p2align 4,, (1 << 4) - 1
-.endm
-
-.macro MY_ALIGN_32 macro
- .p2align 5,, (1 << 5) - 1
-.endm
-
-.macro MY_ALIGN_64 macro
- .p2align 6,, (1 << 6) - 1
-.endm
+// 7zAsm.S -- ASM macros for arm64
+// 2021-04-25 : Igor Pavlov : Public domain
+
+#define r0 x0
+#define r1 x1
+#define r2 x2
+#define r3 x3
+#define r4 x4
+#define r5 x5
+#define r6 x6
+#define r7 x7
+#define r8 x8
+#define r9 x9
+#define r10 x10
+#define r11 x11
+#define r12 x12
+#define r13 x13
+#define r14 x14
+#define r15 x15
+#define r16 x16
+#define r17 x17
+#define r18 x18
+#define r19 x19
+#define r20 x20
+#define r21 x21
+#define r22 x22
+#define r23 x23
+#define r24 x24
+#define r25 x25
+#define r26 x26
+#define r27 x27
+#define r28 x28
+#define r29 x29
+#define r30 x30
+
+#define REG_ABI_PARAM_0 r0
+#define REG_ABI_PARAM_1 r1
+#define REG_ABI_PARAM_2 r2
+
+
+.macro p2_add reg:req, param:req
+ add \reg, \reg, \param
+.endm
+
+.macro p2_sub reg:req, param:req
+ sub \reg, \reg, \param
+.endm
+
+.macro p2_sub_s reg:req, param:req
+ subs \reg, \reg, \param
+.endm
+
+.macro p2_and reg:req, param:req
+ and \reg, \reg, \param
+.endm
+
+.macro xor reg:req, param:req
+ eor \reg, \reg, \param
+.endm
+
+.macro or reg:req, param:req
+ orr \reg, \reg, \param
+.endm
+
+.macro shl reg:req, param:req
+ lsl \reg, \reg, \param
+.endm
+
+.macro shr reg:req, param:req
+ lsr \reg, \reg, \param
+.endm
+
+.macro sar reg:req, param:req
+ asr \reg, \reg, \param
+.endm
+
+.macro p1_neg reg:req
+ neg \reg, \reg
+.endm
+
+.macro dec reg:req
+ sub \reg, \reg, 1
+.endm
+
+.macro dec_s reg:req
+ subs \reg, \reg, 1
+.endm
+
+.macro inc reg:req
+ add \reg, \reg, 1
+.endm
+
+.macro inc_s reg:req
+ adds \reg, \reg, 1
+.endm
+
+
+.macro imul reg:req, param:req
+ mul \reg, \reg, \param
+.endm
+
+/*
+arm64 and arm use reverted c flag after subs/cmp instructions:
+ arm64-arm : x86
+ b.lo / b.cc : jb / jc
+ b.hs / b.cs : jae / jnc
+*/
+
+.macro jmp lab:req
+ b \lab
+.endm
+
+.macro je lab:req
+ b.eq \lab
+.endm
+
+.macro jz lab:req
+ b.eq \lab
+.endm
+
+.macro jnz lab:req
+ b.ne \lab
+.endm
+
+.macro jne lab:req
+ b.ne \lab
+.endm
+
+.macro jb lab:req
+ b.lo \lab
+.endm
+
+.macro jbe lab:req
+ b.ls \lab
+.endm
+
+.macro ja lab:req
+ b.hi \lab
+.endm
+
+.macro jae lab:req
+ b.hs \lab
+.endm
+
+
+.macro cmove dest:req, srcTrue:req
+ csel \dest, \srcTrue, \dest, eq
+.endm
+
+.macro cmovne dest:req, srcTrue:req
+ csel \dest, \srcTrue, \dest, ne
+.endm
+
+.macro cmovs dest:req, srcTrue:req
+ csel \dest, \srcTrue, \dest, mi
+.endm
+
+.macro cmovns dest:req, srcTrue:req
+ csel \dest, \srcTrue, \dest, pl
+.endm
+
+.macro cmovb dest:req, srcTrue:req
+ csel \dest, \srcTrue, \dest, lo
+.endm
+
+.macro cmovae dest:req, srcTrue:req
+ csel \dest, \srcTrue, \dest, hs
+.endm
+
+
+.macro MY_ALIGN_16 macro
+ .p2align 4,, (1 << 4) - 1
+.endm
+
+.macro MY_ALIGN_32 macro
+ .p2align 5,, (1 << 5) - 1
+.endm
+
+.macro MY_ALIGN_64 macro
+ .p2align 6,, (1 << 6) - 1
+.endm
diff --git a/deps/libchdr/deps/lzma-22.01/src/Asm/arm64/LzmaDecOpt.S b/deps/libchdr/deps/lzma-24.05/Asm/arm64/LzmaDecOpt.S
similarity index 100%
rename from deps/libchdr/deps/lzma-22.01/src/Asm/arm64/LzmaDecOpt.S
rename to deps/libchdr/deps/lzma-24.05/Asm/arm64/LzmaDecOpt.S
diff --git a/deps/libchdr/deps/lzma-22.01/src/Asm/x86/7zAsm.asm b/deps/libchdr/deps/lzma-24.05/Asm/x86/7zAsm.asm
similarity index 82%
rename from deps/libchdr/deps/lzma-22.01/src/Asm/x86/7zAsm.asm
rename to deps/libchdr/deps/lzma-24.05/Asm/x86/7zAsm.asm
index 092d7bbc..8910d16c 100644
--- a/deps/libchdr/deps/lzma-22.01/src/Asm/x86/7zAsm.asm
+++ b/deps/libchdr/deps/lzma-24.05/Asm/x86/7zAsm.asm
@@ -1,289 +1,341 @@
-; 7zAsm.asm -- ASM macros
-; 2022-05-16 : Igor Pavlov : Public domain
-
-
-; UASM can require these changes
-; OPTION FRAMEPRESERVEFLAGS:ON
-; OPTION PROLOGUE:NONE
-; OPTION EPILOGUE:NONE
-
-ifdef @wordsize
-; @wordsize is defined only in JWASM and ASMC and is not defined in MASM
-; @wordsize eq 8 for 64-bit x64
-; @wordsize eq 2 for 32-bit x86
-if @wordsize eq 8
- x64 equ 1
-endif
-else
-ifdef RAX
- x64 equ 1
-endif
-endif
-
-
-ifdef x64
- IS_X64 equ 1
-else
- IS_X64 equ 0
-endif
-
-ifdef ABI_LINUX
- IS_LINUX equ 1
-else
- IS_LINUX equ 0
-endif
-
-ifndef x64
-; Use ABI_CDECL for x86 (32-bit) only
-; if ABI_CDECL is not defined, we use fastcall abi
-ifdef ABI_CDECL
- IS_CDECL equ 1
-else
- IS_CDECL equ 0
-endif
-endif
-
-OPTION PROLOGUE:NONE
-OPTION EPILOGUE:NONE
-
-MY_ASM_START macro
- ifdef x64
- .code
- else
- .386
- .model flat
- _TEXT$00 SEGMENT PARA PUBLIC 'CODE'
- endif
-endm
-
-MY_PROC macro name:req, numParams:req
- align 16
- proc_numParams = numParams
- if (IS_X64 gt 0)
- proc_name equ name
- elseif (IS_LINUX gt 0)
- proc_name equ name
- elseif (IS_CDECL gt 0)
- proc_name equ @CatStr(_,name)
- else
- proc_name equ @CatStr(@,name,@, %numParams * 4)
- endif
- proc_name PROC
-endm
-
-MY_ENDP macro
- if (IS_X64 gt 0)
- ret
- elseif (IS_CDECL gt 0)
- ret
- elseif (proc_numParams LT 3)
- ret
- else
- ret (proc_numParams - 2) * 4
- endif
- proc_name ENDP
-endm
-
-
-ifdef x64
- REG_SIZE equ 8
- REG_LOGAR_SIZE equ 3
-else
- REG_SIZE equ 4
- REG_LOGAR_SIZE equ 2
-endif
-
- x0 equ EAX
- x1 equ ECX
- x2 equ EDX
- x3 equ EBX
- x4 equ ESP
- x5 equ EBP
- x6 equ ESI
- x7 equ EDI
-
- x0_W equ AX
- x1_W equ CX
- x2_W equ DX
- x3_W equ BX
-
- x5_W equ BP
- x6_W equ SI
- x7_W equ DI
-
- x0_L equ AL
- x1_L equ CL
- x2_L equ DL
- x3_L equ BL
-
- x0_H equ AH
- x1_H equ CH
- x2_H equ DH
- x3_H equ BH
-
-ifdef x64
- x5_L equ BPL
- x6_L equ SIL
- x7_L equ DIL
-
- r0 equ RAX
- r1 equ RCX
- r2 equ RDX
- r3 equ RBX
- r4 equ RSP
- r5 equ RBP
- r6 equ RSI
- r7 equ RDI
- x8 equ r8d
- x9 equ r9d
- x10 equ r10d
- x11 equ r11d
- x12 equ r12d
- x13 equ r13d
- x14 equ r14d
- x15 equ r15d
-else
- r0 equ x0
- r1 equ x1
- r2 equ x2
- r3 equ x3
- r4 equ x4
- r5 equ x5
- r6 equ x6
- r7 equ x7
-endif
-
-
-ifdef x64
-ifdef ABI_LINUX
-
-MY_PUSH_2_REGS macro
- push r3
- push r5
-endm
-
-MY_POP_2_REGS macro
- pop r5
- pop r3
-endm
-
-endif
-endif
-
-
-MY_PUSH_4_REGS macro
- push r3
- push r5
- push r6
- push r7
-endm
-
-MY_POP_4_REGS macro
- pop r7
- pop r6
- pop r5
- pop r3
-endm
-
-
-; for fastcall and for WIN-x64
-REG_PARAM_0_x equ x1
-REG_PARAM_0 equ r1
-REG_PARAM_1_x equ x2
-REG_PARAM_1 equ r2
-
-ifndef x64
-; for x86-fastcall
-
-REG_ABI_PARAM_0_x equ REG_PARAM_0_x
-REG_ABI_PARAM_0 equ REG_PARAM_0
-REG_ABI_PARAM_1_x equ REG_PARAM_1_x
-REG_ABI_PARAM_1 equ REG_PARAM_1
-
-else
-; x64
-
-if (IS_LINUX eq 0)
-
-; for WIN-x64:
-REG_PARAM_2_x equ x8
-REG_PARAM_2 equ r8
-REG_PARAM_3 equ r9
-
-REG_ABI_PARAM_0_x equ REG_PARAM_0_x
-REG_ABI_PARAM_0 equ REG_PARAM_0
-REG_ABI_PARAM_1_x equ REG_PARAM_1_x
-REG_ABI_PARAM_1 equ REG_PARAM_1
-REG_ABI_PARAM_2_x equ REG_PARAM_2_x
-REG_ABI_PARAM_2 equ REG_PARAM_2
-REG_ABI_PARAM_3 equ REG_PARAM_3
-
-else
-; for LINUX-x64:
-REG_LINUX_PARAM_0_x equ x7
-REG_LINUX_PARAM_0 equ r7
-REG_LINUX_PARAM_1_x equ x6
-REG_LINUX_PARAM_1 equ r6
-REG_LINUX_PARAM_2 equ r2
-REG_LINUX_PARAM_3 equ r1
-REG_LINUX_PARAM_4_x equ x8
-REG_LINUX_PARAM_4 equ r8
-REG_LINUX_PARAM_5 equ r9
-
-REG_ABI_PARAM_0_x equ REG_LINUX_PARAM_0_x
-REG_ABI_PARAM_0 equ REG_LINUX_PARAM_0
-REG_ABI_PARAM_1_x equ REG_LINUX_PARAM_1_x
-REG_ABI_PARAM_1 equ REG_LINUX_PARAM_1
-REG_ABI_PARAM_2 equ REG_LINUX_PARAM_2
-REG_ABI_PARAM_3 equ REG_LINUX_PARAM_3
-REG_ABI_PARAM_4_x equ REG_LINUX_PARAM_4_x
-REG_ABI_PARAM_4 equ REG_LINUX_PARAM_4
-REG_ABI_PARAM_5 equ REG_LINUX_PARAM_5
-
-MY_ABI_LINUX_TO_WIN_2 macro
- mov r2, r6
- mov r1, r7
-endm
-
-MY_ABI_LINUX_TO_WIN_3 macro
- mov r8, r2
- mov r2, r6
- mov r1, r7
-endm
-
-MY_ABI_LINUX_TO_WIN_4 macro
- mov r9, r1
- mov r8, r2
- mov r2, r6
- mov r1, r7
-endm
-
-endif ; IS_LINUX
-
-
-MY_PUSH_PRESERVED_ABI_REGS macro
- if (IS_LINUX gt 0)
- MY_PUSH_2_REGS
- else
- MY_PUSH_4_REGS
- endif
- push r12
- push r13
- push r14
- push r15
-endm
-
-
-MY_POP_PRESERVED_ABI_REGS macro
- pop r15
- pop r14
- pop r13
- pop r12
- if (IS_LINUX gt 0)
- MY_POP_2_REGS
- else
- MY_POP_4_REGS
- endif
-endm
-
-endif ; x64
+; 7zAsm.asm -- ASM macros
+; 2023-12-08 : Igor Pavlov : Public domain
+
+
+; UASM can require these changes
+; OPTION FRAMEPRESERVEFLAGS:ON
+; OPTION PROLOGUE:NONE
+; OPTION EPILOGUE:NONE
+
+ifdef @wordsize
+; @wordsize is defined only in JWASM and ASMC and is not defined in MASM
+; @wordsize eq 8 for 64-bit x64
+; @wordsize eq 2 for 32-bit x86
+if @wordsize eq 8
+ x64 equ 1
+endif
+else
+ifdef RAX
+ x64 equ 1
+endif
+endif
+
+
+ifdef x64
+ IS_X64 equ 1
+else
+ IS_X64 equ 0
+endif
+
+ifdef ABI_LINUX
+ IS_LINUX equ 1
+else
+ IS_LINUX equ 0
+endif
+
+ifndef x64
+; Use ABI_CDECL for x86 (32-bit) only
+; if ABI_CDECL is not defined, we use fastcall abi
+ifdef ABI_CDECL
+ IS_CDECL equ 1
+else
+ IS_CDECL equ 0
+endif
+endif
+
+OPTION PROLOGUE:NONE
+OPTION EPILOGUE:NONE
+
+MY_ASM_START macro
+ ifdef x64
+ .code
+ else
+ .386
+ .model flat
+ _TEXT$00 SEGMENT PARA PUBLIC 'CODE'
+ endif
+endm
+
+MY_PROC macro name:req, numParams:req
+ align 16
+ proc_numParams = numParams
+ if (IS_X64 gt 0)
+ proc_name equ name
+ elseif (IS_LINUX gt 0)
+ proc_name equ name
+ elseif (IS_CDECL gt 0)
+ proc_name equ @CatStr(_,name)
+ else
+ proc_name equ @CatStr(@,name,@, %numParams * 4)
+ endif
+ proc_name PROC
+endm
+
+MY_ENDP macro
+ if (IS_X64 gt 0)
+ ret
+ elseif (IS_CDECL gt 0)
+ ret
+ elseif (proc_numParams LT 3)
+ ret
+ else
+ ret (proc_numParams - 2) * 4
+ endif
+ proc_name ENDP
+endm
+
+
+ifdef x64
+ REG_SIZE equ 8
+ REG_LOGAR_SIZE equ 3
+else
+ REG_SIZE equ 4
+ REG_LOGAR_SIZE equ 2
+endif
+
+ x0 equ EAX
+ x1 equ ECX
+ x2 equ EDX
+ x3 equ EBX
+ x4 equ ESP
+ x5 equ EBP
+ x6 equ ESI
+ x7 equ EDI
+
+ x0_W equ AX
+ x1_W equ CX
+ x2_W equ DX
+ x3_W equ BX
+
+ x5_W equ BP
+ x6_W equ SI
+ x7_W equ DI
+
+ x0_L equ AL
+ x1_L equ CL
+ x2_L equ DL
+ x3_L equ BL
+
+ x0_H equ AH
+ x1_H equ CH
+ x2_H equ DH
+ x3_H equ BH
+
+; r0_L equ AL
+; r1_L equ CL
+; r2_L equ DL
+; r3_L equ BL
+
+; r0_H equ AH
+; r1_H equ CH
+; r2_H equ DH
+; r3_H equ BH
+
+
+ifdef x64
+ x5_L equ BPL
+ x6_L equ SIL
+ x7_L equ DIL
+ x8_L equ r8b
+ x9_L equ r9b
+ x10_L equ r10b
+ x11_L equ r11b
+ x12_L equ r12b
+ x13_L equ r13b
+ x14_L equ r14b
+ x15_L equ r15b
+
+ r0 equ RAX
+ r1 equ RCX
+ r2 equ RDX
+ r3 equ RBX
+ r4 equ RSP
+ r5 equ RBP
+ r6 equ RSI
+ r7 equ RDI
+ x8 equ r8d
+ x9 equ r9d
+ x10 equ r10d
+ x11 equ r11d
+ x12 equ r12d
+ x13 equ r13d
+ x14 equ r14d
+ x15 equ r15d
+else
+ r0 equ x0
+ r1 equ x1
+ r2 equ x2
+ r3 equ x3
+ r4 equ x4
+ r5 equ x5
+ r6 equ x6
+ r7 equ x7
+endif
+
+ x0_R equ r0
+ x1_R equ r1
+ x2_R equ r2
+ x3_R equ r3
+ x4_R equ r4
+ x5_R equ r5
+ x6_R equ r6
+ x7_R equ r7
+ x8_R equ r8
+ x9_R equ r9
+ x10_R equ r10
+ x11_R equ r11
+ x12_R equ r12
+ x13_R equ r13
+ x14_R equ r14
+ x15_R equ r15
+
+ifdef x64
+ifdef ABI_LINUX
+
+MY_PUSH_2_REGS macro
+ push r3
+ push r5
+endm
+
+MY_POP_2_REGS macro
+ pop r5
+ pop r3
+endm
+
+endif
+endif
+
+
+MY_PUSH_4_REGS macro
+ push r3
+ push r5
+ push r6
+ push r7
+endm
+
+MY_POP_4_REGS macro
+ pop r7
+ pop r6
+ pop r5
+ pop r3
+endm
+
+
+; for fastcall and for WIN-x64
+REG_PARAM_0_x equ x1
+REG_PARAM_0 equ r1
+REG_PARAM_1_x equ x2
+REG_PARAM_1 equ r2
+
+ifndef x64
+; for x86-fastcall
+
+REG_ABI_PARAM_0_x equ REG_PARAM_0_x
+REG_ABI_PARAM_0 equ REG_PARAM_0
+REG_ABI_PARAM_1_x equ REG_PARAM_1_x
+REG_ABI_PARAM_1 equ REG_PARAM_1
+
+MY_PUSH_PRESERVED_ABI_REGS_UP_TO_INCLUDING_R11 macro
+ MY_PUSH_4_REGS
+endm
+
+MY_POP_PRESERVED_ABI_REGS_UP_TO_INCLUDING_R11 macro
+ MY_POP_4_REGS
+endm
+
+else
+; x64
+
+if (IS_LINUX eq 0)
+
+; for WIN-x64:
+REG_PARAM_2_x equ x8
+REG_PARAM_2 equ r8
+REG_PARAM_3 equ r9
+
+REG_ABI_PARAM_0_x equ REG_PARAM_0_x
+REG_ABI_PARAM_0 equ REG_PARAM_0
+REG_ABI_PARAM_1_x equ REG_PARAM_1_x
+REG_ABI_PARAM_1 equ REG_PARAM_1
+REG_ABI_PARAM_2_x equ REG_PARAM_2_x
+REG_ABI_PARAM_2 equ REG_PARAM_2
+REG_ABI_PARAM_3 equ REG_PARAM_3
+
+else
+; for LINUX-x64:
+REG_LINUX_PARAM_0_x equ x7
+REG_LINUX_PARAM_0 equ r7
+REG_LINUX_PARAM_1_x equ x6
+REG_LINUX_PARAM_1 equ r6
+REG_LINUX_PARAM_2 equ r2
+REG_LINUX_PARAM_3 equ r1
+REG_LINUX_PARAM_4_x equ x8
+REG_LINUX_PARAM_4 equ r8
+REG_LINUX_PARAM_5 equ r9
+
+REG_ABI_PARAM_0_x equ REG_LINUX_PARAM_0_x
+REG_ABI_PARAM_0 equ REG_LINUX_PARAM_0
+REG_ABI_PARAM_1_x equ REG_LINUX_PARAM_1_x
+REG_ABI_PARAM_1 equ REG_LINUX_PARAM_1
+REG_ABI_PARAM_2 equ REG_LINUX_PARAM_2
+REG_ABI_PARAM_3 equ REG_LINUX_PARAM_3
+REG_ABI_PARAM_4_x equ REG_LINUX_PARAM_4_x
+REG_ABI_PARAM_4 equ REG_LINUX_PARAM_4
+REG_ABI_PARAM_5 equ REG_LINUX_PARAM_5
+
+MY_ABI_LINUX_TO_WIN_2 macro
+ mov r2, r6
+ mov r1, r7
+endm
+
+MY_ABI_LINUX_TO_WIN_3 macro
+ mov r8, r2
+ mov r2, r6
+ mov r1, r7
+endm
+
+MY_ABI_LINUX_TO_WIN_4 macro
+ mov r9, r1
+ mov r8, r2
+ mov r2, r6
+ mov r1, r7
+endm
+
+endif ; IS_LINUX
+
+
+MY_PUSH_PRESERVED_ABI_REGS_UP_TO_INCLUDING_R11 macro
+ if (IS_LINUX gt 0)
+ MY_PUSH_2_REGS
+ else
+ MY_PUSH_4_REGS
+ endif
+endm
+
+MY_POP_PRESERVED_ABI_REGS_UP_TO_INCLUDING_R11 macro
+ if (IS_LINUX gt 0)
+ MY_POP_2_REGS
+ else
+ MY_POP_4_REGS
+ endif
+endm
+
+
+MY_PUSH_PRESERVED_ABI_REGS macro
+ MY_PUSH_PRESERVED_ABI_REGS_UP_TO_INCLUDING_R11
+ push r12
+ push r13
+ push r14
+ push r15
+endm
+
+
+MY_POP_PRESERVED_ABI_REGS macro
+ pop r15
+ pop r14
+ pop r13
+ pop r12
+ MY_POP_PRESERVED_ABI_REGS_UP_TO_INCLUDING_R11
+endm
+
+endif ; x64
diff --git a/deps/libchdr/deps/lzma-22.01/src/Asm/x86/LzmaDecOpt.asm b/deps/libchdr/deps/lzma-24.05/Asm/x86/LzmaDecOpt.asm
similarity index 96%
rename from deps/libchdr/deps/lzma-22.01/src/Asm/x86/LzmaDecOpt.asm
rename to deps/libchdr/deps/lzma-24.05/Asm/x86/LzmaDecOpt.asm
index 7e08acc6..f2818e77 100644
--- a/deps/libchdr/deps/lzma-22.01/src/Asm/x86/LzmaDecOpt.asm
+++ b/deps/libchdr/deps/lzma-24.05/Asm/x86/LzmaDecOpt.asm
@@ -1,1303 +1,1303 @@
-; LzmaDecOpt.asm -- ASM version of LzmaDec_DecodeReal_3() function
-; 2021-02-23: Igor Pavlov : Public domain
-;
-; 3 - is the code compatibility version of LzmaDec_DecodeReal_*()
-; function for check at link time.
-; That code is tightly coupled with LzmaDec_TryDummy()
-; and with another functions in LzmaDec.c file.
-; CLzmaDec structure, (probs) array layout, input and output of
-; LzmaDec_DecodeReal_*() must be equal in both versions (C / ASM).
-
-ifndef x64
-; x64=1
-; .err
-endif
-
-include 7zAsm.asm
-
-MY_ASM_START
-
-_TEXT$LZMADECOPT SEGMENT ALIGN(64) 'CODE'
-
-MY_ALIGN macro num:req
- align num
-endm
-
-MY_ALIGN_16 macro
- MY_ALIGN 16
-endm
-
-MY_ALIGN_32 macro
- MY_ALIGN 32
-endm
-
-MY_ALIGN_64 macro
- MY_ALIGN 64
-endm
-
-
-; _LZMA_SIZE_OPT equ 1
-
-; _LZMA_PROB32 equ 1
-
-ifdef _LZMA_PROB32
- PSHIFT equ 2
- PLOAD macro dest, mem
- mov dest, dword ptr [mem]
- endm
- PSTORE macro src, mem
- mov dword ptr [mem], src
- endm
-else
- PSHIFT equ 1
- PLOAD macro dest, mem
- movzx dest, word ptr [mem]
- endm
- PSTORE macro src, mem
- mov word ptr [mem], @CatStr(src, _W)
- endm
-endif
-
-PMULT equ (1 SHL PSHIFT)
-PMULT_HALF equ (1 SHL (PSHIFT - 1))
-PMULT_2 equ (1 SHL (PSHIFT + 1))
-
-kMatchSpecLen_Error_Data equ (1 SHL 9)
-
-; x0 range
-; x1 pbPos / (prob) TREE
-; x2 probBranch / prm (MATCHED) / pbPos / cnt
-; x3 sym
-;====== r4 === RSP
-; x5 cod
-; x6 t1 NORM_CALC / probs_state / dist
-; x7 t0 NORM_CALC / prob2 IF_BIT_1
-; x8 state
-; x9 match (MATCHED) / sym2 / dist2 / lpMask_reg
-; x10 kBitModelTotal_reg
-; r11 probs
-; x12 offs (MATCHED) / dic / len_temp
-; x13 processedPos
-; x14 bit (MATCHED) / dicPos
-; r15 buf
-
-
-cod equ x5
-cod_L equ x5_L
-range equ x0
-state equ x8
-state_R equ r8
-buf equ r15
-processedPos equ x13
-kBitModelTotal_reg equ x10
-
-probBranch equ x2
-probBranch_R equ r2
-probBranch_W equ x2_W
-
-pbPos equ x1
-pbPos_R equ r1
-
-cnt equ x2
-cnt_R equ r2
-
-lpMask_reg equ x9
-dicPos equ r14
-
-sym equ x3
-sym_R equ r3
-sym_L equ x3_L
-
-probs equ r11
-dic equ r12
-
-t0 equ x7
-t0_W equ x7_W
-t0_R equ r7
-
-prob2 equ t0
-prob2_W equ t0_W
-
-t1 equ x6
-t1_R equ r6
-
-probs_state equ t1
-probs_state_R equ t1_R
-
-prm equ r2
-match equ x9
-match_R equ r9
-offs equ x12
-offs_R equ r12
-bit equ x14
-bit_R equ r14
-
-sym2 equ x9
-sym2_R equ r9
-
-len_temp equ x12
-
-dist equ sym
-dist2 equ x9
-
-
-
-kNumBitModelTotalBits equ 11
-kBitModelTotal equ (1 SHL kNumBitModelTotalBits)
-kNumMoveBits equ 5
-kBitModelOffset equ ((1 SHL kNumMoveBits) - 1)
-kTopValue equ (1 SHL 24)
-
-NORM_2 macro
- ; movzx t0, BYTE PTR [buf]
- shl cod, 8
- mov cod_L, BYTE PTR [buf]
- shl range, 8
- ; or cod, t0
- inc buf
-endm
-
-
-NORM macro
- cmp range, kTopValue
- jae SHORT @F
- NORM_2
-@@:
-endm
-
-
-; ---------- Branch MACROS ----------
-
-UPDATE_0 macro probsArray:req, probOffset:req, probDisp:req
- mov prob2, kBitModelTotal_reg
- sub prob2, probBranch
- shr prob2, kNumMoveBits
- add probBranch, prob2
- PSTORE probBranch, probOffset * 1 + probsArray + probDisp * PMULT
-endm
-
-
-UPDATE_1 macro probsArray:req, probOffset:req, probDisp:req
- sub prob2, range
- sub cod, range
- mov range, prob2
- mov prob2, probBranch
- shr probBranch, kNumMoveBits
- sub prob2, probBranch
- PSTORE prob2, probOffset * 1 + probsArray + probDisp * PMULT
-endm
-
-
-CMP_COD macro probsArray:req, probOffset:req, probDisp:req
- PLOAD probBranch, probOffset * 1 + probsArray + probDisp * PMULT
- NORM
- mov prob2, range
- shr range, kNumBitModelTotalBits
- imul range, probBranch
- cmp cod, range
-endm
-
-
-IF_BIT_1_NOUP macro probsArray:req, probOffset:req, probDisp:req, toLabel:req
- CMP_COD probsArray, probOffset, probDisp
- jae toLabel
-endm
-
-
-IF_BIT_1 macro probsArray:req, probOffset:req, probDisp:req, toLabel:req
- IF_BIT_1_NOUP probsArray, probOffset, probDisp, toLabel
- UPDATE_0 probsArray, probOffset, probDisp
-endm
-
-
-IF_BIT_0_NOUP macro probsArray:req, probOffset:req, probDisp:req, toLabel:req
- CMP_COD probsArray, probOffset, probDisp
- jb toLabel
-endm
-
-
-; ---------- CMOV MACROS ----------
-
-NORM_CALC macro prob:req
- NORM
- mov t0, range
- shr range, kNumBitModelTotalBits
- imul range, prob
- sub t0, range
- mov t1, cod
- sub cod, range
-endm
-
-
-PUP macro prob:req, probPtr:req
- sub t0, prob
- ; only sar works for both 16/32 bit prob modes
- sar t0, kNumMoveBits
- add t0, prob
- PSTORE t0, probPtr
-endm
-
-
-PUP_SUB macro prob:req, probPtr:req, symSub:req
- sbb sym, symSub
- PUP prob, probPtr
-endm
-
-
-PUP_COD macro prob:req, probPtr:req, symSub:req
- mov t0, kBitModelOffset
- cmovb cod, t1
- mov t1, sym
- cmovb t0, kBitModelTotal_reg
- PUP_SUB prob, probPtr, symSub
-endm
-
-
-BIT_0 macro prob:req, probNext:req
- PLOAD prob, probs + 1 * PMULT
- PLOAD probNext, probs + 1 * PMULT_2
-
- NORM_CALC prob
-
- cmovae range, t0
- PLOAD t0, probs + 1 * PMULT_2 + PMULT
- cmovae probNext, t0
- mov t0, kBitModelOffset
- cmovb cod, t1
- cmovb t0, kBitModelTotal_reg
- mov sym, 2
- PUP_SUB prob, probs + 1 * PMULT, 0 - 1
-endm
-
-
-BIT_1 macro prob:req, probNext:req
- PLOAD probNext, probs + sym_R * PMULT_2
- add sym, sym
-
- NORM_CALC prob
-
- cmovae range, t0
- PLOAD t0, probs + sym_R * PMULT + PMULT
- cmovae probNext, t0
- PUP_COD prob, probs + t1_R * PMULT_HALF, 0 - 1
-endm
-
-
-BIT_2 macro prob:req, symSub:req
- add sym, sym
-
- NORM_CALC prob
-
- cmovae range, t0
- PUP_COD prob, probs + t1_R * PMULT_HALF, symSub
-endm
-
-
-; ---------- MATCHED LITERAL ----------
-
-LITM_0 macro
- mov offs, 256 * PMULT
- shl match, (PSHIFT + 1)
- mov bit, offs
- and bit, match
- PLOAD x1, probs + 256 * PMULT + bit_R * 1 + 1 * PMULT
- lea prm, [probs + 256 * PMULT + bit_R * 1 + 1 * PMULT]
- ; lea prm, [probs + 256 * PMULT + 1 * PMULT]
- ; add prm, bit_R
- xor offs, bit
- add match, match
-
- NORM_CALC x1
-
- cmovae offs, bit
- mov bit, match
- cmovae range, t0
- mov t0, kBitModelOffset
- cmovb cod, t1
- cmovb t0, kBitModelTotal_reg
- mov sym, 0
- PUP_SUB x1, prm, -2-1
-endm
-
-
-LITM macro
- and bit, offs
- lea prm, [probs + offs_R * 1]
- add prm, bit_R
- PLOAD x1, prm + sym_R * PMULT
- xor offs, bit
- add sym, sym
- add match, match
-
- NORM_CALC x1
-
- cmovae offs, bit
- mov bit, match
- cmovae range, t0
- PUP_COD x1, prm + t1_R * PMULT_HALF, - 1
-endm
-
-
-LITM_2 macro
- and bit, offs
- lea prm, [probs + offs_R * 1]
- add prm, bit_R
- PLOAD x1, prm + sym_R * PMULT
- add sym, sym
-
- NORM_CALC x1
-
- cmovae range, t0
- PUP_COD x1, prm + t1_R * PMULT_HALF, 256 - 1
-endm
-
-
-; ---------- REVERSE BITS ----------
-
-REV_0 macro prob:req, probNext:req
- ; PLOAD prob, probs + 1 * PMULT
- ; lea sym2_R, [probs + 2 * PMULT]
- ; PLOAD probNext, probs + 2 * PMULT
- PLOAD probNext, sym2_R
-
- NORM_CALC prob
-
- cmovae range, t0
- PLOAD t0, probs + 3 * PMULT
- cmovae probNext, t0
- cmovb cod, t1
- mov t0, kBitModelOffset
- cmovb t0, kBitModelTotal_reg
- lea t1_R, [probs + 3 * PMULT]
- cmovae sym2_R, t1_R
- PUP prob, probs + 1 * PMULT
-endm
-
-
-REV_1 macro prob:req, probNext:req, step:req
- add sym2_R, step * PMULT
- PLOAD probNext, sym2_R
-
- NORM_CALC prob
-
- cmovae range, t0
- PLOAD t0, sym2_R + step * PMULT
- cmovae probNext, t0
- cmovb cod, t1
- mov t0, kBitModelOffset
- cmovb t0, kBitModelTotal_reg
- lea t1_R, [sym2_R + step * PMULT]
- cmovae sym2_R, t1_R
- PUP prob, t1_R - step * PMULT_2
-endm
-
-
-REV_2 macro prob:req, step:req
- sub sym2_R, probs
- shr sym2, PSHIFT
- or sym, sym2
-
- NORM_CALC prob
-
- cmovae range, t0
- lea t0, [sym - step]
- cmovb sym, t0
- cmovb cod, t1
- mov t0, kBitModelOffset
- cmovb t0, kBitModelTotal_reg
- PUP prob, probs + sym2_R * PMULT
-endm
-
-
-REV_1_VAR macro prob:req
- PLOAD prob, sym_R
- mov probs, sym_R
- add sym_R, sym2_R
-
- NORM_CALC prob
-
- cmovae range, t0
- lea t0_R, [sym_R + 1 * sym2_R]
- cmovae sym_R, t0_R
- mov t0, kBitModelOffset
- cmovb cod, t1
- ; mov t1, kBitModelTotal
- ; cmovb t0, t1
- cmovb t0, kBitModelTotal_reg
- add sym2, sym2
- PUP prob, probs
-endm
-
-
-
-
-LIT_PROBS macro lpMaskParam:req
- ; prob += (UInt32)3 * ((((processedPos << 8) + dic[(dicPos == 0 ? dicBufSize : dicPos) - 1]) & lpMask) << lc);
- mov t0, processedPos
- shl t0, 8
- add sym, t0
- and sym, lpMaskParam
- add probs_state_R, pbPos_R
- mov x1, LOC lc2
- lea sym, dword ptr[sym_R + 2 * sym_R]
- add probs, Literal * PMULT
- shl sym, x1_L
- add probs, sym_R
- UPDATE_0 probs_state_R, 0, IsMatch
- inc processedPos
-endm
-
-
-
-kNumPosBitsMax equ 4
-kNumPosStatesMax equ (1 SHL kNumPosBitsMax)
-
-kLenNumLowBits equ 3
-kLenNumLowSymbols equ (1 SHL kLenNumLowBits)
-kLenNumHighBits equ 8
-kLenNumHighSymbols equ (1 SHL kLenNumHighBits)
-kNumLenProbs equ (2 * kLenNumLowSymbols * kNumPosStatesMax + kLenNumHighSymbols)
-
-LenLow equ 0
-LenChoice equ LenLow
-LenChoice2 equ (LenLow + kLenNumLowSymbols)
-LenHigh equ (LenLow + 2 * kLenNumLowSymbols * kNumPosStatesMax)
-
-kNumStates equ 12
-kNumStates2 equ 16
-kNumLitStates equ 7
-
-kStartPosModelIndex equ 4
-kEndPosModelIndex equ 14
-kNumFullDistances equ (1 SHL (kEndPosModelIndex SHR 1))
-
-kNumPosSlotBits equ 6
-kNumLenToPosStates equ 4
-
-kNumAlignBits equ 4
-kAlignTableSize equ (1 SHL kNumAlignBits)
-
-kMatchMinLen equ 2
-kMatchSpecLenStart equ (kMatchMinLen + kLenNumLowSymbols * 2 + kLenNumHighSymbols)
-
-kStartOffset equ 1664
-SpecPos equ (-kStartOffset)
-IsRep0Long equ (SpecPos + kNumFullDistances)
-RepLenCoder equ (IsRep0Long + (kNumStates2 SHL kNumPosBitsMax))
-LenCoder equ (RepLenCoder + kNumLenProbs)
-IsMatch equ (LenCoder + kNumLenProbs)
-kAlign equ (IsMatch + (kNumStates2 SHL kNumPosBitsMax))
-IsRep equ (kAlign + kAlignTableSize)
-IsRepG0 equ (IsRep + kNumStates)
-IsRepG1 equ (IsRepG0 + kNumStates)
-IsRepG2 equ (IsRepG1 + kNumStates)
-PosSlot equ (IsRepG2 + kNumStates)
-Literal equ (PosSlot + (kNumLenToPosStates SHL kNumPosSlotBits))
-NUM_BASE_PROBS equ (Literal + kStartOffset)
-
-if kAlign ne 0
- .err
-endif
-
-if NUM_BASE_PROBS ne 1984
- .err
-endif
-
-
-PTR_FIELD equ dq ?
-
-CLzmaDec_Asm struct
- lc db ?
- lp db ?
- pb db ?
- _pad_ db ?
- dicSize dd ?
-
- probs_Spec PTR_FIELD
- probs_1664 PTR_FIELD
- dic_Spec PTR_FIELD
- dicBufSize PTR_FIELD
- dicPos_Spec PTR_FIELD
- buf_Spec PTR_FIELD
-
- range_Spec dd ?
- code_Spec dd ?
- processedPos_Spec dd ?
- checkDicSize dd ?
- rep0 dd ?
- rep1 dd ?
- rep2 dd ?
- rep3 dd ?
- state_Spec dd ?
- remainLen dd ?
-CLzmaDec_Asm ends
-
-
-CLzmaDec_Asm_Loc struct
- OLD_RSP PTR_FIELD
- lzmaPtr PTR_FIELD
- _pad0_ PTR_FIELD
- _pad1_ PTR_FIELD
- _pad2_ PTR_FIELD
- dicBufSize PTR_FIELD
- probs_Spec PTR_FIELD
- dic_Spec PTR_FIELD
-
- limit PTR_FIELD
- bufLimit PTR_FIELD
- lc2 dd ?
- lpMask dd ?
- pbMask dd ?
- checkDicSize dd ?
-
- _pad_ dd ?
- remainLen dd ?
- dicPos_Spec PTR_FIELD
- rep0 dd ?
- rep1 dd ?
- rep2 dd ?
- rep3 dd ?
-CLzmaDec_Asm_Loc ends
-
-
-GLOB_2 equ [sym_R].CLzmaDec_Asm.
-GLOB equ [r1].CLzmaDec_Asm.
-LOC_0 equ [r0].CLzmaDec_Asm_Loc.
-LOC equ [RSP].CLzmaDec_Asm_Loc.
-
-
-COPY_VAR macro name
- mov t0, GLOB_2 name
- mov LOC_0 name, t0
-endm
-
-
-RESTORE_VAR macro name
- mov t0, LOC name
- mov GLOB name, t0
-endm
-
-
-
-IsMatchBranch_Pre macro reg
- ; prob = probs + IsMatch + (state << kNumPosBitsMax) + posState;
- mov pbPos, LOC pbMask
- and pbPos, processedPos
- shl pbPos, (kLenNumLowBits + 1 + PSHIFT)
- lea probs_state_R, [probs + 1 * state_R]
-endm
-
-
-IsMatchBranch macro reg
- IsMatchBranch_Pre
- IF_BIT_1 probs_state_R, pbPos_R, IsMatch, IsMatch_label
-endm
-
-
-CheckLimits macro reg
- cmp buf, LOC bufLimit
- jae fin_OK
- cmp dicPos, LOC limit
- jae fin_OK
-endm
-
-
-
-; RSP is (16x + 8) bytes aligned in WIN64-x64
-; LocalSize equ ((((SIZEOF CLzmaDec_Asm_Loc) + 7) / 16 * 16) + 8)
-
-PARAM_lzma equ REG_ABI_PARAM_0
-PARAM_limit equ REG_ABI_PARAM_1
-PARAM_bufLimit equ REG_ABI_PARAM_2
-
-; MY_ALIGN_64
-MY_PROC LzmaDec_DecodeReal_3, 3
-MY_PUSH_PRESERVED_ABI_REGS
-
- lea r0, [RSP - (SIZEOF CLzmaDec_Asm_Loc)]
- and r0, -128
- mov r5, RSP
- mov RSP, r0
- mov LOC_0 Old_RSP, r5
- mov LOC_0 lzmaPtr, PARAM_lzma
-
- mov LOC_0 remainLen, 0 ; remainLen must be ZERO
-
- mov LOC_0 bufLimit, PARAM_bufLimit
- mov sym_R, PARAM_lzma ; CLzmaDec_Asm_Loc pointer for GLOB_2
- mov dic, GLOB_2 dic_Spec
- add PARAM_limit, dic
- mov LOC_0 limit, PARAM_limit
-
- COPY_VAR(rep0)
- COPY_VAR(rep1)
- COPY_VAR(rep2)
- COPY_VAR(rep3)
-
- mov dicPos, GLOB_2 dicPos_Spec
- add dicPos, dic
- mov LOC_0 dicPos_Spec, dicPos
- mov LOC_0 dic_Spec, dic
-
- mov x1_L, GLOB_2 pb
- mov t0, 1
- shl t0, x1_L
- dec t0
- mov LOC_0 pbMask, t0
-
- ; unsigned pbMask = ((unsigned)1 << (p->prop.pb)) - 1;
- ; unsigned lc = p->prop.lc;
- ; unsigned lpMask = ((unsigned)0x100 << p->prop.lp) - ((unsigned)0x100 >> lc);
-
- mov x1_L, GLOB_2 lc
- mov x2, 100h
- mov t0, x2
- shr x2, x1_L
- ; inc x1
- add x1_L, PSHIFT
- mov LOC_0 lc2, x1
- mov x1_L, GLOB_2 lp
- shl t0, x1_L
- sub t0, x2
- mov LOC_0 lpMask, t0
- mov lpMask_reg, t0
-
- ; mov probs, GLOB_2 probs_Spec
- ; add probs, kStartOffset SHL PSHIFT
- mov probs, GLOB_2 probs_1664
- mov LOC_0 probs_Spec, probs
-
- mov t0_R, GLOB_2 dicBufSize
- mov LOC_0 dicBufSize, t0_R
-
- mov x1, GLOB_2 checkDicSize
- mov LOC_0 checkDicSize, x1
-
- mov processedPos, GLOB_2 processedPos_Spec
-
- mov state, GLOB_2 state_Spec
- shl state, PSHIFT
-
- mov buf, GLOB_2 buf_Spec
- mov range, GLOB_2 range_Spec
- mov cod, GLOB_2 code_Spec
- mov kBitModelTotal_reg, kBitModelTotal
- xor sym, sym
-
- ; if (processedPos != 0 || checkDicSize != 0)
- or x1, processedPos
- jz @f
-
- add t0_R, dic
- cmp dicPos, dic
- cmovnz t0_R, dicPos
- movzx sym, byte ptr[t0_R - 1]
-
-@@:
- IsMatchBranch_Pre
- cmp state, 4 * PMULT
- jb lit_end
- cmp state, kNumLitStates * PMULT
- jb lit_matched_end
- jmp lz_end
-
-
-
-
-; ---------- LITERAL ----------
-MY_ALIGN_64
-lit_start:
- xor state, state
-lit_start_2:
- LIT_PROBS lpMask_reg
-
- ifdef _LZMA_SIZE_OPT
-
- PLOAD x1, probs + 1 * PMULT
- mov sym, 1
-MY_ALIGN_16
-lit_loop:
- BIT_1 x1, x2
- mov x1, x2
- cmp sym, 127
- jbe lit_loop
-
- else
-
- BIT_0 x1, x2
- BIT_1 x2, x1
- BIT_1 x1, x2
- BIT_1 x2, x1
- BIT_1 x1, x2
- BIT_1 x2, x1
- BIT_1 x1, x2
-
- endif
-
- BIT_2 x2, 256 - 1
-
- ; mov dic, LOC dic_Spec
- mov probs, LOC probs_Spec
- IsMatchBranch_Pre
- mov byte ptr[dicPos], sym_L
- inc dicPos
-
- CheckLimits
-lit_end:
- IF_BIT_0_NOUP probs_state_R, pbPos_R, IsMatch, lit_start
-
- ; jmp IsMatch_label
-
-; ---------- MATCHES ----------
-; MY_ALIGN_32
-IsMatch_label:
- UPDATE_1 probs_state_R, pbPos_R, IsMatch
- IF_BIT_1 probs_state_R, 0, IsRep, IsRep_label
-
- add probs, LenCoder * PMULT
- add state, kNumStates * PMULT
-
-; ---------- LEN DECODE ----------
-len_decode:
- mov len_temp, 8 - 1 - kMatchMinLen
- IF_BIT_0_NOUP probs, 0, 0, len_mid_0
- UPDATE_1 probs, 0, 0
- add probs, (1 SHL (kLenNumLowBits + PSHIFT))
- mov len_temp, -1 - kMatchMinLen
- IF_BIT_0_NOUP probs, 0, 0, len_mid_0
- UPDATE_1 probs, 0, 0
- add probs, LenHigh * PMULT - (1 SHL (kLenNumLowBits + PSHIFT))
- mov sym, 1
- PLOAD x1, probs + 1 * PMULT
-
-MY_ALIGN_32
-len8_loop:
- BIT_1 x1, x2
- mov x1, x2
- cmp sym, 64
- jb len8_loop
-
- mov len_temp, (kLenNumHighSymbols - kLenNumLowSymbols * 2) - 1 - kMatchMinLen
- jmp short len_mid_2 ; we use short here for MASM that doesn't optimize that code as another assembler programs
-
-MY_ALIGN_32
-len_mid_0:
- UPDATE_0 probs, 0, 0
- add probs, pbPos_R
- BIT_0 x2, x1
-len_mid_2:
- BIT_1 x1, x2
- BIT_2 x2, len_temp
- mov probs, LOC probs_Spec
- cmp state, kNumStates * PMULT
- jb copy_match
-
-
-; ---------- DECODE DISTANCE ----------
- ; probs + PosSlot + ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << kNumPosSlotBits);
-
- mov t0, 3 + kMatchMinLen
- cmp sym, 3 + kMatchMinLen
- cmovb t0, sym
- add probs, PosSlot * PMULT - (kMatchMinLen SHL (kNumPosSlotBits + PSHIFT))
- shl t0, (kNumPosSlotBits + PSHIFT)
- add probs, t0_R
-
- ; sym = Len
- ; mov LOC remainLen, sym
- mov len_temp, sym
-
- ifdef _LZMA_SIZE_OPT
-
- PLOAD x1, probs + 1 * PMULT
- mov sym, 1
-MY_ALIGN_16
-slot_loop:
- BIT_1 x1, x2
- mov x1, x2
- cmp sym, 32
- jb slot_loop
-
- else
-
- BIT_0 x1, x2
- BIT_1 x2, x1
- BIT_1 x1, x2
- BIT_1 x2, x1
- BIT_1 x1, x2
-
- endif
-
- mov x1, sym
- BIT_2 x2, 64-1
-
- and sym, 3
- mov probs, LOC probs_Spec
- cmp x1, 32 + kEndPosModelIndex / 2
- jb short_dist
-
- ; unsigned numDirectBits = (unsigned)(((distance >> 1) - 1));
- sub x1, (32 + 1 + kNumAlignBits)
- ; distance = (2 | (distance & 1));
- or sym, 2
- PLOAD x2, probs + 1 * PMULT
- shl sym, kNumAlignBits + 1
- lea sym2_R, [probs + 2 * PMULT]
-
- jmp direct_norm
- ; lea t1, [sym_R + (1 SHL kNumAlignBits)]
- ; cmp range, kTopValue
- ; jb direct_norm
-
-; ---------- DIRECT DISTANCE ----------
-MY_ALIGN_32
-direct_loop:
- shr range, 1
- mov t0, cod
- sub cod, range
- cmovs cod, t0
- cmovns sym, t1
-
- comment ~
- sub cod, range
- mov x2, cod
- sar x2, 31
- lea sym, dword ptr [r2 + sym_R * 2 + 1]
- and x2, range
- add cod, x2
- ~
- dec x1
- je direct_end
-
- add sym, sym
-direct_norm:
- lea t1, [sym_R + (1 SHL kNumAlignBits)]
- cmp range, kTopValue
- jae near ptr direct_loop
- ; we align for 32 here with "near ptr" command above
- NORM_2
- jmp direct_loop
-
-MY_ALIGN_32
-direct_end:
- ; prob = + kAlign;
- ; distance <<= kNumAlignBits;
- REV_0 x2, x1
- REV_1 x1, x2, 2
- REV_1 x2, x1, 4
- REV_2 x1, 8
-
-decode_dist_end:
-
- ; if (distance >= (checkDicSize == 0 ? processedPos: checkDicSize))
-
- mov t1, LOC rep0
- mov x1, LOC rep1
- mov x2, LOC rep2
-
- mov t0, LOC checkDicSize
- test t0, t0
- cmove t0, processedPos
- cmp sym, t0
- jae end_of_payload
- ; jmp end_of_payload ; for debug
-
- ; rep3 = rep2;
- ; rep2 = rep1;
- ; rep1 = rep0;
- ; rep0 = distance + 1;
-
- inc sym
- mov LOC rep0, sym
- ; mov sym, LOC remainLen
- mov sym, len_temp
- mov LOC rep1, t1
- mov LOC rep2, x1
- mov LOC rep3, x2
-
- ; state = (state < kNumStates + kNumLitStates) ? kNumLitStates : kNumLitStates + 3;
- cmp state, (kNumStates + kNumLitStates) * PMULT
- mov state, kNumLitStates * PMULT
- mov t0, (kNumLitStates + 3) * PMULT
- cmovae state, t0
-
-
-; ---------- COPY MATCH ----------
-copy_match:
-
- ; len += kMatchMinLen;
- ; add sym, kMatchMinLen
-
- ; if ((rem = limit - dicPos) == 0)
- ; {
- ; p->dicPos = dicPos;
- ; return SZ_ERROR_DATA;
- ; }
- mov cnt_R, LOC limit
- sub cnt_R, dicPos
- jz fin_dicPos_LIMIT
-
- ; curLen = ((rem < len) ? (unsigned)rem : len);
- cmp cnt_R, sym_R
- ; cmovae cnt_R, sym_R ; 64-bit
- cmovae cnt, sym ; 32-bit
-
- mov dic, LOC dic_Spec
- mov x1, LOC rep0
-
- mov t0_R, dicPos
- add dicPos, cnt_R
- ; processedPos += curLen;
- add processedPos, cnt
- ; len -= curLen;
- sub sym, cnt
- mov LOC remainLen, sym
-
- sub t0_R, dic
-
- ; pos = dicPos - rep0 + (dicPos < rep0 ? dicBufSize : 0);
- sub t0_R, r1
- jae @f
-
- mov r1, LOC dicBufSize
- add t0_R, r1
- sub r1, t0_R
- cmp cnt_R, r1
- ja copy_match_cross
-@@:
- ; if (curLen <= dicBufSize - pos)
-
-; ---------- COPY MATCH FAST ----------
- ; Byte *dest = dic + dicPos;
- ; mov r1, dic
- ; ptrdiff_t src = (ptrdiff_t)pos - (ptrdiff_t)dicPos;
- ; sub t0_R, dicPos
- ; dicPos += curLen;
-
- ; const Byte *lim = dest + curLen;
- add t0_R, dic
- movzx sym, byte ptr[t0_R]
- add t0_R, cnt_R
- neg cnt_R
- ; lea r1, [dicPos - 1]
-copy_common:
- dec dicPos
- ; cmp LOC rep0, 1
- ; je rep0Label
-
- ; t0_R - src_lim
- ; r1 - dest_lim - 1
- ; cnt_R - (-cnt)
-
- IsMatchBranch_Pre
- inc cnt_R
- jz copy_end
-MY_ALIGN_16
-@@:
- mov byte ptr[cnt_R * 1 + dicPos], sym_L
- movzx sym, byte ptr[cnt_R * 1 + t0_R]
- inc cnt_R
- jnz @b
-
-copy_end:
-lz_end_match:
- mov byte ptr[dicPos], sym_L
- inc dicPos
-
- ; IsMatchBranch_Pre
- CheckLimits
-lz_end:
- IF_BIT_1_NOUP probs_state_R, pbPos_R, IsMatch, IsMatch_label
-
-
-
-; ---------- LITERAL MATCHED ----------
-
- LIT_PROBS LOC lpMask
-
- ; matchByte = dic[dicPos - rep0 + (dicPos < rep0 ? dicBufSize : 0)];
- mov x1, LOC rep0
- ; mov dic, LOC dic_Spec
- mov LOC dicPos_Spec, dicPos
-
- ; state -= (state < 10) ? 3 : 6;
- lea t0, [state_R - 6 * PMULT]
- sub state, 3 * PMULT
- cmp state, 7 * PMULT
- cmovae state, t0
-
- sub dicPos, dic
- sub dicPos, r1
- jae @f
- add dicPos, LOC dicBufSize
-@@:
- comment ~
- xor t0, t0
- sub dicPos, r1
- cmovb t0_R, LOC dicBufSize
- ~
-
- movzx match, byte ptr[dic + dicPos * 1]
-
- ifdef _LZMA_SIZE_OPT
-
- mov offs, 256 * PMULT
- shl match, (PSHIFT + 1)
- mov bit, match
- mov sym, 1
-MY_ALIGN_16
-litm_loop:
- LITM
- cmp sym, 256
- jb litm_loop
- sub sym, 256
-
- else
-
- LITM_0
- LITM
- LITM
- LITM
- LITM
- LITM
- LITM
- LITM_2
-
- endif
-
- mov probs, LOC probs_Spec
- IsMatchBranch_Pre
- ; mov dic, LOC dic_Spec
- mov dicPos, LOC dicPos_Spec
- mov byte ptr[dicPos], sym_L
- inc dicPos
-
- CheckLimits
-lit_matched_end:
- IF_BIT_1_NOUP probs_state_R, pbPos_R, IsMatch, IsMatch_label
- ; IsMatchBranch
- mov lpMask_reg, LOC lpMask
- sub state, 3 * PMULT
- jmp lit_start_2
-
-
-
-; ---------- REP 0 LITERAL ----------
-MY_ALIGN_32
-IsRep0Short_label:
- UPDATE_0 probs_state_R, pbPos_R, IsRep0Long
-
- ; dic[dicPos] = dic[dicPos - rep0 + (dicPos < rep0 ? dicBufSize : 0)];
- mov dic, LOC dic_Spec
- mov t0_R, dicPos
- mov probBranch, LOC rep0
- sub t0_R, dic
-
- sub probs, RepLenCoder * PMULT
-
- ; state = state < kNumLitStates ? 9 : 11;
- or state, 1 * PMULT
-
- ; the caller doesn't allow (dicPos >= limit) case for REP_SHORT
- ; so we don't need the following (dicPos == limit) check here:
- ; cmp dicPos, LOC limit
- ; jae fin_dicPos_LIMIT_REP_SHORT
-
- inc processedPos
-
- IsMatchBranch_Pre
-
-; xor sym, sym
-; sub t0_R, probBranch_R
-; cmovb sym_R, LOC dicBufSize
-; add t0_R, sym_R
- sub t0_R, probBranch_R
- jae @f
- add t0_R, LOC dicBufSize
-@@:
- movzx sym, byte ptr[dic + t0_R * 1]
- jmp lz_end_match
-
-
-MY_ALIGN_32
-IsRep_label:
- UPDATE_1 probs_state_R, 0, IsRep
-
- ; The (checkDicSize == 0 && processedPos == 0) case was checked before in LzmaDec.c with kBadRepCode.
- ; So we don't check it here.
-
- ; mov t0, processedPos
- ; or t0, LOC checkDicSize
- ; jz fin_ERROR_2
-
- ; state = state < kNumLitStates ? 8 : 11;
- cmp state, kNumLitStates * PMULT
- mov state, 8 * PMULT
- mov probBranch, 11 * PMULT
- cmovae state, probBranch
-
- ; prob = probs + RepLenCoder;
- add probs, RepLenCoder * PMULT
-
- IF_BIT_1 probs_state_R, 0, IsRepG0, IsRepG0_label
- IF_BIT_0_NOUP probs_state_R, pbPos_R, IsRep0Long, IsRep0Short_label
- UPDATE_1 probs_state_R, pbPos_R, IsRep0Long
- jmp len_decode
-
-MY_ALIGN_32
-IsRepG0_label:
- UPDATE_1 probs_state_R, 0, IsRepG0
- mov dist2, LOC rep0
- mov dist, LOC rep1
- mov LOC rep1, dist2
-
- IF_BIT_1 probs_state_R, 0, IsRepG1, IsRepG1_label
- mov LOC rep0, dist
- jmp len_decode
-
-; MY_ALIGN_32
-IsRepG1_label:
- UPDATE_1 probs_state_R, 0, IsRepG1
- mov dist2, LOC rep2
- mov LOC rep2, dist
-
- IF_BIT_1 probs_state_R, 0, IsRepG2, IsRepG2_label
- mov LOC rep0, dist2
- jmp len_decode
-
-; MY_ALIGN_32
-IsRepG2_label:
- UPDATE_1 probs_state_R, 0, IsRepG2
- mov dist, LOC rep3
- mov LOC rep3, dist2
- mov LOC rep0, dist
- jmp len_decode
-
-
-
-; ---------- SPEC SHORT DISTANCE ----------
-
-MY_ALIGN_32
-short_dist:
- sub x1, 32 + 1
- jbe decode_dist_end
- or sym, 2
- shl sym, x1_L
- lea sym_R, [probs + sym_R * PMULT + SpecPos * PMULT + 1 * PMULT]
- mov sym2, PMULT ; step
-MY_ALIGN_32
-spec_loop:
- REV_1_VAR x2
- dec x1
- jnz spec_loop
-
- mov probs, LOC probs_Spec
- sub sym, sym2
- sub sym, SpecPos * PMULT
- sub sym_R, probs
- shr sym, PSHIFT
-
- jmp decode_dist_end
-
-
-; ---------- COPY MATCH CROSS ----------
-copy_match_cross:
- ; t0_R - src pos
- ; r1 - len to dicBufSize
- ; cnt_R - total copy len
-
- mov t1_R, t0_R ; srcPos
- mov t0_R, dic
- mov r1, LOC dicBufSize ;
- neg cnt_R
-@@:
- movzx sym, byte ptr[t1_R * 1 + t0_R]
- inc t1_R
- mov byte ptr[cnt_R * 1 + dicPos], sym_L
- inc cnt_R
- cmp t1_R, r1
- jne @b
-
- movzx sym, byte ptr[t0_R]
- sub t0_R, cnt_R
- jmp copy_common
-
-
-
-
-; fin_dicPos_LIMIT_REP_SHORT:
- ; mov sym, 1
-
-fin_dicPos_LIMIT:
- mov LOC remainLen, sym
- jmp fin_OK
- ; For more strict mode we can stop decoding with error
- ; mov sym, 1
- ; jmp fin
-
-
-fin_ERROR_MATCH_DIST:
-
- ; rep3 = rep2;
- ; rep2 = rep1;
- ; rep1 = rep0;
- ; rep0 = distance + 1;
-
- add len_temp, kMatchSpecLen_Error_Data
- mov LOC remainLen, len_temp
-
- mov LOC rep0, sym
- mov LOC rep1, t1
- mov LOC rep2, x1
- mov LOC rep3, x2
-
- ; state = (state < kNumStates + kNumLitStates) ? kNumLitStates : kNumLitStates + 3;
- cmp state, (kNumStates + kNumLitStates) * PMULT
- mov state, kNumLitStates * PMULT
- mov t0, (kNumLitStates + 3) * PMULT
- cmovae state, t0
-
- ; jmp fin_OK
- mov sym, 1
- jmp fin
-
-end_of_payload:
- inc sym
- jnz fin_ERROR_MATCH_DIST
-
- mov LOC remainLen, kMatchSpecLenStart
- sub state, kNumStates * PMULT
-
-fin_OK:
- xor sym, sym
-
-fin:
- NORM
-
- mov r1, LOC lzmaPtr
-
- sub dicPos, LOC dic_Spec
- mov GLOB dicPos_Spec, dicPos
- mov GLOB buf_Spec, buf
- mov GLOB range_Spec, range
- mov GLOB code_Spec, cod
- shr state, PSHIFT
- mov GLOB state_Spec, state
- mov GLOB processedPos_Spec, processedPos
-
- RESTORE_VAR(remainLen)
- RESTORE_VAR(rep0)
- RESTORE_VAR(rep1)
- RESTORE_VAR(rep2)
- RESTORE_VAR(rep3)
-
- mov x0, sym
-
- mov RSP, LOC Old_RSP
-
-MY_POP_PRESERVED_ABI_REGS
-MY_ENDP
-
-_TEXT$LZMADECOPT ENDS
-
-end
+; LzmaDecOpt.asm -- ASM version of LzmaDec_DecodeReal_3() function
+; 2021-02-23: Igor Pavlov : Public domain
+;
+; 3 - is the code compatibility version of LzmaDec_DecodeReal_*()
+; function for check at link time.
+; That code is tightly coupled with LzmaDec_TryDummy()
+; and with another functions in LzmaDec.c file.
+; CLzmaDec structure, (probs) array layout, input and output of
+; LzmaDec_DecodeReal_*() must be equal in both versions (C / ASM).
+
+ifndef x64
+; x64=1
+; .err
+endif
+
+include 7zAsm.asm
+
+MY_ASM_START
+
+_TEXT$LZMADECOPT SEGMENT ALIGN(64) 'CODE'
+
+MY_ALIGN macro num:req
+ align num
+endm
+
+MY_ALIGN_16 macro
+ MY_ALIGN 16
+endm
+
+MY_ALIGN_32 macro
+ MY_ALIGN 32
+endm
+
+MY_ALIGN_64 macro
+ MY_ALIGN 64
+endm
+
+
+; _LZMA_SIZE_OPT equ 1
+
+; _LZMA_PROB32 equ 1
+
+ifdef _LZMA_PROB32
+ PSHIFT equ 2
+ PLOAD macro dest, mem
+ mov dest, dword ptr [mem]
+ endm
+ PSTORE macro src, mem
+ mov dword ptr [mem], src
+ endm
+else
+ PSHIFT equ 1
+ PLOAD macro dest, mem
+ movzx dest, word ptr [mem]
+ endm
+ PSTORE macro src, mem
+ mov word ptr [mem], @CatStr(src, _W)
+ endm
+endif
+
+PMULT equ (1 SHL PSHIFT)
+PMULT_HALF equ (1 SHL (PSHIFT - 1))
+PMULT_2 equ (1 SHL (PSHIFT + 1))
+
+kMatchSpecLen_Error_Data equ (1 SHL 9)
+
+; x0 range
+; x1 pbPos / (prob) TREE
+; x2 probBranch / prm (MATCHED) / pbPos / cnt
+; x3 sym
+;====== r4 === RSP
+; x5 cod
+; x6 t1 NORM_CALC / probs_state / dist
+; x7 t0 NORM_CALC / prob2 IF_BIT_1
+; x8 state
+; x9 match (MATCHED) / sym2 / dist2 / lpMask_reg
+; x10 kBitModelTotal_reg
+; r11 probs
+; x12 offs (MATCHED) / dic / len_temp
+; x13 processedPos
+; x14 bit (MATCHED) / dicPos
+; r15 buf
+
+
+cod equ x5
+cod_L equ x5_L
+range equ x0
+state equ x8
+state_R equ r8
+buf equ r15
+processedPos equ x13
+kBitModelTotal_reg equ x10
+
+probBranch equ x2
+probBranch_R equ r2
+probBranch_W equ x2_W
+
+pbPos equ x1
+pbPos_R equ r1
+
+cnt equ x2
+cnt_R equ r2
+
+lpMask_reg equ x9
+dicPos equ r14
+
+sym equ x3
+sym_R equ r3
+sym_L equ x3_L
+
+probs equ r11
+dic equ r12
+
+t0 equ x7
+t0_W equ x7_W
+t0_R equ r7
+
+prob2 equ t0
+prob2_W equ t0_W
+
+t1 equ x6
+t1_R equ r6
+
+probs_state equ t1
+probs_state_R equ t1_R
+
+prm equ r2
+match equ x9
+match_R equ r9
+offs equ x12
+offs_R equ r12
+bit equ x14
+bit_R equ r14
+
+sym2 equ x9
+sym2_R equ r9
+
+len_temp equ x12
+
+dist equ sym
+dist2 equ x9
+
+
+
+kNumBitModelTotalBits equ 11
+kBitModelTotal equ (1 SHL kNumBitModelTotalBits)
+kNumMoveBits equ 5
+kBitModelOffset equ ((1 SHL kNumMoveBits) - 1)
+kTopValue equ (1 SHL 24)
+
+NORM_2 macro
+ ; movzx t0, BYTE PTR [buf]
+ shl cod, 8
+ mov cod_L, BYTE PTR [buf]
+ shl range, 8
+ ; or cod, t0
+ inc buf
+endm
+
+
+NORM macro
+ cmp range, kTopValue
+ jae SHORT @F
+ NORM_2
+@@:
+endm
+
+
+; ---------- Branch MACROS ----------
+
+UPDATE_0 macro probsArray:req, probOffset:req, probDisp:req
+ mov prob2, kBitModelTotal_reg
+ sub prob2, probBranch
+ shr prob2, kNumMoveBits
+ add probBranch, prob2
+ PSTORE probBranch, probOffset * 1 + probsArray + probDisp * PMULT
+endm
+
+
+UPDATE_1 macro probsArray:req, probOffset:req, probDisp:req
+ sub prob2, range
+ sub cod, range
+ mov range, prob2
+ mov prob2, probBranch
+ shr probBranch, kNumMoveBits
+ sub prob2, probBranch
+ PSTORE prob2, probOffset * 1 + probsArray + probDisp * PMULT
+endm
+
+
+CMP_COD macro probsArray:req, probOffset:req, probDisp:req
+ PLOAD probBranch, probOffset * 1 + probsArray + probDisp * PMULT
+ NORM
+ mov prob2, range
+ shr range, kNumBitModelTotalBits
+ imul range, probBranch
+ cmp cod, range
+endm
+
+
+IF_BIT_1_NOUP macro probsArray:req, probOffset:req, probDisp:req, toLabel:req
+ CMP_COD probsArray, probOffset, probDisp
+ jae toLabel
+endm
+
+
+IF_BIT_1 macro probsArray:req, probOffset:req, probDisp:req, toLabel:req
+ IF_BIT_1_NOUP probsArray, probOffset, probDisp, toLabel
+ UPDATE_0 probsArray, probOffset, probDisp
+endm
+
+
+IF_BIT_0_NOUP macro probsArray:req, probOffset:req, probDisp:req, toLabel:req
+ CMP_COD probsArray, probOffset, probDisp
+ jb toLabel
+endm
+
+
+; ---------- CMOV MACROS ----------
+
+NORM_CALC macro prob:req
+ NORM
+ mov t0, range
+ shr range, kNumBitModelTotalBits
+ imul range, prob
+ sub t0, range
+ mov t1, cod
+ sub cod, range
+endm
+
+
+PUP macro prob:req, probPtr:req
+ sub t0, prob
+ ; only sar works for both 16/32 bit prob modes
+ sar t0, kNumMoveBits
+ add t0, prob
+ PSTORE t0, probPtr
+endm
+
+
+PUP_SUB macro prob:req, probPtr:req, symSub:req
+ sbb sym, symSub
+ PUP prob, probPtr
+endm
+
+
+PUP_COD macro prob:req, probPtr:req, symSub:req
+ mov t0, kBitModelOffset
+ cmovb cod, t1
+ mov t1, sym
+ cmovb t0, kBitModelTotal_reg
+ PUP_SUB prob, probPtr, symSub
+endm
+
+
+BIT_0 macro prob:req, probNext:req
+ PLOAD prob, probs + 1 * PMULT
+ PLOAD probNext, probs + 1 * PMULT_2
+
+ NORM_CALC prob
+
+ cmovae range, t0
+ PLOAD t0, probs + 1 * PMULT_2 + PMULT
+ cmovae probNext, t0
+ mov t0, kBitModelOffset
+ cmovb cod, t1
+ cmovb t0, kBitModelTotal_reg
+ mov sym, 2
+ PUP_SUB prob, probs + 1 * PMULT, 0 - 1
+endm
+
+
+BIT_1 macro prob:req, probNext:req
+ PLOAD probNext, probs + sym_R * PMULT_2
+ add sym, sym
+
+ NORM_CALC prob
+
+ cmovae range, t0
+ PLOAD t0, probs + sym_R * PMULT + PMULT
+ cmovae probNext, t0
+ PUP_COD prob, probs + t1_R * PMULT_HALF, 0 - 1
+endm
+
+
+BIT_2 macro prob:req, symSub:req
+ add sym, sym
+
+ NORM_CALC prob
+
+ cmovae range, t0
+ PUP_COD prob, probs + t1_R * PMULT_HALF, symSub
+endm
+
+
+; ---------- MATCHED LITERAL ----------
+
+LITM_0 macro
+ mov offs, 256 * PMULT
+ shl match, (PSHIFT + 1)
+ mov bit, offs
+ and bit, match
+ PLOAD x1, probs + 256 * PMULT + bit_R * 1 + 1 * PMULT
+ lea prm, [probs + 256 * PMULT + bit_R * 1 + 1 * PMULT]
+ ; lea prm, [probs + 256 * PMULT + 1 * PMULT]
+ ; add prm, bit_R
+ xor offs, bit
+ add match, match
+
+ NORM_CALC x1
+
+ cmovae offs, bit
+ mov bit, match
+ cmovae range, t0
+ mov t0, kBitModelOffset
+ cmovb cod, t1
+ cmovb t0, kBitModelTotal_reg
+ mov sym, 0
+ PUP_SUB x1, prm, -2-1
+endm
+
+
+LITM macro
+ and bit, offs
+ lea prm, [probs + offs_R * 1]
+ add prm, bit_R
+ PLOAD x1, prm + sym_R * PMULT
+ xor offs, bit
+ add sym, sym
+ add match, match
+
+ NORM_CALC x1
+
+ cmovae offs, bit
+ mov bit, match
+ cmovae range, t0
+ PUP_COD x1, prm + t1_R * PMULT_HALF, - 1
+endm
+
+
+LITM_2 macro
+ and bit, offs
+ lea prm, [probs + offs_R * 1]
+ add prm, bit_R
+ PLOAD x1, prm + sym_R * PMULT
+ add sym, sym
+
+ NORM_CALC x1
+
+ cmovae range, t0
+ PUP_COD x1, prm + t1_R * PMULT_HALF, 256 - 1
+endm
+
+
+; ---------- REVERSE BITS ----------
+
+REV_0 macro prob:req, probNext:req
+ ; PLOAD prob, probs + 1 * PMULT
+ ; lea sym2_R, [probs + 2 * PMULT]
+ ; PLOAD probNext, probs + 2 * PMULT
+ PLOAD probNext, sym2_R
+
+ NORM_CALC prob
+
+ cmovae range, t0
+ PLOAD t0, probs + 3 * PMULT
+ cmovae probNext, t0
+ cmovb cod, t1
+ mov t0, kBitModelOffset
+ cmovb t0, kBitModelTotal_reg
+ lea t1_R, [probs + 3 * PMULT]
+ cmovae sym2_R, t1_R
+ PUP prob, probs + 1 * PMULT
+endm
+
+
+REV_1 macro prob:req, probNext:req, step:req
+ add sym2_R, step * PMULT
+ PLOAD probNext, sym2_R
+
+ NORM_CALC prob
+
+ cmovae range, t0
+ PLOAD t0, sym2_R + step * PMULT
+ cmovae probNext, t0
+ cmovb cod, t1
+ mov t0, kBitModelOffset
+ cmovb t0, kBitModelTotal_reg
+ lea t1_R, [sym2_R + step * PMULT]
+ cmovae sym2_R, t1_R
+ PUP prob, t1_R - step * PMULT_2
+endm
+
+
+REV_2 macro prob:req, step:req
+ sub sym2_R, probs
+ shr sym2, PSHIFT
+ or sym, sym2
+
+ NORM_CALC prob
+
+ cmovae range, t0
+ lea t0, [sym - step]
+ cmovb sym, t0
+ cmovb cod, t1
+ mov t0, kBitModelOffset
+ cmovb t0, kBitModelTotal_reg
+ PUP prob, probs + sym2_R * PMULT
+endm
+
+
+REV_1_VAR macro prob:req
+ PLOAD prob, sym_R
+ mov probs, sym_R
+ add sym_R, sym2_R
+
+ NORM_CALC prob
+
+ cmovae range, t0
+ lea t0_R, [sym_R + 1 * sym2_R]
+ cmovae sym_R, t0_R
+ mov t0, kBitModelOffset
+ cmovb cod, t1
+ ; mov t1, kBitModelTotal
+ ; cmovb t0, t1
+ cmovb t0, kBitModelTotal_reg
+ add sym2, sym2
+ PUP prob, probs
+endm
+
+
+
+
+LIT_PROBS macro lpMaskParam:req
+ ; prob += (UInt32)3 * ((((processedPos << 8) + dic[(dicPos == 0 ? dicBufSize : dicPos) - 1]) & lpMask) << lc);
+ mov t0, processedPos
+ shl t0, 8
+ add sym, t0
+ and sym, lpMaskParam
+ add probs_state_R, pbPos_R
+ mov x1, LOC lc2
+ lea sym, dword ptr[sym_R + 2 * sym_R]
+ add probs, Literal * PMULT
+ shl sym, x1_L
+ add probs, sym_R
+ UPDATE_0 probs_state_R, 0, IsMatch
+ inc processedPos
+endm
+
+
+
+kNumPosBitsMax equ 4
+kNumPosStatesMax equ (1 SHL kNumPosBitsMax)
+
+kLenNumLowBits equ 3
+kLenNumLowSymbols equ (1 SHL kLenNumLowBits)
+kLenNumHighBits equ 8
+kLenNumHighSymbols equ (1 SHL kLenNumHighBits)
+kNumLenProbs equ (2 * kLenNumLowSymbols * kNumPosStatesMax + kLenNumHighSymbols)
+
+LenLow equ 0
+LenChoice equ LenLow
+LenChoice2 equ (LenLow + kLenNumLowSymbols)
+LenHigh equ (LenLow + 2 * kLenNumLowSymbols * kNumPosStatesMax)
+
+kNumStates equ 12
+kNumStates2 equ 16
+kNumLitStates equ 7
+
+kStartPosModelIndex equ 4
+kEndPosModelIndex equ 14
+kNumFullDistances equ (1 SHL (kEndPosModelIndex SHR 1))
+
+kNumPosSlotBits equ 6
+kNumLenToPosStates equ 4
+
+kNumAlignBits equ 4
+kAlignTableSize equ (1 SHL kNumAlignBits)
+
+kMatchMinLen equ 2
+kMatchSpecLenStart equ (kMatchMinLen + kLenNumLowSymbols * 2 + kLenNumHighSymbols)
+
+kStartOffset equ 1664
+SpecPos equ (-kStartOffset)
+IsRep0Long equ (SpecPos + kNumFullDistances)
+RepLenCoder equ (IsRep0Long + (kNumStates2 SHL kNumPosBitsMax))
+LenCoder equ (RepLenCoder + kNumLenProbs)
+IsMatch equ (LenCoder + kNumLenProbs)
+kAlign equ (IsMatch + (kNumStates2 SHL kNumPosBitsMax))
+IsRep equ (kAlign + kAlignTableSize)
+IsRepG0 equ (IsRep + kNumStates)
+IsRepG1 equ (IsRepG0 + kNumStates)
+IsRepG2 equ (IsRepG1 + kNumStates)
+PosSlot equ (IsRepG2 + kNumStates)
+Literal equ (PosSlot + (kNumLenToPosStates SHL kNumPosSlotBits))
+NUM_BASE_PROBS equ (Literal + kStartOffset)
+
+if kAlign ne 0
+ .err
+endif
+
+if NUM_BASE_PROBS ne 1984
+ .err
+endif
+
+
+PTR_FIELD equ dq ?
+
+CLzmaDec_Asm struct
+ lc db ?
+ lp db ?
+ pb db ?
+ _pad_ db ?
+ dicSize dd ?
+
+ probs_Spec PTR_FIELD
+ probs_1664 PTR_FIELD
+ dic_Spec PTR_FIELD
+ dicBufSize PTR_FIELD
+ dicPos_Spec PTR_FIELD
+ buf_Spec PTR_FIELD
+
+ range_Spec dd ?
+ code_Spec dd ?
+ processedPos_Spec dd ?
+ checkDicSize dd ?
+ rep0 dd ?
+ rep1 dd ?
+ rep2 dd ?
+ rep3 dd ?
+ state_Spec dd ?
+ remainLen dd ?
+CLzmaDec_Asm ends
+
+
+CLzmaDec_Asm_Loc struct
+ OLD_RSP PTR_FIELD
+ lzmaPtr PTR_FIELD
+ _pad0_ PTR_FIELD
+ _pad1_ PTR_FIELD
+ _pad2_ PTR_FIELD
+ dicBufSize PTR_FIELD
+ probs_Spec PTR_FIELD
+ dic_Spec PTR_FIELD
+
+ limit PTR_FIELD
+ bufLimit PTR_FIELD
+ lc2 dd ?
+ lpMask dd ?
+ pbMask dd ?
+ checkDicSize dd ?
+
+ _pad_ dd ?
+ remainLen dd ?
+ dicPos_Spec PTR_FIELD
+ rep0 dd ?
+ rep1 dd ?
+ rep2 dd ?
+ rep3 dd ?
+CLzmaDec_Asm_Loc ends
+
+
+GLOB_2 equ [sym_R].CLzmaDec_Asm.
+GLOB equ [r1].CLzmaDec_Asm.
+LOC_0 equ [r0].CLzmaDec_Asm_Loc.
+LOC equ [RSP].CLzmaDec_Asm_Loc.
+
+
+COPY_VAR macro name
+ mov t0, GLOB_2 name
+ mov LOC_0 name, t0
+endm
+
+
+RESTORE_VAR macro name
+ mov t0, LOC name
+ mov GLOB name, t0
+endm
+
+
+
+IsMatchBranch_Pre macro reg
+ ; prob = probs + IsMatch + (state << kNumPosBitsMax) + posState;
+ mov pbPos, LOC pbMask
+ and pbPos, processedPos
+ shl pbPos, (kLenNumLowBits + 1 + PSHIFT)
+ lea probs_state_R, [probs + 1 * state_R]
+endm
+
+
+IsMatchBranch macro reg
+ IsMatchBranch_Pre
+ IF_BIT_1 probs_state_R, pbPos_R, IsMatch, IsMatch_label
+endm
+
+
+CheckLimits macro reg
+ cmp buf, LOC bufLimit
+ jae fin_OK
+ cmp dicPos, LOC limit
+ jae fin_OK
+endm
+
+
+
+; RSP is (16x + 8) bytes aligned in WIN64-x64
+; LocalSize equ ((((SIZEOF CLzmaDec_Asm_Loc) + 7) / 16 * 16) + 8)
+
+PARAM_lzma equ REG_ABI_PARAM_0
+PARAM_limit equ REG_ABI_PARAM_1
+PARAM_bufLimit equ REG_ABI_PARAM_2
+
+; MY_ALIGN_64
+MY_PROC LzmaDec_DecodeReal_3, 3
+MY_PUSH_PRESERVED_ABI_REGS
+
+ lea r0, [RSP - (SIZEOF CLzmaDec_Asm_Loc)]
+ and r0, -128
+ mov r5, RSP
+ mov RSP, r0
+ mov LOC_0 Old_RSP, r5
+ mov LOC_0 lzmaPtr, PARAM_lzma
+
+ mov LOC_0 remainLen, 0 ; remainLen must be ZERO
+
+ mov LOC_0 bufLimit, PARAM_bufLimit
+ mov sym_R, PARAM_lzma ; CLzmaDec_Asm_Loc pointer for GLOB_2
+ mov dic, GLOB_2 dic_Spec
+ add PARAM_limit, dic
+ mov LOC_0 limit, PARAM_limit
+
+ COPY_VAR(rep0)
+ COPY_VAR(rep1)
+ COPY_VAR(rep2)
+ COPY_VAR(rep3)
+
+ mov dicPos, GLOB_2 dicPos_Spec
+ add dicPos, dic
+ mov LOC_0 dicPos_Spec, dicPos
+ mov LOC_0 dic_Spec, dic
+
+ mov x1_L, GLOB_2 pb
+ mov t0, 1
+ shl t0, x1_L
+ dec t0
+ mov LOC_0 pbMask, t0
+
+ ; unsigned pbMask = ((unsigned)1 << (p->prop.pb)) - 1;
+ ; unsigned lc = p->prop.lc;
+ ; unsigned lpMask = ((unsigned)0x100 << p->prop.lp) - ((unsigned)0x100 >> lc);
+
+ mov x1_L, GLOB_2 lc
+ mov x2, 100h
+ mov t0, x2
+ shr x2, x1_L
+ ; inc x1
+ add x1_L, PSHIFT
+ mov LOC_0 lc2, x1
+ mov x1_L, GLOB_2 lp
+ shl t0, x1_L
+ sub t0, x2
+ mov LOC_0 lpMask, t0
+ mov lpMask_reg, t0
+
+ ; mov probs, GLOB_2 probs_Spec
+ ; add probs, kStartOffset SHL PSHIFT
+ mov probs, GLOB_2 probs_1664
+ mov LOC_0 probs_Spec, probs
+
+ mov t0_R, GLOB_2 dicBufSize
+ mov LOC_0 dicBufSize, t0_R
+
+ mov x1, GLOB_2 checkDicSize
+ mov LOC_0 checkDicSize, x1
+
+ mov processedPos, GLOB_2 processedPos_Spec
+
+ mov state, GLOB_2 state_Spec
+ shl state, PSHIFT
+
+ mov buf, GLOB_2 buf_Spec
+ mov range, GLOB_2 range_Spec
+ mov cod, GLOB_2 code_Spec
+ mov kBitModelTotal_reg, kBitModelTotal
+ xor sym, sym
+
+ ; if (processedPos != 0 || checkDicSize != 0)
+ or x1, processedPos
+ jz @f
+
+ add t0_R, dic
+ cmp dicPos, dic
+ cmovnz t0_R, dicPos
+ movzx sym, byte ptr[t0_R - 1]
+
+@@:
+ IsMatchBranch_Pre
+ cmp state, 4 * PMULT
+ jb lit_end
+ cmp state, kNumLitStates * PMULT
+ jb lit_matched_end
+ jmp lz_end
+
+
+
+
+; ---------- LITERAL ----------
+MY_ALIGN_64
+lit_start:
+ xor state, state
+lit_start_2:
+ LIT_PROBS lpMask_reg
+
+ ifdef _LZMA_SIZE_OPT
+
+ PLOAD x1, probs + 1 * PMULT
+ mov sym, 1
+MY_ALIGN_16
+lit_loop:
+ BIT_1 x1, x2
+ mov x1, x2
+ cmp sym, 127
+ jbe lit_loop
+
+ else
+
+ BIT_0 x1, x2
+ BIT_1 x2, x1
+ BIT_1 x1, x2
+ BIT_1 x2, x1
+ BIT_1 x1, x2
+ BIT_1 x2, x1
+ BIT_1 x1, x2
+
+ endif
+
+ BIT_2 x2, 256 - 1
+
+ ; mov dic, LOC dic_Spec
+ mov probs, LOC probs_Spec
+ IsMatchBranch_Pre
+ mov byte ptr[dicPos], sym_L
+ inc dicPos
+
+ CheckLimits
+lit_end:
+ IF_BIT_0_NOUP probs_state_R, pbPos_R, IsMatch, lit_start
+
+ ; jmp IsMatch_label
+
+; ---------- MATCHES ----------
+; MY_ALIGN_32
+IsMatch_label:
+ UPDATE_1 probs_state_R, pbPos_R, IsMatch
+ IF_BIT_1 probs_state_R, 0, IsRep, IsRep_label
+
+ add probs, LenCoder * PMULT
+ add state, kNumStates * PMULT
+
+; ---------- LEN DECODE ----------
+len_decode:
+ mov len_temp, 8 - 1 - kMatchMinLen
+ IF_BIT_0_NOUP probs, 0, 0, len_mid_0
+ UPDATE_1 probs, 0, 0
+ add probs, (1 SHL (kLenNumLowBits + PSHIFT))
+ mov len_temp, -1 - kMatchMinLen
+ IF_BIT_0_NOUP probs, 0, 0, len_mid_0
+ UPDATE_1 probs, 0, 0
+ add probs, LenHigh * PMULT - (1 SHL (kLenNumLowBits + PSHIFT))
+ mov sym, 1
+ PLOAD x1, probs + 1 * PMULT
+
+MY_ALIGN_32
+len8_loop:
+ BIT_1 x1, x2
+ mov x1, x2
+ cmp sym, 64
+ jb len8_loop
+
+ mov len_temp, (kLenNumHighSymbols - kLenNumLowSymbols * 2) - 1 - kMatchMinLen
+ jmp short len_mid_2 ; we use short here for MASM that doesn't optimize that code as another assembler programs
+
+MY_ALIGN_32
+len_mid_0:
+ UPDATE_0 probs, 0, 0
+ add probs, pbPos_R
+ BIT_0 x2, x1
+len_mid_2:
+ BIT_1 x1, x2
+ BIT_2 x2, len_temp
+ mov probs, LOC probs_Spec
+ cmp state, kNumStates * PMULT
+ jb copy_match
+
+
+; ---------- DECODE DISTANCE ----------
+ ; probs + PosSlot + ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << kNumPosSlotBits);
+
+ mov t0, 3 + kMatchMinLen
+ cmp sym, 3 + kMatchMinLen
+ cmovb t0, sym
+ add probs, PosSlot * PMULT - (kMatchMinLen SHL (kNumPosSlotBits + PSHIFT))
+ shl t0, (kNumPosSlotBits + PSHIFT)
+ add probs, t0_R
+
+ ; sym = Len
+ ; mov LOC remainLen, sym
+ mov len_temp, sym
+
+ ifdef _LZMA_SIZE_OPT
+
+ PLOAD x1, probs + 1 * PMULT
+ mov sym, 1
+MY_ALIGN_16
+slot_loop:
+ BIT_1 x1, x2
+ mov x1, x2
+ cmp sym, 32
+ jb slot_loop
+
+ else
+
+ BIT_0 x1, x2
+ BIT_1 x2, x1
+ BIT_1 x1, x2
+ BIT_1 x2, x1
+ BIT_1 x1, x2
+
+ endif
+
+ mov x1, sym
+ BIT_2 x2, 64-1
+
+ and sym, 3
+ mov probs, LOC probs_Spec
+ cmp x1, 32 + kEndPosModelIndex / 2
+ jb short_dist
+
+ ; unsigned numDirectBits = (unsigned)(((distance >> 1) - 1));
+ sub x1, (32 + 1 + kNumAlignBits)
+ ; distance = (2 | (distance & 1));
+ or sym, 2
+ PLOAD x2, probs + 1 * PMULT
+ shl sym, kNumAlignBits + 1
+ lea sym2_R, [probs + 2 * PMULT]
+
+ jmp direct_norm
+ ; lea t1, [sym_R + (1 SHL kNumAlignBits)]
+ ; cmp range, kTopValue
+ ; jb direct_norm
+
+; ---------- DIRECT DISTANCE ----------
+MY_ALIGN_32
+direct_loop:
+ shr range, 1
+ mov t0, cod
+ sub cod, range
+ cmovs cod, t0
+ cmovns sym, t1
+
+ comment ~
+ sub cod, range
+ mov x2, cod
+ sar x2, 31
+ lea sym, dword ptr [r2 + sym_R * 2 + 1]
+ and x2, range
+ add cod, x2
+ ~
+ dec x1
+ je direct_end
+
+ add sym, sym
+direct_norm:
+ lea t1, [sym_R + (1 SHL kNumAlignBits)]
+ cmp range, kTopValue
+ jae near ptr direct_loop
+ ; we align for 32 here with "near ptr" command above
+ NORM_2
+ jmp direct_loop
+
+MY_ALIGN_32
+direct_end:
+ ; prob = + kAlign;
+ ; distance <<= kNumAlignBits;
+ REV_0 x2, x1
+ REV_1 x1, x2, 2
+ REV_1 x2, x1, 4
+ REV_2 x1, 8
+
+decode_dist_end:
+
+ ; if (distance >= (checkDicSize == 0 ? processedPos: checkDicSize))
+
+ mov t1, LOC rep0
+ mov x1, LOC rep1
+ mov x2, LOC rep2
+
+ mov t0, LOC checkDicSize
+ test t0, t0
+ cmove t0, processedPos
+ cmp sym, t0
+ jae end_of_payload
+ ; jmp end_of_payload ; for debug
+
+ ; rep3 = rep2;
+ ; rep2 = rep1;
+ ; rep1 = rep0;
+ ; rep0 = distance + 1;
+
+ inc sym
+ mov LOC rep0, sym
+ ; mov sym, LOC remainLen
+ mov sym, len_temp
+ mov LOC rep1, t1
+ mov LOC rep2, x1
+ mov LOC rep3, x2
+
+ ; state = (state < kNumStates + kNumLitStates) ? kNumLitStates : kNumLitStates + 3;
+ cmp state, (kNumStates + kNumLitStates) * PMULT
+ mov state, kNumLitStates * PMULT
+ mov t0, (kNumLitStates + 3) * PMULT
+ cmovae state, t0
+
+
+; ---------- COPY MATCH ----------
+copy_match:
+
+ ; len += kMatchMinLen;
+ ; add sym, kMatchMinLen
+
+ ; if ((rem = limit - dicPos) == 0)
+ ; {
+ ; p->dicPos = dicPos;
+ ; return SZ_ERROR_DATA;
+ ; }
+ mov cnt_R, LOC limit
+ sub cnt_R, dicPos
+ jz fin_dicPos_LIMIT
+
+ ; curLen = ((rem < len) ? (unsigned)rem : len);
+ cmp cnt_R, sym_R
+ ; cmovae cnt_R, sym_R ; 64-bit
+ cmovae cnt, sym ; 32-bit
+
+ mov dic, LOC dic_Spec
+ mov x1, LOC rep0
+
+ mov t0_R, dicPos
+ add dicPos, cnt_R
+ ; processedPos += curLen;
+ add processedPos, cnt
+ ; len -= curLen;
+ sub sym, cnt
+ mov LOC remainLen, sym
+
+ sub t0_R, dic
+
+ ; pos = dicPos - rep0 + (dicPos < rep0 ? dicBufSize : 0);
+ sub t0_R, r1
+ jae @f
+
+ mov r1, LOC dicBufSize
+ add t0_R, r1
+ sub r1, t0_R
+ cmp cnt_R, r1
+ ja copy_match_cross
+@@:
+ ; if (curLen <= dicBufSize - pos)
+
+; ---------- COPY MATCH FAST ----------
+ ; Byte *dest = dic + dicPos;
+ ; mov r1, dic
+ ; ptrdiff_t src = (ptrdiff_t)pos - (ptrdiff_t)dicPos;
+ ; sub t0_R, dicPos
+ ; dicPos += curLen;
+
+ ; const Byte *lim = dest + curLen;
+ add t0_R, dic
+ movzx sym, byte ptr[t0_R]
+ add t0_R, cnt_R
+ neg cnt_R
+ ; lea r1, [dicPos - 1]
+copy_common:
+ dec dicPos
+ ; cmp LOC rep0, 1
+ ; je rep0Label
+
+ ; t0_R - src_lim
+ ; r1 - dest_lim - 1
+ ; cnt_R - (-cnt)
+
+ IsMatchBranch_Pre
+ inc cnt_R
+ jz copy_end
+MY_ALIGN_16
+@@:
+ mov byte ptr[cnt_R * 1 + dicPos], sym_L
+ movzx sym, byte ptr[cnt_R * 1 + t0_R]
+ inc cnt_R
+ jnz @b
+
+copy_end:
+lz_end_match:
+ mov byte ptr[dicPos], sym_L
+ inc dicPos
+
+ ; IsMatchBranch_Pre
+ CheckLimits
+lz_end:
+ IF_BIT_1_NOUP probs_state_R, pbPos_R, IsMatch, IsMatch_label
+
+
+
+; ---------- LITERAL MATCHED ----------
+
+ LIT_PROBS LOC lpMask
+
+ ; matchByte = dic[dicPos - rep0 + (dicPos < rep0 ? dicBufSize : 0)];
+ mov x1, LOC rep0
+ ; mov dic, LOC dic_Spec
+ mov LOC dicPos_Spec, dicPos
+
+ ; state -= (state < 10) ? 3 : 6;
+ lea t0, [state_R - 6 * PMULT]
+ sub state, 3 * PMULT
+ cmp state, 7 * PMULT
+ cmovae state, t0
+
+ sub dicPos, dic
+ sub dicPos, r1
+ jae @f
+ add dicPos, LOC dicBufSize
+@@:
+ comment ~
+ xor t0, t0
+ sub dicPos, r1
+ cmovb t0_R, LOC dicBufSize
+ ~
+
+ movzx match, byte ptr[dic + dicPos * 1]
+
+ ifdef _LZMA_SIZE_OPT
+
+ mov offs, 256 * PMULT
+ shl match, (PSHIFT + 1)
+ mov bit, match
+ mov sym, 1
+MY_ALIGN_16
+litm_loop:
+ LITM
+ cmp sym, 256
+ jb litm_loop
+ sub sym, 256
+
+ else
+
+ LITM_0
+ LITM
+ LITM
+ LITM
+ LITM
+ LITM
+ LITM
+ LITM_2
+
+ endif
+
+ mov probs, LOC probs_Spec
+ IsMatchBranch_Pre
+ ; mov dic, LOC dic_Spec
+ mov dicPos, LOC dicPos_Spec
+ mov byte ptr[dicPos], sym_L
+ inc dicPos
+
+ CheckLimits
+lit_matched_end:
+ IF_BIT_1_NOUP probs_state_R, pbPos_R, IsMatch, IsMatch_label
+ ; IsMatchBranch
+ mov lpMask_reg, LOC lpMask
+ sub state, 3 * PMULT
+ jmp lit_start_2
+
+
+
+; ---------- REP 0 LITERAL ----------
+MY_ALIGN_32
+IsRep0Short_label:
+ UPDATE_0 probs_state_R, pbPos_R, IsRep0Long
+
+ ; dic[dicPos] = dic[dicPos - rep0 + (dicPos < rep0 ? dicBufSize : 0)];
+ mov dic, LOC dic_Spec
+ mov t0_R, dicPos
+ mov probBranch, LOC rep0
+ sub t0_R, dic
+
+ sub probs, RepLenCoder * PMULT
+
+ ; state = state < kNumLitStates ? 9 : 11;
+ or state, 1 * PMULT
+
+ ; the caller doesn't allow (dicPos >= limit) case for REP_SHORT
+ ; so we don't need the following (dicPos == limit) check here:
+ ; cmp dicPos, LOC limit
+ ; jae fin_dicPos_LIMIT_REP_SHORT
+
+ inc processedPos
+
+ IsMatchBranch_Pre
+
+; xor sym, sym
+; sub t0_R, probBranch_R
+; cmovb sym_R, LOC dicBufSize
+; add t0_R, sym_R
+ sub t0_R, probBranch_R
+ jae @f
+ add t0_R, LOC dicBufSize
+@@:
+ movzx sym, byte ptr[dic + t0_R * 1]
+ jmp lz_end_match
+
+
+MY_ALIGN_32
+IsRep_label:
+ UPDATE_1 probs_state_R, 0, IsRep
+
+ ; The (checkDicSize == 0 && processedPos == 0) case was checked before in LzmaDec.c with kBadRepCode.
+ ; So we don't check it here.
+
+ ; mov t0, processedPos
+ ; or t0, LOC checkDicSize
+ ; jz fin_ERROR_2
+
+ ; state = state < kNumLitStates ? 8 : 11;
+ cmp state, kNumLitStates * PMULT
+ mov state, 8 * PMULT
+ mov probBranch, 11 * PMULT
+ cmovae state, probBranch
+
+ ; prob = probs + RepLenCoder;
+ add probs, RepLenCoder * PMULT
+
+ IF_BIT_1 probs_state_R, 0, IsRepG0, IsRepG0_label
+ IF_BIT_0_NOUP probs_state_R, pbPos_R, IsRep0Long, IsRep0Short_label
+ UPDATE_1 probs_state_R, pbPos_R, IsRep0Long
+ jmp len_decode
+
+MY_ALIGN_32
+IsRepG0_label:
+ UPDATE_1 probs_state_R, 0, IsRepG0
+ mov dist2, LOC rep0
+ mov dist, LOC rep1
+ mov LOC rep1, dist2
+
+ IF_BIT_1 probs_state_R, 0, IsRepG1, IsRepG1_label
+ mov LOC rep0, dist
+ jmp len_decode
+
+; MY_ALIGN_32
+IsRepG1_label:
+ UPDATE_1 probs_state_R, 0, IsRepG1
+ mov dist2, LOC rep2
+ mov LOC rep2, dist
+
+ IF_BIT_1 probs_state_R, 0, IsRepG2, IsRepG2_label
+ mov LOC rep0, dist2
+ jmp len_decode
+
+; MY_ALIGN_32
+IsRepG2_label:
+ UPDATE_1 probs_state_R, 0, IsRepG2
+ mov dist, LOC rep3
+ mov LOC rep3, dist2
+ mov LOC rep0, dist
+ jmp len_decode
+
+
+
+; ---------- SPEC SHORT DISTANCE ----------
+
+MY_ALIGN_32
+short_dist:
+ sub x1, 32 + 1
+ jbe decode_dist_end
+ or sym, 2
+ shl sym, x1_L
+ lea sym_R, [probs + sym_R * PMULT + SpecPos * PMULT + 1 * PMULT]
+ mov sym2, PMULT ; step
+MY_ALIGN_32
+spec_loop:
+ REV_1_VAR x2
+ dec x1
+ jnz spec_loop
+
+ mov probs, LOC probs_Spec
+ sub sym, sym2
+ sub sym, SpecPos * PMULT
+ sub sym_R, probs
+ shr sym, PSHIFT
+
+ jmp decode_dist_end
+
+
+; ---------- COPY MATCH CROSS ----------
+copy_match_cross:
+ ; t0_R - src pos
+ ; r1 - len to dicBufSize
+ ; cnt_R - total copy len
+
+ mov t1_R, t0_R ; srcPos
+ mov t0_R, dic
+ mov r1, LOC dicBufSize ;
+ neg cnt_R
+@@:
+ movzx sym, byte ptr[t1_R * 1 + t0_R]
+ inc t1_R
+ mov byte ptr[cnt_R * 1 + dicPos], sym_L
+ inc cnt_R
+ cmp t1_R, r1
+ jne @b
+
+ movzx sym, byte ptr[t0_R]
+ sub t0_R, cnt_R
+ jmp copy_common
+
+
+
+
+; fin_dicPos_LIMIT_REP_SHORT:
+ ; mov sym, 1
+
+fin_dicPos_LIMIT:
+ mov LOC remainLen, sym
+ jmp fin_OK
+ ; For more strict mode we can stop decoding with error
+ ; mov sym, 1
+ ; jmp fin
+
+
+fin_ERROR_MATCH_DIST:
+
+ ; rep3 = rep2;
+ ; rep2 = rep1;
+ ; rep1 = rep0;
+ ; rep0 = distance + 1;
+
+ add len_temp, kMatchSpecLen_Error_Data
+ mov LOC remainLen, len_temp
+
+ mov LOC rep0, sym
+ mov LOC rep1, t1
+ mov LOC rep2, x1
+ mov LOC rep3, x2
+
+ ; state = (state < kNumStates + kNumLitStates) ? kNumLitStates : kNumLitStates + 3;
+ cmp state, (kNumStates + kNumLitStates) * PMULT
+ mov state, kNumLitStates * PMULT
+ mov t0, (kNumLitStates + 3) * PMULT
+ cmovae state, t0
+
+ ; jmp fin_OK
+ mov sym, 1
+ jmp fin
+
+end_of_payload:
+ inc sym
+ jnz fin_ERROR_MATCH_DIST
+
+ mov LOC remainLen, kMatchSpecLenStart
+ sub state, kNumStates * PMULT
+
+fin_OK:
+ xor sym, sym
+
+fin:
+ NORM
+
+ mov r1, LOC lzmaPtr
+
+ sub dicPos, LOC dic_Spec
+ mov GLOB dicPos_Spec, dicPos
+ mov GLOB buf_Spec, buf
+ mov GLOB range_Spec, range
+ mov GLOB code_Spec, cod
+ shr state, PSHIFT
+ mov GLOB state_Spec, state
+ mov GLOB processedPos_Spec, processedPos
+
+ RESTORE_VAR(remainLen)
+ RESTORE_VAR(rep0)
+ RESTORE_VAR(rep1)
+ RESTORE_VAR(rep2)
+ RESTORE_VAR(rep3)
+
+ mov x0, sym
+
+ mov RSP, LOC Old_RSP
+
+MY_POP_PRESERVED_ABI_REGS
+MY_ENDP
+
+_TEXT$LZMADECOPT ENDS
+
+end
diff --git a/deps/libchdr/deps/lzma-24.05/CMakeLists.txt b/deps/libchdr/deps/lzma-24.05/CMakeLists.txt
new file mode 100644
index 00000000..92d5f9a5
--- /dev/null
+++ b/deps/libchdr/deps/lzma-24.05/CMakeLists.txt
@@ -0,0 +1,58 @@
+add_library(lzma STATIC
+ include/7zTypes.h
+ include/7zWindows.h
+ include/Alloc.h
+ include/Bra.h
+ include/Compiler.h
+ include/CpuArch.h
+ include/Delta.h
+ include/LzFind.h
+ include/LzHash.h
+ include/Lzma86.h
+ include/LzmaDec.h
+ include/LzmaEnc.h
+ include/Precomp.h
+ include/RotateDefs.h
+ include/Sort.h
+ src/Alloc.c
+ src/Bra.c
+ src/Bra86.c
+ src/BraIA64.c
+ src/CpuArch.c
+ src/Delta.c
+ src/LzFind.c
+ src/Lzma86Dec.c
+ src/LzmaDec.c
+ src/LzmaEnc.c
+ src/Sort.c
+)
+
+target_compile_definitions(lzma PRIVATE Z7_ST)
+
+target_include_directories(lzma PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include")
+target_include_directories(lzma INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include")
+
+set_target_properties(lzma PROPERTIES POSITION_INDEPENDENT_CODE ON)
+
+option(WITH_LZMA_ASM "Use lzma asm" ON)
+if(WITH_LZMA_ASM)
+ if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+ include(CheckSymbolExists)
+ check_symbol_exists("__aarch64__" "" CPU_ARM64)
+ if(CPU_ARM64)
+ enable_language(ASM)
+ set_source_files_properties(src/LzmaDec.c PROPERTIES COMPILE_DEFINITIONS Z7_LZMA_DEC_OPT)
+ target_sources(lzma PRIVATE Asm/arm64/LzmaDecOpt.S)
+ set_source_files_properties(Asm/arm64/LzmaDecOpt.S PROPERTIES LANGUAGE ASM)
+ endif()
+ elseif(WIN32)
+ include(CheckSymbolExists)
+ check_symbol_exists("_M_AMD64" "" CPU_X64)
+ if(CPU_X64)
+ enable_language(ASM_MASM)
+ set_source_files_properties(src/LzmaDec.c PROPERTIES COMPILE_DEFINITIONS Z7_LZMA_DEC_OPT)
+ target_sources(lzma PRIVATE Asm/x86/LzmaDecOpt.asm)
+ set_source_files_properties(Asm/x86/LzmaDecOpt.asm PROPERTIES LANGUAGE ASM_MASM)
+ endif()
+ endif()
+endif()
diff --git a/deps/libchdr/deps/lzma-19.00/LICENSE b/deps/libchdr/deps/lzma-24.05/LICENSE
similarity index 100%
rename from deps/libchdr/deps/lzma-19.00/LICENSE
rename to deps/libchdr/deps/lzma-24.05/LICENSE
diff --git a/deps/libchdr/deps/lzma-22.01/include/7zTypes.h b/deps/libchdr/deps/lzma-24.05/include/7zTypes.h
similarity index 59%
rename from deps/libchdr/deps/lzma-22.01/include/7zTypes.h
rename to deps/libchdr/deps/lzma-24.05/include/7zTypes.h
index 763d3a9b..5b77420a 100644
--- a/deps/libchdr/deps/lzma-22.01/include/7zTypes.h
+++ b/deps/libchdr/deps/lzma-24.05/include/7zTypes.h
@@ -1,529 +1,597 @@
-/* 7zTypes.h -- Basic types
-2022-04-01 : Igor Pavlov : Public domain */
-
-#ifndef __7Z_TYPES_H
-#define __7Z_TYPES_H
-
-#ifdef _WIN32
-/* #include */
-#else
-#include
-#endif
-
-#include
-
-#ifndef EXTERN_C_BEGIN
-#ifdef __cplusplus
-#define EXTERN_C_BEGIN extern "C" {
-#define EXTERN_C_END }
-#else
-#define EXTERN_C_BEGIN
-#define EXTERN_C_END
-#endif
-#endif
-
-EXTERN_C_BEGIN
-
-#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_ARCHIVE 16
-#define SZ_ERROR_NO_ARCHIVE 17
-
-typedef int SRes;
-
-
-#ifdef _MSC_VER
- #if _MSC_VER > 1200
- #define MY_ALIGN(n) __declspec(align(n))
- #else
- #define MY_ALIGN(n)
- #endif
-#else
- #define MY_ALIGN(n) __attribute__ ((aligned(n)))
-#endif
-
-
-#ifdef _WIN32
-
-/* typedef DWORD WRes; */
-typedef unsigned WRes;
-#define MY_SRes_HRESULT_FROM_WRes(x) HRESULT_FROM_WIN32(x)
-
-// #define MY_HRES_ERROR__INTERNAL_ERROR MY_SRes_HRESULT_FROM_WRes(ERROR_INTERNAL_ERROR)
-
-#else // _WIN32
-
-// #define ENV_HAVE_LSTAT
-typedef int WRes;
-
-// (FACILITY_ERRNO = 0x800) is 7zip's FACILITY constant to represent (errno) errors in HRESULT
-#define MY__FACILITY_ERRNO 0x800
-#define MY__FACILITY_WIN32 7
-#define MY__FACILITY__WRes MY__FACILITY_ERRNO
-
-#define MY_HRESULT_FROM_errno_CONST_ERROR(x) ((HRESULT)( \
- ( (HRESULT)(x) & 0x0000FFFF) \
- | (MY__FACILITY__WRes << 16) \
- | (HRESULT)0x80000000 ))
-
-#define MY_SRes_HRESULT_FROM_WRes(x) \
- ((HRESULT)(x) <= 0 ? ((HRESULT)(x)) : MY_HRESULT_FROM_errno_CONST_ERROR(x))
-
-// we call macro HRESULT_FROM_WIN32 for system errors (WRes) that are (errno)
-#define HRESULT_FROM_WIN32(x) MY_SRes_HRESULT_FROM_WRes(x)
-
-/*
-#define ERROR_FILE_NOT_FOUND 2L
-#define ERROR_ACCESS_DENIED 5L
-#define ERROR_NO_MORE_FILES 18L
-#define ERROR_LOCK_VIOLATION 33L
-#define ERROR_FILE_EXISTS 80L
-#define ERROR_DISK_FULL 112L
-#define ERROR_NEGATIVE_SEEK 131L
-#define ERROR_ALREADY_EXISTS 183L
-#define ERROR_DIRECTORY 267L
-#define ERROR_TOO_MANY_POSTS 298L
-
-#define ERROR_INTERNAL_ERROR 1359L
-#define ERROR_INVALID_REPARSE_DATA 4392L
-#define ERROR_REPARSE_TAG_INVALID 4393L
-#define ERROR_REPARSE_TAG_MISMATCH 4394L
-*/
-
-// we use errno equivalents for some WIN32 errors:
-
-#define ERROR_INVALID_PARAMETER EINVAL
-#define ERROR_INVALID_FUNCTION EINVAL
-#define ERROR_ALREADY_EXISTS EEXIST
-#define ERROR_FILE_EXISTS EEXIST
-#define ERROR_PATH_NOT_FOUND ENOENT
-#define ERROR_FILE_NOT_FOUND ENOENT
-#define ERROR_DISK_FULL ENOSPC
-// #define ERROR_INVALID_HANDLE EBADF
-
-// we use FACILITY_WIN32 for errors that has no errno equivalent
-// Too many posts were made to a semaphore.
-#define ERROR_TOO_MANY_POSTS ((HRESULT)0x8007012AL)
-#define ERROR_INVALID_REPARSE_DATA ((HRESULT)0x80071128L)
-#define ERROR_REPARSE_TAG_INVALID ((HRESULT)0x80071129L)
-
-// if (MY__FACILITY__WRes != FACILITY_WIN32),
-// we use FACILITY_WIN32 for COM errors:
-#define E_OUTOFMEMORY ((HRESULT)0x8007000EL)
-#define E_INVALIDARG ((HRESULT)0x80070057L)
-#define MY__E_ERROR_NEGATIVE_SEEK ((HRESULT)0x80070083L)
-
-/*
-// we can use FACILITY_ERRNO for some COM errors, that have errno equivalents:
-#define E_OUTOFMEMORY MY_HRESULT_FROM_errno_CONST_ERROR(ENOMEM)
-#define E_INVALIDARG MY_HRESULT_FROM_errno_CONST_ERROR(EINVAL)
-#define MY__E_ERROR_NEGATIVE_SEEK MY_HRESULT_FROM_errno_CONST_ERROR(EINVAL)
-*/
-
-#define TEXT(quote) quote
-
-#define FILE_ATTRIBUTE_READONLY 0x0001
-#define FILE_ATTRIBUTE_HIDDEN 0x0002
-#define FILE_ATTRIBUTE_SYSTEM 0x0004
-#define FILE_ATTRIBUTE_DIRECTORY 0x0010
-#define FILE_ATTRIBUTE_ARCHIVE 0x0020
-#define FILE_ATTRIBUTE_DEVICE 0x0040
-#define FILE_ATTRIBUTE_NORMAL 0x0080
-#define FILE_ATTRIBUTE_TEMPORARY 0x0100
-#define FILE_ATTRIBUTE_SPARSE_FILE 0x0200
-#define FILE_ATTRIBUTE_REPARSE_POINT 0x0400
-#define FILE_ATTRIBUTE_COMPRESSED 0x0800
-#define FILE_ATTRIBUTE_OFFLINE 0x1000
-#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x2000
-#define FILE_ATTRIBUTE_ENCRYPTED 0x4000
-
-#define FILE_ATTRIBUTE_UNIX_EXTENSION 0x8000 /* trick for Unix */
-
-#endif
-
-
-#ifndef RINOK
-#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }
-#endif
-
-#ifndef RINOK_WRes
-#define RINOK_WRes(x) { WRes __result__ = (x); if (__result__ != 0) return __result__; }
-#endif
-
-typedef unsigned char Byte;
-typedef short Int16;
-typedef unsigned short UInt16;
-
-#ifdef _LZMA_UINT32_IS_ULONG
-typedef long Int32;
-typedef unsigned long UInt32;
-#else
-typedef int Int32;
-typedef unsigned int UInt32;
-#endif
-
-
-#ifndef _WIN32
-
-typedef int INT;
-typedef Int32 INT32;
-typedef unsigned int UINT;
-typedef UInt32 UINT32;
-typedef INT32 LONG; // LONG, ULONG and DWORD must be 32-bit for _WIN32 compatibility
-typedef UINT32 ULONG;
-
-#undef DWORD
-typedef UINT32 DWORD;
-
-#define VOID void
-
-#define HRESULT LONG
-
-typedef void *LPVOID;
-// typedef void VOID;
-// typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR;
-// gcc / clang on Unix : sizeof(long==sizeof(void*) in 32 or 64 bits)
-typedef long INT_PTR;
-typedef unsigned long UINT_PTR;
-typedef long LONG_PTR;
-typedef unsigned long DWORD_PTR;
-
-typedef size_t SIZE_T;
-
-#endif // _WIN32
-
-
-#define MY_HRES_ERROR__INTERNAL_ERROR ((HRESULT)0x8007054FL)
-
-
-#ifdef _SZ_NO_INT_64
-
-/* 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 unsigned long UInt64;
-
-#else
-
-#if defined(_MSC_VER) || defined(__BORLANDC__)
-typedef __int64 Int64;
-typedef unsigned __int64 UInt64;
-#define UINT64_CONST(n) n
-#else
-typedef long long int Int64;
-typedef unsigned long long int UInt64;
-#define UINT64_CONST(n) n ## ULL
-#endif
-
-#endif
-
-#ifdef _LZMA_NO_SYSTEM_SIZE_T
-typedef UInt32 SizeT;
-#else
-typedef size_t SizeT;
-#endif
-
-typedef int BoolInt;
-/* typedef BoolInt Bool; */
-#define True 1
-#define False 0
-
-
-#ifdef _WIN32
-#define MY_STD_CALL __stdcall
-#else
-#define MY_STD_CALL
-#endif
-
-#ifdef _MSC_VER
-
-#if _MSC_VER >= 1300
-#define MY_NO_INLINE __declspec(noinline)
-#else
-#define MY_NO_INLINE
-#endif
-
-#define MY_FORCE_INLINE __forceinline
-
-#define MY_CDECL __cdecl
-#define MY_FAST_CALL __fastcall
-
-#else // _MSC_VER
-
-#if (defined(__GNUC__) && (__GNUC__ >= 4)) \
- || (defined(__clang__) && (__clang_major__ >= 4)) \
- || defined(__INTEL_COMPILER) \
- || defined(__xlC__)
-#define MY_NO_INLINE __attribute__((noinline))
-// #define MY_FORCE_INLINE __attribute__((always_inline)) inline
-#else
-#define MY_NO_INLINE
-#endif
-
-#define MY_FORCE_INLINE
-
-
-#define MY_CDECL
-
-#if defined(_M_IX86) \
- || defined(__i386__)
-// #define MY_FAST_CALL __attribute__((fastcall))
-// #define MY_FAST_CALL __attribute__((cdecl))
-#define MY_FAST_CALL
-#elif defined(MY_CPU_AMD64)
-// #define MY_FAST_CALL __attribute__((ms_abi))
-#define MY_FAST_CALL
-#else
-#define MY_FAST_CALL
-#endif
-
-#endif // _MSC_VER
-
-
-/* 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 */
-};
-#define IByteIn_Read(p) (p)->Read(p)
-
-
-typedef struct IByteOut IByteOut;
-struct IByteOut
-{
- void (*Write)(const IByteOut *p, Byte 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 */
-};
-#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 */
-};
-#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);
-};
-#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);
-};
-
-#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_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 */
-
- /* the following variables must be set outside */
- Byte *buf;
- size_t bufSize;
-} CLookToRead2;
-
-void LookToRead2_CreateVTable(CLookToRead2 *p, int lookahead);
-
-#define LookToRead2_Init(p) { (p)->pos = (p)->size = 0; }
-
-
-typedef struct
-{
- ISeqInStream vt;
- const ILookInStream *realStream;
-} CSecToLook;
-
-void SecToLook_CreateVTable(CSecToLook *p);
-
-
-
-typedef struct
-{
- ISeqInStream vt;
- const ILookInStream *realStream;
-} CSecToRead;
-
-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)
-
-
-
-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 */
-};
-
-#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)
-
-
-
-
-
-#ifndef MY_offsetof
- #ifdef offsetof
- #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))
- #endif
-#endif
-
-
-
-#ifndef MY_container_of
-
-/*
-#define MY_container_of(ptr, type, m) container_of(ptr, type, m)
-#define MY_container_of(ptr, type, m) CONTAINING_RECORD(ptr, type, m)
-#define MY_container_of(ptr, type, m) ((type *)((char *)(ptr) - offsetof(type, m)))
-#define MY_container_of(ptr, type, m) (&((type *)0)->m == (ptr), ((type *)(((char *)(ptr)) - MY_offsetof(type, m))))
-*/
-
-/*
- GCC shows warning: "perhaps the 'offsetof' macro was used incorrectly"
- GCC 3.4.4 : classes with constructor
- GCC 4.8.1 : classes with non-public variable members"
-*/
-
-#define MY_container_of(ptr, type, m) ((type *)(void *)((char *)(void *)(1 ? (ptr) : &((type *)0)->m) - MY_offsetof(type, m)))
-
-#endif
-
-#define CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m) ((type *)(void *)(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_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)
-*/
-
-
-#define MY_memset_0_ARRAY(a) memset((a), 0, sizeof(a))
-
-#ifdef _WIN32
-
-#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"/"
-
-#endif
-
-#define k_PropVar_TimePrec_0 0
-#define k_PropVar_TimePrec_Unix 1
-#define k_PropVar_TimePrec_DOS 2
-#define k_PropVar_TimePrec_HighPrec 3
-#define k_PropVar_TimePrec_Base 16
-#define k_PropVar_TimePrec_100ns (k_PropVar_TimePrec_Base + 7)
-#define k_PropVar_TimePrec_1ns (k_PropVar_TimePrec_Base + 9)
-
-EXTERN_C_END
-
-#endif
+/* 7zTypes.h -- Basic types
+2024-01-24 : Igor Pavlov : Public domain */
+
+#ifndef ZIP7_7Z_TYPES_H
+#define ZIP7_7Z_TYPES_H
+
+#ifdef _WIN32
+/* #include */
+#else
+#include
+#endif
+
+#include
+
+#ifndef EXTERN_C_BEGIN
+#ifdef __cplusplus
+#define EXTERN_C_BEGIN extern "C" {
+#define EXTERN_C_END }
+#else
+#define EXTERN_C_BEGIN
+#define EXTERN_C_END
+#endif
+#endif
+
+EXTERN_C_BEGIN
+
+#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_ARCHIVE 16
+#define SZ_ERROR_NO_ARCHIVE 17
+
+typedef int SRes;
+
+
+#ifdef _MSC_VER
+ #if _MSC_VER > 1200
+ #define MY_ALIGN(n) __declspec(align(n))
+ #else
+ #define MY_ALIGN(n)
+ #endif
+#else
+ /*
+ // C11/C++11:
+ #include
+ #define MY_ALIGN(n) alignas(n)
+ */
+ #define MY_ALIGN(n) __attribute__ ((aligned(n)))
+#endif
+
+
+#ifdef _WIN32
+
+/* typedef DWORD WRes; */
+typedef unsigned WRes;
+#define MY_SRes_HRESULT_FROM_WRes(x) HRESULT_FROM_WIN32(x)
+
+// #define MY_HRES_ERROR_INTERNAL_ERROR MY_SRes_HRESULT_FROM_WRes(ERROR_INTERNAL_ERROR)
+
+#else // _WIN32
+
+// #define ENV_HAVE_LSTAT
+typedef int WRes;
+
+// (FACILITY_ERRNO = 0x800) is 7zip's FACILITY constant to represent (errno) errors in HRESULT
+#define MY_FACILITY_ERRNO 0x800
+#define MY_FACILITY_WIN32 7
+#define MY_FACILITY_WRes MY_FACILITY_ERRNO
+
+#define MY_HRESULT_FROM_errno_CONST_ERROR(x) ((HRESULT)( \
+ ( (HRESULT)(x) & 0x0000FFFF) \
+ | (MY_FACILITY_WRes << 16) \
+ | (HRESULT)0x80000000 ))
+
+#define MY_SRes_HRESULT_FROM_WRes(x) \
+ ((HRESULT)(x) <= 0 ? ((HRESULT)(x)) : MY_HRESULT_FROM_errno_CONST_ERROR(x))
+
+// we call macro HRESULT_FROM_WIN32 for system errors (WRes) that are (errno)
+#define HRESULT_FROM_WIN32(x) MY_SRes_HRESULT_FROM_WRes(x)
+
+/*
+#define ERROR_FILE_NOT_FOUND 2L
+#define ERROR_ACCESS_DENIED 5L
+#define ERROR_NO_MORE_FILES 18L
+#define ERROR_LOCK_VIOLATION 33L
+#define ERROR_FILE_EXISTS 80L
+#define ERROR_DISK_FULL 112L
+#define ERROR_NEGATIVE_SEEK 131L
+#define ERROR_ALREADY_EXISTS 183L
+#define ERROR_DIRECTORY 267L
+#define ERROR_TOO_MANY_POSTS 298L
+
+#define ERROR_INTERNAL_ERROR 1359L
+#define ERROR_INVALID_REPARSE_DATA 4392L
+#define ERROR_REPARSE_TAG_INVALID 4393L
+#define ERROR_REPARSE_TAG_MISMATCH 4394L
+*/
+
+// we use errno equivalents for some WIN32 errors:
+
+#define ERROR_INVALID_PARAMETER EINVAL
+#define ERROR_INVALID_FUNCTION EINVAL
+#define ERROR_ALREADY_EXISTS EEXIST
+#define ERROR_FILE_EXISTS EEXIST
+#define ERROR_PATH_NOT_FOUND ENOENT
+#define ERROR_FILE_NOT_FOUND ENOENT
+#define ERROR_DISK_FULL ENOSPC
+// #define ERROR_INVALID_HANDLE EBADF
+
+// we use FACILITY_WIN32 for errors that has no errno equivalent
+// Too many posts were made to a semaphore.
+#define ERROR_TOO_MANY_POSTS ((HRESULT)0x8007012AL)
+#define ERROR_INVALID_REPARSE_DATA ((HRESULT)0x80071128L)
+#define ERROR_REPARSE_TAG_INVALID ((HRESULT)0x80071129L)
+
+// if (MY_FACILITY_WRes != FACILITY_WIN32),
+// we use FACILITY_WIN32 for COM errors:
+#define E_OUTOFMEMORY ((HRESULT)0x8007000EL)
+#define E_INVALIDARG ((HRESULT)0x80070057L)
+#define MY_E_ERROR_NEGATIVE_SEEK ((HRESULT)0x80070083L)
+
+/*
+// we can use FACILITY_ERRNO for some COM errors, that have errno equivalents:
+#define E_OUTOFMEMORY MY_HRESULT_FROM_errno_CONST_ERROR(ENOMEM)
+#define E_INVALIDARG MY_HRESULT_FROM_errno_CONST_ERROR(EINVAL)
+#define MY_E_ERROR_NEGATIVE_SEEK MY_HRESULT_FROM_errno_CONST_ERROR(EINVAL)
+*/
+
+#define TEXT(quote) quote
+
+#define FILE_ATTRIBUTE_READONLY 0x0001
+#define FILE_ATTRIBUTE_HIDDEN 0x0002
+#define FILE_ATTRIBUTE_SYSTEM 0x0004
+#define FILE_ATTRIBUTE_DIRECTORY 0x0010
+#define FILE_ATTRIBUTE_ARCHIVE 0x0020
+#define FILE_ATTRIBUTE_DEVICE 0x0040
+#define FILE_ATTRIBUTE_NORMAL 0x0080
+#define FILE_ATTRIBUTE_TEMPORARY 0x0100
+#define FILE_ATTRIBUTE_SPARSE_FILE 0x0200
+#define FILE_ATTRIBUTE_REPARSE_POINT 0x0400
+#define FILE_ATTRIBUTE_COMPRESSED 0x0800
+#define FILE_ATTRIBUTE_OFFLINE 0x1000
+#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x2000
+#define FILE_ATTRIBUTE_ENCRYPTED 0x4000
+
+#define FILE_ATTRIBUTE_UNIX_EXTENSION 0x8000 /* trick for Unix */
+
+#endif
+
+
+#ifndef RINOK
+#define RINOK(x) { const int _result_ = (x); if (_result_ != 0) return _result_; }
+#endif
+
+#ifndef RINOK_WRes
+#define RINOK_WRes(x) { const WRes _result_ = (x); if (_result_ != 0) return _result_; }
+#endif
+
+typedef unsigned char Byte;
+typedef short Int16;
+typedef unsigned short UInt16;
+
+#ifdef Z7_DECL_Int32_AS_long
+typedef long Int32;
+typedef unsigned long UInt32;
+#else
+typedef int Int32;
+typedef unsigned int UInt32;
+#endif
+
+
+#ifndef _WIN32
+
+typedef int INT;
+typedef Int32 INT32;
+typedef unsigned int UINT;
+typedef UInt32 UINT32;
+typedef INT32 LONG; // LONG, ULONG and DWORD must be 32-bit for _WIN32 compatibility
+typedef UINT32 ULONG;
+
+#undef DWORD
+typedef UINT32 DWORD;
+
+#define VOID void
+
+#define HRESULT LONG
+
+typedef void *LPVOID;
+// typedef void VOID;
+// typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR;
+// gcc / clang on Unix : sizeof(long==sizeof(void*) in 32 or 64 bits)
+typedef long INT_PTR;
+typedef unsigned long UINT_PTR;
+typedef long LONG_PTR;
+typedef unsigned long DWORD_PTR;
+
+typedef size_t SIZE_T;
+
+#endif // _WIN32
+
+
+#define MY_HRES_ERROR_INTERNAL_ERROR ((HRESULT)0x8007054FL)
+
+
+#ifdef Z7_DECL_Int64_AS_long
+
+typedef long Int64;
+typedef unsigned long UInt64;
+
+#else
+
+#if (defined(_MSC_VER) || defined(__BORLANDC__)) && !defined(__clang__)
+typedef __int64 Int64;
+typedef unsigned __int64 UInt64;
+#else
+#if defined(__clang__) || defined(__GNUC__)
+#include
+typedef int64_t Int64;
+typedef uint64_t UInt64;
+#else
+typedef long long int Int64;
+typedef unsigned long long int UInt64;
+// #define UINT64_CONST(n) n ## ULL
+#endif
+#endif
+
+#endif
+
+#define UINT64_CONST(n) n
+
+
+#ifdef Z7_DECL_SizeT_AS_unsigned_int
+typedef unsigned int SizeT;
+#else
+typedef size_t SizeT;
+#endif
+
+/*
+#if (defined(_MSC_VER) && _MSC_VER <= 1200)
+typedef size_t MY_uintptr_t;
+#else
+#include
+typedef uintptr_t MY_uintptr_t;
+#endif
+*/
+
+typedef int BoolInt;
+/* typedef BoolInt Bool; */
+#define True 1
+#define False 0
+
+
+#ifdef _WIN32
+#define Z7_STDCALL __stdcall
+#else
+#define Z7_STDCALL
+#endif
+
+#ifdef _MSC_VER
+
+#if _MSC_VER >= 1300
+#define Z7_NO_INLINE __declspec(noinline)
+#else
+#define Z7_NO_INLINE
+#endif
+
+#define Z7_FORCE_INLINE __forceinline
+
+#define Z7_CDECL __cdecl
+#define Z7_FASTCALL __fastcall
+
+#else // _MSC_VER
+
+#if (defined(__GNUC__) && (__GNUC__ >= 4)) \
+ || (defined(__clang__) && (__clang_major__ >= 4)) \
+ || defined(__INTEL_COMPILER) \
+ || defined(__xlC__)
+#define Z7_NO_INLINE __attribute__((noinline))
+#define Z7_FORCE_INLINE __attribute__((always_inline)) inline
+#else
+#define Z7_NO_INLINE
+#define Z7_FORCE_INLINE
+#endif
+
+#define Z7_CDECL
+
+#if defined(_M_IX86) \
+ || defined(__i386__)
+// #define Z7_FASTCALL __attribute__((fastcall))
+// #define Z7_FASTCALL __attribute__((cdecl))
+#define Z7_FASTCALL
+#elif defined(MY_CPU_AMD64)
+// #define Z7_FASTCALL __attribute__((ms_abi))
+#define Z7_FASTCALL
+#else
+#define Z7_FASTCALL
+#endif
+
+#endif // _MSC_VER
+
+
+/* The following interfaces use first parameter as pointer to structure */
+
+// #define Z7_C_IFACE_CONST_QUAL
+#define Z7_C_IFACE_CONST_QUAL const
+
+#define Z7_C_IFACE_DECL(a) \
+ struct a ## _; \
+ typedef Z7_C_IFACE_CONST_QUAL struct a ## _ * a ## Ptr; \
+ typedef struct a ## _ a; \
+ struct a ## _
+
+
+Z7_C_IFACE_DECL (IByteIn)
+{
+ Byte (*Read)(IByteInPtr p); /* reads one byte, returns 0 in case of EOF or error */
+};
+#define IByteIn_Read(p) (p)->Read(p)
+
+
+Z7_C_IFACE_DECL (IByteOut)
+{
+ void (*Write)(IByteOutPtr p, Byte b);
+};
+#define IByteOut_Write(p, b) (p)->Write(p, b)
+
+
+Z7_C_IFACE_DECL (ISeqInStream)
+{
+ SRes (*Read)(ISeqInStreamPtr 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)
+
+/* try to read as much as avail in stream and limited by (*processedSize) */
+SRes SeqInStream_ReadMax(ISeqInStreamPtr stream, void *buf, size_t *processedSize);
+/* it can return SZ_ERROR_INPUT_EOF */
+// SRes SeqInStream_Read(ISeqInStreamPtr stream, void *buf, size_t size);
+// SRes SeqInStream_Read2(ISeqInStreamPtr stream, void *buf, size_t size, SRes errorType);
+SRes SeqInStream_ReadByte(ISeqInStreamPtr stream, Byte *buf);
+
+
+Z7_C_IFACE_DECL (ISeqOutStream)
+{
+ size_t (*Write)(ISeqOutStreamPtr 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
+{
+ SZ_SEEK_SET = 0,
+ SZ_SEEK_CUR = 1,
+ SZ_SEEK_END = 2
+} ESzSeek;
+
+
+Z7_C_IFACE_DECL (ISeekInStream)
+{
+ SRes (*Read)(ISeekInStreamPtr p, void *buf, size_t *size); /* same as ISeqInStream::Read */
+ SRes (*Seek)(ISeekInStreamPtr 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)
+
+
+Z7_C_IFACE_DECL (ILookInStream)
+{
+ SRes (*Look)(ILookInStreamPtr 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)(ILookInStreamPtr p, size_t offset);
+ /* offset must be <= output(*size) of Look */
+ SRes (*Read)(ILookInStreamPtr p, void *buf, size_t *size);
+ /* reads directly (without buffer). It's same as ISeqInStream::Read */
+ SRes (*Seek)(ILookInStreamPtr 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)
+
+
+SRes LookInStream_LookRead(ILookInStreamPtr stream, void *buf, size_t *size);
+SRes LookInStream_SeekTo(ILookInStreamPtr stream, UInt64 offset);
+
+/* reads via ILookInStream::Read */
+SRes LookInStream_Read2(ILookInStreamPtr stream, void *buf, size_t size, SRes errorType);
+SRes LookInStream_Read(ILookInStreamPtr stream, void *buf, size_t size);
+
+
+typedef struct
+{
+ ILookInStream vt;
+ ISeekInStreamPtr realStream;
+
+ size_t pos;
+ size_t size; /* it's data size */
+
+ /* the following variables must be set outside */
+ Byte *buf;
+ size_t bufSize;
+} CLookToRead2;
+
+void LookToRead2_CreateVTable(CLookToRead2 *p, int lookahead);
+
+#define LookToRead2_INIT(p) { (p)->pos = (p)->size = 0; }
+
+
+typedef struct
+{
+ ISeqInStream vt;
+ ILookInStreamPtr realStream;
+} CSecToLook;
+
+void SecToLook_CreateVTable(CSecToLook *p);
+
+
+
+typedef struct
+{
+ ISeqInStream vt;
+ ILookInStreamPtr realStream;
+} CSecToRead;
+
+void SecToRead_CreateVTable(CSecToRead *p);
+
+
+Z7_C_IFACE_DECL (ICompressProgress)
+{
+ SRes (*Progress)(ICompressProgressPtr 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 */
+};
+
+#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)
+
+
+
+
+
+#ifndef MY_offsetof
+ #ifdef offsetof
+ #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))
+ #endif
+#endif
+
+
+
+#ifndef Z7_container_of
+
+/*
+#define Z7_container_of(ptr, type, m) container_of(ptr, type, m)
+#define Z7_container_of(ptr, type, m) CONTAINING_RECORD(ptr, type, m)
+#define Z7_container_of(ptr, type, m) ((type *)((char *)(ptr) - offsetof(type, m)))
+#define Z7_container_of(ptr, type, m) (&((type *)0)->m == (ptr), ((type *)(((char *)(ptr)) - MY_offsetof(type, m))))
+*/
+
+/*
+ GCC shows warning: "perhaps the 'offsetof' macro was used incorrectly"
+ GCC 3.4.4 : classes with constructor
+ GCC 4.8.1 : classes with non-public variable members"
+*/
+
+#define Z7_container_of(ptr, type, m) \
+ ((type *)(void *)((char *)(void *) \
+ (1 ? (ptr) : &((type *)NULL)->m) - MY_offsetof(type, m)))
+
+#define Z7_container_of_CONST(ptr, type, m) \
+ ((const type *)(const void *)((const char *)(const void *) \
+ (1 ? (ptr) : &((type *)NULL)->m) - MY_offsetof(type, m)))
+
+/*
+#define Z7_container_of_NON_CONST_FROM_CONST(ptr, type, m) \
+ ((type *)(void *)(const void *)((const char *)(const void *) \
+ (1 ? (ptr) : &((type *)NULL)->m) - MY_offsetof(type, m)))
+*/
+
+#endif
+
+#define Z7_CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m) ((type *)(void *)(ptr))
+
+// #define Z7_CONTAINER_FROM_VTBL(ptr, type, m) Z7_CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m)
+#define Z7_CONTAINER_FROM_VTBL(ptr, type, m) Z7_container_of(ptr, type, m)
+// #define Z7_CONTAINER_FROM_VTBL(ptr, type, m) Z7_container_of_NON_CONST_FROM_CONST(ptr, type, m)
+
+#define Z7_CONTAINER_FROM_VTBL_CONST(ptr, type, m) Z7_container_of_CONST(ptr, type, m)
+
+#define Z7_CONTAINER_FROM_VTBL_CLS(ptr, type, m) Z7_CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m)
+/*
+#define Z7_CONTAINER_FROM_VTBL_CLS(ptr, type, m) Z7_CONTAINER_FROM_VTBL(ptr, type, m)
+*/
+#if defined (__clang__) || defined(__GNUC__)
+#define Z7_DIAGNOSTIC_IGNORE_BEGIN_CAST_QUAL \
+ _Pragma("GCC diagnostic push") \
+ _Pragma("GCC diagnostic ignored \"-Wcast-qual\"")
+#define Z7_DIAGNOSTIC_IGNORE_END_CAST_QUAL \
+ _Pragma("GCC diagnostic pop")
+#else
+#define Z7_DIAGNOSTIC_IGNORE_BEGIN_CAST_QUAL
+#define Z7_DIAGNOSTIC_IGNORE_END_CAST_QUAL
+#endif
+
+#define Z7_CONTAINER_FROM_VTBL_TO_DECL_VAR(ptr, type, m, p) \
+ Z7_DIAGNOSTIC_IGNORE_BEGIN_CAST_QUAL \
+ type *p = Z7_CONTAINER_FROM_VTBL(ptr, type, m); \
+ Z7_DIAGNOSTIC_IGNORE_END_CAST_QUAL
+
+#define Z7_CONTAINER_FROM_VTBL_TO_DECL_VAR_pp_vt_p(type) \
+ Z7_CONTAINER_FROM_VTBL_TO_DECL_VAR(pp, type, vt, p)
+
+
+// #define ZIP7_DECLARE_HANDLE(name) typedef void *name;
+#define Z7_DECLARE_HANDLE(name) struct name##_dummy{int unused;}; typedef struct name##_dummy *name;
+
+
+#define Z7_memset_0_ARRAY(a) memset((a), 0, sizeof(a))
+
+#ifndef Z7_ARRAY_SIZE
+#define Z7_ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
+#endif
+
+
+#ifdef _WIN32
+
+#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"/"
+
+#endif
+
+#define k_PropVar_TimePrec_0 0
+#define k_PropVar_TimePrec_Unix 1
+#define k_PropVar_TimePrec_DOS 2
+#define k_PropVar_TimePrec_HighPrec 3
+#define k_PropVar_TimePrec_Base 16
+#define k_PropVar_TimePrec_100ns (k_PropVar_TimePrec_Base + 7)
+#define k_PropVar_TimePrec_1ns (k_PropVar_TimePrec_Base + 9)
+
+EXTERN_C_END
+
+#endif
+
+/*
+#ifndef Z7_ST
+#ifdef _7ZIP_ST
+#define Z7_ST
+#endif
+#endif
+*/
diff --git a/deps/libchdr/deps/lzma-24.05/include/7zWindows.h b/deps/libchdr/deps/lzma-24.05/include/7zWindows.h
new file mode 100644
index 00000000..42c6db8b
--- /dev/null
+++ b/deps/libchdr/deps/lzma-24.05/include/7zWindows.h
@@ -0,0 +1,101 @@
+/* 7zWindows.h -- StdAfx
+2023-04-02 : Igor Pavlov : Public domain */
+
+#ifndef ZIP7_INC_7Z_WINDOWS_H
+#define ZIP7_INC_7Z_WINDOWS_H
+
+#ifdef _WIN32
+
+#if defined(__clang__)
+# pragma clang diagnostic push
+#endif
+
+#if defined(_MSC_VER)
+
+#pragma warning(push)
+#pragma warning(disable : 4668) // '_WIN32_WINNT' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif'
+
+#if _MSC_VER == 1900
+// for old kit10 versions
+// #pragma warning(disable : 4255) // winuser.h(13979): warning C4255: 'GetThreadDpiAwarenessContext':
+#endif
+// win10 Windows Kit:
+#endif // _MSC_VER
+
+#if defined(_MSC_VER) && _MSC_VER <= 1200 && !defined(_WIN64)
+// for msvc6 without sdk2003
+#define RPC_NO_WINDOWS_H
+#endif
+
+#if defined(__MINGW32__) || defined(__MINGW64__)
+// #if defined(__GNUC__) && !defined(__clang__)
+#include
+#else
+#include
+#endif
+// #include
+// #include
+
+// but if precompiled with clang-cl then we need
+// #include
+#if defined(_MSC_VER)
+#pragma warning(pop)
+#endif
+
+#if defined(__clang__)
+# pragma clang diagnostic pop
+#endif
+
+#if defined(_MSC_VER) && _MSC_VER <= 1200 && !defined(_WIN64)
+#ifndef _W64
+
+typedef long LONG_PTR, *PLONG_PTR;
+typedef unsigned long ULONG_PTR, *PULONG_PTR;
+typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR;
+
+#define Z7_OLD_WIN_SDK
+#endif // _W64
+#endif // _MSC_VER == 1200
+
+#ifdef Z7_OLD_WIN_SDK
+
+#ifndef INVALID_FILE_ATTRIBUTES
+#define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
+#endif
+#ifndef INVALID_SET_FILE_POINTER
+#define INVALID_SET_FILE_POINTER ((DWORD)-1)
+#endif
+#ifndef FILE_SPECIAL_ACCESS
+#define FILE_SPECIAL_ACCESS (FILE_ANY_ACCESS)
+#endif
+
+// ShlObj.h:
+// #define BIF_NEWDIALOGSTYLE 0x0040
+
+#pragma warning(disable : 4201)
+// #pragma warning(disable : 4115)
+
+#undef VARIANT_TRUE
+#define VARIANT_TRUE ((VARIANT_BOOL)-1)
+#endif
+
+#endif // Z7_OLD_WIN_SDK
+
+#ifdef UNDER_CE
+#undef VARIANT_TRUE
+#define VARIANT_TRUE ((VARIANT_BOOL)-1)
+#endif
+
+
+#if defined(_MSC_VER)
+#if _MSC_VER >= 1400 && _MSC_VER <= 1600
+ // BaseTsd.h(148) : 'HandleToULong' : unreferenced inline function has been removed
+ // string.h
+ // #pragma warning(disable : 4514)
+#endif
+#endif
+
+
+/* #include "7zTypes.h" */
+
+#endif
diff --git a/deps/libchdr/deps/lzma-24.05/include/Alloc.h b/deps/libchdr/deps/lzma-24.05/include/Alloc.h
new file mode 100644
index 00000000..01bf6b7d
--- /dev/null
+++ b/deps/libchdr/deps/lzma-24.05/include/Alloc.h
@@ -0,0 +1,76 @@
+/* Alloc.h -- Memory allocation functions
+2024-01-22 : Igor Pavlov : Public domain */
+
+#ifndef ZIP7_INC_ALLOC_H
+#define ZIP7_INC_ALLOC_H
+
+#include "7zTypes.h"
+
+EXTERN_C_BEGIN
+
+/*
+ MyFree(NULL) : is allowed, as free(NULL)
+ MyAlloc(0) : returns NULL : but malloc(0) is allowed to return NULL or non_NULL
+ MyRealloc(NULL, 0) : returns NULL : but realloc(NULL, 0) is allowed to return NULL or non_NULL
+MyRealloc() is similar to realloc() for the following cases:
+ MyRealloc(non_NULL, 0) : returns NULL and always calls MyFree(ptr)
+ MyRealloc(NULL, non_ZERO) : returns NULL, if allocation failed
+ MyRealloc(non_NULL, non_ZERO) : returns NULL, if reallocation failed
+*/
+
+void *MyAlloc(size_t size);
+void MyFree(void *address);
+void *MyRealloc(void *address, size_t size);
+
+void *z7_AlignedAlloc(size_t size);
+void z7_AlignedFree(void *p);
+
+#ifdef _WIN32
+
+#ifdef Z7_LARGE_PAGES
+void SetLargePageSize(void);
+#endif
+
+void *MidAlloc(size_t size);
+void MidFree(void *address);
+void *BigAlloc(size_t size);
+void BigFree(void *address);
+
+/* #define Z7_BIG_ALLOC_IS_ZERO_FILLED */
+
+#else
+
+#define MidAlloc(size) z7_AlignedAlloc(size)
+#define MidFree(address) z7_AlignedFree(address)
+#define BigAlloc(size) z7_AlignedAlloc(size)
+#define BigFree(address) z7_AlignedFree(address)
+
+#endif
+
+extern const ISzAlloc g_Alloc;
+
+#ifdef _WIN32
+extern const ISzAlloc g_BigAlloc;
+extern const ISzAlloc g_MidAlloc;
+#else
+#define g_BigAlloc g_AlignedAlloc
+#define g_MidAlloc g_AlignedAlloc
+#endif
+
+extern const ISzAlloc g_AlignedAlloc;
+
+
+typedef struct
+{
+ ISzAlloc vt;
+ ISzAllocPtr baseAlloc;
+ unsigned numAlignBits; /* ((1 << numAlignBits) >= sizeof(void *)) */
+ size_t offset; /* (offset == (k * sizeof(void *)) && offset < (1 << numAlignBits) */
+} CAlignOffsetAlloc;
+
+void AlignOffsetAlloc_CreateVTable(CAlignOffsetAlloc *p);
+
+
+EXTERN_C_END
+
+#endif
diff --git a/deps/libchdr/deps/lzma-24.05/include/Bra.h b/deps/libchdr/deps/lzma-24.05/include/Bra.h
new file mode 100644
index 00000000..b47112ce
--- /dev/null
+++ b/deps/libchdr/deps/lzma-24.05/include/Bra.h
@@ -0,0 +1,105 @@
+/* Bra.h -- Branch converters for executables
+2024-01-20 : Igor Pavlov : Public domain */
+
+#ifndef ZIP7_INC_BRA_H
+#define ZIP7_INC_BRA_H
+
+#include "7zTypes.h"
+
+EXTERN_C_BEGIN
+
+/* #define PPC BAD_PPC_11 // for debug */
+
+#define Z7_BRANCH_CONV_DEC_2(name) z7_ ## name ## _Dec
+#define Z7_BRANCH_CONV_ENC_2(name) z7_ ## name ## _Enc
+#define Z7_BRANCH_CONV_DEC(name) Z7_BRANCH_CONV_DEC_2(BranchConv_ ## name)
+#define Z7_BRANCH_CONV_ENC(name) Z7_BRANCH_CONV_ENC_2(BranchConv_ ## name)
+#define Z7_BRANCH_CONV_ST_DEC(name) z7_BranchConvSt_ ## name ## _Dec
+#define Z7_BRANCH_CONV_ST_ENC(name) z7_BranchConvSt_ ## name ## _Enc
+
+#define Z7_BRANCH_CONV_DECL(name) Byte * name(Byte *data, SizeT size, UInt32 pc)
+#define Z7_BRANCH_CONV_ST_DECL(name) Byte * name(Byte *data, SizeT size, UInt32 pc, UInt32 *state)
+
+typedef Z7_BRANCH_CONV_DECL( (*z7_Func_BranchConv));
+typedef Z7_BRANCH_CONV_ST_DECL((*z7_Func_BranchConvSt));
+
+#define Z7_BRANCH_CONV_ST_X86_STATE_INIT_VAL 0
+Z7_BRANCH_CONV_ST_DECL (Z7_BRANCH_CONV_ST_DEC(X86));
+Z7_BRANCH_CONV_ST_DECL (Z7_BRANCH_CONV_ST_ENC(X86));
+
+#define Z7_BRANCH_FUNCS_DECL(name) \
+Z7_BRANCH_CONV_DECL (Z7_BRANCH_CONV_DEC_2(name)); \
+Z7_BRANCH_CONV_DECL (Z7_BRANCH_CONV_ENC_2(name));
+
+Z7_BRANCH_FUNCS_DECL (BranchConv_ARM64)
+Z7_BRANCH_FUNCS_DECL (BranchConv_ARM)
+Z7_BRANCH_FUNCS_DECL (BranchConv_ARMT)
+Z7_BRANCH_FUNCS_DECL (BranchConv_PPC)
+Z7_BRANCH_FUNCS_DECL (BranchConv_SPARC)
+Z7_BRANCH_FUNCS_DECL (BranchConv_IA64)
+Z7_BRANCH_FUNCS_DECL (BranchConv_RISCV)
+
+/*
+These functions convert data that contain CPU instructions.
+Each such function converts relative addresses to absolute addresses in some
+branch instructions: CALL (in all converters) and JUMP (X86 converter only).
+Such conversion allows to increase compression ratio, if we compress that data.
+
+There are 2 types of converters:
+ Byte * Conv_RISC (Byte *data, SizeT size, UInt32 pc);
+ Byte * ConvSt_X86(Byte *data, SizeT size, UInt32 pc, UInt32 *state);
+Each Converter supports 2 versions: one for encoding
+and one for decoding (_Enc/_Dec postfixes in function name).
+
+In params:
+ data : data buffer
+ size : size of data
+ pc : current virtual Program Counter (Instruction Pointer) value
+In/Out param:
+ state : pointer to state variable (for X86 converter only)
+
+Return:
+ The pointer to position in (data) buffer after last byte that was processed.
+ If the caller calls converter again, it must call it starting with that position.
+ But the caller is allowed to move data in buffer. So pointer to
+ current processed position also will be changed for next call.
+ Also the caller must increase internal (pc) value for next call.
+
+Each converter has some characteristics: Endian, Alignment, LookAhead.
+ Type Endian Alignment LookAhead
+
+ X86 little 1 4
+ ARMT little 2 2
+ RISCV little 2 6
+ ARM little 4 0
+ ARM64 little 4 0
+ PPC big 4 0
+ SPARC big 4 0
+ IA64 little 16 0
+
+ (data) must be aligned for (Alignment).
+ processed size can be calculated as:
+ SizeT processed = Conv(data, size, pc) - data;
+ if (processed == 0)
+ it means that converter needs more data for processing.
+ If (size < Alignment + LookAhead)
+ then (processed == 0) is allowed.
+
+Example code for conversion in loop:
+ UInt32 pc = 0;
+ size = 0;
+ for (;;)
+ {
+ size += Load_more_input_data(data + size);
+ SizeT processed = Conv(data, size, pc) - data;
+ if (processed == 0 && no_more_input_data_after_size)
+ break; // we stop convert loop
+ data += processed;
+ size -= processed;
+ pc += processed;
+ }
+*/
+
+EXTERN_C_END
+
+#endif
diff --git a/deps/libchdr/deps/lzma-24.05/include/Compiler.h b/deps/libchdr/deps/lzma-24.05/include/Compiler.h
new file mode 100644
index 00000000..2a9c2b7a
--- /dev/null
+++ b/deps/libchdr/deps/lzma-24.05/include/Compiler.h
@@ -0,0 +1,236 @@
+/* Compiler.h : Compiler specific defines and pragmas
+2024-01-22 : Igor Pavlov : Public domain */
+
+#ifndef ZIP7_INC_COMPILER_H
+#define ZIP7_INC_COMPILER_H
+
+#if defined(__clang__)
+# define Z7_CLANG_VERSION (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__)
+#endif
+#if defined(__clang__) && defined(__apple_build_version__)
+# define Z7_APPLE_CLANG_VERSION Z7_CLANG_VERSION
+#elif defined(__clang__)
+# define Z7_LLVM_CLANG_VERSION Z7_CLANG_VERSION
+#elif defined(__GNUC__)
+# define Z7_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
+#endif
+
+#ifdef _MSC_VER
+#if !defined(__clang__) && !defined(__GNUC__)
+#define Z7_MSC_VER_ORIGINAL _MSC_VER
+#endif
+#endif
+
+#if defined(__MINGW32__) || defined(__MINGW64__)
+#define Z7_MINGW
+#endif
+
+#if defined(__LCC__) && (defined(__MCST__) || defined(__e2k__))
+#define Z7_MCST_LCC
+#define Z7_MCST_LCC_VERSION (__LCC__ * 100 + __LCC_MINOR__)
+#endif
+
+/*
+#if defined(__AVX2__) \
+ || defined(Z7_GCC_VERSION) && (Z7_GCC_VERSION >= 40900) \
+ || defined(Z7_APPLE_CLANG_VERSION) && (Z7_APPLE_CLANG_VERSION >= 40600) \
+ || defined(Z7_LLVM_CLANG_VERSION) && (Z7_LLVM_CLANG_VERSION >= 30100) \
+ || defined(Z7_MSC_VER_ORIGINAL) && (Z7_MSC_VER_ORIGINAL >= 1800) \
+ || defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 1400)
+ #define Z7_COMPILER_AVX2_SUPPORTED
+ #endif
+#endif
+*/
+
+// #pragma GCC diagnostic ignored "-Wunknown-pragmas"
+
+#ifdef __clang__
+// padding size of '' with 4 bytes to alignment boundary
+#pragma GCC diagnostic ignored "-Wpadded"
+
+#if defined(Z7_LLVM_CLANG_VERSION) && (__clang_major__ == 13) \
+ && defined(__FreeBSD__)
+// freebsd:
+#pragma GCC diagnostic ignored "-Wexcess-padding"
+#endif
+
+#if __clang_major__ >= 16
+#pragma GCC diagnostic ignored "-Wunsafe-buffer-usage"
+#endif
+
+#if __clang_major__ == 13
+#if defined(__SIZEOF_POINTER__) && (__SIZEOF_POINTER__ == 16)
+// cheri
+#pragma GCC diagnostic ignored "-Wcapability-to-integer-cast"
+#endif
+#endif
+
+#if __clang_major__ == 13
+ // for
+ #pragma GCC diagnostic ignored "-Wreserved-identifier"
+#endif
+
+#endif // __clang__
+
+#if defined(_WIN32) && defined(__clang__) && __clang_major__ >= 16
+// #pragma GCC diagnostic ignored "-Wcast-function-type-strict"
+#define Z7_DIAGNOSTIC_IGNORE_CAST_FUNCTION \
+ _Pragma("GCC diagnostic ignored \"-Wcast-function-type-strict\"")
+#else
+#define Z7_DIAGNOSTIC_IGNORE_CAST_FUNCTION
+#endif
+
+typedef void (*Z7_void_Function)(void);
+#if defined(__clang__) || defined(__GNUC__)
+#define Z7_CAST_FUNC_C (Z7_void_Function)
+#elif defined(_MSC_VER) && _MSC_VER > 1920
+#define Z7_CAST_FUNC_C (void *)
+// #pragma warning(disable : 4191) // 'type cast': unsafe conversion from 'FARPROC' to 'void (__cdecl *)()'
+#else
+#define Z7_CAST_FUNC_C
+#endif
+/*
+#if (defined(__GNUC__) && (__GNUC__ >= 8)) || defined(__clang__)
+ // #pragma GCC diagnostic ignored "-Wcast-function-type"
+#endif
+*/
+#ifdef __GNUC__
+#if defined(Z7_GCC_VERSION) && (Z7_GCC_VERSION >= 40000) && (Z7_GCC_VERSION < 70000)
+#pragma GCC diagnostic ignored "-Wstrict-aliasing"
+#endif
+#endif
+
+
+#ifdef _MSC_VER
+
+ #ifdef UNDER_CE
+ #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
+
+#if defined(_MSC_VER) && _MSC_VER >= 1800
+#pragma warning(disable : 4464) // relative include path contains '..'
+#endif
+
+// == 1200 : -O1 : for __forceinline
+// >= 1900 : -O1 : for printf
+#pragma warning(disable : 4710) // function not inlined
+
+#if _MSC_VER < 1900
+// winnt.h: 'Int64ShllMod32'
+#pragma warning(disable : 4514) // unreferenced inline function has been removed
+#endif
+
+#if _MSC_VER < 1300
+// #pragma warning(disable : 4702) // unreachable code
+// Bra.c : -O1:
+#pragma warning(disable : 4714) // function marked as __forceinline not inlined
+#endif
+
+/*
+#if _MSC_VER > 1400 && _MSC_VER <= 1900
+// strcat: This function or variable may be unsafe
+// sysinfoapi.h: kit10: GetVersion was declared deprecated
+#pragma warning(disable : 4996)
+#endif
+*/
+
+#if _MSC_VER > 1200
+// -Wall warnings
+
+#pragma warning(disable : 4711) // function selected for automatic inline expansion
+#pragma warning(disable : 4820) // '2' bytes padding added after data member
+
+#if _MSC_VER >= 1400 && _MSC_VER < 1920
+// 1400: string.h: _DBG_MEMCPY_INLINE_
+// 1600 - 191x : smmintrin.h __cplusplus'
+// is not defined as a preprocessor macro, replacing with '0' for '#if/#elif'
+#pragma warning(disable : 4668)
+
+// 1400 - 1600 : WinDef.h : 'FARPROC' :
+// 1900 - 191x : immintrin.h: _readfsbase_u32
+// no function prototype given : converting '()' to '(void)'
+#pragma warning(disable : 4255)
+#endif
+
+#if _MSC_VER >= 1914
+// Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified
+#pragma warning(disable : 5045)
+#endif
+
+#endif // _MSC_VER > 1200
+#endif // _MSC_VER
+
+
+#if defined(__clang__) && (__clang_major__ >= 4)
+ #define Z7_PRAGMA_OPT_DISABLE_LOOP_UNROLL_VECTORIZE \
+ _Pragma("clang loop unroll(disable)") \
+ _Pragma("clang loop vectorize(disable)")
+ #define Z7_ATTRIB_NO_VECTORIZE
+#elif defined(__GNUC__) && (__GNUC__ >= 5) \
+ && (!defined(Z7_MCST_LCC_VERSION) || (Z7_MCST_LCC_VERSION >= 12610))
+ #define Z7_ATTRIB_NO_VECTORIZE __attribute__((optimize("no-tree-vectorize")))
+ // __attribute__((optimize("no-unroll-loops")));
+ #define Z7_PRAGMA_OPT_DISABLE_LOOP_UNROLL_VECTORIZE
+#elif defined(_MSC_VER) && (_MSC_VER >= 1920)
+ #define Z7_PRAGMA_OPT_DISABLE_LOOP_UNROLL_VECTORIZE \
+ _Pragma("loop( no_vector )")
+ #define Z7_ATTRIB_NO_VECTORIZE
+#else
+ #define Z7_PRAGMA_OPT_DISABLE_LOOP_UNROLL_VECTORIZE
+ #define Z7_ATTRIB_NO_VECTORIZE
+#endif
+
+#if defined(MY_CPU_X86_OR_AMD64) && ( \
+ defined(__clang__) && (__clang_major__ >= 4) \
+ || defined(__GNUC__) && (__GNUC__ >= 5))
+ #define Z7_ATTRIB_NO_SSE __attribute__((__target__("no-sse")))
+#else
+ #define Z7_ATTRIB_NO_SSE
+#endif
+
+#define Z7_ATTRIB_NO_VECTOR \
+ Z7_ATTRIB_NO_VECTORIZE \
+ Z7_ATTRIB_NO_SSE
+
+
+#if defined(__clang__) && (__clang_major__ >= 8) \
+ || defined(__GNUC__) && (__GNUC__ >= 1000) \
+ /* || defined(_MSC_VER) && (_MSC_VER >= 1920) */
+ // GCC is not good for __builtin_expect()
+ #define Z7_LIKELY(x) (__builtin_expect((x), 1))
+ #define Z7_UNLIKELY(x) (__builtin_expect((x), 0))
+ // #define Z7_unlikely [[unlikely]]
+ // #define Z7_likely [[likely]]
+#else
+ #define Z7_LIKELY(x) (x)
+ #define Z7_UNLIKELY(x) (x)
+ // #define Z7_likely
+#endif
+
+
+#if (defined(Z7_CLANG_VERSION) && (Z7_CLANG_VERSION >= 30600))
+
+#if (Z7_CLANG_VERSION < 130000)
+#define Z7_DIAGNOSTIC_IGNORE_BEGIN_RESERVED_MACRO_IDENTIFIER \
+ _Pragma("GCC diagnostic push") \
+ _Pragma("GCC diagnostic ignored \"-Wreserved-id-macro\"")
+#else
+#define Z7_DIAGNOSTIC_IGNORE_BEGIN_RESERVED_MACRO_IDENTIFIER \
+ _Pragma("GCC diagnostic push") \
+ _Pragma("GCC diagnostic ignored \"-Wreserved-macro-identifier\"")
+#endif
+
+#define Z7_DIAGNOSTIC_IGNORE_END_RESERVED_MACRO_IDENTIFIER \
+ _Pragma("GCC diagnostic pop")
+#else
+#define Z7_DIAGNOSTIC_IGNORE_BEGIN_RESERVED_MACRO_IDENTIFIER
+#define Z7_DIAGNOSTIC_IGNORE_END_RESERVED_MACRO_IDENTIFIER
+#endif
+
+#define UNUSED_VAR(x) (void)x;
+/* #define UNUSED_VAR(x) x=x; */
+
+#endif
diff --git a/deps/libchdr/deps/lzma-24.05/include/CpuArch.h b/deps/libchdr/deps/lzma-24.05/include/CpuArch.h
new file mode 100644
index 00000000..dfc68f13
--- /dev/null
+++ b/deps/libchdr/deps/lzma-24.05/include/CpuArch.h
@@ -0,0 +1,645 @@
+/* CpuArch.h -- CPU specific code
+2024-05-13 : Igor Pavlov : Public domain */
+
+#ifndef ZIP7_INC_CPU_ARCH_H
+#define ZIP7_INC_CPU_ARCH_H
+
+#include "7zTypes.h"
+
+EXTERN_C_BEGIN
+
+/*
+MY_CPU_LE means that CPU is LITTLE ENDIAN.
+MY_CPU_BE means that CPU is BIG ENDIAN.
+If MY_CPU_LE and MY_CPU_BE are not defined, we don't know about ENDIANNESS of platform.
+
+MY_CPU_LE_UNALIGN means that CPU is LITTLE ENDIAN and CPU supports unaligned memory accesses.
+
+MY_CPU_64BIT means that processor can work with 64-bit registers.
+ MY_CPU_64BIT can be used to select fast code branch
+ MY_CPU_64BIT doesn't mean that (sizeof(void *) == 8)
+*/
+
+#if !defined(_M_ARM64EC)
+#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_SIZEOF_POINTER 4
+ #else
+ #define MY_CPU_NAME "x64"
+ #define MY_CPU_SIZEOF_POINTER 8
+ #endif
+ #define MY_CPU_64BIT
+#endif
+#endif
+
+
+#if defined(_M_IX86) \
+ || defined(__i386__)
+ #define MY_CPU_X86
+ #define MY_CPU_NAME "x86"
+ /* #define MY_CPU_32BIT */
+ #define MY_CPU_SIZEOF_POINTER 4
+#endif
+
+
+#if defined(_M_ARM64) \
+ || defined(_M_ARM64EC) \
+ || defined(__AARCH64EL__) \
+ || defined(__AARCH64EB__) \
+ || defined(__aarch64__)
+ #define MY_CPU_ARM64
+#if defined(__ILP32__) \
+ || defined(__SIZEOF_POINTER__) && (__SIZEOF_POINTER__ == 4)
+ #define MY_CPU_NAME "arm64-32"
+ #define MY_CPU_SIZEOF_POINTER 4
+#elif defined(__SIZEOF_POINTER__) && (__SIZEOF_POINTER__ == 16)
+ #define MY_CPU_NAME "arm64-128"
+ #define MY_CPU_SIZEOF_POINTER 16
+#else
+#if defined(_M_ARM64EC)
+ #define MY_CPU_NAME "arm64ec"
+#else
+ #define MY_CPU_NAME "arm64"
+#endif
+ #define MY_CPU_SIZEOF_POINTER 8
+#endif
+ #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
+
+ #if defined(__thumb__) || defined(__THUMBEL__) || defined(_M_ARMT)
+ #define MY_CPU_ARMT
+ #define MY_CPU_NAME "armt"
+ #else
+ #define MY_CPU_ARM32
+ #define MY_CPU_NAME "arm"
+ #endif
+ /* #define MY_CPU_32BIT */
+ #define MY_CPU_SIZEOF_POINTER 4
+#endif
+
+
+#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 */
+#endif
+
+
+#if defined(__ppc64__) \
+ || defined(__powerpc64__) \
+ || defined(__ppc__) \
+ || defined(__powerpc__) \
+ || defined(__PPC__) \
+ || defined(_POWER)
+
+#define MY_CPU_PPC_OR_PPC64
+
+#if defined(__ppc64__) \
+ || defined(__powerpc64__) \
+ || defined(_LP64) \
+ || defined(__64BIT__)
+ #ifdef __ILP32__
+ #define MY_CPU_NAME "ppc64-32"
+ #define MY_CPU_SIZEOF_POINTER 4
+ #else
+ #define MY_CPU_NAME "ppc64"
+ #define MY_CPU_SIZEOF_POINTER 8
+ #endif
+ #define MY_CPU_64BIT
+#else
+ #define MY_CPU_NAME "ppc"
+ #define MY_CPU_SIZEOF_POINTER 4
+ /* #define MY_CPU_32BIT */
+#endif
+#endif
+
+
+#if defined(__sparc__) \
+ || defined(__sparc)
+ #define MY_CPU_SPARC
+ #if defined(__LP64__) \
+ || defined(_LP64) \
+ || defined(__SIZEOF_POINTER__) && (__SIZEOF_POINTER__ == 8)
+ #define MY_CPU_NAME "sparcv9"
+ #define MY_CPU_SIZEOF_POINTER 8
+ #define MY_CPU_64BIT
+ #elif defined(__sparc_v9__) \
+ || defined(__sparcv9)
+ #define MY_CPU_64BIT
+ #if defined(__SIZEOF_POINTER__) && (__SIZEOF_POINTER__ == 4)
+ #define MY_CPU_NAME "sparcv9-32"
+ #else
+ #define MY_CPU_NAME "sparcv9m"
+ #endif
+ #elif defined(__sparc_v8__) \
+ || defined(__sparcv8)
+ #define MY_CPU_NAME "sparcv8"
+ #define MY_CPU_SIZEOF_POINTER 4
+ #else
+ #define MY_CPU_NAME "sparc"
+ #endif
+#endif
+
+
+#if defined(__riscv) \
+ || defined(__riscv__)
+ #define MY_CPU_RISCV
+ #if __riscv_xlen == 32
+ #define MY_CPU_NAME "riscv32"
+ #elif __riscv_xlen == 64
+ #define MY_CPU_NAME "riscv64"
+ #else
+ #define MY_CPU_NAME "riscv"
+ #endif
+#endif
+
+
+#if defined(__loongarch__)
+ #define MY_CPU_LOONGARCH
+ #if defined(__loongarch64) || defined(__loongarch_grlen) && (__loongarch_grlen == 64)
+ #define MY_CPU_64BIT
+ #endif
+ #if defined(__loongarch64)
+ #define MY_CPU_NAME "loongarch64"
+ #define MY_CPU_LOONGARCH64
+ #else
+ #define MY_CPU_NAME "loongarch"
+ #endif
+#endif
+
+
+// #undef MY_CPU_NAME
+// #undef MY_CPU_SIZEOF_POINTER
+// #define __e2k__
+// #define __SIZEOF_POINTER__ 4
+#if defined(__e2k__)
+ #define MY_CPU_E2K
+ #if defined(__ILP32__) || defined(__SIZEOF_POINTER__) && (__SIZEOF_POINTER__ == 4)
+ #define MY_CPU_NAME "e2k-32"
+ #define MY_CPU_SIZEOF_POINTER 4
+ #else
+ #define MY_CPU_NAME "e2k"
+ #if defined(__LP64__) || defined(__SIZEOF_POINTER__) && (__SIZEOF_POINTER__ == 8)
+ #define MY_CPU_SIZEOF_POINTER 8
+ #endif
+ #endif
+ #define MY_CPU_64BIT
+#endif
+
+
+#if defined(MY_CPU_X86) || defined(MY_CPU_AMD64)
+#define MY_CPU_X86_OR_AMD64
+#endif
+
+#if defined(MY_CPU_ARM) || defined(MY_CPU_ARM64)
+#define MY_CPU_ARM_OR_ARM64
+#endif
+
+
+#ifdef _WIN32
+
+ #ifdef MY_CPU_ARM
+ #define MY_CPU_ARM_LE
+ #endif
+
+ #ifdef MY_CPU_ARM64
+ #define MY_CPU_ARM64_LE
+ #endif
+
+ #ifdef _M_IA64
+ #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(__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
+#endif
+
+
+#if defined(MY_CPU_LE) && defined(MY_CPU_BE)
+ #error Stop_Compiling_Bad_Endian
+#endif
+
+#if !defined(MY_CPU_LE) && !defined(MY_CPU_BE)
+ #error Stop_Compiling_CPU_ENDIAN_must_be_detected_at_compile_time
+#endif
+
+#if defined(MY_CPU_32BIT) && defined(MY_CPU_64BIT)
+ #error Stop_Compiling_Bad_32_64_BIT
+#endif
+
+#ifdef __SIZEOF_POINTER__
+ #ifdef MY_CPU_SIZEOF_POINTER
+ #if MY_CPU_SIZEOF_POINTER != __SIZEOF_POINTER__
+ #error Stop_Compiling_Bad_MY_CPU_PTR_SIZE
+ #endif
+ #else
+ #define MY_CPU_SIZEOF_POINTER __SIZEOF_POINTER__
+ #endif
+#endif
+
+#if defined(MY_CPU_SIZEOF_POINTER) && (MY_CPU_SIZEOF_POINTER == 4)
+#if defined (_LP64)
+ #error Stop_Compiling_Bad_MY_CPU_PTR_SIZE
+#endif
+#endif
+
+#ifdef _MSC_VER
+ #if _MSC_VER >= 1300
+ #define MY_CPU_pragma_pack_push_1 __pragma(pack(push, 1))
+ #define MY_CPU_pragma_pop __pragma(pack(pop))
+ #else
+ #define MY_CPU_pragma_pack_push_1
+ #define MY_CPU_pragma_pop
+ #endif
+#else
+ #ifdef __xlC__
+ #define MY_CPU_pragma_pack_push_1 _Pragma("pack(1)")
+ #define MY_CPU_pragma_pop _Pragma("pack()")
+ #else
+ #define MY_CPU_pragma_pack_push_1 _Pragma("pack(push, 1)")
+ #define MY_CPU_pragma_pop _Pragma("pack(pop)")
+ #endif
+#endif
+
+
+#ifndef MY_CPU_NAME
+ // #define MY_CPU_IS_UNKNOWN
+ #ifdef MY_CPU_LE
+ #define MY_CPU_NAME "LE"
+ #elif defined(MY_CPU_BE)
+ #define MY_CPU_NAME "BE"
+ #else
+ /*
+ #define MY_CPU_NAME ""
+ */
+ #endif
+#endif
+
+
+
+
+
+#ifdef __has_builtin
+ #define Z7_has_builtin(x) __has_builtin(x)
+#else
+ #define Z7_has_builtin(x) 0
+#endif
+
+
+#define Z7_BSWAP32_CONST(v) \
+ ( (((UInt32)(v) << 24) ) \
+ | (((UInt32)(v) << 8) & (UInt32)0xff0000) \
+ | (((UInt32)(v) >> 8) & (UInt32)0xff00 ) \
+ | (((UInt32)(v) >> 24) ))
+
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1300)
+
+#include
+
+/* Note: these macros will use bswap instruction (486), that is unsupported in 386 cpu */
+
+#pragma intrinsic(_byteswap_ushort)
+#pragma intrinsic(_byteswap_ulong)
+#pragma intrinsic(_byteswap_uint64)
+
+#define Z7_BSWAP16(v) _byteswap_ushort(v)
+#define Z7_BSWAP32(v) _byteswap_ulong (v)
+#define Z7_BSWAP64(v) _byteswap_uint64(v)
+#define Z7_CPU_FAST_BSWAP_SUPPORTED
+
+/* GCC can generate slow code that calls function for __builtin_bswap32() for:
+ - GCC for RISCV, if Zbb extension is not used.
+ - GCC for SPARC.
+ The code from CLANG for SPARC also is not fastest.
+ So we don't define Z7_CPU_FAST_BSWAP_SUPPORTED in some cases.
+*/
+#elif (!defined(MY_CPU_RISCV) || defined (__riscv_zbb)) \
+ && !defined(MY_CPU_SPARC) \
+ && ( \
+ (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))) \
+ || (defined(__clang__) && Z7_has_builtin(__builtin_bswap16)) \
+ )
+
+#define Z7_BSWAP16(v) __builtin_bswap16(v)
+#define Z7_BSWAP32(v) __builtin_bswap32(v)
+#define Z7_BSWAP64(v) __builtin_bswap64(v)
+#define Z7_CPU_FAST_BSWAP_SUPPORTED
+
+#else
+
+#define Z7_BSWAP16(v) ((UInt16) \
+ ( ((UInt32)(v) << 8) \
+ | ((UInt32)(v) >> 8) \
+ ))
+
+#define Z7_BSWAP32(v) Z7_BSWAP32_CONST(v)
+
+#define Z7_BSWAP64(v) \
+ ( ( ( (UInt64)(v) ) << 8 * 7 ) \
+ | ( ( (UInt64)(v) & ((UInt32)0xff << 8 * 1) ) << 8 * 5 ) \
+ | ( ( (UInt64)(v) & ((UInt32)0xff << 8 * 2) ) << 8 * 3 ) \
+ | ( ( (UInt64)(v) & ((UInt32)0xff << 8 * 3) ) << 8 * 1 ) \
+ | ( ( (UInt64)(v) >> 8 * 1 ) & ((UInt32)0xff << 8 * 3) ) \
+ | ( ( (UInt64)(v) >> 8 * 3 ) & ((UInt32)0xff << 8 * 2) ) \
+ | ( ( (UInt64)(v) >> 8 * 5 ) & ((UInt32)0xff << 8 * 1) ) \
+ | ( ( (UInt64)(v) >> 8 * 7 ) ) \
+ )
+
+#endif
+
+
+
+#ifdef MY_CPU_LE
+ #if defined(MY_CPU_X86_OR_AMD64) \
+ || defined(MY_CPU_ARM64) \
+ || defined(MY_CPU_RISCV) && defined(__riscv_misaligned_fast) \
+ || defined(MY_CPU_E2K) && defined(__iset__) && (__iset__ >= 6)
+ #define MY_CPU_LE_UNALIGN
+ #define MY_CPU_LE_UNALIGN_64
+ #elif defined(__ARM_FEATURE_UNALIGNED)
+/* === ALIGNMENT on 32-bit arm and LDRD/STRD/LDM/STM instructions.
+ Description of problems:
+problem-1 : 32-bit ARM architecture:
+ multi-access (pair of 32-bit accesses) instructions (LDRD/STRD/LDM/STM)
+ require 32-bit (WORD) alignment (by 32-bit ARM architecture).
+ So there is "Alignment fault exception", if data is not aligned for 32-bit.
+
+problem-2 : 32-bit kernels and arm64 kernels:
+ 32-bit linux kernels provide fixup for these "paired" instruction "Alignment fault exception".
+ So unaligned paired-access instructions work via exception handler in kernel in 32-bit linux.
+
+ But some arm64 kernels do not handle these faults in 32-bit programs.
+ So we have unhandled exception for such instructions.
+ Probably some new arm64 kernels have fixed it, and unaligned
+ paired-access instructions work in new kernels?
+
+problem-3 : compiler for 32-bit arm:
+ Compilers use LDRD/STRD/LDM/STM for UInt64 accesses
+ and for another cases where two 32-bit accesses are fused
+ to one multi-access instruction.
+ So UInt64 variables must be aligned for 32-bit, and each
+ 32-bit access must be aligned for 32-bit, if we want to
+ avoid "Alignment fault" exception (handled or unhandled).
+
+problem-4 : performace:
+ Even if unaligned access is handled by kernel, it will be slow.
+ So if we allow unaligned access, we can get fast unaligned
+ single-access, and slow unaligned paired-access.
+
+ We don't allow unaligned access on 32-bit arm, because compiler
+ genarates paired-access instructions that require 32-bit alignment,
+ and some arm64 kernels have no handler for these instructions.
+ Also unaligned paired-access instructions will be slow, if kernel handles them.
+*/
+ // it must be disabled:
+ // #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))
+#ifdef MY_CPU_LE_UNALIGN_64
+#define GetUi64(p) (*(const UInt64 *)(const void *)(p))
+#define SetUi64(p, v) { *(UInt64 *)(void *)(p) = (v); }
+#endif
+
+#define SetUi16(p, v) { *(UInt16 *)(void *)(p) = (v); }
+#define SetUi32(p, v) { *(UInt32 *)(void *)(p) = (v); }
+
+#else
+
+#define GetUi16(p) ( (UInt16) ( \
+ ((const Byte *)(p))[0] | \
+ ((UInt16)((const Byte *)(p))[1] << 8) ))
+
+#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 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); \
+ _ppp_[0] = (Byte)_vvv_; \
+ _ppp_[1] = (Byte)(_vvv_ >> 8); \
+ _ppp_[2] = (Byte)(_vvv_ >> 16); \
+ _ppp_[3] = (Byte)(_vvv_ >> 24); }
+
+#endif
+
+
+#ifndef GetUi64
+#define GetUi64(p) (GetUi32(p) | ((UInt64)GetUi32(((const Byte *)(p)) + 4) << 32))
+#endif
+
+#ifndef SetUi64
+#define SetUi64(p, v) { Byte *_ppp2_ = (Byte *)(p); UInt64 _vvv2_ = (v); \
+ SetUi32(_ppp2_ , (UInt32)_vvv2_) \
+ SetUi32(_ppp2_ + 4, (UInt32)(_vvv2_ >> 32)) }
+#endif
+
+
+#if defined(MY_CPU_LE_UNALIGN) && defined(Z7_CPU_FAST_BSWAP_SUPPORTED)
+
+#define GetBe32(p) Z7_BSWAP32 (*(const UInt32 *)(const void *)(p))
+#define SetBe32(p, v) { (*(UInt32 *)(void *)(p)) = Z7_BSWAP32(v); }
+
+#if defined(MY_CPU_LE_UNALIGN_64)
+#define GetBe64(p) Z7_BSWAP64 (*(const UInt64 *)(const void *)(p))
+#endif
+
+#else
+
+#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 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); \
+ _ppp_[3] = (Byte)_vvv_; }
+
+#endif
+
+#ifndef GetBe64
+#define GetBe64(p) (((UInt64)GetBe32(p) << 32) | GetBe32(((const Byte *)(p)) + 4))
+#endif
+
+#ifndef GetBe16
+#define GetBe16(p) ( (UInt16) ( \
+ ((UInt16)((const Byte *)(p))[0] << 8) | \
+ ((const Byte *)(p))[1] ))
+#endif
+
+
+#if defined(MY_CPU_BE)
+#define Z7_CONV_BE_TO_NATIVE_CONST32(v) (v)
+#define Z7_CONV_LE_TO_NATIVE_CONST32(v) Z7_BSWAP32_CONST(v)
+#define Z7_CONV_NATIVE_TO_BE_32(v) (v)
+#elif defined(MY_CPU_LE)
+#define Z7_CONV_BE_TO_NATIVE_CONST32(v) Z7_BSWAP32_CONST(v)
+#define Z7_CONV_LE_TO_NATIVE_CONST32(v) (v)
+#define Z7_CONV_NATIVE_TO_BE_32(v) Z7_BSWAP32(v)
+#else
+#error Stop_Compiling_Unknown_Endian_CONV
+#endif
+
+
+#if defined(MY_CPU_BE)
+
+#define GetBe64a(p) (*(const UInt64 *)(const void *)(p))
+#define GetBe32a(p) (*(const UInt32 *)(const void *)(p))
+#define GetBe16a(p) (*(const UInt16 *)(const void *)(p))
+#define SetBe32a(p, v) { *(UInt32 *)(void *)(p) = (v); }
+#define SetBe16a(p, v) { *(UInt16 *)(void *)(p) = (v); }
+
+#define GetUi32a(p) GetUi32(p)
+#define GetUi16a(p) GetUi16(p)
+#define SetUi32a(p, v) SetUi32(p, v)
+#define SetUi16a(p, v) SetUi16(p, v)
+
+#elif defined(MY_CPU_LE)
+
+#define GetUi32a(p) (*(const UInt32 *)(const void *)(p))
+#define GetUi16a(p) (*(const UInt16 *)(const void *)(p))
+#define SetUi32a(p, v) { *(UInt32 *)(void *)(p) = (v); }
+#define SetUi16a(p, v) { *(UInt16 *)(void *)(p) = (v); }
+
+#define GetBe64a(p) GetBe64(p)
+#define GetBe32a(p) GetBe32(p)
+#define GetBe16a(p) GetBe16(p)
+#define SetBe32a(p, v) SetBe32(p, v)
+#define SetBe16a(p, v) SetBe16(p, v)
+
+#else
+#error Stop_Compiling_Unknown_Endian_CPU_a
+#endif
+
+
+#if defined(MY_CPU_X86_OR_AMD64) \
+ || defined(MY_CPU_ARM_OR_ARM64) \
+ || defined(MY_CPU_PPC_OR_PPC64)
+ #define Z7_CPU_FAST_ROTATE_SUPPORTED
+#endif
+
+
+#ifdef MY_CPU_X86_OR_AMD64
+
+void Z7_FASTCALL z7_x86_cpuid(UInt32 a[4], UInt32 function);
+UInt32 Z7_FASTCALL z7_x86_cpuid_GetMaxFunc(void);
+#if defined(MY_CPU_AMD64)
+#define Z7_IF_X86_CPUID_SUPPORTED
+#else
+#define Z7_IF_X86_CPUID_SUPPORTED if (z7_x86_cpuid_GetMaxFunc())
+#endif
+
+BoolInt CPU_IsSupported_AES(void);
+BoolInt CPU_IsSupported_AVX(void);
+BoolInt CPU_IsSupported_AVX2(void);
+// BoolInt CPU_IsSupported_AVX512F_AVX512VL(void);
+BoolInt CPU_IsSupported_VAES_AVX2(void);
+BoolInt CPU_IsSupported_CMOV(void);
+BoolInt CPU_IsSupported_SSE(void);
+BoolInt CPU_IsSupported_SSE2(void);
+BoolInt CPU_IsSupported_SSSE3(void);
+BoolInt CPU_IsSupported_SSE41(void);
+BoolInt CPU_IsSupported_SHA(void);
+BoolInt CPU_IsSupported_PageGB(void);
+
+#elif defined(MY_CPU_ARM_OR_ARM64)
+
+BoolInt CPU_IsSupported_CRC32(void);
+BoolInt CPU_IsSupported_NEON(void);
+
+#if defined(_WIN32)
+BoolInt CPU_IsSupported_CRYPTO(void);
+#define CPU_IsSupported_SHA1 CPU_IsSupported_CRYPTO
+#define CPU_IsSupported_SHA2 CPU_IsSupported_CRYPTO
+#define CPU_IsSupported_AES CPU_IsSupported_CRYPTO
+#else
+BoolInt CPU_IsSupported_SHA1(void);
+BoolInt CPU_IsSupported_SHA2(void);
+BoolInt CPU_IsSupported_AES(void);
+#endif
+
+#endif
+
+#if defined(__APPLE__)
+int z7_sysctlbyname_Get(const char *name, void *buf, size_t *bufSize);
+int z7_sysctlbyname_Get_UInt32(const char *name, UInt32 *val);
+#endif
+
+EXTERN_C_END
+
+#endif
diff --git a/deps/libchdr/deps/lzma-19.00/include/Delta.h b/deps/libchdr/deps/lzma-24.05/include/Delta.h
similarity index 75%
rename from deps/libchdr/deps/lzma-19.00/include/Delta.h
rename to deps/libchdr/deps/lzma-24.05/include/Delta.h
index 2fa54ad6..70609541 100644
--- a/deps/libchdr/deps/lzma-19.00/include/Delta.h
+++ b/deps/libchdr/deps/lzma-24.05/include/Delta.h
@@ -1,8 +1,8 @@
/* Delta.h -- Delta converter
-2013-01-18 : Igor Pavlov : Public domain */
+2023-03-03 : Igor Pavlov : Public domain */
-#ifndef __DELTA_H
-#define __DELTA_H
+#ifndef ZIP7_INC_DELTA_H
+#define ZIP7_INC_DELTA_H
#include "7zTypes.h"
diff --git a/deps/libchdr/deps/lzma-22.01/include/LzFind.h b/deps/libchdr/deps/lzma-24.05/include/LzFind.h
similarity index 75%
rename from deps/libchdr/deps/lzma-22.01/include/LzFind.h
rename to deps/libchdr/deps/lzma-24.05/include/LzFind.h
index 8f9fade2..67e8a6e0 100644
--- a/deps/libchdr/deps/lzma-22.01/include/LzFind.h
+++ b/deps/libchdr/deps/lzma-24.05/include/LzFind.h
@@ -1,136 +1,160 @@
-/* LzFind.h -- Match finder for LZ algorithms
-2021-07-13 : Igor Pavlov : Public domain */
-
-#ifndef __LZ_FIND_H
-#define __LZ_FIND_H
-
-#include "7zTypes.h"
-
-EXTERN_C_BEGIN
-
-typedef UInt32 CLzRef;
-
-typedef struct _CMatchFinder
-{
- Byte *buffer;
- UInt32 pos;
- UInt32 posLimit;
- UInt32 streamPos; /* wrap over Zero is allowed (streamPos < pos). Use (UInt32)(streamPos - pos) */
- 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) ((const Byte *)(p)->buffer)
-
-#define Inline_MatchFinder_GetNumAvailableBytes(p) ((UInt32)((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);
-
-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);
-
-/*
-#define Inline_MatchFinder_InitPos(p, val) \
- (p)->pos = (val); \
- (p)->streamPos = (val);
-*/
-
-#define Inline_MatchFinder_ReduceOffsets(p, subValue) \
- (p)->pos -= (subValue); \
- (p)->streamPos -= (subValue);
-
-
-UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son,
- size_t _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,
- UInt32 *distances, UInt32 maxLen);
-
-/*
-Conditions:
- Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func.
- 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;
-} IMatchFinder2;
-
-void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder2 *vTable);
-
-void MatchFinder_Init_LowHash(CMatchFinder *p);
-void MatchFinder_Init_HighHash(CMatchFinder *p);
-void MatchFinder_Init_4(CMatchFinder *p);
-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 LzFindPrepare(void);
-
-EXTERN_C_END
-
-#endif
+/* LzFind.h -- Match finder for LZ algorithms
+2024-01-22 : Igor Pavlov : Public domain */
+
+#ifndef ZIP7_INC_LZ_FIND_H
+#define ZIP7_INC_LZ_FIND_H
+
+#include "7zTypes.h"
+
+EXTERN_C_BEGIN
+
+typedef UInt32 CLzRef;
+
+typedef struct
+{
+ const Byte *buffer;
+ UInt32 pos;
+ UInt32 posLimit;
+ UInt32 streamPos; /* wrap over Zero is allowed (streamPos < pos). Use (UInt32)(streamPos - pos) */
+ 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 *bufBase;
+ ISeqInStreamPtr stream;
+
+ UInt32 blockSize;
+ UInt32 keepSizeBefore;
+ UInt32 keepSizeAfter;
+
+ UInt32 numHashBytes;
+ size_t directInputRem;
+ UInt32 historySize;
+ UInt32 fixedHashSize;
+ Byte numHashBytes_Min;
+ Byte numHashOutBits;
+ Byte _pad2_[2];
+ SRes result;
+ UInt32 crc[256];
+ size_t numRefs;
+
+ UInt64 expectedDataSize;
+} CMatchFinder;
+
+#define Inline_MatchFinder_GetPointerToCurrentPos(p) ((const Byte *)(p)->buffer)
+
+#define Inline_MatchFinder_GetNumAvailableBytes(p) ((UInt32)((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);
+
+void MatchFinder_Construct(CMatchFinder *p);
+
+/* (directInput = 0) is default value.
+ It's required to provide correct (directInput) value
+ before calling MatchFinder_Create().
+ You can set (directInput) by any of the following calls:
+ - MatchFinder_SET_DIRECT_INPUT_BUF()
+ - MatchFinder_SET_STREAM()
+ - MatchFinder_SET_STREAM_MODE()
+*/
+
+#define MatchFinder_SET_DIRECT_INPUT_BUF(p, _src_, _srcLen_) { \
+ (p)->stream = NULL; \
+ (p)->directInput = 1; \
+ (p)->buffer = (_src_); \
+ (p)->directInputRem = (_srcLen_); }
+
+/*
+#define MatchFinder_SET_STREAM_MODE(p) { \
+ (p)->directInput = 0; }
+*/
+
+#define MatchFinder_SET_STREAM(p, _stream_) { \
+ (p)->stream = _stream_; \
+ (p)->directInput = 0; }
+
+
+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);
+
+/*
+#define MatchFinder_INIT_POS(p, val) \
+ (p)->pos = (val); \
+ (p)->streamPos = (val);
+*/
+
+// void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue);
+#define MatchFinder_REDUCE_OFFSETS(p, subValue) \
+ (p)->pos -= (subValue); \
+ (p)->streamPos -= (subValue);
+
+
+UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son,
+ size_t _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,
+ UInt32 *distances, UInt32 maxLen);
+
+/*
+Conditions:
+ Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func.
+ 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
+{
+ Mf_Init_Func Init;
+ Mf_GetNumAvailableBytes_Func GetNumAvailableBytes;
+ Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos;
+ Mf_GetMatches_Func GetMatches;
+ Mf_Skip_Func Skip;
+} IMatchFinder2;
+
+void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder2 *vTable);
+
+void MatchFinder_Init_LowHash(CMatchFinder *p);
+void MatchFinder_Init_HighHash(CMatchFinder *p);
+void MatchFinder_Init_4(CMatchFinder *p);
+// void MatchFinder_Init(CMatchFinder *p);
+void MatchFinder_Init(void *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 LzFindPrepare(void);
+
+EXTERN_C_END
+
+#endif
diff --git a/deps/libchdr/deps/lzma-22.01/include/LzHash.h b/deps/libchdr/deps/lzma-24.05/include/LzHash.h
similarity index 80%
rename from deps/libchdr/deps/lzma-22.01/include/LzHash.h
rename to deps/libchdr/deps/lzma-24.05/include/LzHash.h
index a682f83b..2b6290b6 100644
--- a/deps/libchdr/deps/lzma-22.01/include/LzHash.h
+++ b/deps/libchdr/deps/lzma-24.05/include/LzHash.h
@@ -1,34 +1,34 @@
-/* LzHash.h -- HASH functions for LZ algorithms
-2019-10-30 : Igor Pavlov : Public domain */
-
-#ifndef __LZ_HASH_H
-#define __LZ_HASH_H
-
-/*
- (kHash2Size >= (1 << 8)) : Required
- (kHash3Size >= (1 << 16)) : Required
-*/
-
-#define kHash2Size (1 << 10)
-#define kHash3Size (1 << 16)
-// #define kHash4Size (1 << 20)
-
-#define kFix3HashSize (kHash2Size)
-#define kFix4HashSize (kHash2Size + kHash3Size)
-// #define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size)
-
-/*
- We use up to 3 crc values for hash:
- crc0
- crc1 << Shift_1
- crc2 << Shift_2
- (Shift_1 = 5) and (Shift_2 = 10) is good tradeoff.
- Small values for Shift are not good for collision rate.
- Big value for Shift_2 increases the minimum size
- of hash table, that will be slow for small files.
-*/
-
-#define kLzHash_CrcShift_1 5
-#define kLzHash_CrcShift_2 10
-
-#endif
+/* LzHash.h -- HASH constants for LZ algorithms
+2023-03-05 : Igor Pavlov : Public domain */
+
+#ifndef ZIP7_INC_LZ_HASH_H
+#define ZIP7_INC_LZ_HASH_H
+
+/*
+ (kHash2Size >= (1 << 8)) : Required
+ (kHash3Size >= (1 << 16)) : Required
+*/
+
+#define kHash2Size (1 << 10)
+#define kHash3Size (1 << 16)
+// #define kHash4Size (1 << 20)
+
+#define kFix3HashSize (kHash2Size)
+#define kFix4HashSize (kHash2Size + kHash3Size)
+// #define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size)
+
+/*
+ We use up to 3 crc values for hash:
+ crc0
+ crc1 << Shift_1
+ crc2 << Shift_2
+ (Shift_1 = 5) and (Shift_2 = 10) is good tradeoff.
+ Small values for Shift are not good for collision rate.
+ Big value for Shift_2 increases the minimum size
+ of hash table, that will be slow for small files.
+*/
+
+#define kLzHash_CrcShift_1 5
+#define kLzHash_CrcShift_2 10
+
+#endif
diff --git a/deps/libchdr/deps/lzma-19.00/include/Lzma86.h b/deps/libchdr/deps/lzma-24.05/include/Lzma86.h
similarity index 96%
rename from deps/libchdr/deps/lzma-19.00/include/Lzma86.h
rename to deps/libchdr/deps/lzma-24.05/include/Lzma86.h
index bebed5cb..e7707e2c 100644
--- a/deps/libchdr/deps/lzma-19.00/include/Lzma86.h
+++ b/deps/libchdr/deps/lzma-24.05/include/Lzma86.h
@@ -1,8 +1,8 @@
/* Lzma86.h -- LZMA + x86 (BCJ) Filter
-2013-01-18 : Igor Pavlov : Public domain */
+2023-03-03 : Igor Pavlov : Public domain */
-#ifndef __LZMA86_H
-#define __LZMA86_H
+#ifndef ZIP7_INC_LZMA86_H
+#define ZIP7_INC_LZMA86_H
#include "7zTypes.h"
diff --git a/deps/libchdr/deps/lzma-22.01/include/LzmaDec.h b/deps/libchdr/deps/lzma-24.05/include/LzmaDec.h
similarity index 93%
rename from deps/libchdr/deps/lzma-22.01/include/LzmaDec.h
rename to deps/libchdr/deps/lzma-24.05/include/LzmaDec.h
index 6194b7d1..b0ce28fa 100644
--- a/deps/libchdr/deps/lzma-22.01/include/LzmaDec.h
+++ b/deps/libchdr/deps/lzma-24.05/include/LzmaDec.h
@@ -1,236 +1,237 @@
-/* LzmaDec.h -- LZMA Decoder
-2020-03-19 : Igor Pavlov : Public domain */
-
-#ifndef __LZMA_DEC_H
-#define __LZMA_DEC_H
-
-#include "7zTypes.h"
-
-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 */
-
-typedef
-#ifdef _LZMA_PROB32
- UInt32
-#else
- UInt16
-#endif
- CLzmaProb;
-
-
-/* ---------- LZMA Properties ---------- */
-
-#define LZMA_PROPS_SIZE 5
-
-typedef struct _CLzmaProps
-{
- Byte lc;
- Byte lp;
- Byte pb;
- Byte _pad_;
- UInt32 dicSize;
-} CLzmaProps;
-
-/* LzmaProps_Decode - decodes properties
-Returns:
- SZ_OK
- SZ_ERROR_UNSUPPORTED - Unsupported properties
-*/
-
-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
-
-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];
-} CLzmaDec;
-
-#define LzmaDec_Construct(p) { (p)->dic = NULL; (p)->probs = NULL; }
-
-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
-{
- LZMA_FINISH_ANY, /* finish at any point */
- LZMA_FINISH_END /* block must be finished at the end */
-} ELzmaFinishMode;
-
-/* ELzmaFinishMode has meaning only if the decoding reaches output limit !!!
-
- You must use LZMA_FINISH_END, when you know that current output buffer
- covers last bytes of block. In other cases you must use LZMA_FINISH_ANY.
-
- If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK,
- and output value of destLen will be less than output buffer size limit.
- You can check status result also.
-
- You can use multiple checks to test data integrity after full decompression:
- 1) Check Result and "status" variable.
- 2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.
- 3) Check that output(srcLen) = compressedSize, if you know real compressedSize.
- You must use correct finish mode in that case. */
-
-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 */
- LZMA_STATUS_NEEDS_MORE_INPUT, /* you must provide more input bytes */
- LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK /* there is probability that stream was finished without end mark */
-} ELzmaStatus;
-
-/* ELzmaStatus is used only as output value for function call */
-
-
-/* ---------- Interfaces ---------- */
-
-/* There are 3 levels of interfaces:
- 1) Dictionary Interface
- 2) Buffer Interface
- 3) One Call Interface
- 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
- You can use variant 2, if you set dictionary buffer manually.
- For Buffer Interface you must always use variant 1.
-
-LzmaDec_Allocate* can return:
- SZ_OK
- SZ_ERROR_MEM - Memory allocation error
- 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);
-
-/* ---------- Dictionary Interface ---------- */
-
-/* You can use it, if you want to eliminate the overhead for data copying from
- dictionary to some other external buffer.
- You must work with CLzmaDec variables directly in this interface.
-
- STEPS:
- LzmaDec_Construct()
- LzmaDec_Allocate()
- for (each new stream)
- {
- LzmaDec_Init()
- while (it needs more decompression)
- {
- LzmaDec_DecodeToDic()
- use data from CLzmaDec::dic and update CLzmaDec::dicPos
- }
- }
- LzmaDec_Free()
-*/
-
-/* LzmaDec_DecodeToDic
-
- The decoding to internal dictionary buffer (CLzmaDec::dic).
- You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!!
-
-finishMode:
- It has meaning only if the decoding reaches output limit (dicLimit).
- LZMA_FINISH_ANY - Decode just dicLimit bytes.
- LZMA_FINISH_END - Stream must be finished after dicLimit.
-
-Returns:
- SZ_OK
- status:
- LZMA_STATUS_FINISHED_WITH_MARK
- LZMA_STATUS_NOT_FINISHED
- LZMA_STATUS_NEEDS_MORE_INPUT
- LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
- SZ_ERROR_DATA - Data error
- SZ_ERROR_FAIL - Some unexpected error: internal error of code, memory corruption or hardware failure
-*/
-
-SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit,
- const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
-
-
-/* ---------- Buffer Interface ---------- */
-
-/* It's zlib-like interface.
- See LzmaDec_DecodeToDic description for information about STEPS and return results,
- but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need
- to work with CLzmaDec variables manually.
-
-finishMode:
- It has meaning only if the decoding reaches output limit (*destLen).
- LZMA_FINISH_ANY - Decode just destLen bytes.
- 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);
-
-
-/* ---------- One Call Interface ---------- */
-
-/* LzmaDecode
-
-finishMode:
- It has meaning only if the decoding reaches output limit (*destLen).
- LZMA_FINISH_ANY - Decode just destLen bytes.
- LZMA_FINISH_END - Stream must be finished after (*destLen).
-
-Returns:
- SZ_OK
- status:
- LZMA_STATUS_FINISHED_WITH_MARK
- LZMA_STATUS_NOT_FINISHED
- LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
- SZ_ERROR_DATA - Data error
- SZ_ERROR_MEM - Memory allocation error
- SZ_ERROR_UNSUPPORTED - Unsupported properties
- SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).
- SZ_ERROR_FAIL - Some unexpected error: internal error of code, memory corruption or hardware failure
-*/
-
-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
-
-#endif
+/* LzmaDec.h -- LZMA Decoder
+2023-04-02 : Igor Pavlov : Public domain */
+
+#ifndef ZIP7_INC_LZMA_DEC_H
+#define ZIP7_INC_LZMA_DEC_H
+
+#include "7zTypes.h"
+
+EXTERN_C_BEGIN
+
+/* #define Z7_LZMA_PROB32 */
+/* Z7_LZMA_PROB32 can increase the speed on some CPUs,
+ but memory usage for CLzmaDec::probs will be doubled in that case */
+
+typedef
+#ifdef Z7_LZMA_PROB32
+ UInt32
+#else
+ UInt16
+#endif
+ CLzmaProb;
+
+
+/* ---------- LZMA Properties ---------- */
+
+#define LZMA_PROPS_SIZE 5
+
+typedef struct
+{
+ Byte lc;
+ Byte lp;
+ Byte pb;
+ Byte _pad_;
+ UInt32 dicSize;
+} CLzmaProps;
+
+/* LzmaProps_Decode - decodes properties
+Returns:
+ SZ_OK
+ SZ_ERROR_UNSUPPORTED - Unsupported properties
+*/
+
+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
+
+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];
+} CLzmaDec;
+
+#define LzmaDec_CONSTRUCT(p) { (p)->dic = NULL; (p)->probs = NULL; }
+#define LzmaDec_Construct(p) LzmaDec_CONSTRUCT(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
+{
+ LZMA_FINISH_ANY, /* finish at any point */
+ LZMA_FINISH_END /* block must be finished at the end */
+} ELzmaFinishMode;
+
+/* ELzmaFinishMode has meaning only if the decoding reaches output limit !!!
+
+ You must use LZMA_FINISH_END, when you know that current output buffer
+ covers last bytes of block. In other cases you must use LZMA_FINISH_ANY.
+
+ If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK,
+ and output value of destLen will be less than output buffer size limit.
+ You can check status result also.
+
+ You can use multiple checks to test data integrity after full decompression:
+ 1) Check Result and "status" variable.
+ 2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.
+ 3) Check that output(srcLen) = compressedSize, if you know real compressedSize.
+ You must use correct finish mode in that case. */
+
+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 */
+ LZMA_STATUS_NEEDS_MORE_INPUT, /* you must provide more input bytes */
+ LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK /* there is probability that stream was finished without end mark */
+} ELzmaStatus;
+
+/* ELzmaStatus is used only as output value for function call */
+
+
+/* ---------- Interfaces ---------- */
+
+/* There are 3 levels of interfaces:
+ 1) Dictionary Interface
+ 2) Buffer Interface
+ 3) One Call Interface
+ 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
+ You can use variant 2, if you set dictionary buffer manually.
+ For Buffer Interface you must always use variant 1.
+
+LzmaDec_Allocate* can return:
+ SZ_OK
+ SZ_ERROR_MEM - Memory allocation error
+ 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);
+
+/* ---------- Dictionary Interface ---------- */
+
+/* You can use it, if you want to eliminate the overhead for data copying from
+ dictionary to some other external buffer.
+ You must work with CLzmaDec variables directly in this interface.
+
+ STEPS:
+ LzmaDec_Construct()
+ LzmaDec_Allocate()
+ for (each new stream)
+ {
+ LzmaDec_Init()
+ while (it needs more decompression)
+ {
+ LzmaDec_DecodeToDic()
+ use data from CLzmaDec::dic and update CLzmaDec::dicPos
+ }
+ }
+ LzmaDec_Free()
+*/
+
+/* LzmaDec_DecodeToDic
+
+ The decoding to internal dictionary buffer (CLzmaDec::dic).
+ You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!!
+
+finishMode:
+ It has meaning only if the decoding reaches output limit (dicLimit).
+ LZMA_FINISH_ANY - Decode just dicLimit bytes.
+ LZMA_FINISH_END - Stream must be finished after dicLimit.
+
+Returns:
+ SZ_OK
+ status:
+ LZMA_STATUS_FINISHED_WITH_MARK
+ LZMA_STATUS_NOT_FINISHED
+ LZMA_STATUS_NEEDS_MORE_INPUT
+ LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
+ SZ_ERROR_DATA - Data error
+ SZ_ERROR_FAIL - Some unexpected error: internal error of code, memory corruption or hardware failure
+*/
+
+SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit,
+ const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
+
+
+/* ---------- Buffer Interface ---------- */
+
+/* It's zlib-like interface.
+ See LzmaDec_DecodeToDic description for information about STEPS and return results,
+ but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need
+ to work with CLzmaDec variables manually.
+
+finishMode:
+ It has meaning only if the decoding reaches output limit (*destLen).
+ LZMA_FINISH_ANY - Decode just destLen bytes.
+ 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);
+
+
+/* ---------- One Call Interface ---------- */
+
+/* LzmaDecode
+
+finishMode:
+ It has meaning only if the decoding reaches output limit (*destLen).
+ LZMA_FINISH_ANY - Decode just destLen bytes.
+ LZMA_FINISH_END - Stream must be finished after (*destLen).
+
+Returns:
+ SZ_OK
+ status:
+ LZMA_STATUS_FINISHED_WITH_MARK
+ LZMA_STATUS_NOT_FINISHED
+ LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
+ SZ_ERROR_DATA - Data error
+ SZ_ERROR_MEM - Memory allocation error
+ SZ_ERROR_UNSUPPORTED - Unsupported properties
+ SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).
+ SZ_ERROR_FAIL - Some unexpected error: internal error of code, memory corruption or hardware failure
+*/
+
+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
+
+#endif
diff --git a/deps/libchdr/deps/lzma-22.01/include/LzmaEnc.h b/deps/libchdr/deps/lzma-24.05/include/LzmaEnc.h
similarity index 80%
rename from deps/libchdr/deps/lzma-22.01/include/LzmaEnc.h
rename to deps/libchdr/deps/lzma-24.05/include/LzmaEnc.h
index 26757ba6..9f8039a1 100644
--- a/deps/libchdr/deps/lzma-22.01/include/LzmaEnc.h
+++ b/deps/libchdr/deps/lzma-24.05/include/LzmaEnc.h
@@ -1,78 +1,83 @@
-/* LzmaEnc.h -- LZMA Encoder
-2019-10-30 : Igor Pavlov : Public domain */
-
-#ifndef __LZMA_ENC_H
-#define __LZMA_ENC_H
-
-#include "7zTypes.h"
-
-EXTERN_C_BEGIN
-
-#define LZMA_PROPS_SIZE 5
-
-typedef struct _CLzmaEncProps
-{
- int level; /* 0 <= level <= 9 */
- UInt32 dictSize; /* (1 << 12) <= dictSize <= (1 << 27) for 32-bit version
- (1 << 12) <= dictSize <= (3 << 29) for 64-bit version
- default = (1 << 24) */
- int lc; /* 0 <= lc <= 8, default = 3 */
- int lp; /* 0 <= lp <= 4, default = 0 */
- int pb; /* 0 <= pb <= 4, default = 2 */
- int algo; /* 0 - fast, 1 - normal, default = 1 */
- int fb; /* 5 <= fb <= 273, default = 32 */
- int btMode; /* 0 - hashChain Mode, 1 - binTree mode - normal, default = 1 */
- int numHashBytes; /* 2, 3 or 4, default = 4 */
- UInt32 mc; /* 1 <= mc <= (1 << 30), default = 32 */
- unsigned writeEndMark; /* 0 - do not write EOPM, 1 - write EOPM, default = 0 */
- int numThreads; /* 1 or 2, default = 2 */
-
- UInt64 reduceSize; /* estimated size of data that will be compressed. default = (UInt64)(Int64)-1.
- Encoder uses this value to reduce dictionary size */
-
- UInt64 affinity;
-} CLzmaEncProps;
-
-void LzmaEncProps_Init(CLzmaEncProps *p);
-void LzmaEncProps_Normalize(CLzmaEncProps *p);
-UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2);
-
-
-/* ---------- CLzmaEncHandle Interface ---------- */
-
-/* LzmaEnc* functions can return the following exit codes:
-SRes:
- SZ_OK - OK
- SZ_ERROR_MEM - Memory allocation error
- SZ_ERROR_PARAM - Incorrect paramater in props
- SZ_ERROR_WRITE - ISeqOutStream write callback error
- SZ_ERROR_OUTPUT_EOF - output buffer overflow - version with (Byte *) output
- SZ_ERROR_PROGRESS - some break from progress callback
- SZ_ERROR_THREAD - error in multithreading functions (only for Mt version)
-*/
-
-typedef void * CLzmaEncHandle;
-
-CLzmaEncHandle LzmaEnc_Create(ISzAllocPtr alloc);
-void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAllocPtr alloc, ISzAllocPtr allocBig);
-
-SRes LzmaEnc_SetProps(CLzmaEncHandle p, const CLzmaEncProps *props);
-void LzmaEnc_SetDataSize(CLzmaEncHandle p, UInt64 expectedDataSiize);
-SRes LzmaEnc_WriteProperties(CLzmaEncHandle p, Byte *properties, SizeT *size);
-unsigned LzmaEnc_IsWriteEndMark(CLzmaEncHandle p);
-
-SRes LzmaEnc_Encode(CLzmaEncHandle p, ISeqOutStream *outStream, ISeqInStream *inStream,
- ICompressProgress *progress, ISzAllocPtr alloc, ISzAllocPtr allocBig);
-SRes LzmaEnc_MemEncode(CLzmaEncHandle p, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
- int writeEndMark, ICompressProgress *progress, ISzAllocPtr alloc, ISzAllocPtr allocBig);
-
-
-/* ---------- One Call Interface ---------- */
-
-SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
- const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
- ICompressProgress *progress, ISzAllocPtr alloc, ISzAllocPtr allocBig);
-
-EXTERN_C_END
-
-#endif
+/* LzmaEnc.h -- LZMA Encoder
+2023-04-13 : Igor Pavlov : Public domain */
+
+#ifndef ZIP7_INC_LZMA_ENC_H
+#define ZIP7_INC_LZMA_ENC_H
+
+#include "7zTypes.h"
+
+EXTERN_C_BEGIN
+
+#define LZMA_PROPS_SIZE 5
+
+typedef struct
+{
+ int level; /* 0 <= level <= 9 */
+ UInt32 dictSize; /* (1 << 12) <= dictSize <= (1 << 27) for 32-bit version
+ (1 << 12) <= dictSize <= (3 << 29) for 64-bit version
+ default = (1 << 24) */
+ int lc; /* 0 <= lc <= 8, default = 3 */
+ int lp; /* 0 <= lp <= 4, default = 0 */
+ int pb; /* 0 <= pb <= 4, default = 2 */
+ int algo; /* 0 - fast, 1 - normal, default = 1 */
+ int fb; /* 5 <= fb <= 273, default = 32 */
+ int btMode; /* 0 - hashChain Mode, 1 - binTree mode - normal, default = 1 */
+ int numHashBytes; /* 2, 3 or 4, default = 4 */
+ unsigned numHashOutBits; /* default = ? */
+ UInt32 mc; /* 1 <= mc <= (1 << 30), default = 32 */
+ unsigned writeEndMark; /* 0 - do not write EOPM, 1 - write EOPM, default = 0 */
+ int numThreads; /* 1 or 2, default = 2 */
+
+ // int _pad;
+
+ UInt64 reduceSize; /* estimated size of data that will be compressed. default = (UInt64)(Int64)-1.
+ Encoder uses this value to reduce dictionary size */
+
+ UInt64 affinity;
+} CLzmaEncProps;
+
+void LzmaEncProps_Init(CLzmaEncProps *p);
+void LzmaEncProps_Normalize(CLzmaEncProps *p);
+UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2);
+
+
+/* ---------- CLzmaEncHandle Interface ---------- */
+
+/* LzmaEnc* functions can return the following exit codes:
+SRes:
+ SZ_OK - OK
+ SZ_ERROR_MEM - Memory allocation error
+ SZ_ERROR_PARAM - Incorrect paramater in props
+ SZ_ERROR_WRITE - ISeqOutStream write callback error
+ SZ_ERROR_OUTPUT_EOF - output buffer overflow - version with (Byte *) output
+ SZ_ERROR_PROGRESS - some break from progress callback
+ SZ_ERROR_THREAD - error in multithreading functions (only for Mt version)
+*/
+
+typedef struct CLzmaEnc CLzmaEnc;
+typedef CLzmaEnc * CLzmaEncHandle;
+// Z7_DECLARE_HANDLE(CLzmaEncHandle)
+
+CLzmaEncHandle LzmaEnc_Create(ISzAllocPtr alloc);
+void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAllocPtr alloc, ISzAllocPtr allocBig);
+
+SRes LzmaEnc_SetProps(CLzmaEncHandle p, const CLzmaEncProps *props);
+void LzmaEnc_SetDataSize(CLzmaEncHandle p, UInt64 expectedDataSiize);
+SRes LzmaEnc_WriteProperties(CLzmaEncHandle p, Byte *properties, SizeT *size);
+unsigned LzmaEnc_IsWriteEndMark(CLzmaEncHandle p);
+
+SRes LzmaEnc_Encode(CLzmaEncHandle p, ISeqOutStreamPtr outStream, ISeqInStreamPtr inStream,
+ ICompressProgressPtr progress, ISzAllocPtr alloc, ISzAllocPtr allocBig);
+SRes LzmaEnc_MemEncode(CLzmaEncHandle p, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
+ int writeEndMark, ICompressProgressPtr progress, ISzAllocPtr alloc, ISzAllocPtr allocBig);
+
+
+/* ---------- One Call Interface ---------- */
+
+SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
+ const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
+ ICompressProgressPtr progress, ISzAllocPtr alloc, ISzAllocPtr allocBig);
+
+EXTERN_C_END
+
+#endif
diff --git a/deps/libchdr/deps/lzma-24.05/include/Precomp.h b/deps/libchdr/deps/lzma-24.05/include/Precomp.h
new file mode 100644
index 00000000..7747fdd7
--- /dev/null
+++ b/deps/libchdr/deps/lzma-24.05/include/Precomp.h
@@ -0,0 +1,127 @@
+/* Precomp.h -- precompilation file
+2024-01-25 : Igor Pavlov : Public domain */
+
+#ifndef ZIP7_INC_PRECOMP_H
+#define ZIP7_INC_PRECOMP_H
+
+/*
+ this file must be included before another *.h files and before .
+ this file is included from the following files:
+ C\*.c
+ C\Util\*\Precomp.h <- C\Util\*\*.c
+ CPP\Common\Common.h <- *\StdAfx.h <- *\*.cpp
+
+ this file can set the following macros:
+ Z7_LARGE_PAGES 1
+ Z7_LONG_PATH 1
+ Z7_WIN32_WINNT_MIN 0x0500 (or higher) : we require at least win2000+ for 7-Zip
+ _WIN32_WINNT 0x0500 (or higher)
+ WINVER _WIN32_WINNT
+ UNICODE 1
+ _UNICODE 1
+*/
+
+#include "Compiler.h"
+
+#ifdef _MSC_VER
+// #pragma warning(disable : 4206) // nonstandard extension used : translation unit is empty
+#if _MSC_VER >= 1912
+// #pragma warning(disable : 5039) // pointer or reference to potentially throwing function passed to 'extern "C"' function under - EHc.Undefined behavior may occur if this function throws an exception.
+#endif
+#endif
+
+/*
+// for debug:
+#define UNICODE 1
+#define _UNICODE 1
+#define _WIN32_WINNT 0x0500 // win2000
+#ifndef WINVER
+ #define WINVER _WIN32_WINNT
+#endif
+*/
+
+#ifdef _WIN32
+/*
+ this "Precomp.h" file must be included before ,
+ if we want to define _WIN32_WINNT before .
+*/
+
+#ifndef Z7_LARGE_PAGES
+#ifndef Z7_NO_LARGE_PAGES
+#define Z7_LARGE_PAGES 1
+#endif
+#endif
+
+#ifndef Z7_LONG_PATH
+#ifndef Z7_NO_LONG_PATH
+#define Z7_LONG_PATH 1
+#endif
+#endif
+
+#ifndef Z7_DEVICE_FILE
+#ifndef Z7_NO_DEVICE_FILE
+// #define Z7_DEVICE_FILE 1
+#endif
+#endif
+
+// we don't change macros if included after
+#ifndef _WINDOWS_
+
+#ifndef Z7_WIN32_WINNT_MIN
+ #if defined(_M_ARM64) || defined(__aarch64__)
+ // #define Z7_WIN32_WINNT_MIN 0x0a00 // win10
+ #define Z7_WIN32_WINNT_MIN 0x0600 // vista
+ #elif defined(_M_ARM) && defined(_M_ARMT) && defined(_M_ARM_NT)
+ // #define Z7_WIN32_WINNT_MIN 0x0602 // win8
+ #define Z7_WIN32_WINNT_MIN 0x0600 // vista
+ #elif defined(_M_X64) || defined(_M_AMD64) || defined(__x86_64__) || defined(_M_IA64)
+ #define Z7_WIN32_WINNT_MIN 0x0503 // win2003
+ // #elif defined(_M_IX86) || defined(__i386__)
+ // #define Z7_WIN32_WINNT_MIN 0x0500 // win2000
+ #else // x86 and another(old) systems
+ #define Z7_WIN32_WINNT_MIN 0x0500 // win2000
+ // #define Z7_WIN32_WINNT_MIN 0x0502 // win2003 // for debug
+ #endif
+#endif // Z7_WIN32_WINNT_MIN
+
+
+#ifndef Z7_DO_NOT_DEFINE_WIN32_WINNT
+#ifdef _WIN32_WINNT
+ // #error Stop_Compiling_Bad_WIN32_WINNT
+#else
+ #ifndef Z7_NO_DEFINE_WIN32_WINNT
+Z7_DIAGNOSTIC_IGNORE_BEGIN_RESERVED_MACRO_IDENTIFIER
+ #define _WIN32_WINNT Z7_WIN32_WINNT_MIN
+Z7_DIAGNOSTIC_IGNORE_END_RESERVED_MACRO_IDENTIFIER
+ #endif
+#endif // _WIN32_WINNT
+
+#ifndef WINVER
+ #define WINVER _WIN32_WINNT
+#endif
+#endif // Z7_DO_NOT_DEFINE_WIN32_WINNT
+
+
+#ifndef _MBCS
+#ifndef Z7_NO_UNICODE
+// UNICODE and _UNICODE are used by and by 7-zip code.
+
+#ifndef UNICODE
+#define UNICODE 1
+#endif
+
+#ifndef _UNICODE
+Z7_DIAGNOSTIC_IGNORE_BEGIN_RESERVED_MACRO_IDENTIFIER
+#define _UNICODE 1
+Z7_DIAGNOSTIC_IGNORE_END_RESERVED_MACRO_IDENTIFIER
+#endif
+
+#endif // Z7_NO_UNICODE
+#endif // _MBCS
+#endif // _WINDOWS_
+
+// #include "7zWindows.h"
+
+#endif // _WIN32
+
+#endif
diff --git a/deps/libchdr/deps/lzma-24.05/include/RotateDefs.h b/deps/libchdr/deps/lzma-24.05/include/RotateDefs.h
new file mode 100644
index 00000000..c16b4f8e
--- /dev/null
+++ b/deps/libchdr/deps/lzma-24.05/include/RotateDefs.h
@@ -0,0 +1,50 @@
+/* RotateDefs.h -- Rotate functions
+2023-06-18 : Igor Pavlov : Public domain */
+
+#ifndef ZIP7_INC_ROTATE_DEFS_H
+#define ZIP7_INC_ROTATE_DEFS_H
+
+#ifdef _MSC_VER
+
+#include
+
+/* don't use _rotl with old MINGW. It can insert slow call to function. */
+
+/* #if (_MSC_VER >= 1200) */
+#pragma intrinsic(_rotl)
+#pragma intrinsic(_rotr)
+/* #endif */
+
+#define rotlFixed(x, n) _rotl((x), (n))
+#define rotrFixed(x, n) _rotr((x), (n))
+
+#if (_MSC_VER >= 1300)
+#define Z7_ROTL64(x, n) _rotl64((x), (n))
+#define Z7_ROTR64(x, n) _rotr64((x), (n))
+#else
+#define Z7_ROTL64(x, n) (((x) << (n)) | ((x) >> (64 - (n))))
+#define Z7_ROTR64(x, n) (((x) >> (n)) | ((x) << (64 - (n))))
+#endif
+
+#else
+
+/* new compilers can translate these macros to fast commands. */
+
+#if defined(__clang__) && (__clang_major__ >= 4) \
+ || defined(__GNUC__) && (__GNUC__ >= 5)
+/* GCC 4.9.0 and clang 3.5 can recognize more correct version: */
+#define rotlFixed(x, n) (((x) << (n)) | ((x) >> (-(n) & 31)))
+#define rotrFixed(x, n) (((x) >> (n)) | ((x) << (-(n) & 31)))
+#define Z7_ROTL64(x, n) (((x) << (n)) | ((x) >> (-(n) & 63)))
+#define Z7_ROTR64(x, n) (((x) >> (n)) | ((x) << (-(n) & 63)))
+#else
+/* for old GCC / clang: */
+#define rotlFixed(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
+#define rotrFixed(x, n) (((x) >> (n)) | ((x) << (32 - (n))))
+#define Z7_ROTL64(x, n) (((x) << (n)) | ((x) >> (64 - (n))))
+#define Z7_ROTR64(x, n) (((x) >> (n)) | ((x) << (64 - (n))))
+#endif
+
+#endif
+
+#endif
diff --git a/deps/libchdr/deps/lzma-19.00/include/Sort.h b/deps/libchdr/deps/lzma-24.05/include/Sort.h
similarity index 71%
rename from deps/libchdr/deps/lzma-19.00/include/Sort.h
rename to deps/libchdr/deps/lzma-24.05/include/Sort.h
index 2e2963a2..1817b652 100644
--- a/deps/libchdr/deps/lzma-19.00/include/Sort.h
+++ b/deps/libchdr/deps/lzma-24.05/include/Sort.h
@@ -1,8 +1,8 @@
/* Sort.h -- Sort functions
-2014-04-05 : Igor Pavlov : Public domain */
+2023-03-05 : Igor Pavlov : Public domain */
-#ifndef __7Z_SORT_H
-#define __7Z_SORT_H
+#ifndef ZIP7_INC_SORT_H
+#define ZIP7_INC_SORT_H
#include "7zTypes.h"
diff --git a/deps/libchdr/deps/lzma-22.01/src/Alloc.c b/deps/libchdr/deps/lzma-24.05/src/Alloc.c
similarity index 55%
rename from deps/libchdr/deps/lzma-22.01/src/Alloc.c
rename to deps/libchdr/deps/lzma-24.05/src/Alloc.c
index 0d0107c5..63e1a121 100644
--- a/deps/libchdr/deps/lzma-22.01/src/Alloc.c
+++ b/deps/libchdr/deps/lzma-24.05/src/Alloc.c
@@ -1,463 +1,605 @@
-/* Alloc.c -- Memory allocation functions
-2021-07-13 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#include
-
-#ifdef _WIN32
-#include
-#endif
-#include
-
-#include "Alloc.h"
-
-/* #define _SZ_ALLOC_DEBUG */
-
-/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */
-#ifdef _SZ_ALLOC_DEBUG
-
-#include
-int g_allocCount = 0;
-int g_allocCountMid = 0;
-int g_allocCountBig = 0;
-
-
-#define CONVERT_INT_TO_STR(charType, tempSize) \
- unsigned char temp[tempSize]; unsigned i = 0; \
- while (val >= 10) { temp[i++] = (unsigned char)('0' + (unsigned)(val % 10)); val /= 10; } \
- *s++ = (charType)('0' + (unsigned)val); \
- while (i != 0) { i--; *s++ = temp[i]; } \
- *s = 0;
-
-static void ConvertUInt64ToString(UInt64 val, char *s)
-{
- CONVERT_INT_TO_STR(char, 24);
-}
-
-#define GET_HEX_CHAR(t) ((char)(((t < 10) ? ('0' + t) : ('A' + (t - 10)))))
-
-static void ConvertUInt64ToHex(UInt64 val, char *s)
-{
- UInt64 v = val;
- unsigned i;
- for (i = 1;; i++)
- {
- v >>= 4;
- if (v == 0)
- break;
- }
- s[i] = 0;
- do
- {
- unsigned t = (unsigned)(val & 0xF);
- val >>= 4;
- s[--i] = GET_HEX_CHAR(t);
- }
- while (i);
-}
-
-#define DEBUG_OUT_STREAM stderr
-
-static void Print(const char *s)
-{
- fputs(s, DEBUG_OUT_STREAM);
-}
-
-static void PrintAligned(const char *s, size_t align)
-{
- size_t len = strlen(s);
- for(;;)
- {
- fputc(' ', DEBUG_OUT_STREAM);
- if (len >= align)
- break;
- ++len;
- }
- Print(s);
-}
-
-static void PrintLn()
-{
- Print("\n");
-}
-
-static void PrintHex(UInt64 v, size_t align)
-{
- char s[32];
- ConvertUInt64ToHex(v, s);
- PrintAligned(s, align);
-}
-
-static void PrintDec(UInt64 v, size_t align)
-{
- char s[32];
- ConvertUInt64ToString(v, s);
- PrintAligned(s, align);
-}
-
-static void PrintAddr(void *p)
-{
- PrintHex((UInt64)(size_t)(ptrdiff_t)p, 12);
-}
-
-
-#define PRINT_ALLOC(name, cnt, size, ptr) \
- Print(name " "); \
- PrintDec(cnt++, 10); \
- PrintHex(size, 10); \
- PrintAddr(ptr); \
- PrintLn();
-
-#define PRINT_FREE(name, cnt, ptr) if (ptr) { \
- Print(name " "); \
- PrintDec(--cnt, 10); \
- PrintAddr(ptr); \
- PrintLn(); }
-
-#else
-
-#define PRINT_ALLOC(name, cnt, size, ptr)
-#define PRINT_FREE(name, cnt, ptr)
-#define Print(s)
-#define PrintLn()
-#define PrintHex(v, align)
-#define PrintAddr(p)
-
-#endif
-
-
-
-void *MyAlloc(size_t size)
-{
- if (size == 0)
- return NULL;
- PRINT_ALLOC("Alloc ", g_allocCount, size, NULL);
- #ifdef _SZ_ALLOC_DEBUG
- {
- void *p = malloc(size);
- // PRINT_ALLOC("Alloc ", g_allocCount, size, p);
- return p;
- }
- #else
- return malloc(size);
- #endif
-}
-
-void MyFree(void *address)
-{
- PRINT_FREE("Free ", g_allocCount, address);
-
- free(address);
-}
-
-#ifdef _WIN32
-
-void *MidAlloc(size_t size)
-{
- if (size == 0)
- return NULL;
-
- PRINT_ALLOC("Alloc-Mid", g_allocCountMid, size, NULL);
-
- return VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE);
-}
-
-void MidFree(void *address)
-{
- PRINT_FREE("Free-Mid", g_allocCountMid, address);
-
- if (!address)
- return;
- VirtualFree(address, 0, MEM_RELEASE);
-}
-
-#ifdef _7ZIP_LARGE_PAGES
-
-#ifdef MEM_LARGE_PAGES
- #define MY__MEM_LARGE_PAGES MEM_LARGE_PAGES
-#else
- #define MY__MEM_LARGE_PAGES 0x20000000
-#endif
-
-extern
-SIZE_T g_LargePageSize;
-SIZE_T g_LargePageSize = 0;
-typedef SIZE_T (WINAPI *GetLargePageMinimumP)(VOID);
-
-#endif // _7ZIP_LARGE_PAGES
-
-void SetLargePageSize()
-{
- #ifdef _7ZIP_LARGE_PAGES
- SIZE_T size;
- GetLargePageMinimumP largePageMinimum = (GetLargePageMinimumP)
- GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetLargePageMinimum");
- if (!largePageMinimum)
- return;
- size = largePageMinimum();
- if (size == 0 || (size & (size - 1)) != 0)
- return;
- g_LargePageSize = size;
- #endif
-}
-
-
-void *BigAlloc(size_t size)
-{
- if (size == 0)
- return NULL;
-
- PRINT_ALLOC("Alloc-Big", g_allocCountBig, size, NULL);
-
- #ifdef _7ZIP_LARGE_PAGES
- {
- SIZE_T ps = g_LargePageSize;
- if (ps != 0 && ps <= (1 << 30) && size > (ps / 2))
- {
- size_t size2;
- ps--;
- size2 = (size + ps) & ~ps;
- if (size2 >= size)
- {
- void *res = VirtualAlloc(NULL, size2, MEM_COMMIT | MY__MEM_LARGE_PAGES, PAGE_READWRITE);
- if (res)
- return res;
- }
- }
- }
- #endif
-
- return VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE);
-}
-
-void BigFree(void *address)
-{
- PRINT_FREE("Free-Big", g_allocCountBig, address);
-
- if (!address)
- return;
- VirtualFree(address, 0, MEM_RELEASE);
-}
-
-#endif
-
-
-static void *SzAlloc(ISzAllocPtr p, size_t size) { UNUSED_VAR(p); return MyAlloc(size); }
-static void SzFree(ISzAllocPtr p, void *address) { UNUSED_VAR(p); MyFree(address); }
-const ISzAlloc g_Alloc = { SzAlloc, SzFree };
-
-#ifdef _WIN32
-static void *SzMidAlloc(ISzAllocPtr p, size_t size) { UNUSED_VAR(p); return MidAlloc(size); }
-static void SzMidFree(ISzAllocPtr p, void *address) { UNUSED_VAR(p); MidFree(address); }
-static void *SzBigAlloc(ISzAllocPtr p, size_t size) { UNUSED_VAR(p); return BigAlloc(size); }
-static void SzBigFree(ISzAllocPtr p, void *address) { UNUSED_VAR(p); BigFree(address); }
-const ISzAlloc g_MidAlloc = { SzMidAlloc, SzMidFree };
-const ISzAlloc g_BigAlloc = { SzBigAlloc, SzBigFree };
-#endif
-
-/*
- uintptr_t : C99 (optional)
- : unsupported in VS6
-*/
-
-#ifdef _WIN32
- typedef UINT_PTR UIntPtr;
-#else
- /*
- typedef uintptr_t UIntPtr;
- */
- typedef ptrdiff_t UIntPtr;
-#endif
-
-
-#define ADJUST_ALLOC_SIZE 0
-/*
-#define ADJUST_ALLOC_SIZE (sizeof(void *) - 1)
-*/
-/*
- Use (ADJUST_ALLOC_SIZE = (sizeof(void *) - 1)), if
- MyAlloc() can return address that is NOT multiple of sizeof(void *).
-*/
-
-
-/*
-#define MY_ALIGN_PTR_DOWN(p, align) ((void *)((char *)(p) - ((size_t)(UIntPtr)(p) & ((align) - 1))))
-*/
-#define MY_ALIGN_PTR_DOWN(p, align) ((void *)((((UIntPtr)(p)) & ~((UIntPtr)(align) - 1))))
-
-
-#if !defined(_WIN32) && defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L)
- #define USE_posix_memalign
-#endif
-
-#ifndef USE_posix_memalign
-#define MY_ALIGN_PTR_UP_PLUS(p, align) MY_ALIGN_PTR_DOWN(((char *)(p) + (align) + ADJUST_ALLOC_SIZE), align)
-#endif
-
-/*
- This posix_memalign() is for test purposes only.
- We also need special Free() function instead of free(),
- if this posix_memalign() is used.
-*/
-
-/*
-static int posix_memalign(void **ptr, size_t align, size_t size)
-{
- size_t newSize = size + align;
- void *p;
- void *pAligned;
- *ptr = NULL;
- if (newSize < size)
- return 12; // ENOMEM
- p = MyAlloc(newSize);
- if (!p)
- return 12; // ENOMEM
- pAligned = MY_ALIGN_PTR_UP_PLUS(p, align);
- ((void **)pAligned)[-1] = p;
- *ptr = pAligned;
- return 0;
-}
-*/
-
-/*
- ALLOC_ALIGN_SIZE >= sizeof(void *)
- ALLOC_ALIGN_SIZE >= cache_line_size
-*/
-
-#define ALLOC_ALIGN_SIZE ((size_t)1 << 7)
-
-static void *SzAlignedAlloc(ISzAllocPtr pp, size_t size)
-{
- #ifndef USE_posix_memalign
-
- void *p;
- void *pAligned;
- size_t newSize;
- UNUSED_VAR(pp);
-
- /* also we can allocate additional dummy ALLOC_ALIGN_SIZE bytes after aligned
- block to prevent cache line sharing with another allocated blocks */
-
- newSize = size + ALLOC_ALIGN_SIZE * 1 + ADJUST_ALLOC_SIZE;
- if (newSize < size)
- return NULL;
-
- p = MyAlloc(newSize);
-
- if (!p)
- return NULL;
- pAligned = MY_ALIGN_PTR_UP_PLUS(p, ALLOC_ALIGN_SIZE);
-
- Print(" size="); PrintHex(size, 8);
- Print(" a_size="); PrintHex(newSize, 8);
- Print(" ptr="); PrintAddr(p);
- Print(" a_ptr="); PrintAddr(pAligned);
- PrintLn();
-
- ((void **)pAligned)[-1] = p;
-
- return pAligned;
-
- #else
-
- void *p;
- UNUSED_VAR(pp);
- if (posix_memalign(&p, ALLOC_ALIGN_SIZE, size))
- return NULL;
-
- Print(" posix_memalign="); PrintAddr(p);
- PrintLn();
-
- return p;
-
- #endif
-}
-
-
-static void SzAlignedFree(ISzAllocPtr pp, void *address)
-{
- UNUSED_VAR(pp);
- #ifndef USE_posix_memalign
- if (address)
- MyFree(((void **)address)[-1]);
- #else
- free(address);
- #endif
-}
-
-
-const ISzAlloc g_AlignedAlloc = { SzAlignedAlloc, SzAlignedFree };
-
-
-
-#define MY_ALIGN_PTR_DOWN_1(p) MY_ALIGN_PTR_DOWN(p, sizeof(void *))
-
-/* we align ptr to support cases where CAlignOffsetAlloc::offset is not multiply of sizeof(void *) */
-#define REAL_BLOCK_PTR_VAR(p) ((void **)MY_ALIGN_PTR_DOWN_1(p))[-1]
-/*
-#define REAL_BLOCK_PTR_VAR(p) ((void **)(p))[-1]
-*/
-
-static void *AlignOffsetAlloc_Alloc(ISzAllocPtr pp, size_t size)
-{
- CAlignOffsetAlloc *p = CONTAINER_FROM_VTBL(pp, CAlignOffsetAlloc, vt);
- void *adr;
- void *pAligned;
- size_t newSize;
- size_t extra;
- size_t alignSize = (size_t)1 << p->numAlignBits;
-
- if (alignSize < sizeof(void *))
- alignSize = sizeof(void *);
-
- if (p->offset >= alignSize)
- return NULL;
-
- /* also we can allocate additional dummy ALLOC_ALIGN_SIZE bytes after aligned
- block to prevent cache line sharing with another allocated blocks */
- extra = p->offset & (sizeof(void *) - 1);
- newSize = size + alignSize + extra + ADJUST_ALLOC_SIZE;
- if (newSize < size)
- return NULL;
-
- adr = ISzAlloc_Alloc(p->baseAlloc, newSize);
-
- if (!adr)
- return NULL;
-
- pAligned = (char *)MY_ALIGN_PTR_DOWN((char *)adr +
- alignSize - p->offset + extra + ADJUST_ALLOC_SIZE, alignSize) + p->offset;
-
- PrintLn();
- Print("- Aligned: ");
- Print(" size="); PrintHex(size, 8);
- Print(" a_size="); PrintHex(newSize, 8);
- Print(" ptr="); PrintAddr(adr);
- Print(" a_ptr="); PrintAddr(pAligned);
- PrintLn();
-
- REAL_BLOCK_PTR_VAR(pAligned) = adr;
-
- return pAligned;
-}
-
-
-static void AlignOffsetAlloc_Free(ISzAllocPtr pp, void *address)
-{
- if (address)
- {
- CAlignOffsetAlloc *p = CONTAINER_FROM_VTBL(pp, CAlignOffsetAlloc, vt);
- PrintLn();
- Print("- Aligned Free: ");
- PrintLn();
- ISzAlloc_Free(p->baseAlloc, REAL_BLOCK_PTR_VAR(address));
- }
-}
-
-
-void AlignOffsetAlloc_CreateVTable(CAlignOffsetAlloc *p)
-{
- p->vt.Alloc = AlignOffsetAlloc_Alloc;
- p->vt.Free = AlignOffsetAlloc_Free;
-}
+/* Alloc.c -- Memory allocation functions
+2024-02-18 : Igor Pavlov : Public domain */
+
+#include "Precomp.h"
+
+#ifdef _WIN32
+#include "7zWindows.h"
+#endif
+#include
+
+#include "Alloc.h"
+
+#if defined(Z7_LARGE_PAGES) && defined(_WIN32) && \
+ (!defined(Z7_WIN32_WINNT_MIN) || Z7_WIN32_WINNT_MIN < 0x0502) // < Win2003 (xp-64)
+ #define Z7_USE_DYN_GetLargePageMinimum
+#endif
+
+// for debug:
+#if 0
+#if defined(__CHERI__) && defined(__SIZEOF_POINTER__) && (__SIZEOF_POINTER__ == 16)
+// #pragma message("=== Z7_ALLOC_NO_OFFSET_ALLOCATOR === ")
+#define Z7_ALLOC_NO_OFFSET_ALLOCATOR
+#endif
+#endif
+
+// #define SZ_ALLOC_DEBUG
+/* #define SZ_ALLOC_DEBUG */
+
+/* use SZ_ALLOC_DEBUG to debug alloc/free operations */
+#ifdef SZ_ALLOC_DEBUG
+
+#include
+#include
+static int g_allocCount = 0;
+#ifdef _WIN32
+static int g_allocCountMid = 0;
+static int g_allocCountBig = 0;
+#endif
+
+
+#define CONVERT_INT_TO_STR(charType, tempSize) \
+ char temp[tempSize]; unsigned i = 0; \
+ while (val >= 10) { temp[i++] = (char)('0' + (unsigned)(val % 10)); val /= 10; } \
+ *s++ = (charType)('0' + (unsigned)val); \
+ while (i != 0) { i--; *s++ = temp[i]; } \
+ *s = 0;
+
+static void ConvertUInt64ToString(UInt64 val, char *s)
+{
+ CONVERT_INT_TO_STR(char, 24)
+}
+
+#define GET_HEX_CHAR(t) ((char)(((t < 10) ? ('0' + t) : ('A' + (t - 10)))))
+
+static void ConvertUInt64ToHex(UInt64 val, char *s)
+{
+ UInt64 v = val;
+ unsigned i;
+ for (i = 1;; i++)
+ {
+ v >>= 4;
+ if (v == 0)
+ break;
+ }
+ s[i] = 0;
+ do
+ {
+ unsigned t = (unsigned)(val & 0xF);
+ val >>= 4;
+ s[--i] = GET_HEX_CHAR(t);
+ }
+ while (i);
+}
+
+#define DEBUG_OUT_STREAM stderr
+
+static void Print(const char *s)
+{
+ fputs(s, DEBUG_OUT_STREAM);
+}
+
+static void PrintAligned(const char *s, size_t align)
+{
+ size_t len = strlen(s);
+ for(;;)
+ {
+ fputc(' ', DEBUG_OUT_STREAM);
+ if (len >= align)
+ break;
+ ++len;
+ }
+ Print(s);
+}
+
+static void PrintLn(void)
+{
+ Print("\n");
+}
+
+static void PrintHex(UInt64 v, size_t align)
+{
+ char s[32];
+ ConvertUInt64ToHex(v, s);
+ PrintAligned(s, align);
+}
+
+static void PrintDec(int v, size_t align)
+{
+ char s[32];
+ ConvertUInt64ToString((unsigned)v, s);
+ PrintAligned(s, align);
+}
+
+static void PrintAddr(void *p)
+{
+ PrintHex((UInt64)(size_t)(ptrdiff_t)p, 12);
+}
+
+
+#define PRINT_REALLOC(name, cnt, size, ptr) { \
+ Print(name " "); \
+ if (!ptr) PrintDec(cnt++, 10); \
+ PrintHex(size, 10); \
+ PrintAddr(ptr); \
+ PrintLn(); }
+
+#define PRINT_ALLOC(name, cnt, size, ptr) { \
+ Print(name " "); \
+ PrintDec(cnt++, 10); \
+ PrintHex(size, 10); \
+ PrintAddr(ptr); \
+ PrintLn(); }
+
+#define PRINT_FREE(name, cnt, ptr) if (ptr) { \
+ Print(name " "); \
+ PrintDec(--cnt, 10); \
+ PrintAddr(ptr); \
+ PrintLn(); }
+
+#else
+
+#ifdef _WIN32
+#define PRINT_ALLOC(name, cnt, size, ptr)
+#endif
+#define PRINT_FREE(name, cnt, ptr)
+#define Print(s)
+#define PrintLn()
+#ifndef Z7_ALLOC_NO_OFFSET_ALLOCATOR
+#define PrintHex(v, align)
+#endif
+#define PrintAddr(p)
+
+#endif
+
+
+/*
+by specification:
+ malloc(non_NULL, 0) : returns NULL or a unique pointer value that can later be successfully passed to free()
+ realloc(NULL, size) : the call is equivalent to malloc(size)
+ realloc(non_NULL, 0) : the call is equivalent to free(ptr)
+
+in main compilers:
+ malloc(0) : returns non_NULL
+ realloc(NULL, 0) : returns non_NULL
+ realloc(non_NULL, 0) : returns NULL
+*/
+
+
+void *MyAlloc(size_t size)
+{
+ if (size == 0)
+ return NULL;
+ // PRINT_ALLOC("Alloc ", g_allocCount, size, NULL)
+ #ifdef SZ_ALLOC_DEBUG
+ {
+ void *p = malloc(size);
+ if (p)
+ {
+ PRINT_ALLOC("Alloc ", g_allocCount, size, p)
+ }
+ return p;
+ }
+ #else
+ return malloc(size);
+ #endif
+}
+
+void MyFree(void *address)
+{
+ PRINT_FREE("Free ", g_allocCount, address)
+
+ free(address);
+}
+
+void *MyRealloc(void *address, size_t size)
+{
+ if (size == 0)
+ {
+ MyFree(address);
+ return NULL;
+ }
+ // PRINT_REALLOC("Realloc ", g_allocCount, size, address)
+ #ifdef SZ_ALLOC_DEBUG
+ {
+ void *p = realloc(address, size);
+ if (p)
+ {
+ PRINT_REALLOC("Realloc ", g_allocCount, size, address)
+ }
+ return p;
+ }
+ #else
+ return realloc(address, size);
+ #endif
+}
+
+
+#ifdef _WIN32
+
+void *MidAlloc(size_t size)
+{
+ if (size == 0)
+ return NULL;
+ #ifdef SZ_ALLOC_DEBUG
+ {
+ void *p = VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE);
+ if (p)
+ {
+ PRINT_ALLOC("Alloc-Mid", g_allocCountMid, size, p)
+ }
+ return p;
+ }
+ #else
+ return VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE);
+ #endif
+}
+
+void MidFree(void *address)
+{
+ PRINT_FREE("Free-Mid", g_allocCountMid, address)
+
+ if (!address)
+ return;
+ VirtualFree(address, 0, MEM_RELEASE);
+}
+
+#ifdef Z7_LARGE_PAGES
+
+#ifdef MEM_LARGE_PAGES
+ #define MY_MEM_LARGE_PAGES MEM_LARGE_PAGES
+#else
+ #define MY_MEM_LARGE_PAGES 0x20000000
+#endif
+
+extern
+SIZE_T g_LargePageSize;
+SIZE_T g_LargePageSize = 0;
+typedef SIZE_T (WINAPI *Func_GetLargePageMinimum)(VOID);
+
+void SetLargePageSize(void)
+{
+ SIZE_T size;
+#ifdef Z7_USE_DYN_GetLargePageMinimum
+Z7_DIAGNOSTIC_IGNORE_CAST_FUNCTION
+
+ const
+ Func_GetLargePageMinimum fn =
+ (Func_GetLargePageMinimum) Z7_CAST_FUNC_C GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")),
+ "GetLargePageMinimum");
+ if (!fn)
+ return;
+ size = fn();
+#else
+ size = GetLargePageMinimum();
+#endif
+ if (size == 0 || (size & (size - 1)) != 0)
+ return;
+ g_LargePageSize = size;
+}
+
+#endif // Z7_LARGE_PAGES
+
+void *BigAlloc(size_t size)
+{
+ if (size == 0)
+ return NULL;
+
+ PRINT_ALLOC("Alloc-Big", g_allocCountBig, size, NULL)
+
+ #ifdef Z7_LARGE_PAGES
+ {
+ SIZE_T ps = g_LargePageSize;
+ if (ps != 0 && ps <= (1 << 30) && size > (ps / 2))
+ {
+ size_t size2;
+ ps--;
+ size2 = (size + ps) & ~ps;
+ if (size2 >= size)
+ {
+ void *p = VirtualAlloc(NULL, size2, MEM_COMMIT | MY_MEM_LARGE_PAGES, PAGE_READWRITE);
+ if (p)
+ {
+ PRINT_ALLOC("Alloc-BM ", g_allocCountMid, size2, p)
+ return p;
+ }
+ }
+ }
+ }
+ #endif
+
+ return MidAlloc(size);
+}
+
+void BigFree(void *address)
+{
+ PRINT_FREE("Free-Big", g_allocCountBig, address)
+ MidFree(address);
+}
+
+#endif // _WIN32
+
+
+static void *SzAlloc(ISzAllocPtr p, size_t size) { UNUSED_VAR(p) return MyAlloc(size); }
+static void SzFree(ISzAllocPtr p, void *address) { UNUSED_VAR(p) MyFree(address); }
+const ISzAlloc g_Alloc = { SzAlloc, SzFree };
+
+#ifdef _WIN32
+static void *SzMidAlloc(ISzAllocPtr p, size_t size) { UNUSED_VAR(p) return MidAlloc(size); }
+static void SzMidFree(ISzAllocPtr p, void *address) { UNUSED_VAR(p) MidFree(address); }
+static void *SzBigAlloc(ISzAllocPtr p, size_t size) { UNUSED_VAR(p) return BigAlloc(size); }
+static void SzBigFree(ISzAllocPtr p, void *address) { UNUSED_VAR(p) BigFree(address); }
+const ISzAlloc g_MidAlloc = { SzMidAlloc, SzMidFree };
+const ISzAlloc g_BigAlloc = { SzBigAlloc, SzBigFree };
+#endif
+
+#ifndef Z7_ALLOC_NO_OFFSET_ALLOCATOR
+
+#define ADJUST_ALLOC_SIZE 0
+/*
+#define ADJUST_ALLOC_SIZE (sizeof(void *) - 1)
+*/
+/*
+ Use (ADJUST_ALLOC_SIZE = (sizeof(void *) - 1)), if
+ MyAlloc() can return address that is NOT multiple of sizeof(void *).
+*/
+
+/*
+ uintptr_t : C99 (optional)
+ : unsupported in VS6
+*/
+typedef
+ #ifdef _WIN32
+ UINT_PTR
+ #elif 1
+ uintptr_t
+ #else
+ ptrdiff_t
+ #endif
+ MY_uintptr_t;
+
+#if 0 \
+ || (defined(__CHERI__) \
+ || defined(__SIZEOF_POINTER__) && (__SIZEOF_POINTER__ > 8))
+// for 128-bit pointers (cheri):
+#define MY_ALIGN_PTR_DOWN(p, align) \
+ ((void *)((char *)(p) - ((size_t)(MY_uintptr_t)(p) & ((align) - 1))))
+#else
+#define MY_ALIGN_PTR_DOWN(p, align) \
+ ((void *)((((MY_uintptr_t)(p)) & ~((MY_uintptr_t)(align) - 1))))
+#endif
+
+#endif
+
+#if !defined(_WIN32) \
+ && (defined(Z7_ALLOC_NO_OFFSET_ALLOCATOR) \
+ || defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L))
+ #define USE_posix_memalign
+#endif
+
+#ifndef USE_posix_memalign
+#define MY_ALIGN_PTR_UP_PLUS(p, align) MY_ALIGN_PTR_DOWN(((char *)(p) + (align) + ADJUST_ALLOC_SIZE), align)
+#endif
+
+/*
+ This posix_memalign() is for test purposes only.
+ We also need special Free() function instead of free(),
+ if this posix_memalign() is used.
+*/
+
+/*
+static int posix_memalign(void **ptr, size_t align, size_t size)
+{
+ size_t newSize = size + align;
+ void *p;
+ void *pAligned;
+ *ptr = NULL;
+ if (newSize < size)
+ return 12; // ENOMEM
+ p = MyAlloc(newSize);
+ if (!p)
+ return 12; // ENOMEM
+ pAligned = MY_ALIGN_PTR_UP_PLUS(p, align);
+ ((void **)pAligned)[-1] = p;
+ *ptr = pAligned;
+ return 0;
+}
+*/
+
+/*
+ ALLOC_ALIGN_SIZE >= sizeof(void *)
+ ALLOC_ALIGN_SIZE >= cache_line_size
+*/
+
+#define ALLOC_ALIGN_SIZE ((size_t)1 << 7)
+
+void *z7_AlignedAlloc(size_t size)
+{
+#ifndef USE_posix_memalign
+
+ void *p;
+ void *pAligned;
+ size_t newSize;
+
+ /* also we can allocate additional dummy ALLOC_ALIGN_SIZE bytes after aligned
+ block to prevent cache line sharing with another allocated blocks */
+
+ newSize = size + ALLOC_ALIGN_SIZE * 1 + ADJUST_ALLOC_SIZE;
+ if (newSize < size)
+ return NULL;
+
+ p = MyAlloc(newSize);
+
+ if (!p)
+ return NULL;
+ pAligned = MY_ALIGN_PTR_UP_PLUS(p, ALLOC_ALIGN_SIZE);
+
+ Print(" size="); PrintHex(size, 8);
+ Print(" a_size="); PrintHex(newSize, 8);
+ Print(" ptr="); PrintAddr(p);
+ Print(" a_ptr="); PrintAddr(pAligned);
+ PrintLn();
+
+ ((void **)pAligned)[-1] = p;
+
+ return pAligned;
+
+#else
+
+ void *p;
+ if (posix_memalign(&p, ALLOC_ALIGN_SIZE, size))
+ return NULL;
+
+ Print(" posix_memalign="); PrintAddr(p);
+ PrintLn();
+
+ return p;
+
+#endif
+}
+
+
+void z7_AlignedFree(void *address)
+{
+#ifndef USE_posix_memalign
+ if (address)
+ MyFree(((void **)address)[-1]);
+#else
+ free(address);
+#endif
+}
+
+
+static void *SzAlignedAlloc(ISzAllocPtr pp, size_t size)
+{
+ UNUSED_VAR(pp)
+ return z7_AlignedAlloc(size);
+}
+
+
+static void SzAlignedFree(ISzAllocPtr pp, void *address)
+{
+ UNUSED_VAR(pp)
+#ifndef USE_posix_memalign
+ if (address)
+ MyFree(((void **)address)[-1]);
+#else
+ free(address);
+#endif
+}
+
+
+const ISzAlloc g_AlignedAlloc = { SzAlignedAlloc, SzAlignedFree };
+
+
+
+/* we align ptr to support cases where CAlignOffsetAlloc::offset is not multiply of sizeof(void *) */
+#ifndef Z7_ALLOC_NO_OFFSET_ALLOCATOR
+#if 1
+ #define MY_ALIGN_PTR_DOWN_1(p) MY_ALIGN_PTR_DOWN(p, sizeof(void *))
+ #define REAL_BLOCK_PTR_VAR(p) ((void **)MY_ALIGN_PTR_DOWN_1(p))[-1]
+#else
+ // we can use this simplified code,
+ // if (CAlignOffsetAlloc::offset == (k * sizeof(void *))
+ #define REAL_BLOCK_PTR_VAR(p) (((void **)(p))[-1])
+#endif
+#endif
+
+
+#if 0
+#ifndef Z7_ALLOC_NO_OFFSET_ALLOCATOR
+#include
+static void PrintPtr(const char *s, const void *p)
+{
+ const Byte *p2 = (const Byte *)&p;
+ unsigned i;
+ printf("%s %p ", s, p);
+ for (i = sizeof(p); i != 0;)
+ {
+ i--;
+ printf("%02x", p2[i]);
+ }
+ printf("\n");
+}
+#endif
+#endif
+
+
+static void *AlignOffsetAlloc_Alloc(ISzAllocPtr pp, size_t size)
+{
+#if defined(Z7_ALLOC_NO_OFFSET_ALLOCATOR)
+ UNUSED_VAR(pp)
+ return z7_AlignedAlloc(size);
+#else
+ const CAlignOffsetAlloc *p = Z7_CONTAINER_FROM_VTBL_CONST(pp, CAlignOffsetAlloc, vt);
+ void *adr;
+ void *pAligned;
+ size_t newSize;
+ size_t extra;
+ size_t alignSize = (size_t)1 << p->numAlignBits;
+
+ if (alignSize < sizeof(void *))
+ alignSize = sizeof(void *);
+
+ if (p->offset >= alignSize)
+ return NULL;
+
+ /* also we can allocate additional dummy ALLOC_ALIGN_SIZE bytes after aligned
+ block to prevent cache line sharing with another allocated blocks */
+ extra = p->offset & (sizeof(void *) - 1);
+ newSize = size + alignSize + extra + ADJUST_ALLOC_SIZE;
+ if (newSize < size)
+ return NULL;
+
+ adr = ISzAlloc_Alloc(p->baseAlloc, newSize);
+
+ if (!adr)
+ return NULL;
+
+ pAligned = (char *)MY_ALIGN_PTR_DOWN((char *)adr +
+ alignSize - p->offset + extra + ADJUST_ALLOC_SIZE, alignSize) + p->offset;
+
+#if 0
+ printf("\nalignSize = %6x, offset=%6x, size=%8x \n", (unsigned)alignSize, (unsigned)p->offset, (unsigned)size);
+ PrintPtr("base", adr);
+ PrintPtr("alig", pAligned);
+#endif
+
+ PrintLn();
+ Print("- Aligned: ");
+ Print(" size="); PrintHex(size, 8);
+ Print(" a_size="); PrintHex(newSize, 8);
+ Print(" ptr="); PrintAddr(adr);
+ Print(" a_ptr="); PrintAddr(pAligned);
+ PrintLn();
+
+ REAL_BLOCK_PTR_VAR(pAligned) = adr;
+
+ return pAligned;
+#endif
+}
+
+
+static void AlignOffsetAlloc_Free(ISzAllocPtr pp, void *address)
+{
+#if defined(Z7_ALLOC_NO_OFFSET_ALLOCATOR)
+ UNUSED_VAR(pp)
+ z7_AlignedFree(address);
+#else
+ if (address)
+ {
+ const CAlignOffsetAlloc *p = Z7_CONTAINER_FROM_VTBL_CONST(pp, CAlignOffsetAlloc, vt);
+ PrintLn();
+ Print("- Aligned Free: ");
+ PrintLn();
+ ISzAlloc_Free(p->baseAlloc, REAL_BLOCK_PTR_VAR(address));
+ }
+#endif
+}
+
+
+void AlignOffsetAlloc_CreateVTable(CAlignOffsetAlloc *p)
+{
+ p->vt.Alloc = AlignOffsetAlloc_Alloc;
+ p->vt.Free = AlignOffsetAlloc_Free;
+}
diff --git a/deps/libchdr/deps/lzma-24.05/src/Bra.c b/deps/libchdr/deps/lzma-24.05/src/Bra.c
new file mode 100644
index 00000000..e61edf8f
--- /dev/null
+++ b/deps/libchdr/deps/lzma-24.05/src/Bra.c
@@ -0,0 +1,709 @@
+/* Bra.c -- Branch converters for RISC code
+2024-01-20 : Igor Pavlov : Public domain */
+
+#include "Precomp.h"
+
+#include "Bra.h"
+#include "RotateDefs.h"
+#include "CpuArch.h"
+
+#if defined(MY_CPU_SIZEOF_POINTER) \
+ && ( MY_CPU_SIZEOF_POINTER == 4 \
+ || MY_CPU_SIZEOF_POINTER == 8)
+ #define BR_CONV_USE_OPT_PC_PTR
+#endif
+
+#ifdef BR_CONV_USE_OPT_PC_PTR
+#define BR_PC_INIT pc -= (UInt32)(SizeT)p;
+#define BR_PC_GET (pc + (UInt32)(SizeT)p)
+#else
+#define BR_PC_INIT pc += (UInt32)size;
+#define BR_PC_GET (pc - (UInt32)(SizeT)(lim - p))
+// #define BR_PC_INIT
+// #define BR_PC_GET (pc + (UInt32)(SizeT)(p - data))
+#endif
+
+#define BR_CONVERT_VAL(v, c) if (encoding) v += c; else v -= c;
+// #define BR_CONVERT_VAL(v, c) if (!encoding) c = (UInt32)0 - c; v += c;
+
+#define Z7_BRANCH_CONV(name) z7_ ## name
+
+#define Z7_BRANCH_FUNC_MAIN(name) \
+static \
+Z7_FORCE_INLINE \
+Z7_ATTRIB_NO_VECTOR \
+Byte *Z7_BRANCH_CONV(name)(Byte *p, SizeT size, UInt32 pc, int encoding)
+
+#define Z7_BRANCH_FUNC_IMP(name, m, encoding) \
+Z7_NO_INLINE \
+Z7_ATTRIB_NO_VECTOR \
+Byte *m(name)(Byte *data, SizeT size, UInt32 pc) \
+ { return Z7_BRANCH_CONV(name)(data, size, pc, encoding); } \
+
+#ifdef Z7_EXTRACT_ONLY
+#define Z7_BRANCH_FUNCS_IMP(name) \
+ Z7_BRANCH_FUNC_IMP(name, Z7_BRANCH_CONV_DEC_2, 0)
+#else
+#define Z7_BRANCH_FUNCS_IMP(name) \
+ Z7_BRANCH_FUNC_IMP(name, Z7_BRANCH_CONV_DEC_2, 0) \
+ Z7_BRANCH_FUNC_IMP(name, Z7_BRANCH_CONV_ENC_2, 1)
+#endif
+
+#if defined(__clang__)
+#define BR_EXTERNAL_FOR
+#define BR_NEXT_ITERATION continue;
+#else
+#define BR_EXTERNAL_FOR for (;;)
+#define BR_NEXT_ITERATION break;
+#endif
+
+#if defined(__clang__) && (__clang_major__ >= 8) \
+ || defined(__GNUC__) && (__GNUC__ >= 1000) \
+ // GCC is not good for __builtin_expect() here
+ /* || defined(_MSC_VER) && (_MSC_VER >= 1920) */
+ // #define Z7_unlikely [[unlikely]]
+ // #define Z7_LIKELY(x) (__builtin_expect((x), 1))
+ #define Z7_UNLIKELY(x) (__builtin_expect((x), 0))
+ // #define Z7_likely [[likely]]
+#else
+ // #define Z7_LIKELY(x) (x)
+ #define Z7_UNLIKELY(x) (x)
+ // #define Z7_likely
+#endif
+
+
+Z7_BRANCH_FUNC_MAIN(BranchConv_ARM64)
+{
+ // Byte *p = data;
+ const Byte *lim;
+ const UInt32 flag = (UInt32)1 << (24 - 4);
+ const UInt32 mask = ((UInt32)1 << 24) - (flag << 1);
+ size &= ~(SizeT)3;
+ // if (size == 0) return p;
+ lim = p + size;
+ BR_PC_INIT
+ pc -= 4; // because (p) will point to next instruction
+
+ BR_EXTERNAL_FOR
+ {
+ // Z7_PRAGMA_OPT_DISABLE_LOOP_UNROLL_VECTORIZE
+ for (;;)
+ {
+ UInt32 v;
+ if Z7_UNLIKELY(p == lim)
+ return p;
+ v = GetUi32a(p);
+ p += 4;
+ if Z7_UNLIKELY(((v - 0x94000000) & 0xfc000000) == 0)
+ {
+ UInt32 c = BR_PC_GET >> 2;
+ BR_CONVERT_VAL(v, c)
+ v &= 0x03ffffff;
+ v |= 0x94000000;
+ SetUi32a(p - 4, v)
+ BR_NEXT_ITERATION
+ }
+ // v = rotlFixed(v, 8); v += (flag << 8) - 0x90; if Z7_UNLIKELY((v & ((mask << 8) + 0x9f)) == 0)
+ v -= 0x90000000; if Z7_UNLIKELY((v & 0x9f000000) == 0)
+ {
+ UInt32 z, c;
+ // v = rotrFixed(v, 8);
+ v += flag; if Z7_UNLIKELY(v & mask) continue;
+ z = (v & 0xffffffe0) | (v >> 26);
+ c = (BR_PC_GET >> (12 - 3)) & ~(UInt32)7;
+ BR_CONVERT_VAL(z, c)
+ v &= 0x1f;
+ v |= 0x90000000;
+ v |= z << 26;
+ v |= 0x00ffffe0 & ((z & (((flag << 1) - 1))) - flag);
+ SetUi32a(p - 4, v)
+ }
+ }
+ }
+}
+Z7_BRANCH_FUNCS_IMP(BranchConv_ARM64)
+
+
+Z7_BRANCH_FUNC_MAIN(BranchConv_ARM)
+{
+ // Byte *p = data;
+ const Byte *lim;
+ size &= ~(SizeT)3;
+ lim = p + size;
+ BR_PC_INIT
+ /* in ARM: branch offset is relative to the +2 instructions from current instruction.
+ (p) will point to next instruction */
+ pc += 8 - 4;
+
+ for (;;)
+ {
+ for (;;)
+ {
+ if Z7_UNLIKELY(p >= lim) { return p; } p += 4; if Z7_UNLIKELY(p[-1] == 0xeb) break;
+ if Z7_UNLIKELY(p >= lim) { return p; } p += 4; if Z7_UNLIKELY(p[-1] == 0xeb) break;
+ }
+ {
+ UInt32 v = GetUi32a(p - 4);
+ UInt32 c = BR_PC_GET >> 2;
+ BR_CONVERT_VAL(v, c)
+ v &= 0x00ffffff;
+ v |= 0xeb000000;
+ SetUi32a(p - 4, v)
+ }
+ }
+}
+Z7_BRANCH_FUNCS_IMP(BranchConv_ARM)
+
+
+Z7_BRANCH_FUNC_MAIN(BranchConv_PPC)
+{
+ // Byte *p = data;
+ const Byte *lim;
+ size &= ~(SizeT)3;
+ lim = p + size;
+ BR_PC_INIT
+ pc -= 4; // because (p) will point to next instruction
+
+ for (;;)
+ {
+ UInt32 v;
+ for (;;)
+ {
+ if Z7_UNLIKELY(p == lim)
+ return p;
+ // v = GetBe32a(p);
+ v = *(UInt32 *)(void *)p;
+ p += 4;
+ // if ((v & 0xfc000003) == 0x48000001) break;
+ // if ((p[-4] & 0xFC) == 0x48 && (p[-1] & 3) == 1) break;
+ if Z7_UNLIKELY(
+ ((v - Z7_CONV_BE_TO_NATIVE_CONST32(0x48000001))
+ & Z7_CONV_BE_TO_NATIVE_CONST32(0xfc000003)) == 0) break;
+ }
+ {
+ v = Z7_CONV_NATIVE_TO_BE_32(v);
+ {
+ UInt32 c = BR_PC_GET;
+ BR_CONVERT_VAL(v, c)
+ }
+ v &= 0x03ffffff;
+ v |= 0x48000000;
+ SetBe32a(p - 4, v)
+ }
+ }
+}
+Z7_BRANCH_FUNCS_IMP(BranchConv_PPC)
+
+
+#ifdef Z7_CPU_FAST_ROTATE_SUPPORTED
+#define BR_SPARC_USE_ROTATE
+#endif
+
+Z7_BRANCH_FUNC_MAIN(BranchConv_SPARC)
+{
+ // Byte *p = data;
+ const Byte *lim;
+ const UInt32 flag = (UInt32)1 << 22;
+ size &= ~(SizeT)3;
+ lim = p + size;
+ BR_PC_INIT
+ pc -= 4; // because (p) will point to next instruction
+ for (;;)
+ {
+ UInt32 v;
+ for (;;)
+ {
+ if Z7_UNLIKELY(p == lim)
+ return p;
+ /* // the code without GetBe32a():
+ { const UInt32 v = GetUi16a(p) & 0xc0ff; p += 4; if (v == 0x40 || v == 0xc07f) break; }
+ */
+ v = GetBe32a(p);
+ p += 4;
+ #ifdef BR_SPARC_USE_ROTATE
+ v = rotlFixed(v, 2);
+ v += (flag << 2) - 1;
+ if Z7_UNLIKELY((v & (3 - (flag << 3))) == 0)
+ #else
+ v += (UInt32)5 << 29;
+ v ^= (UInt32)7 << 29;
+ v += flag;
+ if Z7_UNLIKELY((v & (0 - (flag << 1))) == 0)
+ #endif
+ break;
+ }
+ {
+ // UInt32 v = GetBe32a(p - 4);
+ #ifndef BR_SPARC_USE_ROTATE
+ v <<= 2;
+ #endif
+ {
+ UInt32 c = BR_PC_GET;
+ BR_CONVERT_VAL(v, c)
+ }
+ v &= (flag << 3) - 1;
+ #ifdef BR_SPARC_USE_ROTATE
+ v -= (flag << 2) - 1;
+ v = rotrFixed(v, 2);
+ #else
+ v -= (flag << 2);
+ v >>= 2;
+ v |= (UInt32)1 << 30;
+ #endif
+ SetBe32a(p - 4, v)
+ }
+ }
+}
+Z7_BRANCH_FUNCS_IMP(BranchConv_SPARC)
+
+
+Z7_BRANCH_FUNC_MAIN(BranchConv_ARMT)
+{
+ // Byte *p = data;
+ Byte *lim;
+ size &= ~(SizeT)1;
+ // if (size == 0) return p;
+ if (size <= 2) return p;
+ size -= 2;
+ lim = p + size;
+ BR_PC_INIT
+ /* in ARM: branch offset is relative to the +2 instructions from current instruction.
+ (p) will point to the +2 instructions from current instruction */
+ // pc += 4 - 4;
+ // if (encoding) pc -= 0xf800 << 1; else pc += 0xf800 << 1;
+ // #define ARMT_TAIL_PROC { goto armt_tail; }
+ #define ARMT_TAIL_PROC { return p; }
+
+ do
+ {
+ /* in MSVC 32-bit x86 compilers:
+ UInt32 version : it loads value from memory with movzx
+ Byte version : it loads value to 8-bit register (AL/CL)
+ movzx version is slightly faster in some cpus
+ */
+ unsigned b1;
+ // Byte / unsigned
+ b1 = p[1];
+ // optimized version to reduce one (p >= lim) check:
+ // unsigned a1 = p[1]; b1 = p[3]; p += 2; if Z7_LIKELY((b1 & (a1 ^ 8)) < 0xf8)
+ for (;;)
+ {
+ unsigned b3; // Byte / UInt32
+ /* (Byte)(b3) normalization can use low byte computations in MSVC.
+ It gives smaller code, and no loss of speed in some compilers/cpus.
+ But new MSVC 32-bit x86 compilers use more slow load
+ from memory to low byte register in that case.
+ So we try to use full 32-bit computations for faster code.
+ */
+ // if (p >= lim) { ARMT_TAIL_PROC } b3 = b1 + 8; b1 = p[3]; p += 2; if ((b3 & b1) >= 0xf8) break;
+ if Z7_UNLIKELY(p >= lim) { ARMT_TAIL_PROC } b3 = p[3]; p += 2; if Z7_UNLIKELY((b3 & (b1 ^ 8)) >= 0xf8) break;
+ if Z7_UNLIKELY(p >= lim) { ARMT_TAIL_PROC } b1 = p[3]; p += 2; if Z7_UNLIKELY((b1 & (b3 ^ 8)) >= 0xf8) break;
+ }
+ {
+ /* we can adjust pc for (0xf800) to rid of (& 0x7FF) operation.
+ But gcc/clang for arm64 can use bfi instruction for full code here */
+ UInt32 v =
+ ((UInt32)GetUi16a(p - 2) << 11) |
+ ((UInt32)GetUi16a(p) & 0x7FF);
+ /*
+ UInt32 v =
+ ((UInt32)p[1 - 2] << 19)
+ + (((UInt32)p[1] & 0x7) << 8)
+ + (((UInt32)p[-2] << 11))
+ + (p[0]);
+ */
+ p += 2;
+ {
+ UInt32 c = BR_PC_GET >> 1;
+ BR_CONVERT_VAL(v, c)
+ }
+ SetUi16a(p - 4, (UInt16)(((v >> 11) & 0x7ff) | 0xf000))
+ SetUi16a(p - 2, (UInt16)(v | 0xf800))
+ /*
+ p[-4] = (Byte)(v >> 11);
+ p[-3] = (Byte)(0xf0 | ((v >> 19) & 0x7));
+ p[-2] = (Byte)v;
+ p[-1] = (Byte)(0xf8 | (v >> 8));
+ */
+ }
+ }
+ while (p < lim);
+ return p;
+ // armt_tail:
+ // if ((Byte)((lim[1] & 0xf8)) != 0xf0) { lim += 2; } return lim;
+ // return (Byte *)(lim + ((Byte)((lim[1] ^ 0xf0) & 0xf8) == 0 ? 0 : 2));
+ // return (Byte *)(lim + (((lim[1] ^ ~0xfu) & ~7u) == 0 ? 0 : 2));
+ // return (Byte *)(lim + 2 - (((((unsigned)lim[1] ^ 8) + 8) >> 7) & 2));
+}
+Z7_BRANCH_FUNCS_IMP(BranchConv_ARMT)
+
+
+// #define BR_IA64_NO_INLINE
+
+Z7_BRANCH_FUNC_MAIN(BranchConv_IA64)
+{
+ // Byte *p = data;
+ const Byte *lim;
+ size &= ~(SizeT)15;
+ lim = p + size;
+ pc -= 1 << 4;
+ pc >>= 4 - 1;
+ // pc -= 1 << 1;
+
+ for (;;)
+ {
+ unsigned m;
+ for (;;)
+ {
+ if Z7_UNLIKELY(p == lim)
+ return p;
+ m = (unsigned)((UInt32)0x334b0000 >> (*p & 0x1e));
+ p += 16;
+ pc += 1 << 1;
+ if (m &= 3)
+ break;
+ }
+ {
+ p += (ptrdiff_t)m * 5 - 20; // negative value is expected here.
+ do
+ {
+ const UInt32 t =
+ #if defined(MY_CPU_X86_OR_AMD64)
+ // we use 32-bit load here to reduce code size on x86:
+ GetUi32(p);
+ #else
+ GetUi16(p);
+ #endif
+ UInt32 z = GetUi32(p + 1) >> m;
+ p += 5;
+ if (((t >> m) & (0x70 << 1)) == 0
+ && ((z - (0x5000000 << 1)) & (0xf000000 << 1)) == 0)
+ {
+ UInt32 v = (UInt32)((0x8fffff << 1) | 1) & z;
+ z ^= v;
+ #ifdef BR_IA64_NO_INLINE
+ v |= (v & ((UInt32)1 << (23 + 1))) >> 3;
+ {
+ UInt32 c = pc;
+ BR_CONVERT_VAL(v, c)
+ }
+ v &= (0x1fffff << 1) | 1;
+ #else
+ {
+ if (encoding)
+ {
+ // pc &= ~(0xc00000 << 1); // we just need to clear at least 2 bits
+ pc &= (0x1fffff << 1) | 1;
+ v += pc;
+ }
+ else
+ {
+ // pc |= 0xc00000 << 1; // we need to set at least 2 bits
+ pc |= ~(UInt32)((0x1fffff << 1) | 1);
+ v -= pc;
+ }
+ }
+ v &= ~(UInt32)(0x600000 << 1);
+ #endif
+ v += (0x700000 << 1);
+ v &= (0x8fffff << 1) | 1;
+ z |= v;
+ z <<= m;
+ SetUi32(p + 1 - 5, z)
+ }
+ m++;
+ }
+ while (m &= 3); // while (m < 4);
+ }
+ }
+}
+Z7_BRANCH_FUNCS_IMP(BranchConv_IA64)
+
+
+#define BR_CONVERT_VAL_ENC(v) v += BR_PC_GET;
+#define BR_CONVERT_VAL_DEC(v) v -= BR_PC_GET;
+
+#if 1 && defined(MY_CPU_LE_UNALIGN)
+ #define RISCV_USE_UNALIGNED_LOAD
+#endif
+
+#ifdef RISCV_USE_UNALIGNED_LOAD
+ #define RISCV_GET_UI32(p) GetUi32(p)
+ #define RISCV_SET_UI32(p, v) { SetUi32(p, v) }
+#else
+ #define RISCV_GET_UI32(p) \
+ ((UInt32)GetUi16a(p) + \
+ ((UInt32)GetUi16a((p) + 2) << 16))
+ #define RISCV_SET_UI32(p, v) { \
+ SetUi16a(p, (UInt16)(v)) \
+ SetUi16a((p) + 2, (UInt16)(v >> 16)) }
+#endif
+
+#if 1 && defined(MY_CPU_LE)
+ #define RISCV_USE_16BIT_LOAD
+#endif
+
+#ifdef RISCV_USE_16BIT_LOAD
+ #define RISCV_LOAD_VAL(p) GetUi16a(p)
+#else
+ #define RISCV_LOAD_VAL(p) (*(p))
+#endif
+
+#define RISCV_INSTR_SIZE 2
+#define RISCV_STEP_1 (4 + RISCV_INSTR_SIZE)
+#define RISCV_STEP_2 4
+#define RISCV_REG_VAL (2 << 7)
+#define RISCV_CMD_VAL 3
+#if 1
+ // for code size optimization:
+ #define RISCV_DELTA_7F 0x7f
+#else
+ #define RISCV_DELTA_7F 0
+#endif
+
+#define RISCV_CHECK_1(v, b) \
+ (((((b) - RISCV_CMD_VAL) ^ ((v) << 8)) & (0xf8000 + RISCV_CMD_VAL)) == 0)
+
+#if 1
+ #define RISCV_CHECK_2(v, r) \
+ ((((v) - ((RISCV_CMD_VAL << 12) | RISCV_REG_VAL | 8)) \
+ << 18) \
+ < ((r) & 0x1d))
+#else
+ // this branch gives larger code, because
+ // compilers generate larger code for big constants.
+ #define RISCV_CHECK_2(v, r) \
+ ((((v) - ((RISCV_CMD_VAL << 12) | RISCV_REG_VAL)) \
+ & ((RISCV_CMD_VAL << 12) | RISCV_REG_VAL)) \
+ < ((r) & 0x1d))
+#endif
+
+
+#define RISCV_SCAN_LOOP \
+ Byte *lim; \
+ size &= ~(SizeT)(RISCV_INSTR_SIZE - 1); \
+ if (size <= 6) return p; \
+ size -= 6; \
+ lim = p + size; \
+ BR_PC_INIT \
+ for (;;) \
+ { \
+ UInt32 a, v; \
+ /* Z7_PRAGMA_OPT_DISABLE_LOOP_UNROLL_VECTORIZE */ \
+ for (;;) \
+ { \
+ if Z7_UNLIKELY(p >= lim) { return p; } \
+ a = (RISCV_LOAD_VAL(p) ^ 0x10u) + 1; \
+ if ((a & 0x77) == 0) break; \
+ a = (RISCV_LOAD_VAL(p + RISCV_INSTR_SIZE) ^ 0x10u) + 1; \
+ p += RISCV_INSTR_SIZE * 2; \
+ if ((a & 0x77) == 0) \
+ { \
+ p -= RISCV_INSTR_SIZE; \
+ if Z7_UNLIKELY(p >= lim) { return p; } \
+ break; \
+ } \
+ }
+// (xx6f ^ 10) + 1 = xx7f + 1 = xx80 : JAL
+// (xxef ^ 10) + 1 = xxff + 1 = xx00 + 100 : JAL
+// (xx17 ^ 10) + 1 = xx07 + 1 = xx08 : AUIPC
+// (xx97 ^ 10) + 1 = xx87 + 1 = xx88 : AUIPC
+
+Byte * Z7_BRANCH_CONV_ENC(RISCV)(Byte *p, SizeT size, UInt32 pc)
+{
+ RISCV_SCAN_LOOP
+ v = a;
+ a = RISCV_GET_UI32(p);
+#ifndef RISCV_USE_16BIT_LOAD
+ v += (UInt32)p[1] << 8;
+#endif
+
+ if ((v & 8) == 0) // JAL
+ {
+ if ((v - (0x100 /* - RISCV_DELTA_7F */)) & 0xd80)
+ {
+ p += RISCV_INSTR_SIZE;
+ continue;
+ }
+ {
+ v = ((a & 1u << 31) >> 11)
+ | ((a & 0x3ff << 21) >> 20)
+ | ((a & 1 << 20) >> 9)
+ | (a & 0xff << 12);
+ BR_CONVERT_VAL_ENC(v)
+ // ((v & 1) == 0)
+ // v: bits [1 : 20] contain offset bits
+#if 0 && defined(RISCV_USE_UNALIGNED_LOAD)
+ a &= 0xfff;
+ a |= ((UInt32)(v << 23))
+ | ((UInt32)(v << 7) & ((UInt32)0xff << 16))
+ | ((UInt32)(v >> 5) & ((UInt32)0xf0 << 8));
+ RISCV_SET_UI32(p, a)
+#else // aligned
+#if 0
+ SetUi16a(p, (UInt16)(((v >> 5) & 0xf000) | (a & 0xfff)))
+#else
+ p[1] = (Byte)(((v >> 13) & 0xf0) | ((a >> 8) & 0xf));
+#endif
+
+#if 1 && defined(Z7_CPU_FAST_BSWAP_SUPPORTED) && defined(MY_CPU_LE)
+ v <<= 15;
+ v = Z7_BSWAP32(v);
+ SetUi16a(p + 2, (UInt16)v)
+#else
+ p[2] = (Byte)(v >> 9);
+ p[3] = (Byte)(v >> 1);
+#endif
+#endif // aligned
+ }
+ p += 4;
+ continue;
+ } // JAL
+
+ {
+ // AUIPC
+ if (v & 0xe80) // (not x0) and (not x2)
+ {
+ const UInt32 b = RISCV_GET_UI32(p + 4);
+ if (RISCV_CHECK_1(v, b))
+ {
+ {
+ const UInt32 temp = (b << 12) | (0x17 + RISCV_REG_VAL);
+ RISCV_SET_UI32(p, temp)
+ }
+ a &= 0xfffff000;
+ {
+#if 1
+ const int t = -1 >> 1;
+ if (t != -1)
+ a += (b >> 20) - ((b >> 19) & 0x1000); // arithmetic right shift emulation
+ else
+#endif
+ a += (UInt32)((Int32)b >> 20); // arithmetic right shift (sign-extension).
+ }
+ BR_CONVERT_VAL_ENC(a)
+#if 1 && defined(Z7_CPU_FAST_BSWAP_SUPPORTED) && defined(MY_CPU_LE)
+ a = Z7_BSWAP32(a);
+ RISCV_SET_UI32(p + 4, a)
+#else
+ SetBe32(p + 4, a)
+#endif
+ p += 8;
+ }
+ else
+ p += RISCV_STEP_1;
+ }
+ else
+ {
+ UInt32 r = a >> 27;
+ if (RISCV_CHECK_2(v, r))
+ {
+ v = RISCV_GET_UI32(p + 4);
+ r = (r << 7) + 0x17 + (v & 0xfffff000);
+ a = (a >> 12) | (v << 20);
+ RISCV_SET_UI32(p, r)
+ RISCV_SET_UI32(p + 4, a)
+ p += 8;
+ }
+ else
+ p += RISCV_STEP_2;
+ }
+ }
+ } // for
+}
+
+
+Byte * Z7_BRANCH_CONV_DEC(RISCV)(Byte *p, SizeT size, UInt32 pc)
+{
+ RISCV_SCAN_LOOP
+#ifdef RISCV_USE_16BIT_LOAD
+ if ((a & 8) == 0)
+ {
+#else
+ v = a;
+ a += (UInt32)p[1] << 8;
+ if ((v & 8) == 0)
+ {
+#endif
+ // JAL
+ a -= 0x100 - RISCV_DELTA_7F;
+ if (a & 0xd80)
+ {
+ p += RISCV_INSTR_SIZE;
+ continue;
+ }
+ {
+ const UInt32 a_old = (a + (0xef - RISCV_DELTA_7F)) & 0xfff;
+#if 0 // unaligned
+ a = GetUi32(p);
+ v = (UInt32)(a >> 23) & ((UInt32)0xff << 1)
+ | (UInt32)(a >> 7) & ((UInt32)0xff << 9)
+#elif 1 && defined(Z7_CPU_FAST_BSWAP_SUPPORTED) && defined(MY_CPU_LE)
+ v = GetUi16a(p + 2);
+ v = Z7_BSWAP32(v) >> 15
+#else
+ v = (UInt32)p[3] << 1
+ | (UInt32)p[2] << 9
+#endif
+ | (UInt32)((a & 0xf000) << 5);
+ BR_CONVERT_VAL_DEC(v)
+ a = a_old
+ | (v << 11 & 1u << 31)
+ | (v << 20 & 0x3ff << 21)
+ | (v << 9 & 1 << 20)
+ | (v & 0xff << 12);
+ RISCV_SET_UI32(p, a)
+ }
+ p += 4;
+ continue;
+ } // JAL
+
+ {
+ // AUIPC
+ v = a;
+#if 1 && defined(RISCV_USE_UNALIGNED_LOAD)
+ a = GetUi32(p);
+#else
+ a |= (UInt32)GetUi16a(p + 2) << 16;
+#endif
+ if ((v & 0xe80) == 0) // x0/x2
+ {
+ const UInt32 r = a >> 27;
+ if (RISCV_CHECK_2(v, r))
+ {
+ UInt32 b;
+#if 1 && defined(Z7_CPU_FAST_BSWAP_SUPPORTED) && defined(MY_CPU_LE)
+ b = RISCV_GET_UI32(p + 4);
+ b = Z7_BSWAP32(b);
+#else
+ b = GetBe32(p + 4);
+#endif
+ v = a >> 12;
+ BR_CONVERT_VAL_DEC(b)
+ a = (r << 7) + 0x17;
+ a += (b + 0x800) & 0xfffff000;
+ v |= b << 20;
+ RISCV_SET_UI32(p, a)
+ RISCV_SET_UI32(p + 4, v)
+ p += 8;
+ }
+ else
+ p += RISCV_STEP_2;
+ }
+ else
+ {
+ const UInt32 b = RISCV_GET_UI32(p + 4);
+ if (!RISCV_CHECK_1(v, b))
+ p += RISCV_STEP_1;
+ else
+ {
+ v = (a & 0xfffff000) | (b >> 20);
+ a = (b << 12) | (0x17 + RISCV_REG_VAL);
+ RISCV_SET_UI32(p, a)
+ RISCV_SET_UI32(p + 4, v)
+ p += 8;
+ }
+ }
+ }
+ } // for
+}
diff --git a/deps/libchdr/deps/lzma-24.05/src/Bra86.c b/deps/libchdr/deps/lzma-24.05/src/Bra86.c
new file mode 100644
index 00000000..d81f392a
--- /dev/null
+++ b/deps/libchdr/deps/lzma-24.05/src/Bra86.c
@@ -0,0 +1,187 @@
+/* Bra86.c -- Branch converter for X86 code (BCJ)
+2023-04-02 : Igor Pavlov : Public domain */
+
+#include "Precomp.h"
+
+#include "Bra.h"
+#include "CpuArch.h"
+
+
+#if defined(MY_CPU_SIZEOF_POINTER) \
+ && ( MY_CPU_SIZEOF_POINTER == 4 \
+ || MY_CPU_SIZEOF_POINTER == 8)
+ #define BR_CONV_USE_OPT_PC_PTR
+#endif
+
+#ifdef BR_CONV_USE_OPT_PC_PTR
+#define BR_PC_INIT pc -= (UInt32)(SizeT)p; // (MY_uintptr_t)
+#define BR_PC_GET (pc + (UInt32)(SizeT)p)
+#else
+#define BR_PC_INIT pc += (UInt32)size;
+#define BR_PC_GET (pc - (UInt32)(SizeT)(lim - p))
+// #define BR_PC_INIT
+// #define BR_PC_GET (pc + (UInt32)(SizeT)(p - data))
+#endif
+
+#define BR_CONVERT_VAL(v, c) if (encoding) v += c; else v -= c;
+// #define BR_CONVERT_VAL(v, c) if (!encoding) c = (UInt32)0 - c; v += c;
+
+#define Z7_BRANCH_CONV_ST(name) z7_BranchConvSt_ ## name
+
+#define BR86_NEED_CONV_FOR_MS_BYTE(b) ((((b) + 1) & 0xfe) == 0)
+
+#ifdef MY_CPU_LE_UNALIGN
+ #define BR86_PREPARE_BCJ_SCAN const UInt32 v = GetUi32(p) ^ 0xe8e8e8e8;
+ #define BR86_IS_BCJ_BYTE(n) ((v & ((UInt32)0xfe << (n) * 8)) == 0)
+#else
+ #define BR86_PREPARE_BCJ_SCAN
+ // bad for MSVC X86 (partial write to byte reg):
+ #define BR86_IS_BCJ_BYTE(n) ((p[n - 4] & 0xfe) == 0xe8)
+ // bad for old MSVC (partial write to byte reg):
+ // #define BR86_IS_BCJ_BYTE(n) (((*p ^ 0xe8) & 0xfe) == 0)
+#endif
+
+static
+Z7_FORCE_INLINE
+Z7_ATTRIB_NO_VECTOR
+Byte *Z7_BRANCH_CONV_ST(X86)(Byte *p, SizeT size, UInt32 pc, UInt32 *state, int encoding)
+{
+ if (size < 5)
+ return p;
+ {
+ // Byte *p = data;
+ const Byte *lim = p + size - 4;
+ unsigned mask = (unsigned)*state; // & 7;
+#ifdef BR_CONV_USE_OPT_PC_PTR
+ /* if BR_CONV_USE_OPT_PC_PTR is defined: we need to adjust (pc) for (+4),
+ because call/jump offset is relative to the next instruction.
+ if BR_CONV_USE_OPT_PC_PTR is not defined : we don't need to adjust (pc) for (+4),
+ because BR_PC_GET uses (pc - (lim - p)), and lim was adjusted for (-4) before.
+ */
+ pc += 4;
+#endif
+ BR_PC_INIT
+ goto start;
+
+ for (;; mask |= 4)
+ {
+ // cont: mask |= 4;
+ start:
+ if (p >= lim)
+ goto fin;
+ {
+ BR86_PREPARE_BCJ_SCAN
+ p += 4;
+ if (BR86_IS_BCJ_BYTE(0)) { goto m0; } mask >>= 1;
+ if (BR86_IS_BCJ_BYTE(1)) { goto m1; } mask >>= 1;
+ if (BR86_IS_BCJ_BYTE(2)) { goto m2; } mask = 0;
+ if (BR86_IS_BCJ_BYTE(3)) { goto a3; }
+ }
+ goto main_loop;
+
+ m0: p--;
+ m1: p--;
+ m2: p--;
+ if (mask == 0)
+ goto a3;
+ if (p > lim)
+ goto fin_p;
+
+ // if (((0x17u >> mask) & 1) == 0)
+ if (mask > 4 || mask == 3)
+ {
+ mask >>= 1;
+ continue; // goto cont;
+ }
+ mask >>= 1;
+ if (BR86_NEED_CONV_FOR_MS_BYTE(p[mask]))
+ continue; // goto cont;
+ // if (!BR86_NEED_CONV_FOR_MS_BYTE(p[3])) continue; // goto cont;
+ {
+ UInt32 v = GetUi32(p);
+ UInt32 c;
+ v += (1 << 24); if (v & 0xfe000000) continue; // goto cont;
+ c = BR_PC_GET;
+ BR_CONVERT_VAL(v, c)
+ {
+ mask <<= 3;
+ if (BR86_NEED_CONV_FOR_MS_BYTE(v >> mask))
+ {
+ v ^= (((UInt32)0x100 << mask) - 1);
+ #ifdef MY_CPU_X86
+ // for X86 : we can recalculate (c) to reduce register pressure
+ c = BR_PC_GET;
+ #endif
+ BR_CONVERT_VAL(v, c)
+ }
+ mask = 0;
+ }
+ // v = (v & ((1 << 24) - 1)) - (v & (1 << 24));
+ v &= (1 << 25) - 1; v -= (1 << 24);
+ SetUi32(p, v)
+ p += 4;
+ goto main_loop;
+ }
+
+ main_loop:
+ if (p >= lim)
+ goto fin;
+ for (;;)
+ {
+ BR86_PREPARE_BCJ_SCAN
+ p += 4;
+ if (BR86_IS_BCJ_BYTE(0)) { goto a0; }
+ if (BR86_IS_BCJ_BYTE(1)) { goto a1; }
+ if (BR86_IS_BCJ_BYTE(2)) { goto a2; }
+ if (BR86_IS_BCJ_BYTE(3)) { goto a3; }
+ if (p >= lim)
+ goto fin;
+ }
+
+ a0: p--;
+ a1: p--;
+ a2: p--;
+ a3:
+ if (p > lim)
+ goto fin_p;
+ // if (!BR86_NEED_CONV_FOR_MS_BYTE(p[3])) continue; // goto cont;
+ {
+ UInt32 v = GetUi32(p);
+ UInt32 c;
+ v += (1 << 24); if (v & 0xfe000000) continue; // goto cont;
+ c = BR_PC_GET;
+ BR_CONVERT_VAL(v, c)
+ // v = (v & ((1 << 24) - 1)) - (v & (1 << 24));
+ v &= (1 << 25) - 1; v -= (1 << 24);
+ SetUi32(p, v)
+ p += 4;
+ goto main_loop;
+ }
+ }
+
+fin_p:
+ p--;
+fin:
+ // the following processing for tail is optional and can be commented
+ /*
+ lim += 4;
+ for (; p < lim; p++, mask >>= 1)
+ if ((*p & 0xfe) == 0xe8)
+ break;
+ */
+ *state = (UInt32)mask;
+ return p;
+ }
+}
+
+
+#define Z7_BRANCH_CONV_ST_FUNC_IMP(name, m, encoding) \
+Z7_NO_INLINE \
+Z7_ATTRIB_NO_VECTOR \
+Byte *m(name)(Byte *data, SizeT size, UInt32 pc, UInt32 *state) \
+ { return Z7_BRANCH_CONV_ST(name)(data, size, pc, state, encoding); }
+
+Z7_BRANCH_CONV_ST_FUNC_IMP(X86, Z7_BRANCH_CONV_ST_DEC, 0)
+#ifndef Z7_EXTRACT_ONLY
+Z7_BRANCH_CONV_ST_FUNC_IMP(X86, Z7_BRANCH_CONV_ST_ENC, 1)
+#endif
diff --git a/deps/libchdr/deps/lzma-24.05/src/BraIA64.c b/deps/libchdr/deps/lzma-24.05/src/BraIA64.c
new file mode 100644
index 00000000..9dfe3e28
--- /dev/null
+++ b/deps/libchdr/deps/lzma-24.05/src/BraIA64.c
@@ -0,0 +1,14 @@
+/* BraIA64.c -- Converter for IA-64 code
+2023-02-20 : Igor Pavlov : Public domain */
+
+#include "Precomp.h"
+
+// the code was moved to Bra.c
+
+#ifdef _MSC_VER
+#pragma warning(disable : 4206) // nonstandard extension used : translation unit is empty
+#endif
+
+#if defined(__clang__)
+#pragma GCC diagnostic ignored "-Wempty-translation-unit"
+#endif
diff --git a/deps/libchdr/deps/lzma-24.05/src/CpuArch.c b/deps/libchdr/deps/lzma-24.05/src/CpuArch.c
new file mode 100644
index 00000000..a95b4782
--- /dev/null
+++ b/deps/libchdr/deps/lzma-24.05/src/CpuArch.c
@@ -0,0 +1,880 @@
+/* CpuArch.c -- CPU specific code
+2024-03-02 : Igor Pavlov : Public domain */
+
+#include "Precomp.h"
+
+// #include
+
+#include "CpuArch.h"
+
+#ifdef MY_CPU_X86_OR_AMD64
+
+#undef NEED_CHECK_FOR_CPUID
+#if !defined(MY_CPU_AMD64)
+#define NEED_CHECK_FOR_CPUID
+#endif
+
+/*
+ cpuid instruction supports (subFunction) parameter in ECX,
+ that is used only with some specific (function) parameter values.
+ But we always use only (subFunction==0).
+*/
+/*
+ __cpuid(): MSVC and GCC/CLANG use same function/macro name
+ but parameters are different.
+ We use MSVC __cpuid() parameters style for our z7_x86_cpuid() function.
+*/
+
+#if defined(__GNUC__) /* && (__GNUC__ >= 10) */ \
+ || defined(__clang__) /* && (__clang_major__ >= 10) */
+
+/* there was some CLANG/GCC compilers that have issues with
+ rbx(ebx) handling in asm blocks in -fPIC mode (__PIC__ is defined).
+ compiler's contains the macro __cpuid() that is similar to our code.
+ The history of __cpuid() changes in CLANG/GCC:
+ GCC:
+ 2007: it preserved ebx for (__PIC__ && __i386__)
+ 2013: it preserved rbx and ebx for __PIC__
+ 2014: it doesn't preserves rbx and ebx anymore
+ we suppose that (__GNUC__ >= 5) fixed that __PIC__ ebx/rbx problem.
+ CLANG:
+ 2014+: it preserves rbx, but only for 64-bit code. No __PIC__ check.
+ Why CLANG cares about 64-bit mode only, and doesn't care about ebx (in 32-bit)?
+ Do we need __PIC__ test for CLANG or we must care about rbx even if
+ __PIC__ is not defined?
+*/
+
+#define ASM_LN "\n"
+
+#if defined(MY_CPU_AMD64) && defined(__PIC__) \
+ && ((defined (__GNUC__) && (__GNUC__ < 5)) || defined(__clang__))
+
+#define x86_cpuid_MACRO(p, func) { \
+ __asm__ __volatile__ ( \
+ ASM_LN "mov %%rbx, %q1" \
+ ASM_LN "cpuid" \
+ ASM_LN "xchg %%rbx, %q1" \
+ : "=a" ((p)[0]), "=&r" ((p)[1]), "=c" ((p)[2]), "=d" ((p)[3]) : "0" (func), "2"(0)); }
+
+ /* "=&r" selects free register. It can select even rbx, if that register is free.
+ "=&D" for (RDI) also works, but the code can be larger with "=&D"
+ "2"(0) means (subFunction = 0),
+ 2 is (zero-based) index in the output constraint list "=c" (ECX). */
+
+#elif defined(MY_CPU_X86) && defined(__PIC__) \
+ && ((defined (__GNUC__) && (__GNUC__ < 5)) || defined(__clang__))
+
+#define x86_cpuid_MACRO(p, func) { \
+ __asm__ __volatile__ ( \
+ ASM_LN "mov %%ebx, %k1" \
+ ASM_LN "cpuid" \
+ ASM_LN "xchg %%ebx, %k1" \
+ : "=a" ((p)[0]), "=&r" ((p)[1]), "=c" ((p)[2]), "=d" ((p)[3]) : "0" (func), "2"(0)); }
+
+#else
+
+#define x86_cpuid_MACRO(p, func) { \
+ __asm__ __volatile__ ( \
+ ASM_LN "cpuid" \
+ : "=a" ((p)[0]), "=b" ((p)[1]), "=c" ((p)[2]), "=d" ((p)[3]) : "0" (func), "2"(0)); }
+
+#endif
+
+
+void Z7_FASTCALL z7_x86_cpuid(UInt32 p[4], UInt32 func)
+{
+ x86_cpuid_MACRO(p, func)
+}
+
+
+Z7_NO_INLINE
+UInt32 Z7_FASTCALL z7_x86_cpuid_GetMaxFunc(void)
+{
+ #if defined(NEED_CHECK_FOR_CPUID)
+ #define EFALGS_CPUID_BIT 21
+ UInt32 a;
+ __asm__ __volatile__ (
+ ASM_LN "pushf"
+ ASM_LN "pushf"
+ ASM_LN "pop %0"
+ // ASM_LN "movl %0, %1"
+ // ASM_LN "xorl $0x200000, %0"
+ ASM_LN "btc %1, %0"
+ ASM_LN "push %0"
+ ASM_LN "popf"
+ ASM_LN "pushf"
+ ASM_LN "pop %0"
+ ASM_LN "xorl (%%esp), %0"
+
+ ASM_LN "popf"
+ ASM_LN
+ : "=&r" (a) // "=a"
+ : "i" (EFALGS_CPUID_BIT)
+ );
+ if ((a & (1 << EFALGS_CPUID_BIT)) == 0)
+ return 0;
+ #endif
+ {
+ UInt32 p[4];
+ x86_cpuid_MACRO(p, 0)
+ return p[0];
+ }
+}
+
+#undef ASM_LN
+
+#elif !defined(_MSC_VER)
+
+/*
+// for gcc/clang and other: we can try to use __cpuid macro:
+#include
+void Z7_FASTCALL z7_x86_cpuid(UInt32 p[4], UInt32 func)
+{
+ __cpuid(func, p[0], p[1], p[2], p[3]);
+}
+UInt32 Z7_FASTCALL z7_x86_cpuid_GetMaxFunc(void)
+{
+ return (UInt32)__get_cpuid_max(0, NULL);
+}
+*/
+// for unsupported cpuid:
+void Z7_FASTCALL z7_x86_cpuid(UInt32 p[4], UInt32 func)
+{
+ UNUSED_VAR(func)
+ p[0] = p[1] = p[2] = p[3] = 0;
+}
+UInt32 Z7_FASTCALL z7_x86_cpuid_GetMaxFunc(void)
+{
+ return 0;
+}
+
+#else // _MSC_VER
+
+#if !defined(MY_CPU_AMD64)
+
+UInt32 __declspec(naked) Z7_FASTCALL z7_x86_cpuid_GetMaxFunc(void)
+{
+ #if defined(NEED_CHECK_FOR_CPUID)
+ #define EFALGS_CPUID_BIT 21
+ __asm pushfd
+ __asm pushfd
+ /*
+ __asm pop eax
+ // __asm mov edx, eax
+ __asm btc eax, EFALGS_CPUID_BIT
+ __asm push eax
+ */
+ __asm btc dword ptr [esp], EFALGS_CPUID_BIT
+ __asm popfd
+ __asm pushfd
+ __asm pop eax
+ // __asm xor eax, edx
+ __asm xor eax, [esp]
+ // __asm push edx
+ __asm popfd
+ __asm and eax, (1 shl EFALGS_CPUID_BIT)
+ __asm jz end_func
+ #endif
+ __asm push ebx
+ __asm xor eax, eax // func
+ __asm xor ecx, ecx // subFunction (optional) for (func == 0)
+ __asm cpuid
+ __asm pop ebx
+ #if defined(NEED_CHECK_FOR_CPUID)
+ end_func:
+ #endif
+ __asm ret 0
+}
+
+void __declspec(naked) Z7_FASTCALL z7_x86_cpuid(UInt32 p[4], UInt32 func)
+{
+ UNUSED_VAR(p)
+ UNUSED_VAR(func)
+ __asm push ebx
+ __asm push edi
+ __asm mov edi, ecx // p
+ __asm mov eax, edx // func
+ __asm xor ecx, ecx // subfunction (optional) for (func == 0)
+ __asm cpuid
+ __asm mov [edi ], eax
+ __asm mov [edi + 4], ebx
+ __asm mov [edi + 8], ecx
+ __asm mov [edi + 12], edx
+ __asm pop edi
+ __asm pop ebx
+ __asm ret 0
+}
+
+#else // MY_CPU_AMD64
+
+ #if _MSC_VER >= 1600
+ #include
+ #define MY_cpuidex __cpuidex
+ #else
+/*
+ __cpuid (func == (0 or 7)) requires subfunction number in ECX.
+ MSDN: The __cpuid intrinsic clears the ECX register before calling the cpuid instruction.
+ __cpuid() in new MSVC clears ECX.
+ __cpuid() in old MSVC (14.00) x64 doesn't clear ECX
+ We still can use __cpuid for low (func) values that don't require ECX,
+ but __cpuid() in old MSVC will be incorrect for some func values: (func == 7).
+ So here we use the hack for old MSVC to send (subFunction) in ECX register to cpuid instruction,
+ where ECX value is first parameter for FASTCALL / NO_INLINE func,
+ So the caller of MY_cpuidex_HACK() sets ECX as subFunction, and
+ old MSVC for __cpuid() doesn't change ECX and cpuid instruction gets (subFunction) value.
+
+DON'T remove Z7_NO_INLINE and Z7_FASTCALL for MY_cpuidex_HACK(): !!!
+*/
+static
+Z7_NO_INLINE void Z7_FASTCALL MY_cpuidex_HACK(Int32 subFunction, Int32 func, Int32 *CPUInfo)
+{
+ UNUSED_VAR(subFunction)
+ __cpuid(CPUInfo, func);
+}
+ #define MY_cpuidex(info, func, func2) MY_cpuidex_HACK(func2, func, info)
+ #pragma message("======== MY_cpuidex_HACK WAS USED ========")
+ #endif // _MSC_VER >= 1600
+
+#if !defined(MY_CPU_AMD64)
+/* inlining for __cpuid() in MSVC x86 (32-bit) produces big ineffective code,
+ so we disable inlining here */
+Z7_NO_INLINE
+#endif
+void Z7_FASTCALL z7_x86_cpuid(UInt32 p[4], UInt32 func)
+{
+ MY_cpuidex((Int32 *)p, (Int32)func, 0);
+}
+
+Z7_NO_INLINE
+UInt32 Z7_FASTCALL z7_x86_cpuid_GetMaxFunc(void)
+{
+ Int32 a[4];
+ MY_cpuidex(a, 0, 0);
+ return a[0];
+}
+
+#endif // MY_CPU_AMD64
+#endif // _MSC_VER
+
+#if defined(NEED_CHECK_FOR_CPUID)
+#define CHECK_CPUID_IS_SUPPORTED { if (z7_x86_cpuid_GetMaxFunc() == 0) return 0; }
+#else
+#define CHECK_CPUID_IS_SUPPORTED
+#endif
+#undef NEED_CHECK_FOR_CPUID
+
+
+static
+BoolInt x86cpuid_Func_1(UInt32 *p)
+{
+ CHECK_CPUID_IS_SUPPORTED
+ z7_x86_cpuid(p, 1);
+ return True;
+}
+
+/*
+static const UInt32 kVendors[][1] =
+{
+ { 0x756E6547 }, // , 0x49656E69, 0x6C65746E },
+ { 0x68747541 }, // , 0x69746E65, 0x444D4163 },
+ { 0x746E6543 } // , 0x48727561, 0x736C7561 }
+};
+*/
+
+/*
+typedef struct
+{
+ UInt32 maxFunc;
+ UInt32 vendor[3];
+ UInt32 ver;
+ UInt32 b;
+ UInt32 c;
+ UInt32 d;
+} Cx86cpuid;
+
+enum
+{
+ CPU_FIRM_INTEL,
+ CPU_FIRM_AMD,
+ CPU_FIRM_VIA
+};
+int x86cpuid_GetFirm(const Cx86cpuid *p);
+#define x86cpuid_ver_GetFamily(ver) (((ver >> 16) & 0xff0) | ((ver >> 8) & 0xf))
+#define x86cpuid_ver_GetModel(ver) (((ver >> 12) & 0xf0) | ((ver >> 4) & 0xf))
+#define x86cpuid_ver_GetStepping(ver) (ver & 0xf)
+
+int x86cpuid_GetFirm(const Cx86cpuid *p)
+{
+ unsigned i;
+ for (i = 0; i < sizeof(kVendors) / sizeof(kVendors[0]); i++)
+ {
+ const UInt32 *v = kVendors[i];
+ if (v[0] == p->vendor[0]
+ // && v[1] == p->vendor[1]
+ // && v[2] == p->vendor[2]
+ )
+ return (int)i;
+ }
+ return -1;
+}
+
+BoolInt CPU_Is_InOrder()
+{
+ Cx86cpuid p;
+ UInt32 family, model;
+ if (!x86cpuid_CheckAndRead(&p))
+ return True;
+
+ family = x86cpuid_ver_GetFamily(p.ver);
+ model = x86cpuid_ver_GetModel(p.ver);
+
+ switch (x86cpuid_GetFirm(&p))
+ {
+ case CPU_FIRM_INTEL: return (family < 6 || (family == 6 && (
+ // In-Order Atom CPU
+ model == 0x1C // 45 nm, N4xx, D4xx, N5xx, D5xx, 230, 330
+ || model == 0x26 // 45 nm, Z6xx
+ || model == 0x27 // 32 nm, Z2460
+ || model == 0x35 // 32 nm, Z2760
+ || model == 0x36 // 32 nm, N2xxx, D2xxx
+ )));
+ case CPU_FIRM_AMD: return (family < 5 || (family == 5 && (model < 6 || model == 0xA)));
+ case CPU_FIRM_VIA: return (family < 6 || (family == 6 && model < 0xF));
+ }
+ return False; // v23 : unknown processors are not In-Order
+}
+*/
+
+#ifdef _WIN32
+#include "7zWindows.h"
+#endif
+
+#if !defined(MY_CPU_AMD64) && defined(_WIN32)
+
+/* for legacy SSE ia32: there is no user-space cpu instruction to check
+ that OS supports SSE register storing/restoring on context switches.
+ So we need some OS-specific function to check that it's safe to use SSE registers.
+*/
+
+Z7_FORCE_INLINE
+static BoolInt CPU_Sys_Is_SSE_Supported(void)
+{
+#ifdef _MSC_VER
+ #pragma warning(push)
+ #pragma warning(disable : 4996) // `GetVersion': was declared deprecated
+#endif
+ /* low byte is major version of Windows
+ We suppose that any Windows version since
+ Windows2000 (major == 5) supports SSE registers */
+ return (Byte)GetVersion() >= 5;
+#if defined(_MSC_VER)
+ #pragma warning(pop)
+#endif
+}
+#define CHECK_SYS_SSE_SUPPORT if (!CPU_Sys_Is_SSE_Supported()) return False;
+#else
+#define CHECK_SYS_SSE_SUPPORT
+#endif
+
+
+#if !defined(MY_CPU_AMD64)
+
+BoolInt CPU_IsSupported_CMOV(void)
+{
+ UInt32 a[4];
+ if (!x86cpuid_Func_1(&a[0]))
+ return 0;
+ return (BoolInt)(a[3] >> 15) & 1;
+}
+
+BoolInt CPU_IsSupported_SSE(void)
+{
+ UInt32 a[4];
+ CHECK_SYS_SSE_SUPPORT
+ if (!x86cpuid_Func_1(&a[0]))
+ return 0;
+ return (BoolInt)(a[3] >> 25) & 1;
+}
+
+BoolInt CPU_IsSupported_SSE2(void)
+{
+ UInt32 a[4];
+ CHECK_SYS_SSE_SUPPORT
+ if (!x86cpuid_Func_1(&a[0]))
+ return 0;
+ return (BoolInt)(a[3] >> 26) & 1;
+}
+
+#endif
+
+
+static UInt32 x86cpuid_Func_1_ECX(void)
+{
+ UInt32 a[4];
+ CHECK_SYS_SSE_SUPPORT
+ if (!x86cpuid_Func_1(&a[0]))
+ return 0;
+ return a[2];
+}
+
+BoolInt CPU_IsSupported_AES(void)
+{
+ return (BoolInt)(x86cpuid_Func_1_ECX() >> 25) & 1;
+}
+
+BoolInt CPU_IsSupported_SSSE3(void)
+{
+ return (BoolInt)(x86cpuid_Func_1_ECX() >> 9) & 1;
+}
+
+BoolInt CPU_IsSupported_SSE41(void)
+{
+ return (BoolInt)(x86cpuid_Func_1_ECX() >> 19) & 1;
+}
+
+BoolInt CPU_IsSupported_SHA(void)
+{
+ CHECK_SYS_SSE_SUPPORT
+
+ if (z7_x86_cpuid_GetMaxFunc() < 7)
+ return False;
+ {
+ UInt32 d[4];
+ z7_x86_cpuid(d, 7);
+ return (BoolInt)(d[1] >> 29) & 1;
+ }
+}
+
+/*
+MSVC: _xgetbv() intrinsic is available since VS2010SP1.
+ MSVC also defines (_XCR_XFEATURE_ENABLED_MASK) macro in
+ that we can use or check.
+ For any 32-bit x86 we can use asm code in MSVC,
+ but MSVC asm code is huge after compilation.
+ So _xgetbv() is better
+
+ICC: _xgetbv() intrinsic is available (in what version of ICC?)
+ ICC defines (__GNUC___) and it supports gnu assembler
+ also ICC supports MASM style code with -use-msasm switch.
+ but ICC doesn't support __attribute__((__target__))
+
+GCC/CLANG 9:
+ _xgetbv() is macro that works via __builtin_ia32_xgetbv()
+ and we need __attribute__((__target__("xsave")).
+ But with __target__("xsave") the function will be not
+ inlined to function that has no __target__("xsave") attribute.
+ If we want _xgetbv() call inlining, then we should use asm version
+ instead of calling _xgetbv().
+ Note:intrinsic is broke before GCC 8.2:
+ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85684
+*/
+
+#if defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 1100) \
+ || defined(_MSC_VER) && (_MSC_VER >= 1600) && (_MSC_FULL_VER >= 160040219) \
+ || defined(__GNUC__) && (__GNUC__ >= 9) \
+ || defined(__clang__) && (__clang_major__ >= 9)
+// we define ATTRIB_XGETBV, if we want to use predefined _xgetbv() from compiler
+#if defined(__INTEL_COMPILER)
+#define ATTRIB_XGETBV
+#elif defined(__GNUC__) || defined(__clang__)
+// we don't define ATTRIB_XGETBV here, because asm version is better for inlining.
+// #define ATTRIB_XGETBV __attribute__((__target__("xsave")))
+#else
+#define ATTRIB_XGETBV
+#endif
+#endif
+
+#if defined(ATTRIB_XGETBV)
+#include
+#endif
+
+
+// XFEATURE_ENABLED_MASK/XCR0
+#define MY_XCR_XFEATURE_ENABLED_MASK 0
+
+#if defined(ATTRIB_XGETBV)
+ATTRIB_XGETBV
+#endif
+static UInt64 x86_xgetbv_0(UInt32 num)
+{
+#if defined(ATTRIB_XGETBV)
+ {
+ return
+ #if (defined(_MSC_VER))
+ _xgetbv(num);
+ #else
+ __builtin_ia32_xgetbv(
+ #if !defined(__clang__)
+ (int)
+ #endif
+ num);
+ #endif
+ }
+
+#elif defined(__GNUC__) || defined(__clang__) || defined(__SUNPRO_CC)
+
+ UInt32 a, d;
+ #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
+ __asm__
+ (
+ "xgetbv"
+ : "=a"(a), "=d"(d) : "c"(num) : "cc"
+ );
+ #else // is old gcc
+ __asm__
+ (
+ ".byte 0x0f, 0x01, 0xd0" "\n\t"
+ : "=a"(a), "=d"(d) : "c"(num) : "cc"
+ );
+ #endif
+ return ((UInt64)d << 32) | a;
+ // return a;
+
+#elif defined(_MSC_VER) && !defined(MY_CPU_AMD64)
+
+ UInt32 a, d;
+ __asm {
+ push eax
+ push edx
+ push ecx
+ mov ecx, num;
+ // xor ecx, ecx // = MY_XCR_XFEATURE_ENABLED_MASK
+ _emit 0x0f
+ _emit 0x01
+ _emit 0xd0
+ mov a, eax
+ mov d, edx
+ pop ecx
+ pop edx
+ pop eax
+ }
+ return ((UInt64)d << 32) | a;
+ // return a;
+
+#else // it's unknown compiler
+ // #error "Need xgetbv function"
+ UNUSED_VAR(num)
+ // for MSVC-X64 we could call external function from external file.
+ /* Actually we had checked OSXSAVE/AVX in cpuid before.
+ So it's expected that OS supports at least AVX and below. */
+ // if (num != MY_XCR_XFEATURE_ENABLED_MASK) return 0; // if not XCR0
+ return
+ // (1 << 0) | // x87
+ (1 << 1) // SSE
+ | (1 << 2); // AVX
+
+#endif
+}
+
+#ifdef _WIN32
+/*
+ Windows versions do not know about new ISA extensions that
+ can be introduced. But we still can use new extensions,
+ even if Windows doesn't report about supporting them,
+ But we can use new extensions, only if Windows knows about new ISA extension
+ that changes the number or size of registers: SSE, AVX/XSAVE, AVX512
+ So it's enough to check
+ MY_PF_AVX_INSTRUCTIONS_AVAILABLE
+ instead of
+ MY_PF_AVX2_INSTRUCTIONS_AVAILABLE
+*/
+#define MY_PF_XSAVE_ENABLED 17
+// #define MY_PF_SSSE3_INSTRUCTIONS_AVAILABLE 36
+// #define MY_PF_SSE4_1_INSTRUCTIONS_AVAILABLE 37
+// #define MY_PF_SSE4_2_INSTRUCTIONS_AVAILABLE 38
+// #define MY_PF_AVX_INSTRUCTIONS_AVAILABLE 39
+// #define MY_PF_AVX2_INSTRUCTIONS_AVAILABLE 40
+// #define MY_PF_AVX512F_INSTRUCTIONS_AVAILABLE 41
+#endif
+
+BoolInt CPU_IsSupported_AVX(void)
+{
+ #ifdef _WIN32
+ if (!IsProcessorFeaturePresent(MY_PF_XSAVE_ENABLED))
+ return False;
+ /* PF_AVX_INSTRUCTIONS_AVAILABLE probably is supported starting from
+ some latest Win10 revisions. But we need AVX in older Windows also.
+ So we don't use the following check: */
+ /*
+ if (!IsProcessorFeaturePresent(MY_PF_AVX_INSTRUCTIONS_AVAILABLE))
+ return False;
+ */
+ #endif
+
+ /*
+ OS must use new special XSAVE/XRSTOR instructions to save
+ AVX registers when it required for context switching.
+ At OS statring:
+ OS sets CR4.OSXSAVE flag to signal the processor that OS supports the XSAVE extensions.
+ Also OS sets bitmask in XCR0 register that defines what
+ registers will be processed by XSAVE instruction:
+ XCR0.SSE[bit 0] - x87 registers and state
+ XCR0.SSE[bit 1] - SSE registers and state
+ XCR0.AVX[bit 2] - AVX registers and state
+ CR4.OSXSAVE is reflected to CPUID.1:ECX.OSXSAVE[bit 27].
+ So we can read that bit in user-space.
+ XCR0 is available for reading in user-space by new XGETBV instruction.
+ */
+ {
+ const UInt32 c = x86cpuid_Func_1_ECX();
+ if (0 == (1
+ & (c >> 28) // AVX instructions are supported by hardware
+ & (c >> 27))) // OSXSAVE bit: XSAVE and related instructions are enabled by OS.
+ return False;
+ }
+
+ /* also we can check
+ CPUID.1:ECX.XSAVE [bit 26] : that shows that
+ XSAVE, XRESTOR, XSETBV, XGETBV instructions are supported by hardware.
+ But that check is redundant, because if OSXSAVE bit is set, then XSAVE is also set */
+
+ /* If OS have enabled XSAVE extension instructions (OSXSAVE == 1),
+ in most cases we expect that OS also will support storing/restoring
+ for AVX and SSE states at least.
+ But to be ensure for that we call user-space instruction
+ XGETBV(0) to get XCR0 value that contains bitmask that defines
+ what exact states(registers) OS have enabled for storing/restoring.
+ */
+
+ {
+ const UInt32 bm = (UInt32)x86_xgetbv_0(MY_XCR_XFEATURE_ENABLED_MASK);
+ // printf("\n=== XGetBV=%d\n", bm);
+ return 1
+ & (BoolInt)(bm >> 1) // SSE state is supported (set by OS) for storing/restoring
+ & (BoolInt)(bm >> 2); // AVX state is supported (set by OS) for storing/restoring
+ }
+ // since Win7SP1: we can use GetEnabledXStateFeatures();
+}
+
+
+BoolInt CPU_IsSupported_AVX2(void)
+{
+ if (!CPU_IsSupported_AVX())
+ return False;
+ if (z7_x86_cpuid_GetMaxFunc() < 7)
+ return False;
+ {
+ UInt32 d[4];
+ z7_x86_cpuid(d, 7);
+ // printf("\ncpuid(7): ebx=%8x ecx=%8x\n", d[1], d[2]);
+ return 1
+ & (BoolInt)(d[1] >> 5); // avx2
+ }
+}
+
+/*
+// fix it:
+BoolInt CPU_IsSupported_AVX512F_AVX512VL(void)
+{
+ if (!CPU_IsSupported_AVX())
+ return False;
+ if (z7_x86_cpuid_GetMaxFunc() < 7)
+ return False;
+ {
+ UInt32 d[4];
+ z7_x86_cpuid(d, 7);
+ // printf("\ncpuid(7): ebx=%8x ecx=%8x\n", d[1], d[2]);
+ return 1
+ & (BoolInt)(d[1] >> 16) // avx512-f
+ & (BoolInt)(d[1] >> 31); // avx512-Vl
+ }
+}
+*/
+
+BoolInt CPU_IsSupported_VAES_AVX2(void)
+{
+ if (!CPU_IsSupported_AVX())
+ return False;
+ if (z7_x86_cpuid_GetMaxFunc() < 7)
+ return False;
+ {
+ UInt32 d[4];
+ z7_x86_cpuid(d, 7);
+ // printf("\ncpuid(7): ebx=%8x ecx=%8x\n", d[1], d[2]);
+ return 1
+ & (BoolInt)(d[1] >> 5) // avx2
+ // & (d[1] >> 31) // avx512vl
+ & (BoolInt)(d[2] >> 9); // vaes // VEX-256/EVEX
+ }
+}
+
+BoolInt CPU_IsSupported_PageGB(void)
+{
+ CHECK_CPUID_IS_SUPPORTED
+ {
+ UInt32 d[4];
+ z7_x86_cpuid(d, 0x80000000);
+ if (d[0] < 0x80000001)
+ return False;
+ z7_x86_cpuid(d, 0x80000001);
+ return (BoolInt)(d[3] >> 26) & 1;
+ }
+}
+
+
+#elif defined(MY_CPU_ARM_OR_ARM64)
+
+#ifdef _WIN32
+
+#include "7zWindows.h"
+
+BoolInt CPU_IsSupported_CRC32(void) { return IsProcessorFeaturePresent(PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE) ? 1 : 0; }
+BoolInt CPU_IsSupported_CRYPTO(void) { return IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE) ? 1 : 0; }
+BoolInt CPU_IsSupported_NEON(void) { return IsProcessorFeaturePresent(PF_ARM_NEON_INSTRUCTIONS_AVAILABLE) ? 1 : 0; }
+
+#else
+
+#if defined(__APPLE__)
+
+/*
+#include
+#include
+static void Print_sysctlbyname(const char *name)
+{
+ size_t bufSize = 256;
+ char buf[256];
+ int res = sysctlbyname(name, &buf, &bufSize, NULL, 0);
+ {
+ int i;
+ printf("\nres = %d : %s : '%s' : bufSize = %d, numeric", res, name, buf, (unsigned)bufSize);
+ for (i = 0; i < 20; i++)
+ printf(" %2x", (unsigned)(Byte)buf[i]);
+
+ }
+}
+*/
+/*
+ Print_sysctlbyname("hw.pagesize");
+ Print_sysctlbyname("machdep.cpu.brand_string");
+*/
+
+static BoolInt z7_sysctlbyname_Get_BoolInt(const char *name)
+{
+ UInt32 val = 0;
+ if (z7_sysctlbyname_Get_UInt32(name, &val) == 0 && val == 1)
+ return 1;
+ return 0;
+}
+
+BoolInt CPU_IsSupported_CRC32(void)
+{
+ return z7_sysctlbyname_Get_BoolInt("hw.optional.armv8_crc32");
+}
+
+BoolInt CPU_IsSupported_NEON(void)
+{
+ return z7_sysctlbyname_Get_BoolInt("hw.optional.neon");
+}
+
+#ifdef MY_CPU_ARM64
+#define APPLE_CRYPTO_SUPPORT_VAL 1
+#else
+#define APPLE_CRYPTO_SUPPORT_VAL 0
+#endif
+
+BoolInt CPU_IsSupported_SHA1(void) { return APPLE_CRYPTO_SUPPORT_VAL; }
+BoolInt CPU_IsSupported_SHA2(void) { return APPLE_CRYPTO_SUPPORT_VAL; }
+BoolInt CPU_IsSupported_AES (void) { return APPLE_CRYPTO_SUPPORT_VAL; }
+
+
+#else // __APPLE__
+
+#if defined(__GLIBC__) && (__GLIBC__ * 100 + __GLIBC_MINOR__ >= 216)
+ #define Z7_GETAUXV_AVAILABLE
+#else
+// #pragma message("=== is not NEW GLIBC === ")
+ #if defined __has_include
+ #if __has_include ()
+// #pragma message("=== sys/auxv.h is avail=== ")
+ #define Z7_GETAUXV_AVAILABLE
+ #endif
+ #endif
+#endif
+
+#ifdef Z7_GETAUXV_AVAILABLE
+// #pragma message("=== Z7_GETAUXV_AVAILABLE === ")
+#include
+#define USE_HWCAP
+#endif
+
+#ifdef USE_HWCAP
+
+#if defined(__FreeBSD__)
+static unsigned long MY_getauxval(int aux)
+{
+ unsigned long val;
+ if (elf_aux_info(aux, &val, sizeof(val)))
+ return 0;
+ return val;
+}
+#else
+#define MY_getauxval getauxval
+ #if defined __has_include
+ #if __has_include ()
+#include
+ #endif
+ #endif
+#endif
+
+ #define MY_HWCAP_CHECK_FUNC_2(name1, name2) \
+ BoolInt CPU_IsSupported_ ## name1(void) { return (MY_getauxval(AT_HWCAP) & (HWCAP_ ## name2)); }
+
+#ifdef MY_CPU_ARM64
+ #define MY_HWCAP_CHECK_FUNC(name) \
+ MY_HWCAP_CHECK_FUNC_2(name, name)
+#if 1 || defined(__ARM_NEON)
+ BoolInt CPU_IsSupported_NEON(void) { return True; }
+#else
+ MY_HWCAP_CHECK_FUNC_2(NEON, ASIMD)
+#endif
+// MY_HWCAP_CHECK_FUNC (ASIMD)
+#elif defined(MY_CPU_ARM)
+ #define MY_HWCAP_CHECK_FUNC(name) \
+ BoolInt CPU_IsSupported_ ## name(void) { return (MY_getauxval(AT_HWCAP2) & (HWCAP2_ ## name)); }
+ MY_HWCAP_CHECK_FUNC_2(NEON, NEON)
+#endif
+
+#else // USE_HWCAP
+
+ #define MY_HWCAP_CHECK_FUNC(name) \
+ BoolInt CPU_IsSupported_ ## name(void) { return 0; }
+
+#if defined(__SWITCH__) || defined(__vita__)
+ BoolInt CPU_IsSupported_NEON(void) { return 1; }
+#else
+ MY_HWCAP_CHECK_FUNC(NEON)
+#endif
+
+#endif // USE_HWCAP
+
+MY_HWCAP_CHECK_FUNC (CRC32)
+MY_HWCAP_CHECK_FUNC (SHA1)
+MY_HWCAP_CHECK_FUNC (SHA2)
+MY_HWCAP_CHECK_FUNC (AES)
+
+#endif // __APPLE__
+#endif // _WIN32
+
+#endif // MY_CPU_ARM_OR_ARM64
+
+
+
+#ifdef __APPLE__
+
+#include
+
+int z7_sysctlbyname_Get(const char *name, void *buf, size_t *bufSize)
+{
+ return sysctlbyname(name, buf, bufSize, NULL, 0);
+}
+
+int z7_sysctlbyname_Get_UInt32(const char *name, UInt32 *val)
+{
+ size_t bufSize = sizeof(*val);
+ const int res = z7_sysctlbyname_Get(name, val, &bufSize);
+ if (res == 0 && bufSize != sizeof(*val))
+ return EFAULT;
+ return res;
+}
+
+#endif
diff --git a/deps/libchdr/deps/lzma-22.01/src/Delta.c b/deps/libchdr/deps/lzma-24.05/src/Delta.c
similarity index 94%
rename from deps/libchdr/deps/lzma-22.01/src/Delta.c
rename to deps/libchdr/deps/lzma-24.05/src/Delta.c
index fc7e9fe9..c4a4499f 100644
--- a/deps/libchdr/deps/lzma-22.01/src/Delta.c
+++ b/deps/libchdr/deps/lzma-24.05/src/Delta.c
@@ -1,169 +1,169 @@
-/* Delta.c -- Delta converter
-2021-02-09 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#include "Delta.h"
-
-void Delta_Init(Byte *state)
-{
- unsigned i;
- for (i = 0; i < DELTA_STATE_SIZE; i++)
- state[i] = 0;
-}
-
-
-void Delta_Encode(Byte *state, unsigned delta, Byte *data, SizeT size)
-{
- Byte temp[DELTA_STATE_SIZE];
-
- if (size == 0)
- return;
-
- {
- unsigned i = 0;
- do
- temp[i] = state[i];
- while (++i != delta);
- }
-
- if (size <= delta)
- {
- unsigned i = 0, k;
- do
- {
- Byte b = *data;
- *data++ = (Byte)(b - temp[i]);
- temp[i] = b;
- }
- while (++i != size);
-
- k = 0;
-
- do
- {
- if (i == delta)
- i = 0;
- state[k] = temp[i++];
- }
- while (++k != delta);
-
- return;
- }
-
- {
- Byte *p = data + size - delta;
- {
- unsigned i = 0;
- do
- state[i] = *p++;
- while (++i != delta);
- }
- {
- const Byte *lim = data + delta;
- ptrdiff_t dif = -(ptrdiff_t)delta;
-
- if (((ptrdiff_t)size + dif) & 1)
- {
- --p; *p = (Byte)(*p - p[dif]);
- }
-
- while (p != lim)
- {
- --p; *p = (Byte)(*p - p[dif]);
- --p; *p = (Byte)(*p - p[dif]);
- }
-
- dif = -dif;
-
- do
- {
- --p; *p = (Byte)(*p - temp[--dif]);
- }
- while (dif != 0);
- }
- }
-}
-
-
-void Delta_Decode(Byte *state, unsigned delta, Byte *data, SizeT size)
-{
- unsigned i;
- const Byte *lim;
-
- if (size == 0)
- return;
-
- i = 0;
- lim = data + size;
-
- if (size <= delta)
- {
- do
- *data = (Byte)(*data + state[i++]);
- while (++data != lim);
-
- for (; delta != i; state++, delta--)
- *state = state[i];
- data -= i;
- }
- else
- {
- /*
- #define B(n) b ## n
- #define I(n) Byte B(n) = state[n];
- #define U(n) { B(n) = (Byte)((B(n)) + *data++); data[-1] = (B(n)); }
- #define F(n) if (data != lim) { U(n) }
-
- if (delta == 1)
- {
- I(0)
- if ((lim - data) & 1) { U(0) }
- while (data != lim) { U(0) U(0) }
- data -= 1;
- }
- else if (delta == 2)
- {
- I(0) I(1)
- lim -= 1; while (data < lim) { U(0) U(1) }
- lim += 1; F(0)
- data -= 2;
- }
- else if (delta == 3)
- {
- I(0) I(1) I(2)
- lim -= 2; while (data < lim) { U(0) U(1) U(2) }
- lim += 2; F(0) F(1)
- data -= 3;
- }
- else if (delta == 4)
- {
- I(0) I(1) I(2) I(3)
- lim -= 3; while (data < lim) { U(0) U(1) U(2) U(3) }
- lim += 3; F(0) F(1) F(2)
- data -= 4;
- }
- else
- */
- {
- do
- {
- *data = (Byte)(*data + state[i++]);
- data++;
- }
- while (i != delta);
-
- {
- ptrdiff_t dif = -(ptrdiff_t)delta;
- do
- *data = (Byte)(*data + data[dif]);
- while (++data != lim);
- data += dif;
- }
- }
- }
-
- do
- *state++ = *data;
- while (++data != lim);
-}
+/* Delta.c -- Delta converter
+2021-02-09 : Igor Pavlov : Public domain */
+
+#include "Precomp.h"
+
+#include "Delta.h"
+
+void Delta_Init(Byte *state)
+{
+ unsigned i;
+ for (i = 0; i < DELTA_STATE_SIZE; i++)
+ state[i] = 0;
+}
+
+
+void Delta_Encode(Byte *state, unsigned delta, Byte *data, SizeT size)
+{
+ Byte temp[DELTA_STATE_SIZE];
+
+ if (size == 0)
+ return;
+
+ {
+ unsigned i = 0;
+ do
+ temp[i] = state[i];
+ while (++i != delta);
+ }
+
+ if (size <= delta)
+ {
+ unsigned i = 0, k;
+ do
+ {
+ Byte b = *data;
+ *data++ = (Byte)(b - temp[i]);
+ temp[i] = b;
+ }
+ while (++i != size);
+
+ k = 0;
+
+ do
+ {
+ if (i == delta)
+ i = 0;
+ state[k] = temp[i++];
+ }
+ while (++k != delta);
+
+ return;
+ }
+
+ {
+ Byte *p = data + size - delta;
+ {
+ unsigned i = 0;
+ do
+ state[i] = *p++;
+ while (++i != delta);
+ }
+ {
+ const Byte *lim = data + delta;
+ ptrdiff_t dif = -(ptrdiff_t)delta;
+
+ if (((ptrdiff_t)size + dif) & 1)
+ {
+ --p; *p = (Byte)(*p - p[dif]);
+ }
+
+ while (p != lim)
+ {
+ --p; *p = (Byte)(*p - p[dif]);
+ --p; *p = (Byte)(*p - p[dif]);
+ }
+
+ dif = -dif;
+
+ do
+ {
+ --p; *p = (Byte)(*p - temp[--dif]);
+ }
+ while (dif != 0);
+ }
+ }
+}
+
+
+void Delta_Decode(Byte *state, unsigned delta, Byte *data, SizeT size)
+{
+ unsigned i;
+ const Byte *lim;
+
+ if (size == 0)
+ return;
+
+ i = 0;
+ lim = data + size;
+
+ if (size <= delta)
+ {
+ do
+ *data = (Byte)(*data + state[i++]);
+ while (++data != lim);
+
+ for (; delta != i; state++, delta--)
+ *state = state[i];
+ data -= i;
+ }
+ else
+ {
+ /*
+ #define B(n) b ## n
+ #define I(n) Byte B(n) = state[n];
+ #define U(n) { B(n) = (Byte)((B(n)) + *data++); data[-1] = (B(n)); }
+ #define F(n) if (data != lim) { U(n) }
+
+ if (delta == 1)
+ {
+ I(0)
+ if ((lim - data) & 1) { U(0) }
+ while (data != lim) { U(0) U(0) }
+ data -= 1;
+ }
+ else if (delta == 2)
+ {
+ I(0) I(1)
+ lim -= 1; while (data < lim) { U(0) U(1) }
+ lim += 1; F(0)
+ data -= 2;
+ }
+ else if (delta == 3)
+ {
+ I(0) I(1) I(2)
+ lim -= 2; while (data < lim) { U(0) U(1) U(2) }
+ lim += 2; F(0) F(1)
+ data -= 3;
+ }
+ else if (delta == 4)
+ {
+ I(0) I(1) I(2) I(3)
+ lim -= 3; while (data < lim) { U(0) U(1) U(2) U(3) }
+ lim += 3; F(0) F(1) F(2)
+ data -= 4;
+ }
+ else
+ */
+ {
+ do
+ {
+ *data = (Byte)(*data + state[i++]);
+ data++;
+ }
+ while (i != delta);
+
+ {
+ ptrdiff_t dif = -(ptrdiff_t)delta;
+ do
+ *data = (Byte)(*data + data[dif]);
+ while (++data != lim);
+ data += dif;
+ }
+ }
+ }
+
+ do
+ *state++ = *data;
+ while (++data != lim);
+}
diff --git a/deps/libchdr/deps/lzma-22.01/src/LzFind.c b/deps/libchdr/deps/lzma-24.05/src/LzFind.c
similarity index 70%
rename from deps/libchdr/deps/lzma-22.01/src/LzFind.c
rename to deps/libchdr/deps/lzma-24.05/src/LzFind.c
index a17c06bc..1ce40464 100644
--- a/deps/libchdr/deps/lzma-22.01/src/LzFind.c
+++ b/deps/libchdr/deps/lzma-24.05/src/LzFind.c
@@ -1,1628 +1,1746 @@
-/* LzFind.c -- Match finder for LZ algorithms
-2021-11-29 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#include
-// #include
-
-#include "CpuArch.h"
-#include "LzFind.h"
-#include "LzHash.h"
-
-#define kBlockMoveAlign (1 << 7) // alignment for memmove()
-#define kBlockSizeAlign (1 << 16) // alignment for block allocation
-#define kBlockSizeReserveMin (1 << 24) // it's 1/256 from 4 GB dictinary
-
-#define kEmptyHashValue 0
-
-#define kMaxValForNormalize ((UInt32)0)
-// #define kMaxValForNormalize ((UInt32)(1 << 20) + 0xFFF) // for debug
-
-// #define kNormalizeAlign (1 << 7) // alignment for speculated accesses
-
-#define GET_AVAIL_BYTES(p) \
- Inline_MatchFinder_GetNumAvailableBytes(p)
-
-
-// #define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size)
-#define kFix5HashSize kFix4HashSize
-
-/*
- HASH2_CALC:
- if (hv) match, then cur[0] and cur[1] also match
-*/
-#define HASH2_CALC hv = GetUi16(cur);
-
-// (crc[0 ... 255] & 0xFF) provides one-to-one correspondence to [0 ... 255]
-
-/*
- HASH3_CALC:
- if (cur[0]) and (h2) match, then cur[1] also match
- if (cur[0]) and (hv) match, then cur[1] and cur[2] also match
-*/
-#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 { \
- 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]] << kLzHash_CrcShift_1)) & p->hashMask; }
-
-#define HASH5_CALC { \
- UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
- h2 = temp & (kHash2Size - 1); \
- temp ^= ((UInt32)cur[2] << 8); \
- h3 = temp & (kHash3Size - 1); \
- temp ^= (p->crc[cur[3]] << kLzHash_CrcShift_1); \
- /* h4 = temp & p->hash4Mask; */ /* (kHash4Size - 1); */ \
- hv = (temp ^ (p->crc[cur[4]] << kLzHash_CrcShift_2)) & p->hashMask; }
-
-#define HASH_ZIP_CALC hv = ((cur[2] | ((UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF;
-
-
-static void LzInWindow_Free(CMatchFinder *p, ISzAllocPtr alloc)
-{
- if (!p->directInput)
- {
- ISzAlloc_Free(alloc, p->bufferBase);
- p->bufferBase = NULL;
- }
-}
-
-
-static int LzInWindow_Create2(CMatchFinder *p, UInt32 blockSize, ISzAllocPtr alloc)
-{
- if (blockSize == 0)
- return 0;
- if (!p->bufferBase || p->blockSize != blockSize)
- {
- // size_t blockSizeT;
- LzInWindow_Free(p, alloc);
- p->blockSize = blockSize;
- // blockSizeT = blockSize;
-
- // printf("\nblockSize = 0x%x\n", blockSize);
- /*
- #if defined _WIN64
- // we can allocate 4GiB, but still use UInt32 for (p->blockSize)
- // we use UInt32 type for (p->blockSize), because
- // we don't want to wrap over 4 GiB,
- // when we use (p->streamPos - p->pos) that is UInt32.
- if (blockSize >= (UInt32)0 - (UInt32)kBlockSizeAlign)
- {
- blockSizeT = ((size_t)1 << 32);
- printf("\nchanged to blockSizeT = 4GiB\n");
- }
- #endif
- */
-
- p->bufferBase = (Byte *)ISzAlloc_Alloc(alloc, blockSize);
- // printf("\nbufferBase = %p\n", p->bufferBase);
- // return 0; // for debug
- }
- return (p->bufferBase != NULL);
-}
-
-static const Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; }
-
-static UInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return GET_AVAIL_BYTES(p); }
-
-
-MY_NO_INLINE
-static void MatchFinder_ReadBlock(CMatchFinder *p)
-{
- 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 - GET_AVAIL_BYTES(p);
- if (curSize > p->directInputRem)
- curSize = (UInt32)p->directInputRem;
- p->directInputRem -= curSize;
- p->streamPos += curSize;
- if (p->directInputRem == 0)
- p->streamEndWasReached = 1;
- return;
- }
-
- for (;;)
- {
- Byte *dest = p->buffer + GET_AVAIL_BYTES(p);
- size_t size = (size_t)(p->bufferBase + p->blockSize - dest);
- if (size == 0)
- {
- /* we call ReadBlock() after NeedMove() and MoveBlock().
- NeedMove() and MoveBlock() povide more than (keepSizeAfter)
- to the end of (blockSize).
- So we don't execute this branch in normal code flow.
- We can go here, if we will call ReadBlock() before NeedMove(), MoveBlock().
- */
- // p->result = SZ_ERROR_FAIL; // we can show error here
- return;
- }
-
- // #define kRead 3
- // if (size > kRead) size = kRead; // for debug
-
- p->result = ISeqInStream_Read(p->stream, dest, &size);
- if (p->result != SZ_OK)
- return;
- if (size == 0)
- {
- p->streamEndWasReached = 1;
- return;
- }
- p->streamPos += (UInt32)size;
- if (GET_AVAIL_BYTES(p) > p->keepSizeAfter)
- return;
- /* here and in another (p->keepSizeAfter) checks we keep on 1 byte more than was requested by Create() function
- (GET_AVAIL_BYTES(p) >= p->keepSizeAfter) - minimal required size */
- }
-
- // on exit: (p->result != SZ_OK || p->streamEndWasReached || GET_AVAIL_BYTES(p) > p->keepSizeAfter)
-}
-
-
-
-MY_NO_INLINE
-void MatchFinder_MoveBlock(CMatchFinder *p)
-{
- const size_t offset = (size_t)(p->buffer - p->bufferBase) - p->keepSizeBefore;
- const size_t keepBefore = (offset & (kBlockMoveAlign - 1)) + p->keepSizeBefore;
- p->buffer = p->bufferBase + keepBefore;
- memmove(p->bufferBase,
- p->bufferBase + (offset & ~((size_t)kBlockMoveAlign - 1)),
- keepBefore + (size_t)GET_AVAIL_BYTES(p));
-}
-
-/* We call MoveBlock() before ReadBlock().
- So MoveBlock() can be wasteful operation, if the whole input data
- can fit in current block even without calling MoveBlock().
- in important case where (dataSize <= historySize)
- condition (p->blockSize > dataSize + p->keepSizeAfter) is met
- So there is no MoveBlock() in that case case.
-*/
-
-int MatchFinder_NeedMove(CMatchFinder *p)
-{
- if (p->directInput)
- return 0;
- if (p->streamEndWasReached || p->result != SZ_OK)
- return 0;
- return ((size_t)(p->bufferBase + p->blockSize - p->buffer) <= p->keepSizeAfter);
-}
-
-void MatchFinder_ReadIfRequired(CMatchFinder *p)
-{
- if (p->keepSizeAfter >= GET_AVAIL_BYTES(p))
- MatchFinder_ReadBlock(p);
-}
-
-
-
-static void MatchFinder_SetDefaultSettings(CMatchFinder *p)
-{
- p->cutValue = 32;
- p->btMode = 1;
- p->numHashBytes = 4;
- p->bigHash = 0;
-}
-
-#define kCrcPoly 0xEDB88320
-
-void MatchFinder_Construct(CMatchFinder *p)
-{
- unsigned i;
- p->bufferBase = NULL;
- p->directInput = 0;
- p->hash = NULL;
- p->expectedDataSize = (UInt64)(Int64)-1;
- MatchFinder_SetDefaultSettings(p);
-
- 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)
-{
- ISzAlloc_Free(alloc, p->hash);
- p->hash = NULL;
-}
-
-void MatchFinder_Free(CMatchFinder *p, ISzAllocPtr alloc)
-{
- MatchFinder_FreeThisClassMemory(p, alloc);
- LzInWindow_Free(p, alloc);
-}
-
-static CLzRef* AllocRefs(size_t num, ISzAllocPtr alloc)
-{
- size_t sizeInBytes = (size_t)num * sizeof(CLzRef);
- if (sizeInBytes / sizeof(CLzRef) != num)
- return NULL;
- return (CLzRef *)ISzAlloc_Alloc(alloc, sizeInBytes);
-}
-
-#if (kBlockSizeReserveMin < kBlockSizeAlign * 2)
- #error Stop_Compiling_Bad_Reserve
-#endif
-
-
-
-static UInt32 GetBlockSize(CMatchFinder *p, UInt32 historySize)
-{
- UInt32 blockSize = (p->keepSizeBefore + p->keepSizeAfter);
- /*
- if (historySize > kMaxHistorySize)
- return 0;
- */
- // printf("\nhistorySize == 0x%x\n", historySize);
-
- if (p->keepSizeBefore < historySize || blockSize < p->keepSizeBefore) // if 32-bit overflow
- return 0;
-
- {
- const UInt32 kBlockSizeMax = (UInt32)0 - (UInt32)kBlockSizeAlign;
- const UInt32 rem = kBlockSizeMax - blockSize;
- const UInt32 reserve = (blockSize >> (blockSize < ((UInt32)1 << 30) ? 1 : 2))
- + (1 << 12) + kBlockMoveAlign + kBlockSizeAlign; // do not overflow 32-bit here
- if (blockSize >= kBlockSizeMax
- || rem < kBlockSizeReserveMin) // we reject settings that will be slow
- return 0;
- if (reserve >= rem)
- blockSize = kBlockSizeMax;
- else
- {
- blockSize += reserve;
- blockSize &= ~(UInt32)(kBlockSizeAlign - 1);
- }
- }
- // printf("\n LzFind_blockSize = %x\n", blockSize);
- // printf("\n LzFind_blockSize = %d\n", blockSize >> 20);
- return blockSize;
-}
-
-
-int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
- UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,
- ISzAllocPtr alloc)
-{
- /* we need one additional byte in (p->keepSizeBefore),
- since we use MoveBlock() after (p->pos++) and before dictionary using */
- // keepAddBufferBefore = (UInt32)0xFFFFFFFF - (1 << 22); // for debug
- p->keepSizeBefore = historySize + keepAddBufferBefore + 1;
-
- keepAddBufferAfter += matchMaxLen;
- /* we need (p->keepSizeAfter >= p->numHashBytes) */
- if (keepAddBufferAfter < p->numHashBytes)
- keepAddBufferAfter = p->numHashBytes;
- // keepAddBufferAfter -= 2; // for debug
- p->keepSizeAfter = keepAddBufferAfter;
-
- if (p->directInput)
- p->blockSize = 0;
- if (p->directInput || LzInWindow_Create2(p, GetBlockSize(p, historySize), alloc))
- {
- const UInt32 newCyclicBufferSize = historySize + 1; // do not change it
- UInt32 hs;
- p->matchMaxLen = matchMaxLen;
- {
- // UInt32 hs4;
- p->fixedHashSize = 0;
- hs = (1 << 16) - 1;
- if (p->numHashBytes != 2)
- {
- hs = historySize;
- if (hs > p->expectedDataSize)
- hs = (UInt32)p->expectedDataSize;
- if (hs != 0)
- hs--;
- hs |= (hs >> 1);
- hs |= (hs >> 2);
- hs |= (hs >> 4);
- hs |= (hs >> 8);
- // we propagated 16 bits in (hs). Low 16 bits must be set later
- hs >>= 1;
- if (hs >= (1 << 24))
- {
- if (p->numHashBytes == 3)
- hs = (1 << 24) - 1;
- else
- hs >>= 1;
- /* if (bigHash) mode, GetHeads4b() in LzFindMt.c needs (hs >= ((1 << 24) - 1))) */
- }
-
- // hs = ((UInt32)1 << 25) - 1; // for test
-
- // (hash_size >= (1 << 16)) : Required for (numHashBytes > 2)
- hs |= (1 << 16) - 1; /* don't change it! */
-
- // bt5: we adjust the size with recommended minimum size
- if (p->numHashBytes >= 5)
- hs |= (256 << kLzHash_CrcShift_2) - 1;
- }
- p->hashMask = hs;
- hs++;
-
- /*
- hs4 = (1 << 20);
- if (hs4 > hs)
- hs4 = hs;
- // hs4 = (1 << 16); // for test
- p->hash4Mask = hs4 - 1;
- */
-
- if (p->numHashBytes > 2) p->fixedHashSize += kHash2Size;
- if (p->numHashBytes > 3) p->fixedHashSize += kHash3Size;
- // if (p->numHashBytes > 4) p->fixedHashSize += hs4; // kHash4Size;
- hs += p->fixedHashSize;
- }
-
- {
- size_t newSize;
- size_t numSons;
- p->historySize = historySize;
- p->hashSizeSum = hs;
- p->cyclicBufferSize = newCyclicBufferSize; // it must be = (historySize + 1)
-
- numSons = newCyclicBufferSize;
- if (p->btMode)
- numSons <<= 1;
- newSize = hs + numSons;
-
- // aligned size is not required here, but it can be better for some loops
- #define NUM_REFS_ALIGN_MASK 0xF
- newSize = (newSize + NUM_REFS_ALIGN_MASK) & ~(size_t)NUM_REFS_ALIGN_MASK;
-
- if (p->hash && p->numRefs == newSize)
- return 1;
-
- MatchFinder_FreeThisClassMemory(p, alloc);
- p->numRefs = newSize;
- p->hash = AllocRefs(newSize, alloc);
-
- if (p->hash)
- {
- p->son = p->hash + p->hashSizeSum;
- return 1;
- }
- }
- }
-
- MatchFinder_Free(p, alloc);
- return 0;
-}
-
-
-static void MatchFinder_SetLimits(CMatchFinder *p)
-{
- UInt32 k;
- UInt32 n = kMaxValForNormalize - p->pos;
- if (n == 0)
- n = (UInt32)(Int32)-1; // we allow (pos == 0) at start even with (kMaxValForNormalize == 0)
-
- k = p->cyclicBufferSize - p->cyclicBufferPos;
- if (k < n)
- n = k;
-
- k = GET_AVAIL_BYTES(p);
- {
- const UInt32 ksa = p->keepSizeAfter;
- UInt32 mm = p->matchMaxLen;
- if (k > ksa)
- k -= ksa; // we must limit exactly to keepSizeAfter for ReadBlock
- else if (k >= mm)
- {
- // the limitation for (p->lenLimit) update
- k -= mm; // optimization : to reduce the number of checks
- k++;
- // k = 1; // non-optimized version : for debug
- }
- else
- {
- mm = k;
- if (k != 0)
- k = 1;
- }
- p->lenLimit = mm;
- }
- if (k < n)
- n = k;
-
- p->posLimit = p->pos + n;
-}
-
-
-void MatchFinder_Init_LowHash(CMatchFinder *p)
-{
- size_t i;
- CLzRef *items = p->hash;
- const size_t numItems = p->fixedHashSize;
- for (i = 0; i < numItems; i++)
- items[i] = kEmptyHashValue;
-}
-
-
-void MatchFinder_Init_HighHash(CMatchFinder *p)
-{
- size_t i;
- CLzRef *items = p->hash + p->fixedHashSize;
- const size_t numItems = (size_t)p->hashMask + 1;
- for (i = 0; i < numItems; i++)
- items[i] = kEmptyHashValue;
-}
-
-
-void MatchFinder_Init_4(CMatchFinder *p)
-{
- p->buffer = p->bufferBase;
- {
- /* kEmptyHashValue = 0 (Zero) is used in hash tables as NO-VALUE marker.
- the code in CMatchFinderMt expects (pos = 1) */
- p->pos =
- p->streamPos =
- 1; // it's smallest optimal value. do not change it
- // 0; // for debug
- }
- p->result = SZ_OK;
- p->streamEndWasReached = 0;
-}
-
-
-// (CYC_TO_POS_OFFSET == 0) is expected by some optimized code
-#define CYC_TO_POS_OFFSET 0
-// #define CYC_TO_POS_OFFSET 1 // for debug
-
-void MatchFinder_Init(CMatchFinder *p)
-{
- MatchFinder_Init_HighHash(p);
- MatchFinder_Init_LowHash(p);
- MatchFinder_Init_4(p);
- // if (readData)
- MatchFinder_ReadBlock(p);
-
- /* if we init (cyclicBufferPos = pos), then we can use one variable
- instead of both (cyclicBufferPos) and (pos) : only before (cyclicBufferPos) wrapping */
- p->cyclicBufferPos = (p->pos - CYC_TO_POS_OFFSET); // init with relation to (pos)
- // p->cyclicBufferPos = 0; // smallest value
- // p->son[0] = p->son[1] = 0; // unused: we can init skipped record for speculated accesses.
- MatchFinder_SetLimits(p);
-}
-
-
-
-#ifdef MY_CPU_X86_OR_AMD64
- #if defined(__clang__) && (__clang_major__ >= 8) \
- || defined(__GNUC__) && (__GNUC__ >= 8) \
- || defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 1900)
- #define USE_SATUR_SUB_128
- #define USE_AVX2
- #define ATTRIB_SSE41 __attribute__((__target__("sse4.1")))
- #define ATTRIB_AVX2 __attribute__((__target__("avx2")))
- #elif defined(_MSC_VER)
- #if (_MSC_VER >= 1600)
- #define USE_SATUR_SUB_128
- #if (_MSC_VER >= 1900)
- #define USE_AVX2
- #include // avx
- #endif
- #endif
- #endif
-
-// #elif defined(MY_CPU_ARM_OR_ARM64)
-#elif defined(MY_CPU_ARM64)
-
- #if defined(__clang__) && (__clang_major__ >= 8) \
- || defined(__GNUC__) && (__GNUC__ >= 8)
- #define USE_SATUR_SUB_128
- #ifdef MY_CPU_ARM64
- // #define ATTRIB_SSE41 __attribute__((__target__("")))
- #else
- // #define ATTRIB_SSE41 __attribute__((__target__("fpu=crypto-neon-fp-armv8")))
- #endif
-
- #elif defined(_MSC_VER)
- #if (_MSC_VER >= 1910)
- #define USE_SATUR_SUB_128
- #endif
- #endif
-
- #if defined(_MSC_VER) && defined(MY_CPU_ARM64)
- #include
- #else
- #include
- #endif
-
-#endif
-
-/*
-#ifndef ATTRIB_SSE41
- #define ATTRIB_SSE41
-#endif
-#ifndef ATTRIB_AVX2
- #define ATTRIB_AVX2
-#endif
-*/
-
-#ifdef USE_SATUR_SUB_128
-
-// #define _SHOW_HW_STATUS
-
-#ifdef _SHOW_HW_STATUS
-#include
-#define _PRF(x) x
-_PRF(;)
-#else
-#define _PRF(x)
-#endif
-
-#ifdef MY_CPU_ARM_OR_ARM64
-
-#ifdef MY_CPU_ARM64
-// #define FORCE_SATUR_SUB_128
-#endif
-
-typedef uint32x4_t v128;
-#define SASUB_128(i) \
- *(v128 *)(void *)(items + (i) * 4) = \
- vsubq_u32(vmaxq_u32(*(const v128 *)(const void *)(items + (i) * 4), sub2), sub2);
-
-#else
-
-#include // sse4.1
-
-typedef __m128i v128;
-#define SASUB_128(i) \
- *(v128 *)(void *)(items + (i) * 4) = \
- _mm_sub_epi32(_mm_max_epu32(*(const v128 *)(const void *)(items + (i) * 4), sub2), sub2); // SSE 4.1
-
-#endif
-
-
-
-MY_NO_INLINE
-static
-#ifdef ATTRIB_SSE41
-ATTRIB_SSE41
-#endif
-void
-MY_FAST_CALL
-LzFind_SaturSub_128(UInt32 subValue, CLzRef *items, const CLzRef *lim)
-{
- v128 sub2 =
- #ifdef MY_CPU_ARM_OR_ARM64
- vdupq_n_u32(subValue);
- #else
- _mm_set_epi32((Int32)subValue, (Int32)subValue, (Int32)subValue, (Int32)subValue);
- #endif
- do
- {
- SASUB_128(0)
- SASUB_128(1)
- SASUB_128(2)
- SASUB_128(3)
- items += 4 * 4;
- }
- while (items != lim);
-}
-
-
-
-#ifdef USE_AVX2
-
-#include // avx
-
-#define SASUB_256(i) *(__m256i *)(void *)(items + (i) * 8) = _mm256_sub_epi32(_mm256_max_epu32(*(const __m256i *)(const void *)(items + (i) * 8), sub2), sub2); // AVX2
-
-MY_NO_INLINE
-static
-#ifdef ATTRIB_AVX2
-ATTRIB_AVX2
-#endif
-void
-MY_FAST_CALL
-LzFind_SaturSub_256(UInt32 subValue, CLzRef *items, const CLzRef *lim)
-{
- __m256i sub2 = _mm256_set_epi32(
- (Int32)subValue, (Int32)subValue, (Int32)subValue, (Int32)subValue,
- (Int32)subValue, (Int32)subValue, (Int32)subValue, (Int32)subValue);
- do
- {
- SASUB_256(0)
- SASUB_256(1)
- items += 2 * 8;
- }
- while (items != lim);
-}
-#endif // USE_AVX2
-
-#ifndef FORCE_SATUR_SUB_128
-typedef void (MY_FAST_CALL *LZFIND_SATUR_SUB_CODE_FUNC)(
- UInt32 subValue, CLzRef *items, const CLzRef *lim);
-static LZFIND_SATUR_SUB_CODE_FUNC g_LzFind_SaturSub;
-#endif // FORCE_SATUR_SUB_128
-
-#endif // USE_SATUR_SUB_128
-
-
-// kEmptyHashValue must be zero
-// #define SASUB_32(i) v = items[i]; m = v - subValue; if (v < subValue) m = kEmptyHashValue; items[i] = m;
-#define SASUB_32(i) v = items[i]; if (v < subValue) v = subValue; items[i] = v - subValue;
-
-#ifdef FORCE_SATUR_SUB_128
-
-#define DEFAULT_SaturSub LzFind_SaturSub_128
-
-#else
-
-#define DEFAULT_SaturSub LzFind_SaturSub_32
-
-MY_NO_INLINE
-static
-void
-MY_FAST_CALL
-LzFind_SaturSub_32(UInt32 subValue, CLzRef *items, const CLzRef *lim)
-{
- do
- {
- UInt32 v;
- SASUB_32(0)
- SASUB_32(1)
- SASUB_32(2)
- SASUB_32(3)
- SASUB_32(4)
- SASUB_32(5)
- SASUB_32(6)
- SASUB_32(7)
- items += 8;
- }
- while (items != lim);
-}
-
-#endif
-
-
-MY_NO_INLINE
-void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, size_t numItems)
-{
- #define K_NORM_ALIGN_BLOCK_SIZE (1 << 6)
-
- CLzRef *lim;
-
- for (; numItems != 0 && ((unsigned)(ptrdiff_t)items & (K_NORM_ALIGN_BLOCK_SIZE - 1)) != 0; numItems--)
- {
- UInt32 v;
- SASUB_32(0);
- items++;
- }
-
- {
- #define K_NORM_ALIGN_MASK (K_NORM_ALIGN_BLOCK_SIZE / 4 - 1)
- lim = items + (numItems & ~(size_t)K_NORM_ALIGN_MASK);
- numItems &= K_NORM_ALIGN_MASK;
- if (items != lim)
- {
- #if defined(USE_SATUR_SUB_128) && !defined(FORCE_SATUR_SUB_128)
- if (g_LzFind_SaturSub)
- g_LzFind_SaturSub(subValue, items, lim);
- else
- #endif
- DEFAULT_SaturSub(subValue, items, lim);
- }
- items = lim;
- }
-
-
- for (; numItems != 0; numItems--)
- {
- UInt32 v;
- SASUB_32(0);
- items++;
- }
-}
-
-
-
-// call MatchFinder_CheckLimits() only after (p->pos++) update
-
-MY_NO_INLINE
-static void MatchFinder_CheckLimits(CMatchFinder *p)
-{
- if (// !p->streamEndWasReached && p->result == SZ_OK &&
- p->keepSizeAfter == GET_AVAIL_BYTES(p))
- {
- // we try to read only in exact state (p->keepSizeAfter == GET_AVAIL_BYTES(p))
- if (MatchFinder_NeedMove(p))
- MatchFinder_MoveBlock(p);
- MatchFinder_ReadBlock(p);
- }
-
- if (p->pos == kMaxValForNormalize)
- if (GET_AVAIL_BYTES(p) >= p->numHashBytes) // optional optimization for last bytes of data.
- /*
- if we disable normalization for last bytes of data, and
- if (data_size == 4 GiB), we don't call wastfull normalization,
- but (pos) will be wrapped over Zero (0) in that case.
- And we cannot resume later to normal operation
- */
- {
- // MatchFinder_Normalize(p);
- /* after normalization we need (p->pos >= p->historySize + 1); */
- /* we can reduce subValue to aligned value, if want to keep alignment
- of (p->pos) and (p->buffer) for speculated accesses. */
- const UInt32 subValue = (p->pos - p->historySize - 1) /* & ~(UInt32)(kNormalizeAlign - 1) */;
- // const UInt32 subValue = (1 << 15); // for debug
- // printf("\nMatchFinder_Normalize() subValue == 0x%x\n", subValue);
- size_t numSonRefs = p->cyclicBufferSize;
- if (p->btMode)
- numSonRefs <<= 1;
- Inline_MatchFinder_ReduceOffsets(p, subValue);
- MatchFinder_Normalize3(subValue, p->hash, (size_t)p->hashSizeSum + numSonRefs);
- }
-
- if (p->cyclicBufferPos == p->cyclicBufferSize)
- p->cyclicBufferPos = 0;
-
- MatchFinder_SetLimits(p);
-}
-
-
-/*
- (lenLimit > maxLen)
-*/
-MY_FORCE_INLINE
-static UInt32 * Hc_GetMatchesSpec(size_t lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
- size_t _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
- UInt32 *d, unsigned maxLen)
-{
- /*
- son[_cyclicBufferPos] = curMatch;
- for (;;)
- {
- UInt32 delta = pos - curMatch;
- if (cutValue-- == 0 || delta >= _cyclicBufferSize)
- return d;
- {
- const Byte *pb = cur - delta;
- curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)];
- if (pb[maxLen] == cur[maxLen] && *pb == *cur)
- {
- UInt32 len = 0;
- while (++len != lenLimit)
- if (pb[len] != cur[len])
- break;
- if (maxLen < len)
- {
- maxLen = len;
- *d++ = len;
- *d++ = delta - 1;
- if (len == lenLimit)
- return d;
- }
- }
- }
- }
- */
-
- const Byte *lim = cur + lenLimit;
- son[_cyclicBufferPos] = curMatch;
-
- do
- {
- UInt32 delta;
-
- if (curMatch == 0)
- break;
- // if (curMatch2 >= curMatch) return NULL;
- delta = pos - curMatch;
- if (delta >= _cyclicBufferSize)
- break;
- {
- ptrdiff_t diff;
- curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)];
- diff = (ptrdiff_t)0 - (ptrdiff_t)delta;
- if (cur[maxLen] == cur[(ptrdiff_t)maxLen + diff])
- {
- const Byte *c = cur;
- while (*c == c[diff])
- {
- if (++c == lim)
- {
- d[0] = (UInt32)(lim - cur);
- d[1] = delta - 1;
- return d + 2;
- }
- }
- {
- const unsigned len = (unsigned)(c - cur);
- if (maxLen < len)
- {
- maxLen = len;
- d[0] = (UInt32)len;
- d[1] = delta - 1;
- d += 2;
- }
- }
- }
- }
- }
- while (--cutValue);
-
- return d;
-}
-
-
-MY_FORCE_INLINE
-UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
- size_t _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
- UInt32 *d, UInt32 maxLen)
-{
- CLzRef *ptr0 = son + ((size_t)_cyclicBufferPos << 1) + 1;
- CLzRef *ptr1 = son + ((size_t)_cyclicBufferPos << 1);
- unsigned len0 = 0, len1 = 0;
-
- UInt32 cmCheck;
-
- // if (curMatch >= pos) { *ptr0 = *ptr1 = kEmptyHashValue; return NULL; }
-
- cmCheck = (UInt32)(pos - _cyclicBufferSize);
- if ((UInt32)pos <= _cyclicBufferSize)
- cmCheck = 0;
-
- if (cmCheck < curMatch)
- do
- {
- const UInt32 delta = pos - curMatch;
- {
- CLzRef *pair = son + ((size_t)(_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);
- const Byte *pb = cur - delta;
- unsigned len = (len0 < len1 ? len0 : len1);
- const 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;
- *d++ = (UInt32)len;
- *d++ = delta - 1;
- if (len == lenLimit)
- {
- *ptr1 = pair0;
- *ptr0 = pair[1];
- return d;
- }
- }
- }
- if (pb[len] < cur[len])
- {
- *ptr1 = curMatch;
- // const UInt32 curMatch2 = pair[1];
- // if (curMatch2 >= curMatch) { *ptr0 = *ptr1 = kEmptyHashValue; return NULL; }
- // curMatch = curMatch2;
- curMatch = pair[1];
- ptr1 = pair + 1;
- len1 = len;
- }
- else
- {
- *ptr0 = curMatch;
- curMatch = pair[0];
- ptr0 = pair;
- len0 = len;
- }
- }
- }
- while(--cutValue && cmCheck < curMatch);
-
- *ptr0 = *ptr1 = kEmptyHashValue;
- return d;
-}
-
-
-static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
- size_t _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;
-
- UInt32 cmCheck;
-
- cmCheck = (UInt32)(pos - _cyclicBufferSize);
- if ((UInt32)pos <= _cyclicBufferSize)
- cmCheck = 0;
-
- if (// curMatch >= pos || // failure
- cmCheck < curMatch)
- do
- {
- const UInt32 delta = pos - curMatch;
- {
- 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)
- {
- *ptr1 = pair[0];
- *ptr0 = pair[1];
- return;
- }
- }
- }
- if (pb[len] < cur[len])
- {
- *ptr1 = curMatch;
- curMatch = pair[1];
- ptr1 = pair + 1;
- len1 = len;
- }
- else
- {
- *ptr0 = curMatch;
- curMatch = pair[0];
- ptr0 = pair;
- len0 = len;
- }
- }
- }
- while(--cutValue && cmCheck < curMatch);
-
- *ptr0 = *ptr1 = kEmptyHashValue;
- return;
-}
-
-
-#define MOVE_POS \
- ++p->cyclicBufferPos; \
- p->buffer++; \
- { const UInt32 pos1 = p->pos + 1; p->pos = pos1; if (pos1 == p->posLimit) MatchFinder_CheckLimits(p); }
-
-#define MOVE_POS_RET MOVE_POS return distances;
-
-MY_NO_INLINE
-static void MatchFinder_MovePos(CMatchFinder *p)
-{
- /* we go here at the end of stream data, when (avail < num_hash_bytes)
- We don't update sons[cyclicBufferPos << btMode].
- So (sons) record will contain junk. And we cannot resume match searching
- to normal operation, even if we will provide more input data in buffer.
- p->sons[p->cyclicBufferPos << p->btMode] = 0; // kEmptyHashValue
- if (p->btMode)
- p->sons[(p->cyclicBufferPos << p->btMode) + 1] = 0; // kEmptyHashValue
- */
- MOVE_POS;
-}
-
-#define GET_MATCHES_HEADER2(minLen, ret_op) \
- unsigned lenLimit; UInt32 hv; 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 distances)
-#define SKIP_HEADER(minLen) do { GET_MATCHES_HEADER2(minLen, continue)
-
-#define MF_PARAMS(p) lenLimit, curMatch, p->pos, p->buffer, p->son, p->cyclicBufferPos, p->cyclicBufferSize, p->cutValue
-
-#define SKIP_FOOTER SkipMatchesSpec(MF_PARAMS(p)); MOVE_POS; } while (--num);
-
-#define GET_MATCHES_FOOTER_BASE(_maxLen_, func) \
- distances = func(MF_PARAMS(p), \
- distances, (UInt32)_maxLen_); MOVE_POS_RET;
-
-#define GET_MATCHES_FOOTER_BT(_maxLen_) \
- GET_MATCHES_FOOTER_BASE(_maxLen_, GetMatchesSpec1)
-
-#define GET_MATCHES_FOOTER_HC(_maxLen_) \
- GET_MATCHES_FOOTER_BASE(_maxLen_, Hc_GetMatchesSpec)
-
-
-
-#define UPDATE_maxLen { \
- const ptrdiff_t diff = (ptrdiff_t)0 - (ptrdiff_t)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)
-{
- GET_MATCHES_HEADER(2)
- HASH2_CALC;
- curMatch = p->hash[hv];
- p->hash[hv] = p->pos;
- GET_MATCHES_FOOTER_BT(1)
-}
-
-UInt32* Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
-{
- GET_MATCHES_HEADER(3)
- HASH_ZIP_CALC;
- curMatch = p->hash[hv];
- p->hash[hv] = p->pos;
- GET_MATCHES_FOOTER_BT(2)
-}
-
-
-#define SET_mmm \
- mmm = p->cyclicBufferSize; \
- if (pos < mmm) \
- mmm = pos;
-
-
-static UInt32* Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
-{
- UInt32 mmm;
- UInt32 h2, d2, pos;
- unsigned maxLen;
- UInt32 *hash;
- GET_MATCHES_HEADER(3)
-
- HASH3_CALC;
-
- hash = p->hash;
- pos = p->pos;
-
- d2 = pos - hash[h2];
-
- curMatch = (hash + kFix3HashSize)[hv];
-
- hash[h2] = pos;
- (hash + kFix3HashSize)[hv] = pos;
-
- SET_mmm
-
- maxLen = 2;
-
- if (d2 < mmm && *(cur - d2) == *cur)
- {
- UPDATE_maxLen
- distances[0] = (UInt32)maxLen;
- distances[1] = d2 - 1;
- distances += 2;
- if (maxLen == lenLimit)
- {
- SkipMatchesSpec(MF_PARAMS(p));
- MOVE_POS_RET;
- }
- }
-
- GET_MATCHES_FOOTER_BT(maxLen)
-}
-
-
-static UInt32* Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
-{
- UInt32 mmm;
- UInt32 h2, h3, d2, d3, pos;
- unsigned maxLen;
- UInt32 *hash;
- GET_MATCHES_HEADER(4)
-
- HASH4_CALC;
-
- hash = p->hash;
- pos = p->pos;
-
- d2 = pos - hash [h2];
- d3 = pos - (hash + kFix3HashSize)[h3];
- curMatch = (hash + kFix4HashSize)[hv];
-
- hash [h2] = pos;
- (hash + kFix3HashSize)[h3] = pos;
- (hash + kFix4HashSize)[hv] = pos;
-
- SET_mmm
-
- maxLen = 3;
-
- for (;;)
- {
- if (d2 < mmm && *(cur - d2) == *cur)
- {
- distances[0] = 2;
- distances[1] = d2 - 1;
- distances += 2;
- if (*(cur - d2 + 2) == cur[2])
- {
- // distances[-2] = 3;
- }
- else if (d3 < mmm && *(cur - d3) == *cur)
- {
- d2 = d3;
- distances[1] = d3 - 1;
- distances += 2;
- }
- else
- break;
- }
- else if (d3 < mmm && *(cur - d3) == *cur)
- {
- d2 = d3;
- distances[1] = d3 - 1;
- distances += 2;
- }
- else
- break;
-
- UPDATE_maxLen
- distances[-2] = (UInt32)maxLen;
- if (maxLen == lenLimit)
- {
- SkipMatchesSpec(MF_PARAMS(p));
- MOVE_POS_RET
- }
- break;
- }
-
- GET_MATCHES_FOOTER_BT(maxLen)
-}
-
-
-static UInt32* Bt5_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
-{
- UInt32 mmm;
- UInt32 h2, h3, d2, d3, maxLen, pos;
- UInt32 *hash;
- GET_MATCHES_HEADER(5)
-
- HASH5_CALC;
-
- hash = p->hash;
- pos = p->pos;
-
- d2 = pos - hash [h2];
- d3 = pos - (hash + kFix3HashSize)[h3];
- // d4 = pos - (hash + kFix4HashSize)[h4];
-
- curMatch = (hash + kFix5HashSize)[hv];
-
- hash [h2] = pos;
- (hash + kFix3HashSize)[h3] = pos;
- // (hash + kFix4HashSize)[h4] = pos;
- (hash + kFix5HashSize)[hv] = pos;
-
- SET_mmm
-
- maxLen = 4;
-
- for (;;)
- {
- if (d2 < mmm && *(cur - d2) == *cur)
- {
- distances[0] = 2;
- distances[1] = d2 - 1;
- distances += 2;
- if (*(cur - d2 + 2) == cur[2])
- {
- }
- else if (d3 < mmm && *(cur - d3) == *cur)
- {
- distances[1] = d3 - 1;
- distances += 2;
- d2 = d3;
- }
- else
- break;
- }
- else if (d3 < mmm && *(cur - d3) == *cur)
- {
- distances[1] = d3 - 1;
- distances += 2;
- d2 = d3;
- }
- else
- break;
-
- distances[-2] = 3;
- if (*(cur - d2 + 3) != cur[3])
- break;
- UPDATE_maxLen
- distances[-2] = (UInt32)maxLen;
- if (maxLen == lenLimit)
- {
- SkipMatchesSpec(MF_PARAMS(p));
- MOVE_POS_RET;
- }
- break;
- }
-
- GET_MATCHES_FOOTER_BT(maxLen)
-}
-
-
-static UInt32* Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
-{
- UInt32 mmm;
- UInt32 h2, h3, d2, d3, pos;
- unsigned maxLen;
- UInt32 *hash;
- GET_MATCHES_HEADER(4)
-
- HASH4_CALC;
-
- hash = p->hash;
- pos = p->pos;
-
- d2 = pos - hash [h2];
- d3 = pos - (hash + kFix3HashSize)[h3];
- curMatch = (hash + kFix4HashSize)[hv];
-
- hash [h2] = pos;
- (hash + kFix3HashSize)[h3] = pos;
- (hash + kFix4HashSize)[hv] = pos;
-
- SET_mmm
-
- maxLen = 3;
-
- for (;;)
- {
- if (d2 < mmm && *(cur - d2) == *cur)
- {
- distances[0] = 2;
- distances[1] = d2 - 1;
- distances += 2;
- if (*(cur - d2 + 2) == cur[2])
- {
- // distances[-2] = 3;
- }
- else if (d3 < mmm && *(cur - d3) == *cur)
- {
- d2 = d3;
- distances[1] = d3 - 1;
- distances += 2;
- }
- else
- break;
- }
- else if (d3 < mmm && *(cur - d3) == *cur)
- {
- d2 = d3;
- distances[1] = d3 - 1;
- distances += 2;
- }
- else
- break;
-
- UPDATE_maxLen
- distances[-2] = (UInt32)maxLen;
- if (maxLen == lenLimit)
- {
- p->son[p->cyclicBufferPos] = curMatch;
- MOVE_POS_RET;
- }
- break;
- }
-
- GET_MATCHES_FOOTER_HC(maxLen);
-}
-
-
-static UInt32 * Hc5_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
-{
- UInt32 mmm;
- UInt32 h2, h3, d2, d3, maxLen, pos;
- UInt32 *hash;
- GET_MATCHES_HEADER(5)
-
- HASH5_CALC;
-
- hash = p->hash;
- pos = p->pos;
-
- d2 = pos - hash [h2];
- d3 = pos - (hash + kFix3HashSize)[h3];
- // d4 = pos - (hash + kFix4HashSize)[h4];
-
- curMatch = (hash + kFix5HashSize)[hv];
-
- hash [h2] = pos;
- (hash + kFix3HashSize)[h3] = pos;
- // (hash + kFix4HashSize)[h4] = pos;
- (hash + kFix5HashSize)[hv] = pos;
-
- SET_mmm
-
- maxLen = 4;
-
- for (;;)
- {
- if (d2 < mmm && *(cur - d2) == *cur)
- {
- distances[0] = 2;
- distances[1] = d2 - 1;
- distances += 2;
- if (*(cur - d2 + 2) == cur[2])
- {
- }
- else if (d3 < mmm && *(cur - d3) == *cur)
- {
- distances[1] = d3 - 1;
- distances += 2;
- d2 = d3;
- }
- else
- break;
- }
- else if (d3 < mmm && *(cur - d3) == *cur)
- {
- distances[1] = d3 - 1;
- distances += 2;
- d2 = d3;
- }
- else
- break;
-
- distances[-2] = 3;
- if (*(cur - d2 + 3) != cur[3])
- break;
- UPDATE_maxLen
- distances[-2] = maxLen;
- if (maxLen == lenLimit)
- {
- p->son[p->cyclicBufferPos] = curMatch;
- MOVE_POS_RET;
- }
- break;
- }
-
- GET_MATCHES_FOOTER_HC(maxLen);
-}
-
-
-UInt32* Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
-{
- GET_MATCHES_HEADER(3)
- HASH_ZIP_CALC;
- curMatch = p->hash[hv];
- p->hash[hv] = p->pos;
- GET_MATCHES_FOOTER_HC(2)
-}
-
-
-static void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
-{
- SKIP_HEADER(2)
- {
- HASH2_CALC;
- curMatch = p->hash[hv];
- p->hash[hv] = p->pos;
- }
- SKIP_FOOTER
-}
-
-void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
-{
- SKIP_HEADER(3)
- {
- HASH_ZIP_CALC;
- curMatch = p->hash[hv];
- p->hash[hv] = p->pos;
- }
- SKIP_FOOTER
-}
-
-static void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
-{
- SKIP_HEADER(3)
- {
- UInt32 h2;
- UInt32 *hash;
- HASH3_CALC;
- hash = p->hash;
- curMatch = (hash + kFix3HashSize)[hv];
- hash[h2] =
- (hash + kFix3HashSize)[hv] = p->pos;
- }
- SKIP_FOOTER
-}
-
-static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
-{
- SKIP_HEADER(4)
- {
- UInt32 h2, h3;
- UInt32 *hash;
- HASH4_CALC;
- hash = p->hash;
- curMatch = (hash + kFix4HashSize)[hv];
- hash [h2] =
- (hash + kFix3HashSize)[h3] =
- (hash + kFix4HashSize)[hv] = p->pos;
- }
- SKIP_FOOTER
-}
-
-static void Bt5_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
-{
- SKIP_HEADER(5)
- {
- UInt32 h2, h3;
- UInt32 *hash;
- HASH5_CALC;
- hash = p->hash;
- curMatch = (hash + kFix5HashSize)[hv];
- hash [h2] =
- (hash + kFix3HashSize)[h3] =
- // (hash + kFix4HashSize)[h4] =
- (hash + kFix5HashSize)[hv] = p->pos;
- }
- SKIP_FOOTER
-}
-
-
-#define HC_SKIP_HEADER(minLen) \
- do { if (p->lenLimit < minLen) { MatchFinder_MovePos(p); num--; continue; } { \
- Byte *cur; \
- UInt32 *hash; \
- UInt32 *son; \
- UInt32 pos = p->pos; \
- UInt32 num2 = num; \
- /* (p->pos == p->posLimit) is not allowed here !!! */ \
- { const UInt32 rem = p->posLimit - pos; if (num2 > rem) num2 = rem; } \
- num -= num2; \
- { const UInt32 cycPos = p->cyclicBufferPos; \
- son = p->son + cycPos; \
- p->cyclicBufferPos = cycPos + num2; } \
- cur = p->buffer; \
- hash = p->hash; \
- do { \
- UInt32 curMatch; \
- UInt32 hv;
-
-
-#define HC_SKIP_FOOTER \
- cur++; pos++; *son++ = curMatch; \
- } while (--num2); \
- p->buffer = cur; \
- p->pos = pos; \
- if (pos == p->posLimit) MatchFinder_CheckLimits(p); \
- }} while(num); \
-
-
-static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
-{
- HC_SKIP_HEADER(4)
-
- UInt32 h2, h3;
- HASH4_CALC;
- curMatch = (hash + kFix4HashSize)[hv];
- hash [h2] =
- (hash + kFix3HashSize)[h3] =
- (hash + kFix4HashSize)[hv] = pos;
-
- HC_SKIP_FOOTER
-}
-
-
-static void Hc5_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
-{
- HC_SKIP_HEADER(5)
-
- UInt32 h2, h3;
- HASH5_CALC
- curMatch = (hash + kFix5HashSize)[hv];
- hash [h2] =
- (hash + kFix3HashSize)[h3] =
- // (hash + kFix4HashSize)[h4] =
- (hash + kFix5HashSize)[hv] = pos;
-
- HC_SKIP_FOOTER
-}
-
-
-void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
-{
- HC_SKIP_HEADER(3)
-
- HASH_ZIP_CALC;
- curMatch = hash[hv];
- hash[hv] = pos;
-
- HC_SKIP_FOOTER
-}
-
-
-void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder2 *vTable)
-{
- 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->numHashBytes <= 4)
- {
- vTable->GetMatches = (Mf_GetMatches_Func)Hc4_MatchFinder_GetMatches;
- vTable->Skip = (Mf_Skip_Func)Hc4_MatchFinder_Skip;
- }
- else
- {
- vTable->GetMatches = (Mf_GetMatches_Func)Hc5_MatchFinder_GetMatches;
- vTable->Skip = (Mf_Skip_Func)Hc5_MatchFinder_Skip;
- }
- }
- 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->GetMatches = (Mf_GetMatches_Func)Bt3_MatchFinder_GetMatches;
- 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;
- }
- else
- {
- vTable->GetMatches = (Mf_GetMatches_Func)Bt5_MatchFinder_GetMatches;
- vTable->Skip = (Mf_Skip_Func)Bt5_MatchFinder_Skip;
- }
-}
-
-
-
-void LzFindPrepare()
-{
- #ifndef FORCE_SATUR_SUB_128
- #ifdef USE_SATUR_SUB_128
- LZFIND_SATUR_SUB_CODE_FUNC f = NULL;
- #ifdef MY_CPU_ARM_OR_ARM64
- {
- if (CPU_IsSupported_NEON())
- {
- // #pragma message ("=== LzFind NEON")
- _PRF(printf("\n=== LzFind NEON\n"));
- f = LzFind_SaturSub_128;
- }
- // f = 0; // for debug
- }
- #else // MY_CPU_ARM_OR_ARM64
- if (CPU_IsSupported_SSE41())
- {
- // #pragma message ("=== LzFind SSE41")
- _PRF(printf("\n=== LzFind SSE41\n"));
- f = LzFind_SaturSub_128;
-
- #ifdef USE_AVX2
- if (CPU_IsSupported_AVX2())
- {
- // #pragma message ("=== LzFind AVX2")
- _PRF(printf("\n=== LzFind AVX2\n"));
- f = LzFind_SaturSub_256;
- }
- #endif
- }
- #endif // MY_CPU_ARM_OR_ARM64
- g_LzFind_SaturSub = f;
- #endif // USE_SATUR_SUB_128
- #endif // FORCE_SATUR_SUB_128
-}
+/* LzFind.c -- Match finder for LZ algorithms
+2024-03-01 : Igor Pavlov : Public domain */
+
+#include "Precomp.h"
+
+#include
+// #include
+
+#include "CpuArch.h"
+#include "LzFind.h"
+#include "LzHash.h"
+
+#define kBlockMoveAlign (1 << 7) // alignment for memmove()
+#define kBlockSizeAlign (1 << 16) // alignment for block allocation
+#define kBlockSizeReserveMin (1 << 24) // it's 1/256 from 4 GB dictinary
+
+#define kEmptyHashValue 0
+
+#define kMaxValForNormalize ((UInt32)0)
+// #define kMaxValForNormalize ((UInt32)(1 << 20) + 0xfff) // for debug
+
+// #define kNormalizeAlign (1 << 7) // alignment for speculated accesses
+
+#define GET_AVAIL_BYTES(p) \
+ Inline_MatchFinder_GetNumAvailableBytes(p)
+
+
+// #define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size)
+#define kFix5HashSize kFix4HashSize
+
+/*
+ HASH2_CALC:
+ if (hv) match, then cur[0] and cur[1] also match
+*/
+#define HASH2_CALC hv = GetUi16(cur);
+
+// (crc[0 ... 255] & 0xFF) provides one-to-one correspondence to [0 ... 255]
+
+/*
+ HASH3_CALC:
+ if (cur[0]) and (h2) match, then cur[1] also match
+ if (cur[0]) and (hv) match, then cur[1] and cur[2] also match
+*/
+#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 { \
+ 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]] << kLzHash_CrcShift_1)) & p->hashMask; }
+
+#define HASH5_CALC { \
+ UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
+ h2 = temp & (kHash2Size - 1); \
+ temp ^= ((UInt32)cur[2] << 8); \
+ h3 = temp & (kHash3Size - 1); \
+ temp ^= (p->crc[cur[3]] << kLzHash_CrcShift_1); \
+ /* h4 = temp & p->hash4Mask; */ /* (kHash4Size - 1); */ \
+ hv = (temp ^ (p->crc[cur[4]] << kLzHash_CrcShift_2)) & p->hashMask; }
+
+#define HASH_ZIP_CALC hv = ((cur[2] | ((UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF;
+
+
+static void LzInWindow_Free(CMatchFinder *p, ISzAllocPtr alloc)
+{
+ // if (!p->directInput)
+ {
+ ISzAlloc_Free(alloc, p->bufBase);
+ p->bufBase = NULL;
+ }
+}
+
+
+static int LzInWindow_Create2(CMatchFinder *p, UInt32 blockSize, ISzAllocPtr alloc)
+{
+ if (blockSize == 0)
+ return 0;
+ if (!p->bufBase || p->blockSize != blockSize)
+ {
+ // size_t blockSizeT;
+ LzInWindow_Free(p, alloc);
+ p->blockSize = blockSize;
+ // blockSizeT = blockSize;
+
+ // printf("\nblockSize = 0x%x\n", blockSize);
+ /*
+ #if defined _WIN64
+ // we can allocate 4GiB, but still use UInt32 for (p->blockSize)
+ // we use UInt32 type for (p->blockSize), because
+ // we don't want to wrap over 4 GiB,
+ // when we use (p->streamPos - p->pos) that is UInt32.
+ if (blockSize >= (UInt32)0 - (UInt32)kBlockSizeAlign)
+ {
+ blockSizeT = ((size_t)1 << 32);
+ printf("\nchanged to blockSizeT = 4GiB\n");
+ }
+ #endif
+ */
+
+ p->bufBase = (Byte *)ISzAlloc_Alloc(alloc, blockSize);
+ // printf("\nbufferBase = %p\n", p->bufBase);
+ // return 0; // for debug
+ }
+ return (p->bufBase != NULL);
+}
+
+static const Byte *MatchFinder_GetPointerToCurrentPos(void *p)
+{
+ return ((CMatchFinder *)p)->buffer;
+}
+
+static UInt32 MatchFinder_GetNumAvailableBytes(void *p)
+{
+ return GET_AVAIL_BYTES((CMatchFinder *)p);
+}
+
+
+Z7_NO_INLINE
+static void MatchFinder_ReadBlock(CMatchFinder *p)
+{
+ 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 - GET_AVAIL_BYTES(p);
+ if (curSize > p->directInputRem)
+ curSize = (UInt32)p->directInputRem;
+ p->streamPos += curSize;
+ p->directInputRem -= curSize;
+ if (p->directInputRem == 0)
+ p->streamEndWasReached = 1;
+ return;
+ }
+
+ for (;;)
+ {
+ const Byte *dest = p->buffer + GET_AVAIL_BYTES(p);
+ size_t size = (size_t)(p->bufBase + p->blockSize - dest);
+ if (size == 0)
+ {
+ /* we call ReadBlock() after NeedMove() and MoveBlock().
+ NeedMove() and MoveBlock() povide more than (keepSizeAfter)
+ to the end of (blockSize).
+ So we don't execute this branch in normal code flow.
+ We can go here, if we will call ReadBlock() before NeedMove(), MoveBlock().
+ */
+ // p->result = SZ_ERROR_FAIL; // we can show error here
+ return;
+ }
+
+ // #define kRead 3
+ // if (size > kRead) size = kRead; // for debug
+
+ /*
+ // we need cast (Byte *)dest.
+ #ifdef __clang__
+ #pragma GCC diagnostic ignored "-Wcast-qual"
+ #endif
+ */
+ p->result = ISeqInStream_Read(p->stream,
+ p->bufBase + (dest - p->bufBase), &size);
+ if (p->result != SZ_OK)
+ return;
+ if (size == 0)
+ {
+ p->streamEndWasReached = 1;
+ return;
+ }
+ p->streamPos += (UInt32)size;
+ if (GET_AVAIL_BYTES(p) > p->keepSizeAfter)
+ return;
+ /* here and in another (p->keepSizeAfter) checks we keep on 1 byte more than was requested by Create() function
+ (GET_AVAIL_BYTES(p) >= p->keepSizeAfter) - minimal required size */
+ }
+
+ // on exit: (p->result != SZ_OK || p->streamEndWasReached || GET_AVAIL_BYTES(p) > p->keepSizeAfter)
+}
+
+
+
+Z7_NO_INLINE
+void MatchFinder_MoveBlock(CMatchFinder *p)
+{
+ const size_t offset = (size_t)(p->buffer - p->bufBase) - p->keepSizeBefore;
+ const size_t keepBefore = (offset & (kBlockMoveAlign - 1)) + p->keepSizeBefore;
+ p->buffer = p->bufBase + keepBefore;
+ memmove(p->bufBase,
+ p->bufBase + (offset & ~((size_t)kBlockMoveAlign - 1)),
+ keepBefore + (size_t)GET_AVAIL_BYTES(p));
+}
+
+/* We call MoveBlock() before ReadBlock().
+ So MoveBlock() can be wasteful operation, if the whole input data
+ can fit in current block even without calling MoveBlock().
+ in important case where (dataSize <= historySize)
+ condition (p->blockSize > dataSize + p->keepSizeAfter) is met
+ So there is no MoveBlock() in that case case.
+*/
+
+int MatchFinder_NeedMove(CMatchFinder *p)
+{
+ if (p->directInput)
+ return 0;
+ if (p->streamEndWasReached || p->result != SZ_OK)
+ return 0;
+ return ((size_t)(p->bufBase + p->blockSize - p->buffer) <= p->keepSizeAfter);
+}
+
+void MatchFinder_ReadIfRequired(CMatchFinder *p)
+{
+ if (p->keepSizeAfter >= GET_AVAIL_BYTES(p))
+ MatchFinder_ReadBlock(p);
+}
+
+
+
+static void MatchFinder_SetDefaultSettings(CMatchFinder *p)
+{
+ p->cutValue = 32;
+ p->btMode = 1;
+ p->numHashBytes = 4;
+ p->numHashBytes_Min = 2;
+ p->numHashOutBits = 0;
+ p->bigHash = 0;
+}
+
+#define kCrcPoly 0xEDB88320
+
+void MatchFinder_Construct(CMatchFinder *p)
+{
+ unsigned i;
+ p->buffer = NULL;
+ p->bufBase = NULL;
+ p->directInput = 0;
+ p->stream = NULL;
+ p->hash = NULL;
+ p->expectedDataSize = (UInt64)(Int64)-1;
+ MatchFinder_SetDefaultSettings(p);
+
+ 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;
+ }
+}
+
+#undef kCrcPoly
+
+static void MatchFinder_FreeThisClassMemory(CMatchFinder *p, ISzAllocPtr alloc)
+{
+ ISzAlloc_Free(alloc, p->hash);
+ p->hash = NULL;
+}
+
+void MatchFinder_Free(CMatchFinder *p, ISzAllocPtr alloc)
+{
+ MatchFinder_FreeThisClassMemory(p, alloc);
+ LzInWindow_Free(p, alloc);
+}
+
+static CLzRef* AllocRefs(size_t num, ISzAllocPtr alloc)
+{
+ const size_t sizeInBytes = (size_t)num * sizeof(CLzRef);
+ if (sizeInBytes / sizeof(CLzRef) != num)
+ return NULL;
+ return (CLzRef *)ISzAlloc_Alloc(alloc, sizeInBytes);
+}
+
+#if (kBlockSizeReserveMin < kBlockSizeAlign * 2)
+ #error Stop_Compiling_Bad_Reserve
+#endif
+
+
+
+static UInt32 GetBlockSize(CMatchFinder *p, UInt32 historySize)
+{
+ UInt32 blockSize = (p->keepSizeBefore + p->keepSizeAfter);
+ /*
+ if (historySize > kMaxHistorySize)
+ return 0;
+ */
+ // printf("\nhistorySize == 0x%x\n", historySize);
+
+ if (p->keepSizeBefore < historySize || blockSize < p->keepSizeBefore) // if 32-bit overflow
+ return 0;
+
+ {
+ const UInt32 kBlockSizeMax = (UInt32)0 - (UInt32)kBlockSizeAlign;
+ const UInt32 rem = kBlockSizeMax - blockSize;
+ const UInt32 reserve = (blockSize >> (blockSize < ((UInt32)1 << 30) ? 1 : 2))
+ + (1 << 12) + kBlockMoveAlign + kBlockSizeAlign; // do not overflow 32-bit here
+ if (blockSize >= kBlockSizeMax
+ || rem < kBlockSizeReserveMin) // we reject settings that will be slow
+ return 0;
+ if (reserve >= rem)
+ blockSize = kBlockSizeMax;
+ else
+ {
+ blockSize += reserve;
+ blockSize &= ~(UInt32)(kBlockSizeAlign - 1);
+ }
+ }
+ // printf("\n LzFind_blockSize = %x\n", blockSize);
+ // printf("\n LzFind_blockSize = %d\n", blockSize >> 20);
+ return blockSize;
+}
+
+
+// input is historySize
+static UInt32 MatchFinder_GetHashMask2(CMatchFinder *p, UInt32 hs)
+{
+ if (p->numHashBytes == 2)
+ return (1 << 16) - 1;
+ if (hs != 0)
+ hs--;
+ hs |= (hs >> 1);
+ hs |= (hs >> 2);
+ hs |= (hs >> 4);
+ hs |= (hs >> 8);
+ // we propagated 16 bits in (hs). Low 16 bits must be set later
+ if (hs >= (1 << 24))
+ {
+ if (p->numHashBytes == 3)
+ hs = (1 << 24) - 1;
+ /* if (bigHash) mode, GetHeads4b() in LzFindMt.c needs (hs >= ((1 << 24) - 1))) */
+ }
+ // (hash_size >= (1 << 16)) : Required for (numHashBytes > 2)
+ hs |= (1 << 16) - 1; /* don't change it! */
+ // bt5: we adjust the size with recommended minimum size
+ if (p->numHashBytes >= 5)
+ hs |= (256 << kLzHash_CrcShift_2) - 1;
+ return hs;
+}
+
+// input is historySize
+static UInt32 MatchFinder_GetHashMask(CMatchFinder *p, UInt32 hs)
+{
+ if (p->numHashBytes == 2)
+ return (1 << 16) - 1;
+ if (hs != 0)
+ hs--;
+ hs |= (hs >> 1);
+ hs |= (hs >> 2);
+ hs |= (hs >> 4);
+ hs |= (hs >> 8);
+ // we propagated 16 bits in (hs). Low 16 bits must be set later
+ hs >>= 1;
+ if (hs >= (1 << 24))
+ {
+ if (p->numHashBytes == 3)
+ hs = (1 << 24) - 1;
+ else
+ hs >>= 1;
+ /* if (bigHash) mode, GetHeads4b() in LzFindMt.c needs (hs >= ((1 << 24) - 1))) */
+ }
+ // (hash_size >= (1 << 16)) : Required for (numHashBytes > 2)
+ hs |= (1 << 16) - 1; /* don't change it! */
+ // bt5: we adjust the size with recommended minimum size
+ if (p->numHashBytes >= 5)
+ hs |= (256 << kLzHash_CrcShift_2) - 1;
+ return hs;
+}
+
+
+int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
+ UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,
+ ISzAllocPtr alloc)
+{
+ /* we need one additional byte in (p->keepSizeBefore),
+ since we use MoveBlock() after (p->pos++) and before dictionary using */
+ // keepAddBufferBefore = (UInt32)0xFFFFFFFF - (1 << 22); // for debug
+ p->keepSizeBefore = historySize + keepAddBufferBefore + 1;
+
+ keepAddBufferAfter += matchMaxLen;
+ /* we need (p->keepSizeAfter >= p->numHashBytes) */
+ if (keepAddBufferAfter < p->numHashBytes)
+ keepAddBufferAfter = p->numHashBytes;
+ // keepAddBufferAfter -= 2; // for debug
+ p->keepSizeAfter = keepAddBufferAfter;
+
+ if (p->directInput)
+ p->blockSize = 0;
+ if (p->directInput || LzInWindow_Create2(p, GetBlockSize(p, historySize), alloc))
+ {
+ size_t hashSizeSum;
+ {
+ UInt32 hs;
+ UInt32 hsCur;
+
+ if (p->numHashOutBits != 0)
+ {
+ unsigned numBits = p->numHashOutBits;
+ const unsigned nbMax =
+ (p->numHashBytes == 2 ? 16 :
+ (p->numHashBytes == 3 ? 24 : 32));
+ if (numBits > nbMax)
+ numBits = nbMax;
+ if (numBits >= 32)
+ hs = (UInt32)0 - 1;
+ else
+ hs = ((UInt32)1 << numBits) - 1;
+ // (hash_size >= (1 << 16)) : Required for (numHashBytes > 2)
+ hs |= (1 << 16) - 1; /* don't change it! */
+ if (p->numHashBytes >= 5)
+ hs |= (256 << kLzHash_CrcShift_2) - 1;
+ {
+ const UInt32 hs2 = MatchFinder_GetHashMask2(p, historySize);
+ if (hs > hs2)
+ hs = hs2;
+ }
+ hsCur = hs;
+ if (p->expectedDataSize < historySize)
+ {
+ const UInt32 hs2 = MatchFinder_GetHashMask2(p, (UInt32)p->expectedDataSize);
+ if (hsCur > hs2)
+ hsCur = hs2;
+ }
+ }
+ else
+ {
+ hs = MatchFinder_GetHashMask(p, historySize);
+ hsCur = hs;
+ if (p->expectedDataSize < historySize)
+ {
+ hsCur = MatchFinder_GetHashMask(p, (UInt32)p->expectedDataSize);
+ if (hsCur > hs) // is it possible?
+ hsCur = hs;
+ }
+ }
+
+ p->hashMask = hsCur;
+
+ hashSizeSum = hs;
+ hashSizeSum++;
+ if (hashSizeSum < hs)
+ return 0;
+ {
+ UInt32 fixedHashSize = 0;
+ if (p->numHashBytes > 2 && p->numHashBytes_Min <= 2) fixedHashSize += kHash2Size;
+ if (p->numHashBytes > 3 && p->numHashBytes_Min <= 3) fixedHashSize += kHash3Size;
+ // if (p->numHashBytes > 4) p->fixedHashSize += hs4; // kHash4Size;
+ hashSizeSum += fixedHashSize;
+ p->fixedHashSize = fixedHashSize;
+ }
+ }
+
+ p->matchMaxLen = matchMaxLen;
+
+ {
+ size_t newSize;
+ size_t numSons;
+ const UInt32 newCyclicBufferSize = historySize + 1; // do not change it
+ p->historySize = historySize;
+ p->cyclicBufferSize = newCyclicBufferSize; // it must be = (historySize + 1)
+
+ numSons = newCyclicBufferSize;
+ if (p->btMode)
+ numSons <<= 1;
+ newSize = hashSizeSum + numSons;
+
+ if (numSons < newCyclicBufferSize || newSize < numSons)
+ return 0;
+
+ // aligned size is not required here, but it can be better for some loops
+ #define NUM_REFS_ALIGN_MASK 0xF
+ newSize = (newSize + NUM_REFS_ALIGN_MASK) & ~(size_t)NUM_REFS_ALIGN_MASK;
+
+ // 22.02: we don't reallocate buffer, if old size is enough
+ if (p->hash && p->numRefs >= newSize)
+ return 1;
+
+ MatchFinder_FreeThisClassMemory(p, alloc);
+ p->numRefs = newSize;
+ p->hash = AllocRefs(newSize, alloc);
+
+ if (p->hash)
+ {
+ p->son = p->hash + hashSizeSum;
+ return 1;
+ }
+ }
+ }
+
+ MatchFinder_Free(p, alloc);
+ return 0;
+}
+
+
+static void MatchFinder_SetLimits(CMatchFinder *p)
+{
+ UInt32 k;
+ UInt32 n = kMaxValForNormalize - p->pos;
+ if (n == 0)
+ n = (UInt32)(Int32)-1; // we allow (pos == 0) at start even with (kMaxValForNormalize == 0)
+
+ k = p->cyclicBufferSize - p->cyclicBufferPos;
+ if (k < n)
+ n = k;
+
+ k = GET_AVAIL_BYTES(p);
+ {
+ const UInt32 ksa = p->keepSizeAfter;
+ UInt32 mm = p->matchMaxLen;
+ if (k > ksa)
+ k -= ksa; // we must limit exactly to keepSizeAfter for ReadBlock
+ else if (k >= mm)
+ {
+ // the limitation for (p->lenLimit) update
+ k -= mm; // optimization : to reduce the number of checks
+ k++;
+ // k = 1; // non-optimized version : for debug
+ }
+ else
+ {
+ mm = k;
+ if (k != 0)
+ k = 1;
+ }
+ p->lenLimit = mm;
+ }
+ if (k < n)
+ n = k;
+
+ p->posLimit = p->pos + n;
+}
+
+
+void MatchFinder_Init_LowHash(CMatchFinder *p)
+{
+ size_t i;
+ CLzRef *items = p->hash;
+ const size_t numItems = p->fixedHashSize;
+ for (i = 0; i < numItems; i++)
+ items[i] = kEmptyHashValue;
+}
+
+
+void MatchFinder_Init_HighHash(CMatchFinder *p)
+{
+ size_t i;
+ CLzRef *items = p->hash + p->fixedHashSize;
+ const size_t numItems = (size_t)p->hashMask + 1;
+ for (i = 0; i < numItems; i++)
+ items[i] = kEmptyHashValue;
+}
+
+
+void MatchFinder_Init_4(CMatchFinder *p)
+{
+ if (!p->directInput)
+ p->buffer = p->bufBase;
+ {
+ /* kEmptyHashValue = 0 (Zero) is used in hash tables as NO-VALUE marker.
+ the code in CMatchFinderMt expects (pos = 1) */
+ p->pos =
+ p->streamPos =
+ 1; // it's smallest optimal value. do not change it
+ // 0; // for debug
+ }
+ p->result = SZ_OK;
+ p->streamEndWasReached = 0;
+}
+
+
+// (CYC_TO_POS_OFFSET == 0) is expected by some optimized code
+#define CYC_TO_POS_OFFSET 0
+// #define CYC_TO_POS_OFFSET 1 // for debug
+
+void MatchFinder_Init(void *_p)
+{
+ CMatchFinder *p = (CMatchFinder *)_p;
+ MatchFinder_Init_HighHash(p);
+ MatchFinder_Init_LowHash(p);
+ MatchFinder_Init_4(p);
+ // if (readData)
+ MatchFinder_ReadBlock(p);
+
+ /* if we init (cyclicBufferPos = pos), then we can use one variable
+ instead of both (cyclicBufferPos) and (pos) : only before (cyclicBufferPos) wrapping */
+ p->cyclicBufferPos = (p->pos - CYC_TO_POS_OFFSET); // init with relation to (pos)
+ // p->cyclicBufferPos = 0; // smallest value
+ // p->son[0] = p->son[1] = 0; // unused: we can init skipped record for speculated accesses.
+ MatchFinder_SetLimits(p);
+}
+
+
+
+#ifdef MY_CPU_X86_OR_AMD64
+ #if defined(__clang__) && (__clang_major__ >= 4) \
+ || defined(Z7_GCC_VERSION) && (Z7_GCC_VERSION >= 40701)
+ // || defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 1900)
+
+ #define USE_LZFIND_SATUR_SUB_128
+ #define USE_LZFIND_SATUR_SUB_256
+ #define LZFIND_ATTRIB_SSE41 __attribute__((__target__("sse4.1")))
+ #define LZFIND_ATTRIB_AVX2 __attribute__((__target__("avx2")))
+ #elif defined(_MSC_VER)
+ #if (_MSC_VER >= 1600)
+ #define USE_LZFIND_SATUR_SUB_128
+ #endif
+ #if (_MSC_VER >= 1900)
+ #define USE_LZFIND_SATUR_SUB_256
+ #endif
+ #endif
+
+#elif defined(MY_CPU_ARM64) \
+ /* || (defined(__ARM_ARCH) && (__ARM_ARCH >= 7)) */
+
+ #if defined(Z7_CLANG_VERSION) && (Z7_CLANG_VERSION >= 30800) \
+ || defined(__GNUC__) && (__GNUC__ >= 6)
+ #define USE_LZFIND_SATUR_SUB_128
+ #ifdef MY_CPU_ARM64
+ // #define LZFIND_ATTRIB_SSE41 __attribute__((__target__("")))
+ #else
+ #define LZFIND_ATTRIB_SSE41 __attribute__((__target__("fpu=neon")))
+ #endif
+
+ #elif defined(_MSC_VER)
+ #if (_MSC_VER >= 1910)
+ #define USE_LZFIND_SATUR_SUB_128
+ #endif
+ #endif
+
+ #if defined(Z7_MSC_VER_ORIGINAL) && defined(MY_CPU_ARM64)
+ #include
+ #else
+ #include
+ #endif
+
+#endif
+
+
+#ifdef USE_LZFIND_SATUR_SUB_128
+
+// #define Z7_SHOW_HW_STATUS
+
+#ifdef Z7_SHOW_HW_STATUS
+#include
+#define PRF(x) x
+PRF(;)
+#else
+#define PRF(x)
+#endif
+
+
+#ifdef MY_CPU_ARM_OR_ARM64
+
+#ifdef MY_CPU_ARM64
+// #define FORCE_LZFIND_SATUR_SUB_128
+#endif
+typedef uint32x4_t LzFind_v128;
+#define SASUB_128_V(v, s) \
+ vsubq_u32(vmaxq_u32(v, s), s)
+
+#else // MY_CPU_ARM_OR_ARM64
+
+#include // sse4.1
+
+typedef __m128i LzFind_v128;
+// SSE 4.1
+#define SASUB_128_V(v, s) \
+ _mm_sub_epi32(_mm_max_epu32(v, s), s)
+
+#endif // MY_CPU_ARM_OR_ARM64
+
+
+#define SASUB_128(i) \
+ *( LzFind_v128 *)( void *)(items + (i) * 4) = SASUB_128_V( \
+ *(const LzFind_v128 *)(const void *)(items + (i) * 4), sub2);
+
+
+Z7_NO_INLINE
+static
+#ifdef LZFIND_ATTRIB_SSE41
+LZFIND_ATTRIB_SSE41
+#endif
+void
+Z7_FASTCALL
+LzFind_SaturSub_128(UInt32 subValue, CLzRef *items, const CLzRef *lim)
+{
+ const LzFind_v128 sub2 =
+ #ifdef MY_CPU_ARM_OR_ARM64
+ vdupq_n_u32(subValue);
+ #else
+ _mm_set_epi32((Int32)subValue, (Int32)subValue, (Int32)subValue, (Int32)subValue);
+ #endif
+ Z7_PRAGMA_OPT_DISABLE_LOOP_UNROLL_VECTORIZE
+ do
+ {
+ SASUB_128(0) SASUB_128(1) items += 2 * 4;
+ SASUB_128(0) SASUB_128(1) items += 2 * 4;
+ }
+ while (items != lim);
+}
+
+
+
+#ifdef USE_LZFIND_SATUR_SUB_256
+
+#include // avx
+/*
+clang :immintrin.h uses
+#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) || \
+ defined(__AVX2__)
+#include
+#endif
+so we need for clang-cl */
+
+#if defined(__clang__)
+#include
+#include
+#endif
+
+// AVX2:
+#define SASUB_256(i) \
+ *( __m256i *)( void *)(items + (i) * 8) = \
+ _mm256_sub_epi32(_mm256_max_epu32( \
+ *(const __m256i *)(const void *)(items + (i) * 8), sub2), sub2);
+
+Z7_NO_INLINE
+static
+#ifdef LZFIND_ATTRIB_AVX2
+LZFIND_ATTRIB_AVX2
+#endif
+void
+Z7_FASTCALL
+LzFind_SaturSub_256(UInt32 subValue, CLzRef *items, const CLzRef *lim)
+{
+ const __m256i sub2 = _mm256_set_epi32(
+ (Int32)subValue, (Int32)subValue, (Int32)subValue, (Int32)subValue,
+ (Int32)subValue, (Int32)subValue, (Int32)subValue, (Int32)subValue);
+ Z7_PRAGMA_OPT_DISABLE_LOOP_UNROLL_VECTORIZE
+ do
+ {
+ SASUB_256(0) SASUB_256(1) items += 2 * 8;
+ SASUB_256(0) SASUB_256(1) items += 2 * 8;
+ }
+ while (items != lim);
+}
+#endif // USE_LZFIND_SATUR_SUB_256
+
+#ifndef FORCE_LZFIND_SATUR_SUB_128
+typedef void (Z7_FASTCALL *LZFIND_SATUR_SUB_CODE_FUNC)(
+ UInt32 subValue, CLzRef *items, const CLzRef *lim);
+static LZFIND_SATUR_SUB_CODE_FUNC g_LzFind_SaturSub;
+#endif // FORCE_LZFIND_SATUR_SUB_128
+
+#endif // USE_LZFIND_SATUR_SUB_128
+
+
+// kEmptyHashValue must be zero
+// #define SASUB_32(i) { UInt32 v = items[i]; UInt32 m = v - subValue; if (v < subValue) m = kEmptyHashValue; items[i] = m; }
+#define SASUB_32(i) { UInt32 v = items[i]; if (v < subValue) v = subValue; items[i] = v - subValue; }
+
+#ifdef FORCE_LZFIND_SATUR_SUB_128
+
+#define DEFAULT_SaturSub LzFind_SaturSub_128
+
+#else
+
+#define DEFAULT_SaturSub LzFind_SaturSub_32
+
+Z7_NO_INLINE
+static
+void
+Z7_FASTCALL
+LzFind_SaturSub_32(UInt32 subValue, CLzRef *items, const CLzRef *lim)
+{
+ Z7_PRAGMA_OPT_DISABLE_LOOP_UNROLL_VECTORIZE
+ do
+ {
+ SASUB_32(0) SASUB_32(1) items += 2;
+ SASUB_32(0) SASUB_32(1) items += 2;
+ SASUB_32(0) SASUB_32(1) items += 2;
+ SASUB_32(0) SASUB_32(1) items += 2;
+ }
+ while (items != lim);
+}
+
+#endif
+
+
+Z7_NO_INLINE
+void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, size_t numItems)
+{
+ #define LZFIND_NORM_ALIGN_BLOCK_SIZE (1 << 7)
+ Z7_PRAGMA_OPT_DISABLE_LOOP_UNROLL_VECTORIZE
+ for (; numItems != 0 && ((unsigned)(ptrdiff_t)items & (LZFIND_NORM_ALIGN_BLOCK_SIZE - 1)) != 0; numItems--)
+ {
+ SASUB_32(0)
+ items++;
+ }
+ {
+ const size_t k_Align_Mask = (LZFIND_NORM_ALIGN_BLOCK_SIZE / 4 - 1);
+ CLzRef *lim = items + (numItems & ~(size_t)k_Align_Mask);
+ numItems &= k_Align_Mask;
+ if (items != lim)
+ {
+ #if defined(USE_LZFIND_SATUR_SUB_128) && !defined(FORCE_LZFIND_SATUR_SUB_128)
+ if (g_LzFind_SaturSub)
+ g_LzFind_SaturSub(subValue, items, lim);
+ else
+ #endif
+ DEFAULT_SaturSub(subValue, items, lim);
+ }
+ items = lim;
+ }
+ Z7_PRAGMA_OPT_DISABLE_LOOP_UNROLL_VECTORIZE
+ for (; numItems != 0; numItems--)
+ {
+ SASUB_32(0)
+ items++;
+ }
+}
+
+
+
+// call MatchFinder_CheckLimits() only after (p->pos++) update
+
+Z7_NO_INLINE
+static void MatchFinder_CheckLimits(CMatchFinder *p)
+{
+ if (// !p->streamEndWasReached && p->result == SZ_OK &&
+ p->keepSizeAfter == GET_AVAIL_BYTES(p))
+ {
+ // we try to read only in exact state (p->keepSizeAfter == GET_AVAIL_BYTES(p))
+ if (MatchFinder_NeedMove(p))
+ MatchFinder_MoveBlock(p);
+ MatchFinder_ReadBlock(p);
+ }
+
+ if (p->pos == kMaxValForNormalize)
+ if (GET_AVAIL_BYTES(p) >= p->numHashBytes) // optional optimization for last bytes of data.
+ /*
+ if we disable normalization for last bytes of data, and
+ if (data_size == 4 GiB), we don't call wastfull normalization,
+ but (pos) will be wrapped over Zero (0) in that case.
+ And we cannot resume later to normal operation
+ */
+ {
+ // MatchFinder_Normalize(p);
+ /* after normalization we need (p->pos >= p->historySize + 1); */
+ /* we can reduce subValue to aligned value, if want to keep alignment
+ of (p->pos) and (p->buffer) for speculated accesses. */
+ const UInt32 subValue = (p->pos - p->historySize - 1) /* & ~(UInt32)(kNormalizeAlign - 1) */;
+ // const UInt32 subValue = (1 << 15); // for debug
+ // printf("\nMatchFinder_Normalize() subValue == 0x%x\n", subValue);
+ MatchFinder_REDUCE_OFFSETS(p, subValue)
+ MatchFinder_Normalize3(subValue, p->hash, (size_t)p->hashMask + 1 + p->fixedHashSize);
+ {
+ size_t numSonRefs = p->cyclicBufferSize;
+ if (p->btMode)
+ numSonRefs <<= 1;
+ MatchFinder_Normalize3(subValue, p->son, numSonRefs);
+ }
+ }
+
+ if (p->cyclicBufferPos == p->cyclicBufferSize)
+ p->cyclicBufferPos = 0;
+
+ MatchFinder_SetLimits(p);
+}
+
+
+/*
+ (lenLimit > maxLen)
+*/
+Z7_FORCE_INLINE
+static UInt32 * Hc_GetMatchesSpec(size_t lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
+ size_t _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
+ UInt32 *d, unsigned maxLen)
+{
+ /*
+ son[_cyclicBufferPos] = curMatch;
+ for (;;)
+ {
+ UInt32 delta = pos - curMatch;
+ if (cutValue-- == 0 || delta >= _cyclicBufferSize)
+ return d;
+ {
+ const Byte *pb = cur - delta;
+ curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)];
+ if (pb[maxLen] == cur[maxLen] && *pb == *cur)
+ {
+ UInt32 len = 0;
+ while (++len != lenLimit)
+ if (pb[len] != cur[len])
+ break;
+ if (maxLen < len)
+ {
+ maxLen = len;
+ *d++ = len;
+ *d++ = delta - 1;
+ if (len == lenLimit)
+ return d;
+ }
+ }
+ }
+ }
+ */
+
+ const Byte *lim = cur + lenLimit;
+ son[_cyclicBufferPos] = curMatch;
+
+ do
+ {
+ UInt32 delta;
+
+ if (curMatch == 0)
+ break;
+ // if (curMatch2 >= curMatch) return NULL;
+ delta = pos - curMatch;
+ if (delta >= _cyclicBufferSize)
+ break;
+ {
+ ptrdiff_t diff;
+ curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)];
+ diff = (ptrdiff_t)0 - (ptrdiff_t)delta;
+ if (cur[maxLen] == cur[(ptrdiff_t)maxLen + diff])
+ {
+ const Byte *c = cur;
+ while (*c == c[diff])
+ {
+ if (++c == lim)
+ {
+ d[0] = (UInt32)(lim - cur);
+ d[1] = delta - 1;
+ return d + 2;
+ }
+ }
+ {
+ const unsigned len = (unsigned)(c - cur);
+ if (maxLen < len)
+ {
+ maxLen = len;
+ d[0] = (UInt32)len;
+ d[1] = delta - 1;
+ d += 2;
+ }
+ }
+ }
+ }
+ }
+ while (--cutValue);
+
+ return d;
+}
+
+
+Z7_FORCE_INLINE
+UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
+ size_t _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
+ UInt32 *d, UInt32 maxLen)
+{
+ CLzRef *ptr0 = son + ((size_t)_cyclicBufferPos << 1) + 1;
+ CLzRef *ptr1 = son + ((size_t)_cyclicBufferPos << 1);
+ unsigned len0 = 0, len1 = 0;
+
+ UInt32 cmCheck;
+
+ // if (curMatch >= pos) { *ptr0 = *ptr1 = kEmptyHashValue; return NULL; }
+
+ cmCheck = (UInt32)(pos - _cyclicBufferSize);
+ if ((UInt32)pos <= _cyclicBufferSize)
+ cmCheck = 0;
+
+ if (cmCheck < curMatch)
+ do
+ {
+ const UInt32 delta = pos - curMatch;
+ {
+ CLzRef *pair = son + ((size_t)(_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);
+ const Byte *pb = cur - delta;
+ unsigned len = (len0 < len1 ? len0 : len1);
+ const 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;
+ *d++ = (UInt32)len;
+ *d++ = delta - 1;
+ if (len == lenLimit)
+ {
+ *ptr1 = pair0;
+ *ptr0 = pair[1];
+ return d;
+ }
+ }
+ }
+ if (pb[len] < cur[len])
+ {
+ *ptr1 = curMatch;
+ // const UInt32 curMatch2 = pair[1];
+ // if (curMatch2 >= curMatch) { *ptr0 = *ptr1 = kEmptyHashValue; return NULL; }
+ // curMatch = curMatch2;
+ curMatch = pair[1];
+ ptr1 = pair + 1;
+ len1 = len;
+ }
+ else
+ {
+ *ptr0 = curMatch;
+ curMatch = pair[0];
+ ptr0 = pair;
+ len0 = len;
+ }
+ }
+ }
+ while(--cutValue && cmCheck < curMatch);
+
+ *ptr0 = *ptr1 = kEmptyHashValue;
+ return d;
+}
+
+
+static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
+ size_t _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;
+
+ UInt32 cmCheck;
+
+ cmCheck = (UInt32)(pos - _cyclicBufferSize);
+ if ((UInt32)pos <= _cyclicBufferSize)
+ cmCheck = 0;
+
+ if (// curMatch >= pos || // failure
+ cmCheck < curMatch)
+ do
+ {
+ const UInt32 delta = pos - curMatch;
+ {
+ 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)
+ {
+ *ptr1 = pair[0];
+ *ptr0 = pair[1];
+ return;
+ }
+ }
+ }
+ if (pb[len] < cur[len])
+ {
+ *ptr1 = curMatch;
+ curMatch = pair[1];
+ ptr1 = pair + 1;
+ len1 = len;
+ }
+ else
+ {
+ *ptr0 = curMatch;
+ curMatch = pair[0];
+ ptr0 = pair;
+ len0 = len;
+ }
+ }
+ }
+ while(--cutValue && cmCheck < curMatch);
+
+ *ptr0 = *ptr1 = kEmptyHashValue;
+ return;
+}
+
+
+#define MOVE_POS \
+ p->cyclicBufferPos++; \
+ p->buffer++; \
+ { const UInt32 pos1 = p->pos + 1; \
+ p->pos = pos1; \
+ if (pos1 == p->posLimit) MatchFinder_CheckLimits(p); }
+
+#define MOVE_POS_RET MOVE_POS return distances;
+
+Z7_NO_INLINE
+static void MatchFinder_MovePos(CMatchFinder *p)
+{
+ /* we go here at the end of stream data, when (avail < num_hash_bytes)
+ We don't update sons[cyclicBufferPos << btMode].
+ So (sons) record will contain junk. And we cannot resume match searching
+ to normal operation, even if we will provide more input data in buffer.
+ p->sons[p->cyclicBufferPos << p->btMode] = 0; // kEmptyHashValue
+ if (p->btMode)
+ p->sons[(p->cyclicBufferPos << p->btMode) + 1] = 0; // kEmptyHashValue
+ */
+ MOVE_POS
+}
+
+#define GET_MATCHES_HEADER2(minLen, ret_op) \
+ UInt32 hv; const Byte *cur; UInt32 curMatch; \
+ UInt32 lenLimit = p->lenLimit; \
+ if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; } \
+ cur = p->buffer;
+
+#define GET_MATCHES_HEADER(minLen) GET_MATCHES_HEADER2(minLen, return distances)
+#define SKIP_HEADER(minLen) \
+ do { GET_MATCHES_HEADER2(minLen, continue)
+
+#define MF_PARAMS(p) lenLimit, curMatch, p->pos, p->buffer, p->son, \
+ p->cyclicBufferPos, p->cyclicBufferSize, p->cutValue
+
+#define SKIP_FOOTER \
+ SkipMatchesSpec(MF_PARAMS(p)); \
+ MOVE_POS \
+ } while (--num);
+
+#define GET_MATCHES_FOOTER_BASE(_maxLen_, func) \
+ distances = func(MF_PARAMS(p), distances, (UInt32)_maxLen_); \
+ MOVE_POS_RET
+
+#define GET_MATCHES_FOOTER_BT(_maxLen_) \
+ GET_MATCHES_FOOTER_BASE(_maxLen_, GetMatchesSpec1)
+
+#define GET_MATCHES_FOOTER_HC(_maxLen_) \
+ GET_MATCHES_FOOTER_BASE(_maxLen_, Hc_GetMatchesSpec)
+
+
+
+#define UPDATE_maxLen { \
+ const ptrdiff_t diff = (ptrdiff_t)0 - (ptrdiff_t)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(void *_p, UInt32 *distances)
+{
+ CMatchFinder *p = (CMatchFinder *)_p;
+ GET_MATCHES_HEADER(2)
+ HASH2_CALC
+ curMatch = p->hash[hv];
+ p->hash[hv] = p->pos;
+ GET_MATCHES_FOOTER_BT(1)
+}
+
+UInt32* Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
+{
+ GET_MATCHES_HEADER(3)
+ HASH_ZIP_CALC
+ curMatch = p->hash[hv];
+ p->hash[hv] = p->pos;
+ GET_MATCHES_FOOTER_BT(2)
+}
+
+
+#define SET_mmm \
+ mmm = p->cyclicBufferSize; \
+ if (pos < mmm) \
+ mmm = pos;
+
+
+static UInt32* Bt3_MatchFinder_GetMatches(void *_p, UInt32 *distances)
+{
+ CMatchFinder *p = (CMatchFinder *)_p;
+ UInt32 mmm;
+ UInt32 h2, d2, pos;
+ unsigned maxLen;
+ UInt32 *hash;
+ GET_MATCHES_HEADER(3)
+
+ HASH3_CALC
+
+ hash = p->hash;
+ pos = p->pos;
+
+ d2 = pos - hash[h2];
+
+ curMatch = (hash + kFix3HashSize)[hv];
+
+ hash[h2] = pos;
+ (hash + kFix3HashSize)[hv] = pos;
+
+ SET_mmm
+
+ maxLen = 2;
+
+ if (d2 < mmm && *(cur - d2) == *cur)
+ {
+ UPDATE_maxLen
+ distances[0] = (UInt32)maxLen;
+ distances[1] = d2 - 1;
+ distances += 2;
+ if (maxLen == lenLimit)
+ {
+ SkipMatchesSpec(MF_PARAMS(p));
+ MOVE_POS_RET
+ }
+ }
+
+ GET_MATCHES_FOOTER_BT(maxLen)
+}
+
+
+static UInt32* Bt4_MatchFinder_GetMatches(void *_p, UInt32 *distances)
+{
+ CMatchFinder *p = (CMatchFinder *)_p;
+ UInt32 mmm;
+ UInt32 h2, h3, d2, d3, pos;
+ unsigned maxLen;
+ UInt32 *hash;
+ GET_MATCHES_HEADER(4)
+
+ HASH4_CALC
+
+ hash = p->hash;
+ pos = p->pos;
+
+ d2 = pos - hash [h2];
+ d3 = pos - (hash + kFix3HashSize)[h3];
+ curMatch = (hash + kFix4HashSize)[hv];
+
+ hash [h2] = pos;
+ (hash + kFix3HashSize)[h3] = pos;
+ (hash + kFix4HashSize)[hv] = pos;
+
+ SET_mmm
+
+ maxLen = 3;
+
+ for (;;)
+ {
+ if (d2 < mmm && *(cur - d2) == *cur)
+ {
+ distances[0] = 2;
+ distances[1] = d2 - 1;
+ distances += 2;
+ if (*(cur - d2 + 2) == cur[2])
+ {
+ // distances[-2] = 3;
+ }
+ else if (d3 < mmm && *(cur - d3) == *cur)
+ {
+ d2 = d3;
+ distances[1] = d3 - 1;
+ distances += 2;
+ }
+ else
+ break;
+ }
+ else if (d3 < mmm && *(cur - d3) == *cur)
+ {
+ d2 = d3;
+ distances[1] = d3 - 1;
+ distances += 2;
+ }
+ else
+ break;
+
+ UPDATE_maxLen
+ distances[-2] = (UInt32)maxLen;
+ if (maxLen == lenLimit)
+ {
+ SkipMatchesSpec(MF_PARAMS(p));
+ MOVE_POS_RET
+ }
+ break;
+ }
+
+ GET_MATCHES_FOOTER_BT(maxLen)
+}
+
+
+static UInt32* Bt5_MatchFinder_GetMatches(void *_p, UInt32 *distances)
+{
+ CMatchFinder *p = (CMatchFinder *)_p;
+ UInt32 mmm;
+ UInt32 h2, h3, d2, d3, pos;
+ unsigned maxLen;
+ UInt32 *hash;
+ GET_MATCHES_HEADER(5)
+
+ HASH5_CALC
+
+ hash = p->hash;
+ pos = p->pos;
+
+ d2 = pos - hash [h2];
+ d3 = pos - (hash + kFix3HashSize)[h3];
+ // d4 = pos - (hash + kFix4HashSize)[h4];
+
+ curMatch = (hash + kFix5HashSize)[hv];
+
+ hash [h2] = pos;
+ (hash + kFix3HashSize)[h3] = pos;
+ // (hash + kFix4HashSize)[h4] = pos;
+ (hash + kFix5HashSize)[hv] = pos;
+
+ SET_mmm
+
+ maxLen = 4;
+
+ for (;;)
+ {
+ if (d2 < mmm && *(cur - d2) == *cur)
+ {
+ distances[0] = 2;
+ distances[1] = d2 - 1;
+ distances += 2;
+ if (*(cur - d2 + 2) == cur[2])
+ {
+ }
+ else if (d3 < mmm && *(cur - d3) == *cur)
+ {
+ distances[1] = d3 - 1;
+ distances += 2;
+ d2 = d3;
+ }
+ else
+ break;
+ }
+ else if (d3 < mmm && *(cur - d3) == *cur)
+ {
+ distances[1] = d3 - 1;
+ distances += 2;
+ d2 = d3;
+ }
+ else
+ break;
+
+ distances[-2] = 3;
+ if (*(cur - d2 + 3) != cur[3])
+ break;
+ UPDATE_maxLen
+ distances[-2] = (UInt32)maxLen;
+ if (maxLen == lenLimit)
+ {
+ SkipMatchesSpec(MF_PARAMS(p));
+ MOVE_POS_RET
+ }
+ break;
+ }
+
+ GET_MATCHES_FOOTER_BT(maxLen)
+}
+
+
+static UInt32* Hc4_MatchFinder_GetMatches(void *_p, UInt32 *distances)
+{
+ CMatchFinder *p = (CMatchFinder *)_p;
+ UInt32 mmm;
+ UInt32 h2, h3, d2, d3, pos;
+ unsigned maxLen;
+ UInt32 *hash;
+ GET_MATCHES_HEADER(4)
+
+ HASH4_CALC
+
+ hash = p->hash;
+ pos = p->pos;
+
+ d2 = pos - hash [h2];
+ d3 = pos - (hash + kFix3HashSize)[h3];
+ curMatch = (hash + kFix4HashSize)[hv];
+
+ hash [h2] = pos;
+ (hash + kFix3HashSize)[h3] = pos;
+ (hash + kFix4HashSize)[hv] = pos;
+
+ SET_mmm
+
+ maxLen = 3;
+
+ for (;;)
+ {
+ if (d2 < mmm && *(cur - d2) == *cur)
+ {
+ distances[0] = 2;
+ distances[1] = d2 - 1;
+ distances += 2;
+ if (*(cur - d2 + 2) == cur[2])
+ {
+ // distances[-2] = 3;
+ }
+ else if (d3 < mmm && *(cur - d3) == *cur)
+ {
+ d2 = d3;
+ distances[1] = d3 - 1;
+ distances += 2;
+ }
+ else
+ break;
+ }
+ else if (d3 < mmm && *(cur - d3) == *cur)
+ {
+ d2 = d3;
+ distances[1] = d3 - 1;
+ distances += 2;
+ }
+ else
+ break;
+
+ UPDATE_maxLen
+ distances[-2] = (UInt32)maxLen;
+ if (maxLen == lenLimit)
+ {
+ p->son[p->cyclicBufferPos] = curMatch;
+ MOVE_POS_RET
+ }
+ break;
+ }
+
+ GET_MATCHES_FOOTER_HC(maxLen)
+}
+
+
+static UInt32 * Hc5_MatchFinder_GetMatches(void *_p, UInt32 *distances)
+{
+ CMatchFinder *p = (CMatchFinder *)_p;
+ UInt32 mmm;
+ UInt32 h2, h3, d2, d3, pos;
+ unsigned maxLen;
+ UInt32 *hash;
+ GET_MATCHES_HEADER(5)
+
+ HASH5_CALC
+
+ hash = p->hash;
+ pos = p->pos;
+
+ d2 = pos - hash [h2];
+ d3 = pos - (hash + kFix3HashSize)[h3];
+ // d4 = pos - (hash + kFix4HashSize)[h4];
+
+ curMatch = (hash + kFix5HashSize)[hv];
+
+ hash [h2] = pos;
+ (hash + kFix3HashSize)[h3] = pos;
+ // (hash + kFix4HashSize)[h4] = pos;
+ (hash + kFix5HashSize)[hv] = pos;
+
+ SET_mmm
+
+ maxLen = 4;
+
+ for (;;)
+ {
+ if (d2 < mmm && *(cur - d2) == *cur)
+ {
+ distances[0] = 2;
+ distances[1] = d2 - 1;
+ distances += 2;
+ if (*(cur - d2 + 2) == cur[2])
+ {
+ }
+ else if (d3 < mmm && *(cur - d3) == *cur)
+ {
+ distances[1] = d3 - 1;
+ distances += 2;
+ d2 = d3;
+ }
+ else
+ break;
+ }
+ else if (d3 < mmm && *(cur - d3) == *cur)
+ {
+ distances[1] = d3 - 1;
+ distances += 2;
+ d2 = d3;
+ }
+ else
+ break;
+
+ distances[-2] = 3;
+ if (*(cur - d2 + 3) != cur[3])
+ break;
+ UPDATE_maxLen
+ distances[-2] = (UInt32)maxLen;
+ if (maxLen == lenLimit)
+ {
+ p->son[p->cyclicBufferPos] = curMatch;
+ MOVE_POS_RET
+ }
+ break;
+ }
+
+ GET_MATCHES_FOOTER_HC(maxLen)
+}
+
+
+UInt32* Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
+{
+ GET_MATCHES_HEADER(3)
+ HASH_ZIP_CALC
+ curMatch = p->hash[hv];
+ p->hash[hv] = p->pos;
+ GET_MATCHES_FOOTER_HC(2)
+}
+
+
+static void Bt2_MatchFinder_Skip(void *_p, UInt32 num)
+{
+ CMatchFinder *p = (CMatchFinder *)_p;
+ SKIP_HEADER(2)
+ {
+ HASH2_CALC
+ curMatch = p->hash[hv];
+ p->hash[hv] = p->pos;
+ }
+ SKIP_FOOTER
+}
+
+void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
+{
+ SKIP_HEADER(3)
+ {
+ HASH_ZIP_CALC
+ curMatch = p->hash[hv];
+ p->hash[hv] = p->pos;
+ }
+ SKIP_FOOTER
+}
+
+static void Bt3_MatchFinder_Skip(void *_p, UInt32 num)
+{
+ CMatchFinder *p = (CMatchFinder *)_p;
+ SKIP_HEADER(3)
+ {
+ UInt32 h2;
+ UInt32 *hash;
+ HASH3_CALC
+ hash = p->hash;
+ curMatch = (hash + kFix3HashSize)[hv];
+ hash[h2] =
+ (hash + kFix3HashSize)[hv] = p->pos;
+ }
+ SKIP_FOOTER
+}
+
+static void Bt4_MatchFinder_Skip(void *_p, UInt32 num)
+{
+ CMatchFinder *p = (CMatchFinder *)_p;
+ SKIP_HEADER(4)
+ {
+ UInt32 h2, h3;
+ UInt32 *hash;
+ HASH4_CALC
+ hash = p->hash;
+ curMatch = (hash + kFix4HashSize)[hv];
+ hash [h2] =
+ (hash + kFix3HashSize)[h3] =
+ (hash + kFix4HashSize)[hv] = p->pos;
+ }
+ SKIP_FOOTER
+}
+
+static void Bt5_MatchFinder_Skip(void *_p, UInt32 num)
+{
+ CMatchFinder *p = (CMatchFinder *)_p;
+ SKIP_HEADER(5)
+ {
+ UInt32 h2, h3;
+ UInt32 *hash;
+ HASH5_CALC
+ hash = p->hash;
+ curMatch = (hash + kFix5HashSize)[hv];
+ hash [h2] =
+ (hash + kFix3HashSize)[h3] =
+ // (hash + kFix4HashSize)[h4] =
+ (hash + kFix5HashSize)[hv] = p->pos;
+ }
+ SKIP_FOOTER
+}
+
+
+#define HC_SKIP_HEADER(minLen) \
+ do { if (p->lenLimit < minLen) { MatchFinder_MovePos(p); num--; continue; } { \
+ const Byte *cur; \
+ UInt32 *hash; \
+ UInt32 *son; \
+ UInt32 pos = p->pos; \
+ UInt32 num2 = num; \
+ /* (p->pos == p->posLimit) is not allowed here !!! */ \
+ { const UInt32 rem = p->posLimit - pos; if (num2 > rem) num2 = rem; } \
+ num -= num2; \
+ { const UInt32 cycPos = p->cyclicBufferPos; \
+ son = p->son + cycPos; \
+ p->cyclicBufferPos = cycPos + num2; } \
+ cur = p->buffer; \
+ hash = p->hash; \
+ do { \
+ UInt32 curMatch; \
+ UInt32 hv;
+
+
+#define HC_SKIP_FOOTER \
+ cur++; pos++; *son++ = curMatch; \
+ } while (--num2); \
+ p->buffer = cur; \
+ p->pos = pos; \
+ if (pos == p->posLimit) MatchFinder_CheckLimits(p); \
+ }} while(num); \
+
+
+static void Hc4_MatchFinder_Skip(void *_p, UInt32 num)
+{
+ CMatchFinder *p = (CMatchFinder *)_p;
+ HC_SKIP_HEADER(4)
+
+ UInt32 h2, h3;
+ HASH4_CALC
+ curMatch = (hash + kFix4HashSize)[hv];
+ hash [h2] =
+ (hash + kFix3HashSize)[h3] =
+ (hash + kFix4HashSize)[hv] = pos;
+
+ HC_SKIP_FOOTER
+}
+
+
+static void Hc5_MatchFinder_Skip(void *_p, UInt32 num)
+{
+ CMatchFinder *p = (CMatchFinder *)_p;
+ HC_SKIP_HEADER(5)
+
+ UInt32 h2, h3;
+ HASH5_CALC
+ curMatch = (hash + kFix5HashSize)[hv];
+ hash [h2] =
+ (hash + kFix3HashSize)[h3] =
+ // (hash + kFix4HashSize)[h4] =
+ (hash + kFix5HashSize)[hv] = pos;
+
+ HC_SKIP_FOOTER
+}
+
+
+void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
+{
+ HC_SKIP_HEADER(3)
+
+ HASH_ZIP_CALC
+ curMatch = hash[hv];
+ hash[hv] = pos;
+
+ HC_SKIP_FOOTER
+}
+
+
+void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder2 *vTable)
+{
+ vTable->Init = MatchFinder_Init;
+ vTable->GetNumAvailableBytes = MatchFinder_GetNumAvailableBytes;
+ vTable->GetPointerToCurrentPos = MatchFinder_GetPointerToCurrentPos;
+ if (!p->btMode)
+ {
+ if (p->numHashBytes <= 4)
+ {
+ vTable->GetMatches = Hc4_MatchFinder_GetMatches;
+ vTable->Skip = Hc4_MatchFinder_Skip;
+ }
+ else
+ {
+ vTable->GetMatches = Hc5_MatchFinder_GetMatches;
+ vTable->Skip = Hc5_MatchFinder_Skip;
+ }
+ }
+ else if (p->numHashBytes == 2)
+ {
+ vTable->GetMatches = Bt2_MatchFinder_GetMatches;
+ vTable->Skip = Bt2_MatchFinder_Skip;
+ }
+ else if (p->numHashBytes == 3)
+ {
+ vTable->GetMatches = Bt3_MatchFinder_GetMatches;
+ vTable->Skip = Bt3_MatchFinder_Skip;
+ }
+ else if (p->numHashBytes == 4)
+ {
+ vTable->GetMatches = Bt4_MatchFinder_GetMatches;
+ vTable->Skip = Bt4_MatchFinder_Skip;
+ }
+ else
+ {
+ vTable->GetMatches = Bt5_MatchFinder_GetMatches;
+ vTable->Skip = Bt5_MatchFinder_Skip;
+ }
+}
+
+
+
+void LzFindPrepare(void)
+{
+ #ifndef FORCE_LZFIND_SATUR_SUB_128
+ #ifdef USE_LZFIND_SATUR_SUB_128
+ LZFIND_SATUR_SUB_CODE_FUNC f = NULL;
+ #ifdef MY_CPU_ARM_OR_ARM64
+ {
+ if (CPU_IsSupported_NEON())
+ {
+ // #pragma message ("=== LzFind NEON")
+ PRF(printf("\n=== LzFind NEON\n"));
+ f = LzFind_SaturSub_128;
+ }
+ // f = 0; // for debug
+ }
+ #else // MY_CPU_ARM_OR_ARM64
+ if (CPU_IsSupported_SSE41())
+ {
+ // #pragma message ("=== LzFind SSE41")
+ PRF(printf("\n=== LzFind SSE41\n"));
+ f = LzFind_SaturSub_128;
+
+ #ifdef USE_LZFIND_SATUR_SUB_256
+ if (CPU_IsSupported_AVX2())
+ {
+ // #pragma message ("=== LzFind AVX2")
+ PRF(printf("\n=== LzFind AVX2\n"));
+ f = LzFind_SaturSub_256;
+ }
+ #endif
+ }
+ #endif // MY_CPU_ARM_OR_ARM64
+ g_LzFind_SaturSub = f;
+ #endif // USE_LZFIND_SATUR_SUB_128
+ #endif // FORCE_LZFIND_SATUR_SUB_128
+}
+
+
+#undef MOVE_POS
+#undef MOVE_POS_RET
+#undef PRF
diff --git a/deps/libchdr/deps/lzma-19.00/src/Lzma86Dec.c b/deps/libchdr/deps/lzma-24.05/src/Lzma86Dec.c
similarity index 87%
rename from deps/libchdr/deps/lzma-19.00/src/Lzma86Dec.c
rename to deps/libchdr/deps/lzma-24.05/src/Lzma86Dec.c
index 21031745..f094d4c3 100644
--- a/deps/libchdr/deps/lzma-19.00/src/Lzma86Dec.c
+++ b/deps/libchdr/deps/lzma-24.05/src/Lzma86Dec.c
@@ -1,5 +1,5 @@
/* Lzma86Dec.c -- LZMA + x86 (BCJ) Filter Decoder
-2016-05-16 : Igor Pavlov : Public domain */
+2023-03-03 : Igor Pavlov : Public domain */
#include "Precomp.h"
@@ -46,9 +46,8 @@ SRes Lzma86_Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen)
return res;
if (useFilter == 1)
{
- UInt32 x86State;
- x86_Convert_Init(x86State);
- x86_Convert(dest, *destLen, 0, &x86State, 0);
+ UInt32 x86State = Z7_BRANCH_CONV_ST_X86_STATE_INIT_VAL;
+ z7_BranchConvSt_X86_Dec(dest, *destLen, 0, &x86State);
}
return SZ_OK;
}
diff --git a/deps/libchdr/deps/lzma-22.01/src/LzmaDec.c b/deps/libchdr/deps/lzma-24.05/src/LzmaDec.c
similarity index 87%
rename from deps/libchdr/deps/lzma-22.01/src/LzmaDec.c
rename to deps/libchdr/deps/lzma-24.05/src/LzmaDec.c
index 80b70a9e..69bb8bba 100644
--- a/deps/libchdr/deps/lzma-22.01/src/LzmaDec.c
+++ b/deps/libchdr/deps/lzma-24.05/src/LzmaDec.c
@@ -1,1363 +1,1363 @@
-/* LzmaDec.c -- LZMA Decoder
-2021-04-01 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#include
-
-/* #include "CpuArch.h" */
-#include "LzmaDec.h"
-
-#define kNumTopBits 24
-#define kTopValue ((UInt32)1 << kNumTopBits)
-
-#define kNumBitModelTotalBits 11
-#define kBitModelTotal (1 << kNumBitModelTotalBits)
-
-#define RC_INIT_SIZE 5
-
-#ifndef _LZMA_DEC_OPT
-
-#define kNumMoveBits 5
-#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) \
- { 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 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 TREE_DECODE(probs, limit, i) \
- { i = 1; do { TREE_GET_BIT(probs, i); } while (i < limit); i -= limit; }
-
-/* #define _LZMA_SIZE_OPT */
-
-#ifdef _LZMA_SIZE_OPT
-#define TREE_6_DECODE(probs, i) TREE_DECODE(probs, (1 << 6), i)
-#else
-#define TREE_6_DECODE(probs, i) \
- { i = 1; \
- TREE_GET_BIT(probs, i); \
- TREE_GET_BIT(probs, i); \
- TREE_GET_BIT(probs, i); \
- TREE_GET_BIT(probs, i); \
- TREE_GET_BIT(probs, i); \
- TREE_GET_BIT(probs, i); \
- i -= 0x40; }
-#endif
-
-#define NORMAL_LITER_DEC TREE_GET_BIT(prob, symbol)
-#define MATCHED_LITER_DEC \
- matchByte += matchByte; \
- bit = offs; \
- offs &= matchByte; \
- probLit = prob + (offs + bit + symbol); \
- GET_BIT2(probLit, symbol, offs ^= bit; , ;)
-
-#endif // _LZMA_DEC_OPT
-
-
-#define NORMALIZE_CHECK if (range < kTopValue) { if (buf >= bufLimit) return DUMMY_INPUT_EOF; 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) \
- { 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 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) \
- { UPDATE_0_CHECK; i += m; m += m; } else \
- { UPDATE_1_CHECK; m += m; i += m; }
-
-
-#define kNumPosBitsMax 4
-#define kNumPosStatesMax (1 << kNumPosBitsMax)
-
-#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 LenChoice LenLow
-#define LenChoice2 (LenLow + (1 << kLenNumLowBits))
-
-#define kNumStates 12
-#define kNumStates2 16
-#define kNumLitStates 7
-
-#define kStartPosModelIndex 4
-#define kEndPosModelIndex 14
-#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))
-
-#define kNumPosSlotBits 6
-#define kNumLenToPosStates 4
-
-#define kNumAlignBits 4
-#define kAlignTableSize (1 << kNumAlignBits)
-
-#define kMatchMinLen 2
-#define kMatchSpecLenStart (kMatchMinLen + kLenNumLowSymbols * 2 + kLenNumHighSymbols)
-
-#define kMatchSpecLen_Error_Data (1 << 9)
-#define kMatchSpecLen_Error_Fail (kMatchSpecLen_Error_Data - 1)
-
-/* 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 GET_PROBS p->probs + kStartOffset
-#else
-#define kStartOffset 0
-#define GET_PROBS p->probs
-#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)
-
-#if Align != 0 && kStartOffset != 0
- #error Stop_Compiling_Bad_LZMA_kAlign
-#endif
-
-#if NUM_BASE_PROBS != 1984
- #error Stop_Compiling_Bad_LZMA_PROBS
-#endif
-
-
-#define LZMA_LIT_SIZE 0x300
-
-#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 LZMA_DIC_MIN (1 << 12)
-
-/*
-p->remainLen : shows status of LZMA decoder:
- < kMatchSpecLenStart : the number of bytes to be copied with (p->rep0) offset
- = kMatchSpecLenStart : the LZMA stream was finished with end mark
- = kMatchSpecLenStart + 1 : need init range coder
- = kMatchSpecLenStart + 2 : need init range coder and state
- = kMatchSpecLen_Error_Fail : Internal Code Failure
- = kMatchSpecLen_Error_Data + [0 ... 273] : LZMA Data Error
-*/
-
-/* ---------- 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
-
-/*
-LZMA_DECODE_REAL()
-In:
- RangeCoder is normalized
- if (p->dicPos == limit)
- {
- LzmaDec_TryDummy() was called before to exclude LITERAL and MATCH-REP cases.
- So first symbol can be only MATCH-NON-REP. And if that MATCH-NON-REP symbol
- is not END_OF_PAYALOAD_MARKER, then the function doesn't write any byte to dictionary,
- the function returns SZ_OK, and the caller can use (p->remainLen) and (p->reps[0]) later.
- }
-
-Processing:
- The first LZMA symbol will be decoded in any case.
- All main checks for limits are at the end of main loop,
- It decodes additional LZMA-symbols while (p->buf < bufLimit && dicPos < limit),
- RangeCoder is still without last normalization when (p->buf < bufLimit) is being checked.
- But if (p->buf < bufLimit), the caller provided at least (LZMA_REQUIRED_INPUT_MAX + 1) bytes for
- next iteration before limit (bufLimit + LZMA_REQUIRED_INPUT_MAX),
- that is enough for worst case LZMA symbol with one additional RangeCoder normalization for one bit.
- So that function never reads bufLimit [LZMA_REQUIRED_INPUT_MAX] byte.
-
-Out:
- RangeCoder is normalized
- Result:
- SZ_OK - OK
- p->remainLen:
- < kMatchSpecLenStart : the number of bytes to be copied with (p->reps[0]) offset
- = kMatchSpecLenStart : the LZMA stream was finished with end mark
-
- SZ_ERROR_DATA - error, when the MATCH-Symbol refers out of dictionary
- p->remainLen : undefined
- p->reps[*] : undefined
-*/
-
-
-#ifdef _LZMA_DEC_OPT
-
-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)
-{
- 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);
- prob = probs + Literal;
- if (processedPos != 0 || checkDicSize != 0)
- prob += (UInt32)3 * ((((processedPos << 8) + dic[(dicPos == 0 ? dicBufSize : dicPos) - 1]) & lpMask) << lc);
- processedPos++;
-
- 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
- NORMAL_LITER_DEC
- NORMAL_LITER_DEC
- NORMAL_LITER_DEC
- NORMAL_LITER_DEC
- NORMAL_LITER_DEC
- NORMAL_LITER_DEC
- 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;
- MATCHED_LITER_DEC
- }
- while (symbol < 0x100);
- #else
- {
- unsigned bit;
- CLzmaProb *probLit;
- MATCHED_LITER_DEC
- MATCHED_LITER_DEC
- MATCHED_LITER_DEC
- MATCHED_LITER_DEC
- MATCHED_LITER_DEC
- MATCHED_LITER_DEC
- MATCHED_LITER_DEC
- MATCHED_LITER_DEC
- }
- #endif
- }
-
- dic[dicPos++] = (Byte)symbol;
- continue;
- }
-
- {
- UPDATE_1(prob);
- prob = probs + IsRep + state;
- IF_BIT_0(prob)
- {
- UPDATE_0(prob);
- state += kNumStates;
- prob = probs + LenCoder;
- }
- else
- {
- UPDATE_1(prob);
- prob = probs + IsRepG0 + state;
- IF_BIT_0(prob)
- {
- UPDATE_0(prob);
- prob = probs + IsRep0Long + COMBINED_PS_STATE;
- IF_BIT_0(prob)
- {
- UPDATE_0(prob);
-
- // that case was checked before with kBadRepCode
- // if (checkDicSize == 0 && processedPos == 0) { len = kMatchSpecLen_Error_Data + 1; break; }
- // The caller doesn't allow (dicPos == limit) case here
- // so we don't need the following check:
- // if (dicPos == limit) { state = state < kNumLitStates ? 9 : 11; len = 1; break; }
-
- 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);
- prob = probs + IsRepG1 + state;
- IF_BIT_0(prob)
- {
- UPDATE_0(prob);
- distance = rep1;
- }
- else
- {
- UPDATE_1(prob);
- prob = probs + IsRepG2 + state;
- IF_BIT_0(prob)
- {
- UPDATE_0(prob);
- distance = rep2;
- }
- else
- {
- UPDATE_1(prob);
- distance = rep3;
- rep3 = rep2;
- }
- rep2 = rep1;
- }
- rep1 = rep0;
- rep0 = distance;
- }
- state = state < kNumLitStates ? 8 : 11;
- prob = probs + RepLenCoder;
- }
-
- #ifdef _LZMA_SIZE_OPT
- {
- 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);
- probLen = prob + LenChoice2;
- IF_BIT_0(probLen)
- {
- UPDATE_0(probLen);
- probLen = prob + LenLow + GET_LEN_STATE + (1 << kLenNumLowBits);
- offset = kLenNumLowSymbols;
- lim = (1 << kLenNumLowBits);
- }
- else
- {
- UPDATE_1(probLen);
- probLen = prob + LenHigh;
- offset = kLenNumLowSymbols * 2;
- lim = (1 << kLenNumHighBits);
- }
- }
- TREE_DECODE(probLen, lim, len);
- len += offset;
- }
- #else
- {
- 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 -= 8;
- }
- else
- {
- UPDATE_1(probLen);
- probLen = prob + LenChoice2;
- 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);
- probLen = prob + LenHigh;
- TREE_DECODE(probLen, (1 << kLenNumHighBits), len);
- len += kLenNumLowSymbols * 2;
- }
- }
- }
- #endif
-
- 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));
- distance = (2 | (distance & 1));
- if (posSlot < kEndPosModelIndex)
- {
- distance <<= numDirectBits;
- prob = probs + SpecPos;
- {
- UInt32 m = 1;
- distance++;
- do
- {
- REV_BIT_VAR(prob, distance, m);
- }
- while (--numDirectBits);
- distance -= m;
- }
- }
- else
- {
- numDirectBits -= kNumAlignBits;
- do
- {
- NORMALIZE
- range >>= 1;
-
- {
- UInt32 t;
- code -= range;
- t = (0 - ((UInt32)code >> 31)); /* (UInt32)((Int32)code >> 31) */
- distance = (distance << 1) + (t + 1);
- code += range & t;
- }
- /*
- distance <<= 1;
- if (code >= range)
- {
- code -= range;
- distance |= 1;
- }
- */
- }
- 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);
- REV_BIT_LAST (prob, i, 8);
- distance |= i;
- }
- if (distance == (UInt32)0xFFFFFFFF)
- {
- len = kMatchSpecLenStart;
- state -= kNumStates;
- break;
- }
- }
- }
-
- rep3 = rep2;
- rep2 = rep1;
- rep1 = rep0;
- rep0 = distance + 1;
- state = (state < kNumStates + kNumLitStates) ? kNumLitStates : kNumLitStates + 3;
- if (distance >= (checkDicSize == 0 ? processedPos: checkDicSize))
- {
- len += kMatchSpecLen_Error_Data + kMatchMinLen;
- // len = kMatchSpecLen_Error_Data;
- // len += kMatchMinLen;
- break;
- }
- }
-
- len += kMatchMinLen;
-
- {
- SizeT rem;
- unsigned curLen;
- SizeT pos;
-
- if ((rem = limit - dicPos) == 0)
- {
- /*
- We stop decoding and return SZ_OK, and we can resume decoding later.
- Any error conditions can be tested later in caller code.
- For more strict mode we can stop decoding with error
- // len += kMatchSpecLen_Error_Data;
- */
- break;
- }
-
- curLen = ((rem < len) ? (unsigned)rem : len);
- 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;
- dicPos += (SizeT)curLen;
- do
- *(dest) = (Byte)*(dest + src);
- while (++dest != lim);
- }
- else
- {
- do
- {
- dic[dicPos++] = dic[pos];
- if (++pos == dicBufSize)
- pos = 0;
- }
- while (--curLen != 0);
- }
- }
- }
- }
- while (dicPos < limit && buf < bufLimit);
-
- NORMALIZE;
-
- p->buf = buf;
- p->range = range;
- p->code = code;
- p->remainLen = (UInt32)len; // & (kMatchSpecLen_Error_Data - 1); // we can write real length for error matches too.
- 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;
- if (len >= kMatchSpecLen_Error_Data)
- return SZ_ERROR_DATA;
- return SZ_OK;
-}
-#endif
-
-
-
-static void MY_FAST_CALL LzmaDec_WriteRem(CLzmaDec *p, SizeT limit)
-{
- unsigned len = (unsigned)p->remainLen;
- if (len == 0 /* || len >= kMatchSpecLenStart */)
- return;
- {
- SizeT dicPos = p->dicPos;
- Byte *dic;
- SizeT dicBufSize;
- SizeT rep0; /* we use SizeT to avoid the BUG of VC14 for AMD64 */
- {
- SizeT rem = limit - dicPos;
- if (rem < len)
- {
- len = (unsigned)(rem);
- if (len == 0)
- return;
- }
- }
-
- if (p->checkDicSize == 0 && p->prop.dicSize - p->processedPos <= len)
- p->checkDicSize = p->prop.dicSize;
-
- p->processedPos += (UInt32)len;
- p->remainLen -= (UInt32)len;
- dic = p->dic;
- rep0 = p->reps[0];
- dicBufSize = p->dicBufSize;
- do
- {
- dic[dicPos] = dic[dicPos - rep0 + (dicPos < rep0 ? dicBufSize : 0)];
- dicPos++;
- }
- while (--len);
- p->dicPos = dicPos;
- }
-}
-
-
-/*
-At staring of new stream we have one of the following symbols:
- - Literal - is allowed
- - Non-Rep-Match - is allowed only if it's end marker symbol
- - Rep-Match - is not allowed
-We use early check of (RangeCoder:Code) over kBadRepCode to simplify main decoding code
-*/
-
-#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
-
-
-/*
-LzmaDec_DecodeReal2():
- It calls LZMA_DECODE_REAL() and it adjusts limit according (p->checkDicSize).
-
-We correct (p->checkDicSize) after LZMA_DECODE_REAL() and in LzmaDec_WriteRem(),
-and we support the following state of (p->checkDicSize):
- if (total_processed < p->prop.dicSize) then
- {
- (total_processed == p->processedPos)
- (p->checkDicSize == 0)
- }
- else
- (p->checkDicSize == p->prop.dicSize)
-*/
-
-static int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte *bufLimit)
-{
- if (p->checkDicSize == 0)
- {
- UInt32 rem = p->prop.dicSize - p->processedPos;
- if (limit - p->dicPos > rem)
- limit = p->dicPos + rem;
- }
- {
- int res = LZMA_DECODE_REAL(p, limit, bufLimit);
- if (p->checkDicSize == 0 && p->processedPos >= p->prop.dicSize)
- p->checkDicSize = p->prop.dicSize;
- return res;
- }
-}
-
-
-
-typedef enum
-{
- DUMMY_INPUT_EOF, /* need more input data */
- DUMMY_LIT,
- DUMMY_MATCH,
- DUMMY_REP
-} ELzmaDummy;
-
-
-#define IS_DUMMY_END_MARKER_POSSIBLE(dummyRes) ((dummyRes) == DUMMY_MATCH)
-
-static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, const Byte **bufOut)
-{
- UInt32 range = p->range;
- UInt32 code = p->code;
- const Byte *bufLimit = *bufOut;
- const CLzmaProb *probs = GET_PROBS;
- unsigned state = (unsigned)p->state;
- ELzmaDummy res;
-
- for (;;)
- {
- const CLzmaProb *prob;
- UInt32 bound;
- unsigned ttt;
- unsigned posState = CALC_POS_STATE(p->processedPos, ((unsigned)1 << p->prop.pb) - 1);
-
- prob = probs + IsMatch + COMBINED_PS_STATE;
- IF_BIT_0_CHECK(prob)
- {
- UPDATE_0_CHECK
-
- prob = probs + Literal;
- if (p->checkDicSize != 0 || p->processedPos != 0)
- prob += ((UInt32)LZMA_LIT_SIZE *
- ((((p->processedPos) & (((unsigned)1 << (p->prop.lp)) - 1)) << p->prop.lc) +
- ((unsigned)p->dic[(p->dicPos == 0 ? p->dicBufSize : p->dicPos) - 1] >> (8 - p->prop.lc))));
-
- 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);
- }
- res = DUMMY_LIT;
- }
- else
- {
- unsigned len;
- UPDATE_1_CHECK;
-
- prob = probs + IsRep + state;
- IF_BIT_0_CHECK(prob)
- {
- UPDATE_0_CHECK;
- state = 0;
- prob = probs + LenCoder;
- res = DUMMY_MATCH;
- }
- else
- {
- UPDATE_1_CHECK;
- res = DUMMY_REP;
- prob = probs + IsRepG0 + state;
- IF_BIT_0_CHECK(prob)
- {
- UPDATE_0_CHECK;
- prob = probs + IsRep0Long + COMBINED_PS_STATE;
- IF_BIT_0_CHECK(prob)
- {
- UPDATE_0_CHECK;
- break;
- }
- else
- {
- UPDATE_1_CHECK;
- }
- }
- else
- {
- UPDATE_1_CHECK;
- prob = probs + IsRepG1 + state;
- IF_BIT_0_CHECK(prob)
- {
- UPDATE_0_CHECK;
- }
- else
- {
- UPDATE_1_CHECK;
- prob = probs + IsRepG2 + state;
- IF_BIT_0_CHECK(prob)
- {
- UPDATE_0_CHECK;
- }
- else
- {
- UPDATE_1_CHECK;
- }
- }
- }
- state = kNumStates;
- prob = probs + RepLenCoder;
- }
- {
- 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
- {
- UPDATE_1_CHECK;
- probLen = prob + LenChoice2;
- IF_BIT_0_CHECK(probLen)
- {
- UPDATE_0_CHECK;
- probLen = prob + LenLow + GET_LEN_STATE + (1 << kLenNumLowBits);
- offset = kLenNumLowSymbols;
- limit = 1 << kLenNumLowBits;
- }
- else
- {
- UPDATE_1_CHECK;
- probLen = prob + LenHigh;
- offset = kLenNumLowSymbols * 2;
- limit = 1 << kLenNumHighBits;
- }
- }
- TREE_DECODE_CHECK(probLen, limit, len);
- len += offset;
- }
-
- 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);
-
- if (posSlot < kEndPosModelIndex)
- {
- prob = probs + SpecPos + ((2 | (posSlot & 1)) << numDirectBits);
- }
- else
- {
- numDirectBits -= kNumAlignBits;
- do
- {
- NORMALIZE_CHECK
- range >>= 1;
- code -= range & (((code - range) >> 31) - 1);
- /* if (code >= range) code -= range; */
- }
- while (--numDirectBits);
- prob = probs + Align;
- numDirectBits = kNumAlignBits;
- }
- {
- unsigned i = 1;
- unsigned m = 1;
- do
- {
- REV_BIT_CHECK(prob, i, m);
- }
- while (--numDirectBits);
- }
- }
- }
- }
- break;
- }
- NORMALIZE_CHECK;
-
- *bufOut = buf;
- 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->tempBufSize = 0;
-
- if (initDic)
- {
- p->processedPos = 0;
- p->checkDicSize = 0;
- p->remainLen = kMatchSpecLenStart + 2;
- }
- if (initState)
- p->remainLen = kMatchSpecLenStart + 2;
-}
-
-void LzmaDec_Init(CLzmaDec *p)
-{
- p->dicPos = 0;
- LzmaDec_InitDicAndState(p, True, True);
-}
-
-
-/*
-LZMA supports optional end_marker.
-So the decoder can lookahead for one additional LZMA-Symbol to check end_marker.
-That additional LZMA-Symbol can require up to LZMA_REQUIRED_INPUT_MAX bytes in input stream.
-When the decoder reaches dicLimit, it looks (finishMode) parameter:
- if (finishMode == LZMA_FINISH_ANY), the decoder doesn't lookahead
- if (finishMode != LZMA_FINISH_ANY), the decoder lookahead, if end_marker is possible for current position
-
-When the decoder lookahead, and the lookahead symbol is not end_marker, we have two ways:
- 1) Strict mode (default) : the decoder returns SZ_ERROR_DATA.
- 2) The relaxed mode (alternative mode) : we could return SZ_OK, and the caller
- must check (status) value. The caller can show the error,
- if the end of stream is expected, and the (status) is noit
- LZMA_STATUS_FINISHED_WITH_MARK or LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK.
-*/
-
-
-#define RETURN__NOT_FINISHED__FOR_FINISH \
- *status = LZMA_STATUS_NOT_FINISHED; \
- return SZ_ERROR_DATA; // for strict mode
- // return SZ_OK; // for relaxed mode
-
-
-SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen,
- ELzmaFinishMode finishMode, ELzmaStatus *status)
-{
- SizeT inSize = *srcLen;
- (*srcLen) = 0;
- *status = LZMA_STATUS_NOT_SPECIFIED;
-
- if (p->remainLen > kMatchSpecLenStart)
- {
- if (p->remainLen > kMatchSpecLenStart + 2)
- return p->remainLen == kMatchSpecLen_Error_Fail ? SZ_ERROR_FAIL : SZ_ERROR_DATA;
-
- for (; inSize > 0 && p->tempBufSize < RC_INIT_SIZE; (*srcLen)++, inSize--)
- p->tempBuf[p->tempBufSize++] = *src++;
- if (p->tempBufSize != 0 && p->tempBuf[0] != 0)
- return SZ_ERROR_DATA;
- 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[2] << 16)
- | ((UInt32)p->tempBuf[3] << 8)
- | ((UInt32)p->tempBuf[4]);
-
- if (p->checkDicSize == 0
- && p->processedPos == 0
- && p->code >= kBadRepCode)
- return SZ_ERROR_DATA;
-
- 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++)
- probs[i] = kBitModelTotal >> 1;
- p->reps[0] = p->reps[1] = p->reps[2] = p->reps[3] = 1;
- p->state = 0;
- }
-
- p->remainLen = 0;
- }
-
- for (;;)
- {
- if (p->remainLen == kMatchSpecLenStart)
- {
- if (p->code != 0)
- return SZ_ERROR_DATA;
- *status = LZMA_STATUS_FINISHED_WITH_MARK;
- return SZ_OK;
- }
-
- LzmaDec_WriteRem(p, dicLimit);
-
- {
- // (p->remainLen == 0 || p->dicPos == dicLimit)
-
- int checkEndMarkNow = 0;
-
- 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)
- {
- RETURN__NOT_FINISHED__FOR_FINISH;
- }
- checkEndMarkNow = 1;
- }
-
- // (p->remainLen == 0)
-
- if (p->tempBufSize == 0)
- {
- const Byte *bufLimit;
- int dummyProcessed = -1;
-
- if (inSize < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)
- {
- const Byte *bufOut = src + inSize;
-
- ELzmaDummy dummyRes = LzmaDec_TryDummy(p, src, &bufOut);
-
- if (dummyRes == DUMMY_INPUT_EOF)
- {
- size_t i;
- if (inSize >= LZMA_REQUIRED_INPUT_MAX)
- break;
- (*srcLen) += inSize;
- p->tempBufSize = (unsigned)inSize;
- for (i = 0; i < inSize; i++)
- p->tempBuf[i] = src[i];
- *status = LZMA_STATUS_NEEDS_MORE_INPUT;
- return SZ_OK;
- }
-
- dummyProcessed = (int)(bufOut - src);
- if ((unsigned)dummyProcessed > LZMA_REQUIRED_INPUT_MAX)
- break;
-
- if (checkEndMarkNow && !IS_DUMMY_END_MARKER_POSSIBLE(dummyRes))
- {
- unsigned i;
- (*srcLen) += (unsigned)dummyProcessed;
- p->tempBufSize = (unsigned)dummyProcessed;
- for (i = 0; i < (unsigned)dummyProcessed; i++)
- p->tempBuf[i] = src[i];
- // p->remainLen = kMatchSpecLen_Error_Data;
- RETURN__NOT_FINISHED__FOR_FINISH;
- }
-
- bufLimit = src;
- // we will decode only one iteration
- }
- else
- bufLimit = src + inSize - LZMA_REQUIRED_INPUT_MAX;
-
- p->buf = src;
-
- {
- int res = LzmaDec_DecodeReal2(p, dicLimit, bufLimit);
-
- SizeT processed = (SizeT)(p->buf - src);
-
- if (dummyProcessed < 0)
- {
- if (processed > inSize)
- break;
- }
- else if ((unsigned)dummyProcessed != processed)
- break;
-
- src += processed;
- inSize -= processed;
- (*srcLen) += processed;
-
- if (res != SZ_OK)
- {
- p->remainLen = kMatchSpecLen_Error_Data;
- return SZ_ERROR_DATA;
- }
- }
- continue;
- }
-
- {
- // we have some data in (p->tempBuf)
- // in strict mode: tempBufSize is not enough for one Symbol decoding.
- // in relaxed mode: tempBufSize not larger than required for one Symbol decoding.
-
- unsigned rem = p->tempBufSize;
- unsigned ahead = 0;
- int dummyProcessed = -1;
-
- while (rem < LZMA_REQUIRED_INPUT_MAX && ahead < inSize)
- p->tempBuf[rem++] = src[ahead++];
-
- // ahead - the size of new data copied from (src) to (p->tempBuf)
- // rem - the size of temp buffer including new data from (src)
-
- if (rem < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)
- {
- const Byte *bufOut = p->tempBuf + rem;
-
- ELzmaDummy dummyRes = LzmaDec_TryDummy(p, p->tempBuf, &bufOut);
-
- if (dummyRes == DUMMY_INPUT_EOF)
- {
- if (rem >= LZMA_REQUIRED_INPUT_MAX)
- break;
- p->tempBufSize = rem;
- (*srcLen) += (SizeT)ahead;
- *status = LZMA_STATUS_NEEDS_MORE_INPUT;
- return SZ_OK;
- }
-
- dummyProcessed = (int)(bufOut - p->tempBuf);
-
- if ((unsigned)dummyProcessed < p->tempBufSize)
- break;
-
- if (checkEndMarkNow && !IS_DUMMY_END_MARKER_POSSIBLE(dummyRes))
- {
- (*srcLen) += (unsigned)dummyProcessed - p->tempBufSize;
- p->tempBufSize = (unsigned)dummyProcessed;
- // p->remainLen = kMatchSpecLen_Error_Data;
- RETURN__NOT_FINISHED__FOR_FINISH;
- }
- }
-
- p->buf = p->tempBuf;
-
- {
- // we decode one symbol from (p->tempBuf) here, so the (bufLimit) is equal to (p->buf)
- int res = LzmaDec_DecodeReal2(p, dicLimit, p->buf);
-
- SizeT processed = (SizeT)(p->buf - p->tempBuf);
- rem = p->tempBufSize;
-
- if (dummyProcessed < 0)
- {
- if (processed > LZMA_REQUIRED_INPUT_MAX)
- break;
- if (processed < rem)
- break;
- }
- else if ((unsigned)dummyProcessed != processed)
- break;
-
- processed -= rem;
-
- src += processed;
- inSize -= processed;
- (*srcLen) += processed;
- p->tempBufSize = 0;
-
- if (res != SZ_OK)
- {
- p->remainLen = kMatchSpecLen_Error_Data;
- return SZ_ERROR_DATA;
- }
- }
- }
- }
- }
-
- /* Some unexpected error: internal error of code, memory corruption or hardware failure */
- p->remainLen = kMatchSpecLen_Error_Fail;
- return SZ_ERROR_FAIL;
-}
-
-
-
-SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
-{
- SizeT outSize = *destLen;
- SizeT inSize = *srcLen;
- *srcLen = *destLen = 0;
- 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;
- curFinishMode = LZMA_FINISH_ANY;
- }
- else
- {
- outSizeCur = dicPos + outSize;
- curFinishMode = finishMode;
- }
-
- 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;
- *destLen += outSizeCur;
- if (res != 0)
- return res;
- if (outSizeCur == 0 || outSize == 0)
- return SZ_OK;
- }
-}
-
-void LzmaDec_FreeProbs(CLzmaDec *p, ISzAllocPtr alloc)
-{
- ISzAlloc_Free(alloc, p->probs);
- p->probs = NULL;
-}
-
-static void LzmaDec_FreeDict(CLzmaDec *p, ISzAllocPtr alloc)
-{
- ISzAlloc_Free(alloc, p->dic);
- p->dic = NULL;
-}
-
-void LzmaDec_Free(CLzmaDec *p, ISzAllocPtr alloc)
-{
- LzmaDec_FreeProbs(p, alloc);
- LzmaDec_FreeDict(p, alloc);
-}
-
-SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)
-{
- UInt32 dicSize;
- Byte d;
-
- if (size < LZMA_PROPS_SIZE)
- return SZ_ERROR_UNSUPPORTED;
- else
- dicSize = data[1] | ((UInt32)data[2] << 8) | ((UInt32)data[3] << 16) | ((UInt32)data[4] << 24);
-
- if (dicSize < LZMA_DIC_MIN)
- dicSize = LZMA_DIC_MIN;
- p->dicSize = dicSize;
-
- d = data[0];
- if (d >= (9 * 5 * 5))
- return SZ_ERROR_UNSUPPORTED;
-
- p->lc = (Byte)(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)
-{
- 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;
- }
- return SZ_OK;
-}
-
-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));
- p->prop = propNew;
- return SZ_OK;
-}
-
-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));
-
- {
- 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)
- 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);
- return SZ_ERROR_MEM;
- }
- }
- p->dicBufSize = dicBufSize;
- 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)
-{
- CLzmaDec p;
- SRes res;
- SizeT outSize = *destLen, inSize = *srcLen;
- *destLen = *srcLen = 0;
- *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;
- p.dicBufSize = outSize;
- 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)
- res = SZ_ERROR_INPUT_EOF;
- LzmaDec_FreeProbs(&p, alloc);
- return res;
-}
+/* LzmaDec.c -- LZMA Decoder
+2023-04-07 : Igor Pavlov : Public domain */
+
+#include "Precomp.h"
+
+#include
+
+/* #include "CpuArch.h" */
+#include "LzmaDec.h"
+
+// #define kNumTopBits 24
+#define kTopValue ((UInt32)1 << 24)
+
+#define kNumBitModelTotalBits 11
+#define kBitModelTotal (1 << kNumBitModelTotalBits)
+
+#define RC_INIT_SIZE 5
+
+#ifndef Z7_LZMA_DEC_OPT
+
+#define kNumMoveBits 5
+#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) \
+ { 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 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 TREE_DECODE(probs, limit, i) \
+ { i = 1; do { TREE_GET_BIT(probs, i); } while (i < limit); i -= limit; }
+
+/* #define Z7_LZMA_SIZE_OPT */
+
+#ifdef Z7_LZMA_SIZE_OPT
+#define TREE_6_DECODE(probs, i) TREE_DECODE(probs, (1 << 6), i)
+#else
+#define TREE_6_DECODE(probs, i) \
+ { i = 1; \
+ TREE_GET_BIT(probs, i) \
+ TREE_GET_BIT(probs, i) \
+ TREE_GET_BIT(probs, i) \
+ TREE_GET_BIT(probs, i) \
+ TREE_GET_BIT(probs, i) \
+ TREE_GET_BIT(probs, i) \
+ i -= 0x40; }
+#endif
+
+#define NORMAL_LITER_DEC TREE_GET_BIT(prob, symbol)
+#define MATCHED_LITER_DEC \
+ matchByte += matchByte; \
+ bit = offs; \
+ offs &= matchByte; \
+ probLit = prob + (offs + bit + symbol); \
+ GET_BIT2(probLit, symbol, offs ^= bit; , ;)
+
+#endif // Z7_LZMA_DEC_OPT
+
+
+#define NORMALIZE_CHECK if (range < kTopValue) { if (buf >= bufLimit) return DUMMY_INPUT_EOF; 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) \
+ { 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 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) \
+ { UPDATE_0_CHECK i += m; m += m; } else \
+ { UPDATE_1_CHECK m += m; i += m; }
+
+
+#define kNumPosBitsMax 4
+#define kNumPosStatesMax (1 << kNumPosBitsMax)
+
+#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 LenChoice LenLow
+#define LenChoice2 (LenLow + (1 << kLenNumLowBits))
+
+#define kNumStates 12
+#define kNumStates2 16
+#define kNumLitStates 7
+
+#define kStartPosModelIndex 4
+#define kEndPosModelIndex 14
+#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))
+
+#define kNumPosSlotBits 6
+#define kNumLenToPosStates 4
+
+#define kNumAlignBits 4
+#define kAlignTableSize (1 << kNumAlignBits)
+
+#define kMatchMinLen 2
+#define kMatchSpecLenStart (kMatchMinLen + kLenNumLowSymbols * 2 + kLenNumHighSymbols)
+
+#define kMatchSpecLen_Error_Data (1 << 9)
+#define kMatchSpecLen_Error_Fail (kMatchSpecLen_Error_Data - 1)
+
+/* 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 GET_PROBS p->probs + kStartOffset
+#else
+#define kStartOffset 0
+#define GET_PROBS p->probs
+#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)
+
+#if Align != 0 && kStartOffset != 0
+ #error Stop_Compiling_Bad_LZMA_kAlign
+#endif
+
+#if NUM_BASE_PROBS != 1984
+ #error Stop_Compiling_Bad_LZMA_PROBS
+#endif
+
+
+#define LZMA_LIT_SIZE 0x300
+
+#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 LZMA_DIC_MIN (1 << 12)
+
+/*
+p->remainLen : shows status of LZMA decoder:
+ < kMatchSpecLenStart : the number of bytes to be copied with (p->rep0) offset
+ = kMatchSpecLenStart : the LZMA stream was finished with end mark
+ = kMatchSpecLenStart + 1 : need init range coder
+ = kMatchSpecLenStart + 2 : need init range coder and state
+ = kMatchSpecLen_Error_Fail : Internal Code Failure
+ = kMatchSpecLen_Error_Data + [0 ... 273] : LZMA Data Error
+*/
+
+/* ---------- 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
+
+/*
+LZMA_DECODE_REAL()
+In:
+ RangeCoder is normalized
+ if (p->dicPos == limit)
+ {
+ LzmaDec_TryDummy() was called before to exclude LITERAL and MATCH-REP cases.
+ So first symbol can be only MATCH-NON-REP. And if that MATCH-NON-REP symbol
+ is not END_OF_PAYALOAD_MARKER, then the function doesn't write any byte to dictionary,
+ the function returns SZ_OK, and the caller can use (p->remainLen) and (p->reps[0]) later.
+ }
+
+Processing:
+ The first LZMA symbol will be decoded in any case.
+ All main checks for limits are at the end of main loop,
+ It decodes additional LZMA-symbols while (p->buf < bufLimit && dicPos < limit),
+ RangeCoder is still without last normalization when (p->buf < bufLimit) is being checked.
+ But if (p->buf < bufLimit), the caller provided at least (LZMA_REQUIRED_INPUT_MAX + 1) bytes for
+ next iteration before limit (bufLimit + LZMA_REQUIRED_INPUT_MAX),
+ that is enough for worst case LZMA symbol with one additional RangeCoder normalization for one bit.
+ So that function never reads bufLimit [LZMA_REQUIRED_INPUT_MAX] byte.
+
+Out:
+ RangeCoder is normalized
+ Result:
+ SZ_OK - OK
+ p->remainLen:
+ < kMatchSpecLenStart : the number of bytes to be copied with (p->reps[0]) offset
+ = kMatchSpecLenStart : the LZMA stream was finished with end mark
+
+ SZ_ERROR_DATA - error, when the MATCH-Symbol refers out of dictionary
+ p->remainLen : undefined
+ p->reps[*] : undefined
+*/
+
+
+#ifdef Z7_LZMA_DEC_OPT
+
+int Z7_FASTCALL LZMA_DECODE_REAL(CLzmaDec *p, SizeT limit, const Byte *bufLimit);
+
+#else
+
+static
+int Z7_FASTCALL 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);
+
+ prob = probs + IsMatch + COMBINED_PS_STATE;
+ IF_BIT_0(prob)
+ {
+ unsigned symbol;
+ UPDATE_0(prob)
+ prob = probs + Literal;
+ if (processedPos != 0 || checkDicSize != 0)
+ prob += (UInt32)3 * ((((processedPos << 8) + dic[(dicPos == 0 ? dicBufSize : dicPos) - 1]) & lpMask) << lc);
+ processedPos++;
+
+ if (state < kNumLitStates)
+ {
+ state -= (state < 4) ? state : 3;
+ symbol = 1;
+ #ifdef Z7_LZMA_SIZE_OPT
+ do { NORMAL_LITER_DEC } while (symbol < 0x100);
+ #else
+ NORMAL_LITER_DEC
+ NORMAL_LITER_DEC
+ NORMAL_LITER_DEC
+ NORMAL_LITER_DEC
+ NORMAL_LITER_DEC
+ NORMAL_LITER_DEC
+ NORMAL_LITER_DEC
+ 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 Z7_LZMA_SIZE_OPT
+ do
+ {
+ unsigned bit;
+ CLzmaProb *probLit;
+ MATCHED_LITER_DEC
+ }
+ while (symbol < 0x100);
+ #else
+ {
+ unsigned bit;
+ CLzmaProb *probLit;
+ MATCHED_LITER_DEC
+ MATCHED_LITER_DEC
+ MATCHED_LITER_DEC
+ MATCHED_LITER_DEC
+ MATCHED_LITER_DEC
+ MATCHED_LITER_DEC
+ MATCHED_LITER_DEC
+ MATCHED_LITER_DEC
+ }
+ #endif
+ }
+
+ dic[dicPos++] = (Byte)symbol;
+ continue;
+ }
+
+ {
+ UPDATE_1(prob)
+ prob = probs + IsRep + state;
+ IF_BIT_0(prob)
+ {
+ UPDATE_0(prob)
+ state += kNumStates;
+ prob = probs + LenCoder;
+ }
+ else
+ {
+ UPDATE_1(prob)
+ prob = probs + IsRepG0 + state;
+ IF_BIT_0(prob)
+ {
+ UPDATE_0(prob)
+ prob = probs + IsRep0Long + COMBINED_PS_STATE;
+ IF_BIT_0(prob)
+ {
+ UPDATE_0(prob)
+
+ // that case was checked before with kBadRepCode
+ // if (checkDicSize == 0 && processedPos == 0) { len = kMatchSpecLen_Error_Data + 1; break; }
+ // The caller doesn't allow (dicPos == limit) case here
+ // so we don't need the following check:
+ // if (dicPos == limit) { state = state < kNumLitStates ? 9 : 11; len = 1; break; }
+
+ 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)
+ prob = probs + IsRepG1 + state;
+ IF_BIT_0(prob)
+ {
+ UPDATE_0(prob)
+ distance = rep1;
+ }
+ else
+ {
+ UPDATE_1(prob)
+ prob = probs + IsRepG2 + state;
+ IF_BIT_0(prob)
+ {
+ UPDATE_0(prob)
+ distance = rep2;
+ }
+ else
+ {
+ UPDATE_1(prob)
+ distance = rep3;
+ rep3 = rep2;
+ }
+ rep2 = rep1;
+ }
+ rep1 = rep0;
+ rep0 = distance;
+ }
+ state = state < kNumLitStates ? 8 : 11;
+ prob = probs + RepLenCoder;
+ }
+
+ #ifdef Z7_LZMA_SIZE_OPT
+ {
+ 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)
+ probLen = prob + LenChoice2;
+ IF_BIT_0(probLen)
+ {
+ UPDATE_0(probLen)
+ probLen = prob + LenLow + GET_LEN_STATE + (1 << kLenNumLowBits);
+ offset = kLenNumLowSymbols;
+ lim = (1 << kLenNumLowBits);
+ }
+ else
+ {
+ UPDATE_1(probLen)
+ probLen = prob + LenHigh;
+ offset = kLenNumLowSymbols * 2;
+ lim = (1 << kLenNumHighBits);
+ }
+ }
+ TREE_DECODE(probLen, lim, len)
+ len += offset;
+ }
+ #else
+ {
+ 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 -= 8;
+ }
+ else
+ {
+ UPDATE_1(probLen)
+ probLen = prob + LenChoice2;
+ 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)
+ probLen = prob + LenHigh;
+ TREE_DECODE(probLen, (1 << kLenNumHighBits), len)
+ len += kLenNumLowSymbols * 2;
+ }
+ }
+ }
+ #endif
+
+ 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));
+ distance = (2 | (distance & 1));
+ if (posSlot < kEndPosModelIndex)
+ {
+ distance <<= numDirectBits;
+ prob = probs + SpecPos;
+ {
+ UInt32 m = 1;
+ distance++;
+ do
+ {
+ REV_BIT_VAR(prob, distance, m)
+ }
+ while (--numDirectBits);
+ distance -= m;
+ }
+ }
+ else
+ {
+ numDirectBits -= kNumAlignBits;
+ do
+ {
+ NORMALIZE
+ range >>= 1;
+
+ {
+ UInt32 t;
+ code -= range;
+ t = (0 - ((UInt32)code >> 31)); /* (UInt32)((Int32)code >> 31) */
+ distance = (distance << 1) + (t + 1);
+ code += range & t;
+ }
+ /*
+ distance <<= 1;
+ if (code >= range)
+ {
+ code -= range;
+ distance |= 1;
+ }
+ */
+ }
+ 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)
+ REV_BIT_LAST (prob, i, 8)
+ distance |= i;
+ }
+ if (distance == (UInt32)0xFFFFFFFF)
+ {
+ len = kMatchSpecLenStart;
+ state -= kNumStates;
+ break;
+ }
+ }
+ }
+
+ rep3 = rep2;
+ rep2 = rep1;
+ rep1 = rep0;
+ rep0 = distance + 1;
+ state = (state < kNumStates + kNumLitStates) ? kNumLitStates : kNumLitStates + 3;
+ if (distance >= (checkDicSize == 0 ? processedPos: checkDicSize))
+ {
+ len += kMatchSpecLen_Error_Data + kMatchMinLen;
+ // len = kMatchSpecLen_Error_Data;
+ // len += kMatchMinLen;
+ break;
+ }
+ }
+
+ len += kMatchMinLen;
+
+ {
+ SizeT rem;
+ unsigned curLen;
+ SizeT pos;
+
+ if ((rem = limit - dicPos) == 0)
+ {
+ /*
+ We stop decoding and return SZ_OK, and we can resume decoding later.
+ Any error conditions can be tested later in caller code.
+ For more strict mode we can stop decoding with error
+ // len += kMatchSpecLen_Error_Data;
+ */
+ break;
+ }
+
+ curLen = ((rem < len) ? (unsigned)rem : len);
+ 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;
+ dicPos += (SizeT)curLen;
+ do
+ *(dest) = (Byte)*(dest + src);
+ while (++dest != lim);
+ }
+ else
+ {
+ do
+ {
+ dic[dicPos++] = dic[pos];
+ if (++pos == dicBufSize)
+ pos = 0;
+ }
+ while (--curLen != 0);
+ }
+ }
+ }
+ }
+ while (dicPos < limit && buf < bufLimit);
+
+ NORMALIZE
+
+ p->buf = buf;
+ p->range = range;
+ p->code = code;
+ p->remainLen = (UInt32)len; // & (kMatchSpecLen_Error_Data - 1); // we can write real length for error matches too.
+ 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;
+ if (len >= kMatchSpecLen_Error_Data)
+ return SZ_ERROR_DATA;
+ return SZ_OK;
+}
+#endif
+
+
+
+static void Z7_FASTCALL LzmaDec_WriteRem(CLzmaDec *p, SizeT limit)
+{
+ unsigned len = (unsigned)p->remainLen;
+ if (len == 0 /* || len >= kMatchSpecLenStart */)
+ return;
+ {
+ SizeT dicPos = p->dicPos;
+ Byte *dic;
+ SizeT dicBufSize;
+ SizeT rep0; /* we use SizeT to avoid the BUG of VC14 for AMD64 */
+ {
+ SizeT rem = limit - dicPos;
+ if (rem < len)
+ {
+ len = (unsigned)(rem);
+ if (len == 0)
+ return;
+ }
+ }
+
+ if (p->checkDicSize == 0 && p->prop.dicSize - p->processedPos <= len)
+ p->checkDicSize = p->prop.dicSize;
+
+ p->processedPos += (UInt32)len;
+ p->remainLen -= (UInt32)len;
+ dic = p->dic;
+ rep0 = p->reps[0];
+ dicBufSize = p->dicBufSize;
+ do
+ {
+ dic[dicPos] = dic[dicPos - rep0 + (dicPos < rep0 ? dicBufSize : 0)];
+ dicPos++;
+ }
+ while (--len);
+ p->dicPos = dicPos;
+ }
+}
+
+
+/*
+At staring of new stream we have one of the following symbols:
+ - Literal - is allowed
+ - Non-Rep-Match - is allowed only if it's end marker symbol
+ - Rep-Match - is not allowed
+We use early check of (RangeCoder:Code) over kBadRepCode to simplify main decoding code
+*/
+
+#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
+
+
+/*
+LzmaDec_DecodeReal2():
+ It calls LZMA_DECODE_REAL() and it adjusts limit according (p->checkDicSize).
+
+We correct (p->checkDicSize) after LZMA_DECODE_REAL() and in LzmaDec_WriteRem(),
+and we support the following state of (p->checkDicSize):
+ if (total_processed < p->prop.dicSize) then
+ {
+ (total_processed == p->processedPos)
+ (p->checkDicSize == 0)
+ }
+ else
+ (p->checkDicSize == p->prop.dicSize)
+*/
+
+static int Z7_FASTCALL LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte *bufLimit)
+{
+ if (p->checkDicSize == 0)
+ {
+ UInt32 rem = p->prop.dicSize - p->processedPos;
+ if (limit - p->dicPos > rem)
+ limit = p->dicPos + rem;
+ }
+ {
+ int res = LZMA_DECODE_REAL(p, limit, bufLimit);
+ if (p->checkDicSize == 0 && p->processedPos >= p->prop.dicSize)
+ p->checkDicSize = p->prop.dicSize;
+ return res;
+ }
+}
+
+
+
+typedef enum
+{
+ DUMMY_INPUT_EOF, /* need more input data */
+ DUMMY_LIT,
+ DUMMY_MATCH,
+ DUMMY_REP
+} ELzmaDummy;
+
+
+#define IS_DUMMY_END_MARKER_POSSIBLE(dummyRes) ((dummyRes) == DUMMY_MATCH)
+
+static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, const Byte **bufOut)
+{
+ UInt32 range = p->range;
+ UInt32 code = p->code;
+ const Byte *bufLimit = *bufOut;
+ const CLzmaProb *probs = GET_PROBS;
+ unsigned state = (unsigned)p->state;
+ ELzmaDummy res;
+
+ for (;;)
+ {
+ const CLzmaProb *prob;
+ UInt32 bound;
+ unsigned ttt;
+ unsigned posState = CALC_POS_STATE(p->processedPos, ((unsigned)1 << p->prop.pb) - 1);
+
+ prob = probs + IsMatch + COMBINED_PS_STATE;
+ IF_BIT_0_CHECK(prob)
+ {
+ UPDATE_0_CHECK
+
+ prob = probs + Literal;
+ if (p->checkDicSize != 0 || p->processedPos != 0)
+ prob += ((UInt32)LZMA_LIT_SIZE *
+ ((((p->processedPos) & (((unsigned)1 << (p->prop.lp)) - 1)) << p->prop.lc) +
+ ((unsigned)p->dic[(p->dicPos == 0 ? p->dicBufSize : p->dicPos) - 1] >> (8 - p->prop.lc))));
+
+ 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);
+ }
+ res = DUMMY_LIT;
+ }
+ else
+ {
+ unsigned len;
+ UPDATE_1_CHECK
+
+ prob = probs + IsRep + state;
+ IF_BIT_0_CHECK(prob)
+ {
+ UPDATE_0_CHECK
+ state = 0;
+ prob = probs + LenCoder;
+ res = DUMMY_MATCH;
+ }
+ else
+ {
+ UPDATE_1_CHECK
+ res = DUMMY_REP;
+ prob = probs + IsRepG0 + state;
+ IF_BIT_0_CHECK(prob)
+ {
+ UPDATE_0_CHECK
+ prob = probs + IsRep0Long + COMBINED_PS_STATE;
+ IF_BIT_0_CHECK(prob)
+ {
+ UPDATE_0_CHECK
+ break;
+ }
+ else
+ {
+ UPDATE_1_CHECK
+ }
+ }
+ else
+ {
+ UPDATE_1_CHECK
+ prob = probs + IsRepG1 + state;
+ IF_BIT_0_CHECK(prob)
+ {
+ UPDATE_0_CHECK
+ }
+ else
+ {
+ UPDATE_1_CHECK
+ prob = probs + IsRepG2 + state;
+ IF_BIT_0_CHECK(prob)
+ {
+ UPDATE_0_CHECK
+ }
+ else
+ {
+ UPDATE_1_CHECK
+ }
+ }
+ }
+ state = kNumStates;
+ prob = probs + RepLenCoder;
+ }
+ {
+ 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
+ {
+ UPDATE_1_CHECK
+ probLen = prob + LenChoice2;
+ IF_BIT_0_CHECK(probLen)
+ {
+ UPDATE_0_CHECK
+ probLen = prob + LenLow + GET_LEN_STATE + (1 << kLenNumLowBits);
+ offset = kLenNumLowSymbols;
+ limit = 1 << kLenNumLowBits;
+ }
+ else
+ {
+ UPDATE_1_CHECK
+ probLen = prob + LenHigh;
+ offset = kLenNumLowSymbols * 2;
+ limit = 1 << kLenNumHighBits;
+ }
+ }
+ TREE_DECODE_CHECK(probLen, limit, len)
+ len += offset;
+ }
+
+ 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);
+
+ if (posSlot < kEndPosModelIndex)
+ {
+ prob = probs + SpecPos + ((2 | (posSlot & 1)) << numDirectBits);
+ }
+ else
+ {
+ numDirectBits -= kNumAlignBits;
+ do
+ {
+ NORMALIZE_CHECK
+ range >>= 1;
+ code -= range & (((code - range) >> 31) - 1);
+ /* if (code >= range) code -= range; */
+ }
+ while (--numDirectBits);
+ prob = probs + Align;
+ numDirectBits = kNumAlignBits;
+ }
+ {
+ unsigned i = 1;
+ unsigned m = 1;
+ do
+ {
+ REV_BIT_CHECK(prob, i, m)
+ }
+ while (--numDirectBits);
+ }
+ }
+ }
+ }
+ break;
+ }
+ NORMALIZE_CHECK
+
+ *bufOut = buf;
+ 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->tempBufSize = 0;
+
+ if (initDic)
+ {
+ p->processedPos = 0;
+ p->checkDicSize = 0;
+ p->remainLen = kMatchSpecLenStart + 2;
+ }
+ if (initState)
+ p->remainLen = kMatchSpecLenStart + 2;
+}
+
+void LzmaDec_Init(CLzmaDec *p)
+{
+ p->dicPos = 0;
+ LzmaDec_InitDicAndState(p, True, True);
+}
+
+
+/*
+LZMA supports optional end_marker.
+So the decoder can lookahead for one additional LZMA-Symbol to check end_marker.
+That additional LZMA-Symbol can require up to LZMA_REQUIRED_INPUT_MAX bytes in input stream.
+When the decoder reaches dicLimit, it looks (finishMode) parameter:
+ if (finishMode == LZMA_FINISH_ANY), the decoder doesn't lookahead
+ if (finishMode != LZMA_FINISH_ANY), the decoder lookahead, if end_marker is possible for current position
+
+When the decoder lookahead, and the lookahead symbol is not end_marker, we have two ways:
+ 1) Strict mode (default) : the decoder returns SZ_ERROR_DATA.
+ 2) The relaxed mode (alternative mode) : we could return SZ_OK, and the caller
+ must check (status) value. The caller can show the error,
+ if the end of stream is expected, and the (status) is noit
+ LZMA_STATUS_FINISHED_WITH_MARK or LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK.
+*/
+
+
+#define RETURN_NOT_FINISHED_FOR_FINISH \
+ *status = LZMA_STATUS_NOT_FINISHED; \
+ return SZ_ERROR_DATA; // for strict mode
+ // return SZ_OK; // for relaxed mode
+
+
+SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen,
+ ELzmaFinishMode finishMode, ELzmaStatus *status)
+{
+ SizeT inSize = *srcLen;
+ (*srcLen) = 0;
+ *status = LZMA_STATUS_NOT_SPECIFIED;
+
+ if (p->remainLen > kMatchSpecLenStart)
+ {
+ if (p->remainLen > kMatchSpecLenStart + 2)
+ return p->remainLen == kMatchSpecLen_Error_Fail ? SZ_ERROR_FAIL : SZ_ERROR_DATA;
+
+ for (; inSize > 0 && p->tempBufSize < RC_INIT_SIZE; (*srcLen)++, inSize--)
+ p->tempBuf[p->tempBufSize++] = *src++;
+ if (p->tempBufSize != 0 && p->tempBuf[0] != 0)
+ return SZ_ERROR_DATA;
+ 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[2] << 16)
+ | ((UInt32)p->tempBuf[3] << 8)
+ | ((UInt32)p->tempBuf[4]);
+
+ if (p->checkDicSize == 0
+ && p->processedPos == 0
+ && p->code >= kBadRepCode)
+ return SZ_ERROR_DATA;
+
+ 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++)
+ probs[i] = kBitModelTotal >> 1;
+ p->reps[0] = p->reps[1] = p->reps[2] = p->reps[3] = 1;
+ p->state = 0;
+ }
+
+ p->remainLen = 0;
+ }
+
+ for (;;)
+ {
+ if (p->remainLen == kMatchSpecLenStart)
+ {
+ if (p->code != 0)
+ return SZ_ERROR_DATA;
+ *status = LZMA_STATUS_FINISHED_WITH_MARK;
+ return SZ_OK;
+ }
+
+ LzmaDec_WriteRem(p, dicLimit);
+
+ {
+ // (p->remainLen == 0 || p->dicPos == dicLimit)
+
+ int checkEndMarkNow = 0;
+
+ 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)
+ {
+ RETURN_NOT_FINISHED_FOR_FINISH
+ }
+ checkEndMarkNow = 1;
+ }
+
+ // (p->remainLen == 0)
+
+ if (p->tempBufSize == 0)
+ {
+ const Byte *bufLimit;
+ int dummyProcessed = -1;
+
+ if (inSize < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)
+ {
+ const Byte *bufOut = src + inSize;
+
+ ELzmaDummy dummyRes = LzmaDec_TryDummy(p, src, &bufOut);
+
+ if (dummyRes == DUMMY_INPUT_EOF)
+ {
+ size_t i;
+ if (inSize >= LZMA_REQUIRED_INPUT_MAX)
+ break;
+ (*srcLen) += inSize;
+ p->tempBufSize = (unsigned)inSize;
+ for (i = 0; i < inSize; i++)
+ p->tempBuf[i] = src[i];
+ *status = LZMA_STATUS_NEEDS_MORE_INPUT;
+ return SZ_OK;
+ }
+
+ dummyProcessed = (int)(bufOut - src);
+ if ((unsigned)dummyProcessed > LZMA_REQUIRED_INPUT_MAX)
+ break;
+
+ if (checkEndMarkNow && !IS_DUMMY_END_MARKER_POSSIBLE(dummyRes))
+ {
+ unsigned i;
+ (*srcLen) += (unsigned)dummyProcessed;
+ p->tempBufSize = (unsigned)dummyProcessed;
+ for (i = 0; i < (unsigned)dummyProcessed; i++)
+ p->tempBuf[i] = src[i];
+ // p->remainLen = kMatchSpecLen_Error_Data;
+ RETURN_NOT_FINISHED_FOR_FINISH
+ }
+
+ bufLimit = src;
+ // we will decode only one iteration
+ }
+ else
+ bufLimit = src + inSize - LZMA_REQUIRED_INPUT_MAX;
+
+ p->buf = src;
+
+ {
+ int res = LzmaDec_DecodeReal2(p, dicLimit, bufLimit);
+
+ SizeT processed = (SizeT)(p->buf - src);
+
+ if (dummyProcessed < 0)
+ {
+ if (processed > inSize)
+ break;
+ }
+ else if ((unsigned)dummyProcessed != processed)
+ break;
+
+ src += processed;
+ inSize -= processed;
+ (*srcLen) += processed;
+
+ if (res != SZ_OK)
+ {
+ p->remainLen = kMatchSpecLen_Error_Data;
+ return SZ_ERROR_DATA;
+ }
+ }
+ continue;
+ }
+
+ {
+ // we have some data in (p->tempBuf)
+ // in strict mode: tempBufSize is not enough for one Symbol decoding.
+ // in relaxed mode: tempBufSize not larger than required for one Symbol decoding.
+
+ unsigned rem = p->tempBufSize;
+ unsigned ahead = 0;
+ int dummyProcessed = -1;
+
+ while (rem < LZMA_REQUIRED_INPUT_MAX && ahead < inSize)
+ p->tempBuf[rem++] = src[ahead++];
+
+ // ahead - the size of new data copied from (src) to (p->tempBuf)
+ // rem - the size of temp buffer including new data from (src)
+
+ if (rem < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)
+ {
+ const Byte *bufOut = p->tempBuf + rem;
+
+ ELzmaDummy dummyRes = LzmaDec_TryDummy(p, p->tempBuf, &bufOut);
+
+ if (dummyRes == DUMMY_INPUT_EOF)
+ {
+ if (rem >= LZMA_REQUIRED_INPUT_MAX)
+ break;
+ p->tempBufSize = rem;
+ (*srcLen) += (SizeT)ahead;
+ *status = LZMA_STATUS_NEEDS_MORE_INPUT;
+ return SZ_OK;
+ }
+
+ dummyProcessed = (int)(bufOut - p->tempBuf);
+
+ if ((unsigned)dummyProcessed < p->tempBufSize)
+ break;
+
+ if (checkEndMarkNow && !IS_DUMMY_END_MARKER_POSSIBLE(dummyRes))
+ {
+ (*srcLen) += (unsigned)dummyProcessed - p->tempBufSize;
+ p->tempBufSize = (unsigned)dummyProcessed;
+ // p->remainLen = kMatchSpecLen_Error_Data;
+ RETURN_NOT_FINISHED_FOR_FINISH
+ }
+ }
+
+ p->buf = p->tempBuf;
+
+ {
+ // we decode one symbol from (p->tempBuf) here, so the (bufLimit) is equal to (p->buf)
+ int res = LzmaDec_DecodeReal2(p, dicLimit, p->buf);
+
+ SizeT processed = (SizeT)(p->buf - p->tempBuf);
+ rem = p->tempBufSize;
+
+ if (dummyProcessed < 0)
+ {
+ if (processed > LZMA_REQUIRED_INPUT_MAX)
+ break;
+ if (processed < rem)
+ break;
+ }
+ else if ((unsigned)dummyProcessed != processed)
+ break;
+
+ processed -= rem;
+
+ src += processed;
+ inSize -= processed;
+ (*srcLen) += processed;
+ p->tempBufSize = 0;
+
+ if (res != SZ_OK)
+ {
+ p->remainLen = kMatchSpecLen_Error_Data;
+ return SZ_ERROR_DATA;
+ }
+ }
+ }
+ }
+ }
+
+ /* Some unexpected error: internal error of code, memory corruption or hardware failure */
+ p->remainLen = kMatchSpecLen_Error_Fail;
+ return SZ_ERROR_FAIL;
+}
+
+
+
+SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
+{
+ SizeT outSize = *destLen;
+ SizeT inSize = *srcLen;
+ *srcLen = *destLen = 0;
+ 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;
+ curFinishMode = LZMA_FINISH_ANY;
+ }
+ else
+ {
+ outSizeCur = dicPos + outSize;
+ curFinishMode = finishMode;
+ }
+
+ 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;
+ *destLen += outSizeCur;
+ if (res != 0)
+ return res;
+ if (outSizeCur == 0 || outSize == 0)
+ return SZ_OK;
+ }
+}
+
+void LzmaDec_FreeProbs(CLzmaDec *p, ISzAllocPtr alloc)
+{
+ ISzAlloc_Free(alloc, p->probs);
+ p->probs = NULL;
+}
+
+static void LzmaDec_FreeDict(CLzmaDec *p, ISzAllocPtr alloc)
+{
+ ISzAlloc_Free(alloc, p->dic);
+ p->dic = NULL;
+}
+
+void LzmaDec_Free(CLzmaDec *p, ISzAllocPtr alloc)
+{
+ LzmaDec_FreeProbs(p, alloc);
+ LzmaDec_FreeDict(p, alloc);
+}
+
+SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)
+{
+ UInt32 dicSize;
+ Byte d;
+
+ if (size < LZMA_PROPS_SIZE)
+ return SZ_ERROR_UNSUPPORTED;
+ else
+ dicSize = data[1] | ((UInt32)data[2] << 8) | ((UInt32)data[3] << 16) | ((UInt32)data[4] << 24);
+
+ if (dicSize < LZMA_DIC_MIN)
+ dicSize = LZMA_DIC_MIN;
+ p->dicSize = dicSize;
+
+ d = data[0];
+ if (d >= (9 * 5 * 5))
+ return SZ_ERROR_UNSUPPORTED;
+
+ p->lc = (Byte)(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)
+{
+ 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;
+ }
+ return SZ_OK;
+}
+
+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))
+ p->prop = propNew;
+ return SZ_OK;
+}
+
+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))
+
+ {
+ 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)
+ 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);
+ return SZ_ERROR_MEM;
+ }
+ }
+ p->dicBufSize = dicBufSize;
+ 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)
+{
+ CLzmaDec p;
+ SRes res;
+ SizeT outSize = *destLen, inSize = *srcLen;
+ *destLen = *srcLen = 0;
+ *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;
+ p.dicBufSize = outSize;
+ 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)
+ res = SZ_ERROR_INPUT_EOF;
+ LzmaDec_FreeProbs(&p, alloc);
+ return res;
+}
diff --git a/deps/libchdr/deps/lzma-22.01/src/LzmaEnc.c b/deps/libchdr/deps/lzma-24.05/src/LzmaEnc.c
similarity index 86%
rename from deps/libchdr/deps/lzma-22.01/src/LzmaEnc.c
rename to deps/libchdr/deps/lzma-24.05/src/LzmaEnc.c
index ca9154ae..37b2787d 100644
--- a/deps/libchdr/deps/lzma-22.01/src/LzmaEnc.c
+++ b/deps/libchdr/deps/lzma-24.05/src/LzmaEnc.c
@@ -1,3162 +1,3144 @@
-/* LzmaEnc.c -- LZMA Encoder
-2022-07-15: Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#include
-
-/* #define SHOW_STAT */
-/* #define SHOW_STAT2 */
-
-#if defined(SHOW_STAT) || defined(SHOW_STAT2)
-#include
-#endif
-
-#include "CpuArch.h"
-#include "LzmaEnc.h"
-
-#include "LzFind.h"
-#ifndef _7ZIP_ST
-#include "LzFindMt.h"
-#endif
-
-/* the following LzmaEnc_* declarations is internal LZMA interface for LZMA2 encoder */
-
-SRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp, ISeqInStream *inStream, UInt32 keepWindowSize,
- ISzAllocPtr alloc, ISzAllocPtr allocBig);
-SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen,
- UInt32 keepWindowSize, ISzAllocPtr alloc, ISzAllocPtr allocBig);
-SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, BoolInt reInit,
- Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize);
-const Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp);
-void LzmaEnc_Finish(CLzmaEncHandle pp);
-void LzmaEnc_SaveState(CLzmaEncHandle pp);
-void LzmaEnc_RestoreState(CLzmaEncHandle pp);
-
-#ifdef SHOW_STAT
-static unsigned g_STAT_OFFSET = 0;
-#endif
-
-/* for good normalization speed we still reserve 256 MB before 4 GB range */
-#define kLzmaMaxHistorySize ((UInt32)15 << 28)
-
-#define kNumTopBits 24
-#define kTopValue ((UInt32)1 << kNumTopBits)
-
-#define kNumBitModelTotalBits 11
-#define kBitModelTotal (1 << kNumBitModelTotalBits)
-#define kNumMoveBits 5
-#define kProbInitValue (kBitModelTotal >> 1)
-
-#define kNumMoveReducingBits 4
-#define kNumBitPriceShiftBits 4
-// #define kBitPrice (1 << kNumBitPriceShiftBits)
-
-#define REP_LEN_COUNT 64
-
-void LzmaEncProps_Init(CLzmaEncProps *p)
-{
- p->level = 5;
- p->dictSize = p->mc = 0;
- p->reduceSize = (UInt64)(Int64)-1;
- p->lc = p->lp = p->pb = p->algo = p->fb = p->btMode = p->numHashBytes = p->numThreads = -1;
- p->writeEndMark = 0;
- p->affinity = 0;
-}
-
-void LzmaEncProps_Normalize(CLzmaEncProps *p)
-{
- int level = p->level;
- if (level < 0) level = 5;
- p->level = level;
-
- if (p->dictSize == 0)
- p->dictSize =
- ( level <= 3 ? ((UInt32)1 << (level * 2 + 16)) :
- ( level <= 6 ? ((UInt32)1 << (level + 19)) :
- ( level <= 7 ? ((UInt32)1 << 25) : ((UInt32)1 << 26)
- )));
-
- if (p->dictSize > p->reduceSize)
- {
- UInt32 v = (UInt32)p->reduceSize;
- const UInt32 kReduceMin = ((UInt32)1 << 12);
- if (v < kReduceMin)
- v = kReduceMin;
- if (p->dictSize > v)
- p->dictSize = v;
- }
-
- if (p->lc < 0) p->lc = 3;
- if (p->lp < 0) p->lp = 0;
- if (p->pb < 0) p->pb = 2;
-
- if (p->algo < 0) p->algo = (level < 5 ? 0 : 1);
- if (p->fb < 0) p->fb = (level < 7 ? 32 : 64);
- if (p->btMode < 0) p->btMode = (p->algo == 0 ? 0 : 1);
- if (p->numHashBytes < 0) p->numHashBytes = (p->btMode ? 4 : 5);
- if (p->mc == 0) p->mc = (16 + ((unsigned)p->fb >> 1)) >> (p->btMode ? 0 : 1);
-
- if (p->numThreads < 0)
- p->numThreads =
- #ifndef _7ZIP_ST
- ((p->btMode && p->algo) ? 2 : 1);
- #else
- 1;
- #endif
-}
-
-UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2)
-{
- CLzmaEncProps props = *props2;
- LzmaEncProps_Normalize(&props);
- return props.dictSize;
-}
-
-
-/*
-x86/x64:
-
-BSR:
- IF (SRC == 0) ZF = 1, DEST is undefined;
- AMD : DEST is unchanged;
- IF (SRC != 0) ZF = 0; DEST is index of top non-zero bit
- BSR is slow in some processors
-
-LZCNT:
- IF (SRC == 0) CF = 1, DEST is size_in_bits_of_register(src) (32 or 64)
- IF (SRC != 0) CF = 0, DEST = num_lead_zero_bits
- IF (DEST == 0) ZF = 1;
-
-LZCNT works only in new processors starting from Haswell.
-if LZCNT is not supported by processor, then it's executed as BSR.
-LZCNT can be faster than BSR, if supported.
-*/
-
-// #define LZMA_LOG_BSR
-
-#if defined(MY_CPU_ARM_OR_ARM64) /* || defined(MY_CPU_X86_OR_AMD64) */
-
- #if (defined(__clang__) && (__clang_major__ >= 6)) \
- || (defined(__GNUC__) && (__GNUC__ >= 6))
- #define LZMA_LOG_BSR
- #elif defined(_MSC_VER) && (_MSC_VER >= 1300)
- // #if defined(MY_CPU_ARM_OR_ARM64)
- #define LZMA_LOG_BSR
- // #endif
- #endif
-#endif
-
-// #include
-
-#ifdef LZMA_LOG_BSR
-
-#if defined(__clang__) \
- || defined(__GNUC__)
-
-/*
- C code: : (30 - __builtin_clz(x))
- gcc9/gcc10 for x64 /x86 : 30 - (bsr(x) xor 31)
- clang10 for x64 : 31 + (bsr(x) xor -32)
-*/
-
- #define MY_clz(x) ((unsigned)__builtin_clz(x))
- // __lzcnt32
- // __builtin_ia32_lzcnt_u32
-
-#else // #if defined(_MSC_VER)
-
- #ifdef MY_CPU_ARM_OR_ARM64
-
- #define MY_clz _CountLeadingZeros
-
- #else // if defined(MY_CPU_X86_OR_AMD64)
-
- // #define MY_clz __lzcnt // we can use lzcnt (unsupported by old CPU)
- // _BitScanReverse code is not optimal for some MSVC compilers
- #define BSR2_RET(pos, res) { unsigned long zz; _BitScanReverse(&zz, (pos)); zz--; \
- res = (zz + zz) + (pos >> zz); }
-
- #endif // MY_CPU_X86_OR_AMD64
-
-#endif // _MSC_VER
-
-
-#ifndef BSR2_RET
-
- #define BSR2_RET(pos, res) { unsigned zz = 30 - MY_clz(pos); \
- res = (zz + zz) + (pos >> zz); }
-
-#endif
-
-
-unsigned GetPosSlot1(UInt32 pos);
-unsigned GetPosSlot1(UInt32 pos)
-{
- unsigned res;
- BSR2_RET(pos, res);
- return res;
-}
-#define GetPosSlot2(pos, res) { BSR2_RET(pos, res); }
-#define GetPosSlot(pos, res) { if (pos < 2) res = pos; else BSR2_RET(pos, res); }
-
-
-#else // ! LZMA_LOG_BSR
-
-#define kNumLogBits (11 + sizeof(size_t) / 8 * 3)
-
-#define kDicLogSizeMaxCompress ((kNumLogBits - 1) * 2 + 7)
-
-static void LzmaEnc_FastPosInit(Byte *g_FastPos)
-{
- unsigned slot;
- g_FastPos[0] = 0;
- g_FastPos[1] = 1;
- g_FastPos += 2;
-
- for (slot = 2; slot < kNumLogBits * 2; slot++)
- {
- size_t k = ((size_t)1 << ((slot >> 1) - 1));
- size_t j;
- for (j = 0; j < k; j++)
- g_FastPos[j] = (Byte)slot;
- g_FastPos += k;
- }
-}
-
-/* we can use ((limit - pos) >> 31) only if (pos < ((UInt32)1 << 31)) */
-/*
-#define BSR2_RET(pos, res) { unsigned zz = 6 + ((kNumLogBits - 1) & \
- (0 - (((((UInt32)1 << (kNumLogBits + 6)) - 1) - pos) >> 31))); \
- res = p->g_FastPos[pos >> zz] + (zz * 2); }
-*/
-
-/*
-#define BSR2_RET(pos, res) { unsigned zz = 6 + ((kNumLogBits - 1) & \
- (0 - (((((UInt32)1 << (kNumLogBits)) - 1) - (pos >> 6)) >> 31))); \
- res = p->g_FastPos[pos >> zz] + (zz * 2); }
-*/
-
-#define BSR2_RET(pos, res) { unsigned zz = (pos < (1 << (kNumLogBits + 6))) ? 6 : 6 + kNumLogBits - 1; \
- res = p->g_FastPos[pos >> zz] + (zz * 2); }
-
-/*
-#define BSR2_RET(pos, res) { res = (pos < (1 << (kNumLogBits + 6))) ? \
- p->g_FastPos[pos >> 6] + 12 : \
- p->g_FastPos[pos >> (6 + kNumLogBits - 1)] + (6 + (kNumLogBits - 1)) * 2; }
-*/
-
-#define GetPosSlot1(pos) p->g_FastPos[pos]
-#define GetPosSlot2(pos, res) { BSR2_RET(pos, res); }
-#define GetPosSlot(pos, res) { if (pos < kNumFullDistances) res = p->g_FastPos[pos & (kNumFullDistances - 1)]; else BSR2_RET(pos, res); }
-
-#endif // LZMA_LOG_BSR
-
-
-#define LZMA_NUM_REPS 4
-
-typedef UInt16 CState;
-typedef UInt16 CExtra;
-
-typedef struct
-{
- UInt32 price;
- CState state;
- CExtra extra;
- // 0 : normal
- // 1 : LIT : MATCH
- // > 1 : MATCH (extra-1) : LIT : REP0 (len)
- UInt32 len;
- UInt32 dist;
- UInt32 reps[LZMA_NUM_REPS];
-} COptimal;
-
-
-// 18.06
-#define kNumOpts (1 << 11)
-#define kPackReserve (kNumOpts * 8)
-// #define kNumOpts (1 << 12)
-// #define kPackReserve (1 + kNumOpts * 2)
-
-#define kNumLenToPosStates 4
-#define kNumPosSlotBits 6
-// #define kDicLogSizeMin 0
-#define kDicLogSizeMax 32
-#define kDistTableSizeMax (kDicLogSizeMax * 2)
-
-#define kNumAlignBits 4
-#define kAlignTableSize (1 << kNumAlignBits)
-#define kAlignMask (kAlignTableSize - 1)
-
-#define kStartPosModelIndex 4
-#define kEndPosModelIndex 14
-#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))
-
-typedef
-#ifdef _LZMA_PROB32
- UInt32
-#else
- UInt16
-#endif
- CLzmaProb;
-
-#define LZMA_PB_MAX 4
-#define LZMA_LC_MAX 8
-#define LZMA_LP_MAX 4
-
-#define LZMA_NUM_PB_STATES_MAX (1 << LZMA_PB_MAX)
-
-#define kLenNumLowBits 3
-#define kLenNumLowSymbols (1 << kLenNumLowBits)
-#define kLenNumHighBits 8
-#define kLenNumHighSymbols (1 << kLenNumHighBits)
-#define kLenNumSymbolsTotal (kLenNumLowSymbols * 2 + kLenNumHighSymbols)
-
-#define LZMA_MATCH_LEN_MIN 2
-#define LZMA_MATCH_LEN_MAX (LZMA_MATCH_LEN_MIN + kLenNumSymbolsTotal - 1)
-
-#define kNumStates 12
-
-
-typedef struct
-{
- CLzmaProb low[LZMA_NUM_PB_STATES_MAX << (kLenNumLowBits + 1)];
- CLzmaProb high[kLenNumHighSymbols];
-} CLenEnc;
-
-
-typedef struct
-{
- unsigned tableSize;
- UInt32 prices[LZMA_NUM_PB_STATES_MAX][kLenNumSymbolsTotal];
- // UInt32 prices1[LZMA_NUM_PB_STATES_MAX][kLenNumLowSymbols * 2];
- // UInt32 prices2[kLenNumSymbolsTotal];
-} CLenPriceEnc;
-
-#define GET_PRICE_LEN(p, posState, len) \
- ((p)->prices[posState][(size_t)(len) - LZMA_MATCH_LEN_MIN])
-
-/*
-#define GET_PRICE_LEN(p, posState, len) \
- ((p)->prices2[(size_t)(len) - 2] + ((p)->prices1[posState][((len) - 2) & (kLenNumLowSymbols * 2 - 1)] & (((len) - 2 - kLenNumLowSymbols * 2) >> 9)))
-*/
-
-typedef struct
-{
- UInt32 range;
- unsigned cache;
- UInt64 low;
- UInt64 cacheSize;
- Byte *buf;
- Byte *bufLim;
- Byte *bufBase;
- ISeqOutStream *outStream;
- UInt64 processed;
- SRes res;
-} CRangeEnc;
-
-
-typedef struct
-{
- CLzmaProb *litProbs;
-
- unsigned state;
- UInt32 reps[LZMA_NUM_REPS];
-
- CLzmaProb posAlignEncoder[1 << kNumAlignBits];
- CLzmaProb isRep[kNumStates];
- CLzmaProb isRepG0[kNumStates];
- CLzmaProb isRepG1[kNumStates];
- CLzmaProb isRepG2[kNumStates];
- CLzmaProb isMatch[kNumStates][LZMA_NUM_PB_STATES_MAX];
- CLzmaProb isRep0Long[kNumStates][LZMA_NUM_PB_STATES_MAX];
-
- CLzmaProb posSlotEncoder[kNumLenToPosStates][1 << kNumPosSlotBits];
- CLzmaProb posEncoders[kNumFullDistances];
-
- CLenEnc lenProbs;
- CLenEnc repLenProbs;
-
-} CSaveState;
-
-
-typedef UInt32 CProbPrice;
-
-
-typedef struct
-{
- void *matchFinderObj;
- IMatchFinder2 matchFinder;
-
- unsigned optCur;
- unsigned optEnd;
-
- unsigned longestMatchLen;
- unsigned numPairs;
- UInt32 numAvail;
-
- unsigned state;
- unsigned numFastBytes;
- unsigned additionalOffset;
- UInt32 reps[LZMA_NUM_REPS];
- unsigned lpMask, pbMask;
- CLzmaProb *litProbs;
- CRangeEnc rc;
-
- UInt32 backRes;
-
- unsigned lc, lp, pb;
- unsigned lclp;
-
- BoolInt fastMode;
- BoolInt writeEndMark;
- BoolInt finished;
- BoolInt multiThread;
- BoolInt needInit;
- // BoolInt _maxMode;
-
- UInt64 nowPos64;
-
- unsigned matchPriceCount;
- // unsigned alignPriceCount;
- int repLenEncCounter;
-
- unsigned distTableSize;
-
- UInt32 dictSize;
- SRes result;
-
- #ifndef _7ZIP_ST
- BoolInt mtMode;
- // begin of CMatchFinderMt is used in LZ thread
- CMatchFinderMt matchFinderMt;
- // end of CMatchFinderMt is used in BT and HASH threads
- // #else
- // CMatchFinder matchFinderBase;
- #endif
- CMatchFinder matchFinderBase;
-
-
- // we suppose that we have 8-bytes alignment after CMatchFinder
-
- #ifndef _7ZIP_ST
- Byte pad[128];
- #endif
-
- // LZ thread
- CProbPrice ProbPrices[kBitModelTotal >> kNumMoveReducingBits];
-
- // we want {len , dist} pairs to be 8-bytes aligned in matches array
- UInt32 matches[LZMA_MATCH_LEN_MAX * 2 + 2];
-
- // we want 8-bytes alignment here
- UInt32 alignPrices[kAlignTableSize];
- UInt32 posSlotPrices[kNumLenToPosStates][kDistTableSizeMax];
- UInt32 distancesPrices[kNumLenToPosStates][kNumFullDistances];
-
- CLzmaProb posAlignEncoder[1 << kNumAlignBits];
- CLzmaProb isRep[kNumStates];
- CLzmaProb isRepG0[kNumStates];
- CLzmaProb isRepG1[kNumStates];
- CLzmaProb isRepG2[kNumStates];
- CLzmaProb isMatch[kNumStates][LZMA_NUM_PB_STATES_MAX];
- CLzmaProb isRep0Long[kNumStates][LZMA_NUM_PB_STATES_MAX];
- CLzmaProb posSlotEncoder[kNumLenToPosStates][1 << kNumPosSlotBits];
- CLzmaProb posEncoders[kNumFullDistances];
-
- CLenEnc lenProbs;
- CLenEnc repLenProbs;
-
- #ifndef LZMA_LOG_BSR
- Byte g_FastPos[1 << kNumLogBits];
- #endif
-
- CLenPriceEnc lenEnc;
- CLenPriceEnc repLenEnc;
-
- COptimal opt[kNumOpts];
-
- CSaveState saveState;
-
- // BoolInt mf_Failure;
- #ifndef _7ZIP_ST
- Byte pad2[128];
- #endif
-} CLzmaEnc;
-
-
-#define MFB (p->matchFinderBase)
-/*
-#ifndef _7ZIP_ST
-#define MFB (p->matchFinderMt.MatchFinder)
-#endif
-*/
-
-#define COPY_ARR(dest, src, arr) memcpy(dest->arr, src->arr, sizeof(src->arr));
-
-void LzmaEnc_SaveState(CLzmaEncHandle pp)
-{
- CLzmaEnc *p = (CLzmaEnc *)pp;
- CSaveState *dest = &p->saveState;
-
- dest->state = p->state;
-
- dest->lenProbs = p->lenProbs;
- dest->repLenProbs = p->repLenProbs;
-
- COPY_ARR(dest, p, reps);
-
- COPY_ARR(dest, p, posAlignEncoder);
- COPY_ARR(dest, p, isRep);
- COPY_ARR(dest, p, isRepG0);
- COPY_ARR(dest, p, isRepG1);
- COPY_ARR(dest, p, isRepG2);
- COPY_ARR(dest, p, isMatch);
- COPY_ARR(dest, p, isRep0Long);
- COPY_ARR(dest, p, posSlotEncoder);
- COPY_ARR(dest, p, posEncoders);
-
- memcpy(dest->litProbs, p->litProbs, ((UInt32)0x300 << p->lclp) * sizeof(CLzmaProb));
-}
-
-
-void LzmaEnc_RestoreState(CLzmaEncHandle pp)
-{
- CLzmaEnc *dest = (CLzmaEnc *)pp;
- const CSaveState *p = &dest->saveState;
-
- dest->state = p->state;
-
- dest->lenProbs = p->lenProbs;
- dest->repLenProbs = p->repLenProbs;
-
- COPY_ARR(dest, p, reps);
-
- COPY_ARR(dest, p, posAlignEncoder);
- COPY_ARR(dest, p, isRep);
- COPY_ARR(dest, p, isRepG0);
- COPY_ARR(dest, p, isRepG1);
- COPY_ARR(dest, p, isRepG2);
- COPY_ARR(dest, p, isMatch);
- COPY_ARR(dest, p, isRep0Long);
- COPY_ARR(dest, p, posSlotEncoder);
- COPY_ARR(dest, p, posEncoders);
-
- memcpy(dest->litProbs, p->litProbs, ((UInt32)0x300 << dest->lclp) * sizeof(CLzmaProb));
-}
-
-
-
-SRes LzmaEnc_SetProps(CLzmaEncHandle pp, const CLzmaEncProps *props2)
-{
- CLzmaEnc *p = (CLzmaEnc *)pp;
- CLzmaEncProps props = *props2;
- LzmaEncProps_Normalize(&props);
-
- if (props.lc > LZMA_LC_MAX
- || props.lp > LZMA_LP_MAX
- || props.pb > LZMA_PB_MAX)
- return SZ_ERROR_PARAM;
-
-
- if (props.dictSize > kLzmaMaxHistorySize)
- props.dictSize = kLzmaMaxHistorySize;
-
- #ifndef LZMA_LOG_BSR
- {
- const UInt64 dict64 = props.dictSize;
- if (dict64 > ((UInt64)1 << kDicLogSizeMaxCompress))
- return SZ_ERROR_PARAM;
- }
- #endif
-
- p->dictSize = props.dictSize;
- {
- unsigned fb = (unsigned)props.fb;
- if (fb < 5)
- fb = 5;
- if (fb > LZMA_MATCH_LEN_MAX)
- fb = LZMA_MATCH_LEN_MAX;
- p->numFastBytes = fb;
- }
- p->lc = (unsigned)props.lc;
- p->lp = (unsigned)props.lp;
- p->pb = (unsigned)props.pb;
- p->fastMode = (props.algo == 0);
- // p->_maxMode = True;
- MFB.btMode = (Byte)(props.btMode ? 1 : 0);
- {
- unsigned numHashBytes = 4;
- if (props.btMode)
- {
- if (props.numHashBytes < 2) numHashBytes = 2;
- else if (props.numHashBytes < 4) numHashBytes = (unsigned)props.numHashBytes;
- }
- if (props.numHashBytes >= 5) numHashBytes = 5;
-
- MFB.numHashBytes = numHashBytes;
- }
-
- MFB.cutValue = props.mc;
-
- p->writeEndMark = (BoolInt)props.writeEndMark;
-
- #ifndef _7ZIP_ST
- /*
- if (newMultiThread != _multiThread)
- {
- ReleaseMatchFinder();
- _multiThread = newMultiThread;
- }
- */
- p->multiThread = (props.numThreads > 1);
- p->matchFinderMt.btSync.affinity =
- p->matchFinderMt.hashSync.affinity = props.affinity;
- #endif
-
- return SZ_OK;
-}
-
-
-void LzmaEnc_SetDataSize(CLzmaEncHandle pp, UInt64 expectedDataSiize)
-{
- CLzmaEnc *p = (CLzmaEnc *)pp;
- MFB.expectedDataSize = expectedDataSiize;
-}
-
-
-#define kState_Start 0
-#define kState_LitAfterMatch 4
-#define kState_LitAfterRep 5
-#define kState_MatchAfterLit 7
-#define kState_RepAfterLit 8
-
-static const Byte kLiteralNextStates[kNumStates] = {0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5};
-static const Byte kMatchNextStates[kNumStates] = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};
-static const Byte kRepNextStates[kNumStates] = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};
-static const Byte kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};
-
-#define IsLitState(s) ((s) < 7)
-#define GetLenToPosState2(len) (((len) < kNumLenToPosStates - 1) ? (len) : kNumLenToPosStates - 1)
-#define GetLenToPosState(len) (((len) < kNumLenToPosStates + 1) ? (len) - 2 : kNumLenToPosStates - 1)
-
-#define kInfinityPrice (1 << 30)
-
-static void RangeEnc_Construct(CRangeEnc *p)
-{
- p->outStream = NULL;
- p->bufBase = NULL;
-}
-
-#define RangeEnc_GetProcessed(p) ( (p)->processed + (size_t)((p)->buf - (p)->bufBase) + (p)->cacheSize)
-#define RangeEnc_GetProcessed_sizet(p) ((size_t)(p)->processed + (size_t)((p)->buf - (p)->bufBase) + (size_t)(p)->cacheSize)
-
-#define RC_BUF_SIZE (1 << 16)
-
-static int RangeEnc_Alloc(CRangeEnc *p, ISzAllocPtr alloc)
-{
- if (!p->bufBase)
- {
- p->bufBase = (Byte *)ISzAlloc_Alloc(alloc, RC_BUF_SIZE);
- if (!p->bufBase)
- return 0;
- p->bufLim = p->bufBase + RC_BUF_SIZE;
- }
- return 1;
-}
-
-static void RangeEnc_Free(CRangeEnc *p, ISzAllocPtr alloc)
-{
- ISzAlloc_Free(alloc, p->bufBase);
- p->bufBase = NULL;
-}
-
-static void RangeEnc_Init(CRangeEnc *p)
-{
- p->range = 0xFFFFFFFF;
- p->cache = 0;
- p->low = 0;
- p->cacheSize = 0;
-
- p->buf = p->bufBase;
-
- p->processed = 0;
- p->res = SZ_OK;
-}
-
-MY_NO_INLINE static void RangeEnc_FlushStream(CRangeEnc *p)
-{
- const size_t num = (size_t)(p->buf - p->bufBase);
- if (p->res == SZ_OK)
- {
- if (num != ISeqOutStream_Write(p->outStream, p->bufBase, num))
- p->res = SZ_ERROR_WRITE;
- }
- p->processed += num;
- p->buf = p->bufBase;
-}
-
-MY_NO_INLINE static void MY_FAST_CALL RangeEnc_ShiftLow(CRangeEnc *p)
-{
- UInt32 low = (UInt32)p->low;
- unsigned high = (unsigned)(p->low >> 32);
- p->low = (UInt32)(low << 8);
- if (low < (UInt32)0xFF000000 || high != 0)
- {
- {
- Byte *buf = p->buf;
- *buf++ = (Byte)(p->cache + high);
- p->cache = (unsigned)(low >> 24);
- p->buf = buf;
- if (buf == p->bufLim)
- RangeEnc_FlushStream(p);
- if (p->cacheSize == 0)
- return;
- }
- high += 0xFF;
- for (;;)
- {
- Byte *buf = p->buf;
- *buf++ = (Byte)(high);
- p->buf = buf;
- if (buf == p->bufLim)
- RangeEnc_FlushStream(p);
- if (--p->cacheSize == 0)
- return;
- }
- }
- p->cacheSize++;
-}
-
-static void RangeEnc_FlushData(CRangeEnc *p)
-{
- int i;
- for (i = 0; i < 5; i++)
- RangeEnc_ShiftLow(p);
-}
-
-#define RC_NORM(p) if (range < kTopValue) { range <<= 8; RangeEnc_ShiftLow(p); }
-
-#define RC_BIT_PRE(p, prob) \
- ttt = *(prob); \
- newBound = (range >> kNumBitModelTotalBits) * ttt;
-
-// #define _LZMA_ENC_USE_BRANCH
-
-#ifdef _LZMA_ENC_USE_BRANCH
-
-#define RC_BIT(p, prob, bit) { \
- RC_BIT_PRE(p, prob) \
- if (bit == 0) { range = newBound; ttt += (kBitModelTotal - ttt) >> kNumMoveBits; } \
- else { (p)->low += newBound; range -= newBound; ttt -= ttt >> kNumMoveBits; } \
- *(prob) = (CLzmaProb)ttt; \
- RC_NORM(p) \
- }
-
-#else
-
-#define RC_BIT(p, prob, bit) { \
- UInt32 mask; \
- RC_BIT_PRE(p, prob) \
- mask = 0 - (UInt32)bit; \
- range &= mask; \
- mask &= newBound; \
- range -= mask; \
- (p)->low += mask; \
- mask = (UInt32)bit - 1; \
- range += newBound & mask; \
- mask &= (kBitModelTotal - ((1 << kNumMoveBits) - 1)); \
- mask += ((1 << kNumMoveBits) - 1); \
- ttt += (UInt32)((Int32)(mask - ttt) >> kNumMoveBits); \
- *(prob) = (CLzmaProb)ttt; \
- RC_NORM(p) \
- }
-
-#endif
-
-
-
-
-#define RC_BIT_0_BASE(p, prob) \
- range = newBound; *(prob) = (CLzmaProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits));
-
-#define RC_BIT_1_BASE(p, prob) \
- range -= newBound; (p)->low += newBound; *(prob) = (CLzmaProb)(ttt - (ttt >> kNumMoveBits)); \
-
-#define RC_BIT_0(p, prob) \
- RC_BIT_0_BASE(p, prob) \
- RC_NORM(p)
-
-#define RC_BIT_1(p, prob) \
- RC_BIT_1_BASE(p, prob) \
- RC_NORM(p)
-
-static void RangeEnc_EncodeBit_0(CRangeEnc *p, CLzmaProb *prob)
-{
- UInt32 range, ttt, newBound;
- range = p->range;
- RC_BIT_PRE(p, prob)
- RC_BIT_0(p, prob)
- p->range = range;
-}
-
-static void LitEnc_Encode(CRangeEnc *p, CLzmaProb *probs, UInt32 sym)
-{
- UInt32 range = p->range;
- sym |= 0x100;
- do
- {
- UInt32 ttt, newBound;
- // RangeEnc_EncodeBit(p, probs + (sym >> 8), (sym >> 7) & 1);
- CLzmaProb *prob = probs + (sym >> 8);
- UInt32 bit = (sym >> 7) & 1;
- sym <<= 1;
- RC_BIT(p, prob, bit);
- }
- while (sym < 0x10000);
- p->range = range;
-}
-
-static void LitEnc_EncodeMatched(CRangeEnc *p, CLzmaProb *probs, UInt32 sym, UInt32 matchByte)
-{
- UInt32 range = p->range;
- UInt32 offs = 0x100;
- sym |= 0x100;
- do
- {
- UInt32 ttt, newBound;
- CLzmaProb *prob;
- UInt32 bit;
- matchByte <<= 1;
- // RangeEnc_EncodeBit(p, probs + (offs + (matchByte & offs) + (sym >> 8)), (sym >> 7) & 1);
- prob = probs + (offs + (matchByte & offs) + (sym >> 8));
- bit = (sym >> 7) & 1;
- sym <<= 1;
- offs &= ~(matchByte ^ sym);
- RC_BIT(p, prob, bit);
- }
- while (sym < 0x10000);
- p->range = range;
-}
-
-
-
-static void LzmaEnc_InitPriceTables(CProbPrice *ProbPrices)
-{
- UInt32 i;
- for (i = 0; i < (kBitModelTotal >> kNumMoveReducingBits); i++)
- {
- const unsigned kCyclesBits = kNumBitPriceShiftBits;
- UInt32 w = (i << kNumMoveReducingBits) + (1 << (kNumMoveReducingBits - 1));
- unsigned bitCount = 0;
- unsigned j;
- for (j = 0; j < kCyclesBits; j++)
- {
- w = w * w;
- bitCount <<= 1;
- while (w >= ((UInt32)1 << 16))
- {
- w >>= 1;
- bitCount++;
- }
- }
- ProbPrices[i] = (CProbPrice)(((unsigned)kNumBitModelTotalBits << kCyclesBits) - 15 - bitCount);
- // printf("\n%3d: %5d", i, ProbPrices[i]);
- }
-}
-
-
-#define GET_PRICE(prob, bit) \
- p->ProbPrices[((prob) ^ (unsigned)(((-(int)(bit))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits];
-
-#define GET_PRICEa(prob, bit) \
- ProbPrices[((prob) ^ (unsigned)((-((int)(bit))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits];
-
-#define GET_PRICE_0(prob) p->ProbPrices[(prob) >> kNumMoveReducingBits]
-#define GET_PRICE_1(prob) p->ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]
-
-#define GET_PRICEa_0(prob) ProbPrices[(prob) >> kNumMoveReducingBits]
-#define GET_PRICEa_1(prob) ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]
-
-
-static UInt32 LitEnc_GetPrice(const CLzmaProb *probs, UInt32 sym, const CProbPrice *ProbPrices)
-{
- UInt32 price = 0;
- sym |= 0x100;
- do
- {
- unsigned bit = sym & 1;
- sym >>= 1;
- price += GET_PRICEa(probs[sym], bit);
- }
- while (sym >= 2);
- return price;
-}
-
-
-static UInt32 LitEnc_Matched_GetPrice(const CLzmaProb *probs, UInt32 sym, UInt32 matchByte, const CProbPrice *ProbPrices)
-{
- UInt32 price = 0;
- UInt32 offs = 0x100;
- sym |= 0x100;
- do
- {
- matchByte <<= 1;
- price += GET_PRICEa(probs[offs + (matchByte & offs) + (sym >> 8)], (sym >> 7) & 1);
- sym <<= 1;
- offs &= ~(matchByte ^ sym);
- }
- while (sym < 0x10000);
- return price;
-}
-
-
-static void RcTree_ReverseEncode(CRangeEnc *rc, CLzmaProb *probs, unsigned numBits, unsigned sym)
-{
- UInt32 range = rc->range;
- unsigned m = 1;
- do
- {
- UInt32 ttt, newBound;
- unsigned bit = sym & 1;
- // RangeEnc_EncodeBit(rc, probs + m, bit);
- sym >>= 1;
- RC_BIT(rc, probs + m, bit);
- m = (m << 1) | bit;
- }
- while (--numBits);
- rc->range = range;
-}
-
-
-
-static void LenEnc_Init(CLenEnc *p)
-{
- unsigned i;
- for (i = 0; i < (LZMA_NUM_PB_STATES_MAX << (kLenNumLowBits + 1)); i++)
- p->low[i] = kProbInitValue;
- for (i = 0; i < kLenNumHighSymbols; i++)
- p->high[i] = kProbInitValue;
-}
-
-static void LenEnc_Encode(CLenEnc *p, CRangeEnc *rc, unsigned sym, unsigned posState)
-{
- UInt32 range, ttt, newBound;
- CLzmaProb *probs = p->low;
- range = rc->range;
- RC_BIT_PRE(rc, probs);
- if (sym >= kLenNumLowSymbols)
- {
- RC_BIT_1(rc, probs);
- probs += kLenNumLowSymbols;
- RC_BIT_PRE(rc, probs);
- if (sym >= kLenNumLowSymbols * 2)
- {
- RC_BIT_1(rc, probs);
- rc->range = range;
- // RcTree_Encode(rc, p->high, kLenNumHighBits, sym - kLenNumLowSymbols * 2);
- LitEnc_Encode(rc, p->high, sym - kLenNumLowSymbols * 2);
- return;
- }
- sym -= kLenNumLowSymbols;
- }
-
- // RcTree_Encode(rc, probs + (posState << kLenNumLowBits), kLenNumLowBits, sym);
- {
- unsigned m;
- unsigned bit;
- RC_BIT_0(rc, probs);
- probs += (posState << (1 + kLenNumLowBits));
- bit = (sym >> 2) ; RC_BIT(rc, probs + 1, bit); m = (1 << 1) + bit;
- bit = (sym >> 1) & 1; RC_BIT(rc, probs + m, bit); m = (m << 1) + bit;
- bit = sym & 1; RC_BIT(rc, probs + m, bit);
- rc->range = range;
- }
-}
-
-static void SetPrices_3(const CLzmaProb *probs, UInt32 startPrice, UInt32 *prices, const CProbPrice *ProbPrices)
-{
- unsigned i;
- for (i = 0; i < 8; i += 2)
- {
- UInt32 price = startPrice;
- UInt32 prob;
- price += GET_PRICEa(probs[1 ], (i >> 2));
- price += GET_PRICEa(probs[2 + (i >> 2)], (i >> 1) & 1);
- prob = probs[4 + (i >> 1)];
- prices[i ] = price + GET_PRICEa_0(prob);
- prices[i + 1] = price + GET_PRICEa_1(prob);
- }
-}
-
-
-MY_NO_INLINE static void MY_FAST_CALL LenPriceEnc_UpdateTables(
- CLenPriceEnc *p,
- unsigned numPosStates,
- const CLenEnc *enc,
- const CProbPrice *ProbPrices)
-{
- UInt32 b;
-
- {
- unsigned prob = enc->low[0];
- UInt32 a, c;
- unsigned posState;
- b = GET_PRICEa_1(prob);
- a = GET_PRICEa_0(prob);
- c = b + GET_PRICEa_0(enc->low[kLenNumLowSymbols]);
- for (posState = 0; posState < numPosStates; posState++)
- {
- UInt32 *prices = p->prices[posState];
- const CLzmaProb *probs = enc->low + (posState << (1 + kLenNumLowBits));
- SetPrices_3(probs, a, prices, ProbPrices);
- SetPrices_3(probs + kLenNumLowSymbols, c, prices + kLenNumLowSymbols, ProbPrices);
- }
- }
-
- /*
- {
- unsigned i;
- UInt32 b;
- a = GET_PRICEa_0(enc->low[0]);
- for (i = 0; i < kLenNumLowSymbols; i++)
- p->prices2[i] = a;
- a = GET_PRICEa_1(enc->low[0]);
- b = a + GET_PRICEa_0(enc->low[kLenNumLowSymbols]);
- for (i = kLenNumLowSymbols; i < kLenNumLowSymbols * 2; i++)
- p->prices2[i] = b;
- a += GET_PRICEa_1(enc->low[kLenNumLowSymbols]);
- }
- */
-
- // p->counter = numSymbols;
- // p->counter = 64;
-
- {
- unsigned i = p->tableSize;
-
- if (i > kLenNumLowSymbols * 2)
- {
- const CLzmaProb *probs = enc->high;
- UInt32 *prices = p->prices[0] + kLenNumLowSymbols * 2;
- i -= kLenNumLowSymbols * 2 - 1;
- i >>= 1;
- b += GET_PRICEa_1(enc->low[kLenNumLowSymbols]);
- do
- {
- /*
- p->prices2[i] = a +
- // RcTree_GetPrice(enc->high, kLenNumHighBits, i - kLenNumLowSymbols * 2, ProbPrices);
- LitEnc_GetPrice(probs, i - kLenNumLowSymbols * 2, ProbPrices);
- */
- // UInt32 price = a + RcTree_GetPrice(probs, kLenNumHighBits - 1, sym, ProbPrices);
- unsigned sym = --i + (1 << (kLenNumHighBits - 1));
- UInt32 price = b;
- do
- {
- unsigned bit = sym & 1;
- sym >>= 1;
- price += GET_PRICEa(probs[sym], bit);
- }
- while (sym >= 2);
-
- {
- unsigned prob = probs[(size_t)i + (1 << (kLenNumHighBits - 1))];
- prices[(size_t)i * 2 ] = price + GET_PRICEa_0(prob);
- prices[(size_t)i * 2 + 1] = price + GET_PRICEa_1(prob);
- }
- }
- while (i);
-
- {
- unsigned posState;
- size_t num = (p->tableSize - kLenNumLowSymbols * 2) * sizeof(p->prices[0][0]);
- for (posState = 1; posState < numPosStates; posState++)
- memcpy(p->prices[posState] + kLenNumLowSymbols * 2, p->prices[0] + kLenNumLowSymbols * 2, num);
- }
- }
- }
-}
-
-/*
- #ifdef SHOW_STAT
- g_STAT_OFFSET += num;
- printf("\n MovePos %u", num);
- #endif
-*/
-
-#define MOVE_POS(p, num) { \
- p->additionalOffset += (num); \
- p->matchFinder.Skip(p->matchFinderObj, (UInt32)(num)); }
-
-
-static unsigned ReadMatchDistances(CLzmaEnc *p, unsigned *numPairsRes)
-{
- unsigned numPairs;
-
- p->additionalOffset++;
- p->numAvail = p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);
- {
- const UInt32 *d = p->matchFinder.GetMatches(p->matchFinderObj, p->matches);
- // if (!d) { p->mf_Failure = True; *numPairsRes = 0; return 0; }
- numPairs = (unsigned)(d - p->matches);
- }
- *numPairsRes = numPairs;
-
- #ifdef SHOW_STAT
- printf("\n i = %u numPairs = %u ", g_STAT_OFFSET, numPairs / 2);
- g_STAT_OFFSET++;
- {
- unsigned i;
- for (i = 0; i < numPairs; i += 2)
- printf("%2u %6u | ", p->matches[i], p->matches[i + 1]);
- }
- #endif
-
- if (numPairs == 0)
- return 0;
- {
- const unsigned len = p->matches[(size_t)numPairs - 2];
- if (len != p->numFastBytes)
- return len;
- {
- UInt32 numAvail = p->numAvail;
- if (numAvail > LZMA_MATCH_LEN_MAX)
- numAvail = LZMA_MATCH_LEN_MAX;
- {
- const Byte *p1 = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
- const Byte *p2 = p1 + len;
- const ptrdiff_t dif = (ptrdiff_t)-1 - (ptrdiff_t)p->matches[(size_t)numPairs - 1];
- const Byte *lim = p1 + numAvail;
- for (; p2 != lim && *p2 == p2[dif]; p2++)
- {}
- return (unsigned)(p2 - p1);
- }
- }
- }
-}
-
-#define MARK_LIT ((UInt32)(Int32)-1)
-
-#define MakeAs_Lit(p) { (p)->dist = MARK_LIT; (p)->extra = 0; }
-#define MakeAs_ShortRep(p) { (p)->dist = 0; (p)->extra = 0; }
-#define IsShortRep(p) ((p)->dist == 0)
-
-
-#define GetPrice_ShortRep(p, state, posState) \
- ( GET_PRICE_0(p->isRepG0[state]) + GET_PRICE_0(p->isRep0Long[state][posState]))
-
-#define GetPrice_Rep_0(p, state, posState) ( \
- GET_PRICE_1(p->isMatch[state][posState]) \
- + GET_PRICE_1(p->isRep0Long[state][posState])) \
- + GET_PRICE_1(p->isRep[state]) \
- + GET_PRICE_0(p->isRepG0[state])
-
-MY_FORCE_INLINE
-static UInt32 GetPrice_PureRep(const CLzmaEnc *p, unsigned repIndex, size_t state, size_t posState)
-{
- UInt32 price;
- UInt32 prob = p->isRepG0[state];
- if (repIndex == 0)
- {
- price = GET_PRICE_0(prob);
- price += GET_PRICE_1(p->isRep0Long[state][posState]);
- }
- else
- {
- price = GET_PRICE_1(prob);
- prob = p->isRepG1[state];
- if (repIndex == 1)
- price += GET_PRICE_0(prob);
- else
- {
- price += GET_PRICE_1(prob);
- price += GET_PRICE(p->isRepG2[state], repIndex - 2);
- }
- }
- return price;
-}
-
-
-static unsigned Backward(CLzmaEnc *p, unsigned cur)
-{
- unsigned wr = cur + 1;
- p->optEnd = wr;
-
- for (;;)
- {
- UInt32 dist = p->opt[cur].dist;
- unsigned len = (unsigned)p->opt[cur].len;
- unsigned extra = (unsigned)p->opt[cur].extra;
- cur -= len;
-
- if (extra)
- {
- wr--;
- p->opt[wr].len = (UInt32)len;
- cur -= extra;
- len = extra;
- if (extra == 1)
- {
- p->opt[wr].dist = dist;
- dist = MARK_LIT;
- }
- else
- {
- p->opt[wr].dist = 0;
- len--;
- wr--;
- p->opt[wr].dist = MARK_LIT;
- p->opt[wr].len = 1;
- }
- }
-
- if (cur == 0)
- {
- p->backRes = dist;
- p->optCur = wr;
- return len;
- }
-
- wr--;
- p->opt[wr].dist = dist;
- p->opt[wr].len = (UInt32)len;
- }
-}
-
-
-
-#define LIT_PROBS(pos, prevByte) \
- (p->litProbs + (UInt32)3 * (((((pos) << 8) + (prevByte)) & p->lpMask) << p->lc))
-
-
-static unsigned GetOptimum(CLzmaEnc *p, UInt32 position)
-{
- unsigned last, cur;
- UInt32 reps[LZMA_NUM_REPS];
- unsigned repLens[LZMA_NUM_REPS];
- UInt32 *matches;
-
- {
- UInt32 numAvail;
- unsigned numPairs, mainLen, repMaxIndex, i, posState;
- UInt32 matchPrice, repMatchPrice;
- const Byte *data;
- Byte curByte, matchByte;
-
- p->optCur = p->optEnd = 0;
-
- if (p->additionalOffset == 0)
- mainLen = ReadMatchDistances(p, &numPairs);
- else
- {
- mainLen = p->longestMatchLen;
- numPairs = p->numPairs;
- }
-
- numAvail = p->numAvail;
- if (numAvail < 2)
- {
- p->backRes = MARK_LIT;
- return 1;
- }
- if (numAvail > LZMA_MATCH_LEN_MAX)
- numAvail = LZMA_MATCH_LEN_MAX;
-
- data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
- repMaxIndex = 0;
-
- for (i = 0; i < LZMA_NUM_REPS; i++)
- {
- unsigned len;
- const Byte *data2;
- reps[i] = p->reps[i];
- data2 = data - reps[i];
- if (data[0] != data2[0] || data[1] != data2[1])
- {
- repLens[i] = 0;
- continue;
- }
- for (len = 2; len < numAvail && data[len] == data2[len]; len++)
- {}
- repLens[i] = len;
- if (len > repLens[repMaxIndex])
- repMaxIndex = i;
- if (len == LZMA_MATCH_LEN_MAX) // 21.03 : optimization
- break;
- }
-
- if (repLens[repMaxIndex] >= p->numFastBytes)
- {
- unsigned len;
- p->backRes = (UInt32)repMaxIndex;
- len = repLens[repMaxIndex];
- MOVE_POS(p, len - 1)
- return len;
- }
-
- matches = p->matches;
- #define MATCHES matches
- // #define MATCHES p->matches
-
- if (mainLen >= p->numFastBytes)
- {
- p->backRes = MATCHES[(size_t)numPairs - 1] + LZMA_NUM_REPS;
- MOVE_POS(p, mainLen - 1)
- return mainLen;
- }
-
- curByte = *data;
- matchByte = *(data - reps[0]);
-
- last = repLens[repMaxIndex];
- if (last <= mainLen)
- last = mainLen;
-
- if (last < 2 && curByte != matchByte)
- {
- p->backRes = MARK_LIT;
- return 1;
- }
-
- p->opt[0].state = (CState)p->state;
-
- posState = (position & p->pbMask);
-
- {
- const CLzmaProb *probs = LIT_PROBS(position, *(data - 1));
- p->opt[1].price = GET_PRICE_0(p->isMatch[p->state][posState]) +
- (!IsLitState(p->state) ?
- LitEnc_Matched_GetPrice(probs, curByte, matchByte, p->ProbPrices) :
- LitEnc_GetPrice(probs, curByte, p->ProbPrices));
- }
-
- MakeAs_Lit(&p->opt[1]);
-
- matchPrice = GET_PRICE_1(p->isMatch[p->state][posState]);
- repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[p->state]);
-
- // 18.06
- if (matchByte == curByte && repLens[0] == 0)
- {
- UInt32 shortRepPrice = repMatchPrice + GetPrice_ShortRep(p, p->state, posState);
- if (shortRepPrice < p->opt[1].price)
- {
- p->opt[1].price = shortRepPrice;
- MakeAs_ShortRep(&p->opt[1]);
- }
- if (last < 2)
- {
- p->backRes = p->opt[1].dist;
- return 1;
- }
- }
-
- p->opt[1].len = 1;
-
- p->opt[0].reps[0] = reps[0];
- p->opt[0].reps[1] = reps[1];
- p->opt[0].reps[2] = reps[2];
- p->opt[0].reps[3] = reps[3];
-
- // ---------- REP ----------
-
- for (i = 0; i < LZMA_NUM_REPS; i++)
- {
- unsigned repLen = repLens[i];
- UInt32 price;
- if (repLen < 2)
- continue;
- price = repMatchPrice + GetPrice_PureRep(p, i, p->state, posState);
- do
- {
- UInt32 price2 = price + GET_PRICE_LEN(&p->repLenEnc, posState, repLen);
- COptimal *opt = &p->opt[repLen];
- if (price2 < opt->price)
- {
- opt->price = price2;
- opt->len = (UInt32)repLen;
- opt->dist = (UInt32)i;
- opt->extra = 0;
- }
- }
- while (--repLen >= 2);
- }
-
-
- // ---------- MATCH ----------
- {
- unsigned len = repLens[0] + 1;
- if (len <= mainLen)
- {
- unsigned offs = 0;
- UInt32 normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[p->state]);
-
- if (len < 2)
- len = 2;
- else
- while (len > MATCHES[offs])
- offs += 2;
-
- for (; ; len++)
- {
- COptimal *opt;
- UInt32 dist = MATCHES[(size_t)offs + 1];
- UInt32 price = normalMatchPrice + GET_PRICE_LEN(&p->lenEnc, posState, len);
- unsigned lenToPosState = GetLenToPosState(len);
-
- if (dist < kNumFullDistances)
- price += p->distancesPrices[lenToPosState][dist & (kNumFullDistances - 1)];
- else
- {
- unsigned slot;
- GetPosSlot2(dist, slot);
- price += p->alignPrices[dist & kAlignMask];
- price += p->posSlotPrices[lenToPosState][slot];
- }
-
- opt = &p->opt[len];
-
- if (price < opt->price)
- {
- opt->price = price;
- opt->len = (UInt32)len;
- opt->dist = dist + LZMA_NUM_REPS;
- opt->extra = 0;
- }
-
- if (len == MATCHES[offs])
- {
- offs += 2;
- if (offs == numPairs)
- break;
- }
- }
- }
- }
-
-
- cur = 0;
-
- #ifdef SHOW_STAT2
- /* if (position >= 0) */
- {
- unsigned i;
- printf("\n pos = %4X", position);
- for (i = cur; i <= last; i++)
- printf("\nprice[%4X] = %u", position - cur + i, p->opt[i].price);
- }
- #endif
- }
-
-
-
- // ---------- Optimal Parsing ----------
-
- for (;;)
- {
- unsigned numAvail;
- UInt32 numAvailFull;
- unsigned newLen, numPairs, prev, state, posState, startLen;
- UInt32 litPrice, matchPrice, repMatchPrice;
- BoolInt nextIsLit;
- Byte curByte, matchByte;
- const Byte *data;
- COptimal *curOpt, *nextOpt;
-
- if (++cur == last)
- break;
-
- // 18.06
- if (cur >= kNumOpts - 64)
- {
- unsigned j, best;
- UInt32 price = p->opt[cur].price;
- best = cur;
- for (j = cur + 1; j <= last; j++)
- {
- UInt32 price2 = p->opt[j].price;
- if (price >= price2)
- {
- price = price2;
- best = j;
- }
- }
- {
- unsigned delta = best - cur;
- if (delta != 0)
- {
- MOVE_POS(p, delta);
- }
- }
- cur = best;
- break;
- }
-
- newLen = ReadMatchDistances(p, &numPairs);
-
- if (newLen >= p->numFastBytes)
- {
- p->numPairs = numPairs;
- p->longestMatchLen = newLen;
- break;
- }
-
- curOpt = &p->opt[cur];
-
- position++;
-
- // we need that check here, if skip_items in p->opt are possible
- /*
- if (curOpt->price >= kInfinityPrice)
- continue;
- */
-
- prev = cur - curOpt->len;
-
- if (curOpt->len == 1)
- {
- state = (unsigned)p->opt[prev].state;
- if (IsShortRep(curOpt))
- state = kShortRepNextStates[state];
- else
- state = kLiteralNextStates[state];
- }
- else
- {
- const COptimal *prevOpt;
- UInt32 b0;
- UInt32 dist = curOpt->dist;
-
- if (curOpt->extra)
- {
- prev -= (unsigned)curOpt->extra;
- state = kState_RepAfterLit;
- if (curOpt->extra == 1)
- state = (dist < LZMA_NUM_REPS ? kState_RepAfterLit : kState_MatchAfterLit);
- }
- else
- {
- state = (unsigned)p->opt[prev].state;
- if (dist < LZMA_NUM_REPS)
- state = kRepNextStates[state];
- else
- state = kMatchNextStates[state];
- }
-
- prevOpt = &p->opt[prev];
- b0 = prevOpt->reps[0];
-
- if (dist < LZMA_NUM_REPS)
- {
- if (dist == 0)
- {
- reps[0] = b0;
- reps[1] = prevOpt->reps[1];
- reps[2] = prevOpt->reps[2];
- reps[3] = prevOpt->reps[3];
- }
- else
- {
- reps[1] = b0;
- b0 = prevOpt->reps[1];
- if (dist == 1)
- {
- reps[0] = b0;
- reps[2] = prevOpt->reps[2];
- reps[3] = prevOpt->reps[3];
- }
- else
- {
- reps[2] = b0;
- reps[0] = prevOpt->reps[dist];
- reps[3] = prevOpt->reps[dist ^ 1];
- }
- }
- }
- else
- {
- reps[0] = (dist - LZMA_NUM_REPS + 1);
- reps[1] = b0;
- reps[2] = prevOpt->reps[1];
- reps[3] = prevOpt->reps[2];
- }
- }
-
- curOpt->state = (CState)state;
- curOpt->reps[0] = reps[0];
- curOpt->reps[1] = reps[1];
- curOpt->reps[2] = reps[2];
- curOpt->reps[3] = reps[3];
-
- data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
- curByte = *data;
- matchByte = *(data - reps[0]);
-
- posState = (position & p->pbMask);
-
- /*
- The order of Price checks:
- < LIT
- <= SHORT_REP
- < LIT : REP_0
- < REP [ : LIT : REP_0 ]
- < MATCH [ : LIT : REP_0 ]
- */
-
- {
- UInt32 curPrice = curOpt->price;
- unsigned prob = p->isMatch[state][posState];
- matchPrice = curPrice + GET_PRICE_1(prob);
- litPrice = curPrice + GET_PRICE_0(prob);
- }
-
- nextOpt = &p->opt[(size_t)cur + 1];
- nextIsLit = False;
-
- // here we can allow skip_items in p->opt, if we don't check (nextOpt->price < kInfinityPrice)
- // 18.new.06
- if ((nextOpt->price < kInfinityPrice
- // && !IsLitState(state)
- && matchByte == curByte)
- || litPrice > nextOpt->price
- )
- litPrice = 0;
- else
- {
- const CLzmaProb *probs = LIT_PROBS(position, *(data - 1));
- litPrice += (!IsLitState(state) ?
- LitEnc_Matched_GetPrice(probs, curByte, matchByte, p->ProbPrices) :
- LitEnc_GetPrice(probs, curByte, p->ProbPrices));
-
- if (litPrice < nextOpt->price)
- {
- nextOpt->price = litPrice;
- nextOpt->len = 1;
- MakeAs_Lit(nextOpt);
- nextIsLit = True;
- }
- }
-
- repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[state]);
-
- numAvailFull = p->numAvail;
- {
- unsigned temp = kNumOpts - 1 - cur;
- if (numAvailFull > temp)
- numAvailFull = (UInt32)temp;
- }
-
- // 18.06
- // ---------- SHORT_REP ----------
- if (IsLitState(state)) // 18.new
- if (matchByte == curByte)
- if (repMatchPrice < nextOpt->price) // 18.new
- // if (numAvailFull < 2 || data[1] != *(data - reps[0] + 1))
- if (
- // nextOpt->price >= kInfinityPrice ||
- nextOpt->len < 2 // we can check nextOpt->len, if skip items are not allowed in p->opt
- || (nextOpt->dist != 0
- // && nextOpt->extra <= 1 // 17.old
- )
- )
- {
- UInt32 shortRepPrice = repMatchPrice + GetPrice_ShortRep(p, state, posState);
- // if (shortRepPrice <= nextOpt->price) // 17.old
- if (shortRepPrice < nextOpt->price) // 18.new
- {
- nextOpt->price = shortRepPrice;
- nextOpt->len = 1;
- MakeAs_ShortRep(nextOpt);
- nextIsLit = False;
- }
- }
-
- if (numAvailFull < 2)
- continue;
- numAvail = (numAvailFull <= p->numFastBytes ? numAvailFull : p->numFastBytes);
-
- // numAvail <= p->numFastBytes
-
- // ---------- LIT : REP_0 ----------
-
- if (!nextIsLit
- && litPrice != 0 // 18.new
- && matchByte != curByte
- && numAvailFull > 2)
- {
- const Byte *data2 = data - reps[0];
- if (data[1] == data2[1] && data[2] == data2[2])
- {
- unsigned len;
- unsigned limit = p->numFastBytes + 1;
- if (limit > numAvailFull)
- limit = numAvailFull;
- for (len = 3; len < limit && data[len] == data2[len]; len++)
- {}
-
- {
- unsigned state2 = kLiteralNextStates[state];
- unsigned posState2 = (position + 1) & p->pbMask;
- UInt32 price = litPrice + GetPrice_Rep_0(p, state2, posState2);
- {
- unsigned offset = cur + len;
-
- if (last < offset)
- last = offset;
-
- // do
- {
- UInt32 price2;
- COptimal *opt;
- len--;
- // price2 = price + GetPrice_Len_Rep_0(p, len, state2, posState2);
- price2 = price + GET_PRICE_LEN(&p->repLenEnc, posState2, len);
-
- opt = &p->opt[offset];
- // offset--;
- if (price2 < opt->price)
- {
- opt->price = price2;
- opt->len = (UInt32)len;
- opt->dist = 0;
- opt->extra = 1;
- }
- }
- // while (len >= 3);
- }
- }
- }
- }
-
- startLen = 2; /* speed optimization */
-
- {
- // ---------- REP ----------
- unsigned repIndex = 0; // 17.old
- // unsigned repIndex = IsLitState(state) ? 0 : 1; // 18.notused
- for (; repIndex < LZMA_NUM_REPS; repIndex++)
- {
- unsigned len;
- UInt32 price;
- const Byte *data2 = data - reps[repIndex];
- if (data[0] != data2[0] || data[1] != data2[1])
- continue;
-
- for (len = 2; len < numAvail && data[len] == data2[len]; len++)
- {}
-
- // if (len < startLen) continue; // 18.new: speed optimization
-
- {
- unsigned offset = cur + len;
- if (last < offset)
- last = offset;
- }
- {
- unsigned len2 = len;
- price = repMatchPrice + GetPrice_PureRep(p, repIndex, state, posState);
- do
- {
- UInt32 price2 = price + GET_PRICE_LEN(&p->repLenEnc, posState, len2);
- COptimal *opt = &p->opt[cur + len2];
- if (price2 < opt->price)
- {
- opt->price = price2;
- opt->len = (UInt32)len2;
- opt->dist = (UInt32)repIndex;
- opt->extra = 0;
- }
- }
- while (--len2 >= 2);
- }
-
- if (repIndex == 0) startLen = len + 1; // 17.old
- // startLen = len + 1; // 18.new
-
- /* if (_maxMode) */
- {
- // ---------- REP : LIT : REP_0 ----------
- // numFastBytes + 1 + numFastBytes
-
- unsigned len2 = len + 1;
- unsigned limit = len2 + p->numFastBytes;
- if (limit > numAvailFull)
- limit = numAvailFull;
-
- len2 += 2;
- if (len2 <= limit)
- if (data[len2 - 2] == data2[len2 - 2])
- if (data[len2 - 1] == data2[len2 - 1])
- {
- unsigned state2 = kRepNextStates[state];
- unsigned posState2 = (position + len) & p->pbMask;
- price += GET_PRICE_LEN(&p->repLenEnc, posState, len)
- + GET_PRICE_0(p->isMatch[state2][posState2])
- + LitEnc_Matched_GetPrice(LIT_PROBS(position + len, data[(size_t)len - 1]),
- data[len], data2[len], p->ProbPrices);
-
- // state2 = kLiteralNextStates[state2];
- state2 = kState_LitAfterRep;
- posState2 = (posState2 + 1) & p->pbMask;
-
-
- price += GetPrice_Rep_0(p, state2, posState2);
-
- for (; len2 < limit && data[len2] == data2[len2]; len2++)
- {}
-
- len2 -= len;
- // if (len2 >= 3)
- {
- {
- unsigned offset = cur + len + len2;
-
- if (last < offset)
- last = offset;
- // do
- {
- UInt32 price2;
- COptimal *opt;
- len2--;
- // price2 = price + GetPrice_Len_Rep_0(p, len2, state2, posState2);
- price2 = price + GET_PRICE_LEN(&p->repLenEnc, posState2, len2);
-
- opt = &p->opt[offset];
- // offset--;
- if (price2 < opt->price)
- {
- opt->price = price2;
- opt->len = (UInt32)len2;
- opt->extra = (CExtra)(len + 1);
- opt->dist = (UInt32)repIndex;
- }
- }
- // while (len2 >= 3);
- }
- }
- }
- }
- }
- }
-
-
- // ---------- MATCH ----------
- /* for (unsigned len = 2; len <= newLen; len++) */
- if (newLen > numAvail)
- {
- newLen = numAvail;
- for (numPairs = 0; newLen > MATCHES[numPairs]; numPairs += 2);
- MATCHES[numPairs] = (UInt32)newLen;
- numPairs += 2;
- }
-
- // startLen = 2; /* speed optimization */
-
- if (newLen >= startLen)
- {
- UInt32 normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[state]);
- UInt32 dist;
- unsigned offs, posSlot, len;
-
- {
- unsigned offset = cur + newLen;
- if (last < offset)
- last = offset;
- }
-
- offs = 0;
- while (startLen > MATCHES[offs])
- offs += 2;
- dist = MATCHES[(size_t)offs + 1];
-
- // if (dist >= kNumFullDistances)
- GetPosSlot2(dist, posSlot);
-
- for (len = /*2*/ startLen; ; len++)
- {
- UInt32 price = normalMatchPrice + GET_PRICE_LEN(&p->lenEnc, posState, len);
- {
- COptimal *opt;
- unsigned lenNorm = len - 2;
- lenNorm = GetLenToPosState2(lenNorm);
- if (dist < kNumFullDistances)
- price += p->distancesPrices[lenNorm][dist & (kNumFullDistances - 1)];
- else
- price += p->posSlotPrices[lenNorm][posSlot] + p->alignPrices[dist & kAlignMask];
-
- opt = &p->opt[cur + len];
- if (price < opt->price)
- {
- opt->price = price;
- opt->len = (UInt32)len;
- opt->dist = dist + LZMA_NUM_REPS;
- opt->extra = 0;
- }
- }
-
- if (len == MATCHES[offs])
- {
- // if (p->_maxMode) {
- // MATCH : LIT : REP_0
-
- const Byte *data2 = data - dist - 1;
- unsigned len2 = len + 1;
- unsigned limit = len2 + p->numFastBytes;
- if (limit > numAvailFull)
- limit = numAvailFull;
-
- len2 += 2;
- if (len2 <= limit)
- if (data[len2 - 2] == data2[len2 - 2])
- if (data[len2 - 1] == data2[len2 - 1])
- {
- for (; len2 < limit && data[len2] == data2[len2]; len2++)
- {}
-
- len2 -= len;
-
- // if (len2 >= 3)
- {
- unsigned state2 = kMatchNextStates[state];
- unsigned posState2 = (position + len) & p->pbMask;
- unsigned offset;
- price += GET_PRICE_0(p->isMatch[state2][posState2]);
- price += LitEnc_Matched_GetPrice(LIT_PROBS(position + len, data[(size_t)len - 1]),
- data[len], data2[len], p->ProbPrices);
-
- // state2 = kLiteralNextStates[state2];
- state2 = kState_LitAfterMatch;
-
- posState2 = (posState2 + 1) & p->pbMask;
- price += GetPrice_Rep_0(p, state2, posState2);
-
- offset = cur + len + len2;
-
- if (last < offset)
- last = offset;
- // do
- {
- UInt32 price2;
- COptimal *opt;
- len2--;
- // price2 = price + GetPrice_Len_Rep_0(p, len2, state2, posState2);
- price2 = price + GET_PRICE_LEN(&p->repLenEnc, posState2, len2);
- opt = &p->opt[offset];
- // offset--;
- if (price2 < opt->price)
- {
- opt->price = price2;
- opt->len = (UInt32)len2;
- opt->extra = (CExtra)(len + 1);
- opt->dist = dist + LZMA_NUM_REPS;
- }
- }
- // while (len2 >= 3);
- }
-
- }
-
- offs += 2;
- if (offs == numPairs)
- break;
- dist = MATCHES[(size_t)offs + 1];
- // if (dist >= kNumFullDistances)
- GetPosSlot2(dist, posSlot);
- }
- }
- }
- }
-
- do
- p->opt[last].price = kInfinityPrice;
- while (--last);
-
- return Backward(p, cur);
-}
-
-
-
-#define ChangePair(smallDist, bigDist) (((bigDist) >> 7) > (smallDist))
-
-
-
-static unsigned GetOptimumFast(CLzmaEnc *p)
-{
- UInt32 numAvail, mainDist;
- unsigned mainLen, numPairs, repIndex, repLen, i;
- const Byte *data;
-
- if (p->additionalOffset == 0)
- mainLen = ReadMatchDistances(p, &numPairs);
- else
- {
- mainLen = p->longestMatchLen;
- numPairs = p->numPairs;
- }
-
- numAvail = p->numAvail;
- p->backRes = MARK_LIT;
- if (numAvail < 2)
- return 1;
- // if (mainLen < 2 && p->state == 0) return 1; // 18.06.notused
- if (numAvail > LZMA_MATCH_LEN_MAX)
- numAvail = LZMA_MATCH_LEN_MAX;
- data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
- repLen = repIndex = 0;
-
- for (i = 0; i < LZMA_NUM_REPS; i++)
- {
- unsigned len;
- const Byte *data2 = data - p->reps[i];
- if (data[0] != data2[0] || data[1] != data2[1])
- continue;
- for (len = 2; len < numAvail && data[len] == data2[len]; len++)
- {}
- if (len >= p->numFastBytes)
- {
- p->backRes = (UInt32)i;
- MOVE_POS(p, len - 1)
- return len;
- }
- if (len > repLen)
- {
- repIndex = i;
- repLen = len;
- }
- }
-
- if (mainLen >= p->numFastBytes)
- {
- p->backRes = p->matches[(size_t)numPairs - 1] + LZMA_NUM_REPS;
- MOVE_POS(p, mainLen - 1)
- return mainLen;
- }
-
- mainDist = 0; /* for GCC */
-
- if (mainLen >= 2)
- {
- mainDist = p->matches[(size_t)numPairs - 1];
- while (numPairs > 2)
- {
- UInt32 dist2;
- if (mainLen != p->matches[(size_t)numPairs - 4] + 1)
- break;
- dist2 = p->matches[(size_t)numPairs - 3];
- if (!ChangePair(dist2, mainDist))
- break;
- numPairs -= 2;
- mainLen--;
- mainDist = dist2;
- }
- if (mainLen == 2 && mainDist >= 0x80)
- mainLen = 1;
- }
-
- if (repLen >= 2)
- if ( repLen + 1 >= mainLen
- || (repLen + 2 >= mainLen && mainDist >= (1 << 9))
- || (repLen + 3 >= mainLen && mainDist >= (1 << 15)))
- {
- p->backRes = (UInt32)repIndex;
- MOVE_POS(p, repLen - 1)
- return repLen;
- }
-
- if (mainLen < 2 || numAvail <= 2)
- return 1;
-
- {
- unsigned len1 = ReadMatchDistances(p, &p->numPairs);
- p->longestMatchLen = len1;
-
- if (len1 >= 2)
- {
- UInt32 newDist = p->matches[(size_t)p->numPairs - 1];
- if ( (len1 >= mainLen && newDist < mainDist)
- || (len1 == mainLen + 1 && !ChangePair(mainDist, newDist))
- || (len1 > mainLen + 1)
- || (len1 + 1 >= mainLen && mainLen >= 3 && ChangePair(newDist, mainDist)))
- return 1;
- }
- }
-
- data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
-
- for (i = 0; i < LZMA_NUM_REPS; i++)
- {
- unsigned len, limit;
- const Byte *data2 = data - p->reps[i];
- if (data[0] != data2[0] || data[1] != data2[1])
- continue;
- limit = mainLen - 1;
- for (len = 2;; len++)
- {
- if (len >= limit)
- return 1;
- if (data[len] != data2[len])
- break;
- }
- }
-
- p->backRes = mainDist + LZMA_NUM_REPS;
- if (mainLen != 2)
- {
- MOVE_POS(p, mainLen - 2)
- }
- return mainLen;
-}
-
-
-
-
-static void WriteEndMarker(CLzmaEnc *p, unsigned posState)
-{
- UInt32 range;
- range = p->rc.range;
- {
- UInt32 ttt, newBound;
- CLzmaProb *prob = &p->isMatch[p->state][posState];
- RC_BIT_PRE(&p->rc, prob)
- RC_BIT_1(&p->rc, prob)
- prob = &p->isRep[p->state];
- RC_BIT_PRE(&p->rc, prob)
- RC_BIT_0(&p->rc, prob)
- }
- p->state = kMatchNextStates[p->state];
-
- p->rc.range = range;
- LenEnc_Encode(&p->lenProbs, &p->rc, 0, posState);
- range = p->rc.range;
-
- {
- // RcTree_Encode_PosSlot(&p->rc, p->posSlotEncoder[0], (1 << kNumPosSlotBits) - 1);
- CLzmaProb *probs = p->posSlotEncoder[0];
- unsigned m = 1;
- do
- {
- UInt32 ttt, newBound;
- RC_BIT_PRE(p, probs + m)
- RC_BIT_1(&p->rc, probs + m);
- m = (m << 1) + 1;
- }
- while (m < (1 << kNumPosSlotBits));
- }
- {
- // RangeEnc_EncodeDirectBits(&p->rc, ((UInt32)1 << (30 - kNumAlignBits)) - 1, 30 - kNumAlignBits); UInt32 range = p->range;
- unsigned numBits = 30 - kNumAlignBits;
- do
- {
- range >>= 1;
- p->rc.low += range;
- RC_NORM(&p->rc)
- }
- while (--numBits);
- }
-
- {
- // RcTree_ReverseEncode(&p->rc, p->posAlignEncoder, kNumAlignBits, kAlignMask);
- CLzmaProb *probs = p->posAlignEncoder;
- unsigned m = 1;
- do
- {
- UInt32 ttt, newBound;
- RC_BIT_PRE(p, probs + m)
- RC_BIT_1(&p->rc, probs + m);
- m = (m << 1) + 1;
- }
- while (m < kAlignTableSize);
- }
- p->rc.range = range;
-}
-
-
-static SRes CheckErrors(CLzmaEnc *p)
-{
- if (p->result != SZ_OK)
- return p->result;
- if (p->rc.res != SZ_OK)
- p->result = SZ_ERROR_WRITE;
-
- #ifndef _7ZIP_ST
- if (
- // p->mf_Failure ||
- (p->mtMode &&
- ( // p->matchFinderMt.failure_LZ_LZ ||
- p->matchFinderMt.failure_LZ_BT))
- )
- {
- p->result = MY_HRES_ERROR__INTERNAL_ERROR;
- // printf("\nCheckErrors p->matchFinderMt.failureLZ\n");
- }
- #endif
-
- if (MFB.result != SZ_OK)
- p->result = SZ_ERROR_READ;
-
- if (p->result != SZ_OK)
- p->finished = True;
- return p->result;
-}
-
-
-MY_NO_INLINE static SRes Flush(CLzmaEnc *p, UInt32 nowPos)
-{
- /* ReleaseMFStream(); */
- p->finished = True;
- if (p->writeEndMark)
- WriteEndMarker(p, nowPos & p->pbMask);
- RangeEnc_FlushData(&p->rc);
- RangeEnc_FlushStream(&p->rc);
- return CheckErrors(p);
-}
-
-
-MY_NO_INLINE static void FillAlignPrices(CLzmaEnc *p)
-{
- unsigned i;
- const CProbPrice *ProbPrices = p->ProbPrices;
- const CLzmaProb *probs = p->posAlignEncoder;
- // p->alignPriceCount = 0;
- for (i = 0; i < kAlignTableSize / 2; i++)
- {
- UInt32 price = 0;
- unsigned sym = i;
- unsigned m = 1;
- unsigned bit;
- UInt32 prob;
- bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[m], bit); m = (m << 1) + bit;
- bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[m], bit); m = (m << 1) + bit;
- bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[m], bit); m = (m << 1) + bit;
- prob = probs[m];
- p->alignPrices[i ] = price + GET_PRICEa_0(prob);
- p->alignPrices[i + 8] = price + GET_PRICEa_1(prob);
- // p->alignPrices[i] = RcTree_ReverseGetPrice(p->posAlignEncoder, kNumAlignBits, i, p->ProbPrices);
- }
-}
-
-
-MY_NO_INLINE static void FillDistancesPrices(CLzmaEnc *p)
-{
- // int y; for (y = 0; y < 100; y++) {
-
- UInt32 tempPrices[kNumFullDistances];
- unsigned i, lps;
-
- const CProbPrice *ProbPrices = p->ProbPrices;
- p->matchPriceCount = 0;
-
- for (i = kStartPosModelIndex / 2; i < kNumFullDistances / 2; i++)
- {
- unsigned posSlot = GetPosSlot1(i);
- unsigned footerBits = (posSlot >> 1) - 1;
- unsigned base = ((2 | (posSlot & 1)) << footerBits);
- const CLzmaProb *probs = p->posEncoders + (size_t)base * 2;
- // tempPrices[i] = RcTree_ReverseGetPrice(p->posEncoders + base, footerBits, i - base, p->ProbPrices);
- UInt32 price = 0;
- unsigned m = 1;
- unsigned sym = i;
- unsigned offset = (unsigned)1 << footerBits;
- base += i;
-
- if (footerBits)
- do
- {
- unsigned bit = sym & 1;
- sym >>= 1;
- price += GET_PRICEa(probs[m], bit);
- m = (m << 1) + bit;
- }
- while (--footerBits);
-
- {
- unsigned prob = probs[m];
- tempPrices[base ] = price + GET_PRICEa_0(prob);
- tempPrices[base + offset] = price + GET_PRICEa_1(prob);
- }
- }
-
- for (lps = 0; lps < kNumLenToPosStates; lps++)
- {
- unsigned slot;
- unsigned distTableSize2 = (p->distTableSize + 1) >> 1;
- UInt32 *posSlotPrices = p->posSlotPrices[lps];
- const CLzmaProb *probs = p->posSlotEncoder[lps];
-
- for (slot = 0; slot < distTableSize2; slot++)
- {
- // posSlotPrices[slot] = RcTree_GetPrice(encoder, kNumPosSlotBits, slot, p->ProbPrices);
- UInt32 price;
- unsigned bit;
- unsigned sym = slot + (1 << (kNumPosSlotBits - 1));
- unsigned prob;
- bit = sym & 1; sym >>= 1; price = GET_PRICEa(probs[sym], bit);
- bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[sym], bit);
- bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[sym], bit);
- bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[sym], bit);
- bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[sym], bit);
- prob = probs[(size_t)slot + (1 << (kNumPosSlotBits - 1))];
- posSlotPrices[(size_t)slot * 2 ] = price + GET_PRICEa_0(prob);
- posSlotPrices[(size_t)slot * 2 + 1] = price + GET_PRICEa_1(prob);
- }
-
- {
- UInt32 delta = ((UInt32)((kEndPosModelIndex / 2 - 1) - kNumAlignBits) << kNumBitPriceShiftBits);
- for (slot = kEndPosModelIndex / 2; slot < distTableSize2; slot++)
- {
- posSlotPrices[(size_t)slot * 2 ] += delta;
- posSlotPrices[(size_t)slot * 2 + 1] += delta;
- delta += ((UInt32)1 << kNumBitPriceShiftBits);
- }
- }
-
- {
- UInt32 *dp = p->distancesPrices[lps];
-
- dp[0] = posSlotPrices[0];
- dp[1] = posSlotPrices[1];
- dp[2] = posSlotPrices[2];
- dp[3] = posSlotPrices[3];
-
- for (i = 4; i < kNumFullDistances; i += 2)
- {
- UInt32 slotPrice = posSlotPrices[GetPosSlot1(i)];
- dp[i ] = slotPrice + tempPrices[i];
- dp[i + 1] = slotPrice + tempPrices[i + 1];
- }
- }
- }
- // }
-}
-
-
-
-static void LzmaEnc_Construct(CLzmaEnc *p)
-{
- RangeEnc_Construct(&p->rc);
- MatchFinder_Construct(&MFB);
-
- #ifndef _7ZIP_ST
- p->matchFinderMt.MatchFinder = &MFB;
- MatchFinderMt_Construct(&p->matchFinderMt);
- #endif
-
- {
- CLzmaEncProps props;
- LzmaEncProps_Init(&props);
- LzmaEnc_SetProps(p, &props);
- }
-
- #ifndef LZMA_LOG_BSR
- LzmaEnc_FastPosInit(p->g_FastPos);
- #endif
-
- LzmaEnc_InitPriceTables(p->ProbPrices);
- p->litProbs = NULL;
- p->saveState.litProbs = NULL;
-}
-
-CLzmaEncHandle LzmaEnc_Create(ISzAllocPtr alloc)
-{
- void *p;
- p = ISzAlloc_Alloc(alloc, sizeof(CLzmaEnc));
- if (p)
- LzmaEnc_Construct((CLzmaEnc *)p);
- return p;
-}
-
-static void LzmaEnc_FreeLits(CLzmaEnc *p, ISzAllocPtr alloc)
-{
- ISzAlloc_Free(alloc, p->litProbs);
- ISzAlloc_Free(alloc, p->saveState.litProbs);
- p->litProbs = NULL;
- p->saveState.litProbs = NULL;
-}
-
-static void LzmaEnc_Destruct(CLzmaEnc *p, ISzAllocPtr alloc, ISzAllocPtr allocBig)
-{
- #ifndef _7ZIP_ST
- MatchFinderMt_Destruct(&p->matchFinderMt, allocBig);
- #endif
-
- MatchFinder_Free(&MFB, allocBig);
- LzmaEnc_FreeLits(p, alloc);
- RangeEnc_Free(&p->rc, alloc);
-}
-
-void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAllocPtr alloc, ISzAllocPtr allocBig)
-{
- LzmaEnc_Destruct((CLzmaEnc *)p, alloc, allocBig);
- ISzAlloc_Free(alloc, p);
-}
-
-
-MY_NO_INLINE
-static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, UInt32 maxPackSize, UInt32 maxUnpackSize)
-{
- UInt32 nowPos32, startPos32;
- if (p->needInit)
- {
- #ifndef _7ZIP_ST
- if (p->mtMode)
- {
- RINOK(MatchFinderMt_InitMt(&p->matchFinderMt));
- }
- #endif
- p->matchFinder.Init(p->matchFinderObj);
- p->needInit = 0;
- }
-
- if (p->finished)
- return p->result;
- RINOK(CheckErrors(p));
-
- nowPos32 = (UInt32)p->nowPos64;
- startPos32 = nowPos32;
-
- if (p->nowPos64 == 0)
- {
- unsigned numPairs;
- Byte curByte;
- if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0)
- return Flush(p, nowPos32);
- ReadMatchDistances(p, &numPairs);
- RangeEnc_EncodeBit_0(&p->rc, &p->isMatch[kState_Start][0]);
- // p->state = kLiteralNextStates[p->state];
- curByte = *(p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset);
- LitEnc_Encode(&p->rc, p->litProbs, curByte);
- p->additionalOffset--;
- nowPos32++;
- }
-
- if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) != 0)
-
- for (;;)
- {
- UInt32 dist;
- unsigned len, posState;
- UInt32 range, ttt, newBound;
- CLzmaProb *probs;
-
- if (p->fastMode)
- len = GetOptimumFast(p);
- else
- {
- unsigned oci = p->optCur;
- if (p->optEnd == oci)
- len = GetOptimum(p, nowPos32);
- else
- {
- const COptimal *opt = &p->opt[oci];
- len = opt->len;
- p->backRes = opt->dist;
- p->optCur = oci + 1;
- }
- }
-
- posState = (unsigned)nowPos32 & p->pbMask;
- range = p->rc.range;
- probs = &p->isMatch[p->state][posState];
-
- RC_BIT_PRE(&p->rc, probs)
-
- dist = p->backRes;
-
- #ifdef SHOW_STAT2
- printf("\n pos = %6X, len = %3u pos = %6u", nowPos32, len, dist);
- #endif
-
- if (dist == MARK_LIT)
- {
- Byte curByte;
- const Byte *data;
- unsigned state;
-
- RC_BIT_0(&p->rc, probs);
- p->rc.range = range;
- data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;
- probs = LIT_PROBS(nowPos32, *(data - 1));
- curByte = *data;
- state = p->state;
- p->state = kLiteralNextStates[state];
- if (IsLitState(state))
- LitEnc_Encode(&p->rc, probs, curByte);
- else
- LitEnc_EncodeMatched(&p->rc, probs, curByte, *(data - p->reps[0]));
- }
- else
- {
- RC_BIT_1(&p->rc, probs);
- probs = &p->isRep[p->state];
- RC_BIT_PRE(&p->rc, probs)
-
- if (dist < LZMA_NUM_REPS)
- {
- RC_BIT_1(&p->rc, probs);
- probs = &p->isRepG0[p->state];
- RC_BIT_PRE(&p->rc, probs)
- if (dist == 0)
- {
- RC_BIT_0(&p->rc, probs);
- probs = &p->isRep0Long[p->state][posState];
- RC_BIT_PRE(&p->rc, probs)
- if (len != 1)
- {
- RC_BIT_1_BASE(&p->rc, probs);
- }
- else
- {
- RC_BIT_0_BASE(&p->rc, probs);
- p->state = kShortRepNextStates[p->state];
- }
- }
- else
- {
- RC_BIT_1(&p->rc, probs);
- probs = &p->isRepG1[p->state];
- RC_BIT_PRE(&p->rc, probs)
- if (dist == 1)
- {
- RC_BIT_0_BASE(&p->rc, probs);
- dist = p->reps[1];
- }
- else
- {
- RC_BIT_1(&p->rc, probs);
- probs = &p->isRepG2[p->state];
- RC_BIT_PRE(&p->rc, probs)
- if (dist == 2)
- {
- RC_BIT_0_BASE(&p->rc, probs);
- dist = p->reps[2];
- }
- else
- {
- RC_BIT_1_BASE(&p->rc, probs);
- dist = p->reps[3];
- p->reps[3] = p->reps[2];
- }
- p->reps[2] = p->reps[1];
- }
- p->reps[1] = p->reps[0];
- p->reps[0] = dist;
- }
-
- RC_NORM(&p->rc)
-
- p->rc.range = range;
-
- if (len != 1)
- {
- LenEnc_Encode(&p->repLenProbs, &p->rc, len - LZMA_MATCH_LEN_MIN, posState);
- --p->repLenEncCounter;
- p->state = kRepNextStates[p->state];
- }
- }
- else
- {
- unsigned posSlot;
- RC_BIT_0(&p->rc, probs);
- p->rc.range = range;
- p->state = kMatchNextStates[p->state];
-
- LenEnc_Encode(&p->lenProbs, &p->rc, len - LZMA_MATCH_LEN_MIN, posState);
- // --p->lenEnc.counter;
-
- dist -= LZMA_NUM_REPS;
- p->reps[3] = p->reps[2];
- p->reps[2] = p->reps[1];
- p->reps[1] = p->reps[0];
- p->reps[0] = dist + 1;
-
- p->matchPriceCount++;
- GetPosSlot(dist, posSlot);
- // RcTree_Encode_PosSlot(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], posSlot);
- {
- UInt32 sym = (UInt32)posSlot + (1 << kNumPosSlotBits);
- range = p->rc.range;
- probs = p->posSlotEncoder[GetLenToPosState(len)];
- do
- {
- CLzmaProb *prob = probs + (sym >> kNumPosSlotBits);
- UInt32 bit = (sym >> (kNumPosSlotBits - 1)) & 1;
- sym <<= 1;
- RC_BIT(&p->rc, prob, bit);
- }
- while (sym < (1 << kNumPosSlotBits * 2));
- p->rc.range = range;
- }
-
- if (dist >= kStartPosModelIndex)
- {
- unsigned footerBits = ((posSlot >> 1) - 1);
-
- if (dist < kNumFullDistances)
- {
- unsigned base = ((2 | (posSlot & 1)) << footerBits);
- RcTree_ReverseEncode(&p->rc, p->posEncoders + base, footerBits, (unsigned)(dist /* - base */));
- }
- else
- {
- UInt32 pos2 = (dist | 0xF) << (32 - footerBits);
- range = p->rc.range;
- // RangeEnc_EncodeDirectBits(&p->rc, posReduced >> kNumAlignBits, footerBits - kNumAlignBits);
- /*
- do
- {
- range >>= 1;
- p->rc.low += range & (0 - ((dist >> --footerBits) & 1));
- RC_NORM(&p->rc)
- }
- while (footerBits > kNumAlignBits);
- */
- do
- {
- range >>= 1;
- p->rc.low += range & (0 - (pos2 >> 31));
- pos2 += pos2;
- RC_NORM(&p->rc)
- }
- while (pos2 != 0xF0000000);
-
-
- // RcTree_ReverseEncode(&p->rc, p->posAlignEncoder, kNumAlignBits, posReduced & kAlignMask);
-
- {
- unsigned m = 1;
- unsigned bit;
- bit = dist & 1; dist >>= 1; RC_BIT(&p->rc, p->posAlignEncoder + m, bit); m = (m << 1) + bit;
- bit = dist & 1; dist >>= 1; RC_BIT(&p->rc, p->posAlignEncoder + m, bit); m = (m << 1) + bit;
- bit = dist & 1; dist >>= 1; RC_BIT(&p->rc, p->posAlignEncoder + m, bit); m = (m << 1) + bit;
- bit = dist & 1; RC_BIT(&p->rc, p->posAlignEncoder + m, bit);
- p->rc.range = range;
- // p->alignPriceCount++;
- }
- }
- }
- }
- }
-
- nowPos32 += (UInt32)len;
- p->additionalOffset -= len;
-
- if (p->additionalOffset == 0)
- {
- UInt32 processed;
-
- if (!p->fastMode)
- {
- /*
- if (p->alignPriceCount >= 16) // kAlignTableSize
- FillAlignPrices(p);
- if (p->matchPriceCount >= 128)
- FillDistancesPrices(p);
- if (p->lenEnc.counter <= 0)
- LenPriceEnc_UpdateTables(&p->lenEnc, 1 << p->pb, &p->lenProbs, p->ProbPrices);
- */
- if (p->matchPriceCount >= 64)
- {
- FillAlignPrices(p);
- // { int y; for (y = 0; y < 100; y++) {
- FillDistancesPrices(p);
- // }}
- LenPriceEnc_UpdateTables(&p->lenEnc, (unsigned)1 << p->pb, &p->lenProbs, p->ProbPrices);
- }
- if (p->repLenEncCounter <= 0)
- {
- p->repLenEncCounter = REP_LEN_COUNT;
- LenPriceEnc_UpdateTables(&p->repLenEnc, (unsigned)1 << p->pb, &p->repLenProbs, p->ProbPrices);
- }
- }
-
- if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0)
- break;
- processed = nowPos32 - startPos32;
-
- if (maxPackSize)
- {
- if (processed + kNumOpts + 300 >= maxUnpackSize
- || RangeEnc_GetProcessed_sizet(&p->rc) + kPackReserve >= maxPackSize)
- break;
- }
- else if (processed >= (1 << 17))
- {
- p->nowPos64 += nowPos32 - startPos32;
- return CheckErrors(p);
- }
- }
- }
-
- p->nowPos64 += nowPos32 - startPos32;
- return Flush(p, nowPos32);
-}
-
-
-
-#define kBigHashDicLimit ((UInt32)1 << 24)
-
-static SRes LzmaEnc_Alloc(CLzmaEnc *p, UInt32 keepWindowSize, ISzAllocPtr alloc, ISzAllocPtr allocBig)
-{
- UInt32 beforeSize = kNumOpts;
- UInt32 dictSize;
-
- if (!RangeEnc_Alloc(&p->rc, alloc))
- return SZ_ERROR_MEM;
-
- #ifndef _7ZIP_ST
- p->mtMode = (p->multiThread && !p->fastMode && (MFB.btMode != 0));
- #endif
-
- {
- unsigned lclp = p->lc + p->lp;
- if (!p->litProbs || !p->saveState.litProbs || p->lclp != lclp)
- {
- LzmaEnc_FreeLits(p, alloc);
- p->litProbs = (CLzmaProb *)ISzAlloc_Alloc(alloc, ((UInt32)0x300 << lclp) * sizeof(CLzmaProb));
- p->saveState.litProbs = (CLzmaProb *)ISzAlloc_Alloc(alloc, ((UInt32)0x300 << lclp) * sizeof(CLzmaProb));
- if (!p->litProbs || !p->saveState.litProbs)
- {
- LzmaEnc_FreeLits(p, alloc);
- return SZ_ERROR_MEM;
- }
- p->lclp = lclp;
- }
- }
-
- MFB.bigHash = (Byte)(p->dictSize > kBigHashDicLimit ? 1 : 0);
-
-
- dictSize = p->dictSize;
- if (dictSize == ((UInt32)2 << 30) ||
- dictSize == ((UInt32)3 << 30))
- {
- /* 21.03 : here we reduce the dictionary for 2 reasons:
- 1) we don't want 32-bit back_distance matches in decoder for 2 GB dictionary.
- 2) we want to elimate useless last MatchFinder_Normalize3() for corner cases,
- where data size is aligned for 1 GB: 5/6/8 GB.
- That reducing must be >= 1 for such corner cases. */
- dictSize -= 1;
- }
-
- if (beforeSize + dictSize < keepWindowSize)
- beforeSize = keepWindowSize - dictSize;
-
- /* in worst case we can look ahead for
- max(LZMA_MATCH_LEN_MAX, numFastBytes + 1 + numFastBytes) bytes.
- we send larger value for (keepAfter) to MantchFinder_Create():
- (numFastBytes + LZMA_MATCH_LEN_MAX + 1)
- */
-
- #ifndef _7ZIP_ST
- if (p->mtMode)
- {
- RINOK(MatchFinderMt_Create(&p->matchFinderMt, dictSize, beforeSize,
- p->numFastBytes, LZMA_MATCH_LEN_MAX + 1 /* 18.04 */
- , allocBig));
- p->matchFinderObj = &p->matchFinderMt;
- MFB.bigHash = (Byte)(
- (p->dictSize > kBigHashDicLimit && MFB.hashMask >= 0xFFFFFF) ? 1 : 0);
- MatchFinderMt_CreateVTable(&p->matchFinderMt, &p->matchFinder);
- }
- else
- #endif
- {
- if (!MatchFinder_Create(&MFB, dictSize, beforeSize,
- p->numFastBytes, LZMA_MATCH_LEN_MAX + 1 /* 21.03 */
- , allocBig))
- return SZ_ERROR_MEM;
- p->matchFinderObj = &MFB;
- MatchFinder_CreateVTable(&MFB, &p->matchFinder);
- }
-
- return SZ_OK;
-}
-
-static void LzmaEnc_Init(CLzmaEnc *p)
-{
- unsigned i;
- p->state = 0;
- p->reps[0] =
- p->reps[1] =
- p->reps[2] =
- p->reps[3] = 1;
-
- RangeEnc_Init(&p->rc);
-
- for (i = 0; i < (1 << kNumAlignBits); i++)
- p->posAlignEncoder[i] = kProbInitValue;
-
- for (i = 0; i < kNumStates; i++)
- {
- unsigned j;
- for (j = 0; j < LZMA_NUM_PB_STATES_MAX; j++)
- {
- p->isMatch[i][j] = kProbInitValue;
- p->isRep0Long[i][j] = kProbInitValue;
- }
- p->isRep[i] = kProbInitValue;
- p->isRepG0[i] = kProbInitValue;
- p->isRepG1[i] = kProbInitValue;
- p->isRepG2[i] = kProbInitValue;
- }
-
- {
- for (i = 0; i < kNumLenToPosStates; i++)
- {
- CLzmaProb *probs = p->posSlotEncoder[i];
- unsigned j;
- for (j = 0; j < (1 << kNumPosSlotBits); j++)
- probs[j] = kProbInitValue;
- }
- }
- {
- for (i = 0; i < kNumFullDistances; i++)
- p->posEncoders[i] = kProbInitValue;
- }
-
- {
- UInt32 num = (UInt32)0x300 << (p->lp + p->lc);
- UInt32 k;
- CLzmaProb *probs = p->litProbs;
- for (k = 0; k < num; k++)
- probs[k] = kProbInitValue;
- }
-
-
- LenEnc_Init(&p->lenProbs);
- LenEnc_Init(&p->repLenProbs);
-
- p->optEnd = 0;
- p->optCur = 0;
-
- {
- for (i = 0; i < kNumOpts; i++)
- p->opt[i].price = kInfinityPrice;
- }
-
- p->additionalOffset = 0;
-
- p->pbMask = ((unsigned)1 << p->pb) - 1;
- p->lpMask = ((UInt32)0x100 << p->lp) - ((unsigned)0x100 >> p->lc);
-
- // p->mf_Failure = False;
-}
-
-
-static void LzmaEnc_InitPrices(CLzmaEnc *p)
-{
- if (!p->fastMode)
- {
- FillDistancesPrices(p);
- FillAlignPrices(p);
- }
-
- p->lenEnc.tableSize =
- p->repLenEnc.tableSize =
- p->numFastBytes + 1 - LZMA_MATCH_LEN_MIN;
-
- p->repLenEncCounter = REP_LEN_COUNT;
-
- LenPriceEnc_UpdateTables(&p->lenEnc, (unsigned)1 << p->pb, &p->lenProbs, p->ProbPrices);
- LenPriceEnc_UpdateTables(&p->repLenEnc, (unsigned)1 << p->pb, &p->repLenProbs, p->ProbPrices);
-}
-
-static SRes LzmaEnc_AllocAndInit(CLzmaEnc *p, UInt32 keepWindowSize, ISzAllocPtr alloc, ISzAllocPtr allocBig)
-{
- unsigned i;
- for (i = kEndPosModelIndex / 2; i < kDicLogSizeMax; i++)
- if (p->dictSize <= ((UInt32)1 << i))
- break;
- p->distTableSize = i * 2;
-
- p->finished = False;
- p->result = SZ_OK;
- RINOK(LzmaEnc_Alloc(p, keepWindowSize, alloc, allocBig));
- LzmaEnc_Init(p);
- LzmaEnc_InitPrices(p);
- p->nowPos64 = 0;
- return SZ_OK;
-}
-
-static SRes LzmaEnc_Prepare(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream,
- ISzAllocPtr alloc, ISzAllocPtr allocBig)
-{
- CLzmaEnc *p = (CLzmaEnc *)pp;
- MFB.stream = inStream;
- p->needInit = 1;
- p->rc.outStream = outStream;
- return LzmaEnc_AllocAndInit(p, 0, alloc, allocBig);
-}
-
-SRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp,
- ISeqInStream *inStream, UInt32 keepWindowSize,
- ISzAllocPtr alloc, ISzAllocPtr allocBig)
-{
- CLzmaEnc *p = (CLzmaEnc *)pp;
- MFB.stream = inStream;
- p->needInit = 1;
- return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);
-}
-
-static void LzmaEnc_SetInputBuf(CLzmaEnc *p, const Byte *src, SizeT srcLen)
-{
- MFB.directInput = 1;
- MFB.bufferBase = (Byte *)src;
- MFB.directInputRem = srcLen;
-}
-
-SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen,
- UInt32 keepWindowSize, ISzAllocPtr alloc, ISzAllocPtr allocBig)
-{
- CLzmaEnc *p = (CLzmaEnc *)pp;
- LzmaEnc_SetInputBuf(p, src, srcLen);
- p->needInit = 1;
-
- LzmaEnc_SetDataSize(pp, srcLen);
- return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);
-}
-
-void LzmaEnc_Finish(CLzmaEncHandle pp)
-{
- #ifndef _7ZIP_ST
- CLzmaEnc *p = (CLzmaEnc *)pp;
- if (p->mtMode)
- MatchFinderMt_ReleaseStream(&p->matchFinderMt);
- #else
- UNUSED_VAR(pp);
- #endif
-}
-
-
-typedef struct
-{
- ISeqOutStream vt;
- Byte *data;
- SizeT rem;
- BoolInt overflow;
-} CLzmaEnc_SeqOutStreamBuf;
-
-static size_t SeqOutStreamBuf_Write(const ISeqOutStream *pp, const void *data, size_t size)
-{
- CLzmaEnc_SeqOutStreamBuf *p = CONTAINER_FROM_VTBL(pp, CLzmaEnc_SeqOutStreamBuf, vt);
- if (p->rem < size)
- {
- size = p->rem;
- p->overflow = True;
- }
- if (size != 0)
- {
- memcpy(p->data, data, size);
- p->rem -= size;
- p->data += size;
- }
- return size;
-}
-
-
-/*
-UInt32 LzmaEnc_GetNumAvailableBytes(CLzmaEncHandle pp)
-{
- const CLzmaEnc *p = (CLzmaEnc *)pp;
- return p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);
-}
-*/
-
-const Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp)
-{
- const CLzmaEnc *p = (CLzmaEnc *)pp;
- return p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;
-}
-
-
-// (desiredPackSize == 0) is not allowed
-SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, BoolInt reInit,
- Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize)
-{
- CLzmaEnc *p = (CLzmaEnc *)pp;
- UInt64 nowPos64;
- SRes res;
- CLzmaEnc_SeqOutStreamBuf outStream;
-
- outStream.vt.Write = SeqOutStreamBuf_Write;
- outStream.data = dest;
- outStream.rem = *destLen;
- outStream.overflow = False;
-
- p->writeEndMark = False;
- p->finished = False;
- p->result = SZ_OK;
-
- if (reInit)
- LzmaEnc_Init(p);
- LzmaEnc_InitPrices(p);
- RangeEnc_Init(&p->rc);
- p->rc.outStream = &outStream.vt;
- nowPos64 = p->nowPos64;
-
- res = LzmaEnc_CodeOneBlock(p, desiredPackSize, *unpackSize);
-
- *unpackSize = (UInt32)(p->nowPos64 - nowPos64);
- *destLen -= outStream.rem;
- if (outStream.overflow)
- return SZ_ERROR_OUTPUT_EOF;
-
- return res;
-}
-
-
-MY_NO_INLINE
-static SRes LzmaEnc_Encode2(CLzmaEnc *p, ICompressProgress *progress)
-{
- SRes res = SZ_OK;
-
- #ifndef _7ZIP_ST
- Byte allocaDummy[0x300];
- allocaDummy[0] = 0;
- allocaDummy[1] = allocaDummy[0];
- #endif
-
- for (;;)
- {
- res = LzmaEnc_CodeOneBlock(p, 0, 0);
- if (res != SZ_OK || p->finished)
- break;
- if (progress)
- {
- res = ICompressProgress_Progress(progress, p->nowPos64, RangeEnc_GetProcessed(&p->rc));
- if (res != SZ_OK)
- {
- res = SZ_ERROR_PROGRESS;
- break;
- }
- }
- }
-
- LzmaEnc_Finish(p);
-
- /*
- if (res == SZ_OK && !Inline_MatchFinder_IsFinishedOK(&MFB))
- res = SZ_ERROR_FAIL;
- }
- */
-
- return res;
-}
-
-
-SRes LzmaEnc_Encode(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress,
- ISzAllocPtr alloc, ISzAllocPtr allocBig)
-{
- RINOK(LzmaEnc_Prepare(pp, outStream, inStream, alloc, allocBig));
- return LzmaEnc_Encode2((CLzmaEnc *)pp, progress);
-}
-
-
-SRes LzmaEnc_WriteProperties(CLzmaEncHandle pp, Byte *props, SizeT *size)
-{
- if (*size < LZMA_PROPS_SIZE)
- return SZ_ERROR_PARAM;
- *size = LZMA_PROPS_SIZE;
- {
- const CLzmaEnc *p = (const CLzmaEnc *)pp;
- const UInt32 dictSize = p->dictSize;
- UInt32 v;
- props[0] = (Byte)((p->pb * 5 + p->lp) * 9 + p->lc);
-
- // we write aligned dictionary value to properties for lzma decoder
- if (dictSize >= ((UInt32)1 << 21))
- {
- const UInt32 kDictMask = ((UInt32)1 << 20) - 1;
- v = (dictSize + kDictMask) & ~kDictMask;
- if (v < dictSize)
- v = dictSize;
- }
- else
- {
- unsigned i = 11 * 2;
- do
- {
- v = (UInt32)(2 + (i & 1)) << (i >> 1);
- i++;
- }
- while (v < dictSize);
- }
-
- SetUi32(props + 1, v);
- return SZ_OK;
- }
-}
-
-
-unsigned LzmaEnc_IsWriteEndMark(CLzmaEncHandle pp)
-{
- return (unsigned)((CLzmaEnc *)pp)->writeEndMark;
-}
-
-
-SRes LzmaEnc_MemEncode(CLzmaEncHandle pp, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
- int writeEndMark, ICompressProgress *progress, ISzAllocPtr alloc, ISzAllocPtr allocBig)
-{
- SRes res;
- CLzmaEnc *p = (CLzmaEnc *)pp;
-
- CLzmaEnc_SeqOutStreamBuf outStream;
-
- outStream.vt.Write = SeqOutStreamBuf_Write;
- outStream.data = dest;
- outStream.rem = *destLen;
- outStream.overflow = False;
-
- p->writeEndMark = writeEndMark;
- p->rc.outStream = &outStream.vt;
-
- res = LzmaEnc_MemPrepare(pp, src, srcLen, 0, alloc, allocBig);
-
- if (res == SZ_OK)
- {
- res = LzmaEnc_Encode2(p, progress);
- if (res == SZ_OK && p->nowPos64 != srcLen)
- res = SZ_ERROR_FAIL;
- }
-
- *destLen -= outStream.rem;
- if (outStream.overflow)
- return SZ_ERROR_OUTPUT_EOF;
- return res;
-}
-
-
-SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
- const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
- ICompressProgress *progress, ISzAllocPtr alloc, ISzAllocPtr allocBig)
-{
- CLzmaEnc *p = (CLzmaEnc *)LzmaEnc_Create(alloc);
- SRes res;
- if (!p)
- return SZ_ERROR_MEM;
-
- res = LzmaEnc_SetProps(p, props);
- if (res == SZ_OK)
- {
- res = LzmaEnc_WriteProperties(p, propsEncoded, propsSize);
- if (res == SZ_OK)
- res = LzmaEnc_MemEncode(p, dest, destLen, src, srcLen,
- writeEndMark, progress, alloc, allocBig);
- }
-
- LzmaEnc_Destroy(p, alloc, allocBig);
- return res;
-}
-
-
-/*
-#ifndef _7ZIP_ST
-void LzmaEnc_GetLzThreads(CLzmaEncHandle pp, HANDLE lz_threads[2])
-{
- const CLzmaEnc *p = (CLzmaEnc *)pp;
- lz_threads[0] = p->matchFinderMt.hashSync.thread;
- lz_threads[1] = p->matchFinderMt.btSync.thread;
-}
-#endif
-*/
+/* LzmaEnc.c -- LZMA Encoder
+2024-01-24: Igor Pavlov : Public domain */
+
+#include "Precomp.h"
+
+#include
+
+/* #define SHOW_STAT */
+/* #define SHOW_STAT2 */
+
+#if defined(SHOW_STAT) || defined(SHOW_STAT2)
+#include
+#endif
+
+#include "CpuArch.h"
+#include "LzmaEnc.h"
+
+#include "LzFind.h"
+#ifndef Z7_ST
+#include "LzFindMt.h"
+#endif
+
+/* the following LzmaEnc_* declarations is internal LZMA interface for LZMA2 encoder */
+
+SRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle p, ISeqInStreamPtr inStream, UInt32 keepWindowSize,
+ ISzAllocPtr alloc, ISzAllocPtr allocBig);
+SRes LzmaEnc_MemPrepare(CLzmaEncHandle p, const Byte *src, SizeT srcLen,
+ UInt32 keepWindowSize, ISzAllocPtr alloc, ISzAllocPtr allocBig);
+SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle p, BoolInt reInit,
+ Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize);
+const Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle p);
+void LzmaEnc_Finish(CLzmaEncHandle p);
+void LzmaEnc_SaveState(CLzmaEncHandle p);
+void LzmaEnc_RestoreState(CLzmaEncHandle p);
+
+#ifdef SHOW_STAT
+static unsigned g_STAT_OFFSET = 0;
+#endif
+
+/* for good normalization speed we still reserve 256 MB before 4 GB range */
+#define kLzmaMaxHistorySize ((UInt32)15 << 28)
+
+// #define kNumTopBits 24
+#define kTopValue ((UInt32)1 << 24)
+
+#define kNumBitModelTotalBits 11
+#define kBitModelTotal (1 << kNumBitModelTotalBits)
+#define kNumMoveBits 5
+#define kProbInitValue (kBitModelTotal >> 1)
+
+#define kNumMoveReducingBits 4
+#define kNumBitPriceShiftBits 4
+// #define kBitPrice (1 << kNumBitPriceShiftBits)
+
+#define REP_LEN_COUNT 64
+
+void LzmaEncProps_Init(CLzmaEncProps *p)
+{
+ p->level = 5;
+ p->dictSize = p->mc = 0;
+ p->reduceSize = (UInt64)(Int64)-1;
+ p->lc = p->lp = p->pb = p->algo = p->fb = p->btMode = p->numHashBytes = p->numThreads = -1;
+ p->numHashOutBits = 0;
+ p->writeEndMark = 0;
+ p->affinity = 0;
+}
+
+void LzmaEncProps_Normalize(CLzmaEncProps *p)
+{
+ int level = p->level;
+ if (level < 0) level = 5;
+ p->level = level;
+
+ if (p->dictSize == 0)
+ p->dictSize =
+ ( level <= 3 ? ((UInt32)1 << (level * 2 + 16)) :
+ ( level <= 6 ? ((UInt32)1 << (level + 19)) :
+ ( level <= 7 ? ((UInt32)1 << 25) : ((UInt32)1 << 26)
+ )));
+
+ if (p->dictSize > p->reduceSize)
+ {
+ UInt32 v = (UInt32)p->reduceSize;
+ const UInt32 kReduceMin = ((UInt32)1 << 12);
+ if (v < kReduceMin)
+ v = kReduceMin;
+ if (p->dictSize > v)
+ p->dictSize = v;
+ }
+
+ if (p->lc < 0) p->lc = 3;
+ if (p->lp < 0) p->lp = 0;
+ if (p->pb < 0) p->pb = 2;
+
+ if (p->algo < 0) p->algo = (level < 5 ? 0 : 1);
+ if (p->fb < 0) p->fb = (level < 7 ? 32 : 64);
+ if (p->btMode < 0) p->btMode = (p->algo == 0 ? 0 : 1);
+ if (p->numHashBytes < 0) p->numHashBytes = (p->btMode ? 4 : 5);
+ if (p->mc == 0) p->mc = (16 + ((unsigned)p->fb >> 1)) >> (p->btMode ? 0 : 1);
+
+ if (p->numThreads < 0)
+ p->numThreads =
+ #ifndef Z7_ST
+ ((p->btMode && p->algo) ? 2 : 1);
+ #else
+ 1;
+ #endif
+}
+
+UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2)
+{
+ CLzmaEncProps props = *props2;
+ LzmaEncProps_Normalize(&props);
+ return props.dictSize;
+}
+
+
+/*
+x86/x64:
+
+BSR:
+ IF (SRC == 0) ZF = 1, DEST is undefined;
+ AMD : DEST is unchanged;
+ IF (SRC != 0) ZF = 0; DEST is index of top non-zero bit
+ BSR is slow in some processors
+
+LZCNT:
+ IF (SRC == 0) CF = 1, DEST is size_in_bits_of_register(src) (32 or 64)
+ IF (SRC != 0) CF = 0, DEST = num_lead_zero_bits
+ IF (DEST == 0) ZF = 1;
+
+LZCNT works only in new processors starting from Haswell.
+if LZCNT is not supported by processor, then it's executed as BSR.
+LZCNT can be faster than BSR, if supported.
+*/
+
+// #define LZMA_LOG_BSR
+
+#if defined(MY_CPU_ARM_OR_ARM64) /* || defined(MY_CPU_X86_OR_AMD64) */
+
+ #if (defined(__clang__) && (__clang_major__ >= 6)) \
+ || (defined(__GNUC__) && (__GNUC__ >= 6))
+ #define LZMA_LOG_BSR
+ #elif defined(_MSC_VER) && (_MSC_VER >= 1300)
+ // #if defined(MY_CPU_ARM_OR_ARM64)
+ #define LZMA_LOG_BSR
+ // #endif
+ #endif
+#endif
+
+// #include
+
+#ifdef LZMA_LOG_BSR
+
+#if defined(__clang__) \
+ || defined(__GNUC__)
+
+/*
+ C code: : (30 - __builtin_clz(x))
+ gcc9/gcc10 for x64 /x86 : 30 - (bsr(x) xor 31)
+ clang10 for x64 : 31 + (bsr(x) xor -32)
+*/
+
+ #define MY_clz(x) ((unsigned)__builtin_clz(x))
+ // __lzcnt32
+ // __builtin_ia32_lzcnt_u32
+
+#else // #if defined(_MSC_VER)
+
+ #ifdef MY_CPU_ARM_OR_ARM64
+
+ #define MY_clz _CountLeadingZeros
+
+ #else // if defined(MY_CPU_X86_OR_AMD64)
+
+ // #define MY_clz __lzcnt // we can use lzcnt (unsupported by old CPU)
+ // _BitScanReverse code is not optimal for some MSVC compilers
+ #define BSR2_RET(pos, res) { unsigned long zz; _BitScanReverse(&zz, (pos)); zz--; \
+ res = (zz + zz) + (pos >> zz); }
+
+ #endif // MY_CPU_X86_OR_AMD64
+
+#endif // _MSC_VER
+
+
+#ifndef BSR2_RET
+
+ #define BSR2_RET(pos, res) { unsigned zz = 30 - MY_clz(pos); \
+ res = (zz + zz) + (pos >> zz); }
+
+#endif
+
+
+unsigned GetPosSlot1(UInt32 pos);
+unsigned GetPosSlot1(UInt32 pos)
+{
+ unsigned res;
+ BSR2_RET(pos, res)
+ return res;
+}
+#define GetPosSlot2(pos, res) { BSR2_RET(pos, res) }
+#define GetPosSlot(pos, res) { if (pos < 2) res = pos; else BSR2_RET(pos, res) }
+
+
+#else // ! LZMA_LOG_BSR
+
+#define kNumLogBits (11 + sizeof(size_t) / 8 * 3)
+
+#define kDicLogSizeMaxCompress ((kNumLogBits - 1) * 2 + 7)
+
+static void LzmaEnc_FastPosInit(Byte *g_FastPos)
+{
+ unsigned slot;
+ g_FastPos[0] = 0;
+ g_FastPos[1] = 1;
+ g_FastPos += 2;
+
+ for (slot = 2; slot < kNumLogBits * 2; slot++)
+ {
+ size_t k = ((size_t)1 << ((slot >> 1) - 1));
+ size_t j;
+ for (j = 0; j < k; j++)
+ g_FastPos[j] = (Byte)slot;
+ g_FastPos += k;
+ }
+}
+
+/* we can use ((limit - pos) >> 31) only if (pos < ((UInt32)1 << 31)) */
+/*
+#define BSR2_RET(pos, res) { unsigned zz = 6 + ((kNumLogBits - 1) & \
+ (0 - (((((UInt32)1 << (kNumLogBits + 6)) - 1) - pos) >> 31))); \
+ res = p->g_FastPos[pos >> zz] + (zz * 2); }
+*/
+
+/*
+#define BSR2_RET(pos, res) { unsigned zz = 6 + ((kNumLogBits - 1) & \
+ (0 - (((((UInt32)1 << (kNumLogBits)) - 1) - (pos >> 6)) >> 31))); \
+ res = p->g_FastPos[pos >> zz] + (zz * 2); }
+*/
+
+#define BSR2_RET(pos, res) { unsigned zz = (pos < (1 << (kNumLogBits + 6))) ? 6 : 6 + kNumLogBits - 1; \
+ res = p->g_FastPos[pos >> zz] + (zz * 2); }
+
+/*
+#define BSR2_RET(pos, res) { res = (pos < (1 << (kNumLogBits + 6))) ? \
+ p->g_FastPos[pos >> 6] + 12 : \
+ p->g_FastPos[pos >> (6 + kNumLogBits - 1)] + (6 + (kNumLogBits - 1)) * 2; }
+*/
+
+#define GetPosSlot1(pos) p->g_FastPos[pos]
+#define GetPosSlot2(pos, res) { BSR2_RET(pos, res); }
+#define GetPosSlot(pos, res) { if (pos < kNumFullDistances) res = p->g_FastPos[pos & (kNumFullDistances - 1)]; else BSR2_RET(pos, res); }
+
+#endif // LZMA_LOG_BSR
+
+
+#define LZMA_NUM_REPS 4
+
+typedef UInt16 CState;
+typedef UInt16 CExtra;
+
+typedef struct
+{
+ UInt32 price;
+ CState state;
+ CExtra extra;
+ // 0 : normal
+ // 1 : LIT : MATCH
+ // > 1 : MATCH (extra-1) : LIT : REP0 (len)
+ UInt32 len;
+ UInt32 dist;
+ UInt32 reps[LZMA_NUM_REPS];
+} COptimal;
+
+
+// 18.06
+#define kNumOpts (1 << 11)
+#define kPackReserve (kNumOpts * 8)
+// #define kNumOpts (1 << 12)
+// #define kPackReserve (1 + kNumOpts * 2)
+
+#define kNumLenToPosStates 4
+#define kNumPosSlotBits 6
+// #define kDicLogSizeMin 0
+#define kDicLogSizeMax 32
+#define kDistTableSizeMax (kDicLogSizeMax * 2)
+
+#define kNumAlignBits 4
+#define kAlignTableSize (1 << kNumAlignBits)
+#define kAlignMask (kAlignTableSize - 1)
+
+#define kStartPosModelIndex 4
+#define kEndPosModelIndex 14
+#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))
+
+typedef
+#ifdef Z7_LZMA_PROB32
+ UInt32
+#else
+ UInt16
+#endif
+ CLzmaProb;
+
+#define LZMA_PB_MAX 4
+#define LZMA_LC_MAX 8
+#define LZMA_LP_MAX 4
+
+#define LZMA_NUM_PB_STATES_MAX (1 << LZMA_PB_MAX)
+
+#define kLenNumLowBits 3
+#define kLenNumLowSymbols (1 << kLenNumLowBits)
+#define kLenNumHighBits 8
+#define kLenNumHighSymbols (1 << kLenNumHighBits)
+#define kLenNumSymbolsTotal (kLenNumLowSymbols * 2 + kLenNumHighSymbols)
+
+#define LZMA_MATCH_LEN_MIN 2
+#define LZMA_MATCH_LEN_MAX (LZMA_MATCH_LEN_MIN + kLenNumSymbolsTotal - 1)
+
+#define kNumStates 12
+
+
+typedef struct
+{
+ CLzmaProb low[LZMA_NUM_PB_STATES_MAX << (kLenNumLowBits + 1)];
+ CLzmaProb high[kLenNumHighSymbols];
+} CLenEnc;
+
+
+typedef struct
+{
+ unsigned tableSize;
+ UInt32 prices[LZMA_NUM_PB_STATES_MAX][kLenNumSymbolsTotal];
+ // UInt32 prices1[LZMA_NUM_PB_STATES_MAX][kLenNumLowSymbols * 2];
+ // UInt32 prices2[kLenNumSymbolsTotal];
+} CLenPriceEnc;
+
+#define GET_PRICE_LEN(p, posState, len) \
+ ((p)->prices[posState][(size_t)(len) - LZMA_MATCH_LEN_MIN])
+
+/*
+#define GET_PRICE_LEN(p, posState, len) \
+ ((p)->prices2[(size_t)(len) - 2] + ((p)->prices1[posState][((len) - 2) & (kLenNumLowSymbols * 2 - 1)] & (((len) - 2 - kLenNumLowSymbols * 2) >> 9)))
+*/
+
+typedef struct
+{
+ UInt32 range;
+ unsigned cache;
+ UInt64 low;
+ UInt64 cacheSize;
+ Byte *buf;
+ Byte *bufLim;
+ Byte *bufBase;
+ ISeqOutStreamPtr outStream;
+ UInt64 processed;
+ SRes res;
+} CRangeEnc;
+
+
+typedef struct
+{
+ CLzmaProb *litProbs;
+
+ unsigned state;
+ UInt32 reps[LZMA_NUM_REPS];
+
+ CLzmaProb posAlignEncoder[1 << kNumAlignBits];
+ CLzmaProb isRep[kNumStates];
+ CLzmaProb isRepG0[kNumStates];
+ CLzmaProb isRepG1[kNumStates];
+ CLzmaProb isRepG2[kNumStates];
+ CLzmaProb isMatch[kNumStates][LZMA_NUM_PB_STATES_MAX];
+ CLzmaProb isRep0Long[kNumStates][LZMA_NUM_PB_STATES_MAX];
+
+ CLzmaProb posSlotEncoder[kNumLenToPosStates][1 << kNumPosSlotBits];
+ CLzmaProb posEncoders[kNumFullDistances];
+
+ CLenEnc lenProbs;
+ CLenEnc repLenProbs;
+
+} CSaveState;
+
+
+typedef UInt32 CProbPrice;
+
+
+struct CLzmaEnc
+{
+ void *matchFinderObj;
+ IMatchFinder2 matchFinder;
+
+ unsigned optCur;
+ unsigned optEnd;
+
+ unsigned longestMatchLen;
+ unsigned numPairs;
+ UInt32 numAvail;
+
+ unsigned state;
+ unsigned numFastBytes;
+ unsigned additionalOffset;
+ UInt32 reps[LZMA_NUM_REPS];
+ unsigned lpMask, pbMask;
+ CLzmaProb *litProbs;
+ CRangeEnc rc;
+
+ UInt32 backRes;
+
+ unsigned lc, lp, pb;
+ unsigned lclp;
+
+ BoolInt fastMode;
+ BoolInt writeEndMark;
+ BoolInt finished;
+ BoolInt multiThread;
+ BoolInt needInit;
+ // BoolInt _maxMode;
+
+ UInt64 nowPos64;
+
+ unsigned matchPriceCount;
+ // unsigned alignPriceCount;
+ int repLenEncCounter;
+
+ unsigned distTableSize;
+
+ UInt32 dictSize;
+ SRes result;
+
+ #ifndef Z7_ST
+ BoolInt mtMode;
+ // begin of CMatchFinderMt is used in LZ thread
+ CMatchFinderMt matchFinderMt;
+ // end of CMatchFinderMt is used in BT and HASH threads
+ // #else
+ // CMatchFinder matchFinderBase;
+ #endif
+ CMatchFinder matchFinderBase;
+
+
+ // we suppose that we have 8-bytes alignment after CMatchFinder
+
+ #ifndef Z7_ST
+ Byte pad[128];
+ #endif
+
+ // LZ thread
+ CProbPrice ProbPrices[kBitModelTotal >> kNumMoveReducingBits];
+
+ // we want {len , dist} pairs to be 8-bytes aligned in matches array
+ UInt32 matches[LZMA_MATCH_LEN_MAX * 2 + 2];
+
+ // we want 8-bytes alignment here
+ UInt32 alignPrices[kAlignTableSize];
+ UInt32 posSlotPrices[kNumLenToPosStates][kDistTableSizeMax];
+ UInt32 distancesPrices[kNumLenToPosStates][kNumFullDistances];
+
+ CLzmaProb posAlignEncoder[1 << kNumAlignBits];
+ CLzmaProb isRep[kNumStates];
+ CLzmaProb isRepG0[kNumStates];
+ CLzmaProb isRepG1[kNumStates];
+ CLzmaProb isRepG2[kNumStates];
+ CLzmaProb isMatch[kNumStates][LZMA_NUM_PB_STATES_MAX];
+ CLzmaProb isRep0Long[kNumStates][LZMA_NUM_PB_STATES_MAX];
+ CLzmaProb posSlotEncoder[kNumLenToPosStates][1 << kNumPosSlotBits];
+ CLzmaProb posEncoders[kNumFullDistances];
+
+ CLenEnc lenProbs;
+ CLenEnc repLenProbs;
+
+ #ifndef LZMA_LOG_BSR
+ Byte g_FastPos[1 << kNumLogBits];
+ #endif
+
+ CLenPriceEnc lenEnc;
+ CLenPriceEnc repLenEnc;
+
+ COptimal opt[kNumOpts];
+
+ CSaveState saveState;
+
+ // BoolInt mf_Failure;
+ #ifndef Z7_ST
+ Byte pad2[128];
+ #endif
+};
+
+
+#define MFB (p->matchFinderBase)
+/*
+#ifndef Z7_ST
+#define MFB (p->matchFinderMt.MatchFinder)
+#endif
+*/
+
+// #define GET_CLzmaEnc_p CLzmaEnc *p = (CLzmaEnc*)(void *)p;
+// #define GET_const_CLzmaEnc_p const CLzmaEnc *p = (const CLzmaEnc*)(const void *)p;
+
+#define COPY_ARR(dest, src, arr) memcpy((dest)->arr, (src)->arr, sizeof((src)->arr));
+
+#define COPY_LZMA_ENC_STATE(d, s, p) \
+ (d)->state = (s)->state; \
+ COPY_ARR(d, s, reps) \
+ COPY_ARR(d, s, posAlignEncoder) \
+ COPY_ARR(d, s, isRep) \
+ COPY_ARR(d, s, isRepG0) \
+ COPY_ARR(d, s, isRepG1) \
+ COPY_ARR(d, s, isRepG2) \
+ COPY_ARR(d, s, isMatch) \
+ COPY_ARR(d, s, isRep0Long) \
+ COPY_ARR(d, s, posSlotEncoder) \
+ COPY_ARR(d, s, posEncoders) \
+ (d)->lenProbs = (s)->lenProbs; \
+ (d)->repLenProbs = (s)->repLenProbs; \
+ memcpy((d)->litProbs, (s)->litProbs, ((size_t)0x300 * sizeof(CLzmaProb)) << (p)->lclp);
+
+void LzmaEnc_SaveState(CLzmaEncHandle p)
+{
+ // GET_CLzmaEnc_p
+ CSaveState *v = &p->saveState;
+ COPY_LZMA_ENC_STATE(v, p, p)
+}
+
+void LzmaEnc_RestoreState(CLzmaEncHandle p)
+{
+ // GET_CLzmaEnc_p
+ const CSaveState *v = &p->saveState;
+ COPY_LZMA_ENC_STATE(p, v, p)
+}
+
+
+Z7_NO_INLINE
+SRes LzmaEnc_SetProps(CLzmaEncHandle p, const CLzmaEncProps *props2)
+{
+ // GET_CLzmaEnc_p
+ CLzmaEncProps props = *props2;
+ LzmaEncProps_Normalize(&props);
+
+ if (props.lc > LZMA_LC_MAX
+ || props.lp > LZMA_LP_MAX
+ || props.pb > LZMA_PB_MAX)
+ return SZ_ERROR_PARAM;
+
+
+ if (props.dictSize > kLzmaMaxHistorySize)
+ props.dictSize = kLzmaMaxHistorySize;
+
+ #ifndef LZMA_LOG_BSR
+ {
+ const UInt64 dict64 = props.dictSize;
+ if (dict64 > ((UInt64)1 << kDicLogSizeMaxCompress))
+ return SZ_ERROR_PARAM;
+ }
+ #endif
+
+ p->dictSize = props.dictSize;
+ {
+ unsigned fb = (unsigned)props.fb;
+ if (fb < 5)
+ fb = 5;
+ if (fb > LZMA_MATCH_LEN_MAX)
+ fb = LZMA_MATCH_LEN_MAX;
+ p->numFastBytes = fb;
+ }
+ p->lc = (unsigned)props.lc;
+ p->lp = (unsigned)props.lp;
+ p->pb = (unsigned)props.pb;
+ p->fastMode = (props.algo == 0);
+ // p->_maxMode = True;
+ MFB.btMode = (Byte)(props.btMode ? 1 : 0);
+ // MFB.btMode = (Byte)(props.btMode);
+ {
+ unsigned numHashBytes = 4;
+ if (props.btMode)
+ {
+ if (props.numHashBytes < 2) numHashBytes = 2;
+ else if (props.numHashBytes < 4) numHashBytes = (unsigned)props.numHashBytes;
+ }
+ if (props.numHashBytes >= 5) numHashBytes = 5;
+
+ MFB.numHashBytes = numHashBytes;
+ // MFB.numHashBytes_Min = 2;
+ MFB.numHashOutBits = (Byte)props.numHashOutBits;
+ }
+
+ MFB.cutValue = props.mc;
+
+ p->writeEndMark = (BoolInt)props.writeEndMark;
+
+ #ifndef Z7_ST
+ /*
+ if (newMultiThread != _multiThread)
+ {
+ ReleaseMatchFinder();
+ _multiThread = newMultiThread;
+ }
+ */
+ p->multiThread = (props.numThreads > 1);
+ p->matchFinderMt.btSync.affinity =
+ p->matchFinderMt.hashSync.affinity = props.affinity;
+ #endif
+
+ return SZ_OK;
+}
+
+
+void LzmaEnc_SetDataSize(CLzmaEncHandle p, UInt64 expectedDataSiize)
+{
+ // GET_CLzmaEnc_p
+ MFB.expectedDataSize = expectedDataSiize;
+}
+
+
+#define kState_Start 0
+#define kState_LitAfterMatch 4
+#define kState_LitAfterRep 5
+#define kState_MatchAfterLit 7
+#define kState_RepAfterLit 8
+
+static const Byte kLiteralNextStates[kNumStates] = {0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5};
+static const Byte kMatchNextStates[kNumStates] = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};
+static const Byte kRepNextStates[kNumStates] = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};
+static const Byte kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};
+
+#define IsLitState(s) ((s) < 7)
+#define GetLenToPosState2(len) (((len) < kNumLenToPosStates - 1) ? (len) : kNumLenToPosStates - 1)
+#define GetLenToPosState(len) (((len) < kNumLenToPosStates + 1) ? (len) - 2 : kNumLenToPosStates - 1)
+
+#define kInfinityPrice (1 << 30)
+
+static void RangeEnc_Construct(CRangeEnc *p)
+{
+ p->outStream = NULL;
+ p->bufBase = NULL;
+}
+
+#define RangeEnc_GetProcessed(p) ( (p)->processed + (size_t)((p)->buf - (p)->bufBase) + (p)->cacheSize)
+#define RangeEnc_GetProcessed_sizet(p) ((size_t)(p)->processed + (size_t)((p)->buf - (p)->bufBase) + (size_t)(p)->cacheSize)
+
+#define RC_BUF_SIZE (1 << 16)
+
+static int RangeEnc_Alloc(CRangeEnc *p, ISzAllocPtr alloc)
+{
+ if (!p->bufBase)
+ {
+ p->bufBase = (Byte *)ISzAlloc_Alloc(alloc, RC_BUF_SIZE);
+ if (!p->bufBase)
+ return 0;
+ p->bufLim = p->bufBase + RC_BUF_SIZE;
+ }
+ return 1;
+}
+
+static void RangeEnc_Free(CRangeEnc *p, ISzAllocPtr alloc)
+{
+ ISzAlloc_Free(alloc, p->bufBase);
+ p->bufBase = NULL;
+}
+
+static void RangeEnc_Init(CRangeEnc *p)
+{
+ p->range = 0xFFFFFFFF;
+ p->cache = 0;
+ p->low = 0;
+ p->cacheSize = 0;
+
+ p->buf = p->bufBase;
+
+ p->processed = 0;
+ p->res = SZ_OK;
+}
+
+Z7_NO_INLINE static void RangeEnc_FlushStream(CRangeEnc *p)
+{
+ const size_t num = (size_t)(p->buf - p->bufBase);
+ if (p->res == SZ_OK)
+ {
+ if (num != ISeqOutStream_Write(p->outStream, p->bufBase, num))
+ p->res = SZ_ERROR_WRITE;
+ }
+ p->processed += num;
+ p->buf = p->bufBase;
+}
+
+Z7_NO_INLINE static void Z7_FASTCALL RangeEnc_ShiftLow(CRangeEnc *p)
+{
+ UInt32 low = (UInt32)p->low;
+ unsigned high = (unsigned)(p->low >> 32);
+ p->low = (UInt32)(low << 8);
+ if (low < (UInt32)0xFF000000 || high != 0)
+ {
+ {
+ Byte *buf = p->buf;
+ *buf++ = (Byte)(p->cache + high);
+ p->cache = (unsigned)(low >> 24);
+ p->buf = buf;
+ if (buf == p->bufLim)
+ RangeEnc_FlushStream(p);
+ if (p->cacheSize == 0)
+ return;
+ }
+ high += 0xFF;
+ for (;;)
+ {
+ Byte *buf = p->buf;
+ *buf++ = (Byte)(high);
+ p->buf = buf;
+ if (buf == p->bufLim)
+ RangeEnc_FlushStream(p);
+ if (--p->cacheSize == 0)
+ return;
+ }
+ }
+ p->cacheSize++;
+}
+
+static void RangeEnc_FlushData(CRangeEnc *p)
+{
+ int i;
+ for (i = 0; i < 5; i++)
+ RangeEnc_ShiftLow(p);
+}
+
+#define RC_NORM(p) if (range < kTopValue) { range <<= 8; RangeEnc_ShiftLow(p); }
+
+#define RC_BIT_PRE(p, prob) \
+ ttt = *(prob); \
+ newBound = (range >> kNumBitModelTotalBits) * ttt;
+
+// #define Z7_LZMA_ENC_USE_BRANCH
+
+#ifdef Z7_LZMA_ENC_USE_BRANCH
+
+#define RC_BIT(p, prob, bit) { \
+ RC_BIT_PRE(p, prob) \
+ if (bit == 0) { range = newBound; ttt += (kBitModelTotal - ttt) >> kNumMoveBits; } \
+ else { (p)->low += newBound; range -= newBound; ttt -= ttt >> kNumMoveBits; } \
+ *(prob) = (CLzmaProb)ttt; \
+ RC_NORM(p) \
+ }
+
+#else
+
+#define RC_BIT(p, prob, bit) { \
+ UInt32 mask; \
+ RC_BIT_PRE(p, prob) \
+ mask = 0 - (UInt32)bit; \
+ range &= mask; \
+ mask &= newBound; \
+ range -= mask; \
+ (p)->low += mask; \
+ mask = (UInt32)bit - 1; \
+ range += newBound & mask; \
+ mask &= (kBitModelTotal - ((1 << kNumMoveBits) - 1)); \
+ mask += ((1 << kNumMoveBits) - 1); \
+ ttt += (UInt32)((Int32)(mask - ttt) >> kNumMoveBits); \
+ *(prob) = (CLzmaProb)ttt; \
+ RC_NORM(p) \
+ }
+
+#endif
+
+
+
+
+#define RC_BIT_0_BASE(p, prob) \
+ range = newBound; *(prob) = (CLzmaProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits));
+
+#define RC_BIT_1_BASE(p, prob) \
+ range -= newBound; (p)->low += newBound; *(prob) = (CLzmaProb)(ttt - (ttt >> kNumMoveBits)); \
+
+#define RC_BIT_0(p, prob) \
+ RC_BIT_0_BASE(p, prob) \
+ RC_NORM(p)
+
+#define RC_BIT_1(p, prob) \
+ RC_BIT_1_BASE(p, prob) \
+ RC_NORM(p)
+
+static void RangeEnc_EncodeBit_0(CRangeEnc *p, CLzmaProb *prob)
+{
+ UInt32 range, ttt, newBound;
+ range = p->range;
+ RC_BIT_PRE(p, prob)
+ RC_BIT_0(p, prob)
+ p->range = range;
+}
+
+static void LitEnc_Encode(CRangeEnc *p, CLzmaProb *probs, UInt32 sym)
+{
+ UInt32 range = p->range;
+ sym |= 0x100;
+ do
+ {
+ UInt32 ttt, newBound;
+ // RangeEnc_EncodeBit(p, probs + (sym >> 8), (sym >> 7) & 1);
+ CLzmaProb *prob = probs + (sym >> 8);
+ UInt32 bit = (sym >> 7) & 1;
+ sym <<= 1;
+ RC_BIT(p, prob, bit)
+ }
+ while (sym < 0x10000);
+ p->range = range;
+}
+
+static void LitEnc_EncodeMatched(CRangeEnc *p, CLzmaProb *probs, UInt32 sym, UInt32 matchByte)
+{
+ UInt32 range = p->range;
+ UInt32 offs = 0x100;
+ sym |= 0x100;
+ do
+ {
+ UInt32 ttt, newBound;
+ CLzmaProb *prob;
+ UInt32 bit;
+ matchByte <<= 1;
+ // RangeEnc_EncodeBit(p, probs + (offs + (matchByte & offs) + (sym >> 8)), (sym >> 7) & 1);
+ prob = probs + (offs + (matchByte & offs) + (sym >> 8));
+ bit = (sym >> 7) & 1;
+ sym <<= 1;
+ offs &= ~(matchByte ^ sym);
+ RC_BIT(p, prob, bit)
+ }
+ while (sym < 0x10000);
+ p->range = range;
+}
+
+
+
+static void LzmaEnc_InitPriceTables(CProbPrice *ProbPrices)
+{
+ UInt32 i;
+ for (i = 0; i < (kBitModelTotal >> kNumMoveReducingBits); i++)
+ {
+ const unsigned kCyclesBits = kNumBitPriceShiftBits;
+ UInt32 w = (i << kNumMoveReducingBits) + (1 << (kNumMoveReducingBits - 1));
+ unsigned bitCount = 0;
+ unsigned j;
+ for (j = 0; j < kCyclesBits; j++)
+ {
+ w = w * w;
+ bitCount <<= 1;
+ while (w >= ((UInt32)1 << 16))
+ {
+ w >>= 1;
+ bitCount++;
+ }
+ }
+ ProbPrices[i] = (CProbPrice)(((unsigned)kNumBitModelTotalBits << kCyclesBits) - 15 - bitCount);
+ // printf("\n%3d: %5d", i, ProbPrices[i]);
+ }
+}
+
+
+#define GET_PRICE(prob, bit) \
+ p->ProbPrices[((prob) ^ (unsigned)(((-(int)(bit))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits]
+
+#define GET_PRICEa(prob, bit) \
+ ProbPrices[((prob) ^ (unsigned)((-((int)(bit))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits]
+
+#define GET_PRICE_0(prob) p->ProbPrices[(prob) >> kNumMoveReducingBits]
+#define GET_PRICE_1(prob) p->ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]
+
+#define GET_PRICEa_0(prob) ProbPrices[(prob) >> kNumMoveReducingBits]
+#define GET_PRICEa_1(prob) ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]
+
+
+static UInt32 LitEnc_GetPrice(const CLzmaProb *probs, UInt32 sym, const CProbPrice *ProbPrices)
+{
+ UInt32 price = 0;
+ sym |= 0x100;
+ do
+ {
+ unsigned bit = sym & 1;
+ sym >>= 1;
+ price += GET_PRICEa(probs[sym], bit);
+ }
+ while (sym >= 2);
+ return price;
+}
+
+
+static UInt32 LitEnc_Matched_GetPrice(const CLzmaProb *probs, UInt32 sym, UInt32 matchByte, const CProbPrice *ProbPrices)
+{
+ UInt32 price = 0;
+ UInt32 offs = 0x100;
+ sym |= 0x100;
+ do
+ {
+ matchByte <<= 1;
+ price += GET_PRICEa(probs[offs + (matchByte & offs) + (sym >> 8)], (sym >> 7) & 1);
+ sym <<= 1;
+ offs &= ~(matchByte ^ sym);
+ }
+ while (sym < 0x10000);
+ return price;
+}
+
+
+static void RcTree_ReverseEncode(CRangeEnc *rc, CLzmaProb *probs, unsigned numBits, unsigned sym)
+{
+ UInt32 range = rc->range;
+ unsigned m = 1;
+ do
+ {
+ UInt32 ttt, newBound;
+ unsigned bit = sym & 1;
+ // RangeEnc_EncodeBit(rc, probs + m, bit);
+ sym >>= 1;
+ RC_BIT(rc, probs + m, bit)
+ m = (m << 1) | bit;
+ }
+ while (--numBits);
+ rc->range = range;
+}
+
+
+
+static void LenEnc_Init(CLenEnc *p)
+{
+ unsigned i;
+ for (i = 0; i < (LZMA_NUM_PB_STATES_MAX << (kLenNumLowBits + 1)); i++)
+ p->low[i] = kProbInitValue;
+ for (i = 0; i < kLenNumHighSymbols; i++)
+ p->high[i] = kProbInitValue;
+}
+
+static void LenEnc_Encode(CLenEnc *p, CRangeEnc *rc, unsigned sym, unsigned posState)
+{
+ UInt32 range, ttt, newBound;
+ CLzmaProb *probs = p->low;
+ range = rc->range;
+ RC_BIT_PRE(rc, probs)
+ if (sym >= kLenNumLowSymbols)
+ {
+ RC_BIT_1(rc, probs)
+ probs += kLenNumLowSymbols;
+ RC_BIT_PRE(rc, probs)
+ if (sym >= kLenNumLowSymbols * 2)
+ {
+ RC_BIT_1(rc, probs)
+ rc->range = range;
+ // RcTree_Encode(rc, p->high, kLenNumHighBits, sym - kLenNumLowSymbols * 2);
+ LitEnc_Encode(rc, p->high, sym - kLenNumLowSymbols * 2);
+ return;
+ }
+ sym -= kLenNumLowSymbols;
+ }
+
+ // RcTree_Encode(rc, probs + (posState << kLenNumLowBits), kLenNumLowBits, sym);
+ {
+ unsigned m;
+ unsigned bit;
+ RC_BIT_0(rc, probs)
+ probs += (posState << (1 + kLenNumLowBits));
+ bit = (sym >> 2) ; RC_BIT(rc, probs + 1, bit) m = (1 << 1) + bit;
+ bit = (sym >> 1) & 1; RC_BIT(rc, probs + m, bit) m = (m << 1) + bit;
+ bit = sym & 1; RC_BIT(rc, probs + m, bit)
+ rc->range = range;
+ }
+}
+
+static void SetPrices_3(const CLzmaProb *probs, UInt32 startPrice, UInt32 *prices, const CProbPrice *ProbPrices)
+{
+ unsigned i;
+ for (i = 0; i < 8; i += 2)
+ {
+ UInt32 price = startPrice;
+ UInt32 prob;
+ price += GET_PRICEa(probs[1 ], (i >> 2));
+ price += GET_PRICEa(probs[2 + (i >> 2)], (i >> 1) & 1);
+ prob = probs[4 + (i >> 1)];
+ prices[i ] = price + GET_PRICEa_0(prob);
+ prices[i + 1] = price + GET_PRICEa_1(prob);
+ }
+}
+
+
+Z7_NO_INLINE static void Z7_FASTCALL LenPriceEnc_UpdateTables(
+ CLenPriceEnc *p,
+ unsigned numPosStates,
+ const CLenEnc *enc,
+ const CProbPrice *ProbPrices)
+{
+ UInt32 b;
+
+ {
+ unsigned prob = enc->low[0];
+ UInt32 a, c;
+ unsigned posState;
+ b = GET_PRICEa_1(prob);
+ a = GET_PRICEa_0(prob);
+ c = b + GET_PRICEa_0(enc->low[kLenNumLowSymbols]);
+ for (posState = 0; posState < numPosStates; posState++)
+ {
+ UInt32 *prices = p->prices[posState];
+ const CLzmaProb *probs = enc->low + (posState << (1 + kLenNumLowBits));
+ SetPrices_3(probs, a, prices, ProbPrices);
+ SetPrices_3(probs + kLenNumLowSymbols, c, prices + kLenNumLowSymbols, ProbPrices);
+ }
+ }
+
+ /*
+ {
+ unsigned i;
+ UInt32 b;
+ a = GET_PRICEa_0(enc->low[0]);
+ for (i = 0; i < kLenNumLowSymbols; i++)
+ p->prices2[i] = a;
+ a = GET_PRICEa_1(enc->low[0]);
+ b = a + GET_PRICEa_0(enc->low[kLenNumLowSymbols]);
+ for (i = kLenNumLowSymbols; i < kLenNumLowSymbols * 2; i++)
+ p->prices2[i] = b;
+ a += GET_PRICEa_1(enc->low[kLenNumLowSymbols]);
+ }
+ */
+
+ // p->counter = numSymbols;
+ // p->counter = 64;
+
+ {
+ unsigned i = p->tableSize;
+
+ if (i > kLenNumLowSymbols * 2)
+ {
+ const CLzmaProb *probs = enc->high;
+ UInt32 *prices = p->prices[0] + kLenNumLowSymbols * 2;
+ i -= kLenNumLowSymbols * 2 - 1;
+ i >>= 1;
+ b += GET_PRICEa_1(enc->low[kLenNumLowSymbols]);
+ do
+ {
+ /*
+ p->prices2[i] = a +
+ // RcTree_GetPrice(enc->high, kLenNumHighBits, i - kLenNumLowSymbols * 2, ProbPrices);
+ LitEnc_GetPrice(probs, i - kLenNumLowSymbols * 2, ProbPrices);
+ */
+ // UInt32 price = a + RcTree_GetPrice(probs, kLenNumHighBits - 1, sym, ProbPrices);
+ unsigned sym = --i + (1 << (kLenNumHighBits - 1));
+ UInt32 price = b;
+ do
+ {
+ const unsigned bit = sym & 1;
+ sym >>= 1;
+ price += GET_PRICEa(probs[sym], bit);
+ }
+ while (sym >= 2);
+
+ {
+ const unsigned prob = probs[(size_t)i + (1 << (kLenNumHighBits - 1))];
+ prices[(size_t)i * 2 ] = price + GET_PRICEa_0(prob);
+ prices[(size_t)i * 2 + 1] = price + GET_PRICEa_1(prob);
+ }
+ }
+ while (i);
+
+ {
+ unsigned posState;
+ const size_t num = (p->tableSize - kLenNumLowSymbols * 2) * sizeof(p->prices[0][0]);
+ for (posState = 1; posState < numPosStates; posState++)
+ memcpy(p->prices[posState] + kLenNumLowSymbols * 2, p->prices[0] + kLenNumLowSymbols * 2, num);
+ }
+ }
+ }
+}
+
+/*
+ #ifdef SHOW_STAT
+ g_STAT_OFFSET += num;
+ printf("\n MovePos %u", num);
+ #endif
+*/
+
+#define MOVE_POS(p, num) { \
+ p->additionalOffset += (num); \
+ p->matchFinder.Skip(p->matchFinderObj, (UInt32)(num)); }
+
+
+static unsigned ReadMatchDistances(CLzmaEnc *p, unsigned *numPairsRes)
+{
+ unsigned numPairs;
+
+ p->additionalOffset++;
+ p->numAvail = p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);
+ {
+ const UInt32 *d = p->matchFinder.GetMatches(p->matchFinderObj, p->matches);
+ // if (!d) { p->mf_Failure = True; *numPairsRes = 0; return 0; }
+ numPairs = (unsigned)(d - p->matches);
+ }
+ *numPairsRes = numPairs;
+
+ #ifdef SHOW_STAT
+ printf("\n i = %u numPairs = %u ", g_STAT_OFFSET, numPairs / 2);
+ g_STAT_OFFSET++;
+ {
+ unsigned i;
+ for (i = 0; i < numPairs; i += 2)
+ printf("%2u %6u | ", p->matches[i], p->matches[i + 1]);
+ }
+ #endif
+
+ if (numPairs == 0)
+ return 0;
+ {
+ const unsigned len = p->matches[(size_t)numPairs - 2];
+ if (len != p->numFastBytes)
+ return len;
+ {
+ UInt32 numAvail = p->numAvail;
+ if (numAvail > LZMA_MATCH_LEN_MAX)
+ numAvail = LZMA_MATCH_LEN_MAX;
+ {
+ const Byte *p1 = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
+ const Byte *p2 = p1 + len;
+ const ptrdiff_t dif = (ptrdiff_t)-1 - (ptrdiff_t)p->matches[(size_t)numPairs - 1];
+ const Byte *lim = p1 + numAvail;
+ for (; p2 != lim && *p2 == p2[dif]; p2++)
+ {}
+ return (unsigned)(p2 - p1);
+ }
+ }
+ }
+}
+
+#define MARK_LIT ((UInt32)(Int32)-1)
+
+#define MakeAs_Lit(p) { (p)->dist = MARK_LIT; (p)->extra = 0; }
+#define MakeAs_ShortRep(p) { (p)->dist = 0; (p)->extra = 0; }
+#define IsShortRep(p) ((p)->dist == 0)
+
+
+#define GetPrice_ShortRep(p, state, posState) \
+ ( GET_PRICE_0(p->isRepG0[state]) + GET_PRICE_0(p->isRep0Long[state][posState]))
+
+#define GetPrice_Rep_0(p, state, posState) ( \
+ GET_PRICE_1(p->isMatch[state][posState]) \
+ + GET_PRICE_1(p->isRep0Long[state][posState])) \
+ + GET_PRICE_1(p->isRep[state]) \
+ + GET_PRICE_0(p->isRepG0[state])
+
+Z7_FORCE_INLINE
+static UInt32 GetPrice_PureRep(const CLzmaEnc *p, unsigned repIndex, size_t state, size_t posState)
+{
+ UInt32 price;
+ UInt32 prob = p->isRepG0[state];
+ if (repIndex == 0)
+ {
+ price = GET_PRICE_0(prob);
+ price += GET_PRICE_1(p->isRep0Long[state][posState]);
+ }
+ else
+ {
+ price = GET_PRICE_1(prob);
+ prob = p->isRepG1[state];
+ if (repIndex == 1)
+ price += GET_PRICE_0(prob);
+ else
+ {
+ price += GET_PRICE_1(prob);
+ price += GET_PRICE(p->isRepG2[state], repIndex - 2);
+ }
+ }
+ return price;
+}
+
+
+static unsigned Backward(CLzmaEnc *p, unsigned cur)
+{
+ unsigned wr = cur + 1;
+ p->optEnd = wr;
+
+ for (;;)
+ {
+ UInt32 dist = p->opt[cur].dist;
+ unsigned len = (unsigned)p->opt[cur].len;
+ unsigned extra = (unsigned)p->opt[cur].extra;
+ cur -= len;
+
+ if (extra)
+ {
+ wr--;
+ p->opt[wr].len = (UInt32)len;
+ cur -= extra;
+ len = extra;
+ if (extra == 1)
+ {
+ p->opt[wr].dist = dist;
+ dist = MARK_LIT;
+ }
+ else
+ {
+ p->opt[wr].dist = 0;
+ len--;
+ wr--;
+ p->opt[wr].dist = MARK_LIT;
+ p->opt[wr].len = 1;
+ }
+ }
+
+ if (cur == 0)
+ {
+ p->backRes = dist;
+ p->optCur = wr;
+ return len;
+ }
+
+ wr--;
+ p->opt[wr].dist = dist;
+ p->opt[wr].len = (UInt32)len;
+ }
+}
+
+
+
+#define LIT_PROBS(pos, prevByte) \
+ (p->litProbs + (UInt32)3 * (((((pos) << 8) + (prevByte)) & p->lpMask) << p->lc))
+
+
+static unsigned GetOptimum(CLzmaEnc *p, UInt32 position)
+{
+ unsigned last, cur;
+ UInt32 reps[LZMA_NUM_REPS];
+ unsigned repLens[LZMA_NUM_REPS];
+ UInt32 *matches;
+
+ {
+ UInt32 numAvail;
+ unsigned numPairs, mainLen, repMaxIndex, i, posState;
+ UInt32 matchPrice, repMatchPrice;
+ const Byte *data;
+ Byte curByte, matchByte;
+
+ p->optCur = p->optEnd = 0;
+
+ if (p->additionalOffset == 0)
+ mainLen = ReadMatchDistances(p, &numPairs);
+ else
+ {
+ mainLen = p->longestMatchLen;
+ numPairs = p->numPairs;
+ }
+
+ numAvail = p->numAvail;
+ if (numAvail < 2)
+ {
+ p->backRes = MARK_LIT;
+ return 1;
+ }
+ if (numAvail > LZMA_MATCH_LEN_MAX)
+ numAvail = LZMA_MATCH_LEN_MAX;
+
+ data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
+ repMaxIndex = 0;
+
+ for (i = 0; i < LZMA_NUM_REPS; i++)
+ {
+ unsigned len;
+ const Byte *data2;
+ reps[i] = p->reps[i];
+ data2 = data - reps[i];
+ if (data[0] != data2[0] || data[1] != data2[1])
+ {
+ repLens[i] = 0;
+ continue;
+ }
+ for (len = 2; len < numAvail && data[len] == data2[len]; len++)
+ {}
+ repLens[i] = len;
+ if (len > repLens[repMaxIndex])
+ repMaxIndex = i;
+ if (len == LZMA_MATCH_LEN_MAX) // 21.03 : optimization
+ break;
+ }
+
+ if (repLens[repMaxIndex] >= p->numFastBytes)
+ {
+ unsigned len;
+ p->backRes = (UInt32)repMaxIndex;
+ len = repLens[repMaxIndex];
+ MOVE_POS(p, len - 1)
+ return len;
+ }
+
+ matches = p->matches;
+ #define MATCHES matches
+ // #define MATCHES p->matches
+
+ if (mainLen >= p->numFastBytes)
+ {
+ p->backRes = MATCHES[(size_t)numPairs - 1] + LZMA_NUM_REPS;
+ MOVE_POS(p, mainLen - 1)
+ return mainLen;
+ }
+
+ curByte = *data;
+ matchByte = *(data - reps[0]);
+
+ last = repLens[repMaxIndex];
+ if (last <= mainLen)
+ last = mainLen;
+
+ if (last < 2 && curByte != matchByte)
+ {
+ p->backRes = MARK_LIT;
+ return 1;
+ }
+
+ p->opt[0].state = (CState)p->state;
+
+ posState = (position & p->pbMask);
+
+ {
+ const CLzmaProb *probs = LIT_PROBS(position, *(data - 1));
+ p->opt[1].price = GET_PRICE_0(p->isMatch[p->state][posState]) +
+ (!IsLitState(p->state) ?
+ LitEnc_Matched_GetPrice(probs, curByte, matchByte, p->ProbPrices) :
+ LitEnc_GetPrice(probs, curByte, p->ProbPrices));
+ }
+
+ MakeAs_Lit(&p->opt[1])
+
+ matchPrice = GET_PRICE_1(p->isMatch[p->state][posState]);
+ repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[p->state]);
+
+ // 18.06
+ if (matchByte == curByte && repLens[0] == 0)
+ {
+ UInt32 shortRepPrice = repMatchPrice + GetPrice_ShortRep(p, p->state, posState);
+ if (shortRepPrice < p->opt[1].price)
+ {
+ p->opt[1].price = shortRepPrice;
+ MakeAs_ShortRep(&p->opt[1])
+ }
+ if (last < 2)
+ {
+ p->backRes = p->opt[1].dist;
+ return 1;
+ }
+ }
+
+ p->opt[1].len = 1;
+
+ p->opt[0].reps[0] = reps[0];
+ p->opt[0].reps[1] = reps[1];
+ p->opt[0].reps[2] = reps[2];
+ p->opt[0].reps[3] = reps[3];
+
+ // ---------- REP ----------
+
+ for (i = 0; i < LZMA_NUM_REPS; i++)
+ {
+ unsigned repLen = repLens[i];
+ UInt32 price;
+ if (repLen < 2)
+ continue;
+ price = repMatchPrice + GetPrice_PureRep(p, i, p->state, posState);
+ do
+ {
+ UInt32 price2 = price + GET_PRICE_LEN(&p->repLenEnc, posState, repLen);
+ COptimal *opt = &p->opt[repLen];
+ if (price2 < opt->price)
+ {
+ opt->price = price2;
+ opt->len = (UInt32)repLen;
+ opt->dist = (UInt32)i;
+ opt->extra = 0;
+ }
+ }
+ while (--repLen >= 2);
+ }
+
+
+ // ---------- MATCH ----------
+ {
+ unsigned len = repLens[0] + 1;
+ if (len <= mainLen)
+ {
+ unsigned offs = 0;
+ UInt32 normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[p->state]);
+
+ if (len < 2)
+ len = 2;
+ else
+ while (len > MATCHES[offs])
+ offs += 2;
+
+ for (; ; len++)
+ {
+ COptimal *opt;
+ UInt32 dist = MATCHES[(size_t)offs + 1];
+ UInt32 price = normalMatchPrice + GET_PRICE_LEN(&p->lenEnc, posState, len);
+ unsigned lenToPosState = GetLenToPosState(len);
+
+ if (dist < kNumFullDistances)
+ price += p->distancesPrices[lenToPosState][dist & (kNumFullDistances - 1)];
+ else
+ {
+ unsigned slot;
+ GetPosSlot2(dist, slot)
+ price += p->alignPrices[dist & kAlignMask];
+ price += p->posSlotPrices[lenToPosState][slot];
+ }
+
+ opt = &p->opt[len];
+
+ if (price < opt->price)
+ {
+ opt->price = price;
+ opt->len = (UInt32)len;
+ opt->dist = dist + LZMA_NUM_REPS;
+ opt->extra = 0;
+ }
+
+ if (len == MATCHES[offs])
+ {
+ offs += 2;
+ if (offs == numPairs)
+ break;
+ }
+ }
+ }
+ }
+
+
+ cur = 0;
+
+ #ifdef SHOW_STAT2
+ /* if (position >= 0) */
+ {
+ unsigned i;
+ printf("\n pos = %4X", position);
+ for (i = cur; i <= last; i++)
+ printf("\nprice[%4X] = %u", position - cur + i, p->opt[i].price);
+ }
+ #endif
+ }
+
+
+
+ // ---------- Optimal Parsing ----------
+
+ for (;;)
+ {
+ unsigned numAvail;
+ UInt32 numAvailFull;
+ unsigned newLen, numPairs, prev, state, posState, startLen;
+ UInt32 litPrice, matchPrice, repMatchPrice;
+ BoolInt nextIsLit;
+ Byte curByte, matchByte;
+ const Byte *data;
+ COptimal *curOpt, *nextOpt;
+
+ if (++cur == last)
+ break;
+
+ // 18.06
+ if (cur >= kNumOpts - 64)
+ {
+ unsigned j, best;
+ UInt32 price = p->opt[cur].price;
+ best = cur;
+ for (j = cur + 1; j <= last; j++)
+ {
+ UInt32 price2 = p->opt[j].price;
+ if (price >= price2)
+ {
+ price = price2;
+ best = j;
+ }
+ }
+ {
+ unsigned delta = best - cur;
+ if (delta != 0)
+ {
+ MOVE_POS(p, delta)
+ }
+ }
+ cur = best;
+ break;
+ }
+
+ newLen = ReadMatchDistances(p, &numPairs);
+
+ if (newLen >= p->numFastBytes)
+ {
+ p->numPairs = numPairs;
+ p->longestMatchLen = newLen;
+ break;
+ }
+
+ curOpt = &p->opt[cur];
+
+ position++;
+
+ // we need that check here, if skip_items in p->opt are possible
+ /*
+ if (curOpt->price >= kInfinityPrice)
+ continue;
+ */
+
+ prev = cur - curOpt->len;
+
+ if (curOpt->len == 1)
+ {
+ state = (unsigned)p->opt[prev].state;
+ if (IsShortRep(curOpt))
+ state = kShortRepNextStates[state];
+ else
+ state = kLiteralNextStates[state];
+ }
+ else
+ {
+ const COptimal *prevOpt;
+ UInt32 b0;
+ UInt32 dist = curOpt->dist;
+
+ if (curOpt->extra)
+ {
+ prev -= (unsigned)curOpt->extra;
+ state = kState_RepAfterLit;
+ if (curOpt->extra == 1)
+ state = (dist < LZMA_NUM_REPS ? kState_RepAfterLit : kState_MatchAfterLit);
+ }
+ else
+ {
+ state = (unsigned)p->opt[prev].state;
+ if (dist < LZMA_NUM_REPS)
+ state = kRepNextStates[state];
+ else
+ state = kMatchNextStates[state];
+ }
+
+ prevOpt = &p->opt[prev];
+ b0 = prevOpt->reps[0];
+
+ if (dist < LZMA_NUM_REPS)
+ {
+ if (dist == 0)
+ {
+ reps[0] = b0;
+ reps[1] = prevOpt->reps[1];
+ reps[2] = prevOpt->reps[2];
+ reps[3] = prevOpt->reps[3];
+ }
+ else
+ {
+ reps[1] = b0;
+ b0 = prevOpt->reps[1];
+ if (dist == 1)
+ {
+ reps[0] = b0;
+ reps[2] = prevOpt->reps[2];
+ reps[3] = prevOpt->reps[3];
+ }
+ else
+ {
+ reps[2] = b0;
+ reps[0] = prevOpt->reps[dist];
+ reps[3] = prevOpt->reps[dist ^ 1];
+ }
+ }
+ }
+ else
+ {
+ reps[0] = (dist - LZMA_NUM_REPS + 1);
+ reps[1] = b0;
+ reps[2] = prevOpt->reps[1];
+ reps[3] = prevOpt->reps[2];
+ }
+ }
+
+ curOpt->state = (CState)state;
+ curOpt->reps[0] = reps[0];
+ curOpt->reps[1] = reps[1];
+ curOpt->reps[2] = reps[2];
+ curOpt->reps[3] = reps[3];
+
+ data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
+ curByte = *data;
+ matchByte = *(data - reps[0]);
+
+ posState = (position & p->pbMask);
+
+ /*
+ The order of Price checks:
+ < LIT
+ <= SHORT_REP
+ < LIT : REP_0
+ < REP [ : LIT : REP_0 ]
+ < MATCH [ : LIT : REP_0 ]
+ */
+
+ {
+ UInt32 curPrice = curOpt->price;
+ unsigned prob = p->isMatch[state][posState];
+ matchPrice = curPrice + GET_PRICE_1(prob);
+ litPrice = curPrice + GET_PRICE_0(prob);
+ }
+
+ nextOpt = &p->opt[(size_t)cur + 1];
+ nextIsLit = False;
+
+ // here we can allow skip_items in p->opt, if we don't check (nextOpt->price < kInfinityPrice)
+ // 18.new.06
+ if ((nextOpt->price < kInfinityPrice
+ // && !IsLitState(state)
+ && matchByte == curByte)
+ || litPrice > nextOpt->price
+ )
+ litPrice = 0;
+ else
+ {
+ const CLzmaProb *probs = LIT_PROBS(position, *(data - 1));
+ litPrice += (!IsLitState(state) ?
+ LitEnc_Matched_GetPrice(probs, curByte, matchByte, p->ProbPrices) :
+ LitEnc_GetPrice(probs, curByte, p->ProbPrices));
+
+ if (litPrice < nextOpt->price)
+ {
+ nextOpt->price = litPrice;
+ nextOpt->len = 1;
+ MakeAs_Lit(nextOpt)
+ nextIsLit = True;
+ }
+ }
+
+ repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[state]);
+
+ numAvailFull = p->numAvail;
+ {
+ unsigned temp = kNumOpts - 1 - cur;
+ if (numAvailFull > temp)
+ numAvailFull = (UInt32)temp;
+ }
+
+ // 18.06
+ // ---------- SHORT_REP ----------
+ if (IsLitState(state)) // 18.new
+ if (matchByte == curByte)
+ if (repMatchPrice < nextOpt->price) // 18.new
+ // if (numAvailFull < 2 || data[1] != *(data - reps[0] + 1))
+ if (
+ // nextOpt->price >= kInfinityPrice ||
+ nextOpt->len < 2 // we can check nextOpt->len, if skip items are not allowed in p->opt
+ || (nextOpt->dist != 0
+ // && nextOpt->extra <= 1 // 17.old
+ )
+ )
+ {
+ UInt32 shortRepPrice = repMatchPrice + GetPrice_ShortRep(p, state, posState);
+ // if (shortRepPrice <= nextOpt->price) // 17.old
+ if (shortRepPrice < nextOpt->price) // 18.new
+ {
+ nextOpt->price = shortRepPrice;
+ nextOpt->len = 1;
+ MakeAs_ShortRep(nextOpt)
+ nextIsLit = False;
+ }
+ }
+
+ if (numAvailFull < 2)
+ continue;
+ numAvail = (numAvailFull <= p->numFastBytes ? numAvailFull : p->numFastBytes);
+
+ // numAvail <= p->numFastBytes
+
+ // ---------- LIT : REP_0 ----------
+
+ if (!nextIsLit
+ && litPrice != 0 // 18.new
+ && matchByte != curByte
+ && numAvailFull > 2)
+ {
+ const Byte *data2 = data - reps[0];
+ if (data[1] == data2[1] && data[2] == data2[2])
+ {
+ unsigned len;
+ unsigned limit = p->numFastBytes + 1;
+ if (limit > numAvailFull)
+ limit = numAvailFull;
+ for (len = 3; len < limit && data[len] == data2[len]; len++)
+ {}
+
+ {
+ unsigned state2 = kLiteralNextStates[state];
+ unsigned posState2 = (position + 1) & p->pbMask;
+ UInt32 price = litPrice + GetPrice_Rep_0(p, state2, posState2);
+ {
+ unsigned offset = cur + len;
+
+ if (last < offset)
+ last = offset;
+
+ // do
+ {
+ UInt32 price2;
+ COptimal *opt;
+ len--;
+ // price2 = price + GetPrice_Len_Rep_0(p, len, state2, posState2);
+ price2 = price + GET_PRICE_LEN(&p->repLenEnc, posState2, len);
+
+ opt = &p->opt[offset];
+ // offset--;
+ if (price2 < opt->price)
+ {
+ opt->price = price2;
+ opt->len = (UInt32)len;
+ opt->dist = 0;
+ opt->extra = 1;
+ }
+ }
+ // while (len >= 3);
+ }
+ }
+ }
+ }
+
+ startLen = 2; /* speed optimization */
+
+ {
+ // ---------- REP ----------
+ unsigned repIndex = 0; // 17.old
+ // unsigned repIndex = IsLitState(state) ? 0 : 1; // 18.notused
+ for (; repIndex < LZMA_NUM_REPS; repIndex++)
+ {
+ unsigned len;
+ UInt32 price;
+ const Byte *data2 = data - reps[repIndex];
+ if (data[0] != data2[0] || data[1] != data2[1])
+ continue;
+
+ for (len = 2; len < numAvail && data[len] == data2[len]; len++)
+ {}
+
+ // if (len < startLen) continue; // 18.new: speed optimization
+
+ {
+ unsigned offset = cur + len;
+ if (last < offset)
+ last = offset;
+ }
+ {
+ unsigned len2 = len;
+ price = repMatchPrice + GetPrice_PureRep(p, repIndex, state, posState);
+ do
+ {
+ UInt32 price2 = price + GET_PRICE_LEN(&p->repLenEnc, posState, len2);
+ COptimal *opt = &p->opt[cur + len2];
+ if (price2 < opt->price)
+ {
+ opt->price = price2;
+ opt->len = (UInt32)len2;
+ opt->dist = (UInt32)repIndex;
+ opt->extra = 0;
+ }
+ }
+ while (--len2 >= 2);
+ }
+
+ if (repIndex == 0) startLen = len + 1; // 17.old
+ // startLen = len + 1; // 18.new
+
+ /* if (_maxMode) */
+ {
+ // ---------- REP : LIT : REP_0 ----------
+ // numFastBytes + 1 + numFastBytes
+
+ unsigned len2 = len + 1;
+ unsigned limit = len2 + p->numFastBytes;
+ if (limit > numAvailFull)
+ limit = numAvailFull;
+
+ len2 += 2;
+ if (len2 <= limit)
+ if (data[len2 - 2] == data2[len2 - 2])
+ if (data[len2 - 1] == data2[len2 - 1])
+ {
+ unsigned state2 = kRepNextStates[state];
+ unsigned posState2 = (position + len) & p->pbMask;
+ price += GET_PRICE_LEN(&p->repLenEnc, posState, len)
+ + GET_PRICE_0(p->isMatch[state2][posState2])
+ + LitEnc_Matched_GetPrice(LIT_PROBS(position + len, data[(size_t)len - 1]),
+ data[len], data2[len], p->ProbPrices);
+
+ // state2 = kLiteralNextStates[state2];
+ state2 = kState_LitAfterRep;
+ posState2 = (posState2 + 1) & p->pbMask;
+
+
+ price += GetPrice_Rep_0(p, state2, posState2);
+
+ for (; len2 < limit && data[len2] == data2[len2]; len2++)
+ {}
+
+ len2 -= len;
+ // if (len2 >= 3)
+ {
+ {
+ unsigned offset = cur + len + len2;
+
+ if (last < offset)
+ last = offset;
+ // do
+ {
+ UInt32 price2;
+ COptimal *opt;
+ len2--;
+ // price2 = price + GetPrice_Len_Rep_0(p, len2, state2, posState2);
+ price2 = price + GET_PRICE_LEN(&p->repLenEnc, posState2, len2);
+
+ opt = &p->opt[offset];
+ // offset--;
+ if (price2 < opt->price)
+ {
+ opt->price = price2;
+ opt->len = (UInt32)len2;
+ opt->extra = (CExtra)(len + 1);
+ opt->dist = (UInt32)repIndex;
+ }
+ }
+ // while (len2 >= 3);
+ }
+ }
+ }
+ }
+ }
+ }
+
+
+ // ---------- MATCH ----------
+ /* for (unsigned len = 2; len <= newLen; len++) */
+ if (newLen > numAvail)
+ {
+ newLen = numAvail;
+ for (numPairs = 0; newLen > MATCHES[numPairs]; numPairs += 2);
+ MATCHES[numPairs] = (UInt32)newLen;
+ numPairs += 2;
+ }
+
+ // startLen = 2; /* speed optimization */
+
+ if (newLen >= startLen)
+ {
+ UInt32 normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[state]);
+ UInt32 dist;
+ unsigned offs, posSlot, len;
+
+ {
+ unsigned offset = cur + newLen;
+ if (last < offset)
+ last = offset;
+ }
+
+ offs = 0;
+ while (startLen > MATCHES[offs])
+ offs += 2;
+ dist = MATCHES[(size_t)offs + 1];
+
+ // if (dist >= kNumFullDistances)
+ GetPosSlot2(dist, posSlot)
+
+ for (len = /*2*/ startLen; ; len++)
+ {
+ UInt32 price = normalMatchPrice + GET_PRICE_LEN(&p->lenEnc, posState, len);
+ {
+ COptimal *opt;
+ unsigned lenNorm = len - 2;
+ lenNorm = GetLenToPosState2(lenNorm);
+ if (dist < kNumFullDistances)
+ price += p->distancesPrices[lenNorm][dist & (kNumFullDistances - 1)];
+ else
+ price += p->posSlotPrices[lenNorm][posSlot] + p->alignPrices[dist & kAlignMask];
+
+ opt = &p->opt[cur + len];
+ if (price < opt->price)
+ {
+ opt->price = price;
+ opt->len = (UInt32)len;
+ opt->dist = dist + LZMA_NUM_REPS;
+ opt->extra = 0;
+ }
+ }
+
+ if (len == MATCHES[offs])
+ {
+ // if (p->_maxMode) {
+ // MATCH : LIT : REP_0
+
+ const Byte *data2 = data - dist - 1;
+ unsigned len2 = len + 1;
+ unsigned limit = len2 + p->numFastBytes;
+ if (limit > numAvailFull)
+ limit = numAvailFull;
+
+ len2 += 2;
+ if (len2 <= limit)
+ if (data[len2 - 2] == data2[len2 - 2])
+ if (data[len2 - 1] == data2[len2 - 1])
+ {
+ for (; len2 < limit && data[len2] == data2[len2]; len2++)
+ {}
+
+ len2 -= len;
+
+ // if (len2 >= 3)
+ {
+ unsigned state2 = kMatchNextStates[state];
+ unsigned posState2 = (position + len) & p->pbMask;
+ unsigned offset;
+ price += GET_PRICE_0(p->isMatch[state2][posState2]);
+ price += LitEnc_Matched_GetPrice(LIT_PROBS(position + len, data[(size_t)len - 1]),
+ data[len], data2[len], p->ProbPrices);
+
+ // state2 = kLiteralNextStates[state2];
+ state2 = kState_LitAfterMatch;
+
+ posState2 = (posState2 + 1) & p->pbMask;
+ price += GetPrice_Rep_0(p, state2, posState2);
+
+ offset = cur + len + len2;
+
+ if (last < offset)
+ last = offset;
+ // do
+ {
+ UInt32 price2;
+ COptimal *opt;
+ len2--;
+ // price2 = price + GetPrice_Len_Rep_0(p, len2, state2, posState2);
+ price2 = price + GET_PRICE_LEN(&p->repLenEnc, posState2, len2);
+ opt = &p->opt[offset];
+ // offset--;
+ if (price2 < opt->price)
+ {
+ opt->price = price2;
+ opt->len = (UInt32)len2;
+ opt->extra = (CExtra)(len + 1);
+ opt->dist = dist + LZMA_NUM_REPS;
+ }
+ }
+ // while (len2 >= 3);
+ }
+
+ }
+
+ offs += 2;
+ if (offs == numPairs)
+ break;
+ dist = MATCHES[(size_t)offs + 1];
+ // if (dist >= kNumFullDistances)
+ GetPosSlot2(dist, posSlot)
+ }
+ }
+ }
+ }
+
+ do
+ p->opt[last].price = kInfinityPrice;
+ while (--last);
+
+ return Backward(p, cur);
+}
+
+
+
+#define ChangePair(smallDist, bigDist) (((bigDist) >> 7) > (smallDist))
+
+
+
+static unsigned GetOptimumFast(CLzmaEnc *p)
+{
+ UInt32 numAvail, mainDist;
+ unsigned mainLen, numPairs, repIndex, repLen, i;
+ const Byte *data;
+
+ if (p->additionalOffset == 0)
+ mainLen = ReadMatchDistances(p, &numPairs);
+ else
+ {
+ mainLen = p->longestMatchLen;
+ numPairs = p->numPairs;
+ }
+
+ numAvail = p->numAvail;
+ p->backRes = MARK_LIT;
+ if (numAvail < 2)
+ return 1;
+ // if (mainLen < 2 && p->state == 0) return 1; // 18.06.notused
+ if (numAvail > LZMA_MATCH_LEN_MAX)
+ numAvail = LZMA_MATCH_LEN_MAX;
+ data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
+ repLen = repIndex = 0;
+
+ for (i = 0; i < LZMA_NUM_REPS; i++)
+ {
+ unsigned len;
+ const Byte *data2 = data - p->reps[i];
+ if (data[0] != data2[0] || data[1] != data2[1])
+ continue;
+ for (len = 2; len < numAvail && data[len] == data2[len]; len++)
+ {}
+ if (len >= p->numFastBytes)
+ {
+ p->backRes = (UInt32)i;
+ MOVE_POS(p, len - 1)
+ return len;
+ }
+ if (len > repLen)
+ {
+ repIndex = i;
+ repLen = len;
+ }
+ }
+
+ if (mainLen >= p->numFastBytes)
+ {
+ p->backRes = p->matches[(size_t)numPairs - 1] + LZMA_NUM_REPS;
+ MOVE_POS(p, mainLen - 1)
+ return mainLen;
+ }
+
+ mainDist = 0; /* for GCC */
+
+ if (mainLen >= 2)
+ {
+ mainDist = p->matches[(size_t)numPairs - 1];
+ while (numPairs > 2)
+ {
+ UInt32 dist2;
+ if (mainLen != p->matches[(size_t)numPairs - 4] + 1)
+ break;
+ dist2 = p->matches[(size_t)numPairs - 3];
+ if (!ChangePair(dist2, mainDist))
+ break;
+ numPairs -= 2;
+ mainLen--;
+ mainDist = dist2;
+ }
+ if (mainLen == 2 && mainDist >= 0x80)
+ mainLen = 1;
+ }
+
+ if (repLen >= 2)
+ if ( repLen + 1 >= mainLen
+ || (repLen + 2 >= mainLen && mainDist >= (1 << 9))
+ || (repLen + 3 >= mainLen && mainDist >= (1 << 15)))
+ {
+ p->backRes = (UInt32)repIndex;
+ MOVE_POS(p, repLen - 1)
+ return repLen;
+ }
+
+ if (mainLen < 2 || numAvail <= 2)
+ return 1;
+
+ {
+ unsigned len1 = ReadMatchDistances(p, &p->numPairs);
+ p->longestMatchLen = len1;
+
+ if (len1 >= 2)
+ {
+ UInt32 newDist = p->matches[(size_t)p->numPairs - 1];
+ if ( (len1 >= mainLen && newDist < mainDist)
+ || (len1 == mainLen + 1 && !ChangePair(mainDist, newDist))
+ || (len1 > mainLen + 1)
+ || (len1 + 1 >= mainLen && mainLen >= 3 && ChangePair(newDist, mainDist)))
+ return 1;
+ }
+ }
+
+ data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
+
+ for (i = 0; i < LZMA_NUM_REPS; i++)
+ {
+ unsigned len, limit;
+ const Byte *data2 = data - p->reps[i];
+ if (data[0] != data2[0] || data[1] != data2[1])
+ continue;
+ limit = mainLen - 1;
+ for (len = 2;; len++)
+ {
+ if (len >= limit)
+ return 1;
+ if (data[len] != data2[len])
+ break;
+ }
+ }
+
+ p->backRes = mainDist + LZMA_NUM_REPS;
+ if (mainLen != 2)
+ {
+ MOVE_POS(p, mainLen - 2)
+ }
+ return mainLen;
+}
+
+
+
+
+static void WriteEndMarker(CLzmaEnc *p, unsigned posState)
+{
+ UInt32 range;
+ range = p->rc.range;
+ {
+ UInt32 ttt, newBound;
+ CLzmaProb *prob = &p->isMatch[p->state][posState];
+ RC_BIT_PRE(&p->rc, prob)
+ RC_BIT_1(&p->rc, prob)
+ prob = &p->isRep[p->state];
+ RC_BIT_PRE(&p->rc, prob)
+ RC_BIT_0(&p->rc, prob)
+ }
+ p->state = kMatchNextStates[p->state];
+
+ p->rc.range = range;
+ LenEnc_Encode(&p->lenProbs, &p->rc, 0, posState);
+ range = p->rc.range;
+
+ {
+ // RcTree_Encode_PosSlot(&p->rc, p->posSlotEncoder[0], (1 << kNumPosSlotBits) - 1);
+ CLzmaProb *probs = p->posSlotEncoder[0];
+ unsigned m = 1;
+ do
+ {
+ UInt32 ttt, newBound;
+ RC_BIT_PRE(p, probs + m)
+ RC_BIT_1(&p->rc, probs + m)
+ m = (m << 1) + 1;
+ }
+ while (m < (1 << kNumPosSlotBits));
+ }
+ {
+ // RangeEnc_EncodeDirectBits(&p->rc, ((UInt32)1 << (30 - kNumAlignBits)) - 1, 30 - kNumAlignBits); UInt32 range = p->range;
+ unsigned numBits = 30 - kNumAlignBits;
+ do
+ {
+ range >>= 1;
+ p->rc.low += range;
+ RC_NORM(&p->rc)
+ }
+ while (--numBits);
+ }
+
+ {
+ // RcTree_ReverseEncode(&p->rc, p->posAlignEncoder, kNumAlignBits, kAlignMask);
+ CLzmaProb *probs = p->posAlignEncoder;
+ unsigned m = 1;
+ do
+ {
+ UInt32 ttt, newBound;
+ RC_BIT_PRE(p, probs + m)
+ RC_BIT_1(&p->rc, probs + m)
+ m = (m << 1) + 1;
+ }
+ while (m < kAlignTableSize);
+ }
+ p->rc.range = range;
+}
+
+
+static SRes CheckErrors(CLzmaEnc *p)
+{
+ if (p->result != SZ_OK)
+ return p->result;
+ if (p->rc.res != SZ_OK)
+ p->result = SZ_ERROR_WRITE;
+
+ #ifndef Z7_ST
+ if (
+ // p->mf_Failure ||
+ (p->mtMode &&
+ ( // p->matchFinderMt.failure_LZ_LZ ||
+ p->matchFinderMt.failure_LZ_BT))
+ )
+ {
+ p->result = MY_HRES_ERROR_INTERNAL_ERROR;
+ // printf("\nCheckErrors p->matchFinderMt.failureLZ\n");
+ }
+ #endif
+
+ if (MFB.result != SZ_OK)
+ p->result = SZ_ERROR_READ;
+
+ if (p->result != SZ_OK)
+ p->finished = True;
+ return p->result;
+}
+
+
+Z7_NO_INLINE static SRes Flush(CLzmaEnc *p, UInt32 nowPos)
+{
+ /* ReleaseMFStream(); */
+ p->finished = True;
+ if (p->writeEndMark)
+ WriteEndMarker(p, nowPos & p->pbMask);
+ RangeEnc_FlushData(&p->rc);
+ RangeEnc_FlushStream(&p->rc);
+ return CheckErrors(p);
+}
+
+
+Z7_NO_INLINE static void FillAlignPrices(CLzmaEnc *p)
+{
+ unsigned i;
+ const CProbPrice *ProbPrices = p->ProbPrices;
+ const CLzmaProb *probs = p->posAlignEncoder;
+ // p->alignPriceCount = 0;
+ for (i = 0; i < kAlignTableSize / 2; i++)
+ {
+ UInt32 price = 0;
+ unsigned sym = i;
+ unsigned m = 1;
+ unsigned bit;
+ UInt32 prob;
+ bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[m], bit); m = (m << 1) + bit;
+ bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[m], bit); m = (m << 1) + bit;
+ bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[m], bit); m = (m << 1) + bit;
+ prob = probs[m];
+ p->alignPrices[i ] = price + GET_PRICEa_0(prob);
+ p->alignPrices[i + 8] = price + GET_PRICEa_1(prob);
+ // p->alignPrices[i] = RcTree_ReverseGetPrice(p->posAlignEncoder, kNumAlignBits, i, p->ProbPrices);
+ }
+}
+
+
+Z7_NO_INLINE static void FillDistancesPrices(CLzmaEnc *p)
+{
+ // int y; for (y = 0; y < 100; y++) {
+
+ UInt32 tempPrices[kNumFullDistances];
+ unsigned i, lps;
+
+ const CProbPrice *ProbPrices = p->ProbPrices;
+ p->matchPriceCount = 0;
+
+ for (i = kStartPosModelIndex / 2; i < kNumFullDistances / 2; i++)
+ {
+ unsigned posSlot = GetPosSlot1(i);
+ unsigned footerBits = (posSlot >> 1) - 1;
+ unsigned base = ((2 | (posSlot & 1)) << footerBits);
+ const CLzmaProb *probs = p->posEncoders + (size_t)base * 2;
+ // tempPrices[i] = RcTree_ReverseGetPrice(p->posEncoders + base, footerBits, i - base, p->ProbPrices);
+ UInt32 price = 0;
+ unsigned m = 1;
+ unsigned sym = i;
+ unsigned offset = (unsigned)1 << footerBits;
+ base += i;
+
+ if (footerBits)
+ do
+ {
+ unsigned bit = sym & 1;
+ sym >>= 1;
+ price += GET_PRICEa(probs[m], bit);
+ m = (m << 1) + bit;
+ }
+ while (--footerBits);
+
+ {
+ unsigned prob = probs[m];
+ tempPrices[base ] = price + GET_PRICEa_0(prob);
+ tempPrices[base + offset] = price + GET_PRICEa_1(prob);
+ }
+ }
+
+ for (lps = 0; lps < kNumLenToPosStates; lps++)
+ {
+ unsigned slot;
+ unsigned distTableSize2 = (p->distTableSize + 1) >> 1;
+ UInt32 *posSlotPrices = p->posSlotPrices[lps];
+ const CLzmaProb *probs = p->posSlotEncoder[lps];
+
+ for (slot = 0; slot < distTableSize2; slot++)
+ {
+ // posSlotPrices[slot] = RcTree_GetPrice(encoder, kNumPosSlotBits, slot, p->ProbPrices);
+ UInt32 price;
+ unsigned bit;
+ unsigned sym = slot + (1 << (kNumPosSlotBits - 1));
+ unsigned prob;
+ bit = sym & 1; sym >>= 1; price = GET_PRICEa(probs[sym], bit);
+ bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[sym], bit);
+ bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[sym], bit);
+ bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[sym], bit);
+ bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[sym], bit);
+ prob = probs[(size_t)slot + (1 << (kNumPosSlotBits - 1))];
+ posSlotPrices[(size_t)slot * 2 ] = price + GET_PRICEa_0(prob);
+ posSlotPrices[(size_t)slot * 2 + 1] = price + GET_PRICEa_1(prob);
+ }
+
+ {
+ UInt32 delta = ((UInt32)((kEndPosModelIndex / 2 - 1) - kNumAlignBits) << kNumBitPriceShiftBits);
+ for (slot = kEndPosModelIndex / 2; slot < distTableSize2; slot++)
+ {
+ posSlotPrices[(size_t)slot * 2 ] += delta;
+ posSlotPrices[(size_t)slot * 2 + 1] += delta;
+ delta += ((UInt32)1 << kNumBitPriceShiftBits);
+ }
+ }
+
+ {
+ UInt32 *dp = p->distancesPrices[lps];
+
+ dp[0] = posSlotPrices[0];
+ dp[1] = posSlotPrices[1];
+ dp[2] = posSlotPrices[2];
+ dp[3] = posSlotPrices[3];
+
+ for (i = 4; i < kNumFullDistances; i += 2)
+ {
+ UInt32 slotPrice = posSlotPrices[GetPosSlot1(i)];
+ dp[i ] = slotPrice + tempPrices[i];
+ dp[i + 1] = slotPrice + tempPrices[i + 1];
+ }
+ }
+ }
+ // }
+}
+
+
+
+static void LzmaEnc_Construct(CLzmaEnc *p)
+{
+ RangeEnc_Construct(&p->rc);
+ MatchFinder_Construct(&MFB);
+
+ #ifndef Z7_ST
+ p->matchFinderMt.MatchFinder = &MFB;
+ MatchFinderMt_Construct(&p->matchFinderMt);
+ #endif
+
+ {
+ CLzmaEncProps props;
+ LzmaEncProps_Init(&props);
+ LzmaEnc_SetProps((CLzmaEncHandle)(void *)p, &props);
+ }
+
+ #ifndef LZMA_LOG_BSR
+ LzmaEnc_FastPosInit(p->g_FastPos);
+ #endif
+
+ LzmaEnc_InitPriceTables(p->ProbPrices);
+ p->litProbs = NULL;
+ p->saveState.litProbs = NULL;
+}
+
+CLzmaEncHandle LzmaEnc_Create(ISzAllocPtr alloc)
+{
+ void *p;
+ p = ISzAlloc_Alloc(alloc, sizeof(CLzmaEnc));
+ if (p)
+ LzmaEnc_Construct((CLzmaEnc *)p);
+ return p;
+}
+
+static void LzmaEnc_FreeLits(CLzmaEnc *p, ISzAllocPtr alloc)
+{
+ ISzAlloc_Free(alloc, p->litProbs);
+ ISzAlloc_Free(alloc, p->saveState.litProbs);
+ p->litProbs = NULL;
+ p->saveState.litProbs = NULL;
+}
+
+static void LzmaEnc_Destruct(CLzmaEnc *p, ISzAllocPtr alloc, ISzAllocPtr allocBig)
+{
+ #ifndef Z7_ST
+ MatchFinderMt_Destruct(&p->matchFinderMt, allocBig);
+ #endif
+
+ MatchFinder_Free(&MFB, allocBig);
+ LzmaEnc_FreeLits(p, alloc);
+ RangeEnc_Free(&p->rc, alloc);
+}
+
+void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAllocPtr alloc, ISzAllocPtr allocBig)
+{
+ // GET_CLzmaEnc_p
+ LzmaEnc_Destruct(p, alloc, allocBig);
+ ISzAlloc_Free(alloc, p);
+}
+
+
+Z7_NO_INLINE
+static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, UInt32 maxPackSize, UInt32 maxUnpackSize)
+{
+ UInt32 nowPos32, startPos32;
+ if (p->needInit)
+ {
+ #ifndef Z7_ST
+ if (p->mtMode)
+ {
+ RINOK(MatchFinderMt_InitMt(&p->matchFinderMt))
+ }
+ #endif
+ p->matchFinder.Init(p->matchFinderObj);
+ p->needInit = 0;
+ }
+
+ if (p->finished)
+ return p->result;
+ RINOK(CheckErrors(p))
+
+ nowPos32 = (UInt32)p->nowPos64;
+ startPos32 = nowPos32;
+
+ if (p->nowPos64 == 0)
+ {
+ unsigned numPairs;
+ Byte curByte;
+ if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0)
+ return Flush(p, nowPos32);
+ ReadMatchDistances(p, &numPairs);
+ RangeEnc_EncodeBit_0(&p->rc, &p->isMatch[kState_Start][0]);
+ // p->state = kLiteralNextStates[p->state];
+ curByte = *(p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset);
+ LitEnc_Encode(&p->rc, p->litProbs, curByte);
+ p->additionalOffset--;
+ nowPos32++;
+ }
+
+ if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) != 0)
+
+ for (;;)
+ {
+ UInt32 dist;
+ unsigned len, posState;
+ UInt32 range, ttt, newBound;
+ CLzmaProb *probs;
+
+ if (p->fastMode)
+ len = GetOptimumFast(p);
+ else
+ {
+ unsigned oci = p->optCur;
+ if (p->optEnd == oci)
+ len = GetOptimum(p, nowPos32);
+ else
+ {
+ const COptimal *opt = &p->opt[oci];
+ len = opt->len;
+ p->backRes = opt->dist;
+ p->optCur = oci + 1;
+ }
+ }
+
+ posState = (unsigned)nowPos32 & p->pbMask;
+ range = p->rc.range;
+ probs = &p->isMatch[p->state][posState];
+
+ RC_BIT_PRE(&p->rc, probs)
+
+ dist = p->backRes;
+
+ #ifdef SHOW_STAT2
+ printf("\n pos = %6X, len = %3u pos = %6u", nowPos32, len, dist);
+ #endif
+
+ if (dist == MARK_LIT)
+ {
+ Byte curByte;
+ const Byte *data;
+ unsigned state;
+
+ RC_BIT_0(&p->rc, probs)
+ p->rc.range = range;
+ data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;
+ probs = LIT_PROBS(nowPos32, *(data - 1));
+ curByte = *data;
+ state = p->state;
+ p->state = kLiteralNextStates[state];
+ if (IsLitState(state))
+ LitEnc_Encode(&p->rc, probs, curByte);
+ else
+ LitEnc_EncodeMatched(&p->rc, probs, curByte, *(data - p->reps[0]));
+ }
+ else
+ {
+ RC_BIT_1(&p->rc, probs)
+ probs = &p->isRep[p->state];
+ RC_BIT_PRE(&p->rc, probs)
+
+ if (dist < LZMA_NUM_REPS)
+ {
+ RC_BIT_1(&p->rc, probs)
+ probs = &p->isRepG0[p->state];
+ RC_BIT_PRE(&p->rc, probs)
+ if (dist == 0)
+ {
+ RC_BIT_0(&p->rc, probs)
+ probs = &p->isRep0Long[p->state][posState];
+ RC_BIT_PRE(&p->rc, probs)
+ if (len != 1)
+ {
+ RC_BIT_1_BASE(&p->rc, probs)
+ }
+ else
+ {
+ RC_BIT_0_BASE(&p->rc, probs)
+ p->state = kShortRepNextStates[p->state];
+ }
+ }
+ else
+ {
+ RC_BIT_1(&p->rc, probs)
+ probs = &p->isRepG1[p->state];
+ RC_BIT_PRE(&p->rc, probs)
+ if (dist == 1)
+ {
+ RC_BIT_0_BASE(&p->rc, probs)
+ dist = p->reps[1];
+ }
+ else
+ {
+ RC_BIT_1(&p->rc, probs)
+ probs = &p->isRepG2[p->state];
+ RC_BIT_PRE(&p->rc, probs)
+ if (dist == 2)
+ {
+ RC_BIT_0_BASE(&p->rc, probs)
+ dist = p->reps[2];
+ }
+ else
+ {
+ RC_BIT_1_BASE(&p->rc, probs)
+ dist = p->reps[3];
+ p->reps[3] = p->reps[2];
+ }
+ p->reps[2] = p->reps[1];
+ }
+ p->reps[1] = p->reps[0];
+ p->reps[0] = dist;
+ }
+
+ RC_NORM(&p->rc)
+
+ p->rc.range = range;
+
+ if (len != 1)
+ {
+ LenEnc_Encode(&p->repLenProbs, &p->rc, len - LZMA_MATCH_LEN_MIN, posState);
+ --p->repLenEncCounter;
+ p->state = kRepNextStates[p->state];
+ }
+ }
+ else
+ {
+ unsigned posSlot;
+ RC_BIT_0(&p->rc, probs)
+ p->rc.range = range;
+ p->state = kMatchNextStates[p->state];
+
+ LenEnc_Encode(&p->lenProbs, &p->rc, len - LZMA_MATCH_LEN_MIN, posState);
+ // --p->lenEnc.counter;
+
+ dist -= LZMA_NUM_REPS;
+ p->reps[3] = p->reps[2];
+ p->reps[2] = p->reps[1];
+ p->reps[1] = p->reps[0];
+ p->reps[0] = dist + 1;
+
+ p->matchPriceCount++;
+ GetPosSlot(dist, posSlot)
+ // RcTree_Encode_PosSlot(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], posSlot);
+ {
+ UInt32 sym = (UInt32)posSlot + (1 << kNumPosSlotBits);
+ range = p->rc.range;
+ probs = p->posSlotEncoder[GetLenToPosState(len)];
+ do
+ {
+ CLzmaProb *prob = probs + (sym >> kNumPosSlotBits);
+ UInt32 bit = (sym >> (kNumPosSlotBits - 1)) & 1;
+ sym <<= 1;
+ RC_BIT(&p->rc, prob, bit)
+ }
+ while (sym < (1 << kNumPosSlotBits * 2));
+ p->rc.range = range;
+ }
+
+ if (dist >= kStartPosModelIndex)
+ {
+ unsigned footerBits = ((posSlot >> 1) - 1);
+
+ if (dist < kNumFullDistances)
+ {
+ unsigned base = ((2 | (posSlot & 1)) << footerBits);
+ RcTree_ReverseEncode(&p->rc, p->posEncoders + base, footerBits, (unsigned)(dist /* - base */));
+ }
+ else
+ {
+ UInt32 pos2 = (dist | 0xF) << (32 - footerBits);
+ range = p->rc.range;
+ // RangeEnc_EncodeDirectBits(&p->rc, posReduced >> kNumAlignBits, footerBits - kNumAlignBits);
+ /*
+ do
+ {
+ range >>= 1;
+ p->rc.low += range & (0 - ((dist >> --footerBits) & 1));
+ RC_NORM(&p->rc)
+ }
+ while (footerBits > kNumAlignBits);
+ */
+ do
+ {
+ range >>= 1;
+ p->rc.low += range & (0 - (pos2 >> 31));
+ pos2 += pos2;
+ RC_NORM(&p->rc)
+ }
+ while (pos2 != 0xF0000000);
+
+
+ // RcTree_ReverseEncode(&p->rc, p->posAlignEncoder, kNumAlignBits, posReduced & kAlignMask);
+
+ {
+ unsigned m = 1;
+ unsigned bit;
+ bit = dist & 1; dist >>= 1; RC_BIT(&p->rc, p->posAlignEncoder + m, bit) m = (m << 1) + bit;
+ bit = dist & 1; dist >>= 1; RC_BIT(&p->rc, p->posAlignEncoder + m, bit) m = (m << 1) + bit;
+ bit = dist & 1; dist >>= 1; RC_BIT(&p->rc, p->posAlignEncoder + m, bit) m = (m << 1) + bit;
+ bit = dist & 1; RC_BIT(&p->rc, p->posAlignEncoder + m, bit)
+ p->rc.range = range;
+ // p->alignPriceCount++;
+ }
+ }
+ }
+ }
+ }
+
+ nowPos32 += (UInt32)len;
+ p->additionalOffset -= len;
+
+ if (p->additionalOffset == 0)
+ {
+ UInt32 processed;
+
+ if (!p->fastMode)
+ {
+ /*
+ if (p->alignPriceCount >= 16) // kAlignTableSize
+ FillAlignPrices(p);
+ if (p->matchPriceCount >= 128)
+ FillDistancesPrices(p);
+ if (p->lenEnc.counter <= 0)
+ LenPriceEnc_UpdateTables(&p->lenEnc, 1 << p->pb, &p->lenProbs, p->ProbPrices);
+ */
+ if (p->matchPriceCount >= 64)
+ {
+ FillAlignPrices(p);
+ // { int y; for (y = 0; y < 100; y++) {
+ FillDistancesPrices(p);
+ // }}
+ LenPriceEnc_UpdateTables(&p->lenEnc, (unsigned)1 << p->pb, &p->lenProbs, p->ProbPrices);
+ }
+ if (p->repLenEncCounter <= 0)
+ {
+ p->repLenEncCounter = REP_LEN_COUNT;
+ LenPriceEnc_UpdateTables(&p->repLenEnc, (unsigned)1 << p->pb, &p->repLenProbs, p->ProbPrices);
+ }
+ }
+
+ if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0)
+ break;
+ processed = nowPos32 - startPos32;
+
+ if (maxPackSize)
+ {
+ if (processed + kNumOpts + 300 >= maxUnpackSize
+ || RangeEnc_GetProcessed_sizet(&p->rc) + kPackReserve >= maxPackSize)
+ break;
+ }
+ else if (processed >= (1 << 17))
+ {
+ p->nowPos64 += nowPos32 - startPos32;
+ return CheckErrors(p);
+ }
+ }
+ }
+
+ p->nowPos64 += nowPos32 - startPos32;
+ return Flush(p, nowPos32);
+}
+
+
+
+#define kBigHashDicLimit ((UInt32)1 << 24)
+
+static SRes LzmaEnc_Alloc(CLzmaEnc *p, UInt32 keepWindowSize, ISzAllocPtr alloc, ISzAllocPtr allocBig)
+{
+ UInt32 beforeSize = kNumOpts;
+ UInt32 dictSize;
+
+ if (!RangeEnc_Alloc(&p->rc, alloc))
+ return SZ_ERROR_MEM;
+
+ #ifndef Z7_ST
+ p->mtMode = (p->multiThread && !p->fastMode && (MFB.btMode != 0));
+ #endif
+
+ {
+ const unsigned lclp = p->lc + p->lp;
+ if (!p->litProbs || !p->saveState.litProbs || p->lclp != lclp)
+ {
+ LzmaEnc_FreeLits(p, alloc);
+ p->litProbs = (CLzmaProb *)ISzAlloc_Alloc(alloc, ((size_t)0x300 * sizeof(CLzmaProb)) << lclp);
+ p->saveState.litProbs = (CLzmaProb *)ISzAlloc_Alloc(alloc, ((size_t)0x300 * sizeof(CLzmaProb)) << lclp);
+ if (!p->litProbs || !p->saveState.litProbs)
+ {
+ LzmaEnc_FreeLits(p, alloc);
+ return SZ_ERROR_MEM;
+ }
+ p->lclp = lclp;
+ }
+ }
+
+ MFB.bigHash = (Byte)(p->dictSize > kBigHashDicLimit ? 1 : 0);
+
+
+ dictSize = p->dictSize;
+ if (dictSize == ((UInt32)2 << 30) ||
+ dictSize == ((UInt32)3 << 30))
+ {
+ /* 21.03 : here we reduce the dictionary for 2 reasons:
+ 1) we don't want 32-bit back_distance matches in decoder for 2 GB dictionary.
+ 2) we want to elimate useless last MatchFinder_Normalize3() for corner cases,
+ where data size is aligned for 1 GB: 5/6/8 GB.
+ That reducing must be >= 1 for such corner cases. */
+ dictSize -= 1;
+ }
+
+ if (beforeSize + dictSize < keepWindowSize)
+ beforeSize = keepWindowSize - dictSize;
+
+ /* in worst case we can look ahead for
+ max(LZMA_MATCH_LEN_MAX, numFastBytes + 1 + numFastBytes) bytes.
+ we send larger value for (keepAfter) to MantchFinder_Create():
+ (numFastBytes + LZMA_MATCH_LEN_MAX + 1)
+ */
+
+ #ifndef Z7_ST
+ if (p->mtMode)
+ {
+ RINOK(MatchFinderMt_Create(&p->matchFinderMt, dictSize, beforeSize,
+ p->numFastBytes, LZMA_MATCH_LEN_MAX + 1 /* 18.04 */
+ , allocBig))
+ p->matchFinderObj = &p->matchFinderMt;
+ MFB.bigHash = (Byte)(MFB.hashMask >= 0xFFFFFF ? 1 : 0);
+ MatchFinderMt_CreateVTable(&p->matchFinderMt, &p->matchFinder);
+ }
+ else
+ #endif
+ {
+ if (!MatchFinder_Create(&MFB, dictSize, beforeSize,
+ p->numFastBytes, LZMA_MATCH_LEN_MAX + 1 /* 21.03 */
+ , allocBig))
+ return SZ_ERROR_MEM;
+ p->matchFinderObj = &MFB;
+ MatchFinder_CreateVTable(&MFB, &p->matchFinder);
+ }
+
+ return SZ_OK;
+}
+
+static void LzmaEnc_Init(CLzmaEnc *p)
+{
+ unsigned i;
+ p->state = 0;
+ p->reps[0] =
+ p->reps[1] =
+ p->reps[2] =
+ p->reps[3] = 1;
+
+ RangeEnc_Init(&p->rc);
+
+ for (i = 0; i < (1 << kNumAlignBits); i++)
+ p->posAlignEncoder[i] = kProbInitValue;
+
+ for (i = 0; i < kNumStates; i++)
+ {
+ unsigned j;
+ for (j = 0; j < LZMA_NUM_PB_STATES_MAX; j++)
+ {
+ p->isMatch[i][j] = kProbInitValue;
+ p->isRep0Long[i][j] = kProbInitValue;
+ }
+ p->isRep[i] = kProbInitValue;
+ p->isRepG0[i] = kProbInitValue;
+ p->isRepG1[i] = kProbInitValue;
+ p->isRepG2[i] = kProbInitValue;
+ }
+
+ {
+ for (i = 0; i < kNumLenToPosStates; i++)
+ {
+ CLzmaProb *probs = p->posSlotEncoder[i];
+ unsigned j;
+ for (j = 0; j < (1 << kNumPosSlotBits); j++)
+ probs[j] = kProbInitValue;
+ }
+ }
+ {
+ for (i = 0; i < kNumFullDistances; i++)
+ p->posEncoders[i] = kProbInitValue;
+ }
+
+ {
+ const size_t num = (size_t)0x300 << (p->lp + p->lc);
+ size_t k;
+ CLzmaProb *probs = p->litProbs;
+ for (k = 0; k < num; k++)
+ probs[k] = kProbInitValue;
+ }
+
+
+ LenEnc_Init(&p->lenProbs);
+ LenEnc_Init(&p->repLenProbs);
+
+ p->optEnd = 0;
+ p->optCur = 0;
+
+ {
+ for (i = 0; i < kNumOpts; i++)
+ p->opt[i].price = kInfinityPrice;
+ }
+
+ p->additionalOffset = 0;
+
+ p->pbMask = ((unsigned)1 << p->pb) - 1;
+ p->lpMask = ((UInt32)0x100 << p->lp) - ((unsigned)0x100 >> p->lc);
+
+ // p->mf_Failure = False;
+}
+
+
+static void LzmaEnc_InitPrices(CLzmaEnc *p)
+{
+ if (!p->fastMode)
+ {
+ FillDistancesPrices(p);
+ FillAlignPrices(p);
+ }
+
+ p->lenEnc.tableSize =
+ p->repLenEnc.tableSize =
+ p->numFastBytes + 1 - LZMA_MATCH_LEN_MIN;
+
+ p->repLenEncCounter = REP_LEN_COUNT;
+
+ LenPriceEnc_UpdateTables(&p->lenEnc, (unsigned)1 << p->pb, &p->lenProbs, p->ProbPrices);
+ LenPriceEnc_UpdateTables(&p->repLenEnc, (unsigned)1 << p->pb, &p->repLenProbs, p->ProbPrices);
+}
+
+static SRes LzmaEnc_AllocAndInit(CLzmaEnc *p, UInt32 keepWindowSize, ISzAllocPtr alloc, ISzAllocPtr allocBig)
+{
+ unsigned i;
+ for (i = kEndPosModelIndex / 2; i < kDicLogSizeMax; i++)
+ if (p->dictSize <= ((UInt32)1 << i))
+ break;
+ p->distTableSize = i * 2;
+
+ p->finished = False;
+ p->result = SZ_OK;
+ p->nowPos64 = 0;
+ p->needInit = 1;
+ RINOK(LzmaEnc_Alloc(p, keepWindowSize, alloc, allocBig))
+ LzmaEnc_Init(p);
+ LzmaEnc_InitPrices(p);
+ return SZ_OK;
+}
+
+static SRes LzmaEnc_Prepare(CLzmaEncHandle p,
+ ISeqOutStreamPtr outStream,
+ ISeqInStreamPtr inStream,
+ ISzAllocPtr alloc, ISzAllocPtr allocBig)
+{
+ // GET_CLzmaEnc_p
+ MatchFinder_SET_STREAM(&MFB, inStream)
+ p->rc.outStream = outStream;
+ return LzmaEnc_AllocAndInit(p, 0, alloc, allocBig);
+}
+
+SRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle p,
+ ISeqInStreamPtr inStream, UInt32 keepWindowSize,
+ ISzAllocPtr alloc, ISzAllocPtr allocBig)
+{
+ // GET_CLzmaEnc_p
+ MatchFinder_SET_STREAM(&MFB, inStream)
+ return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);
+}
+
+SRes LzmaEnc_MemPrepare(CLzmaEncHandle p,
+ const Byte *src, SizeT srcLen,
+ UInt32 keepWindowSize,
+ ISzAllocPtr alloc, ISzAllocPtr allocBig)
+{
+ // GET_CLzmaEnc_p
+ MatchFinder_SET_DIRECT_INPUT_BUF(&MFB, src, srcLen)
+ LzmaEnc_SetDataSize(p, srcLen);
+ return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);
+}
+
+void LzmaEnc_Finish(CLzmaEncHandle p)
+{
+ #ifndef Z7_ST
+ // GET_CLzmaEnc_p
+ if (p->mtMode)
+ MatchFinderMt_ReleaseStream(&p->matchFinderMt);
+ #else
+ UNUSED_VAR(p)
+ #endif
+}
+
+
+typedef struct
+{
+ ISeqOutStream vt;
+ Byte *data;
+ size_t rem;
+ BoolInt overflow;
+} CLzmaEnc_SeqOutStreamBuf;
+
+static size_t SeqOutStreamBuf_Write(ISeqOutStreamPtr pp, const void *data, size_t size)
+{
+ Z7_CONTAINER_FROM_VTBL_TO_DECL_VAR_pp_vt_p(CLzmaEnc_SeqOutStreamBuf)
+ if (p->rem < size)
+ {
+ size = p->rem;
+ p->overflow = True;
+ }
+ if (size != 0)
+ {
+ memcpy(p->data, data, size);
+ p->rem -= size;
+ p->data += size;
+ }
+ return size;
+}
+
+
+/*
+UInt32 LzmaEnc_GetNumAvailableBytes(CLzmaEncHandle p)
+{
+ GET_const_CLzmaEnc_p
+ return p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);
+}
+*/
+
+const Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle p)
+{
+ // GET_const_CLzmaEnc_p
+ return p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;
+}
+
+
+// (desiredPackSize == 0) is not allowed
+SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle p, BoolInt reInit,
+ Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize)
+{
+ // GET_CLzmaEnc_p
+ UInt64 nowPos64;
+ SRes res;
+ CLzmaEnc_SeqOutStreamBuf outStream;
+
+ outStream.vt.Write = SeqOutStreamBuf_Write;
+ outStream.data = dest;
+ outStream.rem = *destLen;
+ outStream.overflow = False;
+
+ p->writeEndMark = False;
+ p->finished = False;
+ p->result = SZ_OK;
+
+ if (reInit)
+ LzmaEnc_Init(p);
+ LzmaEnc_InitPrices(p);
+ RangeEnc_Init(&p->rc);
+ p->rc.outStream = &outStream.vt;
+ nowPos64 = p->nowPos64;
+
+ res = LzmaEnc_CodeOneBlock(p, desiredPackSize, *unpackSize);
+
+ *unpackSize = (UInt32)(p->nowPos64 - nowPos64);
+ *destLen -= outStream.rem;
+ if (outStream.overflow)
+ return SZ_ERROR_OUTPUT_EOF;
+
+ return res;
+}
+
+
+Z7_NO_INLINE
+static SRes LzmaEnc_Encode2(CLzmaEnc *p, ICompressProgressPtr progress)
+{
+ SRes res = SZ_OK;
+
+ #ifndef Z7_ST
+ Byte allocaDummy[0x300];
+ allocaDummy[0] = 0;
+ allocaDummy[1] = allocaDummy[0];
+ #endif
+
+ for (;;)
+ {
+ res = LzmaEnc_CodeOneBlock(p, 0, 0);
+ if (res != SZ_OK || p->finished)
+ break;
+ if (progress)
+ {
+ res = ICompressProgress_Progress(progress, p->nowPos64, RangeEnc_GetProcessed(&p->rc));
+ if (res != SZ_OK)
+ {
+ res = SZ_ERROR_PROGRESS;
+ break;
+ }
+ }
+ }
+
+ LzmaEnc_Finish((CLzmaEncHandle)(void *)p);
+
+ /*
+ if (res == SZ_OK && !Inline_MatchFinder_IsFinishedOK(&MFB))
+ res = SZ_ERROR_FAIL;
+ }
+ */
+
+ return res;
+}
+
+
+SRes LzmaEnc_Encode(CLzmaEncHandle p, ISeqOutStreamPtr outStream, ISeqInStreamPtr inStream, ICompressProgressPtr progress,
+ ISzAllocPtr alloc, ISzAllocPtr allocBig)
+{
+ // GET_CLzmaEnc_p
+ RINOK(LzmaEnc_Prepare(p, outStream, inStream, alloc, allocBig))
+ return LzmaEnc_Encode2(p, progress);
+}
+
+
+SRes LzmaEnc_WriteProperties(CLzmaEncHandle p, Byte *props, SizeT *size)
+{
+ if (*size < LZMA_PROPS_SIZE)
+ return SZ_ERROR_PARAM;
+ *size = LZMA_PROPS_SIZE;
+ {
+ // GET_CLzmaEnc_p
+ const UInt32 dictSize = p->dictSize;
+ UInt32 v;
+ props[0] = (Byte)((p->pb * 5 + p->lp) * 9 + p->lc);
+
+ // we write aligned dictionary value to properties for lzma decoder
+ if (dictSize >= ((UInt32)1 << 21))
+ {
+ const UInt32 kDictMask = ((UInt32)1 << 20) - 1;
+ v = (dictSize + kDictMask) & ~kDictMask;
+ if (v < dictSize)
+ v = dictSize;
+ }
+ else
+ {
+ unsigned i = 11 * 2;
+ do
+ {
+ v = (UInt32)(2 + (i & 1)) << (i >> 1);
+ i++;
+ }
+ while (v < dictSize);
+ }
+
+ SetUi32(props + 1, v)
+ return SZ_OK;
+ }
+}
+
+
+unsigned LzmaEnc_IsWriteEndMark(CLzmaEncHandle p)
+{
+ // GET_CLzmaEnc_p
+ return (unsigned)p->writeEndMark;
+}
+
+
+SRes LzmaEnc_MemEncode(CLzmaEncHandle p, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
+ int writeEndMark, ICompressProgressPtr progress, ISzAllocPtr alloc, ISzAllocPtr allocBig)
+{
+ SRes res;
+ // GET_CLzmaEnc_p
+
+ CLzmaEnc_SeqOutStreamBuf outStream;
+
+ outStream.vt.Write = SeqOutStreamBuf_Write;
+ outStream.data = dest;
+ outStream.rem = *destLen;
+ outStream.overflow = False;
+
+ p->writeEndMark = writeEndMark;
+ p->rc.outStream = &outStream.vt;
+
+ res = LzmaEnc_MemPrepare(p, src, srcLen, 0, alloc, allocBig);
+
+ if (res == SZ_OK)
+ {
+ res = LzmaEnc_Encode2(p, progress);
+ if (res == SZ_OK && p->nowPos64 != srcLen)
+ res = SZ_ERROR_FAIL;
+ }
+
+ *destLen -= (SizeT)outStream.rem;
+ if (outStream.overflow)
+ return SZ_ERROR_OUTPUT_EOF;
+ return res;
+}
+
+
+SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
+ const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
+ ICompressProgressPtr progress, ISzAllocPtr alloc, ISzAllocPtr allocBig)
+{
+ CLzmaEncHandle p = LzmaEnc_Create(alloc);
+ SRes res;
+ if (!p)
+ return SZ_ERROR_MEM;
+
+ res = LzmaEnc_SetProps(p, props);
+ if (res == SZ_OK)
+ {
+ res = LzmaEnc_WriteProperties(p, propsEncoded, propsSize);
+ if (res == SZ_OK)
+ res = LzmaEnc_MemEncode(p, dest, destLen, src, srcLen,
+ writeEndMark, progress, alloc, allocBig);
+ }
+
+ LzmaEnc_Destroy(p, alloc, allocBig);
+ return res;
+}
+
+
+/*
+#ifndef Z7_ST
+void LzmaEnc_GetLzThreads(CLzmaEncHandle p, HANDLE lz_threads[2])
+{
+ GET_const_CLzmaEnc_p
+ lz_threads[0] = p->matchFinderMt.hashSync.thread;
+ lz_threads[1] = p->matchFinderMt.btSync.thread;
+}
+#endif
+*/
diff --git a/deps/libchdr/deps/lzma-19.00/src/Sort.c b/deps/libchdr/deps/lzma-24.05/src/Sort.c
similarity index 100%
rename from deps/libchdr/deps/lzma-19.00/src/Sort.c
rename to deps/libchdr/deps/lzma-24.05/src/Sort.c
diff --git a/deps/libchdr/deps/zstd-1.5.5/.travis.yml b/deps/libchdr/deps/zstd-1.5.5/.travis.yml
deleted file mode 100644
index b96bf8ba..00000000
--- a/deps/libchdr/deps/zstd-1.5.5/.travis.yml
+++ /dev/null
@@ -1,128 +0,0 @@
-# Travis CI is used to test platforms that github-actions currently doesn't support
-# without either self-hosting or some finnicky work-around. Also, some tests
-# are troublesome to migrate since GH Actions runs tests not in a tty.
-language: c
-
-git:
- depth: 1
-
-branches:
- only:
- - dev
- - release
- - master
- - travisTest
-
-addons:
- apt:
- update: true
-
-env:
- global:
- - FUZZERTEST=-T1mn
- ZSTREAM_TESTTIME=-T1mn
- DECODECORPUS_TESTTIME=-T1mn
-
-matrix:
- fast_finish: true
- include:
- - name: S390X (big endian) + Fuzz test
- dist: trusty
- arch: s390x
- script:
- - FUZZER_FLAGS=--no-big-tests make -C tests fuzztest
-
- - name: S390X (big endian) + Fuzz test + no intrinsics
- dist: trusty
- arch: s390x
- script:
- - MOREFLAGS="-DZSTD_NO_INTRINSICS" FUZZER_FLAGS=--no-big-tests make -C tests fuzztest
-
- - name: arm64 # ~2.5 mn
- os: linux
- arch: arm64
- script:
- - make check
-
- - name: arm64fuzz
- os: linux
- arch: arm64
- script:
- - make -C tests fuzztest
-
- # TODO: migrate to GH Actions once newest clang staticanalyze warnings are fixed
- - name: static analyzer scanbuild # ~8mn
- dist: trusty # note : it's important to pin down a version of static analyzer, since different versions report different false positives
- script:
- - make staticAnalyze
-
- # GH actions can't run this command on OS-X, non-tty issues
- - name: OS-X make all lib
- os: osx
- script:
- - make -C lib all
-
- # Introduced to check compat with old toolchains, to prevent e.g. #1872
- - name: ARM Build Test (on Trusty)
- dist: trusty
- script:
- - make arminstall
- - make armbuild
-
- # check release number (release/new tag only)
- - name: Tag-Specific Test
- if: tag =~ ^v[0-9]\.[0-9]
- script:
- - make -C tests checkTag
- - tests/checkTag "$TRAVIS_BRANCH"
-
- - name: PPC64LE + Fuzz test # ~13mn
- arch: ppc64le
- env:
- - FUZZER_FLAGS=--no-big-tests
- - MOREFLAGS="-static"
- script:
- - cat /proc/cpuinfo
- - make -C tests fuzztest
-
- # This test currently fails on GA specifically, for no obvious reason
- # (it works fine on travisCI, and on local test platforms).
- - name: Versions Compatibility Test # ~6mn
- script:
- - make -C tests versionsTest
-
- # meson dedicated test
- - name: Focal (Meson + clang) # ~15mn
- dist: focal
- language: cpp
- compiler: clang
- install:
- - sudo apt-get install -qq liblz4-dev valgrind tree
- - |
- travis_retry curl -o ~/ninja.zip -L 'https://github.com/ninja-build/ninja/releases/download/v1.9.0/ninja-linux.zip' &&
- unzip ~/ninja.zip -d ~/.local/bin
- - |
- travis_retry curl -o ~/get-pip.py -L 'https://bootstrap.pypa.io/pip/3.6/get-pip.py' &&
- python3 ~/get-pip.py --user &&
- pip3 install --user meson
- script:
- - |
- meson setup \
- --buildtype=debugoptimized \
- -Db_lundef=false \
- -Dauto_features=enabled \
- -Dbin_programs=true \
- -Dbin_tests=true \
- -Dbin_contrib=true \
- -Ddefault_library=both \
- build/meson builddir
- - pushd builddir
- - ninja
- - meson test --verbose --no-rebuild
- - DESTDIR=./staging ninja install
- - tree ./staging
- after_failure:
- - cat "$TRAVIS_BUILD_DIR"/builddir/meson-logs/testlog.txt
-
- allow_failures:
- - env: ALLOW_FAILURES=true
diff --git a/deps/libchdr/deps/zstd-1.5.5/CMakeLists.txt b/deps/libchdr/deps/zstd-1.5.5/CMakeLists.txt
deleted file mode 100644
index 1f32446f..00000000
--- a/deps/libchdr/deps/zstd-1.5.5/CMakeLists.txt
+++ /dev/null
@@ -1,24 +0,0 @@
-add_library(zstd STATIC
- lib/zstd.h
- lib/zstd_errors.h
- lib/zdict.h
- lib/common/debug.c
- lib/common/entropy_common.c
- lib/common/error_private.c
- lib/common/fse_decompress.c
- lib/common/pool.c
- lib/common/threading.c
- lib/common/xxhash.c
- lib/common/zstd_common.c
- lib/decompress/huf_decompress.c
- lib/decompress/zstd_ddict.c
- lib/decompress/zstd_decompress_block.c
- lib/decompress/zstd_decompress.c
-)
-
-
-target_include_directories(zstd PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/lib")
-target_include_directories(zstd INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/lib")
-target_compile_definitions(zstd PRIVATE ZSTD_DISABLE_ASM)
-set_target_properties(zstd PROPERTIES POSITION_INDEPENDENT_CODE ON)
-
diff --git a/deps/libchdr/deps/zstd-1.5.5/appveyor.yml b/deps/libchdr/deps/zstd-1.5.5/appveyor.yml
deleted file mode 100644
index c58ef91a..00000000
--- a/deps/libchdr/deps/zstd-1.5.5/appveyor.yml
+++ /dev/null
@@ -1,205 +0,0 @@
-# Following tests are run _only_ on `release` branch
-# and on selected feature branch named `appveyorTest` or `visual*`
-
--
- version: 1.0.{build}
- branches:
- only:
- - release
- - master
- - /appveyor*/
- - /visual*/
- environment:
- matrix:
- - COMPILER: "gcc"
- HOST: "mingw"
- PLATFORM: "x64"
- SCRIPT: "make allzstd MOREFLAGS=-static"
- ARTIFACT: "true"
- BUILD: "true"
- - COMPILER: "gcc"
- HOST: "mingw"
- PLATFORM: "x86"
- SCRIPT: "make allzstd MOREFLAGS=-static"
- ARTIFACT: "true"
- BUILD: "true"
-
- - COMPILER: "clang-cl"
- HOST: "cmake-visual"
- PLATFORM: "x64"
- CONFIGURATION: "Release"
- CMAKE_GENERATOR: "Visual Studio 15 2017"
- CMAKE_GENERATOR_PLATFORM: "x64"
- CMAKE_GENERATOR_TOOLSET: "LLVM"
- APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2017"
-
- install:
- - ECHO Installing %COMPILER% %PLATFORM% %CONFIGURATION%
- - SET PATH_ORIGINAL=%PATH%
- - if [%HOST%]==[mingw] (
- SET "PATH_MINGW32=C:\mingw-w64\i686-6.3.0-posix-dwarf-rt_v5-rev1\mingw32\bin" &&
- SET "PATH_MINGW64=C:\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\bin" &&
- COPY C:\msys64\usr\bin\make.exe C:\mingw-w64\i686-6.3.0-posix-dwarf-rt_v5-rev1\mingw32\bin\make.exe &&
- COPY C:\msys64\usr\bin\make.exe C:\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\bin\make.exe
- )
- - IF [%HOST%]==[visual] IF [%PLATFORM%]==[x64] (
- SET ADDITIONALPARAM=/p:LibraryPath="C:\Program Files\Microsoft SDKs\Windows\v7.1\lib\x64;c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib\amd64;C:\Program Files (x86)\Microsoft Visual Studio 10.0\;C:\Program Files (x86)\Microsoft Visual Studio 10.0\lib\amd64;"
- )
-
- build_script:
- - if [%HOST%]==[mingw] (
- ( if [%PLATFORM%]==[x64] (
- SET "PATH=%PATH_MINGW64%;%PATH_ORIGINAL%"
- ) else if [%PLATFORM%]==[x86] (
- SET "PATH=%PATH_MINGW32%;%PATH_ORIGINAL%"
- ) )
- )
- - if [%HOST%]==[mingw] if [%BUILD%]==[true] (
- make -v &&
- sh -c "%COMPILER% -v" &&
- ECHO Building zlib to static link &&
- SET "CC=%COMPILER%" &&
- sh -c "cd .. && git clone --depth 1 --branch v1.2.11 https://github.com/madler/zlib" &&
- sh -c "cd ../zlib && make -f win32/Makefile.gcc libz.a"
- ECHO Building zstd &&
- SET "CPPFLAGS=-I../../zlib" &&
- SET "LDFLAGS=../../zlib/libz.a" &&
- sh -c "%SCRIPT%" &&
- ( if [%COMPILER%]==[gcc] if [%ARTIFACT%]==[true]
- ECHO Creating artifacts &&
- ECHO %cd% &&
- lib\dll\example\build_package.bat &&
- make -C programs DEBUGFLAGS= clean zstd &&
- cd programs\ && 7z a -tzip -mx9 zstd-win-binary-%PLATFORM%.zip zstd.exe &&
- appveyor PushArtifact zstd-win-binary-%PLATFORM%.zip &&
- cp zstd.exe ..\bin\zstd.exe &&
- git clone --depth 1 --branch release https://github.com/facebook/zstd &&
- cd zstd &&
- git archive --format=tar release -o zstd-src.tar &&
- ..\zstd -19 zstd-src.tar &&
- appveyor PushArtifact zstd-src.tar.zst &&
- certUtil -hashfile zstd-src.tar.zst SHA256 > zstd-src.tar.zst.sha256.sig &&
- appveyor PushArtifact zstd-src.tar.zst.sha256.sig &&
- cd ..\..\bin\ &&
- 7z a -tzip -mx9 zstd-win-release-%PLATFORM%.zip * &&
- appveyor PushArtifact zstd-win-release-%PLATFORM%.zip
- )
- )
- - if [%HOST%]==[cmake-visual] (
- ECHO *** &&
- ECHO *** Building %CMAKE_GENERATOR% ^(%CMAKE_GENERATOR_TOOLSET%^) %PLATFORM%\%CONFIGURATION% &&
- PUSHD build\cmake &&
- cmake -DBUILD_TESTING=ON . &&
- cmake --build . --config %CONFIGURATION% -j4 &&
- POPD &&
- ECHO ***
- )
-
- test_script:
- - ECHO Testing %COMPILER% %PLATFORM% %CONFIGURATION%
- - SET "CC=gcc"
- - SET "CXX=g++"
- - if [%TEST%]==[cmake] (
- mkdir build\cmake\build &&
- cd build\cmake\build &&
- SET FUZZERTEST=-T2mn &&
- SET ZSTREAM_TESTTIME=-T2mn &&
- cmake -G "Visual Studio 14 2015 Win64" .. &&
- cd ..\..\.. &&
- make clean
- )
-
-
-# The following tests are for regular pushes
-# into `dev` or some feature branch
-# There run less tests, for shorter feedback loop
-
--
- version: 1.0.{build}
- environment:
- matrix:
- - COMPILER: "visual"
- HOST: "visual"
- PLATFORM: "x64"
- CONFIGURATION: "Debug"
- - COMPILER: "visual"
- HOST: "visual"
- PLATFORM: "Win32"
- CONFIGURATION: "Debug"
- - COMPILER: "visual"
- HOST: "visual"
- PLATFORM: "x64"
- CONFIGURATION: "Release"
- - COMPILER: "visual"
- HOST: "visual"
- PLATFORM: "Win32"
- CONFIGURATION: "Release"
-
- - COMPILER: "gcc"
- HOST: "cygwin"
- PLATFORM: "x64"
-
- - COMPILER: "clang-cl"
- HOST: "cmake-visual"
- PLATFORM: "x64"
- CONFIGURATION: "Release"
- CMAKE_GENERATOR: "Visual Studio 15 2017"
- CMAKE_GENERATOR_PLATFORM: "x64"
- CMAKE_GENERATOR_TOOLSET: "LLVM"
- APPVEYOR_BUILD_WORKER_IMAGE: "Visual Studio 2017"
-
- install:
- - ECHO Installing %COMPILER% %PLATFORM% %CONFIGURATION%
- - SET PATH_ORIGINAL=%PATH%
- - if [%HOST%]==[cygwin] (
- ECHO Installing Cygwin Packages &&
- C:\cygwin64\setup-x86_64.exe -qnNdO -R "C:\cygwin64" -g -P ^
- gcc,^
- cmake,^
- make
- )
- - IF [%HOST%]==[visual] IF [%PLATFORM%]==[x64] (
- SET ADDITIONALPARAM=/p:LibraryPath="C:\Program Files\Microsoft SDKs\Windows\v7.1\lib\x64;c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib\amd64;C:\Program Files (x86)\Microsoft Visual Studio 10.0\;C:\Program Files (x86)\Microsoft Visual Studio 10.0\lib\amd64;"
- )
-
- build_script:
- - ECHO Building %COMPILER% %PLATFORM% %CONFIGURATION%
- - if [%HOST%]==[cygwin] (
- set CHERE_INVOKING=yes &&
- set CC=%COMPILER% &&
- C:\cygwin64\bin\bash --login -c "
- set -e;
- cd build/cmake;
- CFLAGS='-Werror' cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE=Debug -DZSTD_BUILD_TESTS:BOOL=ON -DZSTD_FUZZER_FLAGS=-T20s -DZSTD_ZSTREAM_FLAGS=-T20s -DZSTD_FULLBENCH_FLAGS=-i0 .;
- make VERBOSE=1 -j;
- ctest -V -L Medium;
- "
- )
- - if [%HOST%]==[cmake-visual] (
- ECHO *** &&
- ECHO *** Building %CMAKE_GENERATOR% ^(%CMAKE_GENERATOR_TOOLSET%^) %PLATFORM%\%CONFIGURATION% &&
- PUSHD build\cmake &&
- cmake -DBUILD_TESTING=ON . &&
- cmake --build . --config %CONFIGURATION% -j4 &&
- POPD &&
- ECHO ***
- )
- - if [%HOST%]==[visual] (
- ECHO *** &&
- ECHO *** Building Visual Studio 2012 %PLATFORM%\%CONFIGURATION% &&
- ECHO *** &&
- msbuild "build\VS2010\zstd.sln" /m /verbosity:minimal /property:PlatformToolset=v110 /p:ForceImportBeforeCppTargets=%APPVEYOR_BUILD_FOLDER%\build\VS2010\CompileAsCpp.props /t:Clean,Build /p:Platform=%PLATFORM% /p:Configuration=%CONFIGURATION% /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" &&
- DIR build\VS2010\bin\%PLATFORM%_%CONFIGURATION%\*.exe &&
- msbuild "build\VS2010\zstd.sln" /m /verbosity:minimal /property:PlatformToolset=v110 /t:Clean,Build /p:Platform=%PLATFORM% /p:Configuration=%CONFIGURATION% /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" &&
- DIR build\VS2010\bin\%PLATFORM%_%CONFIGURATION%\*.exe
- )
-
-
- test_script:
- - ECHO Testing %COMPILER% %PLATFORM% %CONFIGURATION%
- - SET "FUZZERTEST=-T10s"
- - if [%HOST%]==[mingw] (
- set "CC=%COMPILER%" &&
- make clean &&
- make check
- )
\ No newline at end of file
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/cmake/zstdConfig.cmake b/deps/libchdr/deps/zstd-1.5.5/build/cmake/zstdConfig.cmake
deleted file mode 100644
index ebbfcc38..00000000
--- a/deps/libchdr/deps/zstd-1.5.5/build/cmake/zstdConfig.cmake
+++ /dev/null
@@ -1 +0,0 @@
-include("${CMAKE_CURRENT_LIST_DIR}/zstdTargets.cmake")
diff --git a/deps/libchdr/deps/zstd-1.5.5/programs/benchzstd.c b/deps/libchdr/deps/zstd-1.5.5/programs/benchzstd.c
deleted file mode 100644
index 9bc3628e..00000000
--- a/deps/libchdr/deps/zstd-1.5.5/programs/benchzstd.c
+++ /dev/null
@@ -1,914 +0,0 @@
-/*
- * Copyright (c) Meta Platforms, Inc. and affiliates.
- * All rights reserved.
- *
- * This source code is licensed under both the BSD-style license (found in the
- * LICENSE file in the root directory of this source tree) and the GPLv2 (found
- * in the COPYING file in the root directory of this source tree).
- * You may select, at your option, one of the above-listed licenses.
- */
-
-
-/* **************************************
-* Tuning parameters
-****************************************/
-#ifndef BMK_TIMETEST_DEFAULT_S /* default minimum time per test */
-# define BMK_TIMETEST_DEFAULT_S 3
-#endif
-
-
-/* *************************************
-* Includes
-***************************************/
-#include "platform.h" /* Large Files support */
-#include "util.h" /* UTIL_getFileSize, UTIL_sleep */
-#include /* malloc, free */
-#include /* memset, strerror */
-#include /* fprintf, fopen */
-#include
-#include /* assert */
-
-#include "timefn.h" /* UTIL_time_t */
-#include "benchfn.h"
-#include "../lib/common/mem.h"
-#ifndef ZSTD_STATIC_LINKING_ONLY
-#define ZSTD_STATIC_LINKING_ONLY
-#endif
-#include "../lib/zstd.h"
-#include "datagen.h" /* RDG_genBuffer */
-#ifndef XXH_INLINE_ALL
-#define XXH_INLINE_ALL
-#endif
-#include "../lib/common/xxhash.h"
-#include "benchzstd.h"
-#include "../lib/zstd_errors.h"
-
-
-/* *************************************
-* Constants
-***************************************/
-#ifndef ZSTD_GIT_COMMIT
-# define ZSTD_GIT_COMMIT_STRING ""
-#else
-# define ZSTD_GIT_COMMIT_STRING ZSTD_EXPAND_AND_QUOTE(ZSTD_GIT_COMMIT)
-#endif
-
-#define TIMELOOP_MICROSEC (1*1000000ULL) /* 1 second */
-#define TIMELOOP_NANOSEC (1*1000000000ULL) /* 1 second */
-#define ACTIVEPERIOD_MICROSEC (70*TIMELOOP_MICROSEC) /* 70 seconds */
-#define COOLPERIOD_SEC 10
-
-#define KB *(1 <<10)
-#define MB *(1 <<20)
-#define GB *(1U<<30)
-
-#define BMK_RUNTEST_DEFAULT_MS 1000
-
-static const size_t maxMemory = (sizeof(size_t)==4) ?
- /* 32-bit */ (2 GB - 64 MB) :
- /* 64-bit */ (size_t)(1ULL << ((sizeof(size_t)*8)-31));
-
-
-/* *************************************
-* console display
-***************************************/
-#define DISPLAY(...) { fprintf(stderr, __VA_ARGS__); fflush(NULL); }
-#define DISPLAYLEVEL(l, ...) if (displayLevel>=l) { DISPLAY(__VA_ARGS__); }
-/* 0 : no display; 1: errors; 2 : + result + interaction + warnings; 3 : + progression; 4 : + information */
-#define OUTPUT(...) { fprintf(stdout, __VA_ARGS__); fflush(NULL); }
-#define OUTPUTLEVEL(l, ...) if (displayLevel>=l) { OUTPUT(__VA_ARGS__); }
-
-
-/* *************************************
-* Exceptions
-***************************************/
-#ifndef DEBUG
-# define DEBUG 0
-#endif
-#define DEBUGOUTPUT(...) { if (DEBUG) DISPLAY(__VA_ARGS__); }
-
-#define RETURN_ERROR_INT(errorNum, ...) { \
- DEBUGOUTPUT("%s: %i: \n", __FILE__, __LINE__); \
- DISPLAYLEVEL(1, "Error %i : ", errorNum); \
- DISPLAYLEVEL(1, __VA_ARGS__); \
- DISPLAYLEVEL(1, " \n"); \
- return errorNum; \
-}
-
-#define CHECK_Z(zf) { \
- size_t const zerr = zf; \
- if (ZSTD_isError(zerr)) { \
- DEBUGOUTPUT("%s: %i: \n", __FILE__, __LINE__); \
- DISPLAY("Error : "); \
- DISPLAY("%s failed : %s", \
- #zf, ZSTD_getErrorName(zerr)); \
- DISPLAY(" \n"); \
- exit(1); \
- } \
-}
-
-#define RETURN_ERROR(errorNum, retType, ...) { \
- retType r; \
- memset(&r, 0, sizeof(retType)); \
- DEBUGOUTPUT("%s: %i: \n", __FILE__, __LINE__); \
- DISPLAYLEVEL(1, "Error %i : ", errorNum); \
- DISPLAYLEVEL(1, __VA_ARGS__); \
- DISPLAYLEVEL(1, " \n"); \
- r.tag = errorNum; \
- return r; \
-}
-
-
-/* *************************************
-* Benchmark Parameters
-***************************************/
-
-BMK_advancedParams_t BMK_initAdvancedParams(void) {
- BMK_advancedParams_t const res = {
- BMK_both, /* mode */
- BMK_TIMETEST_DEFAULT_S, /* nbSeconds */
- 0, /* blockSize */
- 0, /* nbWorkers */
- 0, /* realTime */
- 0, /* additionalParam */
- 0, /* ldmFlag */
- 0, /* ldmMinMatch */
- 0, /* ldmHashLog */
- 0, /* ldmBuckSizeLog */
- 0, /* ldmHashRateLog */
- ZSTD_ps_auto, /* literalCompressionMode */
- 0 /* useRowMatchFinder */
- };
- return res;
-}
-
-
-/* ********************************************************
-* Bench functions
-**********************************************************/
-typedef struct {
- const void* srcPtr;
- size_t srcSize;
- void* cPtr;
- size_t cRoom;
- size_t cSize;
- void* resPtr;
- size_t resSize;
-} blockParam_t;
-
-#undef MIN
-#undef MAX
-#define MIN(a,b) ((a) < (b) ? (a) : (b))
-#define MAX(a,b) ((a) > (b) ? (a) : (b))
-
-static void
-BMK_initCCtx(ZSTD_CCtx* ctx,
- const void* dictBuffer, size_t dictBufferSize,
- int cLevel,
- const ZSTD_compressionParameters* comprParams,
- const BMK_advancedParams_t* adv)
-{
- ZSTD_CCtx_reset(ctx, ZSTD_reset_session_and_parameters);
- if (adv->nbWorkers==1) {
- CHECK_Z(ZSTD_CCtx_setParameter(ctx, ZSTD_c_nbWorkers, 0));
- } else {
- CHECK_Z(ZSTD_CCtx_setParameter(ctx, ZSTD_c_nbWorkers, adv->nbWorkers));
- }
- CHECK_Z(ZSTD_CCtx_setParameter(ctx, ZSTD_c_compressionLevel, cLevel));
- CHECK_Z(ZSTD_CCtx_setParameter(ctx, ZSTD_c_useRowMatchFinder, adv->useRowMatchFinder));
- CHECK_Z(ZSTD_CCtx_setParameter(ctx, ZSTD_c_enableLongDistanceMatching, adv->ldmFlag));
- CHECK_Z(ZSTD_CCtx_setParameter(ctx, ZSTD_c_ldmMinMatch, adv->ldmMinMatch));
- CHECK_Z(ZSTD_CCtx_setParameter(ctx, ZSTD_c_ldmHashLog, adv->ldmHashLog));
- CHECK_Z(ZSTD_CCtx_setParameter(ctx, ZSTD_c_ldmBucketSizeLog, adv->ldmBucketSizeLog));
- CHECK_Z(ZSTD_CCtx_setParameter(ctx, ZSTD_c_ldmHashRateLog, adv->ldmHashRateLog));
- CHECK_Z(ZSTD_CCtx_setParameter(ctx, ZSTD_c_windowLog, (int)comprParams->windowLog));
- CHECK_Z(ZSTD_CCtx_setParameter(ctx, ZSTD_c_hashLog, (int)comprParams->hashLog));
- CHECK_Z(ZSTD_CCtx_setParameter(ctx, ZSTD_c_chainLog, (int)comprParams->chainLog));
- CHECK_Z(ZSTD_CCtx_setParameter(ctx, ZSTD_c_searchLog, (int)comprParams->searchLog));
- CHECK_Z(ZSTD_CCtx_setParameter(ctx, ZSTD_c_minMatch, (int)comprParams->minMatch));
- CHECK_Z(ZSTD_CCtx_setParameter(ctx, ZSTD_c_targetLength, (int)comprParams->targetLength));
- CHECK_Z(ZSTD_CCtx_setParameter(ctx, ZSTD_c_literalCompressionMode, (int)adv->literalCompressionMode));
- CHECK_Z(ZSTD_CCtx_setParameter(ctx, ZSTD_c_strategy, (int)comprParams->strategy));
- CHECK_Z(ZSTD_CCtx_loadDictionary(ctx, dictBuffer, dictBufferSize));
-}
-
-static void BMK_initDCtx(ZSTD_DCtx* dctx,
- const void* dictBuffer, size_t dictBufferSize) {
- CHECK_Z(ZSTD_DCtx_reset(dctx, ZSTD_reset_session_and_parameters));
- CHECK_Z(ZSTD_DCtx_loadDictionary(dctx, dictBuffer, dictBufferSize));
-}
-
-
-typedef struct {
- ZSTD_CCtx* cctx;
- const void* dictBuffer;
- size_t dictBufferSize;
- int cLevel;
- const ZSTD_compressionParameters* comprParams;
- const BMK_advancedParams_t* adv;
-} BMK_initCCtxArgs;
-
-static size_t local_initCCtx(void* payload) {
- BMK_initCCtxArgs* ag = (BMK_initCCtxArgs*)payload;
- BMK_initCCtx(ag->cctx, ag->dictBuffer, ag->dictBufferSize, ag->cLevel, ag->comprParams, ag->adv);
- return 0;
-}
-
-typedef struct {
- ZSTD_DCtx* dctx;
- const void* dictBuffer;
- size_t dictBufferSize;
-} BMK_initDCtxArgs;
-
-static size_t local_initDCtx(void* payload) {
- BMK_initDCtxArgs* ag = (BMK_initDCtxArgs*)payload;
- BMK_initDCtx(ag->dctx, ag->dictBuffer, ag->dictBufferSize);
- return 0;
-}
-
-
-/* `addArgs` is the context */
-static size_t local_defaultCompress(
- const void* srcBuffer, size_t srcSize,
- void* dstBuffer, size_t dstSize,
- void* addArgs)
-{
- ZSTD_CCtx* const cctx = (ZSTD_CCtx*)addArgs;
- return ZSTD_compress2(cctx, dstBuffer, dstSize, srcBuffer, srcSize);
-}
-
-/* `addArgs` is the context */
-static size_t local_defaultDecompress(
- const void* srcBuffer, size_t srcSize,
- void* dstBuffer, size_t dstCapacity,
- void* addArgs)
-{
- size_t moreToFlush = 1;
- ZSTD_DCtx* const dctx = (ZSTD_DCtx*)addArgs;
- ZSTD_inBuffer in;
- ZSTD_outBuffer out;
- in.src = srcBuffer; in.size = srcSize; in.pos = 0;
- out.dst = dstBuffer; out.size = dstCapacity; out.pos = 0;
- while (moreToFlush) {
- if(out.pos == out.size) {
- return (size_t)-ZSTD_error_dstSize_tooSmall;
- }
- moreToFlush = ZSTD_decompressStream(dctx, &out, &in);
- if (ZSTD_isError(moreToFlush)) {
- return moreToFlush;
- }
- }
- return out.pos;
-
-}
-
-
-/* ================================================================= */
-/* Benchmark Zstandard, mem-to-mem scenarios */
-/* ================================================================= */
-
-int BMK_isSuccessful_benchOutcome(BMK_benchOutcome_t outcome)
-{
- return outcome.tag == 0;
-}
-
-BMK_benchResult_t BMK_extract_benchResult(BMK_benchOutcome_t outcome)
-{
- assert(outcome.tag == 0);
- return outcome.internal_never_use_directly;
-}
-
-static BMK_benchOutcome_t BMK_benchOutcome_error(void)
-{
- BMK_benchOutcome_t b;
- memset(&b, 0, sizeof(b));
- b.tag = 1;
- return b;
-}
-
-static BMK_benchOutcome_t BMK_benchOutcome_setValidResult(BMK_benchResult_t result)
-{
- BMK_benchOutcome_t b;
- b.tag = 0;
- b.internal_never_use_directly = result;
- return b;
-}
-
-
-/* benchMem with no allocation */
-static BMK_benchOutcome_t
-BMK_benchMemAdvancedNoAlloc(
- const void** srcPtrs, size_t* srcSizes,
- void** cPtrs, size_t* cCapacities, size_t* cSizes,
- void** resPtrs, size_t* resSizes,
- void** resultBufferPtr, void* compressedBuffer,
- size_t maxCompressedSize,
- BMK_timedFnState_t* timeStateCompress,
- BMK_timedFnState_t* timeStateDecompress,
-
- const void* srcBuffer, size_t srcSize,
- const size_t* fileSizes, unsigned nbFiles,
- const int cLevel,
- const ZSTD_compressionParameters* comprParams,
- const void* dictBuffer, size_t dictBufferSize,
- ZSTD_CCtx* cctx, ZSTD_DCtx* dctx,
- int displayLevel, const char* displayName,
- const BMK_advancedParams_t* adv)
-{
- size_t const blockSize = ((adv->blockSize>=32 && (adv->mode != BMK_decodeOnly)) ? adv->blockSize : srcSize) + (!srcSize); /* avoid div by 0 */
- BMK_benchResult_t benchResult;
- size_t const loadedCompressedSize = srcSize;
- size_t cSize = 0;
- double ratio = 0.;
- U32 nbBlocks;
-
- assert(cctx != NULL); assert(dctx != NULL);
-
- /* init */
- memset(&benchResult, 0, sizeof(benchResult));
- if (strlen(displayName)>17) displayName += strlen(displayName) - 17; /* display last 17 characters */
- if (adv->mode == BMK_decodeOnly) {
- /* benchmark only decompression : source must be already compressed */
- const char* srcPtr = (const char*)srcBuffer;
- U64 totalDSize64 = 0;
- U32 fileNb;
- for (fileNb=0; fileNb decodedSize) { /* size_t overflow */
- RETURN_ERROR(32, BMK_benchOutcome_t, "decompressed size is too large for local system");
- }
- *resultBufferPtr = malloc(decodedSize);
- if (!(*resultBufferPtr)) {
- RETURN_ERROR(33, BMK_benchOutcome_t, "allocation error: not enough memory");
- }
- cSize = srcSize;
- srcSize = decodedSize;
- ratio = (double)srcSize / (double)cSize;
- }
- }
-
- /* Init data blocks */
- { const char* srcPtr = (const char*)srcBuffer;
- char* cPtr = (char*)compressedBuffer;
- char* resPtr = (char*)(*resultBufferPtr);
- U32 fileNb;
- for (nbBlocks=0, fileNb=0; fileNbmode == BMK_decodeOnly) ? 1 : (U32)((remaining + (blockSize-1)) / blockSize);
- U32 const blockEnd = nbBlocks + nbBlocksforThisFile;
- for ( ; nbBlocksmode == BMK_decodeOnly) ? thisBlockSize : ZSTD_compressBound(thisBlockSize);
- resPtrs[nbBlocks] = resPtr;
- resSizes[nbBlocks] = (adv->mode == BMK_decodeOnly) ? (size_t) ZSTD_findDecompressedSize(srcPtr, thisBlockSize) : thisBlockSize;
- srcPtr += thisBlockSize;
- cPtr += cCapacities[nbBlocks];
- resPtr += thisBlockSize;
- remaining -= thisBlockSize;
- if (adv->mode == BMK_decodeOnly) {
- cSizes[nbBlocks] = thisBlockSize;
- benchResult.cSize = thisBlockSize;
- } } } }
-
- /* warming up `compressedBuffer` */
- if (adv->mode == BMK_decodeOnly) {
- memcpy(compressedBuffer, srcBuffer, loadedCompressedSize);
- } else {
- RDG_genBuffer(compressedBuffer, maxCompressedSize, 0.10, 0.50, 1);
- }
-
- if (!UTIL_support_MT_measurements() && adv->nbWorkers > 1) {
- OUTPUTLEVEL(2, "Warning : time measurements may be incorrect in multithreading mode... \n")
- }
-
- /* Bench */
- { U64 const crcOrig = (adv->mode == BMK_decodeOnly) ? 0 : XXH64(srcBuffer, srcSize, 0);
-# define NB_MARKS 4
- const char* marks[NB_MARKS] = { " |", " /", " =", " \\" };
- U32 markNb = 0;
- int compressionCompleted = (adv->mode == BMK_decodeOnly);
- int decompressionCompleted = (adv->mode == BMK_compressOnly);
- BMK_benchParams_t cbp, dbp;
- BMK_initCCtxArgs cctxprep;
- BMK_initDCtxArgs dctxprep;
-
- cbp.benchFn = local_defaultCompress; /* ZSTD_compress2 */
- cbp.benchPayload = cctx;
- cbp.initFn = local_initCCtx; /* BMK_initCCtx */
- cbp.initPayload = &cctxprep;
- cbp.errorFn = ZSTD_isError;
- cbp.blockCount = nbBlocks;
- cbp.srcBuffers = srcPtrs;
- cbp.srcSizes = srcSizes;
- cbp.dstBuffers = cPtrs;
- cbp.dstCapacities = cCapacities;
- cbp.blockResults = cSizes;
-
- cctxprep.cctx = cctx;
- cctxprep.dictBuffer = dictBuffer;
- cctxprep.dictBufferSize = dictBufferSize;
- cctxprep.cLevel = cLevel;
- cctxprep.comprParams = comprParams;
- cctxprep.adv = adv;
-
- dbp.benchFn = local_defaultDecompress;
- dbp.benchPayload = dctx;
- dbp.initFn = local_initDCtx;
- dbp.initPayload = &dctxprep;
- dbp.errorFn = ZSTD_isError;
- dbp.blockCount = nbBlocks;
- dbp.srcBuffers = (const void* const *) cPtrs;
- dbp.srcSizes = cSizes;
- dbp.dstBuffers = resPtrs;
- dbp.dstCapacities = resSizes;
- dbp.blockResults = NULL;
-
- dctxprep.dctx = dctx;
- dctxprep.dictBuffer = dictBuffer;
- dctxprep.dictBufferSize = dictBufferSize;
-
- OUTPUTLEVEL(2, "\r%70s\r", ""); /* blank line */
- assert(srcSize < UINT_MAX);
- OUTPUTLEVEL(2, "%2s-%-17.17s :%10u -> \r", marks[markNb], displayName, (unsigned)srcSize);
-
- while (!(compressionCompleted && decompressionCompleted)) {
- if (!compressionCompleted) {
- BMK_runOutcome_t const cOutcome = BMK_benchTimedFn( timeStateCompress, cbp);
-
- if (!BMK_isSuccessful_runOutcome(cOutcome)) {
- RETURN_ERROR(30, BMK_benchOutcome_t, "compression error");
- }
-
- { BMK_runTime_t const cResult = BMK_extract_runTime(cOutcome);
- cSize = cResult.sumOfReturn;
- ratio = (double)srcSize / (double)cSize;
- { BMK_benchResult_t newResult;
- newResult.cSpeed = (U64)((double)srcSize * TIMELOOP_NANOSEC / cResult.nanoSecPerRun);
- benchResult.cSize = cSize;
- if (newResult.cSpeed > benchResult.cSpeed)
- benchResult.cSpeed = newResult.cSpeed;
- } }
-
- { int const ratioAccuracy = (ratio < 10.) ? 3 : 2;
- assert(cSize < UINT_MAX);
- OUTPUTLEVEL(2, "%2s-%-17.17s :%10u ->%10u (x%5.*f), %6.*f MB/s \r",
- marks[markNb], displayName,
- (unsigned)srcSize, (unsigned)cSize,
- ratioAccuracy, ratio,
- benchResult.cSpeed < (10 * MB_UNIT) ? 2 : 1, (double)benchResult.cSpeed / MB_UNIT);
- }
- compressionCompleted = BMK_isCompleted_TimedFn(timeStateCompress);
- }
-
- if(!decompressionCompleted) {
- BMK_runOutcome_t const dOutcome = BMK_benchTimedFn(timeStateDecompress, dbp);
-
- if(!BMK_isSuccessful_runOutcome(dOutcome)) {
- RETURN_ERROR(30, BMK_benchOutcome_t, "decompression error");
- }
-
- { BMK_runTime_t const dResult = BMK_extract_runTime(dOutcome);
- U64 const newDSpeed = (U64)((double)srcSize * TIMELOOP_NANOSEC / dResult.nanoSecPerRun);
- if (newDSpeed > benchResult.dSpeed)
- benchResult.dSpeed = newDSpeed;
- }
-
- { int const ratioAccuracy = (ratio < 10.) ? 3 : 2;
- OUTPUTLEVEL(2, "%2s-%-17.17s :%10u ->%10u (x%5.*f), %6.*f MB/s, %6.1f MB/s\r",
- marks[markNb], displayName,
- (unsigned)srcSize, (unsigned)cSize,
- ratioAccuracy, ratio,
- benchResult.cSpeed < (10 * MB_UNIT) ? 2 : 1, (double)benchResult.cSpeed / MB_UNIT,
- (double)benchResult.dSpeed / MB_UNIT);
- }
- decompressionCompleted = BMK_isCompleted_TimedFn(timeStateDecompress);
- }
- markNb = (markNb+1) % NB_MARKS;
- } /* while (!(compressionCompleted && decompressionCompleted)) */
-
- /* CRC Checking */
- { const BYTE* resultBuffer = (const BYTE*)(*resultBufferPtr);
- U64 const crcCheck = XXH64(resultBuffer, srcSize, 0);
- if ((adv->mode == BMK_both) && (crcOrig!=crcCheck)) {
- size_t u;
- DISPLAY("!!! WARNING !!! %14s : Invalid Checksum : %x != %x \n",
- displayName, (unsigned)crcOrig, (unsigned)crcCheck);
- for (u=0; u u) break;
- bacc += srcSizes[segNb];
- }
- pos = (U32)(u - bacc);
- bNb = pos / (128 KB);
- DISPLAY("(sample %u, block %u, pos %u) \n", segNb, bNb, pos);
- { size_t const lowest = (u>5) ? 5 : u;
- size_t n;
- DISPLAY("origin: ");
- for (n=lowest; n>0; n--)
- DISPLAY("%02X ", ((const BYTE*)srcBuffer)[u-n]);
- DISPLAY(" :%02X: ", ((const BYTE*)srcBuffer)[u]);
- for (n=1; n<3; n++)
- DISPLAY("%02X ", ((const BYTE*)srcBuffer)[u+n]);
- DISPLAY(" \n");
- DISPLAY("decode: ");
- for (n=lowest; n>0; n--)
- DISPLAY("%02X ", resultBuffer[u-n]);
- DISPLAY(" :%02X: ", resultBuffer[u]);
- for (n=1; n<3; n++)
- DISPLAY("%02X ", resultBuffer[u+n]);
- DISPLAY(" \n");
- }
- break;
- }
- if (u==srcSize-1) { /* should never happen */
- DISPLAY("no difference detected\n");
- }
- } /* for (u=0; umode == BMK_both) && (crcOrig!=crcCheck)) */
- } /* CRC Checking */
-
- if (displayLevel == 1) { /* hidden display mode -q, used by python speed benchmark */
- double const cSpeed = (double)benchResult.cSpeed / MB_UNIT;
- double const dSpeed = (double)benchResult.dSpeed / MB_UNIT;
- if (adv->additionalParam) {
- OUTPUT("-%-3i%11i (%5.3f) %6.2f MB/s %6.1f MB/s %s (param=%d)\n", cLevel, (int)cSize, ratio, cSpeed, dSpeed, displayName, adv->additionalParam);
- } else {
- OUTPUT("-%-3i%11i (%5.3f) %6.2f MB/s %6.1f MB/s %s\n", cLevel, (int)cSize, ratio, cSpeed, dSpeed, displayName);
- }
- }
-
- OUTPUTLEVEL(2, "%2i#\n", cLevel);
- } /* Bench */
-
- benchResult.cMem = (1ULL << (comprParams->windowLog)) + ZSTD_sizeof_CCtx(cctx);
- return BMK_benchOutcome_setValidResult(benchResult);
-}
-
-BMK_benchOutcome_t BMK_benchMemAdvanced(const void* srcBuffer, size_t srcSize,
- void* dstBuffer, size_t dstCapacity,
- const size_t* fileSizes, unsigned nbFiles,
- int cLevel, const ZSTD_compressionParameters* comprParams,
- const void* dictBuffer, size_t dictBufferSize,
- int displayLevel, const char* displayName, const BMK_advancedParams_t* adv)
-
-{
- int const dstParamsError = !dstBuffer ^ !dstCapacity; /* must be both NULL or none */
-
- size_t const blockSize = ((adv->blockSize>=32 && (adv->mode != BMK_decodeOnly)) ? adv->blockSize : srcSize) + (!srcSize) /* avoid div by 0 */ ;
- U32 const maxNbBlocks = (U32) ((srcSize + (blockSize-1)) / blockSize) + nbFiles;
-
- /* these are the blockTable parameters, just split up */
- const void ** const srcPtrs = (const void**)malloc(maxNbBlocks * sizeof(void*));
- size_t* const srcSizes = (size_t*)malloc(maxNbBlocks * sizeof(size_t));
-
-
- void ** const cPtrs = (void**)malloc(maxNbBlocks * sizeof(void*));
- size_t* const cSizes = (size_t*)malloc(maxNbBlocks * sizeof(size_t));
- size_t* const cCapacities = (size_t*)malloc(maxNbBlocks * sizeof(size_t));
-
- void ** const resPtrs = (void**)malloc(maxNbBlocks * sizeof(void*));
- size_t* const resSizes = (size_t*)malloc(maxNbBlocks * sizeof(size_t));
-
- BMK_timedFnState_t* timeStateCompress = BMK_createTimedFnState(adv->nbSeconds * 1000, BMK_RUNTEST_DEFAULT_MS);
- BMK_timedFnState_t* timeStateDecompress = BMK_createTimedFnState(adv->nbSeconds * 1000, BMK_RUNTEST_DEFAULT_MS);
-
- ZSTD_CCtx* const cctx = ZSTD_createCCtx();
- ZSTD_DCtx* const dctx = ZSTD_createDCtx();
-
- const size_t maxCompressedSize = dstCapacity ? dstCapacity : ZSTD_compressBound(srcSize) + (maxNbBlocks * 1024);
-
- void* const internalDstBuffer = dstBuffer ? NULL : malloc(maxCompressedSize);
- void* const compressedBuffer = dstBuffer ? dstBuffer : internalDstBuffer;
-
- BMK_benchOutcome_t outcome = BMK_benchOutcome_error(); /* error by default */
-
- void* resultBuffer = srcSize ? malloc(srcSize) : NULL;
-
- int const allocationincomplete = !srcPtrs || !srcSizes || !cPtrs ||
- !cSizes || !cCapacities || !resPtrs || !resSizes ||
- !timeStateCompress || !timeStateDecompress ||
- !cctx || !dctx ||
- !compressedBuffer || !resultBuffer;
-
-
- if (!allocationincomplete && !dstParamsError) {
- outcome = BMK_benchMemAdvancedNoAlloc(srcPtrs, srcSizes,
- cPtrs, cCapacities, cSizes,
- resPtrs, resSizes,
- &resultBuffer,
- compressedBuffer, maxCompressedSize,
- timeStateCompress, timeStateDecompress,
- srcBuffer, srcSize,
- fileSizes, nbFiles,
- cLevel, comprParams,
- dictBuffer, dictBufferSize,
- cctx, dctx,
- displayLevel, displayName, adv);
- }
-
- /* clean up */
- BMK_freeTimedFnState(timeStateCompress);
- BMK_freeTimedFnState(timeStateDecompress);
-
- ZSTD_freeCCtx(cctx);
- ZSTD_freeDCtx(dctx);
-
- free(internalDstBuffer);
- free(resultBuffer);
-
- free((void*)srcPtrs);
- free(srcSizes);
- free(cPtrs);
- free(cSizes);
- free(cCapacities);
- free(resPtrs);
- free(resSizes);
-
- if(allocationincomplete) {
- RETURN_ERROR(31, BMK_benchOutcome_t, "allocation error : not enough memory");
- }
-
- if(dstParamsError) {
- RETURN_ERROR(32, BMK_benchOutcome_t, "Dst parameters not coherent");
- }
- return outcome;
-}
-
-BMK_benchOutcome_t BMK_benchMem(const void* srcBuffer, size_t srcSize,
- const size_t* fileSizes, unsigned nbFiles,
- int cLevel, const ZSTD_compressionParameters* comprParams,
- const void* dictBuffer, size_t dictBufferSize,
- int displayLevel, const char* displayName) {
-
- BMK_advancedParams_t const adv = BMK_initAdvancedParams();
- return BMK_benchMemAdvanced(srcBuffer, srcSize,
- NULL, 0,
- fileSizes, nbFiles,
- cLevel, comprParams,
- dictBuffer, dictBufferSize,
- displayLevel, displayName, &adv);
-}
-
-static BMK_benchOutcome_t BMK_benchCLevel(const void* srcBuffer, size_t benchedSize,
- const size_t* fileSizes, unsigned nbFiles,
- int cLevel, const ZSTD_compressionParameters* comprParams,
- const void* dictBuffer, size_t dictBufferSize,
- int displayLevel, const char* displayName,
- BMK_advancedParams_t const * const adv)
-{
- const char* pch = strrchr(displayName, '\\'); /* Windows */
- if (!pch) pch = strrchr(displayName, '/'); /* Linux */
- if (pch) displayName = pch+1;
-
- if (adv->realTime) {
- DISPLAYLEVEL(2, "Note : switching to real-time priority \n");
- SET_REALTIME_PRIORITY;
- }
-
- if (displayLevel == 1 && !adv->additionalParam) /* --quiet mode */
- OUTPUT("bench %s %s: input %u bytes, %u seconds, %u KB blocks\n",
- ZSTD_VERSION_STRING, ZSTD_GIT_COMMIT_STRING,
- (unsigned)benchedSize, adv->nbSeconds, (unsigned)(adv->blockSize>>10));
-
- return BMK_benchMemAdvanced(srcBuffer, benchedSize,
- NULL, 0,
- fileSizes, nbFiles,
- cLevel, comprParams,
- dictBuffer, dictBufferSize,
- displayLevel, displayName, adv);
-}
-
-int BMK_syntheticTest(int cLevel, double compressibility,
- const ZSTD_compressionParameters* compressionParams,
- int displayLevel, const BMK_advancedParams_t* adv)
-{
- char name[20] = {0};
- size_t const benchedSize = 10000000;
- void* srcBuffer;
- BMK_benchOutcome_t res;
-
- if (cLevel > ZSTD_maxCLevel()) {
- DISPLAYLEVEL(1, "Invalid Compression Level");
- return 15;
- }
-
- /* Memory allocation */
- srcBuffer = malloc(benchedSize);
- if (!srcBuffer) {
- DISPLAYLEVEL(1, "allocation error : not enough memory");
- return 16;
- }
-
- /* Fill input buffer */
- RDG_genBuffer(srcBuffer, benchedSize, compressibility, 0.0, 0);
-
- /* Bench */
- snprintf (name, sizeof(name), "Synthetic %2u%%", (unsigned)(compressibility*100));
- res = BMK_benchCLevel(srcBuffer, benchedSize,
- &benchedSize /* ? */, 1 /* ? */,
- cLevel, compressionParams,
- NULL, 0, /* dictionary */
- displayLevel, name, adv);
-
- /* clean up */
- free(srcBuffer);
-
- return !BMK_isSuccessful_benchOutcome(res);
-}
-
-
-
-static size_t BMK_findMaxMem(U64 requiredMem)
-{
- size_t const step = 64 MB;
- BYTE* testmem = NULL;
-
- requiredMem = (((requiredMem >> 26) + 1) << 26);
- requiredMem += step;
- if (requiredMem > maxMemory) requiredMem = maxMemory;
-
- do {
- testmem = (BYTE*)malloc((size_t)requiredMem);
- requiredMem -= step;
- } while (!testmem && requiredMem > 0);
-
- free(testmem);
- return (size_t)(requiredMem);
-}
-
-/*! BMK_loadFiles() :
- * Loads `buffer` with content of files listed within `fileNamesTable`.
- * At most, fills `buffer` entirely. */
-static int BMK_loadFiles(void* buffer, size_t bufferSize,
- size_t* fileSizes,
- const char* const * fileNamesTable, unsigned nbFiles,
- int displayLevel)
-{
- size_t pos = 0, totalSize = 0;
- unsigned n;
- for (n=0; n bufferSize-pos) fileSize = bufferSize-pos, nbFiles=n; /* buffer too small - stop after this file */
- { size_t const readSize = fread(((char*)buffer)+pos, 1, (size_t)fileSize, f);
- if (readSize != (size_t)fileSize) RETURN_ERROR_INT(11, "could not read %s", fileNamesTable[n]);
- pos += readSize;
- }
- fileSizes[n] = (size_t)fileSize;
- totalSize += (size_t)fileSize;
- fclose(f);
- } }
-
- if (totalSize == 0) RETURN_ERROR_INT(12, "no data to bench");
- return 0;
-}
-
-int BMK_benchFilesAdvanced(
- const char* const * fileNamesTable, unsigned nbFiles,
- const char* dictFileName, int cLevel,
- const ZSTD_compressionParameters* compressionParams,
- int displayLevel, const BMK_advancedParams_t* adv)
-{
- void* srcBuffer = NULL;
- size_t benchedSize;
- void* dictBuffer = NULL;
- size_t dictBufferSize = 0;
- size_t* fileSizes = NULL;
- BMK_benchOutcome_t res;
- U64 const totalSizeToLoad = UTIL_getTotalFileSize(fileNamesTable, nbFiles);
-
- if (!nbFiles) {
- DISPLAYLEVEL(1, "No Files to Benchmark");
- return 13;
- }
-
- if (cLevel > ZSTD_maxCLevel()) {
- DISPLAYLEVEL(1, "Invalid Compression Level");
- return 14;
- }
-
- if (totalSizeToLoad == UTIL_FILESIZE_UNKNOWN) {
- DISPLAYLEVEL(1, "Error loading files");
- return 15;
- }
-
- fileSizes = (size_t*)calloc(nbFiles, sizeof(size_t));
- if (!fileSizes) {
- DISPLAYLEVEL(1, "not enough memory for fileSizes");
- return 16;
- }
-
- /* Load dictionary */
- if (dictFileName != NULL) {
- U64 const dictFileSize = UTIL_getFileSize(dictFileName);
- if (dictFileSize == UTIL_FILESIZE_UNKNOWN) {
- DISPLAYLEVEL(1, "error loading %s : %s \n", dictFileName, strerror(errno));
- free(fileSizes);
- DISPLAYLEVEL(1, "benchmark aborted");
- return 17;
- }
- if (dictFileSize > 64 MB) {
- free(fileSizes);
- DISPLAYLEVEL(1, "dictionary file %s too large", dictFileName);
- return 18;
- }
- dictBufferSize = (size_t)dictFileSize;
- dictBuffer = malloc(dictBufferSize);
- if (dictBuffer==NULL) {
- free(fileSizes);
- DISPLAYLEVEL(1, "not enough memory for dictionary (%u bytes)",
- (unsigned)dictBufferSize);
- return 19;
- }
-
- { int const errorCode = BMK_loadFiles(dictBuffer, dictBufferSize,
- fileSizes, &dictFileName /*?*/,
- 1 /*?*/, displayLevel);
- if (errorCode) {
- res = BMK_benchOutcome_error();
- goto _cleanUp;
- } }
- }
-
- /* Memory allocation & restrictions */
- benchedSize = BMK_findMaxMem(totalSizeToLoad * 3) / 3;
- if ((U64)benchedSize > totalSizeToLoad) benchedSize = (size_t)totalSizeToLoad;
- if (benchedSize < totalSizeToLoad)
- DISPLAY("Not enough memory; testing %u MB only...\n", (unsigned)(benchedSize >> 20));
-
- srcBuffer = benchedSize ? malloc(benchedSize) : NULL;
- if (!srcBuffer) {
- free(dictBuffer);
- free(fileSizes);
- DISPLAYLEVEL(1, "not enough memory for srcBuffer");
- return 20;
- }
-
- /* Load input buffer */
- { int const errorCode = BMK_loadFiles(srcBuffer, benchedSize,
- fileSizes, fileNamesTable, nbFiles,
- displayLevel);
- if (errorCode) {
- res = BMK_benchOutcome_error();
- goto _cleanUp;
- } }
-
- /* Bench */
- { char mfName[20] = {0};
- snprintf (mfName, sizeof(mfName), " %u files", nbFiles);
- { const char* const displayName = (nbFiles > 1) ? mfName : fileNamesTable[0];
- res = BMK_benchCLevel(srcBuffer, benchedSize,
- fileSizes, nbFiles,
- cLevel, compressionParams,
- dictBuffer, dictBufferSize,
- displayLevel, displayName,
- adv);
- } }
-
-_cleanUp:
- free(srcBuffer);
- free(dictBuffer);
- free(fileSizes);
- return !BMK_isSuccessful_benchOutcome(res);
-}
-
-
-int BMK_benchFiles(const char* const * fileNamesTable, unsigned nbFiles,
- const char* dictFileName,
- int cLevel, const ZSTD_compressionParameters* compressionParams,
- int displayLevel)
-{
- BMK_advancedParams_t const adv = BMK_initAdvancedParams();
- return BMK_benchFilesAdvanced(fileNamesTable, nbFiles, dictFileName, cLevel, compressionParams, displayLevel, &adv);
-}
diff --git a/deps/libchdr/deps/zstd-1.5.5/tests/cli-tests/bin/unzstd b/deps/libchdr/deps/zstd-1.5.5/tests/cli-tests/bin/unzstd
deleted file mode 120000
index 613f917f..00000000
--- a/deps/libchdr/deps/zstd-1.5.5/tests/cli-tests/bin/unzstd
+++ /dev/null
@@ -1 +0,0 @@
-zstd
\ No newline at end of file
diff --git a/deps/libchdr/deps/zstd-1.5.5/tests/cli-tests/bin/zstdcat b/deps/libchdr/deps/zstd-1.5.5/tests/cli-tests/bin/zstdcat
deleted file mode 120000
index 613f917f..00000000
--- a/deps/libchdr/deps/zstd-1.5.5/tests/cli-tests/bin/zstdcat
+++ /dev/null
@@ -1 +0,0 @@
-zstd
\ No newline at end of file
diff --git a/deps/libchdr/deps/zstd-1.5.5/tests/datagencli.c b/deps/libchdr/deps/zstd-1.5.5/tests/datagencli.c
deleted file mode 100644
index 09ec5e9a..00000000
--- a/deps/libchdr/deps/zstd-1.5.5/tests/datagencli.c
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * Copyright (c) Meta Platforms, Inc. and affiliates.
- * All rights reserved.
- *
- * This source code is licensed under both the BSD-style license (found in the
- * LICENSE file in the root directory of this source tree) and the GPLv2 (found
- * in the COPYING file in the root directory of this source tree).
- * You may select, at your option, one of the above-listed licenses.
- */
-
-
-/*-************************************
-* Dependencies
-**************************************/
-#include "util.h" /* Compiler options */
-#include /* fprintf, stderr */
-#include "datagen.h" /* RDG_generate */
-
-
-/*-************************************
-* Constants
-**************************************/
-#define KB *(1 <<10)
-#define MB *(1 <<20)
-#define GB *(1U<<30)
-
-#define SIZE_DEFAULT ((64 KB) + 1)
-#define SEED_DEFAULT 0
-#define COMPRESSIBILITY_DEFAULT 50
-
-
-/*-************************************
-* Macros
-**************************************/
-#define DISPLAY(...) fprintf(stderr, __VA_ARGS__)
-#define DISPLAYLEVEL(l, ...) if (displayLevel>=l) { DISPLAY(__VA_ARGS__); }
-static unsigned displayLevel = 2;
-
-
-/*-*******************************************************
-* Command line
-*********************************************************/
-static int usage(const char* programName)
-{
- DISPLAY( "Compressible data generator\n");
- DISPLAY( "Usage :\n");
- DISPLAY( " %s [args]\n", programName);
- DISPLAY( "\n");
- DISPLAY( "Arguments :\n");
- DISPLAY( " -g# : generate # data (default:%i)\n", SIZE_DEFAULT);
- DISPLAY( " -s# : Select seed (default:%i)\n", SEED_DEFAULT);
- DISPLAY( " -P# : Select compressibility in %% (default:%i%%)\n",
- COMPRESSIBILITY_DEFAULT);
- DISPLAY( " -h : display help and exit\n");
- return 0;
-}
-
-
-int main(int argc, const char** argv)
-{
- unsigned probaU32 = COMPRESSIBILITY_DEFAULT;
- double litProba = 0.0;
- U64 size = SIZE_DEFAULT;
- U32 seed = SEED_DEFAULT;
- const char* const programName = argv[0];
-
- int argNb;
- for(argNb=1; argNb='0') && (*argument<='9'))
- size *= 10, size += *argument++ - '0';
- if (*argument=='K') { size <<= 10; argument++; }
- if (*argument=='M') { size <<= 20; argument++; }
- if (*argument=='G') { size <<= 30; argument++; }
- if (*argument=='B') { argument++; }
- break;
- case 's':
- argument++;
- seed=0;
- while ((*argument>='0') && (*argument<='9'))
- seed *= 10, seed += *argument++ - '0';
- break;
- case 'P':
- argument++;
- probaU32 = 0;
- while ((*argument>='0') && (*argument<='9'))
- probaU32 *= 10, probaU32 += *argument++ - '0';
- if (probaU32>100) probaU32 = 100;
- break;
- case 'L': /* hidden argument : Literal distribution probability */
- argument++;
- litProba=0.;
- while ((*argument>='0') && (*argument<='9'))
- litProba *= 10, litProba += *argument++ - '0';
- if (litProba>100.) litProba=100.;
- litProba /= 100.;
- break;
- case 'v':
- displayLevel = 4;
- argument++;
- break;
- default:
- return usage(programName);
- }
- } } } /* for(argNb=1; argNb diff tests/regression/results.csv $CIRCLE_ARTIFACTS/results.csv"
+ diff tests/regression/results.csv $CIRCLE_ARTIFACTS/results.csv
+ - uses: actions/upload-artifact@v4
+ with:
+ path: "/tmp/circleci-artifacts"
diff --git a/deps/libchdr/deps/zstd-1.5.5/.github/workflows/dev-long-tests.yml b/deps/libchdr/deps/zstd-1.5.6/.github/workflows/dev-long-tests.yml
similarity index 71%
rename from deps/libchdr/deps/zstd-1.5.5/.github/workflows/dev-long-tests.yml
rename to deps/libchdr/deps/zstd-1.5.6/.github/workflows/dev-long-tests.yml
index 16202260..eb8f40a9 100644
--- a/deps/libchdr/deps/zstd-1.5.5/.github/workflows/dev-long-tests.yml
+++ b/deps/libchdr/deps/zstd-1.5.6/.github/workflows/dev-long-tests.yml
@@ -15,7 +15,7 @@ jobs:
make-all:
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # tag=v3
+ - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # tag=v4.1.1
- name: make all
run: make all
@@ -26,7 +26,7 @@ jobs:
DEVNULLRIGHTS: 1
READFROMBLOCKDEVICE: 1
steps:
- - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # tag=v3
+ - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # tag=v4.1.1
- name: make test
run: make test
@@ -34,7 +34,7 @@ jobs:
make-test-osx:
runs-on: macos-latest
steps:
- - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # tag=v3
+ - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # tag=v4.1.1
- name: OS-X test
run: make test # make -c lib all doesn't work because of the fact that it's not a tty
@@ -45,7 +45,7 @@ jobs:
DEVNULLRIGHTS: 1
READFROMBLOCKDEVICE: 1
steps:
- - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # tag=v3
+ - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # tag=v4.1.1
- name: make test
run: |
sudo apt-get -qqq update
@@ -55,29 +55,29 @@ jobs:
no-intrinsics-fuzztest:
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # tag=v3
+ - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # tag=v4.1.1
- name: no intrinsics fuzztest
run: MOREFLAGS="-DZSTD_NO_INTRINSICS" make -C tests fuzztest
tsan-zstreamtest:
- runs-on: ubuntu-latest
+ runs-on: ubuntu-20.04
steps:
- - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # tag=v3
+ - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # tag=v4.1.1
- name: thread sanitizer zstreamtest
run: CC=clang ZSTREAM_TESTTIME=-T3mn make tsan-test-zstream
ubsan-zstreamtest:
- runs-on: ubuntu-latest
+ runs-on: ubuntu-20.04
steps:
- - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # tag=v3
+ - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # tag=v4.1.1
- name: undefined behavior sanitizer zstreamtest
run: CC=clang make uasan-test-zstream
# lasts ~15mn
tsan-fuzztest:
- runs-on: ubuntu-latest
+ runs-on: ubuntu-20.04
steps:
- - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # tag=v3
+ - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # tag=v4.1.1
- name: thread sanitizer fuzztest
run: CC=clang make tsan-fuzztest
@@ -85,7 +85,7 @@ jobs:
big-tests-zstreamtest32:
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # tag=v3
+ - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # tag=v4.1.1
- name: zstream tests in 32bit mode, with big tests
run: |
sudo apt-get -qqq update
@@ -94,9 +94,9 @@ jobs:
# lasts ~23mn
gcc-8-asan-ubsan-testzstd:
- runs-on: ubuntu-latest
+ runs-on: ubuntu-20.04
steps:
- - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # tag=v3
+ - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # tag=v4.1.1
- name: gcc-8 + ASan + UBSan + Test Zstd
# See https://askubuntu.com/a/1428822
run: |
@@ -106,16 +106,16 @@ jobs:
CC=gcc-8 make -j uasan-test-zstd -
@@ -524,31 +533,12 @@ jobs:
make -C tests fuzzer &&
./tests/fuzzer.exe -v -T1m
- intel-cet-compatibility:
- runs-on: ubuntu-latest
- steps:
- - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # tag=v3
- - name: Build Zstd
- run: |
- make -j zstd V=1
- readelf -n zstd
- - name: Get Intel SDE
- run: |
- curl -LO https://downloadmirror.intel.com/684899/sde-external-9.0.0-2021-11-07-lin.tar.xz
- tar xJvf sde-external-9.0.0-2021-11-07-lin.tar.xz
- - name: Configure Permissions
- run: |
- echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
- - name: Run Under SDE
- run: |
- sde-external-9.0.0-2021-11-07-lin/sde -cet -cet-raise 0 -cet-endbr-exe -cet-stderr -cet-abort -- ./zstd -b3
-
pkg-config:
runs-on: ubuntu-latest
container:
image: debian:testing
steps:
- - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # tag=v3
+ - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # tag=v4.1.1
- name: Install dependencies
run: |
apt -y update
@@ -563,7 +553,7 @@ jobs:
versions-compatibility:
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # tag=v3
+ - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # tag=v4.1.1
- name: Versions Compatibility Test
run: |
make -C tests versionsTest
@@ -571,7 +561,7 @@ jobs:
clangbuild:
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # tag=v3
+ - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # tag=v4.1.1
- name: make clangbuild
run: |
make clangbuild
@@ -579,7 +569,7 @@ jobs:
clang-pgo:
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # tag=v3
+ - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # tag=v4.1.1
- name: Build PGO Zstd with Clang
env:
CC: clang-14
@@ -591,7 +581,7 @@ jobs:
gcc-pgo:
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # tag=v3
+ - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # tag=v4.1.1
- name: Build PGO Zstd with GCC
env:
CC: gcc
@@ -599,10 +589,29 @@ jobs:
make -C programs zstd-pgo
./programs/zstd -b
+ intel-cet-compatibility:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # tag=v4.1.1
+ - name: Build Zstd
+ run: |
+ make -j zstd V=1
+ readelf -n zstd
+ - name: Get Intel SDE
+ run: |
+ curl -LO https://downloadmirror.intel.com/813591/sde-external-9.33.0-2024-01-07-lin.tar.xz
+ tar xJvf sde-external-9.33.0-2024-01-07-lin.tar.xz
+ - name: Configure Permissions
+ run: |
+ echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
+ - name: Run Under SDE
+ run: |
+ sde-external-9.33.0-2024-01-07-lin/sde -cet -cet-raise 0 -cet-endbr-exe -cet-stderr -cet-abort -- ./zstd -b3
+
+
+# Failing tests, for reference
-# For reference : icc tests
# icc tests are currently failing on Github Actions, likely to issues during installation stage
-# To be fixed later
#
# icc:
# name: icc-check
@@ -618,7 +627,7 @@ jobs:
# sudo add-apt-repository "deb https://apt.repos.intel.com/oneapi all main"
# sudo apt-get update
# sudo apt-get install -y intel-basekit intel-hpckit
-# - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # tag=v3
+# - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # tag=v4.1.1
# - name: make check
# run: |
# make CC=/opt/intel/oneapi/compiler/latest/linux/bin/intel64/icc check
diff --git a/deps/libchdr/deps/zstd-1.5.6/.github/workflows/nightly.yml b/deps/libchdr/deps/zstd-1.5.6/.github/workflows/nightly.yml
new file mode 100644
index 00000000..704e7892
--- /dev/null
+++ b/deps/libchdr/deps/zstd-1.5.6/.github/workflows/nightly.yml
@@ -0,0 +1,65 @@
+name: facebook/zstd/nightly
+on:
+ schedule:
+ - cron: 0 0 * * *
+ push:
+ branches:
+ - release
+ - dev
+ - master
+permissions: read-all
+jobs:
+ regression-test:
+ runs-on: ubuntu-latest
+ services:
+ docker:
+ image: fbopensource/zstd-circleci-primary:0.0.1
+ options: --entrypoint /bin/bash
+ env:
+ CIRCLE_ARTIFACTS: "/tmp/circleci-artifacts"
+ steps:
+ - uses: actions/checkout@v4
+ - uses: actions/cache@v4
+ with:
+ key: regression-cache-{{ checksum "tests/regression/data.c" }}-v0
+ path: tests/regression/cache
+ restore-keys: regression-cache-{{ checksum "tests/regression/data.c" }}-v0
+ - uses: actions/upload-artifact@v4
+ with:
+ path: "/tmp/circleci-artifacts"
+ - name: Install Dependencies
+ run: |
+ sudo apt-get update
+ sudo apt-get install libcurl4-gnutls-dev
+ - name: Regression Test
+ run: |
+ make -C programs zstd
+ make -C tests/regression test
+ mkdir -p $CIRCLE_ARTIFACTS
+ ./tests/regression/test \
+ --cache tests/regression/cache \
+ --output $CIRCLE_ARTIFACTS/results.csv \
+ --zstd programs/zstd
+ echo "NOTE: The new results.csv is uploaded as an artifact to this job"
+ echo " If this fails, go to the Artifacts pane in CircleCI, "
+ echo " download /tmp/circleci-artifacts/results.csv, and if they "
+ echo " are still good, copy it into the repo and commit it."
+ echo "> diff tests/regression/results.csv $CIRCLE_ARTIFACTS/results.csv"
+ diff tests/regression/results.csv $CIRCLE_ARTIFACTS/results.csv
+
+# Longer tests
+ #- make -C tests test-zstd-nolegacy && make clean
+ #- pyenv global 3.4.4; make -C tests versionsTest && make clean
+ #- make zlibwrapper && make clean
+ #- gcc -v; make -C tests test32 MOREFLAGS="-I/usr/include/x86_64-linux-gnu" && make clean
+ #- make uasan && make clean
+ #- make asan32 && make clean
+ #- make -C tests test32 CC=clang MOREFLAGS="-g -fsanitize=address -I/usr/include/x86_64-linux-gnu"
+# Valgrind tests
+ #- CFLAGS="-O1 -g" make -C zlibWrapper valgrindTest && make clean
+ #- make -C tests valgrindTest && make clean
+# ARM, AArch64, PowerPC, PowerPC64 tests
+ #- make ppctest && make clean
+ #- make ppc64test && make clean
+ #- make armtest && make clean
+ #- make aarch64test && make clean
diff --git a/deps/libchdr/deps/zstd-1.5.5/.github/workflows/publish-release-artifacts.yml b/deps/libchdr/deps/zstd-1.5.6/.github/workflows/publish-release-artifacts.yml
similarity index 97%
rename from deps/libchdr/deps/zstd-1.5.5/.github/workflows/publish-release-artifacts.yml
rename to deps/libchdr/deps/zstd-1.5.6/.github/workflows/publish-release-artifacts.yml
index 3c942394..f7af2791 100644
--- a/deps/libchdr/deps/zstd-1.5.5/.github/workflows/publish-release-artifacts.yml
+++ b/deps/libchdr/deps/zstd-1.5.6/.github/workflows/publish-release-artifacts.yml
@@ -17,7 +17,7 @@ jobs:
steps:
- name: Checkout
- uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # tag=v3
+ uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # tag=v3
- name: Archive
env:
diff --git a/deps/libchdr/deps/zstd-1.5.5/.github/workflows/scorecards.yml b/deps/libchdr/deps/zstd-1.5.6/.github/workflows/scorecards.yml
similarity index 85%
rename from deps/libchdr/deps/zstd-1.5.5/.github/workflows/scorecards.yml
rename to deps/libchdr/deps/zstd-1.5.6/.github/workflows/scorecards.yml
index 8a693fa2..a5d5f02a 100644
--- a/deps/libchdr/deps/zstd-1.5.5/.github/workflows/scorecards.yml
+++ b/deps/libchdr/deps/zstd-1.5.6/.github/workflows/scorecards.yml
@@ -27,12 +27,12 @@ jobs:
steps:
- name: "Checkout code"
- uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # tag=v3
+ uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # tag=v3
with:
persist-credentials: false
- name: "Run analysis"
- uses: ossf/scorecard-action@e38b1902ae4f44df626f11ba0734b14fb91f8f86 # tag=v2.1.2
+ uses: ossf/scorecard-action@0864cf19026789058feabb7e87baa5f140aac736 # tag=v2.3.1
with:
results_file: results.sarif
results_format: sarif
@@ -51,7 +51,7 @@ jobs:
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
# format to the repository Actions tab.
- name: "Upload artifact"
- uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # tag=v3.1.2
+ uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # tag=v4.3.1
with:
name: SARIF file
path: results.sarif
@@ -59,6 +59,6 @@ jobs:
# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
- uses: github/codeql-action/upload-sarif@67a35a08586135a9573f4327e904ecbf517a882d # tag=v2.2.8
+ uses: github/codeql-action/upload-sarif@3ab4101902695724f9365a384f86c1074d94e18c # tag=v3.24.7
with:
sarif_file: results.sarif
diff --git a/deps/libchdr/deps/zstd-1.5.5/.github/workflows/windows-artifacts.yml b/deps/libchdr/deps/zstd-1.5.6/.github/workflows/windows-artifacts.yml
similarity index 51%
rename from deps/libchdr/deps/zstd-1.5.5/.github/workflows/windows-artifacts.yml
rename to deps/libchdr/deps/zstd-1.5.6/.github/workflows/windows-artifacts.yml
index 7d73b4b0..52bc90a4 100644
--- a/deps/libchdr/deps/zstd-1.5.5/.github/workflows/windows-artifacts.yml
+++ b/deps/libchdr/deps/zstd-1.5.6/.github/workflows/windows-artifacts.yml
@@ -10,19 +10,26 @@ on:
permissions: read-all
jobs:
- windows-64-artifacts:
+ windows-artifacts:
# see https://ariya.io/2020/07/on-github-actions-with-msys2
runs-on: windows-latest
+ # see https://github.com/msys2/setup-msys2
+ strategy:
+ matrix:
+ include:
+ - { msystem: mingw64, env: x86_64, ziparch: win64 }
+ - { msystem: mingw32, env: i686, ziparch: win32 }
defaults:
run:
shell: msys2 {0}
steps:
- - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # tag=v3
+ - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # tag=v3
- uses: msys2/setup-msys2@5beef6d11f48bba68b9eb503e3adc60b23c0cc36 # tag=v2
with:
- msystem: MINGW64
- install: make zlib git p7zip mingw-w64-x86_64-gcc
+ msystem: ${{ matrix.msystem }}
+ install: make zlib git p7zip mingw-w64-${{matrix.env}}-gcc
update: true
+
- name: display versions
run: |
make -v
@@ -33,19 +40,19 @@ jobs:
git clone --depth 1 --branch v1.2.11 https://github.com/madler/zlib
make -C zlib -f win32/Makefile.gcc libz.a
- - name: Building zstd programs in 64-bit mode
+ - name: Building zstd programs
run: |
CPPFLAGS=-I../zlib LDFLAGS=../zlib/libz.a make -j allzstd MOREFLAGS=-static V=1
- name: Create artifacts
run: |
./lib/dll/example/build_package.bat
- mv bin/ zstd-${{ github.ref_name }}-win64/
- 7z a -tzip -mx9 zstd-${{ github.ref_name }}-win64.zip zstd-${{ github.ref_name }}-win64/
+ mv bin/ zstd-${{ github.ref_name }}-${{matrix.ziparch}}/
+ 7z a -tzip -mx9 zstd-${{ github.ref_name }}-${{matrix.ziparch}}.zip zstd-${{ github.ref_name }}-${{matrix.ziparch}}/
cd ..
- - name: Publish zstd-$VERSION-win64.zip
- uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # tag=v3
+ - name: Publish zstd-$VERSION-${{matrix.ziparch}}.zip
+ uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # tag=v4.3.1
with:
- path: ${{ github.workspace }}/zstd-${{ github.ref_name }}-win64.zip
- name: zstd-${{ github.ref_name }}-win64.zip
+ path: ${{ github.workspace }}/zstd-${{ github.ref_name }}-${{matrix.ziparch}}.zip
+ name: zstd-${{ github.ref_name }}-${{matrix.ziparch}}.zip
diff --git a/deps/libchdr/deps/zstd-1.5.5/.gitignore b/deps/libchdr/deps/zstd-1.5.6/.gitignore
similarity index 89%
rename from deps/libchdr/deps/zstd-1.5.5/.gitignore
rename to deps/libchdr/deps/zstd-1.5.6/.gitignore
index a136ea39..34e18b44 100644
--- a/deps/libchdr/deps/zstd-1.5.5/.gitignore
+++ b/deps/libchdr/deps/zstd-1.5.6/.gitignore
@@ -27,6 +27,8 @@ tmp*
dictionary.
dictionary
NUL
+cmakebuild/
+install/
# Build artefacts
contrib/linux-kernel/linux/
@@ -37,11 +39,15 @@ buck-out/
build-*
*.gcda
+# IDE
+.clang_complete
+compile_flags.txt
+.clang-format
+
# Other files
.directory
_codelite/
_zstdbench/
-.clang_complete
*.idea
*.swp
.DS_Store
diff --git a/deps/libchdr/deps/zstd-1.5.5/CHANGELOG b/deps/libchdr/deps/zstd-1.5.6/CHANGELOG
similarity index 95%
rename from deps/libchdr/deps/zstd-1.5.5/CHANGELOG
rename to deps/libchdr/deps/zstd-1.5.6/CHANGELOG
index c7a7506e..33f43410 100644
--- a/deps/libchdr/deps/zstd-1.5.5/CHANGELOG
+++ b/deps/libchdr/deps/zstd-1.5.6/CHANGELOG
@@ -1,3 +1,40 @@
+V1.5.6 (Mar 2024)
+api: Promote `ZSTD_c_targetCBlockSize` to Stable API by @felixhandte
+api: new `ZSTD_d_maxBlockSize` experimental parameter, to reduce streaming decompression memory, by @terrelln
+perf: improve performance of param `ZSTD_c_targetCBlockSize`, by @Cyan4973
+perf: improved compression of arrays of integers at high compression, by @Cyan4973
+lib: reduce binary size with selective built-time exclusion, by @felixhandte
+lib: improved huffman speed on small data and linux kernel, by @terrelln
+lib: accept dictionaries with partial literal tables, by @terrelln
+lib: fix CCtx size estimation with external sequence producer, by @embg
+lib: fix corner case decoder behaviors, by @Cyan4973 and @aimuz
+lib: fix zdict prototype mismatch in static_only mode, by @ldv-alt
+lib: fix several bugs in magicless-format decoding, by @embg
+cli: add common compressed file types to `--exclude-compressed`` by @daniellerozenblit
+cli: fix mixing `-c` and `-o` commands with `--rm`, by @Cyan4973
+cli: fix erroneous exclusion of hidden files with `--output-dir-mirror` by @felixhandte
+cli: improved time accuracy on BSD, by @felixhandte
+cli: better errors on argument parsing, by @KapJI
+tests: better compatibility with older versions of `grep`, by @Cyan4973
+tests: lorem ipsum generator as default backup content, by @Cyan4973
+build: cmake improvements by @terrelln, @sighingnow, @gjasny, @JohanMabille, @Saverio976, @gruenich, @teo-tsirpanis
+build: bazel support, by @jondo2010
+build: fix cross-compiling for AArch64 with lld by @jcelerier
+build: fix Apple platform compatibility, by @nidhijaju
+build: fix Visual 2012 and lower compatibility, by @Cyan4973
+build: improve win32 support, by @DimitriPapadopoulos
+build: better C90 compliance for zlibWrapper, by @emaste
+port: make: fat binaries on macos, by @mredig
+port: ARM64EC compatibility for Windows, by @dunhor
+port: QNX support by @klausholstjacobsen
+port: MSYS2 and Cygwin makefile installation and test support, by @QBos07
+port: risc-v support validation in CI, by @Cyan4973
+port: sparc64 support validation in CI, by @Cyan4973
+port: AIX compatibility, by @likema
+port: HP-UX compatibility, by @likema
+doc: Improved specification accuracy, by @elasota
+bug: Fix and deprecate ZSTD_generateSequences (#3981)
+
v1.5.5 (Apr 2023)
fix: fix rare corruption bug affecting the high compression mode, reported by @danlark1 (#3517, @terrelln)
perf: improve mid-level compression speed (#3529, #3533, #3543, @yoniko and #3552, @terrelln)
@@ -98,7 +135,7 @@ build: support for m68k (Motorola 68000's), by @cyan4973
build: improved AIX support, by @Helflym
build: improved meson unofficial build, by @eli-schwartz
cli : custom memory limit when training dictionary (#2925), by @embg
-cli : report advanced parameters information when compressing in very verbose mode (``-vv`), by @Svetlitski-FB
+cli : report advanced parameters information when compressing in very verbose mode (`-vv`), by @Svetlitski-FB
v1.5.0 (May 11, 2021)
api: Various functions promoted from experimental to stable API: (#2579-2581, @senhuang42)
@@ -165,7 +202,7 @@ api: Add Function to Generate Skippable Frame (#2439, @senhuang42)
perf: New Algorithms for the Long Distance Matcher (#2483, @mpu)
perf: Performance Improvements for Long Distance Matcher (#2464, @mpu)
perf: Don't Shrink Window Log when Streaming with a Dictionary (#2451, @terrelln)
-cli: Fix `--output-dir-mirror`'s Rejection of `..`-Containing Paths (#2512, @felixhandte)
+cli: Fix `--output-dir-mirror` rejection of `..` -containing paths (#2512, @felixhandte)
cli: Allow Input From Console When `-f`/`--force` is Passed (#2466, @felixhandte)
cli: Improve Help Message (#2500, @senhuang42)
tests: Remove Flaky Tests (#2455, #2486, #2445, @Cyan4973)
diff --git a/deps/libchdr/deps/zstd-1.5.5/CODE_OF_CONDUCT.md b/deps/libchdr/deps/zstd-1.5.6/CODE_OF_CONDUCT.md
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/CODE_OF_CONDUCT.md
rename to deps/libchdr/deps/zstd-1.5.6/CODE_OF_CONDUCT.md
diff --git a/deps/libchdr/deps/zstd-1.5.5/CONTRIBUTING.md b/deps/libchdr/deps/zstd-1.5.6/CONTRIBUTING.md
similarity index 99%
rename from deps/libchdr/deps/zstd-1.5.5/CONTRIBUTING.md
rename to deps/libchdr/deps/zstd-1.5.6/CONTRIBUTING.md
index f5e747ae..47f5bb8f 100644
--- a/deps/libchdr/deps/zstd-1.5.5/CONTRIBUTING.md
+++ b/deps/libchdr/deps/zstd-1.5.6/CONTRIBUTING.md
@@ -171,8 +171,8 @@ who want earlier signal.
| Cirrus CI | Used for testing on FreeBSD | https://github.com/marketplace/cirrus-ci/ | `.cirrus.yml` |
| Circle CI | Historically was used to provide faster signal, but we may be able to migrate these to Github Actions | https://circleci.com/docs/2.0/getting-started/#setting-up-circleci https://youtu.be/Js3hMUsSZ2c https://circleci.com/docs/2.0/enable-checks/ | `.circleci/config.yml` |
-Note: the instructions linked above mostly cover how to set up a repository with CI from scratch.
-The general idea should be the same for setting up CI on your fork of zstd, but you may have to
+Note: the instructions linked above mostly cover how to set up a repository with CI from scratch.
+The general idea should be the same for setting up CI on your fork of zstd, but you may have to
follow slightly different steps. In particular, please ignore any instructions related to setting up
config files (since zstd already has configs for each of these services).
@@ -216,7 +216,7 @@ will typically not be stable enough to obtain reliable benchmark results. If you
hands on a desktop, this is usually a better scenario.
Of course, benchmarking can be done on non-hyper-stable machines as well. You will just have to
-do a little more work to ensure that you are in fact measuring the changes you've made not and
+do a little more work to ensure that you are in fact measuring the changes you've made and not
noise. Here are some things you can do to make your benchmarks more stable:
1. The most simple thing you can do to drastically improve the stability of your benchmark is
diff --git a/deps/libchdr/deps/zstd-1.5.5/COPYING b/deps/libchdr/deps/zstd-1.5.6/COPYING
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/COPYING
rename to deps/libchdr/deps/zstd-1.5.6/COPYING
diff --git a/deps/libchdr/deps/zstd-1.5.5/LICENSE b/deps/libchdr/deps/zstd-1.5.6/LICENSE
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/LICENSE
rename to deps/libchdr/deps/zstd-1.5.6/LICENSE
diff --git a/deps/libchdr/deps/zstd-1.5.5/Makefile b/deps/libchdr/deps/zstd-1.5.6/Makefile
similarity index 90%
rename from deps/libchdr/deps/zstd-1.5.5/Makefile
rename to deps/libchdr/deps/zstd-1.5.6/Makefile
index 3b2e3999..11eca19c 100644
--- a/deps/libchdr/deps/zstd-1.5.5/Makefile
+++ b/deps/libchdr/deps/zstd-1.5.6/Makefile
@@ -145,13 +145,13 @@ clean:
$(Q)$(MAKE) -C contrib/largeNbDicts $@ > $(VOID)
$(Q)$(MAKE) -C contrib/externalSequenceProducer $@ > $(VOID)
$(Q)$(RM) zstd$(EXT) zstdmt$(EXT) tmp*
- $(Q)$(RM) -r lz4
+ $(Q)$(RM) -r lz4 cmakebuild install
@echo Cleaning completed
#------------------------------------------------------------------------------
# make install is validated only for Linux, macOS, Hurd and some BSD targets
#------------------------------------------------------------------------------
-ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD DragonFly NetBSD MSYS_NT Haiku AIX))
+ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD DragonFly NetBSD MSYS_NT CYGWIN_NT Haiku AIX))
HOST_OS = POSIX
@@ -197,6 +197,15 @@ uninstall:
travis-install:
$(MAKE) install PREFIX=~/install_test_dir
+.PHONY: clangbuild-darwin-fat
+clangbuild-darwin-fat: clean
+ clang -v
+ CXX=clang++ CC=clang CFLAGS="-Werror -Wconversion -Wno-sign-conversion -Wdocumentation -arch arm64" $(MAKE) zstd-release
+ mv programs/zstd programs/zstd_arm64
+ CXX=clang++ CC=clang CFLAGS="-Werror -Wconversion -Wno-sign-conversion -Wdocumentation -arch x86_64" $(MAKE) zstd-release
+ mv programs/zstd programs/zstd_x64
+ lipo -create programs/zstd_x64 programs/zstd_arm64 -output programs/zstd
+
.PHONY: gcc5build gcc6build gcc7build clangbuild m32build armbuild aarch64build ppcbuild ppc64build
gcc5build: clean
gcc-5 -v
@@ -308,7 +317,7 @@ update_regressionResults:
# run UBsan with -fsanitize-recover=pointer-overflow
# this only works with recent compilers such as gcc 8+
usan: clean
- $(MAKE) test CC=clang MOREFLAGS="-g -fno-sanitize-recover=all -fsanitize-recover=pointer-overflow -fsanitize=undefined -Werror $(MOREFLAGS)"
+ $(MAKE) test CC=clang MOREFLAGS="-g -fno-sanitize-recover=all -fsanitize=undefined -Werror $(MOREFLAGS)"
asan: clean
$(MAKE) test CC=clang MOREFLAGS="-g -fsanitize=address -Werror $(MOREFLAGS)"
@@ -319,17 +328,18 @@ asan-%: clean
msan: clean
$(MAKE) test CC=clang MOREFLAGS="-g -fsanitize=memory -fno-omit-frame-pointer -Werror $(MOREFLAGS)" HAVE_LZMA=0 # datagen.c fails this test for no obvious reason
-msan-%: clean
- LDFLAGS=-fuse-ld=gold MOREFLAGS="-g -fno-sanitize-recover=all -fsanitize=memory -fno-omit-frame-pointer -Werror $(MOREFLAGS)" FUZZER_FLAGS="--no-big-tests $(FUZZER_FLAGS)" $(MAKE) -C $(TESTDIR) HAVE_LZMA=0 $*
+msan-%:
+ $(MAKE) clean
+ LDFLAGS=-fuse-ld=gold MOREFLAGS="-g -fno-sanitize-recover=all -fsanitize=memory -fno-omit-frame-pointer -Werror $(MOREFLAGS)" FUZZER_FLAGS="--no-big-tests $(FUZZER_FLAGS)" $(MAKE) -j -C $(TESTDIR) HAVE_LZMA=0 $*
asan32: clean
$(MAKE) -C $(TESTDIR) test32 CC=clang MOREFLAGS="-g -fsanitize=address $(MOREFLAGS)"
uasan: clean
- $(MAKE) test CC=clang MOREFLAGS="-g -fno-sanitize-recover=all -fsanitize-recover=pointer-overflow -fsanitize=address,undefined -Werror $(MOREFLAGS)"
+ $(MAKE) test CC=clang MOREFLAGS="-g -fno-sanitize-recover=all -fsanitize=address,undefined -Werror $(MOREFLAGS)"
uasan-%: clean
- LDFLAGS=-fuse-ld=gold MOREFLAGS="-g -fno-sanitize-recover=all -fsanitize-recover=pointer-overflow -fsanitize=address,undefined -Werror $(MOREFLAGS)" $(MAKE) -C $(TESTDIR) $*
+ LDFLAGS=-fuse-ld=gold MOREFLAGS="-g -fno-sanitize-recover=all -fsanitize=address,undefined -Werror $(MOREFLAGS)" $(MAKE) -C $(TESTDIR) $*
tsan-%: clean
LDFLAGS=-fuse-ld=gold MOREFLAGS="-g -fno-sanitize-recover=all -fsanitize=thread -Werror $(MOREFLAGS)" $(MAKE) -C $(TESTDIR) $* FUZZER_FLAGS="--no-big-tests $(FUZZER_FLAGS)"
@@ -380,28 +390,32 @@ lz4install:
endif
-CMAKE_PARAMS = -DZSTD_BUILD_CONTRIB:BOOL=ON -DZSTD_BUILD_STATIC:BOOL=ON -DZSTD_BUILD_TESTS:BOOL=ON -DZSTD_ZLIB_SUPPORT:BOOL=ON -DZSTD_LZMA_SUPPORT:BOOL=ON -DCMAKE_BUILD_TYPE=Release
-
ifneq (,$(filter MSYS%,$(shell uname)))
HOST_OS = MSYS
-CMAKE_PARAMS = -G"MSYS Makefiles" -DCMAKE_BUILD_TYPE=Debug -DZSTD_MULTITHREAD_SUPPORT:BOOL=OFF -DZSTD_BUILD_STATIC:BOOL=ON -DZSTD_BUILD_TESTS:BOOL=ON
endif
#------------------------------------------------------------------------
# target specific tests
#------------------------------------------------------------------------
ifneq (,$(filter $(HOST_OS),MSYS POSIX))
-.PHONY: cmakebuild c89build gnu90build c99build gnu99build c11build bmix64build bmix32build bmi32build staticAnalyze
-cmakebuild:
- cmake --version
- $(RM) -r $(BUILDIR)/cmake/build
- $(MKDIR) $(BUILDIR)/cmake/build
- cd $(BUILDIR)/cmake/build; cmake -DCMAKE_INSTALL_PREFIX:PATH=~/install_test_dir $(CMAKE_PARAMS) ..
- $(MAKE) -C $(BUILDIR)/cmake/build -j4;
- $(MAKE) -C $(BUILDIR)/cmake/build install;
- $(MAKE) -C $(BUILDIR)/cmake/build uninstall;
- cd $(BUILDIR)/cmake/build; ctest -V -L Medium
+CMAKE ?= cmake
+CMAKE_PARAMS = -DZSTD_BUILD_CONTRIB:BOOL=ON -DZSTD_BUILD_STATIC:BOOL=ON -DZSTD_BUILD_TESTS:BOOL=ON -DZSTD_ZLIB_SUPPORT:BOOL=ON -DZSTD_LZMA_SUPPORT:BOOL=ON
+
+ifneq (,$(filter MSYS%,$(shell uname)))
+CMAKE_PARAMS = -G"MSYS Makefiles" -DZSTD_MULTITHREAD_SUPPORT:BOOL=OFF -DZSTD_BUILD_STATIC:BOOL=ON -DZSTD_BUILD_TESTS:BOOL=ON
+endif
+
+.PHONY: cmakebuild
+cmakebuild:
+ $(CMAKE) --version
+ $(RM) -r cmakebuild install
+ $(MKDIR) cmakebuild install
+ cd cmakebuild; $(CMAKE) -Wdev -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_FLAGS="-Werror -O0" -DCMAKE_INSTALL_PREFIX=install $(CMAKE_PARAMS) ../build/cmake
+ $(CMAKE) --build cmakebuild --target install -- -j V=1
+ cd cmakebuild; ctest -V -L Medium
+
+.PHONY: c89build gnu90build c99build gnu99build c11build bmix64build bmix32build bmi32build staticAnalyze
c89build: clean
$(CC) -v
CFLAGS="-std=c89 -Werror -Wno-attributes -Wpedantic -Wno-long-long -Wno-variadic-macros -O0" $(MAKE) lib zstd
diff --git a/deps/libchdr/deps/zstd-1.5.5/Package.swift b/deps/libchdr/deps/zstd-1.5.6/Package.swift
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/Package.swift
rename to deps/libchdr/deps/zstd-1.5.6/Package.swift
diff --git a/deps/libchdr/deps/zstd-1.5.5/README.md b/deps/libchdr/deps/zstd-1.5.6/README.md
similarity index 97%
rename from deps/libchdr/deps/zstd-1.5.5/README.md
rename to deps/libchdr/deps/zstd-1.5.6/README.md
index f91e68fd..0f7478e1 100644
--- a/deps/libchdr/deps/zstd-1.5.5/README.md
+++ b/deps/libchdr/deps/zstd-1.5.6/README.md
@@ -5,7 +5,7 @@ targeting real-time compression scenarios at zlib-level and better compression r
It's backed by a very fast entropy stage, provided by [Huff0 and FSE library](https://github.com/Cyan4973/FiniteStateEntropy).
Zstandard's format is stable and documented in [RFC8878](https://datatracker.ietf.org/doc/html/rfc8878). Multiple independent implementations are already available.
-This repository represents the reference implementation, provided as an open-source dual [BSD](LICENSE) and [GPLv2](COPYING) licensed **C** library,
+This repository represents the reference implementation, provided as an open-source dual [BSD](LICENSE) OR [GPLv2](COPYING) licensed **C** library,
and a command line utility producing and decoding `.zst`, `.gz`, `.xz` and `.lz4` files.
Should your project require another programming language,
a list of known ports and bindings is provided on [Zstandard homepage](https://facebook.github.io/zstd/#other-languages).
@@ -198,6 +198,10 @@ Going into `build` directory, you will find additional possibilities:
You can build the zstd binary via buck by executing: `buck build programs:zstd` from the root of the repo.
The output binary will be in `buck-out/gen/programs/`.
+### Bazel
+
+You easily can integrate zstd into your Bazel project by using the module hosted on the [Bazel Central Repository](https://registry.bazel.build/modules/zstd).
+
## Testing
You can run quick local smoke tests by running `make check`.
@@ -213,7 +217,7 @@ Zstandard is considered safe for production environments.
## License
-Zstandard is dual-licensed under [BSD](LICENSE) and [GPLv2](COPYING).
+Zstandard is dual-licensed under [BSD](LICENSE) OR [GPLv2](COPYING).
## Contributing
diff --git a/deps/libchdr/deps/zstd-1.5.6/SECURITY.md b/deps/libchdr/deps/zstd-1.5.6/SECURITY.md
new file mode 100644
index 00000000..a5f9a7e1
--- /dev/null
+++ b/deps/libchdr/deps/zstd-1.5.6/SECURITY.md
@@ -0,0 +1,15 @@
+# Reporting and Fixing Security Issues
+
+Please do not open GitHub issues or pull requests - this makes the problem immediately visible to everyone, including malicious actors. Security issues in this open source project can be safely reported via the Meta Bug Bounty program:
+
+https://www.facebook.com/whitehat
+
+Meta's security team will triage your report and determine whether or not is it eligible for a bounty under our program.
+
+# Receiving Vulnerability Notifications
+
+In the case that a significant security vulnerability is reported to us or discovered by us---without being publicly known---we will, at our discretion, notify high-profile, high-exposure users of Zstandard ahead of our public disclosure of the issue and associated fix.
+
+If you believe your project would benefit from inclusion in this list, please reach out to one of the maintainers.
+
+
diff --git a/deps/libchdr/deps/zstd-1.5.5/TESTING.md b/deps/libchdr/deps/zstd-1.5.6/TESTING.md
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/TESTING.md
rename to deps/libchdr/deps/zstd-1.5.6/TESTING.md
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/.gitignore b/deps/libchdr/deps/zstd-1.5.6/build/.gitignore
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/.gitignore
rename to deps/libchdr/deps/zstd-1.5.6/build/.gitignore
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/LICENSE b/deps/libchdr/deps/zstd-1.5.6/build/LICENSE
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/LICENSE
rename to deps/libchdr/deps/zstd-1.5.6/build/LICENSE
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/README.md b/deps/libchdr/deps/zstd-1.5.6/build/README.md
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/README.md
rename to deps/libchdr/deps/zstd-1.5.6/build/README.md
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/VS2008/fullbench/fullbench.vcproj b/deps/libchdr/deps/zstd-1.5.6/build/VS2008/fullbench/fullbench.vcproj
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/VS2008/fullbench/fullbench.vcproj
rename to deps/libchdr/deps/zstd-1.5.6/build/VS2008/fullbench/fullbench.vcproj
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/VS2008/fuzzer/fuzzer.vcproj b/deps/libchdr/deps/zstd-1.5.6/build/VS2008/fuzzer/fuzzer.vcproj
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/VS2008/fuzzer/fuzzer.vcproj
rename to deps/libchdr/deps/zstd-1.5.6/build/VS2008/fuzzer/fuzzer.vcproj
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/VS2008/zstd.sln b/deps/libchdr/deps/zstd-1.5.6/build/VS2008/zstd.sln
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/VS2008/zstd.sln
rename to deps/libchdr/deps/zstd-1.5.6/build/VS2008/zstd.sln
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/VS2008/zstd/zstd.vcproj b/deps/libchdr/deps/zstd-1.5.6/build/VS2008/zstd/zstd.vcproj
similarity index 99%
rename from deps/libchdr/deps/zstd-1.5.5/build/VS2008/zstd/zstd.vcproj
rename to deps/libchdr/deps/zstd-1.5.6/build/VS2008/zstd/zstd.vcproj
index 91f2bda5..de1501d2 100644
--- a/deps/libchdr/deps/zstd-1.5.5/build/VS2008/zstd/zstd.vcproj
+++ b/deps/libchdr/deps/zstd-1.5.6/build/VS2008/zstd/zstd.vcproj
@@ -356,6 +356,10 @@
RelativePath="..\..\..\programs\dibio.c"
>
+
+
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/VS2008/zstdlib/zstdlib.vcproj b/deps/libchdr/deps/zstd-1.5.6/build/VS2008/zstdlib/zstdlib.vcproj
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/VS2008/zstdlib/zstdlib.vcproj
rename to deps/libchdr/deps/zstd-1.5.6/build/VS2008/zstdlib/zstdlib.vcproj
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/VS2010/CompileAsCpp.props b/deps/libchdr/deps/zstd-1.5.6/build/VS2010/CompileAsCpp.props
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/VS2010/CompileAsCpp.props
rename to deps/libchdr/deps/zstd-1.5.6/build/VS2010/CompileAsCpp.props
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/VS2010/datagen/datagen.vcxproj b/deps/libchdr/deps/zstd-1.5.6/build/VS2010/datagen/datagen.vcxproj
similarity index 98%
rename from deps/libchdr/deps/zstd-1.5.5/build/VS2010/datagen/datagen.vcxproj
rename to deps/libchdr/deps/zstd-1.5.6/build/VS2010/datagen/datagen.vcxproj
index a66358a0..aaba4788 100644
--- a/deps/libchdr/deps/zstd-1.5.5/build/VS2010/datagen/datagen.vcxproj
+++ b/deps/libchdr/deps/zstd-1.5.6/build/VS2010/datagen/datagen.vcxproj
@@ -157,6 +157,8 @@
+
+
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/VS2010/fullbench-dll/fullbench-dll.vcxproj b/deps/libchdr/deps/zstd-1.5.6/build/VS2010/fullbench-dll/fullbench-dll.vcxproj
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/VS2010/fullbench-dll/fullbench-dll.vcxproj
rename to deps/libchdr/deps/zstd-1.5.6/build/VS2010/fullbench-dll/fullbench-dll.vcxproj
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/VS2010/fullbench/fullbench.vcxproj b/deps/libchdr/deps/zstd-1.5.6/build/VS2010/fullbench/fullbench.vcxproj
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/VS2010/fullbench/fullbench.vcxproj
rename to deps/libchdr/deps/zstd-1.5.6/build/VS2010/fullbench/fullbench.vcxproj
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/VS2010/fuzzer/fuzzer.vcxproj b/deps/libchdr/deps/zstd-1.5.6/build/VS2010/fuzzer/fuzzer.vcxproj
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/VS2010/fuzzer/fuzzer.vcxproj
rename to deps/libchdr/deps/zstd-1.5.6/build/VS2010/fuzzer/fuzzer.vcxproj
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/VS2010/libzstd-dll/libzstd-dll.rc b/deps/libchdr/deps/zstd-1.5.6/build/VS2010/libzstd-dll/libzstd-dll.rc
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/VS2010/libzstd-dll/libzstd-dll.rc
rename to deps/libchdr/deps/zstd-1.5.6/build/VS2010/libzstd-dll/libzstd-dll.rc
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/VS2010/libzstd-dll/libzstd-dll.vcxproj b/deps/libchdr/deps/zstd-1.5.6/build/VS2010/libzstd-dll/libzstd-dll.vcxproj
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/VS2010/libzstd-dll/libzstd-dll.vcxproj
rename to deps/libchdr/deps/zstd-1.5.6/build/VS2010/libzstd-dll/libzstd-dll.vcxproj
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/VS2010/libzstd/libzstd.vcxproj b/deps/libchdr/deps/zstd-1.5.6/build/VS2010/libzstd/libzstd.vcxproj
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/VS2010/libzstd/libzstd.vcxproj
rename to deps/libchdr/deps/zstd-1.5.6/build/VS2010/libzstd/libzstd.vcxproj
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/VS2010/zstd.sln b/deps/libchdr/deps/zstd-1.5.6/build/VS2010/zstd.sln
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/VS2010/zstd.sln
rename to deps/libchdr/deps/zstd-1.5.6/build/VS2010/zstd.sln
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/VS2010/zstd/zstd.rc b/deps/libchdr/deps/zstd-1.5.6/build/VS2010/zstd/zstd.rc
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/VS2010/zstd/zstd.rc
rename to deps/libchdr/deps/zstd-1.5.6/build/VS2010/zstd/zstd.rc
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/VS2010/zstd/zstd.vcxproj b/deps/libchdr/deps/zstd-1.5.6/build/VS2010/zstd/zstd.vcxproj
similarity index 99%
rename from deps/libchdr/deps/zstd-1.5.5/build/VS2010/zstd/zstd.vcxproj
rename to deps/libchdr/deps/zstd-1.5.6/build/VS2010/zstd/zstd.vcxproj
index 5e1bced6..5a5237f0 100644
--- a/deps/libchdr/deps/zstd-1.5.5/build/VS2010/zstd/zstd.vcxproj
+++ b/deps/libchdr/deps/zstd-1.5.6/build/VS2010/zstd/zstd.vcxproj
@@ -63,6 +63,7 @@
+
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/VS_scripts/README.md b/deps/libchdr/deps/zstd-1.5.6/build/VS_scripts/README.md
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/VS_scripts/README.md
rename to deps/libchdr/deps/zstd-1.5.6/build/VS_scripts/README.md
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/VS_scripts/build.VS2010.cmd b/deps/libchdr/deps/zstd-1.5.6/build/VS_scripts/build.VS2010.cmd
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/VS_scripts/build.VS2010.cmd
rename to deps/libchdr/deps/zstd-1.5.6/build/VS_scripts/build.VS2010.cmd
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/VS_scripts/build.VS2012.cmd b/deps/libchdr/deps/zstd-1.5.6/build/VS_scripts/build.VS2012.cmd
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/VS_scripts/build.VS2012.cmd
rename to deps/libchdr/deps/zstd-1.5.6/build/VS_scripts/build.VS2012.cmd
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/VS_scripts/build.VS2013.cmd b/deps/libchdr/deps/zstd-1.5.6/build/VS_scripts/build.VS2013.cmd
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/VS_scripts/build.VS2013.cmd
rename to deps/libchdr/deps/zstd-1.5.6/build/VS_scripts/build.VS2013.cmd
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/VS_scripts/build.VS2015.cmd b/deps/libchdr/deps/zstd-1.5.6/build/VS_scripts/build.VS2015.cmd
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/VS_scripts/build.VS2015.cmd
rename to deps/libchdr/deps/zstd-1.5.6/build/VS_scripts/build.VS2015.cmd
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/VS_scripts/build.VS2017.cmd b/deps/libchdr/deps/zstd-1.5.6/build/VS_scripts/build.VS2017.cmd
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/VS_scripts/build.VS2017.cmd
rename to deps/libchdr/deps/zstd-1.5.6/build/VS_scripts/build.VS2017.cmd
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/VS_scripts/build.VS2017Community.cmd b/deps/libchdr/deps/zstd-1.5.6/build/VS_scripts/build.VS2017Community.cmd
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/VS_scripts/build.VS2017Community.cmd
rename to deps/libchdr/deps/zstd-1.5.6/build/VS_scripts/build.VS2017Community.cmd
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/VS_scripts/build.VS2017Enterprise.cmd b/deps/libchdr/deps/zstd-1.5.6/build/VS_scripts/build.VS2017Enterprise.cmd
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/VS_scripts/build.VS2017Enterprise.cmd
rename to deps/libchdr/deps/zstd-1.5.6/build/VS_scripts/build.VS2017Enterprise.cmd
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/VS_scripts/build.VS2017Professional.cmd b/deps/libchdr/deps/zstd-1.5.6/build/VS_scripts/build.VS2017Professional.cmd
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/VS_scripts/build.VS2017Professional.cmd
rename to deps/libchdr/deps/zstd-1.5.6/build/VS_scripts/build.VS2017Professional.cmd
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/VS_scripts/build.generic.cmd b/deps/libchdr/deps/zstd-1.5.6/build/VS_scripts/build.generic.cmd
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/VS_scripts/build.generic.cmd
rename to deps/libchdr/deps/zstd-1.5.6/build/VS_scripts/build.generic.cmd
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/cmake/.gitignore b/deps/libchdr/deps/zstd-1.5.6/build/cmake/.gitignore
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/cmake/.gitignore
rename to deps/libchdr/deps/zstd-1.5.6/build/cmake/.gitignore
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/cmake/CMakeLists.txt b/deps/libchdr/deps/zstd-1.5.6/build/cmake/CMakeLists.txt
similarity index 84%
rename from deps/libchdr/deps/zstd-1.5.5/build/cmake/CMakeLists.txt
rename to deps/libchdr/deps/zstd-1.5.6/build/cmake/CMakeLists.txt
index 0bffc87d..399b818f 100644
--- a/deps/libchdr/deps/zstd-1.5.5/build/cmake/CMakeLists.txt
+++ b/deps/libchdr/deps/zstd-1.5.6/build/cmake/CMakeLists.txt
@@ -7,16 +7,14 @@
# in the COPYING file in the root directory of this source tree).
# ################################################################
-cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
+cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
# As of 2018-12-26 ZSTD has been validated to build with cmake version 3.13.2 new policies.
# Set and use the newest cmake policies that are validated to work
set(ZSTD_MAX_VALIDATED_CMAKE_MAJOR_VERSION "3")
set(ZSTD_MAX_VALIDATED_CMAKE_MINOR_VERSION "13") #Policies never changed at PATCH level
-if("${CMAKE_MAJOR_VERSION}" LESS 3)
- set(ZSTD_CMAKE_POLICY_VERSION "${CMAKE_VERSION}")
-elseif( "${ZSTD_MAX_VALIDATED_CMAKE_MAJOR_VERSION}" EQUAL "${CMAKE_MAJOR_VERSION}" AND
- "${ZSTD_MAX_VALIDATED_CMAKE_MINOR_VERSION}" GREATER "${CMAKE_MINOR_VERSION}")
+if("${ZSTD_MAX_VALIDATED_CMAKE_MAJOR_VERSION}" EQUAL "${CMAKE_MAJOR_VERSION}" AND
+ "${ZSTD_MAX_VALIDATED_CMAKE_MINOR_VERSION}" GREATER "${CMAKE_MINOR_VERSION}")
set(ZSTD_CMAKE_POLICY_VERSION "${CMAKE_VERSION}")
else()
set(ZSTD_CMAKE_POLICY_VERSION "${ZSTD_MAX_VALIDATED_CMAKE_MAJOR_VERSION}.${ZSTD_MAX_VALIDATED_CMAKE_MINOR_VERSION}.0")
@@ -32,24 +30,13 @@ set(LIBRARY_DIR ${ZSTD_SOURCE_DIR}/lib)
include(GetZstdLibraryVersion)
GetZstdLibraryVersion(${LIBRARY_DIR}/zstd.h zstd_VERSION_MAJOR zstd_VERSION_MINOR zstd_VERSION_PATCH)
-if( CMAKE_MAJOR_VERSION LESS 3 )
- ## Provide cmake 3+ behavior for older versions of cmake
- project(zstd)
- set(PROJECT_VERSION_MAJOR ${zstd_VERSION_MAJOR})
- set(PROJECT_VERSION_MINOR ${zstd_VERSION_MINOR})
- set(PROJECT_VERSION_PATCH ${zstd_VERSION_PATCH})
- set(PROJECT_VERSION "${zstd_VERSION_MAJOR}.${zstd_VERSION_MINOR}.${zstd_VERSION_PATCH}")
- enable_language(C) # Main library is in C
- enable_language(ASM) # And ASM
- enable_language(CXX) # Testing contributed code also utilizes CXX
-else()
- project(zstd
- VERSION "${zstd_VERSION_MAJOR}.${zstd_VERSION_MINOR}.${zstd_VERSION_PATCH}"
- LANGUAGES C # Main library is in C
- ASM # And ASM
- CXX # Testing contributed code also utilizes CXX
- )
-endif()
+project(zstd
+ VERSION "${zstd_VERSION_MAJOR}.${zstd_VERSION_MINOR}.${zstd_VERSION_PATCH}"
+ LANGUAGES C # Main library is in C
+ ASM # And ASM
+ CXX # Testing contributed code also utilizes CXX
+ )
+
message(STATUS "ZSTD VERSION: ${zstd_VERSION}")
set(zstd_HOMEPAGE_URL "https://facebook.github.io/zstd")
set(zstd_DESCRIPTION "Zstandard is a real-time compression algorithm, providing high compression ratios.")
@@ -127,10 +114,26 @@ endif ()
#-----------------------------------------------------------------------------
# External dependencies
#-----------------------------------------------------------------------------
+# Define a function to handle special thread settings for HP-UX
+# See https://github.com/facebook/zstd/pull/3862 for details.
+function(setup_hpux_threads)
+ find_package(Threads)
+ if (NOT Threads_FOUND)
+ set(CMAKE_USE_PTHREADS_INIT 1 PARENT_SCOPE)
+ set(CMAKE_THREAD_LIBS_INIT -lpthread PARENT_SCOPE)
+ set(CMAKE_HAVE_THREADS_LIBRARY 1 PARENT_SCOPE)
+ set(Threads_FOUND TRUE PARENT_SCOPE)
+ endif()
+endfunction()
+
if (ZSTD_MULTITHREAD_SUPPORT AND UNIX)
- set(THREADS_PREFER_PTHREAD_FLAG ON)
- find_package(Threads REQUIRED)
- if(CMAKE_USE_PTHREADS_INIT)
+ if (CMAKE_SYSTEM_NAME MATCHES "HP-UX")
+ setup_hpux_threads()
+ else()
+ set(THREADS_PREFER_PTHREAD_FLAG ON)
+ find_package(Threads REQUIRED)
+ endif()
+ if (CMAKE_USE_PTHREADS_INIT)
set(THREADS_LIBS "${CMAKE_THREAD_LIBS_INIT}")
else()
message(SEND_ERROR "ZSTD currently does not support thread libraries other than pthreads")
@@ -193,10 +196,6 @@ export(EXPORT zstdExports
FILE "${CMAKE_CURRENT_BINARY_DIR}/zstdTargets.cmake"
NAMESPACE zstd::
)
-configure_file(zstdConfig.cmake
- "${CMAKE_CURRENT_BINARY_DIR}/zstdConfig.cmake"
- COPYONLY
- )
# A Package Config file that works from the installation directory
set(ConfigPackageLocation ${CMAKE_INSTALL_LIBDIR}/cmake/zstd)
@@ -205,8 +204,13 @@ install(EXPORT zstdExports
NAMESPACE zstd::
DESTINATION ${ConfigPackageLocation}
)
+configure_package_config_file(
+ zstdConfig.cmake.in
+ "${CMAKE_CURRENT_BINARY_DIR}/zstdConfig.cmake"
+ INSTALL_DESTINATION ${ConfigPackageLocation}
+)
install(FILES
- zstdConfig.cmake
+ "${CMAKE_CURRENT_BINARY_DIR}/zstdConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/zstdConfigVersion.cmake"
DESTINATION ${ConfigPackageLocation}
)
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/cmake/CMakeModules/AddZstdCompilationFlags.cmake b/deps/libchdr/deps/zstd-1.5.6/build/cmake/CMakeModules/AddZstdCompilationFlags.cmake
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/cmake/CMakeModules/AddZstdCompilationFlags.cmake
rename to deps/libchdr/deps/zstd-1.5.6/build/cmake/CMakeModules/AddZstdCompilationFlags.cmake
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/cmake/CMakeModules/FindLibLZ4.cmake b/deps/libchdr/deps/zstd-1.5.6/build/cmake/CMakeModules/FindLibLZ4.cmake
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/cmake/CMakeModules/FindLibLZ4.cmake
rename to deps/libchdr/deps/zstd-1.5.6/build/cmake/CMakeModules/FindLibLZ4.cmake
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/cmake/CMakeModules/GetZstdLibraryVersion.cmake b/deps/libchdr/deps/zstd-1.5.6/build/cmake/CMakeModules/GetZstdLibraryVersion.cmake
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/cmake/CMakeModules/GetZstdLibraryVersion.cmake
rename to deps/libchdr/deps/zstd-1.5.6/build/cmake/CMakeModules/GetZstdLibraryVersion.cmake
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/cmake/CMakeModules/JoinPaths.cmake b/deps/libchdr/deps/zstd-1.5.6/build/cmake/CMakeModules/JoinPaths.cmake
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/cmake/CMakeModules/JoinPaths.cmake
rename to deps/libchdr/deps/zstd-1.5.6/build/cmake/CMakeModules/JoinPaths.cmake
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/cmake/README.md b/deps/libchdr/deps/zstd-1.5.6/build/cmake/README.md
similarity index 77%
rename from deps/libchdr/deps/zstd-1.5.5/build/cmake/README.md
rename to deps/libchdr/deps/zstd-1.5.6/build/cmake/README.md
index a460dd16..4c9d3a08 100644
--- a/deps/libchdr/deps/zstd-1.5.5/build/cmake/README.md
+++ b/deps/libchdr/deps/zstd-1.5.6/build/cmake/README.md
@@ -41,6 +41,38 @@ cmake -DZSTD_BUILD_TESTS=ON -DZSTD_LEGACY_SUPPORT=OFF ..
make
```
+### how to use it with CMake FetchContent
+
+For all options available, you can see it on
+```cmake
+include(FetchContent)
+
+set(ZSTD_BUILD_STATIC ON)
+set(ZSTD_BUILD_SHARED OFF)
+
+FetchContent_Declare(
+ zstd
+ URL "https://github.com/facebook/zstd/releases/download/v1.5.5/zstd-1.5.5.tar.gz"
+ DOWNLOAD_EXTRACT_TIMESTAMP TRUE
+ SOURCE_SUBDIR build/cmake
+)
+
+FetchContent_MakeAvailable(zstd)
+
+target_link_libraries(
+ ${PROJECT_NAME}
+ PRIVATE
+ libzstd_static
+)
+
+# On windows and macos this is needed
+target_include_directories(
+ ${PROJECT_NAME}
+ PRIVATE
+ ${zstd_SOURCE_DIR}/lib
+)
+```
+
### referring
[Looking for a 'cmake clean' command to clear up CMake output](https://stackoverflow.com/questions/9680420/looking-for-a-cmake-clean-command-to-clear-up-cmake-output)
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/cmake/contrib/CMakeLists.txt b/deps/libchdr/deps/zstd-1.5.6/build/cmake/contrib/CMakeLists.txt
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/cmake/contrib/CMakeLists.txt
rename to deps/libchdr/deps/zstd-1.5.6/build/cmake/contrib/CMakeLists.txt
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/cmake/contrib/gen_html/CMakeLists.txt b/deps/libchdr/deps/zstd-1.5.6/build/cmake/contrib/gen_html/CMakeLists.txt
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/cmake/contrib/gen_html/CMakeLists.txt
rename to deps/libchdr/deps/zstd-1.5.6/build/cmake/contrib/gen_html/CMakeLists.txt
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/cmake/contrib/pzstd/CMakeLists.txt b/deps/libchdr/deps/zstd-1.5.6/build/cmake/contrib/pzstd/CMakeLists.txt
similarity index 96%
rename from deps/libchdr/deps/zstd-1.5.5/build/cmake/contrib/pzstd/CMakeLists.txt
rename to deps/libchdr/deps/zstd-1.5.6/build/cmake/contrib/pzstd/CMakeLists.txt
index f7098fa0..e1c8e067 100644
--- a/deps/libchdr/deps/zstd-1.5.5/build/cmake/contrib/pzstd/CMakeLists.txt
+++ b/deps/libchdr/deps/zstd-1.5.6/build/cmake/contrib/pzstd/CMakeLists.txt
@@ -18,6 +18,7 @@ set(PZSTD_DIR ${ZSTD_SOURCE_DIR}/contrib/pzstd)
include_directories(${PROGRAMS_DIR} ${LIBRARY_DIR} ${LIBRARY_DIR}/common ${PZSTD_DIR})
add_executable(pzstd ${PROGRAMS_DIR}/util.c ${PZSTD_DIR}/main.cpp ${PZSTD_DIR}/Options.cpp ${PZSTD_DIR}/Pzstd.cpp ${PZSTD_DIR}/SkippableFrame.cpp)
+target_compile_features(pzstd PRIVATE cxx_std_11)
set_property(TARGET pzstd APPEND PROPERTY COMPILE_DEFINITIONS "NDEBUG")
set_property(TARGET pzstd APPEND PROPERTY COMPILE_OPTIONS "-Wno-shadow")
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/cmake/lib/.gitignore b/deps/libchdr/deps/zstd-1.5.6/build/cmake/lib/.gitignore
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/cmake/lib/.gitignore
rename to deps/libchdr/deps/zstd-1.5.6/build/cmake/lib/.gitignore
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/cmake/lib/CMakeLists.txt b/deps/libchdr/deps/zstd-1.5.6/build/cmake/lib/CMakeLists.txt
similarity index 54%
rename from deps/libchdr/deps/zstd-1.5.5/build/cmake/lib/CMakeLists.txt
rename to deps/libchdr/deps/zstd-1.5.6/build/cmake/lib/CMakeLists.txt
index 30349586..5d514ccb 100644
--- a/deps/libchdr/deps/zstd-1.5.5/build/cmake/lib/CMakeLists.txt
+++ b/deps/libchdr/deps/zstd-1.5.6/build/cmake/lib/CMakeLists.txt
@@ -12,45 +12,70 @@ project(libzstd C ASM)
set(CMAKE_INCLUDE_CURRENT_DIR TRUE)
option(ZSTD_BUILD_STATIC "BUILD STATIC LIBRARIES" ON)
option(ZSTD_BUILD_SHARED "BUILD SHARED LIBRARIES" ON)
+option(ZSTD_BUILD_COMPRESSION "BUILD COMPRESSION MODULE" ON)
+option(ZSTD_BUILD_DECOMPRESSION "BUILD DECOMPRESSION MODULE" ON)
+option(ZSTD_BUILD_DICTBUILDER "BUILD DICTBUILDER MODULE" ON)
+option(ZSTD_BUILD_DEPRECATED "BUILD DEPRECATED MODULE" OFF)
+
+set(ZSTDLIB_VISIBLE "" CACHE STRING "Visibility for ZSTDLIB API")
+set(ZSTDERRORLIB_VISIBLE "" CACHE STRING "Visibility for ZSTDERRORLIB_VISIBLE API")
+set(ZDICTLIB_VISIBLE "" CACHE STRING "Visibility for ZDICTLIB_VISIBLE API")
+set(ZSTDLIB_STATIC_API "" CACHE STRING "Visibility for ZSTDLIB_STATIC_API API")
+set(ZDICTLIB_STATIC_API "" CACHE STRING "Visibility for ZDICTLIB_STATIC_API API")
+
+set_property(CACHE ZSTDLIB_VISIBLE PROPERTY STRINGS "" "hidden" "default" "protected" "internal")
+set_property(CACHE ZSTDERRORLIB_VISIBLE PROPERTY STRINGS "" "hidden" "default" "protected" "internal")
+set_property(CACHE ZDICTLIB_VISIBLE PROPERTY STRINGS "" "hidden" "default" "protected" "internal")
+set_property(CACHE ZSTDLIB_STATIC_API PROPERTY STRINGS "" "hidden" "default" "protected" "internal")
+set_property(CACHE ZDICTLIB_STATIC_API PROPERTY STRINGS "" "hidden" "default" "protected" "internal")
if(NOT ZSTD_BUILD_SHARED AND NOT ZSTD_BUILD_STATIC)
message(SEND_ERROR "You need to build at least one flavor of libzstd")
endif()
-# Define library directory, where sources and header files are located
-include_directories(${LIBRARY_DIR} ${LIBRARY_DIR}/common)
-
file(GLOB CommonSources ${LIBRARY_DIR}/common/*.c)
file(GLOB CompressSources ${LIBRARY_DIR}/compress/*.c)
+file(GLOB DecompressSources ${LIBRARY_DIR}/decompress/*.c)
if (MSVC)
- file(GLOB DecompressSources ${LIBRARY_DIR}/decompress/*.c)
add_compile_options(-DZSTD_DISABLE_ASM)
else ()
- file(GLOB DecompressSources ${LIBRARY_DIR}/decompress/*.c ${LIBRARY_DIR}/decompress/*.S)
+ if(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|AMD64.*|x86_64.*|X86_64.*")
+ set(DecompressSources ${DecompressSources} ${LIBRARY_DIR}/decompress/huf_decompress_amd64.S)
+ else()
+ add_compile_options(-DZSTD_DISABLE_ASM)
+ endif()
endif ()
file(GLOB DictBuilderSources ${LIBRARY_DIR}/dictBuilder/*.c)
+file(GLOB DeprecatedSources ${LIBRARY_DIR}/deprecated/*.c)
-set(Sources
- ${CommonSources}
- ${CompressSources}
- ${DecompressSources}
- ${DictBuilderSources})
-
+file(GLOB PublicHeaders ${LIBRARY_DIR}/*.h)
file(GLOB CommonHeaders ${LIBRARY_DIR}/common/*.h)
file(GLOB CompressHeaders ${LIBRARY_DIR}/compress/*.h)
file(GLOB DecompressHeaders ${LIBRARY_DIR}/decompress/*.h)
file(GLOB DictBuilderHeaders ${LIBRARY_DIR}/dictBuilder/*.h)
+file(GLOB DeprecatedHeaders ${LIBRARY_DIR}/deprecated/*.h)
-set(Headers
- ${LIBRARY_DIR}/zstd.h
- ${CommonHeaders}
- ${CompressHeaders}
- ${DecompressHeaders}
- ${DictBuilderHeaders})
+set(Sources ${CommonSources})
+set(Headers ${PublicHeaders} ${CommonHeaders})
+if (ZSTD_BUILD_COMPRESSION)
+ set(Sources ${Sources} ${CompressSources})
+ set(Headers ${Headers} ${CompressHeaders})
+endif()
+if (ZSTD_BUILD_DECOMPRESSION)
+ set(Sources ${Sources} ${DecompressSources})
+ set(Headers ${Headers} ${DecompressHeaders})
+endif()
+if (ZSTD_BUILD_DICTBUILDER)
+ set(Sources ${Sources} ${DictBuilderSources})
+ set(Headers ${Headers} ${DictBuilderHeaders})
+endif()
+if (ZSTD_BUILD_DEPRECATED)
+ set(Sources ${Sources} ${DeprecatedSources})
+ set(Headers ${Headers} ${DeprecatedHeaders})
+endif()
if (ZSTD_LEGACY_SUPPORT)
set(LIBRARY_LEGACY_DIR ${LIBRARY_DIR}/legacy)
- include_directories(${LIBRARY_LEGACY_DIR})
set(Sources ${Sources}
${LIBRARY_LEGACY_DIR}/zstd_v01.c
@@ -81,22 +106,38 @@ endif ()
# Our assembly expects to be compiled by a C compiler, and is only enabled for
# __GNUC__ compatible compilers. Otherwise all the ASM code is disabled by
# macros.
-set_source_files_properties(${Sources} PROPERTIES LANGUAGE C)
+if(NOT CMAKE_ASM_COMPILER STREQUAL CMAKE_C_COMPILER)
+ set_source_files_properties(${Sources} PROPERTIES LANGUAGE C)
+endif()
+
+macro (add_definition target var)
+ if (NOT ("${${var}}" STREQUAL ""))
+ set_property(TARGET ${target} APPEND PROPERTY COMPILE_DEFINITIONS "${var}=__attribute__((visibility(\"${${var}}\")))")
+ endif ()
+endmacro ()
+
+# Define directories containing the library's public headers
+set(PUBLIC_INCLUDE_DIRS ${LIBRARY_DIR})
# Split project to static and shared libraries build
set(library_targets)
if (ZSTD_BUILD_SHARED)
add_library(libzstd_shared SHARED ${Sources} ${Headers} ${PlatformDependResources})
+ target_include_directories(libzstd_shared INTERFACE $)
list(APPEND library_targets libzstd_shared)
if (ZSTD_MULTITHREAD_SUPPORT)
set_property(TARGET libzstd_shared APPEND PROPERTY COMPILE_DEFINITIONS "ZSTD_MULTITHREAD")
if (UNIX)
target_link_libraries(libzstd_shared ${THREADS_LIBS})
endif ()
- endif()
+ endif ()
+ add_definition(libzstd_shared ZSTDLIB_VISIBLE)
+ add_definition(libzstd_shared ZSTDERRORLIB_VISIBLE)
+ add_definition(libzstd_shared ZDICTLIB_VISIBLE)
endif ()
if (ZSTD_BUILD_STATIC)
add_library(libzstd_static STATIC ${Sources} ${Headers})
+ target_include_directories(libzstd_static INTERFACE $)
list(APPEND library_targets libzstd_static)
if (ZSTD_MULTITHREAD_SUPPORT)
set_property(TARGET libzstd_static APPEND PROPERTY COMPILE_DEFINITIONS "ZSTD_MULTITHREAD")
@@ -104,6 +145,41 @@ if (ZSTD_BUILD_STATIC)
target_link_libraries(libzstd_static ${THREADS_LIBS})
endif ()
endif ()
+ add_definition(libzstd_static ZSTDLIB_VISIBLE)
+ add_definition(libzstd_static ZSTDERRORLIB_VISIBLE)
+ add_definition(libzstd_static ZDICTLIB_VISIBLE)
+ add_definition(libzstd_static ZSTDLIB_STATIC_API)
+ add_definition(libzstd_static ZDICTLIB_STATIC_API)
+endif ()
+if (ZSTD_BUILD_SHARED AND NOT ZSTD_BUILD_STATIC)
+ if (NOT BUILD_SHARED_LIBS)
+ message(WARNING "BUILD_SHARED_LIBS is OFF, but ZSTD_BUILD_SHARED is ON and ZSTD_BUILD_STATIC is OFF, which takes precedence, so libzstd is a shared library")
+ endif ()
+ add_library(libzstd INTERFACE)
+ target_link_libraries(libzstd INTERFACE libzstd_shared)
+ list(APPEND library_targets libzstd)
+endif ()
+if (ZSTD_BUILD_STATIC AND NOT ZSTD_BUILD_SHARED)
+ if (BUILD_SHARED_LIBS)
+ message(WARNING "BUILD_SHARED_LIBS is ON, but ZSTD_BUILD_SHARED is OFF and ZSTD_BUILD_STATIC is ON, which takes precedence, is set so libzstd is a static library")
+ endif ()
+ add_library(libzstd INTERFACE)
+ target_link_libraries(libzstd INTERFACE libzstd_static)
+ list(APPEND library_targets libzstd)
+endif ()
+if (ZSTD_BUILD_SHARED AND ZSTD_BUILD_STATIC)
+ # If both ZSTD_BUILD_SHARED and ZSTD_BUILD_STATIC are set, which is the
+ # default, fallback to using BUILD_SHARED_LIBS to determine whether to
+ # set libzstd to static or shared.
+ if (BUILD_SHARED_LIBS)
+ add_library(libzstd INTERFACE)
+ target_link_libraries(libzstd INTERFACE libzstd_shared)
+ list(APPEND library_targets libzstd)
+ else ()
+ add_library(libzstd INTERFACE)
+ target_link_libraries(libzstd INTERFACE libzstd_static)
+ list(APPEND library_targets libzstd)
+ endif ()
endif ()
# Add specific compile definitions for MSVC project
@@ -154,11 +230,7 @@ configure_file("${LIBRARY_DIR}/libzstd.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/libzs
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libzstd.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
# install target
-install(FILES
- "${LIBRARY_DIR}/zstd.h"
- "${LIBRARY_DIR}/zdict.h"
- "${LIBRARY_DIR}/zstd_errors.h"
- DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
+install(FILES ${PublicHeaders} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
install(TARGETS ${library_targets}
EXPORT zstdExports
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/cmake/lib/cmake_uninstall.cmake.in b/deps/libchdr/deps/zstd-1.5.6/build/cmake/lib/cmake_uninstall.cmake.in
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/cmake/lib/cmake_uninstall.cmake.in
rename to deps/libchdr/deps/zstd-1.5.6/build/cmake/lib/cmake_uninstall.cmake.in
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/cmake/programs/.gitignore b/deps/libchdr/deps/zstd-1.5.6/build/cmake/programs/.gitignore
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/cmake/programs/.gitignore
rename to deps/libchdr/deps/zstd-1.5.6/build/cmake/programs/.gitignore
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/cmake/programs/CMakeLists.txt b/deps/libchdr/deps/zstd-1.5.6/build/cmake/programs/CMakeLists.txt
similarity index 91%
rename from deps/libchdr/deps/zstd-1.5.5/build/cmake/programs/CMakeLists.txt
rename to deps/libchdr/deps/zstd-1.5.6/build/cmake/programs/CMakeLists.txt
index 58d998e4..5e239e32 100644
--- a/deps/libchdr/deps/zstd-1.5.5/build/cmake/programs/CMakeLists.txt
+++ b/deps/libchdr/deps/zstd-1.5.6/build/cmake/programs/CMakeLists.txt
@@ -32,7 +32,12 @@ if (MSVC)
set(PlatformDependResources ${MSVC_RESOURCE_DIR}/zstd.rc)
endif ()
-add_executable(zstd ${PROGRAMS_DIR}/zstdcli.c ${PROGRAMS_DIR}/util.c ${PROGRAMS_DIR}/timefn.c ${PROGRAMS_DIR}/fileio.c ${PROGRAMS_DIR}/fileio_asyncio.c ${PROGRAMS_DIR}/benchfn.c ${PROGRAMS_DIR}/benchzstd.c ${PROGRAMS_DIR}/datagen.c ${PROGRAMS_DIR}/dibio.c ${PROGRAMS_DIR}/zstdcli_trace.c ${PlatformDependResources})
+file(GLOB ZSTD_PROGRAM_SRCS "${PROGRAMS_DIR}/*.c")
+if (MSVC AND ZSTD_PROGRAMS_LINK_SHARED)
+ list(APPEND ZSTD_PROGRAM_SRCS ${LIBRARY_DIR}/common/pool.c ${LIBRARY_DIR}/common/threading.c)
+endif ()
+
+add_executable(zstd ${ZSTD_PROGRAM_SRCS})
target_link_libraries(zstd ${PROGRAMS_ZSTD_LINK_TARGET})
if (CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
target_link_libraries(zstd rt)
@@ -75,7 +80,9 @@ if (UNIX)
${CMAKE_CURRENT_BINARY_DIR}/zstdless.1
DESTINATION "${MAN_INSTALL_DIR}")
- add_executable(zstd-frugal ${PROGRAMS_DIR}/zstdcli.c ${PROGRAMS_DIR}/util.c ${PROGRAMS_DIR}/timefn.c ${PROGRAMS_DIR}/fileio.c ${PROGRAMS_DIR}/fileio_asyncio.c)
+ add_executable(zstd-frugal ${PROGRAMS_DIR}/zstdcli.c
+ ${PROGRAMS_DIR}/util.c ${PROGRAMS_DIR}/timefn.c
+ ${PROGRAMS_DIR}/fileio.c ${PROGRAMS_DIR}/fileio_asyncio.c)
target_link_libraries(zstd-frugal ${PROGRAMS_ZSTD_LINK_TARGET})
set_property(TARGET zstd-frugal APPEND PROPERTY COMPILE_DEFINITIONS "ZSTD_NOBENCH;ZSTD_NODICT;ZSTD_NOTRACE")
endif ()
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/cmake/tests/.gitignore b/deps/libchdr/deps/zstd-1.5.6/build/cmake/tests/.gitignore
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/cmake/tests/.gitignore
rename to deps/libchdr/deps/zstd-1.5.6/build/cmake/tests/.gitignore
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/cmake/tests/CMakeLists.txt b/deps/libchdr/deps/zstd-1.5.6/build/cmake/tests/CMakeLists.txt
similarity index 88%
rename from deps/libchdr/deps/zstd-1.5.5/build/cmake/tests/CMakeLists.txt
rename to deps/libchdr/deps/zstd-1.5.6/build/cmake/tests/CMakeLists.txt
index 250f0508..56104a4e 100644
--- a/deps/libchdr/deps/zstd-1.5.5/build/cmake/tests/CMakeLists.txt
+++ b/deps/libchdr/deps/zstd-1.5.6/build/cmake/tests/CMakeLists.txt
@@ -50,18 +50,18 @@ set(PROGRAMS_DIR ${ZSTD_SOURCE_DIR}/programs)
set(TESTS_DIR ${ZSTD_SOURCE_DIR}/tests)
include_directories(${TESTS_DIR} ${PROGRAMS_DIR} ${LIBRARY_DIR} ${LIBRARY_DIR}/common ${LIBRARY_DIR}/compress ${LIBRARY_DIR}/dictBuilder)
-add_executable(datagen ${PROGRAMS_DIR}/datagen.c ${TESTS_DIR}/datagencli.c)
+add_executable(datagen ${PROGRAMS_DIR}/datagen.c ${PROGRAMS_DIR}/lorem.c ${TESTS_DIR}/loremOut.c ${TESTS_DIR}/datagencli.c)
target_link_libraries(datagen libzstd_static)
#
# fullbench
#
-add_executable(fullbench ${PROGRAMS_DIR}/datagen.c ${PROGRAMS_DIR}/util.c ${PROGRAMS_DIR}/timefn.c ${PROGRAMS_DIR}/benchfn.c ${PROGRAMS_DIR}/benchzstd.c ${TESTS_DIR}/fullbench.c)
+add_executable(fullbench ${PROGRAMS_DIR}/datagen.c ${PROGRAMS_DIR}/lorem.c ${PROGRAMS_DIR}/util.c ${PROGRAMS_DIR}/timefn.c ${PROGRAMS_DIR}/benchfn.c ${PROGRAMS_DIR}/benchzstd.c ${TESTS_DIR}/fullbench.c)
if (NOT MSVC)
target_compile_options(fullbench PRIVATE "-Wno-deprecated-declarations")
endif()
target_link_libraries(fullbench libzstd_static)
-add_test(NAME fullbench COMMAND fullbench ${ZSTD_FULLBENCH_FLAGS})
+add_test(NAME fullbench COMMAND "$" ${ZSTD_FULLBENCH_FLAGS})
#
# fuzzer
@@ -73,7 +73,7 @@ endif()
target_link_libraries(fuzzer libzstd_static)
AddTestFlagsOption(ZSTD_FUZZER_FLAGS "$ENV{FUZZERTEST} $ENV{FUZZER_FLAGS}"
"Semicolon-separated list of flags to pass to the fuzzer test (see `fuzzer -h` for usage)")
-add_test(NAME fuzzer COMMAND fuzzer ${ZSTD_FUZZER_FLAGS})
+add_test(NAME fuzzer COMMAND "$" ${ZSTD_FUZZER_FLAGS})
# Disable the timeout since the run time is too long for the default timeout of
# 1500 seconds and varies considerably between low-end and high-end CPUs.
# set_tests_properties(fuzzer PROPERTIES TIMEOUT 0)
@@ -88,7 +88,7 @@ endif()
target_link_libraries(zstreamtest libzstd_static)
AddTestFlagsOption(ZSTD_ZSTREAM_FLAGS "$ENV{ZSTREAM_TESTTIME} $ENV{FUZZER_FLAGS}"
"Semicolon-separated list of flags to pass to the zstreamtest test (see `zstreamtest -h` for usage)")
-add_test(NAME zstreamtest COMMAND zstreamtest ${ZSTD_ZSTREAM_FLAGS})
+add_test(NAME zstreamtest COMMAND "$" ${ZSTD_ZSTREAM_FLAGS})
#
# playTests.sh
@@ -110,7 +110,7 @@ endif()
# Label the "Medium" set of tests (see TESTING.md)
set_property(TEST fuzzer zstreamtest playTests APPEND PROPERTY LABELS Medium)
-add_executable(paramgrill ${PROGRAMS_DIR}/benchfn.c ${PROGRAMS_DIR}/benchzstd.c ${PROGRAMS_DIR}/datagen.c ${PROGRAMS_DIR}/util.c ${PROGRAMS_DIR}/timefn.c ${TESTS_DIR}/paramgrill.c)
+add_executable(paramgrill ${PROGRAMS_DIR}/benchfn.c ${PROGRAMS_DIR}/benchzstd.c ${PROGRAMS_DIR}/datagen.c ${PROGRAMS_DIR}/lorem.c ${PROGRAMS_DIR}/util.c ${PROGRAMS_DIR}/timefn.c ${TESTS_DIR}/paramgrill.c)
if (UNIX)
target_link_libraries(paramgrill libzstd_static m) #m is math library
else()
diff --git a/deps/libchdr/deps/zstd-1.5.6/build/cmake/zstdConfig.cmake.in b/deps/libchdr/deps/zstd-1.5.6/build/cmake/zstdConfig.cmake.in
new file mode 100644
index 00000000..f4190f98
--- /dev/null
+++ b/deps/libchdr/deps/zstd-1.5.6/build/cmake/zstdConfig.cmake.in
@@ -0,0 +1,10 @@
+@PACKAGE_INIT@
+
+include(CMakeFindDependencyMacro)
+if(@ZSTD_MULTITHREAD_SUPPORT@ AND "@UNIX@")
+ find_dependency(Threads)
+endif()
+
+include("${CMAKE_CURRENT_LIST_DIR}/zstdTargets.cmake")
+
+check_required_components("zstd")
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/meson/GetZstdLibraryVersion.py b/deps/libchdr/deps/zstd-1.5.6/build/meson/GetZstdLibraryVersion.py
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/meson/GetZstdLibraryVersion.py
rename to deps/libchdr/deps/zstd-1.5.6/build/meson/GetZstdLibraryVersion.py
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/meson/InstallSymlink.py b/deps/libchdr/deps/zstd-1.5.6/build/meson/InstallSymlink.py
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/meson/InstallSymlink.py
rename to deps/libchdr/deps/zstd-1.5.6/build/meson/InstallSymlink.py
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/meson/README.md b/deps/libchdr/deps/zstd-1.5.6/build/meson/README.md
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/meson/README.md
rename to deps/libchdr/deps/zstd-1.5.6/build/meson/README.md
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/meson/contrib/gen_html/meson.build b/deps/libchdr/deps/zstd-1.5.6/build/meson/contrib/gen_html/meson.build
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/meson/contrib/gen_html/meson.build
rename to deps/libchdr/deps/zstd-1.5.6/build/meson/contrib/gen_html/meson.build
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/meson/contrib/meson.build b/deps/libchdr/deps/zstd-1.5.6/build/meson/contrib/meson.build
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/meson/contrib/meson.build
rename to deps/libchdr/deps/zstd-1.5.6/build/meson/contrib/meson.build
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/meson/contrib/pzstd/meson.build b/deps/libchdr/deps/zstd-1.5.6/build/meson/contrib/pzstd/meson.build
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/meson/contrib/pzstd/meson.build
rename to deps/libchdr/deps/zstd-1.5.6/build/meson/contrib/pzstd/meson.build
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/meson/lib/meson.build b/deps/libchdr/deps/zstd-1.5.6/build/meson/lib/meson.build
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/meson/lib/meson.build
rename to deps/libchdr/deps/zstd-1.5.6/build/meson/lib/meson.build
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/meson/meson.build b/deps/libchdr/deps/zstd-1.5.6/build/meson/meson.build
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/meson/meson.build
rename to deps/libchdr/deps/zstd-1.5.6/build/meson/meson.build
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/meson/meson_options.txt b/deps/libchdr/deps/zstd-1.5.6/build/meson/meson_options.txt
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/meson/meson_options.txt
rename to deps/libchdr/deps/zstd-1.5.6/build/meson/meson_options.txt
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/meson/programs/meson.build b/deps/libchdr/deps/zstd-1.5.6/build/meson/programs/meson.build
similarity index 98%
rename from deps/libchdr/deps/zstd-1.5.5/build/meson/programs/meson.build
rename to deps/libchdr/deps/zstd-1.5.6/build/meson/programs/meson.build
index 0b5a9305..e103a629 100644
--- a/deps/libchdr/deps/zstd-1.5.5/build/meson/programs/meson.build
+++ b/deps/libchdr/deps/zstd-1.5.6/build/meson/programs/meson.build
@@ -18,6 +18,7 @@ zstd_programs_sources = [join_paths(zstd_rootdir, 'programs/zstdcli.c'),
join_paths(zstd_rootdir, 'programs/benchfn.c'),
join_paths(zstd_rootdir, 'programs/benchzstd.c'),
join_paths(zstd_rootdir, 'programs/datagen.c'),
+ join_paths(zstd_rootdir, 'programs/lorem.c'),
join_paths(zstd_rootdir, 'programs/dibio.c'),
join_paths(zstd_rootdir, 'programs/zstdcli_trace.c')]
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/meson/tests/meson.build b/deps/libchdr/deps/zstd-1.5.6/build/meson/tests/meson.build
similarity index 98%
rename from deps/libchdr/deps/zstd-1.5.5/build/meson/tests/meson.build
rename to deps/libchdr/deps/zstd-1.5.6/build/meson/tests/meson.build
index 2dd8d106..9847ab03 100644
--- a/deps/libchdr/deps/zstd-1.5.5/build/meson/tests/meson.build
+++ b/deps/libchdr/deps/zstd-1.5.6/build/meson/tests/meson.build
@@ -29,6 +29,7 @@ DECODECORPUS_TESTTIME = '-T30'
test_includes = [ include_directories(join_paths(zstd_rootdir, 'programs')) ]
testcommon_sources = [join_paths(zstd_rootdir, 'programs/datagen.c'),
+ join_paths(zstd_rootdir, 'programs/lorem.c'),
join_paths(zstd_rootdir, 'programs/util.c'),
join_paths(zstd_rootdir, 'programs/timefn.c'),
join_paths(zstd_rootdir, 'programs/benchfn.c'),
@@ -43,7 +44,8 @@ testcommon_dep = declare_dependency(link_with: testcommon,
dependencies: libzstd_deps,
include_directories: libzstd_includes)
-datagen_sources = [join_paths(zstd_rootdir, 'tests/datagencli.c')]
+datagen_sources = [join_paths(zstd_rootdir, 'tests/datagencli.c'),
+ join_paths(zstd_rootdir, 'tests/loremOut.c')]
datagen = executable('datagen',
datagen_sources,
c_args: [ '-DNDEBUG' ],
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/meson/tests/valgrindTest.py b/deps/libchdr/deps/zstd-1.5.6/build/meson/tests/valgrindTest.py
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/meson/tests/valgrindTest.py
rename to deps/libchdr/deps/zstd-1.5.6/build/meson/tests/valgrindTest.py
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/single_file_libs/.gitignore b/deps/libchdr/deps/zstd-1.5.6/build/single_file_libs/.gitignore
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/single_file_libs/.gitignore
rename to deps/libchdr/deps/zstd-1.5.6/build/single_file_libs/.gitignore
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/single_file_libs/README.md b/deps/libchdr/deps/zstd-1.5.6/build/single_file_libs/README.md
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/single_file_libs/README.md
rename to deps/libchdr/deps/zstd-1.5.6/build/single_file_libs/README.md
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/single_file_libs/build_decoder_test.sh b/deps/libchdr/deps/zstd-1.5.6/build/single_file_libs/build_decoder_test.sh
old mode 100755
new mode 100644
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/single_file_libs/build_decoder_test.sh
rename to deps/libchdr/deps/zstd-1.5.6/build/single_file_libs/build_decoder_test.sh
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/single_file_libs/build_library_test.sh b/deps/libchdr/deps/zstd-1.5.6/build/single_file_libs/build_library_test.sh
old mode 100755
new mode 100644
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/single_file_libs/build_library_test.sh
rename to deps/libchdr/deps/zstd-1.5.6/build/single_file_libs/build_library_test.sh
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/single_file_libs/combine.py b/deps/libchdr/deps/zstd-1.5.6/build/single_file_libs/combine.py
old mode 100755
new mode 100644
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/single_file_libs/combine.py
rename to deps/libchdr/deps/zstd-1.5.6/build/single_file_libs/combine.py
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/single_file_libs/combine.sh b/deps/libchdr/deps/zstd-1.5.6/build/single_file_libs/combine.sh
old mode 100755
new mode 100644
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/single_file_libs/combine.sh
rename to deps/libchdr/deps/zstd-1.5.6/build/single_file_libs/combine.sh
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/single_file_libs/create_single_file_decoder.sh b/deps/libchdr/deps/zstd-1.5.6/build/single_file_libs/create_single_file_decoder.sh
old mode 100755
new mode 100644
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/single_file_libs/create_single_file_decoder.sh
rename to deps/libchdr/deps/zstd-1.5.6/build/single_file_libs/create_single_file_decoder.sh
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/single_file_libs/create_single_file_library.sh b/deps/libchdr/deps/zstd-1.5.6/build/single_file_libs/create_single_file_library.sh
old mode 100755
new mode 100644
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/single_file_libs/create_single_file_library.sh
rename to deps/libchdr/deps/zstd-1.5.6/build/single_file_libs/create_single_file_library.sh
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/single_file_libs/examples/README.md b/deps/libchdr/deps/zstd-1.5.6/build/single_file_libs/examples/README.md
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/single_file_libs/examples/README.md
rename to deps/libchdr/deps/zstd-1.5.6/build/single_file_libs/examples/README.md
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/single_file_libs/examples/emscripten.c b/deps/libchdr/deps/zstd-1.5.6/build/single_file_libs/examples/emscripten.c
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/single_file_libs/examples/emscripten.c
rename to deps/libchdr/deps/zstd-1.5.6/build/single_file_libs/examples/emscripten.c
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/single_file_libs/examples/roundtrip.c b/deps/libchdr/deps/zstd-1.5.6/build/single_file_libs/examples/roundtrip.c
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/single_file_libs/examples/roundtrip.c
rename to deps/libchdr/deps/zstd-1.5.6/build/single_file_libs/examples/roundtrip.c
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/single_file_libs/examples/shell.html b/deps/libchdr/deps/zstd-1.5.6/build/single_file_libs/examples/shell.html
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/single_file_libs/examples/shell.html
rename to deps/libchdr/deps/zstd-1.5.6/build/single_file_libs/examples/shell.html
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/single_file_libs/examples/simple.c b/deps/libchdr/deps/zstd-1.5.6/build/single_file_libs/examples/simple.c
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/single_file_libs/examples/simple.c
rename to deps/libchdr/deps/zstd-1.5.6/build/single_file_libs/examples/simple.c
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/single_file_libs/examples/testcard-dxt1.inl b/deps/libchdr/deps/zstd-1.5.6/build/single_file_libs/examples/testcard-dxt1.inl
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/single_file_libs/examples/testcard-dxt1.inl
rename to deps/libchdr/deps/zstd-1.5.6/build/single_file_libs/examples/testcard-dxt1.inl
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/single_file_libs/examples/testcard-zstd.inl b/deps/libchdr/deps/zstd-1.5.6/build/single_file_libs/examples/testcard-zstd.inl
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/single_file_libs/examples/testcard-zstd.inl
rename to deps/libchdr/deps/zstd-1.5.6/build/single_file_libs/examples/testcard-zstd.inl
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/single_file_libs/examples/testcard.png b/deps/libchdr/deps/zstd-1.5.6/build/single_file_libs/examples/testcard.png
old mode 100755
new mode 100644
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/single_file_libs/examples/testcard.png
rename to deps/libchdr/deps/zstd-1.5.6/build/single_file_libs/examples/testcard.png
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/single_file_libs/zstd-in.c b/deps/libchdr/deps/zstd-1.5.6/build/single_file_libs/zstd-in.c
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/single_file_libs/zstd-in.c
rename to deps/libchdr/deps/zstd-1.5.6/build/single_file_libs/zstd-in.c
diff --git a/deps/libchdr/deps/zstd-1.5.5/build/single_file_libs/zstddeclib-in.c b/deps/libchdr/deps/zstd-1.5.6/build/single_file_libs/zstddeclib-in.c
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/build/single_file_libs/zstddeclib-in.c
rename to deps/libchdr/deps/zstd-1.5.6/build/single_file_libs/zstddeclib-in.c
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/VS2005/README.md b/deps/libchdr/deps/zstd-1.5.6/contrib/VS2005/README.md
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/VS2005/README.md
rename to deps/libchdr/deps/zstd-1.5.6/contrib/VS2005/README.md
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/VS2005/fullbench/fullbench.vcproj b/deps/libchdr/deps/zstd-1.5.6/contrib/VS2005/fullbench/fullbench.vcproj
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/VS2005/fullbench/fullbench.vcproj
rename to deps/libchdr/deps/zstd-1.5.6/contrib/VS2005/fullbench/fullbench.vcproj
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/VS2005/fuzzer/fuzzer.vcproj b/deps/libchdr/deps/zstd-1.5.6/contrib/VS2005/fuzzer/fuzzer.vcproj
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/VS2005/fuzzer/fuzzer.vcproj
rename to deps/libchdr/deps/zstd-1.5.6/contrib/VS2005/fuzzer/fuzzer.vcproj
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/VS2005/zstd.sln b/deps/libchdr/deps/zstd-1.5.6/contrib/VS2005/zstd.sln
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/VS2005/zstd.sln
rename to deps/libchdr/deps/zstd-1.5.6/contrib/VS2005/zstd.sln
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/VS2005/zstd/zstd.vcproj b/deps/libchdr/deps/zstd-1.5.6/contrib/VS2005/zstd/zstd.vcproj
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/VS2005/zstd/zstd.vcproj
rename to deps/libchdr/deps/zstd-1.5.6/contrib/VS2005/zstd/zstd.vcproj
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/VS2005/zstdlib/zstdlib.vcproj b/deps/libchdr/deps/zstd-1.5.6/contrib/VS2005/zstdlib/zstdlib.vcproj
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/VS2005/zstdlib/zstdlib.vcproj
rename to deps/libchdr/deps/zstd-1.5.6/contrib/VS2005/zstdlib/zstdlib.vcproj
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/cleanTabs b/deps/libchdr/deps/zstd-1.5.6/contrib/cleanTabs
old mode 100755
new mode 100644
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/cleanTabs
rename to deps/libchdr/deps/zstd-1.5.6/contrib/cleanTabs
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/diagnose_corruption/.gitignore b/deps/libchdr/deps/zstd-1.5.6/contrib/diagnose_corruption/.gitignore
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/diagnose_corruption/.gitignore
rename to deps/libchdr/deps/zstd-1.5.6/contrib/diagnose_corruption/.gitignore
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/diagnose_corruption/Makefile b/deps/libchdr/deps/zstd-1.5.6/contrib/diagnose_corruption/Makefile
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/diagnose_corruption/Makefile
rename to deps/libchdr/deps/zstd-1.5.6/contrib/diagnose_corruption/Makefile
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/diagnose_corruption/check_flipped_bits.c b/deps/libchdr/deps/zstd-1.5.6/contrib/diagnose_corruption/check_flipped_bits.c
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/diagnose_corruption/check_flipped_bits.c
rename to deps/libchdr/deps/zstd-1.5.6/contrib/diagnose_corruption/check_flipped_bits.c
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/docker/Dockerfile b/deps/libchdr/deps/zstd-1.5.6/contrib/docker/Dockerfile
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/docker/Dockerfile
rename to deps/libchdr/deps/zstd-1.5.6/contrib/docker/Dockerfile
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/docker/README.md b/deps/libchdr/deps/zstd-1.5.6/contrib/docker/README.md
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/docker/README.md
rename to deps/libchdr/deps/zstd-1.5.6/contrib/docker/README.md
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/externalSequenceProducer/.gitignore b/deps/libchdr/deps/zstd-1.5.6/contrib/externalSequenceProducer/.gitignore
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/externalSequenceProducer/.gitignore
rename to deps/libchdr/deps/zstd-1.5.6/contrib/externalSequenceProducer/.gitignore
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/externalSequenceProducer/Makefile b/deps/libchdr/deps/zstd-1.5.6/contrib/externalSequenceProducer/Makefile
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/externalSequenceProducer/Makefile
rename to deps/libchdr/deps/zstd-1.5.6/contrib/externalSequenceProducer/Makefile
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/externalSequenceProducer/README.md b/deps/libchdr/deps/zstd-1.5.6/contrib/externalSequenceProducer/README.md
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/externalSequenceProducer/README.md
rename to deps/libchdr/deps/zstd-1.5.6/contrib/externalSequenceProducer/README.md
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/externalSequenceProducer/main.c b/deps/libchdr/deps/zstd-1.5.6/contrib/externalSequenceProducer/main.c
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/externalSequenceProducer/main.c
rename to deps/libchdr/deps/zstd-1.5.6/contrib/externalSequenceProducer/main.c
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/externalSequenceProducer/sequence_producer.c b/deps/libchdr/deps/zstd-1.5.6/contrib/externalSequenceProducer/sequence_producer.c
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/externalSequenceProducer/sequence_producer.c
rename to deps/libchdr/deps/zstd-1.5.6/contrib/externalSequenceProducer/sequence_producer.c
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/externalSequenceProducer/sequence_producer.h b/deps/libchdr/deps/zstd-1.5.6/contrib/externalSequenceProducer/sequence_producer.h
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/externalSequenceProducer/sequence_producer.h
rename to deps/libchdr/deps/zstd-1.5.6/contrib/externalSequenceProducer/sequence_producer.h
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/freestanding_lib/freestanding.py b/deps/libchdr/deps/zstd-1.5.6/contrib/freestanding_lib/freestanding.py
old mode 100755
new mode 100644
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/freestanding_lib/freestanding.py
rename to deps/libchdr/deps/zstd-1.5.6/contrib/freestanding_lib/freestanding.py
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/gen_html/.gitignore b/deps/libchdr/deps/zstd-1.5.6/contrib/gen_html/.gitignore
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/gen_html/.gitignore
rename to deps/libchdr/deps/zstd-1.5.6/contrib/gen_html/.gitignore
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/gen_html/Makefile b/deps/libchdr/deps/zstd-1.5.6/contrib/gen_html/Makefile
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/gen_html/Makefile
rename to deps/libchdr/deps/zstd-1.5.6/contrib/gen_html/Makefile
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/gen_html/README.md b/deps/libchdr/deps/zstd-1.5.6/contrib/gen_html/README.md
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/gen_html/README.md
rename to deps/libchdr/deps/zstd-1.5.6/contrib/gen_html/README.md
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/gen_html/gen-zstd-manual.sh b/deps/libchdr/deps/zstd-1.5.6/contrib/gen_html/gen-zstd-manual.sh
old mode 100755
new mode 100644
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/gen_html/gen-zstd-manual.sh
rename to deps/libchdr/deps/zstd-1.5.6/contrib/gen_html/gen-zstd-manual.sh
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/gen_html/gen_html.cpp b/deps/libchdr/deps/zstd-1.5.6/contrib/gen_html/gen_html.cpp
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/gen_html/gen_html.cpp
rename to deps/libchdr/deps/zstd-1.5.6/contrib/gen_html/gen_html.cpp
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/largeNbDicts/.gitignore b/deps/libchdr/deps/zstd-1.5.6/contrib/largeNbDicts/.gitignore
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/largeNbDicts/.gitignore
rename to deps/libchdr/deps/zstd-1.5.6/contrib/largeNbDicts/.gitignore
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/largeNbDicts/Makefile b/deps/libchdr/deps/zstd-1.5.6/contrib/largeNbDicts/Makefile
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/largeNbDicts/Makefile
rename to deps/libchdr/deps/zstd-1.5.6/contrib/largeNbDicts/Makefile
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/largeNbDicts/README.md b/deps/libchdr/deps/zstd-1.5.6/contrib/largeNbDicts/README.md
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/largeNbDicts/README.md
rename to deps/libchdr/deps/zstd-1.5.6/contrib/largeNbDicts/README.md
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/largeNbDicts/largeNbDicts.c b/deps/libchdr/deps/zstd-1.5.6/contrib/largeNbDicts/largeNbDicts.c
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/largeNbDicts/largeNbDicts.c
rename to deps/libchdr/deps/zstd-1.5.6/contrib/largeNbDicts/largeNbDicts.c
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/.gitignore b/deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/.gitignore
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/.gitignore
rename to deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/.gitignore
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/Makefile b/deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/Makefile
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/Makefile
rename to deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/Makefile
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/README.md b/deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/README.md
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/README.md
rename to deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/README.md
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/btrfs-benchmark.sh b/deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/btrfs-benchmark.sh
old mode 100755
new mode 100644
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/btrfs-benchmark.sh
rename to deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/btrfs-benchmark.sh
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/btrfs-extract-benchmark.sh b/deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/btrfs-extract-benchmark.sh
old mode 100755
new mode 100644
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/btrfs-extract-benchmark.sh
rename to deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/btrfs-extract-benchmark.sh
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/decompress_sources.h b/deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/decompress_sources.h
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/decompress_sources.h
rename to deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/decompress_sources.h
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/linux.mk b/deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/linux.mk
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/linux.mk
rename to deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/linux.mk
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/linux_zstd.h b/deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/linux_zstd.h
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/linux_zstd.h
rename to deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/linux_zstd.h
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/mem.h b/deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/mem.h
similarity index 98%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/mem.h
rename to deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/mem.h
index a7231822..2e91e778 100644
--- a/deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/mem.h
+++ b/deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/mem.h
@@ -24,6 +24,7 @@
/*-****************************************
* Compiler specifics
******************************************/
+#undef MEM_STATIC /* may be already defined from common/compiler.h */
#define MEM_STATIC static inline
/*-**************************************************************
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/squashfs-benchmark.sh b/deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/squashfs-benchmark.sh
old mode 100755
new mode 100644
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/squashfs-benchmark.sh
rename to deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/squashfs-benchmark.sh
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/test/Makefile b/deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/test/Makefile
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/test/Makefile
rename to deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/test/Makefile
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/test/include/asm/unaligned.h b/deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/test/include/asm/unaligned.h
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/test/include/asm/unaligned.h
rename to deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/test/include/asm/unaligned.h
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/test/include/linux/compiler.h b/deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/test/include/linux/compiler.h
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/test/include/linux/compiler.h
rename to deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/test/include/linux/compiler.h
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/test/include/linux/errno.h b/deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/test/include/linux/errno.h
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/test/include/linux/errno.h
rename to deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/test/include/linux/errno.h
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/test/include/linux/kernel.h b/deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/test/include/linux/kernel.h
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/test/include/linux/kernel.h
rename to deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/test/include/linux/kernel.h
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/test/include/linux/limits.h b/deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/test/include/linux/limits.h
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/test/include/linux/limits.h
rename to deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/test/include/linux/limits.h
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/test/include/linux/math64.h b/deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/test/include/linux/math64.h
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/test/include/linux/math64.h
rename to deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/test/include/linux/math64.h
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/test/include/linux/module.h b/deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/test/include/linux/module.h
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/test/include/linux/module.h
rename to deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/test/include/linux/module.h
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/test/include/linux/printk.h b/deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/test/include/linux/printk.h
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/test/include/linux/printk.h
rename to deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/test/include/linux/printk.h
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/test/include/linux/stddef.h b/deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/test/include/linux/stddef.h
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/test/include/linux/stddef.h
rename to deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/test/include/linux/stddef.h
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/test/include/linux/swab.h b/deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/test/include/linux/swab.h
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/test/include/linux/swab.h
rename to deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/test/include/linux/swab.h
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/test/include/linux/types.h b/deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/test/include/linux/types.h
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/test/include/linux/types.h
rename to deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/test/include/linux/types.h
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/test/include/linux/xxhash.h b/deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/test/include/linux/xxhash.h
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/test/include/linux/xxhash.h
rename to deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/test/include/linux/xxhash.h
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/test/macro-test.sh b/deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/test/macro-test.sh
old mode 100755
new mode 100644
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/test/macro-test.sh
rename to deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/test/macro-test.sh
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/test/static_test.c b/deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/test/static_test.c
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/test/static_test.c
rename to deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/test/static_test.c
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/test/test.c b/deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/test/test.c
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/test/test.c
rename to deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/test/test.c
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/zstd_common_module.c b/deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/zstd_common_module.c
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/zstd_common_module.c
rename to deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/zstd_common_module.c
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/zstd_compress_module.c b/deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/zstd_compress_module.c
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/zstd_compress_module.c
rename to deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/zstd_compress_module.c
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/zstd_decompress_module.c b/deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/zstd_decompress_module.c
similarity index 97%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/zstd_decompress_module.c
rename to deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/zstd_decompress_module.c
index eb1c49e6..7d31518e 100644
--- a/deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/zstd_decompress_module.c
+++ b/deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/zstd_decompress_module.c
@@ -77,7 +77,7 @@ EXPORT_SYMBOL(zstd_init_dstream);
size_t zstd_reset_dstream(zstd_dstream *dstream)
{
- return ZSTD_resetDStream(dstream);
+ return ZSTD_DCtx_reset(dstream, ZSTD_reset_session_only);
}
EXPORT_SYMBOL(zstd_reset_dstream);
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/zstd_deps.h b/deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/zstd_deps.h
similarity index 95%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/zstd_deps.h
rename to deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/zstd_deps.h
index 670c5fa2..f931f7d0 100644
--- a/deps/libchdr/deps/zstd-1.5.5/contrib/linux-kernel/zstd_deps.h
+++ b/deps/libchdr/deps/zstd-1.5.6/contrib/linux-kernel/zstd_deps.h
@@ -115,11 +115,7 @@ static uint64_t ZSTD_div64(uint64_t dividend, uint32_t divisor) {
#ifndef ZSTD_DEPS_STDINT
#define ZSTD_DEPS_STDINT
-/*
- * The Linux Kernel doesn't provide intptr_t, only uintptr_t, which
- * is an unsigned long.
- */
-typedef long intptr_t;
+/* intptr_t already provided by ZSTD_DEPS_COMMON */
#endif /* ZSTD_DEPS_STDINT */
#endif /* ZSTD_DEPS_NEED_STDINT */
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/match_finders/README.md b/deps/libchdr/deps/zstd-1.5.6/contrib/match_finders/README.md
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/match_finders/README.md
rename to deps/libchdr/deps/zstd-1.5.6/contrib/match_finders/README.md
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/match_finders/zstd_edist.c b/deps/libchdr/deps/zstd-1.5.6/contrib/match_finders/zstd_edist.c
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/match_finders/zstd_edist.c
rename to deps/libchdr/deps/zstd-1.5.6/contrib/match_finders/zstd_edist.c
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/match_finders/zstd_edist.h b/deps/libchdr/deps/zstd-1.5.6/contrib/match_finders/zstd_edist.h
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/match_finders/zstd_edist.h
rename to deps/libchdr/deps/zstd-1.5.6/contrib/match_finders/zstd_edist.h
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/premake/premake4.lua b/deps/libchdr/deps/zstd-1.5.6/contrib/premake/premake4.lua
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/premake/premake4.lua
rename to deps/libchdr/deps/zstd-1.5.6/contrib/premake/premake4.lua
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/premake/zstd.lua b/deps/libchdr/deps/zstd-1.5.6/contrib/premake/zstd.lua
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/premake/zstd.lua
rename to deps/libchdr/deps/zstd-1.5.6/contrib/premake/zstd.lua
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/.gitignore b/deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/.gitignore
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/.gitignore
rename to deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/.gitignore
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/BUCK b/deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/BUCK
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/BUCK
rename to deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/BUCK
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/ErrorHolder.h b/deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/ErrorHolder.h
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/ErrorHolder.h
rename to deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/ErrorHolder.h
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/Logging.h b/deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/Logging.h
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/Logging.h
rename to deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/Logging.h
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/Makefile b/deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/Makefile
similarity index 94%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/Makefile
rename to deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/Makefile
index e62f8e87..e4b3e8a2 100644
--- a/deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/Makefile
+++ b/deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/Makefile
@@ -10,7 +10,7 @@
# Standard variables for installation
DESTDIR ?=
PREFIX ?= /usr/local
-BINDIR := $(DESTDIR)$(PREFIX)/bin
+BINDIR := $(PREFIX)/bin
ZSTDDIR = ../../lib
PROGDIR = ../../programs
@@ -37,11 +37,8 @@ CFLAGS += -Wno-deprecated-declarations
PZSTD_INC = -I$(ZSTDDIR) -I$(ZSTDDIR)/common -I$(PROGDIR) -I.
GTEST_INC = -isystem googletest/googletest/include
-# If default C++ version is older than C++11, explicitly set C++11, which is the
-# minimum required by the code.
-ifeq ($(shell echo "\043if __cplusplus < 201103L\n\043error\n\043endif" | $(CXX) -x c++ -Werror -c - -o /dev/null 2>/dev/null && echo 1 || echo 0),0)
-PZSTD_CXX_STD := -std=c++11
-endif
+# Set the minimum required by gtest
+PZSTD_CXX_STD := -std=c++14
PZSTD_CPPFLAGS = $(PZSTD_INC)
PZSTD_CCXXFLAGS =
@@ -112,12 +109,12 @@ check:
.PHONY: install
install: PZSTD_CPPFLAGS += -DNDEBUG
install: pzstd$(EXT)
- install -d -m 755 $(BINDIR)/
- install -m 755 pzstd$(EXT) $(BINDIR)/pzstd$(EXT)
+ install -d -m 755 $(DESTDIR)$(BINDIR)/
+ install -m 755 pzstd$(EXT) $(DESTDIR)$(BINDIR)/pzstd$(EXT)
.PHONY: uninstall
uninstall:
- $(RM) $(BINDIR)/pzstd$(EXT)
+ $(RM) $(DESTDIR)$(BINDIR)/pzstd$(EXT)
# Targets for many different builds
.PHONY: all
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/Options.cpp b/deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/Options.cpp
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/Options.cpp
rename to deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/Options.cpp
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/Options.h b/deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/Options.h
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/Options.h
rename to deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/Options.h
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/Pzstd.cpp b/deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/Pzstd.cpp
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/Pzstd.cpp
rename to deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/Pzstd.cpp
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/Pzstd.h b/deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/Pzstd.h
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/Pzstd.h
rename to deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/Pzstd.h
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/README.md b/deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/README.md
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/README.md
rename to deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/README.md
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/SkippableFrame.cpp b/deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/SkippableFrame.cpp
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/SkippableFrame.cpp
rename to deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/SkippableFrame.cpp
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/SkippableFrame.h b/deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/SkippableFrame.h
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/SkippableFrame.h
rename to deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/SkippableFrame.h
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/images/Cspeed.png b/deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/images/Cspeed.png
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/images/Cspeed.png
rename to deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/images/Cspeed.png
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/images/Dspeed.png b/deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/images/Dspeed.png
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/images/Dspeed.png
rename to deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/images/Dspeed.png
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/main.cpp b/deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/main.cpp
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/main.cpp
rename to deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/main.cpp
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/test/BUCK b/deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/test/BUCK
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/test/BUCK
rename to deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/test/BUCK
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/test/OptionsTest.cpp b/deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/test/OptionsTest.cpp
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/test/OptionsTest.cpp
rename to deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/test/OptionsTest.cpp
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/test/PzstdTest.cpp b/deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/test/PzstdTest.cpp
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/test/PzstdTest.cpp
rename to deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/test/PzstdTest.cpp
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/test/RoundTrip.h b/deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/test/RoundTrip.h
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/test/RoundTrip.h
rename to deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/test/RoundTrip.h
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/test/RoundTripTest.cpp b/deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/test/RoundTripTest.cpp
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/test/RoundTripTest.cpp
rename to deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/test/RoundTripTest.cpp
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/utils/BUCK b/deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/utils/BUCK
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/utils/BUCK
rename to deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/utils/BUCK
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/utils/Buffer.h b/deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/utils/Buffer.h
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/utils/Buffer.h
rename to deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/utils/Buffer.h
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/utils/FileSystem.h b/deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/utils/FileSystem.h
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/utils/FileSystem.h
rename to deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/utils/FileSystem.h
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/utils/Likely.h b/deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/utils/Likely.h
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/utils/Likely.h
rename to deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/utils/Likely.h
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/utils/Portability.h b/deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/utils/Portability.h
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/utils/Portability.h
rename to deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/utils/Portability.h
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/utils/Range.h b/deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/utils/Range.h
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/utils/Range.h
rename to deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/utils/Range.h
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/utils/ResourcePool.h b/deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/utils/ResourcePool.h
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/utils/ResourcePool.h
rename to deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/utils/ResourcePool.h
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/utils/ScopeGuard.h b/deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/utils/ScopeGuard.h
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/utils/ScopeGuard.h
rename to deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/utils/ScopeGuard.h
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/utils/ThreadPool.h b/deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/utils/ThreadPool.h
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/utils/ThreadPool.h
rename to deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/utils/ThreadPool.h
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/utils/WorkQueue.h b/deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/utils/WorkQueue.h
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/utils/WorkQueue.h
rename to deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/utils/WorkQueue.h
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/utils/test/BUCK b/deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/utils/test/BUCK
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/utils/test/BUCK
rename to deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/utils/test/BUCK
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/utils/test/BufferTest.cpp b/deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/utils/test/BufferTest.cpp
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/utils/test/BufferTest.cpp
rename to deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/utils/test/BufferTest.cpp
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/utils/test/RangeTest.cpp b/deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/utils/test/RangeTest.cpp
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/utils/test/RangeTest.cpp
rename to deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/utils/test/RangeTest.cpp
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/utils/test/ResourcePoolTest.cpp b/deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/utils/test/ResourcePoolTest.cpp
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/utils/test/ResourcePoolTest.cpp
rename to deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/utils/test/ResourcePoolTest.cpp
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/utils/test/ScopeGuardTest.cpp b/deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/utils/test/ScopeGuardTest.cpp
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/utils/test/ScopeGuardTest.cpp
rename to deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/utils/test/ScopeGuardTest.cpp
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/utils/test/ThreadPoolTest.cpp b/deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/utils/test/ThreadPoolTest.cpp
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/utils/test/ThreadPoolTest.cpp
rename to deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/utils/test/ThreadPoolTest.cpp
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/utils/test/WorkQueueTest.cpp b/deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/utils/test/WorkQueueTest.cpp
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/pzstd/utils/test/WorkQueueTest.cpp
rename to deps/libchdr/deps/zstd-1.5.6/contrib/pzstd/utils/test/WorkQueueTest.cpp
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/recovery/Makefile b/deps/libchdr/deps/zstd-1.5.6/contrib/recovery/Makefile
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/recovery/Makefile
rename to deps/libchdr/deps/zstd-1.5.6/contrib/recovery/Makefile
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/recovery/recover_directory.c b/deps/libchdr/deps/zstd-1.5.6/contrib/recovery/recover_directory.c
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/recovery/recover_directory.c
rename to deps/libchdr/deps/zstd-1.5.6/contrib/recovery/recover_directory.c
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/seekable_format/README.md b/deps/libchdr/deps/zstd-1.5.6/contrib/seekable_format/README.md
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/seekable_format/README.md
rename to deps/libchdr/deps/zstd-1.5.6/contrib/seekable_format/README.md
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/seekable_format/examples/.gitignore b/deps/libchdr/deps/zstd-1.5.6/contrib/seekable_format/examples/.gitignore
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/seekable_format/examples/.gitignore
rename to deps/libchdr/deps/zstd-1.5.6/contrib/seekable_format/examples/.gitignore
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/seekable_format/examples/Makefile b/deps/libchdr/deps/zstd-1.5.6/contrib/seekable_format/examples/Makefile
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/seekable_format/examples/Makefile
rename to deps/libchdr/deps/zstd-1.5.6/contrib/seekable_format/examples/Makefile
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/seekable_format/examples/parallel_compression.c b/deps/libchdr/deps/zstd-1.5.6/contrib/seekable_format/examples/parallel_compression.c
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/seekable_format/examples/parallel_compression.c
rename to deps/libchdr/deps/zstd-1.5.6/contrib/seekable_format/examples/parallel_compression.c
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/seekable_format/examples/parallel_processing.c b/deps/libchdr/deps/zstd-1.5.6/contrib/seekable_format/examples/parallel_processing.c
similarity index 99%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/seekable_format/examples/parallel_processing.c
rename to deps/libchdr/deps/zstd-1.5.6/contrib/seekable_format/examples/parallel_processing.c
index 356561e5..92837102 100644
--- a/deps/libchdr/deps/zstd-1.5.5/contrib/seekable_format/examples/parallel_processing.c
+++ b/deps/libchdr/deps/zstd-1.5.6/contrib/seekable_format/examples/parallel_processing.c
@@ -19,7 +19,7 @@
#define ZSTD_STATIC_LINKING_ONLY
#include // presumes zstd library is installed
#include
-#if defined(WIN32) || defined(_WIN32)
+#if defined(_WIN32)
# include
# define SLEEP(x) Sleep(x)
#else
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/seekable_format/examples/seekable_compression.c b/deps/libchdr/deps/zstd-1.5.6/contrib/seekable_format/examples/seekable_compression.c
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/seekable_format/examples/seekable_compression.c
rename to deps/libchdr/deps/zstd-1.5.6/contrib/seekable_format/examples/seekable_compression.c
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/seekable_format/examples/seekable_decompression.c b/deps/libchdr/deps/zstd-1.5.6/contrib/seekable_format/examples/seekable_decompression.c
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/seekable_format/examples/seekable_decompression.c
rename to deps/libchdr/deps/zstd-1.5.6/contrib/seekable_format/examples/seekable_decompression.c
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/seekable_format/examples/seekable_decompression_mem.c b/deps/libchdr/deps/zstd-1.5.6/contrib/seekable_format/examples/seekable_decompression_mem.c
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/seekable_format/examples/seekable_decompression_mem.c
rename to deps/libchdr/deps/zstd-1.5.6/contrib/seekable_format/examples/seekable_decompression_mem.c
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/seekable_format/tests/.gitignore b/deps/libchdr/deps/zstd-1.5.6/contrib/seekable_format/tests/.gitignore
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/seekable_format/tests/.gitignore
rename to deps/libchdr/deps/zstd-1.5.6/contrib/seekable_format/tests/.gitignore
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/seekable_format/tests/Makefile b/deps/libchdr/deps/zstd-1.5.6/contrib/seekable_format/tests/Makefile
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/seekable_format/tests/Makefile
rename to deps/libchdr/deps/zstd-1.5.6/contrib/seekable_format/tests/Makefile
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/seekable_format/tests/seekable_tests.c b/deps/libchdr/deps/zstd-1.5.6/contrib/seekable_format/tests/seekable_tests.c
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/seekable_format/tests/seekable_tests.c
rename to deps/libchdr/deps/zstd-1.5.6/contrib/seekable_format/tests/seekable_tests.c
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/seekable_format/zstd_seekable.h b/deps/libchdr/deps/zstd-1.5.6/contrib/seekable_format/zstd_seekable.h
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/seekable_format/zstd_seekable.h
rename to deps/libchdr/deps/zstd-1.5.6/contrib/seekable_format/zstd_seekable.h
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/seekable_format/zstd_seekable_compression_format.md b/deps/libchdr/deps/zstd-1.5.6/contrib/seekable_format/zstd_seekable_compression_format.md
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/seekable_format/zstd_seekable_compression_format.md
rename to deps/libchdr/deps/zstd-1.5.6/contrib/seekable_format/zstd_seekable_compression_format.md
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/seekable_format/zstdseek_compress.c b/deps/libchdr/deps/zstd-1.5.6/contrib/seekable_format/zstdseek_compress.c
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/seekable_format/zstdseek_compress.c
rename to deps/libchdr/deps/zstd-1.5.6/contrib/seekable_format/zstdseek_compress.c
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/seekable_format/zstdseek_decompress.c b/deps/libchdr/deps/zstd-1.5.6/contrib/seekable_format/zstdseek_decompress.c
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/seekable_format/zstdseek_decompress.c
rename to deps/libchdr/deps/zstd-1.5.6/contrib/seekable_format/zstdseek_decompress.c
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/seqBench/Makefile b/deps/libchdr/deps/zstd-1.5.6/contrib/seqBench/Makefile
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/seqBench/Makefile
rename to deps/libchdr/deps/zstd-1.5.6/contrib/seqBench/Makefile
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/seqBench/seqBench.c b/deps/libchdr/deps/zstd-1.5.6/contrib/seqBench/seqBench.c
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/seqBench/seqBench.c
rename to deps/libchdr/deps/zstd-1.5.6/contrib/seqBench/seqBench.c
diff --git a/deps/libchdr/deps/zstd-1.5.5/contrib/snap/snapcraft.yaml b/deps/libchdr/deps/zstd-1.5.6/contrib/snap/snapcraft.yaml
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/contrib/snap/snapcraft.yaml
rename to deps/libchdr/deps/zstd-1.5.6/contrib/snap/snapcraft.yaml
diff --git a/deps/libchdr/deps/zstd-1.5.5/doc/README.md b/deps/libchdr/deps/zstd-1.5.6/doc/README.md
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/doc/README.md
rename to deps/libchdr/deps/zstd-1.5.6/doc/README.md
diff --git a/deps/libchdr/deps/zstd-1.5.5/doc/decompressor_errata.md b/deps/libchdr/deps/zstd-1.5.6/doc/decompressor_errata.md
similarity index 57%
rename from deps/libchdr/deps/zstd-1.5.5/doc/decompressor_errata.md
rename to deps/libchdr/deps/zstd-1.5.6/doc/decompressor_errata.md
index b162e7fd..b570f731 100644
--- a/deps/libchdr/deps/zstd-1.5.5/doc/decompressor_errata.md
+++ b/deps/libchdr/deps/zstd-1.5.6/doc/decompressor_errata.md
@@ -6,12 +6,53 @@ Each entry will contain:
1. The last affected decompressor versions.
2. The decompressor components affected.
2. Whether the compressed frame could ever be produced by the reference compressor.
-3. An example frame.
+3. An example frame (hexadecimal string when it can be short enough, link to golden file otherwise)
4. A description of the bug.
The document is in reverse chronological order, with the bugs that affect the most recent zstd decompressor versions listed first.
+No sequence using the 2-bytes format
+------------------------------------------------
+
+**Last affected version**: v1.5.5
+
+**Affected decompressor component(s)**: Library & CLI
+
+**Produced by the reference compressor**: No
+
+**Example Frame**: see zstd/tests/golden-decompression/zeroSeq_2B.zst
+
+The zstd decoder incorrectly expects FSE tables when there are 0 sequences present in the block
+if the value 0 is encoded using the 2-bytes format.
+Instead, it should immediately end the sequence section, and move on to next block.
+
+This situation was never generated by the reference compressor,
+because representing 0 sequences with the 2-bytes format is inefficient
+(the 1-byte format is always used in this case).
+
+
+Compressed block with a size of exactly 128 KB
+------------------------------------------------
+
+**Last affected version**: v1.5.2
+
+**Affected decompressor component(s)**: Library & CLI
+
+**Produced by the reference compressor**: No
+
+**Example Frame**: see zstd/tests/golden-decompression/block-128k.zst
+
+The zstd decoder incorrectly rejected blocks of type `Compressed_Block` when their size was exactly 128 KB.
+Note that `128 KB - 1` was accepted, and `128 KB + 1` is forbidden by the spec.
+
+This type of block was never generated by the reference compressor.
+
+These blocks used to be disallowed by the spec up until spec version 0.3.2 when the restriction was lifted by [PR#1689](https://github.com/facebook/zstd/pull/1689).
+
+> A Compressed_Block has the extra restriction that Block_Size is always strictly less than the decompressed size. If this condition cannot be respected, the block must be sent uncompressed instead (Raw_Block).
+
+
Compressed block with 0 literals and 0 sequences
------------------------------------------------
@@ -31,6 +72,7 @@ Additionally, these blocks were disallowed by the spec up until spec version 0.3
> A Compressed_Block has the extra restriction that Block_Size is always strictly less than the decompressed size. If this condition cannot be respected, the block must be sent uncompressed instead (Raw_Block).
+
First block is RLE block
------------------------
@@ -52,6 +94,7 @@ block.
https://github.com/facebook/zstd/blob/8814aa5bfa74f05a86e55e9d508da177a893ceeb/lib/compress/zstd_compress.c#L3527-L3535
+
Tiny FSE Table & Block
----------------------
@@ -82,3 +125,24 @@ The total `Block_Content` is `5` bytes, and `Last_Table_Offset` is `2`.
See the compressor workaround code:
https://github.com/facebook/zstd/blob/8814aa5bfa74f05a86e55e9d508da177a893ceeb/lib/compress/zstd_compress.c#L2667-L2682
+
+Magicless format
+----------------------
+
+**Last affected version**: v1.5.5
+
+**Affected decompressor component(s)**: Library
+
+**Produced by the reference compressor**: Yes (example: https://gist.github.com/embg/9940726094f4cf2cef162cffe9319232)
+
+**Example Frame**: `27 b5 2f fd 00 03 19 00 00 66 6f 6f 3f ba c4 59`
+
+v1.5.6 fixes several bugs in which the magicless-format decoder rejects valid frames.
+These include but are not limited to:
+* Valid frames that happen to begin with a legacy magic number (little-endian)
+* Valid frames that happen to begin with a skippable magic number (little-endian)
+
+If you are affected by this issue and cannot update to v1.5.6 or later, there is a
+workaround to recover affected data. Simply prepend the ZSTD magic number
+`0xFD2FB528` (little-endian) to your data and decompress using the standard-format
+decoder.
diff --git a/deps/libchdr/deps/zstd-1.5.6/doc/decompressor_permissive.md b/deps/libchdr/deps/zstd-1.5.6/doc/decompressor_permissive.md
new file mode 100644
index 00000000..bd77165f
--- /dev/null
+++ b/deps/libchdr/deps/zstd-1.5.6/doc/decompressor_permissive.md
@@ -0,0 +1,60 @@
+Decompressor Permissiveness to Invalid Data
+===========================================
+
+This document describes the behavior of the reference decompressor in cases
+where it accepts formally invalid data instead of reporting an error.
+
+While the reference decompressor *must* decode any compliant frame following
+the specification, its ability to detect erroneous data is on a best effort
+basis: the decoder may accept input data that would be formally invalid,
+when it causes no risk to the decoder, and which detection would cost too much
+complexity or speed regression.
+
+In practice, the vast majority of invalid data are detected, if only because
+many corruption events are dangerous for the decoder process (such as
+requesting an out-of-bound memory access) and many more are easy to check.
+
+This document lists a few known cases where invalid data was formerly accepted
+by the decoder, and what has changed since.
+
+
+Offset == 0
+-----------
+
+**Last affected version**: v1.5.5
+
+**Produced by the reference compressor**: No
+
+**Example Frame**: `28b5 2ffd 0000 4500 0008 0002 002f 430b ae`
+
+If a sequence is decoded with `literals_length = 0` and `offset_value = 3`
+while `Repeated_Offset_1 = 1`, the computed offset will be `0`, which is
+invalid.
+
+The reference decompressor up to v1.5.5 processes this case as if the computed
+offset was `1`, including inserting `1` into the repeated offset list.
+This prevents the output buffer from remaining uninitialized, thus denying a
+potential attack vector from an untrusted source.
+However, in the rare case where this scenario would be the outcome of a
+transmission or storage error, the decoder relies on the checksum to detect
+the error.
+
+In newer versions, this case is always detected and reported as a corruption error.
+
+
+Non-zeroes reserved bits
+------------------------
+
+**Last affected version**: v1.5.5
+
+**Produced by the reference compressor**: No
+
+The Sequences section of each block has a header, and one of its elements is a
+byte, which describes the compression mode of each symbol.
+This byte contains 2 reserved bits which must be set to zero.
+
+The reference decompressor up to v1.5.5 just ignores these 2 bits.
+This behavior has no consequence for the rest of the frame decoding process.
+
+In newer versions, the 2 reserved bits are actively checked for value zero,
+and the decoder reports a corruption error if they are not.
diff --git a/deps/libchdr/deps/zstd-1.5.5/doc/educational_decoder/.gitignore b/deps/libchdr/deps/zstd-1.5.6/doc/educational_decoder/.gitignore
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/doc/educational_decoder/.gitignore
rename to deps/libchdr/deps/zstd-1.5.6/doc/educational_decoder/.gitignore
diff --git a/deps/libchdr/deps/zstd-1.5.5/doc/educational_decoder/Makefile b/deps/libchdr/deps/zstd-1.5.6/doc/educational_decoder/Makefile
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/doc/educational_decoder/Makefile
rename to deps/libchdr/deps/zstd-1.5.6/doc/educational_decoder/Makefile
diff --git a/deps/libchdr/deps/zstd-1.5.5/doc/educational_decoder/README.md b/deps/libchdr/deps/zstd-1.5.6/doc/educational_decoder/README.md
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/doc/educational_decoder/README.md
rename to deps/libchdr/deps/zstd-1.5.6/doc/educational_decoder/README.md
diff --git a/deps/libchdr/deps/zstd-1.5.5/doc/educational_decoder/harness.c b/deps/libchdr/deps/zstd-1.5.6/doc/educational_decoder/harness.c
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/doc/educational_decoder/harness.c
rename to deps/libchdr/deps/zstd-1.5.6/doc/educational_decoder/harness.c
diff --git a/deps/libchdr/deps/zstd-1.5.5/doc/educational_decoder/zstd_decompress.c b/deps/libchdr/deps/zstd-1.5.6/doc/educational_decoder/zstd_decompress.c
similarity index 99%
rename from deps/libchdr/deps/zstd-1.5.5/doc/educational_decoder/zstd_decompress.c
rename to deps/libchdr/deps/zstd-1.5.6/doc/educational_decoder/zstd_decompress.c
index 9ade7650..839e085b 100644
--- a/deps/libchdr/deps/zstd-1.5.5/doc/educational_decoder/zstd_decompress.c
+++ b/deps/libchdr/deps/zstd-1.5.6/doc/educational_decoder/zstd_decompress.c
@@ -997,7 +997,8 @@ static void decompress_sequences(frame_context_t *const ctx,
const size_t num_sequences);
static sequence_command_t decode_sequence(sequence_states_t *const state,
const u8 *const src,
- i64 *const offset);
+ i64 *const offset,
+ int lastSequence);
static void decode_seq_table(FSE_dtable *const table, istream_t *const in,
const seq_part_t type, const seq_mode_t mode);
@@ -1017,12 +1018,7 @@ static size_t decode_sequences(frame_context_t *const ctx, istream_t *in,
// This is a variable size field using between 1 and 3 bytes. Let's call its
// first byte byte0."
u8 header = IO_read_bits(in, 8);
- if (header == 0) {
- // "There are no sequences. The sequence section stops there.
- // Regenerated content is defined entirely by literals section."
- *sequences = NULL;
- return 0;
- } else if (header < 128) {
+ if (header < 128) {
// "Number_of_Sequences = byte0 . Uses 1 byte."
num_sequences = header;
} else if (header < 255) {
@@ -1033,6 +1029,12 @@ static size_t decode_sequences(frame_context_t *const ctx, istream_t *in,
num_sequences = IO_read_bits(in, 16) + 0x7F00;
}
+ if (num_sequences == 0) {
+ // "There are no sequences. The sequence section stops there."
+ *sequences = NULL;
+ return 0;
+ }
+
*sequences = malloc(num_sequences * sizeof(sequence_command_t));
if (!*sequences) {
BAD_ALLOC();
@@ -1114,7 +1116,7 @@ static void decompress_sequences(frame_context_t *const ctx, istream_t *in,
for (size_t i = 0; i < num_sequences; i++) {
// Decode sequences one by one
- sequences[i] = decode_sequence(&states, src, &bit_offset);
+ sequences[i] = decode_sequence(&states, src, &bit_offset, i==num_sequences-1);
}
if (bit_offset != 0) {
@@ -1125,7 +1127,8 @@ static void decompress_sequences(frame_context_t *const ctx, istream_t *in,
// Decode a single sequence and update the state
static sequence_command_t decode_sequence(sequence_states_t *const states,
const u8 *const src,
- i64 *const offset) {
+ i64 *const offset,
+ int lastSequence) {
// "Each symbol is a code in its own context, which specifies Baseline and
// Number_of_Bits to add. Codes are FSE compressed, and interleaved with raw
// additional bits in the same bitstream."
@@ -1160,7 +1163,7 @@ static sequence_command_t decode_sequence(sequence_states_t *const states,
// Literals_Length_State is updated, followed by Match_Length_State, and
// then Offset_State."
// If the stream is complete don't read bits to update state
- if (*offset != 0) {
+ if (!lastSequence) {
FSE_update_state(&states->ll_table, &states->ll_state, src, offset);
FSE_update_state(&states->ml_table, &states->ml_state, src, offset);
FSE_update_state(&states->of_table, &states->of_state, src, offset);
@@ -1210,7 +1213,7 @@ static void decode_seq_table(FSE_dtable *const table, istream_t *const in,
break;
}
case seq_repeat:
- // "Repeat_Mode : re-use distribution table from previous compressed
+ // "Repeat_Mode : reuse distribution table from previous compressed
// block."
// Nothing to do here, table will be unchanged
if (!table->symbols) {
@@ -1399,7 +1402,7 @@ size_t ZSTD_get_decompressed_size(const void *src, const size_t src_len) {
/******* END OUTPUT SIZE COUNTING *********************************************/
/******* DICTIONARY PARSING ***************************************************/
-dictionary_t* create_dictionary() {
+dictionary_t* create_dictionary(void) {
dictionary_t* const dict = calloc(1, sizeof(dictionary_t));
if (!dict) {
BAD_ALLOC();
diff --git a/deps/libchdr/deps/zstd-1.5.5/doc/educational_decoder/zstd_decompress.h b/deps/libchdr/deps/zstd-1.5.6/doc/educational_decoder/zstd_decompress.h
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/doc/educational_decoder/zstd_decompress.h
rename to deps/libchdr/deps/zstd-1.5.6/doc/educational_decoder/zstd_decompress.h
diff --git a/deps/libchdr/deps/zstd-1.5.5/doc/images/CSpeed2.png b/deps/libchdr/deps/zstd-1.5.6/doc/images/CSpeed2.png
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/doc/images/CSpeed2.png
rename to deps/libchdr/deps/zstd-1.5.6/doc/images/CSpeed2.png
diff --git a/deps/libchdr/deps/zstd-1.5.5/doc/images/DCspeed5.png b/deps/libchdr/deps/zstd-1.5.6/doc/images/DCspeed5.png
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/doc/images/DCspeed5.png
rename to deps/libchdr/deps/zstd-1.5.6/doc/images/DCspeed5.png
diff --git a/deps/libchdr/deps/zstd-1.5.5/doc/images/DSpeed3.png b/deps/libchdr/deps/zstd-1.5.6/doc/images/DSpeed3.png
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/doc/images/DSpeed3.png
rename to deps/libchdr/deps/zstd-1.5.6/doc/images/DSpeed3.png
diff --git a/deps/libchdr/deps/zstd-1.5.5/doc/images/cdict_v136.png b/deps/libchdr/deps/zstd-1.5.6/doc/images/cdict_v136.png
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/doc/images/cdict_v136.png
rename to deps/libchdr/deps/zstd-1.5.6/doc/images/cdict_v136.png
diff --git a/deps/libchdr/deps/zstd-1.5.5/doc/images/dict-cr.png b/deps/libchdr/deps/zstd-1.5.6/doc/images/dict-cr.png
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/doc/images/dict-cr.png
rename to deps/libchdr/deps/zstd-1.5.6/doc/images/dict-cr.png
diff --git a/deps/libchdr/deps/zstd-1.5.5/doc/images/dict-cs.png b/deps/libchdr/deps/zstd-1.5.6/doc/images/dict-cs.png
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/doc/images/dict-cs.png
rename to deps/libchdr/deps/zstd-1.5.6/doc/images/dict-cs.png
diff --git a/deps/libchdr/deps/zstd-1.5.5/doc/images/dict-ds.png b/deps/libchdr/deps/zstd-1.5.6/doc/images/dict-ds.png
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/doc/images/dict-ds.png
rename to deps/libchdr/deps/zstd-1.5.6/doc/images/dict-ds.png
diff --git a/deps/libchdr/deps/zstd-1.5.5/doc/images/zstd_cdict_v1_3_5.png b/deps/libchdr/deps/zstd-1.5.6/doc/images/zstd_cdict_v1_3_5.png
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/doc/images/zstd_cdict_v1_3_5.png
rename to deps/libchdr/deps/zstd-1.5.6/doc/images/zstd_cdict_v1_3_5.png
diff --git a/deps/libchdr/deps/zstd-1.5.5/doc/images/zstd_logo86.png b/deps/libchdr/deps/zstd-1.5.6/doc/images/zstd_logo86.png
similarity index 100%
rename from deps/libchdr/deps/zstd-1.5.5/doc/images/zstd_logo86.png
rename to deps/libchdr/deps/zstd-1.5.6/doc/images/zstd_logo86.png
diff --git a/deps/libchdr/deps/zstd-1.5.5/doc/zstd_compression_format.md b/deps/libchdr/deps/zstd-1.5.6/doc/zstd_compression_format.md
similarity index 98%
rename from deps/libchdr/deps/zstd-1.5.5/doc/zstd_compression_format.md
rename to deps/libchdr/deps/zstd-1.5.6/doc/zstd_compression_format.md
index 3843bf39..7955dae4 100644
--- a/deps/libchdr/deps/zstd-1.5.5/doc/zstd_compression_format.md
+++ b/deps/libchdr/deps/zstd-1.5.6/doc/zstd_compression_format.md
@@ -16,7 +16,7 @@ Distribution of this document is unlimited.
### Version
-0.3.9 (2023-03-08)
+0.4.0 (2023-06-05)
Introduction
@@ -650,13 +650,15 @@ __`Number_of_Sequences`__
This is a variable size field using between 1 and 3 bytes.
Let's call its first byte `byte0`.
-- `if (byte0 == 0)` : there are no sequences.
- The sequence section stops there.
- Decompressed content is defined entirely as Literals Section content.
- The FSE tables used in `Repeat_Mode` aren't updated.
- `if (byte0 < 128)` : `Number_of_Sequences = byte0` . Uses 1 byte.
-- `if (byte0 < 255)` : `Number_of_Sequences = ((byte0-128) << 8) + byte1` . Uses 2 bytes.
-- `if (byte0 == 255)`: `Number_of_Sequences = byte1 + (byte2<<8) + 0x7F00` . Uses 3 bytes.
+- `if (byte0 < 255)` : `Number_of_Sequences = ((byte0 - 0x80) << 8) + byte1`. Uses 2 bytes.
+ Note that the 2 bytes format fully overlaps the 1 byte format.
+- `if (byte0 == 255)`: `Number_of_Sequences = byte1 + (byte2<<8) + 0x7F00`. Uses 3 bytes.
+
+`if (Number_of_Sequences == 0)` : there are no sequences.
+ The sequence section stops immediately,
+ FSE tables used in `Repeat_Mode` aren't updated.
+ Block's decompressed content is defined solely by the Literals Section content.
__Symbol compression modes__
@@ -927,7 +929,10 @@ There is an exception though, when current sequence's `literals_length = 0`.
In this case, repeated offsets are shifted by one,
so an `offset_value` of 1 means `Repeated_Offset2`,
an `offset_value` of 2 means `Repeated_Offset3`,
-and an `offset_value` of 3 means `Repeated_Offset1 - 1_byte`.
+and an `offset_value` of 3 means `Repeated_Offset1 - 1`.
+
+In the final case, if `Repeated_Offset1 - 1` evaluates to 0, then the
+data is considered corrupted.
For the first block, the starting offset history is populated with following values :
`Repeated_Offset1`=1, `Repeated_Offset2`=4, `Repeated_Offset3`=8,
@@ -1081,7 +1086,8 @@ It depends on :
Presuming an `Accuracy_Log` of 8,
and presuming 100 probabilities points have already been distributed,
the decoder may read any value from `0` to `256 - 100 + 1 == 157` (inclusive).
- Therefore, it must read `log2sup(157) == 8` bits.
+ Therefore, it may read up to `log2sup(157) == 8` bits, where `log2sup(N)`
+ is the smallest integer `T` that satisfies `(1 << T) > N`.
- Value decoded : small values use 1 less bit :
__example__ :
@@ -1121,6 +1127,9 @@ When last symbol reaches cumulated total of `1 << Accuracy_Log`,
decoding is complete.
If the last symbol makes cumulated total go above `1 << Accuracy_Log`,
distribution is considered corrupted.
+If this process results in a non-zero probability for a value outside of the
+valid range of values that the FSE table is defined for, even if that value is
+not used, then the data is considered corrupted.
Then the decoder can tell how many bytes were used in this process,
and how many symbols are present.
@@ -1184,9 +1193,9 @@ Baseline is assigned starting from the higher states using fewer bits,
increasing at each state, then resuming at the first state,
each state takes its allocated width from Baseline.
-| state value | 1 | 39 | 77 | 84 | 122 |
| state order | 0 | 1 | 2 | 3 | 4 |
| ---------------- | ----- | ----- | ------ | ---- | ------ |
+| state value | 1 | 39 | 77 | 84 | 122 |
| width | 32 | 32 | 32 | 16 | 16 |
| `Number_of_Bits` | 5 | 5 | 5 | 4 | 4 |
| range number | 2 | 4 | 6 | 0 | 1 |
@@ -1249,7 +1258,9 @@ Number_of_Bits = Weight ? (Max_Number_of_Bits + 1 - Weight) : 0
```
When a literal value is not present, it receives a `Weight` of 0.
The least frequent symbol receives a `Weight` of 1.
-Consequently, the `Weight` 1 is necessarily present.
+If no literal has a `Weight` of 1, then the data is considered corrupted.
+If there are not at least two literals with non-zero `Weight`, then the data
+is considered corrupted.
The most frequent symbol receives a `Weight` anywhere between 1 and 11 (max).
The last symbol's `Weight` is deduced from previously retrieved Weights,
by completing to the nearest power of 2. It's necessarily non 0.
@@ -1350,6 +1361,9 @@ If updating state after decoding a symbol would require more bits than
remain in the stream, it is assumed that extra bits are 0. Then,
symbols for each of the final states are decoded and the process is complete.
+If this process would produce more weights than the maximum number of decoded
+weights (255), then the data is considered corrupted.
+
#### Conversion from weights to Huffman prefix codes
All present symbols shall now have a `Weight` value.
@@ -1697,6 +1711,7 @@ or at least provide a meaningful error code explaining for which reason it canno
Version changes
---------------
+- 0.4.0 : fixed imprecise behavior for nbSeq==0, detected by Igor Pavlov
- 0.3.9 : clarifications for Huffman-compressed literal sizes.
- 0.3.8 : clarifications for Huffman Blocks and Huffman Tree descriptions.
- 0.3.7 : clarifications for Repeat_Offsets, matching RFC8878
diff --git a/deps/libchdr/deps/zstd-1.5.5/doc/zstd_manual.html b/deps/libchdr/deps/zstd-1.5.6/doc/zstd_manual.html
similarity index 95%
rename from deps/libchdr/deps/zstd-1.5.5/doc/zstd_manual.html
rename to deps/libchdr/deps/zstd-1.5.6/doc/zstd_manual.html
index dcc10208..bc4a2403 100644
--- a/deps/libchdr/deps/zstd-1.5.5/doc/zstd_manual.html
+++ b/deps/libchdr/deps/zstd-1.5.6/doc/zstd_manual.html
@@ -1,10 +1,10 @@
-zstd 1.5.5 Manual
+zstd 1.5.6 Manual
-
zstd 1.5.5 Manual
+
zstd 1.5.6 Manual
Contents
@@ -156,7 +156,7 @@ unsigned long long ZSTD_getDecompressedSize(const void* src, size_t srcSize);
* for example to size a static array on stack.
* Will produce constant value 0 if srcSize too large.
*/
-#define ZSTD_MAX_INPUT_SIZE ((sizeof(size_t)==8) ? 0xFF00FF00FF00FF00LLU : 0xFF00FF00U)
+#define ZSTD_MAX_INPUT_SIZE ((sizeof(size_t)==8) ? 0xFF00FF00FF00FF00ULL : 0xFF00FF00U)
#define ZSTD_COMPRESSBOUND(srcSize) (((size_t)(srcSize) >= ZSTD_MAX_INPUT_SIZE) ? 0 : (srcSize) + ((srcSize)>>8) + (((srcSize) < (128<<10)) ? (((128<<10) - (srcSize)) >> 11) /* margin, from 64 to 0 */ : 0)) /* this formula ensures that bound(A) + bound(B) <= bound(A+B) as long as A and B >= 128 KB */
size_t ZSTD_compressBound(size_t srcSize); /*!< maximum compressed size in worst case single-pass scenario *//* ZSTD_isError() :
@@ -174,7 +174,7 @@ int ZSTD_defaultCLevel(void); /*!< default compression lev
Compression context
When compressing many times,
it is recommended to allocate a context just once,
- and re-use it for each successive compression operation.
+ and reuse it for each successive compression operation.
This will make workload friendlier for system's memory.
Note : re-using context is just a speed / resource optimization.
It doesn't change the compression ratio, which remains identical.
@@ -190,9 +190,9 @@ size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx); /* accept NULL pointer */
const void* src, size_t srcSize,
int compressionLevel);
Same as ZSTD_compress(), using an explicit ZSTD_CCtx.
- Important : in order to behave similarly to `ZSTD_compress()`,
- this function compresses at requested compression level,
- __ignoring any other parameter__ .
+ Important : in order to mirror `ZSTD_compress()` behavior,
+ this function compresses at the requested compression level,
+ __ignoring any other advanced parameter__ .
If any advanced parameter was set using the advanced API,
they will all be reset. Only `compressionLevel` remains.
@@ -200,7 +200,7 @@ size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx); /* accept NULL pointer */
Decompression context
When decompressing many times,
it is recommended to allocate a context only once,
- and re-use it for each successive compression operation.
+ and reuse it for each successive compression operation.
This will make workload friendlier for system's memory.
Use one context per thread for parallel execution.
Same as ZSTD_decompress(),
requires an allocated ZSTD_DCtx.
- Compatible with sticky parameters.
+ Compatible with sticky parameters (see below).
@@ -296,6 +296,19 @@ size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx); /* accept NULL pointer */
* The higher the value of selected strategy, the more complex it is,
* resulting in stronger and slower compression.
* Special: value 0 means "use default strategy". */
+
+ ZSTD_c_targetCBlockSize=130, /* v1.5.6+
+ * Attempts to fit compressed block size into approximatively targetCBlockSize.
+ * Bound by ZSTD_TARGETCBLOCKSIZE_MIN and ZSTD_TARGETCBLOCKSIZE_MAX.
+ * Note that it's not a guarantee, just a convergence target (default:0).
+ * No target when targetCBlockSize == 0.
+ * This is helpful in low bandwidth streaming environments to improve end-to-end latency,
+ * when a client can make use of partial documents (a prominent example being Chrome).
+ * Note: this parameter is stable since v1.5.6.
+ * It was present as an experimental parameter in earlier versions,
+ * but it's not recommended using it with earlier library versions
+ * due to massive performance regressions.
+ */
/* LDM mode parameters */
ZSTD_c_enableLongDistanceMatching=160, /* Enable long distance matching.
* This parameter is designed to improve compression ratio
@@ -375,7 +388,6 @@ size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx); /* accept NULL pointer */
* ZSTD_c_forceMaxWindow
* ZSTD_c_forceAttachDict
* ZSTD_c_literalCompressionMode
- * ZSTD_c_targetCBlockSize
* ZSTD_c_srcSizeHint
* ZSTD_c_enableDedicatedDictSearch
* ZSTD_c_stableInBuffer
@@ -396,7 +408,7 @@ size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx); /* accept NULL pointer */
ZSTD_c_experimentalParam3=1000,
ZSTD_c_experimentalParam4=1001,
ZSTD_c_experimentalParam5=1002,
- ZSTD_c_experimentalParam6=1003,
+ /* was ZSTD_c_experimentalParam6=1003; is now ZSTD_c_targetCBlockSize */
ZSTD_c_experimentalParam7=1004,
ZSTD_c_experimentalParam8=1005,
ZSTD_c_experimentalParam9=1006,
@@ -483,6 +495,7 @@ size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx); /* accept NULL pointer */
void* dst, size_t dstCapacity,
const void* src, size_t srcSize);
Behave the same as ZSTD_compressCCtx(), but compression parameters are set using the advanced API.
+ (note that this entry point doesn't even expose a compression level parameter).
ZSTD_compress2() always starts a new frame.
Should cctx hold data from a previously unfinished frame, everything about it is forgotten.
- Compression parameters are pushed into CCtx before starting compression, using ZSTD_CCtx_set*()
@@ -513,6 +526,7 @@ size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx); /* accept NULL pointer */
* ZSTD_d_forceIgnoreChecksum
* ZSTD_d_refMultipleDDicts
* ZSTD_d_disableHuffmanAssembly
+ * ZSTD_d_maxBlockSize
* Because they are not stable, it's necessary to define ZSTD_STATIC_LINKING_ONLY to access them.
* note : never ever use experimentalParam? names directly
*/
@@ -520,7 +534,8 @@ size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx); /* accept NULL pointer */
ZSTD_d_experimentalParam2=1001,
ZSTD_d_experimentalParam3=1002,
ZSTD_d_experimentalParam4=1003,
- ZSTD_d_experimentalParam5=1004
+ ZSTD_d_experimentalParam5=1004,
+ ZSTD_d_experimentalParam6=1005
} ZSTD_dParameter;
@@ -568,14 +583,14 @@ size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx); /* accept NULL pointer */
A ZSTD_CStream object is required to track streaming operation.
Use ZSTD_createCStream() and ZSTD_freeCStream() to create/release resources.
ZSTD_CStream objects can be reused multiple times on consecutive compression operations.
- It is recommended to re-use ZSTD_CStream since it will play nicer with system's memory, by re-using already allocated memory.
+ It is recommended to reuse ZSTD_CStream since it will play nicer with system's memory, by re-using already allocated memory.
For parallel execution, use one separate ZSTD_CStream per thread.
note : since v1.3.0, ZSTD_CStream and ZSTD_CCtx are the same thing.
Parameters are sticky : when starting a new compression on the same context,
- it will re-use the same sticky parameters as previous compression session.
+ it will reuse the same sticky parameters as previous compression session.
When in doubt, it's recommended to fully initialize the context before usage.
Use ZSTD_CCtx_reset() to reset the context and ZSTD_CCtx_setParameter(),
ZSTD_CCtx_setPledgedSrcSize(), or ZSTD_CCtx_loadDictionary() and friends to
@@ -666,6 +681,11 @@ size_t ZSTD_freeCStream(ZSTD_CStream* zcs); /* accept NULL pointer */
only ZSTD_e_end or ZSTD_e_flush operations are allowed.
Before starting a new compression job, or changing compression parameters,
it is required to fully flush internal buffers.
+ - note: if an operation ends with an error, it may leave @cctx in an undefined state.
+ Therefore, it's UB to invoke ZSTD_compressStream2() of ZSTD_compressStream() on such a state.
+ In order to be re-employed after an error, a state must be reset,
+ which can be done explicitly (ZSTD_CCtx_reset()),
+ or is sometimes implied by methods starting a new compression job (ZSTD_initCStream(), ZSTD_compressCCtx())
A ZSTD_DStream object is required to track streaming operations.
Use ZSTD_createDStream() and ZSTD_freeDStream() to create/release resources.
- ZSTD_DStream objects can be re-used multiple times.
+ ZSTD_DStream objects can be reused multiple times.
Use ZSTD_initDStream() to start a new decompression operation.
@return : recommended first input size
@@ -751,6 +771,12 @@ size_t ZSTD_freeDStream(ZSTD_DStream* zds); /* accept NULL pointer */
@return : 0 when a frame is completely decoded and fully flushed,
or an error code, which can be tested using ZSTD_isError(),
or any other value > 0, which means there is some decoding or flushing to do to complete current frame.
+
+ Note: when an operation returns with an error code, the @zds state may be left in undefined state.
+ It's UB to invoke `ZSTD_decompressStream()` on such a state.
+ In order to re-use such a state, it must be first reset,
+ which can be done explicitly (`ZSTD_DCtx_reset()`),
+ or is implied for operations starting some new decompression job (`ZSTD_initDStream`, `ZSTD_decompressDCtx()`, `ZSTD_decompress_usingDict()`)
Advanced dictionary and prefix API (Requires v1.4.0+)
This API allows dictionaries to be used with ZSTD_compress2(),
ZSTD_compressStream2(), and ZSTD_decompressDCtx().
- Dictionaries are sticky, they remain valid when same context is re-used,
+ Dictionaries are sticky, they remain valid when same context is reused,
they only reset when the context is reset
with ZSTD_reset_parameters or ZSTD_reset_session_and_parameters.
In contrast, Prefixes are single-use.
@@ -1386,58 +1412,61 @@ ZSTD_compressSequences( ZSTD_CCtx* cctx, void* dst, size_t dstSize,
These functions make it possible to estimate memory usage
of a future {D,C}Ctx, before its creation.
+ This is useful in combination with ZSTD_initStatic(),
+ which makes it possible to employ a static buffer for ZSTD_CCtx* state.
ZSTD_estimateCCtxSize() will provide a memory budget large enough
- for any compression level up to selected one.
- Note : Unlike ZSTD_estimateCStreamSize*(), this estimate
- does not include space for a window buffer.
- Therefore, the estimation is only guaranteed for single-shot compressions, not streaming.
+ to compress data of any size using one-shot compression ZSTD_compressCCtx() or ZSTD_compress2()
+ associated with any compression level up to max specified one.
The estimate will assume the input may be arbitrarily large,
which is the worst case.
+ Note that the size estimation is specific for one-shot compression,
+ it is not valid for streaming (see ZSTD_estimateCStreamSize*())
+ nor other potential ways of using a ZSTD_CCtx* state.
+
When srcSize can be bound by a known and rather "small" value,
- this fact can be used to provide a tighter estimation
- because the CCtx compression context will need less memory.
- This tighter estimation can be provided by more advanced functions
+ this knowledge can be used to provide a tighter budget estimation
+ because the ZSTD_CCtx* state will need less memory for small inputs.
+ This tighter estimation can be provided by employing more advanced functions
ZSTD_estimateCCtxSize_usingCParams(), which can be used in tandem with ZSTD_getCParams(),
and ZSTD_estimateCCtxSize_usingCCtxParams(), which can be used in tandem with ZSTD_CCtxParams_setParameter().
Both can be used to estimate memory using custom compression parameters and arbitrary srcSize limits.
Note : only single-threaded compression is supported.
ZSTD_estimateCCtxSize_usingCCtxParams() will return an error code if ZSTD_c_nbWorkers is >= 1.
-
- Note 2 : ZSTD_estimateCCtxSize* functions are not compatible with the Block-Level Sequence Producer API at this time.
- Size estimates assume that no external sequence producer is registered.
ZSTD_estimateCStreamSize() will provide a budget large enough for any compression level up to selected one.
- It will also consider src size to be arbitrarily "large", which is worst case.
+
ZSTD_estimateCStreamSize() will provide a memory budget large enough for streaming compression
+ using any compression level up to the max specified one.
+ It will also consider src size to be arbitrarily "large", which is a worst case scenario.
If srcSize is known to always be small, ZSTD_estimateCStreamSize_usingCParams() can provide a tighter estimation.
ZSTD_estimateCStreamSize_usingCParams() can be used in tandem with ZSTD_getCParams() to create cParams from compressionLevel.
ZSTD_estimateCStreamSize_usingCCtxParams() can be used in tandem with ZSTD_CCtxParams_setParameter(). Only single-threaded compression is supported. This function will return an error code if ZSTD_c_nbWorkers is >= 1.
Note : CStream size estimation is only correct for single-threaded compression.
- ZSTD_DStream memory budget depends on window Size.
+ ZSTD_estimateCStreamSize_usingCCtxParams() will return an error code if ZSTD_c_nbWorkers is >= 1.
+ Note 2 : ZSTD_estimateCStreamSize* functions are not compatible with the Block-Level Sequence Producer API at this time.
+ Size estimates assume that no external sequence producer is registered.
+
+ ZSTD_DStream memory budget depends on frame's window Size.
This information can be passed manually, using ZSTD_estimateDStreamSize,
or deducted from a valid frame Header, using ZSTD_estimateDStreamSize_fromFrame();
+ Any frame requesting a window size larger than max specified one will be rejected.
Note : if streaming is init with function ZSTD_init?Stream_usingDict(),
an internal ?Dict will be created, which additional size is not estimated here.
In this case, get total size by adding ZSTD_estimate?DictSize
- Note 2 : only single-threaded compression is supported.
- ZSTD_estimateCStreamSize_usingCCtxParams() will return an error code if ZSTD_c_nbWorkers is >= 1.
- Note 3 : ZSTD_estimateCStreamSize* functions are not compatible with the Block-Level Sequence Producer API at this time.
- Size estimates assume that no external sequence producer is registered.
@@ -1857,7 +1886,7 @@ size_t ZSTD_resetCStream(ZSTD_CStream* zcs, unsigned long long pledgedSrcSize);
explicitly specified.
start a new frame, using same parameters from previous frame.
- This is typically useful to skip dictionary loading stage, since it will re-use it in-place.
+ This is typically useful to skip dictionary loading stage, since it will reuse it in-place.
Note that zcs must be init at least once before using ZSTD_resetCStream().
If pledgedSrcSize is not known at reset time, use macro ZSTD_CONTENTSIZE_UNKNOWN.
If pledgedSrcSize > 0, its value must be correct, as it will be written in header, and controlled at the end.
@@ -1918,7 +1947,7 @@ ZSTDLIB_STATIC_API size_t ZSTD_resetDStream(ZSTD_DStream* zds);
Same as ZSTD_registerSequenceProducer(), but operates on ZSTD_CCtx_params.
+ This is used for accurate size estimation with ZSTD_estimateCCtxSize_usingCCtxParams(),
+ which is needed when creating a ZSTD_CCtx with ZSTD_initStaticCCtx().
+
+ If you are using the external sequence producer API in a scenario where ZSTD_initStaticCCtx()
+ is required, then this function is for you. Otherwise, you probably don't need it.
+
+ See tests/zstreamtest.c for example usage.
+
+
Buffer-less and synchronous inner streaming functions (DEPRECATED)
This API is deprecated, and will be removed in a future version.
It allows streaming (de)compression with user allocated buffers.
@@ -1964,7 +2009,7 @@ ZSTD_registerSequenceProducer(
A ZSTD_CCtx object is required to track streaming operations.
Use ZSTD_createCCtx() / ZSTD_freeCCtx() to manage resource.
- ZSTD_CCtx object can be re-used multiple times within successive compression operations.
+ ZSTD_CCtx object can be reused multiple times within successive compression operations.
Start by initializing a context.
Use ZSTD_compressBegin(), or ZSTD_compressBegin_usingDict() for dictionary compression.
@@ -1985,7 +2030,7 @@ ZSTD_registerSequenceProducer(
It's possible to use srcSize==0, in which case, it will write a final empty block to end the frame.
Without last block mark, frames are considered unfinished (hence corrupted) by compliant decoders.
- `ZSTD_CCtx` object can be re-used (ZSTD_compressBegin()) to compress again.
+ `ZSTD_CCtx` object can be reused (ZSTD_compressBegin()) to compress again.
Buffer-less streaming compression functions
ZSTD_DEPRECATED("The buffer-less API is deprecated in favor of the normal streaming API. See docs.")
@@ -2002,7 +2047,7 @@ ZSTDLIB_STATIC_API size_t ZSTD_compressBegin_usingCDict(ZSTD_CCtx* cctx, const Z