From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
Cc: "Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
"Maxime Ripard" <mripard@kernel.org>,
"Thomas Zimmermann" <tzimmermann@suse.de>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Sandy Huang" <hjc@rock-chips.com>,
"Heiko Stübner" <heiko@sntech.de>,
"Andy Yan" <andy.yan@rock-chips.com>,
"Louis Chauvet" <louis.chauvet@bootlin.com>,
"Haneen Mohammed" <hamohammed.sa@gmail.com>,
"Melissa Wen" <melissa.srw@gmail.com>,
"Jani Nikula" <jani.nikula@linux.intel.com>,
"Robert Mader" <robert.mader@collabora.com>,
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" <matthew.d.roper@intel.com>,
"Nícolas F. R. A. Prado" <nfraprado@collabora.com>,
"Diederik de Haas" <diederik@cknow-tech.com>
Subject: Re: [PATCH v6 2/4] drm: Add CRTC background color property
Date: Thu, 29 Jan 2026 12:00:59 +0200 [thread overview]
Message-ID: <aXsv200DLo6ssao2@smile.fi.intel.com> (raw)
In-Reply-To: <aXsp2s5a7sJL7Itp@smile.fi.intel.com>
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
WARNING: multiple messages have this Message-ID (diff)
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
Cc: "Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
"Maxime Ripard" <mripard@kernel.org>,
"Thomas Zimmermann" <tzimmermann@suse.de>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Sandy Huang" <hjc@rock-chips.com>,
"Heiko Stübner" <heiko@sntech.de>,
"Andy Yan" <andy.yan@rock-chips.com>,
"Louis Chauvet" <louis.chauvet@bootlin.com>,
"Haneen Mohammed" <hamohammed.sa@gmail.com>,
"Melissa Wen" <melissa.srw@gmail.com>,
"Jani Nikula" <jani.nikula@linux.intel.com>,
"Robert Mader" <robert.mader@collabora.com>,
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" <matthew.d.roper@intel.com>,
"Nícolas F. R. A. Prado" <nfraprado@collabora.com>,
"Diederik de Haas" <diederik@cknow-tech.com>
Subject: Re: [PATCH v6 2/4] drm: Add CRTC background color property
Date: Thu, 29 Jan 2026 12:00:59 +0200 [thread overview]
Message-ID: <aXsv200DLo6ssao2@smile.fi.intel.com> (raw)
In-Reply-To: <aXsp2s5a7sJL7Itp@smile.fi.intel.com>
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
_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip
next prev parent reply other threads:[~2026-01-29 10:01 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-29 0:58 [PATCH v6 0/4] Introduce BACKGROUND_COLOR DRM CRTC property Cristian Ciocaltea
2026-01-29 0:58 ` Cristian Ciocaltea
2026-01-29 0:58 ` [PATCH v6 1/4] uapi: Provide DIV_ROUND_CLOSEST() Cristian Ciocaltea
2026-01-29 0:58 ` Cristian Ciocaltea
2026-01-29 0:58 ` [PATCH v6 2/4] drm: Add CRTC background color property Cristian Ciocaltea
2026-01-29 0:58 ` Cristian Ciocaltea
2026-01-29 9:37 ` Andy Shevchenko
2026-01-29 9:37 ` Andy Shevchenko
2026-01-29 10:00 ` Andy Shevchenko [this message]
2026-01-29 10:00 ` Andy Shevchenko
2026-02-04 20:32 ` Cristian Ciocaltea
2026-02-04 20:32 ` Cristian Ciocaltea
2026-02-04 21:10 ` Andy Shevchenko
2026-02-04 21:10 ` Andy Shevchenko
2026-01-29 0:58 ` [PATCH v6 3/4] drm/vkms: Support setting custom background color Cristian Ciocaltea
2026-01-29 0:58 ` Cristian Ciocaltea
2026-01-29 0:58 ` [PATCH v6 4/4] drm/rockchip: vop2: " Cristian Ciocaltea
2026-01-29 0:58 ` Cristian Ciocaltea
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aXsv200DLo6ssao2@smile.fi.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=airlied@gmail.com \
--cc=andy.yan@rock-chips.com \
--cc=cristian.ciocaltea@collabora.com \
--cc=diederik@cknow-tech.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=hamohammed.sa@gmail.com \
--cc=heiko@sntech.de \
--cc=hjc@rock-chips.com \
--cc=jani.nikula@linux.intel.com \
--cc=kernel@collabora.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=louis.chauvet@bootlin.com \
--cc=maarten.lankhorst@linux.intel.com \
--cc=matthew.d.roper@intel.com \
--cc=melissa.srw@gmail.com \
--cc=mripard@kernel.org \
--cc=nfraprado@collabora.com \
--cc=robert.mader@collabora.com \
--cc=simona@ffwll.ch \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.