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