Hi Mats,
We are also working on OpenCL. We have implemented some of OpenCL functions using clang's builtin functions. For example,
int atomic_or(volatile int local * p, int val) { return atomic_or(p, val); }
...
int atomic_max(volatile int global * p, int val) { return atomic_max(p, val); }
int atomic_max(volatile uint global * p, uint val) { return atomic_max(p, val); }
...
template <typename P, typename T>
T atomic_or(P p, const T t) {
return __sync_fetch_and_or(p, t);
}
template <typename P, typename T>
int atomic_max(volatile int global *p, const int t) {
if (__is_signedof(T))
return __sync_fetch_and_max(reinterpret_cast<volatile T *>(p), t);
else
return __sync_fetch_and_umax(reinterpret_cast<volatile T *>(p), t);
}
'__sync_fetch_and_or' and '__sync_fetch_and_[u]max' function's prototypes are as follows:
BUILTIN(__sync_fetch_and_or, "v.", "t")
...
BUILTIN(__sync_fetch_and_min, "iiD*i", "n")
BUILTIN(__sync_fetch_and_max, "iiD*i", "n")
BUILTIN(__sync_fetch_and_umin, "UiUiD*Ui", "n")
BUILTIN(__sync_fetch_and_umax, "UiUiD*Ui", "n")
If builtin functions use custom type checking like '__sync_fetch_and_or', it is not problem. But we should match the function prototype in other cases like '__sync_fetch_and_max'. So we need to strip address space qualifier In order to call '__sync_fetch_and_max' function.
I think it depends on just only our implementation so I wanted to check some ways to strip address space qualifier.
Thanks,
JinGu Kang