Commit e5d37823 authored by Rusty Russell's avatar Rusty Russell

alloc: dont clash with libc's fls, avoid void pointer arithmetic

parent 5caaeab8
......@@ -124,7 +124,7 @@ static unsigned long bucket_to_size(unsigned int bucket)
*/
static unsigned int size_to_bucket(unsigned long size)
{
unsigned int base = fls(size/2);
unsigned int base = afls(size/2);
unsigned long overshoot;
overshoot = size - (1UL << base);
......@@ -134,7 +134,7 @@ static unsigned int size_to_bucket(unsigned long size)
static unsigned int small_page_bits(unsigned long poolsize)
{
return fls(poolsize / MAX_SMALL_PAGES - 1);
return afls(poolsize / MAX_SMALL_PAGES - 1);
}
static struct page_header *from_pgnum(struct header *head,
......@@ -313,7 +313,7 @@ static unsigned int find_free_bit(const unsigned long bitmap[])
unsigned int i;
for (i = 0; bitmap[i] == -1UL; i++);
return (i*BITS_PER_LONG) + ffsl(~bitmap[i]) - 1;
return (i*BITS_PER_LONG) + affsl(~bitmap[i]) - 1;
}
/* How many elements can we fit in a page? */
......
......@@ -5,7 +5,7 @@
#include <ccan/ilog/ilog.h>
#include <limits.h>
unsigned int fls(unsigned long val)
unsigned int afls(unsigned long val)
{
BUILD_ASSERT(sizeof(val) == sizeof(u32) || sizeof(val) == sizeof(u64));
if (sizeof(val) == sizeof(u32))
......@@ -15,7 +15,7 @@ unsigned int fls(unsigned long val)
}
/* FIXME: Move to bitops. */
unsigned int ffsl(unsigned long val)
unsigned int affsl(unsigned long val)
{
#if HAVE_BUILTIN_FFSL
/* This is significantly faster! */
......
#ifndef CCAN_ALLOC_BITOPS_H
#define CCAN_ALLOC_BITOPS_H
unsigned int fls(unsigned long val);
unsigned int ffsl(unsigned long val);
unsigned int afls(unsigned long val);
unsigned int affsl(unsigned long val);
unsigned int popcount(unsigned long val);
unsigned long align_up(unsigned long x, unsigned long align);
#endif /* CCAN_ALLOC_BITOPS_H */
......@@ -11,7 +11,7 @@
static int addr_cmp(void **a, void **b)
{
return (*a) - (*b);
return (char *)(*a) - (char *)(*b);
}
static bool unique(void *p[], unsigned int num)
......
......@@ -19,7 +19,7 @@
/* Val is usually offset by MIN_BLOCK_SIZE here. */
static unsigned encode_length(unsigned long val)
{
unsigned int bits = fls(val);
unsigned int bits = afls(val);
/* 5 bits in first byte. */
if (bits <= 5)
return 1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment