From aeb312c48af0e9a3e905f18a49a9b011f496eb1f Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Tue, 24 Jun 2014 10:04:19 +0100 Subject: [PATCH 01/14] Set handle to NULL in clUnload(). --- include/bx/cl.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/bx/cl.h b/include/bx/cl.h index c7b7bd7..62bfe89 100644 --- a/include/bx/cl.h +++ b/include/bx/cl.h @@ -888,6 +888,7 @@ namespace bx if (0 == ref) { dlclose(m_handle); + m_handle = NULL; } return ref; From 2ea546dba017e0230fbfda1eb76ac9ef422cd0dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Wed, 25 Jun 2014 21:16:07 -0700 Subject: [PATCH 02/14] NaCl unit test. --- 3rdparty/UnitTest++/src/Config.h | 29 ++++++++++++------- .../UnitTest++/src/Posix/SignalTranslator.h | 2 +- premake/unittest++.lua | 2 +- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/3rdparty/UnitTest++/src/Config.h b/3rdparty/UnitTest++/src/Config.h index 0ba21a0..5deeb27 100644 --- a/3rdparty/UnitTest++/src/Config.h +++ b/3rdparty/UnitTest++/src/Config.h @@ -4,23 +4,30 @@ // Standard defines documented here: http://predef.sourceforge.net #if defined(_MSC_VER) - #pragma warning(disable:4127) // conditional expression is constant - #pragma warning(disable:4702) // unreachable code - #pragma warning(disable:4722) // destructor never returns, potential memory leak +# pragma warning(disable:4127) // conditional expression is constant +# pragma warning(disable:4702) // unreachable code +# pragma warning(disable:4722) // destructor never returns, potential memory leak - #if (_MSC_VER == 1200) // VC6 - #pragma warning(disable:4786) - #pragma warning(disable:4290) - #endif +# if (_MSC_VER == 1200) // VC6 +# pragma warning(disable:4786) +# pragma warning(disable:4290) +# endif #endif -#if defined(unix) || defined(__unix__) || defined(__unix) || defined(linux) || \ - defined(__APPLE__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) - #define UNITTEST_POSIX +#if defined(unix) \ + || defined(__unix__) \ + || defined(__unix) \ + || defined(linux) \ + || defined(__APPLE__) \ + || defined(__NetBSD__) \ + || defined(__OpenBSD__) \ + || defined(__FreeBSD__) \ + || defined(__native_client__) +# define UNITTEST_POSIX #endif #if defined(__MINGW32__) - #define UNITTEST_MINGW +# define UNITTEST_MINGW #endif // by default, MemoryOutStream is implemented in terms of std::ostringstream, which can be expensive. diff --git a/3rdparty/UnitTest++/src/Posix/SignalTranslator.h b/3rdparty/UnitTest++/src/Posix/SignalTranslator.h index 1daf139..d313d02 100644 --- a/3rdparty/UnitTest++/src/Posix/SignalTranslator.h +++ b/3rdparty/UnitTest++/src/Posix/SignalTranslator.h @@ -26,7 +26,7 @@ private: // struct sigaction m_old_SIGALRM_action; }; -#if !defined (__GNUC__) +#if !defined(__GNUC__) && !defined(__clang__) #define UNITTEST_EXTENSION #else #define UNITTEST_EXTENSION __extension__ diff --git a/premake/unittest++.lua b/premake/unittest++.lua index f7fa4e3..b9a40a0 100644 --- a/premake/unittest++.lua +++ b/premake/unittest++.lua @@ -29,7 +29,7 @@ project "UnitTest++" "../3rdparty/UnitTest++/src/*.h", } - configuration { "linux or osx or android-*" } + configuration { "linux or osx or android-* or *nacl*" } files { "../3rdparty/UnitTest++/src/Posix/**.cpp", "../3rdparty/UnitTest++/src/Posix/**.h", From bb01733bfcfa0c4fbd94551ca55cd671992a302a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Thu, 26 Jun 2014 22:36:04 -0700 Subject: [PATCH 03/14] PNaCl vector intrisics WIP. --- .../UnitTest++/src/Posix/SignalTranslator.cpp | 11 ++++++ .../UnitTest++/src/Posix/SignalTranslator.h | 19 +++++++---- include/bx/float4_neon.h | 2 +- include/bx/float4_ni.h | 34 ++++++++++++++----- include/bx/float4_ref.h | 6 ++-- include/bx/float4_sse.h | 2 +- include/bx/float4_swizzle.inl | 2 +- include/bx/float4_t.h | 4 ++- include/bx/float4x4_t.h | 2 +- premake/premake4.lua | 2 ++ tests/float4_t.cpp | 2 +- tests/main.cpp | 21 +++++++++++- 12 files changed, 82 insertions(+), 25 deletions(-) diff --git a/3rdparty/UnitTest++/src/Posix/SignalTranslator.cpp b/3rdparty/UnitTest++/src/Posix/SignalTranslator.cpp index 3689c8c..d0415ad 100644 --- a/3rdparty/UnitTest++/src/Posix/SignalTranslator.cpp +++ b/3rdparty/UnitTest++/src/Posix/SignalTranslator.cpp @@ -2,6 +2,16 @@ namespace UnitTest { +#if defined(__native_client__) +SignalTranslator::SignalTranslator() +{ +} + +SignalTranslator::~SignalTranslator() +{ +} +#else + sigjmp_buf* SignalTranslator::s_jumpTarget = 0; namespace { @@ -42,5 +52,6 @@ SignalTranslator::~SignalTranslator() s_jumpTarget = m_oldJumpTarget; } +#endif // defined(__native_client__) } diff --git a/3rdparty/UnitTest++/src/Posix/SignalTranslator.h b/3rdparty/UnitTest++/src/Posix/SignalTranslator.h index d313d02..5de677e 100644 --- a/3rdparty/UnitTest++/src/Posix/SignalTranslator.h +++ b/3rdparty/UnitTest++/src/Posix/SignalTranslator.h @@ -12,6 +12,8 @@ public: SignalTranslator(); ~SignalTranslator(); +#if defined(__native_client__) +#else static sigjmp_buf* s_jumpTarget; private: @@ -24,18 +26,23 @@ private: struct sigaction m_old_SIGBUS_action; // struct sigaction m_old_SIGABRT_action; // struct sigaction m_old_SIGALRM_action; +#endif // defined(__native_client__) }; #if !defined(__GNUC__) && !defined(__clang__) - #define UNITTEST_EXTENSION +# define UNITTEST_EXTENSION #else - #define UNITTEST_EXTENSION __extension__ +# define UNITTEST_EXTENSION __extension__ #endif -#define UNITTEST_THROW_SIGNALS \ - UnitTest::SignalTranslator sig; \ - if (UNITTEST_EXTENSION sigsetjmp(*UnitTest::SignalTranslator::s_jumpTarget, 1) != 0) \ - throw ("Unhandled system exception"); +#if defined(__native_client__) +# define UNITTEST_THROW_SIGNALS +#else +# define UNITTEST_THROW_SIGNALS \ + UnitTest::SignalTranslator sig; \ + if (UNITTEST_EXTENSION sigsetjmp(*UnitTest::SignalTranslator::s_jumpTarget, 1) != 0) \ + throw ("Unhandled system exception"); +#endif // defined(__native_client__) } diff --git a/include/bx/float4_neon.h b/include/bx/float4_neon.h index 23fcca1..f8f67d1 100644 --- a/include/bx/float4_neon.h +++ b/include/bx/float4_neon.h @@ -1,5 +1,5 @@ /* - * Copyright 2010-2013 Branimir Karadzic. All rights reserved. + * Copyright 2010-2014 Branimir Karadzic. All rights reserved. * License: http://www.opensource.org/licenses/BSD-2-Clause */ diff --git a/include/bx/float4_ni.h b/include/bx/float4_ni.h index 10ec73d..4786e7f 100644 --- a/include/bx/float4_ni.h +++ b/include/bx/float4_ni.h @@ -1,5 +1,5 @@ /* - * Copyright 2010-2013 Branimir Karadzic. All rights reserved. + * Copyright 2010-2014 Branimir Karadzic. All rights reserved. * License: http://www.opensource.org/licenses/BSD-2-Clause */ @@ -42,6 +42,14 @@ namespace bx return result; } + BX_FLOAT4_INLINE float4_t float4_rcp_ni(float4_t _a) + { + const float4_t one = float4_splat(1.0f); + const float4_t result = float4_div(one, _a); + + return result; + } + BX_FLOAT4_INLINE float4_t float4_div_nr_ni(float4_t _a, float4_t _b) { const float4_t oneish = float4_isplat(0x3f800001); @@ -53,14 +61,6 @@ namespace bx return result; } - BX_FLOAT4_INLINE float4_t float4_rcp_ni(float4_t _a) - { - const float4_t one = float4_splat(1.0f); - const float4_t result = float4_div(one, _a); - - return result; - } - BX_FLOAT4_INLINE float4_t float4_orx_ni(float4_t _a) { const float4_t zwxy = float4_swiz_zwxy(_a); @@ -115,6 +115,22 @@ namespace bx return result; } + BX_FLOAT4_INLINE float4_t float4_min_ni(float4_t _a, float4_t _b) + { + const float4_t mask = float4_cmplt(_a, _b); + const float4_t result = float4_selb(mask, _a, _b); + + return result; + } + + BX_FLOAT4_INLINE float4_t float4_max_ni(float4_t _a, float4_t _b) + { + const float4_t mask = float4_cmpgt(_a, _b); + const float4_t result = float4_selb(mask, _a, _b); + + return result; + } + BX_FLOAT4_INLINE float4_t float4_abs_ni(float4_t _a) { const float4_t a_neg = float4_neg(_a); diff --git a/include/bx/float4_ref.h b/include/bx/float4_ref.h index fe54a0d..9b29f75 100644 --- a/include/bx/float4_ref.h +++ b/include/bx/float4_ref.h @@ -1,5 +1,5 @@ /* - * Copyright 2010-2013 Branimir Karadzic. All rights reserved. + * Copyright 2010-2014 Branimir Karadzic. All rights reserved. * License: http://www.opensource.org/licenses/BSD-2-Clause */ @@ -47,7 +47,7 @@ namespace bx uint32_t tmp = ( (_test.uxyzw[3]>>31)<<3) \ | ( (_test.uxyzw[2]>>31)<<2) \ | ( (_test.uxyzw[1]>>31)<<1) \ - | (_test.uxyzw[0]>>31) \ + | ( _test.uxyzw[0]>>31) \ ; \ return 0 != (tmp&(_mask) ); \ } \ @@ -57,7 +57,7 @@ namespace bx uint32_t tmp = ( (_test.uxyzw[3]>>31)<<3) \ | ( (_test.uxyzw[2]>>31)<<2) \ | ( (_test.uxyzw[1]>>31)<<1) \ - | (_test.uxyzw[0]>>31) \ + | ( _test.uxyzw[0]>>31) \ ; \ return (_mask) == (tmp&(_mask) ); \ } diff --git a/include/bx/float4_sse.h b/include/bx/float4_sse.h index c011e66..a9600a0 100644 --- a/include/bx/float4_sse.h +++ b/include/bx/float4_sse.h @@ -1,5 +1,5 @@ /* - * Copyright 2010-2013 Branimir Karadzic. All rights reserved. + * Copyright 2010-2014 Branimir Karadzic. All rights reserved. * License: http://www.opensource.org/licenses/BSD-2-Clause */ diff --git a/include/bx/float4_swizzle.inl b/include/bx/float4_swizzle.inl index cd9ddbd..73e0c88 100644 --- a/include/bx/float4_swizzle.inl +++ b/include/bx/float4_swizzle.inl @@ -1,5 +1,5 @@ /* - * Copyright 2010-2013 Branimir Karadzic. All rights reserved. + * Copyright 2010-2014 Branimir Karadzic. All rights reserved. * License: http://www.opensource.org/licenses/BSD-2-Clause */ diff --git a/include/bx/float4_t.h b/include/bx/float4_t.h index da3c370..545ec48 100644 --- a/include/bx/float4_t.h +++ b/include/bx/float4_t.h @@ -1,5 +1,5 @@ /* - * Copyright 2010-2013 Branimir Karadzic. All rights reserved. + * Copyright 2010-2014 Branimir Karadzic. All rights reserved. * License: http://www.opensource.org/licenses/BSD-2-Clause */ @@ -15,6 +15,8 @@ # include "float4_sse.h" #elif __ARM_NEON__ && !BX_COMPILER_CLANG # include "float4_neon.h" +#elif 0 // BX_COMPILER_CLANG +# include "float4_langext.h" #else # pragma message("************************************\nUsing SIMD reference implementation!\n************************************") # include "float4_ref.h" diff --git a/include/bx/float4x4_t.h b/include/bx/float4x4_t.h index e70f539..fa12925 100644 --- a/include/bx/float4x4_t.h +++ b/include/bx/float4x4_t.h @@ -1,5 +1,5 @@ /* - * Copyright 2010-2013 Branimir Karadzic. All rights reserved. + * Copyright 2010-2014 Branimir Karadzic. All rights reserved. * License: http://www.opensource.org/licenses/BSD-2-Clause */ diff --git a/premake/premake4.lua b/premake/premake4.lua index 7be9ad9..eeacf1c 100644 --- a/premake/premake4.lua +++ b/premake/premake4.lua @@ -90,3 +90,5 @@ project "bx.test" } configuration {} + + strip() diff --git a/tests/float4_t.cpp b/tests/float4_t.cpp index 9f113e2..b0a14a2 100644 --- a/tests/float4_t.cpp +++ b/tests/float4_t.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2010-2013 Branimir Karadzic. All rights reserved. + * Copyright 2010-2014 Branimir Karadzic. All rights reserved. * License: http://www.opensource.org/licenses/BSD-2-Clause */ diff --git a/tests/main.cpp b/tests/main.cpp index 84ca60d..b9b951e 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -38,12 +38,31 @@ int runAllTests() } #if BX_PLATFORM_ANDROID -#include +# include void ANativeActivity_onCreate(ANativeActivity*, void*, size_t) { exit(runAllTests() ); } +#elif BX_PLATFORM_NACL +# include +# include + +PP_EXPORT const void* PPP_GetInterface(const char* /*_name*/) +{ + return NULL; +} + +PP_EXPORT int32_t PPP_InitializeModule(PP_Module /*_module*/, PPB_GetInterface /*_interface*/) +{ + DBG("PPAPI version: %d", PPAPI_RELEASE); + runAllTests(); + return PP_ERROR_NOINTERFACE; +} + +PP_EXPORT void PPP_ShutdownModule() +{ +} #else int main() { From 77ff36c45935bb00d35ca54e5c1f76c6df261912 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Thu, 26 Jun 2014 22:37:28 -0700 Subject: [PATCH 04/14] PNaCl vector intrisics WIP. --- include/bx/float4_langext.h | 482 ++++++++++++++++++++++++++++++++++++ 1 file changed, 482 insertions(+) create mode 100644 include/bx/float4_langext.h diff --git a/include/bx/float4_langext.h b/include/bx/float4_langext.h new file mode 100644 index 0000000..b57d600 --- /dev/null +++ b/include/bx/float4_langext.h @@ -0,0 +1,482 @@ +/* + * Copyright 2010-2014 Branimir Karadzic. All rights reserved. + * License: http://www.opensource.org/licenses/BSD-2-Clause + */ + +#ifndef BX_FLOAT4_LANGEXT_H_HEADER_GUARD +#define BX_FLOAT4_LANGEXT_H_HEADER_GUARD + +#include + +namespace bx +{ + typedef union float4_t + { + float __attribute__((vector_size(16))) vf; + int32_t __attribute__((vector_size(16))) vi; + uint32_t __attribute__((vector_size(16))) vu; + float fxyzw[4]; + int32_t ixyzw[4]; + uint32_t uxyzw[4]; + + } float4_t; + +#define ELEMx 0 +#define ELEMy 1 +#define ELEMz 2 +#define ELEMw 3 +#define IMPLEMENT_SWIZZLE(_x, _y, _z, _w) \ + BX_FLOAT4_FORCE_INLINE float4_t float4_swiz_##_x##_y##_z##_w(float4_t _a) \ + { \ + float4_t result; \ + result.vf = __builtin_shufflevector(_a.vf, _a.vf, ELEM##_x, ELEM##_y, ELEM##_z, ELEM##_w); \ + return result; \ + } + +#include "float4_swizzle.inl" + +#undef IMPLEMENT_SWIZZLE +#undef ELEMw +#undef ELEMz +#undef ELEMy +#undef ELEMx + +#define IMPLEMENT_TEST(_xyzw, _mask) \ + BX_FLOAT4_FORCE_INLINE bool float4_test_any_##_xyzw(float4_t _test) \ + { \ + uint32_t tmp = ( (_test.uxyzw[3]>>31)<<3) \ + | ( (_test.uxyzw[2]>>31)<<2) \ + | ( (_test.uxyzw[1]>>31)<<1) \ + | ( _test.uxyzw[0]>>31) \ + ; \ + return 0 != (tmp&(_mask) ); \ + } \ + \ + BX_FLOAT4_FORCE_INLINE bool float4_test_all_##_xyzw(float4_t _test) \ + { \ + uint32_t tmp = ( (_test.uxyzw[3]>>31)<<3) \ + | ( (_test.uxyzw[2]>>31)<<2) \ + | ( (_test.uxyzw[1]>>31)<<1) \ + | ( _test.uxyzw[0]>>31) \ + ; \ + return (_mask) == (tmp&(_mask) ); \ + } + +IMPLEMENT_TEST(x , 0x1); +IMPLEMENT_TEST(y , 0x2); +IMPLEMENT_TEST(xy , 0x3); +IMPLEMENT_TEST(z , 0x4); +IMPLEMENT_TEST(xz , 0x5); +IMPLEMENT_TEST(yz , 0x6); +IMPLEMENT_TEST(xyz , 0x7); +IMPLEMENT_TEST(w , 0x8); +IMPLEMENT_TEST(xw , 0x9); +IMPLEMENT_TEST(yw , 0xa); +IMPLEMENT_TEST(xyw , 0xb); +IMPLEMENT_TEST(zw , 0xc); +IMPLEMENT_TEST(xzw , 0xd); +IMPLEMENT_TEST(yzw , 0xe); +IMPLEMENT_TEST(xyzw , 0xf); + +#undef IMPLEMENT_TEST + + BX_FLOAT4_FORCE_INLINE float4_t float4_shuf_xyAB(float4_t _a, float4_t _b) + { + float4_t result; + result.vf = __builtin_shufflevector(_a.vf, _b.vf, 0, 1, 4, 5); + return result; + } + + BX_FLOAT4_FORCE_INLINE float4_t float4_shuf_ABxy(float4_t _a, float4_t _b) + { + float4_t result; + result.vf = __builtin_shufflevector(_a.vf, _b.vf, 4, 5, 0, 1); + return result; + } + + BX_FLOAT4_FORCE_INLINE float4_t float4_shuf_CDzw(float4_t _a, float4_t _b) + { + float4_t result; + result.vf = __builtin_shufflevector(_a.vf, _b.vf, 5, 7, 2, 3); + return result; + } + + BX_FLOAT4_FORCE_INLINE float4_t float4_shuf_zwCD(float4_t _a, float4_t _b) + { + float4_t result; + result.vf = __builtin_shufflevector(_a.vf, _b.vf, 2, 3, 5, 7); + return result; + } + + BX_FLOAT4_FORCE_INLINE float4_t float4_shuf_xAyB(float4_t _a, float4_t _b) + { + float4_t result; + result.vf = __builtin_shufflevector(_a.vf, _b.vf, 0, 4, 1, 5); + return result; + } + + BX_FLOAT4_FORCE_INLINE float4_t float4_shuf_yBxA(float4_t _a, float4_t _b) + { + float4_t result; + result.vf = __builtin_shufflevector(_a.vf, _b.vf, 1, 5, 0, 4); + return result; + } + + BX_FLOAT4_FORCE_INLINE float4_t float4_shuf_zCwD(float4_t _a, float4_t _b) + { + float4_t result; + result.vf = __builtin_shufflevector(_a.vf, _b.vf, 2, 6, 3, 7); + return result; + } + + BX_FLOAT4_FORCE_INLINE float4_t float4_shuf_CzDw(float4_t _a, float4_t _b) + { + float4_t result; + result.vf = __builtin_shufflevector(_a.vf, _b.vf, 6, 2, 7, 3); + return result; + } + + BX_FLOAT4_FORCE_INLINE float4_t float4_shuf_xAzC(float4_t _a, float4_t _b) + { + float4_t result; + result.vf = __builtin_shufflevector(_a.vf, _b.vf, 0, 4, 2, 6); + return result; + } + + BX_FLOAT4_FORCE_INLINE float4_t float4_shuf_yBwD(float4_t _a, float4_t _b) + { + float4_t result; + result.vf = __builtin_shufflevector(_a.vf, _b.vf, 1, 5, 3, 7); + return result; + } + + BX_FLOAT4_FORCE_INLINE float float4_x(float4_t _a) + { + return _a.fxyzw[0]; + } + + BX_FLOAT4_FORCE_INLINE float float4_y(float4_t _a) + { + return _a.fxyzw[1]; + } + + BX_FLOAT4_FORCE_INLINE float float4_z(float4_t _a) + { + return _a.fxyzw[2]; + } + + BX_FLOAT4_FORCE_INLINE float float4_w(float4_t _a) + { + return _a.fxyzw[3]; + } + + BX_FLOAT4_FORCE_INLINE float4_t float4_ld(const void* _ptr) + { + const uint32_t* input = reinterpret_cast(_ptr); + float4_t result; + result.uxyzw[0] = input[0]; + result.uxyzw[1] = input[1]; + result.uxyzw[2] = input[2]; + result.uxyzw[3] = input[3]; + return result; + } + + BX_FLOAT4_FORCE_INLINE void float4_st(void* _ptr, float4_t _a) + { + uint32_t* result = reinterpret_cast(_ptr); + result[0] = _a.uxyzw[0]; + result[1] = _a.uxyzw[1]; + result[2] = _a.uxyzw[2]; + result[3] = _a.uxyzw[3]; + } + + BX_FLOAT4_FORCE_INLINE void float4_stx(void* _ptr, float4_t _a) + { + uint32_t* result = reinterpret_cast(_ptr); + result[0] = _a.uxyzw[0]; + } + + BX_FLOAT4_FORCE_INLINE void float4_stream(void* _ptr, float4_t _a) + { + uint32_t* result = reinterpret_cast(_ptr); + result[0] = _a.uxyzw[0]; + result[1] = _a.uxyzw[1]; + result[2] = _a.uxyzw[2]; + result[3] = _a.uxyzw[3]; + } + + BX_FLOAT4_FORCE_INLINE float4_t float4_ld(float _x, float _y, float _z, float _w) + { + float4_t result; + result.vf = { _x, _y, _z, _w }; + return result; + } + + BX_FLOAT4_FORCE_INLINE float4_t float4_ild(uint32_t _x, uint32_t _y, uint32_t _z, uint32_t _w) + { + float4_t result; + result.vu = { _x, _y, _z, _w }; + return result; + } + + BX_FLOAT4_FORCE_INLINE float4_t float4_splat(const void* _ptr) + { + const uint32_t val = *reinterpret_cast(_ptr); + float4_t result; + result.vu = { val, val, val, val }; + return result; + } + + BX_FLOAT4_FORCE_INLINE float4_t float4_splat(float _a) + { + return float4_ld(_a, _a, _a, _a); + } + + BX_FLOAT4_FORCE_INLINE float4_t float4_isplat(uint32_t _a) + { + return float4_ild(_a, _a, _a, _a); + } + + BX_FLOAT4_FORCE_INLINE float4_t float4_zero() + { + return float4_ild(0, 0, 0, 0); + } + + BX_FLOAT4_FORCE_INLINE float4_t float4_itof(float4_t _a) + { + float4_t result; + result.vf = __builtin_convertvector(_a.vi, float __attribute__((vector_size(16))) ); + return result; + } + + BX_FLOAT4_FORCE_INLINE float4_t float4_ftoi(float4_t _a) + { + float4_t result; + result.vi = __builtin_convertvector(_a.vf, int32_t __attribute__((vector_size(16))) ); + return result; + } + + BX_FLOAT4_FORCE_INLINE float4_t float4_round(float4_t _a) + { + const float4_t tmp = float4_ftoi(_a); + const float4_t result = float4_itof(tmp); + + return result; + } + + BX_FLOAT4_FORCE_INLINE float4_t float4_add(float4_t _a, float4_t _b) + { + float4_t result; + result.vf = _a.vf + _b.vf; + return result; + } + + BX_FLOAT4_FORCE_INLINE float4_t float4_sub(float4_t _a, float4_t _b) + { + float4_t result; + result.vf = _a.vf - _b.vf; + return result; + } + + BX_FLOAT4_FORCE_INLINE float4_t float4_mul(float4_t _a, float4_t _b) + { + float4_t result; + result.vf = _a.vf * _b.vf; + return result; + } + + BX_FLOAT4_FORCE_INLINE float4_t float4_div(float4_t _a, float4_t _b) + { + float4_t result; + result.vf = _a.vf / _b.vf; + return result; + } + +#if 0 + BX_FLOAT4_FORCE_INLINE float4_t float4_rcp_est(float4_t _a) + { + float4_t result; + const float4_t one = float4_splat(1.0f); + result.vf = one / _a.vf; + return result; + } +#endif // 0 + + BX_FLOAT4_FORCE_INLINE float4_t float4_sqrt(float4_t _a) + { + float4_t result; + result.vf[0] = sqrtf(_a.vf[0]); + result.vf[1] = sqrtf(_a.vf[1]); + result.vf[2] = sqrtf(_a.vf[2]); + result.vf[3] = sqrtf(_a.vf[3]); + return result; + } + + BX_FLOAT4_FORCE_INLINE float4_t float4_rsqrt_est(float4_t _a) + { + float4_t result; + result.vf[0] = 1.0f / sqrtf(_a.vf[0]); + result.vf[1] = 1.0f / sqrtf(_a.vf[1]); + result.vf[2] = 1.0f / sqrtf(_a.vf[2]); + result.vf[3] = 1.0f / sqrtf(_a.vf[3]); + return result; + } + + BX_FLOAT4_FORCE_INLINE float4_t float4_cmpeq(float4_t _a, float4_t _b) + { + float4_t result; + result.vi = _a.vf == _b.vf; + return result; + } + + BX_FLOAT4_FORCE_INLINE float4_t float4_cmplt(float4_t _a, float4_t _b) + { + float4_t result; + result.vi = _a.vf < _b.vf; + return result; + } + + BX_FLOAT4_FORCE_INLINE float4_t float4_cmple(float4_t _a, float4_t _b) + { + float4_t result; + result.vi = _a.vf <= _b.vf; + return result; + } + + BX_FLOAT4_FORCE_INLINE float4_t float4_cmpgt(float4_t _a, float4_t _b) + { + float4_t result; + result.vi = _a.vf > _b.vf; + return result; + } + + BX_FLOAT4_FORCE_INLINE float4_t float4_cmpge(float4_t _a, float4_t _b) + { + float4_t result; + result.vi = _a.vf >= _b.vf; + return result; + } + + BX_FLOAT4_FORCE_INLINE float4_t float4_and(float4_t _a, float4_t _b) + { + float4_t result; + result.vu = _a.vu & _b.vu; + return result; + } + + BX_FLOAT4_FORCE_INLINE float4_t float4_andc(float4_t _a, float4_t _b) + { + float4_t result; + result.vu = _a.vu & ~_b.vu; + return result; + } + + BX_FLOAT4_FORCE_INLINE float4_t float4_or(float4_t _a, float4_t _b) + { + float4_t result; + result.vu = _a.vu | _b.vu; + return result; + } + + BX_FLOAT4_FORCE_INLINE float4_t float4_xor(float4_t _a, float4_t _b) + { + float4_t result; + result.vu = _a.vu ^ _b.vu; + return result; + } + + BX_FLOAT4_FORCE_INLINE float4_t float4_sll(float4_t _a, int _count) + { + float4_t result; + const float4_t count = float4_isplat(_count); + result.vu = _a.vu << count.vi; + return result; + } + + BX_FLOAT4_FORCE_INLINE float4_t float4_srl(float4_t _a, int _count) + { + float4_t result; + const float4_t count = float4_isplat(_count); + result.vu = _a.vu >> count.vi; + return result; + } + + BX_FLOAT4_FORCE_INLINE float4_t float4_sra(float4_t _a, int _count) + { + float4_t result; + const float4_t count = float4_isplat(_count); + result.vi = _a.vi >> count.vi; + return result; + } + + BX_FLOAT4_FORCE_INLINE float4_t float4_icmpeq(float4_t _a, float4_t _b) + { + float4_t result; + result.vi = _a.vi == _b.vi; + return result; + } + + BX_FLOAT4_FORCE_INLINE float4_t float4_icmplt(float4_t _a, float4_t _b) + { + float4_t result; + result.vi = _a.vi < _b.vi; + return result; + } + + BX_FLOAT4_FORCE_INLINE float4_t float4_icmpgt(float4_t _a, float4_t _b) + { + float4_t result; + result.vi = _a.vi > _b.vi; + return result; + } + + BX_FLOAT4_FORCE_INLINE float4_t float4_iadd(float4_t _a, float4_t _b) + { + float4_t result; + result.vi = _a.vi + _b.vi; + return result; + } + + BX_FLOAT4_FORCE_INLINE float4_t float4_isub(float4_t _a, float4_t _b) + { + float4_t result; + result.vi = _a.vi - _b.vi; + return result; + } + +} // namespace bx + +#define float4_rcp float4_rcp_ni +#define float4_orx float4_orx_ni +#define float4_orc float4_orc_ni +#define float4_neg float4_neg_ni +#define float4_madd float4_madd_ni +#define float4_nmsub float4_nmsub_ni +#define float4_div_nr float4_div_nr_ni +#define float4_selb float4_selb_ni +#define float4_sels float4_sels_ni +#define float4_not float4_not_ni +#define float4_abs float4_abs_ni +#define float4_clamp float4_clamp_ni +#define float4_lerp float4_lerp_ni +#define float4_rcp_est float4_rcp_ni +#define float4_rsqrt float4_rsqrt_ni +#define float4_rsqrt_nr float4_rsqrt_nr_ni +#define float4_rsqrt_carmack float4_rsqrt_carmack_ni +#define float4_sqrt_nr float4_sqrt_nr_ni +#define float4_log2 float4_log2_ni +#define float4_exp2 float4_exp2_ni +#define float4_pow float4_pow_ni +#define float4_cross3 float4_cross3_ni +#define float4_normalize3 float4_normalize3_ni +#define float4_dot3 float4_dot3_ni +#define float4_dot float4_dot_ni +#define float4_ceil float4_ceil_ni +#define float4_floor float4_floor_ni +#define float4_min float4_min_ni +#define float4_max float4_max_ni +#define float4_imin float4_imin_ni +#define float4_imax float4_imax_ni +#include "float4_ni.h" + +#endif // BX_FLOAT4_LANGEXT_H_HEADER_GUARD From ed0ae5145cf8da8ff2202886a0cb116c57d28596 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Fri, 27 Jun 2014 21:46:28 -0700 Subject: [PATCH 05/14] Added fmin/max3. --- include/bx/fpumath.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/bx/fpumath.h b/include/bx/fpumath.h index f52bbe5..39c7e96 100644 --- a/include/bx/fpumath.h +++ b/include/bx/fpumath.h @@ -34,6 +34,16 @@ namespace bx return _a > _b ? _a : _b; } + inline float fmin3(float _a, float _b, float _c) + { + return fmin(_a, fmin(_b, _c) ); + } + + inline float fmax3(float _a, float _b, float _c) + { + return fmax(_a, fmax(_b, _c) ); + } + inline float fclamp(float _a, float _min, float _max) { return fmin(fmax(_a, _min), _max); From d22d1314e0b0942c9962a8685215e48a903d95ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Sat, 28 Jun 2014 17:21:35 -0700 Subject: [PATCH 06/14] Added color conversion routines to fpumath. --- include/bx/fpumath.h | 72 ++++++++++++++++++++++++++++++++++++++++--- include/bx/uint32_t.h | 8 +++++ 2 files changed, 76 insertions(+), 4 deletions(-) diff --git a/include/bx/fpumath.h b/include/bx/fpumath.h index 39c7e96..54413fa 100644 --- a/include/bx/fpumath.h +++ b/include/bx/fpumath.h @@ -64,6 +64,26 @@ namespace bx return _a < 0.0f ? -1.0f : 1.0f; } + inline float fstep(float _edge, float _a) + { + return _a < _edge ? 0.0f : 1.0f; + } + + inline float fabsolute(float _a) + { + return fabsf(_a); + } + + inline float fsqrt(float _a) + { + return sqrtf(_a); + } + + inline float ffract(float _a) + { + return _a - floorf(_a); + } + inline void vec3Move(float* __restrict _result, const float* __restrict _a) { _result[0] = _a[0]; @@ -73,9 +93,9 @@ namespace bx inline void vec3Abs(float* __restrict _result, const float* __restrict _a) { - _result[0] = fabsf(_a[0]); - _result[1] = fabsf(_a[1]); - _result[2] = fabsf(_a[2]); + _result[0] = fabsolute(_a[0]); + _result[1] = fabsolute(_a[1]); + _result[2] = fabsolute(_a[2]); } inline void vec3Neg(float* __restrict _result, const float* __restrict _a) @@ -127,7 +147,7 @@ namespace bx inline float vec3Length(const float* _a) { - return sqrtf(vec3Dot(_a, _a) ); + return fsqrt(vec3Dot(_a, _a) ); } inline float vec3Norm(float* __restrict _result, const float* __restrict _a) @@ -577,6 +597,50 @@ namespace bx _result[2] = normal[2]; _result[3] = -vec3Dot(normal, _va); } + + inline void rgbToHsv(float _hsv[3], const float _rgb[3]) + { + const float rr = _rgb[0]; + const float gg = _rgb[1]; + const float bb = _rgb[2]; + + const float s0 = fstep(bb, gg); + + const float px = flerp(bb, gg, s0); + const float py = flerp(gg, bb, s0); + const float pz = flerp(-1.0f, 0.0f, s0); + const float pw = flerp(2.0f/3.0f, -1.0f/3.0f, s0); + + const float s1 = fstep(px, rr); + + const float qx = flerp(px, rr, s1); + const float qy = py; + const float qz = flerp(pw, pz, s1); + const float qw = flerp(rr, px, s1); + + const float dd = qx - fmin(qw, qy); + const float ee = 1.0e-10f; + + _hsv[0] = fabsolute(qz + (qw - qy) / (6.0f * dd + ee) ); + _hsv[1] = dd / (qx + ee); + _hsv[2] = qx; + } + + inline void hsvToRgb(float _rgb[3], const float _hsv[3]) + { + const float hh = _hsv[0]; + const float ss = _hsv[1]; + const float vv = _hsv[2]; + + const float px = fabsolute(ffract(hh + 1.0f ) * 6.0f - 3.0f); + const float py = fabsolute(ffract(hh + 2.0f/3.0f) * 6.0f - 3.0f); + const float pz = fabsolute(ffract(hh + 1.0f/3.0f) * 6.0f - 3.0f); + + _rgb[0] = vv * flerp(1.0f, fsaturate(px - 1.0f), ss); + _rgb[1] = vv * flerp(1.0f, fsaturate(py - 1.0f), ss); + _rgb[2] = vv * flerp(1.0f, fsaturate(pz - 1.0f), ss); + } + } // namespace bx #endif // BX_FPU_MATH_H_HEADER_GUARD diff --git a/include/bx/uint32_t.h b/include/bx/uint32_t.h index f06d1b0..f4a65b4 100644 --- a/include/bx/uint32_t.h +++ b/include/bx/uint32_t.h @@ -263,6 +263,14 @@ namespace bx return _a > _b ? _a : _b; } + inline uint32_t uint32_clamp(uint32_t _a, uint32_t _min, uint32_t _max) + { + const uint32_t tmp = uint32_max(_a, _min); + const uint32_t result = uint32_min(tmp, _max); + + return result; + } + inline uint32_t uint32_incwrap(uint32_t _val, uint32_t _min, uint32_t _max) { const uint32_t inc = uint32_inc(_val); From bf241993a41b264c6c2b277087e7295783607212 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Sun, 29 Jun 2014 19:45:56 -0700 Subject: [PATCH 07/14] Added chdir and pwd. --- include/bx/os.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/include/bx/os.h b/include/bx/os.h index 5c4a694..4818f12 100644 --- a/include/bx/os.h +++ b/include/bx/os.h @@ -39,6 +39,12 @@ # endif // BX_PLATFORM_ANDROID #endif // BX_PLATFORM_ +#if BX_COMPILER_MSVC +# include // _getcwd +#else +# include // getcwd +#endif // BX_COMPILER_MSVC + namespace bx { inline void sleep(uint32_t _ms) @@ -134,6 +140,24 @@ namespace bx #endif // BX_PLATFORM_ } + inline int chdir(const char* _path) + { +#if BX_COMPILER_MSVC + return ::_chdir(_path); +#else + return ::chdir(_path); +#endif // BX_COMPILER_ + } + + inline char* pwd(char* _buffer, uint32_t _size) + { +#if BX_COMPILER_MSVC + return ::_getcwd(_buffer, (int)_size); +#else + return ::getcwd(_buffer, _size); +#endif // BX_COMPILER_ + } + } // namespace bx #endif // BX_OS_H_HEADER_GUARD From f1984dea7ce79d79886d850f762677bc14f08ce9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Mon, 30 Jun 2014 20:54:38 -0700 Subject: [PATCH 08/14] Added command line tokenizer. --- include/bx/tokenizecmd.h | 146 +++++++++++++++++++++++++++++++++++++++ tests/tokenizecmd.cpp | 72 +++++++++++++++++++ 2 files changed, 218 insertions(+) create mode 100644 include/bx/tokenizecmd.h create mode 100644 tests/tokenizecmd.cpp diff --git a/include/bx/tokenizecmd.h b/include/bx/tokenizecmd.h new file mode 100644 index 0000000..2e981c1 --- /dev/null +++ b/include/bx/tokenizecmd.h @@ -0,0 +1,146 @@ +/* + * Copyright 2012-2014 Branimir Karadzic. All rights reserved. + * License: http://www.opensource.org/licenses/BSD-2-Clause + */ + +#ifndef BX_TOKENIZE_CMD_H_HEADER_GUARD +#define BX_TOKENIZE_CMD_H_HEADER_GUARD + +#include +#include +#include + +namespace bx +{ + // Reference: + // http://msdn.microsoft.com/en-us/library/a1y7w461.aspx + static inline const char* tokenizeCommandLine(const char* _commandLine, char* _buffer, uint32_t& _bufferSize, int& _argc, char* _argv[], int _maxArgvs, char _term = '\0') + { + int argc = 0; + const char* curr = _commandLine; + char* currOut = _buffer; + char term = ' '; + bool sub = false; + + enum ParserState + { + SkipWhitespace, + SetTerm, + Copy, + Escape, + End, + }; + + ParserState state = SkipWhitespace; + + while ('\0' != *curr + && _term != *curr + && argc < _maxArgvs) + { + switch (state) + { + case SkipWhitespace: + for (; isspace(*curr); ++curr) {}; // skip whitespace + state = SetTerm; + break; + + case SetTerm: + if ('"' == *curr) + { + term = '"'; + ++curr; // skip begining quote + } + else + { + term = ' '; + } + + _argv[argc] = currOut; + ++argc; + + state = Copy; + break; + + case Copy: + if ('\\' == *curr) + { + state = Escape; + } + else if ('"' == *curr + && '"' != term) + { + sub = !sub; + } + else if (isspace(*curr) && !sub) + { + state = End; + } + else if (term != *curr || sub) + { + *currOut = *curr; + ++currOut; + } + else + { + state = End; + } + ++curr; + break; + + case Escape: + { + const char* start = --curr; + for (; '\\' == *curr; ++curr) {}; + + if ('"' != *curr) + { + int count = (int)(curr-start); + + curr = start; + for (int ii = 0; ii < count; ++ii) + { + *currOut = *curr; + ++currOut; + ++curr; + } + } + else + { + curr = start+1; + *currOut = *curr; + ++currOut; + ++curr; + } + } + state = Copy; + break; + + case End: + *currOut = '\0'; + ++currOut; + state = SkipWhitespace; + break; + } + } + + *currOut = '\0'; + if (0 < argc + && '\0' == _argv[argc-1][0]) + { + --argc; + } + + _bufferSize = (uint32_t)(currOut - _buffer); + _argc = argc; + + if ('\0' != *curr) + { + ++curr; + } + + return curr; + } + +} // namespace bx + +#endif // TOKENIZE_CMD_H_HEADER_GUARD diff --git a/tests/tokenizecmd.cpp b/tests/tokenizecmd.cpp new file mode 100644 index 0000000..1e19ce1 --- /dev/null +++ b/tests/tokenizecmd.cpp @@ -0,0 +1,72 @@ +/* + * Copyright 2012-2014 Branimir Karadzic. All rights reserved. + * License: http://www.opensource.org/licenses/BSD-2-Clause + */ + +#include "test.h" +#include +#include + +TEST(tokenizeCommandLine) +{ + const char* input[] = + { + " ", + "\\", +// "\"a b c\" d e", + "\"ab\\\"c\" \"\\\\\" d", + "a\\\\\\b d\"e f\"g h", + "a\\\\\\\"b c d", + "a\\\\\\\\\"b c\" d e", + }; + + const int expected_argc[] = + { + 0, + 0, +// 3, + 3, + 3, + 3, + 3 + }; + + const char* expected_results[] = + { + "a b c", "d", "e", + "ab\"c", "\\", "d", + "a\\\\\\b", "de fg", "h", + "a\\\"b", "c", "d", + "a\\\\b c", "d", "e", + }; + + const char** expected_argv[] = + { + NULL, + NULL, +// &expected_results[0], + &expected_results[3], + &expected_results[6], + &expected_results[9], + &expected_results[12], + }; + + for (uint32_t ii = 0; ii < BX_COUNTOF(exptected_argv); ++ii) + { + printf("x\n"); + char commandLine[1024]; + uint32_t size = BX_COUNTOF(commandLine); + char* argv[50]; + int32_t argc; + bx::tokenizeCommandLine(input[ii], commandLine, size, argc, argv, BX_COUNTOF(argv) ); + printf("\n%d (%d): %s %s\n", ii, argc, input[ii], expected_argc[ii] == argc ? "" : "FAILED!"); + for (uint32_t jj = 0; jj < argc; ++jj) + { + printf("\t%d: {%s} %s\n" + , jj + , argv[jj] + , jj < argc ? (0==strcmp(argv[jj], expected_argv[ii][jj]) ? "" : "FAILED!") : "FAILED!" + ); + } + } +} From 1016c86964e8d96a4848ebb344f49d0fc5053dce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Mon, 30 Jun 2014 20:55:12 -0700 Subject: [PATCH 09/14] Disabled tokenizer test. --- tests/tokenizecmd.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/tokenizecmd.cpp b/tests/tokenizecmd.cpp index 1e19ce1..02eb0e6 100644 --- a/tests/tokenizecmd.cpp +++ b/tests/tokenizecmd.cpp @@ -9,6 +9,7 @@ TEST(tokenizeCommandLine) { +#if 0 const char* input[] = { " ", @@ -69,4 +70,5 @@ TEST(tokenizeCommandLine) ); } } +#endif // 0 } From 191d5ae9be990e4ec7b8906001444cbe0a2abb24 Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Tue, 1 Jul 2014 20:44:31 +0100 Subject: [PATCH 10/14] Added include for alloca.h on OS X. --- include/compat/osx/malloc.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/compat/osx/malloc.h b/include/compat/osx/malloc.h index 448e0a8..8e725c5 100644 --- a/include/compat/osx/malloc.h +++ b/include/compat/osx/malloc.h @@ -1 +1,2 @@ #include +#include From 9277c9b6b3f8308f32b9a08047047e176f279676 Mon Sep 17 00:00:00 2001 From: lye Date: Wed, 9 Jul 2014 20:34:24 -0700 Subject: [PATCH 11/14] Add FreeBSD support to the codebase. The FreeBSD-specific compatibility changes are invoked when the __FreeBSD__ macro is defined, which is the default for (I think all?) toolchains on FreeBSD. This turns on the BX_PLATFORM_FREEBSD macro which can be used for further specializations. FreeBSD is a mix between Linux, NaCl and OSX, with some extra cavaets that have been worked around: * malloc.h is deprecated; FreeBSD uses stdlib.h instead. * alloca.h doesn't exist; it's also in stdlib.h. --- include/bx/allocator.h | 6 +++++- include/bx/macros.h | 1 + include/bx/os.h | 7 ++++--- include/bx/platform.h | 9 ++++++++- include/bx/readerwriter.h | 2 +- include/bx/string.h | 4 +++- include/bx/timer.h | 2 +- 7 files changed, 23 insertions(+), 8 deletions(-) diff --git a/include/bx/allocator.h b/include/bx/allocator.h index ba874e0..5af503f 100644 --- a/include/bx/allocator.h +++ b/include/bx/allocator.h @@ -12,7 +12,11 @@ #include #if BX_CONFIG_ALLOCATOR_CRT -# include +# if BX_PLATFORM_FREEBSD +# include +# else +# include +# endif #endif // BX_CONFIG_ALLOCATOR_CRT #if BX_CONFIG_ALLOCATOR_DEBUG diff --git a/include/bx/macros.h b/include/bx/macros.h index f3dedb3..03c8baa 100644 --- a/include/bx/macros.h +++ b/include/bx/macros.h @@ -162,6 +162,7 @@ |BX_PLATFORM_OSX \ |BX_PLATFORM_QNX \ |BX_PLATFORM_WINDOWS \ + |BX_PLATFORM_FREEBSD \ ) #endif // BX_CONFIG_CRT_FILE_READER_WRITER diff --git a/include/bx/os.h b/include/bx/os.h index 5c4a694..bd0134e 100644 --- a/include/bx/os.h +++ b/include/bx/os.h @@ -15,10 +15,11 @@ || BX_PLATFORM_LINUX \ || BX_PLATFORM_OSX \ || BX_PLATFORM_IOS \ - || BX_PLATFORM_EMSCRIPTEN + || BX_PLATFORM_EMSCRIPTEN \ + || BX_PLATFORM_FREEBSD # include // sched_yield -# if BX_PLATFORM_IOS || BX_PLATFORM_OSX || BX_PLATFORM_NACL +# if BX_PLATFORM_IOS || BX_PLATFORM_OSX || BX_PLATFORM_NACL || BX_PLATFORM_FREEBSD # include // mach_port_t # endif // BX_PLATFORM_IOS || BX_PLATFORM_OSX || BX_PLATFORM_NACL @@ -71,7 +72,7 @@ namespace bx return (pid_t)::syscall(SYS_gettid); #elif BX_PLATFORM_IOS || BX_PLATFORM_OSX return (mach_port_t)::pthread_mach_thread_np(pthread_self() ); -#elif BX_PLATFORM_NACL +#elif BX_PLATFORM_NACL || BX_PLATFORM_FREEBSD // Casting __nc_basic_thread_data*... need better way to do this. return *(uint32_t*)::pthread_self(); #else diff --git a/include/bx/platform.h b/include/bx/platform.h index 81833f4..c9166ae 100644 --- a/include/bx/platform.h +++ b/include/bx/platform.h @@ -19,6 +19,7 @@ #define BX_PLATFORM_QNX 0 #define BX_PLATFORM_WINDOWS 0 #define BX_PLATFORM_XBOX360 0 +#define BX_PLATFORM_FREEBSD 0 #define BX_CPU_ARM 0 #define BX_CPU_JIT 0 @@ -83,6 +84,9 @@ #elif defined(__QNX__) # undef BX_PLATFORM_QNX # define BX_PLATFORM_QNX 1 +#elif defined(__FreeBSD__) +# undef BX_PLATFORM_FREEBSD +# define BX_PLATFORM_FREEBSD 1 #else # error "BX_PLATFORM_* is not defined!" #endif // @@ -93,7 +97,8 @@ || BX_PLATFORM_LINUX \ || BX_PLATFORM_NACL \ || BX_PLATFORM_OSX \ - || BX_PLATFORM_QNX) + || BX_PLATFORM_QNX \ + || BX_PLATFORM_FREEBSD ) // http://sourceforge.net/apps/mediawiki/predef/index.php?title=Architectures #if defined(__arm__) @@ -160,6 +165,8 @@ # define BX_PLATFORM_NAME "OSX" #elif BX_PLATFORM_QNX # define BX_PLATFORM_NAME "QNX" +#elif BX_PLATFORM_FREEBSD +# define BX_PLATFORM_NAME "FreeBSD" #elif BX_PLATFORM_WINDOWS # define BX_PLATFORM_NAME "Windows" #endif // BX_PLATFORM_ diff --git a/include/bx/readerwriter.h b/include/bx/readerwriter.h index 7419783..ccc84a0 100644 --- a/include/bx/readerwriter.h +++ b/include/bx/readerwriter.h @@ -15,7 +15,7 @@ #if BX_COMPILER_MSVC # define fseeko64 _fseeki64 # define ftello64 _ftelli64 -#elif BX_PLATFORM_ANDROID|BX_PLATFORM_IOS|BX_PLATFORM_OSX|BX_PLATFORM_QNX +#elif BX_PLATFORM_ANDROID|BX_PLATFORM_IOS|BX_PLATFORM_OSX|BX_PLATFORM_QNX|BX_PLATFORM_FREEBSD # define fseeko64 fseeko # define ftello64 ftello #endif // BX_ diff --git a/include/bx/string.h b/include/bx/string.h index 044cd99..a81219f 100644 --- a/include/bx/string.h +++ b/include/bx/string.h @@ -7,7 +7,9 @@ #define BX_PRINTF_H_HEADER_GUARD #include "bx.h" -#include +#if !BX_PLATFORM_FREEBSD +# include +#endif #include // tolower #include // va_list #include // vsnprintf, vsnwprintf diff --git a/include/bx/timer.h b/include/bx/timer.h index ae52038..71df01c 100644 --- a/include/bx/timer.h +++ b/include/bx/timer.h @@ -12,7 +12,7 @@ # include // clock, clock_gettime #elif BX_PLATFORM_EMSCRIPTEN # include -#elif BX_PLATFORM_NACL || BX_PLATFORM_LINUX || BX_PLATFORM_OSX || BX_PLATFORM_IOS || BX_PLATFORM_QNX +#elif BX_PLATFORM_NACL || BX_PLATFORM_LINUX || BX_PLATFORM_OSX || BX_PLATFORM_IOS || BX_PLATFORM_QNX || BX_PLATFORM_FREEBSD # include // gettimeofday #elif BX_PLATFORM_WINDOWS # include From 0b7c335824a2fb17c119c687023aa63f939cf561 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Wed, 9 Jul 2014 21:40:32 -0700 Subject: [PATCH 12/14] Cleanup. --- include/bx/allocator.h | 6 +----- include/bx/macros.h | 2 +- include/bx/os.h | 16 ++++++++-------- include/bx/platform.h | 12 +++++++----- include/bx/readerwriter.h | 2 +- include/bx/string.h | 4 +--- include/bx/timer.h | 2 +- include/compat/freebsd/alloca.h | 1 + include/compat/freebsd/malloc.h | 1 + 9 files changed, 22 insertions(+), 24 deletions(-) create mode 100644 include/compat/freebsd/alloca.h create mode 100644 include/compat/freebsd/malloc.h diff --git a/include/bx/allocator.h b/include/bx/allocator.h index 5af503f..ba874e0 100644 --- a/include/bx/allocator.h +++ b/include/bx/allocator.h @@ -12,11 +12,7 @@ #include #if BX_CONFIG_ALLOCATOR_CRT -# if BX_PLATFORM_FREEBSD -# include -# else -# include -# endif +# include #endif // BX_CONFIG_ALLOCATOR_CRT #if BX_CONFIG_ALLOCATOR_DEBUG diff --git a/include/bx/macros.h b/include/bx/macros.h index 03c8baa..bc900bd 100644 --- a/include/bx/macros.h +++ b/include/bx/macros.h @@ -157,12 +157,12 @@ #ifndef BX_CONFIG_CRT_FILE_READER_WRITER # define BX_CONFIG_CRT_FILE_READER_WRITER (0 \ |BX_PLATFORM_ANDROID \ + |BX_PLATFORM_FREEBSD \ |BX_PLATFORM_IOS \ |BX_PLATFORM_LINUX \ |BX_PLATFORM_OSX \ |BX_PLATFORM_QNX \ |BX_PLATFORM_WINDOWS \ - |BX_PLATFORM_FREEBSD \ ) #endif // BX_CONFIG_CRT_FILE_READER_WRITER diff --git a/include/bx/os.h b/include/bx/os.h index 9180802..9f412c7 100644 --- a/include/bx/os.h +++ b/include/bx/os.h @@ -10,16 +10,16 @@ #if BX_PLATFORM_WINDOWS # include -#elif BX_PLATFORM_NACL \ - || BX_PLATFORM_ANDROID \ - || BX_PLATFORM_LINUX \ - || BX_PLATFORM_OSX \ - || BX_PLATFORM_IOS \ +#elif BX_PLATFORM_ANDROID \ || BX_PLATFORM_EMSCRIPTEN \ - || BX_PLATFORM_FREEBSD + || BX_PLATFORM_FREEBSD \ + || BX_PLATFORM_IOS \ + || BX_PLATFORM_LINUX \ + || BX_PLATFORM_NACL \ + || BX_PLATFORM_OSX # include // sched_yield -# if BX_PLATFORM_IOS || BX_PLATFORM_OSX || BX_PLATFORM_NACL || BX_PLATFORM_FREEBSD +# if BX_PLATFORM_FREEBSD || BX_PLATFORM_IOS || BX_PLATFORM_NACL || BX_PLATFORM_OSX # include // mach_port_t # endif // BX_PLATFORM_IOS || BX_PLATFORM_OSX || BX_PLATFORM_NACL @@ -78,7 +78,7 @@ namespace bx return (pid_t)::syscall(SYS_gettid); #elif BX_PLATFORM_IOS || BX_PLATFORM_OSX return (mach_port_t)::pthread_mach_thread_np(pthread_self() ); -#elif BX_PLATFORM_NACL || BX_PLATFORM_FREEBSD +#elif BX_PLATFORM_FREEBSD || BX_PLATFORM_NACL // Casting __nc_basic_thread_data*... need better way to do this. return *(uint32_t*)::pthread_self(); #else diff --git a/include/bx/platform.h b/include/bx/platform.h index c9166ae..a2eb196 100644 --- a/include/bx/platform.h +++ b/include/bx/platform.h @@ -12,6 +12,7 @@ #define BX_PLATFORM_ANDROID 0 #define BX_PLATFORM_EMSCRIPTEN 0 +#define BX_PLATFORM_FREEBSD 0 #define BX_PLATFORM_IOS 0 #define BX_PLATFORM_LINUX 0 #define BX_PLATFORM_NACL 0 @@ -19,7 +20,6 @@ #define BX_PLATFORM_QNX 0 #define BX_PLATFORM_WINDOWS 0 #define BX_PLATFORM_XBOX360 0 -#define BX_PLATFORM_FREEBSD 0 #define BX_CPU_ARM 0 #define BX_CPU_JIT 0 @@ -91,14 +91,16 @@ # error "BX_PLATFORM_* is not defined!" #endif // -#define BX_PLATFORM_POSIX (BX_PLATFORM_ANDROID \ +#define BX_PLATFORM_POSIX (0 \ + || BX_PLATFORM_ANDROID \ || BX_PLATFORM_EMSCRIPTEN \ + || BX_PLATFORM_FREEBSD \ || BX_PLATFORM_IOS \ || BX_PLATFORM_LINUX \ || BX_PLATFORM_NACL \ || BX_PLATFORM_OSX \ || BX_PLATFORM_QNX \ - || BX_PLATFORM_FREEBSD ) + ) // http://sourceforge.net/apps/mediawiki/predef/index.php?title=Architectures #if defined(__arm__) @@ -155,6 +157,8 @@ # define BX_PLATFORM_NAME "Android" #elif BX_PLATFORM_EMSCRIPTEN # define BX_PLATFORM_NAME "asm.js" +#elif BX_PLATFORM_FREEBSD +# define BX_PLATFORM_NAME "FreeBSD" #elif BX_PLATFORM_IOS # define BX_PLATFORM_NAME "iOS" #elif BX_PLATFORM_LINUX @@ -165,8 +169,6 @@ # define BX_PLATFORM_NAME "OSX" #elif BX_PLATFORM_QNX # define BX_PLATFORM_NAME "QNX" -#elif BX_PLATFORM_FREEBSD -# define BX_PLATFORM_NAME "FreeBSD" #elif BX_PLATFORM_WINDOWS # define BX_PLATFORM_NAME "Windows" #endif // BX_PLATFORM_ diff --git a/include/bx/readerwriter.h b/include/bx/readerwriter.h index ccc84a0..c777661 100644 --- a/include/bx/readerwriter.h +++ b/include/bx/readerwriter.h @@ -15,7 +15,7 @@ #if BX_COMPILER_MSVC # define fseeko64 _fseeki64 # define ftello64 _ftelli64 -#elif BX_PLATFORM_ANDROID|BX_PLATFORM_IOS|BX_PLATFORM_OSX|BX_PLATFORM_QNX|BX_PLATFORM_FREEBSD +#elif BX_PLATFORM_ANDROID || BX_PLATFORM_FREEBSD || BX_PLATFORM_IOS || BX_PLATFORM_OSX || BX_PLATFORM_QNX # define fseeko64 fseeko # define ftello64 ftello #endif // BX_ diff --git a/include/bx/string.h b/include/bx/string.h index a81219f..044cd99 100644 --- a/include/bx/string.h +++ b/include/bx/string.h @@ -7,9 +7,7 @@ #define BX_PRINTF_H_HEADER_GUARD #include "bx.h" -#if !BX_PLATFORM_FREEBSD -# include -#endif +#include #include // tolower #include // va_list #include // vsnprintf, vsnwprintf diff --git a/include/bx/timer.h b/include/bx/timer.h index 71df01c..71603a7 100644 --- a/include/bx/timer.h +++ b/include/bx/timer.h @@ -12,7 +12,7 @@ # include // clock, clock_gettime #elif BX_PLATFORM_EMSCRIPTEN # include -#elif BX_PLATFORM_NACL || BX_PLATFORM_LINUX || BX_PLATFORM_OSX || BX_PLATFORM_IOS || BX_PLATFORM_QNX || BX_PLATFORM_FREEBSD +#elif BX_PLATFORM_FREEBSD || BX_PLATFORM_LINUX || BX_PLATFORM_NACL || BX_PLATFORM_OSX || BX_PLATFORM_IOS || BX_PLATFORM_QNX # include // gettimeofday #elif BX_PLATFORM_WINDOWS # include diff --git a/include/compat/freebsd/alloca.h b/include/compat/freebsd/alloca.h new file mode 100644 index 0000000..c8b49f2 --- /dev/null +++ b/include/compat/freebsd/alloca.h @@ -0,0 +1 @@ +#include diff --git a/include/compat/freebsd/malloc.h b/include/compat/freebsd/malloc.h new file mode 100644 index 0000000..c8b49f2 --- /dev/null +++ b/include/compat/freebsd/malloc.h @@ -0,0 +1 @@ +#include From 0af42a72c6fe5d8fbc8e4ac86ea1bb29abaacc83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Wed, 9 Jul 2014 22:01:36 -0700 Subject: [PATCH 13/14] Added FreeBSD to toolchain.lua. --- premake/toolchain.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/premake/toolchain.lua b/premake/toolchain.lua index e5bfce6..1ba6362 100755 --- a/premake/toolchain.lua +++ b/premake/toolchain.lua @@ -17,6 +17,7 @@ function toolchain(_buildDir, _libDir) { "android-mips", "Android - MIPS" }, { "android-x86", "Android - x86" }, { "asmjs", "Emscripten/asm.js" }, + { "freebsd", "FreeBSD" }, { "linux-gcc", "Linux (GCC compiler)" }, { "linux-clang", "Linux (Clang compiler)" }, { "mingw", "MinGW" }, @@ -98,6 +99,10 @@ function toolchain(_buildDir, _libDir) location (_buildDir .. "projects/" .. _ACTION .. "-asmjs") end + if "freebsd" == _OPTIONS["gcc"] then + location (_buildDir .. "projects/" .. _ACTION .. "-freebsd") + end + if "linux-gcc" == _OPTIONS["gcc"] then location (_buildDir .. "projects/" .. _ACTION .. "-linux") end @@ -484,6 +489,14 @@ function toolchain(_buildDir, _libDir) "-Wno-warn-absolute-paths", } + configuration { "freebsd" } + targetdir (_buildDir .. "freebsd" .. "/bin") + objdir (_buildDir .. "freebsd" .. "/obj") + libdirs { _libDir .. "lib/freebsd" } + includedirs { + bxDir .. "include/compat/freebsd", + } + configuration { "nacl or nacl-arm or pnacl" } includedirs { "$(NACL_SDK_ROOT)/include", From ec2d1f8e9321997586a444717f3c3e382f89fcda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Wed, 9 Jul 2014 22:49:15 -0700 Subject: [PATCH 14/14] Cleanup. --- include/bx/float4_ni.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/include/bx/float4_ni.h b/include/bx/float4_ni.h index 4786e7f..524a133 100644 --- a/include/bx/float4_ni.h +++ b/include/bx/float4_ni.h @@ -42,14 +42,6 @@ namespace bx return result; } - BX_FLOAT4_INLINE float4_t float4_rcp_ni(float4_t _a) - { - const float4_t one = float4_splat(1.0f); - const float4_t result = float4_div(one, _a); - - return result; - } - BX_FLOAT4_INLINE float4_t float4_div_nr_ni(float4_t _a, float4_t _b) { const float4_t oneish = float4_isplat(0x3f800001); @@ -61,6 +53,14 @@ namespace bx return result; } + BX_FLOAT4_INLINE float4_t float4_rcp_ni(float4_t _a) + { + const float4_t one = float4_splat(1.0f); + const float4_t result = float4_div(one, _a); + + return result; + } + BX_FLOAT4_INLINE float4_t float4_orx_ni(float4_t _a) { const float4_t zwxy = float4_swiz_zwxy(_a);