1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
2a47a12beSStefan Roese /*
3a47a12beSStefan Roese * (C) Copyright 2002
4a47a12beSStefan Roese * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5a47a12beSStefan Roese */
6a47a12beSStefan Roese
7a47a12beSStefan Roese #include <common.h>
8a47a12beSStefan Roese
9a47a12beSStefan Roese /*
10a47a12beSStefan Roese * CPU test
11a47a12beSStefan Roese * Complex calculations
12a47a12beSStefan Roese *
13a47a12beSStefan Roese * The calculations in this test are just a combination of simpler
14a47a12beSStefan Roese * calculations, but probably under different timing conditions, etc.
15a47a12beSStefan Roese */
16a47a12beSStefan Roese
17a47a12beSStefan Roese #include <post.h>
18a47a12beSStefan Roese #include "cpu_asm.h"
19a47a12beSStefan Roese
20a47a12beSStefan Roese #if CONFIG_POST & CONFIG_SYS_POST_CPU
21a47a12beSStefan Roese
22a47a12beSStefan Roese extern int cpu_post_complex_1_asm (int a1, int a2, int a3, int a4, int n);
23a47a12beSStefan Roese extern int cpu_post_complex_2_asm (int x, int n);
24a47a12beSStefan Roese
25a47a12beSStefan Roese /*
26a47a12beSStefan Roese * n
27a47a12beSStefan Roese * SUM (a1 * a2 - a3) / a4 = n * result
28a47a12beSStefan Roese * i=1
29a47a12beSStefan Roese */
cpu_post_test_complex_1(void)30a47a12beSStefan Roese static int cpu_post_test_complex_1 (void)
31a47a12beSStefan Roese {
32a47a12beSStefan Roese int a1 = 666;
33a47a12beSStefan Roese int a2 = 667;
34a47a12beSStefan Roese int a3 = 668;
35a47a12beSStefan Roese int a4 = 66;
36a47a12beSStefan Roese int n = 100;
37a47a12beSStefan Roese int result = 6720; /* (a1 * a2 - a3) / a4 */
38a47a12beSStefan Roese
39a47a12beSStefan Roese if (cpu_post_complex_1_asm(a1, a2, a3, a4, n) != n * result)
40a47a12beSStefan Roese {
41a47a12beSStefan Roese return -1;
42a47a12beSStefan Roese }
43a47a12beSStefan Roese
44a47a12beSStefan Roese return 0;
45a47a12beSStefan Roese }
46a47a12beSStefan Roese
47a47a12beSStefan Roese /* (1 + x + x^2 + ... + x^n) * (1 - x) = 1 - x^(n+1)
48a47a12beSStefan Roese */
cpu_post_test_complex_2(void)49a47a12beSStefan Roese static int cpu_post_test_complex_2 (void)
50a47a12beSStefan Roese {
51a47a12beSStefan Roese int ret = -1;
52a47a12beSStefan Roese int x;
53a47a12beSStefan Roese int n;
54a47a12beSStefan Roese int k;
55a47a12beSStefan Roese int left;
56a47a12beSStefan Roese int right;
57a47a12beSStefan Roese
58a47a12beSStefan Roese for (x = -8; x <= 8; x ++)
59a47a12beSStefan Roese {
60a47a12beSStefan Roese n = 9;
61a47a12beSStefan Roese
62a47a12beSStefan Roese left = cpu_post_complex_2_asm(x, n);
63a47a12beSStefan Roese left *= 1 - x;
64a47a12beSStefan Roese
65a47a12beSStefan Roese right = 1;
66a47a12beSStefan Roese for (k = 0; k <= n; k ++)
67a47a12beSStefan Roese {
68a47a12beSStefan Roese right *= x;
69a47a12beSStefan Roese }
70a47a12beSStefan Roese right = 1 - right;
71a47a12beSStefan Roese
72a47a12beSStefan Roese if (left != right)
73a47a12beSStefan Roese {
74a47a12beSStefan Roese goto Done;
75a47a12beSStefan Roese }
76a47a12beSStefan Roese }
77a47a12beSStefan Roese
78a47a12beSStefan Roese ret = 0;
79a47a12beSStefan Roese Done:
80a47a12beSStefan Roese
81a47a12beSStefan Roese return ret;
82a47a12beSStefan Roese }
83a47a12beSStefan Roese
cpu_post_test_complex(void)84a47a12beSStefan Roese int cpu_post_test_complex (void)
85a47a12beSStefan Roese {
86a47a12beSStefan Roese int ret = 0;
87a47a12beSStefan Roese int flag = disable_interrupts();
88a47a12beSStefan Roese
89a47a12beSStefan Roese if (ret == 0)
90a47a12beSStefan Roese {
91a47a12beSStefan Roese ret = cpu_post_test_complex_1();
92a47a12beSStefan Roese }
93a47a12beSStefan Roese
94a47a12beSStefan Roese if (ret == 0)
95a47a12beSStefan Roese {
96a47a12beSStefan Roese ret = cpu_post_test_complex_2();
97a47a12beSStefan Roese }
98a47a12beSStefan Roese
99a47a12beSStefan Roese if (ret != 0)
100a47a12beSStefan Roese {
101a47a12beSStefan Roese post_log ("Error at complex test !\n");
102a47a12beSStefan Roese }
103a47a12beSStefan Roese
104a47a12beSStefan Roese if (flag)
105a47a12beSStefan Roese enable_interrupts();
106a47a12beSStefan Roese
107a47a12beSStefan Roese return ret;
108a47a12beSStefan Roese }
109a47a12beSStefan Roese
110a47a12beSStefan Roese #endif
111