public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "klaus.doldinger64 at googlemail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug target/54816] [avr] shift is better than widening mul Date: Tue, 11 Apr 2023 05:22:57 +0000 [thread overview] Message-ID: <bug-54816-4-XcY0IEFlEp@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-54816-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54816 Wilhelm M <klaus.doldinger64 at googlemail dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |klaus.doldinger64@googlemai | |l.com --- Comment #1 from Wilhelm M <klaus.doldinger64 at googlemail dot com> --- The following code has the same problem: #include <avr/io.h> #include <stdint.h> uint16_t b; uint8_t a; template<typename A, typename B> B Mul(const A a, const B b) { static constexpr uint8_t shift = (sizeof(B) - sizeof(A)) * 8; return static_cast<A>(b >> shift) * a ; } int main() { return Mul(a, b); } with 4.6.4. it produces: main: lds r24,a lds r25,b+1 mul r25,r24 movw r24,r0 clr r1 ret with actual 12.2 it produces missing optimization: main: lds r24,b+1 ldi r25,0 lds r18,a movw r20,r24 mul r18,r20 movw r24,r0 mul r18,r21 add r25,r0 clr __zero_reg__ ret Interistingly the follwing code produces optimal code also with 12.2: template<typename A, typename B> B MulX(const A a, const B b) { static const uint8_t shift = (sizeof(B) - sizeof(A)) * 8; return static_cast<A>((b >> shift) + 1) * a ; }
next prev parent reply other threads:[~2023-04-11 5:22 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2012-10-04 18:28 [Bug target/54816] New: " gjl at gcc dot gnu.org 2023-04-11 5:22 ` klaus.doldinger64 at googlemail dot com [this message] 2023-04-15 13:27 ` [Bug target/54816] " roger at nextmovesoftware dot com 2023-04-15 15:48 ` klaus.doldinger64 at googlemail dot com 2023-04-16 12:04 ` cvs-commit at gcc dot gnu.org 2023-04-16 12:11 ` roger at nextmovesoftware dot com 2023-04-21 20:09 ` gjl at gcc dot gnu.org 2023-04-22 20:02 ` cvs-commit at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-54816-4-XcY0IEFlEp@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).