Message ID | 20250131211421.969500-1-ykolerov@synopsys.com |
---|---|
State | New |
Headers |
Return-Path: <newlib-bounces~patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 841253858D37 for <patchwork@sourceware.org>; Fri, 31 Jan 2025 21:15:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 841253858D37 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=synopsys.com header.i=@synopsys.com header.a=rsa-sha256 header.s=pfptdkimsnps header.b=hzZ3NHjj; dkim=pass (2048-bit key, unprotected) header.d=synopsys.com header.i=@synopsys.com header.a=rsa-sha256 header.s=mail header.b=Wb81bIiJ X-Original-To: newlib@sourceware.org Delivered-To: newlib@sourceware.org Received: from mx0b-00230701.pphosted.com (mx0b-00230701.pphosted.com [148.163.158.9]) by sourceware.org (Postfix) with ESMTPS id D57C73858D37 for <newlib@sourceware.org>; Fri, 31 Jan 2025 21:14:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D57C73858D37 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=synopsys.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=synopsys.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D57C73858D37 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=148.163.158.9 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1738358084; cv=none; b=Tcgy5V4gIdAMlyc9IQmIQmueZKWO+pIyNTa0ge172ZttkwFb6hSQTcHP6U5aT2PgSUMceVLH3LpzLOLFZcnRpa+oZRBY93fTeRwTumWeh0Ltr1vKfX0l4zlp96HJXhj/KkcWZ/ACgL01N1WQyvyXlA1SRkLXFUgM0acKSSc3Vtg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1738358084; c=relaxed/simple; bh=X1XWHIVVlzpQCOn8B3HoJniVLcG/BouNQAN2kDIcu6k=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=iZc8U4Ll1pMKs8koifZYI1GOoygr2n8iSNlZAFePXl/0yviU9lVTuwmVEVeIC6eSX5p42Xf7niyUCl3MuyBJ87AbnECgU3Y9/JVoKMI4ktMCmR1UnWDNvTp8ViA6VZGgxHNPYDX04xXCfBt02RFnLFEwVOVvd2sCpudkAGkB+as= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D57C73858D37 Received: from pps.filterd (m0098572.ppops.net [127.0.0.1]) by mx0b-00230701.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50VJjYto027469 for <newlib@sourceware.org>; Fri, 31 Jan 2025 13:14:43 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=synopsys.com; h= cc:content-transfer-encoding:date:from:message-id:mime-version :subject:to; s=pfptdkimsnps; bh=mUp6+oFTpRS98fIh1CfEvE1M9tqZnkXK QXTFGMVBhz4=; b=hzZ3NHjj/SsB+1VlwWYaK1/ihNSyv/6mOYUGhPAhlhg5he9Y 6bUy131wkKbKB5ovOSWs4dufL5YCofluo+6bGKyvGIeuha6Z+epCOwTre263Ovjp FPwaoCDS4RPOpZdUPWvOZPW9ez613XjUBJhkZB9OMYCc0dwSRPLyw4DGT4tNFSsv 51BFmBSOTdETKmBvBmStqaM2V5XC11CfAwJoy/BCL2zXw70n6/mf2AFqwA6RVZ8q hYgCgLOcV6qSHBNK+4YK5MKwS7YqvcZPERE7BiQsXTgrTVfQhI7+XyuL8vLaZV7Z nkXj6Ke/6y95N9m/cblnQLJdjIHy4rqiE0yd3w== Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.73.133]) by mx0b-00230701.pphosted.com (PPS) with ESMTPS id 44h4xv0bbs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for <newlib@sourceware.org>; Fri, 31 Jan 2025 13:14:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1738358082; bh=X1XWHIVVlzpQCOn8B3HoJniVLcG/BouNQAN2kDIcu6k=; h=From:To:Cc:Subject:Date:From; b=Wb81bIiJuXFkruZ41oPf4FSH07uQpSgIePE8Y8D10ngKPMdWKWRZbw19jijvRbevG rYa5BpjBhSc7ucZrJZGirXE4IW5pHTsEfWK+xJOYspwDw3xsGxfzpntkov5QjfYcC8 e2WC44JHo3qOkA0ooyj5RR1ASS+h/UuhDZOagyu8UFWTWrNbicLuU1jjlFBjJjKp8N DgqbvXg3reNsvQZZ/faB3i/drMi+1c+2Z6nCheFp9dgWQrnLSLRerHEowV/QeShKnW Ld9nXVrdgSxm66+2O2dIuCPNBqiZ0R2dtSiwBo6+Vl6tzo9+/GjFSWjUCW4O08QdO4 AkwoxBsfXw5/g== Received: from mailhost.synopsys.com (eudc-mailhost2.synopsys.com [10.213.161.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) client-signature RSA-PSS (2048 bits)) (Client CN "mailhost.synopsys.com", Issuer "SNPSica2" (verified OK)) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 4D51140353 for <newlib@sourceware.org>; Fri, 31 Jan 2025 21:14:42 +0000 (UTC) Received: from SNPS-pZ8jIRJUHe.internal.synopsys.com (snps-pz8jirjuhe.internal.synopsys.com [10.213.60.246]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) by mailhost.synopsys.com (Postfix) with ESMTPSA id BE218C0B3A; Fri, 31 Jan 2025 21:14:40 +0000 (UTC) X-SNPS-Relay: synopsys.com From: Yuriy Kolerov <Yuriy.Kolerov@synopsys.com> To: newlib@sourceware.org Cc: Yuriy Kolerov <Yuriy.Kolerov@synopsys.com> Subject: [PATCH] libm: Add CMPLX, CMPLXF and CMPLXL macros Date: Fri, 31 Jan 2025 23:14:21 +0200 Message-Id: <20250131211421.969500-1-ykolerov@synopsys.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-GUID: w9CMiSOOe0aeX8p_kMCpAj1PhWa3MWec X-Proofpoint-ORIG-GUID: w9CMiSOOe0aeX8p_kMCpAj1PhWa3MWec X-Authority-Analysis: v=2.4 cv=EdIyQOmC c=1 sm=1 tr=0 ts=679d3d43 cx=c_pps a=8EbXvwLXkpGsT4ql/pYRAw==:117 a=8EbXvwLXkpGsT4ql/pYRAw==:17 a=VdSt8ZQiCzkA:10 a=qPHU084jO2kA:10 a=NEAV23lmAAAA:8 a=MhnL__LWAAAA:8 a=jIQo8A4GAAAA:8 a=bxvLZ55A8ERZbdaNwzYA:9 a=DArMNfZabhNmbrQIurc0:22 a=Lf5xNeLK5dgiOs8hzIjU:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-31_08,2025-01-31_02,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_active_cloned_notspam policy=outbound_active_cloned score=0 priorityscore=1501 bulkscore=0 mlxlogscore=883 clxscore=1011 mlxscore=0 malwarescore=0 suspectscore=0 lowpriorityscore=0 adultscore=0 spamscore=0 phishscore=0 impostorscore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2501170000 definitions=main-2501310161 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP 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: newlib@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Newlib mailing list <newlib.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/newlib>, <mailto:newlib-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/newlib/> List-Post: <mailto:newlib@sourceware.org> List-Help: <mailto:newlib-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/newlib>, <mailto:newlib-request@sourceware.org?subject=subscribe> Errors-To: newlib-bounces~patchwork=sourceware.org@sourceware.org |
Series |
libm: Add CMPLX, CMPLXF and CMPLXL macros
|
|
Commit Message
Yuriy Kolerov
Jan. 31, 2025, 9:14 p.m. UTC
This is a backport of the same patch from Picolibc repository with all fixes: https://github.com/picolibc/picolibc/commit/197657202913 libm: Add CMPLX, CMPLXF and CMPLXL macros These use __builtin_complex if available, otherwise they open code as suggested by the C standard. Signed-off-by: Keith Packard <keithp@keithp.com> https://github.com/picolibc/picolibc/commit/a00c65d42760 complex.h: Add type casting to CMPLX, CMPLXF and CMPLXL macros Adding type casting to CMPLX, CMPLXF and CMPLXL macros to ensure type safety constructing complex numbers using __builtin_complex function. The real and imaginary parts passed to __builtin_complex function are explicity cast to double, float and long double respectively, to match the types expected by the function. This change improves code clarity and prevents unintended type conversions when using macros to construct complex numbers. Signed-off-by: Mostafa Salman <mostafas@synopsys.com> Signed-off-by: Yuriy Kolerov <ykolerov@synopsys.com> --- newlib/libc/include/complex.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)
Comments
Hi Yuriy, On Jan 31 23:14, Yuriy Kolerov wrote: > This is a backport of the same patch from Picolibc repository > with all fixes: > > https://github.com/picolibc/picolibc/commit/197657202913 > > libm: Add CMPLX, CMPLXF and CMPLXL macros > > These use __builtin_complex if available, otherwise they open > code as suggested by the C standard. > > Signed-off-by: Keith Packard <keithp@keithp.com> > > https://github.com/picolibc/picolibc/commit/a00c65d42760 > > complex.h: Add type casting to CMPLX, CMPLXF and CMPLXL macros > > Adding type casting to CMPLX, CMPLXF and CMPLXL macros to > ensure type safety constructing complex numbers using > __builtin_complex function. The real and imaginary parts > passed to __builtin_complex function are explicity cast to > double, float and long double respectively, to match the > types expected by the function. > > This change improves code clarity and prevents unintended > type conversions when using macros to construct complex > numbers. > > Signed-off-by: Mostafa Salman <mostafas@synopsys.com> > > Signed-off-by: Yuriy Kolerov <ykolerov@synopsys.com> > --- > newlib/libc/include/complex.h | 12 ++++++++++++ > 1 file changed, 12 insertions(+) The CMPLXx() macros are already in that file, right at the start, lines 20 to 30. Corinna
Hi Corinna, Yes, I see. Sorry, I missed that while rebasing my patches. Regards, Yuriy Kolerov -----Original Message----- From: Corinna Vinschen <vinschen@redhat.com> Sent: Monday, February 3, 2025 4:16 PM To: Yuriy Kolerov <ykolerov@synopsys.com> Cc: newlib@sourceware.org Subject: Re: [PATCH] libm: Add CMPLX, CMPLXF and CMPLXL macros Hi Yuriy, On Jan 31 23:14, Yuriy Kolerov wrote: > This is a backport of the same patch from Picolibc repository with all > fixes: > > https://urldefense.com/v3/__https://github.com/picolibc/picolibc/commi > t/197657202913__;!!A4F2R9G_pg!erpVdhCZzAZUHSMjMkze6yzlGsJZ8D26oU_WOZXv > 3HSIO3FmG2uS1VS7A3UwIPTHO2MsSjMfgWNzj_oAxgz1eKc$ > > libm: Add CMPLX, CMPLXF and CMPLXL macros > > These use __builtin_complex if available, otherwise they open > code as suggested by the C standard. > > Signed-off-by: Keith Packard <keithp@keithp.com> > > https://urldefense.com/v3/__https://github.com/picolibc/picolibc/commi > t/a00c65d42760__;!!A4F2R9G_pg!erpVdhCZzAZUHSMjMkze6yzlGsJZ8D26oU_WOZXv > 3HSIO3FmG2uS1VS7A3UwIPTHO2MsSjMfgWNzj_oAx12zglc$ > > complex.h: Add type casting to CMPLX, CMPLXF and CMPLXL macros > > Adding type casting to CMPLX, CMPLXF and CMPLXL macros to > ensure type safety constructing complex numbers using > __builtin_complex function. The real and imaginary parts > passed to __builtin_complex function are explicity cast to > double, float and long double respectively, to match the > types expected by the function. > > This change improves code clarity and prevents unintended > type conversions when using macros to construct complex > numbers. > > Signed-off-by: Mostafa Salman <mostafas@synopsys.com> > > Signed-off-by: Yuriy Kolerov <ykolerov@synopsys.com> > --- > newlib/libc/include/complex.h | 12 ++++++++++++ > 1 file changed, 12 insertions(+) The CMPLXx() macros are already in that file, right at the start, lines 20 to 30. Corinna
diff --git a/newlib/libc/include/complex.h b/newlib/libc/include/complex.h index dbabdf67a..f06fc2ba6 100644 --- a/newlib/libc/include/complex.h +++ b/newlib/libc/include/complex.h @@ -150,6 +150,18 @@ double creal(double complex); float crealf(float complex); long double creall(long double complex); +#if __ISO_C_VISIBLE >= 2011 +#ifdef _HAVE_BUILTIN_COMPLEX +#define CMPLX(r,i) __builtin_complex((double)(r), (double)(i)) +#define CMPLXF(r,i) __builtin_complex((float)(r), (float)(i)) +#define CMPLXL(r,i) __builtin_complex((long double)(r), (long double)(i)) +#else +#define CMPLX(r,i) ((double complex) ((double) (r) + (double complex) I * (double) (i))) +#define CMPLXF(r,i) ((float complex) ((float) (r) + (float complex) I * (float) (i))) +#define CMPLXL(r,i) ((long double complex) ((long double) (r) + (long double complex) I * (long double) (i))) +#endif +#endif + #if __GNU_VISIBLE double complex clog10(double complex); float complex clog10f(float complex);