source: trunk/IPs/systemC/processor/Morpheo/Common/include/Max.h @ 87

Last change on this file since 87 was 87, checked in by rosiere, 16 years ago

Test Decod and Decod_unit.

  • Property svn:keywords set to Id
File size: 1.0 KB
Line 
1#ifndef morpheo_max
2#define morpheo_max
3
4/*
5 * $Id: Max.h 87 2008-05-15 19:23:42Z rosiere $
6 *
7 * [ Description ]
8 *
9 */
10
11#include <stdint.h>
12
13namespace morpheo {
14
15  template<typename T> inline T max (const T * x, uint32_t size)
16  {
17    T res = x[0];
18
19    for (uint32_t i=1; i<size; i++)
20      if (res<x[i])
21        res = x[i];
22
23    return res;
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
62 
63}; // end namespace morpheo             
64
65#endif
Note: See TracBrowser for help on using the repository browser.