From 2bb310981d4259d90e40f398159e26fa66395a1d Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Sat, 17 May 2008 19:26:36 -0600 Subject: [PATCH 1/2] clean up MoveEvent.compile --- src/compiler.cpp | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/src/compiler.cpp b/src/compiler.cpp index a53aa684ba..3a1b98509f 100644 --- a/src/compiler.cpp +++ b/src/compiler.cpp @@ -953,8 +953,14 @@ trySteal(Context* c, Register* r, Stack* stack) } if (start) { + if (DebugRegisters) { + fprintf(stderr, "push %p\n", v); + } pushNow(c, start, count); } else { + if (DebugRegisters) { + fprintf(stderr, "unable to steal %d from %p\n", r->number, v); + } return false; } } @@ -1053,6 +1059,10 @@ replace(Context* c, Stack* stack, Register* r) Register* s = acquire(c, mask, stack, r->size, r->value, r->site); thaw(r); + if (DebugRegisters) { + fprintf(stderr, "replace %d with %d\n", r->number, s->number); + } + swap(c, r, s); return s; @@ -1067,8 +1077,8 @@ acquire(Context* c, uint32_t mask, Stack* stack, unsigned newSize, if (r->reserved) return r; if (DebugRegisters) { - fprintf(stderr, "acquire %d, value %p, site %p\n", - r->number, newValue, newSite); + fprintf(stderr, "acquire %d, value %p, site %p freeze count %d ref count %d used %d used exclusively %d\n", + r->number, newValue, newSite, r->freezeCount, r->refCount, used(c, r), usedExclusively(c, r)); } if (r->refCount) { @@ -1118,6 +1128,8 @@ validate(Context* c, uint32_t mask, Stack* stack, unsigned size, current->value = value; current->site = site; return current; + } else { + abort(c); } } @@ -1430,21 +1442,20 @@ class MoveEvent: public Event { } else { target = targetOrRegister(c, dst); cost = src->source->copyCost(c, target); - if (type != Move) { - ++ cost; - } if (cost == 0) { target = src->source; } } - nextRead(c, src); + if (target == src->source) { + nextRead(c, src); + } if (dst->reads) { addSite(c, stack, size, dst, target); } - if (cost) { + if (cost or type != Move) { if (match(c, target, dstTarget->typeMask, dstTarget->registerMask)) { apply(c, type, size, src->source, target); } else { @@ -1455,15 +1466,24 @@ class MoveEvent: public Event { addSite(c, stack, size, dst, tmpTarget); apply(c, type, size, src->source, tmpTarget); - apply(c, Move, max(size, BytesPerWord), tmpTarget, target); - removeSite(c, dst, tmpTarget); + if (dst->reads == 0) { + removeSite(c, dst, tmpTarget); + + apply(c, Move, size, tmpTarget, target); + } else { + removeSite(c, dst, target); + } } } if (dst->reads == 0) { removeSite(c, dst, target); } + + if (target != src->source) { + nextRead(c, src); + } } BinaryOperation type; From b6b84af123bf386a1608dfdcfd12816e07593d1e Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Sat, 17 May 2008 21:32:14 -0600 Subject: [PATCH 2/2] various bugfixes --- src/compiler.cpp | 10 +++++++--- src/x86.cpp | 11 +++++------ test/Misc.java | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/src/compiler.cpp b/src/compiler.cpp index 3a1b98509f..a1a9ea3755 100644 --- a/src/compiler.cpp +++ b/src/compiler.cpp @@ -625,9 +625,13 @@ freeRegisterSite(Context* c, uint64_t mask = ~static_cast(0)) RegisterSite* fixedRegisterSite(Context* c, int low, int high = NoRegister) { - uint64_t mask = static_cast(1) << low; - if (high != NoRegister) { - mask |= static_cast(1) << (high + 32); + uint64_t mask; + if (high == NoRegister) { + mask = (~static_cast(0) << 32) + | (static_cast(1) << low); + } else { + mask = (static_cast(1) << (high + 32)) + | (static_cast(1) << low); } return new (c->zone->allocate(sizeof(RegisterSite))) diff --git a/src/x86.cpp b/src/x86.cpp index 2e1cec2fc8..db2c2a25fd 100644 --- a/src/x86.cpp +++ b/src/x86.cpp @@ -1081,7 +1081,7 @@ multiplyRR(Context* c, unsigned size, Assembler::Register* a, // mul a->low,%eax%edx c->code.append(0xf7); - c->code.append(0xe8 | a->low); + c->code.append(0xe0 | a->low); addRR(c, 4, b, &bh); moveRR(c, 4, &axdx, b); @@ -1099,8 +1099,6 @@ void multiplyCR(Context* c, unsigned size, Assembler::Constant* a, Assembler::Register* b) { - assert(c, BytesPerWord == 8 or size == 4); - if (BytesPerWord == 4 and size == 8) { const uint32_t mask = ~((1 << rax) | (1 << rdx)); Assembler::Register tmp(c->client->acquireTemporary(mask), @@ -1517,9 +1515,9 @@ unsignedShiftRightRR(Context* c, unsigned size, Assembler::Register* a, assert(c, a->low == rcx); if (BytesPerWord == 4 and size == 8) { - // shld + // shrd c->code.append(0x0f); - c->code.append(0xa5); + c->code.append(0xad); c->code.append(0xc0 | (b->high << 3) | b->low); // shr @@ -1963,7 +1961,8 @@ class MyAssembler: public Assembler { case ShiftRight: case UnsignedShiftRight: { *aTypeMask = (1 << RegisterOperand); - *aRegisterMask = static_cast(1) << rcx; + *aRegisterMask = (~static_cast(0) << 32) + | (static_cast(1) << rcx); const uint32_t mask = ~(1 << rcx); *bRegisterMask = (static_cast(mask) << 32) | mask; } break; diff --git a/test/Misc.java b/test/Misc.java index 50b303d4be..c262c09833 100644 --- a/test/Misc.java +++ b/test/Misc.java @@ -125,6 +125,35 @@ public class Misc { expect(~a == ~5); } + { long a = -5; + long b = 2; + expect(a >> b == -5L >> 2); + expect(a >>> b == -5L >>> 2); + expect(a << b == -5L << 2); + expect(a * b == -5L * 2L); + expect(a / b == -5L / 2L); + expect(a % b == -5L % 2L); + expect((a & b) == (-5L & 2L)); + expect((a | b) == (-5L | 2L)); + expect((a ^ b) == (-5L ^ 2L)); + expect(-a == 5L); + expect(~a == ~-5L); + + a = 5; + b = 2; + expect(a >> b == 5L >> 2); + expect(a >>> b == 5L >>> 2); + expect(a << b == 5L << 2); + expect(a * b == 5L * 2L); + expect(a / b == 5L / 2L); + expect(a % b == 5L % 2L); + expect((a & b) == (5L & 2L)); + expect((a | b) == (5L | 2L)); + expect((a ^ b) == (5L ^ 2L)); + expect(-a == -5L); + expect(~a == ~5L); + } + byte2 = 0; expect(byte2 == 0); @@ -174,6 +203,10 @@ public class Misc { { Misc m = new Misc(); m.toString(); + expect(m.time == 0xffffffffffffffffL); + long t = m.time; + expect(t == 0xffffffffffffffffL); + String s = "hello"; m.foo(s); m.bar(s);