Changeset 87 for trunk/IPs/systemC/processor/Morpheo/Common
- Timestamp:
- May 15, 2008, 9:23:42 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/IPs/systemC/processor/Morpheo/Common/include/Max.h
r81 r87 4 4 /* 5 5 * $Id$ 6 *7 * with a stephane dubuisson initial idea8 6 * 9 7 * [ Description ] … … 14 12 15 13 namespace morpheo { 16 17 template<typename T> inline T max (const T * x, uint32_t size 1)14 15 template<typename T> inline T max (const T * x, uint32_t size) 18 16 { 19 T res = 0;17 T res = x[0]; 20 18 21 for (uint32_t i= 0; i<size1; i++)19 for (uint32_t i=1; i<size; i++) 22 20 if (res<x[i]) 23 21 res = x[i]; … … 25 23 return res; 26 24 } 25 26 template<typename T> inline T max (const T * x, uint32_t size, uint32_t n) 27 { 28 if ((n==0) or (n>size)) 29 return max<T>(x,size); 30 31 // validity array 32 bool val [size]; 33 for (uint32_t i=0; i<size; i++) 34 val [i] = true; 35 36 // find min 37 T min = x[0]; 38 39 for (uint32_t i=1; i<size; i++) 40 if (min>x[i]) 41 min = x[i]; 42 43 // find n max 44 T res = min; 45 for (uint32_t i=0; i<n; i++) 46 { 47 48 uint32_t index = 0; 49 res = min; // always take the minor 50 for (uint32_t j=0; j<size; j++) 51 if ((res<x[j]) and val[j]) // find greater value, and slot is valid 52 { 53 res = x[j]; 54 index = j; 55 } 56 val [index] = false; // invalid this value 57 } 58 59 return res; 60 } 61 27 62 28 63 }; // end namespace morpheo
Note: See TracChangeset
for help on using the changeset viewer.