[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20070502130204.2cc2fd1a@the-village.bc.nu>
Date: Wed, 2 May 2007 13:02:04 +0100
From: Alan Cox <alan@...rguk.ukuu.org.uk>
To: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: Josh Triplett <josh@...edesktop.org>, linux-sparse@...r.kernel.org,
linux-kernel@...r.kernel.org, Al Viro <viro@....linux.org.uk>
Subject: Re: sparse -Wptr-subtraction-blows: still needed?
On Tue, 1 May 2007 17:24:54 -0700 (PDT)
Linus Torvalds <torvalds@...ux-foundation.org> wrote:
>
>
> On Tue, 1 May 2007, Josh Triplett wrote:
> >
> > Do you know whether the current version of GCC generates poor code for pointer
> > subtraction?
>
> You _cannot_ generate good code.
>
> When you subtract two pointers, the C definition means that you first
> subtract the values (cheap), and then you *divide* the result by the size
> of the object the pointer points to (expensive!).
Good compilers even in the 1990's would defer the divide and try and
propogate it out as a multiply the other side for constants, and they'll
also use shifts when possible.
Thus they'll turn
(ptr.element - base.element) < NELEM
into
(ptr.char - base.char) < (constant) [NELEM *sizeof(element) ]
at least for constant operations. Dunno if gcc is that clever
Alan
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists