|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | + |
| 9 | +#include <spirv/spirv.h> |
| 10 | + |
| 11 | +// TODO: Stop manually mangling this name. Need C++ namespaces to get the exact mangling. |
| 12 | + |
| 13 | +#define FDECL(TYPE, PREFIX, AS, BYTE_SIZE, MEM_ORDER) \ |
| 14 | +TYPE __clc__atomic_##PREFIX##load_##AS##_##BYTE_SIZE##_##MEM_ORDER(volatile AS const TYPE *); |
| 15 | + |
| 16 | +#define IMPL(TYPE, TYPE_MANGLED, AS, AS_MANGLED, PREFIX, BYTE_SIZE) \ |
| 17 | +FDECL(TYPE, PREFIX, AS, BYTE_SIZE, unordered) \ |
| 18 | +FDECL(TYPE, PREFIX, AS, BYTE_SIZE, acquire) \ |
| 19 | +FDECL(TYPE, PREFIX, AS, BYTE_SIZE, seq_cst) \ |
| 20 | +_CLC_DEF TYPE _Z18__spirv_AtomicLoadPU3##AS_MANGLED##K##TYPE_MANGLED##N5__spv5ScopeENS1_19MemorySemanticsMaskE( \ |
| 21 | + volatile AS const TYPE *p, enum Scope scope, enum MemorySemanticsMask semantics) { \ |
| 22 | + if (semantics == Acquire) { \ |
| 23 | + return __clc__atomic_##PREFIX##load_##AS##_##BYTE_SIZE##_acquire(p); \ |
| 24 | + } \ |
| 25 | + if (semantics == SequentiallyConsistent) { \ |
| 26 | + return __clc__atomic_##PREFIX##load_##AS##_##BYTE_SIZE##_seq_cst(p); \ |
| 27 | + } \ |
| 28 | + return __clc__atomic_##PREFIX##load_##AS##_##BYTE_SIZE##_unordered(p); \ |
| 29 | +} |
| 30 | + |
| 31 | +#define IMPL_AS(TYPE, TYPE_MANGLED, PREFIX, BYTE_SIZE) \ |
| 32 | +IMPL(TYPE, TYPE_MANGLED, global, AS1, PREFIX, BYTE_SIZE) \ |
| 33 | +IMPL(TYPE, TYPE_MANGLED, local, AS3, PREFIX, BYTE_SIZE) |
| 34 | + |
| 35 | +IMPL_AS(int, i, , 4) |
| 36 | +IMPL_AS(unsigned int, j, u, 4) |
| 37 | + |
| 38 | +#ifdef cl_khr_int64_base_atomics |
| 39 | +IMPL_AS(long, l, , 8) |
| 40 | +IMPL_AS(unsigned long, m, u, 8) |
| 41 | +IMPL_AS(long, x, , 8) |
| 42 | +IMPL_AS(unsigned long, y, u, 8) |
| 43 | +#endif |
| 44 | + |
| 45 | +#undef FDECL |
| 46 | +#undef IMPL_AS |
| 47 | +#undef IMPL |
0 commit comments