os/kernelhwsrv/kerneltest/e32test/system/t_atomic.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// e32test\system\t_atomic.h
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <e32atomics.h>
sl@0
    19
sl@0
    20
#ifdef __VC32__
sl@0
    21
#pragma warning( disable : 4244 )	/* conversion to shorter type - possible loss of data */
sl@0
    22
#endif
sl@0
    23
sl@0
    24
const TInt KMaxThreads = 8;
sl@0
    25
sl@0
    26
#ifdef __KERNEL_MODE__
sl@0
    27
#include <kernel/kernel.h>
sl@0
    28
#undef	DEBUGPRINT
sl@0
    29
#define	DEBUGPRINT	Kern::Printf
sl@0
    30
#else
sl@0
    31
extern void UPrintf(const char*, ...);
sl@0
    32
#undef	DEBUGPRINT
sl@0
    33
#define DEBUGPRINT	UPrintf
sl@0
    34
#endif
sl@0
    35
sl@0
    36
#undef	__INT64_ALIGNED__
sl@0
    37
#if (defined(__GNUC__) && (__GNUC__ >= 3)) || defined(__EABI__)
sl@0
    38
#define	__INT64_ALIGNED__
sl@0
    39
#endif
sl@0
    40
sl@0
    41
#ifdef __INT64_ALIGNED__
sl@0
    42
typedef	TUint64	TUint64A;
sl@0
    43
typedef	TInt64	TInt64A;
sl@0
    44
#else
sl@0
    45
sl@0
    46
class TUint64A
sl@0
    47
	{
sl@0
    48
public:
sl@0
    49
	inline const TUint64* operator&() const
sl@0
    50
		{ return ((const TUint64*)((T_UintPtr(this)+7)&~7)); }
sl@0
    51
	inline TUint64* operator&()
sl@0
    52
		{ return ((TUint64*)((T_UintPtr(this)+7)&~7)); }
sl@0
    53
private:
sl@0
    54
	TUint64 i_Data[2];
sl@0
    55
	};
sl@0
    56
sl@0
    57
class TInt64A
sl@0
    58
	{
sl@0
    59
public:
sl@0
    60
	inline const TInt64* operator&() const
sl@0
    61
		{ return ((const TInt64*)((T_UintPtr(this)+7)&~7)); }
sl@0
    62
	inline TInt64* operator&()
sl@0
    63
		{ return ((TInt64*)((T_UintPtr(this)+7)&~7)); }
sl@0
    64
private:
sl@0
    65
	TUint64 i_Data[2];
sl@0
    66
	};
sl@0
    67
sl@0
    68
#endif
sl@0
    69
sl@0
    70
struct TDGBase
sl@0
    71
	{
sl@0
    72
	TInt Execute();
sl@0
    73
	void Dump(const char*);
sl@0
    74
sl@0
    75
	TUint64	i0;
sl@0
    76
	TUint64	i1;
sl@0
    77
	TUint64	i2;
sl@0
    78
	TUint64	i3;
sl@0
    79
	TInt	iIndex;
sl@0
    80
	};
sl@0
    81
sl@0
    82
struct TAtomicAction
sl@0
    83
	{
sl@0
    84
	TUint64	i0;			// first parameter to operation
sl@0
    85
	TUint64	i1;			// second parameter to operation
sl@0
    86
	TUint64	i2;			// third parameter to operation
sl@0
    87
	TInt	iIndex;		// index of atomic function
sl@0
    88
	TInt	iThread;	// thread identifier
sl@0
    89
	};
sl@0
    90
sl@0
    91
struct TPerThread
sl@0
    92
	{
sl@0
    93
	TUint64	iDiff;		// accumulated difference
sl@0
    94
	TUint64	iXor;		// accumulated XOR
sl@0
    95
	TUint64 iFailCount;	// failure count for CAS operations
sl@0
    96
	TUint64 iCount;		// iteration count
sl@0
    97
	};
