Skip to content

Commit

Permalink
vga: optimize ppm_save() divisions
Browse files Browse the repository at this point in the history
ppm_save() spends upwards of 50% of its time doing divisions. Replace them
with shifts.

Reviewed-by: Alon Levy <alevy@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
  • Loading branch information
avikivity authored and Anthony Liguori committed Jan 12, 2012
1 parent 19bf7c8 commit a0f4261
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions hw/vga.c
Original file line number Diff line number Diff line change
Expand Up @@ -2373,12 +2373,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;
Expand Down

0 comments on commit a0f4261

Please sign in to comment.