Blame m4/exponentd.m4

Packit Service 4684c1
# exponentd.m4 serial 3
Packit Service 4684c1
dnl Copyright (C) 2007-2008, 2010-2020 Free Software Foundation, Inc.
Packit Service 4684c1
dnl This file is free software; the Free Software Foundation
Packit Service 4684c1
dnl gives unlimited permission to copy and/or distribute it,
Packit Service 4684c1
dnl with or without modifications, as long as this notice is preserved.
Packit Service 4684c1
AC_DEFUN([gl_DOUBLE_EXPONENT_LOCATION],
Packit Service 4684c1
[
Packit Service 4684c1
  AC_CACHE_CHECK([where to find the exponent in a 'double'],
Packit Service 4684c1
    [gl_cv_cc_double_expbit0],
Packit Service 4684c1
    [
Packit Service 4684c1
      AC_RUN_IFELSE(
Packit Service 4684c1
        [AC_LANG_SOURCE([[
Packit Service 4684c1
#include <float.h>
Packit Service 4684c1
#include <stddef.h>
Packit Service 4684c1
#include <stdio.h>
Packit Service 4684c1
#include <string.h>
Packit Service 4684c1
#define NWORDS \
Packit Service 4684c1
  ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
Packit Service 4684c1
typedef union { double value; unsigned int word[NWORDS]; } memory_double;
Packit Service 4684c1
static unsigned int ored_words[NWORDS];
Packit Service 4684c1
static unsigned int anded_words[NWORDS];
Packit Service 4684c1
static void add_to_ored_words (double x)
Packit Service 4684c1
{
Packit Service 4684c1
  memory_double m;
Packit Service 4684c1
  size_t i;
Packit Service 4684c1
  /* Clear it first, in case sizeof (double) < sizeof (memory_double).  */
Packit Service 4684c1
  memset (&m, 0, sizeof (memory_double));
Packit Service 4684c1
  m.value = x;
Packit Service 4684c1
  for (i = 0; i < NWORDS; i++)
Packit Service 4684c1
    {
Packit Service 4684c1
      ored_words[i] |= m.word[i];
Packit Service 4684c1
      anded_words[i] &= m.word[i];
Packit Service 4684c1
    }
Packit Service 4684c1
}
Packit Service 4684c1
int main ()
Packit Service 4684c1
{
Packit Service 4684c1
  size_t j;
Packit Service 4684c1
  FILE *fp = fopen ("conftest.out", "w");
Packit Service 4684c1
  if (fp == NULL)
Packit Service 4684c1
    return 1;
Packit Service 4684c1
  for (j = 0; j < NWORDS; j++)
Packit Service 4684c1
    anded_words[j] = ~ (unsigned int) 0;
Packit Service 4684c1
  add_to_ored_words (0.25);
Packit Service 4684c1
  add_to_ored_words (0.5);
Packit Service 4684c1
  add_to_ored_words (1.0);
Packit Service 4684c1
  add_to_ored_words (2.0);
Packit Service 4684c1
  add_to_ored_words (4.0);
Packit Service 4684c1
  /* Remove bits that are common (e.g. if representation of the first mantissa
Packit Service 4684c1
     bit is explicit).  */
Packit Service 4684c1
  for (j = 0; j < NWORDS; j++)
Packit Service 4684c1
    ored_words[j] &= ~anded_words[j];
Packit Service 4684c1
  /* Now find the nonzero word.  */
Packit Service 4684c1
  for (j = 0; j < NWORDS; j++)
Packit Service 4684c1
    if (ored_words[j] != 0)
Packit Service 4684c1
      break;
Packit Service 4684c1
  if (j < NWORDS)
Packit Service 4684c1
    {
Packit Service 4684c1
      size_t i;
Packit Service 4684c1
      for (i = j + 1; i < NWORDS; i++)
Packit Service 4684c1
        if (ored_words[i] != 0)
Packit Service 4684c1
          {
Packit Service 4684c1
            fprintf (fp, "unknown");
Packit Service 4684c1
            return (fclose (fp) != 0);
Packit Service 4684c1
          }
Packit Service 4684c1
      for (i = 0; ; i++)
Packit Service 4684c1
        if ((ored_words[j] >> i) & 1)
Packit Service 4684c1
          {
Packit Service 4684c1
            fprintf (fp, "word %d bit %d", (int) j, (int) i);
Packit Service 4684c1
            return (fclose (fp) != 0);
Packit Service 4684c1
          }
Packit Service 4684c1
    }
Packit Service 4684c1
  fprintf (fp, "unknown");
Packit Service 4684c1
  return (fclose (fp) != 0);
Packit Service 4684c1
}
Packit Service 4684c1
        ]])],
Packit Service 4684c1
        [gl_cv_cc_double_expbit0=`cat conftest.out`],
Packit Service 4684c1
        [gl_cv_cc_double_expbit0="unknown"],
Packit Service 4684c1
        [
Packit Service 4684c1
          dnl On ARM, there are two 'double' floating-point formats, used by
Packit Service 4684c1
          dnl different sets of instructions: The older FPA instructions assume
Packit Service 4684c1
          dnl that they are stored in big-endian word order, while the words
Packit Service 4684c1
          dnl (like integer types) are stored in little-endian byte order.
Packit Service 4684c1
          dnl The newer VFP instructions assume little-endian order
Packit Service 4684c1
          dnl consistently.
Packit Service 4684c1
          AC_EGREP_CPP([mixed_endianness], [
Packit Service 4684c1
#if defined arm || defined __arm || defined __arm__
Packit Service 4684c1
  mixed_endianness
Packit Service 4684c1
#endif
Packit Service 4684c1
            ],
Packit Service 4684c1
            [gl_cv_cc_double_expbit0="unknown"],
Packit Service 4684c1
            [
Packit Service 4684c1
              pushdef([AC_MSG_CHECKING],[:])dnl
Packit Service 4684c1
              pushdef([AC_MSG_RESULT],[:])dnl
Packit Service 4684c1
              pushdef([AC_MSG_RESULT_UNQUOTED],[:])dnl
Packit Service 4684c1
              AC_C_BIGENDIAN(
Packit Service 4684c1
                [gl_cv_cc_double_expbit0="word 0 bit 20"],
Packit Service 4684c1
                [gl_cv_cc_double_expbit0="word 1 bit 20"],
Packit Service 4684c1
                [gl_cv_cc_double_expbit0="unknown"])
Packit Service 4684c1
              popdef([AC_MSG_RESULT_UNQUOTED])dnl
Packit Service 4684c1
              popdef([AC_MSG_RESULT])dnl
Packit Service 4684c1
              popdef([AC_MSG_CHECKING])dnl
Packit Service 4684c1
            ])
Packit Service 4684c1
        ])
Packit Service 4684c1
      rm -f conftest.out
Packit Service 4684c1
    ])
Packit Service 4684c1
  case "$gl_cv_cc_double_expbit0" in
Packit Service 4684c1
    word*bit*)
Packit Service 4684c1
      word=`echo "$gl_cv_cc_double_expbit0" | sed -e 's/word //' -e 's/ bit.*//'`
Packit Service 4684c1
      bit=`echo "$gl_cv_cc_double_expbit0" | sed -e 's/word.*bit //'`
Packit Service 4684c1
      AC_DEFINE_UNQUOTED([DBL_EXPBIT0_WORD], [$word],
Packit Service 4684c1
        [Define as the word index where to find the exponent of 'double'.])
Packit Service 4684c1
      AC_DEFINE_UNQUOTED([DBL_EXPBIT0_BIT], [$bit],
Packit Service 4684c1
        [Define as the bit index in the word where to find bit 0 of the exponent of 'double'.])
Packit Service 4684c1
      ;;
Packit Service 4684c1
  esac
Packit Service 4684c1
])