OpenSBI Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] lib: sbi_scratch: Optimize the alignment code for alloc size
@ 2023-03-09  9:46 Xiang W
  2023-03-09  9:57 ` Andreas Schwab
  0 siblings, 1 reply; 2+ messages in thread
From: Xiang W @ 2023-03-09  9:46 UTC (permalink / raw)
  To: opensbi

Signed-off-by: Xiang W <wxjstz@126.com>
---
 lib/sbi/sbi_scratch.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/lib/sbi/sbi_scratch.c b/lib/sbi/sbi_scratch.c
index 87b34c6..ea62105 100644
--- a/lib/sbi/sbi_scratch.c
+++ b/lib/sbi/sbi_scratch.c
@@ -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);
 
-- 
2.39.2



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH] lib: sbi_scratch: Optimize the alignment code for alloc size
  2023-03-09  9:46 [PATCH] lib: sbi_scratch: Optimize the alignment code for alloc size Xiang W
@ 2023-03-09  9:57 ` Andreas Schwab
  0 siblings, 0 replies; 2+ messages in thread
From: Andreas Schwab @ 2023-03-09  9:57 UTC (permalink / raw)
  To: opensbi

On M?r 09 2023, Xiang W wrote:

> +	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.

-- 
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."


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-03-09  9:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-09  9:46 [PATCH] lib: sbi_scratch: Optimize the alignment code for alloc size Xiang W
2023-03-09  9:57 ` Andreas Schwab

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox