word_test.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. *******************************************************************************
  3. \file word_test.c
  4. \brief Tests for operations on machine words
  5. \project bee2/test
  6. \author (C) Sergey Agievich [agievich@{bsu.by|gmail.com}]
  7. \created 2015.05.22
  8. \version 2017.01.11
  9. \license This program is released under the GNU General Public License
  10. version 3. See Copyright Notices in bee2/info.h.
  11. *******************************************************************************
  12. */
  13. #include <bee2/core/word.h>
  14. /*
  15. *******************************************************************************
  16. Тестирование
  17. *******************************************************************************
  18. */
  19. bool_t wordTest()
  20. {
  21. // weight / parity
  22. if (wordWeight(0) != 0 ||
  23. wordParity(0) ||
  24. !wordParity(1) ||
  25. wordWeight(0xA001) != 3 ||
  26. !wordParity(0xA001) ||
  27. wordWeight(0xFFFF) != 16 ||
  28. wordParity(0xFFFF)
  29. #if (B_PER_W >= 32)
  30. ||
  31. wordWeight(0xF000A001) != 7 ||
  32. !wordParity(0xF000A001) ||
  33. wordWeight(0x0E00A001) != 6 ||
  34. wordParity(0x0E00A001) ||
  35. wordWeight(0xFFFFFFFF) != 32 ||
  36. wordParity(0xFFFFFFFF)
  37. #endif
  38. #if (B_PER_W == 64)
  39. ||
  40. wordWeight(0xAA0180EEF000A001) != 19 ||
  41. !wordParity(0xAA0180EEF000A001) ||
  42. wordWeight(0x730085060E00A001) != 16 ||
  43. wordParity(0x730085060E00A001) ||
  44. wordWeight(0xFFFFFFFFFFFFFFFF) != 64 ||
  45. wordParity(0xFFFFFFFFFFFFFFFF)
  46. #endif
  47. )
  48. return FALSE;
  49. // CTZ / CLZ
  50. if (wordCTZ(0) != B_PER_W ||
  51. FAST(wordCTZ)(0) != B_PER_W ||
  52. wordCLZ(0) != B_PER_W ||
  53. FAST(wordCLZ)(0) != B_PER_W ||
  54. wordCTZ(1) != 0 ||
  55. FAST(wordCTZ)(1) != 0 ||
  56. wordCLZ(1) != B_PER_W - 1 ||
  57. FAST(wordCLZ)(1) != B_PER_W - 1 ||
  58. wordCTZ(0xFFF8) != 3 ||
  59. FAST(wordCTZ)(0xFFF8) != 3 ||
  60. wordCLZ(0xFFF8) != B_PER_W - 16 ||
  61. FAST(wordCLZ)(0xFFF8) != B_PER_W - 16
  62. #if (B_PER_W >= 32)
  63. ||
  64. wordCTZ(0x7FFFE000) != 13 ||
  65. FAST(wordCTZ)(0x7FFFE000) != 13 ||
  66. wordCLZ(0x7FFFE000) != B_PER_W - 31 ||
  67. FAST(wordCLZ)(0x7FFFE000) != B_PER_W - 31
  68. #endif
  69. #if (B_PER_W == 64)
  70. ||
  71. wordCTZ(0x0000003FFDDF8000) != 15 ||
  72. FAST(wordCTZ)(0x0000003FFDDF8000) != 15 ||
  73. wordCLZ(0x0000003FFDDF8000) != 26 ||
  74. FAST(wordCLZ)(0x0000003FFDDF8000) != 26
  75. #endif
  76. )
  77. return FALSE;
  78. // все нормально
  79. return TRUE;
  80. }