From patchwork Fri May 23 15:07:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wilco Dijkstra X-Patchwork-Id: 1100 Return-Path: X-Original-To: siddhesh@wilcox.dreamhost.com Delivered-To: siddhesh@wilcox.dreamhost.com Received: from homiemail-mx21.g.dreamhost.com (peon2454.g.dreamhost.com [208.113.200.127]) by wilcox.dreamhost.com (Postfix) with ESMTP id 1F447360073 for ; Fri, 23 May 2014 08:48:54 -0700 (PDT) Received: by homiemail-mx21.g.dreamhost.com (Postfix, from userid 14307373) id A384B1B72852; Fri, 23 May 2014 08:08:22 -0700 (PDT) X-Original-To: glibc@patchwork.siddhesh.in Delivered-To: x14307373@homiemail-mx21.g.dreamhost.com 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 homiemail-mx21.g.dreamhost.com (Postfix) with ESMTPS id 4563A1DA40BB for ; Fri, 23 May 2014 08:08:22 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:mime-version :content-type; q=dns; s=default; b=cTwFKpX+ZFQai4i7jEmh9uFMuzhhe Vgdk3n1rpzJW3GYIyzZyncQml07tw5X9vT+J1lfX/nEAIHjwulUYT9r3S9OrOn/C oCGazkiNWUodVahKVatpBHwVk+qJghJ0kVnUv2ILHkJDIz0ClSkXexkLKH5gWi5y kzQDVwAAU/VV3E= 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:from:to:subject:date:message-id:mime-version :content-type; s=default; bh=spEglArmSIpHjavqMNFa4i5iuNc=; b=eBZ 16ka0ACGK1Be32bxNQ11Xg5tNhXWaYdMuYuS+PjuklyPqEti3P+UaohFZ8Lpyeon zM/TClx2pG8Q5mj1ZQU008M4ZIcez2yyPWfMdAkroMBWYBSE2k5MJBdiPk3mO/BW +2Vqnov9Aud0T7A9RKAmkYr+y/OfnLySxxLL3d9w= Received: (qmail 4707 invoked by alias); 23 May 2014 15:07:51 -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 4634 invoked by uid 89); 23 May 2014 15:07:51 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS, UNSUBSCRIBE_BODY autolearn=no version=3.3.2 X-HELO: service87.mimecast.com From: "Wilco" To: Subject: [PATCH] ARM - Rewrite feupdateenv Date: Fri, 23 May 2014 16:07:43 +0100 Message-ID: <000901cf7698$bf4a2e10$3dde8a30$@com> MIME-Version: 1.0 X-MC-Unique: 114052316074705801 X-DH-Original-To: glibc@patchwork.siddhesh.in Hi, This patch rewrites feupdateenv to improve performance by avoiding unnecessary FPSCR reads/writes and to fix bug 16918 (https://sourceware.org/bugzilla/show_bug.cgi?id=16918). OK? Wilco ChangeLog: 2014-05-23 Wilco * sysdeps/arm/feupdateenv.c (feupdateenv): Rewrite to reduce FPSCR accesses and fix bug 16918. --- sysdeps/arm/feupdateenv.c | 44 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/sysdeps/arm/feupdateenv.c b/sysdeps/arm/feupdateenv.c index 55a1502..d811678 100644 --- a/sysdeps/arm/feupdateenv.c +++ b/sysdeps/arm/feupdateenv.c @@ -18,26 +18,58 @@ . */ #include -#include #include int feupdateenv (const fenv_t *envp) { - fpu_control_t fpscr; + fpu_control_t fpscr, new_fpscr, updated_fpscr; + int excepts; /* Fail if a VFP unit isn't present. */ if (!ARM_HAVE_VFP) return 1; _FPU_GETCW (fpscr); + excepts = fpscr & FE_ALL_EXCEPT; - /* Install new environment. */ - fesetenv (envp); + if ((envp != FE_DFL_ENV) && (envp != FE_NOMASK_ENV)) + { + /* Merge current exception flags with the saved fenv. */ + new_fpscr = envp->__cw | excepts; + + /* Write new FPSCR if different (ignoring NZCV flags). */ + if (((fpscr ^ new_fpscr) & ~_FPU_MASK_NZCV) != 0) + _FPU_SETCW (new_fpscr); + + /* Raise the exceptions if enabled in the new FP state. */ + if (excepts & (new_fpscr >> FE_EXCEPT_SHIFT)) + return feraiseexcept (excepts); + + return 0; + } + + /* Preserve the reserved FPSCR flags. */ + new_fpscr = fpscr & (_FPU_RESERVED | FE_ALL_EXCEPT); + new_fpscr |= (envp == FE_DFL_ENV) ? _FPU_DEFAULT : _FPU_IEEE; + + if (((new_fpscr ^ fpscr) & ~_FPU_MASK_NZCV) != 0) + { + _FPU_SETCW (new_fpscr); + + /* Not all VFP architectures support trapping exceptions, so + test whether the relevant bits were set and fail if not. */ + _FPU_GETCW (updated_fpscr); + + if (new_fpscr & ~updated_fpscr) + return 1; + } + + /* Raise the exceptions if enabled in the new FP state. */ + if (excepts & (new_fpscr >> FE_EXCEPT_SHIFT)) + return feraiseexcept (excepts); - /* Raise the saved exceptions. */ - feraiseexcept (fpscr & FE_ALL_EXCEPT); return 0; } libm_hidden_def (feupdateenv)