annotate libvo/fastmemcpy.h @ 480:787f2792beeb

now it accepts monitor_hfreq...
author szabii
date Mon, 16 Apr 2001 22:13:12 +0000
parents 9df257e7ef78
children aec3cad1e41a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
477
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
1
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
2 #ifndef __MPLAYER_MEMCPY
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
3 #define __MPLAYER_MEMCPY
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
4
358
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
5 /*
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
6 This part of code was taken by from Linux-2.4.3 and slightly modified
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
7 for MMX2 instruction set. I have done it since linux uses page aligned
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
8 blocks but mplayer uses weakly ordered data and original sources can not
376
63c47ec706cd P3 fixes...
arpi_esp
parents: 370
diff changeset
9 speedup their. Only using prefetchnta and movntq together have effect!
358
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
10 If you have questions please contact with me: Nick Kurshev: nickols_k@mail.ru.
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
11 */
477
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
12
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
13 // 3dnow memcpy support from kernel 2.4.2
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
14 // by Pontscho/fresh!mindworkz
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
15
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
16 #if defined( HAVE_MMX2 ) || defined( HAVE_3DNOW )
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
17
376
63c47ec706cd P3 fixes...
arpi_esp
parents: 370
diff changeset
18 /* for small memory blocks (<256 bytes) this version is faster */
63c47ec706cd P3 fixes...
arpi_esp
parents: 370
diff changeset
19 #define small_memcpy(to,from,n)\
63c47ec706cd P3 fixes...
arpi_esp
parents: 370
diff changeset
20 {\
63c47ec706cd P3 fixes...
arpi_esp
parents: 370
diff changeset
21 __asm__ __volatile__(\
63c47ec706cd P3 fixes...
arpi_esp
parents: 370
diff changeset
22 "rep ; movsb\n"\
63c47ec706cd P3 fixes...
arpi_esp
parents: 370
diff changeset
23 ::"D" (to), "S" (from),"c" (n)\
63c47ec706cd P3 fixes...
arpi_esp
parents: 370
diff changeset
24 : "memory");\
63c47ec706cd P3 fixes...
arpi_esp
parents: 370
diff changeset
25 }
358
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
26
370
baf3fe20eb23 __memcpy fix
arpi_esp
parents: 368
diff changeset
27 inline static void * fast_memcpy(void * to, const void * from, unsigned len)
358
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
28 {
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
29 void *p;
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
30 int i;
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
31
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
32 if(len >= 0x200) /* 512-byte blocks */
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
33 {
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
34 p = to;
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
35 i = len >> 6; /* len/64 */
376
63c47ec706cd P3 fixes...
arpi_esp
parents: 370
diff changeset
36 len&=63;
63c47ec706cd P3 fixes...
arpi_esp
parents: 370
diff changeset
37
358
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
38 __asm__ __volatile__ (
477
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
39 #if defined( HAVE_3DNOW ) && !defined( HAVE_MMX2 )
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
40 "prefetch (%0)\n"
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
41 "prefetch 64(%0)\n"
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
42 "prefetch 128(%0)\n"
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
43 "prefetch 192(%0)\n"
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
44 "prefetch 256(%0)\n"
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
45 #else
409
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
46 "prefetchnta (%0)\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
47 "prefetchnta 64(%0)\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
48 "prefetchnta 128(%0)\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
49 "prefetchnta 192(%0)\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
50 "prefetchnta 256(%0)\n"
477
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
51 #endif
358
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
52 : : "r" (from) );
409
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
53 /*
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
54 This algorithm is top effective when the code consequently
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
55 reads and writes blocks which have size of cache line.
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
56 Size of cache line is processor-dependent.
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
57 It will, however, be a minimum of 32 bytes on any processors.
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
58 It would be better to have a number of instructions which
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
59 perform reading and writing to be multiple to a number of
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
60 processor's decoders, but it's not always possible.
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
61 */
358
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
62 for(; i>0; i--)
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
63 {
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
64 __asm__ __volatile__ (
477
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
65 #if defined( HAVE_3DNOW ) && !defined( HAVE_MMX2 )
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
66 "prefetch 320(%0)\n"
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
67 #else
409
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
68 "prefetchnta 320(%0)\n"
477
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
69 #endif
409
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
70 #ifdef HAVE_SSE /* Only P3 (may be Cyrix3) */
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
71 "movups (%0), %%xmm0\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
72 "movups 16(%0), %%xmm1\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
73 "movntps %%xmm0, (%1)\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
74 "movntps %%xmm1, 16(%1)\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
75 "movups 32(%0), %%xmm0\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
76 "movups 48(%0), %%xmm1\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
77 "movntps %%xmm0, 32(%1)\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
78 "movntps %%xmm1, 48(%1)\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
79 #else /* Only K7 (may be other) */
477
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
80 #if defined( HAVE_3DNOW ) && !defined( HAVE_MMX2 )
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
81 "movq (%0), %%mm0\n"
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
82 "movq 8(%0), %%mm1\n"
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
83 "movq 16(%0), %%mm2\n"
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
84 "movq 24(%0), %%mm3\n"
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
85 "movq %%mm0, (%1)\n"
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
86 "movq %%mm1, 8(%1)\n"
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
87 "movq %%mm2, 16(%1)\n"
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
88 "movq %%mm3, 24(%1)\n"
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
89 "movq 32(%0), %%mm0\n"
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
90 "movq 40(%0), %%mm1\n"
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
91 "movq 48(%0), %%mm2\n"
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
92 "movq 56(%0), %%mm3\n"
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
93 "movq %%mm0, 32(%1)\n"
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
94 "movq %%mm1, 40(%1)\n"
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
95 "movq %%mm2, 48(%1)\n"
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
96 "movq %%mm3, 56(%1)\n"
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
97 #else
409
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
98 "movq (%0), %%mm0\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
99 "movq 8(%0), %%mm1\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
100 "movq 16(%0), %%mm2\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
101 "movq 24(%0), %%mm3\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
102 "movntq %%mm0, (%1)\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
103 "movntq %%mm1, 8(%1)\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
104 "movntq %%mm2, 16(%1)\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
105 "movntq %%mm3, 24(%1)\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
106 "movq 32(%0), %%mm0\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
107 "movq 40(%0), %%mm1\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
108 "movq 48(%0), %%mm2\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
109 "movq 56(%0), %%mm3\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
110 "movntq %%mm0, 32(%1)\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
111 "movntq %%mm1, 40(%1)\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
112 "movntq %%mm2, 48(%1)\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
113 "movntq %%mm3, 56(%1)\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
114 #endif
477
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
115 #endif
409
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
116 :: "r" (from), "r" (to) : "memory");
358
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
117 from+=64;
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
118 to+=64;
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
119 }
477
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
120 #if defined( HAVE_3DNOW ) && !defined( HAVE_MMX2 )
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
121 __asm__ __volatile__ ("femms":::"memory");
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
122 #else
409
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
123 __asm__ __volatile__ ("emms":::"memory");
477
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
124 #endif
358
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
125 }
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
126 /*
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
127 * Now do the tail of the block
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
128 */
477
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
129 #if 0
376
63c47ec706cd P3 fixes...
arpi_esp
parents: 370
diff changeset
130 small_memcpy(to, from, len);
477
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
131 #else
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
132 __asm__ __volatile__ (
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
133 "shrl $1,%%ecx\n"
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
134 "jnc 1f\n"
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
135 "movsb\n"
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
136 "1:\n"
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
137 "shrl $1,%%ecx\n"
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
138 "jnc 2f\n"
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
139 "movsw\n"
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
140 "2:\n"
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
141 "rep ; movsl\n"
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
142 ::"D" (to), "S" (from),"c" (len)
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
143 : "memory");
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
144 #endif
358
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
145 return p;
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
146 }
376
63c47ec706cd P3 fixes...
arpi_esp
parents: 370
diff changeset
147 #define memcpy(a,b,c) fast_memcpy(a,b,c)
477
a1ceb65cf6ab add 3dnow support
pontscho
parents: 409
diff changeset
148
358
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
149 #endif
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
150
478
9df257e7ef78 sorry, for the #endif
pontscho
parents: 477
diff changeset
151 #endif