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

Commit

Permalink
Add precise gc implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
rainers committed Dec 28, 2018
1 parent e348855 commit cb41c06
Show file tree
Hide file tree
Showing 29 changed files with 918 additions and 100 deletions.
36 changes: 35 additions & 1 deletion src/core/bitop.d
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,32 @@ struct BitRange
}
}

/**
* Construct a BitRange.
*
* Params:
* bitarr = The array of bits to iterate over
* numBits = The total number of valid bits in the given bit array
* startBit = The initial start index to start searching
*/
this(const(size_t)* bitarr, size_t numBits, size_t startBit) @system
{
assert(startBit <= numBits);
bits = bitarr;
len = numBits;
idx = startBit;
if (len)
{
bits += idx / bitsPerWord;
auto curbit = idx % bitsPerWord;
// prime the first bit
cur = *bits++ ^ (size_t(1) << curbit);
if (curbit)
cur &= ~((size_t(1) << curbit) - 1); // clear skipped lower bits
popFront();
}
}

/// Range functions
size_t front()
{
Expand Down Expand Up @@ -453,6 +479,11 @@ struct BitRange
bts(bitArr, 95);
bts(bitArr, 78);

assert(BitRange(bitArr, 100).front() == 24);

bts(bitArr, 0);
assert(BitRange(bitArr, 100).front() == 0);

enum sum = 48 + 24 + 95 + 78;

// iterate
Expand All @@ -465,7 +496,10 @@ struct BitRange
}

assert(testSum == sum);
assert(nBits == 4);
assert(nBits == 5);

assert(BitRange(bitArr, 100, 50).front() == 78);
assert(BitRange(bitArr, 100, 48).front() == 48);
}

@system unittest
Expand Down
8 changes: 7 additions & 1 deletion src/core/memory.d
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,9 @@ struct GC
Example:
----
// Allocate the underlying array.
int* pToArray = cast(int*)GC.malloc(10 * int.sizeof, GC.BlkAttr.NO_SCAN | GC.BlkAttr.APPENDABLE);
BlkInfo info = GC.qalloc(10 * int.sizeof, GC.BlkAttr.NO_SCAN | GC.BlkAttr.APPENDABLE);
info.base[0..info.size] = 0;
int* pToArray = cast(int*)info.base;
// Bind a slice. Check the slice has capacity information.
int[] slice = pToArray[0 .. 0];
assert(capacity(slice) > 0);
Expand All @@ -248,6 +250,10 @@ struct GC
slice ~= 1;
assert(slice.ptr == p);
----
Please be aware that large allocations (> 2 kB) work slightly differently, as the size
of allocated data is stored at the beginning of the allocation instead of the end.
A precise GC might take advantage of the actual memory layout if APPENDABLE is set.
*/
APPENDABLE = 0b0000_1000,

Expand Down
Loading

0 comments on commit cb41c06

Please sign in to comment.