0b41bcc6fd1a10c99959a5efc0fd01eac62b569b
[melted] / src / modules / xine / xineutils.h
1 /*
2 * Copyright (C) 2000-2004 the xine project
3 *
4 * This file is part of xine, a free video player.
5 *
6 * xine is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * xine is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19 *
20 * $Id$
21 *
22 */
23 #ifndef XINEUTILS_H
24 #define XINEUTILS_H
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 #include <unistd.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <stdarg.h>
34 #include <inttypes.h>
35 #include <pthread.h>
36 #if HAVE_LIBGEN_H
37 # include <libgen.h>
38 #endif
39
40 #ifdef XINE_COMPILE
41 # include "attributes.h"
42 # include "compat.h"
43 # include "xmlparser.h"
44 # include "xine_buffer.h"
45 # include "configfile.h"
46 #else
47 # include <xine/attributes.h>
48 # include <xine/compat.h>
49 # include <xine/xmlparser.h>
50 # include <xine/xine_buffer.h>
51 # include <xine/configfile.h>
52 #endif
53
54 #ifdef HAVE_CONFIG_H
55 #include "config.h"
56 #endif
57
58 #include <stdio.h>
59 #include <string.h>
60
61 /*
62 * debugable mutexes
63 */
64
65 typedef struct {
66 pthread_mutex_t mutex;
67 char id[80];
68 char *locked_by;
69 } xine_mutex_t;
70
71 int xine_mutex_init (xine_mutex_t *mutex, const pthread_mutexattr_t *mutexattr,
72 char *id);
73
74 int xine_mutex_lock (xine_mutex_t *mutex, char *who);
75 int xine_mutex_unlock (xine_mutex_t *mutex, char *who);
76 int xine_mutex_destroy (xine_mutex_t *mutex);
77
78
79
80 /* CPU Acceleration */
81
82 /*
83 * The type of an value that fits in an MMX register (note that long
84 * long constant values MUST be suffixed by LL and unsigned long long
85 * values by ULL, lest they be truncated by the compiler)
86 */
87
88 /* generic accelerations */
89 #define MM_ACCEL_MLIB 0x00000001
90
91 /* x86 accelerations */
92 #define MM_ACCEL_X86_MMX 0x80000000
93 #define MM_ACCEL_X86_3DNOW 0x40000000
94 #define MM_ACCEL_X86_MMXEXT 0x20000000
95 #define MM_ACCEL_X86_SSE 0x10000000
96 #define MM_ACCEL_X86_SSE2 0x08000000
97 /* powerpc accelerations */
98 #define MM_ACCEL_PPC_ALTIVEC 0x04000000
99 /* x86 compat defines */
100 #define MM_MMX MM_ACCEL_X86_MMX
101 #define MM_3DNOW MM_ACCEL_X86_3DNOW
102 #define MM_MMXEXT MM_ACCEL_X86_MMXEXT
103 #define MM_SSE MM_ACCEL_X86_SSE
104 #define MM_SSE2 MM_ACCEL_X86_SSE2
105
106 uint32_t xine_mm_accel (void);
107
108 #if defined(ARCH_X86) || defined(ARCH_X86_64)
109
110 typedef union {
111 int64_t q; /* Quadword (64-bit) value */
112 uint64_t uq; /* Unsigned Quadword */
113 int d[2]; /* 2 Doubleword (32-bit) values */
114 unsigned int ud[2]; /* 2 Unsigned Doubleword */
115 short w[4]; /* 4 Word (16-bit) values */
116 unsigned short uw[4]; /* 4 Unsigned Word */
117 char b[8]; /* 8 Byte (8-bit) values */
118 unsigned char ub[8]; /* 8 Unsigned Byte */
119 float s[2]; /* Single-precision (32-bit) value */
120 } ATTR_ALIGN(8) mmx_t; /* On an 8-byte (64-bit) boundary */
121
122
123
124 #define mmx_i2r(op,imm,reg) \
125 __asm__ __volatile__ (#op " %0, %%" #reg \
126 : /* nothing */ \
127 : "i" (imm) )
128
129 #define mmx_m2r(op,mem,reg) \
130 __asm__ __volatile__ (#op " %0, %%" #reg \
131 : /* nothing */ \
132 : "m" (mem))
133
134 #define mmx_r2m(op,reg,mem) \
135 __asm__ __volatile__ (#op " %%" #reg ", %0" \
136 : "=m" (mem) \
137 : /* nothing */ )
138
139 #define mmx_r2r(op,regs,regd) \
140 __asm__ __volatile__ (#op " %" #regs ", %" #regd)
141
142
143 #define emms() __asm__ __volatile__ ("emms")
144
145 #define movd_m2r(var,reg) mmx_m2r (movd, var, reg)
146 #define movd_r2m(reg,var) mmx_r2m (movd, reg, var)
147 #define movd_r2r(regs,regd) mmx_r2r (movd, regs, regd)
148
149 #define movq_m2r(var,reg) mmx_m2r (movq, var, reg)
150 #define movq_r2m(reg,var) mmx_r2m (movq, reg, var)
151 #define movq_r2r(regs,regd) mmx_r2r (movq, regs, regd)
152
153 #define packssdw_m2r(var,reg) mmx_m2r (packssdw, var, reg)
154 #define packssdw_r2r(regs,regd) mmx_r2r (packssdw, regs, regd)
155 #define packsswb_m2r(var,reg) mmx_m2r (packsswb, var, reg)
156 #define packsswb_r2r(regs,regd) mmx_r2r (packsswb, regs, regd)
157
158 #define packuswb_m2r(var,reg) mmx_m2r (packuswb, var, reg)
159 #define packuswb_r2r(regs,regd) mmx_r2r (packuswb, regs, regd)
160
161 #define paddb_m2r(var,reg) mmx_m2r (paddb, var, reg)
162 #define paddb_r2r(regs,regd) mmx_r2r (paddb, regs, regd)
163 #define paddd_m2r(var,reg) mmx_m2r (paddd, var, reg)
164 #define paddd_r2r(regs,regd) mmx_r2r (paddd, regs, regd)
165 #define paddw_m2r(var,reg) mmx_m2r (paddw, var, reg)
166 #define paddw_r2r(regs,regd) mmx_r2r (paddw, regs, regd)
167
168 #define paddsb_m2r(var,reg) mmx_m2r (paddsb, var, reg)
169 #define paddsb_r2r(regs,regd) mmx_r2r (paddsb, regs, regd)
170 #define paddsw_m2r(var,reg) mmx_m2r (paddsw, var, reg)
171 #define paddsw_r2r(regs,regd) mmx_r2r (paddsw, regs, regd)
172
173 #define paddusb_m2r(var,reg) mmx_m2r (paddusb, var, reg)
174 #define paddusb_r2r(regs,regd) mmx_r2r (paddusb, regs, regd)
175 #define paddusw_m2r(var,reg) mmx_m2r (paddusw, var, reg)
176 #define paddusw_r2r(regs,regd) mmx_r2r (paddusw, regs, regd)
177
178 #define pand_m2r(var,reg) mmx_m2r (pand, var, reg)
179 #define pand_r2r(regs,regd) mmx_r2r (pand, regs, regd)
180
181 #define pandn_m2r(var,reg) mmx_m2r (pandn, var, reg)
182 #define pandn_r2r(regs,regd) mmx_r2r (pandn, regs, regd)
183
184 #define pcmpeqb_m2r(var,reg) mmx_m2r (pcmpeqb, var, reg)
185 #define pcmpeqb_r2r(regs,regd) mmx_r2r (pcmpeqb, regs, regd)
186 #define pcmpeqd_m2r(var,reg) mmx_m2r (pcmpeqd, var, reg)
187 #define pcmpeqd_r2r(regs,regd) mmx_r2r (pcmpeqd, regs, regd)
188 #define pcmpeqw_m2r(var,reg) mmx_m2r (pcmpeqw, var, reg)
189 #define pcmpeqw_r2r(regs,regd) mmx_r2r (pcmpeqw, regs, regd)
190
191 #define pcmpgtb_m2r(var,reg) mmx_m2r (pcmpgtb, var, reg)
192 #define pcmpgtb_r2r(regs,regd) mmx_r2r (pcmpgtb, regs, regd)
193 #define pcmpgtd_m2r(var,reg) mmx_m2r (pcmpgtd, var, reg)
194 #define pcmpgtd_r2r(regs,regd) mmx_r2r (pcmpgtd, regs, regd)
195 #define pcmpgtw_m2r(var,reg) mmx_m2r (pcmpgtw, var, reg)
196 #define pcmpgtw_r2r(regs,regd) mmx_r2r (pcmpgtw, regs, regd)
197
198 #define pmaddwd_m2r(var,reg) mmx_m2r (pmaddwd, var, reg)
199 #define pmaddwd_r2r(regs,regd) mmx_r2r (pmaddwd, regs, regd)
200
201 #define pmulhw_m2r(var,reg) mmx_m2r (pmulhw, var, reg)
202 #define pmulhw_r2r(regs,regd) mmx_r2r (pmulhw, regs, regd)
203
204 #define pmullw_m2r(var,reg) mmx_m2r (pmullw, var, reg)
205 #define pmullw_r2r(regs,regd) mmx_r2r (pmullw, regs, regd)
206
207 #define por_m2r(var,reg) mmx_m2r (por, var, reg)
208 #define por_r2r(regs,regd) mmx_r2r (por, regs, regd)
209
210 #define pslld_i2r(imm,reg) mmx_i2r (pslld, imm, reg)
211 #define pslld_m2r(var,reg) mmx_m2r (pslld, var, reg)
212 #define pslld_r2r(regs,regd) mmx_r2r (pslld, regs, regd)
213 #define psllq_i2r(imm,reg) mmx_i2r (psllq, imm, reg)
214 #define psllq_m2r(var,reg) mmx_m2r (psllq, var, reg)
215 #define psllq_r2r(regs,regd) mmx_r2r (psllq, regs, regd)
216 #define psllw_i2r(imm,reg) mmx_i2r (psllw, imm, reg)
217 #define psllw_m2r(var,reg) mmx_m2r (psllw, var, reg)
218 #define psllw_r2r(regs,regd) mmx_r2r (psllw, regs, regd)
219
220 #define psrad_i2r(imm,reg) mmx_i2r (psrad, imm, reg)
221 #define psrad_m2r(var,reg) mmx_m2r (psrad, var, reg)
222 #define psrad_r2r(regs,regd) mmx_r2r (psrad, regs, regd)
223 #define psraw_i2r(imm,reg) mmx_i2r (psraw, imm, reg)
224 #define psraw_m2r(var,reg) mmx_m2r (psraw, var, reg)
225 #define psraw_r2r(regs,regd) mmx_r2r (psraw, regs, regd)
226
227 #define psrld_i2r(imm,reg) mmx_i2r (psrld, imm, reg)
228 #define psrld_m2r(var,reg) mmx_m2r (psrld, var, reg)
229 #define psrld_r2r(regs,regd) mmx_r2r (psrld, regs, regd)
230 #define psrlq_i2r(imm,reg) mmx_i2r (psrlq, imm, reg)
231 #define psrlq_m2r(var,reg) mmx_m2r (psrlq, var, reg)
232 #define psrlq_r2r(regs,regd) mmx_r2r (psrlq, regs, regd)
233 #define psrlw_i2r(imm,reg) mmx_i2r (psrlw, imm, reg)
234 #define psrlw_m2r(var,reg) mmx_m2r (psrlw, var, reg)
235 #define psrlw_r2r(regs,regd) mmx_r2r (psrlw, regs, regd)
236
237 #define psubb_m2r(var,reg) mmx_m2r (psubb, var, reg)
238 #define psubb_r2r(regs,regd) mmx_r2r (psubb, regs, regd)
239 #define psubd_m2r(var,reg) mmx_m2r (psubd, var, reg)
240 #define psubd_r2r(regs,regd) mmx_r2r (psubd, regs, regd)
241 #define psubw_m2r(var,reg) mmx_m2r (psubw, var, reg)
242 #define psubw_r2r(regs,regd) mmx_r2r (psubw, regs, regd)
243
244 #define psubsb_m2r(var,reg) mmx_m2r (psubsb, var, reg)
245 #define psubsb_r2r(regs,regd) mmx_r2r (psubsb, regs, regd)
246 #define psubsw_m2r(var,reg) mmx_m2r (psubsw, var, reg)
247 #define psubsw_r2r(regs,regd) mmx_r2r (psubsw, regs, regd)
248
249 #define psubusb_m2r(var,reg) mmx_m2r (psubusb, var, reg)
250 #define psubusb_r2r(regs,regd) mmx_r2r (psubusb, regs, regd)
251 #define psubusw_m2r(var,reg) mmx_m2r (psubusw, var, reg)
252 #define psubusw_r2r(regs,regd) mmx_r2r (psubusw, regs, regd)
253
254 #define punpckhbw_m2r(var,reg) mmx_m2r (punpckhbw, var, reg)
255 #define punpckhbw_r2r(regs,regd) mmx_r2r (punpckhbw, regs, regd)
256 #define punpckhdq_m2r(var,reg) mmx_m2r (punpckhdq, var, reg)
257 #define punpckhdq_r2r(regs,regd) mmx_r2r (punpckhdq, regs, regd)
258 #define punpckhwd_m2r(var,reg) mmx_m2r (punpckhwd, var, reg)
259 #define punpckhwd_r2r(regs,regd) mmx_r2r (punpckhwd, regs, regd)
260
261 #define punpcklbw_m2r(var,reg) mmx_m2r (punpcklbw, var, reg)
262 #define punpcklbw_r2r(regs,regd) mmx_r2r (punpcklbw, regs, regd)
263 #define punpckldq_m2r(var,reg) mmx_m2r (punpckldq, var, reg)
264 #define punpckldq_r2r(regs,regd) mmx_r2r (punpckldq, regs, regd)
265 #define punpcklwd_m2r(var,reg) mmx_m2r (punpcklwd, var, reg)
266 #define punpcklwd_r2r(regs,regd) mmx_r2r (punpcklwd, regs, regd)
267
268 #define pxor_m2r(var,reg) mmx_m2r (pxor, var, reg)
269 #define pxor_r2r(regs,regd) mmx_r2r (pxor, regs, regd)
270
271
272 /* 3DNOW extensions */
273
274 #define pavgusb_m2r(var,reg) mmx_m2r (pavgusb, var, reg)
275 #define pavgusb_r2r(regs,regd) mmx_r2r (pavgusb, regs, regd)
276
277
278 /* AMD MMX extensions - also available in intel SSE */
279
280
281 #define mmx_m2ri(op,mem,reg,imm) \
282 __asm__ __volatile__ (#op " %1, %0, %%" #reg \
283 : /* nothing */ \
284 : "X" (mem), "X" (imm))
285 #define mmx_r2ri(op,regs,regd,imm) \
286 __asm__ __volatile__ (#op " %0, %%" #regs ", %%" #regd \
287 : /* nothing */ \
288 : "X" (imm) )
289
290 #define mmx_fetch(mem,hint) \
291 __asm__ __volatile__ ("prefetch" #hint " %0" \
292 : /* nothing */ \
293 : "X" (mem))
294
295
296 #define maskmovq(regs,maskreg) mmx_r2ri (maskmovq, regs, maskreg)
297
298 #define movntq_r2m(mmreg,var) mmx_r2m (movntq, mmreg, var)
299
300 #define pavgb_m2r(var,reg) mmx_m2r (pavgb, var, reg)
301 #define pavgb_r2r(regs,regd) mmx_r2r (pavgb, regs, regd)
302 #define pavgw_m2r(var,reg) mmx_m2r (pavgw, var, reg)
303 #define pavgw_r2r(regs,regd) mmx_r2r (pavgw, regs, regd)
304
305 #define pextrw_r2r(mmreg,reg,imm) mmx_r2ri (pextrw, mmreg, reg, imm)
306
307 #define pinsrw_r2r(reg,mmreg,imm) mmx_r2ri (pinsrw, reg, mmreg, imm)
308
309 #define pmaxsw_m2r(var,reg) mmx_m2r (pmaxsw, var, reg)
310 #define pmaxsw_r2r(regs,regd) mmx_r2r (pmaxsw, regs, regd)
311
312 #define pmaxub_m2r(var,reg) mmx_m2r (pmaxub, var, reg)
313 #define pmaxub_r2r(regs,regd) mmx_r2r (pmaxub, regs, regd)
314
315 #define pminsw_m2r(var,reg) mmx_m2r (pminsw, var, reg)
316 #define pminsw_r2r(regs,regd) mmx_r2r (pminsw, regs, regd)
317
318 #define pminub_m2r(var,reg) mmx_m2r (pminub, var, reg)
319 #define pminub_r2r(regs,regd) mmx_r2r (pminub, regs, regd)
320
321 #define pmovmskb(mmreg,reg) \
322 __asm__ __volatile__ ("movmskps %" #mmreg ", %" #reg)
323
324 #define pmulhuw_m2r(var,reg) mmx_m2r (pmulhuw, var, reg)
325 #define pmulhuw_r2r(regs,regd) mmx_r2r (pmulhuw, regs, regd)
326
327 #define prefetcht0(mem) mmx_fetch (mem, t0)
328 #define prefetcht1(mem) mmx_fetch (mem, t1)
329 #define prefetcht2(mem) mmx_fetch (mem, t2)
330 #define prefetchnta(mem) mmx_fetch (mem, nta)
331
332 #define psadbw_m2r(var,reg) mmx_m2r (psadbw, var, reg)
333 #define psadbw_r2r(regs,regd) mmx_r2r (psadbw, regs, regd)
334
335 #define pshufw_m2r(var,reg,imm) mmx_m2ri(pshufw, var, reg, imm)
336 #define pshufw_r2r(regs,regd,imm) mmx_r2ri(pshufw, regs, regd, imm)
337
338 #define sfence() __asm__ __volatile__ ("sfence\n\t")
339
340 typedef union {
341 float sf[4]; /* Single-precision (32-bit) value */
342 } ATTR_ALIGN(16) sse_t; /* On a 16 byte (128-bit) boundary */
343
344
345 #define sse_i2r(op, imm, reg) \
346 __asm__ __volatile__ (#op " %0, %%" #reg \
347 : /* nothing */ \
348 : "X" (imm) )
349
350 #define sse_m2r(op, mem, reg) \
351 __asm__ __volatile__ (#op " %0, %%" #reg \
352 : /* nothing */ \
353 : "X" (mem))
354
355 #define sse_r2m(op, reg, mem) \
356 __asm__ __volatile__ (#op " %%" #reg ", %0" \
357 : "=X" (mem) \
358 : /* nothing */ )
359
360 #define sse_r2r(op, regs, regd) \
361 __asm__ __volatile__ (#op " %" #regs ", %" #regd)
362
363 #define sse_r2ri(op, regs, regd, imm) \
364 __asm__ __volatile__ (#op " %0, %%" #regs ", %%" #regd \
365 : /* nothing */ \
366 : "X" (imm) )
367
368 #define sse_m2ri(op, mem, reg, subop) \
369 __asm__ __volatile__ (#op " %0, %%" #reg ", " #subop \
370 : /* nothing */ \
371 : "X" (mem))
372
373
374 #define movaps_m2r(var, reg) sse_m2r(movaps, var, reg)
375 #define movaps_r2m(reg, var) sse_r2m(movaps, reg, var)
376 #define movaps_r2r(regs, regd) sse_r2r(movaps, regs, regd)
377
378 #define movntps_r2m(xmmreg, var) sse_r2m(movntps, xmmreg, var)
379
380 #define movups_m2r(var, reg) sse_m2r(movups, var, reg)
381 #define movups_r2m(reg, var) sse_r2m(movups, reg, var)
382 #define movups_r2r(regs, regd) sse_r2r(movups, regs, regd)
383
384 #define movhlps_r2r(regs, regd) sse_r2r(movhlps, regs, regd)
385
386 #define movlhps_r2r(regs, regd) sse_r2r(movlhps, regs, regd)
387
388 #define movhps_m2r(var, reg) sse_m2r(movhps, var, reg)
389 #define movhps_r2m(reg, var) sse_r2m(movhps, reg, var)
390
391 #define movlps_m2r(var, reg) sse_m2r(movlps, var, reg)
392 #define movlps_r2m(reg, var) sse_r2m(movlps, reg, var)
393
394 #define movss_m2r(var, reg) sse_m2r(movss, var, reg)
395 #define movss_r2m(reg, var) sse_r2m(movss, reg, var)
396 #define movss_r2r(regs, regd) sse_r2r(movss, regs, regd)
397
398 #define shufps_m2r(var, reg, index) sse_m2ri(shufps, var, reg, index)
399 #define shufps_r2r(regs, regd, index) sse_r2ri(shufps, regs, regd, index)
400
401 #define cvtpi2ps_m2r(var, xmmreg) sse_m2r(cvtpi2ps, var, xmmreg)
402 #define cvtpi2ps_r2r(mmreg, xmmreg) sse_r2r(cvtpi2ps, mmreg, xmmreg)
403
404 #define cvtps2pi_m2r(var, mmreg) sse_m2r(cvtps2pi, var, mmreg)
405 #define cvtps2pi_r2r(xmmreg, mmreg) sse_r2r(cvtps2pi, mmreg, xmmreg)
406
407 #define cvttps2pi_m2r(var, mmreg) sse_m2r(cvttps2pi, var, mmreg)
408 #define cvttps2pi_r2r(xmmreg, mmreg) sse_r2r(cvttps2pi, mmreg, xmmreg)
409
410 #define cvtsi2ss_m2r(var, xmmreg) sse_m2r(cvtsi2ss, var, xmmreg)
411 #define cvtsi2ss_r2r(reg, xmmreg) sse_r2r(cvtsi2ss, reg, xmmreg)
412
413 #define cvtss2si_m2r(var, reg) sse_m2r(cvtss2si, var, reg)
414 #define cvtss2si_r2r(xmmreg, reg) sse_r2r(cvtss2si, xmmreg, reg)
415
416 #define cvttss2si_m2r(var, reg) sse_m2r(cvtss2si, var, reg)
417 #define cvttss2si_r2r(xmmreg, reg) sse_r2r(cvtss2si, xmmreg, reg)
418
419 #define movmskps(xmmreg, reg) \
420 __asm__ __volatile__ ("movmskps %" #xmmreg ", %" #reg)
421
422 #define addps_m2r(var, reg) sse_m2r(addps, var, reg)
423 #define addps_r2r(regs, regd) sse_r2r(addps, regs, regd)
424
425 #define addss_m2r(var, reg) sse_m2r(addss, var, reg)
426 #define addss_r2r(regs, regd) sse_r2r(addss, regs, regd)
427
428 #define subps_m2r(var, reg) sse_m2r(subps, var, reg)
429 #define subps_r2r(regs, regd) sse_r2r(subps, regs, regd)
430
431 #define subss_m2r(var, reg) sse_m2r(subss, var, reg)
432 #define subss_r2r(regs, regd) sse_r2r(subss, regs, regd)
433
434 #define mulps_m2r(var, reg) sse_m2r(mulps, var, reg)
435 #define mulps_r2r(regs, regd) sse_r2r(mulps, regs, regd)
436
437 #define mulss_m2r(var, reg) sse_m2r(mulss, var, reg)
438 #define mulss_r2r(regs, regd) sse_r2r(mulss, regs, regd)
439
440 #define divps_m2r(var, reg) sse_m2r(divps, var, reg)
441 #define divps_r2r(regs, regd) sse_r2r(divps, regs, regd)
442
443 #define divss_m2r(var, reg) sse_m2r(divss, var, reg)
444 #define divss_r2r(regs, regd) sse_r2r(divss, regs, regd)
445
446 #define rcpps_m2r(var, reg) sse_m2r(rcpps, var, reg)
447 #define rcpps_r2r(regs, regd) sse_r2r(rcpps, regs, regd)
448
449 #define rcpss_m2r(var, reg) sse_m2r(rcpss, var, reg)
450 #define rcpss_r2r(regs, regd) sse_r2r(rcpss, regs, regd)
451
452 #define rsqrtps_m2r(var, reg) sse_m2r(rsqrtps, var, reg)
453 #define rsqrtps_r2r(regs, regd) sse_r2r(rsqrtps, regs, regd)
454
455 #define rsqrtss_m2r(var, reg) sse_m2r(rsqrtss, var, reg)
456 #define rsqrtss_r2r(regs, regd) sse_r2r(rsqrtss, regs, regd)
457
458 #define sqrtps_m2r(var, reg) sse_m2r(sqrtps, var, reg)
459 #define sqrtps_r2r(regs, regd) sse_r2r(sqrtps, regs, regd)
460
461 #define sqrtss_m2r(var, reg) sse_m2r(sqrtss, var, reg)
462 #define sqrtss_r2r(regs, regd) sse_r2r(sqrtss, regs, regd)
463
464 #define andps_m2r(var, reg) sse_m2r(andps, var, reg)
465 #define andps_r2r(regs, regd) sse_r2r(andps, regs, regd)
466
467 #define andnps_m2r(var, reg) sse_m2r(andnps, var, reg)
468 #define andnps_r2r(regs, regd) sse_r2r(andnps, regs, regd)
469
470 #define orps_m2r(var, reg) sse_m2r(orps, var, reg)
471 #define orps_r2r(regs, regd) sse_r2r(orps, regs, regd)
472
473 #define xorps_m2r(var, reg) sse_m2r(xorps, var, reg)
474 #define xorps_r2r(regs, regd) sse_r2r(xorps, regs, regd)
475
476 #define maxps_m2r(var, reg) sse_m2r(maxps, var, reg)
477 #define maxps_r2r(regs, regd) sse_r2r(maxps, regs, regd)
478
479 #define maxss_m2r(var, reg) sse_m2r(maxss, var, reg)
480 #define maxss_r2r(regs, regd) sse_r2r(maxss, regs, regd)
481
482 #define minps_m2r(var, reg) sse_m2r(minps, var, reg)
483 #define minps_r2r(regs, regd) sse_r2r(minps, regs, regd)
484
485 #define minss_m2r(var, reg) sse_m2r(minss, var, reg)
486 #define minss_r2r(regs, regd) sse_r2r(minss, regs, regd)
487
488 #define cmpps_m2r(var, reg, op) sse_m2ri(cmpps, var, reg, op)
489 #define cmpps_r2r(regs, regd, op) sse_r2ri(cmpps, regs, regd, op)
490
491 #define cmpeqps_m2r(var, reg) sse_m2ri(cmpps, var, reg, 0)
492 #define cmpeqps_r2r(regs, regd) sse_r2ri(cmpps, regs, regd, 0)
493
494 #define cmpltps_m2r(var, reg) sse_m2ri(cmpps, var, reg, 1)
495 #define cmpltps_r2r(regs, regd) sse_r2ri(cmpps, regs, regd, 1)
496
497 #define cmpleps_m2r(var, reg) sse_m2ri(cmpps, var, reg, 2)
498 #define cmpleps_r2r(regs, regd) sse_r2ri(cmpps, regs, regd, 2)
499
500 #define cmpunordps_m2r(var, reg) sse_m2ri(cmpps, var, reg, 3)
501 #define cmpunordps_r2r(regs, regd) sse_r2ri(cmpps, regs, regd, 3)
502
503 #define cmpneqps_m2r(var, reg) sse_m2ri(cmpps, var, reg, 4)
504 #define cmpneqps_r2r(regs, regd) sse_r2ri(cmpps, regs, regd, 4)
505
506 #define cmpnltps_m2r(var, reg) sse_m2ri(cmpps, var, reg, 5)
507 #define cmpnltps_r2r(regs, regd) sse_r2ri(cmpps, regs, regd, 5)
508
509 #define cmpnleps_m2r(var, reg) sse_m2ri(cmpps, var, reg, 6)
510 #define cmpnleps_r2r(regs, regd) sse_r2ri(cmpps, regs, regd, 6)
511
512 #define cmpordps_m2r(var, reg) sse_m2ri(cmpps, var, reg, 7)
513 #define cmpordps_r2r(regs, regd) sse_r2ri(cmpps, regs, regd, 7)
514
515 #define cmpss_m2r(var, reg, op) sse_m2ri(cmpss, var, reg, op)
516 #define cmpss_r2r(regs, regd, op) sse_r2ri(cmpss, regs, regd, op)
517
518 #define cmpeqss_m2r(var, reg) sse_m2ri(cmpss, var, reg, 0)
519 #define cmpeqss_r2r(regs, regd) sse_r2ri(cmpss, regs, regd, 0)
520
521 #define cmpltss_m2r(var, reg) sse_m2ri(cmpss, var, reg, 1)
522 #define cmpltss_r2r(regs, regd) sse_r2ri(cmpss, regs, regd, 1)
523
524 #define cmpless_m2r(var, reg) sse_m2ri(cmpss, var, reg, 2)
525 #define cmpless_r2r(regs, regd) sse_r2ri(cmpss, regs, regd, 2)
526
527 #define cmpunordss_m2r(var, reg) sse_m2ri(cmpss, var, reg, 3)
528 #define cmpunordss_r2r(regs, regd) sse_r2ri(cmpss, regs, regd, 3)
529
530 #define cmpneqss_m2r(var, reg) sse_m2ri(cmpss, var, reg, 4)
531 #define cmpneqss_r2r(regs, regd) sse_r2ri(cmpss, regs, regd, 4)
532
533 #define cmpnltss_m2r(var, reg) sse_m2ri(cmpss, var, reg, 5)
534 #define cmpnltss_r2r(regs, regd) sse_r2ri(cmpss, regs, regd, 5)
535
536 #define cmpnless_m2r(var, reg) sse_m2ri(cmpss, var, reg, 6)
537 #define cmpnless_r2r(regs, regd) sse_r2ri(cmpss, regs, regd, 6)
538
539 #define cmpordss_m2r(var, reg) sse_m2ri(cmpss, var, reg, 7)
540 #define cmpordss_r2r(regs, regd) sse_r2ri(cmpss, regs, regd, 7)
541
542 #define comiss_m2r(var, reg) sse_m2r(comiss, var, reg)
543 #define comiss_r2r(regs, regd) sse_r2r(comiss, regs, regd)
544
545 #define ucomiss_m2r(var, reg) sse_m2r(ucomiss, var, reg)
546 #define ucomiss_r2r(regs, regd) sse_r2r(ucomiss, regs, regd)
547
548 #define unpcklps_m2r(var, reg) sse_m2r(unpcklps, var, reg)
549 #define unpcklps_r2r(regs, regd) sse_r2r(unpcklps, regs, regd)
550
551 #define unpckhps_m2r(var, reg) sse_m2r(unpckhps, var, reg)
552 #define unpckhps_r2r(regs, regd) sse_r2r(unpckhps, regs, regd)
553
554 #define fxrstor(mem) \
555 __asm__ __volatile__ ("fxrstor %0" \
556 : /* nothing */ \
557 : "X" (mem))
558
559 #define fxsave(mem) \
560 __asm__ __volatile__ ("fxsave %0" \
561 : /* nothing */ \
562 : "X" (mem))
563
564 #define stmxcsr(mem) \
565 __asm__ __volatile__ ("stmxcsr %0" \
566 : /* nothing */ \
567 : "X" (mem))
568
569 #define ldmxcsr(mem) \
570 __asm__ __volatile__ ("ldmxcsr %0" \
571 : /* nothing */ \
572 : "X" (mem))
573 #endif /*ARCH_X86 */
574
575
576
577 /* Optimized/fast memcpy */
578
579 /*
580 TODO : fix dll linkage problem for xine_fast_memcpy on win32
581
582 xine_fast_memcpy dll linkage is screwy here.
583 declaring as dllimport seems to fix the problem
584 but causes compiler warning with libxineutils
585 */
586 #ifdef _MSC_VER
587 __declspec( dllimport ) extern void *(* xine_fast_memcpy)(void *to, const void *from, size_t len);
588 #else
589 extern void *(* xine_fast_memcpy)(void *to, const void *from, size_t len);
590 #endif
591
592 #ifdef HAVE_XINE_INTERNAL_H
593 /* Benchmark available memcpy methods */
594 void xine_probe_fast_memcpy(xine_t *xine);
595 #endif
596
597
598 /*
599 * Debug stuff
600 */
601 /*
602 * profiling (unworkable in non DEBUG isn't defined)
603 */
604 void xine_profiler_init (void);
605 int xine_profiler_allocate_slot (char *label);
606 void xine_profiler_start_count (int id);
607 void xine_profiler_stop_count (int id);
608 void xine_profiler_print_results (void);
609
610 /*
611 * Allocate and clean memory size_t 'size', then return the pointer
612 * to the allocated memory.
613 */
614 #if !defined(__GNUC__) || __GNUC__ < 3
615 void *xine_xmalloc(size_t size);
616 #else
617 void *xine_xmalloc(size_t size) __attribute__ ((__malloc__));
618 #endif
619
620 /*
621 * Same as above, but memory is aligned to 'alignement'.
622 * **base is used to return pointer to un-aligned memory, use
623 * this to free the mem chunk
624 */
625 void *xine_xmalloc_aligned(size_t alignment, size_t size, void **base);
626
627 /*
628 * Get user home directory.
629 */
630 const char *xine_get_homedir(void);
631
632 /*
633 * Clean a string (remove spaces and '=' at the begin,
634 * and '\n', '\r' and spaces at the end.
635 */
636 char *xine_chomp (char *str);
637
638 /*
639 * A thread-safe usecond sleep
640 */
641 void xine_usec_sleep(unsigned usec);
642
643
644 /*
645 * Some string functions
646 */
647
648
649 void xine_strdupa(char *dest, char *src);
650 #define xine_strdupa(d, s) do { \
651 (d) = NULL; \
652 if((s) != NULL) { \
653 (d) = (char *) alloca(strlen((s)) + 1); \
654 strcpy((d), (s)); \
655 } \
656 } while(0)
657
658 /* Shamefully copied from glibc 2.2.3 */
659 #ifdef HAVE_STRPBRK
660 #define xine_strpbrk strpbrk
661 #else
662 static inline char *_private_strpbrk(const char *s, const char *accept) {
663
664 while(*s != '\0') {
665 const char *a = accept;
666 while(*a != '\0')
667 if(*a++ == *s)
668 return(char *) s;
669 ++s;
670 }
671
672 return NULL;
673 }
674 #define xine_strpbrk _private_strpbrk
675 #endif
676
677 #if defined HAVE_STRSEP && !defined(_MSC_VER)
678 #define xine_strsep strsep
679 #else
680 static inline char *_private_strsep(char **stringp, const char *delim) {
681 char *begin, *end;
682
683 begin = *stringp;
684 if(begin == NULL)
685 return NULL;
686
687 if(delim[0] == '\0' || delim[1] == '\0') {
688 char ch = delim[0];
689
690 if(ch == '\0')
691 end = NULL;
692 else {
693 if(*begin == ch)
694 end = begin;
695 else if(*begin == '\0')
696 end = NULL;
697 else
698 end = strchr(begin + 1, ch);
699 }
700 }
701 else
702 end = xine_strpbrk(begin, delim);
703
704 if(end) {
705 *end++ = '\0';
706 *stringp = end;
707 }
708 else
709 *stringp = NULL;
710
711 return begin;
712 }
713 #define xine_strsep _private_strsep
714 #endif
715
716
717 #ifdef HAVE_SETENV
718 #define xine_setenv setenv
719 #else
720 static inline void _private_setenv(const char *name, const char *val, int _xx) {
721 int len = strlen(name) + strlen(val) + 2;
722 char env[len];
723
724 sprintf(env, "%s%c%s", name, '=', val);
725 putenv(env);
726 }
727 #define xine_setenv _private_setenv
728 #endif
729
730 /*
731 * Color Conversion Utility Functions
732 * The following data structures and functions facilitate the conversion
733 * of RGB images to packed YUV (YUY2) images. There are also functions to
734 * convert from YUV9 -> YV12. All of the meaty details are written in
735 * color.c.
736 */
737
738 typedef struct yuv_planes_s {
739
740 unsigned char *y;
741 unsigned char *u;
742 unsigned char *v;
743 unsigned int row_width; /* frame width */
744 unsigned int row_count; /* frame height */
745
746 } yuv_planes_t;
747
748 void init_yuv_conversion(void);
749 void init_yuv_planes(yuv_planes_t *yuv_planes, int width, int height);
750 void free_yuv_planes(yuv_planes_t *yuv_planes);
751
752 extern void (*yuv444_to_yuy2)
753 (yuv_planes_t *yuv_planes, unsigned char *yuy2_map, int pitch);
754 extern void (*yuv9_to_yv12)
755 (unsigned char *y_src, int y_src_pitch, unsigned char *y_dest, int y_dest_pitch,
756 unsigned char *u_src, int u_src_pitch, unsigned char *u_dest, int u_dest_pitch,
757 unsigned char *v_src, int v_src_pitch, unsigned char *v_dest, int v_dest_pitch,
758 int width, int height);
759 extern void (*yuv411_to_yv12)
760 (unsigned char *y_src, int y_src_pitch, unsigned char *y_dest, int y_dest_pitch,
761 unsigned char *u_src, int u_src_pitch, unsigned char *u_dest, int u_dest_pitch,
762 unsigned char *v_src, int v_src_pitch, unsigned char *v_dest, int v_dest_pitch,
763 int width, int height);
764 extern void (*yv12_to_yuy2)
765 (unsigned char *y_src, int y_src_pitch,
766 unsigned char *u_src, int u_src_pitch,
767 unsigned char *v_src, int v_src_pitch,
768 unsigned char *yuy2_map, int yuy2_pitch,
769 int width, int height, int progressive);
770 extern void (*yuy2_to_yv12)
771 (unsigned char *yuy2_map, int yuy2_pitch,
772 unsigned char *y_dst, int y_dst_pitch,
773 unsigned char *u_dst, int u_dst_pitch,
774 unsigned char *v_dst, int v_dst_pitch,
775 int width, int height);
776
777 #define SCALEFACTOR 65536
778 #define CENTERSAMPLE 128
779
780 #define COMPUTE_Y(r, g, b) \
781 (unsigned char) \
782 ((y_r_table[r] + y_g_table[g] + y_b_table[b]) / SCALEFACTOR)
783 #define COMPUTE_U(r, g, b) \
784 (unsigned char) \
785 ((u_r_table[r] + u_g_table[g] + u_b_table[b]) / SCALEFACTOR + CENTERSAMPLE)
786 #define COMPUTE_V(r, g, b) \
787 (unsigned char) \
788 ((v_r_table[r] + v_g_table[g] + v_b_table[b]) / SCALEFACTOR + CENTERSAMPLE)
789
790 #define UNPACK_BGR15(packed_pixel, r, g, b) \
791 b = (packed_pixel & 0x7C00) >> 7; \
792 g = (packed_pixel & 0x03E0) >> 2; \
793 r = (packed_pixel & 0x001F) << 3;
794
795 #define UNPACK_BGR16(packed_pixel, r, g, b) \
796 b = (packed_pixel & 0xF800) >> 8; \
797 g = (packed_pixel & 0x07E0) >> 3; \
798 r = (packed_pixel & 0x001F) << 3;
799
800 #define UNPACK_RGB15(packed_pixel, r, g, b) \
801 r = (packed_pixel & 0x7C00) >> 7; \
802 g = (packed_pixel & 0x03E0) >> 2; \
803 b = (packed_pixel & 0x001F) << 3;
804
805 #define UNPACK_RGB16(packed_pixel, r, g, b) \
806 r = (packed_pixel & 0xF800) >> 8; \
807 g = (packed_pixel & 0x07E0) >> 3; \
808 b = (packed_pixel & 0x001F) << 3;
809
810 extern int y_r_table[256];
811 extern int y_g_table[256];
812 extern int y_b_table[256];
813
814 extern int u_r_table[256];
815 extern int u_g_table[256];
816 extern int u_b_table[256];
817
818 extern int v_r_table[256];
819 extern int v_g_table[256];
820 extern int v_b_table[256];
821
822 /* frame copying functions */
823 extern void yv12_to_yv12
824 (unsigned char *y_src, int y_src_pitch, unsigned char *y_dst, int y_dst_pitch,
825 unsigned char *u_src, int u_src_pitch, unsigned char *u_dst, int u_dst_pitch,
826 unsigned char *v_src, int v_src_pitch, unsigned char *v_dst, int v_dst_pitch,
827 int width, int height);
828 extern void yuy2_to_yuy2
829 (unsigned char *src, int src_pitch,
830 unsigned char *dst, int dst_pitch,
831 int width, int height);
832
833 /* print a hexdump of the given data */
834 void xine_hexdump (const char *buf, int length);
835
836 /*
837 * Optimization macros for conditions
838 * Taken from the FIASCO L4 microkernel sources
839 */
840 #if !defined(__GNUC__) || __GNUC__ < 3
841 # define EXPECT_TRUE(x) (x)
842 # define EXPECT_FALSE(x) (x)
843 #else
844 # define EXPECT_TRUE(x) __builtin_expect((x),1)
845 # define EXPECT_FALSE(x) __builtin_expect((x),0)
846 #endif
847
848 #ifdef NDEBUG
849 #define _x_assert(exp) \
850 do { \
851 if (!(exp)) \
852 fprintf(stderr, "assert: %s:%d: %s: Assertion `%s' failed.\n", \
853 __FILE__, __LINE__, __XINE_FUNCTION__, #exp); \
854 } while(0)
855 #else
856 #define _x_assert(exp) \
857 do { \
858 if (!(exp)) { \
859 fprintf(stderr, "assert: %s:%d: %s: Assertion `%s' failed.\n", \
860 __FILE__, __LINE__, __XINE_FUNCTION__, #exp); \
861 abort(); \
862 } \
863 } while(0)
864 #endif
865
866 #define _x_abort() \
867 do { \
868 fprintf(stderr, "abort: %s:%d: %s: Aborting.\n", \
869 __FILE__, __LINE__, __XINE_FUNCTION__); \
870 abort(); \
871 } while(0)
872
873
874 /****** logging with xine **********************************/
875
876 #ifndef LOG_MODULE
877 #define LOG_MODULE __FILE__
878 #endif /* LOG_MODULE */
879
880 #define LOG_MODULE_STRING printf("%s: ", LOG_MODULE );
881
882 #ifdef LOG_VERBOSE
883 #define LONG_LOG_MODULE_STRING \
884 printf("%s: (%s:%d) ", LOG_MODULE, __XINE_FUNCTION__, __LINE__ );
885 #else
886 #define LONG_LOG_MODULE_STRING LOG_MODULE_STRING
887 #endif /* LOG_VERBOSE */
888
889 #ifdef LOG
890 #ifdef __GNUC__
891 #define lprintf(fmt, args...) \
892 do { \
893 LONG_LOG_MODULE_STRING \
894 printf(fmt, ##args); \
895 } while(0)
896 #else /* __GNUC__ */
897 #ifdef _MSC_VER
898 #define lprintf(fmtargs) \
899 do { \
900 LONG_LOG_MODULE_STRING \
901 printf("%s", fmtargs); \
902 } while(0)
903 #else /* _MSC_VER */
904 #define lprintf(fmt, ...) \
905 do { \
906 LONG_LOG_MODULE_STRING \
907 printf(__VA_ARGS__); \
908 } while(0)
909 #endif /* _MSC_VER */
910 #endif /* __GNUC__ */
911 #else /* LOG */
912 #ifdef __GNUC__
913 #define lprintf(fmt, args...) do {} while(0)
914 #else
915 #ifdef _MSC_VER
916 #define lprintf
917 #else
918 #define lprintf(...) do {} while(0)
919 #endif /* _MSC_VER */
920 #endif /* __GNUC__ */
921 #endif /* LOG */
922
923 #ifdef __GNUC__
924 #define llprintf(cat, fmt, args...) \
925 do{ \
926 if(cat){ \
927 LONG_LOG_MODULE_STRING \
928 printf( fmt, ##args ); \
929 } \
930 }while(0)
931 #else
932 #ifdef _MSC_VER
933 #define llprintf(cat, fmtargs) \
934 do{ \
935 if(cat){ \
936 LONG_LOG_MODULE_STRING \
937 printf( "%s", fmtargs ); \
938 } \
939 }while(0)
940 #else
941 #define llprintf(cat, ...) \
942 do{ \
943 if(cat){ \
944 LONG_LOG_MODULE_STRING \
945 printf( __VA_ARGS__ ); \
946 } \
947 }while(0)
948 #endif /* _MSC_VER */
949 #endif /* __GNUC__ */
950
951 #ifdef __GNUC__
952 #define xprintf(xine, verbose, fmt, args...) \
953 do { \
954 if((xine) && (xine)->verbosity >= verbose){ \
955 xine_log(xine, XINE_LOG_TRACE, fmt, ##args); \
956 } \
957 } while(0)
958 #else
959 #ifdef _MSC_VER
960 #define xprintf(xine, verbose, fmtargs) \
961 do { \
962 if((xine) && (xine)->verbosity >= verbose){ \
963 xine_log(xine, XINE_LOG_TRACE, fmtargs); \
964 } \
965 } while(0)
966 #else
967 #define xprintf(xine, verbose, ...) \
968 do { \
969 if((xine) && (xine)->verbosity >= verbose){ \
970 xine_log(xine, XINE_LOG_TRACE, __VA_ARGS__); \
971 } \
972 } while(0)
973 #endif /* _MSC_VER */
974 #endif /* __GNUC__ */
975
976 /* time measuring macros for profiling tasks */
977
978 #ifdef DEBUG
979 # define XINE_PROFILE(function) \
980 do { \
981 struct timeval current_time; \
982 double dtime; \
983 gettimeofday(&current_time, NULL); \
984 dtime = -(current_time.tv_sec + (current_time.tv_usec / 1000000.0)); \
985 function; \
986 gettimeofday(&current_time, NULL); \
987 dtime += current_time.tv_sec + (current_time.tv_usec / 1000000.0); \
988 printf("%s: (%s:%d) took %lf seconds\n", \
989 LOG_MODULE, __XINE_FUNCTION__, __LINE__, dtime); \
990 } while(0)
991 # define XINE_PROFILE_ACCUMULATE(function) \
992 do { \
993 struct timeval current_time; \
994 static double dtime = 0; \
995 gettimeofday(&current_time, NULL); \
996 dtime -= current_time.tv_sec + (current_time.tv_usec / 1000000.0); \
997 function; \
998 gettimeofday(&current_time, NULL); \
999 dtime += current_time.tv_sec + (current_time.tv_usec / 1000000.0); \
1000 printf("%s: (%s:%d) took %lf seconds\n", \
1001 LOG_MODULE, __XINE_FUNCTION__, __LINE__, dtime); \
1002 } while(0)
1003 #else
1004 # define XINE_PROFILE(function) function
1005 # define XINE_PROFILE_ACCUMULATE(function) function
1006 #endif /* LOG */
1007
1008
1009 /******** double chained lists with builtin iterator *******/
1010
1011 typedef struct xine_node_s {
1012
1013 struct xine_node_s *next, *prev;
1014
1015 void *content;
1016
1017 int priority;
1018
1019 } xine_node_t;
1020
1021
1022 typedef struct {
1023
1024 xine_node_t *first, *last, *cur;
1025
1026 } xine_list_t;
1027
1028
1029
1030 xine_list_t *xine_list_new (void);
1031
1032
1033 /**
1034 * dispose the whole list.
1035 * note: disposes _only_ the list structure, content must be free()d elsewhere
1036 */
1037 void xine_list_free(xine_list_t *l);
1038
1039
1040 /**
1041 * returns: Boolean
1042 */
1043 int xine_list_is_empty (xine_list_t *l);
1044
1045 /**
1046 * return content of first entry in list.
1047 */
1048 void *xine_list_first_content (xine_list_t *l);
1049
1050 /**
1051 * return next content in list.
1052 */
1053 void *xine_list_next_content (xine_list_t *l);
1054
1055 /**
1056 * Return last content of list.
1057 */
1058 void *xine_list_last_content (xine_list_t *l);
1059
1060 /**
1061 * Return previous content of list.
1062 */
1063 void *xine_list_prev_content (xine_list_t *l);
1064
1065 /**
1066 * Append content to list, sorted by decreasing priority.
1067 */
1068 void xine_list_append_priority_content (xine_list_t *l, void *content, int priority);
1069
1070 /**
1071 * Append content to list.
1072 */
1073 void xine_list_append_content (xine_list_t *l, void *content);
1074
1075 /**
1076 * Insert content in list.
1077 */
1078 void xine_list_insert_content (xine_list_t *l, void *content);
1079
1080 /**
1081 * Remove current content in list.
1082 * note: removes only the list entry; content must be free()d elsewhere.
1083 */
1084 void xine_list_delete_current (xine_list_t *l);
1085
1086 #ifndef HAVE_BASENAME
1087 /*
1088 * get base name
1089 */
1090 char *basename (char const *name);
1091 #endif
1092
1093
1094 #ifdef __cplusplus
1095 }
1096 #endif
1097
1098 #endif