Messages in this thread |  | | Date | Tue, 25 May 1999 23:01:19 +0200 (CEST) | | From | Mikulas Patocka <> | | Subject | Re: goto's ??? |
| |
> > G'day all, > > I was just have a bit of a look at the fs code, and noticed something a > little odd. There are alot of 'goto' statements in the code. From what I > can see they are not needed. > > eg : > line 632 of /usr/src/linux/fs/open.c : > > struct file *filp_open(const char * filename, int flags, int mode) > { > struct inode * inode; > struct dentry * dentry; > struct file * f; > int flag,error; > > error = -ENFILE; > f = get_empty_filp(); > if (!f) > goto out; > .... > <SNIP> > > out: > return ERR_PTR(error); > } > > this seems like an extra jmp statement to me (unless the compiler > optimises it) > > ie why not just do this : > struct file *filp_open(const char * filename, int flags, int mode) > { > struct inode * inode; > struct dentry * dentry; > struct file * f; > int flag,error; > > error = -ENFILE; > f = get_empty_filp(); > if (!f) > return ERR_PTR(error); > .... > <SNIP> > } > > Cheers Mof.
Hi.
The first compiles as: cmp f,0 jz ret ... ret: mov eax,error leave ret
However the second is something like: cmp f,0 jnz nz mov eax,error leave ret nz: ...
It's faster when the code goes straight without jumps. Errors do not happen often, so the first is better. The compiler doesn't know which branch is used more, but we know it, so we must suggest the compiler where to put jumps.
Mikulas
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
|  |