From patchwork Thu Jan 11 18:19:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 859229 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-89099-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="VYipvc/D"; dkim-atps=neutral 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 3zHZ0V5PXqz9s7M for ; Fri, 12 Jan 2018 05:19:38 +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=Cje2SFvELDRelAdrYXUlT8xFFdTjj F5VTzwB6gdqSf8SgOyhu+cMB0eC6P+K+ffGhUaZHZNPj838UElhXCWN9TaQA5RrJ 95elCkuIhZb+pxQ+URen/UuxwNWRo3YERO//Op07UII5ZAyR7FadcyA9QvDpoO86 vIA5gWTCiG+iTo= 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=jCXxyIOlRX6cCsQmTMYV4RS0oQU=; b=VYi pvc/DNn79hyxknn2rRb+6yuUE0cJY8JOvVtn7R7IzLp2RjHNb+VePpGVXhXptVo2 oqC6++At0KzEtUa7EEdpVrxZIWCa+139zTAqo6M2KxQ3khJ7yU0M0ubZsqOqWVP7 1pTTB82L7O2/bnp+Z+7+IDDxIFY7iml1KRC6wU4s= Received: (qmail 81809 invoked by alias); 11 Jan 2018 18:19:33 -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 81778 invoked by uid 89); 11 Jan 2018 18:19:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS, URIBL_RED autolearn=ham version=3.3.2 spammy= X-HELO: relay1.mentorg.com Date: Thu, 11 Jan 2018 18:19:24 +0000 From: Joseph Myers To: Subject: Make default libc_feholdsetround_noex_ctx use __feholdexcept (bug 22702) [committed] Message-ID: User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 X-ClientProxiedBy: svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) For soft-float powerpc, the math/test-nearbyint-except-2 test fails because nearbyintl traps when traps on "inexact" are enabled on entry (and an "inexact" exception is generated internally, though cleared for the final return). The problem is the default implementation of libc_feholdsetround_noex_ctx, which does not disable exception traps. There is some ambiguity about whether the *noex* interfaces are required to do so or only permitted to do so. But given that we support fe* interfaces to enable and disable traps (on architectures with that functionality), functions that must not raise an exception (must not leave the flag set on exit if not set on entry) should also not trap on it when traps on that exception are enabled. So it is appropriate to define these interfaces to have the feholdexcept effect of disabling exception traps; this patch updates the default implementation and comments accordingly. At least some architecture versions already disable traps; there are few uses of the *noex* interfaces at all, and while it's possible there are bugs on any architecture versions failing to disable traps that appear in the exp2 and remainder implementations, there are currently no tests, other than this one for nearbyintl (where only the ldbl-128ibm implementation uses SET_RESTORE_ROUND_NOEX), that would fail as a result of such a bug. (Hard-float powerpc does disable traps here, hence the nearbyintl failure not appearing there.) Tested for powerpc (soft-float). This brings that configuration to clean math/ test results, provided you build with GCC 8 to get the fix for GCC bug 64811. Committed. 2018-01-11 Joseph Myers [BZ #22702] * sysdeps/generic/math_private.h (libc_feresetround_noex): Update comment to say exceptions are discarded. (libc_feholdsetround_noex_ctx): Use __feholdexcept instead of __fegetenv. (SET_RESTORE_ROUND_NOEX): Update comment to say non-stop mode must be enabled. diff --git a/sysdeps/generic/math_private.h b/sysdeps/generic/math_private.h index f29898c..e4b9d86 100644 --- a/sysdeps/generic/math_private.h +++ b/sysdeps/generic/math_private.h @@ -498,7 +498,7 @@ default_libc_feupdateenv_test (fenv_t *e, int ex) # define libc_feresetroundl libc_feupdateenvl #endif -/* ... and a version that may also discard exceptions. */ +/* ... and a version that also discards exceptions. */ #ifndef libc_feresetround_noex # define libc_feresetround_noex libc_fesetenv @@ -572,8 +572,9 @@ libc_feresetround_ctx (struct rm_ctx *ctx) static __always_inline void libc_feholdsetround_noex_ctx (struct rm_ctx *ctx, int round) { - /* Save exception flags and rounding mode. */ - __fegetenv (&ctx->env); + /* Save exception flags and rounding mode, and disable exception + traps. */ + __feholdexcept (&ctx->env); /* Update rounding mode only if different. */ if (__glibc_unlikely (round != get_rounding_mode ())) @@ -626,7 +627,7 @@ libc_feresetround_noex_ctx (struct rm_ctx *ctx) the value at the start of the block. The exception mode must be preserved. Exceptions raised within the block must be discarded, and exception flags are restored to the value at the start of the block. - Non-stop mode may be enabled inside the block. */ + Non-stop mode must be enabled inside the block. */ #define SET_RESTORE_ROUND_NOEX(RM) \ SET_RESTORE_ROUND_GENERIC (RM, libc_feholdsetround_noex, \