Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
GC: precalculate shiftBy
Browse files Browse the repository at this point in the history
  • Loading branch information
rainers committed Nov 19, 2014
1 parent 6c6c431 commit aecf464
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions src/gc/gc.d
Original file line number Diff line number Diff line change
Expand Up @@ -3126,6 +3126,8 @@ struct Pool
bool oldChanges; // Whether there were changes on the last mark.
bool newChanges; // Whether there were changes on the current mark.

uint shiftBy; // shift count for the divisor used for determining bit indices.

// This tracks how far back we have to go to find the nearest B_PAGE at
// a smaller address than a B_PAGEPLUS. To save space, we use a uint.
// This limits individual allocations to 16 terabytes, assuming a 4k
Expand All @@ -3142,6 +3144,8 @@ struct Pool
this.isLargeObject = isLargeObject;
size_t poolsize;

shiftBy = isLargeObject ? 12 : 4;

//debug(PRINTF) printf("Pool::Pool(%u)\n", npages);
poolsize = npages * PAGESIZE;
assert(poolsize >= POOLSIZE);
Expand All @@ -3160,8 +3164,7 @@ struct Pool
}
//assert(baseAddr);
topAddr = baseAddr + poolsize;
auto div = this.divisor;
auto nbits = cast(size_t)poolsize / div;
auto nbits = cast(size_t)poolsize >> shiftBy;

mark.alloc(nbits);
scan.alloc(nbits);
Expand Down Expand Up @@ -3266,20 +3269,6 @@ struct Pool
}
}

// The divisor used for determining bit indices.
@property private size_t divisor() nothrow
{
// NOTE: Since this is called by initialize it must be private or
// invariant() will be called and fail.
return isLargeObject ? PAGESIZE : 16;
}

// Bit shift for fast division by divisor.
@property uint shiftBy() nothrow
{
return isLargeObject ? 12 : 4;
}

void updateOffsets(size_t fromWhere) nothrow
{
assert(pagetable[fromWhere] == B_PAGE);
Expand Down

0 comments on commit aecf464

Please sign in to comment.