1// RUN: %libomp-compile -mlong-double-80 && %libomp-run
2// UNSUPPORTED: gcc
3// REQUIRES: x86-target-arch
4
5#include <stdio.h>
6#include <omp.h>
7
8// Used to detect architecture
9#include "../../src/kmp_platform.h"
10
11#ifdef __cplusplus
12extern "C" {
13#endif
14typedef void* ident_t;
15extern void __kmpc_atomic_float10_max(ident_t *id_ref, int gtid,
16 long double *lhs, long double rhs);
17extern void __kmpc_atomic_float10_min(ident_t *id_ref, int gtid,
18 long double *lhs, long double rhs);
19extern long double __kmpc_atomic_float10_max_cpt(ident_t *id_ref, int gtid,
20 long double *lhs,
21 long double rhs, int flag);
22extern long double __kmpc_atomic_float10_min_cpt(ident_t *id_ref, int gtid,
23 long double *lhs,
24 long double rhs, int flag);
25#ifdef __cplusplus
26}
27#endif
28
29int main() {
30 int ret = 0;
31#if (KMP_ARCH_X86 || KMP_ARCH_X86_64) && !defined(_MSC_VER)
32 long double s = 012.3456; // small
33 long double e = 123.4567; // middle
34 long double d = 234.5678; // big
35 long double x = 123.4567; // object
36 long double v = 0.; // captured value
37
38// initialize OpenMP runtime library
39 omp_set_num_threads(4);
40
41// max
42// #pragma omp atomic compare update
43// if (x < d) x = d;
44 __kmpc_atomic_float10_max(NULL, gtid: 0, lhs: &x, rhs: d);
45 if (x != d) {
46 ret++;
47 printf(format: "Error max: %Lf != %Lf\n", x, d);
48 }
49 __kmpc_atomic_float10_max(NULL, gtid: 0, lhs: &x, rhs: s); // no-op
50 if (x != d) {
51 ret++;
52 printf(format: "Error max: %Lf != %Lf\n", x, d);
53 }
54
55// min
56// #pragma omp atomic compare update
57// if (x > s) x = s;
58 __kmpc_atomic_float10_min(NULL, gtid: 0, lhs: &x, rhs: s);
59 if (x != s) {
60 ret++;
61 printf(format: "Error min: %Lf != %Lf\n", x, s);
62 }
63 __kmpc_atomic_float10_min(NULL, gtid: 0, lhs: &x, rhs: e); // no-op
64 if (x != s) {
65 ret++;
66 printf(format: "Error min: %Lf != %Lf\n", x, s);
67 }
68
69// max_cpt old
70// #pragma omp atomic compare update capture
71// { v = x; if (x < d) x = d; }
72 v = __kmpc_atomic_float10_max_cpt(NULL, gtid: 0, lhs: &x, rhs: d, flag: 0);
73 if (x != d) {
74 ret++;
75 printf(format: "Error max_cpt obj: %Lf != %Lf\n", x, d);
76 }
77 if (v != s) {
78 ret++;
79 printf(format: "Error max_cpt cpt: %Lf != %Lf\n", v, s);
80 }
81 v = __kmpc_atomic_float10_max_cpt(NULL, gtid: 0, lhs: &x, rhs: e, flag: 0); // no-op
82 if (x != d) {
83 ret++;
84 printf(format: "Error max_cpt obj: %Lf != %Lf\n", x, d);
85 }
86 if (v != d) {
87 ret++;
88 printf(format: "Error max_cpt cpt: %Lf != %Lf\n", v, d);
89 }
90
91// min_cpt old
92// #pragma omp atomic compare update capture
93// { v = x; if (x > d) x = d; }
94 v = __kmpc_atomic_float10_min_cpt(NULL, gtid: 0, lhs: &x, rhs: s, flag: 0);
95 if (x != s) {
96 ret++;
97 printf(format: "Error min_cpt obj: %Lf != %Lf\n", x, s);
98 }
99 if (v != d) {
100 ret++;
101 printf(format: "Error min_cpt cpt: %Lf != %Lf\n", v, d);
102 }
103 v = __kmpc_atomic_float10_min_cpt(NULL, gtid: 0, lhs: &x, rhs: e, flag: 0); // no-op
104 if (x != s) {
105 ret++;
106 printf(format: "Error max_cpt obj: %Lf != %Lf\n", x, s);
107 }
108 if (v != s) {
109 ret++;
110 printf(format: "Error max_cpt cpt: %Lf != %Lf\n", v, s);
111 }
112
113// max_cpt new
114// #pragma omp atomic compare update capture
115// { if (x < d) x = d; v = x; }
116 v = __kmpc_atomic_float10_max_cpt(NULL, gtid: 0, lhs: &x, rhs: d, flag: 1);
117 if (x != d) {
118 ret++;
119 printf(format: "Error max_cpt obj: %Lf != %Lf\n", x, d);
120 }
121 if (v != d) {
122 ret++;
123 printf(format: "Error max_cpt cpt: %Lf != %Lf\n", v, d);
124 }
125 v = __kmpc_atomic_float10_max_cpt(NULL, gtid: 0, lhs: &x, rhs: e, flag: 1); // no-op
126 if (x != d) {
127 ret++;
128 printf(format: "Error max_cpt obj: %Lf != %Lf\n", x, d);
129 }
130 if (v != d) {
131 ret++;
132 printf(format: "Error max_cpt cpt: %Lf != %Lf\n", v, d);
133 }
134
135// min_cpt new
136// #pragma omp atomic compare update capture
137// { if (x > d) x = d; v = x; }
138 v = __kmpc_atomic_float10_min_cpt(NULL, gtid: 0, lhs: &x, rhs: s, flag: 1);
139 if (x != s) {
140 ret++;
141 printf(format: "Error min_cpt obj: %Lf != %Lf\n", x, s);
142 }
143 if (v != s) {
144 ret++;
145 printf(format: "Error min_cpt cpt: %Lf != %Lf\n", v, s);
146 }
147 v = __kmpc_atomic_float10_min_cpt(NULL, gtid: 0, lhs: &x, rhs: e, flag: 1); // no-op
148 if (x != s) {
149 ret++;
150 printf(format: "Error max_cpt obj: %Lf != %Lf\n", x, s);
151 }
152 if (v != s) {
153 ret++;
154 printf(format: "Error max_cpt cpt: %Lf != %Lf\n", v, s);
155 }
156
157 if (ret == 0)
158 printf(format: "passed\n");
159#else
160 printf("Unsupported architecture, skipping test...\n");
161#endif // (KMP_ARCH_X86 || KMP_ARCH_X86_64) && !defined(_MSC_VER)
162 return ret;
163}
164

source code of openmp/runtime/test/atomic/kmp_atomic_float10_max_min.c