added support for global atomics
This commit is contained in:
43
stdlib.ispc
43
stdlib.ispc
@@ -1842,8 +1842,12 @@ static inline TA atomic_##OPA##_global(uniform TA * varying ptr, TA value) { \
|
||||
} \
|
||||
} \
|
||||
|
||||
#define DEFINE_ATOMIC_SWAP(TA,TB) \
|
||||
#define DEFINE_ATOMIC_SWAP(TA,TB,MASKTYPE,TC) \
|
||||
static inline TA atomic_swap_global(uniform TA * uniform ptr, TA value) { \
|
||||
if (__is_nvptx_target) { \
|
||||
TA ret = __atomic_swap_varying_##TB##_global((TC)ptr, value, (MASKTYPE)__mask); \
|
||||
return ret; \
|
||||
} else { \
|
||||
uniform int i = 0; \
|
||||
TA ret[programCount]; \
|
||||
TA memVal; \
|
||||
@@ -1874,6 +1878,7 @@ static inline TA atomic_swap_global(uniform TA * uniform ptr, TA value) { \
|
||||
originally got back from memory... */ \
|
||||
ret[lastSwap] = memVal; \
|
||||
return ret[programIndex]; \
|
||||
}\
|
||||
} \
|
||||
static inline uniform TA atomic_swap_global(uniform TA * uniform ptr, \
|
||||
uniform TA value) { \
|
||||
@@ -1881,6 +1886,10 @@ static inline uniform TA atomic_swap_global(uniform TA * uniform ptr, \
|
||||
return ret; \
|
||||
} \
|
||||
static inline TA atomic_swap_global(uniform TA * varying ptr, TA value) { \
|
||||
if (__is_nvptx_target) { \
|
||||
TA ret = __atomic_swap_varying_##TB##_global((TC)ptr, value, (MASKTYPE)__mask); \
|
||||
return ret; \
|
||||
} else { \
|
||||
uniform TA * uniform ptrArray[programCount]; \
|
||||
ptrArray[programIndex] = ptr; \
|
||||
TA ret; \
|
||||
@@ -1891,6 +1900,7 @@ static inline TA atomic_swap_global(uniform TA * varying ptr, TA value) { \
|
||||
ret = insert(ret, i, r); \
|
||||
} \
|
||||
return ret; \
|
||||
}\
|
||||
} \
|
||||
|
||||
#define DEFINE_ATOMIC_MINMAX_OP(TA,TB,OPA,OPB,MASKTYPE,TC) \
|
||||
@@ -1932,7 +1942,7 @@ DEFINE_ATOMIC_MINMAX_OP(int32,int32,max,max,IntMaskType,int64)
|
||||
DEFINE_ATOMIC_OP(int32,int32,and,and,IntMaskType,int64)
|
||||
DEFINE_ATOMIC_OP(int32,int32,or,or,IntMaskType,int64)
|
||||
DEFINE_ATOMIC_OP(int32,int32,xor,xor,IntMaskType,int64)
|
||||
DEFINE_ATOMIC_SWAP(int32,int32)
|
||||
DEFINE_ATOMIC_SWAP(int32,int32,IntMaskType,int64)
|
||||
|
||||
// For everything but atomic min and max, we can use the same
|
||||
// implementations for unsigned as for signed.
|
||||
@@ -1943,9 +1953,9 @@ DEFINE_ATOMIC_MINMAX_OP(unsigned int32,uint32,max,umax,UIntMaskType,unsigned int
|
||||
DEFINE_ATOMIC_OP(unsigned int32,int32,and,and,UIntMaskType, unsigned int64)
|
||||
DEFINE_ATOMIC_OP(unsigned int32,int32,or,or,UIntMaskType, unsigned int64)
|
||||
DEFINE_ATOMIC_OP(unsigned int32,int32,xor,xor,UIntMaskType, unsigned int64)
|
||||
DEFINE_ATOMIC_SWAP(unsigned int32,int32)
|
||||
DEFINE_ATOMIC_SWAP(unsigned int32,int32,UIntMaskType, unsigned int64)
|
||||
|
||||
DEFINE_ATOMIC_SWAP(float,float)
|
||||
DEFINE_ATOMIC_SWAP(float,float,IntMaskType,int64)
|
||||
|
||||
DEFINE_ATOMIC_OP(int64,int64,add,add,IntMaskType,int64)
|
||||
DEFINE_ATOMIC_OP(int64,int64,subtract,sub,IntMaskType,int64)
|
||||
@@ -1954,7 +1964,7 @@ DEFINE_ATOMIC_MINMAX_OP(int64,int64,max,max,IntMaskType,int64)
|
||||
DEFINE_ATOMIC_OP(int64,int64,and,and,IntMaskType,int64)
|
||||
DEFINE_ATOMIC_OP(int64,int64,or,or,IntMaskType,int64)
|
||||
DEFINE_ATOMIC_OP(int64,int64,xor,xor,IntMaskType,int64)
|
||||
DEFINE_ATOMIC_SWAP(int64,int64)
|
||||
DEFINE_ATOMIC_SWAP(int64,int64,IntMaskType, int64)
|
||||
|
||||
// For everything but atomic min and max, we can use the same
|
||||
// implementations for unsigned as for signed.
|
||||
@@ -1965,15 +1975,15 @@ DEFINE_ATOMIC_MINMAX_OP(unsigned int64,uint64,max,umax,UIntMaskType,unsigned int
|
||||
DEFINE_ATOMIC_OP(unsigned int64,int64,and,and,UIntMaskType,unsigned int64)
|
||||
DEFINE_ATOMIC_OP(unsigned int64,int64,or,or,UIntMaskType,unsigned int64)
|
||||
DEFINE_ATOMIC_OP(unsigned int64,int64,xor,xor,UIntMaskType,unsigned int64)
|
||||
DEFINE_ATOMIC_SWAP(unsigned int64,int64)
|
||||
DEFINE_ATOMIC_SWAP(unsigned int64,int64,UIntMaskType, unsigned int64)
|
||||
|
||||
DEFINE_ATOMIC_SWAP(double,double)
|
||||
DEFINE_ATOMIC_SWAP(double,double,IntMaskType, int64)
|
||||
|
||||
#undef DEFINE_ATOMIC_OP
|
||||
#undef DEFINE_ATOMIC_MINMAX_OP
|
||||
#undef DEFINE_ATOMIC_SWAP
|
||||
|
||||
#define ATOMIC_DECL_CMPXCHG(TA, TB, MASKTYPE) \
|
||||
#define ATOMIC_DECL_CMPXCHG(TA, TB, MASKTYPE, TC) \
|
||||
static inline uniform TA atomic_compare_exchange_global( \
|
||||
uniform TA * uniform ptr, uniform TA oldval, uniform TA newval) { \
|
||||
uniform TA ret = \
|
||||
@@ -1988,6 +1998,10 @@ static inline TA atomic_compare_exchange_global( \
|
||||
} \
|
||||
static inline TA atomic_compare_exchange_global( \
|
||||
uniform TA * varying ptr, TA oldval, TA newval) { \
|
||||
if (__is_nvptx_target) { \
|
||||
TA ret = __atomic_compare_exchange_varying_##TB##_global((TC)ptr, oldval, newval, (MASKTYPE)__mask); \
|
||||
return ret; \
|
||||
} else { \
|
||||
uniform TA * uniform ptrArray[programCount]; \
|
||||
ptrArray[programIndex] = ptr; \
|
||||
TA ret; \
|
||||
@@ -1999,14 +2013,15 @@ static inline TA atomic_compare_exchange_global( \
|
||||
ret = insert(ret, i, r); \
|
||||
} \
|
||||
return ret; \
|
||||
} \
|
||||
}
|
||||
|
||||
ATOMIC_DECL_CMPXCHG(int32, int32, IntMaskType)
|
||||
ATOMIC_DECL_CMPXCHG(unsigned int32, int32, UIntMaskType)
|
||||
ATOMIC_DECL_CMPXCHG(float, float, IntMaskType)
|
||||
ATOMIC_DECL_CMPXCHG(int64, int64, IntMaskType)
|
||||
ATOMIC_DECL_CMPXCHG(unsigned int64, int64, UIntMaskType)
|
||||
ATOMIC_DECL_CMPXCHG(double, double, IntMaskType)
|
||||
ATOMIC_DECL_CMPXCHG(int32, int32, IntMaskType,int64)
|
||||
ATOMIC_DECL_CMPXCHG(unsigned int32, int32, UIntMaskType,unsigned int64)
|
||||
ATOMIC_DECL_CMPXCHG(float, float, IntMaskType,int64)
|
||||
ATOMIC_DECL_CMPXCHG(int64, int64, IntMaskType,int64)
|
||||
ATOMIC_DECL_CMPXCHG(unsigned int64, int64, UIntMaskType,unsigned int64)
|
||||
ATOMIC_DECL_CMPXCHG(double, double, IntMaskType,int64)
|
||||
|
||||
#undef ATOMIC_DECL_CMPXCHG
|
||||
|
||||
|
||||
Reference in New Issue
Block a user