mirror of
https://sourceware.org/git/glibc.git
synced 2025-11-14 04:22:38 +03:00
As discussed in bug 28327, C23 changed the fromfp functions to return floating types instead of intmax_t / uintmax_t. (Although the motivation in N2548 was reducing the use of intmax_t in library interfaces, the new version does have the advantage of being able to specify arbitrary integer widths for e.g. assigning the result to a _BitInt, as well as being able to indicate an error case in-band with a NaN return.) As with other such changes from interfaces introduced in TS 18661, implement the new types as a replacement for the old ones, with the old functions remaining as compat symbols but not supported as an API. The test generator used for many of the tests is updated to handle both versions of the functions. Tested for x86_64 and x86, and with build-many-glibcs.py. Also tested tgmath tests for x86_64 with GCC 7 to make sure that the modified case for older compilers in <tgmath.h> does work. Also tested for powerpc64le to cover the ldbl-128ibm implementation and the other things that are handled differently for that configuration. The new tests fail for ibm128, but all the failures relate to incorrect signs of zero results and turn out to arise from bugs in the underlying roundl, ceill, truncl and floorl implementations that I've reported in bug 33623, rather than indicating any bug in the actual new implementation of the functions for that format. So given fixes for those functions (which shouldn't be hard, and of course should add to the tests for those functions rather than relying only on indirect testing via fromfp), the fromfp tests should start passing for ibm128 as well.
168 lines
6.0 KiB
Python
Executable File
168 lines
6.0 KiB
Python
Executable File
#!/usr/bin/python3
|
|
# Expand test inputs for fromfp functions into text to edit into libm-test.inc.
|
|
# Copyright (C) 2016-2025 Free Software Foundation, Inc.
|
|
# This file is part of the GNU C Library.
|
|
#
|
|
# The GNU C Library is free software; you can redistribute it and/or
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
# License as published by the Free Software Foundation; either
|
|
# version 2.1 of the License, or (at your option) any later version.
|
|
#
|
|
# The GNU C Library is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
# Lesser General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
# License along with the GNU C Library; if not, see
|
|
# <https://www.gnu.org/licenses/>.
|
|
|
|
# Take test inputs on stdin, in format:
|
|
#
|
|
# i <value>:width [int-value]
|
|
#
|
|
# for integer inputs, or
|
|
#
|
|
# t <value> <pos> <z> <a>
|
|
#
|
|
# for noninteger inputs, where <pos> is "a" for fractional part
|
|
# between 0 and 0.5, "be" for 0.5 with even integer part, "bo" for 0.5
|
|
# with odd integer part and "c" for between 0.5 and 1; <z> is the
|
|
# value truncated towards zero, <a> is the value rounded away from
|
|
# zero, both being in the form <value>:<width>. Width values are for
|
|
# the smallest type that can hold the value; for positive values, this
|
|
# is an unsigned type.
|
|
#
|
|
# Command-line argument is function to generate tests for. A line
|
|
# starting "c23" terminates processing for the compat functions, and
|
|
# is otherwise ignored. Any other input lines not of the above form
|
|
# are just passed through unchanged.
|
|
#
|
|
# Note that the output of this script forms the largest part of the
|
|
# tests for the fromfp functions, but not the whole of those tests.
|
|
|
|
import sys
|
|
|
|
func = sys.argv[1]
|
|
|
|
if func.startswith('compat_'):
|
|
compat = True
|
|
func = func[len('compat_'):]
|
|
invalid_value = 'IGNORE'
|
|
else:
|
|
compat = False
|
|
invalid_value = 'qnan_value'
|
|
invalid_res = (invalid_value
|
|
+ ', NO_INEXACT_EXCEPTION|INVALID_EXCEPTION|ERRNO_EDOM')
|
|
exact_res = 'NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED'
|
|
if func == 'fromfpx' or func == 'ufromfpx':
|
|
inexact_res = 'INEXACT_EXCEPTION|ERRNO_UNCHANGED'
|
|
else:
|
|
inexact_res = exact_res
|
|
unsigned = func.startswith('ufromfp')
|
|
rm_list = ['FP_INT_UPWARD', 'FP_INT_DOWNWARD', 'FP_INT_TOWARDZERO',
|
|
'FP_INT_TONEARESTFROMZERO', 'FP_INT_TONEAREST']
|
|
rm_away_pos = {'FP_INT_UPWARD': 'a',
|
|
'FP_INT_DOWNWARD': 'z',
|
|
'FP_INT_TOWARDZERO': 'z',
|
|
'FP_INT_TONEARESTFROMZERO': 'be',
|
|
'FP_INT_TONEAREST': 'bo'}
|
|
rm_away_neg = {'FP_INT_UPWARD': 'z',
|
|
'FP_INT_DOWNWARD': 'a',
|
|
'FP_INT_TOWARDZERO': 'z',
|
|
'FP_INT_TONEARESTFROMZERO': 'be',
|
|
'FP_INT_TONEAREST': 'bo'}
|
|
if compat:
|
|
if unsigned:
|
|
test_macro = 'TEST_fiu_U'
|
|
else:
|
|
test_macro = 'TEST_fiu_M'
|
|
else:
|
|
test_macro = 'TEST_fiu_f'
|
|
|
|
for line in sys.stdin:
|
|
if line.startswith('c23'):
|
|
if compat:
|
|
break
|
|
elif line.startswith('i'):
|
|
data = line.split()
|
|
val_width = data[1]
|
|
val, width = val_width.split(':')
|
|
negative = val.startswith('-')
|
|
if unsigned and negative:
|
|
continue
|
|
width = int(width)
|
|
if not unsigned and not negative:
|
|
width += 1
|
|
width_list = [0, 1]
|
|
if width > 2:
|
|
width_list.append(width - 1)
|
|
if width > 1 and (width <= 64 or not compat):
|
|
width_list.append(width)
|
|
if width < 64 or not compat:
|
|
width_list.append(width + 1)
|
|
if width < 63:
|
|
width_list.append(64)
|
|
width_list = [(w, str(w)) for w in width_list]
|
|
if compat:
|
|
width_list.append((64, 'UINT_MAX'))
|
|
else:
|
|
width_list.append((1000000, 'UINT_MAX'))
|
|
for rm in rm_list:
|
|
for we in width_list:
|
|
w, ws = we
|
|
if w < width:
|
|
print(' %s (%s, %s, %s, %s, %s),' %
|
|
(test_macro, func, val, rm, ws, invalid_res))
|
|
else:
|
|
print(' %s (%s, %s, %s, %s, %s, %s),' %
|
|
(test_macro, func, val, rm, ws, val, exact_res))
|
|
elif line.startswith('t'):
|
|
data = line.split()
|
|
val = data[1]
|
|
pos = data[2]
|
|
z, z_width = data[3].split(':')
|
|
z_width = int(z_width)
|
|
a, a_width = data[4].split(':')
|
|
a_width = int(a_width)
|
|
if unsigned and z.startswith('-') and z != '-0':
|
|
continue
|
|
negative = val.startswith('-')
|
|
if negative:
|
|
rm_away = rm_away_neg
|
|
else:
|
|
rm_away = rm_away_pos
|
|
for rm in rm_list:
|
|
if pos >= rm_away[rm]:
|
|
res, width = a, a_width
|
|
else:
|
|
res, width = z, z_width
|
|
if not unsigned and not negative and res != '0':
|
|
width += 1
|
|
width_list = [0, 1]
|
|
if width > 2:
|
|
width_list.append(width - 1)
|
|
if width > 1 and (width <= 64 or not compat):
|
|
width_list.append(width)
|
|
if width < 64 or not compat:
|
|
width_list.append(width + 1)
|
|
if width < 63:
|
|
width_list.append(64)
|
|
width_list = [(w, str(w)) for w in width_list]
|
|
if compat:
|
|
width_list.append((64, 'UINT_MAX'))
|
|
else:
|
|
width_list.append((1000000, 'UINT_MAX'))
|
|
if res == '-0':
|
|
res = '0' if compat else 'minus_zero'
|
|
for we in width_list:
|
|
w, ws = we
|
|
if w < width or (unsigned and res.startswith('-')):
|
|
print(' %s (%s, %s, %s, %s, %s),' %
|
|
(test_macro, func, val, rm, ws, invalid_res))
|
|
else:
|
|
print(' %s (%s, %s, %s, %s, %s, %s),' %
|
|
(test_macro, func, val, rm, ws, res, inexact_res))
|
|
else:
|
|
print(line.rstrip())
|