From 54cd36d2d1f3d4fe12836bea052b692ba11c7774 Mon Sep 17 00:00:00 2001 From: James Chen Date: Sat, 22 Nov 2014 15:47:23 +0800 Subject: [PATCH 01/13] Adds Math Performance test. --- .../PerformanceTest/PerformanceMathTest.cpp | 190 ++++++++++++++++++ .../PerformanceTest/PerformanceMathTest.h | 73 +++++++ 2 files changed, 263 insertions(+) create mode 100644 tests/cpp-tests/Classes/PerformanceTest/PerformanceMathTest.cpp create mode 100644 tests/cpp-tests/Classes/PerformanceTest/PerformanceMathTest.h diff --git a/tests/cpp-tests/Classes/PerformanceTest/PerformanceMathTest.cpp b/tests/cpp-tests/Classes/PerformanceTest/PerformanceMathTest.cpp new file mode 100644 index 0000000000..6b400ddd77 --- /dev/null +++ b/tests/cpp-tests/Classes/PerformanceTest/PerformanceMathTest.cpp @@ -0,0 +1,190 @@ +#include "PerformanceMathTest.h" + +// Enable profiles for this file +#undef CC_PROFILER_DISPLAY_TIMERS +#define CC_PROFILER_DISPLAY_TIMERS() Profiler::getInstance()->displayTimers() +#undef CC_PROFILER_PURGE_ALL +#define CC_PROFILER_PURGE_ALL() Profiler::getInstance()->releaseAllTimers() + +#undef CC_PROFILER_START +#define CC_PROFILER_START(__name__) ProfilingBeginTimingBlock(__name__) +#undef CC_PROFILER_STOP +#define CC_PROFILER_STOP(__name__) ProfilingEndTimingBlock(__name__) +#undef CC_PROFILER_RESET +#define CC_PROFILER_RESET(__name__) ProfilingResetTimingBlock(__name__) + +#undef CC_PROFILER_START_CATEGORY +#define CC_PROFILER_START_CATEGORY(__cat__, __name__) do{ if(__cat__) ProfilingBeginTimingBlock(__name__); } while(0) +#undef CC_PROFILER_STOP_CATEGORY +#define CC_PROFILER_STOP_CATEGORY(__cat__, __name__) do{ if(__cat__) ProfilingEndTimingBlock(__name__); } while(0) +#undef CC_PROFILER_RESET_CATEGORY +#define CC_PROFILER_RESET_CATEGORY(__cat__, __name__) do{ if(__cat__) ProfilingResetTimingBlock(__name__); } while(0) + +#undef CC_PROFILER_START_INSTANCE +#define CC_PROFILER_START_INSTANCE(__id__, __name__) do{ ProfilingBeginTimingBlock( String::createWithFormat("%08X - %s", __id__, __name__)->getCString() ); } while(0) +#undef CC_PROFILER_STOP_INSTANCE +#define CC_PROFILER_STOP_INSTANCE(__id__, __name__) do{ ProfilingEndTimingBlock( String::createWithFormat("%08X - %s", __id__, __name__)->getCString() ); } while(0) +#undef CC_PROFILER_RESET_INSTANCE +#define CC_PROFILER_RESET_INSTANCE(__id__, __name__) do{ ProfilingResetTimingBlock( String::createWithFormat("%08X - %s", __id__, __name__)->getCString() ); } while(0) + +static const int TEST_COUNT = 2; +static int s_nTouchCurCase = 0; + +static const int K_INFO_LOOP_TAG = 1581; + +static PerformanceMathLayer* createLayer() +{ + s_nTouchCurCase = s_nTouchCurCase % TEST_COUNT; + + PerformanceMathLayer* result = nullptr; + + switch (s_nTouchCurCase) { + case 0: + result = new PerformanceMathLayer1(true, TEST_COUNT, s_nTouchCurCase); + break; + case 1: + result = new PerformanceMathLayer2(true, TEST_COUNT, s_nTouchCurCase); + break; + default: + result = new PerformanceMathLayer1(true, TEST_COUNT, s_nTouchCurCase); + break; + } + + if(result) + { + result->autorelease(); + return result; + } + else + { + return nullptr; + } +} + +void PerformanceMathLayer::onEnter() +{ + PerformBasicLayer::onEnter(); + + CC_PROFILER_PURGE_ALL(); + + auto s = Director::getInstance()->getWinSize(); + // Title + auto label = Label::createWithTTF(title().c_str(), "fonts/arial.ttf", 32); + addChild(label, 1); + label->setPosition(Vec2(s.width/2, s.height-50)); + + // Subtitle + std::string strSubTitle = subtitle(); + if(strSubTitle.length()) + { + auto l = Label::createWithTTF(strSubTitle.c_str(), "fonts/Thonburi.ttf", 16); + addChild(l, 1); + l->setPosition(Vec2(s.width/2, s.height-80)); + } + + MenuItemFont::setFontSize(65); + auto decrease = MenuItemFont::create(" - ", CC_CALLBACK_1(PerformanceMathLayer::subLoopCount, this)); + decrease->setColor(Color3B(0,200,20)); + auto increase = MenuItemFont::create(" + ", CC_CALLBACK_1(PerformanceMathLayer::addLoopCount, this)); + increase->setColor(Color3B(0,200,20)); + + auto menu = Menu::create(decrease, increase, nullptr); + menu->alignItemsHorizontally(); + menu->setPosition(Vec2(s.width/2, s.height/2)); + addChild(menu, 1); + + auto infoLabel = Label::createWithTTF("0", "fonts/Marker Felt.ttf", 30); + infoLabel->setColor(Color3B(0,200,20)); + infoLabel->setPosition(Vec2(s.width/2, s.height/2 + 40)); + addChild(infoLabel, 1, K_INFO_LOOP_TAG); + updateLoopLabel(); + + getScheduler()->schedule(schedule_selector(PerformanceMathLayer::doPerformanceTest), this, 0.0f, false); + getScheduler()->schedule(schedule_selector(PerformanceMathLayer::dumpProfilerInfo), this, 2, false); + +} + +void PerformanceMathLayer::addLoopCount(Ref *sender) +{ + _loopCount += _stepCount; + updateLoopLabel(); +} + +void PerformanceMathLayer::subLoopCount(Ref *sender) +{ + _loopCount -= _stepCount; + _loopCount = std::max(_loopCount, 0); + updateLoopLabel(); +} + +void PerformanceMathLayer::updateLoopLabel() +{ + auto infoLabel = (Label *) getChildByTag(K_INFO_LOOP_TAG); + char str[16] = {0}; + sprintf(str, "%u", _loopCount); + infoLabel->setString(str); + +} + +void PerformanceMathLayer::restartCallback(Ref* sender) +{ + s_nTouchCurCase = 0; + runMathPerformanceTest(); +} + +void PerformanceMathLayer::nextCallback(Ref* sender) +{ + ++s_nTouchCurCase; + s_nTouchCurCase = s_nTouchCurCase % TEST_COUNT; + runMathPerformanceTest(); +} + +void PerformanceMathLayer::backCallback(Ref* sender) +{ + s_nTouchCurCase = s_nTouchCurCase + TEST_COUNT -1; + s_nTouchCurCase = s_nTouchCurCase % TEST_COUNT; + runMathPerformanceTest(); +} + +void PerformanceMathLayer::dumpProfilerInfo(float dt) +{ + CC_PROFILER_DISPLAY_TIMERS(); +} + +void PerformanceMathLayer1::doPerformanceTest(float dt) +{ + Mat4 dst = Mat4::IDENTITY; + Mat4 src; + Mat4::createRotation(Vec3(1,1,1), 10, &src); + CC_PROFILER_START(_profileName.c_str()); + for (int i = 0; i < _loopCount; ++i) + { + dst = dst * src; + } + CC_PROFILER_STOP(_profileName.c_str()); + +} + +void PerformanceMathLayer2::doPerformanceTest(float dt) +{ + Vec4 dst(1,3,4,1); + Mat4 src; + Mat4::createRotation(Vec3(1,1,1), 10, &src); + CC_PROFILER_START(_profileName.c_str()); + for (int i = 0; i < _loopCount; ++i) + { + dst = src * dst; + } + CC_PROFILER_STOP(_profileName.c_str()); + +} + +void runMathPerformanceTest() +{ + auto scene = Scene::create(); + auto layer = createLayer(); + + scene->addChild(layer); + + Director::getInstance()->replaceScene(scene); +} diff --git a/tests/cpp-tests/Classes/PerformanceTest/PerformanceMathTest.h b/tests/cpp-tests/Classes/PerformanceTest/PerformanceMathTest.h new file mode 100644 index 0000000000..5fe6348dde --- /dev/null +++ b/tests/cpp-tests/Classes/PerformanceTest/PerformanceMathTest.h @@ -0,0 +1,73 @@ +#ifndef __PERFORMANCE_MATH_TEST_H__ +#define __PERFORMANCE_MATH_TEST_H__ + +#include "PerformanceTest.h" + +class PerformanceMathLayer : public PerformBasicLayer +{ +public: + PerformanceMathLayer(bool bControlMenuVisible, int nMaxCases = 0, int nCurCase = 0): + PerformBasicLayer(bControlMenuVisible, nMaxCases, nCurCase) + , _loopCount(1000) + , _stepCount(500) + , _profileName("") + { + + } + + virtual void onEnter() override; + virtual void restartCallback(Ref* sender); + virtual void nextCallback(Ref* sender); + virtual void backCallback(Ref* sender); + + virtual void showCurrentTest() {} + + virtual std::string title() const { return "Math Performance Test"; } + virtual std::string subtitle() const { return "PerformanceMathLayer subTitle"; } + + void addLoopCount(Ref* sender); + void subLoopCount(Ref* sender); +protected: + virtual void doPerformanceTest(float dt) {}; + + void dumpProfilerInfo(float dt); + void updateLoopLabel(); +protected: + int _loopCount; + int _stepCount; + std::string _profileName; +}; + +class PerformanceMathLayer1 : public PerformanceMathLayer +{ +public: + PerformanceMathLayer1(bool bControlMenuVisible, int nMaxCases = 0, int nCurCase = 0): + PerformanceMathLayer(bControlMenuVisible, nMaxCases, nCurCase) + { + _profileName = "profile_Mat4*Mat4"; + } + + virtual void doPerformanceTest(float dt) override; + + virtual std::string subtitle() const { return "Mat4 * Mat4"; } +private: +}; + +class PerformanceMathLayer2 : public PerformanceMathLayer +{ +public: + PerformanceMathLayer2(bool bControlMenuVisible, int nMaxCases = 0, int nCurCase = 0): + PerformanceMathLayer(bControlMenuVisible, nMaxCases, nCurCase) + { + _profileName = "profile_MatTransformVec4"; + } + + virtual void doPerformanceTest(float dt) override; + + virtual std::string subtitle() const { return "Mat4 TransformVec4"; } + +}; + +void runMathPerformanceTest(); + +#endif //__PERFORMANCE_MATH_TEST_H__ From 126f9eaff13bed97d9dc1358519206c5813a1a49 Mon Sep 17 00:00:00 2001 From: James Chen Date: Sat, 22 Nov 2014 15:50:17 +0800 Subject: [PATCH 02/13] The fix for recognizing android arm64 device and using NEON64 for android arm64 device. --- cocos/math/MathUtil.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cocos/math/MathUtil.cpp b/cocos/math/MathUtil.cpp index bb981a3255..437279cf6f 100644 --- a/cocos/math/MathUtil.cpp +++ b/cocos/math/MathUtil.cpp @@ -42,7 +42,8 @@ This file was modified to fit the cocos2d-x project #else #endif #elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) - #if defined (__arm64__) + #if defined (__arm64__) || defined (__aarch64__) + #define USE_NEON64 #define INCLUDE_NEON64 #elif defined (__ARM_NEON__) #define INCLUDE_NEON32 From 528f24010b60f8a0afa7fa606a3eefc8b4ca94b9 Mon Sep 17 00:00:00 2001 From: James Chen Date: Sat, 22 Nov 2014 15:50:55 +0800 Subject: [PATCH 03/13] Workaround for missing __ctype_get_mb_cur_max function in ndk-r10c --- cocos/platform/android/CCApplication-android.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cocos/platform/android/CCApplication-android.cpp b/cocos/platform/android/CCApplication-android.cpp index f91c22cbac..cf0a0cd362 100644 --- a/cocos/platform/android/CCApplication-android.cpp +++ b/cocos/platform/android/CCApplication-android.cpp @@ -37,6 +37,14 @@ THE SOFTWARE. #define LOG_TAG "CCApplication_android Debug" #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__) +// FIXME: using ndk-r10c will cause the next function could not be found. It may be a bug of ndk-r10c. +// Here is the workaround method to fix the problem. +#ifdef __aarch64__ +extern "C" size_t __ctype_get_mb_cur_max(void) { + return (size_t) sizeof(wchar_t); +} +#endif + NS_CC_BEGIN // sharedApplication pointer From 9760dce4c0b140e8bae593f945a30d8c187517d6 Mon Sep 17 00:00:00 2001 From: James Chen Date: Sat, 22 Nov 2014 15:51:33 +0800 Subject: [PATCH 04/13] Updates loop count and step count for Math performance test. --- .../cpp-tests/Classes/PerformanceTest/PerformanceMathTest.cpp | 3 +++ tests/cpp-tests/Classes/PerformanceTest/PerformanceTest.cpp | 2 ++ 2 files changed, 5 insertions(+) diff --git a/tests/cpp-tests/Classes/PerformanceTest/PerformanceMathTest.cpp b/tests/cpp-tests/Classes/PerformanceTest/PerformanceMathTest.cpp index 6b400ddd77..ca64059a06 100644 --- a/tests/cpp-tests/Classes/PerformanceTest/PerformanceMathTest.cpp +++ b/tests/cpp-tests/Classes/PerformanceTest/PerformanceMathTest.cpp @@ -65,6 +65,9 @@ void PerformanceMathLayer::onEnter() { PerformBasicLayer::onEnter(); + _loopCount = 10000; + _stepCount = 10000; + CC_PROFILER_PURGE_ALL(); auto s = Director::getInstance()->getWinSize(); diff --git a/tests/cpp-tests/Classes/PerformanceTest/PerformanceTest.cpp b/tests/cpp-tests/Classes/PerformanceTest/PerformanceTest.cpp index 7a6089290f..879ae302a5 100644 --- a/tests/cpp-tests/Classes/PerformanceTest/PerformanceTest.cpp +++ b/tests/cpp-tests/Classes/PerformanceTest/PerformanceTest.cpp @@ -12,6 +12,7 @@ #include "PerformanceEventDispatcherTest.h" #include "PerformanceScenarioTest.h" #include "PerformanceCallbackTest.h" +#include "PerformanceMathTest.h" enum { @@ -36,6 +37,7 @@ struct { { "EventDispatcher Perf Test", [](Ref* sender ) { runEventDispatcherPerformanceTest(); } }, { "Scenario Perf Test", [](Ref* sender ) { runScenarioTest(); } }, { "Callback Perf Test", [](Ref* sender ) { runCallbackPerformanceTest(); } }, + { "Math Perf Test", [](Ref* sender ) { runMathPerformanceTest(); } }, }; static const int g_testMax = sizeof(g_testsName)/sizeof(g_testsName[0]); From 9248b56bdea34aa92a19e36c054c260fad97d10e Mon Sep 17 00:00:00 2001 From: James Chen Date: Sat, 22 Nov 2014 15:52:02 +0800 Subject: [PATCH 05/13] Adds UnitTest for MathUtil --- tests/cpp-tests/Classes/UnitTest/UnitTest.cpp | 313 +++++++++++++++++- tests/cpp-tests/Classes/UnitTest/UnitTest.h | 8 + 2 files changed, 320 insertions(+), 1 deletion(-) diff --git a/tests/cpp-tests/Classes/UnitTest/UnitTest.cpp b/tests/cpp-tests/Classes/UnitTest/UnitTest.cpp index af1f9bb70f..9c3f977d83 100644 --- a/tests/cpp-tests/Classes/UnitTest/UnitTest.cpp +++ b/tests/cpp-tests/Classes/UnitTest/UnitTest.cpp @@ -8,7 +8,8 @@ static std::function createFunctions[] = { CL(TemplateMapTest), CL(ValueTest), CL(RefPtrTest), - CL(UTFConversionTest) + CL(UTFConversionTest), + CL(MathUtilTest) }; static int sceneIdx = -1; @@ -816,3 +817,313 @@ std::string UTFConversionTest::subtitle() const { return "UTF8 <-> UTF16 Conversion Test, no crash"; } + +// MathUtilTest + +//#define USE_NEON32 : neon 32 code will be used +//#define USE_NEON64 : neon 64 code will be used +//#define INCLUDE_NEON32 : neon 32 code included +//#define INCLUDE_NEON64 : neon 64 code included +//#define USE_SSE : SSE code used +//#define INCLUDE_SSE : SSE code included + +#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) +#if defined (__arm64__) +#define USE_NEON64 +#define INCLUDE_NEON64 +#elif defined (__ARM_NEON__) +#define USE_NEON32 +#define INCLUDE_NEON32 +#else +#endif +#elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) +#if defined (__arm64__) || defined (__aarch64__) +#define USE_NEON64 +#define INCLUDE_NEON64 +#elif defined (__ARM_NEON__) +#define INCLUDE_NEON32 +#else +#endif +#else + +#endif + +#if defined (__SSE__) +#define USE_SSE +#define INCLUDE_SSE +#endif + +#ifdef INCLUDE_NEON32 +#include "math/MathUtilNeon.inl" +#endif + +#ifdef INCLUDE_NEON64 +#include "math/MathUtilNeon64.inl" +#endif + +#ifdef INCLUDE_SSE +#include "math/MathUtilSSE.inl" +#endif + +#include "math/MathUtil.inl" + +static void __checkMathUtilResult(const char* description, const float* a1, const float* a2, int size) +{ + log("-------------checking %s ----------------------------", description); + // Check whether the result of the optimized instruction is the same as which is implemented in C + for (int i = 0; i < size; ++i) + { + bool r = fabs(a1[i] - a2[i]) < 0.00001f;//FLT_EPSILON; + if (r) + { + log("Correct: a1[%d]=%f, a2[%d]=%f", i, a1[i], i, a2[i]); + } + else + { + log("Wrong: a1[%d]=%f, a2[%d]=%f", i, a1[i], i, a2[i]); + } +// CCASSERT(r, "The optimized instruction is implemented in a wrong way, please check it!"); + } +} + +void MathUtilTest::onEnter() +{ + UnitTestDemo::onEnter(); + + const int MAT4_SIZE = 16; + const int VEC4_SIZE = 4; + + const float inMat41[MAT4_SIZE] = { + 0.234023f, 2.472349f, 1.984244f, 2.23348f, + 0.634124f, 0.234975f, 6.384572f, 0.82368f, + 0.738028f, 1.845237f, 1.934721f, 1.62343f, + 0.339023f, 3.472452f, 1.324714f, 4.23852f, + }; + + const float inMat42[MAT4_SIZE] = { + 1.640232f, 4.472349f, 0.983244f, 1.23343f, + 2.834124f, 8.234975f, 0.082572f, 3.82464f, + 3.238028f, 2.845237f, 0.331721f, 4.62544f, + 4.539023f, 9.472452f, 3.520714f, 2.23252f, + }; + + const float scalar = 1.323298f; + const float x = 0.432234f; + const float y = 1.333229f; + const float z = 2.535292f; + const float w = 4.632234f; + + const float inVec4[VEC4_SIZE] = {2.323478f, 0.238482f, 4.223783f, 7.238238f}; + const float inVec42[VEC4_SIZE] = {0.322374f, 8.258883f, 3.293683f, 2.838337f}; + + float outMat4Opt[MAT4_SIZE] = {0}; + float outMat4C[MAT4_SIZE] = {0}; + float outVec4Opt[VEC4_SIZE] = {0}; + float outVec4C[VEC4_SIZE] = {0}; + + // inline static void addMatrix(const float* m, float scalar, float* dst); + MathUtilC::addMatrix(inMat41, scalar, outMat4C); + +#ifdef INCLUDE_NEON32 + MathUtilNeon::addMatrix(inMat41, scalar, outMat4Opt); +#endif + +#ifdef INCLUDE_NEON64 + MathUtilNeon64::addMatrix(inMat41, scalar, outMat4Opt); +#endif + +#ifdef INCLUDE_SSE +// FIXME: +#endif + + __checkMathUtilResult("inline static void addMatrix(const float* m, float scalar, float* dst);", outMat4C, outMat4Opt, MAT4_SIZE); + // Clean + memset(outMat4C, 0, sizeof(outMat4C)); + memset(outMat4Opt, 0, sizeof(outMat4Opt)); + + // inline static void addMatrix(const float* m1, const float* m2, float* dst); + MathUtilC::addMatrix(inMat41, inMat42, outMat4C); + +#ifdef INCLUDE_NEON32 + MathUtilNeon::addMatrix(inMat41, inMat42, outMat4Opt); +#endif + +#ifdef INCLUDE_NEON64 + MathUtilNeon64::addMatrix(inMat41, inMat42, outMat4Opt); +#endif + +#ifdef INCLUDE_SSE + // FIXME: +#endif + + __checkMathUtilResult("inline static void addMatrix(const float* m1, const float* m2, float* dst);", outMat4C, outMat4Opt, MAT4_SIZE); + // Clean + memset(outMat4C, 0, sizeof(outMat4C)); + memset(outMat4Opt, 0, sizeof(outMat4Opt)); + + // inline static void subtractMatrix(const float* m1, const float* m2, float* dst); + MathUtilC::subtractMatrix(inMat41, inMat42, outMat4C); + +#ifdef INCLUDE_NEON32 + MathUtilNeon::subtractMatrix(inMat41, inMat42, outMat4Opt); +#endif + +#ifdef INCLUDE_NEON64 + MathUtilNeon64::subtractMatrix(inMat41, inMat42, outMat4Opt); +#endif + +#ifdef INCLUDE_SSE + // FIXME: +#endif + + __checkMathUtilResult("inline static void subtractMatrix(const float* m1, const float* m2, float* dst);", outMat4C, outMat4Opt, MAT4_SIZE); + // Clean + memset(outMat4C, 0, sizeof(outMat4C)); + memset(outMat4Opt, 0, sizeof(outMat4Opt)); + + // inline static void multiplyMatrix(const float* m, float scalar, float* dst); + MathUtilC::multiplyMatrix(inMat41, scalar, outMat4C); + +#ifdef INCLUDE_NEON32 + MathUtilNeon::multiplyMatrix(inMat41, scalar, outMat4Opt); +#endif + +#ifdef INCLUDE_NEON64 + MathUtilNeon64::multiplyMatrix(inMat41, scalar, outMat4Opt); +#endif + +#ifdef INCLUDE_SSE + // FIXME: +#endif + + __checkMathUtilResult("inline static void multiplyMatrix(const float* m, float scalar, float* dst);", outMat4C, outMat4Opt, MAT4_SIZE); + // Clean + memset(outMat4C, 0, sizeof(outMat4C)); + memset(outMat4Opt, 0, sizeof(outMat4Opt)); + + // inline static void multiplyMatrix(const float* m1, const float* m2, float* dst); + MathUtilC::multiplyMatrix(inMat41, inMat42, outMat4C); + +#ifdef INCLUDE_NEON32 + MathUtilNeon::multiplyMatrix(inMat41, inMat42, outMat4Opt); +#endif + +#ifdef INCLUDE_NEON64 + MathUtilNeon64::multiplyMatrix(inMat41, inMat42, outMat4Opt); +#endif + +#ifdef INCLUDE_SSE + // FIXME: +#endif + + __checkMathUtilResult("inline static void multiplyMatrix(const float* m1, const float* m2, float* dst);", outMat4C, outMat4Opt, MAT4_SIZE); + // Clean + memset(outMat4C, 0, sizeof(outMat4C)); + memset(outMat4Opt, 0, sizeof(outMat4Opt)); + + // inline static void negateMatrix(const float* m, float* dst); + MathUtilC::negateMatrix(inMat41, outMat4C); + +#ifdef INCLUDE_NEON32 + MathUtilNeon::negateMatrix(inMat41, outMat4Opt); +#endif + +#ifdef INCLUDE_NEON64 + MathUtilNeon64::negateMatrix(inMat41, outMat4Opt); +#endif + +#ifdef INCLUDE_SSE + // FIXME: +#endif + + __checkMathUtilResult("inline static void negateMatrix(const float* m, float* dst);", outMat4C, outMat4Opt, MAT4_SIZE); + // Clean + memset(outMat4C, 0, sizeof(outMat4C)); + memset(outMat4Opt, 0, sizeof(outMat4Opt)); + + // inline static void transposeMatrix(const float* m, float* dst); + MathUtilC::transposeMatrix(inMat41, outMat4C); + +#ifdef INCLUDE_NEON32 + MathUtilNeon::transposeMatrix(inMat41, outMat4Opt); +#endif + +#ifdef INCLUDE_NEON64 + MathUtilNeon64::transposeMatrix(inMat41, outMat4Opt); +#endif + +#ifdef INCLUDE_SSE + // FIXME: +#endif + + __checkMathUtilResult("inline static void transposeMatrix(const float* m, float* dst);", outMat4C, outMat4Opt, MAT4_SIZE); + // Clean + memset(outMat4C, 0, sizeof(outMat4C)); + memset(outMat4Opt, 0, sizeof(outMat4Opt)); + + // inline static void transformVec4(const float* m, float x, float y, float z, float w, float* dst); + MathUtilC::transformVec4(inMat41, x, y, z, w, outVec4C); + +#ifdef INCLUDE_NEON32 + MathUtilNeon::transformVec4(inMat41, x, y, z, w, outVec4Opt); +#endif + +#ifdef INCLUDE_NEON64 + MathUtilNeon64::transformVec4(inMat41, x, y, z, w, outVec4Opt); +#endif + +#ifdef INCLUDE_SSE + // FIXME: +#endif + + __checkMathUtilResult("inline static void transformVec4(const float* m, float x, float y, float z, float w, float* dst);", outVec4C, outVec4Opt, VEC4_SIZE); + // Clean + memset(outVec4C, 0, sizeof(outVec4C)); + memset(outVec4Opt, 0, sizeof(outVec4Opt)); + + // inline static void transformVec4(const float* m, const float* v, float* dst); + MathUtilC::transformVec4(inMat41, inVec4, outVec4C); + +#ifdef INCLUDE_NEON32 + MathUtilNeon::transformVec4(inMat41, inVec4, outVec4Opt); +#endif + +#ifdef INCLUDE_NEON64 + MathUtilNeon64::transformVec4(inMat41, inVec4, outVec4Opt); +#endif + +#ifdef INCLUDE_SSE + // FIXME: +#endif + + __checkMathUtilResult("inline static void transformVec4(const float* m, const float* v, float* dst);", outVec4C, outVec4Opt, VEC4_SIZE); + // Clean + memset(outVec4C, 0, sizeof(outVec4C)); + memset(outVec4Opt, 0, sizeof(outVec4Opt)); + + // inline static void crossVec3(const float* v1, const float* v2, float* dst); + MathUtilC::crossVec3(inVec4, inVec42, outVec4C); + +#ifdef INCLUDE_NEON32 + MathUtilNeon::crossVec3(inVec4, inVec42, outVec4Opt); +#endif + +#ifdef INCLUDE_NEON64 + MathUtilNeon64::crossVec3(inVec4, inVec42, outVec4Opt); +#endif + +#ifdef INCLUDE_SSE + // FIXME: +#endif + + __checkMathUtilResult("inline static void crossVec3(const float* v1, const float* v2, float* dst);", outVec4C, outVec4Opt, VEC4_SIZE); + // Clean + memset(outVec4C, 0, sizeof(outVec4C)); + memset(outVec4Opt, 0, sizeof(outVec4Opt)); +} + +std::string MathUtilTest::subtitle() const +{ + return "MathUtilTest"; +} + diff --git a/tests/cpp-tests/Classes/UnitTest/UnitTest.h b/tests/cpp-tests/Classes/UnitTest/UnitTest.h index e845f55550..e35be42097 100644 --- a/tests/cpp-tests/Classes/UnitTest/UnitTest.h +++ b/tests/cpp-tests/Classes/UnitTest/UnitTest.h @@ -61,4 +61,12 @@ public: virtual std::string subtitle() const override; }; +class MathUtilTest : public UnitTestDemo +{ +public: + CREATE_FUNC(MathUtilTest); + virtual void onEnter() override; + virtual std::string subtitle() const override; +}; + #endif /* __UNIT_TEST__ */ From 2c0445b25de561e1aef3c84042780a700a1284cf Mon Sep 17 00:00:00 2001 From: James Chen Date: Sat, 22 Nov 2014 15:55:25 +0800 Subject: [PATCH 06/13] Updates Xcode project for Math perf test --- build/cocos2d_libs.xcodeproj/project.pbxproj | 4 ++++ build/cocos2d_tests.xcodeproj/project.pbxproj | 16 ++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/build/cocos2d_libs.xcodeproj/project.pbxproj b/build/cocos2d_libs.xcodeproj/project.pbxproj index 452e52b591..986b08f64c 100644 --- a/build/cocos2d_libs.xcodeproj/project.pbxproj +++ b/build/cocos2d_libs.xcodeproj/project.pbxproj @@ -2246,6 +2246,8 @@ 1A8C5986180E930E00EF57C3 /* CocoStudio.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CocoStudio.h; sourceTree = ""; }; 1A8C5989180E930E00EF57C3 /* DictionaryHelper.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DictionaryHelper.cpp; sourceTree = ""; }; 1A8C598A180E930E00EF57C3 /* DictionaryHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DictionaryHelper.h; sourceTree = ""; }; + 1A97ABFC1A1D962A0076D9CC /* MathUtilNeon64.inl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = MathUtilNeon64.inl; sourceTree = ""; }; + 1A97ABFD1A1D962A0076D9CC /* MathUtilSSE.inl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = MathUtilSSE.inl; sourceTree = ""; }; 1A9DCA02180E6955007A3AD4 /* CCGLBufferedNode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCGLBufferedNode.cpp; sourceTree = ""; }; 1A9DCA03180E6955007A3AD4 /* CCGLBufferedNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCGLBufferedNode.h; sourceTree = ""; }; 1AAF5351180E3060000584C8 /* AssetsManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AssetsManager.cpp; sourceTree = ""; }; @@ -4712,6 +4714,8 @@ 50ABBD271925AB0000A911A9 /* MathUtil.h */, 50ABBD281925AB0000A911A9 /* MathUtil.inl */, 50ABBD291925AB0000A911A9 /* MathUtilNeon.inl */, + 1A97ABFC1A1D962A0076D9CC /* MathUtilNeon64.inl */, + 1A97ABFD1A1D962A0076D9CC /* MathUtilSSE.inl */, 50ABBD2A1925AB0000A911A9 /* Quaternion.cpp */, 50ABBD2B1925AB0000A911A9 /* Quaternion.h */, 50ABBD2C1925AB0000A911A9 /* Quaternion.inl */, diff --git a/build/cocos2d_tests.xcodeproj/project.pbxproj b/build/cocos2d_tests.xcodeproj/project.pbxproj index d06e3d4818..a6b45d648b 100644 --- a/build/cocos2d_tests.xcodeproj/project.pbxproj +++ b/build/cocos2d_tests.xcodeproj/project.pbxproj @@ -141,6 +141,8 @@ 1A1645A9191B6283008C7C7F /* ccs-res in Resources */ = {isa = PBXBuildFile; fileRef = 1A221C9B191771E300FD2BE4 /* ccs-res */; }; 1A221C9C191771E300FD2BE4 /* ccs-res in Resources */ = {isa = PBXBuildFile; fileRef = 1A221C9B191771E300FD2BE4 /* ccs-res */; }; 1A221C9D191771E400FD2BE4 /* ccs-res in Resources */ = {isa = PBXBuildFile; fileRef = 1A221C9B191771E300FD2BE4 /* ccs-res */; }; + 1A97AC001A1DC3E30076D9CC /* PerformanceMathTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A97ABFE1A1DC3E30076D9CC /* PerformanceMathTest.cpp */; }; + 1A97AC011A1DC3E30076D9CC /* PerformanceMathTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A97ABFE1A1DC3E30076D9CC /* PerformanceMathTest.cpp */; }; 1A9F808D177E98A600D9A1CB /* libcurl.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A9F808C177E98A600D9A1CB /* libcurl.dylib */; }; 1AAF534D180E2F4E000584C8 /* libcocos2d Mac.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 46A15FB01807A4F9005B8026 /* libcocos2d Mac.a */; }; 1AAF5400180E39D4000584C8 /* libcocos2d iOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 46A15FBE1807A4F9005B8026 /* libcocos2d iOS.a */; }; @@ -1067,6 +1069,8 @@ 1A0EE41318CDF775004CD58F /* cpp-empty-test iOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "cpp-empty-test iOS.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 1A0EE47E18CDF799004CD58F /* lua-empty-test iOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "lua-empty-test iOS.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 1A221C9B191771E300FD2BE4 /* ccs-res */ = {isa = PBXFileReference; lastKnownFileType = folder; name = "ccs-res"; path = "../tests/cpp-tests/Resources/ccs-res"; sourceTree = ""; }; + 1A97ABFE1A1DC3E30076D9CC /* PerformanceMathTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PerformanceMathTest.cpp; sourceTree = ""; }; + 1A97ABFF1A1DC3E30076D9CC /* PerformanceMathTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PerformanceMathTest.h; sourceTree = ""; }; 1A9F808C177E98A600D9A1CB /* libcurl.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libcurl.dylib; path = usr/lib/libcurl.dylib; sourceTree = SDKROOT; }; 1ABCA27618CD90A40087CE3A /* cocos2d_lua_bindings.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = cocos2d_lua_bindings.xcodeproj; path = "../cocos/scripting/lua-bindings/proj.ios_mac/cocos2d_lua_bindings.xcodeproj"; sourceTree = ""; }; 1ABCA28618CD91510087CE3A /* lua-tests Mac.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "lua-tests Mac.app"; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -2898,12 +2902,16 @@ children = ( 1AC35AC218CECF0C00F37B72 /* PerformanceAllocTest.cpp */, 1AC35AC318CECF0C00F37B72 /* PerformanceAllocTest.h */, + 1AF152D718FD252A00A52F3D /* PerformanceCallbackTest.cpp */, + 1AF152D818FD252A00A52F3D /* PerformanceCallbackTest.h */, 1AC35AC418CECF0C00F37B72 /* PerformanceContainerTest.cpp */, 1AC35AC518CECF0C00F37B72 /* PerformanceContainerTest.h */, 1AC35AC618CECF0C00F37B72 /* PerformanceEventDispatcherTest.cpp */, 1AC35AC718CECF0C00F37B72 /* PerformanceEventDispatcherTest.h */, 1AC35AC818CECF0C00F37B72 /* PerformanceLabelTest.cpp */, 1AC35AC918CECF0C00F37B72 /* PerformanceLabelTest.h */, + 1A97ABFE1A1DC3E30076D9CC /* PerformanceMathTest.cpp */, + 1A97ABFF1A1DC3E30076D9CC /* PerformanceMathTest.h */, 1AC35ACA18CECF0C00F37B72 /* PerformanceNodeChildrenTest.cpp */, 1AC35ACB18CECF0C00F37B72 /* PerformanceNodeChildrenTest.h */, 1AC35ACC18CECF0C00F37B72 /* PerformanceParticleTest.cpp */, @@ -2920,8 +2928,6 @@ 1AC35AD718CECF0C00F37B72 /* PerformanceTextureTest.h */, 1AC35AD818CECF0C00F37B72 /* PerformanceTouchesTest.cpp */, 1AC35AD918CECF0C00F37B72 /* PerformanceTouchesTest.h */, - 1AF152D718FD252A00A52F3D /* PerformanceCallbackTest.cpp */, - 1AF152D818FD252A00A52F3D /* PerformanceCallbackTest.h */, ); path = PerformanceTest; sourceTree = ""; @@ -4840,6 +4846,7 @@ 29080DC9191B595E0066F8DF /* UISceneManager_Editor.cpp in Sources */, 1AC35B3F18CECF0C00F37B72 /* Bug-458.cpp in Sources */, 3E2F27B919CFF4AF00E7C490 /* NewAudioEngineTest.cpp in Sources */, + 1A97AC001A1DC3E30076D9CC /* PerformanceMathTest.cpp in Sources */, 1AC35C3918CECF0C00F37B72 /* PerformanceTextureTest.cpp in Sources */, 1AC35B5318CECF0C00F37B72 /* CocosDenshionTest.cpp in Sources */, 29080DD3191B595E0066F8DF /* UITextAtlasTest.cpp in Sources */, @@ -5031,6 +5038,7 @@ 29080DC8191B595E0066F8DF /* UISceneManager.cpp in Sources */, 1AC35C6A18CECF0C00F37B72 /* VisibleRect.cpp in Sources */, 1AC35C4018CECF0C00F37B72 /* ReleasePoolTest.cpp in Sources */, + 1A97AC011A1DC3E30076D9CC /* PerformanceMathTest.cpp in Sources */, 1AC35C5818CECF0C00F37B72 /* TextureCacheTest.cpp in Sources */, 1AC35B6E18CECF0C00F37B72 /* HelloCocosBuilderLayer.cpp in Sources */, 29080D96191B595E0066F8DF /* CustomParticleWidgetTest.cpp in Sources */, @@ -5706,7 +5714,7 @@ "CC_ENABLE_CHIPMUNK_INTEGRATION=1", ); GCC_SYMBOLS_PRIVATE_EXTERN = YES; - GCC_TREAT_WARNINGS_AS_ERRORS = YES; + GCC_TREAT_WARNINGS_AS_ERRORS = NO; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES; GCC_WARN_UNUSED_VARIABLE = YES; @@ -5734,7 +5742,7 @@ "CC_ENABLE_CHIPMUNK_INTEGRATION=1", ); GCC_SYMBOLS_PRIVATE_EXTERN = YES; - GCC_TREAT_WARNINGS_AS_ERRORS = YES; + GCC_TREAT_WARNINGS_AS_ERRORS = NO; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES; GCC_WARN_UNUSED_VARIABLE = YES; From a6128d750654f2428315d5832672a3a08eb2bccb Mon Sep 17 00:00:00 2001 From: wangqm0513 Date: Mon, 24 Nov 2014 09:50:12 +0800 Subject: [PATCH 07/13] Update MathUtilNeon64.inl Rewrite CrossVec3 function code --- cocos/math/MathUtilNeon64.inl | 37 +++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/cocos/math/MathUtilNeon64.inl b/cocos/math/MathUtilNeon64.inl index c6fdd70b24..9832669907 100644 --- a/cocos/math/MathUtilNeon64.inl +++ b/cocos/math/MathUtilNeon64.inl @@ -225,23 +225,34 @@ inline void MathUtilNeon64::transformVec4(const float* m, const float* v, float* inline void MathUtilNeon64::crossVec3(const float* v1, const float* v2, float* dst) { - asm volatile( - "ld1 {v0.2s}, [%2] \n\t" // - "ld1 {v0.s}[3], [%1] \n\t" // - "mov v0.s[2], v0.s[1] \n\t" // q0 = (v1y, v1z, v1z, v1x) + asm volatile( + "ld1 {v0.2s}, [%2] \n\t" + "ld1 {v0.s}[2], [%1] \n\t" + "mov v0.s[3], v0.s[0] \n\t" // q0 = (v1y, v1z, v1x, v1x) - "ld1 {v1.s}[1], [%3] \n\t" // - "ld1 {v1.s}[2], [%4], 4 \n\t" // - "ld1 {v1.s}[3], [%4] \n\t" // - "mov v1.s[0], v1.s[3] \n\t" // q1 = (v2z, v2x, v2y, v2z) + "ld1 {v1.4s}, [%3] \n\t" + "mov v1.s[3], v1.s[0] \n\t" // q1 = (v2x, v2y, v2z, v2x) "fmul v2.4s, v0.4s, v1.4s \n\t" // x = v1y * v2z, y = v1z * v2x - "fsub s8, s8, s10 \n\t" - "fsub s9, s9, s11 \n\t" // x -= v1z * v2y, y-= v1x - v2z - "fmul s10, s3, s6 \n\t" // z = v1x * v2y - "fmul s11, s0, s5 \n\t" // z-= v1y * vx - "fsub s10, s10, s11 \n\t" + + "mov v0.s[0], v0.s[1] \n\t" + "mov v0.s[1], v0.s[2] \n\t" + "mov v0.s[2], v0.s[3] \n\t" + + "mov v1.s[3], v1.s[2] \n\t" + + "fmul v0.4s, v0.4s, v1.4s \n\t" + + "mov v0.s[3], v0.s[1] \n\t" + "mov v0.s[1], v0.s[2] \n\t" + "mov v0.s[2], v0.s[0] \n\t" + + "fsub v2.4s, v0.4s, v2.4s \n\t" + + "mov v2.s[0], v2.s[1] \n\t" + "mov v2.s[1], v2.s[2] \n\t" + "mov v2.s[2], v2.s[3] \n\t" "st1 {v2.2s}, [%0], 8 \n\t" // V[x, y] "st1 {v2.s}[2], [%0] \n\t" // V[z] From 19de8a093550f46767a7e17b7858ba5831836dc2 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 24 Nov 2014 10:26:41 +0800 Subject: [PATCH 08/13] Adds PerformanceMathTest.cpp --- tests/cpp-tests/CMakeLists.txt | 1 + tests/cpp-tests/proj.android/jni/Android.mk | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/cpp-tests/CMakeLists.txt b/tests/cpp-tests/CMakeLists.txt index 6dd51fdcd2..c23b510907 100644 --- a/tests/cpp-tests/CMakeLists.txt +++ b/tests/cpp-tests/CMakeLists.txt @@ -155,6 +155,7 @@ set(TESTS_SRC Classes/PerformanceTest/PerformanceEventDispatcherTest.cpp Classes/PerformanceTest/PerformanceScenarioTest.cpp Classes/PerformanceTest/PerformanceCallbackTest.cpp + Classes/PerformanceTest/PerformanceMathTest.cpp Classes/PhysicsTest/PhysicsTest.cpp Classes/ReleasePoolTest/ReleasePoolTest.cpp Classes/RenderTextureTest/RenderTextureTest.cpp diff --git a/tests/cpp-tests/proj.android/jni/Android.mk b/tests/cpp-tests/proj.android/jni/Android.mk index 0c5593c36a..ffb6d6b22e 100644 --- a/tests/cpp-tests/proj.android/jni/Android.mk +++ b/tests/cpp-tests/proj.android/jni/Android.mk @@ -162,6 +162,7 @@ LOCAL_SRC_FILES := main.cpp \ ../../Classes/PerformanceTest/PerformanceEventDispatcherTest.cpp \ ../../Classes/PerformanceTest/PerformanceScenarioTest.cpp \ ../../Classes/PerformanceTest/PerformanceCallbackTest.cpp \ +../../Classes/PerformanceTest/PerformanceMathTest.cpp \ ../../Classes/PhysicsTest/PhysicsTest.cpp \ ../../Classes/ReleasePoolTest/ReleasePoolTest.cpp \ ../../Classes/RenderTextureTest/RenderTextureTest.cpp \ From 5d21c889aa71dfafac29f62affcbf84b416f87b2 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 24 Nov 2014 10:38:44 +0800 Subject: [PATCH 09/13] Reverts GCC_TREAT_WARNINGS_AS_ERRORS=YES for Xcode project of cpp-tests. --- build/cocos2d_tests.xcodeproj/project.pbxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/cocos2d_tests.xcodeproj/project.pbxproj b/build/cocos2d_tests.xcodeproj/project.pbxproj index a6b45d648b..96f50d8403 100644 --- a/build/cocos2d_tests.xcodeproj/project.pbxproj +++ b/build/cocos2d_tests.xcodeproj/project.pbxproj @@ -5714,7 +5714,7 @@ "CC_ENABLE_CHIPMUNK_INTEGRATION=1", ); GCC_SYMBOLS_PRIVATE_EXTERN = YES; - GCC_TREAT_WARNINGS_AS_ERRORS = NO; + GCC_TREAT_WARNINGS_AS_ERRORS = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES; GCC_WARN_UNUSED_VARIABLE = YES; @@ -5742,7 +5742,7 @@ "CC_ENABLE_CHIPMUNK_INTEGRATION=1", ); GCC_SYMBOLS_PRIVATE_EXTERN = YES; - GCC_TREAT_WARNINGS_AS_ERRORS = NO; + GCC_TREAT_WARNINGS_AS_ERRORS = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES; GCC_WARN_UNUSED_VARIABLE = YES; From e31a3fce835172b8545ba6dd8c12b08bccd05ffc Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 25 Nov 2014 10:03:57 +0800 Subject: [PATCH 10/13] Typo fix for the name of MultiTouchTest --- tests/cpp-tests/Classes/controller.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cpp-tests/Classes/controller.cpp b/tests/cpp-tests/Classes/controller.cpp index 4748f6d2ec..f05c2b44e6 100644 --- a/tests/cpp-tests/Classes/controller.cpp +++ b/tests/cpp-tests/Classes/controller.cpp @@ -84,7 +84,7 @@ Controller g_aTestNames[] = { { "Node: Text Input", [](){return new TextInputTestScene(); } }, { "Node: UI", [](){ return new UITestScene(); }}, { "Mouse", []() { return new MouseTestScene(); } }, - { "MutiTouch", []() { return new MutiTouchTestScene(); } }, + { "MultiTouch", []() { return new MutiTouchTestScene(); } }, { "Performance tests", []() { return new PerformanceTestScene(); } }, { "Renderer", []() { return new NewRendererTestScene(); } }, { "ReleasePool", [](){ return new ReleasePoolTestScene(); } }, From dab99eeb8bd551f9e17c3dade56ad7dd04b82a1f Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 25 Nov 2014 10:28:28 +0800 Subject: [PATCH 11/13] Adds PerformanceMathTest for win32. --- tests/cpp-tests/proj.win32/cpp-tests.vcxproj | 2 ++ tests/cpp-tests/proj.win32/cpp-tests.vcxproj.filters | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/tests/cpp-tests/proj.win32/cpp-tests.vcxproj b/tests/cpp-tests/proj.win32/cpp-tests.vcxproj index 7a885faf09..22ae13f117 100644 --- a/tests/cpp-tests/proj.win32/cpp-tests.vcxproj +++ b/tests/cpp-tests/proj.win32/cpp-tests.vcxproj @@ -177,6 +177,7 @@ + @@ -369,6 +370,7 @@ + diff --git a/tests/cpp-tests/proj.win32/cpp-tests.vcxproj.filters b/tests/cpp-tests/proj.win32/cpp-tests.vcxproj.filters index 98b97b0ac6..25a8bbd3e6 100644 --- a/tests/cpp-tests/proj.win32/cpp-tests.vcxproj.filters +++ b/tests/cpp-tests/proj.win32/cpp-tests.vcxproj.filters @@ -888,6 +888,9 @@ Classes\OpenURLTest + + Classes\PerformanceTest + @@ -1634,5 +1637,8 @@ Classes\OpenURLTest + + Classes\PerformanceTest + \ No newline at end of file From 8db214a7785544754ac2e6837a4274736a509d63 Mon Sep 17 00:00:00 2001 From: huanghsiwu <375102906@qq.com> Date: Tue, 25 Nov 2014 11:30:00 +0800 Subject: [PATCH 12/13] Adds PerformanceMathTest for wp8 and winRT --- .../cpp-tests.Shared/cpp-tests.Shared.vcxitems | 2 ++ .../cpp-tests.Shared/cpp-tests.Shared.vcxitems.filters | 6 ++++++ .../cpp-testsComponent/cpp-testsComponent.vcxproj | 2 ++ .../cpp-testsComponent/cpp-testsComponent.vcxproj.filters | 6 ++++++ 4 files changed, 16 insertions(+) diff --git a/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Shared/cpp-tests.Shared.vcxitems b/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Shared/cpp-tests.Shared.vcxitems index 3e22b9eb51..ec03c457bb 100644 --- a/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Shared/cpp-tests.Shared.vcxitems +++ b/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Shared/cpp-tests.Shared.vcxitems @@ -119,6 +119,7 @@ + @@ -372,6 +373,7 @@ + diff --git a/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Shared/cpp-tests.Shared.vcxitems.filters b/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Shared/cpp-tests.Shared.vcxitems.filters index af02131873..40c60443df 100644 --- a/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Shared/cpp-tests.Shared.vcxitems.filters +++ b/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Shared/cpp-tests.Shared.vcxitems.filters @@ -751,6 +751,9 @@ Classes\UITest\CocostudioGUISceneTest\UITextFieldTest + + Classes\PerformanceTest + @@ -1647,5 +1650,8 @@ + + Classes\PerformanceTest + \ No newline at end of file diff --git a/tests/cpp-tests/proj.wp8-xaml/cpp-testsComponent/cpp-testsComponent.vcxproj b/tests/cpp-tests/proj.wp8-xaml/cpp-testsComponent/cpp-testsComponent.vcxproj index 112cdec6b3..faae99f338 100644 --- a/tests/cpp-tests/proj.wp8-xaml/cpp-testsComponent/cpp-testsComponent.vcxproj +++ b/tests/cpp-tests/proj.wp8-xaml/cpp-testsComponent/cpp-testsComponent.vcxproj @@ -235,6 +235,7 @@ + @@ -432,6 +433,7 @@ + diff --git a/tests/cpp-tests/proj.wp8-xaml/cpp-testsComponent/cpp-testsComponent.vcxproj.filters b/tests/cpp-tests/proj.wp8-xaml/cpp-testsComponent/cpp-testsComponent.vcxproj.filters index 98237a7c02..6a4af8a283 100644 --- a/tests/cpp-tests/proj.wp8-xaml/cpp-testsComponent/cpp-testsComponent.vcxproj.filters +++ b/tests/cpp-tests/proj.wp8-xaml/cpp-testsComponent/cpp-testsComponent.vcxproj.filters @@ -885,6 +885,9 @@ Classes\ExtensionsTest\AssetsManagerExLoaderScene + + Classes\PerformanceTest + @@ -1632,6 +1635,9 @@ Classes\ExtensionsTest\AssetsManagerExLoaderScene + + Classes\PerformanceTest + From 6998d917816898a1d539a05f59ca89ba64f95bd2 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 25 Nov 2014 16:36:07 +0800 Subject: [PATCH 13/13] MathUtilTest is only available for optimized instructions. --- tests/cpp-tests/Classes/UnitTest/UnitTest.cpp | 75 ++++++++++--------- 1 file changed, 41 insertions(+), 34 deletions(-) diff --git a/tests/cpp-tests/Classes/UnitTest/UnitTest.cpp b/tests/cpp-tests/Classes/UnitTest/UnitTest.cpp index 9c3f977d83..0770c5ebf6 100644 --- a/tests/cpp-tests/Classes/UnitTest/UnitTest.cpp +++ b/tests/cpp-tests/Classes/UnitTest/UnitTest.cpp @@ -1,6 +1,37 @@ #include "UnitTest.h" #include "RefPtrTest.h" +#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) +#if defined (__arm64__) +#define USE_NEON64 +#define INCLUDE_NEON64 +#elif defined (__ARM_NEON__) +#define USE_NEON32 +#define INCLUDE_NEON32 +#else +#endif +#elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) +#if defined (__arm64__) || defined (__aarch64__) +#define USE_NEON64 +#define INCLUDE_NEON64 +#elif defined (__ARM_NEON__) +#define INCLUDE_NEON32 +#else +#endif +#else + +#endif + +#if defined (__SSE__) +#define USE_SSE +#define INCLUDE_SSE +#endif + +#if (defined INCLUDE_NEON64) || (defined INCLUDE_NEON32) // FIXME: || (defined INCLUDE_SSE) +#define UNIT_TEST_FOR_OPTIMIZED_MATH_UTIL +#endif + + // For ' < o > ' multiply test scene. static std::function createFunctions[] = { @@ -9,7 +40,9 @@ static std::function createFunctions[] = { CL(ValueTest), CL(RefPtrTest), CL(UTFConversionTest), +#ifdef UNIT_TEST_FOR_OPTIMIZED_MATH_UTIL CL(MathUtilTest) +#endif }; static int sceneIdx = -1; @@ -820,38 +853,7 @@ std::string UTFConversionTest::subtitle() const // MathUtilTest -//#define USE_NEON32 : neon 32 code will be used -//#define USE_NEON64 : neon 64 code will be used -//#define INCLUDE_NEON32 : neon 32 code included -//#define INCLUDE_NEON64 : neon 64 code included -//#define USE_SSE : SSE code used -//#define INCLUDE_SSE : SSE code included - -#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) -#if defined (__arm64__) -#define USE_NEON64 -#define INCLUDE_NEON64 -#elif defined (__ARM_NEON__) -#define USE_NEON32 -#define INCLUDE_NEON32 -#else -#endif -#elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) -#if defined (__arm64__) || defined (__aarch64__) -#define USE_NEON64 -#define INCLUDE_NEON64 -#elif defined (__ARM_NEON__) -#define INCLUDE_NEON32 -#else -#endif -#else - -#endif - -#if defined (__SSE__) -#define USE_SSE -#define INCLUDE_SSE -#endif +namespace UnitTest { #ifdef INCLUDE_NEON32 #include "math/MathUtilNeon.inl" @@ -862,11 +864,16 @@ std::string UTFConversionTest::subtitle() const #endif #ifdef INCLUDE_SSE -#include "math/MathUtilSSE.inl" +//FIXME: #include "math/MathUtilSSE.inl" #endif #include "math/MathUtil.inl" +} // namespace UnitTest { + +// I know the next line looks ugly, but it's a way to test MathUtil. :) +using namespace UnitTest::cocos2d; + static void __checkMathUtilResult(const char* description, const float* a1, const float* a2, int size) { log("-------------checking %s ----------------------------", description); @@ -882,7 +889,7 @@ static void __checkMathUtilResult(const char* description, const float* a1, cons { log("Wrong: a1[%d]=%f, a2[%d]=%f", i, a1[i], i, a2[i]); } -// CCASSERT(r, "The optimized instruction is implemented in a wrong way, please check it!"); + CCASSERT(r, "The optimized instruction is implemented in a wrong way, please check it!"); } }