0
|
1 |
// Copyright (c) 2008-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 |
// e32test\system\t_atomic_common.cpp
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
#ifdef __KERNEL_MODE__
|
|
19 |
#include <kernel/kernel.h>
|
|
20 |
#else
|
|
21 |
#define __E32TEST_EXTENSION__
|
|
22 |
|
|
23 |
#include <e32test.h>
|
|
24 |
|
|
25 |
extern RTest test;
|
|
26 |
|
|
27 |
#define __INCLUDE_FUNC_NAMES__
|
|
28 |
#endif
|
|
29 |
|
|
30 |
#define __INCLUDE_ATOMIC_FUNCTIONS__
|
|
31 |
#define __INCLUDE_CONTROL_FUNCTIONS__
|
|
32 |
#define __INCLUDE_FUNCTION_ATTRIBUTES__
|
|
33 |
|
|
34 |
#include "t_atomic.h"
|
|
35 |
|
|
36 |
#define DEBUGPRINTVAR(x) \
|
|
37 |
{ \
|
|
38 |
const TUint8* p = (const TUint8*)&(x); \
|
|
39 |
DEBUGPRINT("Line %d: " #x "=%02x %02x %02x %02x %02x %02x %02x %02x", __LINE__, p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]); \
|
|
40 |
}
|
|
41 |
|
121
|
42 |
#ifdef __WINS__
|
|
43 |
#pragma warning( disable : 4127 ) // disable warning warning C4127: conditional expression is constant
|
|
44 |
#endif
|
|
45 |
template<typename T> void DebugPrintVar(T x, char *name, TInt line)
|
|
46 |
{
|
|
47 |
const TUint8 *p = (const TUint8 *)&x;
|
|
48 |
const TInt size = sizeof(T);
|
|
49 |
if (size < 2)
|
|
50 |
{
|
|
51 |
DEBUGPRINT("Line %d: %s =%02x", line, name, p[0]);
|
|
52 |
}
|
|
53 |
else if (size < 4)
|
|
54 |
{
|
|
55 |
DEBUGPRINT("Line %d: %s =%02x %02x", line, name, p[0], p[1]);
|
|
56 |
}
|
|
57 |
else if (size < 8)
|
|
58 |
{
|
|
59 |
DEBUGPRINT("Line %d: %s =%02x %02x %02x %02x", line, name, p[0], p[1], p[2], p[3]);
|
|
60 |
}
|
|
61 |
else
|
|
62 |
{
|
|
63 |
DEBUGPRINT("Line %d: %s =%02x %02x %02x %02x %02x %02x %02x %02x", line, name, p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
|
|
64 |
}
|
|
65 |
}
|
|
66 |
#ifdef __WINS__
|
|
67 |
#pragma warning( default : 4127 ) // disable warning warning C4127: conditional expression is constant
|
|
68 |
#endif
|
|
69 |
|
|
70 |
|
0
|
71 |
extern "C" {
|
|
72 |
|
|
73 |
// Simulated versions of atomic functions without the atomicity
|
|
74 |
#define __LOAD(T) return *(T*)a
|
|
75 |
#define __STORE(T) *(T*)a=v; return v
|
|
76 |
#define __SWP(T) T oldv=*(T*)a; *(T*)a=v; return oldv
|
|
77 |
#define __CAS(T) if (*(T*)a==*q) {*(T*)a=v; return 1;} *q=*(T*)a; return 0
|
|
78 |
#define __ADD(T) T oldv=*(T*)a; *(T*)a=(T)(oldv+v); return oldv
|
|
79 |
#define __AND(T) T oldv=*(T*)a; *(T*)a=(T)(oldv&v); return oldv
|
|
80 |
#define __IOR(T) T oldv=*(T*)a; *(T*)a=(T)(oldv|v); return oldv
|
|
81 |
#define __XOR(T) T oldv=*(T*)a; *(T*)a=(T)(oldv^v); return oldv
|
|
82 |
#define __AXO(T) T oldv=*(T*)a; *(T*)a=(T)((oldv&u)^v); return oldv
|
|
83 |
#define __TA(T) T oldv=*(T*)a; *(T*)a=(T)(oldv+((oldv>=t)?u:v)); return oldv
|
|
84 |
|
|
85 |
TUint8 __nonatomic_load8(const volatile TAny* a)
|
|
86 |
{
|
|
87 |
__LOAD(TUint8);
|
|
88 |
}
|
|
89 |
|
|
90 |
TUint8 __nonatomic_store8(volatile TAny* a, TUint8 v)
|
|
91 |
{
|
|
92 |
__STORE(TUint8);
|
|
93 |
}
|
|
94 |
|
|
95 |
TUint8 __nonatomic_swp8(volatile TAny* a, TUint8 v)
|
|
96 |
{
|
|
97 |
__SWP(TUint8);
|
|
98 |
}
|
|
99 |
|
|
100 |
TBool __nonatomic_cas8(volatile TAny* a, TUint8* q, TUint8 v)
|
|
101 |
{
|
|
102 |
__CAS(TUint8);
|
|
103 |
}
|
|
104 |
|
|
105 |
TUint8 __nonatomic_add8(volatile TAny* a, TUint8 v)
|
|
106 |
{
|
|
107 |
__ADD(TUint8);
|
|
108 |
}
|
|
109 |
|
|
110 |
TUint8 __nonatomic_and8(volatile TAny* a, TUint8 v)
|
|
111 |
{
|
|
112 |
__AND(TUint8);
|
|
113 |
}
|
|
114 |
|
|
115 |
TUint8 __nonatomic_ior8(volatile TAny* a, TUint8 v)
|
|
116 |
{
|
|
117 |
__IOR(TUint8);
|
|
118 |
}
|
|
119 |
|
|
120 |
TUint8 __nonatomic_xor8(volatile TAny* a, TUint8 v)
|
|
121 |
{
|
|
122 |
__XOR(TUint8);
|
|
123 |
}
|
|
124 |
|
|
125 |
TUint8 __nonatomic_axo8(volatile TAny* a, TUint8 u, TUint8 v)
|
|
126 |
{
|
|
127 |
__AXO(TUint8);
|
|
128 |
}
|
|
129 |
|
|
130 |
TUint8 __nonatomic_tau8(volatile TAny* a, TUint8 t, TUint8 u, TUint8 v)
|
|
131 |
{
|
|
132 |
__TA(TUint8);
|
|
133 |
}
|
|
134 |
|
|
135 |
TInt8 __nonatomic_tas8(volatile TAny* a, TInt8 t, TInt8 u, TInt8 v)
|
|
136 |
{
|
|
137 |
__TA(TInt8);
|
|
138 |
}
|
|
139 |
|
|
140 |
|
|
141 |
TUint16 __nonatomic_load16(const volatile TAny* a)
|
|
142 |
{
|
|
143 |
__LOAD(TUint16);
|
|
144 |
}
|
|
145 |
|
|
146 |
TUint16 __nonatomic_store16(volatile TAny* a, TUint16 v)
|
|
147 |
{
|
|
148 |
__STORE(TUint16);
|
|
149 |
}
|
|
150 |
|
|
151 |
TUint16 __nonatomic_swp16(volatile TAny* a, TUint16 v)
|
|
152 |
{
|
|
153 |
__SWP(TUint16);
|
|
154 |
}
|
|
155 |
|
|
156 |
TBool __nonatomic_cas16(volatile TAny* a, TUint16* q, TUint16 v)
|
|
157 |
{
|
|
158 |
__CAS(TUint16);
|
|
159 |
}
|
|
160 |
|
|
161 |
TUint16 __nonatomic_add16(volatile TAny* a, TUint16 v)
|
|
162 |
{
|
|
163 |
__ADD(TUint16);
|
|
164 |
}
|
|
165 |
|
|
166 |
TUint16 __nonatomic_and16(volatile TAny* a, TUint16 v)
|
|
167 |
{
|
|
168 |
__AND(TUint16);
|
|
169 |
}
|
|
170 |
|
|
171 |
TUint16 __nonatomic_ior16(volatile TAny* a, TUint16 v)
|
|
172 |
{
|
|
173 |
__IOR(TUint16);
|
|
174 |
}
|
|
175 |
|
|
176 |
TUint16 __nonatomic_xor16(volatile TAny* a, TUint16 v)
|
|
177 |
{
|
|
178 |
__XOR(TUint16);
|
|
179 |
}
|
|
180 |
|
|
181 |
TUint16 __nonatomic_axo16(volatile TAny* a, TUint16 u, TUint16 v)
|
|
182 |
{
|
|
183 |
__AXO(TUint16);
|
|
184 |
}
|
|
185 |
|
|
186 |
TUint16 __nonatomic_tau16(volatile TAny* a, TUint16 t, TUint16 u, TUint16 v)
|
|
187 |
{
|
|
188 |
__TA(TUint16);
|
|
189 |
}
|
|
190 |
|
|
191 |
TInt16 __nonatomic_tas16(volatile TAny* a, TInt16 t, TInt16 u, TInt16 v)
|
|
192 |
{
|
|
193 |
__TA(TInt16);
|
|
194 |
}
|
|
195 |
|
|
196 |
|
|
197 |
TUint32 __nonatomic_load32(const volatile TAny* a)
|
|
198 |
{
|
|
199 |
__LOAD(TUint32);
|
|
200 |
}
|
|
201 |
|
|
202 |
TUint32 __nonatomic_store32(volatile TAny* a, TUint32 v)
|
|
203 |
{
|
|
204 |
__STORE(TUint32);
|
|
205 |
}
|
|
206 |
|
|
207 |
TUint32 __nonatomic_swp32(volatile TAny* a, TUint32 v)
|
|
208 |
{
|
|
209 |
__SWP(TUint32);
|
|
210 |
}
|
|
211 |
|
|
212 |
TBool __nonatomic_cas32(volatile TAny* a, TUint32* q, TUint32 v)
|
|
213 |
{
|
|
214 |
__CAS(TUint32);
|
|
215 |
}
|
|
216 |
|
|
217 |
TUint32 __nonatomic_add32(volatile TAny* a, TUint32 v)
|
|
218 |
{
|
|
219 |
__ADD(TUint32);
|
|
220 |
}
|
|
221 |
|
|
222 |
TUint32 __nonatomic_and32(volatile TAny* a, TUint32 v)
|
|
223 |
{
|
|
224 |
__AND(TUint32);
|
|
225 |
}
|
|
226 |
|
|
227 |
TUint32 __nonatomic_ior32(volatile TAny* a, TUint32 v)
|
|
228 |
{
|
|
229 |
__IOR(TUint32);
|
|
230 |
}
|
|
231 |
|
|
232 |
TUint32 __nonatomic_xor32(volatile TAny* a, TUint32 v)
|
|
233 |
{
|
|
234 |
__XOR(TUint32);
|
|
235 |
}
|
|
236 |
|
|
237 |
TUint32 __nonatomic_axo32(volatile TAny* a, TUint32 u, TUint32 v)
|
|
238 |
{
|
|
239 |
__AXO(TUint32);
|
|
240 |
}
|
|
241 |
|
|
242 |
TUint32 __nonatomic_tau32(volatile TAny* a, TUint32 t, TUint32 u, TUint32 v)
|
|
243 |
{
|
|
244 |
__TA(TUint32);
|
|
245 |
}
|
|
246 |
|
|
247 |
TInt32 __nonatomic_tas32(volatile TAny* a, TInt32 t, TInt32 u, TInt32 v)
|
|
248 |
{
|
|
249 |
__TA(TInt32);
|
|
250 |
}
|
|
251 |
|
|
252 |
|
|
253 |
TUint64 __nonatomic_load64(const volatile TAny* a)
|
|
254 |
{
|
|
255 |
__LOAD(TUint64);
|
|
256 |
}
|
|
257 |
|
|
258 |
TUint64 __nonatomic_store64(volatile TAny* a, TUint64 v)
|
|
259 |
{
|
|
260 |
__STORE(TUint64);
|
|
261 |
}
|
|
262 |
|
|
263 |
TUint64 __nonatomic_swp64(volatile TAny* a, TUint64 v)
|
|
264 |
{
|
|
265 |
__SWP(TUint64);
|
|
266 |
}
|
|
267 |
|
|
268 |
TBool __nonatomic_cas64(volatile TAny* a, TUint64* q, TUint64 v)
|
|
269 |
{
|
|
270 |
__CAS(TUint64);
|
|
271 |
}
|
|
272 |
|
|
273 |
TUint64 __nonatomic_add64(volatile TAny* a, TUint64 v)
|
|
274 |
{
|
|
275 |
__ADD(TUint64);
|
|
276 |
}
|
|
277 |
|
|
278 |
TUint64 __nonatomic_and64(volatile TAny* a, TUint64 v)
|
|
279 |
{
|
|
280 |
__AND(TUint64);
|
|
281 |
}
|
|
282 |
|
|
283 |
TUint64 __nonatomic_ior64(volatile TAny* a, TUint64 v)
|
|
284 |
{
|
|
285 |
__IOR(TUint64);
|
|
286 |
}
|
|
287 |
|
|
288 |
TUint64 __nonatomic_xor64(volatile TAny* a, TUint64 v)
|
|
289 |
{
|
|
290 |
__XOR(TUint64);
|
|
291 |
}
|
|
292 |
|
|
293 |
TUint64 __nonatomic_axo64(volatile TAny* a, TUint64 u, TUint64 v)
|
|
294 |
{
|
|
295 |
__AXO(TUint64);
|
|
296 |
}
|
|
297 |
|
|
298 |
TUint64 __nonatomic_tau64(volatile TAny* a, TUint64 t, TUint64 u, TUint64 v)
|
|
299 |
{
|
|
300 |
__TA(TUint64);
|
|
301 |
}
|
|
302 |
|
|
303 |
TInt64 __nonatomic_tas64(volatile TAny* a, TInt64 t, TInt64 u, TInt64 v)
|
|
304 |
{
|
|
305 |
__TA(TInt64);
|
|
306 |
}
|
|
307 |
|
|
308 |
} // extern "C"
|
|
309 |
|
|
310 |
|
|
311 |
#define DEBUGPRINTxyrc() \
|
|
312 |
DEBUGPRINTVAR(x); \
|
121
|
313 |
DebugPrintVar(y, "y", __LINE__); \
|
|
314 |
DebugPrintVar(r, "r", __LINE__); \
|
|
315 |
DebugPrintVar(c, "c", __LINE__)
|
|
316 |
|
0
|
317 |
|
|
318 |
template<class T> TInt DoLoadTest(TInt aIndex, TAny* aPtr, T aInitialValue)
|
|
319 |
{
|
|
320 |
#ifdef __EXTRA_DEBUG__
|
|
321 |
DEBUGPRINT("DoLoadTest %d %08x", aIndex, aPtr);
|
|
322 |
#endif
|
|
323 |
typename TLoadFn<T>::F atomic = (typename TLoadFn<T>::F)AtomicFuncPtr[aIndex];
|
|
324 |
typename TLoadFn<T>::F control = (typename TLoadFn<T>::F)ControlFuncPtr[aIndex];
|
|
325 |
T& x = *(T*)aPtr;
|
|
326 |
x = aInitialValue;
|
|
327 |
T y = aInitialValue;
|
|
328 |
T r = atomic(&x);
|
|
329 |
T c = control(&y);
|
|
330 |
if (r!=c || x!=y)
|
|
331 |
{
|
|
332 |
DEBUGPRINTxyrc();
|
|
333 |
return __LINE__;
|
|
334 |
}
|
|
335 |
return 0;
|
|
336 |
}
|
|
337 |
|
|
338 |
template<class T> TInt DoRmw1Test(TInt aIndex, TAny* aPtr, T aInitialValue, T a1)
|
|
339 |
{
|
|
340 |
#ifdef __EXTRA_DEBUG__
|
|
341 |
DEBUGPRINT("DoRmw1Test %d %08x", aIndex, aPtr);
|
|
342 |
#endif
|
|
343 |
typename TRmw1Fn<T>::F atomic = (typename TRmw1Fn<T>::F)AtomicFuncPtr[aIndex];
|
|
344 |
typename TRmw1Fn<T>::F control = (typename TRmw1Fn<T>::F)ControlFuncPtr[aIndex];
|
|
345 |
T& x = *(T*)aPtr;
|
|
346 |
x = aInitialValue;
|
|
347 |
T y = aInitialValue;
|
|
348 |
T r = atomic(&x,a1);
|
|
349 |
T c = control(&y,a1);
|
|
350 |
if (r!=c || x!=y)
|
|
351 |
{
|
|
352 |
DEBUGPRINTxyrc();
|
|
353 |
return __LINE__;
|
|
354 |
}
|
|
355 |
return 0;
|
|
356 |
}
|
|
357 |
|
|
358 |
template<class T> TInt DoRmw2Test(TInt aIndex, TAny* aPtr, T aInitialValue, T a1, T a2)
|
|
359 |
{
|
|
360 |
#ifdef __EXTRA_DEBUG__
|
|
361 |
DEBUGPRINT("DoRmw2Test %d %08x", aIndex, aPtr);
|
|
362 |
#endif
|
|
363 |
typename TRmw2Fn<T>::F atomic = (typename TRmw2Fn<T>::F)AtomicFuncPtr[aIndex];
|
|
364 |
typename TRmw2Fn<T>::F control = (typename TRmw2Fn<T>::F)ControlFuncPtr[aIndex];
|
|
365 |
T& x = *(T*)aPtr;
|
|
366 |
x = aInitialValue;
|
|
367 |
T y = aInitialValue;
|
|
368 |
T r = atomic(&x,a1,a2);
|
|
369 |
T c = control(&y,a1,a2);
|
|
370 |
if (r!=c || x!=y)
|
|
371 |
{
|
|
372 |
DEBUGPRINTxyrc();
|
|
373 |
return __LINE__;
|
|
374 |
}
|
|
375 |
return 0;
|
|
376 |
}
|
|
377 |
|
|
378 |
template<class T> TInt DoRmw3Test(TInt aIndex, TAny* aPtr, T aInitialValue, T a1, T a2, T a3)
|
|
379 |
{
|
|
380 |
#ifdef __EXTRA_DEBUG__
|
|
381 |
DEBUGPRINT("DoRmw3Test %d %08x", aIndex, aPtr);
|
|
382 |
#endif
|
|
383 |
typename TRmw3Fn<T>::F atomic = (typename TRmw3Fn<T>::F)AtomicFuncPtr[aIndex];
|
|
384 |
typename TRmw3Fn<T>::F control = (typename TRmw3Fn<T>::F)ControlFuncPtr[aIndex];
|
|
385 |
T& x = *(T*)aPtr;
|
|
386 |
x = aInitialValue;
|
|
387 |
T y = aInitialValue;
|
|
388 |
T r = atomic(&x,a1,a2,a3);
|
|
389 |
T c = control(&y,a1,a2,a3);
|
|
390 |
if (r!=c || x!=y)
|
|
391 |
{
|
|
392 |
DEBUGPRINTxyrc();
|
|
393 |
return __LINE__;
|
|
394 |
}
|
|
395 |
return 0;
|
|
396 |
}
|
|
397 |
|
|
398 |
template<class T> TInt DoCasTest(TInt aIndex, TAny* aPtr, T aInitialValue, T aExpectedValue, T aFinalValue)
|
|
399 |
{
|
|
400 |
#ifdef __EXTRA_DEBUG__
|
|
401 |
DEBUGPRINT("DoCasTest %d %08x", aIndex, aPtr);
|
|
402 |
#endif
|
|
403 |
typename TCasFn<T>::F atomic = (typename TCasFn<T>::F)AtomicFuncPtr[aIndex];
|
|
404 |
typename TCasFn<T>::F control = (typename TCasFn<T>::F)ControlFuncPtr[aIndex];
|
|
405 |
T& x = *(T*)aPtr;
|
|
406 |
x = aInitialValue;
|
|
407 |
T ex = aExpectedValue;
|
|
408 |
T y = aInitialValue;
|
|
409 |
T ey = aExpectedValue;
|
|
410 |
TBool r = atomic(&x,&ex,aFinalValue);
|
|
411 |
TBool c = control(&y,&ey,aFinalValue);
|
|
412 |
TInt line = 0;
|
|
413 |
if (r && !c)
|
|
414 |
line = __LINE__;
|
|
415 |
else if (!r && c)
|
|
416 |
line = __LINE__;
|
|
417 |
else if (x!=y)
|
|
418 |
line = __LINE__;
|
|
419 |
else if (ex!=ey)
|
|
420 |
line = __LINE__;
|
|
421 |
else if (r && x!=aFinalValue)
|
|
422 |
line = __LINE__;
|
|
423 |
else if (!r && ex!=aInitialValue)
|
|
424 |
line = __LINE__;
|
|
425 |
if (line)
|
|
426 |
{
|
|
427 |
DEBUGPRINT("r=%d",r);
|
|
428 |
DEBUGPRINTVAR(x);
|
121
|
429 |
DebugPrintVar(ex, "ex", __LINE__);
|
0
|
430 |
DEBUGPRINT("c=%d",c);
|
121
|
431 |
DebugPrintVar(y, "y", __LINE__);
|
|
432 |
DebugPrintVar(ey, "ey", __LINE__);
|
0
|
433 |
}
|
|
434 |
return line;
|
|
435 |
}
|
|
436 |
|
|
437 |
|
|
438 |
|
|
439 |
TEnclosed::TEnclosed(TInt aSize)
|
|
440 |
{
|
|
441 |
iOffset = -1;
|
|
442 |
iSize = aSize;
|
|
443 |
iData = (TUint64*)((T_UintPtr(i_Data) + 7) &~ 7); // align up to next 8 byte boundary
|
|
444 |
iBackup = iData + 8;
|
|
445 |
}
|
|
446 |
|
|
447 |
TAny* TEnclosed::Ptr()
|
|
448 |
{
|
|
449 |
return ((TUint8*)iData + iOffset);
|
|
450 |
}
|
|
451 |
|
|
452 |
TInt TEnclosed::Next()
|
|
453 |
{
|
|
454 |
const TInt KLimit[8] = {8, 16, 0, 32, 0, 0, 0, 32};
|
|
455 |
if (iOffset<0)
|
|
456 |
iOffset = 0;
|
|
457 |
else
|
|
458 |
{
|
|
459 |
TInt r = Verify();
|
|
460 |
if (r!=0)
|
|
461 |
return r;
|
|
462 |
iOffset += iSize;
|
|
463 |
}
|
|
464 |
if (iOffset >= KLimit[iSize-1])
|
|
465 |
return KErrEof;
|
|
466 |
Init();
|
|
467 |
return KErrNone;
|
|
468 |
}
|
|
469 |
|
|
470 |
void TEnclosed::Init()
|
|
471 |
{
|
|
472 |
TUint32 x = iOffset+1;
|
|
473 |
x |= (x<<8);
|
|
474 |
x |= (x<<16);
|
|
475 |
TUint32* d = (TUint32*)iData;
|
|
476 |
TUint32* b = (TUint32*)iBackup;
|
|
477 |
TInt i;
|
|
478 |
for (i=0; i<16; ++i)
|
|
479 |
{
|
|
480 |
*d++ = x;
|
|
481 |
*b++ = x;
|
|
482 |
x = 69069*x + 41;
|
|
483 |
}
|
|
484 |
}
|
|
485 |
|
|
486 |
TInt TEnclosed::Verify()
|
|
487 |
{
|
|
488 |
TUint8* d = (TUint8*)iData;
|
|
489 |
const TUint8* b = (const TUint8*)iBackup;
|
|
490 |
TInt i;
|
|
491 |
for (i=0; i<iSize; ++i)
|
|
492 |
d[iOffset+i] = b[iOffset+i];
|
|
493 |
if (memcompare(b,64,d,64))
|
|
494 |
{
|
|
495 |
DEBUGPRINT("FAIL! iOffset=%02x, sizeof(T)=%1d", iOffset, iSize);
|
|
496 |
for (i=0; i<64; ++i)
|
|
497 |
{
|
|
498 |
if (d[i]!=b[i])
|
|
499 |
{
|
|
500 |
DEBUGPRINT("d[%02x]=%02x b[%02x]=%02x", i, d[i], i, b[i]);
|
|
501 |
}
|
|
502 |
}
|
|
503 |
return __LINE__;
|
|
504 |
}
|
|
505 |
return 0;
|
|
506 |
}
|
|
507 |
|
|
508 |
|
|
509 |
TInt TDGBase::Execute()
|
|
510 |
{
|
|
511 |
PFV af0 = AtomicFuncPtr[iIndex];
|
|
512 |
PFV cf0 = ControlFuncPtr[iIndex];
|
|
513 |
if (!af0 || !cf0)
|
|
514 |
return __LINE__;
|
|
515 |
TUint attr = FuncAttr[iIndex];
|
|
516 |
TInt type = ATTR_TO_TYPE(attr);
|
|
517 |
TInt size = ATTR_TO_SIZE(attr);
|
|
518 |
TInt func = ATTR_TO_FUNC(attr);
|
|
519 |
if (type==EFuncTypeInvalid)
|
|
520 |
return __LINE__;
|
|
521 |
#ifdef __EXTRA_DEBUG__
|
|
522 |
TInt ord = ATTR_TO_ORD(attr);
|
|
523 |
DEBUGPRINT("A=%08x T=%d O=%d S=%d F=%d", attr, type, ord, size, func);
|
|
524 |
#endif
|
|
525 |
TEnclosed enc(size);
|
|
526 |
TInt res = 0;
|
|
527 |
while ( (res = enc.Next()) == KErrNone )
|
|
528 |
{
|
|
529 |
#ifdef __EXTRA_DEBUG__
|
|
530 |
DEBUGPRINT("Offset %02x", enc.Offset());
|
|
531 |
#endif
|
|
532 |
TAny* ptr = enc.Ptr();
|
|
533 |
switch (type)
|
|
534 |
{
|
|
535 |
case EFuncTypeLoad:
|
|
536 |
{
|
|
537 |
switch (size)
|
|
538 |
{
|
|
539 |
case 1: res = DoLoadTest<TUint8>(iIndex, ptr, (TUint8)i0); break;
|
|
540 |
case 2: res = DoLoadTest<TUint16>(iIndex, ptr, (TUint16)i0); break;
|
|
541 |
case 4: res = DoLoadTest<TUint32>(iIndex, ptr, (TUint32)i0); break;
|
|
542 |
case 8: res = DoLoadTest<TUint64>(iIndex, ptr, i0); break;
|
|
543 |
default: res = __LINE__; break;
|
|
544 |
}
|
|
545 |
break;
|
|
546 |
}
|
|
547 |
case EFuncTypeRmw1:
|
|
548 |
{
|
|
549 |
switch (size)
|
|
550 |
{
|
|
551 |
case 1: res = DoRmw1Test<TUint8>(iIndex, ptr, (TUint8)i0, (TUint8)i1); break;
|
|
552 |
case 2: res = DoRmw1Test<TUint16>(iIndex, ptr, (TUint16)i0, (TUint16)i1); break;
|
|
553 |
case 4: res = DoRmw1Test<TUint32>(iIndex, ptr, (TUint32)i0, (TUint32)i1); break;
|
|
554 |
case 8: res = DoRmw1Test<TUint64>(iIndex, ptr, i0, i1); break;
|
|
555 |
default: res = __LINE__; break;
|
|
556 |
}
|
|
557 |
break;
|
|
558 |
}
|
|
559 |
case EFuncTypeRmw2:
|
|
560 |
{
|
|
561 |
switch (size)
|
|
562 |
{
|
|
563 |
case 1: res = DoRmw2Test<TUint8>(iIndex, ptr, (TUint8)i0, (TUint8)i1, (TUint8)i2); break;
|
|
564 |
case 2: res = DoRmw2Test<TUint16>(iIndex, ptr, (TUint16)i0, (TUint16)i1, (TUint16)i2); break;
|
|
565 |
case 4: res = DoRmw2Test<TUint32>(iIndex, ptr, (TUint32)i0, (TUint32)i1, (TUint32)i2); break;
|
|
566 |
case 8: res = DoRmw2Test<TUint64>(iIndex, ptr, i0, i1, i2); break;
|
|
567 |
default: res = __LINE__; break;
|
|
568 |
}
|
|
569 |
break;
|
|
570 |
}
|
|
571 |
case EFuncTypeRmw3:
|
|
572 |
{
|
|
573 |
if (func==EAtomicFuncTAU)
|
|
574 |
{
|
|
575 |
switch (size)
|
|
576 |
{
|
|
577 |
case 1: res = DoRmw3Test<TUint8>(iIndex, ptr, (TUint8)i0, (TUint8)i1, (TUint8)i2, (TUint8)i3); break;
|
|
578 |
case 2: res = DoRmw3Test<TUint16>(iIndex, ptr, (TUint16)i0, (TUint16)i1, (TUint16)i2, (TUint16)i3); break;
|
|
579 |
case 4: res = DoRmw3Test<TUint32>(iIndex, ptr, (TUint32)i0, (TUint32)i1, (TUint32)i2, (TUint32)i3); break;
|
|
580 |
case 8: res = DoRmw3Test<TUint64>(iIndex, ptr, i0, i1, i2, i3); break;
|
|
581 |
default: res = __LINE__; break;
|
|
582 |
}
|
|
583 |
}
|
|
584 |
else if (func==EAtomicFuncTAS)
|
|
585 |
{
|
|
586 |
switch (size)
|
|
587 |
{
|
|
588 |
case 1: res = DoRmw3Test<TInt8>(iIndex, ptr, (TInt8)i0, (TInt8)i1, (TInt8)i2, (TInt8)i3); break;
|
|
589 |
case 2: res = DoRmw3Test<TInt16>(iIndex, ptr, (TInt16)i0, (TInt16)i1, (TInt16)i2, (TInt16)i3); break;
|
|
590 |
case 4: res = DoRmw3Test<TInt32>(iIndex, ptr, (TInt32)i0, (TInt32)i1, (TInt32)i2, (TInt32)i3); break;
|
|
591 |
case 8: res = DoRmw3Test<TInt64>(iIndex, ptr, i0, i1, i2, i3); break;
|
|
592 |
default: res = __LINE__; break;
|
|
593 |
}
|
|
594 |
}
|
|
595 |
else
|
|
596 |
res = __LINE__;
|
|
597 |
break;
|
|
598 |
}
|
|
599 |
case EFuncTypeCas:
|
|
600 |
{
|
|
601 |
switch (size)
|
|
602 |
{
|
|
603 |
case 1: res = DoCasTest<TUint8>(iIndex, ptr, (TUint8)i0, (TUint8)i1, (TUint8)i2); break;
|
|
604 |
case 2: res = DoCasTest<TUint16>(iIndex, ptr, (TUint16)i0, (TUint16)i1, (TUint16)i2); break;
|
|
605 |
case 4: res = DoCasTest<TUint32>(iIndex, ptr, (TUint32)i0, (TUint32)i1, (TUint32)i2); break;
|
|
606 |
case 8: res = DoCasTest<TUint64>(iIndex, ptr, i0, i1, i2); break;
|
|
607 |
default: res = __LINE__; break;
|
|
608 |
}
|
|
609 |
break;
|
|
610 |
}
|
|
611 |
default:
|
|
612 |
res = __LINE__;
|
|
613 |
break;
|
|
614 |
}
|
|
615 |
if (res)
|
|
616 |
return res;
|
|
617 |
}
|
|
618 |
if (res == KErrEof)
|
|
619 |
res = 0;
|
|
620 |
return res;
|
|
621 |
}
|
|
622 |
|
|
623 |
#ifndef __KERNEL_MODE__
|
|
624 |
void TDGBase::Dump(const char* aTitle)
|
|
625 |
{
|
|
626 |
TPtrC8 fname8((const TText8*)FuncName[iIndex]);
|
|
627 |
TBuf<64> fname;
|
|
628 |
fname.Copy(fname8);
|
|
629 |
DEBUGPRINT(aTitle);
|
|
630 |
DEBUGPRINT("iIndex=%d (%S)", iIndex, &fname);
|
|
631 |
DEBUGPRINT("i0 = %08x %08x", I64HIGH(i0), I64LOW(i0));
|
|
632 |
DEBUGPRINT("i1 = %08x %08x", I64HIGH(i1), I64LOW(i1));
|
|
633 |
DEBUGPRINT("i2 = %08x %08x", I64HIGH(i2), I64LOW(i2));
|
|
634 |
DEBUGPRINT("i3 = %08x %08x", I64HIGH(i3), I64LOW(i3));
|
|
635 |
}
|
|
636 |
#endif
|
|
637 |
|
|
638 |
template<class T> TInt DoSwap(TAny* aPtr, TPerThread* aT, TAtomicAction& aA, T*)
|
|
639 |
{
|
|
640 |
typename TRmw1Fn<T>::F atomic = (typename TRmw1Fn<T>::F)AtomicFuncPtr[aA.iIndex];
|
|
641 |
T newv = (T)aA.i0;
|
|
642 |
T orig = atomic(aPtr, newv);
|
|
643 |
T xr = (T)(newv ^ orig);
|
|
644 |
aT->iXor ^= xr;
|
|
645 |
T diff = (T)(newv - orig);
|
|
646 |
aT->iDiff += diff;
|
|
647 |
return 0;
|
|
648 |
}
|
|
649 |
|
|
650 |
template<class T> TInt DoAdd(TAny* aPtr, TPerThread* aT, TAtomicAction& aA, T*)
|
|
651 |
{
|
|
652 |
typename TRmw1Fn<T>::F atomic = (typename TRmw1Fn<T>::F)AtomicFuncPtr[aA.iIndex];
|
|
653 |
T arg = (T)aA.i0;
|
|
654 |
T orig = atomic(aPtr, arg);
|
|
655 |
T xr = (T)((arg+orig) ^ orig);
|
|
656 |
aT->iXor ^= xr;
|
|
657 |
aT->iDiff += arg;
|
|
658 |
return 0;
|
|
659 |
}
|
|
660 |
|
|
661 |
template<class T> TInt DoXor(TAny* aPtr, TPerThread* aT, TAtomicAction& aA, T*)
|
|
662 |
{
|
|
663 |
typename TRmw1Fn<T>::F atomic = (typename TRmw1Fn<T>::F)AtomicFuncPtr[aA.iIndex];
|
|
664 |
T arg = (T)aA.i0;
|
|
665 |
T orig = atomic(aPtr, arg);
|
|
666 |
T diff = (T)((arg^orig) - orig);
|
|
667 |
aT->iDiff += diff;
|
|
668 |
aT->iXor ^= arg;
|
|
669 |
return 0;
|
|
670 |
}
|
|
671 |
|
|
672 |
template<class T> TInt DoAndOr(TAny* aPtr, TPerThread* aT, TAtomicAction& aA, T*)
|
|
673 |
{
|
|
674 |
typename TRmw1Fn<T>::F atomic_and = (typename TRmw1Fn<T>::F)AtomicFuncPtr[aA.iIndex];
|
|
675 |
typename TRmw1Fn<T>::F atomic_or = (typename TRmw1Fn<T>::F)AtomicFuncPtr[aA.iIndex+4];
|
|
676 |
T aarg = (T)aA.i0;
|
|
677 |
T oarg = (T)aA.i1;
|
|
678 |
T aorig = atomic_and(aPtr, aarg);
|
|
679 |
T oorig = atomic_or(aPtr, oarg);
|
|
680 |
T adiff = (T)((aorig & aarg) - aorig);
|
|
681 |
T odiff = (T)((oorig | oarg) - oorig);
|
|
682 |
aT->iDiff += adiff + odiff;
|
|
683 |
T axor = (T)((aorig & aarg) ^ aorig);
|
|
684 |
T oxor = (T)((oorig | oarg) ^ oorig);
|
|
685 |
aT->iXor ^= axor ^ oxor;
|
|
686 |
return 0;
|
|
687 |
}
|
|
688 |
|
|
689 |
template<class T> TInt DoAxo(TAny* aPtr, TPerThread* aT, TAtomicAction& aA, T*)
|
|
690 |
{
|
|
691 |
typename TRmw2Fn<T>::F atomic = (typename TRmw2Fn<T>::F)AtomicFuncPtr[aA.iIndex];
|
|
692 |
T aarg = (T)aA.i0;
|
|
693 |
T xarg = (T)aA.i1;
|
|
694 |
T orig = atomic(aPtr, aarg, xarg);
|
|
695 |
T newv = (T)((orig & aarg) ^ xarg);
|
|
696 |
aT->iDiff += (newv - orig);
|
|
697 |
aT->iXor ^= (newv ^ orig);
|
|
698 |
return 0;
|
|
699 |
}
|
|
700 |
|
|
701 |
template<class T> TInt DoThAdd(TAny* aPtr, TPerThread* aT, TAtomicAction& aA, T*)
|
|
702 |
{
|
|
703 |
typename TRmw3Fn<T>::F atomic = (typename TRmw3Fn<T>::F)AtomicFuncPtr[aA.iIndex];
|
|
704 |
T thr = (T)aA.i0;
|
|
705 |
T arg1 = (T)aA.i1;
|
|
706 |
T arg2 = (T)aA.i2;
|
|
707 |
T orig = atomic(aPtr, thr, arg1, arg2);
|
|
708 |
T newv = (T)((orig >= thr) ? (orig + arg1) : (orig + arg2));
|
|
709 |
aT->iDiff += (orig >= thr) ? arg1 : arg2;
|
|
710 |
aT->iXor ^= (newv ^ orig);
|
|
711 |
return 0;
|
|
712 |
}
|
|
713 |
|
|
714 |
template<class T> TInt DoCas(TAny* aPtr, TPerThread* aT, TAtomicAction& aA, T*)
|
|
715 |
{
|
|
716 |
typename TCasFn<T>::F atomic = (typename TCasFn<T>::F)AtomicFuncPtr[aA.iIndex];
|
|
717 |
T orig = *(const volatile T*)aPtr;
|
|
718 |
T newv;
|
|
719 |
TBool done = FALSE;
|
|
720 |
TUint32 fails = 0xffffffffu;
|
|
721 |
do {
|
|
722 |
++fails;
|
|
723 |
newv = Transform<T>::F(orig);
|
|
724 |
done = atomic(aPtr, &orig, newv);
|
|
725 |
} while(!done);
|
|
726 |
aT->iFailCount += fails;
|
|
727 |
++aT->iDiff;
|
|
728 |
aT->iXor ^= (newv ^ orig);
|
|
729 |
return 0;
|
|
730 |
}
|
|
731 |
|
|
732 |
volatile TUint Dummy;
|
|
733 |
extern "C" TInt DoAtomicAction(TAny* aPtr, TPerThread* aT, TAtomicAction& aA)
|
|
734 |
{
|
|
735 |
TUint x = TUint(aT)*0x9E3779B9u;
|
|
736 |
x = (x>>8)&15;
|
|
737 |
while(x--)
|
|
738 |
++Dummy;
|
|
739 |
TInt r = KErrNotSupported;
|
|
740 |
TUint attr = FuncAttr[aA.iIndex];
|
|
741 |
TUint func = ATTR_TO_FUNC(attr);
|
|
742 |
TUint size = ATTR_TO_SIZE(attr);
|
|
743 |
switch (size)
|
|
744 |
{
|
|
745 |
case 1:
|
|
746 |
{
|
|
747 |
TUint8 xx;
|
|
748 |
TUint8* dummy = &xx;
|
|
749 |
TInt8 yy;
|
|
750 |
TInt8* sdummy = &yy;
|
|
751 |
switch (func)
|
|
752 |
{
|
|
753 |
case EAtomicFuncSWP: r=DoSwap<TUint8>(aPtr, aT, aA, dummy); break;
|
|
754 |
case EAtomicFuncADD: r=DoAdd<TUint8>(aPtr, aT, aA, dummy); break;
|
|
755 |
case EAtomicFuncAND: r=DoAndOr<TUint8>(aPtr, aT, aA, dummy); break;
|
|
756 |
case EAtomicFuncXOR: r=DoXor<TUint8>(aPtr, aT, aA, dummy); break;
|
|
757 |
case EAtomicFuncAXO: r=DoAxo<TUint8>(aPtr, aT, aA, dummy); break;
|
|
758 |
case EAtomicFuncTAU: r=DoThAdd<TUint8>(aPtr, aT, aA, dummy); break;
|
|
759 |
case EAtomicFuncTAS: r=DoThAdd<TInt8>(aPtr, aT, aA, sdummy); break;
|
|
760 |
case EAtomicFuncCAS: r=DoCas<TUint8>(aPtr, aT, aA, dummy); break;
|
|
761 |
default: break;
|
|
762 |
}
|
|
763 |
break;
|
|
764 |
}
|
|
765 |
case 2:
|
|
766 |
{
|
|
767 |
TUint16 xx;
|
|
768 |
TUint16* dummy = &xx;
|
|
769 |
TInt16 yy;
|
|
770 |
TInt16* sdummy = &yy;
|
|
771 |
switch (func)
|
|
772 |
{
|
|
773 |
case EAtomicFuncSWP: r=DoSwap<TUint16>(aPtr, aT, aA, dummy); break;
|
|
774 |
case EAtomicFuncADD: r=DoAdd<TUint16>(aPtr, aT, aA, dummy); break;
|
|
775 |
case EAtomicFuncAND: r=DoAndOr<TUint16>(aPtr, aT, aA, dummy); break;
|
|
776 |
case EAtomicFuncXOR: r=DoXor<TUint16>(aPtr, aT, aA, dummy); break;
|
|
777 |
case EAtomicFuncAXO: r=DoAxo<TUint16>(aPtr, aT, aA, dummy); break;
|
|
778 |
case EAtomicFuncTAU: r=DoThAdd<TUint16>(aPtr, aT, aA, dummy); break;
|
|
779 |
case EAtomicFuncTAS: r=DoThAdd<TInt16>(aPtr, aT, aA, sdummy); break;
|
|
780 |
case EAtomicFuncCAS: r=DoCas<TUint16>(aPtr, aT, aA, dummy); break;
|
|
781 |
default: break;
|
|
782 |
}
|
|
783 |
break;
|
|
784 |
}
|
|
785 |
case 4:
|
|
786 |
{
|
|
787 |
TUint32 xx;
|
|
788 |
TUint32* dummy = &xx;
|
|
789 |
TInt32 yy;
|
|
790 |
TInt32* sdummy = &yy;
|
|
791 |
switch (func)
|
|
792 |
{
|
|
793 |
case EAtomicFuncSWP: r=DoSwap<TUint32>(aPtr, aT, aA, dummy); break;
|
|
794 |
case EAtomicFuncADD: r=DoAdd<TUint32>(aPtr, aT, aA, dummy); break;
|
|
795 |
case EAtomicFuncAND: r=DoAndOr<TUint32>(aPtr, aT, aA, dummy); break;
|
|
796 |
case EAtomicFuncXOR: r=DoXor<TUint32>(aPtr, aT, aA, dummy); break;
|
|
797 |
case EAtomicFuncAXO: r=DoAxo<TUint32>(aPtr, aT, aA, dummy); break;
|
|
798 |
case EAtomicFuncTAU: r=DoThAdd<TUint32>(aPtr, aT, aA, dummy); break;
|
|
799 |
case EAtomicFuncTAS: r=DoThAdd<TInt32>(aPtr, aT, aA, sdummy); break;
|
|
800 |
case EAtomicFuncCAS: r=DoCas<TUint32>(aPtr, aT, aA, dummy); break;
|
|
801 |
default: break;
|
|
802 |
}
|
|
803 |
break;
|
|
804 |
}
|
|
805 |
case 8:
|
|
806 |
{
|
|
807 |
TUint64A xx;
|
|
808 |
TUint64* dummy = &xx;
|
|
809 |
TInt64A yy;
|
|
810 |
TInt64* sdummy = &yy;
|
|
811 |
switch (func)
|
|
812 |
{
|
|
813 |
case EAtomicFuncSWP: r=DoSwap<TUint64>(aPtr, aT, aA, dummy); break;
|
|
814 |
case EAtomicFuncADD: r=DoAdd<TUint64>(aPtr, aT, aA, dummy); break;
|
|
815 |
case EAtomicFuncAND: r=DoAndOr<TUint64>(aPtr, aT, aA, dummy); break;
|
|
816 |
case EAtomicFuncXOR: r=DoXor<TUint64>(aPtr, aT, aA, dummy); break;
|
|
817 |
case EAtomicFuncAXO: r=DoAxo<TUint64>(aPtr, aT, aA, dummy); break;
|
|
818 |
case EAtomicFuncTAU: r=DoThAdd<TUint64>(aPtr, aT, aA, dummy); break;
|
|
819 |
case EAtomicFuncTAS: r=DoThAdd<TInt64>(aPtr, aT, aA, sdummy); break;
|
|
820 |
case EAtomicFuncCAS: r=DoCas<TUint64>(aPtr, aT, aA, dummy); break;
|
|
821 |
default: break;
|
|
822 |
}
|
|
823 |
break;
|
|
824 |
}
|
|
825 |
default:
|
|
826 |
break;
|
|
827 |
}
|
|
828 |
++aT->iCount;
|
|
829 |
return r;
|
|
830 |
}
|
|
831 |
|
|
832 |
|
|
833 |
|