From: chsieh Date: Sat, 18 Dec 2010 07:25:20 +0000 (-0800) Subject: Fixing up various x86 simulator vs. ARM device low level differences. Also filled... X-Git-Tag: box2d-testbed~37 X-Git-Url: http://git.less.ly:3516/?a=commitdiff_plain;h=ead28a9912f1ca7890e0164ec6ab4bdae6ca5d3c;p=tanks-ios.git Fixing up various x86 simulator vs. ARM device low level differences. Also filled in OS-dependent implementations. --- diff --git a/Classes/Foundation/Common/Assert.h b/Classes/Foundation/Common/Assert.h index 123e36a..8e3cd40 100755 --- a/Classes/Foundation/Common/Assert.h +++ b/Classes/Foundation/Common/Assert.h @@ -1,13 +1,64 @@ #pragma once -#ifdef DEBUG +#if defined(DEBUG) #include +#include +#include +#include +#include +#include -#define Assert(expression) if (!(expression)) __debugbreak(); +#include "GlobalDefines.h" -#define AssertMessage(expression, message, ...) \ - if (!(expression)) Printf(message, ##__VA_ARGS__) + #if defined(__WINDOWS__) + + #define Assert(expression) if (!(expression)) __debugbreak(); + + #elif defined(__iOS__) + + // Returns true if the current process is being debugged (either + // running under the debugger or has a debugger attached post facto). + static bool AmIBeingDebugged(void) + { + int junk; + int mib[4]; + struct kinfo_proc info; + size_t size; + + // Initialize the flags so that, if sysctl fails for some bizarre + // reason, we get a predictable result. + info.kp_proc.p_flag = 0; + + // Initialize mib, which tells sysctl the info we want, in this case + // we're looking for information about a specific process ID. + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = KERN_PROC_PID; + mib[3] = getpid(); + + // Call sysctl. + size = sizeof(info); + junk = sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, NULL, 0); + assert(junk == 0); + + // We're being debugged if the P_TRACED flag is set. + return ( (info.kp_proc.p_flag & P_TRACED) != 0 ); + } + + // http://iphone.m20.nl/wp/?p=1#more-1 + //#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"); + //#define DEBUGGER do { int trapSignal = AmIBeingDebugged () ? SIGINT : SIGSTOP; DEBUGSTOP(trapSignal); if (trapSignal == SIGSTOP) { DEBUGSTOP (SIGINT); } } while (false); + + // Graciously copied from http://cocoawithlove.com/2008/03/break-into-debugger.html + #define DebugBreak() if (AmIBeingDebugged()) { DebugBreak(); } + + #define Assert(expression) if (!(expression)) raise(SIGTRAP); + + #endif + + #define AssertMessage(expression, message, ...) \ + if (!(expression)) Printf(message, ##__VA_ARGS__) #else diff --git a/Classes/Foundation/Common/GlobalDefines.h b/Classes/Foundation/Common/GlobalDefines.h index 94b70ba..aa242fa 100755 --- a/Classes/Foundation/Common/GlobalDefines.h +++ b/Classes/Foundation/Common/GlobalDefines.h @@ -2,41 +2,49 @@ #include "Foundation/Common/GlobalTypes.h" -#ifdef _WINDOWS +#if defined(_WINDOWS) #define __WINDOWS__ -#ifdef __iOS__ - #define __ARM__ + #define __X86__ +#elif defined(__iOS__) + #include + #if TARGET_IPHONE_SIMULATOR + #define __X86__ + #elif TARGET_OS_IPHONE + #define __ARM__ + #else + #error undefined architecture! + #endif #endif -#ifdef _DEBUG +#if defined(_DEBUG) #define DEBUG #endif -#ifdef _NDEBUG +#if defined(_NDEBUG) #define RELEASE #endif -#ifndef NULL +#if !defined(NULL) #define NULL 0 #endif -#ifndef FALSE +#if !defined(FALSE) #define FALSE 0 #endif -#ifndef TRUE +#if !defined(TRUE) #define TRUE 1 #endif //---------------------------------------------------------------------------------------- // cache information -#ifndef CACHE_LINE_SIZE +#if !defined(CACHE_LINE_SIZE) #define CACHE_LINE_SIZE 128 // normally equals to 2 lines for intel #endif //---------------------------------------------------------------------------------------- //force inline on non-debug, might make code explode -#ifdef DEBUG +#if defined(DEBUG) #define slInline inline #else #define slInline __forceinline @@ -52,7 +60,7 @@ #if defined(__WINDOWS__) #define ALIGN(N) __declspec(align(N)) #elif defined(__iOS__) -#define ALIGN(N) __atribute__((aligned (N))) +#define ALIGN(N) __attribute__((aligned (N))) #endif #define IS_POWER_OF_TWO(x) ( ((x) & -(x)) == (x) ) @@ -67,10 +75,10 @@ //---------------------------------------------------------------------------------------- // cache macros -#if defined(__WINDOWS__) +#if defined(__X86__) // uhh, nothing? #elif defined(__ARM__) -#define DCBT(x) __asm__("pld %0" : : "r"((x))) +#define DCBT(x) __asm__("pld %[input]" : : [input] "r" ((x))) #else #error Not implemented yet! #endif @@ -78,8 +86,6 @@ //---------------------------------------------------------------------------------------- // string and memory functions #if defined(__WINDOWS__) - #include - #pragma intrinsic(memcpy) #pragma intrinsic(memset) #pragma intrinsic(strcmp) @@ -98,7 +104,16 @@ #define WHITE_COLOR 0xffffffff //---------------------------------------------------------------------------------------- -#if defined(__WINDOWS__) +#if defined(__ARM__) + +slInline uint8_t LZCount(uint64_t x) +{ + uint8_t result; + __asm__("clz %[result] %[input]" : [result] "=r" (result) : [input] "r" (x)); + return result; +} + +#else slInline uint8_t LZCount(uint64_t x) { @@ -114,21 +129,10 @@ slInline uint8_t LZCount(uint64_t x) next_shift >>= 1; } leading_zero_count += (copy == 0x1ULL); - + return leading_zero_count; } -#elif defined(__ARM__) - -slInline uint8_t LZCount(uint64_t x) -{ - uint8_t result; - __asm__("clz %1 %0" : "=r" (result) : "r"(x)); - return result; -} - -#else -#error use lzcnt! #endif //---------------------------------------------------------------------------------------- diff --git a/Classes/Foundation/Common/GlobalInclude.h b/Classes/Foundation/Common/GlobalInclude.h index 5ffd39f..bf31d87 100755 --- a/Classes/Foundation/Common/GlobalInclude.h +++ b/Classes/Foundation/Common/GlobalInclude.h @@ -1,5 +1,6 @@ #pragma once +#include #include "GlobalDefines.h" #include "GlobalTypes.h" #include "Assert.h" diff --git a/Classes/Foundation/Common/GlobalTypes.h b/Classes/Foundation/Common/GlobalTypes.h index 5e1d3d5..a2d92f0 100755 --- a/Classes/Foundation/Common/GlobalTypes.h +++ b/Classes/Foundation/Common/GlobalTypes.h @@ -1,6 +1,6 @@ #pragma once -#ifdef uint32_t +#if defined(uint32_t) #undef uint32_t #endif diff --git a/Classes/Foundation/Containers/LocklessRingBuffer.cpp b/Classes/Foundation/Containers/LocklessRingBuffer.cpp index 48d7ed7..0a9f9d6 100755 --- a/Classes/Foundation/Containers/LocklessRingBuffer.cpp +++ b/Classes/Foundation/Containers/LocklessRingBuffer.cpp @@ -1,5 +1,3 @@ -#pragma once - #include "LocklessRingBuffer.h" #include "Foundation/Synchronization/MemorySync.h" diff --git a/Classes/Foundation/GraphicsServices/OpenGLServices.h b/Classes/Foundation/GraphicsServices/OpenGLServices.h index ad6aad9..838caca 100644 --- a/Classes/Foundation/GraphicsServices/OpenGLServices.h +++ b/Classes/Foundation/GraphicsServices/OpenGLServices.h @@ -16,7 +16,7 @@ class OpenGLServices { public: - bool Init(); + bool init(); private: diff --git a/Classes/Foundation/Memory/MemoryBitset.cpp b/Classes/Foundation/Memory/MemoryBitset.cpp index a9d4e19..c832cc8 100755 --- a/Classes/Foundation/Memory/MemoryBitset.cpp +++ b/Classes/Foundation/Memory/MemoryBitset.cpp @@ -50,8 +50,6 @@ int32_t MemoryBitset::FindLowestUnused(int32_t start_search_index) uint64_t right_most_top_unused_bit = RightMostEnabledBit(~*top_pointer); int32_t bottom_index = top_index * 64 + 64 - LZCount(right_most_top_unused_bit); uint64_t* bottom_pointer = m_BottomBits + bottom_index; - int32_t bottom_offset = start_search_index - top_index * 4096; - uint64_t first_bottom_mask = ~(0xffffffffffffffffULL << bottom_offset); // skip over all bottom bits that're fully allocated while (*bottom_pointer == 0xffffffffffffffffULL && bottom_pointer <= m_MaxBottomPointer) diff --git a/Classes/Foundation/Memory/MemoryHeap.cpp b/Classes/Foundation/Memory/MemoryHeap.cpp index 8a8d2fd..82c87fd 100755 --- a/Classes/Foundation/Memory/MemoryHeap.cpp +++ b/Classes/Foundation/Memory/MemoryHeap.cpp @@ -3,6 +3,7 @@ //---------------------------------------------------------------------------------------- bool MemoryHeap::Init(void* base, size_t size) { + Assert(0); if (size <= sizeof(FreeRecordInPage)) { return false; diff --git a/Classes/Foundation/Memory/MemoryHeap.h b/Classes/Foundation/Memory/MemoryHeap.h index 12ad656..4eab6e3 100755 --- a/Classes/Foundation/Memory/MemoryHeap.h +++ b/Classes/Foundation/Memory/MemoryHeap.h @@ -14,6 +14,10 @@ private: #if defined(__WINDOWS__) static const uint32_t s_PageSize = 4096; +#elif defined(__ARM__) + static const uint32_t s_PageSize = 4096; +#elif defined(__X86__) && defined(__iOS__) + static const uint32_t s_PageSize = 4096; #else #error NEED TO SPECIFY THIS! #endif diff --git a/Classes/Foundation/Synchronization/MemorySync.h b/Classes/Foundation/Synchronization/MemorySync.h index 357084c..08de018 100755 --- a/Classes/Foundation/Synchronization/MemorySync.h +++ b/Classes/Foundation/Synchronization/MemorySync.h @@ -1,5 +1,7 @@ #pragma once +#include "Foundation/Common/GlobalDefines.h" + #if defined(__WINDOWS__) #include @@ -14,6 +16,11 @@ #define ReadWriteSync() __asm__("dsb") +#elif defined(__X86__) && defined(__iOS__) + +#include +#define ReadWriteSync() OSMemoryBarrier() + #else #error MemorySync not yet implemented for this build! diff --git a/Littlest.xcodeproj/project.pbxproj b/Littlest.xcodeproj/project.pbxproj index 81661ef..76b10a4 100755 --- a/Littlest.xcodeproj/project.pbxproj +++ b/Littlest.xcodeproj/project.pbxproj @@ -93,6 +93,7 @@ 080E96DDFE201D6D7F000001 /* Classes */ = { isa = PBXGroup; children = ( + 4B6858C912BC3E80005667D3 /* Game */, 4B68583B12BC1E97005667D3 /* Foundation */, ); path = Classes; @@ -262,6 +263,13 @@ path = OSInterface; sourceTree = ""; }; + 4B6858C912BC3E80005667D3 /* Game */ = { + isa = PBXGroup; + children = ( + ); + path = Game; + sourceTree = ""; + }; 4B90648212B41E0800655D84 /* Standard */ = { isa = PBXGroup; children = ( @@ -296,6 +304,9 @@ /* 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; @@ -393,10 +404,18 @@ __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; }; @@ -412,11 +431,13 @@ 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; };