IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit
UniformRandomLCGReg.h
Go to the documentation of this file.
1 // UniformRandomLCGReg.h:
3 // -------------------
4 //
14 
15 #ifndef __IPSDKUTIL_INSTRUCTIONSET_ARITHMETIC_DETAIL_STD_UNIFORMRANDOMLCGREG_H__
16 #define __IPSDKUTIL_INSTRUCTIONSET_ARITHMETIC_DETAIL_STD_UNIFORMRANDOMLCGREG_H__
17 
21 #include <IPSDKUtil/InstructionSet/Arithmetic/detail/SignedUnsignedOpReg.h>
24 
25 #include <math.h>
26 
27 namespace ipsdk {
28 namespace simd {
29 namespace detail {
30 
33 
36 template <typename T>
38  typename boost::enable_if_c<sizeof(T)==1>::type>
39 {
40  typedef ipReal64 FloatType;
41 
42  static
43  IPSDK_FORCEINLINE
45  initSeed(ipUInt32 seed)
46  {
47  return seed;
48  }
49 
50  static
51  IPSDK_FORCEINLINE
53  computeRangeMultiplier(T tMin, T tMax)
54  {
55  return (static_cast<FloatType>(tMax) - static_cast<FloatType>(tMin)+1.0) /
56  32768.0;
57  }
58 
59  static
60  IPSDK_FORCEINLINE
62  computeRangeOffset(T tMin, T tMax)
63  {
64  return static_cast<FloatType>(tMin);
65  }
66 
67  static
68  IPSDK_FORCEINLINE
69  T
73  {
74  rSeed = 214013*rSeed+2531011;
75  const ipUInt16 nSeed = 0x7FFF & (rSeed >> 16);
76  const FloatType fSeed = static_cast<FloatType>(nSeed);
77 
78  const FloatType fRet = floor(fSeed*rRangeMultiplier) + rRangeOffset;
79  return static_cast<T>(fRet);
80  }
81 };
82 
85 template <typename T>
87  typename boost::enable_if_c<sizeof(T)==2>::type>
88 {
89  typedef ipReal64 FloatType;
90 
91  static
92  IPSDK_FORCEINLINE
94  initSeed(ipUInt32 seed)
95  {
96  return seed;
97  }
98 
99  static
100  IPSDK_FORCEINLINE
102  computeRangeMultiplier(T tMin, T tMax)
103  {
104  return (static_cast<FloatType>(tMax) - static_cast<FloatType>(tMin)+1.0) /
105  65536.0;
106  }
107 
108  static
109  IPSDK_FORCEINLINE
111  computeRangeOffset(T tMin, T tMax)
112  {
113  return static_cast<FloatType>(tMin);
114  }
115 
116  static
117  IPSDK_FORCEINLINE
118  T
122  {
123  rSeed = 214013*rSeed+2531011;
124  ipUInt16 nSeed = (0x7FFF & (rSeed >> 16)) << 1;
125  rSeed = 214013*rSeed+2531011;
126  nSeed = ((rSeed >> 16) & 0x1) + nSeed;
127  const FloatType fSeed = static_cast<FloatType>(nSeed);
128  const FloatType fRet = floor(fSeed*rRangeMultiplier) + rRangeOffset;
129  return static_cast<T>(fRet);
130  }
131 };
132 
135 template <typename T>
137  typename boost::enable_if_c<sizeof(T)==4>::type>
138 {
139  typedef ipReal64 FloatType;
140 
141  static
142  IPSDK_FORCEINLINE
144  initSeed(ipUInt32 seed)
145  {
146  return seed;
147  }
148 
149  static
150  IPSDK_FORCEINLINE
152  computeRangeMultiplier(T tMin, T tMax)
153  {
154  return (static_cast<FloatType>(tMax) - static_cast<FloatType>(tMin)+1.0) /
155  4294967296.0;
156  }
157 
158  static
159  IPSDK_FORCEINLINE
161  computeRangeOffset(T tMin, T tMax)
162  {
163  return static_cast<FloatType>(tMin);
164  }
165 
166  static
167  IPSDK_FORCEINLINE
168  T
172  {
173  rSeed = 214013*rSeed+2531011;
174  ipUInt32 nSeed = (0x7FFF & (rSeed >> 16)) << 17;
175  rSeed = 214013*rSeed+2531011;
176  nSeed = (((rSeed >> 16) & 0x7FFF) << 2) + nSeed;
177  rSeed = 214013*rSeed+2531011;
178  nSeed = ((rSeed >> 16) & 0x3) + nSeed;
179 
180  const FloatType fSeed = static_cast<FloatType>(nSeed);
181  const FloatType fRet = floor(fSeed*rRangeMultiplier) + rRangeOffset;
182  return static_cast<T>(fRet);
183  }
184 };
185 
188 template <>
190 {
191  typedef ipReal64 FloatType;
192 
193  static
194  IPSDK_FORCEINLINE
196  initSeed(ipUInt32 seed)
197  {
198  return seed;
199  }
200 
201  static
202  IPSDK_FORCEINLINE
204  computeRangeMultiplier(ipReal32 tMin, ipReal32 tMax)
205  {
206  return (static_cast<FloatType>(tMax) - static_cast<FloatType>(tMin)) /
207  4294967295.0;
208  }
209 
210  static
211  IPSDK_FORCEINLINE
213  computeRangeOffset(ipReal32 tMin, ipReal32 tMax)
214  {
215  return static_cast<FloatType>(tMin);
216  }
217 
218  static
219  IPSDK_FORCEINLINE
220  ipReal32
224  {
225  rSeed = 214013*rSeed+2531011;
226  ipUInt32 nSeed = (0x7FFF & (rSeed >> 16)) << 17;
227  rSeed = 214013*rSeed+2531011;
228  nSeed = (((rSeed >> 16) & 0x7FFF) << 2) + nSeed;
229  rSeed = 214013*rSeed+2531011;
230  nSeed = ((rSeed >> 16) & 0x3) + nSeed;
231 
232  const FloatType fSeed = static_cast<FloatType>(nSeed);
233  const FloatType fRet = fSeed*rRangeMultiplier + rRangeOffset;
234  return static_cast<ipReal32>(fRet);
235  }
236 };
237 
240 template <>
242 {
243  typedef ipReal64 FloatType;
244 
245  static
246  IPSDK_FORCEINLINE
248  initSeed(ipUInt32 seed)
249  {
250  return seed;
251  }
252 
253  static
254  IPSDK_FORCEINLINE
256  computeRangeMultiplier(ipReal64 tMin, ipReal64 tMax)
257  {
258  return (tMax-tMin) / 4294967295.0;
259  }
260 
261  static
262  IPSDK_FORCEINLINE
264  computeRangeOffset(ipReal64 tMin, ipReal64 tMax)
265  {
266  return tMin;
267  }
268 
269  static
270  IPSDK_FORCEINLINE
271  ipReal64
275  {
276  rSeed = 214013*rSeed+2531011;
277  ipUInt32 nSeed = (0x7FFF & (rSeed >> 16)) << 17;
278  rSeed = 214013*rSeed+2531011;
279  nSeed = (((rSeed >> 16) & 0x7FFF) << 2) + nSeed;
280  rSeed = 214013*rSeed+2531011;
281  nSeed = ((rSeed >> 16) & 0x3) + nSeed;
282 
283  const FloatType fSeed = static_cast<FloatType>(nSeed);
284  const FloatType fRet = fSeed*rRangeMultiplier + rRangeOffset;
285  return fRet;
286  }
287 };
288 
291 
292 } // end of namespace detail
293 } // end of namespace simd
294 } // end of namespace ipsdk
295 
296 #endif // __IPSDKUTIL_INSTRUCTIONSET_ARITHMETIC_DETAIL_STD_ABSPACK_H__
Defines the IPSDK_FORCEINLINE.
Main namespace for IPSDK library.
Definition: AlgorithmFunctionEfficiency.h:22
double ipReal64
Base types definition.
Definition: BaseTypes.h:57
RegType class.
eInstructionSet
Enumerate for processor instruction set description.
Definition: InstructionSetTypes.h:31
Definition: UniformRandomLCGReg.h:29
Definition of import/export macro for library.
compiler optimisations only
Definition: InstructionSetTypes.h:34
Definition: RegType.h:29
uint16_t ipUInt16
Base types definition.
Definition: BaseTypes.h:51
float ipReal32
Base types definition.
Definition: BaseTypes.h:56
uint32_t ipUInt32
Base types definition.
Definition: BaseTypes.h:53