ucl_util.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /* ucl_util.h -- utilities for the UCL library
  2. This file is part of the UCL data compression library.
  3. Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
  4. All Rights Reserved.
  5. The UCL library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License as
  7. published by the Free Software Foundation; either version 2 of
  8. the License, or (at your option) any later version.
  9. The UCL library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with the UCL library; see the file COPYING.
  15. If not, write to the Free Software Foundation, Inc.,
  16. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. Markus F.X.J. Oberhumer
  18. <markus@oberhumer.com>
  19. */
  20. /* WARNING: this file should *not* be used by applications. It is
  21. part of the implementation of the library and is subject
  22. to change.
  23. */
  24. #ifndef __UCL_UTIL_H
  25. #define __UCL_UTIL_H
  26. #ifndef __UCL_CONF_H
  27. # include "ucl_conf.h"
  28. #endif
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. /***********************************************************************
  33. // fast memcpy that copies multiples of 8 byte chunks.
  34. // len is the number of bytes.
  35. // note: all parameters must be lvalues, len >= 8
  36. // dest and src advance, len is undefined afterwards
  37. ************************************************************************/
  38. #if 1 && defined(HAVE_MEMCPY)
  39. #if !defined(__UCL_DOS16) && !defined(__UCL_WIN16)
  40. #define MEMCPY8_DS(dest,src,len) \
  41. memcpy(dest,src,len); \
  42. dest += len; \
  43. src += len
  44. #endif
  45. #endif
  46. #if 0 && !defined(MEMCPY8_DS)
  47. #define MEMCPY8_DS(dest,src,len) \
  48. { do { \
  49. *dest++ = *src++; \
  50. *dest++ = *src++; \
  51. *dest++ = *src++; \
  52. *dest++ = *src++; \
  53. *dest++ = *src++; \
  54. *dest++ = *src++; \
  55. *dest++ = *src++; \
  56. *dest++ = *src++; \
  57. len -= 8; \
  58. } while (len > 0); }
  59. #endif
  60. #if !defined(MEMCPY8_DS)
  61. #define MEMCPY8_DS(dest,src,len) \
  62. { register ucl_uint __l = (len) / 8; \
  63. do { \
  64. *dest++ = *src++; \
  65. *dest++ = *src++; \
  66. *dest++ = *src++; \
  67. *dest++ = *src++; \
  68. *dest++ = *src++; \
  69. *dest++ = *src++; \
  70. *dest++ = *src++; \
  71. *dest++ = *src++; \
  72. } while (--__l > 0); }
  73. #endif
  74. /***********************************************************************
  75. // memcpy and pseudo-memmove
  76. // len is the number of bytes.
  77. // note: all parameters must be lvalues, len > 0
  78. // dest and src advance, len is undefined afterwards
  79. ************************************************************************/
  80. #define MEMCPY_DS(dest,src,len) \
  81. do *dest++ = *src++; \
  82. while (--len > 0)
  83. #define MEMMOVE_DS(dest,src,len) \
  84. do *dest++ = *src++; \
  85. while (--len > 0)
  86. /***********************************************************************
  87. // fast bzero that clears multiples of 8 pointers
  88. // n is the number of pointers.
  89. // note: n > 0
  90. // s and n are undefined afterwards
  91. ************************************************************************/
  92. #if (UCL_UINT_MAX <= SIZE_T_MAX) && defined(HAVE_MEMSET)
  93. #if 1
  94. #define BZERO8_PTR(s,l,n) memset((s),0,(ucl_uint)(l)*(n))
  95. #else
  96. #define BZERO8_PTR(s,l,n) memset((ucl_voidp)(s),0,(ucl_uint)(l)*(n))
  97. #endif
  98. #else
  99. #define BZERO8_PTR(s,l,n) \
  100. ucl_memset((ucl_voidp)(s),0,(ucl_uint)(l)*(n))
  101. #endif
  102. /***********************************************************************
  103. // rotate (not used at the moment)
  104. ************************************************************************/
  105. #if 0
  106. #if defined(__GNUC__) && defined(__i386__)
  107. unsigned char ucl_rotr8(unsigned char value, int shift);
  108. extern __inline__ unsigned char ucl_rotr8(unsigned char value, int shift)
  109. {
  110. unsigned char result;
  111. __asm__ __volatile__ ("movb %b1, %b0; rorb %b2, %b0"
  112. : "=a"(result) : "g"(value), "c"(shift));
  113. return result;
  114. }
  115. unsigned short ucl_rotr16(unsigned short value, int shift);
  116. extern __inline__ unsigned short ucl_rotr16(unsigned short value, int shift)
  117. {
  118. unsigned short result;
  119. __asm__ __volatile__ ("movw %b1, %b0; rorw %b2, %b0"
  120. : "=a"(result) : "g"(value), "c"(shift));
  121. return result;
  122. }
  123. #endif
  124. #endif
  125. #ifdef __cplusplus
  126. } /* extern "C" */
  127. #endif
  128. #endif /* already included */
  129. /*
  130. vi:ts=4:et
  131. */