18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Port on Texas Instruments TMS320C6x architecture 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2004, 2009, 2010 Texas Instruments Incorporated 68c2ecf20Sopenharmony_ci * Author: Aurelien Jacquiot (aurelien.jacquiot@jaluna.com) 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci#ifndef _ASM_C6X_BITOPS_H 98c2ecf20Sopenharmony_ci#define _ASM_C6X_BITOPS_H 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#ifdef __KERNEL__ 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include <linux/bitops.h> 148c2ecf20Sopenharmony_ci#include <asm/byteorder.h> 158c2ecf20Sopenharmony_ci#include <asm/barrier.h> 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci/* 188c2ecf20Sopenharmony_ci * We are lucky, DSP is perfect for bitops: do it in 3 cycles 198c2ecf20Sopenharmony_ci */ 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci/** 228c2ecf20Sopenharmony_ci * __ffs - find first bit in word. 238c2ecf20Sopenharmony_ci * @word: The word to search 248c2ecf20Sopenharmony_ci * 258c2ecf20Sopenharmony_ci * Undefined if no bit exists, so code should check against 0 first. 268c2ecf20Sopenharmony_ci * Note __ffs(0) = undef, __ffs(1) = 0, __ffs(0x80000000) = 31. 278c2ecf20Sopenharmony_ci * 288c2ecf20Sopenharmony_ci */ 298c2ecf20Sopenharmony_cistatic inline unsigned long __ffs(unsigned long x) 308c2ecf20Sopenharmony_ci{ 318c2ecf20Sopenharmony_ci asm (" bitr .M1 %0,%0\n" 328c2ecf20Sopenharmony_ci " nop\n" 338c2ecf20Sopenharmony_ci " lmbd .L1 1,%0,%0\n" 348c2ecf20Sopenharmony_ci : "+a"(x)); 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci return x; 378c2ecf20Sopenharmony_ci} 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci/* 408c2ecf20Sopenharmony_ci * ffz - find first zero in word. 418c2ecf20Sopenharmony_ci * @word: The word to search 428c2ecf20Sopenharmony_ci * 438c2ecf20Sopenharmony_ci * Undefined if no zero exists, so code should check against ~0UL first. 448c2ecf20Sopenharmony_ci */ 458c2ecf20Sopenharmony_ci#define ffz(x) __ffs(~(x)) 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci/** 488c2ecf20Sopenharmony_ci * fls - find last (most-significant) bit set 498c2ecf20Sopenharmony_ci * @x: the word to search 508c2ecf20Sopenharmony_ci * 518c2ecf20Sopenharmony_ci * This is defined the same way as ffs. 528c2ecf20Sopenharmony_ci * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32. 538c2ecf20Sopenharmony_ci */ 548c2ecf20Sopenharmony_cistatic inline int fls(unsigned int x) 558c2ecf20Sopenharmony_ci{ 568c2ecf20Sopenharmony_ci if (!x) 578c2ecf20Sopenharmony_ci return 0; 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci asm (" lmbd .L1 1,%0,%0\n" : "+a"(x)); 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci return 32 - x; 628c2ecf20Sopenharmony_ci} 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci/** 658c2ecf20Sopenharmony_ci * ffs - find first bit set 668c2ecf20Sopenharmony_ci * @x: the word to search 678c2ecf20Sopenharmony_ci * 688c2ecf20Sopenharmony_ci * This is defined the same way as 698c2ecf20Sopenharmony_ci * the libc and compiler builtin ffs routines, therefore 708c2ecf20Sopenharmony_ci * differs in spirit from the above ffz (man ffs). 718c2ecf20Sopenharmony_ci * Note ffs(0) = 0, ffs(1) = 1, ffs(0x80000000) = 32. 728c2ecf20Sopenharmony_ci */ 738c2ecf20Sopenharmony_cistatic inline int ffs(int x) 748c2ecf20Sopenharmony_ci{ 758c2ecf20Sopenharmony_ci if (!x) 768c2ecf20Sopenharmony_ci return 0; 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci return __ffs(x) + 1; 798c2ecf20Sopenharmony_ci} 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci#include <asm-generic/bitops/__fls.h> 828c2ecf20Sopenharmony_ci#include <asm-generic/bitops/fls64.h> 838c2ecf20Sopenharmony_ci#include <asm-generic/bitops/find.h> 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci#include <asm-generic/bitops/sched.h> 868c2ecf20Sopenharmony_ci#include <asm-generic/bitops/hweight.h> 878c2ecf20Sopenharmony_ci#include <asm-generic/bitops/lock.h> 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci#include <asm-generic/bitops/atomic.h> 908c2ecf20Sopenharmony_ci#include <asm-generic/bitops/non-atomic.h> 918c2ecf20Sopenharmony_ci#include <asm-generic/bitops/le.h> 928c2ecf20Sopenharmony_ci#include <asm-generic/bitops/ext2-atomic.h> 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci#endif /* __KERNEL__ */ 958c2ecf20Sopenharmony_ci#endif /* _ASM_C6X_BITOPS_H */ 96