home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 March / PCO3_97.ISO / filesbbs / os2 / lzo026.arj / LZO026.ZIP / lzo-0.26 / src / lzo1a_cr.ch < prev    next >
Encoding:
Text File  |  1996-06-13  |  2.8 KB  |  121 lines

  1. /* lzo1a_cr.ch -- literal run handling for the the LZO1A algorithm
  2.  
  3.    This file is part of the LZO real-time data compression library.
  4.  
  5.    Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
  6.  
  7.    The LZO library is free software; you can redistribute it and/or
  8.    modify it under the terms of the GNU General Public License as
  9.    published by the Free Software Foundation; either version 2 of
  10.    the License, or (at your option) any later version.
  11.  
  12.    The LZO library is distributed in the hope that it will be useful,
  13.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.    GNU General Public License for more details.
  16.  
  17.    You should have received a copy of the GNU General Public License
  18.    along with the LZO library; see the file COPYING.
  19.    If not, write to the Free Software Foundation, Inc.,
  20.    59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21.  
  22.    Markus F.X.J. Oberhumer
  23.    markus.oberhumer@jk.uni-linz.ac.at
  24.  */
  25.  
  26.  
  27. /* WARNING: this file should *not* be used by applications. It is
  28.    part of the implementation of the LZO package and is subject
  29.    to change.
  30.  */
  31.  
  32.  
  33. #ifndef __LZO_LRUN_H
  34. #define __LZO_LRUN_H
  35.  
  36.  
  37. /***********************************************************************
  38. // code a literal run 
  39. ************************************************************************/
  40.  
  41. static lzo_byte *
  42. store_run(lzo_byte * const oo, const lzo_byte * const ii, lzo_uint r_len)
  43. {
  44. #if defined(LZO_OPTIMIZE_GNUC_i386)
  45.     register lzo_byte *op __asm__("%edi");
  46.     register const lzo_byte *ip __asm__("%esi");
  47.     register lzo_uint t __asm__("%ecx");
  48. #else
  49.     register lzo_byte *op;
  50.     register const lzo_byte *ip;
  51.     register lzo_uint t;
  52. #endif
  53.  
  54.     op = oo;
  55.     ip = ii;
  56.     assert(r_len > 0);
  57.  
  58.     /* code a long R0 run */
  59.     if (r_len >= 512)
  60.     {
  61.         unsigned r_bits = 6;        /* 256 << 6 == 16384 */
  62.         lzo_uint tt = 32768u;
  63.  
  64.         while (r_len >= (t = tt))
  65.         {
  66.             r_len -= t;
  67.             *op++ = 0; *op++ = (R0MAX - R0MIN);
  68.             MEMCPY8_DS(op, ip, t);
  69.             LZO_STATS(lzo_stats->r0long_runs++);
  70.         }
  71.         tt >>= 1;
  72.         do {
  73.             if (r_len >= (t = tt))
  74.             {
  75.                 r_len -= t;
  76.                 *op++ = 0; *op++ = LZO_BYTE((R0FAST - R0MIN) + r_bits);
  77.                 MEMCPY8_DS(op, ip, t);
  78.                 LZO_STATS(lzo_stats->r0long_runs++);
  79.             }
  80.             tt >>= 1;
  81.         } while (--r_bits > 0);
  82.     }
  83.     assert(r_len < 512);
  84.  
  85.     while (r_len >= (t = R0FAST))
  86.     {
  87.         r_len -= t;
  88.         *op++ = 0; *op++ = (R0FAST - R0MIN);
  89.         MEMCPY8_DS(op, ip, t);
  90.         LZO_STATS(lzo_stats->r0fast_runs++);
  91.     }
  92.  
  93.     t = r_len;
  94.     if (t >= R0MIN)
  95.     {
  96.         /* code a short R0 run */
  97.         *op++ = 0; *op++ = LZO_BYTE(t - R0MIN);
  98.         MEMCPY_DS(op, ip, t);
  99.         LZO_STATS(lzo_stats->r0short_runs++);
  100.     }
  101.     else if (t > 0)
  102.     {
  103.         /* code a short literal run */
  104.         LZO_STATS(lzo_stats->lit_runs++);
  105.         LZO_STATS(lzo_stats->lit_run[t]++);
  106.         *op++ = LZO_BYTE(t);
  107.         MEMCPY_DS(op, ip, t);
  108.     }
  109.  
  110.     return op;
  111. }
  112.  
  113.  
  114.  
  115. #endif /* already included */
  116.  
  117. /*
  118. vi:ts=4
  119. */
  120.  
  121.