Skip to content

Commit

Permalink
unarr: update code included from LZMA SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
zeniko committed May 11, 2015
1 parent 6d746df commit c4136ab
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 34 deletions.
4 changes: 2 additions & 2 deletions Makefile
Expand Up @@ -14,10 +14,10 @@ LIBS += -lm
ifeq "$(build)" "debug"
CFLAGS += -pipe -g -DDEBUG
else ifeq "$(build)" "profile"
CFLAGS += -pipe -O2 -DNDEBUG -pg
CFLAGS += -pipe -O3 -DNDEBUG -pg
LDFLAGS += -pg
else ifeq "$(build)" "release"
CFLAGS += -pipe -O2 -DNDEBUG -fomit-frame-pointer
CFLAGS += -pipe -O3 -DNDEBUG -fomit-frame-pointer
else ifeq "$(build)" "coverage"
CFLAGS += -pipe -g -DDEBUG -pg -fprofile-arcs -ftest-coverage
LIBS += -lgcov
Expand Down
2 changes: 1 addition & 1 deletion _7z/_7z.h
Expand Up @@ -6,7 +6,7 @@

#include "../common/unarr-imp.h"

#include "../lzmasdk/Types.h"
#include "../lzmasdk/7zTypes.h"
#ifdef HAVE_7Z
#include <7z.h>
#endif
Expand Down
14 changes: 8 additions & 6 deletions lzmasdk/Types.h → lzmasdk/7zTypes.h
@@ -1,15 +1,15 @@
/* Types.h -- Basic types
2010-10-09 : Igor Pavlov : Public domain */
/* 7zTypes.h -- Basic types
2013-11-12 : Igor Pavlov : Public domain */

#ifndef __7Z_TYPES_H
#define __7Z_TYPES_H

#include <stddef.h>

#ifdef _WIN32
#include <windows.h>
/* #include <windows.h> */
#endif

#include <stddef.h>

#ifndef EXTERN_C_BEGIN
#ifdef __cplusplus
#define EXTERN_C_BEGIN extern "C" {
Expand Down Expand Up @@ -43,7 +43,8 @@ EXTERN_C_BEGIN
typedef int SRes;

#ifdef _WIN32
typedef DWORD WRes;
/* typedef DWORD WRes; */
typedef unsigned WRes;
#else
typedef int WRes;
#endif
Expand Down Expand Up @@ -116,6 +117,7 @@ typedef int Bool;

#else

#define MY_NO_INLINE
#define MY_CDECL
#define MY_FAST_CALL

Expand Down
26 changes: 24 additions & 2 deletions lzmasdk/CpuArch.c
@@ -1,5 +1,7 @@
/* CpuArch.c -- CPU specific code
2010-10-26: Igor Pavlov : Public domain */
2012-05-29: Igor Pavlov : Public domain */

#include "Precomp.h"

#include "CpuArch.h"

Expand All @@ -9,6 +11,10 @@
#define USE_ASM
#endif

#if !defined(USE_ASM) && _MSC_VER >= 1500
#include <intrin.h>
#endif

#if defined(USE_ASM) && !defined(MY_CPU_AMD64)
static UInt32 CheckFlag(UInt32 flag)
{
Expand Down Expand Up @@ -73,9 +79,17 @@ static void MyCPUID(UInt32 function, UInt32 *a, UInt32 *b, UInt32 *c, UInt32 *d)
#else

__asm__ __volatile__ (
#if 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)) ;
Expand Down Expand Up @@ -135,14 +149,22 @@ Bool CPU_Is_InOrder()
firm = x86cpuid_GetFirm(&p);
switch (firm)
{
case CPU_FIRM_INTEL: return (family < 6 || (family == 6 && model == 0x100C));
case CPU_FIRM_INTEL: return (family < 6 || (family == 6 && (
/* Atom CPU */
model == 0x100C /* 45 nm, N4xx, D4xx, N5xx, D5xx, 230, 330 */
|| model == 0x2006 /* 45 nm, Z6xx */
|| model == 0x2007 /* 32 nm, Z2460 */
|| model == 0x3005 /* 32 nm, Z2760 */
|| model == 0x3006 /* 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 <windows.h>
static Bool CPU_Sys_Is_SSE_Supported()
{
OSVERSIONINFO vi;
Expand Down
14 changes: 8 additions & 6 deletions lzmasdk/CpuArch.h
@@ -1,10 +1,10 @@
/* CpuArch.h -- CPU specific code
2010-12-01: Igor Pavlov : Public domain */
2013-11-12: Igor Pavlov : Public domain */

#ifndef __CPU_ARCH_H
#define __CPU_ARCH_H

#include "Types.h"
#include "7zTypes.h"

EXTERN_C_BEGIN

Expand Down Expand Up @@ -62,9 +62,9 @@ Stop_Compiling_Bad_Endian

#ifdef MY_CPU_LE_UNALIGN

#define GetUi16(p) (*(const UInt16 *)(p))
#define GetUi32(p) (*(const UInt32 *)(p))
#define GetUi64(p) (*(const UInt64 *)(p))
#define GetUi16(p) (*(const UInt16 *)(const void *)(p))
#define GetUi32(p) (*(const UInt32 *)(const void *)(p))
#define GetUi64(p) (*(const UInt64 *)(const void *)(p))
#define SetUi16(p, d) *(UInt16 *)(p) = (d);
#define SetUi32(p, d) *(UInt32 *)(p) = (d);
#define SetUi64(p, d) *(UInt64 *)(p) = (d);
Expand Down Expand Up @@ -99,6 +99,8 @@ Stop_Compiling_Bad_Endian

#if defined(MY_CPU_LE_UNALIGN) && defined(_WIN64) && (_MSC_VER >= 1300)

#include <stdlib.h>

#pragma intrinsic(_byteswap_ulong)
#pragma intrinsic(_byteswap_uint64)
#define GetBe32(p) _byteswap_ulong(*(const UInt32 *)(const Byte *)(p))
Expand All @@ -116,7 +118,7 @@ Stop_Compiling_Bad_Endian

#endif

#define GetBe16(p) (((UInt16)((const Byte *)(p))[0] << 8) | ((const Byte *)(p))[1])
#define GetBe16(p) ((UInt16)(((UInt16)((const Byte *)(p))[0] << 8) | ((const Byte *)(p))[1]))


#ifdef MY_CPU_X86_OR_AMD64
Expand Down
46 changes: 39 additions & 7 deletions lzmasdk/LzmaDec.c
@@ -1,5 +1,7 @@
/* LzmaDec.c -- LZMA Decoder
2010-12-15 : Igor Pavlov : Public domain */
2015-01-01 : Igor Pavlov : Public domain */

#include "Precomp.h"

#include "LzmaDec.h"

Expand Down Expand Up @@ -44,6 +46,13 @@
i -= 0x40; }
#endif

#define NORMAL_LITER_DEC GET_BIT(prob + symbol, symbol)
#define MATCHED_LITER_DEC \
matchByte <<= 1; \
bit = (matchByte & offs); \
probLit = prob + offs + bit + symbol; \
GET_BIT2(probLit, symbol, offs &= ~bit, 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) * ttt; if (code < bound)
Expand Down Expand Up @@ -171,24 +180,47 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
{
state -= (state < 4) ? state : 3;
symbol = 1;
do { GET_BIT(prob + symbol, symbol) } while (symbol < 0x100);
#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 = p->dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];
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;
matchByte <<= 1;
bit = (matchByte & offs);
probLit = prob + offs + bit + symbol;
GET_BIT2(probLit, symbol, offs &= ~bit, offs &= bit)
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;
processedPos++;
Expand Down
12 changes: 4 additions & 8 deletions lzmasdk/LzmaDec.h
@@ -1,14 +1,12 @@
/* LzmaDec.h -- LZMA Decoder
2009-02-07 : Igor Pavlov : Public domain */
2013-01-18 : Igor Pavlov : Public domain */

#ifndef __LZMA_DEC_H
#define __LZMA_DEC_H

#include "Types.h"
#include "7zTypes.h"

#ifdef __cplusplus
extern "C" {
#endif
EXTERN_C_BEGIN

/* #define _LZMA_PROB32 */
/* _LZMA_PROB32 can increase the speed on some CPUs,
Expand Down Expand Up @@ -224,8 +222,6 @@ SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,
ELzmaStatus *status, ISzAlloc *alloc);

#ifdef __cplusplus
}
#endif
EXTERN_C_END

#endif
3 changes: 1 addition & 2 deletions lzmasdk/Ppmd.h
@@ -1,11 +1,10 @@
/* Ppmd.h -- PPMD codec common code
2011-01-27 : Igor Pavlov : Public domain
2013-01-18 : Igor Pavlov : Public domain
This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */

#ifndef __PPMD_H
#define __PPMD_H

#include "Types.h"
#include "CpuArch.h"

EXTERN_C_BEGIN
Expand Down
2 changes: 2 additions & 0 deletions lzmasdk/Ppmd7.c
Expand Up @@ -2,6 +2,8 @@
2010-03-12 : Igor Pavlov : Public domain
This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */

#include "Precomp.h"

#include <memory.h>

#include "Ppmd7.h"
Expand Down
2 changes: 2 additions & 0 deletions lzmasdk/Ppmd7Dec.c
Expand Up @@ -2,6 +2,8 @@
2010-03-12 : Igor Pavlov : Public domain
This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */

#include "Precomp.h"

#include "Ppmd7.h"

#define kTopValue (1 << 24)
Expand Down
13 changes: 13 additions & 0 deletions lzmasdk/Precomp.h
@@ -0,0 +1,13 @@
/* Precomp.h -- StdAfx
2013-11-12 : Igor Pavlov : Public domain */

#ifndef __7Z_PRECOMP_H
#define __7Z_PRECOMP_H

/* #include "Compiler.h" */
#ifdef _MSC_VER
#pragma warning(disable : 4996) // This function or variable may be unsafe
#endif
/* #include "7zTypes.h" */

#endif

0 comments on commit c4136ab

Please sign in to comment.