CMS 3D CMS Logo

Functions
approx_exp.h File Reference
#include "DataFormats/Math/interface/approx_math.h"

Go to the source code of this file.

Functions

template<int DEGREE>
constexpr float approx_expf (float x)
 
template<int DEGREE>
constexpr float approx_expf_P (float p)
 
template<>
constexpr float approx_expf_P< 2 > (float y)
 
template<>
constexpr float approx_expf_P< 3 > (float y)
 
template<>
constexpr float approx_expf_P< 4 > (float y)
 
template<>
constexpr float approx_expf_P< 5 > (float y)
 
template<>
constexpr float approx_expf_P< 6 > (float y)
 
template<>
constexpr float approx_expf_P< 7 > (float y)
 
template<int DEGREE>
constexpr float unsafe_expf (float x)
 
template<int DEGREE>
constexpr float unsafe_expf_impl (float x)
 

Function Documentation

template<int DEGREE>
constexpr float approx_expf ( float  x)

Definition at line 168 of file approx_exp.h.

References constexpr, JetChargeProducer_cfi::exp, objects.autophobj::float, SiStripPI::max, min(), alignCSCRings::r, and unsafe_expf().

168  {
169 
170  constexpr float inf_threshold =float(0x5.8b90cp4);
171  // log of the smallest normal
172  constexpr float zero_threshold_ftz =-float(0x5.75628p4); // sollya: single(log(1b-126));
173  // flush to zero on the output
174  // manage infty output:
175  // faster than directly on output!
176  x = std::min(std::max(x,zero_threshold_ftz),inf_threshold);
177  float r = unsafe_expf<DEGREE>(x);
178 
179  return r;
180 }
#define constexpr
T min(T a, T b)
Definition: MathUtil.h:58
template<int DEGREE>
constexpr float approx_expf_P ( float  p)
template<>
constexpr float approx_expf_P< 2 > ( float  y)

Definition at line 43 of file approx_exp.h.

References objects.autophobj::float, globals_cff::x1, globals_cff::x2, and detailsBasic3DVector::y.

43  {
44  return float(0x2.p0) + y * (float(0x2.07b99p0) + y * float(0x1.025b84p0)) ;
45 }
template<>
constexpr float approx_expf_P< 3 > ( float  y)

Definition at line 48 of file approx_exp.h.

References objects.autophobj::float, globals_cff::x1, globals_cff::x2, and detailsBasic3DVector::y.

48  {
49 #ifdef HORNER // HORNER
50  return float(0x2.p0) + y * (float(0x1.fff798p0) + y * (float(0x1.02249p0) + y * float(0x5.62042p-4))) ;
51 #else // ESTRIN
52  float p23 = (float(0x1.02249p0) + y * float(0x5.62042p-4)) ;
53  float p01 = float(0x2.p0) + y * float(0x1.fff798p0);
54  return p01 + y*y*p23;
55 #endif
56 }
template<>
constexpr float approx_expf_P< 4 > ( float  y)

Definition at line 59 of file approx_exp.h.

References objects.autophobj::float, globals_cff::x1, globals_cff::x2, and detailsBasic3DVector::y.

59  {
60  return float(0x2.p0) + y * (float(0x1.fffb1p0) + y * (float(0xf.ffe84p-4) + y * (float(0x5.5f9c1p-4) + y * float(0x1.57755p-4)))) ;
61 }
template<>
constexpr float approx_expf_P< 5 > ( float  y)

Definition at line 64 of file approx_exp.h.

References objects.autophobj::float, globals_cff::x1, globals_cff::x2, and detailsBasic3DVector::y.

64  {
65  return float(0x2.p0) + y * (float(0x2.p0) + y * (float(0xf.ffed8p-4) + y * (float(0x5.5551cp-4) + y * (float(0x1.5740d8p-4) + y * float(0x4.49368p-8))))) ;
66 }
template<>
constexpr float approx_expf_P< 6 > ( float  y)

