Fixing up various x86 simulator vs. ARM device low level differences. Also filled...
authorchsieh <chester.developer@hotmail.com>
Sat, 18 Dec 2010 07:25:20 +0000 (23:25 -0800)
committerchsieh <chester.developer@hotmail.com>
Sat, 18 Dec 2010 07:25:20 +0000 (23:25 -0800)
Classes/Foundation/Common/Assert.h
Classes/Foundation/Common/GlobalDefines.h
Classes/Foundation/Common/GlobalInclude.h
Classes/Foundation/Common/GlobalTypes.h
Classes/Foundation/Containers/LocklessRingBuffer.cpp
Classes/Foundation/GraphicsServices/OpenGLServices.h
Classes/Foundation/Memory/MemoryBitset.cpp
Classes/Foundation/Memory/MemoryHeap.cpp
Classes/Foundation/Memory/MemoryHeap.h
Classes/Foundation/Synchronization/MemorySync.h
Littlest.xcodeproj/project.pbxproj

index 123e36a..8e3cd40 100755 (executable)
@@ -1,13 +1,64 @@
 #pragma once\r
 \r
-#ifdef DEBUG\r
+#if defined(DEBUG)\r
 \r
 #include <assert.h>\r
+#include <stdbool.h>\r
+#include <signal.h>\r
+#include <sys/types.h>\r
+#include <sys/sysctl.h>\r
+#include <unistd.h>\r
 \r
-#define Assert(expression) if (!(expression)) __debugbreak();\r
+#include "GlobalDefines.h"\r
 \r
