Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Run libm-test tests for finite-math-only functions.
This patch arranges for the libm-test tests to be run for the
finite-math-only function variants, in addition to the existing runs
for out-of-line and bits/mathinline.h inline variants.

gen-libm-test.pl is made to add a flag to all tests with non-finite
inputs or outputs so that they can be skipped at runtime when the
finite-math-only variants are being tested (skipping is for all
rounding modes; that is, -ffinite-math-only is being treated as
excluding overflow cases even when the rounding mode is such that the
overflowed result is finite).  errno setting is not tested for these
variants (in general they don't set it, and it's
implementation-defined in ISO C whether it's set on underflow, with
the glibc definition being that it may not be for -ffinite-math-only;
other cases where errno would normally be expected to be set are
mostly excluded as having non-finite or overflowing arguments or
results).

As with the inline function tests, these ones are built with
-D__FINITE_MATH_ONLY=1 to select the function variants, rather than
-ffinite-math-only.  Use of -ffinite-math-only would not be suitable
for these tests because it would also affect libm-test.inc code that
e.g. tests whether results are infinities or NaNs - if these function
variants have bugs that incorrectly produce such results, we want them
to show up in the tests, which means the compiler should not be
optimizing the tests on the basis of results being finite.

The finite-math-only functions share the same ulps settings as the
main out-of-line functions.

These interfaces were one significant group of untested ABIs listed at
<https://sourceware.org/ml/libc-alpha/2013-07/msg00386.html>.  I
haven't rerun the script to list untested interfaces, but I expect
that the vast bulk of interfaces there are still untested and could do
with testcases being added (or, if applicable, being made compat
symbols; in general, most symbols not starting '_' are safe bets to
add tests for, while _* need more investigation of what the actual
public API is, if any).  I'd like to encourage people to help reduce
the accumulation of untested interfaces by adding more tests.

Tested for x86_64 and x86.  Given my recent lgamma/gamma and log*
fixes, the new tests pass (before those fixes, the new tests showed up
those bugs, so illustrating the practical utility of having tests for
these function variants).

	* math/libm-test.inc (NON_FINITE): New macro.
	(enable_test): Do not run tests flagged NON_FINITE if TEST_FINITE.
	* math/gen-libm-test.pl (show_exceptions): Add argument
	$non_finite.
	(parse_args): Update call to show_exceptions.
	* math/test-math-finite.h: New file.
	* math/test-math-no-finite.h: Likewise.
	* math/test-double-finite.c: Likewise.
	* math/test-float-finite.c: Likewise.
	* math/test-ldouble-finite.c: Likewise.
	* math/test-double.c: Include "test-math-no-finite.h".
	* math/test-float.c: Include "test-math-no-finite.h".
	* math/test-ldouble.c: Include "test-math-no-finite.h".
	* math/test-math-inline.h (TEST_FINITE): New macro.
	* math/test-math-vector.h (TEST_FINITE): Likewise.
	* math/Makefile (test-longdouble-yes): Add test-ldouble-finite.
	(libm-tests): Add test-float-finite and test-double-finite.
	($(objpfx)test-float-finite.o): New dependency on
	$(objpfx)libm-test.stmp.
	($(objpfx)test-double-finite.o): Likewise.
	($(objpfx)test-ldouble-finite.o): Likewise.
	(libm-test-no-inline-cflags): New variable.
	(libm-test-finite-cflags): Likewise.
	(CFLAGS-test-float-finite.c): Likewise.
	(CFLAGS-test-double-finite.c): Likewise.
	(CFLAGS-test-ldouble-finite.c): Likewise.
	(CFLAGS-test-float.c): Use $(libm-test-no-inline-cflags).
	(CFLAGS-test-double.c): Likewise.
	(CFLAGS-test-ldouble.c): Likewise.
  • Loading branch information
Joseph Myers committed Nov 5, 2015
1 parent f75226e commit 5a28590
Show file tree
Hide file tree
Showing 14 changed files with 181 additions and 8 deletions.
32 changes: 32 additions & 0 deletions ChangeLog
@@ -1,3 +1,35 @@
2015-11-05 Joseph Myers <joseph@codesourcery.com>

* math/libm-test.inc (NON_FINITE): New macro.
(enable_test): Do not run tests flagged NON_FINITE if TEST_FINITE.
* math/gen-libm-test.pl (show_exceptions): Add argument
$non_finite.
(parse_args): Update call to show_exceptions.
* math/test-math-finite.h: New file.
* math/test-math-no-finite.h: Likewise.
* math/test-double-finite.c: Likewise.
* math/test-float-finite.c: Likewise.
* math/test-ldouble-finite.c: Likewise.
* math/test-double.c: Include "test-math-no-finite.h".
* math/test-float.c: Include "test-math-no-finite.h".
* math/test-ldouble.c: Include "test-math-no-finite.h".
* math/test-math-inline.h (TEST_FINITE): New macro.
* math/test-math-vector.h (TEST_FINITE): Likewise.
* math/Makefile (test-longdouble-yes): Add test-ldouble-finite.
(libm-tests): Add test-float-finite and test-double-finite.
($(objpfx)test-float-finite.o): New dependency on
$(objpfx)libm-test.stmp.
($(objpfx)test-double-finite.o): Likewise.
($(objpfx)test-ldouble-finite.o): Likewise.
(libm-test-no-inline-cflags): New variable.
(libm-test-finite-cflags): Likewise.
(CFLAGS-test-float-finite.c): Likewise.
(CFLAGS-test-double-finite.c): Likewise.
(CFLAGS-test-ldouble-finite.c): Likewise.
(CFLAGS-test-float.c): Use $(libm-test-no-inline-cflags).
(CFLAGS-test-double.c): Likewise.
(CFLAGS-test-ldouble.c): Likewise.

2015-11-05 Roland McGrath <roland@hack.frob.com>

* io/fcntl.c (__fcntl): Add ... to prototype.
Expand Down
20 changes: 15 additions & 5 deletions math/Makefile
Expand Up @@ -113,12 +113,13 @@ tests = test-matherr test-fenv atest-exp atest-sincos atest-exp2 basic-test \
tests-static = test-fpucw-static test-fpucw-ieee-static
# We do the `long double' tests only if this data type is available and
# distinct from `double'.
test-longdouble-yes = test-ldouble test-ildoubl
test-longdouble-yes = test-ldouble test-ildoubl test-ldouble-finite

ifneq (no,$(PERL))
libm-vec-tests = $(addprefix test-,$(libmvec-tests))
libm-tests = test-float test-double $(test-longdouble-$(long-double-fcts)) \
test-ifloat test-idouble $(libm-vec-tests)
test-ifloat test-idouble test-float-finite test-double-finite \
$(libm-vec-tests)
libm-tests.o = $(addsuffix .o,$(libm-tests))

tests += $(libm-tests)
Expand All @@ -141,10 +142,13 @@ $(objpfx)libm-test.stmp: $(ulps-file) libm-test.inc gen-libm-test.pl \

$(objpfx)test-float.o: $(objpfx)libm-test.stmp
$(objpfx)test-ifloat.o: $(objpfx)libm-test.stmp
$(objpfx)test-float-finite.o: $(objpfx)libm-test.stmp
$(objpfx)test-double.o: $(objpfx)libm-test.stmp
$(objpfx)test-idouble.o: $(objpfx)libm-test.stmp
$(objpfx)test-double-finite.o: $(objpfx)libm-test.stmp
$(objpfx)test-ldouble.o: $(objpfx)libm-test.stmp
$(objpfx)test-ildoubl.o: $(objpfx)libm-test.stmp
$(objpfx)test-ldouble-finite.o: $(objpfx)libm-test.stmp
endif

