From 1ecb318bcca6dc0120316dcd6d5a0f5aa69c55bd Mon Sep 17 00:00:00 2001 From: Rohit Nirmal Date: Sat, 6 Sep 2014 01:23:05 -0500 Subject: [PATCH 1/2] Fix some formatting (new lines on collapsed single-line conditionals, new lines for opening braces). --- Source/Core/Common/x64Emitter.cpp | 72 ++++++++++++++++++--------- Source/Core/Core/ArmMemTools.cpp | 9 ++-- Source/Core/Core/PowerPC/GDBStub.cpp | 36 +++++++++----- Source/Core/Core/PowerPC/PPCCache.cpp | 6 ++- 4 files changed, 82 insertions(+), 41 deletions(-) diff --git a/Source/Core/Common/x64Emitter.cpp b/Source/Core/Common/x64Emitter.cpp index da8363d314..02ffdea5ce 100644 --- a/Source/Core/Common/x64Emitter.cpp +++ b/Source/Core/Common/x64Emitter.cpp @@ -582,14 +582,16 @@ void XEmitter::SFENCE() {Write8(0x0F); Write8(0xAE); Write8(0xF8);} void XEmitter::WriteSimple1Byte(int bits, u8 byte, X64Reg reg) { - if (bits == 16) {Write8(0x66);} + if (bits == 16) + Write8(0x66); Rex(bits == 64, 0, 0, (int)reg >> 3); Write8(byte + ((int)reg & 7)); } void XEmitter::WriteSimple2Byte(int bits, u8 byte1, u8 byte2, X64Reg reg) { - if (bits == 16) {Write8(0x66);} + if (bits == 16) + Write8(0x66); Rex(bits==64, 0, 0, (int)reg >> 3); Write8(byte1); Write8(byte2 + ((int)reg & 7)); @@ -597,14 +599,16 @@ void XEmitter::WriteSimple2Byte(int bits, u8 byte1, u8 byte2, X64Reg reg) void XEmitter::CWD(int bits) { - if (bits == 16) {Write8(0x66);} + if (bits == 16) + Write8(0x66); Rex(bits == 64, 0, 0, 0); Write8(0x99); } void XEmitter::CBW(int bits) { - if (bits == 8) {Write8(0x66);} + if (bits == 8) + Write8(0x66); Rex(bits == 32, 0, 0, 0); Write8(0x98); } @@ -690,7 +694,8 @@ void XEmitter::UD2() void XEmitter::PREFETCH(PrefetchLevel level, OpArg arg) { - if (arg.IsImm()) _assert_msg_(DYNA_REC, 0, "PREFETCH - Imm argument");; + if (arg.IsImm()) + _assert_msg_(DYNA_REC, 0, "PREFETCH - Imm argument"); arg.operandReg = (u8)level; arg.WriteRex(this, 0, 0); Write8(0x0F); @@ -700,7 +705,8 @@ void XEmitter::PREFETCH(PrefetchLevel level, OpArg arg) void XEmitter::SETcc(CCFlags flag, OpArg dest) { - if (dest.IsImm()) _assert_msg_(DYNA_REC, 0, "SETcc - Imm argument"); + if (dest.IsImm()) + _assert_msg_(DYNA_REC, 0, "SETcc - Imm argument"); dest.operandReg = 0; dest.WriteRex(this, 0, 8); Write8(0x0F); @@ -710,9 +716,12 @@ void XEmitter::SETcc(CCFlags flag, OpArg dest) void XEmitter::CMOVcc(int bits, X64Reg dest, OpArg src, CCFlags flag) { - if (src.IsImm()) _assert_msg_(DYNA_REC, 0, "CMOVcc - Imm argument"); - if (bits == 8) _assert_msg_(DYNA_REC, 0, "CMOVcc - 8 bits unsupported"); - if (bits == 16) Write8(0x66); + if (src.IsImm()) + _assert_msg_(DYNA_REC, 0, "CMOVcc - Imm argument"); + if (bits == 8) + _assert_msg_(DYNA_REC, 0, "CMOVcc - 8 bits unsupported"); + if (bits == 16) + Write8(0x66); src.operandReg = dest; src.WriteRex(this, bits, bits); Write8(0x0F); @@ -722,9 +731,11 @@ void XEmitter::CMOVcc(int bits, X64Reg dest, OpArg src, CCFlags flag) void XEmitter::WriteMulDivType(int bits, OpArg src, int ext) { - if (src.IsImm()) _assert_msg_(DYNA_REC, 0, "WriteMulDivType - Imm argument"); + if (src.IsImm()) + _assert_msg_(DYNA_REC, 0, "WriteMulDivType - Imm argument"); src.operandReg = ext; - if (bits == 16) Write8(0x66); + if (bits == 16) + Write8(0x66); src.WriteRex(this, bits, bits, 0); if (bits == 8) { @@ -746,9 +757,11 @@ void XEmitter::NOT(int bits, OpArg src) {WriteMulDivType(bits, src, 2);} void XEmitter::WriteBitSearchType(int bits, X64Reg dest, OpArg src, u8 byte2) { - if (src.IsImm()) _assert_msg_(DYNA_REC, 0, "WriteBitSearchType - Imm argument"); + if (src.IsImm()) + _assert_msg_(DYNA_REC, 0, "WriteBitSearchType - Imm argument"); src.operandReg = (u8)dest; - if (bits == 16) Write8(0x66); + if (bits == 16) + Write8(0x66); src.WriteRex(this, bits, bits); Write8(0x0F); Write8(byte2); @@ -757,7 +770,8 @@ void XEmitter::WriteBitSearchType(int bits, X64Reg dest, OpArg src, u8 byte2) void XEmitter::MOVNTI(int bits, OpArg dest, X64Reg src) { - if (bits <= 16) _assert_msg_(DYNA_REC, 0, "MOVNTI - bits<=16"); + if (bits <= 16) + _assert_msg_(DYNA_REC, 0, "MOVNTI - bits<=16"); WriteBitSearchType(bits, src, dest, 0xC3); } @@ -766,14 +780,16 @@ void XEmitter::BSR(int bits, X64Reg dest, OpArg src) {WriteBitSearchType(bits,de void XEmitter::MOVSX(int dbits, int sbits, X64Reg dest, OpArg src) { - if (src.IsImm()) _assert_msg_(DYNA_REC, 0, "MOVSX - Imm argument"); + if (src.IsImm()) + _assert_msg_(DYNA_REC, 0, "MOVSX - Imm argument"); if (dbits == sbits) { MOV(dbits, R(dest), src); return; } src.operandReg = (u8)dest; - if (dbits == 16) Write8(0x66); + if (dbits == 16) + Write8(0x66); src.WriteRex(this, dbits, sbits); if (sbits == 8) { @@ -798,14 +814,16 @@ void XEmitter::MOVSX(int dbits, int sbits, X64Reg dest, OpArg src) void XEmitter::MOVZX(int dbits, int sbits, X64Reg dest, OpArg src) { - if (src.IsImm()) _assert_msg_(DYNA_REC, 0, "MOVZX - Imm argument"); + if (src.IsImm()) + _assert_msg_(DYNA_REC, 0, "MOVZX - Imm argument"); if (dbits == sbits) { MOV(dbits, R(dest), src); return; } src.operandReg = (u8)dest; - if (dbits == 16) Write8(0x66); + if (dbits == 16) + Write8(0x66); //the 32bit result is automatically zero extended to 64bit src.WriteRex(this, dbits == 64 ? 32 : dbits, sbits); if (sbits == 8) @@ -864,9 +882,11 @@ void XEmitter::MOVBE(int bits, const OpArg& dest, const OpArg& src) void XEmitter::LEA(int bits, X64Reg dest, OpArg src) { - if (src.IsImm()) _assert_msg_(DYNA_REC, 0, "LEA - Imm argument"); + if (src.IsImm()) + _assert_msg_(DYNA_REC, 0, "LEA - Imm argument"); src.operandReg = (u8)dest; - if (bits == 16) Write8(0x66); //TODO: performance warning + if (bits == 16) + Write8(0x66); //TODO: performance warning src.WriteRex(this, bits, bits); Write8(0x8D); src.WriteRest(this, 0, INVALID_REG, bits == 64); @@ -885,7 +905,8 @@ void XEmitter::WriteShift(int bits, OpArg dest, OpArg &shift, int ext) _assert_msg_(DYNA_REC, 0, "WriteShift - illegal argument"); } dest.operandReg = ext; - if (bits == 16) Write8(0x66); + if (bits == 16) + Write8(0x66); dest.WriteRex(this, bits, bits, 0); if (shift.GetImmBits() == 8) { @@ -931,7 +952,8 @@ void XEmitter::WriteBitTest(int bits, OpArg &dest, OpArg &index, int ext) { _assert_msg_(DYNA_REC, 0, "WriteBitTest - illegal argument"); } - if (bits == 16) Write8(0x66); + if (bits == 16) + Write8(0x66); if (index.IsImm()) { dest.WriteRex(this, bits, bits); @@ -968,7 +990,8 @@ void XEmitter::SHRD(int bits, OpArg dest, OpArg src, OpArg shift) { _assert_msg_(DYNA_REC, 0, "SHRD - illegal shift"); } - if (bits == 16) Write8(0x66); + if (bits == 16) + Write8(0x66); X64Reg operand = src.GetSimpleReg(); dest.WriteRex(this, bits, bits, operand); if (shift.GetImmBits() == 8) @@ -998,7 +1021,8 @@ void XEmitter::SHLD(int bits, OpArg dest, OpArg src, OpArg shift) { _assert_msg_(DYNA_REC, 0, "SHLD - illegal shift"); } - if (bits == 16) Write8(0x66); + if (bits == 16) + Write8(0x66); X64Reg operand = src.GetSimpleReg(); dest.WriteRex(this, bits, bits, operand); if (shift.GetImmBits() == 8) diff --git a/Source/Core/Core/ArmMemTools.cpp b/Source/Core/Core/ArmMemTools.cpp index 8f27160330..f26b84c1d9 100644 --- a/Source/Core/Core/ArmMemTools.cpp +++ b/Source/Core/Core/ArmMemTools.cpp @@ -54,14 +54,16 @@ void sigsegv_handler(int signal, siginfo_t *info, void *raw_context) void *fault_memory_ptr = (void*)ctx->arm_r10; u8 *fault_instruction_ptr = (u8 *)ctx->arm_pc; - if (!JitInterface::IsInCodeSpace(fault_instruction_ptr)) { + if (!JitInterface::IsInCodeSpace(fault_instruction_ptr)) + { // Let's not prevent debugging. return; } u64 bad_address = (u64)fault_memory_ptr; u64 memspace_bottom = (u64)Memory::base; - if (bad_address < memspace_bottom) { + if (bad_address < memspace_bottom) + { PanicAlertT("Exception handler - access below memory space. %08llx%08llx", bad_address >> 32, bad_address); } @@ -69,7 +71,8 @@ void sigsegv_handler(int signal, siginfo_t *info, void *raw_context) u32 em_address = (u32)(bad_address - memspace_bottom); const u8 *new_rip = jit->BackPatch(fault_instruction_ptr, em_address, ctx); - if (new_rip) { + if (new_rip) + { ctx->arm_pc = (u32) new_rip; } } diff --git a/Source/Core/Core/PowerPC/GDBStub.cpp b/Source/Core/Core/PowerPC/GDBStub.cpp index 412c808a3e..90b3e3f79d 100644 --- a/Source/Core/Core/PowerPC/GDBStub.cpp +++ b/Source/Core/Core/PowerPC/GDBStub.cpp @@ -147,7 +147,8 @@ static gdb_bp_t *gdb_bp_empty_slot(u32 type) if (p == nullptr) return nullptr; - for (i = 0; i < GDB_MAX_BP; i++) { + for (i = 0; i < GDB_MAX_BP; i++) + { if (p[i].active == 0) return &p[i]; } @@ -164,7 +165,8 @@ static gdb_bp_t *gdb_bp_find(u32 type, u32 addr, u32 len) if (p == nullptr) return nullptr; - for (i = 0; i < GDB_MAX_BP; i++) { + for (i = 0; i < GDB_MAX_BP; i++) + { if (p[i].active == 1 && p[i].addr == addr && p[i].len == len) @@ -180,7 +182,8 @@ static void gdb_bp_remove(u32 type, u32 addr, u32 len) do { p = gdb_bp_find(type, addr, len); - if (p != nullptr) { + if (p != nullptr) + { DEBUG_LOG(GDB_STUB, "gdb: removed a breakpoint: %08x bytes at %08x\n", len, addr); p->active = 0; memset(p, 0, sizeof(gdb_bp_t)); @@ -197,7 +200,8 @@ static int gdb_bp_check(u32 addr, u32 type) if (p == nullptr) return 0; - for (i = 0; i < GDB_MAX_BP; i++) { + for (i = 0; i < GDB_MAX_BP; i++) + { if (p[i].active == 1 && (addr >= p[i].addr && addr < p[i].addr + p[i].len)) return 1; @@ -246,12 +250,14 @@ static void gdb_read_command() gdb_signal(SIGTRAP); return; } - else if (c != GDB_STUB_START) { + else if (c != GDB_STUB_START) + { DEBUG_LOG(GDB_STUB, "gdb: read invalid byte %02x\n", c); return; } - while ((c = gdb_read_byte()) != GDB_STUB_END) { + while ((c = gdb_read_byte()) != GDB_STUB_END) + { cmd_bfr[cmd_len++] = c; if (cmd_len == sizeof cmd_bfr) { @@ -266,7 +272,8 @@ static void gdb_read_command() chk_calc = gdb_calc_chksum(); - if (chk_calc != chk_read) { + if (chk_calc != chk_read) + { ERROR_LOG(GDB_STUB, "gdb: invalid checksum: calculated %02x and read %02x for $%s# (length: %d)\n", chk_calc, chk_read, cmd_bfr, cmd_len); cmd_len = 0; @@ -469,13 +476,15 @@ static void gdb_read_registers() memset(bfr, 0, sizeof bfr); - for (i = 0; i < 32; i++) { + for (i = 0; i < 32; i++) + { wbe32hex(bufptr + i*8, GPR(i)); } bufptr += 32 * 8; /* - for (i = 0; i < 32; i++) { + for (i = 0; i < 32; i++) + { wbe32hex(bufptr + i*8, riPS0(i)); } bufptr += 32 * 8; @@ -500,7 +509,8 @@ static void gdb_write_registers() u32 i; u8 * bufptr = cmd_bfr; - for (i = 0; i < 32; i++) { + for (i = 0; i < 32; i++) + { GPR(i) = re32hex(bufptr + i*8); } bufptr += 32 * 8; @@ -649,7 +659,8 @@ static void _gdb_add_bp() u32 i, addr = 0, len = 0; type = hex2char(cmd_bfr[1]); - switch (type) { + switch (type) + { case 0: case 1: type = GDB_BP_TYPE_X; @@ -869,7 +880,8 @@ int gdb_signal(u32 s) sig = s; - if (send_signal) { + if (send_signal) + { gdb_handle_signal(); send_signal = 0; } diff --git a/Source/Core/Core/PowerPC/PPCCache.cpp b/Source/Core/Core/PowerPC/PPCCache.cpp index 88c9b47053..7cc06b1787 100644 --- a/Source/Core/Core/PowerPC/PPCCache.cpp +++ b/Source/Core/Core/PowerPC/PPCCache.cpp @@ -20,14 +20,16 @@ namespace PowerPC for (u32 m = 0; m < 0xff; m++) { u32 w = 0; - while (m & (1< Date: Sat, 6 Sep 2014 01:24:03 -0500 Subject: [PATCH 2/2] Split some parts of UpdateBoundingBox into multiple lines. Also, fix issues causing failure on Lint. --- Source/Core/Common/x64Emitter.cpp | 27 ++---- Source/Core/Core/PowerPC/GDBStub.cpp | 7 +- Source/Core/Core/PowerPC/PPCCache.cpp | 26 ++--- Source/Core/VideoCommon/VertexLoader.cpp | 117 ++++++++++++++++++++--- 4 files changed, 131 insertions(+), 46 deletions(-) diff --git a/Source/Core/Common/x64Emitter.cpp b/Source/Core/Common/x64Emitter.cpp index 02ffdea5ce..b654a04b47 100644 --- a/Source/Core/Common/x64Emitter.cpp +++ b/Source/Core/Common/x64Emitter.cpp @@ -694,8 +694,7 @@ void XEmitter::UD2() void XEmitter::PREFETCH(PrefetchLevel level, OpArg arg) { - if (arg.IsImm()) - _assert_msg_(DYNA_REC, 0, "PREFETCH - Imm argument"); + _assert_msg_(DYNA_REC, !arg.IsImm(), "PREFETCH - Imm argument"); arg.operandReg = (u8)level; arg.WriteRex(this, 0, 0); Write8(0x0F); @@ -705,8 +704,7 @@ void XEmitter::PREFETCH(PrefetchLevel level, OpArg arg) void XEmitter::SETcc(CCFlags flag, OpArg dest) { - if (dest.IsImm()) - _assert_msg_(DYNA_REC, 0, "SETcc - Imm argument"); + _assert_msg_(DYNA_REC, !dest.IsImm(), "SETcc - Imm argument"); dest.operandReg = 0; dest.WriteRex(this, 0, 8); Write8(0x0F); @@ -716,10 +714,8 @@ void XEmitter::SETcc(CCFlags flag, OpArg dest) void XEmitter::CMOVcc(int bits, X64Reg dest, OpArg src, CCFlags flag) { - if (src.IsImm()) - _assert_msg_(DYNA_REC, 0, "CMOVcc - Imm argument"); - if (bits == 8) - _assert_msg_(DYNA_REC, 0, "CMOVcc - 8 bits unsupported"); + _assert_msg_(DYNA_REC, !src.IsImm(), "CMOVcc - Imm argument"); + _assert_msg_(DYNA_REC, bits != 8, "CMOVcc - 8 bits unsupported"); if (bits == 16) Write8(0x66); src.operandReg = dest; @@ -731,8 +727,7 @@ void XEmitter::CMOVcc(int bits, X64Reg dest, OpArg src, CCFlags flag) void XEmitter::WriteMulDivType(int bits, OpArg src, int ext) { - if (src.IsImm()) - _assert_msg_(DYNA_REC, 0, "WriteMulDivType - Imm argument"); + _assert_msg_(DYNA_REC, !src.IsImm(), "WriteMulDivType - Imm argument"); src.operandReg = ext; if (bits == 16) Write8(0x66); @@ -757,8 +752,7 @@ void XEmitter::NOT(int bits, OpArg src) {WriteMulDivType(bits, src, 2);} void XEmitter::WriteBitSearchType(int bits, X64Reg dest, OpArg src, u8 byte2) { - if (src.IsImm()) - _assert_msg_(DYNA_REC, 0, "WriteBitSearchType - Imm argument"); + _assert_msg_(DYNA_REC, !src.IsImm(), "WriteBitSearchType - Imm argument"); src.operandReg = (u8)dest; if (bits == 16) Write8(0x66); @@ -780,8 +774,7 @@ void XEmitter::BSR(int bits, X64Reg dest, OpArg src) {WriteBitSearchType(bits,de void XEmitter::MOVSX(int dbits, int sbits, X64Reg dest, OpArg src) { - if (src.IsImm()) - _assert_msg_(DYNA_REC, 0, "MOVSX - Imm argument"); + _assert_msg_(DYNA_REC, !src.IsImm(), "MOVSX - Imm argument"); if (dbits == sbits) { MOV(dbits, R(dest), src); @@ -814,8 +807,7 @@ void XEmitter::MOVSX(int dbits, int sbits, X64Reg dest, OpArg src) void XEmitter::MOVZX(int dbits, int sbits, X64Reg dest, OpArg src) { - if (src.IsImm()) - _assert_msg_(DYNA_REC, 0, "MOVZX - Imm argument"); + _assert_msg_(DYNA_REC, !src.IsImm(), "MOVZX - Imm argument"); if (dbits == sbits) { MOV(dbits, R(dest), src); @@ -882,8 +874,7 @@ void XEmitter::MOVBE(int bits, const OpArg& dest, const OpArg& src) void XEmitter::LEA(int bits, X64Reg dest, OpArg src) { - if (src.IsImm()) - _assert_msg_(DYNA_REC, 0, "LEA - Imm argument"); + _assert_msg_(DYNA_REC, !src.IsImm(), "LEA - Imm argument"); src.operandReg = (u8)dest; if (bits == 16) Write8(0x66); //TODO: performance warning diff --git a/Source/Core/Core/PowerPC/GDBStub.cpp b/Source/Core/Core/PowerPC/GDBStub.cpp index 90b3e3f79d..0123e71276 100644 --- a/Source/Core/Core/PowerPC/GDBStub.cpp +++ b/Source/Core/Core/PowerPC/GDBStub.cpp @@ -180,9 +180,10 @@ static void gdb_bp_remove(u32 type, u32 addr, u32 len) { gdb_bp_t *p; - do { + do + { p = gdb_bp_find(type, addr, len); - if (p != nullptr) + if (p != nullptr) { DEBUG_LOG(GDB_STUB, "gdb: removed a breakpoint: %08x bytes at %08x\n", len, addr); p->active = 0; @@ -659,7 +660,7 @@ static void _gdb_add_bp() u32 i, addr = 0, len = 0; type = hex2char(cmd_bfr[1]); - switch (type) + switch (type) { case 0: case 1: diff --git a/Source/Core/Core/PowerPC/PPCCache.cpp b/Source/Core/Core/PowerPC/PPCCache.cpp index 7cc06b1787..26388bc575 100644 --- a/Source/Core/Core/PowerPC/PPCCache.cpp +++ b/Source/Core/Core/PowerPC/PPCCache.cpp @@ -12,15 +12,15 @@ namespace PowerPC { - const u32 plru_mask[8] = {11,11,19,19,37,37,69,69}; - const u32 plru_value[8] = {11,3,17,1,36,4,64,0}; + const u32 plru_mask[8] = {11, 11, 19, 19, 37, 37, 69, 69}; + const u32 plru_value[8] = {11, 3, 17, 1, 36, 4, 64, 0}; InstructionCache::InstructionCache() { for (u32 m = 0; m < 0xff; m++) { u32 w = 0; - while (m & (1<> 5) & 0x7f; for (int i = 0; i < 8; i++) - if (valid[set] & (1<> 12)) lookup_table_vmem[((tags[set][i] << 7) | set) & 0xfffff] = 0xff; @@ -107,15 +107,15 @@ namespace PowerPC u32 t; if (addr & ICACHE_VMEM_BIT) { - t = lookup_table_vmem[(addr>>5) & 0xfffff]; + t = lookup_table_vmem[(addr >> 5) & 0xfffff]; } else if (addr & ICACHE_EXRAM_BIT) { - t = lookup_table_ex[(addr>>5) & 0x1fffff]; + t = lookup_table_ex[(addr >> 5) & 0x1fffff]; } else { - t = lookup_table[(addr>>5) & 0xfffff]; + t = lookup_table[(addr >> 5) & 0xfffff]; } if (t == 0xff) // load to the cache @@ -130,7 +130,7 @@ namespace PowerPC // load u8 *p = Memory::GetPointer(addr & ~0x1f); memcpy(data[set][t], p, 32); - if (valid[set] & (1<> 12)) lookup_table_vmem[((tags[set][t] << 7) | set) & 0xfffff] = 0xff; @@ -141,17 +141,17 @@ namespace PowerPC } if (addr & ICACHE_VMEM_BIT) - lookup_table_vmem[(addr>>5) & 0xfffff] = t; + lookup_table_vmem[(addr >> 5) & 0xfffff] = t; else if (addr & ICACHE_EXRAM_BIT) - lookup_table_ex[(addr>>5) & 0x1fffff] = t; + lookup_table_ex[(addr >> 5) & 0x1fffff] = t; else lookup_table[(addr>>5) & 0xfffff] = t; tags[set][t] = tag; - valid[set] |= 1<>2)&7]); + u32 res = Common::swap32(data[set][t][(addr >> 2) & 7]); return res; } diff --git a/Source/Core/VideoCommon/VertexLoader.cpp b/Source/Core/VideoCommon/VertexLoader.cpp index 6ca9a04da1..a227b6da52 100644 --- a/Source/Core/VideoCommon/VertexLoader.cpp +++ b/Source/Core/VideoCommon/VertexLoader.cpp @@ -374,10 +374,41 @@ static void LOADERDECL UpdateBoundingBox() { m = (p1.x - p0.x) ? ((p1.y - p0.y) / (p1.x - p0.x)) : highNum; c = p0.y - (m * p0.x); - if (i0 & 1) { s = (s32)(c + roundUp); if (s >= 0 && s <= 479) left = 0; top = std::min(s, top); bottom = std::max(s, bottom); } - if (i0 & 2) { s = (s32)((-c / m) + roundUp); if (s >= 0 && s <= 607) top = 0; left = std::min(s, left); right = std::max(s, right); } - if (i0 & 4) { s = (s32)((m * 607) + c + roundUp); if (s >= 0 && s <= 479) right = 607; top = std::min(s, top); bottom = std::max(s, bottom); } - if (i0 & 8) { s = (s32)(((479 - c) / m) + roundUp); if (s >= 0 && s <= 607) bottom = 479; left = std::min(s, left); right = std::max(s, right); } + if (i0 & 1) + { + s = (s32)(c + roundUp); + if (s >= 0 && s <= 479) + left = 0; + top = std::min(s, top); + bottom = std::max(s, bottom); + } + + if (i0 & 2) + { + s = (s32)((-c / m) + roundUp); + if (s >= 0 && s <= 607) + top = 0; + left = std::min(s, left); + right = std::max(s, right); + } + + if (i0 & 4) + { + s = (s32)((m * 607) + c + roundUp); + if (s >= 0 && s <= 479) + right = 607; + top = std::min(s, top); + bottom = std::max(s, bottom); + } + + if (i0 & 8) + { + s = (s32)(((479 - c) / m) + roundUp); + if (s >= 0 && s <= 607) + bottom = 479; + left = std::min(s, left); + right = std::max(s, right); + } } // Only check other lines if we are dealing with a triangle @@ -388,10 +419,41 @@ static void LOADERDECL UpdateBoundingBox() { m = (p2.x - p1.x) ? ((p2.y - p1.y) / (p2.x - p1.x)) : highNum; c = p1.y - (m * p1.x); - if (i1 & 1) { s = (s32)(c + roundUp); if (s >= 0 && s <= 479) left = 0; top = std::min(s, top); bottom = std::max(s, bottom); } - if (i1 & 2) { s = (s32)((-c / m) + roundUp); if (s >= 0 && s <= 607) top = 0; left = std::min(s, left); right = std::max(s, right); } - if (i1 & 4) { s = (s32)((m * 607) + c + roundUp); if (s >= 0 && s <= 479) right = 607; top = std::min(s, top); bottom = std::max(s, bottom); } - if (i1 & 8) { s = (s32)(((479 - c) / m) + roundUp); if (s >= 0 && s <= 607) bottom = 479; left = std::min(s, left); right = std::max(s, right); } + if (i1 & 1) + { + s = (s32)(c + roundUp); + if (s >= 0 && s <= 479) + left = 0; + top = std::min(s, top); + bottom = std::max(s, bottom); + } + + if (i1 & 2) + { + s = (s32)((-c / m) + roundUp); + if (s >= 0 && s <= 607) + top = 0; + left = std::min(s, left); + right = std::max(s, right); + } + + if (i1 & 4) + { + s = (s32)((m * 607) + c + roundUp); + if (s >= 0 && s <= 479) + right = 607; + top = std::min(s, top); + bottom = std::max(s, bottom); + } + + if (i1 & 8) + { + s = (s32)(((479 - c) / m) + roundUp); + if (s >= 0 && s <= 607) + bottom = 479; + left = std::min(s, left); + right = std::max(s, right); + } } // Third line intersects @@ -399,10 +461,41 @@ static void LOADERDECL UpdateBoundingBox() { m = (p2.x - p0.x) ? ((p2.y - p0.y) / (p2.x - p0.x)) : highNum; c = p0.y - (m * p0.x); - if (i2 & 1) { s = (s32)(c + roundUp); if (s >= 0 && s <= 479) left = 0; top = std::min(s, top); bottom = std::max(s, bottom); } - if (i2 & 2) { s = (s32)((-c / m) + roundUp); if (s >= 0 && s <= 607) top = 0; left = std::min(s, left); right = std::max(s, right); } - if (i2 & 4) { s = (s32)((m * 607) + c + roundUp); if (s >= 0 && s <= 479) right = 607; top = std::min(s, top); bottom = std::max(s, bottom); } - if (i2 & 8) { s = (s32)(((479 - c) / m) + roundUp); if (s >= 0 && s <= 607) bottom = 479; left = std::min(s, left); right = std::max(s, right); } + if (i2 & 1) + { + s = (s32)(c + roundUp); + if (s >= 0 && s <= 479) + left = 0; + top = std::min(s, top); + bottom = std::max(s, bottom); + } + + if (i2 & 2) + { + s = (s32)((-c / m) + roundUp); + if (s >= 0 && s <= 607) + top = 0; + left = std::min(s, left); + right = std::max(s, right); + } + + if (i2 & 4) + { + s = (s32)((m * 607) + c + roundUp); + if (s >= 0 && s <= 479) + right = 607; + top = std::min(s, top); + bottom = std::max(s, bottom); + } + + if (i2 & 8) + { + s = (s32)(((479 - c) / m) + roundUp); + if (s >= 0 && s <= 607) + bottom = 479; + left = std::min(s, left); + right = std::max(s, right); + } } }