[Git][ghc/ghc][wip/buggymcbugfix/insertArray] 2 commits: Cleanup

Vilem-Benjamin Liepelt gitlab at gitlab.haskell.org
Mon Aug 31 12:03:13 UTC 2020



Vilem-Benjamin Liepelt pushed to branch wip/buggymcbugfix/insertArray at Glasgow Haskell Compiler / GHC


Commits:
7fa459f8 by buggymcbugfix at 2020-08-30T15:52:31+02:00
Cleanup

* Remove unused variable
* Use WDS macro

- - - - -
24cf65fc by buggymcbugfix at 2020-08-31T14:02:54+02:00
WIP

- - - - -


4 changed files:

- compiler/GHC/Builtin/primops.txt.pp
- compiler/GHC/StgToCmm/Prim.hs
- includes/Cmm.h
- rts/PrimOps.cmm


Changes:

=====================================
compiler/GHC/Builtin/primops.txt.pp
=====================================
@@ -1264,6 +1264,32 @@ primop CasArrayOp  "casArray#" GenPrimOp
    out_of_line = True
    has_side_effects = True
 
+primop InsertArrayOp "insertArray#" GenPrimOp
+  Array# a -> Int# -> a -> Array# a
+  {Given an array @a@, an index @i@ and an element @x@, insert the @x@ into a
+   copy of @a@ at @i at . Assumes @0 <= i <= sizeOf a at .}
+  with
+  out_of_line      = True
+  has_side_effects = True
+  can_fail         = True
+
+primop UpdateArrayOp "updateArray#" GenPrimOp
+  Array# a -> Int# -> a -> Array# a
+  {Given an array @a@, an index @i@ and an element @x@, update the @i at th element
+   to @x@ in a copy of @a@ at @i at . Assumes @0 <= i < sizeOf a at .}
+  with
+  out_of_line      = True
+  has_side_effects = True
+  can_fail         = True
+
+primop DeleteArrayOp "deleteArray#" GenPrimOp
+  Array# a -> Int# -> Array# a
+  {Given an array @a@ and an index @i@ and an element @x@, return a copy of @a@
+   with the @i at th element deleted. Assumes @0 <= i < sizeOf a at .}
+  with
+  out_of_line      = True
+  has_side_effects = True
+  can_fail         = True
 
 ------------------------------------------------------------------------
 section "Small Arrays"
@@ -1445,6 +1471,33 @@ primop CasSmallArrayOp  "casSmallArray#" GenPrimOp
    out_of_line = True
    has_side_effects = True
 
