diff --git a/src/alloy/backend/ivm/ivm_assembler.cc b/src/alloy/backend/ivm/ivm_assembler.cc index 67d8c63b2..c26657d37 100644 --- a/src/alloy/backend/ivm/ivm_assembler.cc +++ b/src/alloy/backend/ivm/ivm_assembler.cc @@ -26,7 +26,7 @@ using alloy::runtime::Function; using alloy::runtime::FunctionInfo; IVMAssembler::IVMAssembler(Backend* backend) - : source_map_arena_(128 * 1024), Assembler(backend) {} + : Assembler(backend), source_map_arena_(128 * 1024) {} IVMAssembler::~IVMAssembler() { alloy::tracing::WriteEvent(EventType::AssemblerDeinit({})); @@ -94,7 +94,7 @@ int IVMAssembler::Assemble(FunctionInfo* symbol_info, HIRBuilder* builder, auto i = block->instr_head; while (i) { - int result = TranslateIntCodes(ctx, i); + TranslateIntCodes(ctx, i); i = i->next; } block = block->next; diff --git a/src/alloy/backend/ivm/ivm_function.cc b/src/alloy/backend/ivm/ivm_function.cc index 4ed6a13b9..b44f1f07a 100644 --- a/src/alloy/backend/ivm/ivm_function.cc +++ b/src/alloy/backend/ivm/ivm_function.cc @@ -23,12 +23,12 @@ using alloy::runtime::FunctionInfo; using alloy::runtime::ThreadState; IVMFunction::IVMFunction(FunctionInfo* symbol_info) - : register_count_(0), + : Function(symbol_info), + register_count_(0), intcode_count_(0), intcodes_(0), source_map_count_(0), - source_map_(0), - Function(symbol_info) {} + source_map_(0) {} IVMFunction::~IVMFunction() { xe_free(intcodes_); diff --git a/src/alloy/backend/x64/x64_assembler.cc b/src/alloy/backend/x64/x64_assembler.cc index b274a7eca..3f3e6e4fb 100644 --- a/src/alloy/backend/x64/x64_assembler.cc +++ b/src/alloy/backend/x64/x64_assembler.cc @@ -34,7 +34,7 @@ using alloy::runtime::Function; using alloy::runtime::FunctionInfo; X64Assembler::X64Assembler(X64Backend* backend) - : x64_backend_(backend), emitter_(0), allocator_(0), Assembler(backend) {} + : Assembler(backend), x64_backend_(backend), emitter_(0), allocator_(0) {} X64Assembler::~X64Assembler() { alloy::tracing::WriteEvent(EventType::AssemblerDeinit({})); diff --git a/src/alloy/backend/x64/x64_backend.cc b/src/alloy/backend/x64/x64_backend.cc index 3ec784599..e1bf31cbe 100644 --- a/src/alloy/backend/x64/x64_backend.cc +++ b/src/alloy/backend/x64/x64_backend.cc @@ -21,7 +21,7 @@ namespace x64 { using alloy::runtime::Runtime; -X64Backend::X64Backend(Runtime* runtime) : code_cache_(0), Backend(runtime) {} +X64Backend::X64Backend(Runtime* runtime) : Backend(runtime), code_cache_(0) {} X64Backend::~X64Backend() { alloy::tracing::WriteEvent(EventType::Deinit({})); diff --git a/src/alloy/backend/x64/x64_code_cache.cc b/src/alloy/backend/x64/x64_code_cache.cc index b3ea120c8..71a0b2d30 100644 --- a/src/alloy/backend/x64/x64_code_cache.cc +++ b/src/alloy/backend/x64/x64_code_cache.cc @@ -214,8 +214,6 @@ void X64CodeChunk::AddTableEntry(uint8_t* code, size_t code_size, offset += UNWIND_INFO_SIZE; if (!stack_size) { - uint8_t prolog_size = 0; - // http://msdn.microsoft.com/en-us/library/ddssxxy8.aspx UNWIND_INFO* unwind_info = (UNWIND_INFO*)(buffer + unwind_info_offset); unwind_info->Version = 1; diff --git a/src/alloy/backend/x64/x64_emitter.cc b/src/alloy/backend/x64/x64_emitter.cc index ee552c71a..797a03dd3 100644 --- a/src/alloy/backend/x64/x64_emitter.cc +++ b/src/alloy/backend/x64/x64_emitter.cc @@ -54,12 +54,12 @@ const uint32_t X64Emitter::xmm_reg_map_[X64Emitter::XMM_COUNT] = { }; X64Emitter::X64Emitter(X64Backend* backend, XbyakAllocator* allocator) - : runtime_(backend->runtime()), + : CodeGenerator(MAX_CODE_SIZE, AutoGrow, allocator), + runtime_(backend->runtime()), backend_(backend), code_cache_(backend->code_cache()), allocator_(allocator), - current_instr_(0), - CodeGenerator(MAX_CODE_SIZE, AutoGrow, allocator) {} + current_instr_(0) {} X64Emitter::~X64Emitter() {} @@ -263,9 +263,14 @@ uint64_t ResolveFunctionSymbol(void* raw_context, uint64_t symbol_info_ptr) { auto x64_fn = static_cast(fn); uint64_t addr = reinterpret_cast(x64_fn->machine_code()); - // Overwrite the call site. - // The return address points to ReloadRCX work after the call. +// Overwrite the call site. +// The return address points to ReloadRCX work after the call. +#if XE_WIN32_LIKE uint64_t return_address = reinterpret_cast(_ReturnAddress()); +#else + uint64_t return_address = + reinterpret_cast(__builtin_return_address(0)); +#endif // XE_WIN32_LIKE #pragma pack(push, 1) struct Asm { uint16_t mov_rax; @@ -364,7 +369,7 @@ void X64Emitter::CallIndirect(const hir::Instr* instr, const Reg64& reg) { uint64_t UndefinedCallExtern(void* raw_context, uint64_t symbol_info_ptr) { auto symbol_info = reinterpret_cast(symbol_info_ptr); - XELOGW("undefined extern call to %.8X %s", symbol_info->address(), + XELOGW("undefined extern call to %.8llX %s", symbol_info->address(), symbol_info->name()); return 0; } @@ -584,7 +589,7 @@ void X64Emitter::LoadConstantXmm(Xbyak::Xmm dest, float v) { if (!v) { // 0 vpxor(dest, dest); - } else if (x.i == ~0UL) { + } else if (x.i == ~0U) { // 1111... vpcmpeqb(dest, dest); } else { diff --git a/src/alloy/backend/x64/x64_function.cc b/src/alloy/backend/x64/x64_function.cc index 5e20887ba..28b16ee1e 100644 --- a/src/alloy/backend/x64/x64_function.cc +++ b/src/alloy/backend/x64/x64_function.cc @@ -24,7 +24,7 @@ using alloy::runtime::FunctionInfo; using alloy::runtime::ThreadState; X64Function::X64Function(FunctionInfo* symbol_info) - : machine_code_(NULL), code_size_(0), Function(symbol_info) {} + : Function(symbol_info), machine_code_(NULL), code_size_(0) {} X64Function::~X64Function() { // machine_code_ is freed by code cache. diff --git a/src/alloy/backend/x64/x64_sequences.cc b/src/alloy/backend/x64/x64_sequences.cc index 6d513aae0..e969fe402 100644 --- a/src/alloy/backend/x64/x64_sequences.cc +++ b/src/alloy/backend/x64/x64_sequences.cc @@ -2665,7 +2665,7 @@ EMITTER(VECTOR_ADD, MATCH(I, V128<>, V128<>>)) { case FLOAT32_TYPE: e.vaddps(dest, src1, src2); break; - default: XEASSERTALWAYS(); break; + default: XEASSERTUNHANDLEDCASE(part_type); break; } }); } @@ -4704,7 +4704,7 @@ EMITTER(PACK, MATCH(I, V128<>>)) { case PACK_TYPE_S16_IN_32_HI: EmitS16_IN_32_HI(e, i); break; - default: XEASSERTALWAYS(); break; + default: XEASSERTUNHANDLEDCASE(i.instr->flags); break; } } static void EmitD3DCOLOR(X64Emitter& e, const EmitArgType& i) { @@ -4806,7 +4806,7 @@ EMITTER(UNPACK, MATCH(I, V128<>>)) { case PACK_TYPE_S16_IN_32_HI: EmitS16_IN_32_HI(e, i); break; - default: XEASSERTALWAYS(); break; + default: XEASSERTUNHANDLEDCASE(i.instr->flags); break; } } static void EmitD3DCOLOR(X64Emitter& e, const EmitArgType& i) { diff --git a/src/alloy/backend/x64/x64_tracers.cc b/src/alloy/backend/x64/x64_tracers.cc index 29227db0d..4c4fdaabf 100644 --- a/src/alloy/backend/x64/x64_tracers.cc +++ b/src/alloy/backend/x64/x64_tracers.cc @@ -34,6 +34,20 @@ namespace x64 { DFLUSH(); \ if (thread_state->thread_id() == TARGET_THREAD) printf +// TODO(benvanik): properly pull out values. +typedef union __declspec(align(16)) { + __m128 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_x; + uint32_t GetTracingMode() { uint32_t mode = 0; #if ITRACE @@ -53,154 +67,142 @@ void TraceString(void* raw_context, const char* str) { void TraceContextLoadI8(void* raw_context, uint64_t offset, uint8_t value) { auto thread_state = *((ThreadState**)raw_context); - DPRINT("%d (%X) = ctx i8 +%d\n", (int8_t)value, value, offset); + DPRINT("%d (%X) = ctx i8 +%llu\n", (int8_t)value, value, offset); } void TraceContextLoadI16(void* raw_context, uint64_t offset, uint16_t value) { auto thread_state = *((ThreadState**)raw_context); - DPRINT("%d (%X) = ctx i16 +%d\n", (int16_t)value, value, offset); + DPRINT("%d (%X) = ctx i16 +%llu\n", (int16_t)value, value, offset); } void TraceContextLoadI32(void* raw_context, uint64_t offset, uint32_t value) { auto thread_state = *((ThreadState**)raw_context); - DPRINT("%d (%X) = ctx i32 +%d\n", (int32_t)value, value, offset); + DPRINT("%d (%X) = ctx i32 +%llu\n", (int32_t)value, value, offset); } void TraceContextLoadI64(void* raw_context, uint64_t offset, uint64_t value) { auto thread_state = *((ThreadState**)raw_context); - DPRINT("%lld (%llX) = ctx i64 +%d\n", (int64_t)value, value, offset); + DPRINT("%lld (%llX) = ctx i64 +%llu\n", (int64_t)value, value, offset); } void TraceContextLoadF32(void* raw_context, uint64_t offset, __m128 value) { auto thread_state = *((ThreadState**)raw_context); - DPRINT("%e (%X) = ctx f32 +%d\n", value.m128_f32[0], value.m128_i32[0], - offset); + DPRINT("%e (%X) = ctx f32 +%llu\n", poly::m128_f32<0>(value), + poly::m128_i32<0>(value), offset); } void TraceContextLoadF64(void* raw_context, uint64_t offset, __m128 value) { auto thread_state = *((ThreadState**)raw_context); - union { - double d; - uint64_t x; - } f; - f.x = value.m128_i64[0]; - DPRINT("%lle (%llX) = ctx f64 +%d\n", f.d, value.m128_i64[0], offset); + DPRINT("%le (%llX) = ctx f64 +%llu\n", poly::m128_f64<0>(value), + poly::m128_i64<0>(value), offset); } void TraceContextLoadV128(void* raw_context, uint64_t offset, __m128 value) { auto thread_state = *((ThreadState**)raw_context); - DPRINT("[%e, %e, %e, %e] [%.8X, %.8X, %.8X, %.8X] = ctx v128 +%d\n", - value.m128_f32[0], value.m128_f32[1], value.m128_f32[2], - value.m128_f32[3], value.m128_i32[0], value.m128_i32[1], - value.m128_i32[2], value.m128_i32[3], offset); + DPRINT("[%e, %e, %e, %e] [%.8X, %.8X, %.8X, %.8X] = ctx v128 +%llu\n", + poly::m128_f32<0>(value), poly::m128_f32<1>(value), + poly::m128_f32<2>(value), poly::m128_f32<3>(value), + poly::m128_i32<0>(value), poly::m128_i32<1>(value), + poly::m128_i32<2>(value), poly::m128_i32<3>(value), offset); } void TraceContextStoreI8(void* raw_context, uint64_t offset, uint8_t value) { auto thread_state = *((ThreadState**)raw_context); - DPRINT("ctx i8 +%d = %d (%X)\n", offset, (int8_t)value, value); + DPRINT("ctx i8 +%llu = %d (%X)\n", offset, (int8_t)value, value); } void TraceContextStoreI16(void* raw_context, uint64_t offset, uint16_t value) { auto thread_state = *((ThreadState**)raw_context); - DPRINT("ctx i16 +%d = %d (%X)\n", offset, (int16_t)value, value); + DPRINT("ctx i16 +%llu = %d (%X)\n", offset, (int16_t)value, value); } void TraceContextStoreI32(void* raw_context, uint64_t offset, uint32_t value) { auto thread_state = *((ThreadState**)raw_context); - DPRINT("ctx i32 +%d = %d (%X)\n", offset, (int32_t)value, value); + DPRINT("ctx i32 +%llu = %d (%X)\n", offset, (int32_t)value, value); } void TraceContextStoreI64(void* raw_context, uint64_t offset, uint64_t value) { auto thread_state = *((ThreadState**)raw_context); - DPRINT("ctx i64 +%d = %lld (%llX)\n", offset, (int64_t)value, value); + DPRINT("ctx i64 +%llu = %lld (%llX)\n", offset, (int64_t)value, value); } void TraceContextStoreF32(void* raw_context, uint64_t offset, __m128 value) { auto thread_state = *((ThreadState**)raw_context); - DPRINT("ctx f32 +%d = %e (%X)\n", offset, value.m128_i32[0], - value.m128_f32[0]); + DPRINT("ctx f32 +%llu = %e (%X)\n", offset, poly::m128_f32<0>(value), + poly::m128_i32<0>(value)); } void TraceContextStoreF64(void* raw_context, uint64_t offset, __m128 value) { auto thread_state = *((ThreadState**)raw_context); - union { - double d; - uint64_t x; - } f; - f.x = value.m128_i64[0]; - DPRINT("ctx f64 +%d = %lle (%llX)\n", offset, value.m128_i64[0], f.d); + DPRINT("ctx f64 +%llu = %le (%llX)\n", offset, poly::m128_f64<0>(value), + poly::m128_i64<0>(value)); } void TraceContextStoreV128(void* raw_context, uint64_t offset, __m128 value) { auto thread_state = *((ThreadState**)raw_context); - DPRINT("ctx v128 +%d = [%e, %e, %e, %e] [%.8X, %.8X, %.8X, %.8X]\n", offset, - value.m128_f32[0], value.m128_f32[1], value.m128_f32[2], - value.m128_f32[3], value.m128_i32[0], value.m128_i32[1], - value.m128_i32[2], value.m128_i32[3]); + DPRINT("ctx v128 +%llu = [%e, %e, %e, %e] [%.8X, %.8X, %.8X, %.8X]\n", offset, + poly::m128_f32<0>(value), poly::m128_f32<1>(value), + poly::m128_f32<2>(value), poly::m128_f32<3>(value), + poly::m128_i32<0>(value), poly::m128_i32<1>(value), + poly::m128_i32<2>(value), poly::m128_i32<3>(value)); } void TraceMemoryLoadI8(void* raw_context, uint64_t address, uint8_t value) { auto thread_state = *((ThreadState**)raw_context); - DPRINT("%d (%X) = load.i8 %.8X\n", (int8_t)value, value, address); + DPRINT("%d (%X) = load.i8 %.8llX\n", (int8_t)value, value, address); } void TraceMemoryLoadI16(void* raw_context, uint64_t address, uint16_t value) { auto thread_state = *((ThreadState**)raw_context); - DPRINT("%d (%X) = load.i16 %.8X\n", (int16_t)value, value, address); + DPRINT("%d (%X) = load.i16 %.8llX\n", (int16_t)value, value, address); } void TraceMemoryLoadI32(void* raw_context, uint64_t address, uint32_t value) { auto thread_state = *((ThreadState**)raw_context); - DPRINT("%d (%X) = load.i32 %.8X\n", (int32_t)value, value, address); + DPRINT("%d (%X) = load.i32 %.8llX\n", (int32_t)value, value, address); } void TraceMemoryLoadI64(void* raw_context, uint64_t address, uint64_t value) { auto thread_state = *((ThreadState**)raw_context); - DPRINT("%lld (%llX) = load.i64 %.8X\n", (int64_t)value, value, address); + DPRINT("%lld (%llX) = load.i64 %.8llX\n", (int64_t)value, value, address); } void TraceMemoryLoadF32(void* raw_context, uint64_t address, __m128 value) { auto thread_state = *((ThreadState**)raw_context); - DPRINT("%e (%X) = load.f32 %.8X\n", value.m128_f32[0], value.m128_i32[0], - address); + DPRINT("%e (%X) = load.f32 %.8llX\n", poly::m128_f32<0>(value), + poly::m128_i32<0>(value), address); } void TraceMemoryLoadF64(void* raw_context, uint64_t address, __m128 value) { auto thread_state = *((ThreadState**)raw_context); - union { - double d; - uint64_t x; - } f; - f.x = value.m128_i64[0]; - DPRINT("%lle (%llX) = load.f64 %.8X\n", f.d, value.m128_i64[0], address); + DPRINT("%le (%llX) = load.f64 %.8llX\n", poly::m128_f64<0>(value), + poly::m128_i64<0>(value), address); } void TraceMemoryLoadV128(void* raw_context, uint64_t address, __m128 value) { auto thread_state = *((ThreadState**)raw_context); - DPRINT("[%e, %e, %e, %e] [%.8X, %.8X, %.8X, %.8X] = load.v128 %.8X\n", - value.m128_f32[0], value.m128_f32[1], value.m128_f32[2], - value.m128_f32[3], value.m128_i32[0], value.m128_i32[1], - value.m128_i32[2], value.m128_i32[3], address); + DPRINT("[%e, %e, %e, %e] [%.8X, %.8X, %.8X, %.8X] = load.v128 %.8llX\n", + poly::m128_f32<0>(value), poly::m128_f32<1>(value), + poly::m128_f32<2>(value), poly::m128_f32<3>(value), + poly::m128_i32<0>(value), poly::m128_i32<1>(value), + poly::m128_i32<2>(value), poly::m128_i32<3>(value), address); } void TraceMemoryStoreI8(void* raw_context, uint64_t address, uint8_t value) { auto thread_state = *((ThreadState**)raw_context); - DPRINT("store.i8 %.8X = %d (%X)\n", address, (int8_t)value, value); + DPRINT("store.i8 %.8llX = %d (%X)\n", address, (int8_t)value, value); } void TraceMemoryStoreI16(void* raw_context, uint64_t address, uint16_t value) { auto thread_state = *((ThreadState**)raw_context); - DPRINT("store.i16 %.8X = %d (%X)\n", address, (int16_t)value, value); + DPRINT("store.i16 %.8llX = %d (%X)\n", address, (int16_t)value, value); } void TraceMemoryStoreI32(void* raw_context, uint64_t address, uint32_t value) { auto thread_state = *((ThreadState**)raw_context); - DPRINT("store.i32 %.8X = %d (%X)\n", address, (int32_t)value, value); + DPRINT("store.i32 %.8llX = %d (%X)\n", address, (int32_t)value, value); } void TraceMemoryStoreI64(void* raw_context, uint64_t address, uint64_t value) { auto thread_state = *((ThreadState**)raw_context); - DPRINT("store.i64 %.8X = %lld (%llX)\n", address, (int64_t)value, value); + DPRINT("store.i64 %.8llX = %lld (%llX)\n", address, (int64_t)value, value); } void TraceMemoryStoreF32(void* raw_context, uint64_t address, __m128 value) { auto thread_state = *((ThreadState**)raw_context); - DPRINT("store.f32 %.8X = %e (%X)\n", address, value.m128_f32[0], - value.m128_i32[0]); + DPRINT("store.f32 %.8llX = %e (%X)\n", address, poly::m128_f32<0>(value), + poly::m128_i32<0>(value)); } void TraceMemoryStoreF64(void* raw_context, uint64_t address, __m128 value) { auto thread_state = *((ThreadState**)raw_context); - union { - double d; - uint64_t x; - } f; - f.x = value.m128_i64[0]; - DPRINT("store.f64 %.8X = %lle (%llX)\n", address, f.d, value.m128_i64[0]); + DPRINT("store.f64 %.8llX = %le (%llX)\n", address, poly::m128_f64<0>(value), + poly::m128_i64<0>(value)); } void TraceMemoryStoreV128(void* raw_context, uint64_t address, __m128 value) { auto thread_state = *((ThreadState**)raw_context); - DPRINT("store.v128 %.8X = [%e, %e, %e, %e] [%.8X, %.8X, %.8X, %.8X]\n", - address, value.m128_f32[0], value.m128_f32[1], value.m128_f32[2], - value.m128_f32[3], value.m128_i32[0], value.m128_i32[1], - value.m128_i32[2], value.m128_i32[3]); + DPRINT("store.v128 %.8llX = [%e, %e, %e, %e] [%.8X, %.8X, %.8X, %.8X]\n", + address, poly::m128_f32<0>(value), poly::m128_f32<1>(value), + poly::m128_f32<2>(value), poly::m128_f32<3>(value), + poly::m128_i32<0>(value), poly::m128_i32<1>(value), + poly::m128_i32<2>(value), poly::m128_i32<3>(value)); } } // namespace x64 diff --git a/src/alloy/backend/x64/x64_tracers.h b/src/alloy/backend/x64/x64_tracers.h index 8151b4305..6ef29927b 100644 --- a/src/alloy/backend/x64/x64_tracers.h +++ b/src/alloy/backend/x64/x64_tracers.h @@ -12,21 +12,7 @@ #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 { namespace backend { diff --git a/src/alloy/compiler/passes/constant_propagation_pass.cc b/src/alloy/compiler/passes/constant_propagation_pass.cc index 9dcb8d3ec..d9f2b8620 100644 --- a/src/alloy/compiler/passes/constant_propagation_pass.cc +++ b/src/alloy/compiler/passes/constant_propagation_pass.cc @@ -430,6 +430,10 @@ int ConstantPropagationPass::Run(HIRBuilder* builder) { // Quite a few of these, from building vec128s. } break; + + default: + // Ignored. + break; } i = i->next; } diff --git a/src/alloy/compiler/passes/context_promotion_pass.cc b/src/alloy/compiler/passes/context_promotion_pass.cc index 2f14acd77..1b028464c 100644 --- a/src/alloy/compiler/passes/context_promotion_pass.cc +++ b/src/alloy/compiler/passes/context_promotion_pass.cc @@ -31,7 +31,7 @@ using alloy::hir::Instr; using alloy::hir::Value; ContextPromotionPass::ContextPromotionPass() - : context_values_size_(0), context_values_(0), CompilerPass() {} + : CompilerPass(), context_values_size_(0), context_values_(0) {} ContextPromotionPass::~ContextPromotionPass() { if (context_values_) { diff --git a/src/alloy/compiler/passes/data_flow_analysis_pass.cc b/src/alloy/compiler/passes/data_flow_analysis_pass.cc index 5c7fbdc89..4c82d527c 100644 --- a/src/alloy/compiler/passes/data_flow_analysis_pass.cc +++ b/src/alloy/compiler/passes/data_flow_analysis_pass.cc @@ -13,11 +13,15 @@ #include #include +#if XE_COMPILER_MSVC #pragma warning(push) #pragma warning(disable : 4244) #pragma warning(disable : 4267) #include #pragma warning(pop) +#else +#include +#endif // XE_COMPILER_MSVC namespace alloy { namespace compiler { diff --git a/src/alloy/compiler/passes/dead_code_elimination_pass.cc b/src/alloy/compiler/passes/dead_code_elimination_pass.cc index f18bfc26f..40f83bb3d 100644 --- a/src/alloy/compiler/passes/dead_code_elimination_pass.cc +++ b/src/alloy/compiler/passes/dead_code_elimination_pass.cc @@ -153,9 +153,9 @@ void DeadCodeEliminationPass::MakeNopRecursive(Instr* i) { #define MAKE_NOP_SRC(n) \ if (i->src##n##_use) { \ Value::Use* use = i->src##n##_use; \ - Value* value = i->src##n##.value; \ + Value* value = i->src##n.value; \ i->src##n##_use = NULL; \ - i->src##n##.value = NULL; \ + i->src##n.value = NULL; \ value->RemoveUse(use); \ if (!value->use_head) { \ /* Value is now unused, so recursively kill it. */ \ @@ -192,7 +192,6 @@ void DeadCodeEliminationPass::ReplaceAssignment(Instr* i) { } bool DeadCodeEliminationPass::CheckLocalUse(Instr* i) { - auto slot = i->src1.value; auto src = i->src2.value; auto use = src->use_head; diff --git a/src/alloy/compiler/passes/register_allocation_pass.cc b/src/alloy/compiler/passes/register_allocation_pass.cc index aa6fcf13c..26840a20f 100644 --- a/src/alloy/compiler/passes/register_allocation_pass.cc +++ b/src/alloy/compiler/passes/register_allocation_pass.cc @@ -29,7 +29,7 @@ using alloy::hir::Value; #define ASSERT_NO_CYCLES 0 RegisterAllocationPass::RegisterAllocationPass(const MachineInfo* machine_info) - : machine_info_(machine_info), CompilerPass() { + : CompilerPass() { // Initialize register sets. // TODO(benvanik): rewrite in a way that makes sense - this is terrible. auto mi_sets = machine_info->register_sets; @@ -301,11 +301,11 @@ bool RegisterAllocationPass::TryAllocateRegister(Value* value) { // Find the first free register, if any. // We have to ensure it's a valid one (in our count). - unsigned long first_unused = 0; - bool all_used = - _BitScanForward(&first_unused, usage_set->availability.to_ulong()) == 0; - if (!all_used && first_unused < usage_set->count) { - // Available! Use it!. + uint32_t first_unused = 0; + bool none_used = poly::bit_scan_forward( + static_cast(usage_set->availability.to_ulong()), &first_unused); + if (none_used && first_unused < usage_set->count) { + // Available! Use it! value->reg.set = usage_set->set; value->reg.index = first_unused; MarkRegUsed(value->reg, value, value->use_head); diff --git a/src/alloy/compiler/passes/register_allocation_pass.h b/src/alloy/compiler/passes/register_allocation_pass.h index 47b88cae0..70f212c08 100644 --- a/src/alloy/compiler/passes/register_allocation_pass.h +++ b/src/alloy/compiler/passes/register_allocation_pass.h @@ -69,7 +69,6 @@ class RegisterAllocationPass : public CompilerPass { void SortUsageList(hir::Value* value); private: - const backend::MachineInfo* machine_info_; struct { RegisterSetUsage* int_set = nullptr; RegisterSetUsage* float_set = nullptr; diff --git a/src/alloy/compiler/passes/validation_pass.cc b/src/alloy/compiler/passes/validation_pass.cc index 4ddb06cf2..a199e9416 100644 --- a/src/alloy/compiler/passes/validation_pass.cc +++ b/src/alloy/compiler/passes/validation_pass.cc @@ -33,11 +33,13 @@ ValidationPass::~ValidationPass() {} int ValidationPass::Run(HIRBuilder* builder) { SCOPE_profile_cpu_f("alloy"); +#if 0 StringBuffer str; builder->Dump(&str); printf(str.GetString()); fflush(stdout); str.Reset(); +#endif // 0 auto block = builder->first_block(); while (block) { diff --git a/src/alloy/compiler/passes/value_reduction_pass.cc b/src/alloy/compiler/passes/value_reduction_pass.cc index 94dbba0bb..4c5cf2e28 100644 --- a/src/alloy/compiler/passes/value_reduction_pass.cc +++ b/src/alloy/compiler/passes/value_reduction_pass.cc @@ -13,11 +13,15 @@ #include #include +#if XE_COMPILER_MSVC #pragma warning(push) #pragma warning(disable : 4244) #pragma warning(disable : 4267) #include #pragma warning(pop) +#else +#include +#endif // XE_COMPILER_MSVC namespace alloy { namespace compiler { diff --git a/src/alloy/core.h b/src/alloy/core.h index df3724e7b..b7f5dae91 100644 --- a/src/alloy/core.h +++ b/src/alloy/core.h @@ -13,6 +13,8 @@ // TODO(benvanik): move the common stuff into here? #include +#include + #include #include #include diff --git a/src/alloy/frontend/ppc/ppc_disasm.cc b/src/alloy/frontend/ppc/ppc_disasm.cc index 98f7a7746..c362cae2c 100644 --- a/src/alloy/frontend/ppc/ppc_disasm.cc +++ b/src/alloy/frontend/ppc/ppc_disasm.cc @@ -286,16 +286,9 @@ void Disasm_bcx(InstrData& i, StringBuffer* str) { } else { s1 = ""; } - char s2[8] = { - 'c', 'r', 0, - }; + char s2[8] = {0}; if (!XESELECTBITS(i.B.BO, 4, 4)) { - char* s2a = _itoa(i.B.BI >> 2, s2 + 2, 10); - s2a += xestrlena(s2a); - s2a[0] = ','; - s2a[1] = ' '; - } else { - s2[0] = 0; + xesnprintfa(s2, XECOUNT(s2), "cr%d, ", i.B.BI >> 2); } uint32_t nia; if (i.B.AA) { @@ -309,16 +302,9 @@ void Disasm_bcx(InstrData& i, StringBuffer* str) { void Disasm_bcctrx(InstrData& i, StringBuffer* str) { // TODO(benvanik): mnemonics const char* s0 = i.XL.LK ? "lr, " : ""; - char s2[8] = { - 'c', 'r', 0, - }; + char s2[8] = {0}; if (!XESELECTBITS(i.XL.BO, 4, 4)) { - char* s2a = _itoa(i.XL.BI >> 2, s2 + 2, 10); - s2a += xestrlena(s2a); - s2a[0] = ','; - s2a[1] = ' '; - } else { - s2[0] = 0; + xesnprintfa(s2, XECOUNT(s2), "cr%d, ", i.XL.BI >> 2); } str->Append("%-8s %s%sctr", i.type->name, s0, s2); // TODO(benvanik): resolve target name? @@ -334,16 +320,9 @@ void Disasm_bclrx(InstrData& i, StringBuffer* str) { } else { s1 = ""; } - char s2[8] = { - 'c', 'r', 0, - }; + char s2[8] = {0}; if (!XESELECTBITS(i.XL.BO, 4, 4)) { - char* s2a = _itoa(i.XL.BI >> 2, s2 + 2, 10); - s2a += xestrlena(s2a); - s2a[0] = ','; - s2a[1] = ' '; - } else { - s2[0] = 0; + xesnprintfa(s2, XECOUNT(s2), "cr%d, ", i.XL.BI >> 2); } str->Append("%-8s %s%s", name, s1, s2); } diff --git a/src/alloy/frontend/ppc/ppc_emit_altivec.cc b/src/alloy/frontend/ppc/ppc_emit_altivec.cc index 9b0a845c5..583e1c00b 100644 --- a/src/alloy/frontend/ppc/ppc_emit_altivec.cc +++ b/src/alloy/frontend/ppc/ppc_emit_altivec.cc @@ -588,7 +588,7 @@ int InstrEmit_vcmpxxfp_(PPCHIRBuilder& f, InstrData& i, vcmpxxfp_op cmpop, v = f.VectorCompareSGE(f.LoadVR(va), f.LoadVR(vb), FLOAT32_TYPE); break; default: - XEASSERTALWAYS(); + XEASSERTUNHANDLEDCASE(cmpop); return 1; } if (rc) { @@ -648,7 +648,7 @@ int InstrEmit_vcmpxxi_(PPCHIRBuilder& f, InstrData& i, vcmpxxi_op cmpop, v = f.VectorCompareEQ(f.LoadVR(va), f.LoadVR(vb), INT32_TYPE); break; default: - XEASSERTALWAYS(); + XEASSERTUNHANDLEDCASE(width); return 1; } break; @@ -664,7 +664,7 @@ int InstrEmit_vcmpxxi_(PPCHIRBuilder& f, InstrData& i, vcmpxxi_op cmpop, v = f.VectorCompareSGT(f.LoadVR(va), f.LoadVR(vb), INT32_TYPE); break; default: - XEASSERTALWAYS(); + XEASSERTUNHANDLEDCASE(width); return 1; } break; @@ -680,12 +680,12 @@ int InstrEmit_vcmpxxi_(PPCHIRBuilder& f, InstrData& i, vcmpxxi_op cmpop, v = f.VectorCompareUGT(f.LoadVR(va), f.LoadVR(vb), INT32_TYPE); break; default: - XEASSERTALWAYS(); + XEASSERTUNHANDLEDCASE(width); return 1; } break; default: - XEASSERTALWAYS(); + XEASSERTUNHANDLEDCASE(cmpop); return 1; } if (rc) { @@ -1117,7 +1117,7 @@ XEEMITTER(vpermwi128, VX128_P(6, 528), VX128_P)(PPCHIRBuilder& f, int InstrEmit_vrefp_(PPCHIRBuilder& f, uint32_t vd, uint32_t vb) { // (VD) <- 1/(VB) - vec128_t one = {1, 1, 1, 1}; + vec128_t one = {{{1, 1, 1, 1}}}; Value* v = f.Div(f.LoadConstant(one), f.LoadVR(vb)); f.StoreVR(vd, v); return 0; @@ -1784,7 +1784,7 @@ XEEMITTER(vpkd3d128, VX128_4(6, 1552), VX128_4)(PPCHIRBuilder& f, v = f.Pack(v, PACK_TYPE_FLOAT16_4); break; default: - XEASSERTALWAYS(); + XEASSERTUNHANDLEDCASE(type); return 1; } // http://hlssmod.net/he_code/public/pixelwriter.h @@ -1819,7 +1819,7 @@ XEEMITTER(vpkd3d128, VX128_4(6, 1552), VX128_4)(PPCHIRBuilder& f, control = (control & ~mask) | (src & mask); break; default: - XEASSERTALWAYS(); + XEASSERTUNHANDLEDCASE(pack); return 1; } v = f.Permute(f.LoadConstant(control), f.LoadVR(vd), v, INT32_TYPE); @@ -1851,7 +1851,7 @@ XEEMITTER(vupkd3d128, VX128_3(6, 2032), VX128_3)(PPCHIRBuilder& f, v = f.Unpack(v, PACK_TYPE_FLOAT16_4); break; default: - XEASSERTALWAYS(); + XEASSERTUNHANDLEDCASE(type); return 1; } f.StoreVR(vd, v); diff --git a/src/alloy/frontend/ppc/ppc_hir_builder.cc b/src/alloy/frontend/ppc/ppc_hir_builder.cc index 4b81401dd..1d737917f 100644 --- a/src/alloy/frontend/ppc/ppc_hir_builder.cc +++ b/src/alloy/frontend/ppc/ppc_hir_builder.cc @@ -32,7 +32,7 @@ using alloy::runtime::Runtime; using alloy::runtime::FunctionInfo; PPCHIRBuilder::PPCHIRBuilder(PPCFrontend* frontend) - : frontend_(frontend), HIRBuilder() { + : HIRBuilder(), frontend_(frontend) { comment_buffer_ = new StringBuffer(4096); } @@ -88,8 +88,6 @@ int PPCHIRBuilder::Emit(FunctionInfo* symbol_info, bool with_debug_info) { // TODO(benvanik): find a way to avoid using the opcode tables. i.type = GetInstrType(i.code); - Instr* prev_instr = last_instr(); - // Mark label, if we were assigned one earlier on in the walk. // We may still get a label, but it'll be inserted by LookupLabel // as needed. @@ -120,7 +118,7 @@ int PPCHIRBuilder::Emit(FunctionInfo* symbol_info, bool with_debug_info) { instr_offset_list_[offset] = first_instr; if (!i.type) { - XELOGCPU("Invalid instruction %.8X %.8X", i.address, i.code); + XELOGCPU("Invalid instruction %.8llX %.8X", i.address, i.code); Comment("INVALID!"); // TraceInvalidInstruction(i); continue; @@ -135,7 +133,7 @@ int PPCHIRBuilder::Emit(FunctionInfo* symbol_info, bool with_debug_info) { } if (!i.type->emit || emit(*this, i)) { - XELOGCPU("Unimplemented instr %.8X %.8X %s", i.address, i.code, + XELOGCPU("Unimplemented instr %.8llX %.8X %s", i.address, i.code, i.type->name); Comment("UNIMPLEMENTED!"); // DebugBreak(); diff --git a/src/alloy/frontend/ppc/ppc_instr.cc b/src/alloy/frontend/ppc/ppc_instr.cc index 83647dfe7..c7029158a 100644 --- a/src/alloy/frontend/ppc/ppc_instr.cc +++ b/src/alloy/frontend/ppc/ppc_instr.cc @@ -146,7 +146,7 @@ void InstrAccessBits::MarkAccess(InstrRegister& reg) { } break; default: - XEASSERTALWAYS(); + XEASSERTUNHANDLEDCASE(reg.set); break; } } diff --git a/src/alloy/hir/block.cc b/src/alloy/hir/block.cc index 60e9f988d..66160338f 100644 --- a/src/alloy/hir/block.cc +++ b/src/alloy/hir/block.cc @@ -20,7 +20,7 @@ void Block::AssertNoCycles() { if (!hare) { return; } - while (hare = hare->next) { + while ((hare = hare->next)) { if (hare == tortoise) { // Cycle! XEASSERTALWAYS(); diff --git a/src/alloy/hir/hir_builder.cc b/src/alloy/hir/hir_builder.cc index 3cd66c157..d25aaac23 100644 --- a/src/alloy/hir/hir_builder.cc +++ b/src/alloy/hir/hir_builder.cc @@ -273,7 +273,7 @@ void HIRBuilder::AssertNoCycles() { if (!hare) { return; } - while (hare = hare->next) { + while ((hare = hare->next)) { if (hare == tortoise) { // Cycle! XEASSERTALWAYS(); diff --git a/src/alloy/hir/value.cc b/src/alloy/hir/value.cc index 3d78c407b..41c162080 100644 --- a/src/alloy/hir/value.cc +++ b/src/alloy/hir/value.cc @@ -47,7 +47,7 @@ uint32_t Value::AsUint32() { case INT64_TYPE: return (uint32_t)constant.i64; default: - XEASSERTALWAYS(); + XEASSERTUNHANDLEDCASE(type); return 0; } } @@ -64,7 +64,7 @@ uint64_t Value::AsUint64() { case INT64_TYPE: return constant.i64; default: - XEASSERTALWAYS(); + XEASSERTUNHANDLEDCASE(type); return 0; } } @@ -88,9 +88,10 @@ void Value::ZeroExtend(TypeName target_type) { type = target_type; constant.i64 = constant.i64 & 0xFFFFFFFF; return; + default: + XEASSERTUNHANDLEDCASE(type); + break; } - // Unsupported types. - XEASSERTALWAYS(); } void Value::SignExtend(TypeName target_type) { @@ -100,37 +101,44 @@ void Value::SignExtend(TypeName target_type) { switch (target_type) { case INT16_TYPE: constant.i16 = constant.i8; - break; + return; case INT32_TYPE: constant.i32 = constant.i8; - break; + return; case INT64_TYPE: constant.i64 = constant.i8; - break; + return; + default: + XEASSERTUNHANDLEDCASE(target_type); + return; } - return; case INT16_TYPE: type = target_type; switch (target_type) { case INT32_TYPE: constant.i32 = constant.i16; - break; + return; case INT64_TYPE: constant.i64 = constant.i16; - break; + return; + default: + XEASSERTUNHANDLEDCASE(target_type); + return; } - return; case INT32_TYPE: type = target_type; switch (target_type) { case INT64_TYPE: constant.i64 = constant.i32; - break; + return; + default: + XEASSERTUNHANDLEDCASE(target_type); + return; } + default: + XEASSERTUNHANDLEDCASE(); return; } - // Unsupported types. - XEASSERTALWAYS(); } void Value::Truncate(TypeName target_type) { @@ -141,8 +149,10 @@ void Value::Truncate(TypeName target_type) { type = target_type; constant.i64 = constant.i64 & 0xFF; return; + default: + XEASSERTUNHANDLEDCASE(target_type); + return; } - break; case INT32_TYPE: switch (target_type) { case INT8_TYPE: @@ -153,8 +163,10 @@ void Value::Truncate(TypeName target_type) { type = target_type; constant.i64 = constant.i64 & 0xFFFF; return; + default: + XEASSERTUNHANDLEDCASE(target_type); + return; } - break; case INT64_TYPE: switch (target_type) { case INT8_TYPE: @@ -169,11 +181,14 @@ void Value::Truncate(TypeName target_type) { type = target_type; constant.i64 = constant.i64 & 0xFFFFFFFF; return; + default: + XEASSERTUNHANDLEDCASE(target_type); + return; } - break; + default: + XEASSERTUNHANDLEDCASE(type); + return; } - // Unsupported types. - XEASSERTALWAYS(); } void Value::Convert(TypeName target_type, RoundMode round_mode) { @@ -215,7 +230,7 @@ bool Value::Add(Value* other) { constant.f64 += other->constant.f64; break; default: - XEASSERTALWAYS(); + XEASSERTUNHANDLEDCASE(type); break; } return did_carry; @@ -249,7 +264,7 @@ bool Value::Sub(Value* other) { constant.f64 -= other->constant.f64; break; default: - XEASSERTALWAYS(); + XEASSERTUNHANDLEDCASE(type); break; } return did_carry; @@ -277,7 +292,7 @@ void Value::Mul(Value* other) { constant.f64 *= other->constant.f64; break; default: - XEASSERTALWAYS(); + XEASSERTUNHANDLEDCASE(type); break; } } @@ -304,7 +319,7 @@ void Value::Div(Value* other) { constant.f64 /= other->constant.f64; break; default: - XEASSERTALWAYS(); + XEASSERTUNHANDLEDCASE(type); break; } } @@ -340,7 +355,7 @@ void Value::Neg() { constant.f64 = -constant.f64; break; default: - XEASSERTALWAYS(); + XEASSERTUNHANDLEDCASE(type); break; } } @@ -366,7 +381,7 @@ void Value::Abs() { constant.f64 = abs(constant.f64); break; default: - XEASSERTALWAYS(); + XEASSERTUNHANDLEDCASE(type); break; } } @@ -380,7 +395,7 @@ void Value::Sqrt() { constant.f64 = 1.0 / sqrt(constant.f64); break; default: - XEASSERTALWAYS(); + XEASSERTUNHANDLEDCASE(type); break; } } @@ -394,7 +409,7 @@ void Value::RSqrt() { constant.f64 = sqrt(constant.f64); break; default: - XEASSERTALWAYS(); + XEASSERTUNHANDLEDCASE(type); break; } } @@ -415,7 +430,7 @@ void Value::And(Value* other) { constant.i64 &= other->constant.i64; break; default: - XEASSERTALWAYS(); + XEASSERTUNHANDLEDCASE(type); break; } } @@ -436,7 +451,7 @@ void Value::Or(Value* other) { constant.i64 |= other->constant.i64; break; default: - XEASSERTALWAYS(); + XEASSERTUNHANDLEDCASE(type); break; } } @@ -457,7 +472,7 @@ void Value::Xor(Value* other) { constant.i64 ^= other->constant.i64; break; default: - XEASSERTALWAYS(); + XEASSERTUNHANDLEDCASE(type); break; } } @@ -481,7 +496,7 @@ void Value::Not() { constant.v128.high = ~constant.v128.high; break; default: - XEASSERTALWAYS(); + XEASSERTUNHANDLEDCASE(type); break; } } @@ -502,7 +517,7 @@ void Value::Shl(Value* other) { constant.i64 <<= other->constant.i8; break; default: - XEASSERTALWAYS(); + XEASSERTUNHANDLEDCASE(type); break; } } @@ -523,7 +538,7 @@ void Value::Shr(Value* other) { constant.i64 = (uint16_t)constant.i64 >> other->constant.i8; break; default: - XEASSERTALWAYS(); + XEASSERTUNHANDLEDCASE(type); break; } } @@ -544,7 +559,7 @@ void Value::Sha(Value* other) { constant.i64 = constant.i64 >> other->constant.i8; break; default: - XEASSERTALWAYS(); + XEASSERTUNHANDLEDCASE(type); break; } } @@ -569,7 +584,7 @@ void Value::ByteSwap() { } break; default: - XEASSERTALWAYS(); + XEASSERTUNHANDLEDCASE(type); break; } } @@ -577,19 +592,19 @@ void Value::ByteSwap() { void Value::CountLeadingZeros(const Value* other) { switch (other->type) { case INT8_TYPE: - constant.i8 = static_cast(__lzcnt16(other->constant.i8) - 8); + constant.i8 = poly::lzcnt(constant.i8); break; case INT16_TYPE: - constant.i8 = static_cast(__lzcnt16(other->constant.i16)); + constant.i8 = poly::lzcnt(constant.i16); break; case INT32_TYPE: - constant.i8 = static_cast(__lzcnt(other->constant.i32)); + constant.i8 = poly::lzcnt(constant.i32); break; case INT64_TYPE: - constant.i8 = static_cast(__lzcnt64(other->constant.i64)); + constant.i8 = poly::lzcnt(constant.i64); break; default: - XEASSERTALWAYS(); + XEASSERTUNHANDLEDCASE(type); break; } } diff --git a/src/alloy/hir/value.h b/src/alloy/hir/value.h index edde60c67..eb87a983f 100644 --- a/src/alloy/hir/value.h +++ b/src/alloy/hir/value.h @@ -31,11 +31,6 @@ enum TypeName { MAX_TYPENAME, }; -static bool IsIntType(TypeName type_name) { return type_name <= INT64_TYPE; } -static bool IsFloatType(TypeName type_name) { - return type_name == FLOAT32_TYPE || type_name == FLOAT64_TYPE; -} -static bool IsVecType(TypeName type_name) { return type_name == VEC128_TYPE; } static size_t GetTypeSize(TypeName type_name) { switch (type_name) { case INT8_TYPE: @@ -50,9 +45,11 @@ static size_t GetTypeSize(TypeName type_name) { return 4; case FLOAT64_TYPE: return 8; - default: case VEC128_TYPE: return 16; + default: + XEASSERTUNHANDLEDCASE(type_name); + break; } } diff --git a/src/alloy/runtime/debugger.h b/src/alloy/runtime/debugger.h index 5eb399a0f..40eb93d04 100644 --- a/src/alloy/runtime/debugger.h +++ b/src/alloy/runtime/debugger.h @@ -62,9 +62,9 @@ class BreakpointHitEvent : public DebugEvent { public: BreakpointHitEvent(Debugger* debugger, ThreadState* thread_state, Breakpoint* breakpoint) - : thread_state_(thread_state), - breakpoint_(breakpoint), - DebugEvent(debugger) {} + : DebugEvent(debugger), + thread_state_(thread_state), + breakpoint_(breakpoint) {} virtual ~BreakpointHitEvent() {} ThreadState* thread_state() const { return thread_state_; } Breakpoint* breakpoint() const { return breakpoint_; } diff --git a/src/alloy/runtime/function.cc b/src/alloy/runtime/function.cc index 6b1125681..974b50eaa 100644 --- a/src/alloy/runtime/function.cc +++ b/src/alloy/runtime/function.cc @@ -81,7 +81,7 @@ int Function::Call(ThreadState* thread_state, uint64_t return_address) { handler(thread_state->raw_context(), symbol_info_->extern_arg0(), symbol_info_->extern_arg1()); } else { - XELOGW("undefined extern call to %.8X %s", symbol_info_->address(), + XELOGW("undefined extern call to %.8llX %s", symbol_info_->address(), symbol_info_->name()); result = 1; } diff --git a/src/alloy/runtime/instrument.cc b/src/alloy/runtime/instrument.cc index 87bdcec78..3466d7cd5 100644 --- a/src/alloy/runtime/instrument.cc +++ b/src/alloy/runtime/instrument.cc @@ -44,7 +44,7 @@ bool Instrument::Detach() { } FunctionInstrument::FunctionInstrument(Runtime* runtime, Function* function) - : target_(function), Instrument(runtime) {} + : Instrument(runtime), target_(function) {} bool FunctionInstrument::Attach() { if (!Instrument::Attach()) { @@ -81,7 +81,7 @@ void FunctionInstrument::Exit(ThreadState* thread_state) { MemoryInstrument::MemoryInstrument(Runtime* runtime, uint64_t address, uint64_t end_address) - : address_(address), end_address_(end_address), Instrument(runtime) {} + : Instrument(runtime), address_(address), end_address_(end_address) {} bool MemoryInstrument::Attach() { if (!Instrument::Attach()) { diff --git a/src/alloy/runtime/raw_module.cc b/src/alloy/runtime/raw_module.cc index 32346bc1a..43df9f67a 100644 --- a/src/alloy/runtime/raw_module.cc +++ b/src/alloy/runtime/raw_module.cc @@ -13,11 +13,11 @@ namespace alloy { namespace runtime { RawModule::RawModule(Runtime* runtime) - : name_(0), + : Module(runtime), + name_(0), base_address_(0), low_address_(0), - high_address_(0), - Module(runtime) {} + high_address_(0) {} RawModule::~RawModule() { if (base_address_) { diff --git a/src/alloy/runtime/runtime.cc b/src/alloy/runtime/runtime.cc index 233dc0c07..5d8f4bc23 100644 --- a/src/alloy/runtime/runtime.cc +++ b/src/alloy/runtime/runtime.cc @@ -27,7 +27,7 @@ using alloy::backend::Backend; using alloy::frontend::Frontend; Runtime::Runtime(Memory* memory) - : memory_(memory), debugger_(0), backend_(0), frontend_(0) { + : memory_(memory), debugger_(0), frontend_(0), backend_(0) { tracing::Initialize(); } diff --git a/src/alloy/runtime/symbol_info.cc b/src/alloy/runtime/symbol_info.cc index 7e060ff7f..2392cc452 100644 --- a/src/alloy/runtime/symbol_info.cc +++ b/src/alloy/runtime/symbol_info.cc @@ -14,8 +14,8 @@ namespace runtime { SymbolInfo::SymbolInfo(Type type, Module* module, uint64_t address) : type_(type), - status_(STATUS_DEFINING), module_(module), + status_(STATUS_DEFINING), address_(address), name_(0) {} @@ -33,10 +33,10 @@ void SymbolInfo::set_name(const char* name) { } FunctionInfo::FunctionInfo(Module* module, uint64_t address) - : end_address_(0), + : SymbolInfo(SymbolInfo::TYPE_FUNCTION, module, address), + end_address_(0), behavior_(BEHAVIOR_DEFAULT), - function_(0), - SymbolInfo(SymbolInfo::TYPE_FUNCTION, module, address) { + function_(0) { xe_zero_struct(&extern_info_, sizeof(extern_info_)); } diff --git a/src/alloy/runtime/thread_state.cc b/src/alloy/runtime/thread_state.cc index 828863fc5..cfe153bd6 100644 --- a/src/alloy/runtime/thread_state.cc +++ b/src/alloy/runtime/thread_state.cc @@ -14,7 +14,7 @@ namespace alloy { namespace runtime { -__declspec(thread) ThreadState* thread_state_ = NULL; +thread_local ThreadState* thread_state_ = NULL; ThreadState::ThreadState(Runtime* runtime, uint32_t thread_id) : runtime_(runtime), diff --git a/src/alloy/tracing/tracing.cc b/src/alloy/tracing/tracing.cc index 16c7eaf75..ace0d54a9 100644 --- a/src/alloy/tracing/tracing.cc +++ b/src/alloy/tracing/tracing.cc @@ -25,7 +25,7 @@ namespace alloy { namespace tracing { Channel* shared_channel = NULL; -__declspec(thread) Tracer* thread_tracer = NULL; +thread_local Tracer* thread_tracer = NULL; void CleanupTracing() { if (shared_channel) { diff --git a/src/poly/cxx_compat.h b/src/poly/cxx_compat.h new file mode 100644 index 000000000..88d647aa5 --- /dev/null +++ b/src/poly/cxx_compat.h @@ -0,0 +1,25 @@ +/** + ****************************************************************************** + * Xenia : Xbox 360 Emulator Research Project * + ****************************************************************************** + * Copyright 2014 Ben Vanik. All rights reserved. * + * Released under the BSD license - see LICENSE in the root for more details. * + ****************************************************************************** + */ + +#ifndef POLY_POLY_CXX_COMPAT_H_ +#define POLY_POLY_CXX_COMPAT_H_ + +// C++11 thread local storage. +// http://en.cppreference.com/w/cpp/language/storage_duration +#if XE_COMPILER_MSVC +// VC++2014 may have this. +#define thread_local __declspec(thread) +#elif XE_LIKE_OSX +// Clang supports it on OSX but the runtime doesn't. +#define thread_local __thread +#endif // XE_COMPILER_MSVC + +namespace poly {} // namespace poly + +#endif // POLY_POLY_CXX_COMPAT_H_ diff --git a/src/poly/math.h b/src/poly/math.h new file mode 100644 index 000000000..d332191b5 --- /dev/null +++ b/src/poly/math.h @@ -0,0 +1,104 @@ +/** + ****************************************************************************** + * Xenia : Xbox 360 Emulator Research Project * + ****************************************************************************** + * Copyright 2014 Ben Vanik. All rights reserved. * + * Released under the BSD license - see LICENSE in the root for more details. * + ****************************************************************************** + */ + +#ifndef POLY_MATH_H_ +#define POLY_MATH_H_ + +#include + +#include +#include + +namespace poly { + +// lzcnt instruction, typed for integers of all sizes. +// The number of leading zero bits in the value parameter. If value is zero, the +// return value is the size of the input operand (8, 16, 32, or 64). If the most +// significant bit of value is one, the return value is zero. +#if XE_COMPILER_MSVC +uint8_t lzcnt(uint8_t v) { return static_cast(__lzcnt16(v) - 8); } +uint8_t lzcnt(uint16_t v) { return static_cast(__lzcnt16(v)); } +uint8_t lzcnt(uint32_t v) { return static_cast(__lzcnt(v)); } +uint8_t lzcnt(uint64_t v) { return static_cast(__lzcnt64(v)); } +#else +uint8_t lzcnt(uint8_t v) { return static_cast(__builtin_clzs(v) - 8); } +uint8_t lzcnt(uint16_t v) { return static_cast(__builtin_clzs(v)); } +uint8_t lzcnt(uint32_t v) { return static_cast(__builtin_clz(v)); } +uint8_t lzcnt(uint64_t v) { return static_cast(__builtin_clzll(v)); } +#endif // XE_COMPILER_MSVC +uint8_t lzcnt(int8_t v) { return lzcnt(static_cast(v)); } +uint8_t lzcnt(int16_t v) { return lzcnt(static_cast(v)); } +uint8_t lzcnt(int32_t v) { return lzcnt(static_cast(v)); } +uint8_t lzcnt(int64_t v) { return lzcnt(static_cast(v)); } + +// BitScanForward (bsf). +// Search the value from least significant bit (LSB) to the most significant bit +// (MSB) for a set bit (1). +// Returns false if no bits are set and the output index is invalid. +#if XE_COMPILER_MSVC +bool bit_scan_forward(uint32_t v, uint32_t* out_first_set_index) { + return _BitScanForward(out_first_set_index, v) != 0; +} +bool bit_scan_forward(uint64_t v, uint32_t* out_first_set_index) { + return _BitScanForward64(out_first_set_index, v) != 0; +} +#else +bool bit_scan_forward(uint32_t v, uint32_t* out_first_set_index) { + int i = ffs(v); + *out_first_set_index = i; + return i != 0; +} +bool bit_scan_forward(uint64_t v, uint32_t* out_first_set_index) { + int i = ffsll(v); + *out_first_set_index = i; + return i != 0; +} +#endif // XE_COMPILER_MSVC +bool bit_scan_forward(int32_t v, uint32_t* out_first_set_index) { + return bit_scan_forward(static_cast(v), out_first_set_index); +} +bool bit_scan_forward(int64_t v, uint32_t* out_first_set_index) { + return bit_scan_forward(static_cast(v), out_first_set_index); +} + +// Utilities for SSE values. +template +float m128_f32(const __m128& v) { + float ret; + _mm_store_ss(&ret, _mm_shuffle_ps(v, v, _MM_SHUFFLE(N, N, N, N))); + return ret; +} +template +int32_t m128_i32(const __m128& v) { + union { + float f; + int32_t i; + } ret; + _mm_store_ss(&ret.f, _mm_shuffle_ps(v, v, _MM_SHUFFLE(N, N, N, N))); + return ret.i; +} +template +double m128_f64(const __m128& v) { + double ret; + _mm_store_sd(&ret, _mm_shuffle_ps(v, v, _MM_SHUFFLE(N, N, N, N))); + return ret; +} +template +int64_t m128_i64(const __m128& v) { + union { + double f; + int64_t i; + } ret; + _mm_store_sd(&ret.f, _mm_shuffle_ps(v, v, _MM_SHUFFLE(N, N, N, N))); + return ret.i; +} + +} // namespace poly + +#endif // POLY_MATH_H_ diff --git a/src/poly/poly.h b/src/poly/poly.h index f6e6eb97b..e9b10a17b 100644 --- a/src/poly/poly.h +++ b/src/poly/poly.h @@ -10,6 +10,9 @@ #ifndef POLY_POLY_H_ #define POLY_POLY_H_ +#include +#include + namespace poly {} // namespace poly #endif // POLY_POLY_H_ diff --git a/src/poly/sources.gypi b/src/poly/sources.gypi index 91b1b6c4f..d19d26fdd 100644 --- a/src/poly/sources.gypi +++ b/src/poly/sources.gypi @@ -1,6 +1,8 @@ # Copyright 2014 Ben Vanik. All Rights Reserved. { 'sources': [ + 'cxx_compat.h', + 'math.h', 'poly-private.h', 'poly.cc', 'poly.h', diff --git a/src/xenia/assert.h b/src/xenia/assert.h index 8215bd549..05803a62a 100644 --- a/src/xenia/assert.h +++ b/src/xenia/assert.h @@ -52,6 +52,7 @@ #define XEASSERTNOTZERO(expr) XEASSERTCORE( (expr) != 0 ) #define XEASSERTNULL(expr) XEASSERTCORE( (expr) == NULL ) #define XEASSERTNOTNULL(expr) XEASSERTCORE( (expr) != NULL ) +#define XEASSERTUNHANDLEDCASE(var) XEASSERTALWAYS() #if XE_COMPILER_MSVC diff --git a/src/xenia/kernel/xboxkrnl_modules.cc b/src/xenia/kernel/xboxkrnl_modules.cc index 222517882..319cc0ec2 100644 --- a/src/xenia/kernel/xboxkrnl_modules.cc +++ b/src/xenia/kernel/xboxkrnl_modules.cc @@ -43,7 +43,7 @@ X_STATUS xeExGetXConfigSetting( value = 0x00001000; // USA/Canada break; default: - XEASSERTALWAYS(); + XEASSERTUNHANDLEDCASE(setting); return X_STATUS_INVALID_PARAMETER_2; } break; @@ -80,12 +80,12 @@ X_STATUS xeExGetXConfigSetting( value = 0; break; default: - XEASSERTALWAYS(); + XEASSERTUNHANDLEDCASE(setting); return X_STATUS_INVALID_PARAMETER_2; } break; default: - XEASSERTALWAYS(); + XEASSERTUNHANDLEDCASE(category); return X_STATUS_INVALID_PARAMETER_1; }