Subversion Repositories freemyipod

Rev

Details | Last modification | View Log | RSS feed

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