Subversion Repositories autosfx

Rev

Blame | Last modification | View Log | RSS feed

  1. #include "stdafx.h"
  2. #pragma hdrstop
  3. #if defined(_USE_ASM_) && (__BORLANDC__ < 0x0570)
  4. #pragma inline
  5. #endif
  6. #include "common.h"
  7. #include "dz_errs.h"
  8.  
  9. #undef _DZ_FILE_
  10. #define _DZ_FILE_ DZ_CRC32_CPP
  11. /* crc32.c -- compute the CRC-32 of a data stream
  12. * Copyright (C) 1995 Mark Adler
  13. * For conditions of distribution and use, see copyright notice in zlib.h
  14. * This version modified by Chris Vleghert for BCB/Delphi Zip.
  15.  ** distributed under LGPL license ** see license.txt for details
  16.  
  17.   Copyright (c) 1990-2007 Info-ZIP.  All rights reserved.
  18.  
  19.   See the accompanying file LICENSE, version 2007-Mar-4 or later
  20.   (the contents of which are also included in zip.h) for terms of use.
  21.   If, for some reason, all these files are missing, the Info-ZIP license
  22.   also may be found at:  ftp://ftp.info-zip.org/pub/infozip/license.html
  23.  
  24.   parts Copyright (C) 1997 Mike White, Eric W. Engler
  25. ************************************************************************
  26.  Copyright (C) 2009, 2010  by Russell J. Peters, Roger Aelbrecht
  27.  
  28.    This file is part of TZipMaster Version 1.9.
  29.  
  30.     TZipMaster is free software: you can redistribute it and/or modify
  31.     it under the terms of the GNU Lesser General Public License as published by
  32.     the Free Software Foundation, either version 3 of the License, or
  33.     (at your option) any later version.
  34.  
  35.     TZipMaster is distributed in the hope that it will be useful,
  36.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  37.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  38.     GNU Lesser General Public License for more details.
  39.  
  40.     You should have received a copy of the GNU Lesser General Public License
  41.     along with TZipMaster.  If not, see <http://www.gnu.org/licenses/>.
  42.  
  43.     contact: problems@delphizip.org (include ZipMaster in the subject).
  44.     updates: http://www.delphizip.org
  45.     DelphiZip maillist subscribe at http://www.freelists.org/list/delphizip
  46. ************************************************************************/
  47.  
  48. /* $Id: crc32.c,v 1.5 1996/01/13 14:55:12 spc Exp $ */
  49. /*$Id This is generic text from the file Header_Func.txt
  50. It is optionally included via the Source Format utility
  51. It can be as long and descriptive as desired.
  52.  */
  53. //It is optionally included via the Source Format utility
  54. //It can be as long and descriptive as desired.
  55. //
  56.  
  57. #ifndef _USE_ASM_
  58.  
  59. // Run a set of bytes through the crc shift register. If buf is a NULL
  60. //   pointer, then initialize the crc shift register contents instead. Return
  61. //   the current crc in either case. crc :: crc shift register. buf :: Pointer
  62. //   to bytes to pump through. len :: Number of bytes in buf[].
  63. ulg __fastcall crc32(ulg crc, const uch *buf, int len)
  64. {
  65.     if (buf == NULL)
  66.         return 0L;
  67.  
  68.     crc = crc ^ 0xFFFFFFFFL;
  69.     if (len)
  70.         do
  71.         {
  72.                         crc = crc_table[((int)(crc) ^ (*buf++)) & 0xFF] ^ ((crc) >> 8);
  73.         }
  74.         while (--len);
  75.  
  76.     return crc ^ 0xFFFFFFFFL; // (instead of ~c for 64-bit machines)
  77. }
  78.  
  79. #else
  80. // ; These two (three) macros make up the loop body of the CRC32 cruncher.
  81. // ; registers modified:
  82. // ; eax : crc value "c"
  83. // ; edx : pointer to next data byte (or dword) "buf++"
  84. // ; registers read:
  85. // ; esi : pointer to base of crc_table array
  86. // ; scratch registers:
  87. // ; ebx : index into crc_table array
  88. // Run a set of bytes through the crc shift register. If buf is a NULL
  89. //   pointer, then initialize the crc shift register contents instead. Return
  90. //   the current crc in either case. crc :: crc shift register. buf :: Pointer
  91. //   to bytes to pump through. len :: Number of bytes in buf[].
  92. ulg __fastcall crc32(ulg crc, const uch *buf, int len)
  93. {
  94. #pragma argsused
  95.     asm
  96.     {
  97.         // ; EAX = crc, EDX = buf, ESI = &
  98.         // crc_table, ECX = len
  99.         // if (buf == NULL) return 0L;
  100.         test  edx, edx
  101.         jne short L2
  102.         xor eax, eax
  103.         jmp Empty
  104.  
  105. L2:
  106.         // if (!len) return crc;
  107.         test ecx, ecx
  108.         jz Empty
  109.         mov esi, offset crc_table
  110.  
  111.         // ; EAX = crc, EDX = buf, ESI = &
  112.         // crc_table, ECX = len
  113.         // crc = crc ^ 0xFFFFFFFFL;
  114.         not eax
  115.  
  116. N3:
  117.         test edx, 3                 // aligned ?
  118.         jz short Next_Eight
  119.                 xor al, byte ptr[edx];
  120.                 inc edx;
  121.                 movzx ebx, al;
  122.                 shr eax, 8;
  123.                 xor eax, dword ptr[esi + 4 * ebx];
  124.  
  125.         dec ecx
  126.         jnz short N3
  127.         // aligned
  128.  
  129. Next_Eight:
  130.         cmp ecx, 8
  131.         jb NoEights
  132.  
  133.         // Next_Eight:
  134.                 xor eax, dword ptr[edx];
  135.                 add edx, 4;
  136.                 movzx ebx, al;
  137.                 shr eax, 8;
  138.                 xor eax, dword ptr[esi + 4 * ebx];
  139.                 movzx ebx, al;
  140.                 shr eax, 8;
  141.                 xor eax, dword ptr[esi + 4 * ebx];
  142.                 movzx ebx, al;
  143.                 shr eax, 8;
  144.                 xor eax, dword ptr[esi + 4 * ebx];
  145.                 movzx ebx, al;
  146.                 shr eax, 8;
  147.                 xor eax, dword ptr[esi + 4 * ebx];
  148.  
  149.                 xor eax, dword ptr[edx];
  150.                 add edx, 4;
  151.                 movzx ebx, al;
  152.                 shr eax, 8;
  153.                 xor eax, dword ptr[esi + 4 * ebx];
  154.                 movzx ebx, al;
  155.                 shr eax, 8;
  156.                 xor eax, dword ptr[esi + 4 * ebx];
  157.                 movzx ebx, al;
  158.                 shr eax, 8;
  159.                 xor eax, dword ptr[esi + 4 * ebx];
  160.                 movzx ebx, al;
  161.                 shr eax, 8;
  162.                 xor eax, dword ptr[esi + 4 * ebx];
  163.  
  164.         sub ecx, 8
  165.         jnz Next_Eight
  166.         jmp short Done
  167.  
  168.         // ; EAX = crc, EDX = buf, ESI = &
  169.         // crc_table, ECX = len
  170.  
  171. NoEights:
  172.         sub ecx, 1
  173.         jb short Done
  174.  
  175.         // DoLast:
  176.                 xor al, byte ptr[edx];
  177.                 inc edx;
  178.                 movzx ebx, al;
  179.                 shr eax, 8;
  180.                 xor eax, dword ptr[esi + 4 * ebx];
  181.         jmp short NoEights
  182.  
  183. Done:
  184.         xor eax, -1
  185.  
  186.         // ; EAX = crc
  187.  
  188. Empty:
  189. #pragma warn - rvl
  190.     };
  191. };
  192.  
  193. #endif // !_USE_ASM_
  194.