Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2002 |
| 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | 8f3f761 | 2019-11-14 12:57:42 -0700 | [diff] [blame] | 8 | #include <irq_func.h> |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 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 Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 18 | #include <post.h> |
| 19 | #include "cpu_asm.h" |
| 20 | |
Tom Rini | 8eaa3c7 | 2022-11-19 18:45:44 -0500 | [diff] [blame] | 21 | #if CFG_POST & CONFIG_SYS_POST_CPU |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 22 | |
| 23 | extern int cpu_post_complex_1_asm (int a1, int a2, int a3, int a4, int n); |
| 24 | extern 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 | */ |
| 31 | static 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 | */ |
| 50 | static 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 | |
| 85 | int cpu_post_test_complex (void) |
| 86 | { |
| 87 | int ret = 0; |
Stefan Roese | 3762825 | 2008-08-06 14:05:38 +0200 | [diff] [blame] | 88 | int flag = disable_interrupts(); |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 89 | |
| 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 Roese | 3762825 | 2008-08-06 14:05:38 +0200 | [diff] [blame] | 105 | if (flag) |
| 106 | enable_interrupts(); |
| 107 | |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 108 | return ret; |
| 109 | } |
| 110 | |
| 111 | #endif |