sl@0
    98
sl@0
    99
extern "C" TInt DoAtomicAction(TAny* aPtr, TPerThread* aT, TAtomicAction& aA);
sl@0
   100
sl@0
   101
enum TMemoryOrder
sl@0
   102
	{
sl@0
   103
	EOrderRelaxed=0,
sl@0
   104
	EOrderAcquire=1,
sl@0
   105
	EOrderRelease=2,
sl@0
   106
	EOrderOrdered=3,
sl@0
   107
	};
sl@0
   108
sl@0
   109
enum TAtomicFunc
sl@0
   110
	{
sl@0
   111
	EAtomicFuncLOAD=0,
sl@0
   112
	EAtomicFuncSTORE=1,
sl@0
   113
	EAtomicFuncSWP=2,
sl@0
   114
	EAtomicFuncADD=3,
sl@0
   115
	EAtomicFuncAND=4,
sl@0
   116
	EAtomicFuncIOR=5,
sl@0
   117
	EAtomicFuncXOR=6,
sl@0
   118
	EAtomicFuncAXO=7,
sl@0
   119
	EAtomicFuncTAU=8,
sl@0
   120
	EAtomicFuncTAS=9,
sl@0
   121
	EAtomicFuncCAS=10,
sl@0
   122
	EAtomicFuncN
sl@0
   123
	};
sl@0
   124
sl@0
   125
enum TFuncType
sl@0
   126
	{
sl@0
   127
	EFuncTypeInvalid=0,
sl@0
   128
	EFuncTypeLoad=1,
sl@0
   129
	EFuncTypeRmw1=2,
sl@0
   130
	EFuncTypeRmw2=3,
sl@0
   131
	EFuncTypeRmw3=4,
sl@0
   132
	EFuncTypeCas=5,
sl@0
   133
	};
sl@0
   134
sl@0
   135
#define	FUNCS_PER_SIZE			(TUint(EAtomicFuncN)*4)
sl@0
   136
#define TOTAL_FUNCS				(FUNCS_PER_SIZE*4)
sl@0
   137
#define	INDEXES_PER_SIZE		(16*4)
sl@0
   138
#define	TOTAL_INDEXES			(INDEXES_PER_SIZE*4)
sl@0
   139
sl@0
   140
#define FUNCATTR(func,size,ord,type)	((TUint(func)<<24)|(TUint(size)<<16)|(TUint(ord)<<8)|(TUint(type)))
sl@0
   141
#define	ATTR_TO_TYPE(attr)				((attr)&0xff)
sl@0
   142
#define	ATTR_TO_ORD(attr)				(((attr)>>8)&0xff)
sl@0
   143
#define	ATTR_TO_SIZE(attr)				(((attr)>>16)&0xff)
sl@0
   144
#define	ATTR_TO_FUNC(attr)				(((attr)>>24)&0xff)
sl@0
   145
#define	FUNCATTR2(func,size,type)	\
sl@0
   146
			FUNCATTR(func,size,EOrderRelaxed,type),	FUNCATTR(func,size,EOrderAcquire,type), FUNCATTR(func,size,EOrderRelease,type), FUNCATTR(func,size,EOrderOrdered,type)
sl@0
   147
#define	FUNCATTR2A(func,size,type)	\
sl@0
   148
												0,	FUNCATTR(func,size,EOrderAcquire,type),										0,										0
sl@0
   149
#define	FUNCATTR2B(func,size,type)	\
sl@0
   150
												0,										0,	FUNCATTR(func,size,EOrderRelease,type),	FUNCATTR(func,size,EOrderOrdered,type)
sl@0
   151
#define	FUNCATTR3(size)				\
sl@0
   152
			FUNCATTR2A(EAtomicFuncLOAD,size,EFuncTypeLoad),		\
sl@0
   153
			FUNCATTR2B(EAtomicFuncSTORE,size,EFuncTypeRmw1),	\
