blob: d5a206865036a6c3c95f61c478187442a52b4567 [file] [log] [blame]
Chris Metcalf867e3592010-05-28 23:09:12 -04001/*
2 * Copyright 1992, Linus Torvalds.
3 * Copyright 2010 Tilera Corporation. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation, version 2.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for
13 * more details.
14 */
15
16#ifndef _ASM_TILE_BITOPS_H
17#define _ASM_TILE_BITOPS_H
18
19#include <linux/types.h>
20
21#ifndef _LINUX_BITOPS_H
22#error only <linux/bitops.h> can be included directly
23#endif
24
25#ifdef __tilegx__
26#include <asm/bitops_64.h>
27#else
28#include <asm/bitops_32.h>
29#endif
30
31/**
Chris Metcalf867e3592010-05-28 23:09:12 -040032 * ffz - find first zero bit in word
33 * @word: The word to search
34 *
35 * Undefined if no zero exists, so code should check against ~0UL first.
36 */
37static inline unsigned long ffz(unsigned long word)
38{
39 return __builtin_ctzl(~word);
40}
41
Chris Metcalf9f1d62b2012-05-25 12:32:09 -040042static inline int fls64(__u64 w)
43{
44 return (sizeof(__u64) * 8) - __builtin_clzll(w);
45}
46
Chris Metcalf867e3592010-05-28 23:09:12 -040047/**
48 * fls - find last set bit in word
49 * @x: the word to search
50 *
51 * This is defined in a similar way as the libc and compiler builtin
52 * ffs, but returns the position of the most significant set bit.
53 *
54 * fls(value) returns 0 if value is 0 or the position of the last
55 * set bit if value is nonzero. The last (most significant) bit is
56 * at position 32.
57 */
58static inline int fls(int x)
59{
Chris Metcalf9f1d62b2012-05-25 12:32:09 -040060 return fls64((unsigned int) x);
Chris Metcalf867e3592010-05-28 23:09:12 -040061}
62
Chris Metcalf947e7dc2010-08-13 20:32:41 -040063static inline unsigned int __arch_hweight32(unsigned int w)
Chris Metcalf867e3592010-05-28 23:09:12 -040064{
65 return __builtin_popcount(w);
66}
67
Chris Metcalf947e7dc2010-08-13 20:32:41 -040068static inline unsigned int __arch_hweight16(unsigned int w)
Chris Metcalf867e3592010-05-28 23:09:12 -040069{
70 return __builtin_popcount(w & 0xffff);
71}
72
Chris Metcalf947e7dc2010-08-13 20:32:41 -040073static inline unsigned int __arch_hweight8(unsigned int w)
Chris Metcalf867e3592010-05-28 23:09:12 -040074{
75 return __builtin_popcount(w & 0xff);
76}
77
Chris Metcalf947e7dc2010-08-13 20:32:41 -040078static inline unsigned long __arch_hweight64(__u64 w)
Chris Metcalf867e3592010-05-28 23:09:12 -040079{
80 return __builtin_popcountll(w);
81}
82
Akinobu Mitad6a0aa32013-08-14 22:07:30 +090083#include <asm-generic/bitops/builtin-__ffs.h>
84#include <asm-generic/bitops/builtin-__fls.h>
85#include <asm-generic/bitops/builtin-ffs.h>
Chris Metcalf947e7dc2010-08-13 20:32:41 -040086#include <asm-generic/bitops/const_hweight.h>
Chris Metcalf867e3592010-05-28 23:09:12 -040087#include <asm-generic/bitops/lock.h>
Akinobu Mita708ff2a2010-09-29 18:08:50 +090088#include <asm-generic/bitops/find.h>
Chris Metcalf867e3592010-05-28 23:09:12 -040089#include <asm-generic/bitops/sched.h>
Chris Metcalf18aecc22011-05-04 14:38:26 -040090#include <asm-generic/bitops/non-atomic.h>
Akinobu Mita861b5ae2011-03-23 16:42:02 -070091#include <asm-generic/bitops/le.h>
Chris Metcalf867e3592010-05-28 23:09:12 -040092
93#endif /* _ASM_TILE_BITOPS_H */