• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * linux/arch/unicore32/include/asm/bitops.h
4  *
5  * Code specific to PKUnity SoC and UniCore ISA
6  *
7  * Copyright (C) 2001-2010 GUAN Xue-tao
8  */
9 
10 #ifndef __UNICORE_BITOPS_H__
11 #define __UNICORE_BITOPS_H__
12 
13 #define _ASM_GENERIC_BITOPS_FLS_H_
14 #define _ASM_GENERIC_BITOPS___FLS_H_
15 #define _ASM_GENERIC_BITOPS_FFS_H_
16 #define _ASM_GENERIC_BITOPS___FFS_H_
17 /*
18  * On UNICORE, those functions can be implemented around
19  * the cntlz instruction for much better code efficiency.
20  */
21 
fls(unsigned int x)22 static inline int fls(unsigned int x)
23 {
24 	int ret;
25 
26 	asm("cntlz\t%0, %1" : "=r" (ret) : "r" (x) : "cc");
27 	ret = 32 - ret;
28 
29 	return ret;
30 }
31 
32 #define __fls(x) (fls(x) - 1)
33 #define ffs(x) ({ unsigned long __t = (x); fls(__t & -__t); })
34 #define __ffs(x) (ffs(x) - 1)
35 
36 #include <asm-generic/bitops.h>
37 
38 /* following definitions: to avoid using codes in lib/find_*.c */
39 #define find_next_bit		find_next_bit
40 #define find_next_zero_bit	find_next_zero_bit
41 #define find_first_bit		find_first_bit
42 #define find_first_zero_bit	find_first_zero_bit
43 
44 #include <asm-generic/bitops/find.h>
45 
46 #endif /* __UNICORE_BITOPS_H__ */
47