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