comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: reading a text file into a string
Date: Fri, 23 Jul 2004 20:42:53 -0500
Date: 2004-07-23T20:42:53-05:00	[thread overview]
Message-ID: <nvCdnXEk6MblI5zcRVn-pg@megapath.net> (raw)
In-Reply-To: opsbl1vsgsp4pfvb@bram-2

"Nick Roberts" <nick.roberts@acm.org> wrote in message
news:opsbl1vsgsp4pfvb@bram-2...
> On Thu, 22 Jul 2004 19:49:34 -0500, Randy Brukardt <randy@rrsoftware.com>
> wrote:
>
> > ...
> > That could only be done at run-time, as you couldn't insure anything
> > about the alignment of the stack at compile-time. (That's probably
> > why GNAT will support only 4 byte alignment, which is about all you
> > can guarentee.) So you're asking to make subprogram linkage more
> > expensive, to make heap allocation more expensive, and probably to
> > use indirect access to statically allocated objects (in order to align
> > the starting address). I don't doubt that there are cases where you
> > might gain a tiny bit of performance from doing so, but it seems a
> > large burden on all of the users to insist on it.
>
> Randy, this is weird. It is a well established technique for highly
> optimising compilers to align things for cache efficiency. Good grief
> there are whole books on the subject. Not only do they advocate the
> possibility of aligning both basic blocks (code) and data objects on
> cache-line boundaries, but they advocate that the compiler do it
> automatically wherever possible.

Well, first of all, books don't necessarily equal practice. If aligning
things causes a program to use more pages, it can make it run slower,
because it makes it load code from disk more frequently. (And if you think
that everything is always in main memory, you forget one of the primary
rules of computing: programs and data always expand to fill - and overfill -
available resources).

Anyway, I wasn't arguing that alignment per-se is a bad idea. We do it on
integers, for instance, and I think that virtually all compilers do that. I
was arguing that on the x86, stack alignments beyond 4 can only be done at
run-time. (Unless *all* software in the system in under your control, and
there are no interrupts/signals on your stack -- never true in practice.)
That's a distributed penalty that gets paid everywhere. Similarly, existing
Windows linkers don't support alignments beyond 16 to my knowledge -- so
again you would have to do something at runtime with a penalty. In both
cases, the penalty might very well cost more than the time savings possible.

Given there is a penalty, doing alignments automatically is a bad idea.

> If you think having big 'gaps' is an efficiency concern, I think the
> idea is that you fill in the gaps with smaller objects (or basic
> blocks).

Last time I checked, Intel was recommending that labels in code not be
aligned further than 4 byte boundaries. I don't know precisely why they
recommended that, but I don't claim to know better than Intel!

> If you are worried about the fact that all stacks and heaps/
> pools must be cache-line aligned (32, 64 bytes?), you have missed the
> RAM revolution that has been going on for the last two decades ;-)

That's only possible if you build a new OS from the ground up. Stacks aren't
aligned in Windows or Linux. So you have a pay a penalty to make them so;
and because of interrupt handlers and the like, you can't even trust your
own stack. Heap allocations aren't aligned in Windows, either. (Although you
could build you own heap on top of the page management in Windows -- but you
better be prepared to allocate 64K at a time.) Again, you can fix this with
run-time overhead. But if you're willing to spend run-time overhead, an
address clause does the same thing without any work.

                  Randy.








  parent reply	other threads:[~2004-07-24  1:42 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-07-15 17:27 reading a text file into a string zork
2004-07-15 17:49 ` Marius Amado Alves
2004-07-15 19:57   ` Nick Roberts
2004-07-15 17:59 ` Marius Amado Alves
2004-07-15 19:18   ` Nick Roberts
2004-07-15 19:18 ` Nick Roberts
2004-07-15 20:02   ` Nick Roberts
2004-07-16  1:23 ` Jeffrey Carter
2004-07-16  2:20 ` Steve
2004-07-16  2:26 ` Steve
2004-07-16 16:16   ` Jeffrey Carter
2004-07-16 17:45     ` Nick Roberts
2004-07-16 21:19   ` Randy Brukardt
2004-07-17  2:27     ` Robert I. Eachus
2004-07-17 11:31       ` Mats Weber
2004-07-17 15:52         ` Robert I. Eachus
2004-07-17 22:38           ` Jeffrey Carter
2004-07-18 13:44             ` zork
2004-07-19  8:07       ` Dale Stanbrough
2004-07-19  8:58         ` Martin Dowie
2004-07-21  0:17           ` Robert I. Eachus
2004-07-21 21:39             ` Randy Brukardt
2004-07-22 22:34               ` Robert I. Eachus
2004-07-23  0:49                 ` Randy Brukardt
2004-07-23 21:56                   ` Nick Roberts
2004-07-24  0:34                     ` tmoran
2004-07-24  1:16                       ` Nick Roberts
2004-07-24  1:42                     ` Randy Brukardt [this message]
2004-07-24 15:14                       ` Nick Roberts
2004-07-26 23:48                         ` Randy Brukardt
2004-07-27 12:08                           ` Nick Roberts
2004-07-27 23:24                             ` Robert I. Eachus
2004-07-29  0:55                               ` Randy Brukardt
2004-07-29  0:53                             ` Randy Brukardt
2004-07-29  7:25                               ` Martin Dowie
2004-07-29 20:08                               ` Robert I. Eachus
2004-07-30  0:14                                 ` tmoran
2004-07-24  2:56                   ` Robert I. Eachus
2004-07-19 11:51       ` Ada2005 (was " Peter Hermann
2004-07-19 12:51         ` Dmitry A. Kazakov
2004-07-19 13:01         ` Nick Roberts
2004-07-19 13:35           ` Martin Dowie
2004-07-19 17:22             ` Nick Roberts
2004-07-19 23:50           ` Randy Brukardt
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox