Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Unified Diff: third_party/lzma_sdk/Bcj2.c

Issue 10152012: Second attempt to update lzma_sdk to 9.20 (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/lzma_sdk/Bcj2.h ('k') | third_party/lzma_sdk/Bra.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/lzma_sdk/Bcj2.c
diff --git a/third_party/lzma_sdk/Compress/Branch/BranchX86_2.c b/third_party/lzma_sdk/Bcj2.c
similarity index 53%
rename from third_party/lzma_sdk/Compress/Branch/BranchX86_2.c
rename to third_party/lzma_sdk/Bcj2.c
index 241789a551306f8a802b0b340d5a5ed963da171d..20199ce5659874f229c24674fbdd8b9d3a15fec2 100644
--- a/third_party/lzma_sdk/Compress/Branch/BranchX86_2.c
+++ b/third_party/lzma_sdk/Bcj2.c
@@ -1,8 +1,7 @@
-// BranchX86_2.c
+/* Bcj2.c -- Converter for x86 code (BCJ2)
+2008-10-04 : Igor Pavlov : Public domain */
-#include "BranchX86_2.h"
-
-#include "../../Alloc.h"
+#include "Bcj2.h"
#ifdef _LZMA_PROB32
#define CProb UInt32
@@ -20,50 +19,48 @@
#define kBitModelTotal (1 << kNumBitModelTotalBits)
#define kNumMoveBits 5
-#define RC_READ_BYTE (*Buffer++)
-
-#define RC_INIT2 Code = 0; Range = 0xFFFFFFFF; \
- { int i; for(i = 0; i < 5; i++) { RC_TEST; Code = (Code << 8) | RC_READ_BYTE; }}
+#define RC_READ_BYTE (*buffer++)
+#define RC_TEST { if (buffer == bufferLim) return SZ_ERROR_DATA; }
+#define RC_INIT2 code = 0; range = 0xFFFFFFFF; \
+ { int i; for (i = 0; i < 5; i++) { RC_TEST; code = (code << 8) | RC_READ_BYTE; }}
-#define RC_TEST { if (Buffer == BufferLim) return BCJ2_RESULT_DATA_ERROR; }
+#define NORMALIZE if (range < kTopValue) { RC_TEST; range <<= 8; code = (code << 8) | RC_READ_BYTE; }
-#define RC_INIT(buffer, bufferSize) Buffer = buffer; BufferLim = buffer + bufferSize; RC_INIT2
-
-#define RC_NORMALIZE if (Range < kTopValue) { RC_TEST; Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; }
+#define IF_BIT_0(p) ttt = *(p); bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)
+#define UPDATE_0(p) range = bound; *(p) = (CProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits)); NORMALIZE;
+#define UPDATE_1(p) range -= bound; code -= bound; *(p) = (CProb)(ttt - (ttt >> kNumMoveBits)); NORMALIZE;
-#define IfBit0(p) RC_NORMALIZE; bound = (Range >> kNumBitModelTotalBits) * *(p); if (Code < bound)
-#define UpdateBit0(p) Range = bound; *(p) += (kBitModelTotal - *(p)) >> kNumMoveBits;
-#define UpdateBit1(p) Range -= bound; Code -= bound; *(p) -= (*(p)) >> kNumMoveBits;
-// #define UpdateBit0(p) Range = bound; *(p) = (CProb)(*(p) + ((kBitModelTotal - *(p)) >> kNumMoveBits));
-// #define UpdateBit1(p) Range -= bound; Code -= bound; *(p) = (CProb)(*(p) - (*(p) >> kNumMoveBits));
-
-int x86_2_Decode(
- const Byte *buf0, SizeT size0,
- const Byte *buf1, SizeT size1,
- const Byte *buf2, SizeT size2,
- const Byte *buf3, SizeT size3,
+int Bcj2_Decode(
+ const Byte *buf0, SizeT size0,
+ const Byte *buf1, SizeT size1,
+ const Byte *buf2, SizeT size2,
+ const Byte *buf3, SizeT size3,
Byte *outBuf, SizeT outSize)
{
CProb p[256 + 2];
SizeT inPos = 0, outPos = 0;
- const Byte *Buffer, *BufferLim;
- UInt32 Range, Code;
+ const Byte *buffer, *bufferLim;
+ UInt32 range, code;
Byte prevByte = 0;
unsigned int i;
for (i = 0; i < sizeof(p) / sizeof(p[0]); i++)
- p[i] = kBitModelTotal >> 1;
- RC_INIT(buf3, size3);
+ p[i] = kBitModelTotal >> 1;
+
+ buffer = buf3;
+ bufferLim = buffer + size3;
+ RC_INIT2
if (outSize == 0)
- return BCJ2_RESULT_OK;
+ return SZ_OK;
for (;;)
{
Byte b;
CProb *prob;
UInt32 bound;
+ UInt32 ttt;
SizeT limit = size0 - inPos;
if (outSize - outPos < limit)
@@ -91,21 +88,21 @@ int x86_2_Decode(
else
prob = p + 257;
- IfBit0(prob)
+ IF_BIT_0(prob)
{
- UpdateBit0(prob)
+ UPDATE_0(prob)
prevByte = b;
}
else
{
UInt32 dest;
const Byte *v;
- UpdateBit1(prob)
+ UPDATE_1(prob)
if (b == 0xE8)
{
v = buf1;
if (size1 < 4)
- return BCJ2_RESULT_DATA_ERROR;
+ return SZ_ERROR_DATA;
buf1 += 4;
size1 -= 4;
}
@@ -113,11 +110,11 @@ int x86_2_Decode(
{
v = buf2;
if (size2 < 4)
- return BCJ2_RESULT_DATA_ERROR;
+ return SZ_ERROR_DATA;
buf2 += 4;
size2 -= 4;
}
- dest = (((UInt32)v[0] << 24) | ((UInt32)v[1] << 16) |
+ dest = (((UInt32)v[0] << 24) | ((UInt32)v[1] << 16) |
((UInt32)v[2] << 8) | ((UInt32)v[3])) - ((UInt32)outPos + 4);
outBuf[outPos++] = (Byte)dest;
if (outPos == outSize)
@@ -131,5 +128,5 @@ int x86_2_Decode(
outBuf[outPos++] = prevByte = (Byte)(dest >> 24);
}
}
- return (outPos == outSize) ? BCJ2_RESULT_OK : BCJ2_RESULT_DATA_ERROR;
+ return (outPos == outSize) ? SZ_OK : SZ_ERROR_DATA;
}
« no previous file with comments | « third_party/lzma_sdk/Bcj2.h ('k') | third_party/lzma_sdk/Bra.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698