complex.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * (C) Copyright 2002
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. /*
  25. * CPU test
  26. * Complex calculations
  27. *
  28. * The calculations in this test are just a combination of simpler
  29. * calculations, but probably under different timing conditions, etc.
  30. */
  31. #ifdef CONFIG_POST
  32. #include <post.h>
  33. #include "cpu_asm.h"
  34. #if CONFIG_POST & CFG_POST_CPU
  35. extern int cpu_post_complex_1_asm (int a1, int a2, int a3, int a4, int n);
  36. extern int cpu_post_complex_2_asm (int x, int n);
  37. /*
  38. * n
  39. * SUM (a1 * a2 - a3) / a4 = n * result
  40. * i=1
  41. */
  42. static int cpu_post_test_complex_1 (void)
  43. {
  44. int a1 = 666;
  45. int a2 = 667;
  46. int a3 = 668;
  47. int a4 = 66;
  48. int n = 100;
  49. int result = 6720; /* (a1 * a2 - a3) / a4 */
  50. if (cpu_post_complex_1_asm(a1, a2, a3, a4, n) != n * result)
  51. {
  52. return -1;
  53. }
  54. return 0;
  55. }
  56. /* (1 + x + x^2 + ... + x^n) * (1 - x) = 1 - x^(n+1)
  57. */
  58. static int cpu_post_test_complex_2 (void)
  59. {
  60. int ret = -1;
  61. int x;
  62. int n;
  63. int k;
  64. int left;
  65. int right;
  66. for (x = -8; x <= 8; x ++)
  67. {
  68. n = 9;
  69. left = cpu_post_complex_2_asm(x, n);
  70. left *= 1 - x;
  71. right = 1;
  72. for (k = 0; k <= n; k ++)
  73. {
  74. right *= x;
  75. }
  76. right = 1 - right;
  77. if (left != right)
  78. {
  79. goto Done;
  80. }
  81. }
  82. ret = 0;
  83. Done:
  84. return ret;
  85. }
  86. int cpu_post_test_complex (void)
  87. {
  88. int ret = 0;
  89. if (ret == 0)
  90. {
  91. ret = cpu_post_test_complex_1();
  92. }
  93. if (ret == 0)
  94. {
  95. ret = cpu_post_test_complex_2();
  96. }
  97. if (ret != 0)
  98. {
  99. post_log ("Error at complex test !\n");
  100. }
  101. return ret;
  102. }
  103. #endif
  104. #endif