complex.c 1.7 KB

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