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