source: sasmodels/sasmodels/kernel_header.c @ c0c3393

core_shell_microgelscostrafo411magnetic_modelrelease_v0.94release_v0.95ticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since c0c3393 was 03cac08, checked in by Paul Kienzle <pkienzle@…>, 8 years ago

new generator produces code that compiles

  • Property mode set to 100644
File size: 3.7 KB
Line 
1#ifdef __OPENCL_VERSION__
2# define USE_OPENCL
3#elif defined(_OPENMP)
4# define USE_OPENMP
5#endif
6
7// If opencl is not available, then we are compiling a C function
8// Note: if using a C++ compiler, then define kernel as extern "C"
9#ifndef USE_OPENCL
10#  ifdef __cplusplus
11      #include <cstdio>
12      #include <cmath>
13      using namespace std;
14      #if defined(_MSC_VER)
15         #include <limits>
16         #include <float.h>
17         #define kernel extern "C" __declspec( dllexport )
18         static double trunc(double x) { return x>=0?floor(x):-floor(-x); }
19         static double fmin(double x, double y) { return x>y ? y : x; }
20         static double fmax(double x, double y) { return x<y ? y : x; }
21         static double isnan(double x) { return _isnan(x); }
22         #define NAN (std::numeric_limits<double>::quiet_NaN()) // non-signalling NaN
23         static double cephes_expm1(double x) {
24            // Adapted from the cephes math library.
25            // Copyright 1984 - 1992 by Stephen L. Moshier
26            if (x != x || x == 0.0) {
27               return x; // NaN and +/- 0
28            } else if (x < -0.5 || x > 0.5) {
29               return exp(x) - 1.0;
30            } else {
31               const double xsq = x*x;
32               const double p = (((
33                  +1.2617719307481059087798E-4)*xsq
34                  +3.0299440770744196129956E-2)*xsq
35                  +9.9999999999999999991025E-1);
36               const double q = ((((
37                  +3.0019850513866445504159E-6)*xsq
38                  +2.5244834034968410419224E-3)*xsq
39                  +2.2726554820815502876593E-1)*xsq
40                  +2.0000000000000000000897E0);
41               double r = x * p;
42               r =  r / (q - r);
43               return r+r;
44             }
45         }
46         #define expm1 cephes_expm1
47     #else
48         #define kernel extern "C"
49     #endif
50     static void SINCOS(double angle, double &svar, double &cvar) { svar=sin(angle); cvar=cos(angle); }
51#  else
52     #include <stdio.h>
53     #include <tgmath.h> // C99 type-generic math, so sin(float) => sinf
54     // MSVC doesn't support C99, so no need for dllexport on C99 branch
55     #define kernel
56     #define SINCOS(angle,svar,cvar) do {const double _t_=angle; svar=sin(_t_);cvar=cos(_t_);} while (0)
57#  endif
58#  define global
59#  define local
60#  define constant const
61// OpenCL powr(a,b) = C99 pow(a,b), b >= 0
62// OpenCL pown(a,b) = C99 pow(a,b), b integer
63#  define powr(a,b) pow(a,b)
64#  define pown(a,b) pow(a,b)
65#else
66#  if defined(USE_SINCOS)
67#    define SINCOS(angle,svar,cvar) svar=sincos(angle,&cvar)
68#  else
69#    define SINCOS(angle,svar,cvar) do {const double _t_=angle; svar=sin(_t_);cvar=cos(_t_);} while (0)
70#  endif
71#endif
72
73// Standard mathematical constants:
74//   M_E, M_LOG2E, M_LOG10E, M_LN2, M_LN10, M_PI, M_PI_2=pi/2, M_PI_4=pi/4,
75//   M_1_PI=1/pi, M_2_PI=2/pi, M_2_SQRTPI=2/sqrt(pi), SQRT2, SQRT1_2=sqrt(1/2)
76// OpenCL defines M_constant_F for float constants, and nothing if double
77// is not enabled on the card, which is why these constants may be missing
78#ifndef M_PI
79#  define M_PI 3.141592653589793
80#endif
81#ifndef M_PI_2
82#  define M_PI_2 1.570796326794897
83#endif
84#ifndef M_PI_4
85#  define M_PI_4 0.7853981633974483
86#endif
87#ifndef M_E
88#  define M_E 2.718281828459045091
89#endif
90
91// Non-standard function library
92// pi/180, used for converting between degrees and radians
93// 4/3 pi for computing sphere volumes
94// square and cube for computing squares and cubes
95#ifndef M_PI_180
96#  define M_PI_180 0.017453292519943295
97#endif
98#ifndef M_4PI_3
99#  define M_4PI_3 4.18879020478639
100#endif
101static double square(double x) { return x*x; }
102static double cube(double x) { return x*x*x; }
103static double sinc(double x) { return x==0 ? 1.0 : sin(x)/x; }
104
Note: See TracBrowser for help on using the repository browser.