lkml.org 
[lkml]   [1999]   [May]   [28]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: goto's ???
Date
This is just a guess, so I may be totally wrong.

There may have been a desire to have only own "return point" out of a
function that is complex. The use of goto's would make it clear that the
function was being exited.

On most pipelined processors of today, the CPU is capable of branch
prediction. Given this case, it is theoretically possible that the goto
jump instruction takes no longer than a direct return, because it is
executed in parallel with the if statement. I don't know if this is the
case, but I thought that was the whole reason behind multiple execution
units and branch prediction. In effect, the if () goto statement is the
same as if you said if (!) {x} where {x} was everything in between the if
and the end of the function.

These are the only two reasons that I can think of for this >particular<
goto statement (in that it goes directly to the end of the function where an
error is returned.

fwr


----- Original Message -----
From: Mofeed Shahin <shahin@labf.org>
To: <linux-kernel@vger.rutgers.edu>
Sent: Saturday, May 22, 1999 1:01 PM
Subject: 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.
>
>
> -
> 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/
>


-
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/

\
 
 \ /
  Last update: 2005-03-22 13:51    [W:0.080 / U:1.640 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site