[commit: ghc] master: Optimize casMutVar# for single-threaded RTS (ff7a3c4)
git at git.haskell.org
git at git.haskell.org
Tue May 9 02:27:03 UTC 2017
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/ff7a3c4f9034af0aca1119c1c1e8f7187460bbad/ghc
>---------------------------------------------------------------
commit ff7a3c4f9034af0aca1119c1c1e8f7187460bbad
Author: David Feuer <david.feuer at gmail.com>
Date: Mon May 8 17:44:37 2017 -0400
Optimize casMutVar# for single-threaded RTS
The single-threaded RTS shouldn't actually need to use CAS to
implement `casMutVar#`; there are no other threads to coordinate
with.
Reviewers: austin, bgamari, erikd, simonmar
Reviewed By: simonmar
Subscribers: rwbarton, thomie
Differential Revision: https://phabricator.haskell.org/D3544
>---------------------------------------------------------------
ff7a3c4f9034af0aca1119c1c1e8f7187460bbad
rts/PrimOps.cmm | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/rts/PrimOps.cmm b/rts/PrimOps.cmm
index 7dd88b8..dddba39 100644
--- a/rts/PrimOps.cmm
+++ b/rts/PrimOps.cmm
@@ -528,6 +528,7 @@ stg_newMutVarzh ( gcptr init )
stg_casMutVarzh ( gcptr mv, gcptr old, gcptr new )
/* MutVar# s a -> a -> a -> State# s -> (# State#, Int#, Any a #) */
{
+#if defined(THREADED_RTS)
gcptr h;
(h) = prim %cmpxchgW(mv + SIZEOF_StgHeader + OFFSET_StgMutVar_var, old, new);
@@ -539,6 +540,20 @@ stg_casMutVarzh ( gcptr mv, gcptr old, gcptr new )
}
return (0,new);
}
+#else
+ gcptr prev_val;
+
+ prev_val = StgMutVar_var(mv);
+ if (prev_val != old) {
+ return (1,prev_val);
+ } else {
+ StgMutVar_var(mv) = new;
+ if (GET_INFO(mv) == stg_MUT_VAR_CLEAN_info) {
+ ccall dirty_MUT_VAR(BaseReg "ptr", mv "ptr");
+ }
+ return (0,new);
+ }
+#endif
}
stg_atomicModifyMutVarzh ( gcptr mv, gcptr f )
More information about the ghc-commits
mailing list