From: David Gibson <david@gibson.dropbear.id.au>
To: BALATON Zoltan <balaton@eik.bme.hu>
Cc: Peter Maydell <peter.maydell@linaro.org>,
Paolo Bonzini <pbonzini@redhat.com>,
qemu-ppc@nongnu.org, f4bug@amsat.org, qemu-devel@nongnu.org
Subject: Re: [PATCH v10 6/7] hw/pci-host: Add emulation of Marvell MV64361 PPC system controller
Date: Thu, 25 Mar 2021 12:56:18 +1100 [thread overview]
Message-ID: <YFvtwv4XzwdvtsNi@yekko.fritz.box> (raw)
In-Reply-To: <bdd91d23-53e5-5335-63ab-ce8b6dcd8d4@eik.bme.hu>
[-- Attachment #1: Type: text/plain, Size: 3567 bytes --]
On Wed, Mar 24, 2021 at 12:11:50PM +0100, BALATON Zoltan wrote:
> On Wed, 24 Mar 2021, David Gibson wrote:
> > On Tue, Mar 23, 2021 at 02:31:07PM +0100, BALATON Zoltan wrote:
> > > On Tue, 23 Mar 2021, David Gibson wrote:
> > > > On Wed, Mar 17, 2021 at 02:17:51AM +0100, BALATON Zoltan wrote:
> > [snip]
> > > > > +static void setup_mem_windows(MV64361State *s, uint32_t val)
> > > > > +{
> > > > > + MV64361PCIState *p;
> > > > > + MemoryRegion *mr;
> > > > > + uint32_t mask;
> > > > > + int i;
> > > > > +
> > > > > + val &= 0x1fffff;
> > > > > + for (mask = 1, i = 0; i < 21; i++, mask <<= 1) {
> > > >
> > > > Having a loop, where nearly the entire body is a switch over the loop
> > > > variable seems a rather odd choice to me, compared to just unrolling
> > > > the whole thing. Or alternatively, maybe more can be be factored out
> > > > of the switch into common body code.
> > >
> > > The loop is really over the bits in val that say which memory regions to
> >
> > I see that, but it doesn't change the point.
> >
> > > enable so depending on this we need to touch different mem regions. For
> > > selecting those memory regions and what to do with them a switch seems to be
> > > obvious choice. I probably can't factor out anything as these lines in
> > > switch cases are similar but all differ in some little details (like which
> > > PCI bus, name of the region, etc.). Unrolling could be possible but would
> > > just add lines between cases that's now in the loop head so I really don't
> >
> > I see only 2 common lines, which basically balances about the case and
> > break lines in every switchcase.
>
> Not sure what you mean by that. To me that means that these cannot be
> factored out as they are in the middle so can't put them neither before nor
> after the switch (without adding more local variables that would just make
> the result longer than it is now).
I'm saying that I don't think unrolling would actually make things
longer, because the small amount of duplication would balanced by
removing the switch boilerplate.
> Does that mean you prefer this to be unrolled then (written without a for
> just repeating the if ((val & mask) != (s->base_addr_enable & mask)) at
> every case)? That would also be longer by about 20 lines as we also log
> regions that are not in the switch that would need their enable bits checked
> separately if it's unrolled. Basically the trace is the common part of the
> loop and handling of the individual regions are branching out from the
> switch as they are different enough that factoring out the common parts is
> not shorter than this way due to then needing local variables to hold the
> different parts (name, address, size, base) the assigning of which are as
> many or more lines than the map_pci_region call that could be factored out
> that way.
>
> I don't see why it is a problem to have a switch in a loop. If you insist I
> can try to turn the switch into if else but I don't see how would that be
> any better. Please explain a bit more what would you prefer here as I'm not
> sure what to do with this. To me this is the shortest and simplest way to
> write this.
Hmm... you know, it still seems kinda weird to me, but I am getting
too hung up on details here. It's good enough, go with it.
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2021-03-25 2:02 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-17 1:17 [PATCH v10 0/7] Pegasos2 emulation BALATON Zoltan
2021-03-17 1:17 ` [PATCH v10 7/7] hw/ppc: Add emulation of Genesi/bPlan Pegasos II BALATON Zoltan
2021-03-23 0:55 ` David Gibson
2021-03-23 13:01 ` BALATON Zoltan
2021-03-24 1:45 ` David Gibson
2021-03-24 11:21 ` BALATON Zoltan
2021-03-25 2:00 ` David Gibson
2021-03-17 1:17 ` [PATCH v10 1/7] vt82c686: QOM-ify superio related functionality BALATON Zoltan
2021-03-17 1:17 ` [PATCH v10 6/7] hw/pci-host: Add emulation of Marvell MV64361 PPC system controller BALATON Zoltan
2021-03-23 0:40 ` David Gibson
2021-03-23 13:31 ` BALATON Zoltan
2021-03-24 1:48 ` David Gibson
2021-03-24 11:11 ` BALATON Zoltan
2021-03-25 1:56 ` David Gibson [this message]
2021-03-17 1:17 ` [PATCH v10 4/7] vt82c686: Add emulation of VT8231 south bridge BALATON Zoltan
2021-03-17 1:17 ` [PATCH v10 5/7] hw/isa/Kconfig: Add missing dependency VIA VT82C686 -> APM BALATON Zoltan
2021-03-17 1:17 ` [PATCH v10 3/7] vt82c686: Introduce abstract TYPE_VIA_ISA and base vt82c686b_isa on it BALATON Zoltan
2021-03-17 18:23 ` Philippe Mathieu-Daudé
2021-03-17 19:24 ` BALATON Zoltan
2021-03-17 1:17 ` [PATCH v10 2/7] vt82c686: Add VT8231_SUPERIO based on VIA_SUPERIO BALATON Zoltan
2021-03-23 0:42 ` [PATCH v10 0/7] Pegasos2 emulation David Gibson
2021-03-23 12:57 ` BALATON Zoltan
2021-03-25 1:54 ` David Gibson
2021-03-25 14:04 ` BALATON Zoltan
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=YFvtwv4XzwdvtsNi@yekko.fritz.box \
--to=david@gibson.dropbear.id.au \
--cc=balaton@eik.bme.hu \
--cc=f4bug@amsat.org \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.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: link
Be 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 NNTP newsgroup(s).