From: Andy Isaacson <adi@hexapodia.org>
To: Jan Engelhardt <jengelh@linux01.gwdg.de>
Cc: Jesper Juhl <jesper.juhl@gmail.com>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
David Woodhouse <dwmw2@infradead.org>,
jffs-dev@axis.com, Andrew Morton <akpm@osdl.org>
Subject: Re: [PATCH] Reduce nr of ptr derefs in fs/jffs2/summary.c
Date: Thu, 15 Dec 2005 19:34:35 -0800 [thread overview]
Message-ID: <20051216033435.GA21600@hexapodia.org> (raw)
In-Reply-To: <Pine.LNX.4.61.0512152354240.13568@yvahk01.tjqt.qr>
On Thu, Dec 15, 2005 at 11:55:05PM +0100, Jan Engelhardt wrote:
> >Benefits:
> > - micro speed optimization due to fewer pointer derefs
> > - generated code is slightly smaller
>
> Should not these two at best be done by the compiler?
The compiler cannot, in general, do CSE on pointer dereferences.
Consider the following snippet from fs/jffs2/summary.c, both before
610 sdrnt_ptr->type = c->summary->sum_list_head->d.type;
612 memcpy(sdrnt_ptr->name, c->summary->sum_list_head->d.name,
613 c->summary->sum_list_head->d.nsize);
615 wpage += JFFS2_SUMMARY_DIRENT_SIZE(c->summary->sum_list_head->d.nsize);
and after Jesper's patch:
611 sdrnt_ptr->type = temp->d.type;
613 memcpy(sdrnt_ptr->name, temp->d.name,
614 temp->d.nsize);
616 wpage += JFFS2_SUMMARY_DIRENT_SIZE(temp->d.nsize);
Assuming that memcpy is an out-of-line function, the compiler has to
handle the worst case, that it might modify c->summary->sum_list_head
and thus make the saved value stale. (In the specific case of memcpy
the compiler can take advantage of special knowledge about the function,
and it's probably inline anyways, so this *particular* example is not
real; but it's a nice clean classroom example.)
But a human *can* make the obvious leap and tell the compiler that the
value can be computed once and then saved. And besides, isn't the code
just *much* nicer to look at, above?
-andy
next prev parent reply other threads:[~2005-12-16 3:34 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-12-11 5:40 [PATCH] Reduce nr of ptr derefs in fs/jffs2/summary.c Jesper Juhl
2005-12-15 22:55 ` Jan Engelhardt
2005-12-16 3:34 ` Andy Isaacson [this message]
2005-12-16 22:05 ` Jan Engelhardt
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=20051216033435.GA21600@hexapodia.org \
--to=adi@hexapodia.org \
--cc=akpm@osdl.org \
--cc=dwmw2@infradead.org \
--cc=jengelh@linux01.gwdg.de \
--cc=jesper.juhl@gmail.com \
--cc=jffs-dev@axis.com \
--cc=linux-kernel@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox