summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libc/stdlib/malloc.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/lib/libc/stdlib/malloc.c b/src/lib/libc/stdlib/malloc.c
index c4196c74ed..04f211c4ef 100644
--- a/src/lib/libc/stdlib/malloc.c
+++ b/src/lib/libc/stdlib/malloc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: malloc.c,v 1.285 2023/06/04 06:58:33 otto Exp $ */ 1/* $OpenBSD: malloc.c,v 1.286 2023/06/07 12:56:22 aoyama Exp $ */
2/* 2/*
3 * Copyright (c) 2008, 2010, 2011, 2016, 2023 Otto Moerbeek <otto@drijf.net> 3 * Copyright (c) 2008, 2010, 2011, 2016, 2023 Otto Moerbeek <otto@drijf.net>
4 * Copyright (c) 2012 Matthew Dempsky <matthew@openbsd.org> 4 * Copyright (c) 2012 Matthew Dempsky <matthew@openbsd.org>
@@ -988,12 +988,32 @@ err:
988 return NULL; 988 return NULL;
989} 989}
990 990
991#if defined(__GNUC__) && __GNUC__ < 4
992static inline unsigned int
993lb(u_int x)
994{
995#if defined(__m88k__)
996 __asm__ __volatile__ ("ff1 %0, %0" : "=r" (x) : "0" (x));
997 return x;
998#else
999 /* portable version */
1000 unsigned int count = 0;
1001 while ((x & (1U << (sizeof(int) * CHAR_BIT - 1))) == 0) {
1002 count++;
1003 x <<= 1;
1004 }
1005 return (sizeof(int) * CHAR_BIT - 1) - count;
1006#endif
1007}
1008#else
1009/* using built-in function version */
991static inline unsigned int 1010static inline unsigned int
992lb(u_int x) 1011lb(u_int x)
993{ 1012{
994 /* I need an extension just for integer-length (: */ 1013 /* I need an extension just for integer-length (: */
995 return (sizeof(int) * CHAR_BIT - 1) - __builtin_clz(x); 1014 return (sizeof(int) * CHAR_BIT - 1) - __builtin_clz(x);
996} 1015}
1016#endif
997 1017
998/* https://pvk.ca/Blog/2015/06/27/linear-log-bucketing-fast-versatile-simple/ 1018/* https://pvk.ca/Blog/2015/06/27/linear-log-bucketing-fast-versatile-simple/
999 via Tony Finch */ 1019 via Tony Finch */