blob: 4a3bc0003101a8cea84d29a53fae9c59cd68c754 [file] [log] [blame]
Wolfgang Denkb38e0df2007-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
Wolfgang Denkb38e0df2007-03-06 18:08:43 +010034#include <post.h>
35#include "cpu_asm.h"
36
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020037#if CONFIG_POST & CONFIG_SYS_POST_CPU
Wolfgang Denkb38e0df2007-03-06 18:08:43 +010038
39extern int cpu_post_complex_1_asm (int a1, int a2, int a3, int a4, int n);
40extern int cpu_post_complex_2_asm (int x, int n);
41
42 /*
43 * n
44 * SUM (a1 * a2 - a3) / a4 = n * result
45 * i=1
46 */
47static int cpu_post_test_complex_1 (void)
48{
49 int a1 = 666;
50 int a2 = 667;
51 int a3 = 668;
52 int a4 = 66;
53 int n = 100;
54 int result = 6720; /* (a1 * a2 - a3) / a4 */
55
56 if (cpu_post_complex_1_asm(a1, a2, a3, a4, n) != n * result)
57 {
58 return -1;
59 }
60
61 return 0;
62}
63
64 /* (1 + x + x^2 + ... + x^n) * (1 - x) = 1 - x^(n+1)
65 */
66static int cpu_post_test_complex_2 (void)
67{
68 int ret = -1;
69 int x;
70 int n;
71 int k;
72 int left;
73 int right;
74
75 for (x = -8; x <= 8; x ++)
76 {
77 n = 9;
78
79 left = cpu_post_complex_2_asm(x, n);
80 left *= 1 - x;
81
82 right = 1;
83 for (k = 0; k <= n; k ++)
84 {
85 right *= x;
86 }
87 right = 1 - right;
88
89 if (left != right)
90 {
91 goto Done;
92 }
93 }
94
95 ret = 0;
96 Done:
97
98 return ret;
99}
100
101int cpu_post_test_complex (void)
102{
103 int ret = 0;
Stefan Roese37628252008-08-06 14:05:38 +0200104 int flag = disable_interrupts();
Wolfgang Denkb38e0df2007-03-06 18:08:43 +0100105
106 if (ret == 0)
107 {
108 ret = cpu_post_test_complex_1();
109 }
110
111 if (ret == 0)
112 {
113 ret = cpu_post_test_complex_2();
114 }
115
116 if (ret != 0)
117 {
118 post_log ("Error at complex test !\n");
119 }
120
Stefan Roese37628252008-08-06 14:05:38 +0200121 if (flag)
122 enable_interrupts();
123
Wolfgang Denkb38e0df2007-03-06 18:08:43 +0100124 return ret;
125}
126
127#endif