blob: 216b90d803187087d1a28768b81162804ed5a4d6 [file] [log] [blame]
Ross Burton2a9c3802018-09-19 07:25:48 +01001# ===============================================================================
2# https://www.gnu.org/software/autoconf-archive/ax_c_float_words_bigendian.html
3# ===============================================================================
4#
5# SYNOPSIS
6#
7# AX_C_FLOAT_WORDS_BIGENDIAN([ACTION-IF-TRUE], [ACTION-IF-FALSE], [ACTION-IF-UNKNOWN])
8#
9# DESCRIPTION
10#
11# Checks the ordering of words within a multi-word float. This check is
12# necessary because on some systems (e.g. certain ARM systems), the float
13# word ordering can be different from the byte ordering. In a multi-word
14# float context, "big-endian" implies that the word containing the sign
15# bit is found in the memory location with the lowest address. This
16# implementation was inspired by the AC_C_BIGENDIAN macro in autoconf.
17#
18# The endianness is detected by first compiling C code that contains a
19# special double float value, then grepping the resulting object file for
20# certain strings of ASCII values. The double is specially crafted to have
21# a binary representation that corresponds with a simple string. In this
22# implementation, the string "noonsees" was selected because the
23# individual word values ("noon" and "sees") are palindromes, thus making
24# this test byte-order agnostic. If grep finds the string "noonsees" in
25# the object file, the target platform stores float words in big-endian
26# order. If grep finds "seesnoon", float words are in little-endian order.
27# If neither value is found, the user is instructed to specify the
28# ordering.
29#
30# LICENSE
31#
32# Copyright (c) 2008 Daniel Amelang <dan@amelang.net>
33#
34# Copying and distribution of this file, with or without modification, are
35# permitted in any medium without royalty provided the copyright notice
36# and this notice are preserved. This file is offered as-is, without any
37# warranty.
38
39#serial 11
40
41AC_DEFUN([AX_C_FLOAT_WORDS_BIGENDIAN],
42 [AC_CACHE_CHECK(whether float word ordering is bigendian,
43 ax_cv_c_float_words_bigendian, [
44
45ax_cv_c_float_words_bigendian=unknown
46AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
47
48double d = 90904234967036810337470478905505011476211692735615632014797120844053488865816695273723469097858056257517020191247487429516932130503560650002327564517570778480236724525140520121371739201496540132640109977779420565776568942592.0;
49
50]])], [
51
52if grep noonsees conftest.$ac_objext >/dev/null ; then
53 ax_cv_c_float_words_bigendian=yes
54fi
55if grep seesnoon conftest.$ac_objext >/dev/null ; then
56 if test "$ax_cv_c_float_words_bigendian" = unknown; then
57 ax_cv_c_float_words_bigendian=no
58 else
59 ax_cv_c_float_words_bigendian=unknown
60 fi
61fi
62
63])])
64
65case $ax_cv_c_float_words_bigendian in
66 yes)
67 m4_default([$1],
68 [AC_DEFINE([FLOAT_WORDS_BIGENDIAN], 1,
69 [Define to 1 if your system stores words within floats
70 with the most significant word first])]) ;;
71 no)
72 $2 ;;
73 *)
74 m4_default([$3],
75 [AC_MSG_ERROR([
76
77Unknown float word ordering. You need to manually preset
78ax_cv_c_float_words_bigendian=no (or yes) according to your system.
79
80 ])]) ;;
81esac
82
83])# AX_C_FLOAT_WORDS_BIGENDIAN