From: Adrian Bunk <bunk@stusta.de>
To: Pekka Enberg <penberg@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [RFC: -mm patch] kcalloc(): INT_MAX -> ULONG_MAX
Date: Thu, 25 Aug 2005 18:01:37 +0200 [thread overview]
Message-ID: <20050825160136.GA6471@stusta.de> (raw)
In-Reply-To: <84144f0205082113123049afe2@mail.gmail.com>
On Sun, Aug 21, 2005 at 11:12:06PM +0300, Pekka Enberg wrote:
> On Sun, Aug 21, 2005 at 10:47:13PM +0300, Pekka Enberg wrote:
> > > You'll probably get even better code if you change the above to:
> > >
> > > if (size != 0 && n > ULONG_MAX / size)
> > >
> > > Reason being that size is virtually always a constant so the compiler
> > > can evaluate the division at compile-time.
>
> On 8/21/05, Adrian Bunk <bunk@stusta.de> wrote:
> > I doubt this would make any difference.
> >
> > And besides, except in some rare cases, the second argument is a
> > sizeof(foo) whose size is already known at compile time.
>
> Yes, that's my point. The second argument (size) is virtually always
> sizeof() whereas the first one (n) is sometimes a variable. GCC
> currently does not optimize away the division when n is not a
> constant.
>
> Looking at 2.6.13-rc6-mm1, we have roughly 15 callers with the first
> parameter being a variable. The compiler would be able to get rid of
> one comparison and division instruction for each of these so looks
> like we could shave off some more bytes...
With gcc 4.0.1:
text data bss dec hex filename
25675334 5851630 1819976 33346940 1fcd57c vmlinux-my-patch
25675366 5851630 1819976 33346972 1fcd59c vmlinux-your-patch
INT_MAX -> ULONG_MAX is correct, even though it doesn't seem to make a
difference with today's gcc.
Trying to change the code in a way that gcc will produce better code
doesn't seem to be worth it (except in extreme hot paths).
> Pekka
cu
Adrian
--
"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon Seed
next prev parent reply other threads:[~2005-08-25 16:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-08-20 19:32 [RFC: -mm patch] kcalloc(): INT_MAX -> ULONG_MAX Adrian Bunk
2005-08-21 19:47 ` Pekka Enberg
2005-08-21 19:54 ` Adrian Bunk
2005-08-21 20:12 ` Pekka Enberg
2005-08-25 16:01 ` Adrian Bunk [this message]
-- strict thread matches above, loose matches on Subject: below --
2006-01-28 22:30 Adrian Bunk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20050825160136.GA6471@stusta.de \
--to=bunk@stusta.de \
--cc=linux-kernel@vger.kernel.org \
--cc=penberg@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.