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

Subversion Repositories aemb

[/] [aemb/] [trunk/] [sw/] [c/] [aeMB_testbench.c] - Blame information for rev 22

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

Line No. Rev Author Line
1 2 sybreon
/*
2 22 sybreon
 * $Id: aeMB_testbench.c,v 1.4 2007-04-25 22:15:05 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 22 sybreon
 * Revision 1.3  2007/04/04 14:09:04  sybreon
32
 * Added initial interrupt/exception support.
33
 *
34 14 sybreon
 * Revision 1.2  2007/04/04 06:07:45  sybreon
35
 * Fixed C code bug which passes the test
36
 *
37 6 sybreon
 * Revision 1.1  2007/03/09 17:41:57  sybreon
38
 * initial import
39
 *
40 2 sybreon
 */
41
 
42 6 sybreon
/* Special Prototypes */
43 14 sybreon
void int_call_func (); // __attribute__((save_volatiles));
44 6 sybreon
void int_handler_func () __attribute__ ((interrupt_handler));
45 2 sybreon
 
46 6 sybreon
/* Interrupt Handler */
47
void int_handler_func () {
48
  int_call_func();
49
}
50 2 sybreon
 
51 6 sybreon
void int_call_func () {
52 14 sybreon
  int *p;
53
  p = 0x88888888;
54 22 sybreon
  *p = 0x52544E49; // "INTR"
55 6 sybreon
}
56 2 sybreon
 
57 6 sybreon
/* Recursive Version */
58 2 sybreon
 
59 6 sybreon
unsigned int slowfib(unsigned int n)
60
{
61
  return n < 2 ? n : slowfib(n-1) + slowfib(n-2);
62
}
63 2 sybreon
 
64 6 sybreon
/* Iterative Version */
65
 
66
unsigned int fastfib(unsigned int n)
67
{
68
  unsigned int a[3];
69
  unsigned int *p=a;
70
  unsigned int i;
71
 
72
  for(i=0; i<=n; ++i) {
73
    if(i<2) *p=i;
74
    else {
75
      if(p==a) *p=*(a+1)+*(a+2);
76
      else if(p==a+1) *p=*a+*(a+2);
77
      else *p=*a+*(a+1);
78
    }
79
    if(++p>a+2) p=a;
80 2 sybreon
  }
81 6 sybreon
 
82
  return p==a?*(p+2):*(p-1);
83 2 sybreon
}
84
 
85 22 sybreon
/* Various Test */
86 2 sybreon
 
87 6 sybreon
int main() {
88
  unsigned int n;
89
  unsigned int fib_fast, fib_slow;
90 22 sybreon
  unsigned int fib_lut32[] = {0,
91
                              1,
92
                              1,
93
                              2,
94
                              3,
95
                              5,
96
                              8,
97
                              13,
98
                              21,
99
                              34,
100
                              55,
101
                              89,
102
                              144,
103
                              233};
104
 
105
  unsigned short fib_lut16[] = {0,
106
                                1,
107
                                1,
108
                                2,
109
                                3,
110
                                5,
111
                                8,
112
                                13,
113
                                21,
114
                                34,
115
                                55,
116
                                89,
117
                                144,
118
                                233};
119 6 sybreon
 
120 22 sybreon
  unsigned char fib_lut8[] = {0,
121
                              1,
122
                              1,
123
                              2,
124
                              3,
125
                              5,
126
                              8,
127
                              13,
128
                              21,
129
                              34,
130
                              55,
131
                              89,
132
                              144,
133
                              233};
134
 
135
  for (n=0;n<14;n++) {
136 6 sybreon
    fib_slow = slowfib(n);
137
    fib_fast = fastfib(n);
138 22 sybreon
    while ((fib_slow != fib_fast) ||
139
           (fib_fast != fib_lut32[n]) ||
140
           (fib_fast != fib_lut16[n]) ||
141
           (fib_fast != fib_lut8[n])) {
142
      // "FAIL" 
143
      fib_lut32[n] = 0x4C494146;
144 6 sybreon
    }
145 22 sybreon
    // "PASS"
146
    fib_lut32[n] = 0x53534150;
147
  }
148
 
149
  return 0;
150 6 sybreon
}
151 22 sybreon
 

powered by: WebSVN 2.1.0

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