From patchwork Mon Aug 15 10:18:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 523 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6a10:38f:b0:2d5:3c95:9e21 with SMTP id 15csp1274017pxh; Mon, 15 Aug 2022 03:19:54 -0700 (PDT) X-Google-Smtp-Source: AA6agR5s7LJbURZKamajjLL5VooZqEX1PBN+QYlHFRa8uJ529ErbN5UvynOVpW/UVK+LeaqhDGLm X-Received: by 2002:a17:906:4787:b0:734:1ad4:aff0 with SMTP id cw7-20020a170906478700b007341ad4aff0mr9813587ejc.317.1660558794282; Mon, 15 Aug 2022 03:19:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660558794; cv=none; d=google.com; s=arc-20160816; b=g5gArl2Bbb1oPiOUrreww+rMJATQ5iJkEhwVcuAYcYD3U+glP4PJPyTmARtgfhOIJ4 9Iu4MXUEKz7dC90JQfEN6Lw8v/QSWXWMsrYW826uFsI2m6+YKJRI+7CxnJP9TKAZC6mj RFVaUPglHGBtEo+vIcbudB2/oIxn5O1Ox9pnmqTWRsAHUDzuLCHXq9eQNTEfFlHI4ANG biGxNiJgi1lk33iyMSqitvvwDHxzcPcCwIL53dvA+7jCFK4XTHNckFJ0H1WUGdfTowVm 9eNgv9UkgXGDQvuR5Q509CdlwSYlvE0EsMGVjCgCPxQVgTf4OWOpOxHeHrQyvzQltOTY ZJ9Q== 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=jwnv4MsYGdilF5rDZ1e9eWmVWKha450cku+7y4OJQqU=; b=eq+q9QqiM3ENGYH1sh3ydT0vK5BY1/5FfYMpRDBDrgc5F4ZhEZB40nsUfUSWussUAq 4y8FdzDAQmAg36XU1np927GEdCRspIbgZ0H71PMbCbrwQ6gH31fAKdNKgko8hPRUBVa4 4VEQrlZjnQZNPtYl3BGPdNjRC1Ca9MPcTWSOjj6OQyPKtBQ/Kh5pR/nhubIv1NWdlAJv PjeAbX0yIE+i6KcLA7AgHbqug3vWVWXBtjO8ssYT85e7FJSZf+5ee2e8EM0Hpwxc99FZ +KEDBRzy9Bc6La2dlpo5/M0xAO/64CD7G37lO1F7bW1xJVcVEFqHYRP8Ra7itlD2f2Pk Ds3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=stqu5rIh; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id l13-20020a170906794d00b00730a1d46e98si9112793ejo.734.2022.08.15.03.19.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Aug 2022 03:19:54 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=stqu5rIh; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 EFE803858429 for ; Mon, 15 Aug 2022 10:19:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EFE803858429 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1660558793; bh=jwnv4MsYGdilF5rDZ1e9eWmVWKha450cku+7y4OJQqU=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=stqu5rIh0fo9lQUF7L8+lZqUP9mhDbO6RWR0g7u7h/tjQnojzv2H7oVzqXCknQSiO RATdQAYRqGCWas8o0cyiJp27lpLd0CMWg2IAkeNWhFmu/ph4RIDIV5vYWlCT6MLJmV Gd5po9oePCB32h5jAxqZBb4U4SBiKF+Xd/k8dF1g= 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 846143858C2F for ; Mon, 15 Aug 2022 10:18:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 846143858C2F Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-310-DCW9665JNBewcKx00d4uOQ-1; Mon, 15 Aug 2022 06:18:50 -0400 X-MC-Unique: DCW9665JNBewcKx00d4uOQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EA5098037AC; Mon, 15 Aug 2022 10:18:49 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.41]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A242740D296C; Mon, 15 Aug 2022 10:18:49 +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 27FAIlkS1240898 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 15 Aug 2022 12:18:47 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 27FAIkZ01240896; Mon, 15 Aug 2022 12:18:46 +0200 Date: Mon, 15 Aug 2022 12:18:46 +0200 To: FX Subject: [PATCH] fortran: Expand ieee_arithmetic module's ieee_class inline [PR106579] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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?1741222098428660931?= X-GMAIL-MSGID: =?utf-8?q?1741222098428660931?= Hi! The following patch expands IEEE_CLASS inline in the FE, using the __builtin_fpclassify, __builtin_signbit and the new __builtin_issignaling builtins. Bootstrapped/regtested on x86_64-linux, i686-linux, powerpc64le-linux and powerpc64-linux, ok for trunk? 2022-08-15 Jakub Jelinek PR fortran/106579 gcc/fortran/ * f95-lang.cc (gfc_init_builtin_functions): Initialize BUILT_IN_FPCLASSIFY. * libgfortran.h (IEEE_OTHER_VALUE, IEEE_SIGNALING_NAN, IEEE_QUIET_NAN, IEEE_NEGATIVE_INF, IEEE_NEGATIVE_NORMAL, IEEE_NEGATIVE_DENORMAL, IEEE_NEGATIVE_SUBNORMAL, IEEE_NEGATIVE_ZERO, IEEE_POSITIVE_ZERO, IEEE_POSITIVE_DENORMAL, IEEE_POSITIVE_SUBNORMAL, IEEE_POSITIVE_NORMAL, IEEE_POSITIVE_INF): New enum. * trans-intrinsic.cc (conv_intrinsic_ieee_class): New function. (gfc_conv_ieee_arithmetic_function): Handle ieee_class. libgfortran/ * ieee/ieee_helper.c (IEEE_OTHER_VALUE, IEEE_SIGNALING_NAN, IEEE_QUIET_NAN, IEEE_NEGATIVE_INF, IEEE_NEGATIVE_NORMAL, IEEE_NEGATIVE_DENORMAL, IEEE_NEGATIVE_SUBNORMAL, IEEE_NEGATIVE_ZERO, IEEE_POSITIVE_ZERO, IEEE_POSITIVE_DENORMAL, IEEE_POSITIVE_SUBNORMAL, IEEE_POSITIVE_NORMAL, IEEE_POSITIVE_INF): Move to gcc/fortran/libgfortran.h. Jakub --- gcc/fortran/f95-lang.cc.jj 2022-08-12 17:06:33.906598328 +0200 +++ gcc/fortran/f95-lang.cc 2022-08-12 18:39:47.727073699 +0200 @@ -1017,8 +1017,9 @@ gfc_init_builtin_functions (void) "__builtin_issignaling", ATTR_CONST_NOTHROW_LEAF_LIST); gfc_define_builtin ("__builtin_signbit", ftype, BUILT_IN_SIGNBIT, "__builtin_signbit", ATTR_CONST_NOTHROW_LEAF_LIST); + gfc_define_builtin ("__builtin_fpclassify", ftype, BUILT_IN_FPCLASSIFY, + "__builtin_fpclassify", ATTR_CONST_NOTHROW_LEAF_LIST); - ftype = build_function_type (integer_type_node, NULL_TREE); gfc_define_builtin ("__builtin_isless", ftype, BUILT_IN_ISLESS, "__builtin_isless", ATTR_CONST_NOTHROW_LEAF_LIST); gfc_define_builtin ("__builtin_islessequal", ftype, BUILT_IN_ISLESSEQUAL, --- gcc/fortran/libgfortran.h.jj 2022-05-31 11:33:51.550250610 +0200 +++ gcc/fortran/libgfortran.h 2022-08-12 17:22:33.210947170 +0200 @@ -187,3 +187,23 @@ typedef enum BT_ASSUMED, BT_UNION, BT_BOZ } bt; + +/* Enumeration of the possible floating-point types. These values + correspond to the hidden arguments of the IEEE_CLASS_TYPE + derived-type of IEEE_ARITHMETIC. */ + +enum { + IEEE_OTHER_VALUE = 0, + IEEE_SIGNALING_NAN, + IEEE_QUIET_NAN, + IEEE_NEGATIVE_INF, + IEEE_NEGATIVE_NORMAL, + IEEE_NEGATIVE_DENORMAL, + IEEE_NEGATIVE_SUBNORMAL = IEEE_NEGATIVE_DENORMAL, + IEEE_NEGATIVE_ZERO, + IEEE_POSITIVE_ZERO, + IEEE_POSITIVE_DENORMAL, + IEEE_POSITIVE_SUBNORMAL = IEEE_POSITIVE_DENORMAL, + IEEE_POSITIVE_NORMAL, + IEEE_POSITIVE_INF +}; --- gcc/fortran/trans-intrinsic.cc.jj 2022-06-28 13:14:45.322799333 +0200 +++ gcc/fortran/trans-intrinsic.cc 2022-08-12 18:51:28.095927643 +0200 @@ -10013,6 +10013,78 @@ conv_intrinsic_ieee_copy_sign (gfc_se * } +/* Generate code for IEEE_CLASS. */ + +static void +conv_intrinsic_ieee_class (gfc_se *se, gfc_expr *expr) +{ + tree arg, c, t1, t2, t3, t4; + + /* Convert arg, evaluate it only once. */ + conv_ieee_function_args (se, expr, &arg, 1); + arg = gfc_evaluate_now (arg, &se->pre); + + c = build_call_expr_loc (input_location, + builtin_decl_explicit (BUILT_IN_FPCLASSIFY), 6, + build_int_cst (integer_type_node, IEEE_QUIET_NAN), + build_int_cst (integer_type_node, + IEEE_POSITIVE_INF), + build_int_cst (integer_type_node, + IEEE_POSITIVE_NORMAL), + build_int_cst (integer_type_node, + IEEE_POSITIVE_DENORMAL), + build_int_cst (integer_type_node, + IEEE_POSITIVE_ZERO), + arg); + c = gfc_evaluate_now (c, &se->pre); + t1 = fold_build2_loc (input_location, EQ_EXPR, logical_type_node, + c, build_int_cst (integer_type_node, + IEEE_QUIET_NAN)); + t2 = build_call_expr_loc (input_location, + builtin_decl_explicit (BUILT_IN_ISSIGNALING), 1, + arg); + t2 = fold_build2_loc (input_location, NE_EXPR, logical_type_node, + t2, build_zero_cst (TREE_TYPE (t2))); + t1 = fold_build2_loc (input_location, TRUTH_AND_EXPR, + logical_type_node, t1, t2); + t3 = fold_build2_loc (input_location, GE_EXPR, logical_type_node, + c, build_int_cst (integer_type_node, + IEEE_POSITIVE_ZERO)); + t4 = build_call_expr_loc (input_location, + builtin_decl_explicit (BUILT_IN_SIGNBIT), 1, + arg); + t4 = fold_build2_loc (input_location, NE_EXPR, logical_type_node, + t4, build_zero_cst (TREE_TYPE (t4))); + t3 = fold_build2_loc (input_location, TRUTH_AND_EXPR, + logical_type_node, t3, t4); + int s = IEEE_NEGATIVE_ZERO + IEEE_POSITIVE_ZERO; + gcc_assert (IEEE_NEGATIVE_INF == s - IEEE_POSITIVE_INF); + gcc_assert (IEEE_NEGATIVE_NORMAL == s - IEEE_POSITIVE_NORMAL); + gcc_assert (IEEE_NEGATIVE_DENORMAL == s - IEEE_POSITIVE_DENORMAL); + gcc_assert (IEEE_NEGATIVE_SUBNORMAL == s - IEEE_POSITIVE_SUBNORMAL); + gcc_assert (IEEE_NEGATIVE_ZERO == s - IEEE_POSITIVE_ZERO); + t4 = fold_build2_loc (input_location, MINUS_EXPR, TREE_TYPE (c), + build_int_cst (TREE_TYPE (c), s), c); + t3 = fold_build3_loc (input_location, COND_EXPR, TREE_TYPE (c), + t3, t4, c); + t1 = fold_build3_loc (input_location, COND_EXPR, TREE_TYPE (c), t1, + build_int_cst (TREE_TYPE (c), IEEE_SIGNALING_NAN), + t3); + tree type = gfc_typenode_for_spec (&expr->ts); + gcc_assert (TREE_CODE (type) == RECORD_TYPE); + tree field = NULL_TREE; + for (tree f = TYPE_FIELDS (type); f != NULL_TREE; f = DECL_CHAIN (f)) + if (TREE_CODE (f) == FIELD_DECL) + { + gcc_assert (field == NULL_TREE); + field = f; + } + gcc_assert (field); + t1 = fold_convert (TREE_TYPE (field), t1); + se->expr = build_constructor_single (type, field, t1); +} + + /* Generate code for an intrinsic function from the IEEE_ARITHMETIC module. */ @@ -10043,6 +10115,8 @@ gfc_conv_ieee_arithmetic_function (gfc_s conv_intrinsic_ieee_logb_rint (se, expr, BUILT_IN_LOGB); else if (startswith (name, "_gfortran_ieee_rint")) conv_intrinsic_ieee_logb_rint (se, expr, BUILT_IN_RINT); + else if (startswith (name, "ieee_class_") && ISDIGIT (name[11])) + conv_intrinsic_ieee_class (se, expr); else /* It is not among the functions we translate directly. We return false, so a library function call is emitted. */ --- libgfortran/ieee/ieee_helper.c.jj 2022-08-12 13:39:50.285337026 +0200 +++ libgfortran/ieee/ieee_helper.c 2022-08-12 17:22:00.923372705 +0200 @@ -51,26 +51,6 @@ extern int ieee_class_helper_16 (GFC_REA internal_proto(ieee_class_helper_16); #endif -/* Enumeration of the possible floating-point types. These values - correspond to the hidden arguments of the IEEE_CLASS_TYPE - derived-type of IEEE_ARITHMETIC. */ - -enum { - IEEE_OTHER_VALUE = 0, - IEEE_SIGNALING_NAN, - IEEE_QUIET_NAN, - IEEE_NEGATIVE_INF, - IEEE_NEGATIVE_NORMAL, - IEEE_NEGATIVE_DENORMAL, - IEEE_NEGATIVE_SUBNORMAL = IEEE_NEGATIVE_DENORMAL, - IEEE_NEGATIVE_ZERO, - IEEE_POSITIVE_ZERO, - IEEE_POSITIVE_DENORMAL, - IEEE_POSITIVE_SUBNORMAL = IEEE_POSITIVE_DENORMAL, - IEEE_POSITIVE_NORMAL, - IEEE_POSITIVE_INF -}; - #define CLASSMACRO(TYPE) \ int ieee_class_helper_ ## TYPE (GFC_REAL_ ## TYPE *value) \