-#define AssertMessage(expression, message, ...) \\r
-  if (!(expression)) Printf(message, ##__VA_ARGS__)\r
+  #if defined(__WINDOWS__)\r
+\r
+    #define Assert(expression) if (!(expression)) __debugbreak();\r
+\r
+  #elif defined(__iOS__)\r
+\r
+    // Returns true if the current process is being debugged (either\r
+    // running under the debugger or has a debugger attached post facto).\r
+    static bool AmIBeingDebugged(void)\r
+    {\r
+      int                 junk;\r
+      int                 mib[4];\r
+      struct kinfo_proc   info;\r
+      size_t              size;\r
+\r
+      // Initialize the flags so that, if sysctl fails for some bizarre\r
+      // reason, we get a predictable result.\r
+      info.kp_proc.p_flag = 0;\r
+\r
+      // Initialize mib, which tells sysctl the info we want, in this case\r
+      // we're looking for information about a specific process ID.\r
+      mib[0] = CTL_KERN;\r
+      mib[1] = KERN_PROC;\r
+      mib[2] = KERN_PROC_PID;\r
+      mib[3] = getpid();\r
+\r
+      // Call sysctl.\r
+      size = sizeof(info);\r
+      junk = sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, NULL, 0);\r
+      assert(junk == 0);\r
+\r
+      // We're being debugged if the P_TRACED flag is set.\r
+      return ( (info.kp_proc.p_flag & P_TRACED) != 0 );\r
+    }\r
+\r
+    // http://iphone.m20.nl/wp/?p=1#more-1\r
+    //#define DEBUGSTOP(signal) __asm__ __volatile__ ("mov r0, %0\nmov r1, %1\nmov r12, #37\nswi 128\n" : : "r" (getpid ()), "r" (signal) : "r12", "r0", "r1", "cc");\r
+    //#define DEBUGGER do { int trapSignal = AmIBeingDebugged () ? SIGINT : SIGSTOP; DEBUGSTOP(trapSignal); if (trapSignal == SIGSTOP) { DEBUGSTOP (SIGINT); } } while (false);\r
+\r
+    // Graciously copied from http://cocoawithlove.com/2008/03/break-into-debugger.html\r
+    #define DebugBreak() if (AmIBeingDebugged()) { DebugBreak(); }\r
+\r
+    #define Assert(expression) if (!(expression)) raise(SIGTRAP);\r
+\r
+  #endif\r
+\r
+  #define AssertMessage(expression, message, ...) \\r
+    if (!(expression)) Printf(message, ##__VA_ARGS__)\r
 \r
 #else\r
 \r
index 94b70ba..aa242fa 100755 (executable)
@@ -2,41 +2,49 @@
 \r
 #include "Foundation/Common/GlobalTypes.h"\r
 \r
-#ifdef _WINDOWS\r
+#if defined(_WINDOWS)\r
   #define __WINDOWS__\r
-#ifdef __iOS__\r
-  #define __ARM__\r
+  #define __X86__\r
+#elif defined(__iOS__)\r
+  #include <TargetConditionals.h>\r
+  #if TARGET_IPHONE_SIMULATOR\r
+    #define __X86__\r
+  #elif TARGET_OS_IPHONE\r
+    #define __ARM__\r
+  #else\r
+    #error undefined architecture!\r
+  #endif\r
 #endif\r
 \r
-#ifdef _DEBUG\r
+#if defined(_DEBUG)\r
   #define DEBUG\r
 #endif\r
 \r
-#ifdef _NDEBUG\r
+#if defined(_NDEBUG)\r
   #define RELEASE\r
 #endif\r
 \r
-#ifndef NULL\r
+#if !defined(NULL)\r
   #define NULL 0\r
 #endif\r
 \r
-#ifndef FALSE\r
+#if !defined(FALSE)\r
   #define FALSE 0\r
 #endif\r
 \r
-#ifndef TRUE\r
+#if !defined(TRUE)\r
   #define TRUE 1\r
 #endif\r
 \r
 //----------------------------------------------------------------------------------------\r
 // cache information\r
-#ifndef CACHE_LINE_SIZE\r
+#if !defined(CACHE_LINE_SIZE)\r
 #define CACHE_LINE_SIZE         128 // normally equals to 2 lines for intel\r
 #endif\r
 \r
 //----------------------------------------------------------------------------------------\r
 //force inline on non-debug, might make code explode\r
-#ifdef DEBUG\r
+#if defined(DEBUG)\r
   #define slInline                inline\r
 #else\r
   #define slInline                __forceinline\r
@@ -52,7 +60,7 @@
 #if defined(__WINDOWS__)\r
 #define ALIGN(N)                  __declspec(align(N))\r
 #elif defined(__iOS__)\r
-#define ALIGN(N)                  __atribute__((aligned (N)))\r
+#define ALIGN(N)                  __attribute__((aligned (N)))\r
 #endif\r
 \r
 #define IS_POWER_OF_TWO(x)        ( ((x) & -(x)) == (x) )\r
 \r
 //----------------------------------------------------------------------------------------\r
 // cache macros\r
-#if defined(__WINDOWS__)\r
+#if defined(__X86__)\r
 // uhh, nothing?\r
 #elif defined(__ARM__)\r
-#define DCBT(x) __asm__("pld %0" : : "r"((x)))\r
+#define DCBT(x) __asm__("pld %[input]" : : [input] "r" ((x)))\r
 #else\r
 #error Not implemented yet!\r
 #endif\r
@@ -78,8 +86,6 @@
 //----------------------------------------------------------------------------------------\r
 // string and memory functions\r
 #if defined(__WINDOWS__)\r
-  #include <string.h>\r
-\r
   #pragma intrinsic(memcpy)\r
   #pragma intrinsic(memset)\r
   #pragma intrinsic(strcmp)\r
 #define WHITE_COLOR 0xffffffff\r
 \r
 //----------------------------------------------------------------------------------------\r
-#if defined(__WINDOWS__)\r
+#if defined(__ARM__)\r
+\r
+slInline uint8_t LZCount(uint64_t x)\r
+{\r
+  uint8_t result;\r
+  __asm__("clz %[result] %[input]" : [result] "=r" (result) : [input] "r" (x));\r
+  return result;\r
+}\r
+\r
+#else\r
 \r
 slInline uint8_t LZCount(uint64_t x)\r
 {\r
@@ -114,21 +129,10 @@ slInline uint8_t LZCount(uint64_t x)
     next_shift >>= 1;\r
   }\r
   leading_zero_count += (copy == 0x1ULL);\r
-\r
+  \r
   return leading_zero_count;\r
 }\r
 \r
-#elif defined(__ARM__)\r
-\r
-slInline uint8_t LZCount(uint64_t x)\r
-{\r
-  uint8_t result;\r
-  __asm__("clz %1 %0" : "=r" (result) : "r"(x));\r
-  return result;\r
-}\r
-\r
-#else\r
-#error use lzcnt!\r
 #endif\r
 \r
 //----------------------------------------------------------------------------------------\r
index 5ffd39f..bf31d87 100755 (executable)
@@ -1,5 +1,6 @@
 #pragma once\r
 \r
+#include <string.h>\r
 #include "GlobalDefines.h"\r
 #include "GlobalTypes.h"\r
 #include "Assert.h"\r
index 5e1d3d5..a2d92f0 100755 (executable)
@@ -1,6 +1,6 @@
 #pragma once\r
 \r
-#ifdef uint32_t\r
+#if defined(uint32_t)\r
 #undef uint32_t\r
 #endif\r
 \r
index 48d7ed7..0a9f9d6 100755 (executable)
@@ -1,5 +1,3 @@
-#pragma once\r
-\r
 #include "LocklessRingBuffer.h"\r
 #include "Foundation/Synchronization/MemorySync.h"\r
 \r