+primop InsertSmallArrayOp "insertSmallArray#" GenPrimOp
+  SmallArray# a -> Int# -> a -> SmallArray# a
+  {Given an array, an index and an element, insert the element into a copy of
+   the array. Assumes 0 <= index <= sizeOf array.}
+  with
+  out_of_line      = True
+  has_side_effects = True
+  can_fail         = True
+
+primop UpdateSmallArrayOp "updateSmallArray#" GenPrimOp
+  SmallArray# a -> Int# -> a -> SmallArray# a
+  {Given an array @a@, an index @i@ and an element @x@, update the @i at th element
+   to @x@ in a copy of @a@ at @i at . Assumes @0 <= i < sizeOf a at .}
+  with
+  out_of_line      = True
+  has_side_effects = True
+  can_fail         = True
+
+primop DeleteSmallArrayOp "deleteSmallArray#" GenPrimOp
+  SmallArray# a -> Int# -> SmallArray# a
+  {Clone the array but without the element at the given index.
+   Assumes 0 <= index < sizeOf array.}
+  with
+  out_of_line      = True
+  has_side_effects = True
+  can_fail         = True
+
 ------------------------------------------------------------------------
 section "Byte Arrays"
         {Operations on {\tt ByteArray\#}. A {\tt ByteArray\#} is a just a region of


=====================================
compiler/GHC/StgToCmm/Prim.hs
=====================================
@@ -219,6 +219,12 @@ emitPrimOp dflags primop = case primop of
       -> opIntoRegs $ \ [res] -> emitCloneArray mkMAP_DIRTY_infoLabel res src src_off (fromInteger n)
     _ -> PrimopCmmEmit_External
 
+  InsertArrayOp -> const PrimopCmmEmit_External
+
+  UpdateArrayOp -> const PrimopCmmEmit_External
+
+  DeleteArrayOp -> const PrimopCmmEmit_External
+
   NewSmallArrayOp -> \case
     [(CmmLit (CmmInt n w)), init]
       | wordsToBytes platform (asUnsigned w n) <= fromIntegral (maxInlineAllocSize dflags)
@@ -264,6 +270,12 @@ emitPrimOp dflags primop = case primop of
       -> opIntoRegs $ \ [res] -> emitCloneSmallArray mkSMAP_DIRTY_infoLabel res src src_off (fromInteger n)
     _ -> PrimopCmmEmit_External
 
+  InsertSmallArrayOp -> const PrimopCmmEmit_External
+
+  UpdateSmallArrayOp -> const PrimopCmmEmit_External
+
+  DeleteSmallArrayOp -> const PrimopCmmEmit_External
+
 -- First we handle various awkward cases specially.
 
   ParOp -> \[arg] -> opIntoRegs $ \[res] -> do


=====================================
includes/Cmm.h
=====================================
@@ -801,7 +801,7 @@
                                                                \
     dst_p = dst + SIZEOF_StgMutArrPtrs;                        \
     src_p = src + SIZEOF_StgMutArrPtrs + WDS(offset);          \
-    prim %memcpy(dst_p, src_p, n * SIZEOF_W, SIZEOF_W);        \
+    prim %memcpy(dst_p, src_p, WDS(n), SIZEOF_W);              \
                                                                \
     return (dst);
 
@@ -862,7 +862,7 @@
    array ops. Defined as a macro to avoid function call overhead or
    code duplication. */
 #define cloneSmallArray(info, src, offset, n)                  \
-    W_ words, size;                                            \
+    W_ words;                                                  \
     gcptr dst, dst_p, src_p;                                   \
                                                                \
     again: MAYBE_GC(again);                                    \
@@ -876,7 +876,7 @@
                                                                \
     dst_p = dst + SIZEOF_StgSmallMutArrPtrs;                   \
     src_p = src + SIZEOF_StgSmallMutArrPtrs + WDS(offset);     \
-    prim %memcpy(dst_p, src_p, n * SIZEOF_W, SIZEOF_W);        \
+    prim %memcpy(dst_p, src_p, WDS(n), SIZEOF_W);              \
                                                                \
     return (dst);
 


=====================================
rts/PrimOps.cmm
=====================================
@@ -371,6 +371,19 @@ stg_casArrayzh ( gcptr arr, W_ ind, gcptr old, gcptr new )
     }
 }
 
+stg_insertArrayzh( gcptr src, W_ idx, gcptr elemt )
+{
+    return ();
+}
+stg_updateArrayzh( gcptr src, W_ idx, gcptr elemt )
+{
+    return ();
+}
+stg_deleteArrayzh( gcptr src, W_ idx )
+{
+    return ();
+}
+
 stg_newArrayArrayzh ( W_ n /* words */ )
 {
     W_ words, size, p;
@@ -570,6 +583,81 @@ stg_casSmallArrayzh ( gcptr arr, W_ ind, gcptr old, gcptr new )
     }
 }
 
