HCC
HCC is a single-source, C/C++ compiler for heterogeneous computing. It's optimized with HSA (http://www.hsafoundation.com/).
hsa_atomic.h
1 #pragma once
2 
3 #define HSAIL_BUILTIN_GPU __attribute__((hc))
4 #define HSAIL_BUILTIN_CPU __attribute__((cpu)) inline
5 
6 #ifdef __KALMAR_ACCELERATOR__
7 
8 // fetch_add
9 extern "C" HSAIL_BUILTIN_GPU int __hsail_atomic_fetch_add_int(int* dest, int val);
10 extern "C" HSAIL_BUILTIN_GPU unsigned int __hsail_atomic_fetch_add_unsigned(unsigned int* dest, unsigned int val);
11 extern "C" HSAIL_BUILTIN_GPU int64_t __hsail_atomic_fetch_add_int64(int64_t* dest, int64_t val);
12 extern "C" HSAIL_BUILTIN_GPU uint64_t __hsail_atomic_fetch_add_uint64(uint64_t* dest, uint64_t val);
13 
14 // fetch_sub
15 extern "C" HSAIL_BUILTIN_GPU int __hsail_atomic_fetch_sub_int(int* dest, int val);
16 extern "C" HSAIL_BUILTIN_GPU unsigned int __hsail_atomic_fetch_sub_unsigned(unsigned int* dest, unsigned int val);
17 extern "C" HSAIL_BUILTIN_GPU int64_t __hsail_atomic_fetch_sub_int64(int64_t* dest, int64_t val);
18 extern "C" HSAIL_BUILTIN_GPU uint64_t __hsail_atomic_fetch_sub_uint64(uint64_t* dest, uint64_t val);
19 
20 // fetch_and
21 extern "C" HSAIL_BUILTIN_GPU int __hsail_atomic_fetch_and_int(int* dest, int val);
22 extern "C" HSAIL_BUILTIN_GPU unsigned int __hsail_atomic_fetch_and_unsigned(unsigned int* dest, unsigned int val);
23 extern "C" HSAIL_BUILTIN_GPU int64_t __hsail_atomic_fetch_and_int64(int64_t* dest, int64_t val);
24 extern "C" HSAIL_BUILTIN_GPU uint64_t __hsail_atomic_fetch_and_uint64(uint64_t* dest, uint64_t val);
25 
26 // fetch_or
27 extern "C" HSAIL_BUILTIN_GPU int __hsail_atomic_fetch_or_int(int* dest, int val);
28 extern "C" HSAIL_BUILTIN_GPU unsigned int __hsail_atomic_fetch_or_unsigned(unsigned int* dest, unsigned int val);
29 extern "C" HSAIL_BUILTIN_GPU int64_t __hsail_atomic_fetch_or_int64(int64_t* dest, int64_t val);
30 extern "C" HSAIL_BUILTIN_GPU uint64_t __hsail_atomic_fetch_or_uint64(uint64_t* dest, uint64_t val);
31 
32 // fetch_xor
33 extern "C" HSAIL_BUILTIN_GPU int __hsail_atomic_fetch_xor_int(int* dest, int val);
34 extern "C" HSAIL_BUILTIN_GPU unsigned int __hsail_atomic_fetch_xor_unsigned(unsigned int* dest, unsigned int val);
35 extern "C" HSAIL_BUILTIN_GPU int64_t __hsail_atomic_fetch_xor_int64(int64_t* dest, int64_t val);
36 extern "C" HSAIL_BUILTIN_GPU uint64_t __hsail_atomic_fetch_xor_uint64(uint64_t* dest, uint64_t val);
37 
38 // exchange
39 extern "C" HSAIL_BUILTIN_GPU int __hsail_atomic_exchange_int(int* dest, int val);
40 extern "C" HSAIL_BUILTIN_GPU unsigned int __hsail_atomic_exchange_unsigned(unsigned int* dest, unsigned int val);
41 extern "C" HSAIL_BUILTIN_GPU int64_t __hsail_atomic_exchange_int64(int64_t* dest, int64_t val);
42 extern "C" HSAIL_BUILTIN_GPU uint64_t __hsail_atomic_exchange_uint64(uint64_t* dest, uint64_t val);
43 
44 // compare_exchange
45 extern "C" HSAIL_BUILTIN_GPU int __hsail_atomic_compare_exchange_int(int* dest, int compare, int val);
46 extern "C" HSAIL_BUILTIN_GPU unsigned int __hsail_atomic_compare_exchange_unsigned(unsigned int* dest, unsigned int compare, unsigned int val);
47 extern "C" HSAIL_BUILTIN_GPU int64_t __hsail_atomic_compare_exchange_int64(int64_t* dest, int64_t compare, int64_t val);
48 extern "C" HSAIL_BUILTIN_GPU uint64_t __hsail_atomic_compare_exchange_uint64(uint64_t* dest, uint64_t compare, uint64_t val);
49 
50 #else
51 
52 // fetch_add
53 extern "C" HSAIL_BUILTIN_CPU int __hsail_atomic_fetch_add_int(int* dest, int val)
54 { return __sync_fetch_and_add(dest, val); }
55 
56 extern "C" HSAIL_BUILTIN_CPU unsigned int __hsail_atomic_fetch_add_unsigned(unsigned int* dest, unsigned int val)
57 { return __sync_fetch_and_add(dest, val); }
58 
59 extern "C" HSAIL_BUILTIN_CPU int64_t __hsail_atomic_fetch_add_int64(int64_t* dest, int64_t val)
60 { return __sync_fetch_and_add(dest, val); }
61 
62 extern "C" HSAIL_BUILTIN_CPU uint64_t __hsail_atomic_fetch_add_uint64(uint64_t* dest, uint64_t val)
63 { return __sync_fetch_and_add(dest, val); }
64 
65 // fetch_sub
66 extern "C" HSAIL_BUILTIN_CPU int __hsail_atomic_fetch_sub_int(int* dest, int val)
67 { return __sync_fetch_and_sub(dest, val); }
68 
69 extern "C" HSAIL_BUILTIN_CPU unsigned int __hsail_atomic_fetch_sub_unsigned(unsigned int* dest, unsigned int val)
70 { return __sync_fetch_and_sub(dest, val); }
71 
72 extern "C" HSAIL_BUILTIN_CPU int64_t __hsail_atomic_fetch_sub_int64(int64_t* dest, int64_t val)
73 { return __sync_fetch_and_sub(dest, val); }
74 
75 extern "C" HSAIL_BUILTIN_CPU uint64_t __hsail_atomic_fetch_sub_uint64(uint64_t* dest, uint64_t val)
76 { return __sync_fetch_and_sub(dest, val); }
77 
78 // fetch_and
79 extern "C" HSAIL_BUILTIN_CPU int __hsail_atomic_fetch_and_int(int* dest, int val)
80 { return __sync_fetch_and_and(dest, val); }
81 
82 extern "C" HSAIL_BUILTIN_CPU unsigned int __hsail_atomic_fetch_and_unsigned(unsigned int* dest, unsigned int val)
83 { return __sync_fetch_and_and(dest, val); }
84 
85 extern "C" HSAIL_BUILTIN_CPU int64_t __hsail_atomic_fetch_and_int64(int64_t* dest, int64_t val)
86 { return __sync_fetch_and_and(dest, val); }
87 
88 extern "C" HSAIL_BUILTIN_CPU uint64_t __hsail_atomic_fetch_and_uint64(uint64_t* dest, uint64_t val)
89 { return __sync_fetch_and_and(dest, val); }
90 
91 // fetch_or
92 extern "C" HSAIL_BUILTIN_CPU int __hsail_atomic_fetch_or_int(int* dest, int val)
93 { return __sync_fetch_and_or(dest, val); }
94 
95 extern "C" HSAIL_BUILTIN_CPU unsigned int __hsail_atomic_fetch_or_unsigned(unsigned int* dest, unsigned int val)
96 { return __sync_fetch_and_or(dest, val); }
97 
98 extern "C" HSAIL_BUILTIN_CPU int64_t __hsail_atomic_fetch_or_int64(int64_t* dest, int64_t val)
99 { return __sync_fetch_and_or(dest, val); }
100 
101 extern "C" HSAIL_BUILTIN_CPU uint64_t __hsail_atomic_fetch_or_uint64(uint64_t* dest, uint64_t val)
102 { return __sync_fetch_and_or(dest, val); }
103 
104 // fetch_xor
105 extern "C" HSAIL_BUILTIN_CPU int __hsail_atomic_fetch_xor_int(int* dest, int val)
106 { return __sync_fetch_and_xor(dest, val); }
107 
108 extern "C" HSAIL_BUILTIN_CPU unsigned int __hsail_atomic_fetch_xor_unsigned(unsigned int* dest, unsigned int val)
109 { return __sync_fetch_and_xor(dest, val); }
110 
111 extern "C" HSAIL_BUILTIN_CPU int64_t __hsail_atomic_fetch_xor_int64(int64_t* dest, int64_t val)
112 { return __sync_fetch_and_xor(dest, val); }
113 
114 extern "C" HSAIL_BUILTIN_CPU uint64_t __hsail_atomic_fetch_xor_uint64(uint64_t* dest, uint64_t val)
115 { return __sync_fetch_and_xor(dest, val); }
116 
117 // exchange
118 extern "C" HSAIL_BUILTIN_CPU int __hsail_atomic_exchange_int(int* dest, int val)
119 { return __sync_swap(dest, val); }
120 
121 extern "C" HSAIL_BUILTIN_CPU unsigned int __hsail_atomic_exchange_unsigned(unsigned int* dest, unsigned int val)
122 { return __sync_swap(dest, val); }
123 
124 extern "C" HSAIL_BUILTIN_CPU int64_t __hsail_atomic_exchange_int64(int64_t* dest, int64_t val)
125 { return __sync_swap(dest, val); }
126 
127 extern "C" HSAIL_BUILTIN_CPU uint64_t __hsail_atomic_exchange_uint64(uint64_t* dest, uint64_t val)
128 { return __sync_swap(dest, val); }
129 
130 // compare_exchange
131 extern "C" HSAIL_BUILTIN_CPU int __hsail_atomic_compare_exchange_int(int* dest, int compare, int val)
132 { return __sync_val_compare_and_swap(dest, compare, val); }
133 
134 extern "C" HSAIL_BUILTIN_CPU unsigned int __hsail_atomic_compare_exchange_unsigned(unsigned int* dest, unsigned int compare, unsigned int val)
135 { return __sync_val_compare_and_swap(dest, compare, val); }
136 
137 extern "C" HSAIL_BUILTIN_CPU int64_t __hsail_atomic_compare_exchange_int64(int64_t* dest, int64_t compare, int64_t val)
138 { return __sync_val_compare_and_swap(dest, compare, val); }
139 
140 extern "C" HSAIL_BUILTIN_CPU uint64_t __hsail_atomic_compare_exchange_uint64(uint64_t* dest, uint64_t compare, uint64_t val)
141 { return __sync_val_compare_and_swap(dest, compare, val); }
142 
143 #endif