2 This source code file is part of thread_mpi.
3 Original for gcc written by Sander Pronk, Erik Lindahl, and possibly
4 others. Modified for the Cray compiler by Daniel Landau.
7 Copyright (c) 2009, Sander Pronk, Erik Lindahl.
8 Copyright 2014, Cray Inc.
11 Redistribution and use in source and binary forms, with or without
12 modification, are permitted provided that the following conditions are met:
13 1) Redistributions of source code must retain the above copyright
14 notice, this list of conditions and the following disclaimer.
15 2) Redistributions in binary form must reproduce the above copyright
16 notice, this list of conditions and the following disclaimer in the
17 documentation and/or other materials provided with the distribution.
18 3) Neither the name of the copyright holders nor the
19 names of its contributors may be used to endorse or promote products
20 derived from this software without specific prior written permission.
22 THIS SOFTWARE IS PROVIDED BY US ''AS IS'' AND ANY
23 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 DISCLAIMED. IN NO EVENT SHALL WE BE LIABLE FOR ANY
26 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 If you want to redistribute modifications, please consider that
34 scientific software is very special. Version control is crucial -
35 bugs must be traceable. We will be happy to consider code for
36 inclusion in the official distribution, but derived work should not
37 be called official thread_mpi. Details are found in the README & COPYING
41 #include <intrinsics.h>
43 #define tMPI_Atomic_memory_barrier() __builtin_ia32_mfence()
46 static inline int tMPI_Atomic_cas(tMPI_Atomic_t *a, int oldval, int newval)
48 return __sync_val_compare_and_swap(&(a->value), oldval, newval) == oldval;
52 static inline int tMPI_Atomic_ptr_cas(tMPI_Atomic_ptr_t* a, void *oldval,
55 return __sync_val_compare_and_swap((size_t*)&(a->value), (size_t)oldval, (size_t)newval) == (size_t)oldval;
59 static inline int tMPI_Atomic_add_return(tMPI_Atomic_t *a, volatile int i)
61 return __sync_add_and_fetch( &(a->value), i);
63 #define TMPI_ATOMIC_HAVE_NATIVE_ADD_RETURN
67 static inline int tMPI_Atomic_fetch_add(tMPI_Atomic_t *a, volatile int i)
69 return __sync_fetch_and_add( &(a->value), i);
71 #define TMPI_ATOMIC_HAVE_NATIVE_FETCH_ADD