From nobody Sun Feb 8 23:41:53 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1592687556; cv=none; d=zohomail.com; s=zohoarc; b=INnsNF4g1W/lq6GFe0ZA+5t6XXmKp25ivpS9a/UUcfqtYXCy53IPLLs/UFrij4l5/lygRWRxchIC5Uj50F0HPu8qhR1keahlNxUTdGCyeS56DC9xCGJIUcUe7r1FgzkYd62qOQJ7RNoPotQ2OyS/YmIGQs48gPiIqYSud7qL/Yo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592687556; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=MWNDzCc1PbPIqz2IS5AJ0RtKpVsIWgrsb32l58QY9VY=; b=D5TE8ivWxTqWR1WBx+tQw5yLdZz8yh36M7XP3iGAOtT/pZP48jA//m4SHYMLqh/B2LOpmeR6X0jmNmXuy/86wVdvFIbPbiA4VdAhmy74lbofP9sKPR9sLA6pZt7lGtu2KE8H5T0A0L8hMeVJ+F+LemYO3HON5lMJ7kTT8+DZs94= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1592687556647927.4179684832643; Sat, 20 Jun 2020 14:12:36 -0700 (PDT) Received: from localhost ([::1]:40804 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jmkmx-0001CZ-7Y for importer@patchew.org; Sat, 20 Jun 2020 17:12:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53422) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmkfO-0005Gf-81 for qemu-devel@nongnu.org; Sat, 20 Jun 2020 17:04:46 -0400 Received: from zero.eik.bme.hu ([152.66.115.2]:31473) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmkfL-0001g8-8s for qemu-devel@nongnu.org; Sat, 20 Jun 2020 17:04:45 -0400 Received: from zero.eik.bme.hu (blah.eik.bme.hu [152.66.115.182]) by localhost (Postfix) with SMTP id 2A2A1748DDF; Sat, 20 Jun 2020 23:04:33 +0200 (CEST) Received: by zero.eik.bme.hu (Postfix, from userid 432) id CEB7B748DC8; Sat, 20 Jun 2020 23:04:32 +0200 (CEST) Message-Id: In-Reply-To: References: From: BALATON Zoltan Subject: [PATCH v3 4/9] sm501: Introduce variable for commonly used value for better readability Date: Sat, 20 Jun 2020 22:56:28 +0200 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: qemu-devel@nongnu.org X-Spam-Probability: 8% Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=152.66.115.2; envelope-from=balaton@eik.bme.hu; helo=zero.eik.bme.hu X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/20 17:04:33 X-ACL-Warn: Detected OS = FreeBSD 9.x or newer [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Sebastian Bauer , Magnus Damm , Gerd Hoffmann , Aurelien Jarno Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The bytes per pixel value can be calculated from format but it's used freqently enough (and will be used more in subseqent patches) so store it in a variable for better readabilty. Also drop some unneded 0x prefix around where new variable is defined. Signed-off-by: BALATON Zoltan Reviewed-by: Peter Maydell --- hw/display/sm501.c | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/hw/display/sm501.c b/hw/display/sm501.c index ad5a62bfab..3ced2c42db 100644 --- a/hw/display/sm501.c +++ b/hw/display/sm501.c @@ -684,10 +684,11 @@ static void sm501_2d_operation(SM501State *s) { int cmd =3D (s->twoD_control >> 16) & 0x1F; int rtl =3D s->twoD_control & BIT(27); - int format =3D (s->twoD_stretch >> 20) & 0x3; - int rop_mode =3D (s->twoD_control >> 15) & 0x1; /* 1 for rop2, else ro= p3 */ + int format =3D (s->twoD_stretch >> 20) & 3; + int bypp =3D 1 << format; /* bytes per pixel */ + int rop_mode =3D (s->twoD_control >> 15) & 1; /* 1 for rop2, else rop3= */ /* 1 if rop2 source is the pattern, otherwise the source is the bitmap= */ - int rop2_source_is_pattern =3D (s->twoD_control >> 14) & 0x1; + int rop2_source_is_pattern =3D (s->twoD_control >> 14) & 1; int rop =3D s->twoD_control & 0xFF; unsigned int dst_x =3D (s->twoD_destination >> 16) & 0x01FFF; unsigned int dst_y =3D s->twoD_destination & 0xFFFF; @@ -724,8 +725,8 @@ static void sm501_2d_operation(SM501State *s) } =20 if (dst_base >=3D get_local_mem_size(s) || - dst_base + (dst_x + width + (dst_y + height) * dst_pitch) * - (1 << format) >=3D get_local_mem_size(s)) { + dst_base + (dst_x + width + (dst_y + height) * dst_pitch) * bypp >= =3D + get_local_mem_size(s)) { qemu_log_mask(LOG_GUEST_ERROR, "sm501: 2D op dest is outside vram.= \n"); return; } @@ -750,8 +751,8 @@ static void sm501_2d_operation(SM501State *s) } =20 if (src_base >=3D get_local_mem_size(s) || - src_base + (src_x + width + (src_y + height) * src_pitch) * - (1 << format) >=3D get_local_mem_size(s)) { + src_base + (src_x + width + (src_y + height) * src_pitch) * by= pp >=3D + get_local_mem_size(s)) { qemu_log_mask(LOG_GUEST_ERROR, "sm501: 2D op src is outside vram.\n"); return; @@ -763,8 +764,8 @@ static void sm501_2d_operation(SM501State *s) uint8_t *d =3D s->local_mem + dst_base; =20 for (y =3D 0; y < height; y++) { - i =3D (dst_x + (dst_y + y) * dst_pitch) * (1 << format); - for (x =3D 0; x < width; x++, i +=3D (1 << format)) { + i =3D (dst_x + (dst_y + y) * dst_pitch) * bypp; + for (x =3D 0; x < width; x++, i +=3D bypp) { switch (format) { case 0: d[i] =3D ~d[i]; @@ -801,7 +802,7 @@ static void sm501_2d_operation(SM501State *s) de =3D db + width + height * (width + dst_pitch); if (rtl && ((db >=3D sb && db <=3D se) || (de >=3D sb && de <= =3D se))) { /* regions may overlap: copy via temporary */ - int llb =3D width * (1 << format); + int llb =3D width * bypp; int tmp_stride =3D DIV_ROUND_UP(llb, sizeof(uint32_t)); uint32_t *tmp =3D tmp_buf; =20 @@ -809,13 +810,13 @@ static void sm501_2d_operation(SM501State *s) tmp =3D g_malloc(tmp_stride * sizeof(uint32_t) * heigh= t); } pixman_blt((uint32_t *)&s->local_mem[src_base], tmp, - src_pitch * (1 << format) / sizeof(uint32_t), - tmp_stride, 8 * (1 << format), 8 * (1 << format= ), + src_pitch * bypp / sizeof(uint32_t), + tmp_stride, 8 * bypp, 8 * bypp, src_x, src_y, 0, 0, width, height); pixman_blt(tmp, (uint32_t *)&s->local_mem[dst_base], tmp_stride, - dst_pitch * (1 << format) / sizeof(uint32_t), - 8 * (1 << format), 8 * (1 << format), + dst_pitch * bypp / sizeof(uint32_t), + 8 * bypp, 8 * bypp, 0, 0, dst_x, dst_y, width, height); if (tmp !=3D tmp_buf) { g_free(tmp); @@ -823,9 +824,9 @@ static void sm501_2d_operation(SM501State *s) } else { pixman_blt((uint32_t *)&s->local_mem[src_base], (uint32_t *)&s->local_mem[dst_base], - src_pitch * (1 << format) / sizeof(uint32_t), - dst_pitch * (1 << format) / sizeof(uint32_t), - 8 * (1 << format), 8 * (1 << format), + src_pitch * bypp / sizeof(uint32_t), + dst_pitch * bypp / sizeof(uint32_t), + 8 * bypp, 8 * bypp, src_x, src_y, dst_x, dst_y, width, height); } } @@ -842,8 +843,8 @@ static void sm501_2d_operation(SM501State *s) } =20 pixman_fill((uint32_t *)&s->local_mem[dst_base], - dst_pitch * (1 << format) / sizeof(uint32_t), - 8 * (1 << format), dst_x, dst_y, width, height, color); + dst_pitch * bypp / sizeof(uint32_t), + 8 * bypp, dst_x, dst_y, width, height, color); break; } default: @@ -855,7 +856,7 @@ static void sm501_2d_operation(SM501State *s) if (dst_base >=3D get_fb_addr(s, crt) && dst_base <=3D get_fb_addr(s, crt) + fb_len) { int dst_len =3D MIN(fb_len, ((dst_y + height - 1) * dst_pitch + - dst_x + width) * (1 << format)); + dst_x + width) * bypp); if (dst_len) { memory_region_set_dirty(&s->local_mem_region, dst_base, dst_le= n); } --=20 2.21.3