1 /******************************************************************************
2   Copyright (c) 2007-2011, Intel Corp.
3   All rights reserved.
4 
5   Redistribution and use in source and binary forms, with or without
6   modification, are permitted provided that the following conditions are met:
7 
8     * Redistributions of source code must retain the above copyright notice,
9       this list of conditions and the following disclaimer.
10     * Redistributions in binary form must reproduce the above copyright
11       notice, this list of conditions and the following disclaimer in the
12       documentation and/or other materials provided with the distribution.
13     * Neither the name of Intel Corporation nor the names of its contributors
14       may be used to endorse or promote products derived from this software
15       without specific prior written permission.
16 
17   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27   THE POSSIBILITY OF SUCH DAMAGE.
28 ******************************************************************************/
29 
30 #ifndef COMPILER_H
31 #define COMPILER_H
32 
33 #undef	INLINE
34 #define	INLINE_DIRECTIVE
35 
36 
37 #if ((defined(epc_cc) || defined(EPC_CC)) || defined(ecc) || defined(__ECC) || \
38       defined(__ICC) || defined(icc) )
39 #   define __ecc__
40 #endif
41 
42 
43 
44 
45 #if (defined(dec_cc) || defined(DEC_CC) || defined(__DECC))
46 
47 #   define __xxx_dec_cc
48 
49 #elif (defined(mips_cc) || defined(MIPS_CC) || defined(_CFE) \
50 	|| (defined(host_mips) && !defined(__GNUC__)) )
51 
52 #   define __xxx_mips_cc
53 
54 #elif (defined(vax_cc) || defined(VAX_CC) \
55 	|| defined(vaxc) || defined(VAXC) || defined(__VAXC))
56 
57 #   define __xxx_vax_cc
58 
59 #elif (defined(msc_cc) || defined(MSC_CC) || defined(_MSC_VER)) && !defined(__ICL)
60 
61 #   define __xxx_msc_cc
62 
63 #elif (defined(hp_cc) || defined(HP_CC))
64 
65 #   define __xxx_hp_cc
66 
67 #elif ((defined(gnu_cc) || defined(GNU_CC) || defined(__GNUC__)) \
68          && !defined(__ecc__))
69 
70 #   define __xxx_gnu_cc
71 
72 #elif defined(__ecc__)
73 
74 #   define __xxx_intel_icc
75 
76 #elif ( defined(__ICL) || defined(icl) )
77 
78 #   define __xxx_intel_icl
79 
80 #else
81 
82 #   define __xxx_just_cc
83 
84 #endif
85 
86 #undef  dec_cc
87 #undef  gnu_cc
88 #undef  mips_cc
89 #undef  vax_cc
90 #undef  msc_cc
91 #undef  hp_cc
92 #undef  intel_icc
93 #undef  intel_icl
94 #undef  just_cc
95 
96 #if defined __xxx_dec_cc
97 
98 #   undef  __xxx_dec_cc 1
99 #   define dec_cc 1
100 #   define COMPILER dec_cc
101 
102 #   define INLINE
103 #   undef  INLINE_DIRECTIVE
104 #   define INLINE_DIRECTIVE	static
105 
106 #elif defined __xxx_mips_cc
107 
108 #   undef  __xxx_mips_cc
109 #   define mips_cc 2
110 #   define COMPILER mips_cc
111 
112 #elif defined __xxx_vax_cc
113 
114 #   undef  __xxx_vax_cc
115 #   define vax_cc 3
116 #   define COMPILER vax_cc
117 
118 #elif defined __xxx_msc_cc
119 
120 #   undef  __xxx_msc_cc
121 #   define msc_cc 4
122 #   define COMPILER msc_cc
123 
124 #elif defined __xxx_hp_cc
125 
126 #   undef  __xxx_hp_cc
127 #   define hp_cc 5
128 #   define COMPILER hp_cc
129 
130 #elif defined __xxx_gnu_cc
131 
132 #   define gnu_cc 6
133 #   define COMPILER gnu_cc
134 
135 #   define INLINE
136 #   undef  INLINE_DIRECTIVE
137 #   define INLINE_DIRECTIVE	static __inline__
138 
139 #elif defined __xxx_intel_icc
140 
141 #   undef  __xxx_intel_icc
142 #   define intel_icc 7
143 #   define COMPILER intel_icc
144 
145 #elif defined __xxx_intel_icl
146 
147 #   undef  __xxx_intel_icl
148 #   define intel_icl 8
149 #   define COMPILER intel_icl
150 
151 #else
152 
153 #   undef  __xxx_just_cc
154 #   define just_cc 9
155 #   define COMPILER just_cc
156 
157 #endif
158 
159 
160 #define NULL_MACRO(a) a
161 
162 
163 #define tmp_TRY 0
164 #define tmp_THIS + 0
165 #define tmp_TRYtmp_THIS 1
166 
167 
168 #ifndef GLUE
169 #	define GLUE(a,b) a/**/b
170 #	if (GLUE(tmp_TRY,tmp_THIS) != tmp_TRYtmp_THIS)
171 #		undef GLUE
172 #	endif
173 #endif
174 
175 #ifndef GLUE
176 #	define GLUE(a,b) a ## b
177 #	if (GLUE(tmp_TRY,tmp_THIS) != tmp_TRYtmp_THIS)
178 #		undef GLUE
179 #	endif
180 #endif
181 
182 #ifndef GLUE
183 #	define GLUE(a,b) NULL_MACRO(a)b
184 #	if (GLUE(tmp_TRY,tmp_THIS) != tmp_TRYtmp_THIS)
185 #		undef GLUE
186 #	endif
187 #endif
188 
189 #ifndef GLUE
190 #	error GLUE macro not defined
191 #endif
192 
193 #undef tmp_TRY
194 #undef tmp_THIS
195 #undef tmp_TRYtmp_THIS
196 
197 #define PASTE(a,b) GLUE(a,b)
198 #define PASTE_2(a,b) PASTE(a,b)
199 #define PASTE_3(a,b,c) PASTE(PASTE(a,b),c)
200 #define PASTE_4(a,b,c,d) PASTE(PASTE(PASTE(a,b),c),d)
201 #define PASTE_5(a,b,c,d,e) PASTE(PASTE(PASTE(PASTE(a,b),c),d),e)
202 #define PASTE_6(a,b,c,d,e,f) PASTE(PASTE(PASTE(PASTE(PASTE(a,b),c),d),e),f)
203 #define PASTE_7(a,b,c,d,e,f,g) PASTE(PASTE(PASTE(PASTE(PASTE(PASTE(a,b),c),d),e),f),g)
204 
205 
206 #define QUOTE_IT(s) #s
207 
208 /* Defining QUOTE_IT(s) to be "s" might work with some compilers. */
209 
210 #define STR(s) QUOTE_IT(s)
211 
212 
213 // =============================================================================
214 // At higher optimization levels, some compilers will ignore parenthesis and
215 // re-arrange floating point calculation. Doing so will break some of the
216 // algorithms in the DPML (eg. divide). The intel compiler in particular has
217 // this problem. However, the Intel compiler has an opperator to avoid
218 // reassociations.
219 // =============================================================================
220 
221 #if  COMPILER == intel_icc || COMPILER == intel_icl
222 #   define GROUP(x)     __fence(x)
223 #endif
224 
225 
226 #if (COMPILER == dec_cc)
227 
228 /* Declare decc linkages for various platforms */
229 
230 
231 
232 #	if ((OP_SYSTEM == osf) || (OP_SYSTEM == linux))
233 
234 #		if ((OP_SYSTEM == linux) || ( __DECC_VER >= 60000000 ))
235 #			pragma message disable (nofntpdefdecl)
236 #		endif
237 
238 
239 #		if 0
240 		/*
241 		 * For reference, the Alpha AXP Calling Standard has:
242 		 */
243 #		pragma linkage standard_linkage = (
244 			parameters(	r16, r17, r18, r19, r20, r21,
245 					f16, f17, f18, f19, f20, f21 ),
246 			result(		r0, f0, f1 ),
247 			/**/
248 			nopreserve (	r0, r1, r2, r3, r4, r5, r6, r7, r8 ),
249 			  preserved(	r9, r10, r11, r12, r13, r14 ),
250 			  preserved(	r15 ),				/* Frame Pointer */
251 			nopreserve (	r16, r17, r18, r19, r20, r21 ),	/* Parameters */
252 			nopreserve (	r22, r23, r24, r25 ),
253 			  preserved(	r26 ),				/* Return Address */
254 			nopreserve (	r27 ),				/* Bound Procedure Value */
255 			nopreserve (	r28 ),				/* Volatile Scratch */
256 			nopreserve (	r29 ), 				/* Global Pointer */
257 			  preserved(	r30 ),				/* Stack Pointer */
258 			/*preserved(	r31 ),*/			/* Read as Zero */
259 			nopreserve (	f0, f1 ),
260 			  preserved(	f2, f3, f4, f5, f6, f7, f8, f9 ),
261 			nopreserve (	f10, f11, f12, f13, f14, f15 ),
262 			nopreserve (	f16, f17, f18, f19, f20, f21 ),	/* Parameters */
263 			nopreserve (	f22, f23, f24, f25, f26, f27 ),
264 			nopreserve (	f28, f29, f30 ),
265 			/*preserved(	f31 ),*/			/* Read as Zero */
266                         notneeded(ai) )
267 #		endif
268 
269 
270 #		pragma linkage complex_linkage = ( result (f0, f1) )
271 
272 #		pragma use_linkage complex_linkage ( \
273 			F_sincosd, F_sincosdf, \
274 			F_sincos, F_sincosf, ccos, ccosf, cdiv, cdivf, cexp, cexpf, clog, clogf, \
275 			cmul, cmulf, cpow, cpowf, cpowi, cpowif, csin, csinf, csqrt, csqrtf, \
276 			r_ccos, r_ccosf, r_cexp, r_cexpf, r_clog, r_clogf, r_cmplx, r_cmplxf, \
277 			r_conjg, r_conjgf, r_csin, r_csinf, r_csqrt, r_csqrtf, sincos, sincos_vo, \
278 			sincosd, sincosdf, sincosf, sincosf_vo, sinhcosh, sinhcoshf, \
279 			csinh, ctan, ctanh, ccosh, catanh, catan, casin, casinh, cacos, \
280 			cacosh, conj, cproj, ccoshf, catanf, csinhf,\
281 			ctanf, ctanhf,catanhf, casinf, casinhf, cacosf, cacoshf, conjf, cprojf \
282 		)
283 
284 
285 #		pragma linkage res_vec_4_linkage = ( result (f20, f21, f22, f23) )
286 
287 #		pragma use_linkage res_vec_4_linkage ( \
288 			__F_sqrt4, __F_sqrt4f, \
289 			__rsqrt4,  __rsqrt4f, \
290 			__sqrt4,   __sqrt4f \
291 		)
292 
293 
294                 /*
295                 **  The trig reduce functions can have a bad effect on routines
296                 **  that call them, because the DECC compiler saves registers
297                 **  for _any_ path through the routine, rather than deferring
298                 **  until it's known whether a call to a trig reduce function
299                 **  is actually needed.
300                 **
301                 **  To avoid this problem (which is likely to be inherent in most
302 		**  compilers), we specify a linkage for the trig reduce functions
303 		**  that allows their callers (nearly) maximal freedom in register use.
304 		**  I.e., specify that they preserve (nearly) all registers.
305                 */
306 #               pragma linkage trig_reduce_linkage = ( \
307                         parameters (f0, r0, r1, r2), \
308                         result (r0), \
309 		       	  preserved(	r16, r17, r18, r19, r20, r21 ),	/* Parameters */	\
310 		       	  preserved(	f16, f17, f18, f19, f20, f21 ),	/* Parameters */	\
311 		       	  preserved(	f22, f23, f24, f25, f26, f27 ),				\
312 		       	  preserved(	f28, f29, f30 ),					\
313                         notneeded(ai)								\
314                 )
315 #               pragma linkage trigd_reduce_linkage = ( \
316                         parameters (f0, r0, r1), \
317                         result (r0), \
318 		       	  preserved(	r16, r17, r18, r19, r20, r21 ),	/* Parameters */	\
319 		       	  preserved(	f16, f17, f18, f19, f20, f21 ),	/* Parameters */	\
320 		       	  preserved(	f22, f23, f24, f25, f26, f27 ),				\
321 		       	  preserved(	f28, f29, f30 ),					\
322                         notneeded(ai)								\
323                 )
324 #               pragma linkage trig_reduce_linkage_l = ( \
325                         parameters (r3, r0, r1, r2), \
326                         result (r0), \
327 		       	  preserved(	r16, r17, r18, r19, r20, r21 ),	/* Parameters */	\
328 		       	  preserved(	f16, f17, f18, f19, f20, f21 ),	/* Parameters */	\
329 		       	  preserved(	f22, f23, f24, f25, f26, f27 ),				\
330 		       	  preserved(	f28, f29, f30 ),					\
331                         notneeded(ai)								\
332                 )
333 
334 #               pragma use_linkage trig_reduce_linkage ( \
335                         __trig_reduce, \
336                         __trig_reducef \
337 		)
338 
339 #               pragma use_linkage trigd_reduce_linkage ( \
340                         __trigd_reduce, \
341                         __trigd_reducef \
342 		)
343 
344 		/* some recent decc compilers can not do this */
345 /* #               pragma use_linkage trig_reduce_linkage_l ( __trig_reducel, __trigd_reducel ) */
346 
347 #	endif  /* OSF */
348 
349 
350 	/*
351 	** NOTE: the "&&" clause is to turn off the pragma definitions for iVMS when
352 	** compiling f, g or d floating types because the compiler issues an error
353 	*/
354 
355 #	if (OP_SYSTEM == vms)
356 
357 #		if ( __DECC_VER >= 60260000 )
358 #			pragma message disable (nofntpdefdecl)
359 #		endif
360 #		if ( __ia64__ )
361 #			pragma message disable (showmaplinkage,mapregignored)
362 #		endif
363 
364 #               if __ia64__ && !__IEEE_FLOAT
365 #		    pragma linkage complex_linkage = ( result (r0, r1) )
366 #               else
367 #		    pragma linkage complex_linkage = ( result (f0, f1) )
368 #               endif
369 
370 #		pragma use_linkage complex_linkage   ( \
371                         math$cacos_f, math$cacos_g, math$cacos_s, math$cacos_t, \
372                         math$cacosh_f, math$cacosh_g, math$cacosh_s, math$cacosh_t, \
373                         math$casin_f, math$casin_g, math$casin_s, math$casin_t, \
374                         math$casinh_f, math$casinh_g, math$casinh_s, math$casinh_t, \
375                         math$catan_f, math$catan_g, math$catan_s, math$catan_t, \
376                         math$catanh_f, math$catanh_g, math$catanh_s, math$catanh_t, \
377                         math$ccosh_f, math$ccosh_g, math$ccosh_s, math$ccosh_t, \
378                         math$ctanh_f, math$ctanh_g, math$ctanh_s, math$ctanh_t, \
379                         math$csinh_f, math$csinh_g, math$csinh_s, math$csinh_t, \
380                         math$ctan_f, math$ctan_g, math$ctan_s, math$ctan_t, \
381                         math$conj_f, math$conj_g, math$conj_s, math$conj_t, \
382                         math$cproj_f, math$cproj_g, math$cproj_s, math$cproj_t, \
383 			math$F_sincosd_f, math$F_sincosd_g, math$F_sincosd_s, math$F_sincosd_t, \
384 			math$F_sincos_f, math$F_sincos_g, math$F_sincos_s, math$F_sincos_t, \
385 			math$ccos_f, math$ccos_g, math$ccos_s, math$ccos_t, math$cdiv_f, \
386 			math$cdiv_g, math$cdiv_s, math$cdiv_t, math$cexp_f, math$cexp_g, \
387 			math$cexp_s, math$cexp_t, math$clog_f, math$clog_g, math$clog_s, \
388 			math$clog_t, math$cmul_f, math$cmul_g, math$cmul_s, math$cmul_t, \
389 			math$cpow_f, math$cpow_g, math$cpow_s, math$cpow_t, math$cpow_fq, \
390 			math$cpow_gq, math$cpow_sq, math$cpow_tq, math$cpowi_f, math$cpowi_g, \
391 			math$cpowi_s, math$cpowi_t, math$csin_f, math$csin_g, math$csin_s, \
392 			math$csin_t, math$csqrt_f, math$csqrt_g, math$csqrt_s, math$csqrt_t, \
393 			math$sincos_f, math$sincos_g, math$sincos_s, math$sincos_t, \
394 			math$sincos_vo_f, math$sincos_vo_g, math$sincos_vo_s, math$sincos_vo_t, \
395 			math$sincosd_f, math$sincosd_g, math$sincosd_s, math$sincosd_t, \
396 			math$sinhcosh_f, math$sinhcosh_g, math$sinhcosh_s, math$sinhcosh_t, \
397 			mth$ccos, mth$cdcos, mth$cdexp, mth$cdlog, mth$cdsin, mth$cdsqrt, mth$cexp, \
398 			mth$cgcos, mth$cgexp, mth$cglog, mth$cgsin, mth$cgsqrt, mth$clog, \
399 			mth$cmplx, mth$conjg, mth$cscos, mth$csexp, mth$csin, mth$cslog, mth$csqrt, \
400 			mth$cssin, mth$cssqrt, mth$ctcos, mth$ctexp, mth$ctlog, mth$ctsin, \
401 			mth$ctsqrt, mth$dcmplx, mth$dconjg, mth$gcmplx, mth$gconjg, mth$scmplx, \
402 			mth$sconjg, mth$tcmplx, mth$tconjg, ots$divc, ots$divcd_r3, ots$divcg_r3, \
403 			ots$mulc, ots$mulcd_r3, ots$mulcg_r3, ots$powcc, ots$powcc_r3, \
404 			ots$powcdcd_r3, ots$powcdj, ots$powcgcg_r3, ots$powcgj, ots$powcj \
405 		)
406 
407 
408 #		define PRESERVED_REGISTERS preserved( \
409 			r1, \
410 			r16, r17, r18, r19, r20, r21, r22, r23, r24, r25, \
411 			f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, \
412 			f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, \
413 			f30 \
414 		)
415 
416 #               if !__ia64__ || __IEEE_FLOAT
417 
418 #			pragma linkage trig_reduce_linkage = ( \
419 				parameters (f0, r0, r1, r16), \
420 				result (r0), \
421 				PRESERVED_REGISTERS, \
422 				notneeded(ai) \
423 			)
424 
425 #			pragma use_linkage trig_reduce_linkage ( \
426 				math$trig_reduce_f, \
427 				math$trig_reduce_g, \
428 				math$trig_reduce_s, \
429 				math$trig_reduce_t  \
430 			)
431 
432 #			pragma linkage trigd_reduce_linkage = ( \
433 				parameters (f0, r0, r1), \
434 				result (r0), \
435 				PRESERVED_REGISTERS, \
436 				notneeded(ai) \
437 			)
438 
439 #			pragma use_linkage trigd_reduce_linkage ( \
440 				math$trigd_reduce_f, \
441 				math$trigd_reduce_g, \
442 				math$trigd_reduce_s, \
443 				math$trigd_reduce_t  \
444 			)
445 #	               endif
446 
447 #	endif  /* VMS */
448 
449 #endif  /* (COMPILER == dec_cc) */
450 
451 #endif  /* COMPILER_H */
452