]> git.sesse.net Git - casparcg/blob - tbb30_20100406oss/include/tbb/machine/mac_ppc.h
2487d212732d13ebc25dde3bb4c50cbd6dec7a86
[casparcg] / tbb30_20100406oss / include / tbb / machine / mac_ppc.h
1 /*
2     Copyright 2005-2010 Intel Corporation.  All Rights Reserved.
3
4     This file is part of Threading Building Blocks.
5
6     Threading Building Blocks is free software; you can redistribute it
7     and/or modify it under the terms of the GNU General Public License
8     version 2 as published by the Free Software Foundation.
9
10     Threading Building Blocks is distributed in the hope that it will be
11     useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12     of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with Threading Building Blocks; if not, write to the Free Software
17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
19     As a special exception, you may use this file as part of a free software
20     library without restriction.  Specifically, if other files instantiate
21     templates or use macros or inline functions from this file, or you compile
22     this file and link it with other files to produce an executable, this
23     file does not by itself cause the resulting executable to be covered by
24     the GNU General Public License.  This exception does not however
25     invalidate any other reasons why the executable file might be covered by
26     the GNU General Public License.
27 */
28
29 #ifndef __TBB_machine_H
30 #error Do not include this file directly; include tbb_machine.h instead
31 #endif
32
33 #include <stdint.h>
34 #include <unistd.h>
35
36 #include <sched.h> // sched_yield
37
38 inline int32_t __TBB_machine_cmpswp4 (volatile void *ptr, int32_t value, int32_t comparand )
39 {
40     int32_t result;
41
42     __asm__ __volatile__("sync\n"
43                          "0: lwarx %0,0,%2\n\t"  /* load w/ reservation */
44                          "cmpw %0,%4\n\t"        /* compare against comparand */
45                          "bne- 1f\n\t"           /* exit if not same */
46                          "stwcx. %3,0,%2\n\t"    /* store new_value */
47                          "bne- 0b\n"             /* retry if reservation lost */
48                          "1: sync"               /* the exit */
49                           : "=&r"(result), "=m"(* (int32_t*) ptr)
50                           : "r"(ptr), "r"(value), "r"(comparand), "m"(* (int32_t*) ptr)
51                           : "cr0");
52     return result;
53 }
54
55 inline int64_t __TBB_machine_cmpswp8 (volatile void *ptr, int64_t value, int64_t comparand )
56 {
57     int64_t result;
58     __asm__ __volatile__("sync\n"
59                          "0: ldarx %0,0,%2\n\t"  /* load w/ reservation */
60                          "cmpd %0,%4\n\t"        /* compare against comparand */
61                          "bne- 1f\n\t"           /* exit if not same */
62                          "stdcx. %3,0,%2\n\t"    /* store new_value */
63                          "bne- 0b\n"             /* retry if reservation lost */
64                          "1: sync"               /* the exit */
65                           : "=&b"(result), "=m"(* (int64_t*) ptr)
66                           : "r"(ptr), "r"(value), "r"(comparand), "m"(* (int64_t*) ptr)
67                           : "cr0");
68     return result;
69 }
70
71 #define __TBB_BIG_ENDIAN 1
72
73 #if defined(powerpc64) || defined(__powerpc64__) || defined(__ppc64__)
74 #define __TBB_WORDSIZE 8
75 #define __TBB_CompareAndSwapW(P,V,C) __TBB_machine_cmpswp8(P,V,C)
76 #else
77 #define __TBB_WORDSIZE 4
78 #define __TBB_CompareAndSwapW(P,V,C) __TBB_machine_cmpswp4(P,V,C)
79 #endif
80
81 #define __TBB_CompareAndSwap4(P,V,C) __TBB_machine_cmpswp4(P,V,C)
82 #define __TBB_CompareAndSwap8(P,V,C) __TBB_machine_cmpswp8(P,V,C)
83 #define __TBB_Yield() sched_yield()
84 #define __TBB_rel_acq_fence() __asm__ __volatile__("lwsync": : :"memory")
85 #define __TBB_release_consistency_helper() __TBB_rel_acq_fence()