blob: 4e21f7e1d7a991ce9b1187020e66aab88ae897ef [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
Jonathan Peyton30419822017-05-12 18:01:32 +000050kmp_int32 __kmp_test_then_or32(volatile kmp_int32 *p, kmp_int32 d) {
51 kmp_int32 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
56 while (!__kmp_compare_and_store32(p, old_value, new_value)) {
57 KMP_CPU_PAUSE();
58 old_value = TCR_4(*p);
Jim Cownie5e8470a2013-09-27 10:38:44 +000059 new_value = old_value | d;
Jonathan Peyton30419822017-05-12 18:01:32 +000060 }
61 return old_value;
Jim Cownie5e8470a2013-09-27 10:38:44 +000062}
63
Jonathan Peyton30419822017-05-12 18:01:32 +000064kmp_int32 __kmp_test_then_and32(volatile kmp_int32 *p, kmp_int32 d) {
65 kmp_int32 old_value, new_value;
Jim Cownie5e8470a2013-09-27 10:38:44 +000066
Jonathan Peyton30419822017-05-12 18:01:32 +000067 old_value = TCR_4(*p);
68 new_value = old_value & d;
69
70 while (!__kmp_compare_and_store32(p, old_value, new_value)) {
71 KMP_CPU_PAUSE();
72 old_value = TCR_4(*p);
Jim Cownie5e8470a2013-09-27 10:38:44 +000073 new_value = old_value & d;
Jonathan Peyton30419822017-05-12 18:01:32 +000074 }
75 return old_value;
Jim Cownie5e8470a2013-09-27 10:38:44 +000076}
77
Jonathan Peyton30419822017-05-12 18:01:32 +000078kmp_int8 __kmp_test_then_add8(volatile kmp_int8 *p, kmp_int8 d) {
79 kmp_int64 old_value, new_value;
Andrey Churbanov7b2ab712015-03-10 09:03:42 +000080
Jonathan Peyton30419822017-05-12 18:01:32 +000081 old_value = TCR_1(*p);
82 new_value = old_value + d;
83 while (!__kmp_compare_and_store8(p, old_value, new_value)) {
84 KMP_CPU_PAUSE();
85 old_value = TCR_1(*p);
Andrey Churbanov7b2ab712015-03-10 09:03:42 +000086 new_value = old_value + d;
Jonathan Peyton30419822017-05-12 18:01:32 +000087 }
88 return old_value;
Andrey Churbanov7b2ab712015-03-10 09:03:42 +000089}
90
Jim Cownie5e8470a2013-09-27 10:38:44 +000091#if KMP_ARCH_X86
Jonathan Peyton30419822017-05-12 18:01:32 +000092kmp_int64 __kmp_test_then_add64(volatile kmp_int64 *p, kmp_int64 d) {
93 kmp_int64 old_value, new_value;
Jim Cownie5e8470a2013-09-27 10:38:44 +000094
Jonathan Peyton30419822017-05-12 18:01:32 +000095 old_value = TCR_8(*p);
96 new_value = old_value + d;
97 while (!__kmp_compare_and_store64(p, old_value, new_value)) {
98 KMP_CPU_PAUSE();
99 old_value = TCR_8(*p);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000100 new_value = old_value + d;
Jonathan Peyton30419822017-05-12 18:01:32 +0000101 }
102 return old_value;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000103}
104#endif /* KMP_ARCH_X86 */
105
Jonathan Peyton30419822017-05-12 18:01:32 +0000106kmp_int64 __kmp_test_then_or64(volatile kmp_int64 *p, kmp_int64 d) {
107 kmp_int64 old_value, new_value;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000108
Jonathan Peyton30419822017-05-12 18:01:32 +0000109 old_value = TCR_8(*p);
110 new_value = old_value | d;
111 while (!__kmp_compare_and_store64(p, old_value, new_value)) {
112 KMP_CPU_PAUSE();
113 old_value = TCR_8(*p);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000114 new_value = old_value | d;
Jonathan Peyton30419822017-05-12 18:01:32 +0000115 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000116
Jonathan Peyton30419822017-05-12 18:01:32 +0000117 return old_value;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000118}
119
Jonathan Peyton30419822017-05-12 18:01:32 +0000120kmp_int64 __kmp_test_then_and64(volatile kmp_int64 *p, kmp_int64 d) {
121 kmp_int64 old_value, new_value;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000122
Jonathan Peyton30419822017-05-12 18:01:32 +0000123 old_value = TCR_8(*p);
124 new_value = old_value & d;
125 while (!__kmp_compare_and_store64(p, old_value, new_value)) {
126 KMP_CPU_PAUSE();
127 old_value = TCR_8(*p);
Jim Cownie5e8470a2013-09-27 10:38:44 +0000128 new_value = old_value & d;
Jonathan Peyton30419822017-05-12 18:01:32 +0000129 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000130
Jonathan Peyton30419822017-05-12 18:01:32 +0000131 return old_value;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000132}
133
134#endif /* KMP_ARCH_X86 || KMP_ARCH_X86_64 */