Selaa lähdekoodia

Adds support for MacOS with UnitTests passing (#61)

* Adds support for MacOS with UnitTests passing
Florian Hoenig 3 vuotta sitten
vanhempi
commit
ba9c34933c
3 muutettua tiedostoa jossa 15 lisäystä ja 6 poistoa
  1. 8 1
      Jolt/Core/Core.h
  2. 3 1
      Jolt/Core/TickCounter.cpp
  3. 4 4
      Jolt/Math/Math.h

+ 8 - 1
Jolt/Core/Core.h

@@ -12,6 +12,13 @@
 	#define JPH_PLATFORM_ANDROID
 #elif defined(__linux__)
 	#define JPH_PLATFORM_LINUX
+#elif defined(__APPLE__)
+    #include <TargetConditionals.h>
+    #if defined(TARGET_OS_IPHONE) && !TARGET_OS_IPHONE
+        #define JPH_PLATFORM_MACOS
+    #else
+        #define JPH_PLATFORM_IOS
+    #endif
 #endif
 
 // Determine compiler and turn off warnings
@@ -111,7 +118,7 @@
 	// Creating one should only be a couple of minutes of work if you have the documentation for the platform 
 	// (you only need to define JPH_BREAKPOINT, JPH_PLATFORM_BLUE_GET_TICKS and JPH_PLATFORM_BLUE_GET_TICK_FREQUENCY and include the right header).
 	#include <Core/PlatformBlue.h> 
-#elif defined(JPH_PLATFORM_LINUX) || defined(JPH_PLATFORM_ANDROID)
+#elif defined(JPH_PLATFORM_LINUX) || defined(JPH_PLATFORM_ANDROID) || defined(JPH_PLATFORM_MACOS) || defined(JPH_PLATFORM_IOS)
 	#include <float.h>
 	#include <limits.h>
 	#include <string.h>

+ 3 - 1
Jolt/Core/TickCounter.cpp

@@ -35,7 +35,7 @@ static const uint64 sProcessorTicksPerSecond = []() {
 	return uint64(mhz) * 1000000UL;
 #elif defined(JPH_PLATFORM_BLUE)
 	return JPH_PLATFORM_BLUE_GET_TICK_FREQUENCY();
-#elif defined(JPH_PLATFORM_LINUX) || defined(JPH_PLATFORM_ANDROID)
+#elif defined(JPH_PLATFORM_LINUX) || defined(JPH_PLATFORM_ANDROID) 
 	// Open /proc/cpuinfo
     ifstream ifs("/proc/cpuinfo");
     if (ifs.is_open())
@@ -73,6 +73,8 @@ static const uint64 sProcessorTicksPerSecond = []() {
 
 	JPH_ASSERT(false);
     return uint64(0);
+#elif defined(JPH_PLATFORM_MACOS) || defined(JPH_PLATFORM_IOS)
+    return 0;
 #else
 	#error Undefined
 #endif

+ 4 - 4
Jolt/Math/Math.h

@@ -105,7 +105,7 @@ inline uint CountTrailingZeros(uint32 inValue)
 	#else
 		if (inValue == 0)
 			return 32;
-		return __builtin_clz(__builtin_bitreverse32(inValue));
+		return __builtin_ctz(inValue);
 	#endif
 #elif defined(JPH_CPU_ARM64)
 	return __builtin_clz(__builtin_bitreverse32(inValue));
@@ -141,10 +141,10 @@ inline uint CountLeadingZeros(uint32 inValue)
 /// Count the number of 1 bits in a value
 inline uint CountBits(uint32 inValue)
 {
-#if defined(JPH_CPU_X64)
+#if defined(JPH_COMPILER_CLANG)
+    return __builtin_popcount(inValue);
+#elif defined(JPH_COMPILER_MSVC)
 	return _mm_popcnt_u32(inValue);
-#elif defined(JPH_CPU_ARM64)
-	return __builtin_popcount(inValue);
 #else
 	#error Undefined
 #endif