i386: clean up user_mode macros
PATCH 1/1 i386: clean up user_mode macros
Recent patches from the Xen group changed the X86 user_mode macros.
This patch does the following:
1. Makes the new user_mode() return 0 or 1 (same as x86_64)
2. Removes conditional jump from user_mode_vm() (it's called every timer tick on each CPU on SMP)
I've been running this patch for a while now. Please apply.
include/asm-i386/ptrace.h +2 -2
@@ -57,8 +57,8 @@#ifdef __KERNEL__struct task_struct ;extern void send_sigtrap (struct task_struct *tsk,struct pt_regs *regs,int error_code); -#define user_mode (regs) (3 & (regs)->xcs) -#define user_mode_vm (regs) ((VM_MASK & (regs)->eflags) || user_mode(regs)) +#define user_mode (regs) (!!(3 & (regs)->xcs)) +#define user_mode_vm (regs) (!!((VM_MASK & (regs)->eflags) | (3 & (regs)->xcs)))#define instruction_pointer (regs) ((regs)->eip)#if defined(CONFIG_SMP ) && defined(CONFIG_FRAME_POINTER )extern unsigned long profile_pc (struct pt_regs *regs);
__
Chuck
Quoted 6 lines · Chuck Ebbert
Recent patches from the Xen group changed the X86
user_modemacros.This patch does the following:
1. Makes the new
user_mode()return 0 or 1 (same asx86_64)
I _really_ prefer
x != 0
over
!!x
since double negation is not only a bad habit in natural languages, it's a bad habit in computer languages too, for exactly the same reason. It's confusing.
Ask a hundred random C programmers what "!!x" means, versus what "x != 0" means, and time their replies.
I will bet you $5 USD that even if they all give the right answer (and I suspect you'll get a few wrogn answers in there too for the !! case), they'll take a _lot_ longer answering the "!!x" version than they will the "x != 0" question.
And guess what? That means that the "!!x" version is worse. It means that people don't "see" what it means - they have to think about it. And you shouldn't have to think about something like that, you should write it in the obvious way in the first place.
Linus
Quoted 7 lines · Linus Torvalds
I _really_ prefer
x != 0over
!!x
Good to hear. This means that you should have no problem accepting my previous patch for signal.c that changed the x ^ y to x != y. And I would also assume that you prefer x *= 2 over x <<= 1 (also since the first person to show this example used x <<= 2. Right Lee? :-)
-- Steve
Quoted 3 lines · Steven Rostedt
And I
would also assume that you prefer x *= 2 over x <<= 1 (also since the first person to show this example used x <<= 2. Right Lee? :-)
Let us never speak of that again. These aren't the droids you're looking for.
Lee
Quoted 2 lines · Linus Torvalds
Ask a hundred random C programmers what "!!x" means, versus what "x != 0" means, and time their replies.
I've always thought of "!!" as the "canonicalize boolean" operator...
Vaguely ugly, but I think it's actually _more clear_ than != 0 in contexts where the value is already "boolean" in the C zero or not-zero sense, but you want a "proper" boolean (0 or 1) for some reason.
-miles
Signature · 2 lines
Somebody has to do something, and it's just incredibly pathetic that it has to be us. -- Jerry Garcia
Quoted 6 lines · Miles Bader
Quoted 2 lines · Linus Torvalds
Ask a hundred random C programmers what "!!x" means, versus what "x != 0" means, and time their replies.
I've always thought of "!!" as the "canonicalize boolean" operator...
Me too. Once you get used to it, it's just the "convert non-zero to 1" operator.
But whatever.
Quoted 6 lines · On Mon, 25 Jul 2005 18:34:13 -0700 Andrew Morton wrote:
Quoted 5 lines · Miles Bader
Quoted 2 lines · Linus Torvalds
Ask a hundred random C programmers what "!!x" means, versus what "x != 0" means, and time their replies.
Quoted 6 lines
Quoted 1 line
I've always thought of "!!" as the "canonicalize boolean" operator...
Me too. Once you get used to it, it's just the "convert non-zero to 1" operator.
But whatever.
I call it "truth value" (true or false), but once I got used to it, I thought it was OK too.
---
~Randy