sl@0
   154
			FUNCATTR2(EAtomicFuncSWP,size,EFuncTypeRmw1),		\
sl@0
   155
			FUNCATTR2(EAtomicFuncADD,size,EFuncTypeRmw1),		\
sl@0
   156
			FUNCATTR2(EAtomicFuncAND,size,EFuncTypeRmw1),		\
sl@0
   157
			FUNCATTR2(EAtomicFuncIOR,size,EFuncTypeRmw1),		\
sl@0
   158
			FUNCATTR2(EAtomicFuncXOR,size,EFuncTypeRmw1),		\
sl@0
   159
			FUNCATTR2(EAtomicFuncAXO,size,EFuncTypeRmw2),		\
sl@0
   160
			FUNCATTR2(EAtomicFuncTAU,size,EFuncTypeRmw3),		\
sl@0
   161
			FUNCATTR2(EAtomicFuncTAS,size,EFuncTypeRmw3),		\
sl@0
   162
			FUNCATTR2(EAtomicFuncCAS,size,EFuncTypeCas),		\
sl@0
   163
			0,	0,	0,	0,										\
sl@0
   164
			0,	0,	0,	0,										\
sl@0
   165
			0,	0,	0,	0,										\
sl@0
   166
			0,	0,	0,	0,										\
sl@0
   167
			0,	0,	0,	0
sl@0
   168
sl@0
   169
sl@0
   170
#define	__DO_STRINGIFY__(x)			#x
sl@0
   171
#define	__STRINGIFY__(x)			__DO_STRINGIFY__(x)
sl@0
   172
#define __concat3__(a,b,c)			a##b##c
sl@0
   173
#define __concat5__(a,b,c,d,e)		a##b##c##d##e
sl@0
   174
#define FUNCNAME(func,size,ord)		__STRINGIFY__(__concat3__(func,size,ord))
sl@0
   175
#define ATOMICFUNC(func,size,ord)	__concat5__(__e32_atomic_,func,_,ord,size)
sl@0
   176
#define CONTROLFUNC(func,size,ord)	__concat3__(__nonatomic_,func,size)
sl@0
   177
#define	FUNCNAME2(func,size)		FUNCNAME(func,size,rlx), FUNCNAME(func,size,acq), FUNCNAME(func,size,rel), FUNCNAME(func,size,ord)
sl@0
   178
#define	FUNCNAME3(size)	\
sl@0
   179
			FUNCNAME2(load,size),	\
sl@0
   180
			FUNCNAME2(store,size),	\
sl@0
   181
			FUNCNAME2(swp,size),	\
sl@0
   182
			FUNCNAME2(add,size),	\
sl@0
   183
			FUNCNAME2(and,size),	\
sl@0
   184
			FUNCNAME2(ior,size),	\
sl@0
   185
			FUNCNAME2(xor,size),	\
sl@0
   186
			FUNCNAME2(axo,size),	\
sl@0
   187
			FUNCNAME2(tau,size),	\
sl@0
   188
			FUNCNAME2(tas,size),	\
sl@0
   189
			FUNCNAME2(cas,size),	\
sl@0
   190
			"", "", "", "",			\
sl@0
   191
			"", "", "", "",			\
sl@0
   192
			"", "", "", "",			\
sl@0
   193
			"", "", "", "",			\
sl@0
   194
			"", "", "", ""
sl@0
   195
sl@0
   196
sl@0
   197
#define	ATOMICFUNC2(func,size)		(PFV)&ATOMICFUNC(func,size,rlx), (PFV)&ATOMICFUNC(func,size,acq), (PFV)&ATOMICFUNC(func,size,rel), (PFV)&ATOMICFUNC(func,size,ord)
sl@0
   198
#define	ATOMICFUNC2A(func,size)									0,	(PFV)&ATOMICFUNC(func,size,acq),								0,							0
sl@0
   199
