From patchwork Mon Aug 15 10:16:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 522 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6a10:38f:b0:2d5:3c95:9e21 with SMTP id 15csp1272930pxh; Mon, 15 Aug 2022 03:17:19 -0700 (PDT) X-Google-Smtp-Source: AA6agR5FmpKKjZ/mMnlCFwU562prAzaYDTdlDtiV1WCK3vO+L0yrJRfK+nqQHdirDr76voflkv6r X-Received: by 2002:a05:6402:51d4:b0:43d:9c8e:2617 with SMTP id r20-20020a05640251d400b0043d9c8e2617mr14575973edd.146.1660558639775; Mon, 15 Aug 2022 03:17:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660558639; cv=none; d=google.com; s=arc-20160816; b=GRDZym6i56/RZ0XhJOfgBYxdkArVY0S4CC9fk8y035y9gZk1rdtJizR3lmwVCiWJPW CVNyYDlB2NietPoz9Jbt7gAoTKEdG4nl+3kk7pske/aRxr6x1AvNmpEIhRnvxMj+5BG+ sKO9r/D+nuOrnCdoCstp8LxObkVSffCmZpm6I4ZbvxDtYa/a2YMf0rN0xEe/f6N3OTzL 4G1axfM5LKM5qN2z4C/hhzMW5eMLP2wEaZxPB/mZpSKK2np4rxHBQhAeHM8wEiU1T80d zRovKQW8V8WBkh3TltbrQWlVtXcj4DIDSCRTQx6a7fNxyMJKxcodj5g46eFOa0vL70KM 2ptA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=eK+PPjWTYGUx5UW7lWyUKGumBtthk5382CwAGnB2R4w=; b=tizi+u0wblMGQ54H7+Oa1qM/ZSyexVw8Igl4Y/Z6i81xiX/tOhf8E09tvBCxSpJOp5 6rxBfKjnvzNJOPoNPVqAN20FZCtZ0/XJyBlK8W4N/ooyqP5xm35mdJBXSvQ0k32FQtWa q7YlwUvXXB7DzZMzUdA30bACZsF/cOh1rxUUuf2gHm0Rwd9eLtyFwzlbws1AtY3C5vs/ cB/mnN4be/YwqQvwl7fg21hahHBOvd6u+akziFl9s3dqJ3HWoV5sKkOaB8yQVKkQpnDe EICPyo7e+wlex6V/b+EHOhEzTMMpyLVZu8WylPOXRr9o32t9Zn0xSgq4TsyB/GTk1LqF zaaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=BxRoDjQz; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id g26-20020aa7d1da000000b0043be1f48544si6776696edp.130.2022.08.15.03.17.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Aug 2022 03:17:19 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=BxRoDjQz; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9365038582A4 for ; Mon, 15 Aug 2022 10:17:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9365038582A4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1660558638; bh=eK+PPjWTYGUx5UW7lWyUKGumBtthk5382CwAGnB2R4w=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=BxRoDjQzd72L+IYeWuRFOGynsdUYhmD4QzedS5LWCSrJkpd04bsE4+aEEd42D25Og we2R5UgHSURwHRvvuFZnigN38u3ZerHs966NN3aahkdgYYJhICG9asuZRw3tjQz+c/ vAeZ18hiQLXnZ5GHTyMT+JN4JOkyb6FsNdbFtHBE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 8CC1E3858D32 for ; Mon, 15 Aug 2022 10:16:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8CC1E3858D32 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-164-T0YQtAfcMAWqTss1IgkSFQ-1; Mon, 15 Aug 2022 06:16:34 -0400 X-MC-Unique: T0YQtAfcMAWqTss1IgkSFQ-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CA93B29AA2FB; Mon, 15 Aug 2022 10:16:33 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.41]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8A1AA492C3B; Mon, 15 Aug 2022 10:16:33 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 27FAGV0f1240879 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 15 Aug 2022 12:16:31 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 27FAGUJ01240878; Mon, 15 Aug 2022 12:16:30 +0200 Date: Mon, 15 Aug 2022 12:16:30 +0200 To: FX Subject: [PATCH] libgfortran: Use __builtin_issignaling in libgfortran Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1741221936623020802?= X-GMAIL-MSGID: =?utf-8?q?1741221936623020802?= Hi! The following patch makes use of the new __builtin_issignaling, so it no longer needs the fallback implementation and can use the builtin even where glibc provides the macro. Bootstrapped/regtested on x86_64-linux, i686-linux, powerpc64le-linux and powerpc64le-linux, ok for trunk? 2022-08-15 Jakub Jelinek * ieee/ieee_helper.c: Don't include issignaling_fallback.h. (CLASSMACRO): Use __builtin_issignaling instead of issignaling. * ieee/issignaling_fallback.h: Removed. Jakub --- libgfortran/ieee/ieee_helper.c.jj 2022-06-27 15:34:47.111928150 +0200 +++ libgfortran/ieee/ieee_helper.c 2022-08-12 13:21:00.922306862 +0200 @@ -26,13 +26,6 @@ see the files COPYING3 and COPYING.RUNTI #include "libgfortran.h" -/* Check support for issignaling macro. If not, we include our own - fallback implementation. */ -#ifndef issignaling -# include "issignaling_fallback.h" -#endif - - /* Prototypes. */ extern int ieee_class_helper_4 (GFC_REAL_4 *); @@ -94,7 +87,7 @@ enum { \ if (res == IEEE_QUIET_NAN) \ { \ - if (issignaling (*value)) \ + if (__builtin_issignaling (*value)) \ return IEEE_SIGNALING_NAN; \ else \ return IEEE_QUIET_NAN; \ --- libgfortran/ieee/issignaling_fallback.h.jj 2022-06-28 13:14:45.332799201 +0200 +++ libgfortran/ieee/issignaling_fallback.h 2022-08-12 13:20:17.784877531 +0200 @@ -1,251 +0,0 @@ -/* Fallback implementation of issignaling macro. - Copyright (C) 2022 Free Software Foundation, Inc. - Contributed by Francois-Xavier Coudert - -This file is part of the GNU Fortran runtime library (libgfortran). - -Libgfortran is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public -License as published by the Free Software Foundation; either -version 3 of the License, or (at your option) any later version. - -Libgfortran 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 General Public License for more details. - -Under Section 7 of GPL version 3, you are granted additional -permissions described in the GCC Runtime Library Exception, version -3.1, as published by the Free Software Foundation. - -You should have received a copy of the GNU General Public License and -a copy of the GCC Runtime Library Exception along with this program; -see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -. */ - -#include "libgfortran.h" - -/* This header provides an implementation of the type-generic issignaling macro. - Some points of note: - - - This header is only included if the issignaling macro is not defined. - - All targets for which Fortran IEEE modules are supported currently have - the high-order bit of the NaN mantissa clear for signaling (and set - for quiet), as recommended by IEEE. - - We use the __*_IS_IEC_60559__ macros to make sure we only deal with formats - we know. For other floating-point formats, we consider all NaNs as quiet. - - */ - -typedef union -{ - float value; - uint32_t word; -} ieee_float_shape_type; - -static inline int -__issignalingf (float x) -{ -#if __FLT_IS_IEC_60559__ - uint32_t xi; - ieee_float_shape_type u; - - u.value = x; - xi = u.word; - - xi ^= 0x00400000; - return (xi & 0x7fffffff) > 0x7fc00000; -#else - return 0; -#endif -} - - -typedef union -{ - double value; - uint64_t word; -} ieee_double_shape_type; - -static inline int -__issignaling (double x) -{ -#if __DBL_IS_IEC_60559__ - ieee_double_shape_type u; - uint64_t xi; - - u.value = x; - xi = u.word; - - xi ^= UINT64_C (0x0008000000000000); - return (xi & UINT64_C (0x7fffffffffffffff)) > UINT64_C (0x7ff8000000000000); -#else - return 0; -#endif -} - - -#if __LDBL_DIG__ == __DBL_DIG__ - -/* Long double is the same as double. */ -static inline int -__issignalingl (long double x) -{ - return __issignaling (x); -} - -#elif (__LDBL_DIG__ == 18) && __LDBL_IS_IEC_60559__ - -/* Long double is x86 extended type. */ - -typedef union -{ - long double value; - struct - { -#if __FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__ - int sign_exponent:16; - unsigned int empty:16; - uint32_t msw; - uint32_t lsw; -#elif __FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__ - uint32_t lsw; - uint32_t msw; - int sign_exponent:16; - unsigned int empty:16; -#endif - } parts; -} ieee_long_double_shape_type; - -static inline int -__issignalingl (long double x) -{ - int ret; - uint32_t exi, hxi, lxi; - ieee_long_double_shape_type u; - - u.value = x; - exi = u.parts.sign_exponent; - hxi = u.parts.msw; - lxi = u.parts.lsw; - - /* Pseudo numbers on x86 are always signaling. */ - ret = (exi & 0x7fff) && ((hxi & 0x80000000) == 0); - - hxi ^= 0x40000000; - hxi |= (lxi | -lxi) >> 31; - return ret || (((exi & 0x7fff) == 0x7fff) && (hxi > 0xc0000000)); -} - -#elif (__LDBL_DIG__ == 31) - -/* Long double is 128-bit IBM extended type. */ - -static inline int -__issignalingl (long double x) -{ - union { long double value; double parts[2]; } u; - - u.value = x; - return __issignaling (u.parts[0]); -} - -#elif (__LDBL_DIG__ == 33) && __LDBL_IS_IEC_60559__ - -/* Long double is 128-bit type. */ - -typedef union -{ - long double value; - struct - { -#if __FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__ - uint64_t msw; - uint64_t lsw; -#elif __FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__ - uint64_t lsw; - uint64_t msw; -#endif - } parts64; -} ieee854_long_double_shape_type; - -static inline int -__issignalingl (long double x) -{ - uint64_t hxi, lxi; - ieee854_long_double_shape_type u; - - u.value = x; - hxi = u.parts64.msw; - lxi = u.parts64.lsw; - - hxi ^= UINT64_C (0x0000800000000000); - hxi |= (lxi | -lxi) >> 63; - return (hxi & UINT64_C (0x7fffffffffffffff)) > UINT64_C (0x7fff800000000000); -} - -#else - -static inline int -__issignalingl (long double x) -{ - return 0; -} - -#endif - - -#if defined(GFC_REAL_16_IS_FLOAT128) - -/* We have a _Float128 type. */ - -typedef union -{ - _Float128 value; - struct - { -#if __FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__ - uint64_t msw; - uint64_t lsw; -#elif __FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__ - uint64_t lsw; - uint64_t msw; -#endif - } parts64; -} ieee854_float128_shape_type; - -static inline int -__issignalingf128 (_Float128 x) -{ - uint64_t hxi, lxi; - ieee854_float128_shape_type u; - - u.value = x; - hxi = u.parts64.msw; - lxi = u.parts64.lsw; - - hxi ^= UINT64_C (0x0000800000000000); - hxi |= (lxi | -lxi) >> 63; - return (hxi & UINT64_C (0x7fffffffffffffff)) > UINT64_C (0x7fff800000000000); -} - -#endif - - -/* Define the type-generic macro based on the functions above. */ - -#if defined(GFC_REAL_16_IS_FLOAT128) -# define issignaling(X) \ - _Generic ((X), \ - _Float128: __issignalingf128, \ - float: __issignalingf, \ - double: __issignaling, \ - long double: __issignalingl)(X) -#else -# define issignaling(X) \ - _Generic ((X), \ - float: __issignalingf, \ - double: __issignaling, \ - long double: __issignalingl)(X) -#endif -