From patchwork Wed May 8 17:01:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Georg-Johann Lay X-Patchwork-Id: 1933106 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gjlay.de header.i=@gjlay.de header.a=rsa-sha256 header.s=strato-dkim-0002 header.b=UFk8ynNG; dkim=pass header.d=gjlay.de header.i=@gjlay.de header.a=ed25519-sha256 header.s=strato-dkim-0003 header.b=NocA/XHq; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VZLz52K2mz1ymg for ; Thu, 9 May 2024 03:01:52 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4B2293881873 for ; Wed, 8 May 2024 17:01:50 +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.217]) by sourceware.org (Postfix) with ESMTPS id 11E05384B000 for ; Wed, 8 May 2024 17:01:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 11E05384B000 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-Filter: OpenARC Filter v1.0.0 sourceware.org 11E05384B000 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=81.169.146.217 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1715187687; cv=pass; b=yE1JkzO+LboMEEYD9b26fpTkBWjRk1Bo2fwBT4fj9tDPOa/dR/VUkwVJPp2LynbaN4uwrntE1EOh5uXjTrYs1ialyWI6uoCVfNWOpLRLyhqXaFvWJhrxtghv3Jkmt7VCEcYIgU77H0suyEJYUhPlQv24duZtr/7poSaDIjkJwqo= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1715187687; c=relaxed/simple; bh=D6oqbihib/fZdofyAkwjyzOJv3LljU1LNMmuhDXcbNE=; h=DKIM-Signature:DKIM-Signature:Message-ID:Date:MIME-Version:From: To:Subject; b=Rkt+HJHPJUZSwadQUnnKM1lL1fMKw0yx5+Sl18mPV5OOb5EkaxOIAsLZDRyE8F4qDlVtZ1ehuZWs5m3xdA5PLBc0w5cbgLnoocBpn6TbzYYoKBK4LmM4q0Xch91HkbqXxyEdVZEHBFoadzLHdetAJmFFprrr0BGixaR4u1zN7Ok= ARC-Authentication-Results: i=2; server2.sourceware.org ARC-Seal: i=1; a=rsa-sha256; t=1715187682; cv=none; d=strato.com; s=strato-dkim-0002; b=Dc44MC0Ozfudit+hiVIxE52rfo5VYTqCcKHbLn5mV5ApXXr/pSyXKDoT4QiYiyg1pU FmRFKSaP/UurZuL4aQR5UDV4Tv40FX2EfQzgrdUiT2mvxJP3/AM1GRUSkMBOvGMNLmE9 h0adwEJ0TxB6wNPFaBzrkYcl+e+0tXVcCakD6ZasQcV/fiPrnMkLNaQnngd5JdngH8id tTI6uM14mifwaIyRYzkHLAq5GAmk6J9COI0oLdOxT8b19g31rCaKW2Jhh72jAaHGFT3c tFmWoVuHFzBStgTj3Wql6waMGdQVD0E99BP9gMGIg7lucX5woxFk3jkc9Q1Fi1d5hUKX 0++A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1715187682; s=strato-dkim-0002; d=strato.com; h=Subject:To:From:Date:Message-ID:Cc:Date:From:Subject:Sender; bh=c2gsSTW2WjX2thoXePddBxj0iQj7hiyw7NcdFCnT0RY=; b=AYMXnM6TE1k2Gft61qV2gsvGdv+Tbklo//fSrA2z7VRlEyjEzqBqAJgCEgqGCQJ3vx jyjglSAANeewdZ5NQJlTfPP/BHqr0ho+b2KlhfxZSDRvz/TQh2N/jK4NVhQpfmHv6knm yhcbtPRLWYp5BaIGebu7vF5WuJOTtFrWXZnOnzdDl+eyKhO+1w8ofVEWZZ1+eoDhnybn TjejpwKV+zcMxGltxM1wI6mCElfRCXbw20Hn2v7IB7PhYBRnS+pbKCTJUN617yeZd4Cd lN98OPYDzJnYCoUJ17q3+SA+Nv+PQcCCMbM8sJe0S79vHMjIhKeZDazU3ONhKV8AjP+e GnQg== 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=1715187682; s=strato-dkim-0002; d=gjlay.de; h=Subject:To:From:Date:Message-ID:Cc:Date:From:Subject:Sender; bh=c2gsSTW2WjX2thoXePddBxj0iQj7hiyw7NcdFCnT0RY=; b=UFk8ynNGImQ1FZFpjETbhdOwrN500HWSZHSdPupaW1Qxp5uB70Hto4ohlQf8W4ph3M k/rg9zyY76xLBRCy9nxwjWTsJCjgApApAU/CIFUFbQELWQxc+X4TzD8I0BT5+q9zWITh qze5MjHiG/97/hA5UjvxETHZeI1aq5IrGwk8mZ9MG2T8mqnDPUjbaYYCAcJ3xLKKbcXh z7OX1oGfx7the4R70RnQcgVJ+LlFCtuD1A+c8H3NgRwRXF5S2JxgGMY/HyJ1IGrQUr+s HajSfRoF/jhn+dC71OhIdt3zCZNw9eO+wRwCmKts4mEb5jSqVMBLtpAMCAR39/144XGc sK3g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1715187682; s=strato-dkim-0003; d=gjlay.de; h=Subject:To:From:Date:Message-ID:Cc:Date:From:Subject:Sender; bh=c2gsSTW2WjX2thoXePddBxj0iQj7hiyw7NcdFCnT0RY=; b=NocA/XHqEvfATo6TjNuU3/8dDxSmV+U2nSYdfxZaCp/qSfdIXVhk/2BEiEUXILT5aT UZaOB4nJumMPXWJ2woBw== X-RZG-AUTH: ":LXoWVUeid/7A29J/hMvvT3koxZnKT7Qq0xotTetVnKkahNK6p2y+LQ4kG4HR" Received: from [192.168.2.102] by smtp.strato.de (RZmta 50.5.0 DYNA|AUTH) with ESMTPSA id xcdf44048H1MxDB (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate) for ; Wed, 8 May 2024 19:01:22 +0200 (CEST) Message-ID: <367b9b58-12a5-45b0-ba2c-61a8708bd335@gjlay.de> Date: Wed, 8 May 2024 19:01:21 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Georg-Johann Lay Content-Language: en-US To: "gcc-patches@gcc.gnu.org" Subject: [patch,avr,applied] PR114981: Implement __powidf2 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, 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+incoming=patchwork.ozlabs.org@gcc.gnu.org This adds __powidf2 as a wrapper in LibF7. Johann diff --git a/gcc/testsuite/gcc.target/avr/pr114981-powil.c b/gcc/testsuite/gcc.target/avr/pr114981-powil.c new file mode 100644 index 00000000000..70f8e796c65 --- /dev/null +++ b/gcc/testsuite/gcc.target/avr/pr114981-powil.c @@ -0,0 +1,33 @@ +/* { dg-do run { target { ! avr_tiny } } } */ +/* { dg-additional-options "-Os" } */ + +const long double vals[] = + { + 0.0625L, -0.125L, 0.25L, -0.5L, + 1.0L, + -2.0L, 4.0L, -8.0L, 16.0L + }; + +#define ARRAY_SIZE(X) ((int) (sizeof(X) / sizeof(*X))) + +__attribute__((noinline,noclone)) +void test1 (long double x) +{ + int i; + + for (i = 0; i < ARRAY_SIZE (vals); ++i) + { + long double val0 = vals[i]; + long double val1 = __builtin_powil (x, i - 4); + __asm ("" : "+r" (val0)); + + if (val0 != val1) + __builtin_exit (__LINE__); + } +} + +int main (void) +{ + test1 (-2.0L); + return 0; +} diff --git a/libgcc/config/avr/libf7/libf7-asm.sx b/libgcc/config/avr/libf7/libf7-asm.sx index 1ab91270cb2..1f8f60ab282 100644 --- a/libgcc/config/avr/libf7/libf7-asm.sx +++ b/libgcc/config/avr/libf7/libf7-asm.sx @@ -1877,4 +1877,16 @@ DEFUN call_ddd #include "f7-wraps.h" +;;; Some additional, singular wraps that don't match any pattern. + +;; double __powidf2 (double, int) ; __builtin_powi +#ifdef F7MOD_D_powi_ +_DEFUN __powidf2 + .global F7_NAME(powi) + ldi ZH, hi8(gs(F7_NAME(powi))) + ldi ZL, lo8(gs(F7_NAME(powi))) + F7jmp call_ddx +_ENDF __powidf2 +#endif /* F7MOD_D_powi_ */ + #endif /* !AVR_TINY */ diff --git a/libgcc/config/avr/libf7/libf7-common.mk b/libgcc/config/avr/libf7/libf7-common.mk index d541b48ff3c..5d411071c8e 100644 --- a/libgcc/config/avr/libf7/libf7-common.mk +++ b/libgcc/config/avr/libf7/libf7-common.mk @@ -22,7 +22,7 @@ F7_ASM_PARTS += addsub_mant_scaled store load F7_ASM_PARTS += to_integer to_unsigned clz normalize_with_carry normalize F7_ASM_PARTS += store_expo sqrt16 sqrt_approx div -F7_ASM_PARTS += D_class D_fma +F7_ASM_PARTS += D_class D_fma D_powi F7_ASM_PARTS += D_isnan D_isinf D_isfinite D_signbit D_copysign D_neg D_fabs F7_ASM_PARTS += call_dd call_ddd diff --git a/libgcc/config/avr/libf7/libf7.c b/libgcc/config/avr/libf7/libf7.c index 369dbe24103..375becb854c 100644 --- a/libgcc/config/avr/libf7/libf7.c +++ b/libgcc/config/avr/libf7/libf7.c @@ -1752,20 +1752,33 @@ void f7_powi (f7_t *cc, const f7_t *aa, int ii) { uint16_t u16 = ii; f7_t xx27, *xx2 = &xx27; + bool cc_is_one = true; + bool expo_is_neg = false; if (ii < 0) - u16 = -u16; + { + u16 = -u16; + expo_is_neg = true; + } f7_copy (xx2, aa); - f7_set_u16 (cc, 1); - while (1) { if (u16 & 1) - f7_Imul (cc, xx2); + { + if (cc_is_one) + { + // C *= X2 simplifies to C = X2. + f7_copy (cc, xx2); + cc_is_one = false; + } + else + f7_Imul (cc, xx2); + } - if (! f7_is_nonzero (cc)) + if (! cc_is_one + && ! f7_is_nonzero (cc)) break; u16 >>= 1; @@ -1774,8 +1787,10 @@ void f7_powi (f7_t *cc, const f7_t *aa, int ii) f7_Isquare (xx2); } - if (ii < 0) - f7_div1 (xx2, aa); + if (cc_is_one) + f7_set_u16 (cc, 1); + else if (expo_is_neg) + f7_div1 (cc, cc); } #endif // F7MOD_powi_