[lkml]   [2007]   [May]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: sparse -Wptr-subtraction-blows: still needed?
On Tue, 1 May 2007 17:24:54 -0700 (PDT)
Linus Torvalds <> 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

(ptr.char - base.char) < (constant) [NELEM *sizeof(element) ]

at least for constant operations. Dunno if gcc is that clever

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

 \ /
  Last update: 2007-05-02 14:05    [W:0.057 / U:0.772 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site