Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp3823121pxb; Fri, 11 Feb 2022 08:30:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJwejCaIgPxlKH3gRjn0S5MOQR5vBv9PhXuTmCWKNggWTLyoqvQC6/h1hRgKfSn5SJwhkr6s X-Received: by 2002:a05:6402:354d:: with SMTP id f13mr2771781edd.289.1644597010016; Fri, 11 Feb 2022 08:30:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644597010; cv=none; d=google.com; s=arc-20160816; b=OotPgu3BJigLf06RmeiQowfuBtH8LrluF3OUY11rv7SkePVq/Ec6hmK8nyK8WSxFMi aB2ojCl+32xv0/+a1ELsWpv5Kso04/34EPy+NLSKdQz8Lc3WO2mTsJEkTK5D9SjhtKAr 8HPeqqu8JV/zp9vbFORmlh1+kWbAkW9PkleFcW4IINYiuhHzP69yqfiR4sISB8h9VsG1 piPKD17FUJz8+h8m5R2Nz+iRZ/gfpoL+AIerR44HhAACqKjkHm1A52CJz4Y045ZSdrvq mRS7/rYMfY3+NPaQ60wWu0mxjcXVRiNW7356bGIzlrM4QQNEmZcdrKCS61iafZiuJK0R 9kBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :organization:in-reply-to:subject:cc:to:from:dkim-signature; bh=AHEwkBYe//m+5VXgbYTif2A4AC86fcRrS3M5jNlkUvo=; b=rKaYyICQpsC4w8phBHAHjlEbI7GnhMmBAOvBmtS6oudcqIpo92QcwMLrLOhyVR5iyP twKGFSuCgmdkFuCB+K+AJwaNa2QcVyPoaAqc5RoUvgz/oF/NOCyUISKWtsjVZBqY++jF lHebss55VcaCALohss84c0ud+LHso8azmjjcAV4s8kIF2e5pe++37xErTtjJzlifylwl AKu1NOHPSCXS8rtGwlfSG9Y/suO17CW5xM0S0tO8HZwfnPavHtvuIopBEw8Np0MUc5Fc XW8ZjuQazJtHWMMlilVwKCuc8/8vIctBJ8fMJUCe+f+CXkeAZPguXDxq6MlFdGKAkGsv rKNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="Yk+/i2Vu"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id di5si16351777ejc.743.2022.02.11.08.29.45; Fri, 11 Feb 2022 08:30:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="Yk+/i2Vu"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235216AbiBKMGS (ORCPT + 99 others); Fri, 11 Feb 2022 07:06:18 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:51580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234432AbiBKMGR (ORCPT ); Fri, 11 Feb 2022 07:06:17 -0500 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5866F65; Fri, 11 Feb 2022 04:06:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1644581176; x=1676117176; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=oPJ3HrbBkuSthMTs0EG6JJSdCgStR5rAPs5DdmwBg3c=; b=Yk+/i2VuJC1i8OUxoy1XV8p+tD2QHhzMvAf6SrqtTFYGWnrDrB6gCdgb anhb4py3iX4Gcbav18+Rshi+iardKcZklyEHUNf2fUYDQLh7KpYdfpeZS s8w6R4r/ZCOqj2TVGkfI25VADPus25bfEaml5em2xcDxBQDmWH/gKNebO tVx9r2xCltZi/AtfZpc0kZJIulbnmpc+0hFEVjXIwF4PU7Rz3RdgLjbwz CAj7ROjcDDL25f0l71HLHwTezzkEmOqGp3TPJ6Wc9xSZu+kbtpnYWsyoV NHyPIsFElT4ZzHLVrIe/0IHhAUPm38IJ7oJUP9J6OKBEJFy9OqixC4mcE w==; X-IronPort-AV: E=McAfee;i="6200,9189,10254"; a="313001726" X-IronPort-AV: E=Sophos;i="5.88,360,1635231600"; d="scan'208";a="313001726" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Feb 2022 04:06:02 -0800 X-IronPort-AV: E=Sophos;i="5.88,360,1635231600"; d="scan'208";a="526937460" Received: from rriverox-mobl.ger.corp.intel.com (HELO localhost) ([10.252.19.108]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Feb 2022 04:05:58 -0800 From: Jani Nikula To: Thomas Zimmermann , Andy Shevchenko , Javier Martinez Canillas Cc: linux-fbdev@vger.kernel.org, David Airlie , Daniel Vetter , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Noralf =?utf-8?Q?Tr=C3=B8nnes?= , Geert Uytterhoeven , Maxime Ripard , Sam Ravnborg Subject: Re: [PATCH v4 1/6] drm/format-helper: Add drm_fb_xrgb8888_to_gray8_line() In-Reply-To: <7560cd10-0a7c-3fda-da83-9008833e3901@suse.de> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo References: <20220211091927.2988283-1-javierm@redhat.com> <20220211091927.2988283-2-javierm@redhat.com> <4fa465d9-4fac-4199-9a04-d8e09d164308@redhat.com> <7560cd10-0a7c-3fda-da83-9008833e3901@suse.de> Date: Fri, 11 Feb 2022 14:05:56 +0200 Message-ID: <87pmnt7gm3.fsf@intel.com> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 11 Feb 2022, Thomas Zimmermann wrote: > Hi > > Am 11.02.22 um 12:12 schrieb Andy Shevchenko: >> On Fri, Feb 11, 2022 at 11:40:13AM +0100, Javier Martinez Canillas wrote: >>> On 2/11/22 11:28, Andy Shevchenko wrote: >>>> On Fri, Feb 11, 2022 at 10:19:22AM +0100, Javier Martinez Canillas wrote: >> >> ... >> >>>>> +static void drm_fb_xrgb8888_to_gray8_line(u8 *dst, const u32 *src, unsigned int pixels) >>>>> +{ >>>>> + unsigned int x; >>>>> + >>>>> + for (x = 0; x < pixels; x++) { >>>>> + u8 r = (*src & 0x00ff0000) >> 16; >>>>> + u8 g = (*src & 0x0000ff00) >> 8; >>>>> + u8 b = *src & 0x000000ff; >>>>> + >>>>> + /* ITU BT.601: Y = 0.299 R + 0.587 G + 0.114 B */ >>>>> + *dst++ = (3 * r + 6 * g + b) / 10; >>>>> + src++; >>>>> + } >>>> >>>> Can be done as >>>> >>>> while (pixels--) { >>>> ... >>>> } >>>> >>>> or >>>> >>>> do { >>>> ... >>>> } while (--pixels); >>>> >>> >>> I don't see why a while loop would be an improvement here TBH. >> >> Less letters to parse when reading the code. > > It's a simple refactoring of code that has worked well so far. Let's > leave it as-is for now. IMO *always* prefer a for loop over while or do-while. The for (i = 0; i < N; i++) is such a strong paradigm in C. You instantly know how many times you're going to loop, at a glance. Not so with with the alternatives, which should be used sparingly. And yes, the do-while suggested above is buggy, and you actually need to stop and think to see why. BR, Jani. > > Best regards > Thomas > >> >>> In any case, I just pulled the line conversion logic as a separate >>> function with minimal code changes since doing that should be in a >>> separate patch. >> >> >>> Feel free to post a patch if you want to change that while loop. >> >> Perhaps some day :-) >> -- Jani Nikula, Intel Open Source Graphics Center