From patchwork Fri Nov 3 13:16:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gabriel F. T. Gomes" X-Patchwork-Id: 833851 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-86701-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="OQoc9l6L"; 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 3yT2XW3mvlz9sNV for ; Sat, 4 Nov 2017 00:16:27 +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:from:to:subject:date:message-id:mime-version :content-type; q=dns; s=default; b=PtnSAD1l7K80SSd7Xm2aHGjiXLeY7 AaBRR0YMutnLWah+R2a0EVFEteMz3PGBM1LkewomlLVA41F1IWj8WEAW9AA/IXpw i9JKA8wZWBIHAeMLS8a7+jAB8XLQEMy71jxZoORTs4EhN3UdA+t7obPjjvtDnWjG PqXxX2NCcu03Qg= 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=pPR1jeO2HCJmNyxjsSIpNotHBeg=; b=OQo c9l6LPI0/qsXNaDrAyVvt9CnQxKGQg7NjsjZ1enFq4QyLXInzSpdNGoaFtffRIfd 59mjNdDmKXQ4cH02B0+s2VBBsUt3sw0nmLPdxnbFV89h3NWAE5hrj5pp01voIHPA +JwSqaRIFAsTxf+CTj2sEFXgyfF8AGnG+C0oe39Y= Received: (qmail 33514 invoked by alias); 3 Nov 2017 13:16:20 -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 33501 invoked by uid 89); 3 Nov 2017 13:16:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy=choosing, raising, HX-Envelope-From:sk:gabriel, H*F:D*br X-HELO: mo19.mail-out.ovh.net From: "Gabriel F. T. Gomes" To: Subject: [PATCH] Provide a C++ version of iseqsig Date: Fri, 3 Nov 2017 11:16:04 -0200 Message-ID: <20171103131604.14412-1-gabriel@inconstante.eti.br> MIME-Version: 1.0 X-ClientProxiedBy: EX1.emp.local (172.16.2.1) To EX2.emp.local (172.16.2.2) X-Ovh-Tracer-Id: 7789538509376376515 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedttddrgeekgdehtdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecu I would like to receive some feedback on the correctness of this implementation, more specifically on the correctness of any implicit type conversions, which I might have missed. I'm working on a test case in the meantime (I only did some standalone tests outside of glibc test suite). -- 8< -- In C++ mode, __MATH_TG cannot be used for defining iseqsig, because __MATH_TG relies on __builtin_types_compatible_p, which is a C-only builtin. This is true when float128 is provided as an ABI-distinct type from long double. Moreover, the comparison macros from ISO C take two floating-point arguments, which need not have the same type. Choosing what underlying function to call requires evaluating the formats of the arguments, then selecting which is wider. The macro __MATH_EVAL_FMT2 provides this information, however, only the type of the macro expansion is relevant (actually evaluating the expression would be incorrect). This patch provides a C++ version of iseqsig, in which only the type resulted from a call to __MATH_EVAL_FMT2 is used as an additional argument, fmt, to the helper function, __iseqsig_type. This function is overloaded, in compilation-time, to the floating-point type specified by the fmt argument, then calls the appropriate underlying function (the type of the arguments is left unchanged with the help of templates). Tested for powerpc64le and x86_64. [BZ #22377] * math/math.h [C++] (iseqsig): New implementation, which does not rely on __MATH_TG/__builtin_types_compatible_p. --- math/math.h | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/math/math.h b/math/math.h index 326fd8ebe1..4744f9a4c9 100644 --- a/math/math.h +++ b/math/math.h @@ -1152,8 +1152,56 @@ iszero (__T __val) /* Return X == Y but raising "invalid" and setting errno if X or Y is a NaN. */ +# ifndef __cplusplus +# define iseqsig(x, y) \ + __MATH_TG (__MATH_EVAL_FMT2 (x, y), __iseqsig, ((x), (y))) +# else +/* In C++ mode, __MATH_TG cannot be used, because it relies on + __builtin_types_compatible_p, which is a C-only builtin. Moreover, + the comparison macros from ISO C take two floating-point arguments, + which need not have the same type. Choosing what underlying function + to call requires evaluating the formats of the arguments, then + selecting which is wider. The macro __MATH_EVAL_FMT2 provides this + information, however, only the type of the macro expansion is + relevant (actually evaluating the expression would be incorrect). + Thus, the type is used in an additional argument, fmt, to the helper + function, __iseqsig_type, which is overloaded in compilation-time for + the correct floating-point type, then calls the appropriate + underlying function (the type of the arguments is unchanged with the + help of templates). */ +extern "C++" { +template inline int +__iseqsig_type (float fmt, __T1 x, __T2 y) +{ + return __iseqsigf (x, y); +} +template inline int +__iseqsig_type (double fmt, __T1 x, __T2 y) +{ + return __iseqsig (x, y); +} +template inline int +__iseqsig_type (long double fmt, __T1 x, __T2 y) +{ +# ifdef __NO_LONG_DOUBLE_MATH + return __iseqsig (x, y); +# else + return __iseqsigl (x, y); +# endif +} +# if __HAVE_DISTINCT_FLOAT128 +template inline int +__iseqsig_type (_Float128 fmt, __T1 x, __T2 y) +{ + return __iseqsigf128 (x, y); +} +# endif +} +# endif + # define iseqsig(x, y) \ - __MATH_TG (__MATH_EVAL_FMT2 (x, y), __iseqsig, ((x), (y))) + __iseqsig_type (__MATH_EVAL_FMT2 (x, y), x, y) + #endif __END_DECLS