word_test.c 2.1 KB

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