OpenCores
URL https://opencores.org/ocsvn/aemb/aemb/trunk

Subversion Repositories aemb

[/] [aemb/] [tags/] [AEMB_7_05/] [sw/] [c/] [aeMB_testbench.c] - Blame information for rev 14

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 sybreon
/*
2 14 sybreon
 * $Id: aeMB_testbench.c,v 1.3 2007-04-04 14:09:04 sybreon Exp $
3 2 sybreon
 *
4 6 sybreon
 * AEMB Function Verification C Testbench
5 2 sybreon
 * Copyright (C) 2006 Shawn Tan Ser Ngiap <shawn.tan@aeste.net>
6
 *
7
 * This library is free software; you can redistribute it and/or modify it
8
 * under the terms of the GNU Lesser General Public License as published by
9
 * the Free Software Foundation; either version 2.1 of the License,
10
 * or (at your option) any later version.
11
 *
12
 * This library is distributed in the hope that it will be useful, but
13
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15
 * License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public License
18
 * along with this library; if not, write to the Free Software Foundation, Inc.,
19
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
 *
21
 * DESCRIPTION
22 6 sybreon
 * Runs a simple test programme that calculates fibonnaci numbers using two
23
 * different methods. It tests a whole gamut of operations and is tightly
24
 * linked to the ae68_testbench.v testbench module for verification.
25
 *
26
 * The fibonnaci code is from
27
 * http://en.literateprograms.org/Fibonacci_numbers_(C)
28 2 sybreon
 *
29
 * HISTORY
30
 * $Log: not supported by cvs2svn $
31 14 sybreon
 * Revision 1.2  2007/04/04 06:07:45  sybreon
32
 * Fixed C code bug which passes the test
33
 *
34 6 sybreon
 * Revision 1.1  2007/03/09 17:41:57  sybreon
35
 * initial import
36
 *
37 2 sybreon
 */
38
 
39 6 sybreon
/* Special Prototypes */
40 14 sybreon
void int_call_func (); // __attribute__((save_volatiles));
41 6 sybreon
void int_handler_func () __attribute__ ((interrupt_handler));
42 2 sybreon
 
43 6 sybreon
/* Interrupt Handler */
44
void int_handler_func () {
45
  int_call_func();
46
}
47 2 sybreon
 
48 6 sybreon
void int_call_func () {
49 14 sybreon
  int *p;
50
  p = 0x88888888;
51
  *p = 0x00ED557A; // Write a value to a IO port.
52 6 sybreon
}
53 2 sybreon
 
54 6 sybreon
/* Recursive Version */
55 2 sybreon
 
56 6 sybreon
unsigned int slowfib(unsigned int n)
57
{
58
  return n < 2 ? n : slowfib(n-1) + slowfib(n-2);
59
}
60 2 sybreon
 
61 6 sybreon
/* Iterative Version */
62
 
63
unsigned int fastfib(unsigned int n)
64
{
65
  unsigned int a[3];
66
  unsigned int *p=a;
67
  unsigned int i;
68
 
69
  for(i=0; i<=n; ++i) {
70
    if(i<2) *p=i;
71
    else {
72
      if(p==a) *p=*(a+1)+*(a+2);
73
      else if(p==a+1) *p=*a+*(a+2);
74
      else *p=*a+*(a+1);
75
    }
76
    if(++p>a+2) p=a;
77 2 sybreon
  }
78 6 sybreon
 
79
  return p==a?*(p+2):*(p-1);
80 2 sybreon
}
81
 
82 6 sybreon
/* Compare the Results */
83 2 sybreon
 
84 6 sybreon
int main() {
85
  unsigned int n;
86
  unsigned int fib_fast, fib_slow;
87
  unsigned int fib_lut[] = {0,
88
                            1,
89
                            1,
90
                            2,
91
                            3,
92
                            5,
93
                            8,
94
                            13,
95
                            21,
96
                            34,
97
                            55,
98
                            89,
99
                            144,
100
                            233,
101
                            377,
102
                            610,
103
                            987,
104
                            1597,
105
                            2584,
106
                            4181,
107
                            6765,
108
                            10946,
109
                            17711,
110
                            28657,
111
                            46368,
112
                            75025,
113
                            121393,
114
                            196418,
115
                            317811,
116
                            514229,
117
                            832040,
118
                            1346269,
119
                            2178309,
120
                            3524578,
121
                            5702887};
122
 
123
  for (n=0;n<35;n++) {
124
    fib_slow = slowfib(n);
125
    fib_fast = fastfib(n);
126
    while ((fib_fast != fib_lut[n]) || (fib_slow != fib_fast)) {
127
      fib_lut[n] = 0x00ED17FA;
128
    }
129
  }
130
 
131
  return fib_fast;
132
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.