[Git][ghc/ghc][wip/ioref-swap-xchg] Make atomicSwapMutVar# an inline primop

Ben Gamari (@bgamari) gitlab at gitlab.haskell.org
Thu Mar 23 02:15:45 UTC 2023



Ben Gamari pushed to branch wip/ioref-swap-xchg at Glasgow Haskell Compiler / GHC


Commits:
e6ba99fb by Ben Gamari at 2023-03-22T22:15:38-04:00
Make atomicSwapMutVar# an inline primop

- - - - -


5 changed files:

- compiler/GHC/Builtin/primops.txt.pp
- compiler/GHC/StgToCmm/Prim.hs
- rts/PrimOps.cmm
- rts/RtsSymbols.c
- rts/include/stg/MiscClosures.h


Changes:

=====================================
compiler/GHC/Builtin/primops.txt.pp
=====================================
@@ -2517,7 +2517,6 @@ primop  AtomicSwapMutVarOp "atomicSwapMutVar#" GenPrimOp
    MutVar# s v -> v -> State# s -> (# State# s, v #)
    {Atomically exchange the value of a 'MutVar#'.}
    with
-   out_of_line = True
    has_side_effects = True
 
 -- Note [Why not an unboxed tuple in atomicModifyMutVar2#?]


=====================================
compiler/GHC/StgToCmm/Prim.hs
=====================================
@@ -308,6 +308,10 @@ emitPrimOp cfg primop =
        (closureInfoPtr platform (stgToCmmAlignCheck cfg) mutv))
       mkdirtyMutVarCCall
 
+  AtomicSwapMutVarOp -> \[mutv, val] -> opIntoRegs $ \[res] -> do
+    let dst = cmmOffsetW platform mutv (fixedHdrSizeW profile)
+    emitAssign (CmmLocal res) (MO_Xchg (wordWidth platform)) [dst, val]
+
 --  #define sizzeofByteArrayzh(r,a) \
 --     r = ((StgArrBytes *)(a))->bytes
   SizeofByteArrayOp -> \[arg] -> opIntoRegs $ \[res] ->
@@ -1559,7 +1563,6 @@ emitPrimOp cfg primop =
   ResizeMutableByteArrayOp_Char -> alwaysExternal
   ShrinkSmallMutableArrayOp_Char -> alwaysExternal
   NewMutVarOp -> alwaysExternal
-  AtomicSwapMutVarOp -> alwaysExternal
   AtomicModifyMutVar2Op -> alwaysExternal
   AtomicModifyMutVar_Op -> alwaysExternal
   CasMutVarOp -> alwaysExternal


=====================================
rts/PrimOps.cmm
=====================================
@@ -689,14 +689,6 @@ stg_newMutVarzh ( gcptr init )
     return (mv);
 }
 
-stg_atomicSwapMutVarzh ( gcptr mv, gcptr old )
- /* MutVar# s a -> a -> State# s -> (# State#, a #) */
-{
-    W_ new;
-    (new) = prim %xchgW(mv+OFFSET_StgMutVar_var, old);
-    return (new);
-}
-
 // RRN: To support the "ticketed" approach, we return the NEW rather
 // than old value if the CAS is successful.  This is received in an
 // opaque form in the Haskell code, preventing the compiler from


=====================================
rts/RtsSymbols.c
=====================================
@@ -633,7 +633,6 @@ extern char **environ;
       SymI_HasDataProto(stg_writeIOPortzh)                                  \
       SymI_HasDataProto(stg_newIOPortzh)                                    \
       SymI_HasDataProto(stg_noDuplicatezh)                                  \
-      SymI_HasDataProto(stg_atomicSwapMutVarzh)                             \
       SymI_HasDataProto(stg_atomicModifyMutVar2zh)                          \
       SymI_HasDataProto(stg_atomicModifyMutVarzuzh)                         \
       SymI_HasDataProto(stg_casMutVarzh)                                    \


=====================================
rts/include/stg/MiscClosures.h
=====================================
@@ -481,7 +481,6 @@ RTS_FUN_DECL(stg_copySmallMutableArrayzh);
 RTS_FUN_DECL(stg_casSmallArrayzh);
 
 RTS_FUN_DECL(stg_newMutVarzh);
-RTS_FUN_DECL(stg_atomicSwapMutVarzh);
 RTS_FUN_DECL(stg_atomicModifyMutVar2zh);
 RTS_FUN_DECL(stg_atomicModifyMutVarzuzh);
 RTS_FUN_DECL(stg_casMutVarzh);



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/e6ba99fb878a10f12cd8b8d55a34a9cd1f599f1e

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/e6ba99fb878a10f12cd8b8d55a34a9cd1f599f1e
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/20230322/1b87f055/attachment-0001.html>


More information about the ghc-commits mailing list