diff --git a/libclc/generic/include/clc/atomic/atomic_xchg.h b/libclc/generic/include/clc/atomic/atomic_xchg.h new file mode 100644 index 000000000000..7add098c7732 --- /dev/null +++ b/libclc/generic/include/clc/atomic/atomic_xchg.h @@ -0,0 +1,5 @@ +#define __CLC_FUNCTION atomic_xchg +#include +__CLC_DECLARE_ATOMIC_ADDRSPACE(float); +#undef __CLC_FUNCTION +#undef __CLC_DECLARE_ATOMIC_ADDRSPACE diff --git a/libclc/generic/include/clc/cl_khr_global_int32_base_atomics/atom_xchg.h b/libclc/generic/include/clc/cl_khr_global_int32_base_atomics/atom_xchg.h new file mode 100644 index 000000000000..6a18e9e8e1b1 --- /dev/null +++ b/libclc/generic/include/clc/cl_khr_global_int32_base_atomics/atom_xchg.h @@ -0,0 +1,2 @@ +_CLC_OVERLOAD _CLC_DECL int atom_xchg(global int *p, int val); +_CLC_OVERLOAD _CLC_DECL unsigned int atom_xchg(global unsigned int *p, unsigned int val); diff --git a/libclc/generic/include/clc/cl_khr_local_int32_base_atomics/atom_xchg.h b/libclc/generic/include/clc/cl_khr_local_int32_base_atomics/atom_xchg.h new file mode 100644 index 000000000000..c5a1f09b0849 --- /dev/null +++ b/libclc/generic/include/clc/cl_khr_local_int32_base_atomics/atom_xchg.h @@ -0,0 +1,2 @@ +_CLC_OVERLOAD _CLC_DECL int atom_xchg(local int *p, int val); +_CLC_OVERLOAD _CLC_DECL unsigned int atom_xchg(local unsigned int *p, unsigned int val); diff --git a/libclc/generic/include/clc/clc.h b/libclc/generic/include/clc/clc.h index 45bcf4726272..a9988c1c5725 100644 --- a/libclc/generic/include/clc/clc.h +++ b/libclc/generic/include/clc/clc.h @@ -148,6 +148,7 @@ #include #include #include +#include #include /* cl_khr_global_int32_base_atomics Extension Functions */ @@ -155,6 +156,7 @@ #include #include #include +#include /* cl_khr_global_int32_extended_atomics Extension Functions */ #include @@ -168,6 +170,7 @@ #include #include #include +#include /* cl_khr_local_int32_extended_atomics Extension Functions */ #include diff --git a/libclc/generic/lib/SOURCES b/libclc/generic/lib/SOURCES index 20048ac40e43..a9f1d56451ec 100644 --- a/libclc/generic/lib/SOURCES +++ b/libclc/generic/lib/SOURCES @@ -1,9 +1,11 @@ async/prefetch.cl +atomic/atomic_xchg.cl atomic/atomic_impl.ll cl_khr_global_int32_base_atomics/atom_add.cl cl_khr_global_int32_base_atomics/atom_dec.cl cl_khr_global_int32_base_atomics/atom_inc.cl cl_khr_global_int32_base_atomics/atom_sub.cl +cl_khr_global_int32_base_atomics/atom_xchg.cl cl_khr_global_int32_extended_atomics/atom_and.cl cl_khr_global_int32_extended_atomics/atom_max.cl cl_khr_global_int32_extended_atomics/atom_min.cl @@ -13,6 +15,7 @@ cl_khr_local_int32_base_atomics/atom_add.cl cl_khr_local_int32_base_atomics/atom_dec.cl cl_khr_local_int32_base_atomics/atom_inc.cl cl_khr_local_int32_base_atomics/atom_sub.cl +cl_khr_local_int32_base_atomics/atom_xchg.cl cl_khr_local_int32_extended_atomics/atom_and.cl cl_khr_local_int32_extended_atomics/atom_max.cl cl_khr_local_int32_extended_atomics/atom_min.cl diff --git a/libclc/generic/lib/atomic/atomic_impl.ll b/libclc/generic/lib/atomic/atomic_impl.ll index 792762b21727..b5495cc37883 100644 --- a/libclc/generic/lib/atomic/atomic_impl.ll +++ b/libclc/generic/lib/atomic/atomic_impl.ll @@ -94,6 +94,18 @@ entry: ret i32 %0 } +define i32 @__clc_atomic_xchg_addr1(i32 addrspace(1)* nocapture %ptr, i32 %value) nounwind alwaysinline { +entry: + %0 = atomicrmw volatile xchg i32 addrspace(1)* %ptr, i32 %value seq_cst + ret i32 %0 +} + +define i32 @__clc_atomic_xchg_addr3(i32 addrspace(3)* nocapture %ptr, i32 %value) nounwind alwaysinline { +entry: + %0 = atomicrmw volatile xchg i32 addrspace(3)* %ptr, i32 %value seq_cst + ret i32 %0 +} + define i32 @__clc_atomic_xor_addr1(i32 addrspace(1)* nocapture %ptr, i32 %value) nounwind alwaysinline { entry: %0 = atomicrmw volatile xor i32 addrspace(1)* %ptr, i32 %value seq_cst diff --git a/libclc/generic/lib/atomic/atomic_xchg.cl b/libclc/generic/lib/atomic/atomic_xchg.cl new file mode 100644 index 000000000000..9aee5950141c --- /dev/null +++ b/libclc/generic/lib/atomic/atomic_xchg.cl @@ -0,0 +1,9 @@ +#include + +_CLC_OVERLOAD _CLC_DEF float atomic_xchg(volatile global float *p, float val) { + return as_float(atomic_xchg((volatile global int *)p, as_int(val))); +} + +_CLC_OVERLOAD _CLC_DEF float atomic_xchg(volatile local float *p, float val) { + return as_float(atomic_xchg((volatile local int *)p, as_int(val))); +} diff --git a/libclc/generic/lib/cl_khr_global_int32_base_atomics/atom_xchg.cl b/libclc/generic/lib/cl_khr_global_int32_base_atomics/atom_xchg.cl new file mode 100644 index 000000000000..9c77db13f309 --- /dev/null +++ b/libclc/generic/lib/cl_khr_global_int32_base_atomics/atom_xchg.cl @@ -0,0 +1,9 @@ +#include + +#define IMPL(TYPE) \ +_CLC_OVERLOAD _CLC_DEF TYPE atom_xchg(global TYPE *p, TYPE val) { \ + return atomic_xchg(p, val); \ +} + +IMPL(int) +IMPL(unsigned int) diff --git a/libclc/generic/lib/cl_khr_local_int32_base_atomics/atom_xchg.cl b/libclc/generic/lib/cl_khr_local_int32_base_atomics/atom_xchg.cl new file mode 100644 index 000000000000..7d4bcca3fe7a --- /dev/null +++ b/libclc/generic/lib/cl_khr_local_int32_base_atomics/atom_xchg.cl @@ -0,0 +1,9 @@ +#include + +#define IMPL(TYPE) \ +_CLC_OVERLOAD _CLC_DEF TYPE atom_xchg(local TYPE *p, TYPE val) { \ + return atomic_xchg(p, val); \ +} + +IMPL(int) +IMPL(unsigned int)