From patchwork Thu Oct 12 13:38:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Georg-Johann Lay X-Patchwork-Id: 152015 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp1237983vqb; Thu, 12 Oct 2023 06:39:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHiPG8RimzCaMUw+3AQsjYnfvTATGnIseH/++ecJJFafS7MqhLZQ1+le5uXnr8gc1jebWHV X-Received: by 2002:a05:6402:11cf:b0:53d:a4e5:67d0 with SMTP id j15-20020a05640211cf00b0053da4e567d0mr7072201edw.13.1697117968303; Thu, 12 Oct 2023 06:39:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697117968; cv=pass; d=google.com; s=arc-20160816; b=F4XKKV4XoyyktlZDbyJvDb6r0YXiFku6W4KjFk3aexYj7DYjd0NoU6hRxzxROihY+r 9Qz1fjL5hBm7tiqqomuEvVJgEuag0nTRTIP7QShFhygs87B5x0FjoeH9csKqXvEr30zM 3YUatMNOG6TGZKk45B0JotkvGjzYVPal1BvGxaGWo546khWSMMkESwTWm3NuSLnPFYPJ V8+T4RpgWk6f+tQOpto6cszYsndGOHR1ycub24yL7tuvjrPWgfE1P6nq46IF1g5T0BWO eV2Zqyxh9CfJ3bMEcvzcTRO5PTUMS0iKPw5wMVbfdkNdRcQasShT0el7+ELuOum+ILCH yrJw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :subject:from:to:content-language:user-agent:mime-version:date :message-id:dkim-signature:dkim-signature:dmarc-filter:delivered-to; bh=Vt9DHGAh9kU0ZpAYWHSZ+iQL+o7W0QfprAJfXl8qE/0=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=pBQmSMEGMbmoLqn96fJlZLh7ipzmaclUARozp7u6ihHiwGYbbQr8zgb7LchkNqlYhP 3FaIxZIa8LPG7co4ZJnmVJzSgr3hx5R1FpG2eNx03JKX+fsJv7oi77BllcNUkR6F5GYw oc72aY5ORjxBTVfkNO5+aeiqb5sVXTarHJRabvxOBSO0YQF5H3vSXrh87UIO4lptsW+r Kmzj/nd5EirDK2QUBxSFDG9pubg1bWdLGS44gBeXUQUp5MKW2L9yPT1JDGtnwtxRWBJf 65q0g5d7IzHY96tbFyG3O4cEtRFtlGNzSjFjLjsCuBAbRd15gvWNEFI4Qe+w+0dn1vGH Dogg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gjlay.de header.s=strato-dkim-0002 header.b=IBmDXVZF; dkim=neutral (no key) header.i=@gjlay.de header.b=OgWoALrF; arc=pass (i=1); 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" Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id o22-20020aa7d3d6000000b00534777419ddsi7827997edr.319.2023.10.12.06.39.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 06:39:28 -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=@gjlay.de header.s=strato-dkim-0002 header.b=IBmDXVZF; dkim=neutral (no key) header.i=@gjlay.de header.b=OgWoALrF; arc=pass (i=1); 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 62836385CC80 for ; Thu, 12 Oct 2023 13:39:23 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mo4-p00-ob.smtp.rzone.de (mo4-p00-ob.smtp.rzone.de [81.169.146.216]) by sourceware.org (Postfix) with ESMTPS id BB1FB3858C5E for ; Thu, 12 Oct 2023 13:38:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BB1FB3858C5E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gjlay.de Authentication-Results: sourceware.org; spf=none smtp.mailfrom=gjlay.de ARC-Seal: i=1; a=rsa-sha256; t=1697117933; cv=none; d=strato.com; s=strato-dkim-0002; b=i8wSz2hxIcrUWKpTRorBhqVhkv/pCH3pE84FgnYSsRmIfE4c3yHJxhEA/ASWUPFFDr pLFZf2WzGHJf8tLTUMsrk2zo1ehl5sAm0UqtFFoK7dkyDVqYk5AhfEZB45cjqUPSzaqH GPdr2Zpx/d1FxeerRRwgQIF324cqNFgkhGsFG/GgmOyS2GRwEbVMcUUIBjL4Bs+lMhrk 27u5Ex8OWzX1G1K/rzJ7JBkCdXeijhHWrjyd3CXWsLusmITJZpp/cJtjMWvSFZO8dgPu 8vpnJSCSSUcocqyLpYpoYnP9DE5zsjsaCnrZ3YlqaH6V2hViwo6hdUXcVjx8ToYCgmGP 33jQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1697117933; s=strato-dkim-0002; d=strato.com; h=Subject:From:To:Date:Message-ID:Cc:Date:From:Subject:Sender; bh=Vt9DHGAh9kU0ZpAYWHSZ+iQL+o7W0QfprAJfXl8qE/0=; b=Ds6N0Z1hU2iEvX4vf1Vw4t9o2AXBtCnM7lZplsS47W+5QEiSjo8sVHfH/ZBtb6hguN sqsgiSs9E3jZ50c2Xjnu144jRcUVA7YFJ5hDXm0x5rLpebjT5mCa+t0n7JeGXVLJtDAV a3+tmoJ3B7K+lz8+wXpq4LhmGzyGd+OpiFGqBKEmn4CicI4TsuwcZbh1Z0htGIVR1/O/ uLofWOVTdeodbu0zsB1zPrxxtz2IKvIe2MEya4c3yTroXKuLrupd7c2UT1aPR24at62a PPXMmyjU2sfJmMhSFQ/9QztJsShagBMITsYEmblWVkDiG6h5fHx/9AswksimHMGpRFtQ PIMQ== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1697117933; s=strato-dkim-0002; d=gjlay.de; h=Subject:From:To:Date:Message-ID:Cc:Date:From:Subject:Sender; bh=Vt9DHGAh9kU0ZpAYWHSZ+iQL+o7W0QfprAJfXl8qE/0=; b=IBmDXVZFrateeG+puU3UQ/sl9PX/3QPCq5czmOiVgeyd6um3UFjzH1QQN/S7sxyUUs BYlFd9Wb5xalb2nytKoY0eXgY4r+uvs0Y5m8iIA0bsppiSQKp83kt1KEcigsqbJk3C1Y jyErDG16nJLe4s5dRcMBvuAUhb0sAmsOIDp1DAynbUg0769LVDppli7u2Ni2THvJGWCd fGswtis4OeIIVCn/OvoCv292mA00b4ocqJW1rg6w0dIAGdkjc5Jv0OR8N9K+T3rUw1Oq S/oi641dUJk3/5R1rv0pL+ybsQcrdHujgwk1GnMOoz8Au1Kyu4ItOKPHKJVhvoS60R3O yE+g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1697117933; s=strato-dkim-0003; d=gjlay.de; h=Subject:From:To:Date:Message-ID:Cc:Date:From:Subject:Sender; bh=Vt9DHGAh9kU0ZpAYWHSZ+iQL+o7W0QfprAJfXl8qE/0=; b=OgWoALrFtqe7hpelvgi1gnSDPfKUxg/EqM6Csucw6mpgRTsb30zNFGMuFrkg8YPMMk XGpji8wRL6QIlwCLJoDA== X-RZG-AUTH: ":LXoWVUeid/7A29J/hMvvT3koxZnKT7Qq0xotTetVnKkSjsSjo3O/MHXSzlaR/rBp" Received: from [192.168.2.102] by smtp.strato.de (RZmta 49.8.2 DYNA|AUTH) with ESMTPSA id a0474az9CDcrKbg (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate) for ; Thu, 12 Oct 2023 15:38:53 +0200 (CEST) Message-ID: Date: Thu, 12 Oct 2023 15:38:52 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Content-Language: en-US To: gcc-patches@gcc.gnu.org From: Georg-Johann Lay Subject: [avr,committed] Implement atan2 X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779557170693617973 X-GMAIL-MSGID: 1779557170693617973 This implements atan2 which was missing from LibF7. Johann --- LibF7: Implement atan2. libgcc/config/avr/libf7/ * libf7.c (F7MOD_atan2_, f7_atan2): New module and function. * libf7.h: Adjust comments. * libf7-common.mk (CALL_PROLOGUES): Add atan2. diff --git a/libgcc/config/avr/libf7/libf7-common.mk b/libgcc/config/avr/libf7/libf7-common.mk index 28663b52e6c..e417715a7e5 100644 --- a/libgcc/config/avr/libf7/libf7-common.mk +++ b/libgcc/config/avr/libf7/libf7-common.mk @@ -43,7 +43,7 @@ m_xd += lrint lround # -mcall-prologues CALL_PROLOGUES += divx sqrt cbrt get_double set_double logx exp exp10 pow10 CALL_PROLOGUES += put_C truncx round minmax sincos tan cotan pow powi fmod -CALL_PROLOGUES += atan asinacos madd_msub hypot init horner sinhcosh tanh +CALL_PROLOGUES += atan atan2 asinacos madd_msub hypot init horner sinhcosh tanh # -mstrict-X STRICT_X += log addsub truncx ldexp exp diff --git a/libgcc/config/avr/libf7/libf7.c b/libgcc/config/avr/libf7/libf7.c index 0d9e4c325b2..49baac73e6d 100644 --- a/libgcc/config/avr/libf7/libf7.c +++ b/libgcc/config/avr/libf7/libf7.c @@ -1099,7 +1099,7 @@ f7_t* f7_ldexp (f7_t *cc, const f7_t *aa, int delta) F7_CONST_ADDR ( CST, f7_t* PTMP) - Return an LD address to for some f7_const_X[_P] constant. + Return an LD address to some f7_const_X[_P] constant. *PTMP might be needed to hold a copy of f7_const_X_P in RAM. f7_t* F7_U16_ADDR (uint16_t X, f7_t* PTMP) // USE_LPM @@ -2189,6 +2189,64 @@ void f7_atan (f7_t *cc, const f7_t *aa) #endif // F7MOD_atan_ +#ifdef F7MOD_atan2_ +F7_WEAK +void f7_atan2 (f7_t *cc, const f7_t *yy, const f7_t *xx) +{ + uint8_t y_class = f7_classify (yy); + uint8_t x_class = f7_classify (xx); + + // (NaN, *) -> NaN + // (*, NaN) -> NaN + if (f7_class_nan (y_class | x_class)) + return f7_set_nan (cc); + + // (0, 0) -> 0 + if (f7_class_zero (y_class & x_class)) + return f7_clr (cc); + + f7_t pi7, *pi = &pi7; + f7_const (pi, pi); + + // (Inf, +Inf) -> +pi/4; (-Inf, +Inf) -> +3pi/4 + // (Inf, -Inf) -> -pi/4; (-Inf, -Inf) -> -3pi/4 + if (f7_class_inf (y_class & x_class)) + { + f7_copy (cc, pi); + if (! f7_class_sign (x_class)) + cc->expo = F7_(const_pi_expo) - 1; // pi / 2 + pi->expo = F7_(const_pi_expo) - 2; // pi / 4 + f7_Isub (cc, pi); + cc->flags = y_class & F7_FLAG_sign; + return; + } + + // sign(pi) := sign(y) + pi->flags = y_class & F7_FLAG_sign; + + // Only use atan(*) with |*| <= 1. + + if (f7_cmp_abs (yy, xx) > 0) + { + // |y| > |x|: atan2 = sgn(y) * pi/2 - atan (x / y); + pi->expo = F7_(const_pi_expo) - 1; // +- pi / 2 + f7_div (cc, xx, yy); + f7_atan (cc, cc); + f7_IRsub (cc, pi); + } + else + { + // x > |y|: atan2 = atan (y / x) + // x < -|y|: atan2 = atan (y / x) +- pi + f7_div (cc, yy, xx); + f7_atan (cc, cc); + if (f7_class_sign (x_class)) + f7_Iadd (cc, pi); + } +} +#endif // F7MOD_atan2_ + + #ifdef F7MOD_asinacos_ #define ARRAY_NAME coeff_func_a_zahler diff --git a/libgcc/config/avr/libf7/libf7.h b/libgcc/config/avr/libf7/libf7.h index f692854dced..b50e6e218ba 100644 --- a/libgcc/config/avr/libf7/libf7.h +++ b/libgcc/config/avr/libf7/libf7.h @@ -606,6 +606,7 @@ extern void f7_sin (f7_t*, const f7_t*); extern void f7_cos (f7_t*, const f7_t*); extern void f7_tan (f7_t*, const f7_t*); extern void f7_atan (f7_t*, const f7_t*); +extern void f7_atan2 (f7_t*, const f7_t*, const f7_t*); extern void f7_asin (f7_t*, const f7_t*); extern void f7_acos (f7_t*, const f7_t*); extern void f7_tanh (f7_t*, const f7_t*); @@ -617,7 +618,6 @@ extern void f7_exp10 (f7_t*, const f7_t*); extern void f7_pow10 (f7_t*, const f7_t*); // Just prototypes, not implemented yet. -extern void f7_atan2 (f7_t*, const f7_t*, const f7_t*); extern long f7_lrint (const f7_t*); extern long f7_lround (const f7_t*);