Rev 532 | Rev 1702 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 532 | Rev 534 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (C) 2005 Sergey Bondari |
2 | * Copyright (C) 2005 Sergey Bondari |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | #ifndef __ia32_MEMSTR_H__ |
29 | #ifndef __ia32_MEMSTR_H__ |
30 | #define __ia32_MEMSTR_H__ |
30 | #define __ia32_MEMSTR_H__ |
31 | 31 | ||
32 | /** Copy memory |
32 | /** Copy memory |
33 | * |
33 | * |
34 | * Copy a given number of bytes (3rd argument) |
34 | * Copy a given number of bytes (3rd argument) |
35 | * from the memory location defined by 2nd argument |
35 | * from the memory location defined by 2nd argument |
36 | * to the memory location defined by 1st argument. |
36 | * to the memory location defined by 1st argument. |
37 | * The memory areas cannot overlap. |
37 | * The memory areas cannot overlap. |
38 | * |
38 | * |
39 | * @param dst Destination |
39 | * @param dst Destination |
40 | * @param src Source |
40 | * @param src Source |
41 | * @param cnt Number of bytes |
41 | * @param cnt Number of bytes |
42 | * @return Destination |
42 | * @return Destination |
43 | */ |
43 | */ |
44 | static inline void * memcpy(void * dst, const void * src, size_t cnt) |
44 | static inline void * memcpy(void * dst, const void * src, size_t cnt) |
45 | { |
45 | { |
46 | __native d0, d1, d2; |
46 | __native d0, d1, d2; |
47 | 47 | ||
48 | __asm__ __volatile__( |
48 | __asm__ __volatile__( |
49 | /* copy all full dwords */ |
49 | /* copy all full dwords */ |
50 | "rep movsl\n\t" |
50 | "rep movsl\n\t" |
51 | /* load count again */ |
51 | /* load count again */ |
52 | "movl %4, %%ecx\n\t" |
52 | "movl %4, %%ecx\n\t" |
53 | /* ecx = ecx mod 4 */ |
53 | /* ecx = ecx mod 4 */ |
54 | "andl $3, %%ecx\n\t" |
54 | "andl $3, %%ecx\n\t" |
55 | /* are there last <=3 bytes? */ |
55 | /* are there last <=3 bytes? */ |
56 | "jz 1f\n\t" |
56 | "jz 1f\n\t" |
57 | /* copy last <=3 bytes */ |
57 | /* copy last <=3 bytes */ |
58 | "rep movsb\n\t" |
58 | "rep movsb\n\t" |
59 | /* exit from asm block */ |
59 | /* exit from asm block */ |
60 | "1:\n" |
60 | "1:\n" |
61 | : "=&c" (d0), "=&D" (d1), "=&S" (d2) |
61 | : "=&c" (d0), "=&D" (d1), "=&S" (d2) |
62 | : "0" ((__native) (cnt / 4)), "g" ((__native) cnt), "1" ((__native) dst), "2" ((__native) src) |
62 | : "0" ((__native) (cnt / 4)), "g" ((__native) cnt), "1" ((__native) dst), "2" ((__native) src) |
63 | : "memory"); |
63 | : "memory"); |
64 | 64 | ||
65 | return dst; |
65 | return dst; |
66 | } |
66 | } |
67 | 67 | ||
68 | 68 | ||
69 | /** Compare memory regions for equality |
69 | /** Compare memory regions for equality |
70 | * |
70 | * |
71 | * Compare a given number of bytes (3rd argument) |
71 | * Compare a given number of bytes (3rd argument) |
72 | * at memory locations defined by 1st and 2nd argument |
72 | * at memory locations defined by 1st and 2nd argument |
73 | * for equality. If bytes are equal function returns 0. |
73 | * for equality. If bytes are equal function returns 0. |
74 | * |
74 | * |
75 | * @param src Region 1 |
75 | * @param src Region 1 |
76 | * @param dst Region 2 |
76 | * @param dst Region 2 |
77 | * @param cnt Number of bytes |
77 | * @param cnt Number of bytes |
78 | * @return Zero if bytes are equal, non-zero otherwise |
78 | * @return Zero if bytes are equal, non-zero otherwise |
79 | */ |
79 | */ |
80 | static inline int memcmp(const void * src, const void * dst, size_t cnt) |
80 | static inline int memcmp(const void * src, const void * dst, size_t cnt) |
81 | { |
81 | { |
82 | __u32 d0, d1, d2; |
82 | __u32 d0, d1, d2; |
83 | int ret; |
83 | int ret; |
84 | 84 | ||
85 | __asm__ ( |
85 | __asm__ ( |
86 | "repe cmpsb\n\t" |
86 | "repe cmpsb\n\t" |
87 | "je 1f\n\t" |
87 | "je 1f\n\t" |
88 | "movl %3, %0\n\t" |
88 | "movl %3, %0\n\t" |
89 | "addl $1, %0\n\t" |
89 | "addl $1, %0\n\t" |
90 | "1:\n" |
90 | "1:\n" |
91 | : "=a" (ret), "=%S" (d0), "=&D" (d1), "=&c" (d2) |
91 | : "=a" (ret), "=%S" (d0), "=&D" (d1), "=&c" (d2) |
92 | : "0" (0), "1" ((__native) src), "2" ((__native) dst), "3" ((__native) cnt) |
92 | : "0" (0), "1" ((__native) src), "2" ((__native) dst), "3" ((__native) cnt) |
93 | ); |
93 | ); |
94 | 94 | ||
95 | return ret; |
95 | return ret; |
96 | } |
96 | } |
97 | 97 | ||
98 | /** Fill memory with words |
98 | /** Fill memory with words |
99 | * Fill a given number of words (2nd argument) |
99 | * Fill a given number of words (2nd argument) |
100 | * at memory defined by 1st argument with the |
100 | * at memory defined by 1st argument with the |
101 | * word value defined by 3rd argument. |
101 | * word value defined by 3rd argument. |
102 | * |
102 | * |
103 | * @param dst Destination |
103 | * @param dst Destination |
104 | * @param cnt Number of words |
104 | * @param cnt Number of words |
105 | * @param x Value to fill |
105 | * @param x Value to fill |
106 | */ |
106 | */ |
107 | static inline void memsetw(__address dst, size_t cnt, __u16 x) |
107 | static inline void memsetw(__address dst, size_t cnt, __u16 x) |
108 | { |
108 | { |
109 | __u32 d0, d1; |
109 | __u32 d0, d1; |
110 | 110 | ||
111 | __asm__ __volatile__ ( |
111 | __asm__ __volatile__ ( |
112 | "rep stosw\n\t" |
112 | "rep stosw\n\t" |
113 | : "=&D" (d0), "=&c" (d1), "=a" (x) |
113 | : "=&D" (d0), "=&c" (d1), "=a" (x) |
114 | : "0" (dst), "1" (cnt), "2" (x) |
114 | : "0" (dst), "1" (cnt), "2" (x) |
115 | : "memory" |
115 | : "memory" |
116 | ); |
116 | ); |
117 | 117 | ||
118 | } |
118 | } |
119 | 119 | ||
120 | /** Fill memory with bytes |
120 | /** Fill memory with bytes |
121 | * Fill a given number of bytes (2nd argument) |
121 | * Fill a given number of bytes (2nd argument) |
122 | * at memory defined by 1st argument with the |
122 | * at memory defined by 1st argument with the |
123 | * word value defined by 3rd argument. |
123 | * word value defined by 3rd argument. |
124 | * |
124 | * |
125 | * @param dst Destination |
125 | * @param dst Destination |
126 | * @param cnt Number of bytes |
126 | * @param cnt Number of bytes |
127 | * @param x Value to fill |
127 | * @param x Value to fill |
128 | */ |
128 | */ |
129 | static inline void memsetb(__address dst, size_t cnt, __u8 x) |
129 | static inline void memsetb(__address dst, size_t cnt, __u8 x) |
130 | { |
130 | { |
131 | __u32 d0, d1; |
131 | __u32 d0, d1; |
132 | 132 | ||
133 | __asm__ __volatile__ ( |
133 | __asm__ __volatile__ ( |
134 | "rep stosb\n\t" |
134 | "rep stosb\n\t" |
135 | : "=&D" (d0), "=&c" (d1), "=a" (x) |
135 | : "=&D" (d0), "=&c" (d1), "=a" (x) |
136 | : "0" (dst), "1" (cnt), "2" (x) |
136 | : "0" (dst), "1" (cnt), "2" (x) |
137 | : "memory" |
137 | : "memory" |
138 | ); |
138 | ); |
139 | 139 | ||
140 | } |
140 | } |
141 | 141 | ||
142 | #endif |
142 | #endif |
143 | 143 |