]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgfortran/mk-kinds-h.sh
rs6000: Expand fmod and remainder when built with fast-math [PR97142]
[thirdparty/gcc.git] / libgfortran / mk-kinds-h.sh
CommitLineData
32aa3bff 1#!/bin/sh
094817b0
TB
2LC_ALL=C
3export LC_ALL
32aa3bff 4
2e764ae1
TB
5if test "$#" -ne 3; then
6 echo "Usage $0 int_kinds real_kinds compile"
7 exit 1
8fi
32aa3bff 9
2e764ae1
TB
10# Possible kinds must be listed in ascending order
11possible_integer_kinds="$1"
12possible_real_kinds="$2"
13compile="$3"
32aa3bff
FXC
14
15largest=""
6ad5cf72 16smallest=""
32aa3bff
FXC
17for k in $possible_integer_kinds; do
18 echo " integer (kind=$k) :: i" > tmp$$.f90
b554826c 19 echo " i = 1_$k" >> tmp$$.f90
32aa3bff 20 echo " end" >> tmp$$.f90
4349e292 21 if $compile -S tmp$$.f90 > /dev/null 2>&1; then
32aa3bff
FXC
22 s=`expr 8 \* $k`
23 largest="$k"
24
25 if [ $s -eq 128 ]; then
26 prefix="__"
27 else
28 prefix=""
29 fi
30
6ad5cf72
CR
31 if [ "$smallest" = "" ]; then
32 smallest="$k"
33 fi
34
32aa3bff
FXC
35 echo "typedef ${prefix}int${s}_t GFC_INTEGER_${k};"
36 echo "typedef ${prefix}uint${s}_t GFC_UINTEGER_${k};"
37 echo "typedef GFC_INTEGER_${k} GFC_LOGICAL_${k};"
fef67987
SL
38 echo "#define HAVE_GFC_LOGICAL_${k} 1"
39 echo "#define HAVE_GFC_INTEGER_${k} 1"
1fa6df85 40 echo ""
32aa3bff
FXC
41 fi
42 rm -f tmp$$.*
43done
44
45echo "#define GFC_INTEGER_LARGEST GFC_INTEGER_${largest}"
46echo "#define GFC_UINTEGER_LARGEST GFC_UINTEGER_${largest}"
6ad5cf72 47echo "#define GFC_DEFAULT_CHAR ${smallest}"
32aa3bff
FXC
48echo ""
49
1ec601bf
FXC
50
51# Get the kind value for long double, so we may disambiguate it
52# from __float128.
53echo "use iso_c_binding; print *, c_long_double ; end" > tmq$$.f90
54long_double_kind=`$compile -S -fdump-parse-tree tmq$$.f90 | grep TRANSFER \
55 | sed 's/ *TRANSFER *//'`
56rm -f tmq$$.*
57
32aa3bff 58
32aa3bff
FXC
59for k in $possible_real_kinds; do
60 echo " real (kind=$k) :: x" > tmp$$.f90
b554826c 61 echo " x = 1.0_$k" >> tmp$$.f90
32aa3bff 62 echo " end" >> tmp$$.f90
4349e292 63 if $compile -S tmp$$.f90 > /dev/null 2>&1; then
32aa3bff 64 case $k in
1ec601bf
FXC
65 4) ctype="float" ; cplxtype="complex float" ; suffix="f" ;;
66 8) ctype="double" ; cplxtype="complex double" ; suffix="" ;;
67 10) ctype="long double" ; cplxtype="complex long double" ; suffix="l" ;;
68 16) if [ $long_double_kind -eq 10 ]; then
69 ctype="__float128"
70 cplxtype="_Complex float __attribute__((mode(TC)))"
71 suffix="q"
72 else
73 ctype="long double"
74 cplxtype="complex long double"
75 suffix="l"
76 fi ;;
32aa3bff
FXC
77 *) echo "$0: Unknown type" >&2 ; exit 1 ;;
78 esac
1fa6df85
FXC
79
80 # Check for the value of HUGE
81 echo "print *, huge(0._$k) ; end" > tmq$$.f90
4349e292 82 huge=`$compile -S -fdump-parse-tree tmq$$.f90 | grep TRANSFER \
66ec5f87 83 | sed 's/ *TRANSFER *//' | sed 's/_.*//'`
1fa6df85
FXC
84 rm -f tmq$$.*
85
86 # Check for the value of DIGITS
87 echo "print *, digits(0._$k) ; end" > tmq$$.f90
4349e292 88 digits=`$compile -S -fdump-parse-tree tmq$$.f90 | grep TRANSFER \
1fa6df85
FXC
89 | sed 's/ *TRANSFER *//'`
90 rm -f tmq$$.*
91
92 # Check for the value of RADIX
93 echo "print *, radix(0._$k) ; end" > tmq$$.f90
4349e292 94 radix=`$compile -S -fdump-parse-tree tmq$$.f90 | grep TRANSFER \
1fa6df85
FXC
95 | sed 's/ *TRANSFER *//'`
96 rm -f tmq$$.*
97
98 # Output the information we've gathered
32aa3bff 99 echo "typedef ${ctype} GFC_REAL_${k};"
1ec601bf 100 echo "typedef ${cplxtype} GFC_COMPLEX_${k};"
fef67987
SL
101 echo "#define HAVE_GFC_REAL_${k} 1"
102 echo "#define HAVE_GFC_COMPLEX_${k} 1"
1fa6df85 103 echo "#define GFC_REAL_${k}_HUGE ${huge}${suffix}"
a83169cd
FXC
104 echo "#define GFC_REAL_${k}_LITERAL_SUFFIX ${suffix}"
105 if [ "x$suffix" = "x" ]; then
106 echo "#define GFC_REAL_${k}_LITERAL(X) (X)"
107 else
108 echo "#define GFC_REAL_${k}_LITERAL(X) (X ## ${suffix})"
109 fi
1fa6df85
FXC
110 echo "#define GFC_REAL_${k}_DIGITS ${digits}"
111 echo "#define GFC_REAL_${k}_RADIX ${radix}"
112 echo ""
32aa3bff
FXC
113 fi
114 rm -f tmp$$.*
115done
116
fef67987
SL
117# For ISO_Fortran_binding.h
118for k in "C_LONG_DOUBLE" "C_FLOAT128" "C_INT128_T"; do
119 fname="tmp$$.val"
120 echo "use iso_c_binding, only: $k; end" > tmp$$.f90
121 if $compile -S -fdump-parse-tree tmp$$.f90 > "$fname"; then
122 kind=`grep "value:" "$fname" |grep value: | sed -e 's/.*value: *//'`
123 if [ "x$kind" = "x" ]; then
124 echo "ERROR: Failed to extract kind for $k" 1>&2
125 exit 1
126 fi
127 echo "#define GFC_${k}_KIND ${kind}"
128 else
129 echo "ERROR: Failed to extract kind for $k" 1>&2
130 exit 1
131 fi
132 rm -f tmp$$.*
133done
1ec601bf 134
2e764ae1 135# After this, we include a header that can override some of the
1ec601bf
FXC
136# autodetected settings.
137echo '#include "kinds-override.h"'
138
32aa3bff 139exit 0