Intel® OpenMP* Runtime Library
 All Classes Functions Variables Typedefs Enumerations Enumerator Groups Pages
z_Windows_NT-586_util.c
1 /*
2  * z_Windows_NT-586_util.c -- platform specific routines.
3  * $Revision: 42181 $
4  * $Date: 2013-03-26 15:04:45 -0500 (Tue, 26 Mar 2013) $
5  */
6 
7 /* <copyright>
8  Copyright (c) 1997-2013 Intel Corporation. All Rights Reserved.
9 
10  Redistribution and use in source and binary forms, with or without
11  modification, are permitted provided that the following conditions
12  are met:
13 
14  * Redistributions of source code must retain the above copyright
15  notice, this list of conditions and the following disclaimer.
16  * Redistributions in binary form must reproduce the above copyright
17  notice, this list of conditions and the following disclaimer in the
18  documentation and/or other materials provided with the distribution.
19  * Neither the name of Intel Corporation nor the names of its
20  contributors may be used to endorse or promote products derived
21  from this software without specific prior written permission.
22 
23  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 
35 </copyright> */
36 
37 #include "kmp.h"
38 
39 #if (KMP_ARCH_X86 || KMP_ARCH_X86_64)
40 /* Only 32-bit "add-exchange" instruction on IA-32 architecture causes us to
41  * use compare_and_store for these routines
42  */
43 
44 kmp_int32
45 __kmp_test_then_or32( volatile kmp_int32 *p, kmp_int32 d )
46 {
47  kmp_int32 old_value, new_value;
48 
49  old_value = TCR_4( *p );
50  new_value = old_value | d;
51 
52  while ( ! __kmp_compare_and_store32 ( p, old_value, new_value ) )
53  {
54  KMP_CPU_PAUSE();
55  old_value = TCR_4( *p );
56  new_value = old_value | d;
57  }
58 
59  return old_value;
60 }
61 
62 kmp_int32
63 __kmp_test_then_and32( volatile kmp_int32 *p, kmp_int32 d )
64 {
65  kmp_int32 old_value, new_value;
66 
67  old_value = TCR_4( *p );
68  new_value = old_value & d;
69 
70  while ( ! __kmp_compare_and_store32 ( p, old_value, new_value ) )
71  {
72  KMP_CPU_PAUSE();
73  old_value = TCR_4( *p );
74  new_value = old_value & d;
75  }
76  return old_value;
77 }
78 
79 #if KMP_ARCH_X86
80 kmp_int64
81 __kmp_test_then_add64( volatile kmp_int64 *p, kmp_int64 d )
82 {
83  kmp_int64 old_value, new_value;
84 
85  old_value = TCR_8( *p );
86  new_value = old_value + d;
87  while ( ! __kmp_compare_and_store64 ( p, old_value, new_value ) )
88  {
89  KMP_CPU_PAUSE();
90  old_value = TCR_8( *p );
91  new_value = old_value + d;
92  }
93 
94  return old_value;
95 }
96 #endif /* KMP_ARCH_X86 */
97 
98 kmp_int64
99 __kmp_test_then_or64( volatile kmp_int64 *p, kmp_int64 d )
100 {
101  kmp_int64 old_value, new_value;
102 
103  old_value = TCR_8( *p );
104  new_value = old_value | d;
105  while ( ! __kmp_compare_and_store64 ( p, old_value, new_value ) )
106  {
107  KMP_CPU_PAUSE();
108  old_value = TCR_8( *p );
109  new_value = old_value | d;
110  }
111 
112  return old_value;
113 }
114 
115 kmp_int64
116 __kmp_test_then_and64( volatile kmp_int64 *p, kmp_int64 d )
117 {
118  kmp_int64 old_value, new_value;
119 
120  old_value = TCR_8( *p );
121  new_value = old_value & d;
122  while ( ! __kmp_compare_and_store64 ( p, old_value, new_value ) )
123  {
124  KMP_CPU_PAUSE();
125  old_value = TCR_8( *p );
126  new_value = old_value & d;
127  }
128 
129  return old_value;
130 }
131 
132 #endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */
133 
134 /* ------------------------------------------------------------------------ */
135 /* ------------------------------------------------------------------------ */
136