* [RFC PATCH v2 0/2] staging: media: atomisp: Refactor bit logic helpers in vmem.c
@ 2025-09-03 9:27 Adrian Barnaś
2025-09-03 9:27 ` [RFC PATCH v2 1/2] staging: media: atomisp: Change name to better follow its behavior Adrian Barnaś
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Adrian Barnaś @ 2025-09-03 9:27 UTC (permalink / raw)
To: Hans de Goede, Mauro Carvalho Chehab, Sakari Ailus,
Andy Shevchenko, Greg Kroah-Hartman, Dan Carpenter, linux-media,
linux-kernel, linux-staging
Cc: Adrian Barnaś
Refactor proposition for bit operation in vmem.c.
* Previous name for function "inv_subword()" for me is not telling what
function acctualy does - it clears bit specified by subword, so renamed
to clear_subword()
* Added a helper to create a proper bitmask for a subword, without using
GENMASK(end-1, start) which was claimed to be unsafe
* Simplified subword() and clear_subword() to be more readable.
Continuation of https://lore.kernel.org/linux-staging/20250902073841.2338568-1-abarnas@google.com/
Adrian Barnaś (2):
staging: media: atomisp: Change name to better follow its behavior
staging: media: atomisp: Simplify logic in vmem.c
.../pci/hive_isp_css_common/host/vmem.c | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
--
2.51.0.355.g5224444f11-goog
^ permalink raw reply [flat|nested] 4+ messages in thread
* [RFC PATCH v2 1/2] staging: media: atomisp: Change name to better follow its behavior
2025-09-03 9:27 [RFC PATCH v2 0/2] staging: media: atomisp: Refactor bit logic helpers in vmem.c Adrian Barnaś
@ 2025-09-03 9:27 ` Adrian Barnaś
2025-09-03 9:27 ` [RFC PATCH v2 2/2] staging: media: atomisp: Simplify logic in vmem.c Adrian Barnaś
2025-09-03 11:07 ` [RFC PATCH v2 0/2] staging: media: atomisp: Refactor bit logic helpers " Andy Shevchenko
2 siblings, 0 replies; 4+ messages in thread
From: Adrian Barnaś @ 2025-09-03 9:27 UTC (permalink / raw)
To: Hans de Goede, Mauro Carvalho Chehab, Sakari Ailus,
Andy Shevchenko, Greg Kroah-Hartman, Dan Carpenter, linux-media,
linux-kernel, linux-staging
Cc: Adrian Barnaś
Change name to clearly states what function does.
Signed-off-by: Adrian Barnaś <abarnas@google.com>
---
.../atomisp/pci/hive_isp_css_common/host/vmem.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/drivers/staging/media/atomisp/pci/hive_isp_css_common/host/vmem.c b/drivers/staging/media/atomisp/pci/hive_isp_css_common/host/vmem.c
index 547cc480c105..a3fe03216389 100644
--- a/drivers/staging/media/atomisp/pci/hive_isp_css_common/host/vmem.c
+++ b/drivers/staging/media/atomisp/pci/hive_isp_css_common/host/vmem.c
@@ -22,9 +22,9 @@ subword(unsigned long long w, unsigned int start, unsigned int end)
return (w & (((1ULL << (end - 1)) - 1) << 1 | 1)) >> start;
}
-/* inverse subword bits move like this: MSB[xxxx____xxxx]LSB -> MSB[xxxx0000xxxx]LSB */
+/* clears subword bits like this: MSB[xxxx____xxxx]LSB -> MSB[xxxx0000xxxx]LSB */
static inline unsigned long long
-inv_subword(unsigned long long w, unsigned int start, unsigned int end)
+clear_subword(unsigned long long w, unsigned int start, unsigned int end)
{
return w & (~(((1ULL << (end - 1)) - 1) << 1 | 1) | ((1ULL << start) - 1));
}
@@ -45,16 +45,16 @@ static void move_subword(unsigned long long *target, unsigned int target_bit,
if (subword_width + start_bit > uedge_bits) { /* overlap */
unsigned long long old_val1;
- unsigned long long old_val0 = inv_subword(target[start_elem],
- start_bit, uedge_bits);
+ unsigned long long old_val0 = clear_subword(target[start_elem],
+ start_bit, uedge_bits);
target[start_elem] = old_val0 | (src_subword << start_bit);
- old_val1 = inv_subword(target[start_elem + 1], 0,
- subword_width + start_bit - uedge_bits);
+ old_val1 = clear_subword(target[start_elem + 1], 0,
+ subword_width + start_bit - uedge_bits);
target[start_elem + 1] = old_val1 | (src_subword >> (uedge_bits - start_bit));
} else {
- unsigned long long old_val = inv_subword(target[start_elem], start_bit,
- start_bit + subword_width);
+ unsigned long long old_val = clear_subword(target[start_elem], start_bit,
+ start_bit + subword_width);
target[start_elem] = old_val | (src_subword << start_bit);
}
--
2.51.0.355.g5224444f11-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [RFC PATCH v2 2/2] staging: media: atomisp: Simplify logic in vmem.c
2025-09-03 9:27 [RFC PATCH v2 0/2] staging: media: atomisp: Refactor bit logic helpers in vmem.c Adrian Barnaś
2025-09-03 9:27 ` [RFC PATCH v2 1/2] staging: media: atomisp: Change name to better follow its behavior Adrian Barnaś
@ 2025-09-03 9:27 ` Adrian Barnaś
2025-09-03 11:07 ` [RFC PATCH v2 0/2] staging: media: atomisp: Refactor bit logic helpers " Andy Shevchenko
2 siblings, 0 replies; 4+ messages in thread
From: Adrian Barnaś @ 2025-09-03 9:27 UTC (permalink / raw)
To: Hans de Goede, Mauro Carvalho Chehab, Sakari Ailus,
Andy Shevchenko, Greg Kroah-Hartman, Dan Carpenter, linux-media,
linux-kernel, linux-staging
Cc: Adrian Barnaś
Add inline helper and simplify logic for subword operations in
pci/hive_isp_css_common/host/vmem.c.
Signed-off-by: Adrian Barnaś <abarnas@google.com>
---
.../media/atomisp/pci/hive_isp_css_common/host/vmem.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/media/atomisp/pci/hive_isp_css_common/host/vmem.c b/drivers/staging/media/atomisp/pci/hive_isp_css_common/host/vmem.c
index a3fe03216389..f11b0448ed83 100644
--- a/drivers/staging/media/atomisp/pci/hive_isp_css_common/host/vmem.c
+++ b/drivers/staging/media/atomisp/pci/hive_isp_css_common/host/vmem.c
@@ -15,18 +15,23 @@
/* Copied from SDK: sim_semantics.c */
+static inline unsigned long long subword_bitmask(unsigned int start, unsigned int end)
+{
+ return GENMASK_ULL(end - 1, 0) & ~(GENMASK_ULL(start, 0) >> 1);
+}
+
/* subword bits move like this: MSB[____xxxx____]LSB -> MSB[00000000xxxx]LSB */
static inline unsigned long long
subword(unsigned long long w, unsigned int start, unsigned int end)
{
- return (w & (((1ULL << (end - 1)) - 1) << 1 | 1)) >> start;
+ return (w & GENMASK_ULL(end - 1, 0)) >> start;
}
/* clears subword bits like this: MSB[xxxx____xxxx]LSB -> MSB[xxxx0000xxxx]LSB */
static inline unsigned long long
clear_subword(unsigned long long w, unsigned int start, unsigned int end)
{
- return w & (~(((1ULL << (end - 1)) - 1) << 1 | 1) | ((1ULL << start) - 1));
+ return w & ~subword_bitmask(start, end);
}
#define uedge_bits (8 * sizeof(unsigned long long))
--
2.51.0.355.g5224444f11-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [RFC PATCH v2 0/2] staging: media: atomisp: Refactor bit logic helpers in vmem.c
2025-09-03 9:27 [RFC PATCH v2 0/2] staging: media: atomisp: Refactor bit logic helpers in vmem.c Adrian Barnaś
2025-09-03 9:27 ` [RFC PATCH v2 1/2] staging: media: atomisp: Change name to better follow its behavior Adrian Barnaś
2025-09-03 9:27 ` [RFC PATCH v2 2/2] staging: media: atomisp: Simplify logic in vmem.c Adrian Barnaś
@ 2025-09-03 11:07 ` Andy Shevchenko
2 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2025-09-03 11:07 UTC (permalink / raw)
To: Adrian Barnaś
Cc: Hans de Goede, Mauro Carvalho Chehab, Sakari Ailus,
Andy Shevchenko, Greg Kroah-Hartman, Dan Carpenter, linux-media,
linux-kernel, linux-staging
On Wed, Sep 03, 2025 at 09:27:52AM +0000, Adrian Barnaś wrote:
> Refactor proposition for bit operation in vmem.c.
> * Previous name for function "inv_subword()" for me is not telling what
> function acctualy does - it clears bit specified by subword, so renamed
> to clear_subword()
> * Added a helper to create a proper bitmask for a subword, without using
> GENMASK(end-1, start) which was claimed to be unsafe
> * Simplified subword() and clear_subword() to be more readable.
>
> Continuation of https://lore.kernel.org/linux-staging/20250902073841.2338568-1-abarnas@google.com/
Thanks for the effort, but I think it's just a tip of the iceberg.
What we really need is to completely rewrite hive_sim_wide_unpack()
and hive_sim_wide_pack(). If we want to preserve arbitrary bit numbers
we ought to use bitmap API rather than that custom approach.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-09-03 11:07 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-03 9:27 [RFC PATCH v2 0/2] staging: media: atomisp: Refactor bit logic helpers in vmem.c Adrian Barnaś
2025-09-03 9:27 ` [RFC PATCH v2 1/2] staging: media: atomisp: Change name to better follow its behavior Adrian Barnaś
2025-09-03 9:27 ` [RFC PATCH v2 2/2] staging: media: atomisp: Simplify logic in vmem.c Adrian Barnaś
2025-09-03 11:07 ` [RFC PATCH v2 0/2] staging: media: atomisp: Refactor bit logic helpers " Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).