Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5131 | clevermous | 1 | /* |
2 | SDL - Simple DirectMedia Layer |
||
3 | Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga |
||
4 | |||
5 | This library is free software; you can redistribute it and/or |
||
6 | modify it under the terms of the GNU Library General Public |
||
7 | License as published by the Free Software Foundation; either |
||
8 | version 2 of the License, or (at your option) any later version. |
||
9 | |||
10 | This library is distributed in the hope that it will be useful, |
||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||
13 | Library General Public License for more details. |
||
14 | |||
15 | You should have received a copy of the GNU Library General Public |
||
16 | License along with this library; if not, write to the Free |
||
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
18 | |||
19 | Sam Lantinga |
||
20 | slouken@devolution.com |
||
21 | */ |
||
22 | |||
23 | #ifdef SAVE_RCSID |
||
24 | static char rcsid = |
||
25 | "@(#) $Id: SDL_memops.h,v 1.2 2001/04/26 16:50:18 hercules Exp $"; |
||
26 | #endif |
||
27 | |||
28 | #ifndef _SDL_memops_h |
||
29 | #define _SDL_memops_h |
||
30 | |||
31 | /* System dependent optimized memory manipulation routines: |
||
32 | */ |
||
33 | #include |
||
34 | |||
35 | #if defined(__GNUC__) && defined(i386) |
||
36 | /* Thanks to Brennan "Bas" Underwood, for the inspiration. :) |
||
37 | */ |
||
38 | #define SDL_memcpy(dst, src, len) \ |
||
39 | do { \ |
||
40 | int u0, u1, u2; \ |
||
41 | __asm__ __volatile__ ( \ |
||
42 | "cld\n\t" \ |
||
43 | "rep ; movsl\n\t" \ |
||
44 | "testb $2,%b4\n\t" \ |
||
45 | "je 1f\n\t" \ |
||
46 | "movsw\n" \ |
||
47 | "1:\ttestb $1,%b4\n\t" \ |
||
48 | "je 2f\n\t" \ |
||
49 | "movsb\n" \ |
||
50 | "2:" \ |
||
51 | : "=&c" (u0), "=&D" (u1), "=&S" (u2) \ |
||
52 | : "0" ((unsigned)(len)/4), "q" (len), "1" (dst),"2" (src) \ |
||
53 | : "memory" ); \ |
||
54 | } while(0) |
||
55 | |||
56 | #define SDL_memcpy4(dst, src, len) \ |
||
57 | do { \ |
||
58 | int ecx, edi, esi; \ |
||
59 | __asm__ __volatile__ ( \ |
||
60 | "cld\n\t" \ |
||
61 | "rep ; movsl" \ |
||
62 | : "=&c" (ecx), "=&D" (edi), "=&S" (esi) \ |
||
63 | : "0" ((unsigned)(len)), "1" (dst), "2" (src) \ |
||
64 | : "memory" ); \ |
||
65 | } while(0) |
||
66 | |||
67 | #define SDL_revcpy(dst, src, len) \ |
||
68 | do { \ |
||
69 | int u0, u1, u2; \ |
||
70 | char *dstp = (char *)(dst); \ |
||
71 | char *srcp = (char *)(src); \ |
||
72 | int n = (len); \ |
||
73 | if ( n >= 4 ) { \ |
||
74 | __asm__ __volatile__ ( \ |
||
75 | "std\n\t" \ |
||
76 | "rep ; movsl\n\t" \ |
||
77 | : "=&c" (u0), "=&D" (u1), "=&S" (u2) \ |
||
78 | : "0" (n >> 2), \ |
||
79 | "1" (dstp+(n-4)), "2" (srcp+(n-4)) \ |
||
80 | : "memory" ); \ |
||
81 | } \ |
||
82 | switch (n & 3) { \ |
||
83 | case 3: dstp[2] = srcp[2]; \ |
||
84 | case 2: dstp[1] = srcp[1]; \ |
||
85 | case 1: dstp[0] = srcp[0]; \ |
||
86 | break; \ |
||
87 | default: \ |
||
88 | break; \ |
||
89 | } \ |
||
90 | } while(0) |
||
91 | |||
92 | #define SDL_memmove(dst, src, len) \ |
||
93 | do { \ |
||
94 | if ( (dst) < (src) ) { \ |
||
95 | SDL_memcpy((dst), (src), (len)); \ |
||
96 | } else { \ |
||
97 | SDL_revcpy((dst), (src), (len)); \ |
||
98 | } \ |
||
99 | } while(0) |
||
100 | |||
101 | #define SDL_memset4(dst, val, len) \ |
||
102 | do { \ |
||
103 | int u0, u1, u2; \ |
||
104 | __asm__ __volatile__ ( \ |
||
105 | "cld\n\t" \ |
||
106 | "rep ; stosl\n\t" \ |
||
107 | : "=&D" (u0), "=&a" (u1), "=&c" (u2) \ |
||
108 | : "0" (dst), "1" (val), "2" ((Uint32)(len)) \ |
||
109 | : "memory" ); \ |
||
110 | } while(0) |
||
111 | |||
112 | #endif /* GNU C and x86 */ |
||
113 | |||
114 | /* If there are no optimized versions, define the normal versions */ |
||
115 | #ifndef SDL_memcpy |
||
116 | #define SDL_memcpy(dst, src, len) memcpy(dst, src, len) |
||
117 | #endif |
||
118 | |||
119 | #ifndef SDL_memcpy4 |
||
120 | #define SDL_memcpy4(dst, src, len) memcpy(dst, src, (len) << 2) |
||
121 | #endif |
||
122 | |||
123 | #ifndef SDL_revcpy |
||
124 | #define SDL_revcpy(dst, src, len) memmove(dst, src, len) |
||
125 | #endif |
||
126 | |||
127 | #ifndef SDL_memset4 |
||
128 | #define SDL_memset4(dst, val, len) \ |
||
129 | do { \ |
||
130 | unsigned _count = (len); \ |
||
131 | unsigned _n = (_count + 3) / 4; \ |
||
132 | Uint32 *_p = (Uint32 *)(dst); \ |
||
133 | Uint32 _val = (val); \ |
||
134 | switch (_count % 4) { \ |
||
135 | case 0: do { *_p++ = _val; \ |
||
136 | case 3: *_p++ = _val; \ |
||
137 | case 2: *_p++ = _val; \ |
||
138 | case 1: *_p++ = _val; \ |
||
139 | } while ( --_n ); \ |
||
140 | } \ |
||
141 | } while(0) |
||
142 | #endif |
||
143 | |||
144 | #endif /* _SDL_memops_h */><>> |