#define	ATOMICFUNC2B(func,size)									0,								0,	(PFV)&ATOMICFUNC(func,size,rel), (PFV)&ATOMICFUNC(func,size,ord)
sl@0
   200
#define	ATOMICFUNC3(size)				\
sl@0
   201
			ATOMICFUNC2A(load,size),	\
sl@0
   202
			ATOMICFUNC2B(store,size),	\
sl@0
   203
			ATOMICFUNC2(swp,size),		\
sl@0
   204
			ATOMICFUNC2(add,size),		\
sl@0
   205
			ATOMICFUNC2(and,size),		\
sl@0
   206
			ATOMICFUNC2(ior,size),		\
sl@0
   207
			ATOMICFUNC2(xor,size),		\
sl@0
   208
			ATOMICFUNC2(axo,size),		\
sl@0
   209
			ATOMICFUNC2(tau,size),		\
sl@0
   210
			ATOMICFUNC2(tas,size),		\
sl@0
   211
			ATOMICFUNC2(cas,size),		\
sl@0
   212
			0, 0, 0, 0,					\
sl@0
   213
			0, 0, 0, 0,					\
sl@0
   214
			0, 0, 0, 0,					\
sl@0
   215
			0, 0, 0, 0,					\
sl@0
   216
			0, 0, 0, 0
sl@0
   217
sl@0
   218
sl@0
   219
#define	CONTROLFUNC2(func,size)		(PFV)&CONTROLFUNC(func,size,rlx), (PFV)&CONTROLFUNC(func,size,acq), (PFV)&CONTROLFUNC(func,size,rel), (PFV)&CONTROLFUNC(func,size,ord)
sl@0
   220
#define	CONTROLFUNC2A(func,size)								0,	(PFV)&CONTROLFUNC(func,size,acq),								0,							0
sl@0
   221
#define	CONTROLFUNC2B(func,size)								0,								0,	(PFV)&CONTROLFUNC(func,size,rel), (PFV)&CONTROLFUNC(func,size,ord)
sl@0
   222
#define	CONTROLFUNC3(size)				\
sl@0
   223
			CONTROLFUNC2A(load,size),	\
sl@0
   224
			CONTROLFUNC2B(store,size),	\
sl@0
   225
			CONTROLFUNC2(swp,size),		\
sl@0
   226
			CONTROLFUNC2(add,size),		\
sl@0
   227
			CONTROLFUNC2(and,size),		\
sl@0
   228
			CONTROLFUNC2(ior,size),		\
sl@0
   229
			CONTROLFUNC2(xor,size),		\
sl@0
   230
			CONTROLFUNC2(axo,size),		\
sl@0
   231
			CONTROLFUNC2(tau,size),		\
sl@0
   232
			CONTROLFUNC2(tas,size),		\
sl@0
   233
			CONTROLFUNC2(cas,size),		\
sl@0
   234
			0, 0, 0, 0,					\
sl@0
   235
			0, 0, 0, 0,					\
sl@0
   236
			0, 0, 0, 0,					\
sl@0
   237
			0, 0, 0, 0,					\
sl@0
   238
			0, 0, 0, 0
sl@0
   239
sl@0
   240
sl@0
   241
#ifdef __INCLUDE_FUNC_NAMES__
sl@0
   242
extern "C" const char* FuncName[] =
sl@0
   243
	{
sl@0
   244
	FUNCNAME3(8),
sl@0
   245
	FUNCNAME3(16),
sl@0
   246
	FUNCNAME3(32),
sl@0
   247
	FUNCNAME3(64)
sl@0
   248
	};
sl@0
   249
#endif
sl@0
   250
sl@0
   251
typedef void (*PFV)();
sl@0
   252
sl@0
   253
#ifdef __INCLUDE_ATOMIC_FUNCTIONS__
sl@0
   254
