sl@0: // Copyright (c) 2005-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_userasmfnc.cpp sl@0: // sl@0: // sl@0: sl@0: #include "t_userbm.h" sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: TBool PointsEqual(const TPoint& a, const TPoint& b) sl@0: { sl@0: return a.iX == b.iX && a.iY == b.iY; sl@0: } sl@0: sl@0: TInt ComparePoints(const TPoint& a, const TPoint& b) sl@0: { sl@0: if (a.iX < b.iX) sl@0: return -1; sl@0: else if (a.iX > b.iX) sl@0: return 1; sl@0: else if (a.iY < b.iY) sl@0: return -1; sl@0: else sl@0: return a.iY < b.iY; sl@0: } sl@0: sl@0: RArray ArrayTInt; // RArrayPointerBase derived sl@0: RArray ArrayTUint; // RArrayPointerBase derived sl@0: RPointerArray ArrayTPointPtr; sl@0: RArray ArrayTPoint; sl@0: sl@0: TPoint Point(6, 13); sl@0: TIdentityRelation PointIdentity(PointsEqual); sl@0: TLinearOrder PointOrder(ComparePoints); sl@0: sl@0: CObjectConIx* ObjectConIx; sl@0: CObjectIx* ObjectIx; sl@0: CObjectCon* ObjectCon; sl@0: TInt ObjectHandle; sl@0: sl@0: TUint32 HuffmanTable[] = { 0, 1, 3, 8, 10, 3, 1, 0 }; sl@0: TBitInput BitInput; sl@0: TUint8 BitData[] = { 0, 0, 0, 0 }; sl@0: sl@0: RRegion Region, Region2, Region3; sl@0: TRect Rect1(20, 20, 40, 40); sl@0: sl@0: SPoly* Poly; sl@0: TRealX PolyXCoeffs[] = { 1.0, 3.0, 5.0 }; sl@0: sl@0: RHeap* Heap; sl@0: const TInt HeapSize = 32768; sl@0: const TInt SmallAlloc = 4; sl@0: const TInt Allocs = HeapSize / 2 / (SmallAlloc + RHeap::EAllocCellSize) / 2 * 2; sl@0: sl@0: void InitDataL() sl@0: { sl@0: TInt array1Data[] = { 1, 2, 3, 5, 7, 11, 13, 17, 23 }; sl@0: for (TUint i = 0 ; i < sizeof(array1Data) / sizeof(TInt) ; ++i) sl@0: { sl@0: User::LeaveIfError(ArrayTInt.Append(array1Data[i])); sl@0: User::LeaveIfError(ArrayTUint.Append(array1Data[i])); sl@0: TPoint* p = new (ELeave) TPoint(i, array1Data[i]); sl@0: CleanupStack::PushL(p); sl@0: User::LeaveIfError(ArrayTPointPtr.Append(p)); sl@0: CleanupStack::Pop(p); sl@0: User::LeaveIfError(ArrayTPoint.Append(*p)); sl@0: } sl@0: sl@0: ObjectConIx = CObjectConIx::NewL(); sl@0: ObjectCon = ObjectConIx->CreateL(); sl@0: ObjectIx = CObjectIx::NewL(); sl@0: CObject* o = new (ELeave) CObject; sl@0: ObjectCon->AddL(o); sl@0: ObjectHandle = ObjectIx->AddL(o); sl@0: sl@0: Huffman::HuffmanL(HuffmanTable, sizeof(HuffmanTable) / sizeof(TUint32), HuffmanTable); sl@0: Huffman::Decoding(HuffmanTable, sizeof(HuffmanTable) / sizeof(TUint32), HuffmanTable); sl@0: sl@0: Region.AddRect(TRect(10, 10, 30, 30)); sl@0: Region.AddRect(TRect(30, 20, 50, 50)); sl@0: Region.AddRect(TRect(10, 50, 50, 60)); sl@0: sl@0: Region2.AddRect(TRect(0, 40, 100, 60)); sl@0: Region2.AddRect(TRect(40, 0, 60, 100)); sl@0: Region2.AddRect(TRect(30, 30, 70, 70)); sl@0: sl@0: Region3.AddRect(TRect(0, 30, 100, 40)); sl@0: Region3.AddRect(TRect(0, 0, 100, 10)); sl@0: Region3.AddRect(TRect(0, 20, 100, 30)); sl@0: Region3.AddRect(TRect(0, 10, 100, 20)); sl@0: Region3.AddRect(TRect(0, 40, 100, 50)); sl@0: sl@0: Poly = (SPoly*) User::AllocL(sizeof(SPoly) + (3 - 1) * sizeof(TReal)); sl@0: Poly->num = 3; sl@0: Poly->c[0] = 3; sl@0: Poly->c[1] = 6; sl@0: Poly->c[2] = 9; sl@0: sl@0: Heap = (RHeap*)User::LeaveIfNull(UserHeap::ChunkHeap(NULL, HeapSize, HeapSize)); sl@0: TInt x; sl@0: TAny* cells[Allocs]; sl@0: for (x=0; xAlloc(4); sl@0: for (x=0; xFree(cells[x]); sl@0: } sl@0: sl@0: // Define benchmarks for assembler-coded euser functions. Note that these are sl@0: // named after the function we're trying to test, which is not necessarily the sl@0: // one we call. sl@0: sl@0: // RPointerArrayBase sl@0: DEFINE_USER_BENCHMARK(RPointerArrayBase_At, sl@0: , sl@0: ArrayTInt[4]); sl@0: sl@0: DEFINE_USER_BENCHMARK(RPointerArrayBase_Append, sl@0: RArray a, sl@0: a.Reset(); a.Append(1)); sl@0: sl@0: DEFINE_USER_BENCHMARK(RPointerArrayBase_Find1, sl@0: , sl@0: ArrayTInt.Find(5)); sl@0: sl@0: DEFINE_USER_BENCHMARK(RPointerArrayBase_Find2, sl@0: , sl@0: ArrayTPointPtr.Find(&Point, PointIdentity)); sl@0: sl@0: DEFINE_USER_BENCHMARK(RPointerArrayBase_BinarySearchSigned, sl@0: TInt i, sl@0: ArrayTInt.SpecificFindInOrder(13, i, EArrayFindMode_Any)); sl@0: sl@0: DEFINE_USER_BENCHMARK(RPointerArrayBase_BinarySearchUnsigned, sl@0: TInt i, sl@0: ArrayTUint.SpecificFindInOrder(13, i, EArrayFindMode_Any)); sl@0: sl@0: DEFINE_USER_BENCHMARK(RPointerArrayBase_BinarySearch, sl@0: , sl@0: ArrayTPointPtr.SpecificFindInOrder(&Point, PointOrder, EArrayFindMode_Any)); sl@0: sl@0: DEFINE_USER_BENCHMARK(RPointerArrayBase_FindIsqSigned, sl@0: , sl@0: ArrayTInt.SpecificFindInOrder(5, EArrayFindMode_Any)); sl@0: sl@0: DEFINE_USER_BENCHMARK(RPointerArrayBase_FindIsqUnsigned, sl@0: , sl@0: ArrayTUint.SpecificFindInOrder(5, EArrayFindMode_Any)); sl@0: sl@0: DEFINE_USER_BENCHMARK(RPointerArrayBase_FindIsq, sl@0: , sl@0: ArrayTPointPtr.SpecificFindInOrder(&Point, PointOrder, EArrayFindMode_Any)); sl@0: sl@0: DEFINE_USER_BENCHMARK(RPointerArrayBase_HeapSortSigned, sl@0: , sl@0: ArrayTInt.Sort()); sl@0: sl@0: DEFINE_USER_BENCHMARK(RPointerArrayBase_HeapSortUnsigned, sl@0: , sl@0: ArrayTUint.Sort()); sl@0: sl@0: DEFINE_USER_BENCHMARK(RPointerArrayBase_HeapSort, sl@0: , sl@0: ArrayTPointPtr.Sort(PointOrder)); sl@0: sl@0: // RArrayBase sl@0: DEFINE_USER_BENCHMARK(RArrayBase_At, sl@0: , sl@0: ArrayTPoint[4]); sl@0: sl@0: DEFINE_USER_BENCHMARK(RArrayBase_Append, sl@0: RArray a, sl@0: a.Reset(); a.Append(Point)); sl@0: sl@0: DEFINE_USER_BENCHMARK(RArrayBase_Find1, sl@0: , sl@0: ArrayTPoint.Find(Point)); sl@0: sl@0: DEFINE_USER_BENCHMARK(RArrayBase_Find2, sl@0: , sl@0: ArrayTPoint.Find(Point, PointIdentity)); sl@0: sl@0: DEFINE_USER_BENCHMARK(RArrayBase_BinarySearchSigned, sl@0: TInt i, sl@0: ArrayTPoint.SpecificFindInSignedKeyOrder(Point, i, EArrayFindMode_Any)); sl@0: sl@0: DEFINE_USER_BENCHMARK(RArrayBase_BinarySearchUnsigned, sl@0: TInt i, sl@0: ArrayTPoint.SpecificFindInUnsignedKeyOrder(Point, i, EArrayFindMode_Any)); sl@0: sl@0: DEFINE_USER_BENCHMARK(RArrayBase_BinarySearch, sl@0: TInt i, sl@0: ArrayTPoint.FindInOrder(Point, i, PointOrder)); sl@0: sl@0: DEFINE_USER_BENCHMARK(RArrayBase_FindIsqSigned, sl@0: , sl@0: ArrayTPoint.SpecificFindInSignedKeyOrder(Point, EArrayFindMode_Any)); sl@0: sl@0: DEFINE_USER_BENCHMARK(RArrayBase_FindIsqUnsigned, sl@0: , sl@0: ArrayTPoint.SpecificFindInUnsignedKeyOrder(Point, EArrayFindMode_Any)); sl@0: sl@0: DEFINE_USER_BENCHMARK(RArrayBase_HeapSortSigned, sl@0: , sl@0: ArrayTPoint.SortSigned()); sl@0: sl@0: DEFINE_USER_BENCHMARK(RArrayBase_HeapSortUnsigned, sl@0: , sl@0: ArrayTPoint.SortUnsigned()); sl@0: sl@0: DEFINE_USER_BENCHMARK(RArrayBase_HeapSort, sl@0: , sl@0: ArrayTPointPtr.Sort(PointOrder)); sl@0: sl@0: // CObject related sl@0: DEFINE_USER_BENCHMARK(CObjectIx_At1, sl@0: , sl@0: ObjectIx->At(ObjectHandle)); sl@0: sl@0: DEFINE_USER_BENCHMARK(CObjectIx_At2, sl@0: , sl@0: ObjectIx->At(ObjectHandle, 0)); sl@0: sl@0: DEFINE_USER_BENCHMARK(CObjectIx_ArrayOperator, sl@0: , sl@0: (*ObjectIx)[0]); sl@0: sl@0: DEFINE_USER_BENCHMARK(CObjectCon_ArrayOperator, sl@0: , sl@0: (*ObjectCon)[0]); sl@0: sl@0: DEFINE_USER_BENCHMARK(CObjectCon_At, sl@0: , sl@0: ObjectCon->At(ObjectHandle)); sl@0: sl@0: DEFINE_USER_BENCHMARK(CObjectCon_AtL, sl@0: , sl@0: ObjectCon->AtL(ObjectHandle)); sl@0: sl@0: // Huffman coding sl@0: DEFINE_USER_BENCHMARK(TBitInput_ReadL1, sl@0: , sl@0: BitInput.Set(BitData, 128); BitInput.ReadL()); sl@0: sl@0: DEFINE_USER_BENCHMARK(TBitInput_ReadL2, sl@0: , sl@0: BitInput.Set(BitData, 128); BitInput.ReadL(7)); sl@0: sl@0: DEFINE_USER_BENCHMARK(TBitInput_HuffmanL, sl@0: , sl@0: BitInput.Set(BitData, 128); BitInput.HuffmanL(HuffmanTable)); sl@0: sl@0: // Regions sl@0: DEFINE_USER_BENCHMARK(TRegion_BoundingRect, sl@0: , sl@0: Region.BoundingRect()); sl@0: sl@0: DEFINE_USER_BENCHMARK(TRegion_IsContainedBy, sl@0: TRect r(0,0,90,90), sl@0: Region.IsContainedBy(r)); sl@0: sl@0: DEFINE_USER_BENCHMARK(TRegion_Copy, sl@0: RRegion r, sl@0: r.Copy(Region)); sl@0: sl@0: DEFINE_USER_BENCHMARK(TRegion_Offset1, sl@0: , sl@0: Region.Offset(0, 0)); sl@0: sl@0: DEFINE_USER_BENCHMARK(TRegion_Contains, sl@0: TPoint p(0, 0), sl@0: Region.Contains(p)); sl@0: sl@0: DEFINE_USER_BENCHMARK(TRegion_Intersects, sl@0: TRect r(0, 0, 10, 10), sl@0: Region2.Intersects(r)); sl@0: sl@0: DEFINE_USER_BENCHMARK(TRegion_SubRect, sl@0: RRegion r, sl@0: r.Copy(Region); r.SubRect(Rect1)); sl@0: sl@0: DEFINE_USER_BENCHMARK(TRegion_Intersection, sl@0: RRegion r, sl@0: r.Intersection(Region, Region2)); sl@0: sl@0: DEFINE_USER_BENCHMARK(TRegion_ClipRect, sl@0: RRegion r, sl@0: r.Copy(Region); r.ClipRect(Rect1)); sl@0: sl@0: DEFINE_USER_BENCHMARK(TRegion_Tidy, sl@0: RRegion r, sl@0: r.Copy(Region3); r.Tidy()); sl@0: sl@0: // Maths sl@0: DEFINE_USER_BENCHMARK(Math_Frac, sl@0: TReal t, sl@0: Math::Frac(t, KPi)); sl@0: sl@0: DEFINE_USER_BENCHMARK(Math_Int1, sl@0: TReal t, sl@0: Math::Int(t, KPi)); sl@0: sl@0: DEFINE_USER_BENCHMARK(Math_Int2, sl@0: TInt16 t, sl@0: Math::Int(t, KPi)); sl@0: sl@0: DEFINE_USER_BENCHMARK(Math_Int3, sl@0: TInt32 t, sl@0: Math::Int(t, KPi)); sl@0: sl@0: DEFINE_USER_BENCHMARK(Math_IsZero, sl@0: , sl@0: Math::IsZero(KPi)); sl@0: sl@0: DEFINE_USER_BENCHMARK(Math_IsNaN, sl@0: , sl@0: Math::IsNaN(KPi)); sl@0: sl@0: DEFINE_USER_BENCHMARK(Math_IsInfinite, sl@0: , sl@0: Math::IsInfinite(KPi)); sl@0: sl@0: DEFINE_USER_BENCHMARK(Math_IsFinite, sl@0: , sl@0: Math::IsFinite(KPi)); sl@0: sl@0: DEFINE_USER_BENCHMARK(Math_Sqrt, sl@0: TReal t, sl@0: Math::Sqrt(t, KPi)); sl@0: sl@0: DEFINE_USER_BENCHMARK(Math_Poly, sl@0: TRealX t, sl@0: Math::PolyX(t, KPi, 3, PolyXCoeffs)); sl@0: sl@0: // Not tested due to not being exported: sl@0: // Math::SetZero sl@0: // Math::SetNan sl@0: // Math::SetInfinite sl@0: sl@0: // TRealX sl@0: DEFINE_USER_BENCHMARK(TRealX_Cons1, sl@0: TRealX t, sl@0: new (&t) TRealX); sl@0: sl@0: DEFINE_USER_BENCHMARK(TRealX_Cons2, sl@0: TRealX t, sl@0: new (&t) TRealX(0, 0, 0)); sl@0: sl@0: // covers TRealX::Set(TInt), TRealX::TRealX(TInt) and TRealX::operator=(TInt) sl@0: DEFINE_USER_BENCHMARK(TRealX_SetInt, sl@0: TRealX t, sl@0: t = (TInt) 23); sl@0: sl@0: // covers TRealX::Set(TUint), TRealX::TRealX(TUint) and TRealX::operator=(TUint) sl@0: DEFINE_USER_BENCHMARK(TRealX_SetUint, sl@0: TRealX t, sl@0: t = (TUint) 23); sl@0: sl@0: // covers TRealX::Set(TInt64), TRealX::TRealX(TInt64) and TRealX::operator=(TInt64) sl@0: DEFINE_USER_BENCHMARK(TRealX_SetInt64, sl@0: TRealX t, sl@0: t = (TInt64) 23); sl@0: sl@0: // covers TRealX::Set(TReal32), TRealX::TRealX(TReal32) and TRealX::operator=(TReal32) sl@0: DEFINE_USER_BENCHMARK(TRealX_SetReal32, sl@0: TRealX t; TReal32 v = 23, sl@0: t = v); sl@0: sl@0: // covers TRealX::Set(TReal64), TRealX::TRealX(TReal64) and TRealX::operator=(TReal64) sl@0: DEFINE_USER_BENCHMARK(TRealX_SetReal64, sl@0: TRealX t; TReal64 v = 23, sl@0: t = v); sl@0: sl@0: DEFINE_USER_BENCHMARK(TRealX_SetZero, sl@0: TRealX t, sl@0: t.SetZero(EFalse)); sl@0: sl@0: DEFINE_USER_BENCHMARK(TRealX_SetNaN, sl@0: TRealX t, sl@0: t.SetNaN()); sl@0: sl@0: DEFINE_USER_BENCHMARK(TRealX_SetInfinite, sl@0: TRealX t, sl@0: t.SetInfinite(EFalse)); sl@0: sl@0: DEFINE_USER_BENCHMARK(TRealX_IsZero, sl@0: TRealX t, sl@0: t.IsZero()); sl@0: sl@0: DEFINE_USER_BENCHMARK(TRealX_IsNaN, sl@0: TRealX t; t.SetNaN(), sl@0: t.IsNaN()); sl@0: sl@0: DEFINE_USER_BENCHMARK(TRealX_IsInfinite, sl@0: TRealX t; t.SetInfinite(EFalse), sl@0: t.IsInfinite()); sl@0: sl@0: DEFINE_USER_BENCHMARK(TRealX_IsFinite, sl@0: TRealX t, sl@0: t.IsFinite()); sl@0: sl@0: DEFINE_USER_BENCHMARK(TRealX_Int, sl@0: TRealX t = 2.3, sl@0: (TInt) t); sl@0: sl@0: DEFINE_USER_BENCHMARK(TRealX_Uint, sl@0: TRealX t = 2.3, sl@0: (TUint) t); sl@0: sl@0: DEFINE_USER_BENCHMARK(TRealX_Int64, sl@0: TRealX t = 2.3, sl@0: (TInt64) t); sl@0: sl@0: DEFINE_USER_BENCHMARK(TRealX_Real32, sl@0: TRealX t = 2.3, sl@0: (TReal32) t); sl@0: sl@0: DEFINE_USER_BENCHMARK(TRealX_Real64, sl@0: TRealX t = 2.3, sl@0: (TReal64) t); sl@0: sl@0: DEFINE_USER_BENCHMARK(TRealX_GetReal32, sl@0: TRealX t = 2.3; TReal32 out, sl@0: t.GetTReal(out)); sl@0: sl@0: DEFINE_USER_BENCHMARK(TRealX_GetReal64, sl@0: TRealX t = 2.3; TReal64 out, sl@0: t.GetTReal(out)); sl@0: sl@0: DEFINE_USER_BENCHMARK(TRealX_UnaryPlus, sl@0: TRealX t, sl@0: +t); sl@0: sl@0: DEFINE_USER_BENCHMARK(TRealX_UnaryMinus, sl@0: TRealX t, sl@0: -t); sl@0: sl@0: DEFINE_USER_BENCHMARK(TRealX_Compare, sl@0: TRealX a = 0.2; TRealX b = 0.21, sl@0: a.Compare(b)); sl@0: sl@0: DEFINE_USER_BENCHMARK(TRealX_Sub, sl@0: TRealX a = 1.0; TRealX b = 0.2, sl@0: a - b); sl@0: sl@0: DEFINE_USER_BENCHMARK(TRealX_Add, sl@0: TRealX a = 1.0; TRealX b = 0.2, sl@0: a + b); sl@0: sl@0: DEFINE_USER_BENCHMARK(TRealX_Mult, sl@0: TRealX a = 1.0; TRealX b = 0.2, sl@0: a * b); sl@0: sl@0: DEFINE_USER_BENCHMARK(TRealX_Div, sl@0: TRealX a = 1.0; TRealX b = 0.2, sl@0: a / b); sl@0: sl@0: DEFINE_USER_BENCHMARK(TRealX_Mod, sl@0: TRealX a = 1.1; TRealX b = 0.2, sl@0: a % b); sl@0: sl@0: DEFINE_USER_BENCHMARK(TRealX_PreInc, sl@0: TRealX t = 0.0, sl@0: ++t); sl@0: sl@0: DEFINE_USER_BENCHMARK(TRealX_PostInc, sl@0: TRealX t = 0.0, sl@0: t++); sl@0: sl@0: DEFINE_USER_BENCHMARK(TRealX_PreDec, sl@0: TRealX t = 0.0, sl@0: --t); sl@0: sl@0: DEFINE_USER_BENCHMARK(TRealX_PostDec, sl@0: TRealX t = 0.0, sl@0: t--); sl@0: sl@0: DEFINE_USER_BENCHMARK(RHeap_AllocFree, sl@0: TAny* mem, sl@0: mem = Heap->Alloc(8); sl@0: Heap->Free(mem)); sl@0: sl@0: // The following were added for timing functions affected by user-side thread data. sl@0: sl@0: DEFINE_USER_BENCHMARK(User_Heap, sl@0: , sl@0: User::Heap()); sl@0: sl@0: DEFINE_USER_BENCHMARK(CActiveScheduler_Current, sl@0: , sl@0: CActiveScheduler::Current()); sl@0: sl@0: DEFINE_USER_BENCHMARK(User_TrapHandler, sl@0: , sl@0: User::TrapHandler()); sl@0: sl@0: DEFINE_USER_BENCHMARK(UserSvr_DllSetTls, sl@0: , sl@0: UserSvr::DllSetTls(0, 0, 0)); sl@0: sl@0: DEFINE_USER_BENCHMARK(UserSvr_DllTls, sl@0: , sl@0: UserSvr::DllTls(0));