annotate libvo/fastmemcpy.h @ 410:ad05b8b1aa7e

more sh_audio/sh_video cleanup, removed has_video
author arpi_esp
date Sat, 14 Apr 2001 18:09:46 +0000
parents 90a50c8e15b8
children a1ceb65cf6ab
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
358
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
1 /*
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
2 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
3 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
4 blocks but mplayer uses weakly ordered data and original sources can not
376
63c47ec706cd P3 fixes...
arpi_esp
parents: 370
diff changeset
5 speedup their. Only using prefetchnta and movntq together have effect!
358
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
6 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
7 */
376
63c47ec706cd P3 fixes...
arpi_esp
parents: 370
diff changeset
8 #ifdef HAVE_MMX2
63c47ec706cd P3 fixes...
arpi_esp
parents: 370
diff changeset
9 /* for small memory blocks (<256 bytes) this version is faster */
63c47ec706cd P3 fixes...
arpi_esp
parents: 370
diff changeset
10 #define small_memcpy(to,from,n)\
63c47ec706cd P3 fixes...
arpi_esp
parents: 370
diff changeset
11 {\
63c47ec706cd P3 fixes...
arpi_esp
parents: 370
diff changeset
12 __asm__ __volatile__(\
63c47ec706cd P3 fixes...
arpi_esp
parents: 370
diff changeset
13 "rep ; movsb\n"\
63c47ec706cd P3 fixes...
arpi_esp
parents: 370
diff changeset
14 ::"D" (to), "S" (from),"c" (n)\
63c47ec706cd P3 fixes...
arpi_esp
parents: 370
diff changeset
15 : "memory");\
63c47ec706cd P3 fixes...
arpi_esp
parents: 370
diff changeset
16 }
358
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
17
370
baf3fe20eb23 __memcpy fix
arpi_esp
parents: 368
diff changeset
18 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
19 {
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
20 void *p;
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
21 int i;
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
22
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
23 if(len >= 0x200) /* 512-byte blocks */
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
24 {
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
25 p = to;
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
26 i = len >> 6; /* len/64 */
376
63c47ec706cd P3 fixes...
arpi_esp
parents: 370
diff changeset
27 len&=63;
63c47ec706cd P3 fixes...
arpi_esp
parents: 370
diff changeset
28
358
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
29 __asm__ __volatile__ (
409
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
30 "prefetchnta (%0)\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
31 "prefetchnta 64(%0)\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
32 "prefetchnta 128(%0)\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
33 "prefetchnta 192(%0)\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
34 "prefetchnta 256(%0)\n"
358
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
35 : : "r" (from) );
409
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
36 /*
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
37 This algorithm is top effective when the code consequently
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
38 reads and writes blocks which have size of cache line.
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
39 Size of cache line is processor-dependent.
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
40 It will, however, be a minimum of 32 bytes on any processors.
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
41 It would be better to have a number of instructions which
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
42 perform reading and writing to be multiple to a number of
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
43 processor's decoders, but it's not always possible.
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
44 */
358
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
45 for(; i>0; i--)
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
46 {
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
47 __asm__ __volatile__ (
409
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
48 "prefetchnta 320(%0)\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
49 #ifdef HAVE_SSE /* Only P3 (may be Cyrix3) */
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
50 "movups (%0), %%xmm0\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
51 "movups 16(%0), %%xmm1\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
52 "movntps %%xmm0, (%1)\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
53 "movntps %%xmm1, 16(%1)\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
54 "movups 32(%0), %%xmm0\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
55 "movups 48(%0), %%xmm1\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
56 "movntps %%xmm0, 32(%1)\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
57 "movntps %%xmm1, 48(%1)\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
58 #else /* Only K7 (may be other) */
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
59 "movq (%0), %%mm0\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
60 "movq 8(%0), %%mm1\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
61 "movq 16(%0), %%mm2\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
62 "movq 24(%0), %%mm3\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
63 "movntq %%mm0, (%1)\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
64 "movntq %%mm1, 8(%1)\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
65 "movntq %%mm2, 16(%1)\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
66 "movntq %%mm3, 24(%1)\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
67 "movq 32(%0), %%mm0\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
68 "movq 40(%0), %%mm1\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
69 "movq 48(%0), %%mm2\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
70 "movq 56(%0), %%mm3\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
71 "movntq %%mm0, 32(%1)\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
72 "movntq %%mm1, 40(%1)\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
73 "movntq %%mm2, 48(%1)\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
74 "movntq %%mm3, 56(%1)\n"
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
75 #endif
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
76 :: "r" (from), "r" (to) : "memory");
358
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
77 from+=64;
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
78 to+=64;
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
79 }
409
90a50c8e15b8 - applied SSE patch by Nick Kurshev
atmosfear
parents: 376
diff changeset
80 __asm__ __volatile__ ("emms":::"memory");
358
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
81 }
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
82 /*
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
83 * Now do the tail of the block
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
84 */
376
63c47ec706cd P3 fixes...
arpi_esp
parents: 370
diff changeset
85 small_memcpy(to, from, len);
358
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
86 return p;
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
87 }
376
63c47ec706cd P3 fixes...
arpi_esp
parents: 370
diff changeset
88 #define memcpy(a,b,c) fast_memcpy(a,b,c)
358
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
89 #endif
223439e2de87 fast memcpy() using x86 asm or mmxext
arpi_esp
parents:
diff changeset
90
370
baf3fe20eb23 __memcpy fix
arpi_esp
parents: 368
diff changeset
91