diff --git a/src/assembler.h b/src/assembler.h index 226bc31351..ebbc4a487b 100644 --- a/src/assembler.h +++ b/src/assembler.h @@ -134,7 +134,8 @@ class Assembler { public: virtual ~Client() { } - virtual int acquireTemporary() = 0; + virtual int acquireTemporary + (uint32_t mask = ~static_cast(0)) = 0; virtual void releaseTemporary(int r) = 0; virtual void save(int r) = 0; @@ -157,11 +158,11 @@ class Assembler { virtual int argumentRegister(unsigned index) = 0; virtual void plan(UnaryOperation op, unsigned size, uint8_t* typeMask, - uint64_t* registerMask, uintptr_t* procedure); + uint64_t* registerMask, uintptr_t* procedure) = 0; - virtual void plan(UnaryOperation op, unsigned size, uint8_t* aTypeMask, + virtual void plan(BinaryOperation op, unsigned size, uint8_t* aTypeMask, uint64_t* aRegisterMask, uint8_t* bTypeMask, - uint64_t* bRegisterMask, uintptr_t* procedure); + uint64_t* bRegisterMask, uintptr_t* procedure) = 0; virtual void apply(Operation op) = 0; diff --git a/src/compile.cpp b/src/compile.cpp index b0721925a2..fc7590a10a 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -27,7 +27,7 @@ vmCall(); namespace { -const bool Verbose = false; +const bool Verbose = true; const bool DebugNatives = false; const bool DebugCallTable = false; const bool DebugMethodTree = false; @@ -463,9 +463,8 @@ class Context { thread(t), zone(t->m->system, t->m->heap, 16 * 1024), assembler(makeAssembler(t->m->system, t->m->heap, &zone)), - compiler(makeCompiler(t->m->system, assembler, &zone)), + compiler(makeCompiler(t->m->system, assembler, &zone, indirection)), method(method), - indirection(indirection), objectPool(0), traceLog(0), traceLogCount(0), @@ -481,7 +480,6 @@ class Context { assembler(makeAssembler(t->m->system, t->m->heap, &zone)), compiler(0), method(0), - indirection(0), objectPool(0), traceLog(0), traceLogCount(0), @@ -501,7 +499,6 @@ class Context { Assembler* assembler; Compiler* compiler; object method; - void* indirection; PoolElement* objectPool; TraceElement* traceLog; unsigned traceLogCount; @@ -1637,7 +1634,6 @@ compileDirectInvoke(MyThread* t, Frame* frame, object target) (reinterpret_cast (&singletonBody(t, nativeCompiled(t), 0))), 0, - 0, frame->trace(target, false), rSize, 0); @@ -1646,7 +1642,6 @@ compileDirectInvoke(MyThread* t, Frame* frame, object target) (c->constant (reinterpret_cast (&singletonBody(t, defaultCompiled(t), 0))), - 0, Compiler::Aligned, frame->trace(target, false), rSize, @@ -1657,7 +1652,6 @@ compileDirectInvoke(MyThread* t, Frame* frame, object target) (reinterpret_cast (&singletonBody(t, methodCompiled(t, target), 0))), 0, - 0, frame->trace(0, false), rSize, 0); @@ -1687,8 +1681,7 @@ handleMonitorEvent(MyThread* t, Frame* frame, intptr_t function) } c->call(c->constant(function), - frame->context->indirection, - 0, + Compiler::Indirect, frame->trace(0, false), 0, 2, c->thread(), lock); @@ -1756,8 +1749,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, c->call (c->constant(reinterpret_cast(gcIfNecessary)), - context->indirection, - 0, + Compiler::Indirect, frame->trace(0, false), 0, 1, c->thread()); @@ -1806,8 +1798,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, c->call (c->constant(reinterpret_cast(throwArrayIndexOutOfBounds)), - context->indirection, - Compiler::NoReturn, + Compiler::NoReturn | Compiler::Indirect, frame->trace(0, false), 0, 3, c->thread(), array, index); @@ -1923,8 +1914,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, c->call (c->constant(reinterpret_cast(throwArrayIndexOutOfBounds)), - context->indirection, - Compiler::NoReturn, + Compiler::NoReturn | Compiler::Indirect, frame->trace(0, false), 0, 3, c->thread(), array, index); @@ -1950,8 +1940,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, case aastore: { c->call (c->constant(reinterpret_cast(setMaybeNull)), - context->indirection, - 0, + Compiler::Indirect, frame->trace(0, false), 0, 4, c->thread(), array, @@ -1983,8 +1972,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, case aastore: { c->call (c->constant(reinterpret_cast(setMaybeNull)), - context->indirection, - 0, + Compiler::Indirect, frame->trace(0, false), 0, 4, c->thread(), array, @@ -2050,8 +2038,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, frame->pushObject (c->call (c->constant(reinterpret_cast(makeBlankObjectArray)), - context->indirection, - 0, + Compiler::Indirect, frame->trace(0, false), BytesPerWord, 3, c->thread(), frame->append(class_), length)); @@ -2091,8 +2078,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, case athrow: { c->call (c->constant(reinterpret_cast(throw_)), - context->indirection, - Compiler::NoReturn, + Compiler::NoReturn | Compiler::Indirect, frame->trace(0, false), 0, 2, c->thread(), frame->popObject()); @@ -2113,8 +2099,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, c->call (c->constant(reinterpret_cast(checkCast)), - context->indirection, - 0, + Compiler::Indirect, frame->trace(0, false), 0, 3, c->thread(), frame->append(class_), instance); @@ -2124,21 +2109,21 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, frame->pushInt (c->call (c->constant(reinterpret_cast(doubleToFloat)), - context->indirection, 0, 0, 4, 1, frame->popLong())); + Compiler::Indirect, 0, 4, 1, frame->popLong())); } break; case d2i: { frame->pushInt (c->call (c->constant(reinterpret_cast(doubleToInt)), - context->indirection, 0, 0, 4, 1, frame->popLong())); + Compiler::Indirect, 0, 4, 1, frame->popLong())); } break; case d2l: { frame->pushLong (c->call (c->constant(reinterpret_cast(doubleToLong)), - context->indirection, 0, 0, 8, 1, frame->popLong())); + Compiler::Indirect, 0, 8, 1, frame->popLong())); } break; case dadd: { @@ -2148,7 +2133,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, frame->pushLong (c->call (c->constant(reinterpret_cast(addDouble)), - context->indirection, 0, 0, 8, 4, 0, a, 0, b)); + Compiler::Indirect, 0, 8, 4, 0, a, 0, b)); } break; case dcmpg: { @@ -2158,7 +2143,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, frame->pushInt (c->call (c->constant(reinterpret_cast(compareDoublesG)), - context->indirection, 0, 0, 4, 4, 0, a, 0, b)); + Compiler::Indirect, 0, 4, 4, 0, a, 0, b)); } break; case dcmpl: { @@ -2168,7 +2153,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, frame->pushInt (c->call (c->constant(reinterpret_cast(compareDoublesL)), - context->indirection, 0, 0, 4, 4, 0, a, 0, b)); + Compiler::Indirect, 0, 4, 4, 0, a, 0, b)); } break; case dconst_0: @@ -2186,7 +2171,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, frame->pushLong (c->call (c->constant(reinterpret_cast(divideDouble)), - context->indirection, 0, 0, 8, 4, 0, a, 0, b)); + Compiler::Indirect, 0, 8, 4, 0, a, 0, b)); } break; case dmul: { @@ -2196,14 +2181,14 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, frame->pushLong (c->call (c->constant(reinterpret_cast(multiplyDouble)), - context->indirection, 0, 0, 8, 4, 0, a, 0, b)); + Compiler::Indirect, 0, 8, 4, 0, a, 0, b)); } break; case dneg: { frame->pushLong (c->call (c->constant(reinterpret_cast(negateDouble)), - context->indirection, 0, 0, 8, 2, 0, frame->popLong())); + Compiler::Indirect, 0, 8, 2, 0, frame->popLong())); } break; case vm::drem: { @@ -2213,7 +2198,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, frame->pushLong (c->call (c->constant(reinterpret_cast(moduloDouble)), - context->indirection, 0, 0, 8, 4, 0, a, 0, b)); + Compiler::Indirect, 0, 8, 4, 0, a, 0, b)); } break; case dsub: { @@ -2223,7 +2208,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, frame->pushLong (c->call (c->constant(reinterpret_cast(subtractDouble)), - context->indirection, 0, 0, 8, 4, 0, a, 0, b)); + Compiler::Indirect, 0, 8, 4, 0, a, 0, b)); } break; case dup: @@ -2254,21 +2239,21 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, frame->pushLong (c->call (c->constant(reinterpret_cast(floatToDouble)), - context->indirection, 0, 0, 8, 1, frame->popInt())); + Compiler::Indirect, 0, 8, 1, frame->popInt())); } break; case f2i: { frame->pushInt (c->call (c->constant(reinterpret_cast(floatToInt)), - context->indirection, 0, 0, 4, 1, frame->popInt())); + Compiler::Indirect, 0, 4, 1, frame->popInt())); } break; case f2l: { frame->pushLong (c->call (c->constant(reinterpret_cast(floatToLong)), - context->indirection, 0, 0, 8, 1, frame->popInt())); + Compiler::Indirect, 0, 8, 1, frame->popInt())); } break; case fadd: { @@ -2278,7 +2263,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, frame->pushInt (c->call (c->constant(reinterpret_cast(addFloat)), - context->indirection, 0, 0, 4, 2, a, b)); + Compiler::Indirect, 0, 4, 2, a, b)); } break; case fcmpg: { @@ -2288,7 +2273,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, frame->pushInt (c->call (c->constant(reinterpret_cast(compareFloatsG)), - context->indirection, 0, 0, 4, 2, a, b)); + Compiler::Indirect, 0, 4, 2, a, b)); } break; case fcmpl: { @@ -2298,7 +2283,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, frame->pushInt (c->call (c->constant(reinterpret_cast(compareFloatsL)), - context->indirection, 0, 0, 4, 2, a, b)); + Compiler::Indirect, 0, 4, 2, a, b)); } break; case fconst_0: @@ -2320,7 +2305,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, frame->pushInt (c->call (c->constant(reinterpret_cast(divideFloat)), - context->indirection, 0, 0, 4, 2, a, b)); + Compiler::Indirect, 0, 4, 2, a, b)); } break; case fmul: { @@ -2330,14 +2315,14 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, frame->pushInt (c->call (c->constant(reinterpret_cast(multiplyFloat)), - context->indirection, 0, 0, 4, 2, a, b)); + Compiler::Indirect, 0, 4, 2, a, b)); } break; case fneg: { frame->pushInt (c->call (c->constant(reinterpret_cast(negateFloat)), - context->indirection, 0, 0, 4, 1, frame->popInt())); + Compiler::Indirect, 0, 4, 1, frame->popInt())); } break; case vm::frem: { @@ -2347,7 +2332,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, frame->pushInt (c->call (c->constant(reinterpret_cast(moduloFloat)), - context->indirection, 0, 0, 4, 2, a, b)); + Compiler::Indirect, 0, 4, 2, a, b)); } break; case fsub: { @@ -2357,7 +2342,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, frame->pushInt (c->call (c->constant(reinterpret_cast(subtractFloat)), - context->indirection, 0, 0, 4, 2, a, b)); + Compiler::Indirect, 0, 4, 2, a, b)); } break; case getfield: @@ -2375,8 +2360,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, { c->call (c->constant(reinterpret_cast(tryInitClass)), - context->indirection, - 0, + Compiler::Indirect, frame->trace(0, false), 0, 2, c->thread(), frame->append(fieldClass(t, field))); @@ -2455,14 +2439,14 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, frame->pushLong (c->call (c->constant(reinterpret_cast(intToDouble)), - context->indirection, 0, 0, 8, 1, frame->popInt())); + Compiler::Indirect, 0, 8, 1, frame->popInt())); } break; case i2f: { frame->pushInt (c->call (c->constant(reinterpret_cast(intToFloat)), - context->indirection, 0, 0, 4, 1, frame->popInt())); + Compiler::Indirect, 0, 4, 1, frame->popInt())); } break; case i2l: @@ -2689,7 +2673,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, frame->pushInt (c->call (c->constant(reinterpret_cast(instanceOf)), - context->indirection, 0, 0, 4, + Compiler::Indirect, 0, 4, 3, c->thread(), frame->append(class_), frame->popObject())); } break; @@ -2710,14 +2694,12 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, (c->call (c->constant (reinterpret_cast(findInterfaceMethodFromInstance)), - context->indirection, - 0, + Compiler::Indirect, frame->trace(0, false), BytesPerWord, 3, c->thread(), frame->append(target), c->peek(BytesPerWord, instance)), 0, - 0, frame->trace(target, true), rSize, 0); @@ -2773,7 +2755,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, (BytesPerWord, c->constant(PointerMask), c->memory(instance, 0, 0, 1)), offset, 0, 1), 0, - 0, frame->trace(target, true), rSize, 0); @@ -2885,14 +2866,14 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, frame->pushLong (c->call (c->constant(reinterpret_cast(longToDouble)), - context->indirection, 0, 0, 8, 1, frame->popLong())); + Compiler::Indirect, 0, 8, 1, frame->popLong())); } break; case l2f: { frame->pushInt (c->call (c->constant(reinterpret_cast(longToFloat)), - context->indirection, 0, 0, 4, 1, frame->popLong())); + Compiler::Indirect, 0, 4, 1, frame->popLong())); } break; case l2i: @@ -3070,7 +3051,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, c->jmp (c->call (c->constant(reinterpret_cast(lookUpAddress)), - context->indirection, 0, 0, BytesPerWord, + Compiler::Indirect, 0, BytesPerWord, 4, key, start, c->constant(pairCount), default_)); for (int32_t i = 0; i < pairCount; ++i) { @@ -3157,15 +3138,15 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, case monitorenter: { c->call (c->constant(reinterpret_cast(acquireMonitorForObject)), - context->indirection, - 0, frame->trace(0, false), 0, 2, c->thread(), frame->popObject()); + Compiler::Indirect, + frame->trace(0, false), 0, 2, c->thread(), frame->popObject()); } break; case monitorexit: { c->call (c->constant(reinterpret_cast(releaseMonitorForObject)), - context->indirection, - 0, frame->trace(0, false), 0, 2, c->thread(), frame->popObject()); + Compiler::Indirect, + frame->trace(0, false), 0, 2, c->thread(), frame->popObject()); } break; case multianewarray: { @@ -3178,8 +3159,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, Compiler::Operand* result = c->call (c->constant(reinterpret_cast(makeMultidimensionalArray)), - context->indirection, - 0, + Compiler::Indirect, frame->trace(0, false), BytesPerWord, 4, c->thread(), frame->append(class_), @@ -3199,8 +3179,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, frame->pushObject (c->call (c->constant(reinterpret_cast(makeNewWeakReference)), - context->indirection, - 0, + Compiler::Indirect, frame->trace(0, false), BytesPerWord, 2, c->thread(), frame->append(class_))); @@ -3208,8 +3187,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, frame->pushObject (c->call (c->constant(reinterpret_cast(makeNew)), - context->indirection, - 0, + Compiler::Indirect, frame->trace(0, false), BytesPerWord, 2, c->thread(), frame->append(class_))); @@ -3261,8 +3239,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, frame->pushObject (c->call (c->constant(reinterpret_cast(makeBlankArray)), - context->indirection, - 0, + Compiler::Indirect, frame->trace(0, false), BytesPerWord, 3, c->thread(), c->constant(reinterpret_cast(constructor)), @@ -3294,8 +3271,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, { c->call (c->constant(reinterpret_cast(tryInitClass)), - context->indirection, - 0, + Compiler::Indirect, frame->trace(0, false), 0, 2, c->thread(), frame->append(fieldClass(t, field))); @@ -3360,15 +3336,14 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip, if (instruction == putfield) { c->call (c->constant(reinterpret_cast(setMaybeNull)), - context->indirection, - 0, + Compiler::Indirect, frame->trace(0, false), 0, 4, c->thread(), table, c->constant(fieldOffset(t, field)), value); } else { c->call (c->constant(reinterpret_cast(set)), - context->indirection, 0, 0, 0, + Compiler::Indirect, 0, 0, 4, c->thread(), table, c->constant(fieldOffset(t, field)), value); } break; @@ -3872,7 +3847,7 @@ finish(MyThread* t, Context* context) } // for debugging: - if (false and + if (//false and strcmp (reinterpret_cast (&byteArrayBody(t, className(t, methodClass(t, context->method)), 0)), diff --git a/src/compiler.cpp b/src/compiler.cpp index c3fa3b7f86..ed2a80644e 100644 --- a/src/compiler.cpp +++ b/src/compiler.cpp @@ -154,10 +154,11 @@ class Value: public Compiler::Operand { class Context { public: - Context(System* system, Assembler* assembler, Zone* zone): + Context(System* system, Assembler* assembler, Zone* zone, void* indirection): system(system), assembler(assembler), zone(zone), + indirection(indirection), logicalIp(-1), state(new (zone->allocate(sizeof(State))) State(0, 0)), logicalCode(0), @@ -186,6 +187,7 @@ class Context { System* system; Assembler* assembler; Zone* zone; + void* indirection; int logicalIp; State* state; LogicalInstruction* logicalCode; @@ -628,9 +630,9 @@ matchRegister(Context* c, Site* s, uint64_t mask) assert(c, s->type(c) == RegisterOperand); RegisterSite* r = static_cast(s); - return ((static_cast(1) << r->low) & mask) - and (r->high == NoRegister - or ((static_cast(1) << (r->high + 32)) & mask)); + return ((static_cast(1) << r->register_.low) & mask) + and (r->register_.high == NoRegister + or ((static_cast(1) << (r->register_.high + 32)) & mask)); } bool @@ -641,75 +643,6 @@ match(Context* c, Site* s, uint8_t typeMask, uint64_t registerMask) and (t != RegisterOperand or matchRegister(c, s, registerMask)); } -class AbstractSite: public Site { - public: - AbstractSite(Value* value, uint8_t typeMask, uint64_t registerMask): - value(value), registerMask(registerMask), typeMask(typeMask) - { } - - virtual Site* readTarget(Context* c, Read* r, Event*) { - if (value) { - Site* s = targetOrNull(c, value, event); - if (s and match(c, s, typeMask, registerMask)) { - return s; - } - } - - Site* site = 0; - unsigned copyCost = 0xFFFFFFFF; - for (Site* s = r->value->sites; s; s = s->next) { - if (match(c, s, typeMask, registerMask)) { - unsigned v = s->copyCost(c, 0); - if (v < copyCost) { - site = s; - copyCost = v; - } - } - } - - if (site) { - return site; - } else { - return freeRegister(c, r->size, registerMask); - } - } - - virtual unsigned copyCost(Context* c, Site*) { - abort(c); - } - - virtual void copyTo(Context* c, unsigned, Site*) { - abort(c); - } - - virtual OperandType type(Context* c) { - abort(c); - } - - virtual Assembler::Operand* asAssemblerOperand(Context* c) { - abort(c); - } - - Value* value; - uint64_t registerMask; - uint8_t typeMask; -}; - -AbstractSite* -abstractSite(Context* c, Value* v = 0, - uint8_t typeMask = ~static_cast(0), - uint64_t registerMask = ~static_cast(0)) -{ - return new (c->zone->allocate(sizeof(AbstractSite))) - AbstractSite(v, typeMask, registerMask); -} - -AbstractSite* -anyRegisterSite(Context* c) -{ - return abstractSite(c, 0, 1 << RegisterOperand, ~static_cast(0)); -} - Site* targetOrNull(Context* c, Read* r, Event* event) { @@ -735,6 +668,78 @@ targetOrNull(Context* c, Value* v, Event* event) } } +class AbstractSite: public Site { + public: + virtual unsigned copyCost(Context* c, Site*) { + abort(c); + } + + virtual void copyTo(Context* c, unsigned, Site*) { + abort(c); + } + + virtual OperandType type(Context* c) { + abort(c); + } + + virtual Assembler::Operand* asAssemblerOperand(Context* c) { + abort(c); + } +}; + +class VirtualSite: public AbstractSite { + public: + VirtualSite(Value* value, uint8_t typeMask, uint64_t registerMask): + value(value), registerMask(registerMask), typeMask(typeMask) + { } + + virtual Site* readTarget(Context* c, Read* r, Event* e) { + if (value) { + Site* s = targetOrNull(c, value, e); + if (s and match(c, s, typeMask, registerMask)) { + return s; + } + } + + Site* site = 0; + unsigned copyCost = 0xFFFFFFFF; + for (Site* s = r->value->sites; s; s = s->next) { + if (match(c, s, typeMask, registerMask)) { + unsigned v = s->copyCost(c, 0); + if (v < copyCost) { + site = s; + copyCost = v; + } + } + } + + if (site) { + return site; + } else { + return freeRegister(c, r->size, registerMask); + } + } + + Value* value; + uint64_t registerMask; + uint8_t typeMask; +}; + +VirtualSite* +virtualSite(Context* c, Value* v = 0, + uint8_t typeMask = ~static_cast(0), + uint64_t registerMask = ~static_cast(0)) +{ + return new (c->zone->allocate(sizeof(VirtualSite))) + VirtualSite(v, typeMask, registerMask); +} + +VirtualSite* +anyRegisterSite(Context* c) +{ + return virtualSite(c, 0, 1 << RegisterOperand, ~static_cast(0)); +} + bool used(Context* c, int r) { @@ -1032,12 +1037,11 @@ ignore(Context* c, unsigned count) class CallEvent: public Event { public: - CallEvent(Context* c, Value* address, void* indirection, unsigned flags, + CallEvent(Context* c, Value* address, unsigned flags, TraceHandler* traceHandler, Value* result, unsigned resultSize, Stack* argumentStack, unsigned argumentCount): Event(c), address(address), - indirection(indirection), traceHandler(traceHandler), result(result), flags(flags), @@ -1066,7 +1070,8 @@ class CallEvent: public Event { } addRead(c, address, BytesPerWord, - (indirection ? registerSite(c, c->assembler->returnLow()) : 0)); + ((flags & Compiler::Indirect) ? + registerSite(c, c->assembler->returnLow()) : 0)); } virtual void compile(Context* c) { @@ -1077,9 +1082,9 @@ class CallEvent: public Event { pushNow(c, stack); UnaryOperation type = ((flags & Compiler::Aligned) ? AlignedCall : Call); - if (indirection) { + if (flags & Compiler::Indirect) { apply(c, type, BytesPerWord, - constantSite(c, reinterpret_cast(indirection))); + constantSite(c, reinterpret_cast(c->indirection))); } else { apply(c, type, BytesPerWord, address->source); } @@ -1117,7 +1122,6 @@ class CallEvent: public Event { } Value* address; - void* indirection; TraceHandler* traceHandler; Value* result; unsigned flags; @@ -1126,7 +1130,7 @@ class CallEvent: public Event { }; void -appendCall(Context* c, Value* address, void* indirection, unsigned flags, +appendCall(Context* c, Value* address, unsigned flags, TraceHandler* traceHandler, Value* result, unsigned resultSize, Stack* argumentStack, unsigned argumentCount) { @@ -1135,7 +1139,7 @@ appendCall(Context* c, Value* address, void* indirection, unsigned flags, } new (c->zone->allocate(sizeof(CallEvent))) - CallEvent(c, address, indirection, flags, traceHandler, result, + CallEvent(c, address, flags, traceHandler, result, resultSize, argumentStack, argumentCount); } @@ -1189,7 +1193,7 @@ class MoveEvent: public Event { Value* dst, Site* srcTarget): Event(c), type(type), size(size), src(src), dst(dst) { - addRead(c, src, size, target); + addRead(c, src, size, srcTarget); } virtual void compile(Context* c) { @@ -1240,15 +1244,8 @@ appendMove(Context* c, BinaryOperation type, unsigned size, Value* src, fprintf(stderr, "appendMove\n"); } - Site* target; - if (type == Move and size >= BytesPerWord) { - target = moveSite(c, dst); - } else { - target = 0; - } - - AbstractSite* srcTarget = abstractSite(c, dst); - AbstractSite* dstTarget = abstractSite(c); + VirtualSite* srcTarget = virtualSite(c, dst); + VirtualSite* dstTarget = virtualSite(c); uintptr_t procedure; c->assembler->plan(type, size, @@ -1259,7 +1256,7 @@ appendMove(Context* c, BinaryOperation type, unsigned size, Value* src, assert(c, procedure == 0); // todo new (c->zone->allocate(sizeof(MoveEvent))) - MoveEvent(c, type, size, src, dst, srcTarget, dstTarget); + MoveEvent(c, type, size, src, dst, srcTarget); } class CompareEvent: public Event { @@ -1349,12 +1346,18 @@ class CombineEvent: public Event { void appendStackSync(Context* c); +Value* +value(Context* c, Site* site = 0, Site* target = 0) +{ + return new (c->zone->allocate(sizeof(Value))) Value(site, target); +} + void appendCombine(Context* c, BinaryOperation type, unsigned size, Value* first, Value* second, Value* result) { - AbstractSite* firstTarget = abstractSite(c); - AbstractSite* secondTarget = abstractSite(c, result); + VirtualSite* firstTarget = virtualSite(c); + VirtualSite* secondTarget = virtualSite(c, result); uintptr_t procedure; c->assembler->plan(type, size, @@ -1363,16 +1366,16 @@ appendCombine(Context* c, BinaryOperation type, unsigned size, Value* first, &procedure); if (procedure) { - Stack* oldStack = c.state->stack; + Stack* oldStack = c->state->stack; - ::push(&c, size, second); - ::push(&c, size, first); + ::push(c, size, second); + ::push(c, size, first); - Stack* argumentStack = c.state->stack; - c.state->stack = oldStack; + Stack* argumentStack = c->state->stack; + c->state->stack = oldStack; Value* result = value(c); - appendCall(&c, constant(c, procedure), Compiler::Indirect, + appendCall(c, value(c, constantSite(c, procedure)), Compiler::Indirect, 0, result, size, argumentStack, 2); } else { if (DebugAppend) { @@ -1425,7 +1428,7 @@ appendTranslate(Context* c, UnaryOperation type, unsigned size, Value* value, fprintf(stderr, "appendTranslate\n"); } - AbstractSite* target = abstractSite(c, result); + VirtualSite* target = virtualSite(c, result); uintptr_t procedure; c->assembler->plan @@ -1503,12 +1506,6 @@ stack(Context* c, Value* value, unsigned size, unsigned index, Stack* next) Stack(value, size, index, next); } -Value* -value(Context* c, Site* site = 0, Site* target = 0) -{ - return new (c->zone->allocate(sizeof(Value))) Value(site, target); -} - void resetStack(Context* c) { @@ -1958,8 +1955,8 @@ class Client: public Assembler::Client { public: Client(Context* c): c(c) { } - virtual int acquireTemporary() { - int r = freeRegister2(c, ~static_cast(0)); + virtual int acquireTemporary(uint32_t mask) { + int r = freeRegister2(c, mask); save(r); increment(c, r); return r; @@ -1991,8 +1988,8 @@ class Client: public Assembler::Client { class MyCompiler: public Compiler { public: - MyCompiler(System* s, Assembler* assembler, Zone* zone): - c(s, assembler, zone), client(&c) + MyCompiler(System* s, Assembler* assembler, Zone* zone, void* indirection): + c(s, assembler, zone, indirection), client(&c) { assembler->setClient(&client); } @@ -2194,7 +2191,6 @@ class MyCompiler: public Compiler { } virtual Operand* call(Operand* address, - void* indirection, unsigned flags, TraceHandler* traceHandler, unsigned resultSize, @@ -2240,7 +2236,7 @@ class MyCompiler: public Compiler { c.state->stack = oldStack; Value* result = value(&c); - appendCall(&c, static_cast(address), indirection, flags, + appendCall(&c, static_cast(address), flags, traceHandler, result, resultSize, argumentStack, index); @@ -2425,10 +2421,11 @@ class MyCompiler: public Compiler { namespace vm { Compiler* -makeCompiler(System* system, Assembler* assembler, Zone* zone) +makeCompiler(System* system, Assembler* assembler, Zone* zone, + void* indirection) { return new (zone->allocate(sizeof(MyCompiler))) - MyCompiler(system, assembler, zone); + MyCompiler(system, assembler, zone, indirection); } } // namespace vm diff --git a/src/compiler.h b/src/compiler.h index d17396a484..7bb4186b56 100644 --- a/src/compiler.h +++ b/src/compiler.h @@ -21,6 +21,7 @@ class Compiler { public: static const unsigned Aligned = 1 << 0; static const unsigned NoReturn = 1 << 1; + static const unsigned Indirect = 1 << 2; class Operand { }; @@ -67,7 +68,6 @@ class Compiler { virtual Operand* peek(unsigned size, unsigned index) = 0; virtual Operand* call(Operand* address, - void* indirection, unsigned flags, TraceHandler* traceHandler, unsigned resultSize, @@ -109,7 +109,8 @@ class Compiler { }; Compiler* -makeCompiler(System* system, Assembler* assembler, Zone* zone); +makeCompiler(System* system, Assembler* assembler, Zone* zone, + void* indirection); } // namespace vm diff --git a/src/x86.cpp b/src/x86.cpp index 8b9f025659..e00ab4107b 100644 --- a/src/x86.cpp +++ b/src/x86.cpp @@ -1089,7 +1089,7 @@ multiplyCR(Context* c, unsigned size, Assembler::Constant* a, c->client->acquireTemporary(mask)); moveCR(c, size, a, &tmp); - remainderRR(c, size, &tmp, b); + multiplyRR(c, size, &tmp, b); c->client->releaseTemporary(tmp.low); c->client->releaseTemporary(tmp.high); @@ -1869,7 +1869,7 @@ class MyAssembler: public Assembler { *procedure = 0; } - virtual void plan(UnaryOperation op, unsigned size, uint8_t* aTypeMask, + virtual void plan(BinaryOperation op, unsigned size, uint8_t* aTypeMask, uint64_t* aRegisterMask, uint8_t* bTypeMask, uint64_t* bRegisterMask, uintptr_t* procedure) { @@ -1928,11 +1928,11 @@ class MyAssembler: public Assembler { case ShiftLeft: case ShiftRight: - case UnsignedShiftRight: + case UnsignedShiftRight: { *aRegisterMask = static_cast(1) << rcx; const uint32_t mask = ~(1 << rcx); *bRegisterMask = (static_cast(mask) << 32) | mask; - break; + } break; default: break;