cpu_vsx_aligned.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // check sanity of vsx aligned ld/st
  2. // https://github.com/opencv/opencv/issues/13211
  3. #include <altivec.h>
  4. #undef bool
  5. #define vsx_ld vec_vsx_ld
  6. #define vsx_st vec_vsx_st
  7. template<typename T>
  8. static void fill(T& d, int from = 0, int to = 16)
  9. {
  10. for (int i = from; i < to; i++)
  11. d[i] = i;
  12. }
  13. template<typename T, typename Tvec>
  14. static bool check_data(T& d, Tvec& v, int from = 0, int to = 16)
  15. {
  16. for (int i = from; i < to; i++)
  17. {
  18. if (d[i] != vec_extract(v, i))
  19. return false;
  20. }
  21. return true;
  22. }
  23. int main()
  24. {
  25. unsigned char __attribute__ ((aligned (16))) rbuf[16];
  26. unsigned char __attribute__ ((aligned (16))) wbuf[16];
  27. __vector unsigned char a;
  28. // 1- check aligned load and store
  29. fill(rbuf);
  30. a = vec_ld(0, rbuf);
  31. if (!check_data(rbuf, a))
  32. return 1;
  33. vec_st(a, 0, wbuf);
  34. if (!check_data(wbuf, a))
  35. return 11;
  36. // 2- check mixing aligned load and unaligned store
  37. a = vec_ld(0, rbuf);
  38. vsx_st(a, 0, wbuf);
  39. if (!check_data(wbuf, a))
  40. return 2;
  41. // 3- check mixing unaligned load and aligned store
  42. a = vsx_ld(0, rbuf);
  43. vec_st(a, 0, wbuf);
  44. if (!check_data(wbuf, a))
  45. return 3;
  46. return 0;
  47. }