+stg_insertSmallArrayzh( gcptr src, W_ idx, gcptr elemt )
+{
+    W_ words, n;
+    gcptr dst, dst_p, src_p;
+
+    again: MAYBE_GC(again);
+
+    // ccall barf("argh");
+    n = StgSmallMutArrPtrs_ptrs(src) + 1;
+
+    words = BYTES_TO_WDS(SIZEOF_StgSmallMutArrPtrs) + n;
+    ("ptr" dst) = ccall allocate(MyCapability() "ptr", words);
+    TICK_ALLOC_PRIM(SIZEOF_StgSmallMutArrPtrs, WDS(n), 0);
+
+    SET_HDR(dst, stg_SMALL_MUT_ARR_PTRS_FROZEN_CLEAN_info, CCCS);
+    StgSmallMutArrPtrs_ptrs(dst) = n;
+
+    dst_p = dst + SIZEOF_StgSmallMutArrPtrs;
+    src_p = src + SIZEOF_StgSmallMutArrPtrs;
+    prim %memcpy(dst_p, src_p, WDS(idx), SIZEOF_W);
+    REP_StgSmallMutArrPtrs_ptrs[dst_p + WDS(idx)] = elemt;
+    prim %memcpy(dst_p + WDS(idx + 1), src_p + WDS(idx), WDS(n - idx - 1), SIZEOF_W);
+
+    return (dst);
+}
+
+stg_updateSmallArrayzh( gcptr src, W_ idx, gcptr elemt )
+{
+    W_ words, n;
+    gcptr dst, dst_p, src_p;
+
+    again: MAYBE_GC(again);
+
+    n = StgSmallMutArrPtrs_ptrs(src);
+
+    words = BYTES_TO_WDS(SIZEOF_StgSmallMutArrPtrs) + n;
+    ("ptr" dst) = ccall allocate(MyCapability() "ptr", words);
+    TICK_ALLOC_PRIM(SIZEOF_StgSmallMutArrPtrs, WDS(n), 0);
+
+    SET_HDR(dst, stg_SMALL_MUT_ARR_PTRS_FROZEN_CLEAN_info, CCCS);
+    StgSmallMutArrPtrs_ptrs(dst) = n;
+
+    dst_p = dst + SIZEOF_StgSmallMutArrPtrs;
+    src_p = src + SIZEOF_StgSmallMutArrPtrs;
+    prim %memcpy(dst_p, src_p, WDS(idx), SIZEOF_W);
+    REP_StgSmallMutArrPtrs_ptrs[dst_p + WDS(idx)] = elemt;
+    prim %memcpy(dst_p + WDS(idx + 1), src_p + WDS(idx + 1), WDS(n - idx - 1), SIZEOF_W);
+
+    return (dst);
+}
+
+stg_deleteSmallArrayzh( gcptr src, W_ idx )
+{
+    W_ words, n;
+    gcptr dst, dst_p, src_p;
+
+    again: MAYBE_GC(again);
+
+    n = StgSmallMutArrPtrs_ptrs(src) - 1;
+
+    words = BYTES_TO_WDS(SIZEOF_StgSmallMutArrPtrs) + n;
+    ("ptr" dst) = ccall allocate(MyCapability() "ptr", words);
+    TICK_ALLOC_PRIM(SIZEOF_StgSmallMutArrPtrs, WDS(n), 0);
+
+    SET_HDR(dst, stg_SMALL_MUT_ARR_PTRS_FROZEN_CLEAN_info, CCCS);
+    StgSmallMutArrPtrs_ptrs(dst) = n;
+
+    dst_p = dst + SIZEOF_StgSmallMutArrPtrs;
+    src_p = src + SIZEOF_StgSmallMutArrPtrs;
+
+    prim %memcpy(dst_p, src_p, WDS(idx), SIZEOF_W);
+    prim %memcpy(dst_p + WDS(idx), src_p + WDS(idx + 1), WDS(n - idx), SIZEOF_W);
+
+    return (dst);
+}
 
 /* -----------------------------------------------------------------------------
    MutVar primitives



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/5a0320d42f30ee4b0c37700d7dfd3e3ac81d13ad...24cf65fc849c483d75da379495516da09dbd2b38

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/5a0320d42f30ee4b0c37700d7dfd3e3ac81d13ad...24cf65fc849c483d75da379495516da09dbd2b38
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20200831/b72afc28/attachment-0001.html>


More information about the ghc-commits mailing list