mirror of
https://github.com/corda/corda.git
synced 2025-01-21 03:55:00 +00:00
make RegisterMask a class
This commit is contained in:
parent
87465e890b
commit
94761711c9
@ -45,7 +45,7 @@ class OperandMask {
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
OperandMask() : typeMask(~0), lowRegisterMask(~static_cast<RegisterMask>(0)), highRegisterMask(~static_cast<RegisterMask>(0))
|
OperandMask() : typeMask(~0), lowRegisterMask(RegisterMask::Any), highRegisterMask(RegisterMask::Any)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ class Assembler {
|
|||||||
public:
|
public:
|
||||||
class Client {
|
class Client {
|
||||||
public:
|
public:
|
||||||
virtual Register acquireTemporary(RegisterMask mask = ~static_cast<RegisterMask>(0)) = 0;
|
virtual Register acquireTemporary(RegisterMask mask = RegisterMask::Any) = 0;
|
||||||
virtual void releaseTemporary(Register r) = 0;
|
virtual void releaseTemporary(Register r) = 0;
|
||||||
|
|
||||||
virtual void save(Register r) = 0;
|
virtual void save(Register r) = 0;
|
||||||
|
@ -16,9 +16,47 @@
|
|||||||
namespace avian {
|
namespace avian {
|
||||||
namespace codegen {
|
namespace codegen {
|
||||||
|
|
||||||
typedef uint64_t RegisterMask;
|
|
||||||
typedef int Register;
|
typedef int Register;
|
||||||
|
|
||||||
|
class RegisterMask {
|
||||||
|
private:
|
||||||
|
uint64_t mask;
|
||||||
|
public:
|
||||||
|
RegisterMask(uint64_t mask) : mask(mask) {}
|
||||||
|
RegisterMask() : mask(0) {}
|
||||||
|
|
||||||
|
RegisterMask operator &(RegisterMask o) const {
|
||||||
|
return RegisterMask(mask & o.mask);
|
||||||
|
}
|
||||||
|
|
||||||
|
RegisterMask operator &=(RegisterMask o) {
|
||||||
|
mask &= o.mask;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
RegisterMask operator |(RegisterMask o) const {
|
||||||
|
return RegisterMask(mask | o.mask);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool contains(Register reg) const {
|
||||||
|
return (mask & (static_cast<uint64_t>(1) << reg)) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool containsExactly(Register reg) const {
|
||||||
|
return mask == (mask & (static_cast<uint64_t>(1) << reg));
|
||||||
|
}
|
||||||
|
|
||||||
|
explicit operator uint64_t() const {
|
||||||
|
return mask;
|
||||||
|
}
|
||||||
|
|
||||||
|
explicit operator bool() const {
|
||||||
|
return mask != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static RegisterMask Any;
|
||||||
|
};
|
||||||
|
|
||||||
class BoundedRegisterMask {
|
class BoundedRegisterMask {
|
||||||
public:
|
public:
|
||||||
RegisterMask mask;
|
RegisterMask mask;
|
||||||
@ -68,7 +106,7 @@ class RegisterIterator {
|
|||||||
int r = index;
|
int r = index;
|
||||||
do {
|
do {
|
||||||
index++;
|
index++;
|
||||||
} while (index < mask.limit && !(mask.mask & (1 << index)));
|
} while (index < mask.limit && !(mask.mask.contains(index)));
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -64,7 +64,7 @@ bool pickRegisterTarget(Context* c,
|
|||||||
unsigned* cost,
|
unsigned* cost,
|
||||||
CostCalculator* costCalculator)
|
CostCalculator* costCalculator)
|
||||||
{
|
{
|
||||||
if ((1 << i) & mask) {
|
if (mask.contains(i)) {
|
||||||
RegisterResource* r = c->registerResources + i;
|
RegisterResource* r = c->registerResources + i;
|
||||||
unsigned myCost
|
unsigned myCost
|
||||||
= resourceCost(
|
= resourceCost(
|
||||||
@ -74,7 +74,7 @@ bool pickRegisterTarget(Context* c,
|
|||||||
SiteMask(1 << lir::RegisterOperand, 1 << i, NoFrameIndex),
|
SiteMask(1 << lir::RegisterOperand, 1 << i, NoFrameIndex),
|
||||||
costCalculator) + Target::MinimumRegisterCost;
|
costCalculator) + Target::MinimumRegisterCost;
|
||||||
|
|
||||||
if ((static_cast<RegisterMask>(1) << i) == mask) {
|
if (mask.containsExactly(i)) {
|
||||||
*cost = myCost;
|
*cost = myCost;
|
||||||
return true;
|
return true;
|
||||||
} else if (myCost < *cost) {
|
} else if (myCost < *cost) {
|
||||||
@ -235,7 +235,7 @@ Target pickTarget(Context* c,
|
|||||||
Value* value = read->value;
|
Value* value = read->value;
|
||||||
|
|
||||||
RegisterMask registerMask
|
RegisterMask registerMask
|
||||||
= (isFloatValue(value) ? ~0 : c->regFile->generalRegisters.mask);
|
= (isFloatValue(value) ? RegisterMask::Any : c->regFile->generalRegisters.mask);
|
||||||
|
|
||||||
SiteMask mask(~0, registerMask, AnyFrameIndex);
|
SiteMask mask(~0, registerMask, AnyFrameIndex);
|
||||||
read->intersect(&mask);
|
read->intersect(&mask);
|
||||||
@ -275,7 +275,7 @@ Target pickTarget(Context* c,
|
|||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"mask type %d reg %" LLD " frame %d\n",
|
"mask type %d reg %" LLD " frame %d\n",
|
||||||
mask.typeMask,
|
mask.typeMask,
|
||||||
mask.registerMask,
|
(uint64_t)mask.registerMask,
|
||||||
mask.frameIndex);
|
mask.frameIndex);
|
||||||
abort(c);
|
abort(c);
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ void RegisterResource::freeze(Context* c, Value* v)
|
|||||||
freezeResource(c, this, v);
|
freezeResource(c, this, v);
|
||||||
|
|
||||||
if (freezeCount == 1
|
if (freezeCount == 1
|
||||||
and ((1 << index(c)) & c->regFile->generalRegisters.mask)) {
|
and c->regFile->generalRegisters.mask.contains(index(c))) {
|
||||||
decrementAvailableGeneralRegisterCount(c);
|
decrementAvailableGeneralRegisterCount(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -100,7 +100,7 @@ void RegisterResource::thaw(Context* c, Value* v)
|
|||||||
thawResource(c, this, v);
|
thawResource(c, this, v);
|
||||||
|
|
||||||
if (freezeCount == 0
|
if (freezeCount == 0
|
||||||
and ((1 << index(c)) & c->regFile->generalRegisters.mask)) {
|
and c->regFile->generalRegisters.mask.contains(index(c))) {
|
||||||
incrementAvailableGeneralRegisterCount(c);
|
incrementAvailableGeneralRegisterCount(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -130,7 +130,7 @@ void RegisterResource::increment(Context* c)
|
|||||||
++this->referenceCount;
|
++this->referenceCount;
|
||||||
|
|
||||||
if (this->referenceCount == 1
|
if (this->referenceCount == 1
|
||||||
and ((1 << this->index(c)) & c->regFile->generalRegisters.mask)) {
|
and c->regFile->generalRegisters.mask.contains(this->index(c))) {
|
||||||
decrementAvailableGeneralRegisterCount(c);
|
decrementAvailableGeneralRegisterCount(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -150,7 +150,7 @@ void RegisterResource::decrement(Context* c)
|
|||||||
--this->referenceCount;
|
--this->referenceCount;
|
||||||
|
|
||||||
if (this->referenceCount == 0
|
if (this->referenceCount == 0
|
||||||
and ((1 << this->index(c)) & c->regFile->generalRegisters.mask)) {
|
and c->regFile->generalRegisters.mask.contains(this->index(c))) {
|
||||||
incrementAvailableGeneralRegisterCount(c);
|
incrementAvailableGeneralRegisterCount(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -238,7 +238,7 @@ unsigned RegisterSite::copyCost(Context* c, Site* s)
|
|||||||
|
|
||||||
if (s and (this == s
|
if (s and (this == s
|
||||||
or (s->type(c) == lir::RegisterOperand
|
or (s->type(c) == lir::RegisterOperand
|
||||||
and (static_cast<RegisterSite*>(s)->mask_ & (1 << number))))) {
|
and (static_cast<RegisterSite*>(s)->mask_.contains(number))))) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
return RegisterCopyCost;
|
return RegisterCopyCost;
|
||||||
@ -250,7 +250,7 @@ bool RegisterSite::match(Context* c UNUSED, const SiteMask& mask)
|
|||||||
assertT(c, number != lir::NoRegister);
|
assertT(c, number != lir::NoRegister);
|
||||||
|
|
||||||
if ((mask.typeMask & (1 << lir::RegisterOperand))) {
|
if ((mask.typeMask & (1 << lir::RegisterOperand))) {
|
||||||
return ((static_cast<uint64_t>(1) << number) & mask.registerMask);
|
return mask.registerMask.contains(number);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -261,7 +261,7 @@ bool RegisterSite::loneMatch(Context* c UNUSED, const SiteMask& mask)
|
|||||||
assertT(c, number != lir::NoRegister);
|
assertT(c, number != lir::NoRegister);
|
||||||
|
|
||||||
if ((mask.typeMask & (1 << lir::RegisterOperand))) {
|
if ((mask.typeMask & (1 << lir::RegisterOperand))) {
|
||||||
return ((static_cast<uint64_t>(1) << number) == mask.registerMask);
|
return mask.registerMask.containsExactly(number);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -282,7 +282,7 @@ bool RegisterSite::matchNextWord(Context* c, Site* s, unsigned)
|
|||||||
return number == rs->number;
|
return number == rs->number;
|
||||||
} else {
|
} else {
|
||||||
RegisterMask mask = c->regFile->generalRegisters.mask;
|
RegisterMask mask = c->regFile->generalRegisters.mask;
|
||||||
return ((1 << number) & mask) and ((1 << rs->number) & mask);
|
return mask.contains(number) and mask.contains(rs->number);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -378,7 +378,7 @@ Site* RegisterSite::copyHigh(Context* c)
|
|||||||
Site* RegisterSite::makeNextWord(Context* c, unsigned)
|
Site* RegisterSite::makeNextWord(Context* c, unsigned)
|
||||||
{
|
{
|
||||||
assertT(c, number != lir::NoRegister);
|
assertT(c, number != lir::NoRegister);
|
||||||
assertT(c, ((1 << number) & c->regFile->generalRegisters.mask));
|
assertT(c, c->regFile->generalRegisters.mask.contains(number));
|
||||||
|
|
||||||
return freeRegisterSite(c, c->regFile->generalRegisters.mask);
|
return freeRegisterSite(c, c->regFile->generalRegisters.mask);
|
||||||
}
|
}
|
||||||
@ -405,7 +405,7 @@ unsigned RegisterSite::registerSize(Context* c)
|
|||||||
{
|
{
|
||||||
assertT(c, number != lir::NoRegister);
|
assertT(c, number != lir::NoRegister);
|
||||||
|
|
||||||
if ((1 << number) & c->regFile->floatRegisters.mask) {
|
if (c->regFile->floatRegisters.mask.contains(number)) {
|
||||||
return c->arch->floatRegisterSize();
|
return c->arch->floatRegisterSize();
|
||||||
} else {
|
} else {
|
||||||
return c->targetInfo.pointerSize;
|
return c->targetInfo.pointerSize;
|
||||||
@ -423,8 +423,8 @@ Site* registerSite(Context* c, int number)
|
|||||||
{
|
{
|
||||||
assertT(c, number >= 0);
|
assertT(c, number >= 0);
|
||||||
assertT(c,
|
assertT(c,
|
||||||
(1 << number) & (c->regFile->generalRegisters.mask
|
(c->regFile->generalRegisters.mask
|
||||||
| c->regFile->floatRegisters.mask));
|
| c->regFile->floatRegisters.mask).contains(number));
|
||||||
|
|
||||||
return new (c->zone) RegisterSite(1 << number, number);
|
return new (c->zone) RegisterSite(1 << number, number);
|
||||||
}
|
}
|
||||||
@ -467,9 +467,9 @@ unsigned MemorySite::copyCost(Context* c, Site* s)
|
|||||||
bool MemorySite::conflicts(const SiteMask& mask)
|
bool MemorySite::conflicts(const SiteMask& mask)
|
||||||
{
|
{
|
||||||
return (mask.typeMask & (1 << lir::RegisterOperand)) != 0
|
return (mask.typeMask & (1 << lir::RegisterOperand)) != 0
|
||||||
and (((1 << base) & mask.registerMask) == 0
|
and (!mask.registerMask.contains(base)
|
||||||
or (index != lir::NoRegister
|
or (index != lir::NoRegister
|
||||||
and ((1 << index) & mask.registerMask) == 0));
|
and !mask.registerMask.contains(index)));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MemorySite::match(Context* c, const SiteMask& mask)
|
bool MemorySite::match(Context* c, const SiteMask& mask)
|
||||||
|
@ -16,7 +16,7 @@ namespace codegen {
|
|||||||
unsigned BoundedRegisterMask::maskStart(RegisterMask mask)
|
unsigned BoundedRegisterMask::maskStart(RegisterMask mask)
|
||||||
{
|
{
|
||||||
for (int i = 0; i <= 31; ++i) {
|
for (int i = 0; i <= 31; ++i) {
|
||||||
if (mask & (1 << i))
|
if (mask.contains(i))
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
return 32;
|
return 32;
|
||||||
@ -25,11 +25,13 @@ unsigned BoundedRegisterMask::maskStart(RegisterMask mask)
|
|||||||
unsigned BoundedRegisterMask::maskLimit(RegisterMask mask)
|
unsigned BoundedRegisterMask::maskLimit(RegisterMask mask)
|
||||||
{
|
{
|
||||||
for (int i = 31; i >= 0; --i) {
|
for (int i = 31; i >= 0; --i) {
|
||||||
if (mask & (1 << i))
|
if (mask.contains(i))
|
||||||
return i + 1;
|
return i + 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RegisterMask RegisterMask::Any(~static_cast<uint64_t>(0));
|
||||||
|
|
||||||
} // namespace codegen
|
} // namespace codegen
|
||||||
} // namespace avian
|
} // namespace avian
|
||||||
|
@ -79,6 +79,6 @@ TEST(ArchitecturePlan)
|
|||||||
(lir::UnaryOperation)op, vm::TargetBytesPerWord, mask, &thunk);
|
(lir::UnaryOperation)op, vm::TargetBytesPerWord, mask, &thunk);
|
||||||
assertFalse(thunk);
|
assertFalse(thunk);
|
||||||
assertNotEqual(static_cast<uint8_t>(0), mask.typeMask);
|
assertNotEqual(static_cast<uint8_t>(0), mask.typeMask);
|
||||||
assertNotEqual(static_cast<uint64_t>(0), mask.lowRegisterMask);
|
assertNotEqual(static_cast<uint64_t>(0), (uint64_t)mask.lowRegisterMask);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user