| 1 | dnl @synopsis AX_CHECK_NONALIGNED_ACCESS |
|---|
| 2 | dnl |
|---|
| 3 | dnl This macro will see if non-aligned memory accesses will fail. The following |
|---|
| 4 | dnl defines will be made as appropriate: |
|---|
| 5 | dnl HAVE_ALIGNED_ONLY_INT16 |
|---|
| 6 | dnl HAVE_ALIGNED_ONLY_INT32 |
|---|
| 7 | dnl HAVE_ALIGNED_ONLY_INT64 |
|---|
| 8 | dnl |
|---|
| 9 | dnl @category C |
|---|
| 10 | dnl @author Martin Ebourne |
|---|
| 11 | dnl @version 2005/07/12 |
|---|
| 12 | dnl @license AllPermissive |
|---|
| 13 | |
|---|
| 14 | AC_DEFUN([AX_CHECK_NONALIGNED_ACCESS], [ |
|---|
| 15 | AC_CACHE_CHECK([if non-aligned 16 bit word accesses fail], [box_cv_have_aligned_only_int16], |
|---|
| 16 | [AC_RUN_IFELSE([AC_LANG_PROGRAM([[$ac_includes_default]], [[ |
|---|
| 17 | #ifndef HAVE_UINT16_T |
|---|
| 18 | #define uint16_t u_int16_t; |
|---|
| 19 | #endif |
|---|
| 20 | uint16_t scratch[2]; |
|---|
| 21 | memset(scratch, 0, sizeof(scratch)); |
|---|
| 22 | return *(uint16_t*)((char*)scratch+1); |
|---|
| 23 | ]])], |
|---|
| 24 | [box_cv_have_aligned_only_int16=no], [box_cv_have_aligned_only_int16=yes] |
|---|
| 25 | )]) |
|---|
| 26 | if test "x$box_cv_have_aligned_only_int16" = "xyes"; then |
|---|
| 27 | AC_DEFINE([HAVE_ALIGNED_ONLY_INT16], 1, [Define to 1 if non-aligned int16 access will fail]) |
|---|
| 28 | fi |
|---|
| 29 | AC_CACHE_CHECK([if non-aligned 32 bit word accesses fail], [box_cv_have_aligned_only_int32], |
|---|
| 30 | [AC_RUN_IFELSE([AC_LANG_PROGRAM([[$ac_includes_default]], [[ |
|---|
| 31 | #ifndef HAVE_UINT32_T |
|---|
| 32 | #define uint32_t u_int32_t; |
|---|
| 33 | #endif |
|---|
| 34 | uint32_t scratch[2]; |
|---|
| 35 | memset(scratch, 0, sizeof(scratch)); |
|---|
| 36 | return *(uint32_t*)((char*)scratch+1); |
|---|
| 37 | ]])], |
|---|
| 38 | [box_cv_have_aligned_only_int32=no], [box_cv_have_aligned_only_int32=yes] |
|---|
| 39 | )]) |
|---|
| 40 | if test "x$box_cv_have_aligned_only_int32" = "xyes"; then |
|---|
| 41 | AC_DEFINE([HAVE_ALIGNED_ONLY_INT32], 1, [Define to 1 if non-aligned int32 access will fail]) |
|---|
| 42 | fi |
|---|
| 43 | AC_CACHE_CHECK([if non-aligned 64 bit word accesses fail], [box_cv_have_aligned_only_int64], |
|---|
| 44 | [AC_RUN_IFELSE([AC_LANG_PROGRAM([[$ac_includes_default]], [[ |
|---|
| 45 | #ifndef HAVE_UINT64_T |
|---|
| 46 | #define uint64_t u_int64_t; |
|---|
| 47 | #endif |
|---|
| 48 | uint64_t scratch[2]; |
|---|
| 49 | memset(scratch, 0, sizeof(scratch)); |
|---|
| 50 | return *(uint64_t*)((char*)scratch+1); |
|---|
| 51 | ]])], |
|---|
| 52 | [box_cv_have_aligned_only_int64=no], [box_cv_have_aligned_only_int64=yes] |
|---|
| 53 | )]) |
|---|
| 54 | if test "x$box_cv_have_aligned_only_int64" = "xyes"; then |
|---|
| 55 | AC_DEFINE([HAVE_ALIGNED_ONLY_INT64], 1, [Define to 1 if non-aligned int64 access will fail]) |
|---|
| 56 | fi |
|---|
| 57 | ])dnl |
|---|