staging: media: atomisp: Refactor bit logic helpers in vmem.c
Subsystems (4)
v2 cover staging: media: atomisp: Refactor bit logic helpers in vmem.c
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/[email protected]/
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(-)
Signature · 1 line
2.51.0.355.g5224444f11-goog
RFC PATCH v2 1/2 staging: media: atomisp: Change name to better follow its behavior
Change name to clearly states what function does.
--- .../atomisp/pci/hive_isp_css_common/host/vmem.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/staging/media/atomisp/pci/hive_isp_css_common/host/vmem.c +8 -8
@@ -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); }
Signature · 1 line
2.51.0.355.g5224444f11-goog
Re: [RFC PATCH v2 1/2] staging: media: atomisp: Change name to better follow its behavior
Quoted 1 line · Adrian Barnaś
Change name to clearly states what function does.
The Subject and the body of the commit message should be more specific.
Missing blank line.
Quoted 1 line
Signed-off-by Adrian Barnaś <[email protected]>
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [RFC PATCH v2 1/2] staging: media: atomisp: Change name to better follow its behavior
Hi Andy
Regardless commit message, is the change OK and can post it as a patch, or similarly to second patch it is not worth the effort as it will be refactored at some point?
Quoted 1 line
Change name to clearly states what function does.
Proposed description:
staging: media: atomisp: Rename inv_subword() to clear_subword()
Function inv_subword() does not inverse bits or subword and neither is inverse operation for subword() function. It is used to clear target bits of move_subword operation (specified by start and end-1 indexes). Name clear_subword() explains the function behavior better.
Best Regards
Adrian Barnaś
Quoted 15 lines · Andy Shevchenko
Quoted 1 line · Adrian Barnaś
Change name to clearly states what function does.
The Subject and the body of the commit message should be more specific.
Missing blank line.
Quoted 1 line
Signed-off-by Adrian Barnaś <[email protected]>--
With Best Regards,
Andy Shevchenko
RFC PATCH v2 2/2 staging: media: atomisp: Simplify logic in vmem.c
In reply to Adrian BarnaśAdd inline helper and simplify logic for subword operations in pci/hive_isp_css_common/host/vmem.c.
--- .../media/atomisp/pci/hive_isp_css_common/host/vmem.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/staging/media/atomisp/pci/hive_isp_css_common/host/vmem.c +7 -2
@@ -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))
Signature · 1 line
2.51.0.355.g5224444f11-goog
Quoted 9 lines · 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 toclear_subword()
* Added a helper to create a proper bitmask for a subword, without usingGENMASK(end-1, start)which was claimed to be unsafe
* Simplifiedsubword()andclear_subword()to be more readable.Continuation of https://lore.kernel.org/linux-staging/[email protected]/
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.
Signature · 2 lines
With Best Regards, Andy Shevchenko