Commit 1e117923 authored by Tom Lane's avatar Tom Lane

Revise memutils.h to use alignment information gathered by

configure, instead of having a bunch of crufty platform-specific guesses.
parent 235a569a
This diff is collapsed.
......@@ -896,6 +896,70 @@ fi
AC_DEFINE_UNQUOTED(INT64_FORMAT, $INT64_FORMAT)
dnl Determine memory alignment requirements for the basic C datatypes.
dnl CHECK_ALIGNOF(TYPE)
dnl This is modeled on the standard autoconf macro AC_CHECK_SIZEOF,
dnl except it finds the alignment requirement of the type instead of the size.
dnl The defined symbol is named ALIGNOF_TYPE, where the type name is
dnl converted in the same way as for AC_CHECK_SIZEOF.
dnl If cross-compiling, sizeof(type) is used as a default assumption.
AC_DEFUN(CHECK_ALIGNOF,
[changequote(<<, >>)dnl
dnl The name to #define.
define(<<AC_TYPE_NAME>>, translit(alignof_$1, [a-z *], [A-Z_P]))dnl
dnl The cache variable name.
define(<<AC_CV_NAME>>, translit(ac_cv_alignof_$1, [ *], [_p]))dnl
changequote([, ])dnl
AC_MSG_CHECKING(alignment of $1)
AC_CACHE_VAL(AC_CV_NAME,
[AC_TRY_RUN([#include <stdio.h>
struct { char filler; $1 field; } mystruct;
main()
{
FILE *f=fopen("conftestval", "w");
if (!f) exit(1);
fprintf(f, "%d\n", ((char*) & mystruct.field) - ((char*) & mystruct));
exit(0);
}], AC_CV_NAME=`cat conftestval`,
AC_CV_NAME='sizeof($1)',
AC_CV_NAME='sizeof($1)')])dnl
AC_MSG_RESULT($AC_CV_NAME)
AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME)
undefine([AC_TYPE_NAME])dnl
undefine([AC_CV_NAME])dnl
])
CHECK_ALIGNOF(short)
CHECK_ALIGNOF(int)
CHECK_ALIGNOF(long)
if [[ $HAVE_LONG_LONG_INT_64 -eq 1 ]] ; then
CHECK_ALIGNOF(long long int)
fi
CHECK_ALIGNOF(double)
dnl Compute maximum alignment of any basic type.
dnl We assume long's alignment is at least as strong as char, short, or int;
dnl but we must check long long (if it exists) and double.
if [[ $ac_cv_alignof_double != 'sizeof(double)' ]] ; then
MAX_ALIGNOF="$ac_cv_alignof_long"
if [[ $MAX_ALIGNOF -lt $ac_cv_alignof_double ]] ; then
MAX_ALIGNOF="$ac_cv_alignof_double"
fi
if [[ $HAVE_LONG_LONG_INT_64 -eq 1 ]] ; then
if [[ $MAX_ALIGNOF -lt $ac_cv_alignof_long_long_int ]] ; then
MAX_ALIGNOF="$ac_cv_alignof_long_long_int"
fi
fi
else
dnl cross-compiling: assume that double's alignment is worst case
MAX_ALIGNOF="$ac_cv_alignof_double"
fi
AC_DEFINE_UNQUOTED(MAXIMUM_ALIGNOF, $MAX_ALIGNOF)
dnl Check to see if platform has POSIX signal interface.
dnl NOTE: if this test fails then POSIX signals definitely don't work.
dnl It could be that the test compiles but the POSIX routines don't
......
......@@ -290,6 +290,18 @@ extern void srandom(unsigned int seed);
/* Define this as the appropriate snprintf format for 64-bit ints, if any */
#undef INT64_FORMAT
/* These must be defined as the alignment requirement (NOT the size) of
* each of the basic C data types (except char, which we assume has align 1).
* MAXIMUM_ALIGNOF is the largest alignment requirement for any C data type.
* ALIGNOF_LONG_LONG_INT need only be defined if HAVE_LONG_LONG_INT_64 is.
*/
#undef ALIGNOF_SHORT
#undef ALIGNOF_INT
#undef ALIGNOF_LONG
#undef ALIGNOF_LONG_LONG_INT
#undef ALIGNOF_DOUBLE
#undef MAXIMUM_ALIGNOF
/* Define as the base type of the last arg to accept */
#undef SOCKET_SIZE_TYPE
......
......@@ -15,7 +15,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: memutils.h,v 1.22 1999/03/25 03:49:34 tgl Exp $
* $Id: memutils.h,v 1.23 1999/03/25 19:05:19 tgl Exp $
*
* NOTES
* some of the information in this file will be moved to
......@@ -30,50 +30,21 @@
/* ----------------
* Alignment macros: align a length or address appropriately for a given type.
*
* It'd be best to use offsetof to check how the compiler aligns stuff,
* but not all compilers support that (still true)? So we make the
* conservative assumption that a type must be aligned on a boundary equal
* to its own size, except on a few architectures where we know better.
* There used to be some incredibly crufty platform-dependent hackery here,
* but now we rely on the configure script to get the info for us. Much nicer.
*
* CAUTION: for the system tables, the struct declarations found in
* src/include/pg_*.h had better be interpreted by the compiler in a way
* that agrees with the workings of these macros. In practice that means
* being careful to lay out the columns of a system table in a way that avoids
* wasted pad space.
*
* CAUTION: _ALIGN will not work if sizeof(TYPE) is not a power of 2.
* There are machines where sizeof(double) is not, for example.
* But such a size is almost certainly not an alignment boundary anyway.
* NOTE: _ALIGN will not work if ALIGNVAL is not a power of 2.
* That case seems extremely unlikely to occur in practice, however.
* ----------------
*/
#define _ALIGN(TYPE,LEN) \
(((long)(LEN) + (sizeof(TYPE) - 1)) & ~(sizeof(TYPE) - 1))
#define SHORTALIGN(LEN) _ALIGN(short, (LEN))
#if defined(m68k)
#define INTALIGN(LEN) _ALIGN(short, (LEN))
#else
#define INTALIGN(LEN) _ALIGN(int, (LEN))
#endif
#if (defined(sun) && ! defined(sparc)) || defined(m68k)
#define LONGALIGN(LEN) _ALIGN(short, (LEN))
#else
#define LONGALIGN(LEN) _ALIGN(long, (LEN))
#endif
#if defined(m68k)
#define DOUBLEALIGN(LEN) _ALIGN(short, (LEN))
#define MAXALIGN(LEN) _ALIGN(short, (LEN))
#elif defined(sco)
#define DOUBLEALIGN(LEN) _ALIGN(int, (LEN))
#define MAXALIGN(LEN) _ALIGN(int, (LEN))
#else
#define DOUBLEALIGN(LEN) _ALIGN(double, (LEN))
#define MAXALIGN(LEN) _ALIGN(double, (LEN))
#endif
#define _ALIGN(ALIGNVAL,LEN) (((long)(LEN) + (ALIGNVAL-1)) & ~(ALIGNVAL-1))
#define SHORTALIGN(LEN) _ALIGN(ALIGNOF_SHORT, (LEN))
#define INTALIGN(LEN) _ALIGN(ALIGNOF_INT, (LEN))
#define LONGALIGN(LEN) _ALIGN(ALIGNOF_LONG, (LEN))
#define DOUBLEALIGN(LEN) _ALIGN(ALIGNOF_DOUBLE, (LEN))
#define MAXALIGN(LEN) _ALIGN(MAXIMUM_ALIGNOF, (LEN))
/*****************************************************************************
* oset.h -- Fixed format ordered set definitions. *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment