summaryrefslogtreecommitdiff
path: root/libraries/ghc-prim/cbits/atomic.c
Commit message (Collapse)AuthorAgeFilesLines
* winio: Add Atomic Exchange PrimOp and implement Atomic Ptr exchanges.Tamar Christina2020-06-141-0/+33
| | | | | | | The initial version was rewritten by Tamar Christina. It was rewritten in large parts by Andreas Klebinger. Co-authored-by: Andreas Klebinger <klebinger.andreas@gmx.at>
* Modules (#13009)Sylvain Henry2020-04-181-2/+2
| | | | | | | | | | | | | | * SysTools * Parser * GHC.Builtin * GHC.Iface.Recomp * Settings Update Haddock submodule Metric Decrease: Naperian parsing001
* Do not define hs_atomic{read,write}64() on non-64bitIlias Tsitsimpis2020-03-021-0/+5
| | | | | | | | | | | | | | | Do not define hs_atomicread64() and hs_atomicwrite64() on machines where WORD_SIZE_IN_BITS is less than 64, just like we do with the rest of the atomic functions which work on 64-bit values. Without this, compilation fails on MIPSel and PowerPC with the following error: /usr/bin/ld: /<<PKGBUILDDIR>>/libraries/ghc-prim/dist-install/build/libHSghc-prim-0.5.3_p.a(atomic.p_o): in function `hs_atomicread64': atomic.c:(.text.hs_atomicread64+0x8): undefined reference to `__sync_add_and_fetch_8' /usr/bin/ld: /<<PKGBUILDDIR>>/libraries/ghc-prim/dist-install/build/libHSghc-prim-0.5.3_p.a(atomic.p_o): in function `hs_atomicwrite64': atomic.c:(.text.hs_atomicwrite64+0x38): undefined reference to `__sync_bool_compare_and_swap_8' Fixes #17886.
* No atomics on arm32; this will just yield stubs.Moritz Angermann2019-07-021-0/+2
| | | | | | | | | | | | | | | As such the internal linker will fail for them. The alternative would be to implement them as stubs in the linker and have them barf when called. > Not all operations are supported by all target processors. If a particular operation cannot be implemented on the target processor, a warning is generated and a call an external function is generated. The external function carries the same name as the built-in version, with an additional suffix ā€˜_nā€™ where n is the size of the data type. (https://gcc.gnu.org/onlinedocs/gcc/_005f_005fsync-Builtins.html)
* Update Trac ticket URLs to point to GitLabRyan Scott2019-03-151-1/+1
| | | | | This moves all URL references to Trac tickets to their corresponding GitLab counterparts.
* ghc-prim: Refactor and document __sync_fetch_and_nand workaroundBen Gamari2018-04-241-15/+60
| | | | | | | | | | | | | | | | ed6f9fb9d5a684d2159c29633159c3254cf04deb reduced the scope of this hack to only include Clangs which actually lack __sync_fetch_and_nand. However, this causes GHC to fail to build with -Werror on Clang due to the lack of the -Wsync-nand warning flag. As it turns out a flag controlling the warning is available under a different name, however. Test Plan: Validate with Clang, GCC Subscribers: thomie, carter GHC Trac Issues: #9678 Differential Revision: https://phabricator.haskell.org/D4613
* Fix compilation stopper on macOS with -WerrorRichard Eisenberg2018-03-261-0/+2
| | | | | | | | | Commit 94f02547083cf6df686ea0b95fed050184c533de added some pragmas that allow GCC to compile GHC, but stop macOS's clang. This adds another counter-pragma to halp clang lumber along, too. Fixes #14977.
* ghc-prim: Silence -Wsync-nand warning in atomic.cBen Gamari2018-03-081-0/+6
| | | | | | | | | | | | GCC throws this warning to inform us that __sync_fetch_and_nand's behavior changed in GCC 4.4. However, this causes the build to fail when -Werror is used. Test Plan: Validate with -Werror Subscribers: rwbarton, thomie, carter Differential Revision: https://phabricator.haskell.org/D4481
* ghc-prim: Reduce scope of Clang sync_fetch_and_nand workaroundBen Gamari2018-03-081-4/+9
| | | | | | | | | | | | | | As described in https://bugs.llvm.org/show_bug.cgi?id=8842, Clang removed the __sync_fetch_and_nand builtins due to inconsistency in GCC's behavior in 2010. However, GCC has since clarified the behavior of their builtins and consequently Clang re-added them in 2014. Consequently this workaround should no longer be necessary. Test Plan: Validate building with Clang Subscribers: rwbarton, thomie, carter Differential Revision: https://phabricator.haskell.org/D4480
* ghc-prim: Emulate C11 atomics when not availableBen Gamari2018-02-031-0/+36
| | | | | | | | | | | | | | | | | | 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 Reviewers: hvr, simonmar, trommler Subscribers: rwbarton, thomie, erikd, carter GHC Trac Issues: #14244 Differential Revision: https://phabricator.haskell.org/D4364
* Fix atomicread/write operationsPeter Trommler2017-11-021-8/+14
| | | | | | | | | | | | | | | | | | | In `libraries/ghc-prim/cbits/atomic.c` no barriers were issued for atomic read and write operations. Starting with gcc 4.7 compiler intrinsics are offered. The atomic intrinisics are also available in clang. Use these to implement `hs_atomicread*` and `hs_atomicwrite`. Test Plan: validate on OSX and Windows Reviewers: austin, bgamari, simonmar, hvr, erikd, dfeuer Reviewed By: bgamari Subscribers: dfeuer, rwbarton, thomie GHC Trac Issues: #14244 Differential Revision: https://phabricator.haskell.org/D4009
* Fix signature of atomic builtinsAndreas Schwab2015-10-021-112/+112
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch is due to Andreas Schwab. This fixes #10926, which reports (on AArch64) errors of the form, ``` /tmp/ghc1492_0/ghc_1.hc:2844:25: warning: passing argument 1 of 'hs_atomic_xor64' makes pointer from integer without a cast [-Wint-conversion] _c1Ho = hs_atomic_xor64((*Sp) + (((Sp[1]) << 0x3UL) + 0x10UL), Sp[2]); ^ In file included from /home/abuild/rpmbuild/BUILD/ghc-7.10.2/includes/Stg.h:273:0: 0, from /tmp/ghc1492_0/ghc_1.hc:3: /home/abuild/rpmbuild/BUILD/ghc-7.10.2/includes/stg/Prim.h:41:11: note: expected 'volatile StgWord64 * {aka volatile long unsigned int *}' but argument is of type 'long unsigned int' StgWord64 hs_atomic_xor64(volatile StgWord64 *x, StgWord64 val); ^ ``` Test Plan: Validate Reviewers: austin, simonmar Reviewed By: simonmar Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1300 GHC Trac Issues: #10926
* ghc-prim : Hide 64 bit primops when the word size is 32 bits (fixes #9886).Erik de Castro Lopo2015-03-101-0/+14
| | | | | | | | | | | | | | | | | | | | | | | | Summary: These primops were failing to compile on PowerPC (32 bit). There is also currently no way to call into these primops from Haskell code. Currently, the *only* way to call any of these C hs_atomic_* functions is via the fetch*IntArray primops which are only defined for Int values and Int is always the native word size. When these functions can be called (and tested) from Haskell code, then it will be worth while implementing them. Test Plan: Compile and run on x86, x86_64, powerpc and arm: testsuite/tests/concurrent/should_run/AtomicPrimops.hs Reviewers: tibbe, austin Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D702 GHC Trac Issues: #9886
* Re-add more primops for atomic ops on byte arraysJohan Tibell2014-06-301-0/+306
| | | | | | | | | | | | | | | | | | | | | | | This is the second attempt to add this functionality. The first attempt was reverted in 950fcae46a82569e7cd1fba1637a23b419e00ecd, due to register allocator failure on x86. Given how the register allocator currently works, we don't have enough registers on x86 to support cmpxchg using complicated addressing modes. Instead we fall back to a simpler addressing mode on x86. Adds the following primops: * atomicReadIntArray# * atomicWriteIntArray# * fetchSubIntArray# * fetchOrIntArray# * fetchXorIntArray# * fetchAndIntArray# Makes these pre-existing out-of-line primops inline: * fetchAddIntArray# * casIntArray#
* Revert "Add more primops for atomic ops on byte arrays"Johan Tibell2014-06-261-306/+0
| | | | | | | | This commit caused the register allocator to fail on i386. This reverts commit d8abf85f8ca176854e9d5d0b12371c4bc402aac3 and 04dd7cb3423f1940242fdfe2ea2e3b8abd68a177 (the second being a fix to the first).
* Work around lack of __sync_fetch_and_nand in clangJohan Tibell2014-06-261-0/+26
| | | | | clang chose to not implement this function. See http://llvm.org/bugs/show_bug.cgi?id=8842
* Add more primops for atomic ops on byte arraysJohan Tibell2014-06-241-0/+280
Summary: Add more primops for atomic ops on byte arrays Adds the following primops: * atomicReadIntArray# * atomicWriteIntArray# * fetchSubIntArray# * fetchOrIntArray# * fetchXorIntArray# * fetchAndIntArray# Makes these pre-existing out-of-line primops inline: * fetchAddIntArray# * casIntArray#