summaryrefslogtreecommitdiffstats
path: root/third_party/lzma_sdk/7zCrc.c
diff options
context:
space:
mode:
authorbashi@chromium.org <bashi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-22 23:01:02 +0000
committerbashi@chromium.org <bashi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-22 23:01:02 +0000
commitc2a4e52708caf2c92e8f783ffb79e7212ad3f853 (patch)
treebf761d0b82ad8c5a456240edf38fbb11623964ec /third_party/lzma_sdk/7zCrc.c
parent4a4e3477010dceec7df3313ec20c6d0915ef4fca (diff)
downloadchromium_src-c2a4e52708caf2c92e8f783ffb79e7212ad3f853.zip
chromium_src-c2a4e52708caf2c92e8f783ffb79e7212ad3f853.tar.gz
chromium_src-c2a4e52708caf2c92e8f783ffb79e7212ad3f853.tar.bz2
Second attempt to update lzma_sdk to 9.20
The first attempt (r132887) was reverted because the CL caused build failure on Linux. This is second attempt. Copied only C code required to open 7z archive files and uncompress LZMA compression. CpuArch.c was modified to fix an compile error on 32bit Linux. Updated chrome/installer/util/lzma_util.cc to follow API changes. BUG=None TEST=installer_util_unittests --gtest_filter='LzmaUtilTest.*' Review URL: http://codereview.chromium.org/10152012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133393 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party/lzma_sdk/7zCrc.c')
-rw-r--r--third_party/lzma_sdk/7zCrc.c74
1 files changed, 58 insertions, 16 deletions
diff --git a/third_party/lzma_sdk/7zCrc.c b/third_party/lzma_sdk/7zCrc.c
index 61050dd..a9208496 100644
--- a/third_party/lzma_sdk/7zCrc.c
+++ b/third_party/lzma_sdk/7zCrc.c
@@ -1,9 +1,50 @@
-/* 7zCrc.c */
+/* 7zCrc.c -- CRC32 calculation
+2009-11-23 : Igor Pavlov : Public domain */
#include "7zCrc.h"
+#include "CpuArch.h"
#define kCrcPoly 0xEDB88320
-UInt32 g_CrcTable[256];
+
+#ifdef MY_CPU_LE
+#define CRC_NUM_TABLES 8
+#else
+#define CRC_NUM_TABLES 1
+#endif
+
+typedef UInt32 (MY_FAST_CALL *CRC_FUNC)(UInt32 v, const void *data, size_t size, const UInt32 *table);
+
+static CRC_FUNC g_CrcUpdate;
+UInt32 g_CrcTable[256 * CRC_NUM_TABLES];
+
+#if CRC_NUM_TABLES == 1
+
+#define CRC_UPDATE_BYTE_2(crc, b) (table[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))
+
+static UInt32 MY_FAST_CALL CrcUpdateT1(UInt32 v, const void *data, size_t size, const UInt32 *table)
+{
+ const Byte *p = (const Byte *)data;
+ for (; size > 0; size--, p++)
+ v = CRC_UPDATE_BYTE_2(v, *p);
+ return v;
+}
+
+#else
+
+UInt32 MY_FAST_CALL CrcUpdateT4(UInt32 v, const void *data, size_t size, const UInt32 *table);
+UInt32 MY_FAST_CALL CrcUpdateT8(UInt32 v, const void *data, size_t size, const UInt32 *table);
+
+#endif
+
+UInt32 MY_FAST_CALL CrcUpdate(UInt32 v, const void *data, size_t size)
+{
+ return g_CrcUpdate(v, data, size, g_CrcTable);
+}
+
+UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size)
+{
+ return g_CrcUpdate(CRC_INIT_VAL, data, size, g_CrcTable) ^ CRC_INIT_VAL;
+}
void MY_FAST_CALL CrcGenerateTable()
{
@@ -11,22 +52,23 @@ void MY_FAST_CALL CrcGenerateTable()
for (i = 0; i < 256; i++)
{
UInt32 r = i;
- int j;
+ unsigned j;
for (j = 0; j < 8; j++)
r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));
g_CrcTable[i] = r;
}
-}
-
-UInt32 MY_FAST_CALL CrcUpdate(UInt32 v, const void *data, size_t size)
-{
- const Byte *p = (const Byte *)data;
- for (; size > 0 ; size--, p++)
- v = CRC_UPDATE_BYTE(v, *p);
- return v;
-}
-
-UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size)
-{
- return CrcUpdate(CRC_INIT_VAL, data, size) ^ 0xFFFFFFFF;
+ #if CRC_NUM_TABLES == 1
+ g_CrcUpdate = CrcUpdateT1;
+ #else
+ for (; i < 256 * CRC_NUM_TABLES; i++)
+ {
+ UInt32 r = g_CrcTable[i - 256];
+ g_CrcTable[i] = g_CrcTable[r & 0xFF] ^ (r >> 8);
+ }
+ g_CrcUpdate = CrcUpdateT4;
+ #ifdef MY_CPU_X86_OR_AMD64
+ if (!CPU_Is_InOrder())
+ g_CrcUpdate = CrcUpdateT8;
+ #endif
+ #endif
}