home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 March / PCO3_97.ISO / filesbbs / os2 / lzo026.arj / LZO026.ZIP / lzo-0.26 / src / lzo_util.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-26  |  4.5 KB  |  184 lines

  1. /* lzo_util.h -- utilities for the the LZO library
  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 library and is subject
  29.    to change.
  30.  */
  31.  
  32.  
  33. #ifndef __LZO_UTIL_H
  34. #define __LZO_UTIL_H
  35.  
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39.  
  40.  
  41. /***********************************************************************
  42. // some prototypes
  43. ************************************************************************/
  44.  
  45. extern const lzo_byte __lzo_copyright[];
  46.  
  47.  
  48. /***********************************************************************
  49. // fast memcpy that copies multiples of 8 byte chunks.
  50. // len is the number of bytes.
  51. // note: all parameters must be lvalues, len > 0
  52. //       dest and src advance, len is undefined afterwards
  53. ************************************************************************/
  54.  
  55. #if 1 && !defined(__LZO_MSDOS16)
  56.  
  57. #define MEMCPY8_DS(dest,src,len) \
  58.     memcpy(dest,src,len); \
  59.     dest += len; \
  60.     src += len
  61.  
  62. #else
  63.  
  64. #define MEMCPY8_DS(dest,src,len) \
  65.     { register lzo_uint __l = (len) / 8; \
  66.     do { \
  67.         *dest++ = *src++; \
  68.         *dest++ = *src++; \
  69.         *dest++ = *src++; \
  70.         *dest++ = *src++; \
  71.         *dest++ = *src++; \
  72.         *dest++ = *src++; \
  73.         *dest++ = *src++; \
  74.         *dest++ = *src++; \
  75.     } while (--__l > 0); }
  76.  
  77. #endif
  78.  
  79.  
  80.  
  81. /***********************************************************************
  82. // memcpy and memmove
  83. // len is the number of bytes.
  84. // note: all parameters must be lvalues, len > 0
  85. //       dest and src advance, len is undefined afterwards
  86. ************************************************************************/
  87.  
  88. #if defined(LZO_ALWAYS_USE_MEMCPY)
  89.  
  90. #define MEMCPY_DS(dest,src,len) \
  91.     memcpy(dest,src,len); \
  92.     dest += len; \
  93.     src += len;
  94.  
  95. #else
  96.  
  97. #define MEMCPY_DS(dest,src,len) \
  98.     do *dest++ = *src++; \
  99.     while (--len > 0)
  100.  
  101. #endif
  102.  
  103.  
  104. #define MEMMOVE_DS(dest,src,len) \
  105.     do *dest++ = *src++; \
  106.     while (--len > 0)
  107.  
  108.  
  109.  
  110. /***********************************************************************
  111. // fast bzero that clears multiples of 8 pointers
  112. // n is the number of pointers.
  113. // note: n > 0
  114. //       s and n are undefined afterwards
  115. ************************************************************************/
  116.  
  117. #if defined(LZO_OPTIMIZE_GNUC_i386)
  118.  
  119. #define BZERO8_PTR(s,n) \
  120. __asm__ __volatile__( \
  121.     "movl  %0,%%eax \n"             \
  122.     "movl  %1,%%edi \n"             \
  123.     "movl  %2,%%ecx \n"             \
  124.     "cld \n"                        \
  125.     "rep \n"                        \
  126.     "stosl %%eax,(%%edi) \n"        \
  127.     : /* no outputs */              \
  128.     :"g" (0),"g" (s),"g" (n)          \
  129.     :"eax","edi","ecx", "cc"        \
  130. )
  131.  
  132. #elif (LZO_UINT_MAX <= UINT_MAX)
  133.  
  134. #define BZERO8_PTR(s,n) \
  135.     memset((lzo_voidp)(s),0,(n)*sizeof(lzo_byte *))
  136.  
  137. #else
  138.  
  139. #define BZERO8_PTR(s,n) \
  140.     lzo_memset((lzo_voidp)(s),0,(n)*lzo_sizeof(lzo_byte *))
  141.  
  142. #endif
  143.  
  144.  
  145. /***********************************************************************
  146. // rotate (not used at the moment)
  147. ************************************************************************/
  148.  
  149. #if defined(__GNUC__) && defined(__i386__)
  150.  
  151. unsigned char lzo_rotr8(unsigned char value, int shift);
  152. extern __inline__ unsigned char lzo_rotr8(unsigned char value, int shift)
  153. {
  154.     unsigned char result;
  155.  
  156.     __asm__ __volatile__ ("movb %b1, %b0; rorb %b2, %b0"
  157.                           : "=a"(result) : "g"(value), "c"(shift));
  158.     return result;
  159. }
  160.  
  161. unsigned short lzo_rotr16(unsigned short value, int shift);
  162. extern __inline__ unsigned short lzo_rotr16(unsigned short value, int shift)
  163. {
  164.     unsigned short result;
  165.  
  166.     __asm__ __volatile__ ("movw %b1, %b0; rorw %b2, %b0"
  167.                           : "=a"(result) : "g"(value), "c"(shift));
  168.     return result;
  169. }
  170.  
  171. #endif
  172.  
  173.  
  174.  
  175. #ifdef __cplusplus
  176. } /* extern "C" */
  177. #endif
  178.  
  179. #endif /* already included */
  180.  
  181. /*
  182. vi:ts=4
  183. */
  184.