author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 31 Aug 2010 16:34:26 +0300 | |
branch | RCL_3 |
changeset 43 | c1f20ce4abcf |
parent 0 | a41df078684a |
child 44 | 3e88ff8f41d5 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1994-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 |
// All rights reserved. |
|
3 |
// This component and the accompanying materials are made available |
|
4 |
// under the terms of the License "Eclipse Public License v1.0" |
|
5 |
// which accompanies this distribution, and is available |
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 |
// |
|
8 |
// Initial Contributors: |
|
9 |
// Nokia Corporation - initial contribution. |
|
10 |
// |
|
11 |
// Contributors: |
|
12 |
// |
|
13 |
// Description: |
|
14 |
// e32\common\mem.cpp |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
#include "common.h" |
|
19 |
||
20 |
//This is used in heap.cpp and it is defined here, as a requirement for patchdata |
|
21 |
EXPORT_D extern const TInt KHeapMinCellSize = 0; |
|
22 |
EXPORT_D extern const TInt KHeapShrinkHysRatio = RHeap::EShrinkRatioDflt; |
|
23 |
//NOTE - if these values are changed then the WINS test case value must be updated |
|
24 |
||
25 |
#ifndef __MEM_MACHINE_CODED__ |
|
26 |
||
27 |
extern "C" { |
|
28 |
||
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
29 |
#ifndef __MEMMOVE_MACHINE_CODED__ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
30 |
|
0 | 31 |
// See header file e32cmn.h for the in-source documentation. |
32 |
EXPORT_C TAny* memcpy(TAny* aTrg, const TAny* aSrc, unsigned int aLength) |
|
33 |
{ |
|
34 |
return memmove(aTrg, aSrc, aLength); |
|
35 |
} |
|
36 |
||
37 |
||
38 |
||
39 |
// See header file e32cmn.h for the in-source documentation. |
|
40 |
EXPORT_C TAny* memmove(TAny* aTrg, const TAny* aSrc, unsigned int aLength) |
|
41 |
{ |
|
42 |
if (aLength==0) |
|
43 |
return((TUint8*)aTrg); |
|
44 |
TInt aLen32=0; |
|
45 |
TUint32* pT32=(TUint32*)aTrg; |
|
46 |
const TUint32* pS32=(TUint32 *)aSrc; |
|
47 |
if (((TInt)pT32&3)==0 && ((TInt)pS32&3)==0) |
|
48 |
aLen32=aLength>>2; |
|
49 |
TInt aLen8=aLength-(aLen32<<2); |
|
50 |
TUint32* pE32=pT32+aLen32; |
|
51 |
TUint8* pT; |
|
52 |
TUint8* pE; |
|
53 |
TUint8* pS; |
|
54 |
if (aTrg<aSrc) |
|
55 |
{ |
|
56 |
pS32=(TUint32*)aSrc; |
|
57 |
while (pT32<pE32) |
|
58 |
*pT32++=(*pS32++); |
|
59 |
pT=(TUint8*)pT32; |
|
60 |
pS=(TUint8*)pS32; |
|
61 |
pE=(TUint8*)aTrg+aLength; |
|
62 |
while (pT<pE) |
|
63 |
*pT++=(*pS++); |
|
64 |
} |
|
65 |
else if (aTrg>aSrc) |
|
66 |
{ |
|
67 |
pT=(TUint8*)(pT32+aLen32); |
|
68 |
pE=pT+aLen8; |
|
69 |
pS=(TUint8*)aSrc+aLength; |
|
70 |
while (pE>pT) |
|
71 |
*--pE=(*--pS); |
|
72 |
pS32=(TUint32*)pS; |
|
73 |
while (pE32>pT32) |
|
74 |
*--pE32=(*--pS32); |
|
75 |
} |
|
76 |
return aTrg; |
|
77 |
} |
|
78 |
||
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
79 |
#endif // ! __MEMMOVE_MACHINE_CODED__ |
0 | 80 |
|
81 |
// See header file e32cmn.h for the in-source documentation. |
|
82 |
EXPORT_C TAny* memclr(TAny* aTrg, unsigned int aLength) |
|
83 |
{ |
|
84 |
return memset(aTrg, 0, aLength); |
|
85 |
} |
|
86 |
||
87 |
||
88 |
||
89 |
// See header file e32cmn.h for the in-source documentation. |
|
90 |
EXPORT_C TAny* memset(TAny* aTrg, TInt aValue, unsigned int aLength) |
|
91 |
{ |
|
92 |
TInt aLen32=0; |
|
93 |
TUint32 *pM32=(TUint32 *)aTrg; |
|
94 |
if (((TInt)aTrg&3)==0) |
|
95 |
{ |
|
96 |
aLen32=aLength>>2; |
|
97 |
TUint32 *pE32=pM32+aLen32; |
|
98 |
TUint c = aValue & 0xff; |
|
99 |
TUint32 fillChar=c+(c<<8)+(c<<16)+(c<<24); |
|
100 |
while (pM32<pE32) |
|
101 |
*pM32++=fillChar; |
|
102 |
} |
|
103 |
TInt aLen8=aLength-(aLen32<<2); |
|
104 |
TUint8 *pM=(TUint8 *)pM32; |
|
105 |
TUint8 *pE=pM+aLen8; |
|
106 |
while (pM<pE) |
|
107 |
*pM++=TUint8(aValue); |
|
108 |
return aTrg; |
|
109 |
} |
|
110 |
||
111 |
} // extern "C" |
|
112 |
||
113 |
extern "C" { |
|
114 |
||
115 |
||
116 |
||
117 |
// See header file e32cmn.h for the in-source documentation. |
|
118 |
EXPORT_C TAny* wordmove(TAny* aTrg, const TAny* aSrc, unsigned int aLength) |
|
119 |
{ |
|
120 |
__ASSERT_DEBUG((aLength&3)==0,Panic(EWordMoveLengthNotMultipleOf4)); |
|
121 |
__ASSERT_DEBUG((((TUint)aSrc)&3)==0,Panic(EWordMoveSourceNotAligned)); |
|
122 |
__ASSERT_DEBUG((((TUint)aTrg)&3)==0,Panic(EWordMoveTargetNotAligned)); |
|
123 |
if (aLength==0) |
|
124 |
return((TUint8*)aTrg); |
|
125 |
TInt len=aLength>>2; |
|
126 |
TUint32* pT=(TUint32*)aTrg; |
|
127 |
const TUint32* pS=(const TUint32*)aSrc; |
|
128 |
const TUint32* pE=pS+len; |
|
129 |
if (pT<pS) |
|
130 |
{ |
|
131 |
while (pS<pE) |
|
132 |
*pT++=(*pS++); |
|
133 |
} |
|
134 |
else if (pT>pS) |
|
135 |
{ |
|
136 |
pT+=len; |
|
137 |
while (pE>pS) |
|
138 |
*--pT=(*--pE); |
|
139 |
} |
|
140 |
return aTrg; |
|
141 |
} |
|
142 |
||
143 |
||
144 |
||
145 |
||
146 |
// See header file e32cmn.h for the in-source documentation. |
|
147 |
EXPORT_C TInt memcompare(const TUint8* aLeft, TInt aLeftL, const TUint8* aRight, TInt aRightL) |
|
148 |
{ |
|
149 |
||
150 |
__ASSERT_DEBUG(aLeftL>=0,Panic(EMemLeftNegative)); |
|
151 |
__ASSERT_DEBUG(aRightL>=0,Panic(EMemRightNegative)); |
|
152 |
const TUint8 *pE=aLeft+Min(aLeftL,aRightL); |
|
153 |
while (aLeft<pE) |
|
154 |
{ |
|
155 |
TInt d=(*aLeft++)-(*aRight++); |
|
156 |
if (d!=0) |
|
157 |
return(d); |
|
158 |
} |
|
159 |
return(aLeftL-aRightL); |
|
160 |
} |
|
161 |
||
162 |
} // extern "C" |
|
163 |
||
164 |
||
165 |
||
166 |
||
167 |
#if defined(__GCC32__) && !defined(__KERNEL_MODE__) |
|
168 |
/** |
|
169 |
Compares a block of data at one specified location with a block of data at |
|
170 |
another specified location. |
|
171 |
||
172 |
The comparison proceeds on a byte for byte basis, the result of the comparison |
|
173 |
is based on the difference of the first bytes to disagree. |
|
174 |
||
175 |
The data at the two locations are equal if they have the same length and content. |
|
176 |
Where the lengths are different and the shorter section of data is the same |
|
177 |
as the first part of the longer section of data, the shorter is considered |
|
178 |
to be less than the longer. |
|
179 |
||
180 |
@param aLeft A pointer to the first (or left) block of 8 bit data |
|
181 |
to be compared. |
|
182 |
@param aLeftL The length of the first (or left) block of data to be compared, |
|
183 |
i.e. the number of bytes. |
|
184 |
@param aRight A pointer to the second (or right) block of 8 bit data to be |
|
185 |
compared. |
|
186 |
@param aRightL The length of the second (or right) block of data to be compared |
|
187 |
i.e. the number of bytes. |
|
188 |
||
189 |
@return Positive, if the first (or left) block of data is greater than the |
|
190 |
second (or right) block of data. |
|
191 |
Negative, if the first (or left) block of data is less than the |
|
192 |
second (or right) block of data. |
|
193 |
Zero, if both the first (or left) and second (or right) blocks of data |
|
194 |
have the same length and the same content. |
|
195 |
*/ |
|
196 |
EXPORT_C TInt Mem::Compare(const TUint8* aLeft, TInt aLeftL, const TUint8* aRight, TInt aRightL) |
|
197 |
{ |
|
198 |
memcompare(aLeft, aLeftL, aRight, aRightL); |
|
199 |
} |
|
200 |
#endif |
|
201 |
||
202 |
#else // __MEM_MACHINE_CODED__ |
|
203 |
||
204 |
#if defined(_DEBUG) && defined(__CPU_ARM) |
|
205 |
||
206 |
GLDEF_C void PanicEWordMoveLengthNotMultipleOf4() |
|
207 |
{ |
|
208 |
Panic(EWordMoveLengthNotMultipleOf4); |
|
209 |
} |
|
210 |
||
211 |
GLDEF_C void PanicEWordMoveSourceNotAligned() |
|
212 |
{ |
|
213 |
Panic(EWordMoveSourceNotAligned); |
|
214 |
} |
|
215 |
||
216 |
GLDEF_C void PanicEWordMoveTargetNotAligned() |
|
217 |
{ |
|
218 |
Panic(EWordMoveTargetNotAligned); |
|
219 |
} |
|
220 |
||
221 |
#endif |
|
222 |
||
223 |
#endif // __MEM_MACHINE_CODED__ |
|
224 |
||
225 |
#ifndef __KERNEL_MODE__ |
|
226 |
// |
|
227 |
// Dummy class for Binary Compatibility purposes |
|
228 |
// |
|
229 |
class Mem1 |
|
230 |
{ |
|
231 |
public: |
|
232 |
IMPORT_C static TUint8* Copy(TAny* aTrg,const TAny* aSrc,TInt aLength); |
|
233 |
IMPORT_C static TUint8* Move(TAny* aTrg,const TAny* aSrc,TInt aLength); |
|
234 |
IMPORT_C static void Fill(TAny* aTrg,TInt aLength,TChar aChar); |
|
235 |
}; |
|
236 |
EXPORT_C void Mem1::Fill(TAny* aTrg,TInt aLength,TChar aChar) |
|
237 |
{ Mem::Fill(aTrg,aLength,aChar); } |
|
238 |
EXPORT_C TUint8* Mem1::Copy(TAny* aTrg, const TAny* aSrc, TInt aLength) |
|
239 |
{ return Mem::Copy(aTrg, aSrc, aLength); } |
|
240 |
EXPORT_C TUint8* Mem1::Move(TAny* aTrg, const TAny* aSrc, TInt aLength) |
|
241 |
{ return Mem::Move(aTrg, aSrc, aLength); } |
|
242 |
||
243 |
#endif // __KERNEL_MODE__ |