index ad6aad9..838caca 100644 (file)
@@ -16,7 +16,7 @@
 class OpenGLServices
 {
 public:
-       bool Init();
+       bool init();
        
 private:
        
index a9d4e19..c832cc8 100755 (executable)
@@ -50,8 +50,6 @@ int32_t MemoryBitset::FindLowestUnused(int32_t start_search_index)
   uint64_t right_most_top_unused_bit = RightMostEnabledBit(~*top_pointer);\r
   int32_t bottom_index = top_index * 64 + 64 - LZCount(right_most_top_unused_bit);\r
   uint64_t* bottom_pointer = m_BottomBits + bottom_index;\r
-  int32_t bottom_offset = start_search_index - top_index * 4096;\r
-  uint64_t first_bottom_mask = ~(0xffffffffffffffffULL << bottom_offset);\r
 \r
   // skip over all bottom bits that're fully allocated\r
   while (*bottom_pointer == 0xffffffffffffffffULL && bottom_pointer <= m_MaxBottomPointer)\r
index 8a8d2fd..82c87fd 100755 (executable)
@@ -3,6 +3,7 @@
 //----------------------------------------------------------------------------------------\r
 bool MemoryHeap::Init(void* base, size_t size)\r
 {\r
+  Assert(0);\r
   if (size <= sizeof(FreeRecordInPage))\r
   {\r
     return false;\r
index 12ad656..4eab6e3 100755 (executable)
@@ -14,6 +14,10 @@ private:
 \r
 #if defined(__WINDOWS__)\r
   static const uint32_t s_PageSize = 4096;\r
+#elif defined(__ARM__)\r
+  static const uint32_t s_PageSize = 4096;\r
+#elif defined(__X86__) && defined(__iOS__)\r
+  static const uint32_t s_PageSize = 4096;\r
 #else\r
 #error NEED TO SPECIFY THIS!\r
 #endif\r
index 357084c..08de018 100755 (executable)
@@ -1,5 +1,7 @@
 #pragma once\r
 \r
+#include "Foundation/Common/GlobalDefines.h"\r
+\r
 #if defined(__WINDOWS__)\r
 \r
 #include <Windows.h>\r
 \r
 #define ReadWriteSync() __asm__("dsb")\r
 \r
+#elif defined(__X86__) && defined(__iOS__)\r
+\r
+#include <libkern/OSAtomic.h>\r
+#define ReadWriteSync() OSMemoryBarrier()\r
+\r
 #else\r
 \r
 #error MemorySync not yet implemented for this build!\r
index 81661ef..76b10a4 100755 (executable)
@@ -93,6 +93,7 @@
                080E96DDFE201D6D7F000001 /* Classes */ = {
                        isa = PBXGroup;
                        children = (
+                               4B6858C912BC3E80005667D3 /* Game */,
                                4B68583B12BC1E97005667D3 /* Foundation */,
                        );
                        path = Classes;
                        path = OSInterface;
                        sourceTree = "<group>";
                };
+               4B6858C912BC3E80005667D3 /* Game */ = {
+                       isa = PBXGroup;
+                       children = (
+                       );
+                       path = Game;
+                       sourceTree = "<group>";
+               };
                4B90648212B41E0800655D84 /* Standard */ = {
                        isa = PBXGroup;
                        children = (
 /* Begin PBXProject section */
                29B97313FDCFA39411CA2CEA /* Project object */ = {
                        isa = PBXProject;
+                       attributes = {
+                               ORGANIZATIONNAME = Fubar;
+                       };
                        buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "Littlest" */;
                        compatibilityVersion = "Xcode 3.1";
                        developmentRegion = English;
                                        __iOS__,
                                        DEBUG,
                                );
+                               GCC_VERSION = 4.2;
+                               GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
                                GCC_WARN_ABOUT_RETURN_TYPE = YES;
+                               GCC_WARN_UNKNOWN_PRAGMAS = YES;
+                               GCC_WARN_UNUSED_VALUE = NO;
                                GCC_WARN_UNUSED_VARIABLE = YES;
+                               ONLY_ACTIVE_ARCH = NO;
                                PREBINDING = NO;
+                               "PROVISIONING_PROFILE[sdk=iphoneos*]" = "";
                                SDKROOT = iphoneos;
+                               TARGETED_DEVICE_FAMILY = "1,2";
+                               USER_HEADER_SEARCH_PATHS = "$(PROJECT_DIR)/Classes";
                        };
                        name = Debug;
                };
                                GCC_FAST_MATH = YES;
                                GCC_ONE_BYTE_BOOL = NO;
                                GCC_PREPROCESSOR_DEFINITIONS = __iOS__;
+                               GCC_VERSION = com.apple.compilers.llvmgcc42;
                                GCC_WARN_ABOUT_RETURN_TYPE = YES;
                                GCC_WARN_UNUSED_VARIABLE = YES;
                                OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1";
                                PREBINDING = NO;
                                SDKROOT = iphoneos;
+                               USER_HEADER_SEARCH_PATHS = "$(PROJECT_DIR)/Classes";
                        };
                        name = Release;
                };