From patchwork Tue Jul 23 09:55:24 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 261020 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 440AE2C00C1 for ; Tue, 23 Jul 2013 19:55:40 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:cc:content-type; q=dns; s=default; b=iaho8lgzfir0E2DfIWJmboh+UTkVOxMDTW72nrXm+Ia CBc/CpZvAthlRtZXCOS1KCqXOXgqqz+XZ7KFO3f/tTcYH0jutLAke1GwWJZa66oo 7ai3v3l5PfUAlErmObIf4NONQMk2PHFwD2rbgTk69j2EKqvCn4QQgSl7D9Abi7Bg = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:cc:content-type; s=default; bh=lRgsRG96wqa5QjOJqBOoXNr2pP4=; b=w8BZGPOSElyqJf/FF +dLyzrp3YvOCIldcMdY6Zsvn9/T11QReEtW4T5xpEmUFVnnBYyp/3mT7cqJeLwGr xvLhbZ4cRghtTj1jdeALPpcnTvfeBgOmmKxsZu7EquO94Xta372CWDWWx/aXdRrh kmBR1qp48ffUMkFSBXr5Rg6GZQ= Received: (qmail 15391 invoked by alias); 23 Jul 2013 09:55:33 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 15357 invoked by uid 89); 23 Jul 2013 09:55:33 -0000 X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, RDNS_NONE, SPF_PASS, TW_MX, TW_XC, TW_ZJ autolearn=no version=3.3.1 X-Spam-User: qpsmtpd, 2 recipients Received: from Unknown (HELO mail-ob0-f173.google.com) (209.85.214.173) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Tue, 23 Jul 2013 09:55:32 +0000 Received: by mail-ob0-f173.google.com with SMTP id er7so1130344obc.32 for ; Tue, 23 Jul 2013 02:55:24 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.182.130.228 with SMTP id oh4mr24186925obb.38.1374573324577; Tue, 23 Jul 2013 02:55:24 -0700 (PDT) Received: by 10.182.92.202 with HTTP; Tue, 23 Jul 2013 02:55:24 -0700 (PDT) Date: Tue, 23 Jul 2013 11:55:24 +0200 Message-ID: Subject: [PATCH, libfortran]: Committed: Read rounding mode from SSE mxcsr register on x86_64. From: Uros Bizjak To: "gcc-patches@gcc.gnu.org" Cc: Fortran List , Tobias Burnus X-Virus-Found: No Hello! On x86_64, we can look into SSE mxcsr register to determine rounding mode. 2013-07-23 Uros Bizjak * config/fpu-387.h (get_fpu_rounding_mode): Read rounding mode from SSE mxcsr register on x86_64. Tested on x86_64-pc-linux-gnu {,-m32} and committed to mainline svn. BTW. gfortran.dg/round_4.f90 test will fail on glibc < 2.17 due to glibc bug 3479 [1], "Incorrect rounding in strtod()". [1] http://sourceware.org/bugzilla/show_bug.cgi?id=3479 Uros. Index: config/fpu-387.h =================================================================== --- config/fpu-387.h (revision 201156) +++ config/fpu-387.h (working copy) @@ -102,11 +102,11 @@ has_sse (void) /* i387 rounding modes. */ #define _FPU_RC_NEAREST 0x0 -#define _FPU_RC_DOWN 0x400 -#define _FPU_RC_UP 0x800 -#define _FPU_RC_ZERO 0xc00 +#define _FPU_RC_DOWN 0x1 +#define _FPU_RC_UP 0x2 +#define _FPU_RC_ZERO 0x3 -#define _FPU_RC_MASK 0xc00 +#define _FPU_RC_MASK 0x3 void @@ -202,8 +202,9 @@ set_fpu_rounding_mode (int round) __asm__ __volatile__ ("fnstcw\t%0" : "=m" (cw)); - cw &= ~_FPU_RC_MASK; - cw |= round_mode; + /* The x87 round control bits are shifted by 10 bits. */ + cw &= ~(_FPU_RC_MASK << 10); + cw |= round_mode << 10; __asm__ __volatile__ ("fldcw\t%0" : : "m" (cw)); @@ -213,9 +214,9 @@ set_fpu_rounding_mode (int round) __asm__ __volatile__ ("%vstmxcsr\t%0" : "=m" (cw_sse)); - /* The SSE round control bits are shifted by 3 bits. */ - cw_sse &= ~(_FPU_RC_MASK << 3); - cw_sse |= round_mode << 3; + /* The SSE round control bits are shifted by 13 bits. */ + cw_sse &= ~(_FPU_RC_MASK << 13); + cw_sse |= round_mode << 13; __asm__ __volatile__ ("%vldmxcsr\t%0" : : "m" (cw_sse)); } @@ -224,13 +225,27 @@ set_fpu_rounding_mode (int round) int get_fpu_rounding_mode (void) { + int round_mode; + +#ifdef __x86_64__ + unsigned int cw; + + __asm__ __volatile__ ("%vstmxcsr\t%0" : "=m" (cw)); + + /* The SSE round control bits are shifted by 13 bits. */ + round_mode = cw >> 13; +#else unsigned short cw; __asm__ __volatile__ ("fnstcw\t%0" : "=m" (cw)); - cw &= _FPU_RC_MASK; + /* The x87 round control bits are shifted by 10 bits. */ + round_mode = cw >> 10; +#endif - switch (cw) + round_mode &= _FPU_RC_MASK; + + switch (round_mode) { case _FPU_RC_NEAREST: return GFC_FPE_TONEAREST;