blob: d88ff5bd719e3832fc727facfc44b3c15bf6d6b5 [file] [log] [blame]
Jim Cownie5e8470a2013-09-27 10:38:44 +00001/*
Jonathan Peytonde4749b2016-12-14 23:01:24 +00002 * z_Windows_NT-586_util.cpp -- platform specific routines.
Jim Cownie5e8470a2013-09-27 10:38:44 +00003 */
4
5
6//===----------------------------------------------------------------------===//
7//
8// The LLVM Compiler Infrastructure
9//
10// This file is dual licensed under the MIT and the University of Illinois Open
11// Source Licenses. See LICENSE.txt for details.
12//
13//===----------------------------------------------------------------------===//
14
15
16#include "kmp.h"
17
18#if (KMP_ARCH_X86 || KMP_ARCH_X86_64)
19/* Only 32-bit "add-exchange" instruction on IA-32 architecture causes us to
Jonathan Peyton30419822017-05-12 18:01:32 +000020 use compare_and_store for these routines */
Jim Cownie5e8470a2013-09-27 10:38:44 +000021
Jonathan Peyton30419822017-05-12 18:01:32 +000022kmp_int8 __kmp_test_then_or8(volatile kmp_int8 *p, kmp_int8 d) {
23 kmp_int8 old_value, new_value;
Andrey Churbanov7b2ab712015-03-10 09:03:42 +000024
Jonathan Peyton30419822017-05-12 18:01:32 +000025 old_value = TCR_1(*p);
26 new_value = old_value | d;
27
28 while (!__kmp_compare_and_store8(p, old_value, new_value)) {
29 KMP_CPU_PAUSE();
30 old_value = TCR_1(*p);
Andrey Churbanov7b2ab712015-03-10 09:03:42 +000031 new_value = old_value | d;
Jonathan Peyton30419822017-05-12 18:01:32 +000032 }
33 return old_value;
Andrey Churbanov7b2ab712015-03-10 09:03:42 +000034}
35
Jonathan Peyton30419822017-05-12 18:01:32 +000036kmp_int8 __kmp_test_then_and8(volatile kmp_int8 *p, kmp_int8 d) {
37 kmp_int8 old_value, new_value;
Andrey Churbanov7b2ab712015-03-10 09:03:42 +000038
Jonathan Peyton30419822017-05-12 18:01:32 +000039 old_value = TCR_1(*p);
40 new_value = old_value & d;
41
42 while (!__kmp_compare_and_store8(p, old_value, new_value)) {
43 KMP_CPU_PAUSE();
44 old_value = TCR_1(*p);
Andrey Churbanov7b2ab712015-03-10 09:03:42 +000045 new_value = old_value & d;
Jonathan Peyton30419822017-05-12 18:01:32 +000046 }
47 return old_value;
Andrey Churbanov7b2ab712015-03-10 09:03:42 +000048}
49
Andrey Churbanov5ba90c72017-07-17 09:03:14 +000050kmp_uint32 __kmp_test_then_or32(volatile kmp_uint32 *p, kmp_uint32 d) {
51 kmp_uint32 old_value, new_value;
Jim Cownie5e8470a2013-09-27 10:38:44 +000052
Jonathan Peyton30419822017-05-12 18:01:32 +000053 old_value = TCR_4(*p);
54 new_value = old_value | d;
55
Andrey Churbanov5ba90c72017-07-17 09:03:14 +000056 while (!__kmp_compare_and_store32((volatile kmp_int32 *)p, old_value,
57 new_value)) {
Jonathan Peyton30419822017-05-12 18:01:32 +000058 KMP_CPU_PAUSE();
59 old_value = TCR_4(*p);
Jim Cownie5e8470a2013-09-27 10:38:44 +000060 new_value = old_value | d;
Jonathan Peyton30419822017-05-12 18:01:32 +000061 }
62 return old_value;
Jim Cownie5e8470a2013-09-27 10:38:44 +000063}
64
Andrey Churbanov5ba90c72017-07-17 09:03:14 +000065kmp_uint32 __kmp_test_then_and32(volatile kmp_uint32 *p, kmp_uint32 d) {
66 kmp_uint32 old_value, new_value;
Jim Cownie5e8470a2013-09-27 10:38:44 +000067
Jonathan Peyton30419822017-05-12 18:01:32 +000068 old_value = TCR_4(*p);
69 new_value = old_value & d;
70
Andrey Churbanov5ba90c72017-07-17 09:03:14 +000071 while (!__kmp_compare_and_store32((volatile kmp_int32 *)p, old_value,
72 new_value)) {
Jonathan Peyton30419822017-05-12 18:01:32 +000073 KMP_CPU_PAUSE();
74 old_value = TCR_4(*p);
Jim Cownie5e8470a2013-09-27 10:38:44 +000075 new_value = old_value & d;
Jonathan Peyton30419822017-05-12 18:01:32 +000076 }
77 return old_value;
Jim Cownie5e8470a2013-09-27 10:38:44 +000078}
79
Jonathan Peyton30419822017-05-12 18:01:32 +000080kmp_int8 __kmp_test_then_add8(volatile kmp_int8 *p, kmp_int8 d) {
81 kmp_int64 old_value, new_value;
Andrey Churbanov7b2ab712015-03-10 09:03:42 +000082
Jonathan Peyton30419822017-05-12 18:01:32 +000083 old_value = TCR_1(*p);
84 new_value = old_value + d;
85 while (!__kmp_compare_and_store8(p, old_value, new_value)) {
86 KMP_CPU_PAUSE();
87 old_value = TCR_1(*p);
Andrey Churbanov7b2ab712015-03-10 09:03:42 +000088 new_value = old_value + d;
Jonathan Peyton30419822017-05-12 18:01:32 +000089 }
90 return old_value;
Andrey Churbanov7b2ab712015-03-10 09:03:42 +000091}
92
Jim Cownie5e8470a2013-09-27 10:38:44 +000093#if KMP_ARCH_X86
Jonathan Peyton30419822017-05-12 18:01:32 +000094kmp_int64 __kmp_test_then_add64(volatile kmp_int64 *p, kmp_int64 d) {
95 kmp_int64 old_value, new_value;
Jim Cownie5e8470a2013-09-27 10:38:44 +000096
Jonathan Peyton30419822017-05-12 18:01:32 +000097 old_value = TCR_8(*p);
98 new_value = old_value + d;
99 while (!__kmp_compare_and_store64(p, old_value, new_value)) {
100 KMP_CPU_PAUSE();
101 old_value = TCR_8(*p);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000102 new_value = old_value + d;
Jonathan Peyton30419822017-05-12 18:01:32 +0000103 }
104 return old_value;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000105}
106#endif /* KMP_ARCH_X86 */
107
Andrey Churbanov5ba90c72017-07-17 09:03:14 +0000108kmp_uint64 __kmp_test_then_or64(volatile kmp_uint64 *p, kmp_uint64 d) {
109 kmp_uint64 old_value, new_value;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000110
Jonathan Peyton30419822017-05-12 18:01:32 +0000111 old_value = TCR_8(*p);
112 new_value = old_value | d;
Andrey Churbanov5ba90c72017-07-17 09:03:14 +0000113 while (!__kmp_compare_and_store64((volatile kmp_int64 *)p, old_value,
114 new_value)) {
Jonathan Peyton30419822017-05-12 18:01:32 +0000115 KMP_CPU_PAUSE();
116 old_value = TCR_8(*p);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000117 new_value = old_value | d;
Jonathan Peyton30419822017-05-12 18:01:32 +0000118 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000119
Jonathan Peyton30419822017-05-12 18:01:32 +0000120 return old_value;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000121}
122
Andrey Churbanov5ba90c72017-07-17 09:03:14 +0000123kmp_uint64 __kmp_test_then_and64(volatile kmp_uint64 *p, kmp_uint64 d) {
124 kmp_uint64 old_value, new_value;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000125
Jonathan Peyton30419822017-05-12 18:01:32 +0000126 old_value = TCR_8(*p);
127 new_value = old_value & d;
Andrey Churbanov5ba90c72017-07-17 09:03:14 +0000128 while (!__kmp_compare_and_store64((volatile kmp_int64 *)p, old_value,
129 new_value)) {
Jonathan Peyton30419822017-05-12 18:01:32 +0000130 KMP_CPU_PAUSE();
131 old_value = TCR_8(*p);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000132 new_value = old_value & d;
Jonathan Peyton30419822017-05-12 18:01:32 +0000133 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000134
Jonathan Peyton30419822017-05-12 18:01:32 +0000135 return old_value;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000136}
137
138#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */