Changeset b966a96 in sasmodels for sasmodels/kernel_header.c


Ignore:
Timestamp:
Jul 21, 2016 5:12:18 PM (8 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
6a0d6aa
Parents:
32e3c9b
Message:

better line numbers for compiler errors; tinycc support (mostly)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/kernel_header.c

    rba32cdd rb966a96  
    88// Note: if using a C++ compiler, then define kernel as extern "C" 
    99#ifndef USE_OPENCL 
     10// Use SAS_DOUBLE to force the use of double even for float kernels 
     11#  define SAS_DOUBLE dou ## ble 
    1012#  ifdef __cplusplus 
    1113      #include <cstdio> 
     
    1618         #include <float.h> 
    1719         #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); } 
     20         inline double trunc(double x) { return x>=0?floor(x):-floor(-x); } 
     21         inline double fmin(double x, double y) { return x>y ? y : x; } 
     22         inline double fmax(double x, double y) { return x<y ? y : x; } 
     23         #define isnan(x) _isnan(x) 
     24         #define isinf(x) (!_finite(x)) 
     25         #define isfinite(x) _finite(x) 
    2226         #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          typedef __int32 int32_t 
     27         #define INFINITY (std::numeric_limits<double>::infinity()) 
     28         #define NEED_EXPM1 
     29         #define NEED_TGAMMA 
    4830     #else 
    4931         #define kernel extern "C" 
    5032         #include <cstdint> 
    5133     #endif 
    52      static void SINCOS(double angle, double &svar, double &cvar) { svar=sin(angle); cvar=cos(angle); } 
     34     inline void SINCOS(double angle, double &svar, double &cvar) { svar=sin(angle); cvar=cos(angle); } 
    5335#  else 
    5436     #include <inttypes.h>  // C99 guarantees that int32_t types is here 
    5537     #include <stdio.h> 
    56      #include <tgmath.h> // C99 type-generic math, so sin(float) => sinf 
     38     #if defined(__TINYC__) 
     39         typedef int int32_t; 
     40         #include <math.h> 
     41         // TODO: test isnan 
     42         inline double _isnan(double x) { return x != x; } // hope this doesn't optimize away! 
     43         #undef isnan 
     44         #define isnan(x) _isnan(x) 
     45         // Defeat the double->float conversion since we don't have tgmath 
     46         inline SAS_DOUBLE trunc(SAS_DOUBLE x) { return x>=0?floor(x):-floor(-x); } 
     47         inline SAS_DOUBLE fmin(SAS_DOUBLE x, SAS_DOUBLE y) { return x>y ? y : x; } 
     48         inline SAS_DOUBLE fmax(SAS_DOUBLE x, SAS_DOUBLE y) { return x<y ? y : x; } 
     49         #define NEED_EXPM1 
     50         #define NEED_TGAMMA 
     51     #else 
     52         #include <tgmath.h> // C99 type-generic math, so sin(float) => sinf 
     53     #endif 
    5754     // MSVC doesn't support C99, so no need for dllexport on C99 branch 
    5855     #define kernel 
     
    7370#    define SINCOS(angle,svar,cvar) do {const double _t_=angle; svar=sin(_t_);cvar=cos(_t_);} while (0) 
    7471#  endif 
     72#endif 
     73 
     74#if defined(NEED_EXPM1) 
     75   static SAS_DOUBLE expm1(SAS_DOUBLE x_in) { 
     76      double x = (double)x_in;  // go back to float for single precision kernels 
     77      // Adapted from the cephes math library. 
     78      // Copyright 1984 - 1992 by Stephen L. Moshier 
     79      if (x != x || x == 0.0) { 
     80         return x; // NaN and +/- 0 
     81      } else if (x < -0.5 || x > 0.5) { 
     82         return exp(x) - 1.0; 
     83      } else { 
     84         const double xsq = x*x; 
     85         const double p = ((( 
     86            +1.2617719307481059087798E-4)*xsq 
     87            +3.0299440770744196129956E-2)*xsq 
     88            +9.9999999999999999991025E-1); 
     89         const double q = (((( 
     90            +3.0019850513866445504159E-6)*xsq 
     91            +2.5244834034968410419224E-3)*xsq 
     92            +2.2726554820815502876593E-1)*xsq 
     93            +2.0000000000000000000897E0); 
     94         double r = x * p; 
     95         r =  r / (q - r); 
     96         return r+r; 
     97       } 
     98   } 
    7599#endif 
    76100 
     
    103127#  define M_4PI_3 4.18879020478639 
    104128#endif 
    105 static double square(double x) { return x*x; } 
    106 static double cube(double x) { return x*x*x; } 
    107 static double sinc(double x) { return x==0 ? 1.0 : sin(x)/x; } 
     129inline double square(double x) { return x*x; } 
     130inline double cube(double x) { return x*x*x; } 
     131inline double sinc(double x) { return x==0 ? 1.0 : sin(x)/x; } 
    108132 
Note: See TracChangeset for help on using the changeset viewer.