/*1* Copyright 1992, Linus Torvalds.2* Copyright 2010 Tilera Corporation. All Rights Reserved.3*4* This program is free software; you can redistribute it and/or5* modify it under the terms of the GNU General Public License6* as published by the Free Software Foundation, version 2.7*8* This program is distributed in the hope that it will be useful, but9* WITHOUT ANY WARRANTY; without even the implied warranty of10* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or11* NON INFRINGEMENT. See the GNU General Public License for12* more details.13*/1415#ifndef _ASM_TILE_BITOPS_H16#define _ASM_TILE_BITOPS_H1718#include <linux/types.h>1920#ifndef _LINUX_BITOPS_H21#error only <linux/bitops.h> can be included directly22#endif2324#ifdef __tilegx__25#include <asm/bitops_64.h>26#else27#include <asm/bitops_32.h>28#endif2930/**31* __ffs - find first set bit in word32* @word: The word to search33*34* Undefined if no set bit exists, so code should check against 0 first.35*/36static inline unsigned long __ffs(unsigned long word)37{38return __builtin_ctzl(word);39}4041/**42* ffz - find first zero bit in word43* @word: The word to search44*45* Undefined if no zero exists, so code should check against ~0UL first.46*/47static inline unsigned long ffz(unsigned long word)48{49return __builtin_ctzl(~word);50}5152/**53* __fls - find last set bit in word54* @word: The word to search55*56* Undefined if no set bit exists, so code should check against 0 first.57*/58static inline unsigned long __fls(unsigned long word)59{60return (sizeof(word) * 8) - 1 - __builtin_clzl(word);61}6263/**64* ffs - find first set bit in word65* @x: the word to search66*67* This is defined the same way as the libc and compiler builtin ffs68* routines, therefore differs in spirit from the other bitops.69*70* ffs(value) returns 0 if value is 0 or the position of the first71* set bit if value is nonzero. The first (least significant) bit72* is at position 1.73*/74static inline int ffs(int x)75{76return __builtin_ffs(x);77}7879/**80* fls - find last set bit in word81* @x: the word to search82*83* This is defined in a similar way as the libc and compiler builtin84* ffs, but returns the position of the most significant set bit.85*86* fls(value) returns 0 if value is 0 or the position of the last87* set bit if value is nonzero. The last (most significant) bit is88* at position 32.89*/90static inline int fls(int x)91{92return (sizeof(int) * 8) - __builtin_clz(x);93}9495static inline int fls64(__u64 w)96{97return (sizeof(__u64) * 8) - __builtin_clzll(w);98}99100static inline unsigned int __arch_hweight32(unsigned int w)101{102return __builtin_popcount(w);103}104105static inline unsigned int __arch_hweight16(unsigned int w)106{107return __builtin_popcount(w & 0xffff);108}109110static inline unsigned int __arch_hweight8(unsigned int w)111{112return __builtin_popcount(w & 0xff);113}114115static inline unsigned long __arch_hweight64(__u64 w)116{117return __builtin_popcountll(w);118}119120#include <asm-generic/bitops/const_hweight.h>121#include <asm-generic/bitops/lock.h>122#include <asm-generic/bitops/find.h>123#include <asm-generic/bitops/sched.h>124#include <asm-generic/bitops/non-atomic.h>125#include <asm-generic/bitops/le.h>126127#endif /* _ASM_TILE_BITOPS_H */128129130