mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-17 17:24:17 +08:00
117780eef7
The gcc people have confirmed that using "bool" when combined with inline assembly always is treated as a byte-sized operand that can be assumed to be 0 or 1, which is exactly what the SET instruction emits. Change the output types and intermediate variables of as many operations as practical to "bool". Signed-off-by: H. Peter Anvin <hpa@zytor.com> Link: http://lkml.kernel.org/r/1465414726-197858-3-git-send-email-hpa@linux.intel.com Reviewed-by: Andy Lutomirski <luto@kernel.org> Reviewed-by: Borislav Petkov <bp@suse.de> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
46 lines
1.2 KiB
C
46 lines
1.2 KiB
C
/* -*- linux-c -*- ------------------------------------------------------- *
|
|
*
|
|
* Copyright (C) 1991, 1992 Linus Torvalds
|
|
* Copyright 2007 rPath, Inc. - All Rights Reserved
|
|
*
|
|
* This file is part of the Linux kernel, and is made available under
|
|
* the terms of the GNU General Public License version 2.
|
|
*
|
|
* ----------------------------------------------------------------------- */
|
|
|
|
/*
|
|
* Very simple bitops for the boot code.
|
|
*/
|
|
|
|
#ifndef BOOT_BITOPS_H
|
|
#define BOOT_BITOPS_H
|
|
#define _LINUX_BITOPS_H /* Inhibit inclusion of <linux/bitops.h> */
|
|
|
|
#include <linux/types.h>
|
|
|
|
static inline bool constant_test_bit(int nr, const void *addr)
|
|
{
|
|
const u32 *p = (const u32 *)addr;
|
|
return ((1UL << (nr & 31)) & (p[nr >> 5])) != 0;
|
|
}
|
|
static inline bool variable_test_bit(int nr, const void *addr)
|
|
{
|
|
bool v;
|
|
const u32 *p = (const u32 *)addr;
|
|
|
|
asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
|
|
return v;
|
|
}
|
|
|
|
#define test_bit(nr,addr) \
|
|
(__builtin_constant_p(nr) ? \
|
|
constant_test_bit((nr),(addr)) : \
|
|
variable_test_bit((nr),(addr)))
|
|
|
|
static inline void set_bit(int nr, void *addr)
|
|
{
|
|
asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
|
|
}
|
|
|
|
#endif /* BOOT_BITOPS_H */
|