Merge branch 'master' of github.com:ucb-bar/riscv-tests
[riscv-tests.git] / benchmarks / median / median.c
1 //**************************************************************************
2 // Median filter (c version)
3 //--------------------------------------------------------------------------
4
5 void median( int n, int input[], int results[] )
6 {
7 int A, B, C, i;
8
9 // Zero the ends
10 results[0] = 0;
11 results[n-1] = 0;
12
13 // Do the filter
14 for ( i = 1; i < (n-1); i++ ) {
15
16 A = input[i-1];
17 B = input[i];
18 C = input[i+1];
19
20 if ( A < B ) {
21 if ( B < C )
22 results[i] = B;
23 else if ( C < A )
24 results[i] = A;
25 else
26 results[i] = C;
27 }
28
29 else {
30 if ( A < C )
31 results[i] = A;
32 else if ( C < B )
33 results[i] = B;
34 else
35 results[i] = C;
36 }
37
38 }
39
40 }