blob: 593bbf7358b9b39f54bd489eaecc338c271ad96c [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 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Wolfgang Denkad5bb452007-03-06 18:08:43 +01006 */
7
8#include <common.h>
9
10/*
11 * CPU test
12 * Complex calculations
13 *
14 * The calculations in this test are just a combination of simpler
15 * calculations, but probably under different timing conditions, etc.
16 */
17
Wolfgang Denkad5bb452007-03-06 18:08:43 +010018#include <post.h>
19#include "cpu_asm.h"
20
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020021#if CONFIG_POST & CONFIG_SYS_POST_CPU
Wolfgang Denkad5bb452007-03-06 18:08:43 +010022
23extern int cpu_post_complex_1_asm (int a1, int a2, int a3, int a4, int n);
24extern int cpu_post_complex_2_asm (int x, int n);
25
26 /*
27 * n
28 * SUM (a1 * a2 - a3) / a4 = n * result
29 * i=1
30 */
31static int cpu_post_test_complex_1 (void)
32{
33 int a1 = 666;
34 int a2 = 667;
35 int a3 = 668;
36 int a4 = 66;
37 int n = 100;
38 int result = 6720; /* (a1 * a2 - a3) / a4 */
39
40 if (cpu_post_complex_1_asm(a1, a2, a3, a4, n) != n * result)
41 {
42 return -1;
43 }
44
45 return 0;
46}
47
48 /* (1 + x + x^2 + ... + x^n) * (1 - x) = 1 - x^(n+1)
49 */
50static int cpu_post_test_complex_2 (void)
51{
52 int ret = -1;
53 int x;
54 int n;
55 int k;
56 int left;
57 int right;
58
59 for (x = -8; x <= 8; x ++)
60 {
61 n = 9;
62
63 left = cpu_post_complex_2_asm(x, n);
64 left *= 1 - x;
65
66 right = 1;
67 for (k = 0; k <= n; k ++)
68 {
69 right *= x;
70 }
71 right = 1 - right;
72
73 if (left != right)
74 {
75 goto Done;
76 }
77 }
78
79 ret = 0;
80 Done:
81
82 return ret;
83}
84
85int cpu_post_test_complex (void)
86{
87 int ret = 0;
Stefan Roesef2302d42008-08-06 14:05:38 +020088 int flag = disable_interrupts();
Wolfgang Denkad5bb452007-03-06 18:08:43 +010089
90 if (ret == 0)
91 {
92 ret = cpu_post_test_complex_1();
93 }
94
95 if (ret == 0)
96 {
97 ret = cpu_post_test_complex_2();
98 }
99
100 if (ret != 0)
101 {
102 post_log ("Error at complex test !\n");
103 }
104
Stefan Roesef2302d42008-08-06 14:05:38 +0200105 if (flag)
106 enable_interrupts();
107
Wolfgang Denkad5bb452007-03-06 18:08:43 +0100108 return ret;
109}
110
111#endif