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

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



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


Commits:
373f22f7 by Ben Gamari at 2023-03-22T22:22:54-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)
+    emitPrimCall [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/373f22f7e8813caf26556d51978aac2669b4aaf1

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/373f22f7e8813caf26556d51978aac2669b4aaf1
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/5f1f9265/attachment-0001.html>


More information about the ghc-commits mailing list