complex.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2002
  4. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  5. */
  6. #include <common.h>
  7. /*
  8. * CPU test
  9. * Complex calculations
  10. *
  11. * The calculations in this test are just a combination of simpler
  12. * calculations, but probably under different timing conditions, etc.
  13. */
  14. #include <post.h>
  15. #include "cpu_asm.h"
  16. #if CONFIG_POST & CONFIG_SYS_POST_CPU
  17. extern int cpu_post_complex_1_asm (int a1, int a2, int a3, int a4, int n);
  18. extern int cpu_post_complex_2_asm (int x, int n);
  19. /*
  20. * n
  21. * SUM (a1 * a2 - a3) / a4 = n * result
  22. * i=1
  23. */
  24. static int cpu_post_test_complex_1 (void)
  25. {
  26. int a1 = 666;
  27. int a2 = 667;
  28. int a3 = 668;
  29. int a4 = 66;
  30. int n = 100;
  31. int result = 6720; /* (a1 * a2 - a3) / a4 */
  32. if (cpu_post_complex_1_asm(a1, a2, a3, a4, n) != n * result)
  33. {
  34. return -1;
  35. }
  36. return 0;
  37. }
  38. /* (1 + x + x^2 + ... + x^n) * (1 - x) = 1 - x^(n+1)
  39. */
  40. static int cpu_post_test_complex_2 (void)
  41. {
  42. int ret = -1;
  43. int x;
  44. int n;
  45. int k;
  46. int left;
  47. int right;
  48. for (x = -8; x <= 8; x ++)
  49. {
  50. n = 9;
  51. left = cpu_post_complex_2_asm(x, n);
  52. left *= 1 - x;
  53. right = 1;
  54. for (k = 0; k <= n; k ++)
  55. {
  56. right *= x;
  57. }
  58. right = 1 - right;
  59. if (left != right)
  60. {
  61. goto Done;
  62. }
  63. }
  64. ret = 0;
  65. Done:
  66. return ret;
  67. }
  68. int cpu_post_test_complex (void)
  69. {
  70. int ret = 0;
  71. int flag = disable_interrupts();
  72. if (ret == 0)
  73. {
  74. ret = cpu_post_test_complex_1();
  75. }
  76. if (ret == 0)
  77. {
  78. ret = cpu_post_test_complex_2();
  79. }
  80. if (ret != 0)
  81. {
  82. post_log ("Error at complex test !\n");
  83. }
  84. if (flag)
  85. enable_interrupts();
  86. return ret;
  87. }
  88. #endif