|
1 | 1 | ! Copyright (c), The Regents of the University of California |
2 | 2 | ! Terms of use are as specified in LICENSE.txt |
| 3 | + |
| 4 | +#include "assert_macros.h" |
| 5 | +#include "caffeine-internal.h" |
| 6 | + |
3 | 7 | submodule(prif:prif_private_s) atomic_s |
4 | 8 | ! DO NOT ADD USE STATEMENTS HERE |
5 | 9 | ! All use statements belong in prif_private_s.F90 |
6 | 10 | implicit none |
7 | 11 |
|
| 12 | + ! placeholder variables that simplify the macro logic below |
| 13 | + integer(PRIF_ATOMIC_INT_KIND) :: out_placeholder_int |
| 14 | + logical(PRIF_ATOMIC_LOGICAL_KIND) :: out_placeholder_logical |
| 15 | + integer(PRIF_ATOMIC_INT_KIND), parameter :: in_placeholder_int = 0 |
| 16 | + logical(PRIF_ATOMIC_LOGICAL_KIND), parameter :: in_placeholder_logical = .false. |
8 | 17 | contains |
9 | 18 |
|
10 | | - module procedure prif_atomic_add |
11 | | - call unimplemented("prif_atomic_add") |
12 | | - end procedure |
13 | | - |
14 | | - module procedure prif_atomic_add_indirect |
15 | | - call unimplemented("prif_atomic_add_indirect") |
16 | | - end procedure |
17 | | - |
18 | | - module procedure prif_atomic_and |
19 | | - call unimplemented("prif_atomic_and") |
20 | | - end procedure |
21 | | - |
22 | | - module procedure prif_atomic_and_indirect |
23 | | - call unimplemented("prif_atomic_and_indirect") |
24 | | - end procedure |
25 | | - |
26 | | - module procedure prif_atomic_or |
27 | | - call unimplemented("prif_atomic_or") |
28 | | - end procedure |
29 | | - |
30 | | - module procedure prif_atomic_or_indirect |
31 | | - call unimplemented("prif_atomic_or_indirect") |
32 | | - end procedure |
33 | | - |
34 | | - module procedure prif_atomic_xor |
35 | | - call unimplemented("prif_atomic_xor") |
36 | | - end procedure |
37 | | - |
38 | | - module procedure prif_atomic_xor_indirect |
39 | | - call unimplemented("prif_atomic_xor_indirect") |
40 | | - end procedure |
41 | | - |
42 | | - module procedure prif_atomic_cas_int |
43 | | - call unimplemented("prif_atomic_cas_int") |
44 | | - end procedure |
45 | | - |
46 | | - module procedure prif_atomic_cas_int_indirect |
47 | | - call unimplemented("prif_atomic_cas_int_indirect") |
48 | | - end procedure |
49 | | - |
50 | | - module procedure prif_atomic_cas_logical |
51 | | - call unimplemented("prif_atomic_cas_logical") |
52 | | - end procedure |
53 | | - |
54 | | - module procedure prif_atomic_cas_logical_indirect |
55 | | - call unimplemented("prif_atomic_cas_logical_indirect") |
56 | | - end procedure |
57 | | - |
58 | | - module procedure prif_atomic_fetch_add |
59 | | - call unimplemented("prif_atomic_fetch_add") |
60 | | - end procedure |
61 | | - |
62 | | - module procedure prif_atomic_fetch_add_indirect |
63 | | - call unimplemented("prif_atomic_fetch_add_indirect") |
64 | | - end procedure |
65 | | - |
66 | | - module procedure prif_atomic_fetch_and |
67 | | - call unimplemented("prif_atomic_fetch_and") |
68 | | - end procedure |
69 | | - |
70 | | - module procedure prif_atomic_fetch_and_indirect |
71 | | - call unimplemented("prif_atomic_fetch_and_indirect") |
72 | | - end procedure |
73 | | - |
74 | | - module procedure prif_atomic_fetch_or |
75 | | - call unimplemented("prif_atomic_fetch_or") |
76 | | - end procedure |
77 | | - |
78 | | - module procedure prif_atomic_fetch_or_indirect |
79 | | - call unimplemented("prif_atomic_fetch_or_indirect") |
80 | | - end procedure |
81 | | - |
82 | | - module procedure prif_atomic_fetch_xor |
83 | | - call unimplemented("prif_atomic_fetch_xor") |
84 | | - end procedure |
85 | | - |
86 | | - module procedure prif_atomic_fetch_xor_indirect |
87 | | - call unimplemented("prif_atomic_fetch_xor_indirect") |
88 | | - end procedure |
89 | | - |
90 | | - module procedure prif_atomic_define_int |
91 | | - call unimplemented("prif_atomic_define_int") |
92 | | - end procedure |
93 | | - |
94 | | - module procedure prif_atomic_define_int_indirect |
95 | | - call unimplemented("prif_atomic_define_int_indirect") |
96 | | - end procedure |
97 | | - |
98 | | - module procedure prif_atomic_define_logical |
99 | | - call unimplemented("prif_atomic_define_logical") |
100 | | - end procedure |
101 | | - |
102 | | - module procedure prif_atomic_define_logical_indirect |
103 | | - call unimplemented("prif_atomic_define_logical_indirect") |
104 | | - end procedure |
105 | | - |
106 | | - module procedure prif_atomic_ref_int |
107 | | - call unimplemented("prif_atomic_ref_int") |
108 | | - end procedure |
109 | | - |
110 | | - module procedure prif_atomic_ref_int_indirect |
111 | | - call unimplemented("prif_atomic_ref_int_indirect") |
112 | | - end procedure |
113 | | - |
114 | | - module procedure prif_atomic_ref_logical |
115 | | - call unimplemented("prif_atomic_ref_logical") |
116 | | - end procedure |
117 | | - |
118 | | - module procedure prif_atomic_ref_logical_indirect |
119 | | - call unimplemented("prif_atomic_ref_logical_indirect") |
120 | | - end procedure |
| 19 | +#define ATOMIC_OP(OPNAME, OPCODE, caf_op) \ |
| 20 | + module procedure CAF_CONCAT2(prif_atomic_,OPNAME) ; \ |
| 21 | + integer(c_intptr_t) :: remote_base; \ |
| 22 | + call_assert(offset >= 0); \ |
| 23 | + call base_pointer(coarray_handle, image_num, remote_base); \ |
| 24 | + call CAF_CONCAT3(prif_atomic_,OPNAME,_indirect) \ |
| 25 | + ( image_num, remote_base + offset, OPPASSF, stat ); \ |
| 26 | + end procedure ; \ |
| 27 | + module procedure CAF_CONCAT3(prif_atomic_,OPNAME,_indirect) ; \ |
| 28 | + call_assert(c_sizeof(out_placeholder_int) == 8); call_assert(c_sizeof(out_placeholder_logical) == 8); \ |
| 29 | + call_assert_describe(image_num > 0 .and. image_num <= initial_team%num_images, "image_num not within valid range"); \ |
| 30 | + call caf_op(CAF_CONCAT2(CAF_OP_,OPCODE), image_num, atom_remote_ptr, OPPASSC); \ |
| 31 | + if (present(stat)) stat = 0; \ |
| 32 | + end procedure |
| 33 | + |
| 34 | +! Extra arg below is another workaround gfortran's sub-standard preprocessor |
| 35 | +#define ATOMIC_INT_OP(OPNAME,_,OPCODE) ATOMIC_OP(OPNAME,OPCODE,caf_atomic_int) |
| 36 | +#define ATOMIC_LOG_OP(OPNAME,_,OPCODE) ATOMIC_OP(OPNAME,OPCODE,caf_atomic_logical) |
| 37 | + |
| 38 | +! OPPASSF defines the dummy argument pass-thru in Fortran, |
| 39 | +! from the direct module procedure to the indirect variant |
| 40 | +#undef OPPASSF |
| 41 | +#define OPPASSF value |
| 42 | +! OPPASSC defines the dummy argument pass-thru to C, |
| 43 | +! from the indirect module procedure to the BIND(C) call |
| 44 | +#undef OPPASSC |
| 45 | +#define OPPASSC value, in_placeholder_int, in_placeholder_int |
| 46 | + ATOMIC_INT_OP(ref_int, ,GET) |
| 47 | +#undef OPPASSC |
| 48 | +#define OPPASSC value, in_placeholder_logical, in_placeholder_logical |
| 49 | + ATOMIC_LOG_OP(ref_logical, ,GET) |
| 50 | +#undef OPPASSC |
| 51 | +#define OPPASSC out_placeholder_logical, value, in_placeholder_logical |
| 52 | + ATOMIC_LOG_OP(define_logical, ,SET) |
| 53 | +#undef OPPASSC |
| 54 | +#define OPPASSC out_placeholder_int, value, in_placeholder_int |
| 55 | + ATOMIC_INT_OP(define_int, ,SET) |
| 56 | + |
| 57 | + ATOMIC_INT_OP(add, ,ADD) |
| 58 | + ATOMIC_INT_OP(and, ,AND) |
| 59 | + ATOMIC_INT_OP(or, ,OR) |
| 60 | + ATOMIC_INT_OP(xor, ,XOR) |
| 61 | + |
| 62 | +#undef OPPASSF |
| 63 | +#define OPPASSF value, old |
| 64 | +#undef OPPASSC |
| 65 | +#define OPPASSC old, value, in_placeholder_int |
| 66 | + ATOMIC_INT_OP(fetch_add, ,FADD) |
| 67 | + ATOMIC_INT_OP(fetch_and, ,FAND) |
| 68 | + ATOMIC_INT_OP(fetch_or, ,FOR) |
| 69 | + ATOMIC_INT_OP(fetch_xor, ,FXOR) |
| 70 | + |
| 71 | +#undef OPPASSF |
| 72 | +#define OPPASSF old, compare, new |
| 73 | +#undef OPPASSC |
| 74 | +#define OPPASSC old, compare, new |
| 75 | + ATOMIC_INT_OP(cas_int, ,FCAS) |
| 76 | + ATOMIC_LOG_OP(cas_logical, ,FCAS) |
121 | 77 |
|
122 | 78 | end submodule atomic_s |
0 commit comments