2fb88a9ed82dc1bbf54a878bb6db417761d6b0d0
[sdk] / ecere / src / sys / memory.ec
1 namespace sys;
2
3 import "System"
4
5 public void MoveBytes(void * dest, const void * source, uint count)
6 {
7    memmove(dest, source, count);
8 }
9
10 public void CopyBytes(void * dest, const void * source, uint count)
11 {
12 #if !defined(ECERE_BOOTSTRAP) && (defined(__WATCOMC__) || defined(__MSC__) || defined(__BORLANDC__))
13    _asm
14    {
15       push esi      
16       push edi
17       push ecx
18
19       mov esi,source
20       mov edi,dest
21       mov ecx,count
22       rep movsb
23       
24       pop ecx
25       pop edi
26       pop esi
27    };
28 #elif !defined(ECERE_BOOTSTRAP) && (defined(__GNUC__) && defined(i386))
29    asm volatile(
30    //Set source & destination
31        "movl %0, %%esi\n\t"
32        "movl %1, %%edi\n\t"
33        "movl %2, %%ecx\n\t"
34
35        "rep\n\t"
36        "movsb\n\t"
37    ::"g"(source),"g"(dest),"g"(count)
38    :"ecx","esi","edi","memory");
39 #else
40    memcpy(dest,source,count);
41 #endif
42 }
43
44 public void CopyBytesBy2(void * dest, const void * source, uint count)
45 {
46 #if !defined(ECERE_BOOTSTRAP) && (defined(__WATCOMC__) || defined(__MSC__) || defined(__BORLANDC__))
47    _asm
48    {
49       push esi
50       push edi
51       push ecx
52
53       mov esi,source
54       mov edi,dest
55       mov ecx,count
56       rep movsw
57
58       pop ecx
59       pop edi
60       pop esi
61    };
62 #elif !defined(ECERE_BOOTSTRAP) && (defined(__GNUC__) && defined(i386))
63    asm volatile(
64    //Set source & destination
65        "movl %0, %%esi\n\t"
66        "movl %1, %%edi\n\t"
67        "movl %2, %%ecx\n\t"
68
69        "rep\n\t"
70        "movsw\n\t"
71    ::"g"(source),"g"(dest),"g"(count)
72    :"cx","si","di","memory");
73 #else
74    memcpy(dest,source,count<<1);
75 #endif
76 }
77
78 public void CopyBytesBy4(void * dest, const void * source, uint count)
79 {
80 #if !defined(ECERE_BOOTSTRAP) && (defined(__WATCOMC__) || defined(__MSC__) || defined(__BORLANDC__))
81    _asm
82    {
83       push esi
84       push edi
85       push ecx
86
87       mov esi,source
88       mov edi,dest
89       mov ecx,count
90       rep movsd
91       
92       pop ecx
93       pop edi
94       pop esi
95    };
96 #elif !defined(ECERE_BOOTSTRAP) && (defined(__GNUC__) && defined(i386))
97    asm volatile(
98    //Set source & destination
99        "movl %0, %%esi\n\t"
100        "movl %1, %%edi\n\t"
101        "movl %2, %%ecx\n\t"
102
103        "rep\n\t"
104        "movsl\n\t"
105    ::"g"(source),"g"(dest),"g"(count)
106    :"cx","si","di","memory");
107 #else
108    memcpy(dest,source,count<<2);
109 #endif
110 }
111
112 public void FillBytes(void * area, byte value, uint count)
113 {
114 #if !defined(ECERE_BOOTSTRAP) && (defined(__WATCOMC__) || defined(__MSC__) || defined(__BORLANDC__))
115    __asm
116    {
117       push edi
118       push ecx
119       push eax
120       mov edi,area
121       mov ecx,count
122       mov al,value
123       rep stosb
124       pop eax
125       pop ecx
126       pop edi
127    };
128 #elif !defined(ECERE_BOOTSTRAP) && (defined(__GNUC__) && defined(i386))
129    asm volatile(
130    //Set source & destination
131        "movl %0, %%edi\n\t"
132        "movl %1, %%ecx\n\t"
133        "movb %2, %%al\n\t"
134
135        "rep\n\t"
136        "stosb\n\t"
137    ::"g"(area),"g"(count),"g"(value)
138    :"ax","cx","di","memory");
139 #else
140    memset(area,value,count);
141 #endif
142 }
143
144 public void FillBytesBy2(void * area, uint16 value, uint count)
145 {
146 #if !defined(ECERE_BOOTSTRAP) && (defined(__WATCOMC__) || defined(__MSC__) || defined(__BORLANDC__))
147    _asm
148    {
149       push edi
150       push ecx
151       push eax
152
153       mov edi,area
154       mov ecx,count
155       mov ax,value
156       rep stosw
157       
158       pop eax
159       pop ecx
160       pop edi
161    };
162 #elif !defined(ECERE_BOOTSTRAP) && (defined(__GNUC__) && defined(i386))
163    asm volatile(
164    //Set source & destination
165        "movl %0, %%edi\n\t"
166        "movl %1, %%ecx\n\t"
167        "movw %2, %%ax\n\t"
168
169        "rep\n\t"
170        "stosw\n\t"
171    ::"g"(area),"g"(count),"g"(value)
172    :"ax","cx","di","memory");
173 #else
174    uint16 * dest = area;
175    int c;
176    for(c=0; c<count; c++) dest[c] = value;
177 #endif
178 }
179
180 public void FillBytesBy4(void * area, uint32 value, uint count)
181 {
182 #if !defined(ECERE_BOOTSTRAP) && (defined(__WATCOMC__) || defined(__MSC__) || defined(__BORLANDC__))
183    _asm
184    {
185       push edi
186       push ecx
187       push eax
188
189       mov edi,area
190       mov ecx,count
191       mov eax,value
192       rep stosd
193
194       pop eax
195       pop ecx
196       pop edi
197    };
198 #elif !defined(ECERE_BOOTSTRAP) && (defined(__GNUC__) && defined(i386))
199    asm volatile(
200    //Set source & destination
201        "movl %0, %%edi\n\t"
202        "movl %1, %%ecx\n\t"
203        "movl %2, %%eax\n\t"
204
205        "rep\n\t"
206        "stosl\n\t"
207    ::"g"(area),"g"(count),"g"(value)
208    :"ax","cx","di","memory");
209 #else
210    uint * dest = area;
211    int c;
212    for(c=0; c<count; c++) dest[c] = value;
213 #endif
214 }