From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9E10F37C114 for ; Thu, 29 Jan 2026 10:01:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.20 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769680869; cv=none; b=blupVeHzyjQLWKChlb0QLLGovqwqiXNezsXy0hhR7KsqNCCwj6/S3fn/VAEWy0YYcfHqVEyeQjrZt8qtlIU3kEz7jz55NcNCPKncgP6fYmAQYCXW6sfV/VIL2JOiUSRLi/wQe3e8MSEAVuiYkiLCX+RqlT8N2bsBMWXlWqpa/3c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769680869; c=relaxed/simple; bh=SqH9AdxR/lHB8viiJnIr2poCQMky6Igt6nCYuv99EBc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jrYNrYgS1PMPjjlvISkXH76eviBCfhKVSC6eCIM5Q1dnNrlFRkX5vOg2RLKk9+zRKtJfkyLmL4iKFQBtptBWDnG9QySn2Vju4bLkGDzA094EZ8tD1JR7Q9V7KkgsM0zTtoNkrP8ZKP/DEpLnYwMXio4jzAoEWqH7GNyrYab61XI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=nyLDpiFT; arc=none smtp.client-ip=198.175.65.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="nyLDpiFT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1769680868; x=1801216868; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=SqH9AdxR/lHB8viiJnIr2poCQMky6Igt6nCYuv99EBc=; b=nyLDpiFTL25OvFoNSpgwaualxiJG8yXw3Z7Vapz03MaSiC+iBDZRjJ/9 I8AlW2eg3CY5uX6F8WRq9BJMYrZerlXlMTjmoz7seY0Ggq4ZHpFSJ47ex wD+ozHhu5yOvxdUlIAQKiOw6tirQxYGVOM6Zvf1IvjiGpOd1FyiIuSC3c M13qshi+rOILnbz9HRW6APLNXG4CsXHkdEcwcA3ATLiuvVs8ZwnCIiUfr 5vXJ8EzHdfXOhUiZMUhdLxznf4y7Zdz9+ox5jn7l07i3xAlCFe9VzwBMU WZGKIi7gXhaso9a+ZeFuu4/ATAGBRByCS0g7lAH8GajY6ww/Vw3DTyyab A==; X-CSE-ConnectionGUID: ckvEvw/JS9+QduNe3ZG4MA== X-CSE-MsgGUID: VzVO+SV1TsmtQOc8xNWR6g== X-IronPort-AV: E=McAfee;i="6800,10657,11685"; a="70630029" X-IronPort-AV: E=Sophos;i="6.21,260,1763452800"; d="scan'208";a="70630029" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jan 2026 02:01:07 -0800 X-CSE-ConnectionGUID: q96kEhegQ5GodER4IxHUhQ== X-CSE-MsgGUID: n0Y7OLBCQQaoEMLmTpwHhw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,260,1763452800"; d="scan'208";a="213400871" Received: from klitkey1-mobl1.ger.corp.intel.com (HELO localhost) ([10.245.245.155]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jan 2026 02:01:01 -0800 Date: Thu, 29 Jan 2026 12:00:59 +0200 From: Andy Shevchenko To: Cristian Ciocaltea Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Sandy Huang , Heiko =?iso-8859-1?Q?St=FCbner?= , Andy Yan , Louis Chauvet , Haneen Mohammed , Melissa Wen , Jani Nikula , Robert Mader , kernel@collabora.com, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, Matt Roper , =?iso-8859-1?Q?N=EDcolas_F=2E_R=2E_A=2E?= Prado , Diederik de Haas Subject: Re: [PATCH v6 2/4] drm: Add CRTC background color property Message-ID: References: <20260129-rk3588-bgcolor-v6-0-c15f755a4055@collabora.com> <20260129-rk3588-bgcolor-v6-2-c15f755a4055@collabora.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo On Thu, Jan 29, 2026 at 11:37:33AM +0200, Andy Shevchenko wrote: > On Thu, Jan 29, 2026 at 02:58:52AM +0200, Cristian Ciocaltea wrote: ... > > +#define __DRM_ARGB64_PREP_BPC(c, shift, bpc)({ \ > > + __u16 mask = __GENMASK((bpc) - 1, 0); \ > > + __u16 conv = __KERNEL_DIV_ROUND_CLOSEST((mask & (c)) * \ > > + __GENMASK(15, 0), mask);\ > > The whole point of the first patch is to use it in the divisions by 2^n - 1. > Can we transform this to make it "divisions" by power-of-two? > > ...: def dbm2(c, bpc): > ...: m = (1 << bpc) - 1 > ...: c1 = m & c > ...: r = c1 << (16 - bpc) > ...: for i in range(1, 16 // bpc): > ...: r = r + (c1 << (16 - (i + 1) * bpc)) > ...: return r I noticed that on some inputs it gives off-by-small-number error. But you got the idea. Taking this into account, perhaps we can share __KERNEL_DIV_ROUND_CLOSEST() anyway and leave it there and improve the situation later on. Up to DRM maintainers. > The above is a Python version of PoC of this approximation. Basically > we transform the fraction X / (2^n - 1) to a chained version of > X / 2^n + X / 2^2n + ... X / 2^kn as derived from recurrent formula > of i+1:th iteration as Xi+1 = Xi / 2^n + Xi / (2^n * (2^n - 1)). > > So, maybe that one should be used instead? (It may be thought through > on how to collapse the for-loop to maybe some bitops, but even with > a for-loop it might be faster than real division.) > > Note, we have some (for sure more than one, I remember the same Q appeared to > me a few years ago) of the examples which may avoid division at all. I would > like to have this macro to be kernel wide (and UAPI seems also okay). > > + __DRM_ARGB64_PREP(conv, shift); \ > > +}) -- With Best Regards, Andy Shevchenko