Skip to contentSkip to conversation

lib: sbi_scratch: Optimize the alignment code for alloc size

PATCH New Xiang W 2 participants 2 messages Mar 9, 2023 – Apr 6, 2023

lore
Share & tools
lore

Xiang W

author
#0 lore raw

PATCH v2 1/1 lib: sbi_scratch: Optimize the alignment code for alloc size

---
Changes in v2:
- Added type conversion as suggested by Andreas Schwab to prevent errors when extending sign bits

 lib/sbi/sbi_scratch.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/sbi/sbi_scratch.c +2 -2
index 87b34c6..55ebdbb 100644
@@ -59,8 +59,8 @@ unsigned long sbi_scratch_alloc_offset(unsigned long size)
 	if (!size)
 		return 0;
 
-	if (size & (__SIZEOF_POINTER__ - 1))
-		size = (size & ~(__SIZEOF_POINTER__ - 1)) + __SIZEOF_POINTER__;
+	size += __SIZEOF_POINTER__ - 1;
+	size &= ~((unsigned long)__SIZEOF_POINTER__ - 1);
 
 	spin_lock(&extra_lock);
 
Signature · 1 line
2.39.2
Applied
#1 lore raw

PATCH v2 1/1 lib: sbi_scratch: Optimize the alignment code for alloc size

Quoted 2 lines · On Thu, Mar 9, 2023 at 4:57?PM Xiang W <[email protected]> wrote:

Looks good to me.

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

Quoted 31 lines

---
Changes in v2:
- Added type conversion as suggested by Andreas Schwab to prevent errors when extending sign bits

 lib/sbi/sbi_scratch.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/sbi/sbi_scratch.c +2 -3
index 87b34c6..55ebdbb 100644
@@ -59,8 +59,8 @@ unsigned long sbi_scratch_alloc_offset(unsigned long size)
        if (!size)
                return 0;
 
-       if (size & (__SIZEOF_POINTER__ - 1))
-               size = (size & ~(__SIZEOF_POINTER__ - 1)) + __SIZEOF_POINTER__;
+       size += __SIZEOF_POINTER__ - 1;
+       size &= ~((unsigned long)__SIZEOF_POINTER__ - 1);
 
        spin_lock(&extra_lock);
 
--

2.39.2

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi