blob: 2899dece2c1d9004aa70a8dee6db4bb0b3df217a [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Wolfgang Denkb38e0df2007-03-06 18:08:43 +01002/*
3 * (C) Copyright 2002
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
Wolfgang Denkb38e0df2007-03-06 18:08:43 +01005 */
6
Tom Rinidec7ea02024-05-20 13:35:03 -06007#include <config.h>
Simon Glass8f3f7612019-11-14 12:57:42 -07008#include <irq_func.h>
Wolfgang Denkb38e0df2007-03-06 18:08:43 +01009
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 Denkb38e0df2007-03-06 18:08:43 +010018#include <post.h>
19#include "cpu_asm.h"
20
Tom Rini3dd5d4a2022-12-04 10:14:17 -050021#if CFG_POST & CFG_SYS_POST_CPU
Wolfgang Denkb38e0df2007-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 Roese37628252008-08-06 14:05:38 +020088 int flag = disable_interrupts();
Wolfgang Denkb38e0df2007-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 Roese37628252008-08-06 14:05:38 +0200105 if (flag)
106 enable_interrupts();
107
Wolfgang Denkb38e0df2007-03-06 18:08:43 +0100108 return ret;
109}
110
111#endif