1 /*
2     Copyright 2005-2014 Intel Corporation.  All Rights Reserved.
3 
4     This file is part of Threading Building Blocks. Threading Building Blocks is free software;
5     you can redistribute it and/or modify it under the terms of the GNU General Public License
6     version 2  as  published  by  the  Free Software Foundation.  Threading Building Blocks is
7     distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
8     implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9     See  the GNU General Public License for more details.   You should have received a copy of
10     the  GNU General Public License along with Threading Building Blocks; if not, write to the
11     Free Software Foundation, Inc.,  51 Franklin St,  Fifth Floor,  Boston,  MA 02110-1301 USA
12 
13     As a special exception,  you may use this file  as part of a free software library without
14     restriction.  Specifically,  if other files instantiate templates  or use macros or inline
15     functions from this file, or you compile this file and link it with other files to produce
16     an executable,  this file does not by itself cause the resulting executable to be covered
17     by the GNU General Public License. This exception does not however invalidate any other
18     reasons why the executable file might be covered by the GNU General Public License.
19 */
20 
21 #include <stdint.h>
22 #include <sys/atomic_op.h>
23 
24 /* This file must be compiled with gcc.  The IBM compiler doesn't seem to
25    support inline assembly statements (October 2007). */
26 
27 #ifdef __GNUC__
28 
__TBB_machine_cas_32(volatile void * ptr,int32_t value,int32_t comparand)29 int32_t __TBB_machine_cas_32 (volatile void* ptr, int32_t value, int32_t comparand) {
30     __asm__ __volatile__ ("sync\n");  /* memory release operation */
31     compare_and_swap ((atomic_p) ptr, &comparand, value);
32     __asm__ __volatile__ ("isync\n");  /* memory acquire operation */
33     return comparand;
34 }
35 
__TBB_machine_cas_64(volatile void * ptr,int64_t value,int64_t comparand)36 int64_t __TBB_machine_cas_64 (volatile void* ptr, int64_t value, int64_t comparand) {
37     __asm__ __volatile__ ("sync\n");  /* memory release operation */
38     compare_and_swaplp ((atomic_l) ptr, &comparand, value);
39     __asm__ __volatile__ ("isync\n");  /* memory acquire operation */
40     return comparand;
41 }
42 
__TBB_machine_flush()43 void __TBB_machine_flush () {
44     __asm__ __volatile__ ("sync\n");
45 }
46 
__TBB_machine_lwsync()47 void __TBB_machine_lwsync () {
48     __asm__ __volatile__ ("lwsync\n");
49 }
50 
__TBB_machine_isync()51 void __TBB_machine_isync () {
52     __asm__ __volatile__ ("isync\n");
53 }
54 
55 #endif /* __GNUC__ */
56