Re: [PATCH 1/3] futex: remove duplicated code
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
- To: Russell King - ARM Linux <linux@xxxxxxxxxxxxxxx>, Jiri Slaby <jslaby@xxxxxxx>
- Subject: Re: [PATCH 1/3] futex: remove duplicated code
- From: "H. Peter Anvin" <hpa@xxxxxxxxx>
- Date: Sat, 4 Mar 2017 11:15:17 -0800
- Cc: akpm@xxxxxxxxxxxxxxxxxxxx, linux-kernel@xxxxxxxxxxxxxxx, Richard Henderson <rth@xxxxxxxxxxx>, Ivan Kokshaysky <ink@xxxxxxxxxxxxxxxxxxxx>, Matt Turner <mattst88@xxxxxxxxx>, Vineet Gupta <vgupta@xxxxxxxxxxxx>, Catalin Marinas <catalin.marinas@xxxxxxx>, Will Deacon <will.deacon@xxxxxxx>, Richard Kuo <rkuo@xxxxxxxxxxxxxx>, Tony Luck <tony.luck@xxxxxxxxx>, Fenghua Yu <fenghua.yu@xxxxxxxxx>, Michal Simek <monstr@xxxxxxxxx>, Ralf Baechle <ralf@xxxxxxxxxxxxxx>, Jonas Bonn <jonas@xxxxxxxxxxxx>, Stefan Kristiansson <stefan.kristiansson@xxxxxxxxxxxxx>, Stafford Horne <shorne@xxxxxxxxx>, "James E.J. Bottomley" <jejb@xxxxxxxxxxxxxxxx>, Helge Deller <deller@xxxxxx>, Benjamin Herrenschmidt <benh@xxxxxxxxxxxxxxxxxxx>, Paul Mackerras <paulus@xxxxxxxxx>, Michael Ellerman <mpe@xxxxxxxxxxxxxx>, Martin Schwidefsky <schwidefsky@xxxxxxxxxx>, Heiko Carstens <heiko.carstens@xxxxxxxxxx>, Yoshinori Sato <ysato@xxxxxxxxxxxxxxxxxxxx>, Rich Felker <dalias@xxxxxxxx>, "David S. Miller" <davem@xxxxxxxxxxxxx>, Chris Metcalf <cmetcalf@xxxxxxxxxxxx>, Thomas Gleixner <tglx@xxxxxxxxxxxxx>, Ingo Molnar <mingo@xxxxxxxxxx>, Chris Zankel <chris@xxxxxxxxxx>, Max Filippov <jcmvbkbc@xxxxxxxxx>, Arnd Bergmann <arnd@xxxxxxxx>, x86@xxxxxxxxxx, linux-alpha@xxxxxxxxxxxxxxx, linux-snps-arc@xxxxxxxxxxxxxxxxxxx, linux-arm-kernel@xxxxxxxxxxxxxxxxxxx, linux-hexagon@xxxxxxxxxxxxxxx, linux-ia64@xxxxxxxxxxxxxxx, linux-mips@xxxxxxxxxxxxxx, openrisc@xxxxxxxxxxxxxxxxxxxx, linux-parisc@xxxxxxxxxxxxxxx, linuxppc-dev@xxxxxxxxxxxxxxxx, linux-s390@xxxxxxxxxxxxxxx, linux-sh@xxxxxxxxxxxxxxx, sparclinux@xxxxxxxxxxxxxxx, linux-xtensa@xxxxxxxxxxxxxxxx, linux-arch@xxxxxxxxxxxxxxx
- In-reply-to: <20170304130550.GT21222@n2100.armlinux.org.uk>
- References: <20170303122712.13353-1-jslaby@suse.cz> <20170304130550.GT21222@n2100.armlinux.org.uk>
- User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0
On 03/04/17 05:05, Russell King - ARM Linux wrote:
>>
>> +static int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
>> +{
>> + int op = (encoded_op >> 28) & 7;
>> + int cmp = (encoded_op >> 24) & 15;
>> + int oparg = (encoded_op << 8) >> 20;
>> + int cmparg = (encoded_op << 20) >> 20;
>
> Hmm. oparg and cmparg look like they're doing these shifts to get sign
> extension of the 12-bit values by assuming that "int" is 32-bit -
> probably worth a comment, or for safety, they should be "s32" so it's
> not dependent on the bit-width of "int".
>
For readability, perhaps we should make sign- and zero-extension an
explicit facility?
/*
* Truncate an integer x to n bits, using sign- or
* zero-extension, respectively.
*/
static inline __const_func__ s32 sex32(s32 x, int n)
{
return (x << (32-n)) >> (32-n);
}
static inline __const_func__ s64 sex64(s64 x, int n)
{
return (x << (64-n)) >> (64-n);
}
#define sex(x,y) \
((__typeof__(x)) \
(((__builtin_constant_p(y) && ((y) <= 32)) || \
(sizeof(x) <= sizeof(s32))) \
? sex32((x),(y)) : sex64((x),(y))))
static inline __const_func__ u32 zex32(u32 x, int n)
{
return (x << (32-n)) >> (32-n);
}
static inline __const_func__ u64 zex64(u64 x, int n)
{
return (x << (64-n)) >> (64-n);
}
#define zex(x,y) \
((__typeof__(x)) \
(((__builtin_constant_p(y) && ((y) <= 32)) || \
(sizeof(x) <= sizeof(u32))) \
? zex32((x),(y)) : zex64((x),(y))))
--
To unsubscribe from this list: send the line "unsubscribe linux-ia64" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
[Index of Archives]
[Linux Kernel]
[Sparc Linux]
[DCCP]
[Linux ARM]
[Yosemite News]
[Linux SCSI]
[Linux x86_64]
[Linux for Ham Radio]