ghc-prim: Emulate C11 atomics when not available
ClosedPublic

Authored by bgamari on Feb 1 2018, 10:47 AM.

Details

Summary

GCC's __sync primitives apparently "usually" imply a full barrier, meaning they
can be used to emulate the more precise C11 atomics albeit with a loss of
efficiency. This restores compatibility with GCC 4.4.

This partially reverts commit 59de290928e6903337f31c1f8107ac8a98ea145d.

Test Plan

Validate on Centos

Diff Detail

Repository
rGHC Glasgow Haskell Compiler
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
bgamari created this revision.Feb 1 2018, 10:47 AM
bgamari updated this revision to Diff 15313.Feb 1 2018, 10:50 AM
  • Remove redundancies

I think atomic read is fine but atomic write is missing a parameter. See inline comment.

libraries/ghc-prim/cbits/atomic.c
327

You need as a second parameter the value you compare with *x here and also below.

Perhaps something like this would do?
while (!__sync_bool_compare_and_swap((StgWord8 *) x, *(StgWord8 *) x, (StgWord8) val)) ;

BTW: Do you remember which version of GCC has the bug with incorrect parameter passing to __sync_* functions? Perhaps, we could get rid of those annoying casts?!

bgamari updated this revision to Diff 15318.Feb 1 2018, 3:33 PM
bgamari marked an inline comment as done.Feb 3 2018, 10:37 AM
bgamari added inline comments.
libraries/ghc-prim/cbits/atomic.c
327

Perhaps something like this would do?

Whoops, yes, of course. Got a bit carried away with copy/paste.

BTW: Do you remember which version of GCC has the bug with incorrect parameter passing to __sync_* functions? Perhaps, we could get rid of those annoying casts?!

Unfortunately I don't. That being said, the patch from Trac #10926 was written two years ago, so, while I agree that the casts are rather intrusive, I suspect that it's a bit too early to drop them.

This revision was automatically updated to reflect the committed changes.
bgamari marked an inline comment as done.