extern "C" const PFV AtomicFuncPtr[] =
sl@0
   255
	{
sl@0
   256
	ATOMICFUNC3(8),
sl@0
   257
	ATOMICFUNC3(16),
sl@0
   258
	ATOMICFUNC3(32),
sl@0
   259
	ATOMICFUNC3(64)
sl@0
   260
	};
sl@0
   261
#endif
sl@0
   262
sl@0
   263
#ifdef __INCLUDE_CONTROL_FUNCTIONS__
sl@0
   264
extern "C" {
sl@0
   265
sl@0
   266
// Simulated versions of atomic functions without the atomicity
sl@0
   267
extern TUint8	__nonatomic_load8(const volatile TAny* a);
sl@0
   268
extern TUint8	__nonatomic_store8(volatile TAny* a, TUint8 v);
sl@0
   269
extern TUint8	__nonatomic_swp8(volatile TAny* a, TUint8 v);
sl@0
   270
extern TBool	__nonatomic_cas8(volatile TAny* a, TUint8* q, TUint8 v);
sl@0
   271
extern TUint8	__nonatomic_add8(volatile TAny* a, TUint8 v);
sl@0
   272
extern TUint8	__nonatomic_and8(volatile TAny* a, TUint8 v);
sl@0
   273
extern TUint8	__nonatomic_ior8(volatile TAny* a, TUint8 v);
sl@0
   274
extern TUint8	__nonatomic_xor8(volatile TAny* a, TUint8 v);
sl@0
   275
extern TUint8	__nonatomic_axo8(volatile TAny* a, TUint8 u, TUint8 v);
sl@0
   276
extern TUint8	__nonatomic_tau8(volatile TAny* a, TUint8 t, TUint8 u, TUint8 v);
sl@0
   277
extern TInt8	__nonatomic_tas8(volatile TAny* a, TInt8 t, TInt8 u, TInt8 v);
sl@0
   278
sl@0
   279
extern TUint16	__nonatomic_load16(const volatile TAny* a);
sl@0
   280
extern TUint16	__nonatomic_store16(volatile TAny* a, TUint16 v);
sl@0
   281
extern TUint16	__nonatomic_swp16(volatile TAny* a, TUint16 v);
sl@0
   282
extern TBool	__nonatomic_cas16(volatile TAny* a, TUint16* q, TUint16 v);
sl@0
   283
extern TUint16	__nonatomic_add16(volatile TAny* a, TUint16 v);
sl@0
   284
extern TUint16	__nonatomic_and16(volatile TAny* a, TUint16 v);
sl@0
   285
extern TUint16	__nonatomic_ior16(volatile TAny* a, TUint16 v);
sl@0
   286
extern TUint16	__nonatomic_xor16(volatile TAny* a, TUint16 v);
sl@0
   287
extern TUint16	__nonatomic_axo16(volatile TAny* a, TUint16 u, TUint16 v);
sl@0
   288
extern TUint16	__nonatomic_tau16(volatile TAny* a, TUint16 t, TUint16 u, TUint16 v);
sl@0
   289
extern TInt16	__nonatomic_tas16(volatile TAny* a, TInt16 t, TInt16 u, TInt16 v);
sl@0
   290
sl@0
   291
extern TUint32	__nonatomic_load32(const volatile TAny* a);
sl@0
   292
extern TUint32	__nonatomic_store32(volatile TAny* a, TUint32 v);
sl@0
   293
extern TUint32	__nonatomic_swp32(volatile TAny* a, TUint32 v);
sl@0
   294
extern TBool	__nonatomic_cas32(volatile TAny* a, TUint32* q, TUint32 v);
sl@0
   295
extern TUint32	__nonatomic_add32(volatile TAny* a, TUint32 v);
sl@0
   296
extern TUint32	__nonatomic_and32(volatile TAny* a, TUint32 v);
sl@0
   297
extern TUint32	__nonatomic_ior32(volatile TAny* a, TUint32 v);
sl@0
   298
extern TUint32	__nonatomic_xor32(volatile TAny* a, TUint32 v);
sl@0
   299
extern TUint32	__nonatomic_axo32(volatile TAny* a, TUint32 u, TUint32 v);
sl@0
   300
extern TUint32	__nonatomic_tau32(volatile TAny* a, TUint32 t, TUint32 u, TUint32 v);
sl@0
   301
extern TInt32	__nonatomic_tas32(volatile TAny* a, TInt32 t, TInt32 u, TInt32 v);
sl@0
   302
sl@0
   303
extern TUint64	__nonatomic_load64(const volatile TAny* a);
sl@0
   304
extern TUint64	__nonatomic_store64(volatile TAny* a, TUint64 v);
sl@0
   305
extern TUint64	__nonatomic_swp64(volatile TAny* a, TUint64 v);
sl@0
   306
extern TBool	__nonatomic_cas64(volatile TAny* a, TUint64* q, TUint64 v);
sl@0
   307
extern TUint64	__nonatomic_add64(volatile TAny* a, TUint64 v);
sl@0
   308
extern TUint64	__nonatomic_and64(volatile TAny* a, TUint64 v);
sl@0
   309
extern TUint64	__nonatomic_ior64(volatile TAny* a, TUint64 v);
sl@0
   310
extern TUint64	__nonatomic_xor64(volatile TAny* a, TUint64 v);
sl@0
   311
extern TUint64	__nonatomic_axo64(volatile TAny* a, TUint64 u, TUint64 v);
sl@0
   312
extern TUint64	__nonatomic_tau64(volatile TAny* a, TUint64 t, TUint64 u, TUint64 v);
sl@0
   313
extern TInt64	__nonatomic_tas64(volatile TAny* a, TInt64 t, TInt64 u, TInt64 v);
sl@0
   314
sl@0
   315
} // extern "C"
sl@0
   316
