itpp_sci  1.0.0
it++ based simulation framework for scicoslab, scilab and scipy
_sim_extension.hpp
1 /*xxx
2 * \brief - new math format
3 * \author maki
4 */
5 
6 #ifndef SIM_EXTENSION_HPP
7 #define SIM_EXTENSION_HPP
8 #include <complex>
9 #include "itpp/itbase.h"
10 
11 
12 typedef std::complex<double> complexd;
13 
14 // for future use
15 // #include <itpp/itbase.h>
16 // typedef Vec<long long> lvec;
17 // typedef Mat<long long> lmat;
18 
22 typedef int8_t q7_t;
23 
27 typedef int16_t q15_t;
28 
32 typedef int32_t q31_t;
33 
37 typedef int64_t q63_t;
38 
42 typedef float float32_t;
43 
47 typedef double float64_t;
48 
52 static inline q31_t clip_q63_to_q31(q63_t x)
53 {
54  return ((q31_t)(x >> 32) != ((q31_t)x >> 31)) ? ((0x7FFFFFFF ^ ((q31_t)(x >> 63)))) : (q31_t)x;
55 }
56 
60 static inline q15_t clip_q63_to_q15(q63_t x)
61 {
62  return ((q31_t)(x >> 32) != ((q31_t)x >> 31)) ? ((0x7FFF ^ ((q15_t)(x >> 63)))) : (q15_t)(x >> 15);
63 }
64 
68 static inline q7_t clip_q31_to_q7(q31_t x)
69 {
70  return ((q31_t)(x >> 24) != ((q31_t)x >> 23)) ? ((0x7F ^ ((q7_t)(x >> 31)))) : (q7_t)x;
71 }
72 
76 static inline q15_t clip_q31_to_q15(q31_t x)
77 {
78  return ((q31_t)(x >> 16) != ((q31_t)x >> 15)) ? ((0x7FFF ^ ((q15_t)(x >> 31)))) : (q15_t)x;
79 }
80 
84 static inline q63_t mult32x64(q63_t x, q31_t y)
85 {
86  return ((((q63_t)(x & 0x00000000FFFFFFFF) * y) >> 32) + (((q63_t)(x >> 32) * y)));
87 }
88 
89 static inline q31_t __SSAT(q31_t x, uint32_t y)
90 {
91  int32_t posMax, negMin;
92  uint32_t i;
93 
94  posMax = 1;
95  for(i = 0; i < (y - 1); i++)
96  {
97  posMax = posMax * 2;
98  }
99 
100  if(x > 0)
101  {
102  posMax = (posMax - 1);
103 
104  if(x > posMax)
105  {
106  x = posMax;
107  }
108  }
109  else
110  {
111  negMin = -posMax;
112 
113  if(x < negMin)
114  {
115  x = negMin;
116  }
117  }
118  return (x);
119 
120 }
121 
122 
123 
124 #endif