sl@0: // Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32test\bench\t_memfnc.cpp sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: const TInt Len64K = 64*1024; sl@0: sl@0: volatile extern TInt count; sl@0: volatile extern TInt iters; sl@0: extern TInt8* trg; sl@0: extern TInt8* src; sl@0: extern TInt8 trgoffset; sl@0: extern TInt8 srcoffset; sl@0: extern TInt len; sl@0: sl@0: GLREF_C TInt PurgeCache() sl@0: { sl@0: TInt8* purgetrg; sl@0: TInt8* purgesrc; sl@0: sl@0: purgetrg=(TInt8*)User::Alloc(Len64K); sl@0: purgesrc=(TInt8*)User::Alloc(Len64K); sl@0: sl@0: Mem::Copy(purgetrg,purgesrc,Len64K); sl@0: sl@0: User::Free(purgetrg); sl@0: User::Free(purgesrc); sl@0: return 0; sl@0: } sl@0: sl@0: TInt MemBaseline(TAny*) sl@0: { sl@0: FOREVER sl@0: { sl@0: for (iters=0; iters<8192; ) sl@0: { sl@0: // eight off, unrolled for accuracy sl@0: iters++; sl@0: iters++; sl@0: iters++; sl@0: iters++; sl@0: sl@0: iters++; sl@0: iters++; sl@0: iters++; sl@0: iters++; sl@0: } sl@0: sl@0: count++; sl@0: } sl@0: } sl@0: sl@0: TInt MemCopy(TAny*) sl@0: { sl@0: FOREVER sl@0: { sl@0: Mem::Copy(trgoffset+trg,srcoffset+src,len); sl@0: count++; sl@0: } sl@0: } sl@0: sl@0: TInt MemFill(TAny*) sl@0: { sl@0: FOREVER sl@0: { sl@0: Mem::Fill(trgoffset+trg,len,42); sl@0: count++; sl@0: } sl@0: } sl@0: sl@0: TInt MemSwap(TAny*) sl@0: { sl@0: FOREVER sl@0: { sl@0: Mem::Swap(trgoffset+trg,srcoffset+src,len); sl@0: count++; sl@0: } sl@0: } sl@0: sl@0: /// For lengths smaller than the allocated size of 64K. Pointers are stepped sl@0: /// though RAM so that we never hit the cache. Stepping is done backwards to sl@0: /// foil any automatic preparation for loading of the next cache line. sl@0: TInt MemCopyUncached(TAny*) sl@0: { sl@0: TUint step = (len + 31) & (~31); // length rounded up to cache line size sl@0: sl@0: TInt8* slimit = src + 2*Len64K - step + srcoffset; sl@0: TInt8* tlimit = trg + 2*Len64K - step + trgoffset; sl@0: sl@0: TInt8* s = slimit; sl@0: TInt8* t = tlimit; sl@0: sl@0: FOREVER sl@0: { sl@0: Mem::Copy(t,s,len); sl@0: s -= step; sl@0: t -= step; sl@0: if (s < src) sl@0: { sl@0: s = slimit; sl@0: t = tlimit; sl@0: } sl@0: count++; sl@0: } sl@0: } sl@0: sl@0: // See comments for MemCopyUncached above sl@0: TInt MemFillUncached(TAny*) sl@0: { sl@0: TUint step = (len + 31) & (~31); // length rounded up to cache line size sl@0: sl@0: TInt8* tlimit = trg + 2*Len64K - step + trgoffset; sl@0: TInt8* t = tlimit; sl@0: sl@0: FOREVER sl@0: { sl@0: Mem::Fill(t,len,42); sl@0: t -= step; sl@0: if (t < trg) sl@0: t = tlimit; sl@0: count++; sl@0: } sl@0: } sl@0: sl@0: TInt WordMove(TAny*) sl@0: { sl@0: FOREVER sl@0: { sl@0: wordmove(trgoffset+trg,srcoffset+src,len); sl@0: count++; sl@0: } sl@0: } sl@0: sl@0: // See comments for MemCopyUncached above sl@0: TInt WordMoveUncached(TAny*) sl@0: { sl@0: TUint step = (len + 31) & (~31); // length rounded up to cache line size sl@0: sl@0: TInt8* slimit = src + 2*Len64K - step + srcoffset; sl@0: TInt8* tlimit = trg + 2*Len64K - step + trgoffset; sl@0: sl@0: TInt8* s = slimit; sl@0: TInt8* t = tlimit; sl@0: sl@0: FOREVER sl@0: { sl@0: wordmove(t,s,len); sl@0: s -= step; sl@0: t -= step; sl@0: if (s < src) sl@0: { sl@0: s = slimit; sl@0: t = tlimit; sl@0: } sl@0: count++; sl@0: } sl@0: }