Changeset 71 for trunk/IPs/systemC/processor/Morpheo/Common/include
- Timestamp:
- Jan 19, 2008, 12:09:01 PM (17 years ago)
- Location:
- trunk/IPs/systemC/processor/Morpheo/Common/include
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/IPs/systemC/processor/Morpheo/Common/include/BitManipulation.h
r63 r71 11 11 #include <stdint.h> 12 12 #include <iostream> 13 using namespace std;14 13 15 14 namespace morpheo { 16 15 16 //............................................................................ 17 17 // gen_mask .................................................................. 18 //............................................................................ 18 19 19 20 template <typename T> … … 29 30 }; 30 31 32 template <typename T> 33 T gen_mask (uint32_t index_max, uint32_t index_min) 34 { 35 return (gen_mask<T>(index_max-index_min+1)<<index_min); 36 }; 37 38 template <typename T> 39 T gen_mask_not (uint32_t index_max, uint32_t index_min) 40 { 41 return ~(gen_mask<T>(index_max-index_min+1)<<index_min); 42 }; 43 44 //............................................................................ 31 45 // mask, mask_not ............................................................ 32 template <typename T> 33 T mask (uint32_t data, uint32_t index_max, uint32_t index_min) 34 { 35 return (gen_mask<T>(index_max-index_min+1)<<index_min) & data; 36 } 37 38 template <typename T> 39 T mask_not (uint32_t data, uint32_t index_max, uint32_t index_min) 40 { 41 return (~(gen_mask<T>(index_max-index_min+1)<<index_min)) & data; 42 } 43 46 //............................................................................ 47 template <typename T> 48 T mask (T data, uint32_t index_max, uint32_t index_min) 49 { 50 return gen_mask <T>(index_max,index_min) & data; 51 } 52 53 template <typename T> 54 T mask_not (T data, uint32_t index_max, uint32_t index_min) 55 { 56 return gen_mask_not<T>(index_max,index_min) & data; 57 } 58 59 //............................................................................ 44 60 // shift_left_logic, shift_right_logic ....................................... 45 template <typename T> 46 T shift_logic_left (uint32_t size, uint32_t data, uint32_t value) 61 //............................................................................ 62 template <typename T> 63 T shift_logic_left (uint32_t size, T data, T value) 47 64 { 48 65 T mask = gen_mask<T> (size); … … 52 69 53 70 template <typename T> 54 T shift_logic_right (uint32_t size, uint32_t data, uint32_tvalue)71 T shift_logic_right (uint32_t size, T data, T value) 55 72 { 56 73 T mask = gen_mask<T> (size); … … 59 76 } 60 77 78 //............................................................................ 61 79 // shift_logic ............................................................... 62 template <typename T> 63 T shift_logic (uint32_t size, uint32_t data, uint32_t value, bool is_direction_left) 80 //............................................................................ 81 template <typename T> 82 T shift_logic (uint32_t size, T data, T value, bool is_direction_left) 64 83 { 65 84 if (is_direction_left == true) … … 69 88 } 70 89 90 //............................................................................ 71 91 // shift_left_arithmetic, shift_right_arithmetic ............................. 72 template <typename T> 73 T shift_arithmetic_left (uint32_t size, uint32_t data, uint32_t value) 92 //............................................................................ 93 template <typename T> 94 T shift_arithmetic_left (uint32_t size, T data, T value) 74 95 { 75 96 bool carry = (data&1) != 0; … … 89 110 90 111 template <typename T> 91 T shift_arithmetic_right (uint32_t size, uint32_t data, uint32_tvalue)112 T shift_arithmetic_right (uint32_t size, T data, T value) 92 113 { 93 114 bool carry = (data&(1<<(size-1))) != 0; … … 105 126 } 106 127 128 //............................................................................ 107 129 // shift_arithmetic .......................................................... 108 template <typename T> 109 T shift_arithmetic (uint32_t size, uint32_t data, uint32_t value, bool is_direction_left) 130 //............................................................................ 131 template <typename T> 132 T shift_arithmetic (uint32_t size, T data, T value, bool is_direction_left) 110 133 { 111 134 if (is_direction_left == true) … … 115 138 } 116 139 140 //............................................................................ 117 141 // shift ..................................................................... 118 template <typename T> 119 T shift (uint32_t size, uint32_t data, uint32_t value, bool is_direction_left, bool is_shift_arithmetic) 142 //............................................................................ 143 template <typename T> 144 T shift (uint32_t size, T data, T value, bool is_direction_left, bool is_shift_arithmetic) 120 145 { 121 146 if (is_shift_arithmetic == true) … … 125 150 } 126 151 152 //............................................................................ 127 153 // rotate_left, rotate_right ................................................. 128 129 template <typename T> 130 T rotate_left (uint32_t size, uint32_t data, uint32_tvalue)154 //............................................................................ 155 template <typename T> 156 T rotate_left (uint32_t size, T data, T value) 131 157 { 132 158 T mask = gen_mask<T> (size); … … 137 163 138 164 template <typename T> 139 T rotate_right (uint32_t size, uint32_t data, uint32_tvalue)165 T rotate_right (uint32_t size, T data, T value) 140 166 { 141 167 T mask = gen_mask<T> (size); … … 145 171 } 146 172 173 //............................................................................ 147 174 // rotate .................................................................... 148 template <typename T> 149 T rotate (uint32_t size, uint32_t data, uint32_t value, bool is_direction_left) 175 //............................................................................ 176 template <typename T> 177 T rotate (uint32_t size, T data, T value, bool is_direction_left) 150 178 { 151 179 if (is_direction_left == true) … … 155 183 } 156 184 185 //............................................................................ 157 186 // range ..................................................................... 158 template <typename T> 159 T range (uint32_t data, uint32_t index_max, uint32_t index_min) 187 //............................................................................ 188 template <typename T> 189 T range (T data, uint32_t index_max, uint32_t index_min) 160 190 { 161 191 return gen_mask<T>(index_max-index_min+1) & (data << index_min); … … 163 193 164 194 template <typename T> 165 T range ( uint32_tdata, uint32_t nb_bits)195 T range (T data, uint32_t nb_bits) 166 196 { 167 197 return gen_mask<T>(nb_bits) & data; 168 198 } 199 200 //............................................................................ 201 // insert .................................................................... 202 //............................................................................ 203 template <typename T> 204 T insert (T data_old, T data_new, uint32_t index_max, uint32_t index_min) 205 { 206 return (mask<T>(data_new,index_max,index_min) | mask_not<T>(data_old,index_max,index_min)); 207 } 208 209 //............................................................................ 210 // extend .................................................................... 211 //............................................................................ 212 template <typename T> 213 T extend (uint32_t size, T data, bool extend_with_sign, uint32_t nb_bits_keep) 214 { 215 if (size < nb_bits_keep) 216 return data; 217 218 if (extend_with_sign and ((data>>(nb_bits_keep-1))&1)) 219 return data | (mask<T>(gen_mask<T>(size),size-1, nb_bits_keep)); 220 else 221 return data & (mask<T>(gen_mask<T>(size),nb_bits_keep-1, 0)); 222 } 223 224 //............................................................................ 225 // duplicate.................................................................. 226 //............................................................................ 227 228 template <typename T> 229 T duplicate (uint32_t size, T data_src, uint32_t nb_bits, uint32_t index_min) 230 { 231 T data_duplicate = mask<T>((data_src)>>index_min, nb_bits-1, 0); 232 T data_dest = 0; 233 234 for (uint32_t i=0; i < size; i+=nb_bits) 235 data_dest |= (data_duplicate<<i); 236 237 return data_dest; 238 } 239 240 template <typename T> 241 T duplicate (uint32_t size, T data_src, uint32_t nb_bits) 242 { 243 return duplicate<T> (size,data_src,nb_bits,0); 244 } 245 246 169 247 }; // end namespace morpheo 170 248 -
trunk/IPs/systemC/processor/Morpheo/Common/include/ChangeCase.h
r63 r71 12 12 #include <stdint.h> 13 13 14 using namespace std;15 16 14 namespace morpheo { 17 15 18 inline void UpperCase(st ring& S)16 inline void UpperCase(std::string& S) 19 17 { 20 18 uint32_t n = S.size(); … … 27 25 } 28 26 29 inline void LowerCase(st ring& S)27 inline void LowerCase(std::string& S) 30 28 { 31 29 uint32_t n = S.size(); -
trunk/IPs/systemC/processor/Morpheo/Common/include/Debug.h
r63 r71 2 2 #define DEBUG_H 3 3 4 #include "Common/include/Message.h" 4 5 #include "Behavioural/include/Debug_component.h" 5 6 #include <stdio.h> … … 8 9 #include <sstream> 9 10 #include <string> 10 using namespace std;11 11 12 12 // Debug's Level : … … 29 29 //Debug 30 30 # define log_printf(level, component, func, str... ) \ 31 do\32 {\33 if ( (DEBUG == DEBUG_ALL ) or\34 (DEBUG_ ## level == DEBUG_NONE) or\35 (( DEBUG_ ## level <= DEBUG) and\36 ( DEBUG_ ## component == true )) )\37 {\38 if (DEBUG >= DEBUG_ALL )\39 {\40 switch (DEBUG_ ## level)\41 {\42 case DEBUG_NONE : fprintf(stdout,"(none ) "); break;\43 case DEBUG_INFO : fprintf(stdout,"(information) "); break;\44 case DEBUG_TRACE : fprintf(stdout,"(trace ) "); break;\45 case DEBUG_FUNC : fprintf(stdout,"(function ) "); break;\46 case DEBUG_ALL : fprintf(stdout,"(all ) "); break;\47 default : fprintf(stdout,"(undefine ) "); break;\48 }\49 }\50 fprintf(stdout,"<%s> ",func);\51 if (DEBUG >= DEBUG_FUNC)\52 {\53 fprintf(stdout,"In file %s, ",__FILE__);\54 fprintf(stdout,"at line %d, ",__LINE__);\55 }\56 fprintf(stdout,": ");\57 fprintf(stdout,str);\58 fprintf(stdout,"\n");\59 fflush (stdout);\60 }\61 } while(0)31 do \ 32 { \ 33 if ((DEBUG == DEBUG_ALL ) or \ 34 (DEBUG_ ## level == DEBUG_NONE) or \ 35 (( DEBUG_ ## level <= DEBUG) and \ 36 ( DEBUG_ ## component == true )) ) \ 37 { \ 38 if (DEBUG >= DEBUG_ALL ) \ 39 { \ 40 switch (DEBUG_ ## level) \ 41 { \ 42 case DEBUG_NONE : msg(_("(none ) ")); break; \ 43 case DEBUG_INFO : msg(_("(information) ")); break; \ 44 case DEBUG_TRACE : msg(_("(trace ) ")); break; \ 45 case DEBUG_FUNC : msg(_("(function ) ")); break; \ 46 case DEBUG_ALL : msg(_("(all ) ")); break; \ 47 default : msg(_("(undefine ) ")); break; \ 48 } \ 49 } \ 50 msg(_("<%s> "),func); \ 51 if (DEBUG >= DEBUG_FUNC) \ 52 { \ 53 msg(_("In file %s, "),__FILE__); \ 54 msg(_("at line %d, "),__LINE__); \ 55 } \ 56 msg(_(": ")); \ 57 msg(str); \ 58 msg(_("\n")); \ 59 fflush (stdout); \ 60 } \ 61 } while(0) 62 62 63 63 #else -
trunk/IPs/systemC/processor/Morpheo/Common/include/ErrorMorpheo.h
r43 r71 5 5 * $Id$ 6 6 * 7 * [ 7 * [ Description ] 8 8 * 9 9 */ 10 10 11 #include "ToString.h" 11 12 #include <iostream> 12 13 #include <exception> 13 14 14 using namespace std;15 16 15 namespace morpheo { 17 16 18 class ErrorMorpheo : public exception 17 #define ERRORMORPHEO(funcname,msg) ErrorMorpheo(funcname,msg,__LINE__,__FILE__) 18 19 class ErrorMorpheo : public std::exception 19 20 { 20 21 // -----[ fields ]---------------------------------------------------- 21 private : st ring _msg;22 private : std::string _msg; 22 23 23 24 // -----[ methods ]--------------------------------------------------- 24 public : ErrorMorpheo () throw() { _msg = "Exception detected ...";} 25 public : ErrorMorpheo (string msg) throw() { _msg = msg;} 25 public : ErrorMorpheo () throw() {_msg="Exception detected ...";} 26 public : ErrorMorpheo (std::string msg) throw() {_msg=msg;} 27 public : ErrorMorpheo (std::string funcname, 28 std::string msg , 29 int line , 30 std::string file ) throw() 31 { 32 _msg = "<"+funcname+"> at line " + toString(line) + ", in file " + file + " : "+msg; 33 } 26 34 public : ~ErrorMorpheo (void) throw() {} 27 35 public : const char* what () const throw() { return ( _msg.c_str() );} … … 29 37 }; 30 38 31 class TestMorpheo : public exception39 class TestMorpheo : public std::exception 32 40 { 33 41 // -----[ fields ]---------------------------------------------------- 34 private : st ring _msg;42 private : std::string _msg; 35 43 36 44 // -----[ methods ]--------------------------------------------------- 37 public : TestMorpheo () throw() { _msg ="Test error ...";}38 public : TestMorpheo (st ring msg) throw() { _msg =msg;}39 public : ~TestMorpheo (void) throw() {}40 public : const char* what () const throw() { return ( _msg.c_str() );}45 public : TestMorpheo () throw() {_msg="Test error ...";} 46 public : TestMorpheo (std::string msg) throw() {_msg=msg;} 47 public : ~TestMorpheo (void) throw() {} 48 public : const char* what () const throw() { return ( _msg.c_str() );} 41 49 }; 42 50 -
trunk/IPs/systemC/processor/Morpheo/Common/include/Log2.h
r67 r71 11 11 #include <stdint.h> 12 12 #include <math.h> 13 using namespace std;14 13 15 14 namespace morpheo { -
trunk/IPs/systemC/processor/Morpheo/Common/include/Message.h
r2 r71 1 #ifndef MESSAGE_H 2 #define MESSAGE_H 1 3 /* 2 4 * $Id$ 3 5 * 4 * [ 6 * [ Description ] 5 7 * 6 8 * Routine of Test 7 9 */ 8 10 9 namespace morpheo { 11 #include <stdio.h> 12 #include <string.h> 13 #include <libintl.h> 10 14 11 #define cerr_msg cerr << "<" << __FILE__ << "> line " << __LINE__ << " : " 12 15 namespace morpheo { 16 17 #ifdef NO_TRANSLATION 18 # define _(String) (String) 19 #else 20 # define _(String) gettext (String) 21 #endif 22 23 #define msg(arg...) fprintf(stdout,arg); 24 #define err(arg...) fprintf(stderr,arg); 25 13 26 }; // end namespace morpheo 27 #endif -
trunk/IPs/systemC/processor/Morpheo/Common/include/Test.h
r53 r71 5 5 #include <sstream> 6 6 #include <stdint.h> 7 #include "Common/include/Message.h" 7 8 #include "Common/include/ErrorMorpheo.h" 8 using namespace std; 9 #include "Common/include/ToString.h" 9 10 10 11 //-----[ Routine de test ]--------------------------------------- … … 12 13 static uint32_t num_test; 13 14 14 void test_ko_error (void)15 inline void test_ko_error (void) 15 16 { 16 string msg = "Test ko : error in test \""+ toString(num_test)+"\"";17 throw ( ErrorMorpheo (msg));17 string msg = "Test ko : error in test \""+morpheo::toString(num_test)+"\""; 18 throw (morpheo::ErrorMorpheo (msg)); 18 19 } 19 20 20 21 template <class T> 21 void test_ko (char * file, uint32_t line, T exp1, T exp2)22 inline void test_ko (char * file, uint32_t line, T exp1, T exp2) 22 23 { 23 24 cerr << "[" << num_test << "] : Test KO" … … 27 28 << " - Line : " << line << endl 28 29 << " * Expression is different" << endl 29 << " - exp1 : "+ toString(exp1) << endl30 << " - exp2 : "+ toString(exp2) << endl;30 << " - exp1 : "+morpheo::toString(exp1) << endl 31 << " - exp2 : "+morpheo::toString(exp2) << endl; 31 32 32 33 test_ko_error (); 33 34 }; 34 35 35 void test_ko (char * file, uint32_t line)36 inline void test_ko (char * file, uint32_t line) 36 37 { 37 38 cerr << "[" << num_test << "] : Test KO" … … 44 45 }; 45 46 46 void test_ok ()47 inline void test_ok () 47 48 { 48 cout << "[" << num_test << "] : Test OK" << endl;49 msg (_("[%d] : Test OK\n"), num_test); 49 50 50 51 num_test ++; 51 52 }; 52 53 53 void test_ok (char * file, uint32_t line)54 inline void test_ok (char * file, uint32_t line) 54 55 { 55 cout << "[" << num_test << "] : Test OK" 56 << "\tline " << line << endl 57 // << " * Localisation" << endl 58 // << " - File : " << file << endl 59 // << " - Line : " << line << endl 60 ; 56 msg (_("[%d] : Test OK\n"), num_test); 57 msg (_("\tline %d\n"), line); 61 58 62 59 num_test ++; … … 64 61 65 62 template <class T> 66 void test_ok (char * file, uint32_t line, T exp)63 inline void test_ok (char * file, uint32_t line, T exp) 67 64 { 68 cout << "[" << num_test << "] : Test OK" 69 << "\tline " << line 70 << "\tvalue : " << toString(exp) << endl 71 // << " * Localisation" << endl 72 // << " - File : " << file << endl 73 // << " - Line : " << line << endl 74 // << " * Expression" << endl 75 // << " - exp : "+toString(exp) << endl 76 ; 65 msg (_("[%d] : Test OK\n"), num_test); 66 msg (_("\tline %d\n"), line); 67 msg (_("\tvalue %s\n"), (morpheo::toString(exp)).c_str()); 77 68 78 69 num_test ++; … … 80 71 81 72 template <class T> 82 void test(char * file, uint32_t line, T exp1, T exp2)73 inline void test(char * file, uint32_t line, T exp1, T exp2) 83 74 { 84 75 if (exp1 != exp2) -
trunk/IPs/systemC/processor/Morpheo/Common/include/ToString.h
r66 r71 17 17 #include <limits> 18 18 19 using std::setprecision ;20 using std::ostringstream ;21 using std::boolalpha ;22 23 19 namespace morpheo { 24 20 25 21 template<typename T> inline std::string toString (const T& x) 26 22 { 27 ostringstream out("");23 std::ostringstream out(""); 28 24 out << x; 29 25 return out.str(); … … 32 28 template<> inline std::string toString<bool> (const bool& x) 33 29 { 34 ostringstream out("");30 std::ostringstream out(""); 35 31 //out << boolalpha << x; 36 32 out << x; … … 41 37 { 42 38 const int sigdigits = std::numeric_limits<float>::digits10; 43 ostringstream out("");44 out << s etprecision(sigdigits) << x;39 std::ostringstream out(""); 40 out << std::setprecision(sigdigits) << x; 45 41 return out.str(); 46 42 } … … 49 45 { 50 46 const int sigdigits = std::numeric_limits<double>::digits10; 51 ostringstream out("");52 out << s etprecision(sigdigits) << x;47 std::ostringstream out(""); 48 out << std::setprecision(sigdigits) << x; 53 49 return out.str(); 54 50 } … … 57 53 { 58 54 const int sigdigits = std::numeric_limits<long double>::digits10; 59 ostringstream out("");60 out << s etprecision(sigdigits) << x;55 std::ostringstream out(""); 56 out << std::setprecision(sigdigits) << x; 61 57 return out.str(); 62 58 } … … 64 60 // template<> inline std::string toString< int8_t> (const int8_t& x) 65 61 // { 66 // ostringstream out("");62 // std::ostringstream out(""); 67 63 // out << x; 68 64 // return out.str(); … … 71 67 // template<> inline std::string toString<uint8_t> (const uint8_t& x) 72 68 // { 73 // ostringstream out("");69 // std::ostringstream out(""); 74 70 // out << x; 75 71 // return out.str(); … … 78 74 // template<> inline std::string toString< int16_t> (const int16_t& x) 79 75 // { 80 // ostringstream out("");76 // std::ostringstream out(""); 81 77 // out << x; 82 78 // return out.str(); … … 85 81 // template<> inline std::string toString<uint16_t> (const uint16_t& x) 86 82 // { 87 // ostringstream out("");83 // std::ostringstream out(""); 88 84 // out << x; 89 85 // return out.str(); … … 92 88 // template<> inline std::string toString< int32_t> (const int32_t& x) 93 89 // { 94 // ostringstream out("");90 // std::ostringstream out(""); 95 91 // out << x; 96 92 // return out.str(); … … 99 95 // template<> inline std::string toString<uint32_t> (const uint32_t& x) 100 96 // { 101 // ostringstream out("");97 // std::ostringstream out(""); 102 98 // out << x; 103 99 // return out.str();
Note: See TracChangeset
for help on using the changeset viewer.