diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index 9af7e73e97..e747e5668a 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -1595,119 +1595,6 @@ register_(Context* c, int number) return value(c, type, s, s); } -class TranslateEvent: public Event { - public: - TranslateEvent(Context* c, lir::BinaryOperation type, unsigned valueSize, - Value* value, unsigned resultSize, Value* result, - const SiteMask& valueLowMask, - const SiteMask& valueHighMask): - Event(c), type(type), valueSize(valueSize), resultSize(resultSize), - value(value), result(result) - { - bool condensed = c->arch->alwaysCondensed(type); - - if (resultSize > TargetBytesPerWord) { - result->grow(c); - } - - this->addReads(c, value, valueSize, valueLowMask, condensed ? result : 0, - valueHighMask, condensed ? result->nextWord : 0); - } - - virtual const char* name() { - return "TranslateEvent"; - } - - virtual void compile(Context* c) { - assert(c, value->source->type(c) == value->nextWord->source->type(c)); - - uint8_t bTypeMask; - uint64_t bRegisterMask; - - c->arch->planDestination - (type, - valueSize, - 1 << value->source->type(c), - (static_cast(value->nextWord->source->registerMask(c)) << 32) - | static_cast(value->source->registerMask(c)), - resultSize, - &bTypeMask, - &bRegisterMask); - - SiteMask resultLowMask(bTypeMask, bRegisterMask, AnyFrameIndex); - SiteMask resultHighMask(bTypeMask, bRegisterMask >> 32, AnyFrameIndex); - - Site* low = getTarget(c, value, result, resultLowMask); - unsigned lowSize = low->registerSize(c); - Site* high - = (resultSize > lowSize - ? getTarget(c, value->nextWord, result->nextWord, resultHighMask) - : low); - - apply(c, type, valueSize, value->source, value->nextWord->source, - resultSize, low, high); - - for (Read* r = reads; r; r = r->eventNext) { - popRead(c, this, r->value); - } - - low->thaw(c, value); - if (resultSize > lowSize) { - high->thaw(c, value->nextWord); - } - - if (live(c, result)) { - result->addSite(c, low); - if (resultSize > lowSize and live(c, result->nextWord)) { - result->nextWord->addSite(c, high); - } - } - } - - lir::BinaryOperation type; - unsigned valueSize; - unsigned resultSize; - Value* value; - Value* result; - Read* resultRead; - SiteMask resultLowMask; - SiteMask resultHighMask; -}; - -void -appendTranslate(Context* c, lir::BinaryOperation type, unsigned firstSize, - Value* first, unsigned resultSize, Value* result) -{ - bool thunk; - uint8_t firstTypeMask; - uint64_t firstRegisterMask; - - c->arch->planSource(type, firstSize, &firstTypeMask, &firstRegisterMask, - resultSize, &thunk); - - if (thunk) { - Stack* oldStack = c->stack; - - compiler::push(c, ceilingDivide(firstSize, TargetBytesPerWord), first); - - Stack* argumentStack = c->stack; - c->stack = oldStack; - - appendCall - (c, value - (c, lir::ValueGeneral, constantSite - (c, c->client->getThunk(type, firstSize, resultSize))), - 0, 0, result, resultSize, argumentStack, - ceilingDivide(firstSize, TargetBytesPerWord), 0); - } else { - append(c, new(c->zone) - TranslateEvent - (c, type, firstSize, first, resultSize, result, - SiteMask(firstTypeMask, firstRegisterMask, AnyFrameIndex), - SiteMask(firstTypeMask, firstRegisterMask >> 32, AnyFrameIndex))); - } -} - class OperationEvent: public Event { public: OperationEvent(Context* c, lir::Operation op): diff --git a/src/codegen/compiler/event.cpp b/src/codegen/compiler/event.cpp index d238f54bd8..c98cbacbf3 100644 --- a/src/codegen/compiler/event.cpp +++ b/src/codegen/compiler/event.cpp @@ -932,6 +932,119 @@ appendCombine(Context* c, lir::TernaryOperation type, } } +class TranslateEvent: public Event { + public: + TranslateEvent(Context* c, lir::BinaryOperation type, unsigned valueSize, + Value* value, unsigned resultSize, Value* result, + const SiteMask& valueLowMask, + const SiteMask& valueHighMask): + Event(c), type(type), valueSize(valueSize), resultSize(resultSize), + value(value), result(result) + { + bool condensed = c->arch->alwaysCondensed(type); + + if (resultSize > vm::TargetBytesPerWord) { + result->grow(c); + } + + this->addReads(c, value, valueSize, valueLowMask, condensed ? result : 0, + valueHighMask, condensed ? result->nextWord : 0); + } + + virtual const char* name() { + return "TranslateEvent"; + } + + virtual void compile(Context* c) { + assert(c, value->source->type(c) == value->nextWord->source->type(c)); + + uint8_t bTypeMask; + uint64_t bRegisterMask; + + c->arch->planDestination + (type, + valueSize, + 1 << value->source->type(c), + (static_cast(value->nextWord->source->registerMask(c)) << 32) + | static_cast(value->source->registerMask(c)), + resultSize, + &bTypeMask, + &bRegisterMask); + + SiteMask resultLowMask(bTypeMask, bRegisterMask, AnyFrameIndex); + SiteMask resultHighMask(bTypeMask, bRegisterMask >> 32, AnyFrameIndex); + + Site* low = getTarget(c, value, result, resultLowMask); + unsigned lowSize = low->registerSize(c); + Site* high + = (resultSize > lowSize + ? getTarget(c, value->nextWord, result->nextWord, resultHighMask) + : low); + + apply(c, type, valueSize, value->source, value->nextWord->source, + resultSize, low, high); + + for (Read* r = reads; r; r = r->eventNext) { + popRead(c, this, r->value); + } + + low->thaw(c, value); + if (resultSize > lowSize) { + high->thaw(c, value->nextWord); + } + + if (live(c, result)) { + result->addSite(c, low); + if (resultSize > lowSize and live(c, result->nextWord)) { + result->nextWord->addSite(c, high); + } + } + } + + lir::BinaryOperation type; + unsigned valueSize; + unsigned resultSize; + Value* value; + Value* result; + Read* resultRead; + SiteMask resultLowMask; + SiteMask resultHighMask; +}; + +void +appendTranslate(Context* c, lir::BinaryOperation type, unsigned firstSize, + Value* first, unsigned resultSize, Value* result) +{ + bool thunk; + uint8_t firstTypeMask; + uint64_t firstRegisterMask; + + c->arch->planSource(type, firstSize, &firstTypeMask, &firstRegisterMask, + resultSize, &thunk); + + if (thunk) { + Stack* oldStack = c->stack; + + compiler::push(c, vm::ceilingDivide(firstSize, vm::TargetBytesPerWord), first); + + Stack* argumentStack = c->stack; + c->stack = oldStack; + + appendCall + (c, value + (c, lir::ValueGeneral, constantSite + (c, c->client->getThunk(type, firstSize, resultSize))), + 0, 0, result, resultSize, argumentStack, + vm::ceilingDivide(firstSize, vm::TargetBytesPerWord), 0); + } else { + append(c, new(c->zone) + TranslateEvent + (c, type, firstSize, first, resultSize, result, + SiteMask(firstTypeMask, firstRegisterMask, AnyFrameIndex), + SiteMask(firstTypeMask, firstRegisterMask >> 32, AnyFrameIndex))); + } +} + } // namespace compiler } // namespace codegen } // namespace avian diff --git a/src/codegen/compiler/event.h b/src/codegen/compiler/event.h index 08de6e26c9..a87619e0a7 100644 --- a/src/codegen/compiler/event.h +++ b/src/codegen/compiler/event.h @@ -128,6 +128,10 @@ appendCombine(Context* c, lir::TernaryOperation type, unsigned secondSize, Value* second, unsigned resultSize, Value* result); +void +appendTranslate(Context* c, lir::BinaryOperation type, unsigned firstSize, + Value* first, unsigned resultSize, Value* result); + } // namespace compiler } // namespace codegen } // namespace avian