From patchwork Tue Nov 8 18:31:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Schwinge X-Patchwork-Id: 17161 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2878674wru; Tue, 8 Nov 2022 10:32:29 -0800 (PST) X-Google-Smtp-Source: AMsMyM6qPbtsd7PF+R31IZIuOWz+7lnZmuL1y9F60wRse6Ogb7VOTiGcTx2pz8/RBoK/5/6XdhQF X-Received: by 2002:aa7:c417:0:b0:463:3f0c:be12 with SMTP id j23-20020aa7c417000000b004633f0cbe12mr49633135edq.35.1667932349301; Tue, 08 Nov 2022 10:32:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667932349; cv=none; d=google.com; s=arc-20160816; b=vZnxzRhZbEntzq3izpqet9c9cNjvdEGyz7Aa9q5Dv5M+rzbClthGC8aJE9ph51HgOb /Uv4pcYOtdDhZ70OTQ69jPATajjemNBBaVLN0/9ocIxvj8onb6xam3WrOcZJLl8aSxlB Y3AzRolyGdT4vMTgFGZv8Qcy4zz0Z+U+O9qqXv7nrMbVPe3NU+4KPSrUVwrXXS8i9OIk v2mr1bPYrhN6T9wr8eBm1pjW+nTLWJ+e5oW4TPfyfS/O3kszQoLKUWvW6AKVuiA83v+Y 5YjaMH2PSenTbiDd1bUsk0zCbWSNeBpzpW6BOeFfGK0L5sKiaivdiRWj0rIqIU20Vb59 IZsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:ironport-sdr:dmarc-filter:delivered-to; bh=mabBk5BibVkEcpI85cyepa7HT6vOdh6i1Z+1nJWY4pc=; b=lONP1Tg1gpulz7Y2UgldgXy4tOrfm7PExqZqp9U/e8ZwVoV2aGEZGx3amVAvajCHY5 MeYF/gnaVdnO0OVQxAcqO2v32NhBjmUQTuSEqu5Rvu8gTfBC7/gtUNRcKc/2iuBDy8ON UhZK1ycg7bTqzp6em09+wabck1H8PCCiOyLsyAKXhMZgz0FPpk8mFvXiJ7Lv6IVY6EwW 2OAwiL0MDoN+Tb6jVNHN2zDqZrW+eYqgJnHUYgUtFcsikDMgxU2POa163KIH2+HX0Nzu COoaExJspYkeys8HYYKSm+WMor8NYzv2+unXCNR60Nv92oreyLj160DyK0yUaNzdlY2c tONQ== ARC-Authentication-Results: i=1; mx.google.com; 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" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id gn2-20020a1709070d0200b007adfc1509afsi15122800ejc.34.2022.11.08.10.32.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 10:32:29 -0800 (PST) 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; 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 332C538582B8 for ; Tue, 8 Nov 2022 18:32:21 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa3.mentor.iphmx.com (esa3.mentor.iphmx.com [68.232.137.180]) by sourceware.org (Postfix) with ESMTPS id 9E0C038582A5; Tue, 8 Nov 2022 18:31:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9E0C038582A5 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="5.96,148,1665475200"; d="scan'208";a="86264110" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 08 Nov 2022 10:31:33 -0800 IronPort-SDR: 5n7v0eKnbIWF2aURMx6bG1xkXg8v2alf6Pf13M/r44SR3apoCjt6WloDAbcgqPZxT6PUGrlKMh YJ5bEACwt/TLoQOGLINiL5HNUM5pEMB/dlGdQJEQTBUWRLD82/r9cfXa7m3XURhfl1mBx/W0sb vLkPwpEC4wWYXbFHjNiPI0lenVe+U9mz3XhXwAQeMPAKotAKDcnexjg0ItbiY1+CpYAtWJ23I1 an37uWGOmjKtVzNPzkdlthRQ7GhJzqVMOQvE+gcudvu6VPSrCiZitLF4itKXOIKeq9QQguQr1z fVQ= From: Thomas Schwinge To: CC: , , , , , , Thomas Schwinge Subject: [newlib] Generally make all 'long double complex' methods available in Date: Tue, 8 Nov 2022 19:31:08 +0100 Message-ID: <20221108183108.1233500-1-thomas@codesourcery.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: SVR-IES-MBX-08.mgc.mentorg.com (139.181.222.8) To svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP 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: , 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?1748953830724918092?= X-GMAIL-MSGID: =?utf-8?q?1748953830724918092?= ..., not just '#if defined(__CYGWIN__)'. (Exception: 'clog10l' which currently indeed is for Cygwin only.) This completes 2017-07-05 commit be3ca3947402827aa52709e677369bc7ad30aa1d "Fixed warnings for some long double complex methods" after Aditya Upadhyay's work on importing "Long double complex methods" from NetBSD. For example, this changes GCC/nvptx libgfortran 'configure' output as follows: [...] checking for ccosf... yes checking for ccos... yes checking for ccosl... [-no-]{+yes+} [...] ..., and correspondingly GCC/nvptx 'nvptx-none/libgfortran/config.h' as follows: [...] /* Define to 1 if you have the `ccosl' function. */ -/* #undef HAVE_CCOSL */ +#define HAVE_CCOSL 1 [...] Similarly for 'ccoshl', 'cexpl', 'cpowl', 'csinl', 'csinhl', 'ctanl', 'ctanhl', 'cacoshl', 'cacosl', 'casinhl', 'catanhl'. ('conjl', 'cprojl' are not currently being used in libgfortran.) This in turn simplifies GCC/nvptx 'libgfortran/intrinsics/c99_functions.c' compilation such that this files doesn't have to provide its own "Implementation of various C99 functions" for those, when in fact they're available in newlib libm. --- A few more words on why this is relevant for GCC. For example, 'cexpl' usually is provided by libm, but if it isn't, the open-coded replacement function in 'libgfortran/intrinsics/c99_functions.c' is effective if it holds that 'defined(HAVE_COSL) && defined(HAVE_SINL) && defined(HAVE_EXPL)': long double complex cexpl (long double complex z) { long double a, b; long double complex v; a = REALPART (z); b = IMAGPART (z); COMPLEX_ASSIGN (v, cosl (b), sinl (b)); return expl (a) * v; } This replacement code is active for current GCC/nvptx (... if no longer compiling GCC/nvptx libgfortran in "minimal" mode, 'LIBGFOR_MINIMAL', which I'm currently working on). Comparing the preceeding to the 'c99_functions.c.188t.sincos' dump, we see for that function: __attribute__((nothrow, leaf, const)) complex long double cexpl (complex long double z) { long double b; long double a; long double _1; long double _2; long double _4; long double _5; long double _11; + complex long double sincostmp_13; [local count: 1073741824]: a_7 = REALPART_EXPR ; b_8 = IMAGPART_EXPR ; - _1 = cosl (b_8); - _2 = sinl (b_8); + sincostmp_13 = __builtin_cexpil (b_8); + _1 = REALPART_EXPR ; + _2 = IMAGPART_EXPR ; _11 = expl (a_7); _4 = _1 * _11; _5 = _2 * _11; REALPART_EXPR <> = _4; IMAGPART_EXPR <> = _5; return ; } That is, the 'cosl (b)', 'sinl (b)' sequence is replaced by '__builtin_cexpil'. That '__builtin_cexpil' is then later mapped back into: 'cexpl'. We've now got an infinitely-recursive 'cexpl' replacement function, "implemented via itself"; GCC/nvptx libgfortran assumes there is no 'cexpl' in libm, whereas this 'sincos' transformation does assume that there is. (..., which looks like an additional bug on its own.) At the PTX-level, this leads to the following: [...] // BEGIN GLOBAL FUNCTION DECL: cexpl .visible .func cexpl (.param.u64 %in_ar0, .param.f64 %in_ar1, .param.f64 %in_ar2); // BEGIN GLOBAL FUNCTION DEF: cexpl .visible .func cexpl (.param.u64 %in_ar0, .param.f64 %in_ar1, .param.f64 %in_ar2) { [...] call cexpl, (%out_arg1, %out_arg2, %out_arg3); [...] ret; } [...] // BEGIN GLOBAL FUNCTION DECL: cexpl .extern .func cexpl (.param.u64 %in_ar0, .param.f64 %in_ar1, .param.f64 %in_ar2); [...] We see the '.visible .func cexpl' declaration and definition for the libgfortran replacement function and in the same compilation unit also the '.extern .func cexpl' declaration that implicitly gets introduced via the 'sincos' transformation (via the GCC/nvptx back end emitting an explicit declaration of any function referenced), and 'ptxas' then (rightfully so) complains about that mismatch: ptxas c99_functions.o, line 35; error : Inconsistent redefinition of variable 'cexpl' ptxas fatal : Ptx assembly aborted due to errors nvptx-as: ptxas returned 255 exit status make[2]: *** [c99_functions.lo] Error 1 --- newlib/libc/include/complex.h | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) -- 2.25.1 ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955 diff --git a/newlib/libc/include/complex.h b/newlib/libc/include/complex.h index 0a3ea97ed..ad3028e4c 100644 --- a/newlib/libc/include/complex.h +++ b/newlib/libc/include/complex.h @@ -20,6 +20,7 @@ __BEGIN_DECLS /* 7.3.5.1 The cacos functions */ double complex cacos(double complex); float complex cacosf(float complex); +long double complex cacosl(long double complex); /* 7.3.5.2 The casin functions */ double complex casin(double complex); @@ -34,44 +35,54 @@ long double complex catanl(long double complex); /* 7.3.5.1 The ccos functions */ double complex ccos(double complex); float complex ccosf(float complex); +long double complex ccosl(long double complex); /* 7.3.5.1 The csin functions */ double complex csin(double complex); float complex csinf(float complex); +long double complex csinl(long double complex); /* 7.3.5.1 The ctan functions */ double complex ctan(double complex); float complex ctanf(float complex); +long double complex ctanl(long double complex); /* 7.3.6 Hyperbolic functions */ /* 7.3.6.1 The cacosh functions */ double complex cacosh(double complex); float complex cacoshf(float complex); +long double complex cacoshl(long double complex); /* 7.3.6.2 The casinh functions */ double complex casinh(double complex); float complex casinhf(float complex); +long double complex casinhl(long double complex); /* 7.3.6.3 The catanh functions */ double complex catanh(double complex); float complex catanhf(float complex); +long double complex catanhl(long double complex); /* 7.3.6.4 The ccosh functions */ double complex ccosh(double complex); float complex ccoshf(float complex); +long double complex ccoshl(long double complex); /* 7.3.6.5 The csinh functions */ double complex csinh(double complex); float complex csinhf(float complex); +long double complex csinhl(long double complex); /* 7.3.6.6 The ctanh functions */ double complex ctanh(double complex); float complex ctanhf(float complex); +long double complex ctanhl(long double complex); /* 7.3.7 Exponential and logarithmic functions */ /* 7.3.7.1 The cexp functions */ double complex cexp(double complex); float complex cexpf(float complex); +long double complex cexpl(long double complex); /* 7.3.7.2 The clog functions */ double complex clog(double complex); @@ -93,6 +104,7 @@ float cabsf(float complex) ; /* 7.3.8.2 The cpow functions */ double complex cpow(double complex, double complex); float complex cpowf(float complex, float complex); +long double complex cpowl(long double complex, long double complex); /* 7.3.8.3 The csqrt functions */ double complex csqrt(double complex); @@ -113,10 +125,12 @@ long double cimagl(long double complex); /* 7.3.9.3 The conj functions */ double complex conj(double complex); float complex conjf(float complex); +long double complex conjl(long double complex); /* 7.3.9.4 The cproj functions */ double complex cproj(double complex); float complex cprojf(float complex); +long double complex cprojl(long double complex); /* 7.3.9.5 The creal functions */ double creal(double complex); @@ -126,27 +140,10 @@ long double creall(long double complex); #if __GNU_VISIBLE double complex clog10(double complex); float complex clog10f(float complex); -#endif - -#if defined(__CYGWIN__) -long double complex cacosl(long double complex); -long double complex ccosl(long double complex); -long double complex csinl(long double complex); -long double complex ctanl(long double complex); -long double complex cacoshl(long double complex); -long double complex casinhl(long double complex); -long double complex catanhl(long double complex); -long double complex ccoshl(long double complex); -long double complex csinhl(long double complex); -long double complex ctanhl(long double complex); -long double complex cexpl(long double complex); -long double complex cpowl(long double complex, long double complex); -long double complex conjl(long double complex); -long double complex cprojl(long double complex); -#if __GNU_VISIBLE +# if defined(__CYGWIN__) long double complex clog10l(long double complex); +# endif #endif -#endif /* __CYGWIN__ */ __END_DECLS