Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 0 additions & 56 deletions so3/so3/arch/arm32/include/asm/utils.h

This file was deleted.

56 changes: 0 additions & 56 deletions so3/so3/arch/arm64/include/asm/utils.h

This file was deleted.

69 changes: 1 addition & 68 deletions so3/so3/include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <compiler.h>
#include <printk.h>
#include <string.h>
#include <math.h>

#endif /* __ASSEMBLY__ */

Expand All @@ -49,30 +50,6 @@
extern addr_t __end[];
extern addr_t __stack_bottom[];

#define DIV_ROUND_CLOSEST(x, divisor) \
({ \
typeof(x) __x = x; \
typeof(divisor) __d = divisor; \
(((typeof(x)) -1) > 0 || ((typeof(divisor)) -1) > 0 || (__x) > 0) ? (((__x) + ((__d) / 2)) / (__d)) : \
(((__x) - ((__d) / 2)) / (__d)); \
})

#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))

#define max(a, b) \
({ \
typeof(a) _a = a; \
typeof(b) _b = b; \
_a > _b ? _a : _b; \
})

#define min(a, b) \
({ \
typeof(a) _a = a; \
typeof(b) _b = b; \
_a < _b ? _a : _b; \
})

/**
* container_of - cast a member of a structure out to the containing structure
*
Expand Down Expand Up @@ -138,24 +115,6 @@ extern boot_stage_t boot_stage;
extern uint32_t origin_cpu;

extern void __backtrace(void);
/*
* ..and if you can't take the strict
* types, you can specify one yourself.
*
* Or not use min/max at all, of course.
*/
#define min_t(type, x, y) \
({ \
type __x = (x); \
type __y = (y); \
__x < __y ? __x : __y; \
})
#define max_t(type, x, y) \
({ \
type __x = (x); \
type __y = (y); \
__x > __y ? __x : __y; \
})

/*
* Check at compile time that something is of a particular type.
Expand All @@ -169,32 +128,6 @@ extern void __backtrace(void);
1; \
})

/*
* This looks more complex than it should be. But we need to
* get the type for the ~ right in round_down (it needs to be
* as wide as the result!), and we want to evaluate the macro
* arguments just once each.
*/
#define __round_mask(x, y) ((__typeof__(x)) ((y) - 1))
/**
* round_up - round up to next specified power of 2
* @x: the value to round
* @y: multiple to round up to (must be a power of 2)
*
* Rounds @x up to next multiple of @y (which must be a power of 2).
* To perform arbitrary rounding up, use roundup() below.
*/
#define round_up(x, y) ((((x) - 1) | __round_mask(x, y)) + 1)
/**
* round_down - round down to next specified power of 2
* @x: the value to round
* @y: multiple to round down to (must be a power of 2)
*
* Rounds @x down to next multiple of @y (which must be a power of 2).
* To perform arbitrary rounding down, use rounddown() below.
*/
#define round_down(x, y) ((x) & ~__round_mask(x, y))

#endif /* __ASSEMBLY__ */

#endif /* COMMON_H */
107 changes: 107 additions & 0 deletions so3/so3/include/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,77 @@

#include <types.h>

#ifndef __ASSEMBLY__

#define max(a, b) \
({ \
typeof(a) _a = a; \
typeof(b) _b = b; \
_a > _b ? _a : _b; \
})

#define min(a, b) \
({ \
typeof(a) _a = a; \
typeof(b) _b = b; \
_a < _b ? _a : _b; \
})

/*
* ..and if you can't take the strict
* types, you can specify one yourself.
*
* Or not use min/max at all, of course.
*/
#define min_t(type, x, y) \
({ \
type __x = (x); \
type __y = (y); \
__x < __y ? __x : __y; \
})
#define max_t(type, x, y) \
({ \
type __x = (x); \
type __y = (y); \
__x > __y ? __x : __y; \
})

#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))

#define DIV_ROUND_CLOSEST(x, divisor) \
({ \
typeof(x) __x = x; \
typeof(divisor) __d = divisor; \
(((typeof(x)) -1) > 0 || ((typeof(divisor)) -1) > 0 || (__x) > 0) ? (((__x) + ((__d) / 2)) / (__d)) : \
(((__x) - ((__d) / 2)) / (__d)); \
})

/*
* This looks more complex than it should be. But we need to
* get the type for the ~ right in round_down (it needs to be
* as wide as the result!), and we want to evaluate the macro
* arguments just once each.
*/
#define __round_mask(x, y) ((__typeof__(x)) ((y) - 1))
/**
* round_up - round up to next specified power of 2
* @x: the value to round
* @y: multiple to round up to (must be a power of 2)
*
* Rounds @x up to next multiple of @y (which must be a power of 2).
* To perform arbitrary rounding up, use roundup() below.
*/
#define round_up(x, y) ((((x) - 1) | __round_mask(x, y)) + 1)
/**
* round_down - round down to next specified power of 2
* @x: the value to round
* @y: multiple to round down to (must be a power of 2)
*
* Rounds @x down to next multiple of @y (which must be a power of 2).
* To perform arbitrary rounding down, use rounddown() below.
*/
#define round_down(x, y) ((x) & ~__round_mask(x, y))

/*
* Round @n up to the next power of two. Returns @n unchanged when it already is
* a power of two, and 1 for @n == 0.
Expand All @@ -36,4 +107,40 @@ static inline size_t round_up_pow2(size_t n)
return p;
}

/*
* Integer base-2 logarithm of @n, rounded up to the next integer. Originally
* from U-Boot -- Copyright (C) 2010 Texas Instruments, Aneesh V <aneesh@ti.com>.
*/
static inline s32 log_2_n_round_up(u32 n)
{
s32 log2n = -1;
u32 temp = n;

while (temp) {
log2n++;
temp >>= 1;
}

if (n & (n - 1))
return log2n + 1; /* not power of 2 - round up */
else
return log2n; /* power of 2 */
}

/* Integer base-2 logarithm of @n, rounded down (i.e. the index of the MSB). */
static inline s32 log_2_n_round_down(u32 n)
{
s32 log2n = -1;
u32 temp = n;

while (temp) {
log2n++;
temp >>= 1;
}

return log2n;
}

#endif /* __ASSEMBLY__ */

#endif /* MATH_H */
5 changes: 2 additions & 3 deletions so3/so3/kernel/bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <common.h>
#include <types.h>
#include <math.h>
#include <errno.h>
#include <bitmap.h>
#include <bitops.h>
Expand Down Expand Up @@ -242,8 +243,6 @@ int __bitmap_subset(const unsigned long *bitmap1, const unsigned long *bitmap2,
*/

#define CHUNKSZ 32
#define nbits_to_hold_value(val) fls(val)
#define roundup_power2(val, modulus) (((val) + (modulus) - 1) & ~((modulus) - 1))
#define unhex(c) (isdigit(c) ? (c - '0') : (toupper(c) - 'A' + 10))
#define BASEDEC 10 /* fancier cpuset lists input in decimal */

Expand All @@ -269,7 +268,7 @@ int bitmap_scnprintf(char *buf, unsigned int buflen, const unsigned long *maskp,
if (chunksz == 0)
chunksz = CHUNKSZ;

i = roundup_power2(nmaskbits, CHUNKSZ) - CHUNKSZ;
i = round_up(nmaskbits, CHUNKSZ) - CHUNKSZ;
for (; i >= 0; i -= CHUNKSZ) {
chunkmask = ((1ULL << chunksz) - 1);
word = i / BITS_PER_LONG;
Expand Down
Loading