From 60a7e79e1aa59f8e82a6d27b0e7bbc4b5479d330 Mon Sep 17 00:00:00 2001 From: Anthony Pesch Date: Tue, 13 May 2014 22:20:42 -0700 Subject: [PATCH 1/6] assume c++11 clang didn't like static members in anonymous structures, gave them names WriteEvent template wouldn't resolve for temporary values without const decl in clang added a few missing headers added -fno-operator-names for xbyak compilation under gcc/clang --- src/alloy/backend/ivm/ivm_assembler.cc | 2 +- src/alloy/backend/ivm/tracing.h | 8 ++++---- src/alloy/backend/x64/lowering/tracers.h | 1 + src/alloy/backend/x64/tracing.h | 8 ++++---- src/alloy/compiler/tracing.h | 4 ++-- src/alloy/delegate.h | 1 + src/alloy/frontend/tracing.h | 4 ++-- src/alloy/runtime/entry_table.h | 2 +- src/alloy/runtime/module.h | 2 +- src/alloy/runtime/tracing.h | 20 ++++++++++---------- src/alloy/tracing/event_type.h | 4 ++-- src/alloy/tracing/tracing.h | 2 +- src/xenia/kernel/fs/filesystem.cc | 4 ++-- src/xenia/kernel/fs/filesystem.h | 2 +- src/xenia/platform_includes.h | 5 ----- src/xenia/types.h | 2 +- xenia.gyp | 18 +++++++++++++++++- 17 files changed, 51 insertions(+), 38 deletions(-) diff --git a/src/alloy/backend/ivm/ivm_assembler.cc b/src/alloy/backend/ivm/ivm_assembler.cc index ff665b8f3..bfd7600a7 100644 --- a/src/alloy/backend/ivm/ivm_assembler.cc +++ b/src/alloy/backend/ivm/ivm_assembler.cc @@ -109,7 +109,7 @@ int IVMAssembler::Assemble( // Fixup label references. LabelRef* label_ref = ctx.label_ref_head; while (label_ref) { - label_ref->instr->src1_reg = (uint32_t)label_ref->label->tag & ~0x80000000; + label_ref->instr->src1_reg = (uint32_t)(intptr_t)label_ref->label->tag & ~0x80000000; label_ref = label_ref->next; } diff --git a/src/alloy/backend/ivm/tracing.h b/src/alloy/backend/ivm/tracing.h index a1fcdf20d..526aa912e 100644 --- a/src/alloy/backend/ivm/tracing.h +++ b/src/alloy/backend/ivm/tracing.h @@ -32,17 +32,17 @@ public: ALLOY_BACKEND_IVM_ASSEMBLER_DEINIT = ALLOY_BACKEND_IVM_ASSEMBLER | (2), }; - typedef struct { + typedef struct Init_s { static const uint32_t event_type = ALLOY_BACKEND_IVM_INIT; } Init; - typedef struct { + typedef struct Deinit_s { static const uint32_t event_type = ALLOY_BACKEND_IVM_DEINIT; } Deinit; - typedef struct { + typedef struct AssemblerInit_s { static const uint32_t event_type = ALLOY_BACKEND_IVM_ASSEMBLER_INIT; } AssemblerInit; - typedef struct { + typedef struct AssemblerDeinit_s { static const uint32_t event_type = ALLOY_BACKEND_IVM_ASSEMBLER_DEINIT; } AssemblerDeinit; }; diff --git a/src/alloy/backend/x64/lowering/tracers.h b/src/alloy/backend/x64/lowering/tracers.h index 9afd58448..e0536c7c5 100644 --- a/src/alloy/backend/x64/lowering/tracers.h +++ b/src/alloy/backend/x64/lowering/tracers.h @@ -11,6 +11,7 @@ #define ALLOY_BACKEND_X64_X64_LOWERING_TRACERS_H_ #include +#include namespace alloy { diff --git a/src/alloy/backend/x64/tracing.h b/src/alloy/backend/x64/tracing.h index 36d814d67..e6689b830 100644 --- a/src/alloy/backend/x64/tracing.h +++ b/src/alloy/backend/x64/tracing.h @@ -32,17 +32,17 @@ public: ALLOY_BACKEND_X64_ASSEMBLER_DEINIT = ALLOY_BACKEND_X64_ASSEMBLER | (2), }; - typedef struct { + typedef struct Init_s { static const uint32_t event_type = ALLOY_BACKEND_X64_INIT; } Init; - typedef struct { + typedef struct Deinit_s { static const uint32_t event_type = ALLOY_BACKEND_X64_DEINIT; } Deinit; - typedef struct { + typedef struct AssemblerInit_s { static const uint32_t event_type = ALLOY_BACKEND_X64_ASSEMBLER_INIT; } AssemblerInit; - typedef struct { + typedef struct AssemblerDeinit_s { static const uint32_t event_type = ALLOY_BACKEND_X64_ASSEMBLER_DEINIT; } AssemblerDeinit; }; diff --git a/src/alloy/compiler/tracing.h b/src/alloy/compiler/tracing.h index 04da6d9ee..85d99992a 100644 --- a/src/alloy/compiler/tracing.h +++ b/src/alloy/compiler/tracing.h @@ -27,10 +27,10 @@ public: ALLOY_COMPILER_DEINIT = ALLOY_COMPILER | (2), }; - typedef struct { + typedef struct Init_s { static const uint32_t event_type = ALLOY_COMPILER_INIT; } Init; - typedef struct { + typedef struct Deinit_s { static const uint32_t event_type = ALLOY_COMPILER_DEINIT; } Deinit; }; diff --git a/src/alloy/delegate.h b/src/alloy/delegate.h index e6ad2fcd1..176ff4b6b 100644 --- a/src/alloy/delegate.h +++ b/src/alloy/delegate.h @@ -11,6 +11,7 @@ #define ALLOY_DELEGATE_H_ #include +#include #include #include diff --git a/src/alloy/frontend/tracing.h b/src/alloy/frontend/tracing.h index 61aadb949..ad9e8dae7 100644 --- a/src/alloy/frontend/tracing.h +++ b/src/alloy/frontend/tracing.h @@ -27,10 +27,10 @@ public: ALLOY_FRONTEND_DEINIT = ALLOY_FRONTEND | (2), }; - typedef struct { + typedef struct Init_s { static const uint32_t event_type = ALLOY_FRONTEND_INIT; } Init; - typedef struct { + typedef struct Deinit_s { static const uint32_t event_type = ALLOY_FRONTEND_DEINIT; } Deinit; }; diff --git a/src/alloy/runtime/entry_table.h b/src/alloy/runtime/entry_table.h index e9f1ca9f2..acbabc26e 100644 --- a/src/alloy/runtime/entry_table.h +++ b/src/alloy/runtime/entry_table.h @@ -47,7 +47,7 @@ public: private: // TODO(benvanik): replace with a better data structure. Mutex* lock_; - typedef std::tr1::unordered_map EntryMap; + typedef std::unordered_map EntryMap; EntryMap map_; }; diff --git a/src/alloy/runtime/module.h b/src/alloy/runtime/module.h index 005e325a1..c05e009ca 100644 --- a/src/alloy/runtime/module.h +++ b/src/alloy/runtime/module.h @@ -62,7 +62,7 @@ protected: private: // TODO(benvanik): replace with a better data structure. Mutex* lock_; - typedef std::tr1::unordered_map SymbolMap; + typedef std::unordered_map SymbolMap; SymbolMap map_; typedef std::vector SymbolList; SymbolList list_; diff --git a/src/alloy/runtime/tracing.h b/src/alloy/runtime/tracing.h index 005562d07..262662b90 100644 --- a/src/alloy/runtime/tracing.h +++ b/src/alloy/runtime/tracing.h @@ -40,46 +40,46 @@ public: ALLOY_RUNTIME_MEMORY_HEAP_FREE = ALLOY_RUNTIME_MEMORY | (4), }; - typedef struct { + typedef struct Init_s { static const uint32_t event_type = ALLOY_RUNTIME_INIT; } Init; - typedef struct { + typedef struct Deinit_s { static const uint32_t event_type = ALLOY_RUNTIME_DEINIT; } Deinit; - typedef struct { + typedef struct ThreadInit_s { static const uint32_t event_type = ALLOY_RUNTIME_THREAD_INIT; } ThreadInit; - typedef struct { + typedef struct ThreadDeinit_s { static const uint32_t event_type = ALLOY_RUNTIME_THREAD_DEINIT; } ThreadDeinit; - typedef struct { + typedef struct MemoryInit_s { static const uint32_t event_type = ALLOY_RUNTIME_MEMORY_INIT; // map of memory, etc? } MemoryInit; - typedef struct { + typedef struct MemoryDeinit_s { static const uint32_t event_type = ALLOY_RUNTIME_MEMORY_DEINIT; } MemoryDeinit; - typedef struct { + typedef struct MemoryHeapInit_s { static const uint32_t event_type = ALLOY_RUNTIME_MEMORY_HEAP_INIT; uint32_t heap_id; uint64_t low_address; uint64_t high_address; uint32_t is_physical; } MemoryHeapInit; - typedef struct { + typedef struct MemoryHeapDeinit_s { static const uint32_t event_type = ALLOY_RUNTIME_MEMORY_HEAP_DEINIT; uint32_t heap_id; } MemoryHeapDeinit; - typedef struct { + typedef struct MemoryHeapAlloc_s { static const uint32_t event_type = ALLOY_RUNTIME_MEMORY_HEAP_ALLOC; uint32_t heap_id; uint32_t flags; uint64_t address; size_t size; } MemoryHeapAlloc; - typedef struct { + typedef struct MemoryHeapFree_s { static const uint32_t event_type = ALLOY_RUNTIME_MEMORY_HEAP_FREE; uint32_t heap_id; uint64_t address; diff --git a/src/alloy/tracing/event_type.h b/src/alloy/tracing/event_type.h index e51353708..33e2614fb 100644 --- a/src/alloy/tracing/event_type.h +++ b/src/alloy/tracing/event_type.h @@ -33,10 +33,10 @@ public: USER = (1 << 31), }; - typedef struct { + typedef struct TraceInit_s { static const uint32_t event_type = ALLOY_TRACE_INIT; } TraceInit; - typedef struct { + typedef struct TraceEOF_s { static const uint32_t event_type = ALLOY_TRACE_EOF; } TraceEOF; }; diff --git a/src/alloy/tracing/tracing.h b/src/alloy/tracing/tracing.h index b4eb2c865..ced2081de 100644 --- a/src/alloy/tracing/tracing.h +++ b/src/alloy/tracing/tracing.h @@ -30,7 +30,7 @@ Tracer* GetThreadTracer(); void WriteEvent(uint32_t event_type, size_t size = 0, const void* data = 0); -template void WriteEvent(T& ev) { +template void WriteEvent(const T& ev) { if (sizeof(T) > 1) { alloy::tracing::WriteEvent(T::event_type, sizeof(T), &ev); } else { diff --git a/src/xenia/kernel/fs/filesystem.cc b/src/xenia/kernel/fs/filesystem.cc index 6efa53de6..e83d409c8 100644 --- a/src/xenia/kernel/fs/filesystem.cc +++ b/src/xenia/kernel/fs/filesystem.cc @@ -70,7 +70,7 @@ int FileSystem::CreateSymbolicLink(const char* path, const char* target) { } int FileSystem::DeleteSymbolicLink(const char* path) { - std::tr1::unordered_map::iterator it = + std::unordered_map::iterator it = symlinks_.find(std::string(path)); if (it != symlinks_.end()) { symlinks_.erase(it); @@ -93,7 +93,7 @@ Entry* FileSystem::ResolvePath(const char* path) { // drive path -> device mappings with nothing nested. char full_path[XE_MAX_PATH]; XEIGNORE(xestrcpya(full_path, XECOUNT(full_path), path)); - for (std::tr1::unordered_map::iterator it = + for (std::unordered_map::iterator it = symlinks_.begin(); it != symlinks_.end(); ++it) { if (xestrcasestra(path, it->first.c_str()) == path) { // Found symlink, fixup. diff --git a/src/xenia/kernel/fs/filesystem.h b/src/xenia/kernel/fs/filesystem.h index acc6dbda6..94b9d787f 100644 --- a/src/xenia/kernel/fs/filesystem.h +++ b/src/xenia/kernel/fs/filesystem.h @@ -43,7 +43,7 @@ public: private: std::vector devices_; - std::tr1::unordered_map symlinks_; + std::unordered_map symlinks_; }; diff --git a/src/xenia/platform_includes.h b/src/xenia/platform_includes.h index e9d513316..6aaf86811 100644 --- a/src/xenia/platform_includes.h +++ b/src/xenia/platform_includes.h @@ -56,13 +56,8 @@ #include #include -#if XE_COMPILER_MSVC #include #include -#else -#include -#include -#endif // MSVC #endif // XENIA_PLATFORM_INCLUDES_H_ diff --git a/src/xenia/types.h b/src/xenia/types.h index 928c71766..42d6aa658 100644 --- a/src/xenia/types.h +++ b/src/xenia/types.h @@ -16,7 +16,7 @@ namespace xe { // TODO(benvanik): support other compilers/etc using std::auto_ptr; -using std::tr1::shared_ptr; +using std::shared_ptr; } // namespace xe diff --git a/xenia.gyp b/xenia.gyp index aea3ec75f..e59823058 100644 --- a/xenia.gyp +++ b/xenia.gyp @@ -96,7 +96,7 @@ 'SYMROOT': '<(DEPTH)/build/xenia/', 'ALWAYS_SEARCH_USER_PATHS': 'NO', 'ARCHS': ['x86_64'], - #'CLANG_CXX_LANGUAGE_STANDARD': 'c++0x', + 'CLANG_CXX_LANGUAGE_STANDARD': 'c++11', 'COMBINE_HIDPI_IMAGES': 'YES', 'GCC_C_LANGUAGE_STANDARD': 'gnu99', 'GCC_SYMBOLS_PRIVATE_EXTERN': 'YES', @@ -190,6 +190,22 @@ 'gflags', 'llvm', ], + + 'conditions': [ + ['OS == "mac"', { + 'xcode_settings': { + 'OTHER_CFLAGS': [ + '-fno-operator-names', + ], + }, + }], + ['OS == "linux"', { + 'cflags': [ + '-fno-operator-names', + ], + }], + ], + 'export_dependent_settings': [ 'beaengine', 'gflags', From c6cdf1f6726957d4353a66f1bfce021b0f5eebf1 Mon Sep 17 00:00:00 2001 From: Anthony Pesch Date: Tue, 13 May 2014 23:19:56 -0700 Subject: [PATCH 2/6] nest X64Function in its own block to avoid clang errors related to goto usage --- src/alloy/backend/x64/x64_assembler.cc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/alloy/backend/x64/x64_assembler.cc b/src/alloy/backend/x64/x64_assembler.cc index 3f90b077b..5a7028e11 100644 --- a/src/alloy/backend/x64/x64_assembler.cc +++ b/src/alloy/backend/x64/x64_assembler.cc @@ -83,13 +83,15 @@ int X64Assembler::Assemble( string_buffer_.Reset(); } - X64Function* fn = new X64Function(symbol_info); - fn->set_debug_info(debug_info); - fn->Setup(machine_code, code_size); + { + X64Function* fn = new X64Function(symbol_info); + fn->set_debug_info(debug_info); + fn->Setup(machine_code, code_size); - *out_function = fn; + *out_function = fn; - result = 0; + result = 0; + } XECLEANUP: Reset(); From 0e6c47aac57678c4d9eb43ecc52746285faaf298 Mon Sep 17 00:00:00 2001 From: Anthony Pesch Date: Tue, 13 May 2014 23:46:42 -0700 Subject: [PATCH 3/6] use custom __m128 struct on non-win32 platforms to provide element-wise access explicitly cast param for set_constant to correctly resolve overloaded function --- src/alloy/backend/ivm/ivm_assembler.cc | 2 +- src/alloy/backend/x64/lowering/tracers.h | 15 +++++++++++++++ src/alloy/backend/x64/x64_emitter.cc | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/alloy/backend/ivm/ivm_assembler.cc b/src/alloy/backend/ivm/ivm_assembler.cc index bfd7600a7..a95237f2e 100644 --- a/src/alloy/backend/ivm/ivm_assembler.cc +++ b/src/alloy/backend/ivm/ivm_assembler.cc @@ -81,7 +81,7 @@ int IVMAssembler::Assemble( size_t type_size = GetTypeSize(slot->type); // Align to natural size. stack_offset = XEALIGN(stack_offset, type_size); - slot->set_constant(stack_offset); + slot->set_constant((uint32_t)stack_offset); stack_offset += type_size; } // Ensure 16b alignment. diff --git a/src/alloy/backend/x64/lowering/tracers.h b/src/alloy/backend/x64/lowering/tracers.h index e0536c7c5..7201b4f25 100644 --- a/src/alloy/backend/x64/lowering/tracers.h +++ b/src/alloy/backend/x64/lowering/tracers.h @@ -11,7 +11,22 @@ #define ALLOY_BACKEND_X64_X64_LOWERING_TRACERS_H_ #include + +#if XE_LIKE_WIN32 #include +#else +typedef union __declspec(align(16)) __m128 { + float m128_f32[4]; + uint64_t m128_u64[2]; + int8_t m128_i8[16]; + int16_t m128_i16[8]; + int32_t m128_i32[4]; + int64_t m128_i64[2]; + uint8_t m128_u8[16]; + uint16_t m128_u16[8]; + uint32_t m128_u32[4]; +} __m128; +#endif namespace alloy { diff --git a/src/alloy/backend/x64/x64_emitter.cc b/src/alloy/backend/x64/x64_emitter.cc index 3a9e6d142..80ed2cbca 100644 --- a/src/alloy/backend/x64/x64_emitter.cc +++ b/src/alloy/backend/x64/x64_emitter.cc @@ -117,7 +117,7 @@ int X64Emitter::Emit(HIRBuilder* builder, size_t& out_stack_size) { size_t type_size = GetTypeSize(slot->type); // Align to natural size. stack_offset = XEALIGN(stack_offset, type_size); - slot->set_constant(stack_offset); + slot->set_constant((uint32_t)stack_offset); stack_offset += type_size; } // Ensure 16b alignment. From 68e5833647091ea04f31ab7ea99bea3bb989cecd Mon Sep 17 00:00:00 2001 From: Anthony Pesch Date: Wed, 14 May 2014 00:14:32 -0700 Subject: [PATCH 4/6] use getpagesize on non-win32 platforms --- src/alloy/memory.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/alloy/memory.cc b/src/alloy/memory.cc index 8b4eaa2e3..2933392dd 100644 --- a/src/alloy/memory.cc +++ b/src/alloy/memory.cc @@ -9,14 +9,22 @@ #include +#if !XE_LIKE_WIN32 +#include +#endif + using namespace alloy; Memory::Memory() : membase_(0), reserve_address_(0) { +#if XE_LIKE_WIN32 SYSTEM_INFO si; GetSystemInfo(&si); system_page_size_ = si.dwPageSize; +#else + system_page_size_ = getpagesize(); +#endif } Memory::~Memory() { From f01609c5aa69cc24519f6b61686fb0bc22bae85a Mon Sep 17 00:00:00 2001 From: Anthony Pesch Date: Wed, 14 May 2014 00:14:56 -0700 Subject: [PATCH 5/6] replace usage of itoa with snprintf --- src/alloy/compiler/passes/finalization_pass.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/alloy/compiler/passes/finalization_pass.cc b/src/alloy/compiler/passes/finalization_pass.cc index 3fa3fc1b6..9a430ecc1 100644 --- a/src/alloy/compiler/passes/finalization_pass.cc +++ b/src/alloy/compiler/passes/finalization_pass.cc @@ -44,9 +44,9 @@ int FinalizationPass::Run(HIRBuilder* builder) { auto label = block->label_head; while (label) { if (!label->name) { - char* name = (char*)arena->Alloc(6 + 4 + 1); - xestrcpya(name, 6 + 1, "_label"); - char* part = _itoa(label->id, name + 6, 10); + const size_t label_len = 6 + 4 + 1; + char* name = (char*)arena->Alloc(label_len); + xesnprintf(name, label_len, "_label%d", label->id); label->name = name; } label = label->next; From 1a4355a36bfc9ef3281a1deedd498fbd5985caef Mon Sep 17 00:00:00 2001 From: Anthony Pesch Date: Wed, 14 May 2014 00:33:00 -0700 Subject: [PATCH 6/6] implemented xerotl to replace win32 specific _rotl usage --- src/alloy/frontend/ppc/ppc_emit_altivec.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/alloy/frontend/ppc/ppc_emit_altivec.cc b/src/alloy/frontend/ppc/ppc_emit_altivec.cc index d5a77c400..1a985d1ae 100644 --- a/src/alloy/frontend/ppc/ppc_emit_altivec.cc +++ b/src/alloy/frontend/ppc/ppc_emit_altivec.cc @@ -105,6 +105,10 @@ Value* CalculateEA_0(PPCHIRBuilder& f, uint32_t ra, uint32_t rb); // } +unsigned int xerotl(unsigned int value, unsigned int shift) { + XEASSERT(shift < 32); + return shift == 0 ? value : ((value << shift) | (value >> (32 - shift))); +} XEEMITTER(dst, 0x7C0002AC, XDSS)(PPCHIRBuilder& f, InstrData& i) { XEINSTRNOTIMPLEMENTED(); @@ -1797,7 +1801,7 @@ XEEMITTER(vpkd3d128, VX128_4(6, 1552), VX128_4)(PPCHIRBuilder& f, InstrData // http://hlssmod.net/he_code/public/pixelwriter.h // control = prev:0123 | new:4567 uint32_t control = 0x00010203; // original - uint32_t src = _rotl(0x04050607, shift * 8); + uint32_t src = xerotl(0x04050607, shift * 8); uint32_t mask = 0; switch (pack) { case 1: // VPACK_32