File: kmp_atomic_float10_max_min.c

package info (click to toggle)
llvm-toolchain-15 1%3A15.0.6-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,554,644 kB
  • sloc: cpp: 5,922,452; ansic: 1,012,136; asm: 674,362; python: 191,568; objc: 73,855; f90: 42,327; lisp: 31,913; pascal: 11,973; javascript: 10,144; sh: 9,421; perl: 7,447; ml: 5,527; awk: 3,523; makefile: 2,520; xml: 885; cs: 573; fortran: 567
file content (163 lines) | stat: -rw-r--r-- 4,365 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// RUN: %libomp-compile -mlong-double-80 && %libomp-run
// UNSUPPORTED: gcc
// REQUIRES: x86-registered-target

#include <stdio.h>
#include <omp.h>

// Used to detect architecture
#include "../../src/kmp_platform.h"

#ifdef  __cplusplus
extern "C" {
#endif
typedef void* ident_t;
extern void __kmpc_atomic_float10_max(ident_t *id_ref, int gtid,
                                      long double *lhs, long double rhs);
extern void __kmpc_atomic_float10_min(ident_t *id_ref, int gtid,
                                      long double *lhs, long double rhs);
extern long double __kmpc_atomic_float10_max_cpt(ident_t *id_ref, int gtid,
                                                 long double *lhs,
                                                 long double rhs, int flag);
extern long double __kmpc_atomic_float10_min_cpt(ident_t *id_ref, int gtid,
                                                 long double *lhs,
                                                 long double rhs, int flag);
#ifdef  __cplusplus
}
#endif

int main() {
  int ret = 0;
#if KMP_ARCH_X86 || KMP_ARCH_X86_64
  long double s = 012.3456; // small
  long double e = 123.4567; // middle
  long double d = 234.5678; // big
  long double x = 123.4567; // object
  long double v = 0.; // captured value

// initialize OpenMP runtime library
  omp_set_num_threads(4);

// max
//  #pragma omp atomic compare update
//    if (x < d) x = d;
  __kmpc_atomic_float10_max(NULL, 0, &x, d);
  if (x != d) {
    ret++;
    printf("Error max: %Lf != %Lf\n", x, d);
  }
  __kmpc_atomic_float10_max(NULL, 0, &x, s); // no-op
  if (x != d) {
    ret++;
    printf("Error max: %Lf != %Lf\n", x, d);
  }

// min
//  #pragma omp atomic compare update
//    if (x > s) x = s;
  __kmpc_atomic_float10_min(NULL, 0, &x, s);
  if (x != s) {
    ret++;
    printf("Error min: %Lf != %Lf\n", x, s);
  }
  __kmpc_atomic_float10_min(NULL, 0, &x, e); // no-op
  if (x != s) {
    ret++;
    printf("Error min: %Lf != %Lf\n", x, s);
  }

// max_cpt old
//  #pragma omp atomic compare update capture
//    { v = x; if (x < d) x = d; }
  v = __kmpc_atomic_float10_max_cpt(NULL, 0, &x, d, 0);
  if (x != d) {
    ret++;
    printf("Error max_cpt obj: %Lf != %Lf\n", x, d);
  }
  if (v != s) {
    ret++;
    printf("Error max_cpt cpt: %Lf != %Lf\n", v, s);
  }
  v = __kmpc_atomic_float10_max_cpt(NULL, 0, &x, e, 0); // no-op
  if (x != d) {
    ret++;
    printf("Error max_cpt obj: %Lf != %Lf\n", x, d);
  }
  if (v != d) {
    ret++;
    printf("Error max_cpt cpt: %Lf != %Lf\n", v, d);
  }

// min_cpt old
//  #pragma omp atomic compare update capture
//    { v = x; if (x > d) x = d; }
  v = __kmpc_atomic_float10_min_cpt(NULL, 0, &x, s, 0);
  if (x != s) {
    ret++;
    printf("Error min_cpt obj: %Lf != %Lf\n", x, s);
  }
  if (v != d) {
    ret++;
    printf("Error min_cpt cpt: %Lf != %Lf\n", v, d);
  }
  v = __kmpc_atomic_float10_min_cpt(NULL, 0, &x, e, 0); // no-op
  if (x != s) {
    ret++;
    printf("Error max_cpt obj: %Lf != %Lf\n", x, s);
  }
  if (v != s) {
    ret++;
    printf("Error max_cpt cpt: %Lf != %Lf\n", v, s);
  }

// max_cpt new
//  #pragma omp atomic compare update capture
//    { if (x < d) x = d; v = x; }
  v = __kmpc_atomic_float10_max_cpt(NULL, 0, &x, d, 1);
  if (x != d) {
    ret++;
    printf("Error max_cpt obj: %Lf != %Lf\n", x, d);
  }
  if (v != d) {
    ret++;
    printf("Error max_cpt cpt: %Lf != %Lf\n", v, d);
  }
  v = __kmpc_atomic_float10_max_cpt(NULL, 0, &x, e, 1); // no-op
  if (x != d) {
    ret++;
    printf("Error max_cpt obj: %Lf != %Lf\n", x, d);
  }
  if (v != d) {
    ret++;
    printf("Error max_cpt cpt: %Lf != %Lf\n", v, d);
  }

// min_cpt new
//  #pragma omp atomic compare update capture
//    { if (x > d) x = d; v = x; }
  v = __kmpc_atomic_float10_min_cpt(NULL, 0, &x, s, 1);
  if (x != s) {
    ret++;
    printf("Error min_cpt obj: %Lf != %Lf\n", x, s);
  }
  if (v != s) {
    ret++;
    printf("Error min_cpt cpt: %Lf != %Lf\n", v, s);
  }
  v = __kmpc_atomic_float10_min_cpt(NULL, 0, &x, e, 1); // no-op
  if (x != s) {
    ret++;
    printf("Error max_cpt obj: %Lf != %Lf\n", x, s);
  }
  if (v != s) {
    ret++;
    printf("Error max_cpt cpt: %Lf != %Lf\n", v, s);
  }

  if (ret == 0)
    printf("passed\n");
#else
  printf("Unsupported architecture, skipping test...\n");
#endif // KMP_ARCH_X86 || KMP_ARCH_X86_64
  return ret;
}