+
+AC_MSG_CHECKING(the maximal size of scalar)
+ac_cv_sizeof_max=0
+for s in $ac_cv_sizeof_char \
+ $ac_cv_sizeof_short_int $ac_cv_sizeof_int $ac_cv_sizeof_long_int $ac_cv_sizeof_long_long_int \
+ $ac_cv_sizeof_void_p $ac_cv_sizeof_void_LpR_LvoidR \
+ 4 8; do
+
+ if test $ac_cv_sizeof_max -lt $s ; then
+ ac_cv_sizeof_max=$s
+ fi
+done
+AC_MSG_RESULT($ac_cv_sizeof_max)
+AC_DEFINE_UNQUOTED([SIZEOF_MAX],$ac_cv_sizeof_max,[The maximal size of any scalar on this arch])
+
+])
+# END OF GRAS ARCH CHECK
+
+AC_DEFUN([GRAS_CHECK_STRUCT_COMPACTION],
+[ AC_MSG_CHECKING(whether the struct gets packed)
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include "confdefs.h"
+ #include <sys/types.h>
+ #include <stddef.h> /* offsetof() */
+ struct s {char c; double d;};
+ ]],[[switch (0)
+ case 0:
+ case (sizeof(struct s) == sizeof(double)+sizeof(char)):;
+ ]])],[gras_struct_packed=yes],[gras_struct_packed=no])
+
+ AC_MSG_RESULT($gras_struct_packed)
+ if test x$gras_struct_packed = "xyes" ; then
+ AC_MSG_ERROR([GRAS does not support packed structures since it leads to nasty misalignments])
+ fi
+
+ AC_MSG_CHECKING(whether the struct gets compacted)
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include "confdefs.h"
+ #include <sys/types.h>
+ #include <stddef.h> /* offsetof() */
+ struct s {double d; int i; char c;};
+ ]],[[switch (0)
+ case 0:
+ case (offsetof(struct s,c) == sizeof(double)+sizeof(int)):;
+ ]])],[gras_struct_compact=yes],[gras_struct_compact=no])
+
+ AC_MSG_RESULT($gras_struct_compact)
+
+ if test x$gras_struct_compact != xyes ; then
+ AC_MSG_ERROR([GRAS works only on structure compacting architectures (yet)])
+ fi
+ AC_DEFINE_UNQUOTED(GRAS_STRUCT_COMPACT, 1,
+ [Defined if structures are compacted when possible.
+
+ Consider this structure: struct s {double d; int i; char c;};
+
+ If it is allowed, the char is placed just after the int. If not,
+ it has to be on the 8 bytes boundary imposed by the double.
+
+ For now, GRAS requires the structures to be compacted.
+ ])
+ AC_MSG_CHECKING(whether arrays can straddle struct alignment boundaries)
+
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include "confdefs.h"
+ #include <sys/types.h>
+ #include <stddef.h> /* offsetof() */
+ struct s { double d; int i; char c[6]; };
+ ]],[[switch (0)
+ case 0:
+ case (offsetof(struct s,c) == sizeof(double)+sizeof(int)):;
+ ]])],[gras_array_straddle_struct=yes],[gras_array_straddle_struct=no])
+
+ AC_MSG_RESULT($gras_array_straddle_struct)
+
+ if test x$gras_array_straddle_struct = xyes ; then
+ AC_DEFINE_UNQUOTED(GRAS_ARRAY_STRADDLE_STRUCT, 1,
+ [Defined if arrays in struct can straddle struct alignment boundaries.
+
+ This is like than the structure compaction above, but this time,
+ the argument to be compacted is an array whom each element would be
+ normally compacted. Exemple:
+
+ struct s { double d; int i; char c[6]; };
+
+ Arrays can straddle if c is allowed to come just after i.
+
+ Note that GRAS only support architecture presenting this
+ caracteristic so far.
+ ])
+ else
+ AC_MSG_ERROR([GRAS can only work on architectures allowing array fields to straddle alignment boundaries (yet)])
+ fi
+])
+# END OF GRAS CHECK STRUCT COMPACTION
+
+AC_DEFUN([GRAS_C_COMPACT_STRUCT],
+[ AC_MSG_CHECKING(whether the struct gets compacted)
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include "confdefs.h"
+ #include <sys/types.h>
+ #include <stddef.h> /* offsetof() */
+ struct s {double d; int a; int b;};
+ ]],[[switch (0)
+ case 0:
+ case (offsetof(struct s,b) == sizeof(double)+sizeof(int)):;
+ ]])],[gras_compact_struct=yes],[gras_compact_struct=no])
+
+ AC_MSG_RESULT($gras_compact_struct)
+
+ if test x$gras_compact_struct = xyes ; then
+ AC_DEFINE_UNQUOTED(GRAS_COMPACT_STRUCT, 1,
+ [Defined if structures are compacted when possible])
+ fi