memory.cpp 746 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include<__vic/memory.h>
  2. #include<__vic/stdint.h>
  3. #include<iostream>
  4. #include<exception>
  5. #include<cassert>
  6. void load_unaligned_test()
  7. {
  8. unsigned char bytes[5] = { 0, 0xFE, 0xFE, 0xFE, 0xFE };
  9. assert(__vic::load_unaligned<uint32_t>(bytes + 1) == 0xFEFEFEFE);
  10. }
  11. void store_unaligned_test()
  12. {
  13. unsigned char bytes[5] = {};
  14. __vic::store_unaligned<uint32_t>(bytes + 1, 0xFEFEFEFE);
  15. assert(bytes[1] == 0xFE && bytes[2] == 0xFE
  16. && bytes[3] == 0xFE && bytes[4] == 0xFE);
  17. }
  18. void run_tests()
  19. {
  20. load_unaligned_test();
  21. store_unaligned_test();
  22. }
  23. int main()
  24. {
  25. try
  26. {
  27. run_tests();
  28. return 0;
  29. }
  30. catch(const std::exception &ex)
  31. {
  32. std::cerr << ex.what() << '\n';
  33. }
  34. return 1;
  35. }