From: Anthony Liguori <anthony@codemonkey.ws>
To: Avi Kivity <avi@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] vga: optimize ppm_save() divisions
Date: Thu, 12 Jan 2012 10:54:11 -0600 [thread overview]
Message-ID: <4F0F1033.20304@codemonkey.ws> (raw)
In-Reply-To: <1325597577-29385-1-git-send-email-avi@redhat.com>
On 01/03/2012 07:32 AM, Avi Kivity wrote:
> ppm_save() spends upwards of 50% of its time doing divisions. Replace them
> with shifts.
>
> Signed-off-by: Avi Kivity<avi@redhat.com>
Applied. Thanks.
Regards,
Anthony Liguori
> ---
> 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;
prev parent reply other threads:[~2012-01-12 16:54 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-03 13:32 [Qemu-devel] [PATCH] vga: optimize ppm_save() divisions Avi Kivity
2012-01-12 13:46 ` Avi Kivity
2012-01-12 15:16 ` Alon Levy
2012-01-12 15:19 ` Alon Levy
2012-01-12 16:54 ` Anthony Liguori [this message]
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=4F0F1033.20304@codemonkey.ws \
--to=anthony@codemonkey.ws \
--cc=avi@redhat.com \
--cc=qemu-devel@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).