Definition at line 69 of file approx_exp.h.

References objects.autophobj::float, AlCaHLTBitMon_ParallelJobs::p, globals_cff::x1, globals_cff::x2, and detailsBasic3DVector::y.

69  {
70 #ifdef HORNER // HORNER
71  float p = float(0x2.p0) + y * (float(0x2.p0) + y * (float(0x1.p0) + y * (float(0x5.55523p-4) + y * (float(0x1.5554dcp-4) + y * (float(0x4.48f41p-8) + y * float(0xb.6ad4p-12)))))) ;
72 #else // ESTRIN does seem to save a cycle or two
73  float p56 = float(0x4.48f41p-8) + y * float(0xb.6ad4p-12);
74  float p34 = float(0x5.55523p-4) + y * float(0x1.5554dcp-4);
75  float y2 = y*y;
76  float p12 = float(0x2.p0) + y; // By chance we save one operation here! Funny.
77  float p36 = p34 + y2*p56;
78  float p16 = p12 + y2*p36;
79  float p = float(0x2.p0) + y*p16;
80 #endif
81  return p;
82 }
template<>
constexpr float approx_expf_P< 7 > ( float  y)

Definition at line 86 of file approx_exp.h.

References objects.autophobj::float, globals_cff::x1, globals_cff::x2, and detailsBasic3DVector::y.

86  {
87  return float(0x2.p0) + y * (float(0x2.p0) + y * (float(0x1.p0) + y * (float(0x5.55555p-4) + y * (float(0x1.5554e4p-4) + y * (float(0x4.444adp-8) + y * (float(0xb.6a8a6p-12) + y * float(0x1.9ec814p-12))))))) ;
88 }
template<int DEGREE>
constexpr float unsafe_expf ( float  x)

Definition at line 163 of file approx_exp.h.

Referenced by approx_expf().

163  {
164  return unsafe_expf_impl<DEGREE>(x);
165 }
template<int DEGREE>
constexpr float unsafe_expf_impl ( float  x)

Definition at line 114 of file approx_exp.h.

References constexpr, MillePedeFileConverter_cfg::e, f, objects.autophobj::float, approx_math::fpfloor(), AlCaHLTBitMon_ParallelJobs::p, approx_math::binary32::ui32, and globals_cff::x1.

114  {
115  using namespace approx_math;
116  /* Sollya for the following constants:
117  display=hexadecimal;
118  1b23+1b22;
119  single(1/log(2));
120  log2H=round(log(2), 16, RN);
121  log2L = single(log(2)-log2H);
122  log2H; log2L;
123 
124  */
125  // constexpr float rnd_cst = float(0xc.p20);
126  constexpr float inv_log2f = float(0x1.715476p0);
127  constexpr float log2H = float(0xb.172p-4);
128  constexpr float log2L = float(0x1.7f7d1cp-20);
129 
130 
131  float y = x;
132  // This is doing round(x*inv_log2f) to the nearest integer
133  float z = fpfloor((x*inv_log2f) +0.5f);
134  // Cody-and-Waite accurate range reduction. FMA-safe.
135  y -= z*log2H;
136  y -= z*log2L;
137  // exponent
138  int32_t e = z;
139 
140 
141  // we want RN above because it centers the interval around zero
142  // but then we could have 2^e = below being infinity when it shouldn't
143  // (when e=128 but p<1)
144  // so we avoid this case by reducing e and evaluating a polynomial for 2*exp
145  e -=1;
146 
147  // NaN inputs will propagate to the output as expected
148 
149  float p = approx_expf_P<DEGREE>(y);
150 
151  // cout << "x=" << x << " e=" << e << " y=" << y << " p=" << p <<"\n";
152  binary32 ef;
153  uint32_t biased_exponent= e+127;
154  ef.ui32=(biased_exponent<<23);
155 
156  return p * ef.f;
157 }
constexpr float fpfloor(float x)
Definition: approx_math.h:28
#define constexpr
float float float z
double f[11][100]