Blame m4/exponentl.m4

Packit Service a2489d
# exponentl.m4 serial 4
Packit Service a2489d
dnl Copyright (C) 2007-2018 Free Software Foundation, Inc.
Packit Service a2489d
dnl This file is free software; the Free Software Foundation
Packit Service a2489d
dnl gives unlimited permission to copy and/or distribute it,
Packit Service a2489d
dnl with or without modifications, as long as this notice is preserved.
Packit Service a2489d
AC_DEFUN([gl_LONG_DOUBLE_EXPONENT_LOCATION],
Packit Service a2489d
[
Packit Service a2489d
  AC_REQUIRE([gl_BIGENDIAN])
Packit Service a2489d
  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
Packit Service a2489d
  AC_CACHE_CHECK([where to find the exponent in a 'long double'],
Packit Service a2489d
    [gl_cv_cc_long_double_expbit0],
Packit Service a2489d
    [
Packit Service a2489d
      AC_RUN_IFELSE(
Packit Service a2489d
        [AC_LANG_SOURCE([[
Packit Service a2489d
#include <float.h>
Packit Service a2489d
#include <stddef.h>
Packit Service a2489d
#include <stdio.h>
Packit Service a2489d
#include <string.h>
Packit Service a2489d
#define NWORDS \
Packit Service a2489d
  ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
Packit Service a2489d
typedef union { long double value; unsigned int word[NWORDS]; }
Packit Service a2489d
        memory_long_double;
Packit Service a2489d
static unsigned int ored_words[NWORDS];
Packit Service a2489d
static unsigned int anded_words[NWORDS];
Packit Service a2489d
static void add_to_ored_words (long double x)
Packit Service a2489d
{
Packit Service a2489d
  memory_long_double m;
Packit Service a2489d
  size_t i;
Packit Service a2489d
  /* Clear it first, in case
Packit Service a2489d
     sizeof (long double) < sizeof (memory_long_double).  */
Packit Service a2489d
  memset (&m, 0, sizeof (memory_long_double));
Packit Service a2489d
  m.value = x;
Packit Service a2489d
  for (i = 0; i < NWORDS; i++)
Packit Service a2489d
    {
Packit Service a2489d
      ored_words[i] |= m.word[i];
Packit Service a2489d
      anded_words[i] &= m.word[i];
Packit Service a2489d
    }
Packit Service a2489d
}
Packit Service a2489d
int main ()
Packit Service a2489d
{
Packit Service a2489d
  size_t j;
Packit Service a2489d
  FILE *fp = fopen ("conftest.out", "w");
Packit Service a2489d
  if (fp == NULL)
Packit Service a2489d
    return 1;
Packit Service a2489d
  for (j = 0; j < NWORDS; j++)
Packit Service a2489d
    anded_words[j] = ~ (unsigned int) 0;
Packit Service a2489d
  add_to_ored_words (0.25L);
Packit Service a2489d
  add_to_ored_words (0.5L);
Packit Service a2489d
  add_to_ored_words (1.0L);
Packit Service a2489d
  add_to_ored_words (2.0L);
Packit Service a2489d
  add_to_ored_words (4.0L);
Packit Service a2489d
  /* Remove bits that are common (e.g. if representation of the first mantissa
Packit Service a2489d
     bit is explicit).  */
Packit Service a2489d
  for (j = 0; j < NWORDS; j++)
Packit Service a2489d
    ored_words[j] &= ~anded_words[j];
Packit Service a2489d
  /* Now find the nonzero word.  */
Packit Service a2489d
  for (j = 0; j < NWORDS; j++)
Packit Service a2489d
    if (ored_words[j] != 0)
Packit Service a2489d
      break;
Packit Service a2489d
  if (j < NWORDS)
Packit Service a2489d
    {
Packit Service a2489d
      size_t i;
Packit Service a2489d
      for (i = j + 1; i < NWORDS; i++)
Packit Service a2489d
        if (ored_words[i] != 0)
Packit Service a2489d
          {
Packit Service a2489d
            fprintf (fp, "unknown");
Packit Service a2489d
            return (fclose (fp) != 0);
Packit Service a2489d
          }
Packit Service a2489d
      for (i = 0; ; i++)
Packit Service a2489d
        if ((ored_words[j] >> i) & 1)
Packit Service a2489d
          {
Packit Service a2489d
            fprintf (fp, "word %d bit %d", (int) j, (int) i);
Packit Service a2489d
            return (fclose (fp) != 0);
Packit Service a2489d
          }
Packit Service a2489d
    }
Packit Service a2489d
  fprintf (fp, "unknown");
Packit Service a2489d
  return (fclose (fp) != 0);
Packit Service a2489d
}
Packit Service a2489d
        ]])],
Packit Service a2489d
        [gl_cv_cc_long_double_expbit0=`cat conftest.out`],
Packit Service a2489d
        [gl_cv_cc_long_double_expbit0="unknown"],
Packit Service a2489d
        [
Packit Service a2489d
          dnl When cross-compiling, in general we don't know. It depends on the
Packit Service a2489d
          dnl ABI and compiler version. There are too many cases.
Packit Service a2489d
          gl_cv_cc_long_double_expbit0="unknown"
Packit Service a2489d
          case "$host_os" in
Packit Service a2489d
            mingw*) # On native Windows (little-endian), we know the result
Packit Service a2489d
                    # in two cases: mingw, MSVC.
Packit Service a2489d
              AC_EGREP_CPP([Known], [
Packit Service a2489d
#ifdef __MINGW32__
Packit Service a2489d
 Known
Packit Service a2489d
#endif
Packit Service a2489d
                ], [gl_cv_cc_long_double_expbit0="word 2 bit 0"])
Packit Service a2489d
              AC_EGREP_CPP([Known], [
Packit Service a2489d
#ifdef _MSC_VER
Packit Service a2489d
 Known
Packit Service a2489d
#endif
Packit Service a2489d
                ], [gl_cv_cc_long_double_expbit0="word 1 bit 20"])
Packit Service a2489d
              ;;
Packit Service a2489d
          esac
Packit Service a2489d
        ])
Packit Service a2489d
      rm -f conftest.out
Packit Service a2489d
    ])
Packit Service a2489d
  case "$gl_cv_cc_long_double_expbit0" in
Packit Service a2489d
    word*bit*)
Packit Service a2489d
      word=`echo "$gl_cv_cc_long_double_expbit0" | sed -e 's/word //' -e 's/ bit.*//'`
Packit Service a2489d
      bit=`echo "$gl_cv_cc_long_double_expbit0" | sed -e 's/word.*bit //'`
Packit Service a2489d
      AC_DEFINE_UNQUOTED([LDBL_EXPBIT0_WORD], [$word],
Packit Service a2489d
        [Define as the word index where to find the exponent of 'long double'.])
Packit Service a2489d
      AC_DEFINE_UNQUOTED([LDBL_EXPBIT0_BIT], [$bit],
Packit Service a2489d
        [Define as the bit index in the word where to find bit 0 of the exponent of 'long double'.])
Packit Service a2489d
      ;;
Packit Service a2489d
  esac
Packit Service a2489d
])