Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp5560450pxb; Mon, 14 Feb 2022 01:57:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJzicKQ+6gCJbam7hnqvwYUaiefoPZkrAz01qJSoKDe4r6H+FW5+LkzEswGDWFjNl53hYI8+ X-Received: by 2002:a17:906:6499:: with SMTP id e25mr10805286ejm.557.1644832650053; Mon, 14 Feb 2022 01:57:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644832650; cv=none; d=google.com; s=arc-20160816; b=Il41tpwBEsedISWPW5UrULSKdIhJqX3cYEcRl2DylCp2tI4fIAbgiYRX5MARZlvgtP M5sKHoetPX9inLAw6lapEyw/T+nlatmk/EMs6KrUZ/t28Shb6HicgwUHtK/DjHNe1dOr z7faM08BLwsFYWR8eOF8FEgUEgFbpJZO++m7D85q7dMKtbikvtwDmBq7XDBBNvpvlznr RL4SddPBLFV2H9oSgVBUf2dpZ40/p2kwFGehQTv7+LO0u5DfBGhr/w2XEXUhcX8n7ytu LIUe1IYueB7XvAE3wto/d9qWSpY8oJXY1dYMt+iEo9xLXfL8Bt/GWVgUYUavEsr6/W23 wGEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=l9h0FTYLGGXap1dzR54tfKoCeVF0BWZXnPqUVsNDnPk=; b=EH0lUoIXEhjMnH3AfISYKS1hAJof34oReo+sRWXDAzRuDWPKhjZIeKYM1+dqsks7n9 l8IwQZLpujGeXBu8FIPzpGFCOCi8Qi1hprnNQIYJflPSDviKbReKDf/at/HoO3c/Hrne 9VQEwmGEhx1XsaS61jXD0pApBXOUv6feBF+uoQeuot21nFg0+CPsUnBBgo7B0a1SK8ow c3rdNC/aIk4cKYREBlvySIEo52Z/Rxy5SzUcB3oerHsJoa6FmcLc+mVOogEmHvze9TMi y2db0DPWpOiT4RDUVUI2oqX05Rl9XbIdrrIcIVqPI2M+x4iv0hNyvm0HSRhgfrKUIMfA IJlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=DkvwKpBh; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id da15si3748857edb.462.2022.02.14.01.57.07; Mon, 14 Feb 2022 01:57:30 -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=@gmail.com header.s=20210112 header.b=DkvwKpBh; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242785AbiBNJR2 (ORCPT + 99 others); Mon, 14 Feb 2022 04:17:28 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:34920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242772AbiBNJRY (ORCPT ); Mon, 14 Feb 2022 04:17:24 -0500 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CC00606E8; Mon, 14 Feb 2022 01:17:16 -0800 (PST) Received: by mail-lf1-x12b.google.com with SMTP id b11so4555358lfb.12; Mon, 14 Feb 2022 01:17:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version; bh=l9h0FTYLGGXap1dzR54tfKoCeVF0BWZXnPqUVsNDnPk=; b=DkvwKpBhCufekGCIS5SQfzSw8JRCD5NCeSGrPcE9I6Po6jAmlGlUzZTeRka4A91X60 WnIiBro4xCKDtdUeNalV6JEU2KSM7JzyWIDz4kmSW0BYHi87Aqj7vd+2tIfxTxbPI8/g 05+r82GG9u8cYov5oGUZfMDtob2UsCFFcMsK6emvgWvxIF6P/dZ6LeVk8X0xOxPSHI2H Pmy9A0dKDxP2VvsVsUl1WxfxR1xUqhPN3W4dcIGjgB11vReOpgnFmr52Ykl7CtJUhJSU wJ/pXLQ0Qerjqyqj8Adelkp0i1Fe2B3PmlXGpgQ6RgBaa0P8LA2jh0FKg9c1VcymaSUL 0OZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version; bh=l9h0FTYLGGXap1dzR54tfKoCeVF0BWZXnPqUVsNDnPk=; b=LnogE/cXsms1fYnlNRGbV+3WMxV6i4qObd/lDIylO/kK7xyf3dynX2KpQsCxzE4izo Ab6BBJOc9liCD7Jyzq4/KUmhHMd5o1c9CzmSQigZeCxbbiSCMzKhm9s8Ptq4+RlWuhIe 8PtycnS+PnRjEC3UsAy84lCoMGhdimFsa03FuPhms3qYZTfZzYi0PJpA+V+EWEwbYZUB Hep6Mf6mR0d3ZLsBHR7mcvIfGQ9nzXTccQZ2cSOR9gr0f7ItZsXyhRNULuIiZHWUMNHP cOZ3WjKRzRcbPcbq0za2xhA6JNYppXnOlS3Cgny+0wTdVRPYJEH3KGSNaVZHgU4YQwBs v1RA== X-Gm-Message-State: AOAM5335hrGRsmY1dC4HhDOn4aN7B4vSVRKLyudXspskwsc0nREAbc+Z xlHYm2+0zE9erG4FpUTBvVE= X-Received: by 2002:a05:6512:39c4:: with SMTP id k4mr10352957lfu.69.1644830234620; Mon, 14 Feb 2022 01:17:14 -0800 (PST) Received: from eldfell ([194.136.85.206]) by smtp.gmail.com with ESMTPSA id v6sm4049956lfq.181.2022.02.14.01.17.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Feb 2022 01:17:14 -0800 (PST) Date: Mon, 14 Feb 2022 11:17:11 +0200 From: Pekka Paalanen To: Andy Shevchenko Cc: Jani Nikula , linux-fbdev@vger.kernel.org, David Airlie , Daniel Vetter , Javier Martinez Canillas , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Noralf =?UTF-8?B?VHLDuG5uZXM=?= , Geert Uytterhoeven , Maxime Ripard , Thomas Zimmermann , Sam Ravnborg Subject: Re: [PATCH v4 1/6] drm/format-helper: Add drm_fb_xrgb8888_to_gray8_line() Message-ID: <20220214111711.6536b4b6@eldfell> In-Reply-To: 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> <87pmnt7gm3.fsf@intel.com> <87fsop74lu.fsf@intel.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: multipart/signed; boundary="Sig_/4exzfizoYWTXAR0xVEcWx0+"; protocol="application/pgp-signature"; micalg=pgp-sha256 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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 --Sig_/4exzfizoYWTXAR0xVEcWx0+ Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable On Fri, 11 Feb 2022 19:27:12 +0200 Andy Shevchenko wrote: > On Fri, Feb 11, 2022 at 06:25:17PM +0200, Jani Nikula wrote: > > On Fri, 11 Feb 2022, Andy Shevchenko wrote: =20 > > > On Fri, Feb 11, 2022 at 02:05:56PM +0200, Jani Nikula wrote: =20 > > >> On Fri, 11 Feb 2022, Thomas Zimmermann wrote: = =20 > > >> > Am 11.02.22 um 12:12 schrieb Andy Shevchenko: =20 > > >> >> On Fri, Feb 11, 2022 at 11:40:13AM +0100, Javier Martinez Canilla= s wrote: =20 > > >> >>> On 2/11/22 11:28, Andy Shevchenko wrote: =20 > > >> >>>> On Fri, Feb 11, 2022 at 10:19:22AM +0100, Javier Martinez Canil= las wrote: =20 > > > > > > ... > > > =20 > > >> >>>>> +static void drm_fb_xrgb8888_to_gray8_line(u8 *dst, const u32 = *src, unsigned int pixels) > > >> >>>>> +{ > > >> >>>>> + unsigned int x; > > >> >>>>> + > > >> >>>>> + for (x =3D 0; x < pixels; x++) { > > >> >>>>> + u8 r =3D (*src & 0x00ff0000) >> 16; > > >> >>>>> + u8 g =3D (*src & 0x0000ff00) >> 8; > > >> >>>>> + u8 b =3D *src & 0x000000ff; > > >> >>>>> + > > >> >>>>> + /* ITU BT.601: Y =3D 0.299 R + 0.587 G + 0.114 B */ > > >> >>>>> + *dst++ =3D (3 * r + 6 * g + b) / 10; > > >> >>>>> + src++; > > >> >>>>> + } =20 > > >> >>>> > > >> >>>> Can be done as > > >> >>>> > > >> >>>> while (pixels--) { > > >> >>>> ... > > >> >>>> } > > >> >>>> > > >> >>>> or > > >> >>>> > > >> >>>> do { > > >> >>>> ... > > >> >>>> } while (--pixels); > > >> >>>> =20 > > >> >>> > > >> >>> I don't see why a while loop would be an improvement here TBH. = =20 > > >> >>=20 > > >> >> Less letters to parse when reading the code. =20 > > >> > > > >> > It's a simple refactoring of code that has worked well so far. Let= 's=20 > > >> > leave it as-is for now. =20 > > >>=20 > > >> IMO *always* prefer a for loop over while or do-while. > > >>=20 > > >> The for (i =3D 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. =20 > > > > > > while () {} _is_ a paradigm, for-loop is syntax sugar on top of it. = =20 > >=20 > > And while() is just syntax sugar for goto. :p > >=20 > > The for loop written as for (i =3D 0; i < N; i++) is hands down the most > > obvious counting loop pattern there is in C. > > =20 > > >> And yes, the do-while suggested above is buggy, and you actually nee= d to > > >> stop and think to see why. =20 > > > > > > It depends if pixels can be 0 or not and if it's not, then does it co= ntain last > > > or number. > > > > > > The do {} while (--pixels); might be buggy iff pixels may be 0. =20 > >=20 > > Yeah. And how long does it take to figure that out? =20 >=20 > Okay, I made a mistake to drop the explanation. So, I (mistakenly) assumed > that people know this difference between post-decrement and pre-decrement > (note, while-loop here is not what is problematic). That was not the question. The question was, how long does it take to figure out if pixels can or cannot be zero? Code is styled for humans other than the author, not for compilers. Having to stop to think about the difference between post- and pre-decrement to figure out when the while-loop runs does take me a few more brain cycles to understand, even though I know the rules very well. I would call that brain cycle optimization, and leave the CPU cycle optimization for the compiler in these cases. Thanks, pq --Sig_/4exzfizoYWTXAR0xVEcWx0+ Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEJQjwWQChkWOYOIONI1/ltBGqqqcFAmIKHhcACgkQI1/ltBGq qqdGXQ/8Ce5+VDdFo8ZqWQRABxsfdcoBZkUB3cRRRD8YTXpIMW1qCfd4hY4Pc/XL JacypoitZ/9Oy9pctixUmmle4U9J9e1mXtkS5IGbCaZpGq/TkeGBHBQ8IuObt00r PzjKU7dkAsGHrWqKfozMegK/h/upIaGrO3Q24TtRu6mlKGQGMq2eeIJ1bl9XI36C DEgHzqM6vWkYk6nIDNNSiQmltdHlzWm2CfTsqe5tVTNvYKTO/zqKkOfJ21PY3LNX bl8IO+E7RPGGzBs0VV1W+AbgF8ZPX8YmHLjfRjYAk5jWARcMr2Cz4cKqB5GIo/sw YUabXM4dsnxBrPXDMyHgg+nwZXbQrdW0Vizn6JwPTUxQJWQ0arjewgUJv5YLygB+ eDO/PoBaKU7rbh/ybaTmF06wVan7nDxD8sw8spNrAqb5+u7Lwt2v9ZwMenqrAC0s z/wrKFN91apZcuVMPWnskdktdl0dJJ2ZeyqDOXHdXa9mkIrqZ1cM5wBgfStonlbg d4g9I0Tmct/S4WuphGO4NCLm7vPahH0UtKqvWiK2K3DZVJf8rAOp6ePu4zKKMu80 0pnrdhbzTtDiDJb0RGPGDQQ1Y08BS213Uc0gI11TQu2MEMaofvpptUsxXqqcr41H aSvDOqtOg42lKNTjHTfKOpObwScIrtRB7zPkr0kmOQxg3WZ00hc= =NCW9 -----END PGP SIGNATURE----- --Sig_/4exzfizoYWTXAR0xVEcWx0+--