as-unaligned-access.m4 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. dnl AS_UNALIGNED_ACCESS
  2. dnl check if unaligned memory access works correctly
  3. AC_DEFUN([AS_UNALIGNED_ACCESS], [
  4. AC_MSG_CHECKING([if unaligned memory access works correctly])
  5. if test x"$as_cv_unaligned_access" = x ; then
  6. case $host in
  7. alpha*|arm*|hp*|mips*|sh*|sparc*|ia64*)
  8. _AS_ECHO_N([(blacklisted) ])
  9. as_cv_unaligned_access=no
  10. ;;
  11. i?86*|x86_64|amd64|powerpc*|m68k*|cris*)
  12. _AS_ECHO_N([(whitelisted) ])
  13. as_cv_unaligned_access=yes
  14. ;;
  15. esac
  16. else
  17. _AS_ECHO_N([(cached) ])
  18. fi
  19. if test x"$as_cv_unaligned_access" = x ; then
  20. AC_TRY_RUN([
  21. int main(int argc, char **argv)
  22. {
  23. char array[] = "ABCDEFGH";
  24. unsigned int iarray[2];
  25. memcpy(iarray,array,8);
  26. #define GET(x) (*(unsigned int *)((char *)iarray + (x)))
  27. if(GET(0) != 0x41424344 && GET(0) != 0x44434241) return 1;
  28. if(GET(1) != 0x42434445 && GET(1) != 0x45444342) return 1;
  29. if(GET(2) != 0x43444546 && GET(2) != 0x46454443) return 1;
  30. if(GET(3) != 0x44454647 && GET(3) != 0x47464544) return 1;
  31. return 0;
  32. }
  33. ], as_cv_unaligned_access="yes", as_cv_unaligned_access="no")
  34. fi
  35. AC_MSG_RESULT($as_cv_unaligned_access)
  36. if test "$as_cv_unaligned_access" = "yes"; then
  37. AC_DEFINE_UNQUOTED(HAVE_UNALIGNED_ACCESS, 1,
  38. [defined if unaligned memory access works correctly])
  39. fi
  40. ])