os/kernelhwsrv/kerneltest/e32test/bench/t_memfnc.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 1996-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\bench\t_memfnc.cpp
    15 // 
    16 //
    17 
    18 #include <e32std.h>
    19 #include <e32std_private.h>
    20 #include <e32base.h>
    21 #include <e32base_private.h>
    22 
    23 const TInt Len64K = 64*1024;
    24 
    25 volatile extern TInt count;
    26 volatile extern TInt iters;
    27 extern TInt8* trg;
    28 extern TInt8* src;
    29 extern TInt8 trgoffset;
    30 extern TInt8 srcoffset;
    31 extern TInt len;
    32 
    33 GLREF_C TInt PurgeCache()
    34 	{
    35     TInt8* purgetrg;
    36     TInt8* purgesrc;
    37 
    38     purgetrg=(TInt8*)User::Alloc(Len64K);
    39     purgesrc=(TInt8*)User::Alloc(Len64K);
    40 
    41 	Mem::Copy(purgetrg,purgesrc,Len64K);
    42 
    43 	User::Free(purgetrg);
    44 	User::Free(purgesrc);
    45 	return 0;
    46 	}
    47 
    48 TInt MemBaseline(TAny*)
    49 	{
    50 	FOREVER
    51 		{		
    52 		for (iters=0; iters<8192; )
    53 			{
    54 			// eight off, unrolled for accuracy
    55 			iters++;
    56 			iters++;
    57 			iters++;
    58 			iters++;
    59 
    60 			iters++;
    61 			iters++;
    62 			iters++;
    63 			iters++;
    64 			}
    65 
    66 		count++;
    67 		}
    68 	}
    69 
    70 TInt MemCopy(TAny*)
    71 	{
    72 	FOREVER
    73 		{
    74 		Mem::Copy(trgoffset+trg,srcoffset+src,len);
    75 		count++;
    76 		}
    77 	}
    78 
    79 TInt MemFill(TAny*)
    80 	{
    81 	FOREVER
    82 		{
    83 		Mem::Fill(trgoffset+trg,len,42);
    84 		count++;
    85 		}
    86 	}
    87 
    88 TInt MemSwap(TAny*)
    89 	{
    90 	FOREVER
    91 		{
    92 		Mem::Swap(trgoffset+trg,srcoffset+src,len);
    93 		count++;
    94 		}
    95 	}
    96 
    97 /// For lengths smaller than the allocated size of 64K.  Pointers are stepped
    98 /// though RAM so that we never hit the cache.  Stepping is done backwards to
    99 /// foil any automatic preparation for loading of the next cache line.
   100 TInt MemCopyUncached(TAny*)
   101 	{
   102 	TUint step = (len + 31) & (~31);	// length rounded up to cache line size
   103 
   104 	TInt8* slimit = src + 2*Len64K - step + srcoffset;
   105 	TInt8* tlimit = trg + 2*Len64K - step + trgoffset;
   106 
   107 	TInt8* s = slimit;
   108 	TInt8* t = tlimit;
   109 	
   110 	FOREVER
   111 		{
   112 		Mem::Copy(t,s,len);
   113 		s -= step;
   114 		t -= step;
   115 		if (s < src)
   116 			{
   117 			s = slimit;
   118 			t = tlimit;
   119 			}
   120 		count++;
   121 		}
   122 	}
   123 
   124 // See comments for MemCopyUncached above
   125 TInt MemFillUncached(TAny*)
   126 	{
   127 	TUint step = (len + 31) & (~31);	// length rounded up to cache line size
   128 
   129 	TInt8* tlimit = trg + 2*Len64K - step + trgoffset;
   130 	TInt8* t = tlimit;
   131 	
   132 	FOREVER
   133 		{
   134 		Mem::Fill(t,len,42);
   135 		t -= step;
   136 		if (t < trg)
   137 			t = tlimit;
   138 		count++;
   139 		}
   140 	}
   141 
   142 TInt WordMove(TAny*)
   143 	{
   144 	FOREVER
   145 		{
   146 		wordmove(trgoffset+trg,srcoffset+src,len);
   147 		count++;
   148 		}
   149 	}
   150 
   151 // See comments for MemCopyUncached above
   152 TInt WordMoveUncached(TAny*)
   153 	{
   154 	TUint step = (len + 31) & (~31);	// length rounded up to cache line size
   155 
   156 	TInt8* slimit = src + 2*Len64K - step + srcoffset;
   157 	TInt8* tlimit = trg + 2*Len64K - step + trgoffset;
   158 
   159 	TInt8* s = slimit;
   160 	TInt8* t = tlimit;
   161 	
   162 	FOREVER
   163 		{
   164 		wordmove(t,s,len);
   165 		s -= step;
   166 		t -= step;
   167 		if (s < src)
   168 			{
   169 			s = slimit;
   170 			t = tlimit;
   171 			}
   172 		count++;
   173 		}
   174 	}