complex.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. #include <post.h>
  32. #include "cpu_asm.h"
  33. #if CONFIG_POST & CONFIG_SYS_POST_CPU
  34. extern int cpu_post_complex_1_asm (int a1, int a2, int a3, int a4, int n);
  35. extern int cpu_post_complex_2_asm (int x, int n);
  36. /*
  37. * n
  38. * SUM (a1 * a2 - a3) / a4 = n * result
  39. * i=1
  40. */
  41. static int cpu_post_test_complex_1 (void)
  42. {
  43. int a1 = 666;
  44. int a2 = 667;
  45. int a3 = 668;
  46. int a4 = 66;
  47. int n = 100;
  48. int result = 6720; /* (a1 * a2 - a3) / a4 */
  49. if (cpu_post_complex_1_asm(a1, a2, a3, a4, n) != n * result)
  50. {
  51. return -1;
  52. }
  53. return 0;
  54. }
  55. /* (1 + x + x^2 + ... + x^n) * (1 - x) = 1 - x^(n+1)
  56. */
  57. static int cpu_post_test_complex_2 (void)
  58. {
  59. int ret = -1;
  60. int x;
  61. int n;
  62. int k;
  63. int left;
  64. int right;
  65. for (x = -8; x <= 8; x ++)
  66. {
  67. n = 9;
  68. left = cpu_post_complex_2_asm(x, n);
  69. left *= 1 - x;
  70. right = 1;
  71. for (k = 0; k <= n; k ++)
  72. {
  73. right *= x;
  74. }
  75. right = 1 - right;
  76. if (left != right)
  77. {
  78. goto Done;
  79. }
  80. }
  81. ret = 0;
  82. Done:
  83. return ret;
  84. }
  85. int cpu_post_test_complex (void)
  86. {
  87. int ret = 0;
  88. int flag = disable_interrupts();
  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. if (flag)
  102. enable_interrupts();
  103. return ret;
  104. }
  105. #endif