aboutsummaryrefslogtreecommitdiff
path: root/benchmarks/median/median.c
diff options
context:
space:
mode:
authorYunsup Lee <yunsup@cs.berkeley.edu>2013-04-29 18:44:21 -0700
committerYunsup Lee <yunsup@cs.berkeley.edu>2013-04-29 18:44:21 -0700
commit23507d668862dff15a898f20e109a46c6e95780d (patch)
treea3b620e117c1ded337e9508042e353c62a1a97a8 /benchmarks/median/median.c
parentf8ea498f79ab4d6495f2966d1e5c3dd42f567752 (diff)
downloadriscv-tests-23507d668862dff15a898f20e109a46c6e95780d.zip
riscv-tests-23507d668862dff15a898f20e109a46c6e95780d.tar.gz
riscv-tests-23507d668862dff15a898f20e109a46c6e95780d.tar.bz2
benchmarks initial commit
Diffstat (limited to 'benchmarks/median/median.c')
-rw-r--r--benchmarks/median/median.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/benchmarks/median/median.c b/benchmarks/median/median.c
new file mode 100644
index 0000000..3c509cc
--- /dev/null
+++ b/benchmarks/median/median.c
@@ -0,0 +1,40 @@
+//**************************************************************************
+// Median filter (c version)
+//--------------------------------------------------------------------------
+
+void median( int n, int input[], int results[] )
+{
+ int A, B, C, i;
+
+ // Zero the ends
+ results[0] = 0;
+ results[n-1] = 0;
+
+ // Do the filter
+ for ( i = 1; i < (n-1); i++ ) {
+
+ A = input[i-1];
+ B = input[i];
+ C = input[i+1];
+
+ if ( A < B ) {
+ if ( B < C )
+ results[i] = B;
+ else if ( C < A )
+ results[i] = A;
+ else
+ results[i] = C;
+ }
+
+ else {
+ if ( A < C )
+ results[i] = A;
+ else if ( C < B )
+ results[i] = B;
+ else
+ results[i] = C;
+ }
+
+ }
+
+}