mailing list of musl libc
 help / color / mirror / code / Atom feed
* question about -falign
@ 2013-03-24 10:25 michikaze
  2013-03-24 12:32 ` Szabolcs Nagy
  2013-03-24 15:34 ` Rich Felker
  0 siblings, 2 replies; 3+ messages in thread
From: michikaze @ 2013-03-24 10:25 UTC (permalink / raw)
  To: musl

Hello. I'm reading configure script for musl, and those lines confused 
me. Ain't disabling alignment actually hurts performance more?

#
# Some optimization levels add bloated alignment that hurt performance
#
tryflag CFLAGS_AUTO -falign-functions=1
tryflag CFLAGS_AUTO -falign-labels=1
tryflag CFLAGS_AUTO -falign-loops=1
tryflag CFLAGS_AUTO -falign-jumps=1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: question about -falign
  2013-03-24 10:25 question about -falign michikaze
@ 2013-03-24 12:32 ` Szabolcs Nagy
  2013-03-24 15:34 ` Rich Felker
  1 sibling, 0 replies; 3+ messages in thread
From: Szabolcs Nagy @ 2013-03-24 12:32 UTC (permalink / raw)
  To: musl

* michikaze <michikaze@rocketmail.com> [2013-03-24 14:25:26 +0400]:
> Hello. I'm reading configure script for musl, and those lines
> confused me. Ain't disabling alignment actually hurts performance
> more?

alignment usually adds a constant cost (nop padding)
to reduce the instruction cache pressure of the
following code

so it only helps if the following code fits into the
instruction cache better with the alignment and it is
executed many times or the constant cost is small
otherwise it can make things worse

and if the padding happens to make your code just
large enough so it spans into an extra page, then
you greatly increased the startup cost of your
program

maybe we should have a benchmark suit so it's easy
to answer such questions..

for n>1:

-falign-functions=n has no const cost, but it's not
clear how much you can win in general with it and
libc has a lot of unused interfaces you don't want
to waste space on

-falign-jumps=n has no const cost if the target is
only reachable through jumps

-falign-loops=n can be good or bad depending on how
many times the loop body is executed. there are
many loops in the code and only a few of them are
interesting for performance, aligning the rest just
adds code bloat

-falign-labels=n almost surely hurts performance


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: question about -falign
  2013-03-24 10:25 question about -falign michikaze
  2013-03-24 12:32 ` Szabolcs Nagy
@ 2013-03-24 15:34 ` Rich Felker
  1 sibling, 0 replies; 3+ messages in thread
From: Rich Felker @ 2013-03-24 15:34 UTC (permalink / raw)
  To: musl

On Sun, Mar 24, 2013 at 02:25:26PM +0400, michikaze wrote:
> Hello. I'm reading configure script for musl, and those lines
> confused me. Ain't disabling alignment actually hurts performance
> more?
> 
> #
> # Some optimization levels add bloated alignment that hurt performance
> #
> tryflag CFLAGS_AUTO -falign-functions=1
> tryflag CFLAGS_AUTO -falign-labels=1
> tryflag CFLAGS_AUTO -falign-loops=1
> tryflag CFLAGS_AUTO -falign-jumps=1

I haven't seen any good evidence that alignment makes code faster in
practice. The only type of situation where it should help even in
theory is when your loop is so big it barely fits in the instruction
cache, and where misaligning it with respect to cache lines would make
it spill over into an extra cache line and no longer fit. Anyone
hoping for such a bloated function to be fast is on crack.

On the other hand, the way alignment hurts is by adding unused space
all over the place, wasting a significant portion of each instruction
cache line on code that does nothing or that's never run. This waste
is unlikely to show up in micro-benchmarks (where the code all easily
fits in l1 cache) but in large programs will end up evicting other
potentially-performance-critical code from the cache.

Unless anyone can explain to me why the above reasoning is wrong, my
view is that alignment is just harmful.

Rich


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-03-24 15:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-24 10:25 question about -falign michikaze
2013-03-24 12:32 ` Szabolcs Nagy
2013-03-24 15:34 ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).