• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- SPIRVBuiltin.h - SPIR-V extended instruction --------------*- C++ -*-===//
2 //
3 //                     The LLVM/SPIRV Translator
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 // Copyright (c) 2014 Advanced Micro Devices, Inc. All rights reserved.
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal with the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
16 //
17 // Redistributions of source code must retain the above copyright notice,
18 // this list of conditions and the following disclaimers.
19 // Redistributions in binary form must reproduce the above copyright notice,
20 // this list of conditions and the following disclaimers in the documentation
21 // and/or other materials provided with the distribution.
22 // Neither the names of Advanced Micro Devices, Inc., nor the names of its
23 // contributors may be used to endorse or promote products derived from this
24 // Software without specific prior written permission.
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28 // CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH
31 // THE SOFTWARE.
32 //
33 //===----------------------------------------------------------------------===//
34 /// \file
35 ///
36 /// This file defines SPIR-V extended instructions.
37 ///
38 //===----------------------------------------------------------------------===//
39 
40 #ifndef SPIRVBUILTIN_HPP_
41 #define SPIRVBUILTIN_HPP_
42 
43 #include "SPIRVUtil.h"
44 #include "OpenCL.std.h"
45 
46 #include <string>
47 #include <vector>
48 
49 namespace SPIRV{
50 
51 
52 inline bool
isOpenCLBuiltinSet(SPIRVExtInstSetKind Set)53 isOpenCLBuiltinSet (SPIRVExtInstSetKind Set) {
54   return Set == SPIRVEIS_OpenCL;
55 }
56 
57 typedef OpenCLLIB::Entrypoints OCLExtOpKind;
58 
59 template<> inline void
init()60 SPIRVMap<OCLExtOpKind, std::string>::init() {
61   add(OpenCLLIB::Acos, "acos");
62   add(OpenCLLIB::Acosh, "acosh");
63   add(OpenCLLIB::Acospi, "acospi");
64   add(OpenCLLIB::Asin, "asin");
65   add(OpenCLLIB::Asinh, "asinh");
66   add(OpenCLLIB::Asinpi, "asinpi");
67   add(OpenCLLIB::Atan, "atan");
68   add(OpenCLLIB::Atan2, "atan2");
69   add(OpenCLLIB::Atanh, "atanh");
70   add(OpenCLLIB::Atanpi, "atanpi");
71   add(OpenCLLIB::Atan2pi, "atan2pi");
72   add(OpenCLLIB::Cbrt, "cbrt");
73   add(OpenCLLIB::Ceil, "ceil");
74   add(OpenCLLIB::Copysign, "copysign");
75   add(OpenCLLIB::Cos, "cos");
76   add(OpenCLLIB::Cosh, "cosh");
77   add(OpenCLLIB::Cospi, "cospi");
78   add(OpenCLLIB::Erfc, "erfc");
79   add(OpenCLLIB::Erf, "erf");
80   add(OpenCLLIB::Exp, "exp");
81   add(OpenCLLIB::Exp2, "exp2");
82   add(OpenCLLIB::Exp10, "exp10");
83   add(OpenCLLIB::Expm1, "expm1");
84   add(OpenCLLIB::Fabs, "fabs");
85   add(OpenCLLIB::Fdim, "fdim");
86   add(OpenCLLIB::Floor, "floor");
87   add(OpenCLLIB::Fma, "fma");
88   add(OpenCLLIB::Fmax, "fmax");
89   add(OpenCLLIB::Fmin, "fmin");
90   add(OpenCLLIB::Fmod, "fmod");
91   add(OpenCLLIB::Fract, "fract");
92   add(OpenCLLIB::Frexp, "frexp");
93   add(OpenCLLIB::Hypot, "hypot");
94   add(OpenCLLIB::Ilogb, "ilogb");
95   add(OpenCLLIB::Ldexp, "ldexp");
96   add(OpenCLLIB::Lgamma, "lgamma");
97   add(OpenCLLIB::Lgamma_r, "lgamma_r");
98   add(OpenCLLIB::Log, "log");
99   add(OpenCLLIB::Log2, "log2");
100   add(OpenCLLIB::Log10, "log10");
101   add(OpenCLLIB::Log1p, "log1p");
102   add(OpenCLLIB::Logb, "logb");
103   add(OpenCLLIB::Mad, "mad");
104   add(OpenCLLIB::Maxmag, "maxmag");
105   add(OpenCLLIB::Minmag, "minmag");
106   add(OpenCLLIB::Modf, "modf");
107   add(OpenCLLIB::Nan, "nan");
108   add(OpenCLLIB::Nextafter, "nextafter");
109   add(OpenCLLIB::Pow, "pow");
110   add(OpenCLLIB::Pown, "pown");
111   add(OpenCLLIB::Powr, "powr");
112   add(OpenCLLIB::Remainder, "remainder");
113   add(OpenCLLIB::Remquo, "remquo");
114   add(OpenCLLIB::Rint, "rint");
115   add(OpenCLLIB::Rootn, "rootn");
116   add(OpenCLLIB::Round, "round");
117   add(OpenCLLIB::Rsqrt, "rsqrt");
118   add(OpenCLLIB::Sin, "sin");
119   add(OpenCLLIB::Sincos, "sincos");
120   add(OpenCLLIB::Sinh, "sinh");
121   add(OpenCLLIB::Sinpi, "sinpi");
122   add(OpenCLLIB::Sqrt, "sqrt");
123   add(OpenCLLIB::Tan, "tan");
124   add(OpenCLLIB::Tanh, "tanh");
125   add(OpenCLLIB::Tanpi, "tanpi");
126   add(OpenCLLIB::Tgamma, "tgamma");
127   add(OpenCLLIB::Trunc, "trunc");
128   add(OpenCLLIB::Half_cos, "half_cos");
129   add(OpenCLLIB::Half_divide, "half_divide");
130   add(OpenCLLIB::Half_exp, "half_exp");
131   add(OpenCLLIB::Half_exp2, "half_exp2");
132   add(OpenCLLIB::Half_exp10, "half_exp10");
133   add(OpenCLLIB::Half_log, "half_log");
134   add(OpenCLLIB::Half_log2, "half_log2");
135   add(OpenCLLIB::Half_log10, "half_log10");
136   add(OpenCLLIB::Half_powr, "half_powr");
137   add(OpenCLLIB::Half_recip, "half_recip");
138   add(OpenCLLIB::Half_rsqrt, "half_rsqrt");
139   add(OpenCLLIB::Half_sin, "half_sin");
140   add(OpenCLLIB::Half_sqrt, "half_sqrt");
141   add(OpenCLLIB::Half_tan, "half_tan");
142   add(OpenCLLIB::Native_cos, "native_cos");
143   add(OpenCLLIB::Native_divide, "native_divide");
144   add(OpenCLLIB::Native_exp, "native_exp");
145   add(OpenCLLIB::Native_exp2, "native_exp2");
146   add(OpenCLLIB::Native_exp10, "native_exp10");
147   add(OpenCLLIB::Native_log, "native_log");
148   add(OpenCLLIB::Native_log2, "native_log2");
149   add(OpenCLLIB::Native_log10, "native_log10");
150   add(OpenCLLIB::Native_powr, "native_powr");
151   add(OpenCLLIB::Native_recip, "native_recip");
152   add(OpenCLLIB::Native_rsqrt, "native_rsqrt");
153   add(OpenCLLIB::Native_sin, "native_sin");
154   add(OpenCLLIB::Native_sqrt, "native_sqrt");
155   add(OpenCLLIB::Native_tan, "native_tan");
156   add(OpenCLLIB::FClamp, "fclamp");
157   add(OpenCLLIB::Degrees, "degrees");
158   add(OpenCLLIB::Mix, "mix");
159   add(OpenCLLIB::FMax_common, "fmax_common");
160   add(OpenCLLIB::FMin_common, "fmin_common");
161   add(OpenCLLIB::Radians, "radians");
162   add(OpenCLLIB::Step, "step");
163   add(OpenCLLIB::Smoothstep, "smoothstep");
164   add(OpenCLLIB::Sign, "sign");
165   add(OpenCLLIB::Cross, "cross");
166   add(OpenCLLIB::Distance, "distance");
167   add(OpenCLLIB::Length, "length");
168   add(OpenCLLIB::Normalize, "normalize");
169   add(OpenCLLIB::Fast_distance, "fast_distance");
170   add(OpenCLLIB::Fast_length, "fast_length");
171   add(OpenCLLIB::Fast_normalize, "fast_normalize");
172   add(OpenCLLIB::Read_imagef, "read_imagef");
173   add(OpenCLLIB::Read_imagei, "read_imagei");
174   add(OpenCLLIB::Read_imageui, "read_imageui");
175   add(OpenCLLIB::Read_imageh, "read_imageh");
176   add(OpenCLLIB::Read_imagef_samplerless, "read_imagef_samplerless");
177   add(OpenCLLIB::Read_imagei_samplerless, "read_imagei_samplerless");
178   add(OpenCLLIB::Read_imageui_samplerless, "read_imageui_samplerless");
179   add(OpenCLLIB::Read_imageh_samplerless, "read_imageh_samplerless");
180   add(OpenCLLIB::Write_imagef, "write_imagef");
181   add(OpenCLLIB::Write_imagei, "write_imagei");
182   add(OpenCLLIB::Write_imageui, "write_imageui");
183   add(OpenCLLIB::Write_imageh, "write_imageh");
184   add(OpenCLLIB::Read_imagef_mipmap_lod, "read_imagef_mipmap_lod");
185   add(OpenCLLIB::Read_imagei_mipmap_lod, "read_imagei_mipmap_lod");
186   add(OpenCLLIB::Read_imageui_mipmap_lod, "read_imageui_mipmap_lod");
187   add(OpenCLLIB::Read_imagef_mipmap_grad, "read_imagef_mipmap_gradient");
188   add(OpenCLLIB::Read_imagei_mipmap_grad, "read_imagei_mipmap_gradient");
189   add(OpenCLLIB::Read_imageui_mipmap_grad, "read_imageui_mipmap_gradient");
190   add(OpenCLLIB::Write_imagef_mipmap_lod, "write_imagef_mipmap_lod");
191   add(OpenCLLIB::Write_imagei_mipmap_lod, "write_imagei_mipmap_lod");
192   add(OpenCLLIB::Write_imageui_mipmap_lod, "write_imageui_mipmap_lod");
193   add(OpenCLLIB::Get_image_width, "get_image_width");
194   add(OpenCLLIB::Get_image_height, "get_image_height");
195   add(OpenCLLIB::Get_image_depth, "get_image_depth");
196   add(OpenCLLIB::Get_image_channel_data_type, "get_image_channel_data_type");
197   add(OpenCLLIB::Get_image_channel_order, "get_image_channel_order");
198   add(OpenCLLIB::Get_image_dim, "get_image_dim");
199   add(OpenCLLIB::Get_image_array_size, "get_image_array_size");
200   add(OpenCLLIB::Get_image_num_samples, "get_image_num_samples");
201   add(OpenCLLIB::Get_image_num_mip_levels, "get_image_num_mip_levels");
202   add(OpenCLLIB::SAbs, "s_abs");
203   add(OpenCLLIB::SAbs_diff, "s_abs_diff");
204   add(OpenCLLIB::SAdd_sat, "s_add_sat");
205   add(OpenCLLIB::UAdd_sat, "u_add_sat");
206   add(OpenCLLIB::SHadd, "s_hadd");
207   add(OpenCLLIB::UHadd, "u_hadd");
208   add(OpenCLLIB::SRhadd, "s_rhadd");
209   add(OpenCLLIB::URhadd, "u_rhadd");
210   add(OpenCLLIB::SClamp, "s_clamp");
211   add(OpenCLLIB::UClamp, "u_clamp");
212   add(OpenCLLIB::Clz, "clz");
213   add(OpenCLLIB::Ctz, "ctz");
214   add(OpenCLLIB::SMad_hi, "s_mad_hi");
215   add(OpenCLLIB::SMad_sat, "s_mad_sat");
216   add(OpenCLLIB::UMad_sat, "u_mad_sat");
217   add(OpenCLLIB::SMax, "s_max");
218   add(OpenCLLIB::SMin, "s_min");
219   add(OpenCLLIB::UMax, "u_max");
220   add(OpenCLLIB::UMin, "u_min");
221   add(OpenCLLIB::SMul_hi, "s_mul_hi");
222   add(OpenCLLIB::Rotate, "rotate");
223   add(OpenCLLIB::SSub_sat, "s_sub_sat");
224   add(OpenCLLIB::USub_sat, "u_sub_sat");
225   add(OpenCLLIB::U_Upsample, "u_upsample");
226   add(OpenCLLIB::S_Upsample, "s_upsample");
227   add(OpenCLLIB::Popcount, "popcount");
228   add(OpenCLLIB::SMad24, "s_mad24");
229   add(OpenCLLIB::UMad24, "u_mad24");
230   add(OpenCLLIB::SMul24, "s_mul24");
231   add(OpenCLLIB::UMul24, "u_mul24");
232   add(OpenCLLIB::Vloadn, "vloadn");
233   add(OpenCLLIB::Vstoren, "vstoren");
234   add(OpenCLLIB::Vload_half, "vload_half");
235   add(OpenCLLIB::Vload_halfn, "vload_halfn");
236   add(OpenCLLIB::Vstore_half, "vstore_half");
237   add(OpenCLLIB::Vstore_half_r, "vstore_half_r");
238   add(OpenCLLIB::Vstore_halfn, "vstore_halfn");
239   add(OpenCLLIB::Vstore_halfn_r, "vstore_halfn_r");
240   add(OpenCLLIB::Vloada_halfn, "vloada_halfn");
241   add(OpenCLLIB::Vstorea_halfn, "vstorea_halfn");
242   add(OpenCLLIB::Vstorea_halfn_r, "vstorea_halfn_r");
243   add(OpenCLLIB::Shuffle, "shuffle");
244   add(OpenCLLIB::Shuffle2, "shuffle2");
245   add(OpenCLLIB::Printf, "printf");
246   add(OpenCLLIB::Prefetch, "prefetch");
247   add(OpenCLLIB::Bitselect, "bitselect");
248   add(OpenCLLIB::Select, "select");
249   add(OpenCLLIB::UAbs, "u_abs");
250   add(OpenCLLIB::UAbs_diff, "u_abs_diff");
251   add(OpenCLLIB::UMul_hi, "u_mul_hi");
252   add(OpenCLLIB::UMad_hi, "u_mad_hi");
253 }
SPIRV_DEF_NAMEMAP(OCLExtOpKind,OCLExtOpMap)254 SPIRV_DEF_NAMEMAP(OCLExtOpKind, OCLExtOpMap)
255 
256 inline bool
257 isReadImage(SPIRVWord EntryPoint) {
258   return EntryPoint >= OpenCLLIB::Read_imagef &&
259       EntryPoint <= OpenCLLIB::Read_imageui;
260 }
261 
262 inline bool
isWriteImage(SPIRVWord EntryPoint)263 isWriteImage(SPIRVWord EntryPoint) {
264   return EntryPoint >= OpenCLLIB::Write_imagef &&
265       EntryPoint <= OpenCLLIB::Write_imageui;
266 }
267 
268 inline bool
isReadOrWriteImage(SPIRVWord EntryPoint)269 isReadOrWriteImage(SPIRVWord EntryPoint) {
270   return isReadImage(EntryPoint) || isWriteImage(EntryPoint);
271 }
272 
273 }
274 
275 #endif
276