qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alon Levy <alevy@redhat.com>
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 17:16:03 +0200	[thread overview]
Message-ID: <20120112151603.GY5762@garlic.tlv.redhat.com> (raw)
In-Reply-To: <1325597577-29385-1-git-send-email-avi@redhat.com>

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 <alevy@redhat.com>

rmax/bmax/gmax are all uint8_t atm, could add a compilation error if
sizeof(bmax)!=1 ever.

> Signed-off-by: Avi Kivity <avi@redhat.com>
> ---
>  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
> 
> 

  parent reply	other threads:[~2012-01-12 15:16 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 [this message]
2012-01-12 15:19   ` Alon Levy
2012-01-12 16:54 ` Anthony Liguori

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=20120112151603.GY5762@garlic.tlv.redhat.com \
    --to=alevy@redhat.com \
    --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).