From: Eric Blake <eblake@redhat.com> To: "Philippe Mathieu-Daudé" <f4bug@amsat.org>, "Alistair Francis" <alistair23@gmail.com> Cc: "open list:RISC-V" <qemu-riscv@nongnu.org>, "qemu-devel@nongnu.org Developers" <qemu-devel@nongnu.org>, Palmer Dabbelt <palmer@dabbelt.com>, Alistair Francis <alistair.francis@wdc.com>, Bin Meng <bmeng.cn@gmail.com>, Richard Henderson <rth@twiddle.net> Subject: Re: [PATCH v1 1/1] riscv: Pass RISCVHartArrayState by pointer Date: Tue, 19 Jan 2021 15:50:17 -0600 [thread overview] Message-ID: <f57d1ae2-eb00-3fa0-b1ca-c0fdc6f339e1@redhat.com> (raw) In-Reply-To: <31a5b411-66d8-87ef-865a-6b3d33d0a874@amsat.org> On 1/17/21 10:52 AM, Philippe Mathieu-Daudé wrote: > On 1/16/21 11:38 PM, Alistair Francis wrote: >> On Sat, Jan 16, 2021 at 2:32 PM Philippe Mathieu-Daudé <f4bug@amsat.org> wrote: >>> >>> On 1/16/21 12:00 AM, Alistair Francis wrote: >>>> We were accidently passing RISCVHartArrayState by value instead of accidentally >>>> pointer. The type is 824 bytes long so let's correct that and pass it by >>>> pointer instead. >>>> -bool riscv_is_32bit(RISCVHartArrayState harts) >>>> +bool riscv_is_32bit(RISCVHartArrayState *harts) Definitely better, >>>> { >>>> - RISCVCPU hart = harts.harts[0]; >>>> + RISCVCPU hart = harts->harts[0]; but yeah, this still results in a copy (unless the compiler optimizes it). >>> >>> This doesn't look improved. Maybe you want: >>> >>> return riscv_cpu_is_32bit(&harts->harts[0].env); Whereas this is obviously a pointer into the original without relying on the compiler to elide a copy. >> >> I suspect this ends up generating the same code. > > If the compiler is smart enough, but I'm not sure it can figure out > only 1 element from the structure is accessed... > My understanding is "first copy the content pointed at '*harts' in > 'hart' on the stack", then only use "env". > > Cc'ing Eric/Richard to double check. I agree that relying on the compiler optimization is not as straightforward as writing the code to directly access the correct pointer from the get-go. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
WARNING: multiple messages have this Message-ID (diff)
From: Eric Blake <eblake@redhat.com> To: "Philippe Mathieu-Daudé" <f4bug@amsat.org>, "Alistair Francis" <alistair23@gmail.com> Cc: "open list:RISC-V" <qemu-riscv@nongnu.org>, Palmer Dabbelt <palmer@dabbelt.com>, Bin Meng <bmeng.cn@gmail.com>, Alistair Francis <alistair.francis@wdc.com>, "qemu-devel@nongnu.org Developers" <qemu-devel@nongnu.org>, Richard Henderson <rth@twiddle.net> Subject: Re: [PATCH v1 1/1] riscv: Pass RISCVHartArrayState by pointer Date: Tue, 19 Jan 2021 15:50:17 -0600 [thread overview] Message-ID: <f57d1ae2-eb00-3fa0-b1ca-c0fdc6f339e1@redhat.com> (raw) In-Reply-To: <31a5b411-66d8-87ef-865a-6b3d33d0a874@amsat.org> On 1/17/21 10:52 AM, Philippe Mathieu-Daudé wrote: > On 1/16/21 11:38 PM, Alistair Francis wrote: >> On Sat, Jan 16, 2021 at 2:32 PM Philippe Mathieu-Daudé <f4bug@amsat.org> wrote: >>> >>> On 1/16/21 12:00 AM, Alistair Francis wrote: >>>> We were accidently passing RISCVHartArrayState by value instead of accidentally >>>> pointer. The type is 824 bytes long so let's correct that and pass it by >>>> pointer instead. >>>> -bool riscv_is_32bit(RISCVHartArrayState harts) >>>> +bool riscv_is_32bit(RISCVHartArrayState *harts) Definitely better, >>>> { >>>> - RISCVCPU hart = harts.harts[0]; >>>> + RISCVCPU hart = harts->harts[0]; but yeah, this still results in a copy (unless the compiler optimizes it). >>> >>> This doesn't look improved. Maybe you want: >>> >>> return riscv_cpu_is_32bit(&harts->harts[0].env); Whereas this is obviously a pointer into the original without relying on the compiler to elide a copy. >> >> I suspect this ends up generating the same code. > > If the compiler is smart enough, but I'm not sure it can figure out > only 1 element from the structure is accessed... > My understanding is "first copy the content pointed at '*harts' in > 'hart' on the stack", then only use "env". > > Cc'ing Eric/Richard to double check. I agree that relying on the compiler optimization is not as straightforward as writing the code to directly access the correct pointer from the get-go. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
next prev parent reply other threads:[~2021-01-19 21:51 UTC|newest] Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-01-15 23:00 [PATCH v1 1/1] riscv: Pass RISCVHartArrayState by pointer Alistair Francis 2021-01-15 23:00 ` Alistair Francis 2021-01-15 23:03 ` Palmer Dabbelt 2021-01-15 23:03 ` Palmer Dabbelt 2021-01-16 16:30 ` Bin Meng 2021-01-16 16:30 ` Bin Meng 2021-01-16 17:50 ` Alistair Francis 2021-01-16 17:50 ` Alistair Francis 2021-01-16 18:55 ` Alistair Francis 2021-01-16 18:55 ` Alistair Francis 2021-01-16 22:32 ` Philippe Mathieu-Daudé 2021-01-16 22:32 ` Philippe Mathieu-Daudé 2021-01-16 22:38 ` Alistair Francis 2021-01-16 22:38 ` Alistair Francis 2021-01-17 16:52 ` Philippe Mathieu-Daudé 2021-01-17 16:52 ` Philippe Mathieu-Daudé 2021-01-19 21:50 ` Eric Blake [this message] 2021-01-19 21:50 ` Eric Blake 2021-01-18 17:14 ` Richard Henderson 2021-01-18 17:14 ` Richard Henderson
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=f57d1ae2-eb00-3fa0-b1ca-c0fdc6f339e1@redhat.com \ --to=eblake@redhat.com \ --cc=alistair.francis@wdc.com \ --cc=alistair23@gmail.com \ --cc=bmeng.cn@gmail.com \ --cc=f4bug@amsat.org \ --cc=palmer@dabbelt.com \ --cc=qemu-devel@nongnu.org \ --cc=qemu-riscv@nongnu.org \ --cc=rth@twiddle.net \ /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 an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.