Skip to contentSkip to conversation

lib: sbi_scratch: Optimize the alignment code for alloc size

PATCH Superseded Xiang W 2 participants 2 messages Mar 9, 2023

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Xiang W

author
#0 lore raw

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

---
 lib/sbi/sbi_scratch.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
lib/sbi/sbi_scratch.c +1 -2
index 87b34c6..ea62105 100644
@@ -59,8 +59,7 @@ 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 = (size + __SIZEOF_POINTER__ - 1) & ~(__SIZEOF_POINTER__ - 1);
 
 	spin_lock(&extra_lock);
 
Signature · 1 line
2.39.2
#1 lore raw

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

lib/sbi/sbi_scratch.c unsigned long sbi_scratch_alloc_offset(unsigned long size) · line 62

Quoted 1 line · Xiang W
lib/sbi/sbi_scratch.c +1 -0
+	size = (size + __SIZEOF_POINTER__ - 1) & ~(__SIZEOF_POINTER__ - 1);

It is probably more robust to convert (__SIZEOF_POINTER__ - 1) to unsigned long before inverting. This currently depends on the fact that ~(__SIZEOF_POINTER__ - 1) is a signed int, and thus sign extended, to work correctly.

Signature · 3 lines
Andreas Schwab, SUSE Labs, schwab at suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."