From nobody Sun Nov 16 06:31:11 2025 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=1592267821; cv=none; d=zohomail.com; s=zohoarc; b=jyFyDOc2sPGu1BmB8AVVXNV6SE6d4BHOCHLfKOrwIJHkWKt3t9SURPUnMSoFgutJ6aoj9vf24t5TRg2bw3j0mHoOSAFeA4OnuDwdHw9rbshLTW39jhj1sc3alRlBtA8LLWrMxH1HLauwq5EQeKuf975Owb8W3ueGLdZW9ICL168= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592267821; 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=0CN3/Q0nuWlua9fM0ltPpd/K6oWc+TgWCF+lgGY3npA=; b=Uxvemgq8eQVE98XJ6//QXDu1kfQeLAhL3uNEF2UfIYppUMfZuoz/+IDD/IUDj9oukjW8hLmNDQ80tL7bhJC5xC2EXKZuFXlCjUP6vAGEO2nmf+/4ulGMTSaiMxL0EhfaJU/Y9Yw4CGR7b/lPwb6XlneYGf1lgRdKebnb+EcJmr0= 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 1592267821796834.6443415764462; Mon, 15 Jun 2020 17:37:01 -0700 (PDT) Received: from localhost ([::1]:33488 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jkzb2-0006Hd-A3 for importer@patchew.org; Mon, 15 Jun 2020 20:37:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43148) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jkzZr-0004cy-I6 for qemu-devel@nongnu.org; Mon, 15 Jun 2020 20:35:47 -0400 Received: from zero.eik.bme.hu ([152.66.115.2]:46185) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jkzZn-0003td-Mt for qemu-devel@nongnu.org; Mon, 15 Jun 2020 20:35:47 -0400 Received: from zero.eik.bme.hu (blah.eik.bme.hu [152.66.115.182]) by localhost (Postfix) with SMTP id C585E748DD0; Tue, 16 Jun 2020 02:35:40 +0200 (CEST) Received: by zero.eik.bme.hu (Postfix, from userid 432) id 6C4DE7482CE; Tue, 16 Jun 2020 02:35:40 +0200 (CEST) Message-Id: <728903de06f672d4afc9c29827c246027860bfb8.1592266950.git.balaton@eik.bme.hu> In-Reply-To: References: From: BALATON Zoltan Subject: [PATCH v2 4/8] sm501: Introduce variable for commonly used value for better readability Date: Tue, 16 Jun 2020 02:22:30 +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/15 20:35:40 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 3397ca9fbf..282574adec 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