blob: 033584bec087ca530c3de80f88409bfdde4c5cb5 [file] [log] [blame]
Wolfgang Denkad5bb452007-03-06 18:08:43 +01001/*
2 * (C) Copyright 2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24#include <common.h>
25
26/*
27 * CPU test
28 * Complex calculations
29 *
30 * The calculations in this test are just a combination of simpler
31 * calculations, but probably under different timing conditions, etc.
32 */
33
34#ifdef CONFIG_POST
35
36#include <post.h>
37#include "cpu_asm.h"
38
39#if CONFIG_POST & CFG_POST_CPU
40
41extern int cpu_post_complex_1_asm (int a1, int a2, int a3, int a4, int n);
42extern int cpu_post_complex_2_asm (int x, int n);
43
44 /*
45 * n
46 * SUM (a1 * a2 - a3) / a4 = n * result
47 * i=1
48 */
49static int cpu_post_test_complex_1 (void)
50{
51 int a1 = 666;
52 int a2 = 667;
53 int a3 = 668;
54 int a4 = 66;
55 int n = 100;
56 int result = 6720; /* (a1 * a2 - a3) / a4 */
57
58 if (cpu_post_complex_1_asm(a1, a2, a3, a4, n) != n * result)
59 {
60 return -1;
61 }
62
63 return 0;
64}
65
66 /* (1 + x + x^2 + ... + x^n) * (1 - x) = 1 - x^(n+1)
67 */
68static int cpu_post_test_complex_2 (void)
69{
70 int ret = -1;
71 int x;
72 int n;
73 int k;
74 int left;
75 int right;
76
77 for (x = -8; x <= 8; x ++)
78 {
79 n = 9;
80
81 left = cpu_post_complex_2_asm(x, n);
82 left *= 1 - x;
83
84 right = 1;
85 for (k = 0; k <= n; k ++)
86 {
87 right *= x;
88 }
89 right = 1 - right;
90
91 if (left != right)
92 {
93 goto Done;
94 }
95 }
96
97 ret = 0;
98 Done:
99
100 return ret;
101}
102
103int cpu_post_test_complex (void)
104{
105 int ret = 0;
106
107 if (ret == 0)
108 {
109 ret = cpu_post_test_complex_1();
110 }
111
112 if (ret == 0)
113 {
114 ret = cpu_post_test_complex_2();
115 }
116
117 if (ret != 0)
118 {
119 post_log ("Error at complex test !\n");
120 }
121
122 return ret;
123}
124
125#endif
126#endif