Commit 5f3d2d3b authored by Ben Gamari's avatar Ben Gamari Committed by David Feuer
Browse files

CNF: Implement compaction for small pointer arrays

Test Plan: Validate

Reviewers: austin, erikd, simonmar, dfeuer

Reviewed By: dfeuer

Subscribers: rwbarton, andrewthad, thomie, dfeuer

GHC Trac Issues: #13860, #13857

Differential Revision: https://phabricator.haskell.org/D3888
parent aeb4bd95
......@@ -4,6 +4,7 @@ test('compact_simple', normal, compile_and_run, [''])
test('compact_loop', normal, compile_and_run, [''])
test('compact_append', normal, compile_and_run, [''])
test('compact_autoexpand', normal, compile_and_run, [''])
test('compact_small_array', [reqlib('primitive')], compile_and_run, [''])
test('compact_simple_array', normal, compile_and_run, [''])
test('compact_huge_array', normal, compile_and_run, [''])
test('compact_serialize', normal, compile_and_run, [''])
......
import GHC.Compact
import Data.Primitive.SmallArray
main :: IO ()
main = do
arr <- newSmallArray 5 (Just 'a')
arr' <- compact arr
print $ getCompact arr'
......@@ -188,9 +188,27 @@ eval:
case
SMALL_MUT_ARR_PTRS_FROZEN0,
SMALL_MUT_ARR_PTRS_FROZEN: {
// (P_ to) = allocateForCompact(cap, compact, size);
// use prim memcpy
ccall barf("stg_compactAddWorkerzh: TODO: SMALL_MUT_ARR_PTRS");
W_ i, size, ptrs;
size = SIZEOF_StgMutArrPtrs + WDS(StgMutArrPtrs_size(p));
ptrs = StgMutArrPtrs_ptrs(p);
ALLOCATE(compact, BYTES_TO_WDS(size), p, to, tag);
P_[pp] = tag | to;
SET_HDR(to, StgHeader_info(p), StgHeader_ccs(p));
StgMutArrPtrs_ptrs(to) = ptrs;
StgMutArrPtrs_size(to) = StgMutArrPtrs_size(p);
prim %memcpy(to, p, size, 1);
i = 0;
loop0:
if (i < ptrs) {
W_ q;
q = to + SIZEOF_StgSmallMutArrPtrs + WDS(i);
call stg_compactAddWorkerzh(
compact, P_[p + SIZEOF_StgSmallMutArrPtrs + WDS(i)], q);
i = i + 1;
goto loop0;
}
return();
}
// Everything else we should copy and evaluate the components:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment