From patchwork Fri Feb 13 21:55:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 439642 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 84D0C140216 for ; Sat, 14 Feb 2015 08:55:45 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:mime-version :content-type; q=dns; s=default; b=KdSXeBxJYESib6Ncwty6it9+nMDqn 0AFB+7Vqdfz/3gFA2GyEhhXIWgv7P0on4CuQksq0qoRRmPj3Y56P52q2kjb3XRv8 Oy9EG6Eh6azF+YZPplb5UtWoRZiBYSUgbLm9qjUkT7rGLNLmolI9pSSAIzwQNpN7 RRGNrWtyHhQOek= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:mime-version :content-type; s=default; bh=Sw9kKIJ58VC3JtiSgrzuXh8/Bso=; b=w8B ZY7+xdmjg/SLXNPcC2lOmVP8PHzNu4oZvo/HdgFOL+e/BzutHjbReyKNP9MOkkrZ ptJTNQBuA3WWHxGfB1dwBwENWIO6jxrEDAyBeNKrk/CDUEKmLRvZx/N4NQzGyGnY wwE971K5cylfbHjk/FOnb+uD0bAtKbuJ/9pL34/4= Received: (qmail 2675 invoked by alias); 13 Feb 2015 21:55:39 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 2665 invoked by uid 89); 13 Feb 2015 21:55:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=AWL, BAYES_50, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Date: Fri, 13 Feb 2015 21:55:30 +0000 From: Joseph Myers To: Subject: Fix dbl-64/wordsize-64 remquo (bug 17569) [committed] Message-ID: User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) MIME-Version: 1.0 The dbl-64/wordsize-64 remquo implementation follows similar logic to various other implementations, but where that logic computes some absolute values, it wrongly uses a previously computed bit-pattern for the absolute value of the first argument, where actually it needs the absolute value of the first argument mod 8 times the second. This patch fixes it to compute the correct absolute value. The integer quotient result of remquo is only specified mod 8 (including its sign); architecture-specific versions may well vary in what results they give for higher bits of that result (and indeed bug 17569 gives an example correct result from __builtin_remquo giving 9 for that result, where the particular glibc implementation used in that bug report would give 1 after this fix). Thus, this patch adapts the tests of remquo to test that result only mod 8, to allow for such variation when tests with higher quotient are included. Tested for x86_64 and x86. Committed. 2015-02-13 Joseph Myers [BZ #17569] * sysdeps/ieee754/dbl-64/wordsize-64/s_remquo.c (__remquo): Compute absolute value of x as modified by fmod, not original value of x. * math/libm-test.inc (RUN_TEST_ffI_f1): Rename to RUN_TEST_ffI_f1_mod8. Check extra return value mod 8. (RUN_TEST_LOOP_ffI_f1): Rename to RUN_TEST_LOOP_ffI_f1_mod8. Call RUN_TEST_ffI_f1_mod8. (remquo_test_data): Add more tests. diff --git a/math/libm-test.inc b/math/libm-test.inc index aa7ba2b..2f3902a 100644 --- a/math/libm-test.inc +++ b/math/libm-test.inc @@ -1461,9 +1461,9 @@ struct test_fFF_11_data (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \ (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \ ROUND_RESTORE_ ## ROUNDING_MODE -#define RUN_TEST_ffI_f1(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \ - EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \ - EXTRA_EXPECTED) \ +#define RUN_TEST_ffI_f1_mod8(ARG_STR, FUNC_NAME, ARG1, ARG2, EXPECTED, \ + EXCEPTIONS, EXTRA_VAR, EXTRA_TEST, \ + EXTRA_EXPECTED) \ do \ if (enable_test (EXCEPTIONS)) \ { \ @@ -1474,22 +1474,22 @@ struct test_fFF_11_data EXPECTED, EXCEPTIONS); \ EXTRA_OUTPUT_TEST_SETUP (ARG_STR, 1); \ if (EXTRA_TEST) \ - check_int (extra1_name, EXTRA_VAR, EXTRA_EXPECTED, 0); \ + check_int (extra1_name, (EXTRA_VAR) % 8, EXTRA_EXPECTED, 0); \ EXTRA_OUTPUT_TEST_CLEANUP (1); \ COMMON_TEST_CLEANUP; \ } \ while (0) -#define RUN_TEST_LOOP_ffI_f1(FUNC_NAME, ARRAY, ROUNDING_MODE, \ - EXTRA_VAR) \ +#define RUN_TEST_LOOP_ffI_f1_mod8(FUNC_NAME, ARRAY, ROUNDING_MODE, \ + EXTRA_VAR) \ IF_ROUND_INIT_ ## ROUNDING_MODE \ for (size_t i = 0; i < sizeof (ARRAY) / sizeof (ARRAY)[0]; i++) \ - RUN_TEST_ffI_f1 ((ARRAY)[i].arg_str, FUNC_NAME, \ - (ARRAY)[i].arg1, (ARRAY)[i].arg2, \ - (ARRAY)[i].RM_##ROUNDING_MODE.expected, \ - (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \ - EXTRA_VAR, \ - (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \ - (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \ + RUN_TEST_ffI_f1_mod8 ((ARRAY)[i].arg_str, FUNC_NAME, \ + (ARRAY)[i].arg1, (ARRAY)[i].arg2, \ + (ARRAY)[i].RM_##ROUNDING_MODE.expected, \ + (ARRAY)[i].RM_##ROUNDING_MODE.exceptions, \ + EXTRA_VAR, \ + (ARRAY)[i].RM_##ROUNDING_MODE.extra_test, \ + (ARRAY)[i].RM_##ROUNDING_MODE.extra_expected); \ ROUND_RESTORE_ ## ROUNDING_MODE #define RUN_TEST_c_c(ARG_STR, FUNC_NAME, ARGR, ARGC, EXPR, EXPC, \ EXCEPTIONS) \ @@ -8759,6 +8759,11 @@ static const struct test_ffI_f1_data remquo_test_data[] = TEST_ffI_f1 (remquo, 5, 2, 1, 2, NO_INEXACT_EXCEPTION), TEST_ffI_f1 (remquo, 3, 2, -1, 2, NO_INEXACT_EXCEPTION), + + TEST_ffI_f1 (remquo, 3419, 360, 179, 1, NO_INEXACT_EXCEPTION), + TEST_ffI_f1 (remquo, -3419, 360, -179, -1, NO_INEXACT_EXCEPTION), + TEST_ffI_f1 (remquo, 3419, -360, 179, -1, NO_INEXACT_EXCEPTION), + TEST_ffI_f1 (remquo, -3419, -360, -179, 1, NO_INEXACT_EXCEPTION), }; static void @@ -8766,7 +8771,7 @@ remquo_test (void) { int x; - ALL_RM_TEST (remquo, 1, remquo_test_data, RUN_TEST_LOOP_ffI_f1, END, x); + ALL_RM_TEST (remquo, 1, remquo_test_data, RUN_TEST_LOOP_ffI_f1_mod8, END, x); } static const struct test_f_f_data rint_test_data[] = diff --git a/sysdeps/ieee754/dbl-64/wordsize-64/s_remquo.c b/sysdeps/ieee754/dbl-64/wordsize-64/s_remquo.c index 36fc37c..5b71425 100644 --- a/sysdeps/ieee754/dbl-64/wordsize-64/s_remquo.c +++ b/sysdeps/ieee754/dbl-64/wordsize-64/s_remquo.c @@ -55,7 +55,7 @@ __remquo (double x, double y, int *quo) return zero * x; } - INSERT_WORDS64 (x, hx); + x = fabs (x); INSERT_WORDS64 (y, hy); cquo = 0;