From patchwork Tue Jan 3 13:32:57 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avi Kivity X-Patchwork-Id: 134002 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id EFCECB6FA9 for ; Wed, 4 Jan 2012 00:33:36 +1100 (EST) Received: from localhost ([::1]:42834 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ri4Ud-0004KX-DK for incoming@patchwork.ozlabs.org; Tue, 03 Jan 2012 08:33:31 -0500 Received: from eggs.gnu.org ([140.186.70.92]:34047) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ri4UO-0004Ha-Pb for qemu-devel@nongnu.org; Tue, 03 Jan 2012 08:33:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ri4UK-00044r-Jx for qemu-devel@nongnu.org; Tue, 03 Jan 2012 08:33:16 -0500 Received: from mx1.redhat.com ([209.132.183.28]:37102) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ri4UK-00044g-A2 for qemu-devel@nongnu.org; Tue, 03 Jan 2012 08:33:12 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q03DXBoq008579 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 3 Jan 2012 08:33:11 -0500 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q03DXAgD000526 for ; Tue, 3 Jan 2012 08:33:11 -0500 Received: from s01.tlv.redhat.com (s01.tlv.redhat.com [10.35.255.8]) by cleopatra.tlv.redhat.com (Postfix) with ESMTP id 4D559250B9E; Tue, 3 Jan 2012 15:33:06 +0200 (IST) From: Avi Kivity To: qemu-devel@nongnu.org Date: Tue, 3 Jan 2012 15:32:57 +0200 Message-Id: <1325597577-29385-1-git-send-email-avi@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] vga: optimize ppm_save() divisions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org ppm_save() spends upwards of 50% of its time doing divisions. Replace them with shifts. Signed-off-by: Avi Kivity Reviewed-by: Alon Levy --- 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;