libm-test-fast-math-cflags = -fno-builtin -D__FAST_MATH__ -DTEST_FAST_MATH
Expand All @@ -167,9 +171,15 @@ CFLAGS-test-float-vlen8-wrappers.c = $(float-vlen8-arch-ext-cflags)
CFLAGS-test-float-vlen16.c = $(libm-test-vec-cflags)
CFLAGS-test-float-vlen16-wrappers.c = $(float-vlen16-arch-ext-cflags)

CFLAGS-test-float.c = -fno-inline -ffloat-store -fno-builtin
CFLAGS-test-double.c = -fno-inline -ffloat-store -fno-builtin
CFLAGS-test-ldouble.c = -fno-inline -ffloat-store -fno-builtin
libm-test-no-inline-cflags = -fno-inline -ffloat-store -fno-builtin
libm-test-finite-cflags = $(libm-test-no-inline-cflags) \
-U__FINITE_MATH_ONLY__ -D__FINITE_MATH_ONLY__=1
CFLAGS-test-float.c = $(libm-test-no-inline-cflags)
CFLAGS-test-float-finite.c = $(libm-test-finite-cflags)
CFLAGS-test-double.c = $(libm-test-no-inline-cflags)
CFLAGS-test-double-finite.c = $(libm-test-finite-cflags)
CFLAGS-test-ldouble.c = $(libm-test-no-inline-cflags)
CFLAGS-test-ldouble-finite.c = $(libm-test-finite-cflags)
CFLAGS-test-tgmath.c = -fno-builtin
# The following testcase uses very long lines (>3 million), so it may take a
# while to compile it. See: http://llvm.org/bugs/show_bug.cgi?id=14106 and
Expand Down
12 changes: 9 additions & 3 deletions math/gen-libm-test.pl
Expand Up @@ -141,12 +141,13 @@ sub build_complex_beautify {
# Return the text to put in an initializer for a test's exception
# information.
sub show_exceptions {
my ($ignore_result, $exception) = @_;
my ($ignore_result, $non_finite, $exception) = @_;
$ignore_result = ($ignore_result ? "IGNORE_RESULT|" : "");
$non_finite = ($non_finite ? "NON_FINITE|" : "");
if (defined $exception) {
return ", ${ignore_result}$exception";
return ", ${ignore_result}${non_finite}$exception";
} else {
return ", ${ignore_result}0";
return ", ${ignore_result}${non_finite}0";
}
}

Expand All @@ -162,6 +163,7 @@ sub parse_args {
my (@plus_oflow, @minus_oflow, @plus_uflow, @minus_uflow);
my (@errno_plus_oflow, @errno_minus_oflow);
my (@errno_plus_uflow, @errno_minus_uflow);
my ($non_finite);

($descr_args, $descr_res) = split /_/,$descr, 2;

Expand Down Expand Up @@ -306,8 +308,12 @@ sub parse_args {
if ($ignore_result_any && !$ignore_result_all) {
die ("some but not all function results ignored\n");
}
# Determine whether any arguments or results, for any rounding
# mode, are non-finite.
$non_finite = ($args =~ /qnan_value|plus_infty|minus_infty/);
# Add exceptions.
$cline_res .= show_exceptions ($ignore_result_any,
$non_finite,
($current_arg <= $#args_res)
? $args_res[$current_arg]
: undef);
Expand Down
3 changes: 3 additions & 0 deletions math/libm-test.inc
Expand Up @@ -182,6 +182,7 @@ struct ulp_data
#define ERRNO_ERANGE 0x10000
/* Flags generated by gen-libm-test.pl, not entered here manually. */
#define IGNORE_RESULT 0x20000
#define NON_FINITE 0x40000

/* Values underflowing only for float. */
#ifdef TEST_FLOAT
Expand Down Expand Up @@ -1041,6 +1042,8 @@ enable_test (int exceptions)
return 0;
if (TEST_INLINE && (exceptions & NO_TEST_INLINE))
return 0;
if (TEST_FINITE && (exceptions & NON_FINITE) != 0)
return 0;
return 1;
}

Expand Down
26 changes: 26 additions & 0 deletions math/test-double-finite.c
@@ -0,0 +1,26 @@
/* Copyright (C) 1997-2015 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
<http://www.gnu.org/licenses/>. */

#include "test-double.h"
#include "test-math-finite.h"
#include "test-math-no-inline.h"
#include "test-math-scalar.h"

#define TEST_MSG "testing double (finite-math-only)\n"
#define CHOOSE(Clongdouble,Cdouble,Cfloat,Cinlinelongdouble,Cinlinedouble,Cinlinefloat) Cdouble

#include "libm-test.c"
1 change: 1 addition & 0 deletions math/test-double.c
Expand Up @@ -17,6 +17,7 @@
<http://www.gnu.org/licenses/>. */

#include "test-double.h"
#include "test-math-no-finite.h"
#include "test-math-no-inline.h"
#include "test-math-errno.h"
#include "test-math-scalar.h"
Expand Down
26 changes: 26 additions & 0 deletions math/test-float-finite.c
@@ -0,0 +1,26 @@
/* Copyright (C) 1997-2015 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
<http://www.gnu.org/licenses/>. */

#include "test-float.h"
#include "test-math-finite.h"
#include "test-math-no-inline.h"
#include "test-math-scalar.h"

#define TEST_MSG "testing float (finite-math-only)\n"
#define CHOOSE(Clongdouble,Cdouble,Cfloat,Cinlinelongdouble,Cinlinedouble,Cinlinefloat) Cfloat

#include "libm-test.c"
1 change: 1 addition & 0 deletions math/test-float.c
Expand Up @@ -17,6 +17,7 @@
<http://www.gnu.org/licenses/>. */

#include "test-float.h"
#include "test-math-no-finite.h"
#include "test-math-no-inline.h"
#include "test-math-errno.h"
#include "test-math-scalar.h"
Expand Down
26 changes: 26 additions & 0 deletions math/test-ldouble-finite.c
@@ -0,0 +1,26 @@
/* Copyright (C) 1997-2015 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
<http://www.gnu.org/licenses/>. */

#include "test-ldouble.h"
#include "test-math-finite.h"
#include "test-math-no-inline.h"
#include "test-math-scalar.h"

#define TEST_MSG "testing long double (finite-math-only)\n"
#define CHOOSE(Clongdouble,Cdouble,Cfloat,Cinlinelongdouble,Cinlinedouble,Cinlinefloat) Clongdouble

#include "libm-test.c"
1 change: 1 addition & 0 deletions math/test-ldouble.c
Expand Up @@ -17,6 +17,7 @@
<http://www.gnu.org/licenses/>. */

#include "test-ldouble.h"
#include "test-math-no-finite.h"
#include "test-math-no-inline.h"
#include "test-math-errno.h"
#include "test-math-scalar.h"
Expand Down
20 changes: 20 additions & 0 deletions math/test-math-finite.h
@@ -0,0 +1,20 @@
/* Common definitions for libm tests for finite-math-only.
Copyright (C) 2015 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
<http://www.gnu.org/licenses/>. */

#define TEST_FINITE 1
#define TEST_ERRNO 0
1 change: 1 addition & 0 deletions math/test-math-inline.h
Expand Up @@ -17,6 +17,7 @@
<http://www.gnu.org/licenses/>. */

#define TEST_INLINE 1
#define TEST_FINITE 0
#define TEST_ERRNO 0
#define TEST_EXCEPTIONS 0

Expand Down
19 changes: 19 additions & 0 deletions math/test-math-no-finite.h
@@ -0,0 +1,19 @@
/* Common definitions for libm tests for no-finite-math-only.
Copyright (C) 2015 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
<http://www.gnu.org/licenses/>. */

#define TEST_FINITE 0
1 change: 1 addition & 0 deletions math/test-math-vector.h
Expand Up @@ -17,6 +17,7 @@
<http://www.gnu.org/licenses/>. */

#define TEST_MATHVEC 1
#define TEST_FINITE 0
#define TEST_ERRNO 0

#define CNCT(x, y) x ## y
Expand Down

0 comments on commit 5a28590

Please sign in to comment.