Received: from eggs.gnu.org ([140.186.70.92]:35722) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RlMNu-00049t-ND for qemu-devel@nongnu.org; Thu, 12 Jan 2012 10:16:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RlMNs-0001pK-RC for qemu-devel@nongnu.org; Thu, 12 Jan 2012 10:16:10 -0500 Received: from mx1.redhat.com ([209.132.183.28]:13590) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RlMNs-0001p8-GH for qemu-devel@nongnu.org; Thu, 12 Jan 2012 10:16:08 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q0CFG7XL001206 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 12 Jan 2012 10:16:07 -0500 Date: Thu, 12 Jan 2012 17:16:03 +0200 From: Alon Levy Message-ID: <20120112151603.GY5762@garlic.tlv.redhat.com> References: <1325597577-29385-1-git-send-email-avi@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1325597577-29385-1-git-send-email-avi@redhat.com> Subject: Re: [Qemu-devel] [PATCH] vga: optimize ppm_save() divisions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Avi Kivity Cc: qemu-devel@nongnu.org On Tue, Jan 03, 2012 at 03:32:57PM +0200, Avi Kivity wrote: > ppm_save() spends upwards of 50% of its time doing divisions. Replace them > with shifts. > Reviewed-by: Alon Levy rmax/bmax/gmax are all uint8_t atm, could add a compilation error if sizeof(bmax)!=1 ever. > Signed-off-by: Avi Kivity > --- > hw/vga.c | 10 ++++------ > 1 files changed, 4 insertions(+), 6 deletions(-) > > diff --git a/hw/vga.c b/hw/vga.c > index ca79aa1..a228cde 100644 > --- a/hw/vga.c > +++ b/hw/vga.c > @@ -2370,12 +2370,10 @@ int ppm_save(const char *filename, struct DisplaySurface *ds) > v = *(uint32_t *)d; > else > v = (uint32_t) (*(uint16_t *)d); > - r = ((v >> ds->pf.rshift) & ds->pf.rmax) * 256 / > - (ds->pf.rmax + 1); > - g = ((v >> ds->pf.gshift) & ds->pf.gmax) * 256 / > - (ds->pf.gmax + 1); > - b = ((v >> ds->pf.bshift) & ds->pf.bmax) * 256 / > - (ds->pf.bmax + 1); > + /* Limited to 8 or fewer bits per channel: */ > + r = ((v >> ds->pf.rshift) & ds->pf.rmax) << (8 - ds->pf.rbits); > + g = ((v >> ds->pf.gshift) & ds->pf.gmax) << (8 - ds->pf.gbits); > + b = ((v >> ds->pf.bshift) & ds->pf.bmax) << (8 - ds->pf.bbits); > *pbuf++ = r; > *pbuf++ = g; > *pbuf++ = b; > -- > 1.7.7.1 > >