fix REQ-51

This commit is contained in:
Tomoki Shirasawa
2016-03-26 12:23:16 +09:00
parent a11479eba8
commit b0096a2740
10 changed files with 249 additions and 109 deletions

View File

@@ -0,0 +1,37 @@
/* bitops-__ffs.h COPYRIGHT FUJITSU LIMITED 2014 */
#ifndef INCLUDE_BITOPS___FFS_H
#define INCLUDE_BITOPS___FFS_H
static inline unsigned long __ffs(unsigned long word)
{
int num = 0;
if (BITS_PER_LONG == 64) {
if ((word & 0xffffffff) == 0) {
num += 32;
word >>= 32;
}
}
if ((word & 0xffff) == 0) {
num += 16;
word >>= 16;
}
if ((word & 0xff) == 0) {
num += 8;
word >>= 8;
}
if ((word & 0xf) == 0) {
num += 4;
word >>= 4;
}
if ((word & 0x3) == 0) {
num += 2;
word >>= 2;
}
if ((word & 0x1) == 0)
num += 1;
return num;
}
#endif

View File

@@ -0,0 +1,14 @@
/* bitops-clear_bit.h COPYRIGHT FUJITSU LIMITED 2014 */
#ifndef INCLUDE_BITOPS_CLEAR_BIT_H
#define INCLUDE_BITOPS_CLEAR_BIT_H
static inline void clear_bit(int nr, volatile unsigned long *addr)
{
unsigned long mask = (1UL << (nr % BITS_PER_LONG));
unsigned long *p = ((unsigned long *)addr) + (nr / BITS_PER_LONG);
*p &= ~mask;
}
#endif

8
lib/include/bitops-ffz.h Normal file
View File

@@ -0,0 +1,8 @@
/* bitops-ffz.h COPYRIGHT FUJITSU LIMITED 2014 */
#ifndef INCLUDE_BITOPS_FFZ_H
#define INCLUDE_BITOPS_FFZ_H
#define ffz(x) __ffs(~(x))
#endif

36
lib/include/bitops-fls.h Normal file
View File

@@ -0,0 +1,36 @@
/* bitops-fls.h COPYRIGHT FUJITSU LIMITED 2014 */
#ifndef INCLUDE_BITOPS_FLS_H
#define INCLUDE_BITOPS_FLS_H
static inline int fls(int x)
{
int r = 32;
if (!x) {
return 0;
}
if (!(x & 0xffff0000u)) {
x <<= 16;
r -= 16;
}
if (!(x & 0xff000000u)) {
x <<= 8;
r -= 8;
}
if (!(x & 0xf0000000u)) {
x <<= 4;
r -= 4;
}
if (!(x & 0xc0000000u)) {
x <<= 2;
r -= 2;
}
if (!(x & 0x80000000u)) {
x <<= 1;
r -= 1;
}
return r;
}
#endif

View File

@@ -0,0 +1,14 @@
/* bitops-set_bit.h COPYRIGHT FUJITSU LIMITED 2014 */
#ifndef INCLUDE_BITOPS_SET_BIT_H
#define INCLUDE_BITOPS_SET_BIT_H
static inline void set_bit(int nr, volatile unsigned long *addr)
{
unsigned long mask = (1UL << (nr % BITS_PER_LONG));
unsigned long *p = ((unsigned long *)addr) + (nr / BITS_PER_LONG);
*p |= mask;
}
#endif

35
lib/include/bitops.h Normal file
View File

@@ -0,0 +1,35 @@
/* bitops.h COPYRIGHT FUJITSU LIMITED 2014 */
#ifndef INCLUDE_BITOPS_H
#define INCLUDE_BITOPS_H
#include <types.h>
#define __BITS_TO_LONGS(n,d) (((n) + (d) - 1) / (d))
#define BITS_TO_LONGS(nr) __BITS_TO_LONGS(nr, BITS_PER_LONG)
#define DECLARE_BITMAP(name,bits) unsigned long name[BITS_TO_LONGS(bits)]
#define for_each_set_bit(bit, addr, size) \
for ((bit) = find_first_bit((addr), (size)); \
(bit) < (size); \
(bit) = find_next_bit((addr), (size), (bit) + 1))
#ifndef __ASSEMBLY__
unsigned long find_next_bit(const unsigned long *addr, unsigned long size,
unsigned long offset);
unsigned long find_next_zero_bit(const unsigned long *addr,
unsigned long size, unsigned long offset);
unsigned long find_first_bit(const unsigned long *addr,
unsigned long size);
unsigned long find_first_zero_bit(const unsigned long *addr,
unsigned long size);
#endif /*__ASSEMBLY__*/
#include <arch-bitops.h>
#endif /*INCLUDE_BITOPS_H*/

View File

@@ -13,7 +13,9 @@
#ifndef TYPES_H
#define TYPES_H
#define BITS_PER_BYTE 8
#define BITS_PER_LONG (sizeof(long) * BITS_PER_BYTE)
#include <ihk/types.h>
#endif