sl@0
   317
sl@0
   318
extern "C" const PFV ControlFuncPtr[] =
sl@0
   319
	{
sl@0
   320
	CONTROLFUNC3(8),
sl@0
   321
	CONTROLFUNC3(16),
sl@0
   322
	CONTROLFUNC3(32),
sl@0
   323
	CONTROLFUNC3(64)
sl@0
   324
	};
sl@0
   325
#endif
sl@0
   326
sl@0
   327
#ifdef __INCLUDE_FUNCTION_ATTRIBUTES__
sl@0
   328
extern "C" const TUint FuncAttr[] =
sl@0
   329
	{
sl@0
   330
	FUNCATTR3(1),
sl@0
   331
	FUNCATTR3(2),
sl@0
   332
	FUNCATTR3(4),
sl@0
   333
	FUNCATTR3(8)
sl@0
   334
	};
sl@0
   335
#endif
sl@0
   336
sl@0
   337
template<class T>
sl@0
   338
struct TLoadFn	//	load
sl@0
   339
	{
sl@0
   340
	typedef T (*F)(const volatile TAny*);
sl@0
   341
	};
sl@0
   342
sl@0
   343
template<class T>
sl@0
   344
struct TRmw1Fn	// store, swp, add, and, ior, xor
sl@0
   345
	{
sl@0
   346
	typedef T (*F)(volatile TAny*, T);
sl@0
   347
	};
sl@0
   348
sl@0
   349
template<class T>
sl@0
   350
struct TRmw2Fn	// axo
sl@0
   351
	{
sl@0
   352
	typedef T (*F)(volatile TAny*, T, T);
sl@0
   353
	};
sl@0
   354
sl@0
   355
template<class T>
sl@0
   356
struct TRmw3Fn	// tau, tas
sl@0
   357
	{
sl@0
   358
	typedef T (*F)(volatile TAny*, T, T, T);
sl@0
   359
	};
sl@0
   360
sl@0
   361
template<class T>
sl@0
   362
struct TCasFn	// cas
sl@0
   363
	{
sl@0
   364
	typedef TBool (*F)(volatile TAny*, T*, T);
sl@0
   365
	};
sl@0
   366
sl@0
   367
class TEnclosed
sl@0
   368
	{
sl@0
   369
public:
sl@0
   370
	TEnclosed(TInt aSize);
sl@0
   371
	TAny* Ptr();
sl@0
   372
	TInt Next();
sl@0
   373
	void Init();
sl@0
   374
	TInt Verify();
sl@0
   375
	TInt Offset() const {return iOffset;}
sl@0
   376
private:
sl@0
   377
	TUint64* iData;
sl@0
   378
	TUint64* iBackup;
sl@0
   379
	TUint64	i_Data[17];
sl@0
   380
	TInt iOffset;
sl@0
   381
	TInt iSize;
sl@0
   382
	};
sl@0
   383
sl@0
   384
template<class T>
sl@0
   385
class Transform
sl@0
   386
	{
sl@0
   387
public:
sl@0
   388
	inline static T A();
sl@0
   389
	inline static T B();
sl@0
   390
	static T F(T aOrig);						// return Ax+B mod M (M=2^n, n=number of bits in T)
sl@0
   391
	static T Pow(T aBase, TUint64 aExp);		// return aBase^aExp mod M
sl@0
   392
	static T PowerSum(T aBase, TUint64 aExp);	// return 1 + T + T^2 + ... + T^(aExp-1) mod M
sl@0
   393
	static T F_iter(T aOrig, TUint64 aCount);	// return result of applying F iterated aCount times to aOrig
sl@0
   394
	};
sl@0
   395
sl@0
   396
TEMPLATE_SPECIALIZATION inline TUint8 Transform<TUint8>::A()
sl@0
   397
	{ return 19; }
sl@0
   398
TEMPLATE_SPECIALIZATION inline TUint8 Transform<TUint8>::B()
sl@0
   399
	{ return 29; }
sl@0
   400
sl@0
   401
TEMPLATE_SPECIALIZATION inline TUint16 Transform<TUint16>::A()
sl@0
   402
	{ return 487; }
sl@0
   403
TEMPLATE_SPECIALIZATION inline TUint16 Transform<TUint16>::B()
sl@0
   404
	{ return 12983; }
sl@0
   405
sl@0
   406
TEMPLATE_SPECIALIZATION inline TUint32 Transform<TUint32>::A()
sl@0
   407
	{ return 29943829; }
sl@0
   408
TEMPLATE_SPECIALIZATION inline TUint32 Transform<TUint32>::B()
sl@0
   409
	{ return 104729; }
sl@0
   410
sl@0
   411
TEMPLATE_SPECIALIZATION inline TUint64 Transform<TUint64>::A()
sl@0
   412
	{ return UI64LIT(2862933555777941757); }
sl@0
   413
TEMPLATE_SPECIALIZATION inline TUint64 Transform<TUint64>::B()
sl@0
   414
	{ return UI64LIT(104917093); }
sl@0
   415
sl@0
   416
template<class T>
sl@0
   417
T Transform<T>::F(T aOrig)
sl@0
   418
	{
sl@0
   419
	return (T)(aOrig * Transform<T>::A() + Transform<T>::B());
sl@0
   420
	}
sl@0
   421
sl@0
   422
template<class T>
sl@0
   423
T Transform<T>::Pow(T aBase, TUint64 aExp)
sl@0
   424
	{
sl@0
   425
	T result(1);
sl@0
   426
	T multiplier(aBase);
sl@0
   427
	while (aExp)
sl@0
   428
		{
sl@0
   429
		if (aExp&1)
sl@0
   430
			result *= multiplier;
sl@0
   431
		aExp >>= 1;
sl@0
   432
		if (aExp)
sl@0
   433
			multiplier *= multiplier;
sl@0
   434
		}
sl@0
   435
	return (T)result;
sl@0
   436
	}
sl@0
   437
sl@0
   438
template<class T>
sl@0
   439
T Transform<T>::PowerSum(T aBase, TUint64 aExp)
sl@0
   440
	{
sl@0
   441
	T result(0);
sl@0
   442
	T multiplier(aBase);
sl@0
   443
	T inter(1);
sl@0
   444
	while (aExp)
sl@0
   445
		{
sl@0
   446
		if (aExp&1)
sl@0
   447
			{
sl@0
   448
			result *= multiplier;
sl@0
   449
			result += inter;
sl@0
   450
			}
sl@0
   451
		aExp >>= 1;
sl@0
   452
		if (aExp)
sl@0
   453
			{
sl@0
   454
			inter *= (multiplier + 1);
sl@0
   455
			multiplier *= multiplier;
sl@0
   456
			}
sl@0
   457
		}
sl@0
   458
	return (T)result;
sl@0
   459
	}
sl@0
   460
sl@0
   461
template<class T>
sl@0
   462
T Transform<T>::F_iter(T aOrig, TUint64 aCount)
sl@0
   463
	{
sl@0
   464
	return (T)(Pow(A(),aCount)*aOrig + PowerSum(A(),aCount)*B());
sl@0
   465
	}
sl@0
   466
sl@0
   467
sl@0
   468
sl@0
   469
#ifdef __EPOC32__
sl@0
   470
_LIT(KAtomicTestLddName,"D_ATOMIC");
sl@0
   471
sl@0
   472
class RTestAtomic : public RBusLogicalChannel
sl@0
   473
	{
sl@0
   474
public:
sl@0
   475
	enum TControl
sl@0
   476
		{
sl@0
   477
		ETDGExecuteK=0,
sl@0
   478
		EInitialise=1,
sl@0
   479
		ERetrieve=2,
sl@0
   480
		ESetCurrentThreadTimeslice=3,
sl@0
   481
		ESwitchExecTables=4,
sl@0
   482
		EGetKernelMemoryAddress=5,
sl@0
   483
		EMaxControl
sl@0
   484
		};
sl@0
   485
sl@0
   486
#ifndef __KERNEL_MODE__
sl@0
   487
public:
sl@0
   488
	inline TInt Open()
sl@0
   489
		{ return DoCreate(KAtomicTestLddName,TVersion(),KNullUnit,NULL,NULL); }
sl@0
   490
public:
sl@0
   491
	inline TInt TDGExecuteK(TDGBase& a)
sl@0
   492
		{ return DoControl(ETDGExecuteK, &a); }
sl@0
   493
	inline TInt Initialise(TUint64 aValue)
sl@0
   494
		{ return DoControl(EInitialise, &aValue); }
sl@0
   495
	inline TUint64 Retrieve()
sl@0
   496
		{ TUint64 x; DoControl(ERetrieve, &x); return x; }
sl@0
   497
	inline TInt SetCurrentThreadTimeslice(TInt aTimeslice)
sl@0
   498
		{ return DoControl(ESetCurrentThreadTimeslice, (TAny*)aTimeslice); }
sl@0
   499
	inline TInt SwitchExecTables(TInt aThread)
sl@0
   500
		{ return DoControl(ESwitchExecTables, (TAny*)aThread); }
sl@0
   501
	inline TAny* KernelMemoryAddress()
sl@0
   502
		{ return (TAny*)DoControl(EGetKernelMemoryAddress); }
sl@0
   503
sl@0
   504
	static TInt GetThreadInfo(TPerThread& aInfo);
sl@0
   505
	static TInt SetThreadInfo(const TPerThread& aInfo);
sl@0
   506
	static TInt AtomicAction(TAtomicAction& aAction);
sl@0
   507
	static TInt RestoreExecTable();
sl@0
   508
#endif
sl@0
   509
	};
sl@0
   510
#endif
sl@0
   511
sl@0
   512