From 66070868f754ec4f7cdd8ec91aacdfdbcc4223fc Mon Sep 17 00:00:00 2001 From: sunzhuoshi Date: Mon, 8 Sep 2014 20:58:59 +0800 Subject: [PATCH 1/6] Added Math SSE implementation on x86 --- cocos/math/Mat4.cpp | 38 ++++++++-- cocos/math/Mat4.h | 11 +++ cocos/math/MathUtil.h | 25 +++++- cocos/math/MathUtilSSE.inl | 152 +++++++++++++++++++++++++++++++++++++ cocos/math/Vec4.h | 18 ++++- 5 files changed, 235 insertions(+), 9 deletions(-) create mode 100644 cocos/math/MathUtilSSE.inl diff --git a/cocos/math/Mat4.cpp b/cocos/math/Mat4.cpp index ff598d3da8..1e3dc5a972 100644 --- a/cocos/math/Mat4.cpp +++ b/cocos/math/Mat4.cpp @@ -414,8 +414,11 @@ void Mat4::add(float scalar) void Mat4::add(float scalar, Mat4* dst) { GP_ASSERT(dst); - +#ifdef __SSE__ + MathUtil::addMatrix(col, scalar, dst->col); +#else MathUtil::addMatrix(m, scalar, dst->m); +#endif } void Mat4::add(const Mat4& mat) @@ -426,8 +429,11 @@ void Mat4::add(const Mat4& mat) void Mat4::add(const Mat4& m1, const Mat4& m2, Mat4* dst) { GP_ASSERT(dst); - +#ifdef __SSE__ + MathUtil::addMatrix(m1.col, m2.col, dst->col); +#else MathUtil::addMatrix(m1.m, m2.m, dst->m); +#endif } bool Mat4::decompose(Vec3* scale, Quaternion* rotation, Vec3* translation) const @@ -700,8 +706,11 @@ void Mat4::multiply(float scalar, Mat4* dst) const void Mat4::multiply(const Mat4& m, float scalar, Mat4* dst) { GP_ASSERT(dst); - +#ifdef __SSE__ + MathUtil::multiplyMatrix(m.col, scalar, dst->col); +#else MathUtil::multiplyMatrix(m.m, scalar, dst->m); +#endif } void Mat4::multiply(const Mat4& mat) @@ -712,13 +721,20 @@ void Mat4::multiply(const Mat4& mat) void Mat4::multiply(const Mat4& m1, const Mat4& m2, Mat4* dst) { GP_ASSERT(dst); - +#ifdef __SSE__ + MathUtil::multiplyMatrix(m1.col, m2.col, dst->col); +#else MathUtil::multiplyMatrix(m1.m, m2.m, dst->m); +#endif } void Mat4::negate() { +#ifdef __SSE__ + MathUtil::negateMatrix(col, col); +#else MathUtil::negateMatrix(m, m); +#endif } Mat4 Mat4::getNegated() const @@ -870,8 +886,11 @@ void Mat4::subtract(const Mat4& mat) void Mat4::subtract(const Mat4& m1, const Mat4& m2, Mat4* dst) { GP_ASSERT(dst); - +#ifdef __SSE__ + MathUtil::subtractMatrix(m1.col, m2.col, dst->col); +#else MathUtil::subtractMatrix(m1.m, m2.m, dst->m); +#endif } void Mat4::transformPoint(Vec3* point) const @@ -912,8 +931,11 @@ void Mat4::transformVector(Vec4* vector) const void Mat4::transformVector(const Vec4& vector, Vec4* dst) const { GP_ASSERT(dst); - +#ifdef __SSE__ + MathUtil::transformVec4(col, vector.v, dst->v); +#else MathUtil::transformVec4(m, (const float*) &vector, (float*)dst); +#endif } void Mat4::translate(float x, float y, float z) @@ -940,7 +962,11 @@ void Mat4::translate(const Vec3& t, Mat4* dst) const void Mat4::transpose() { +#ifdef __SSE__ + MathUtil::transposeMatrix(col, col); +#else MathUtil::transposeMatrix(m, m); +#endif } Mat4 Mat4::getTransposed() const diff --git a/cocos/math/Mat4.h b/cocos/math/Mat4.h index 53b4b64da1..7616221943 100644 --- a/cocos/math/Mat4.h +++ b/cocos/math/Mat4.h @@ -24,6 +24,10 @@ #include "math/Vec3.h" #include "math/Vec4.h" +#ifdef __SSE__ +#include +#endif + NS_CC_MATH_BEGIN //class Plane; @@ -77,7 +81,14 @@ public: /** * Stores the columns of this 4x4 matrix. * */ +#ifdef __SSE__ + union { + __m128 col[4]; + float m[16]; + }; +#else float m[16]; +#endif /** * Constructs a matrix initialized to the identity matrix: diff --git a/cocos/math/MathUtil.h b/cocos/math/MathUtil.h index da5fe3c830..acf6ab0b42 100644 --- a/cocos/math/MathUtil.h +++ b/cocos/math/MathUtil.h @@ -21,6 +21,10 @@ #ifndef MATHUTIL_H_ #define MATHUTIL_H_ +#ifdef __SSE__ +#include +#endif + #include "CCMathBase.h" NS_CC_MATH_BEGIN @@ -67,7 +71,23 @@ public: static void smooth(float* x, float target, float elapsedTime, float riseTime, float fallTime); private: - +#ifdef __SSE__ + inline static void addMatrix(const __m128 m[4], float scalar, __m128 dst[4]); + + inline static void addMatrix(const __m128 m1[4], const __m128 m2[4], __m128 dst[4]); + + inline static void subtractMatrix(const __m128 m1[4], const __m128 m2[4], __m128 dst[4]); + + inline static void multiplyMatrix(const __m128 m[4], float scalar, __m128 dst[4]); + + inline static void multiplyMatrix(const __m128 m1[4], const __m128 m2[4], __m128 dst[4]); + + inline static void negateMatrix(const __m128 m[4], __m128 dst[4]); + + inline static void transposeMatrix(const __m128 m[4], __m128 dst[4]); + + inline static void transformVec4(const __m128 m[4], const __m128& v, __m128& dst); +#endif inline static void addMatrix(const float* m, float scalar, float* dst); inline static void addMatrix(const float* m1, const float* m2, float* dst); @@ -99,6 +119,9 @@ NS_CC_MATH_END #include "MathUtilNeon.inl" #else #include "MathUtil.inl" +#if defined(__SSE__) +#include "MathUtilSSE.inl" +#endif #endif #endif diff --git a/cocos/math/MathUtilSSE.inl b/cocos/math/MathUtilSSE.inl new file mode 100644 index 0000000000..b701bb51ca --- /dev/null +++ b/cocos/math/MathUtilSSE.inl @@ -0,0 +1,152 @@ +NS_CC_MATH_BEGIN + +inline void MathUtil::addMatrix(const __m128 m[4], float scalar, __m128 dst[4]) +{ + __m128 s = _mm_set1_ps(scalar); + dst[0] = _mm_add_ps(m[0], s); + dst[1] = _mm_add_ps(m[1], s); + dst[2] = _mm_add_ps(m[2], s); + dst[3] = _mm_add_ps(m[3], s); +} + +inline void MathUtil::addMatrix(const __m128 m1[4], const __m128 m2[4], __m128 dst[4]) +{ + dst[0] = _mm_add_ps(m1[0], m2[0]); + dst[1] = _mm_add_ps(m1[1], m2[1]); + dst[2] = _mm_add_ps(m1[2], m2[2]); + dst[3] = _mm_add_ps(m1[3], m2[3]); +} + +inline void MathUtil::subtractMatrix(const __m128 m1[4], const __m128 m2[4], __m128 dst[4]) +{ + dst[0] = _mm_sub_ps(m1[0], m2[0]); + dst[1] = _mm_sub_ps(m1[1], m2[1]); + dst[2] = _mm_sub_ps(m1[2], m2[2]); + dst[3] = _mm_sub_ps(m1[3], m2[3]); +} + +inline void MathUtil::multiplyMatrix(const __m128 m[4], float scalar, __m128 dst[4]) +{ + __m128 s = _mm_set1_ps(scalar); + dst[0] = _mm_mul_ps(m[0], s); + dst[1] = _mm_mul_ps(m[1], s); + dst[2] = _mm_mul_ps(m[2], s); + dst[3] = _mm_mul_ps(m[3], s); +} + +inline void MathUtil::multiplyMatrix(const __m128 m1[4], const __m128 m2[4], __m128 dst[4]) +{ + __m128 dst0, dst1, dst2, dst3; + { + __m128 e0 = _mm_shuffle_ps(m2[0], m2[0], _MM_SHUFFLE(0, 0, 0, 0)); + __m128 e1 = _mm_shuffle_ps(m2[0], m2[0], _MM_SHUFFLE(1, 1, 1, 1)); + __m128 e2 = _mm_shuffle_ps(m2[0], m2[0], _MM_SHUFFLE(2, 2, 2, 2)); + __m128 e3 = _mm_shuffle_ps(m2[0], m2[0], _MM_SHUFFLE(3, 3, 3, 3)); + + __m128 v0 = _mm_mul_ps(m1[0], e0); + __m128 v1 = _mm_mul_ps(m1[1], e1); + __m128 v2 = _mm_mul_ps(m1[2], e2); + __m128 v3 = _mm_mul_ps(m1[3], e3); + + __m128 a0 = _mm_add_ps(v0, v1); + __m128 a1 = _mm_add_ps(v2, v3); + __m128 a2 = _mm_add_ps(a0, a1); + + dst0 = a2; + } + + { + __m128 e0 = _mm_shuffle_ps(m2[1], m2[1], _MM_SHUFFLE(0, 0, 0, 0)); + __m128 e1 = _mm_shuffle_ps(m2[1], m2[1], _MM_SHUFFLE(1, 1, 1, 1)); + __m128 e2 = _mm_shuffle_ps(m2[1], m2[1], _MM_SHUFFLE(2, 2, 2, 2)); + __m128 e3 = _mm_shuffle_ps(m2[1], m2[1], _MM_SHUFFLE(3, 3, 3, 3)); + + __m128 v0 = _mm_mul_ps(m1[0], e0); + __m128 v1 = _mm_mul_ps(m1[1], e1); + __m128 v2 = _mm_mul_ps(m1[2], e2); + __m128 v3 = _mm_mul_ps(m1[3], e3); + + __m128 a0 = _mm_add_ps(v0, v1); + __m128 a1 = _mm_add_ps(v2, v3); + __m128 a2 = _mm_add_ps(a0, a1); + + dst1 = a2; + } + + { + __m128 e0 = _mm_shuffle_ps(m2[2], m2[2], _MM_SHUFFLE(0, 0, 0, 0)); + __m128 e1 = _mm_shuffle_ps(m2[2], m2[2], _MM_SHUFFLE(1, 1, 1, 1)); + __m128 e2 = _mm_shuffle_ps(m2[2], m2[2], _MM_SHUFFLE(2, 2, 2, 2)); + __m128 e3 = _mm_shuffle_ps(m2[2], m2[2], _MM_SHUFFLE(3, 3, 3, 3)); + + __m128 v0 = _mm_mul_ps(m1[0], e0); + __m128 v1 = _mm_mul_ps(m1[1], e1); + __m128 v2 = _mm_mul_ps(m1[2], e2); + __m128 v3 = _mm_mul_ps(m1[3], e3); + + __m128 a0 = _mm_add_ps(v0, v1); + __m128 a1 = _mm_add_ps(v2, v3); + __m128 a2 = _mm_add_ps(a0, a1); + + dst2 = a2; + } + + { + __m128 e0 = _mm_shuffle_ps(m2[3], m2[3], _MM_SHUFFLE(0, 0, 0, 0)); + __m128 e1 = _mm_shuffle_ps(m2[3], m2[3], _MM_SHUFFLE(1, 1, 1, 1)); + __m128 e2 = _mm_shuffle_ps(m2[3], m2[3], _MM_SHUFFLE(2, 2, 2, 2)); + __m128 e3 = _mm_shuffle_ps(m2[3], m2[3], _MM_SHUFFLE(3, 3, 3, 3)); + + __m128 v0 = _mm_mul_ps(m1[0], e0); + __m128 v1 = _mm_mul_ps(m1[1], e1); + __m128 v2 = _mm_mul_ps(m1[2], e2); + __m128 v3 = _mm_mul_ps(m1[3], e3); + + __m128 a0 = _mm_add_ps(v0, v1); + __m128 a1 = _mm_add_ps(v2, v3); + __m128 a2 = _mm_add_ps(a0, a1); + + dst3 = a2; + } + dst[0] = dst0; + dst[1] = dst1; + dst[2] = dst2; + dst[3] = dst3; +} + +inline void MathUtil::negateMatrix(const __m128 m[4], __m128 dst[4]) +{ + __m128 z = _mm_setzero_ps(); + dst[0] = _mm_sub_ps(z, m[0]); + dst[1] = _mm_sub_ps(z, m[1]); + dst[2] = _mm_sub_ps(z, m[2]); + dst[3] = _mm_sub_ps(z, m[3]); +} + +inline void MathUtil::transposeMatrix(const __m128 m[4], __m128 dst[4]) +{ + __m128 tmp0 = _mm_shuffle_ps(m[0], m[1], 0x44); + __m128 tmp2 = _mm_shuffle_ps(m[0], m[1], 0xEE); + __m128 tmp1 = _mm_shuffle_ps(m[2], m[3], 0x44); + __m128 tmp3 = _mm_shuffle_ps(m[2], m[3], 0xEE); + + dst[0] = _mm_shuffle_ps(tmp0, tmp1, 0x88); + dst[1] = _mm_shuffle_ps(tmp0, tmp1, 0xDD); + dst[2] = _mm_shuffle_ps(tmp2, tmp3, 0x88); + dst[3] = _mm_shuffle_ps(tmp2, tmp3, 0xDD); +} + +inline void MathUtil::transformVec4(const __m128 m[4], const __m128& v, __m128& dst) +{ + __m128 col1 = _mm_shuffle_ps(v, v, _MM_SHUFFLE(0, 0, 0, 0)); + __m128 col2 = _mm_shuffle_ps(v, v, _MM_SHUFFLE(1, 1, 1, 1)); + __m128 col3 = _mm_shuffle_ps(v, v, _MM_SHUFFLE(2, 2, 2, 2)); + __m128 col4 = _mm_shuffle_ps(v, v, _MM_SHUFFLE(3, 3, 3, 3)); + + dst = _mm_add_ps( + _mm_add_ps(_mm_mul_ps(m[0], col1), _mm_mul_ps(m[1], col2)), + _mm_add_ps(_mm_mul_ps(m[2], col3), _mm_mul_ps(m[3], col4)) + ); +} + +NS_CC_MATH_END diff --git a/cocos/math/Vec4.h b/cocos/math/Vec4.h index d6399fb339..712f60fd4f 100644 --- a/cocos/math/Vec4.h +++ b/cocos/math/Vec4.h @@ -21,6 +21,10 @@ #ifndef MATH_VEC4_H #define MATH_VEC4_H +#ifdef __SSE__ +#include +#endif + #include "math/CCMathBase.h" NS_CC_MATH_BEGIN @@ -33,7 +37,17 @@ class Mat4; class CC_DLL Vec4 { public: - +#ifdef __SSE__ + union { + struct { + float x; + float y; + float z; + float w; + }; + __m128 v; + }; +#else /** * The x-coordinate. */ @@ -53,7 +67,7 @@ public: * The w-coordinate. */ float w; - +#endif /** * Constructs a new vector initialized to all zeros. */ From 3a433b2cd6ae7d469f73100f1aad7750a9e110e1 Mon Sep 17 00:00:00 2001 From: samuele3hu Date: Tue, 9 Sep 2014 16:26:06 +0800 Subject: [PATCH 2/6] Update bindings-generator submodule --- tools/bindings-generator | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/bindings-generator b/tools/bindings-generator index c1db553615..a8496d540c 160000 --- a/tools/bindings-generator +++ b/tools/bindings-generator @@ -1 +1 @@ -Subproject commit c1db553615789a1545d495d0d0fd6f620547f99d +Subproject commit a8496d540c174236bec0d5a33457340571699f19 From 3151c54879e27b97fa0d2ef85b7330509ebe4d7b Mon Sep 17 00:00:00 2001 From: samuele3hu Date: Tue, 9 Sep 2014 19:08:01 +0800 Subject: [PATCH 3/6] Update macro define limited --- cocos/math/Mat4.cpp | 16 ++++++++-------- cocos/math/Mat4.h | 4 ++-- cocos/math/MathUtil.h | 4 ++-- cocos/math/MathUtilSSE.inl | 4 ++-- cocos/math/Vec4.h | 4 ++-- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/cocos/math/Mat4.cpp b/cocos/math/Mat4.cpp index 1e3dc5a972..0062888a87 100644 --- a/cocos/math/Mat4.cpp +++ b/cocos/math/Mat4.cpp @@ -414,7 +414,7 @@ void Mat4::add(float scalar) void Mat4::add(float scalar, Mat4* dst) { GP_ASSERT(dst); -#ifdef __SSE__ +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) && defined (__SSE__) MathUtil::addMatrix(col, scalar, dst->col); #else MathUtil::addMatrix(m, scalar, dst->m); @@ -429,7 +429,7 @@ void Mat4::add(const Mat4& mat) void Mat4::add(const Mat4& m1, const Mat4& m2, Mat4* dst) { GP_ASSERT(dst); -#ifdef __SSE__ +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) && defined (__SSE__) MathUtil::addMatrix(m1.col, m2.col, dst->col); #else MathUtil::addMatrix(m1.m, m2.m, dst->m); @@ -706,7 +706,7 @@ void Mat4::multiply(float scalar, Mat4* dst) const void Mat4::multiply(const Mat4& m, float scalar, Mat4* dst) { GP_ASSERT(dst); -#ifdef __SSE__ +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) && defined (__SSE__) MathUtil::multiplyMatrix(m.col, scalar, dst->col); #else MathUtil::multiplyMatrix(m.m, scalar, dst->m); @@ -721,7 +721,7 @@ void Mat4::multiply(const Mat4& mat) void Mat4::multiply(const Mat4& m1, const Mat4& m2, Mat4* dst) { GP_ASSERT(dst); -#ifdef __SSE__ +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) && defined (__SSE__) MathUtil::multiplyMatrix(m1.col, m2.col, dst->col); #else MathUtil::multiplyMatrix(m1.m, m2.m, dst->m); @@ -730,7 +730,7 @@ void Mat4::multiply(const Mat4& m1, const Mat4& m2, Mat4* dst) void Mat4::negate() { -#ifdef __SSE__ +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) && defined (__SSE__) MathUtil::negateMatrix(col, col); #else MathUtil::negateMatrix(m, m); @@ -886,7 +886,7 @@ void Mat4::subtract(const Mat4& mat) void Mat4::subtract(const Mat4& m1, const Mat4& m2, Mat4* dst) { GP_ASSERT(dst); -#ifdef __SSE__ +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) && defined (__SSE__) MathUtil::subtractMatrix(m1.col, m2.col, dst->col); #else MathUtil::subtractMatrix(m1.m, m2.m, dst->m); @@ -931,7 +931,7 @@ void Mat4::transformVector(Vec4* vector) const void Mat4::transformVector(const Vec4& vector, Vec4* dst) const { GP_ASSERT(dst); -#ifdef __SSE__ +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) && defined (__SSE__) MathUtil::transformVec4(col, vector.v, dst->v); #else MathUtil::transformVec4(m, (const float*) &vector, (float*)dst); @@ -962,7 +962,7 @@ void Mat4::translate(const Vec3& t, Mat4* dst) const void Mat4::transpose() { -#ifdef __SSE__ +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) && defined (__SSE__) MathUtil::transposeMatrix(col, col); #else MathUtil::transposeMatrix(m, m); diff --git a/cocos/math/Mat4.h b/cocos/math/Mat4.h index 7616221943..3b6438dcd1 100644 --- a/cocos/math/Mat4.h +++ b/cocos/math/Mat4.h @@ -24,7 +24,7 @@ #include "math/Vec3.h" #include "math/Vec4.h" -#ifdef __SSE__ +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) && defined (__SSE__) #include #endif @@ -81,7 +81,7 @@ public: /** * Stores the columns of this 4x4 matrix. * */ -#ifdef __SSE__ +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) && defined (__SSE__) union { __m128 col[4]; float m[16]; diff --git a/cocos/math/MathUtil.h b/cocos/math/MathUtil.h index acf6ab0b42..ada14e70c0 100644 --- a/cocos/math/MathUtil.h +++ b/cocos/math/MathUtil.h @@ -21,7 +21,7 @@ #ifndef MATHUTIL_H_ #define MATHUTIL_H_ -#ifdef __SSE__ +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) && defined (__SSE__) #include #endif @@ -71,7 +71,7 @@ public: static void smooth(float* x, float target, float elapsedTime, float riseTime, float fallTime); private: -#ifdef __SSE__ +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) && defined (__SSE__) inline static void addMatrix(const __m128 m[4], float scalar, __m128 dst[4]); inline static void addMatrix(const __m128 m1[4], const __m128 m2[4], __m128 dst[4]); diff --git a/cocos/math/MathUtilSSE.inl b/cocos/math/MathUtilSSE.inl index b701bb51ca..e701d2cdbd 100644 --- a/cocos/math/MathUtilSSE.inl +++ b/cocos/math/MathUtilSSE.inl @@ -1,5 +1,5 @@ NS_CC_MATH_BEGIN - +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) && defined (__SSE__) inline void MathUtil::addMatrix(const __m128 m[4], float scalar, __m128 dst[4]) { __m128 s = _mm_set1_ps(scalar); @@ -148,5 +148,5 @@ inline void MathUtil::transformVec4(const __m128 m[4], const __m128& v, __m128& _mm_add_ps(_mm_mul_ps(m[2], col3), _mm_mul_ps(m[3], col4)) ); } - +#endif NS_CC_MATH_END diff --git a/cocos/math/Vec4.h b/cocos/math/Vec4.h index 712f60fd4f..cf5f2fe16b 100644 --- a/cocos/math/Vec4.h +++ b/cocos/math/Vec4.h @@ -21,7 +21,7 @@ #ifndef MATH_VEC4_H #define MATH_VEC4_H -#ifdef __SSE__ +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) && defined (__SSE__) #include #endif @@ -37,7 +37,7 @@ class Mat4; class CC_DLL Vec4 { public: -#ifdef __SSE__ +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) && defined (__SSE__) union { struct { float x; From 8c0f8e1eb654c05e5600e6be2ff68a5d914712ca Mon Sep 17 00:00:00 2001 From: samuele3hu Date: Tue, 9 Sep 2014 23:01:37 +0800 Subject: [PATCH 4/6] Reset marco limited to `#ifdef __SSE__` --- cocos/math/Mat4.cpp | 16 ++++++++-------- cocos/math/Mat4.h | 4 ++-- cocos/math/MathUtil.h | 4 ++-- cocos/math/MathUtilSSE.inl | 4 ++-- cocos/math/Vec4.h | 4 ++-- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/cocos/math/Mat4.cpp b/cocos/math/Mat4.cpp index 0062888a87..1e3dc5a972 100644 --- a/cocos/math/Mat4.cpp +++ b/cocos/math/Mat4.cpp @@ -414,7 +414,7 @@ void Mat4::add(float scalar) void Mat4::add(float scalar, Mat4* dst) { GP_ASSERT(dst); -#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) && defined (__SSE__) +#ifdef __SSE__ MathUtil::addMatrix(col, scalar, dst->col); #else MathUtil::addMatrix(m, scalar, dst->m); @@ -429,7 +429,7 @@ void Mat4::add(const Mat4& mat) void Mat4::add(const Mat4& m1, const Mat4& m2, Mat4* dst) { GP_ASSERT(dst); -#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) && defined (__SSE__) +#ifdef __SSE__ MathUtil::addMatrix(m1.col, m2.col, dst->col); #else MathUtil::addMatrix(m1.m, m2.m, dst->m); @@ -706,7 +706,7 @@ void Mat4::multiply(float scalar, Mat4* dst) const void Mat4::multiply(const Mat4& m, float scalar, Mat4* dst) { GP_ASSERT(dst); -#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) && defined (__SSE__) +#ifdef __SSE__ MathUtil::multiplyMatrix(m.col, scalar, dst->col); #else MathUtil::multiplyMatrix(m.m, scalar, dst->m); @@ -721,7 +721,7 @@ void Mat4::multiply(const Mat4& mat) void Mat4::multiply(const Mat4& m1, const Mat4& m2, Mat4* dst) { GP_ASSERT(dst); -#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) && defined (__SSE__) +#ifdef __SSE__ MathUtil::multiplyMatrix(m1.col, m2.col, dst->col); #else MathUtil::multiplyMatrix(m1.m, m2.m, dst->m); @@ -730,7 +730,7 @@ void Mat4::multiply(const Mat4& m1, const Mat4& m2, Mat4* dst) void Mat4::negate() { -#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) && defined (__SSE__) +#ifdef __SSE__ MathUtil::negateMatrix(col, col); #else MathUtil::negateMatrix(m, m); @@ -886,7 +886,7 @@ void Mat4::subtract(const Mat4& mat) void Mat4::subtract(const Mat4& m1, const Mat4& m2, Mat4* dst) { GP_ASSERT(dst); -#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) && defined (__SSE__) +#ifdef __SSE__ MathUtil::subtractMatrix(m1.col, m2.col, dst->col); #else MathUtil::subtractMatrix(m1.m, m2.m, dst->m); @@ -931,7 +931,7 @@ void Mat4::transformVector(Vec4* vector) const void Mat4::transformVector(const Vec4& vector, Vec4* dst) const { GP_ASSERT(dst); -#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) && defined (__SSE__) +#ifdef __SSE__ MathUtil::transformVec4(col, vector.v, dst->v); #else MathUtil::transformVec4(m, (const float*) &vector, (float*)dst); @@ -962,7 +962,7 @@ void Mat4::translate(const Vec3& t, Mat4* dst) const void Mat4::transpose() { -#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) && defined (__SSE__) +#ifdef __SSE__ MathUtil::transposeMatrix(col, col); #else MathUtil::transposeMatrix(m, m); diff --git a/cocos/math/Mat4.h b/cocos/math/Mat4.h index 3b6438dcd1..7616221943 100644 --- a/cocos/math/Mat4.h +++ b/cocos/math/Mat4.h @@ -24,7 +24,7 @@ #include "math/Vec3.h" #include "math/Vec4.h" -#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) && defined (__SSE__) +#ifdef __SSE__ #include #endif @@ -81,7 +81,7 @@ public: /** * Stores the columns of this 4x4 matrix. * */ -#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) && defined (__SSE__) +#ifdef __SSE__ union { __m128 col[4]; float m[16]; diff --git a/cocos/math/MathUtil.h b/cocos/math/MathUtil.h index ada14e70c0..acf6ab0b42 100644 --- a/cocos/math/MathUtil.h +++ b/cocos/math/MathUtil.h @@ -21,7 +21,7 @@ #ifndef MATHUTIL_H_ #define MATHUTIL_H_ -#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) && defined (__SSE__) +#ifdef __SSE__ #include #endif @@ -71,7 +71,7 @@ public: static void smooth(float* x, float target, float elapsedTime, float riseTime, float fallTime); private: -#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) && defined (__SSE__) +#ifdef __SSE__ inline static void addMatrix(const __m128 m[4], float scalar, __m128 dst[4]); inline static void addMatrix(const __m128 m1[4], const __m128 m2[4], __m128 dst[4]); diff --git a/cocos/math/MathUtilSSE.inl b/cocos/math/MathUtilSSE.inl index e701d2cdbd..b701bb51ca 100644 --- a/cocos/math/MathUtilSSE.inl +++ b/cocos/math/MathUtilSSE.inl @@ -1,5 +1,5 @@ NS_CC_MATH_BEGIN -#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) && defined (__SSE__) + inline void MathUtil::addMatrix(const __m128 m[4], float scalar, __m128 dst[4]) { __m128 s = _mm_set1_ps(scalar); @@ -148,5 +148,5 @@ inline void MathUtil::transformVec4(const __m128 m[4], const __m128& v, __m128& _mm_add_ps(_mm_mul_ps(m[2], col3), _mm_mul_ps(m[3], col4)) ); } -#endif + NS_CC_MATH_END diff --git a/cocos/math/Vec4.h b/cocos/math/Vec4.h index cf5f2fe16b..712f60fd4f 100644 --- a/cocos/math/Vec4.h +++ b/cocos/math/Vec4.h @@ -21,7 +21,7 @@ #ifndef MATH_VEC4_H #define MATH_VEC4_H -#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) && defined (__SSE__) +#ifdef __SSE__ #include #endif @@ -37,7 +37,7 @@ class Mat4; class CC_DLL Vec4 { public: -#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) && defined (__SSE__) +#ifdef __SSE__ union { struct { float x; From daeb51e5480fb3aab150bab605dc2db36de326bd Mon Sep 17 00:00:00 2001 From: samuele3hu Date: Tue, 9 Sep 2014 23:02:06 +0800 Subject: [PATCH 5/6] Update cocos2d.ini --- tools/tolua/cocos2dx.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/tolua/cocos2dx.ini b/tools/tolua/cocos2dx.ini index d6894e123b..c84570383f 100644 --- a/tools/tolua/cocos2dx.ini +++ b/tools/tolua/cocos2dx.ini @@ -11,7 +11,7 @@ android_headers = -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include android_flags = -D_SIZE_T_DEFINED_ clang_headers = -I%(clangllvmdir)s/lib/clang/3.3/include -clang_flags = -nostdinc -x c++ -std=c++11 +clang_flags = -nostdinc -x c++ -std=c++11 -D__STRICT_ANSI__ cocos_headers = -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/platform/android cocos_flags = -DANDROID From 51879a7e394b88907970a9fcb6476cdd7ada1ee5 Mon Sep 17 00:00:00 2001 From: samuele3hu Date: Wed, 10 Sep 2014 14:18:21 +0800 Subject: [PATCH 6/6] Update lua bindings ini config files --- tools/tolua/cocos2dx.ini | 2 +- tools/tolua/cocos2dx_3d.ini | 2 +- tools/tolua/cocos2dx_cocosbuilder.ini | 2 +- tools/tolua/cocos2dx_cocosdenshion.ini | 2 +- tools/tolua/cocos2dx_controller.ini | 2 +- tools/tolua/cocos2dx_experimental.ini | 2 +- tools/tolua/cocos2dx_experimental_video.ini | 2 +- tools/tolua/cocos2dx_extension.ini | 2 +- tools/tolua/cocos2dx_physics.ini | 2 +- tools/tolua/cocos2dx_spine.ini | 2 +- tools/tolua/cocos2dx_studio.ini | 2 +- tools/tolua/cocos2dx_ui.ini | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tools/tolua/cocos2dx.ini b/tools/tolua/cocos2dx.ini index c84570383f..f2769ce810 100644 --- a/tools/tolua/cocos2dx.ini +++ b/tools/tolua/cocos2dx.ini @@ -11,7 +11,7 @@ android_headers = -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include android_flags = -D_SIZE_T_DEFINED_ clang_headers = -I%(clangllvmdir)s/lib/clang/3.3/include -clang_flags = -nostdinc -x c++ -std=c++11 -D__STRICT_ANSI__ +clang_flags = -nostdinc -x c++ -std=c++11 -U __SSE__ cocos_headers = -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/platform/android cocos_flags = -DANDROID diff --git a/tools/tolua/cocos2dx_3d.ini b/tools/tolua/cocos2dx_3d.ini index a043f994f9..e218da343a 100644 --- a/tools/tolua/cocos2dx_3d.ini +++ b/tools/tolua/cocos2dx_3d.ini @@ -11,7 +11,7 @@ android_headers = -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include android_flags = -D_SIZE_T_DEFINED_ clang_headers = -I%(clangllvmdir)s/lib/clang/3.3/include -clang_flags = -nostdinc -x c++ -std=c++11 +clang_flags = -nostdinc -x c++ -std=c++11 -U __SSE__ cocos_headers = -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/platform/android cocos_flags = -DANDROID diff --git a/tools/tolua/cocos2dx_cocosbuilder.ini b/tools/tolua/cocos2dx_cocosbuilder.ini index 40a7de384b..410fdeb5a5 100644 --- a/tools/tolua/cocos2dx_cocosbuilder.ini +++ b/tools/tolua/cocos2dx_cocosbuilder.ini @@ -11,7 +11,7 @@ android_headers = -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include android_flags = -D_SIZE_T_DEFINED_ clang_headers = -I%(clangllvmdir)s/lib/clang/3.3/include -clang_flags = -nostdinc -x c++ -std=c++11 +clang_flags = -nostdinc -x c++ -std=c++11 -U __SSE__ cocos_headers = -I%(cocosdir)s -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/editor-support -I%(cocosdir)s/cocos/platform/android diff --git a/tools/tolua/cocos2dx_cocosdenshion.ini b/tools/tolua/cocos2dx_cocosdenshion.ini index b032989626..6e337f3b84 100644 --- a/tools/tolua/cocos2dx_cocosdenshion.ini +++ b/tools/tolua/cocos2dx_cocosdenshion.ini @@ -11,7 +11,7 @@ android_headers = -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include android_flags = -D_SIZE_T_DEFINED_ clang_headers = -I%(clangllvmdir)s/lib/clang/3.3/include -clang_flags = -nostdinc -x c++ -std=c++11 +clang_flags = -nostdinc -x c++ -std=c++11 -U __SSE__ cocos_headers = -I%(cocosdir)s -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/platform/android diff --git a/tools/tolua/cocos2dx_controller.ini b/tools/tolua/cocos2dx_controller.ini index d80733b677..aed359d313 100644 --- a/tools/tolua/cocos2dx_controller.ini +++ b/tools/tolua/cocos2dx_controller.ini @@ -13,7 +13,7 @@ android_headers = -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include android_flags = -D_SIZE_T_DEFINED_ clang_headers = -I%(clangllvmdir)s/lib/clang/3.3/include -clang_flags = -nostdinc -x c++ -std=c++11 +clang_flags = -nostdinc -x c++ -std=c++11 -U __SSE__ cocos_headers = -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/base -I%(cocosdir)s/cocos/platform/android cocos_flags = -DANDROID diff --git a/tools/tolua/cocos2dx_experimental.ini b/tools/tolua/cocos2dx_experimental.ini index 97d890abf1..3ab59b7e59 100644 --- a/tools/tolua/cocos2dx_experimental.ini +++ b/tools/tolua/cocos2dx_experimental.ini @@ -11,7 +11,7 @@ android_headers = -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include android_flags = -D_SIZE_T_DEFINED_ clang_headers = -I%(clangllvmdir)s/lib/clang/3.3/include -clang_flags = -nostdinc -x c++ -std=c++11 +clang_flags = -nostdinc -x c++ -std=c++11 -U __SSE__ cocos_headers = -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/editor-support -I%(cocosdir)s/cocos/platform/android diff --git a/tools/tolua/cocos2dx_experimental_video.ini b/tools/tolua/cocos2dx_experimental_video.ini index e0c343b56e..3f92bf13d7 100644 --- a/tools/tolua/cocos2dx_experimental_video.ini +++ b/tools/tolua/cocos2dx_experimental_video.ini @@ -13,7 +13,7 @@ android_headers = -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include android_flags = -D_SIZE_T_DEFINED_ clang_headers = -I%(clangllvmdir)s/lib/clang/3.3/include -clang_flags = -nostdinc -x c++ -std=c++11 +clang_flags = -nostdinc -x c++ -std=c++11 -U __SSE__ cocos_headers = -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/editor-support -I%(cocosdir)s/cocos/platform/android diff --git a/tools/tolua/cocos2dx_extension.ini b/tools/tolua/cocos2dx_extension.ini index 3b474c792f..162ebddd02 100644 --- a/tools/tolua/cocos2dx_extension.ini +++ b/tools/tolua/cocos2dx_extension.ini @@ -11,7 +11,7 @@ android_headers = -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include android_flags = -D_SIZE_T_DEFINED_ clang_headers = -I%(clangllvmdir)s/lib/clang/3.3/include -clang_flags = -nostdinc -x c++ -std=c++11 +clang_flags = -nostdinc -x c++ -std=c++11 -U __SSE__ cocos_headers = -I%(cocosdir)s -I%(cocosdir)s/cocos/editor-support -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/platform/android diff --git a/tools/tolua/cocos2dx_physics.ini b/tools/tolua/cocos2dx_physics.ini index dca3e11f6f..c5042f1dde 100644 --- a/tools/tolua/cocos2dx_physics.ini +++ b/tools/tolua/cocos2dx_physics.ini @@ -13,7 +13,7 @@ android_headers = -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include android_flags = -D_SIZE_T_DEFINED_ clang_headers = -I%(clangllvmdir)s/lib/clang/3.3/include -clang_flags = -nostdinc -x c++ -std=c++11 +clang_flags = -nostdinc -x c++ -std=c++11 -U __SSE__ cocos_headers = -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/platform/android diff --git a/tools/tolua/cocos2dx_spine.ini b/tools/tolua/cocos2dx_spine.ini index 9ab910e8a2..b43c0ca4e3 100644 --- a/tools/tolua/cocos2dx_spine.ini +++ b/tools/tolua/cocos2dx_spine.ini @@ -11,7 +11,7 @@ android_headers = -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include android_flags = -D_SIZE_T_DEFINED_ clang_headers = -I%(clangllvmdir)s/lib/clang/3.3/include -clang_flags = -nostdinc -x c++ -std=c++11 +clang_flags = -nostdinc -x c++ -std=c++11 -U __SSE__ cocos_headers = -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/editor-support -I%(cocosdir)s/cocos/platform/android diff --git a/tools/tolua/cocos2dx_studio.ini b/tools/tolua/cocos2dx_studio.ini index a25e3b67b9..5aaf483758 100644 --- a/tools/tolua/cocos2dx_studio.ini +++ b/tools/tolua/cocos2dx_studio.ini @@ -14,7 +14,7 @@ android_headers = -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include android_flags = -D_SIZE_T_DEFINED_ clang_headers = -I%(clangllvmdir)s/lib/clang/3.3/include -clang_flags = -nostdinc -x c++ -std=c++11 +clang_flags = -nostdinc -x c++ -std=c++11 -U __SSE__ cocos_headers = -I%(cocosdir)s/external -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/editor-support -I%(cocosdir)s/cocos/platform/android diff --git a/tools/tolua/cocos2dx_ui.ini b/tools/tolua/cocos2dx_ui.ini index 1852a16b97..90258ae875 100644 --- a/tools/tolua/cocos2dx_ui.ini +++ b/tools/tolua/cocos2dx_ui.ini @@ -14,7 +14,7 @@ android_headers = -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include android_flags = -D_SIZE_T_DEFINED_ clang_headers = -I%(clangllvmdir)s/lib/clang/3.3/include -clang_flags = -nostdinc -x c++ -std=c++11 +clang_flags = -nostdinc -x c++ -std=c++11 -U __SSE__ cocos_headers = -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/editor-support -I%(cocosdir)s/cocos/platform/android