Merge pull request #990 from rohit-n/fix-formatting

Fix formatting
This commit is contained in:
shuffle2 2014-09-06 11:54:17 -07:00
commit 1b23432d34
5 changed files with 191 additions and 65 deletions

View File

@ -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,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);
@ -700,7 +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);
@ -710,9 +714,10 @@ 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);
_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;
src.WriteRex(this, bits, bits);
Write8(0x0F);
@ -722,9 +727,10 @@ 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);
if (bits == 16)
Write8(0x66);
src.WriteRex(this, bits, bits, 0);
if (bits == 8)
{
@ -746,9 +752,10 @@ 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);
if (bits == 16)
Write8(0x66);
src.WriteRex(this, bits, bits);
Write8(0x0F);
Write8(byte2);
@ -757,7 +764,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 +774,15 @@ 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);
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 +807,15 @@ 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);
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 +874,10 @@ 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
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 +896,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 +943,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 +981,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 +1012,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)

View File

@ -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;
}
}

View File

@ -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)
@ -178,9 +180,11 @@ 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;
memset(p, 0, sizeof(gdb_bp_t));
@ -197,7 +201,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 +251,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 +273,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 +477,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 +510,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 +660,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 +881,8 @@ int gdb_signal(u32 s)
sig = s;
if (send_signal) {
if (send_signal)
{
gdb_handle_signal();
send_signal = 0;
}

View File

@ -12,22 +12,24 @@
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<<w)) w++;
while (m & (1 << w))
w++;
way_from_valid[m] = w;
}
for (u32 m = 0; m < 128; m++)
{
u32 b[7];
for (int i = 0; i < 7; i++) b[i] = m & (1<<i);
for (int i = 0; i < 7; i++)
b[i] = m & (1 << i);
u32 w;
if (b[0])
if (b[2])
@ -82,7 +84,7 @@ namespace PowerPC
// invalidates the whole set
u32 set = (addr >> 5) & 0x7f;
for (int i = 0; i < 8; i++)
if (valid[set] & (1<<i))
if (valid[set] & (1 << i))
{
if (tags[set][i] & (ICACHE_VMEM_BIT >> 12))
lookup_table_vmem[((tags[set][i] << 7) | set) & 0xfffff] = 0xff;
@ -105,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
@ -128,7 +130,7 @@ namespace PowerPC
// load
u8 *p = Memory::GetPointer(addr & ~0x1f);
memcpy(data[set][t], p, 32);
if (valid[set] & (1<<t))
if (valid[set] & (1 << t))
{
if (tags[set][t] & (ICACHE_VMEM_BIT >> 12))
lookup_table_vmem[((tags[set][t] << 7) | set) & 0xfffff] = 0xff;
@ -139,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<<t;
valid[set] |= (1 << t);
}
// update plru
plru[set] = (plru[set] & ~plru_mask[t]) | plru_value[t];
u32 res = Common::swap32(data[set][t][(addr>>2)&7]);
u32 res = Common::swap32(data[set][t][(addr >> 2) & 7]);
return res;
}

View File

@ -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);
}
}
}