From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7A9EC433C1 for ; Thu, 25 Mar 2021 02:02:39 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 30E3661A1F for ; Thu, 25 Mar 2021 02:02:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 30E3661A1F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:53084 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPFKY-00056D-9N for qemu-devel@archiver.kernel.org; Wed, 24 Mar 2021 22:02:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55382) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPFIm-0003iH-BI; Wed, 24 Mar 2021 22:00:48 -0400 Received: from ozlabs.org ([203.11.71.1]:41213) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPFIk-0003CE-DG; Wed, 24 Mar 2021 22:00:48 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 4F5SxQ0yLvz9sWS; Thu, 25 Mar 2021 13:00:41 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1616637642; bh=1F7Gmfmu5IkHBP6WzMO0br3YHiL8j3PWBnCDKlLsa1w=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=nZDEISFaqyEzfBMyecYZQpr0hd+2W4ZmsbvvQnME67Y85Amqh+RhiIMOYfO+yM6Qt xEi6cQ+nU0uDM7oDM9p9C2fKviqrxXafspNZxbzbFlu9Om4crClKSS3fSSEi7vy6r1 JhM8x8cJzb8GTorXANb7D0W6tRupXm5JtyluAdpc= Date: Thu, 25 Mar 2021 12:56:18 +1100 From: David Gibson To: BALATON Zoltan Subject: Re: [PATCH v10 6/7] hw/pci-host: Add emulation of Marvell MV64361 PPC system controller Message-ID: References: <265d13b0-6f3e-fa51-30fb-36a88188cb3@eik.bme.hu> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="UFs1GWDpCOjTvkDO" Content-Disposition: inline In-Reply-To: Received-SPF: pass client-ip=203.11.71.1; envelope-from=dgibson@ozlabs.org; helo=ozlabs.org X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Paolo Bonzini , qemu-ppc@nongnu.org, f4bug@amsat.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" --UFs1GWDpCOjTvkDO Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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 &=3D 0x1fffff; > > > > > + for (mask =3D 1, i =3D 0; i < 21; i++, mask <<=3D 1) { > > > >=20 > > > > Having a loop, where nearly the entire body is a switch over the lo= op > > > > variable seems a rather odd choice to me, compared to just unrolling > > > > the whole thing. Or alternatively, maybe more can be be factored o= ut > > > > of the switch into common body code. > > >=20 > > > The loop is really over the bits in val that say which memory regions= to > >=20 > > I see that, but it doesn't change the point. > >=20 > > > enable so depending on this we need to touch different mem regions. F= or > > > selecting those memory regions and what to do with them a switch seem= s 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 w= ould > > > just add lines between cases that's now in the loop head so I really = don't > >=20 > > I see only 2 common lines, which basically balances about the case and > > break lines in every switchcase. >=20 > 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 n= or > 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) !=3D (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 chec= ked > 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. >=20 > 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 n= ot > 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. --=20 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 --UFs1GWDpCOjTvkDO Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEdfRlhq5hpmzETofcbDjKyiDZs5IFAmBb7cIACgkQbDjKyiDZ s5I5UxAA1cc/+Tsl5hjPLzv4f45svM8hvZJkYNGShyZhUrpbYU+Dw+oV8kgloGlH pCw5OYDki0SAH6yiOHM9eKZ22gWZPYbRvtDxoRQY3cDQFrvnLc35NCVyTIpl6zUj iaGNu5J1VKdva9JEuA3bBHR0TC7VMY2U+ymAlHA36mR4vSanBri8p5fahftV/ZJz 1bTQobL8im/sACfUqHzjyWlwxH1sAWHVVP++/RgSL7xvZCrv7X4ghat6GkdSjiF3 fKQ3TrqwijtoH3SP2TSFyNcNbbsXBJi4VGQg3Ogh+z99o4Z6eyI0+KnMGqNUDg1s L9p2HVhjZ765xSyVdQVOxQIuenpdlHxFd/QA+kh3nzRR6HvcxdmkJWXqGvs3Kgyj Y0oCUTzbdCnwY0cj3pLi1mXJjQ4VJH7MO1aSOBFLGCX0z94HU320RfTFABbhQSWs ERizgPWp08B6xK3eY+n67DjDqiwpZN+jlaFX/CoFWgHFR0kXADLrcqcCyRRFfCp6 i4ly2zbKmdH6VLi9il9latfgT9ttkJ6v8P1ONgBXruWWk45NlkBbsnwmjUMHzABm z22OSA5elrHVWh0Z+RVR/heMbpTjWJw3//a4NmtaJqrRYYdbrPpQG4j65HDabq7x +Dw4bEVhm5gKrmU3VWtKE5r6RbmdD77XK3RiirZdpI86VOp63k8= =uVWx -----END PGP SIGNATURE----- --UFs1GWDpCOjTvkDO--