On Mon, Aug 04, 2008 at 10:09:07PM +0200, Petter Reinholdtsen wrote:
> [Dr. Werner Fink]
> > Beside speed there is no problem to drop the alignment.
> > Nevertheless it is very strange that the struct re_pattern_buffer,
> > the real type of regex_t, and found in /usr/include/regex.h is not
> > aligned within power of 2.
> >
> > There are some more alignment I've done for 1.12.0 (speed over
> > size).  Maybe this will show similar problems.
> 
> It seem my guess about this being a speed optimization was correct.

As I said: using alignment for optimization is not usually a good idea,
unless you _really_ know what you're doing, and even then only in
architecture-specific code. The effect of manually specifying alignment
like that will have wildly different results from one architecture to
another; it's usually safe to trust the compiler to know what will be
fastest.

> But the fact that there might be more of them make me hope for a patch
> from someone with access to a m68k machine, to make sure I do not
> upload a new version fixing only part of the problems, and thus having
> to do more than one upload to fix the issue.

Why have them in the first place? If you just remove them all, that will
surely fix the issue. I seriously doubt this benefits performance on
_all_ architectures where it is currently enabled, anyway.

If, however, there is indeed a measureable performance difference on
some architecture(s), then you could make the code look similar to this:

struct foo {
        int foo;
        int bar;
#ifdef ARCHITECTURE_ON_WHICH_WE_TESTED
} attribute((aligned(whatever)));
#else
}
#endif

with ARCHITECTURE_ON_WHICH_WE_TESTED being defined on an architecture
where you actually did measure performance differences.

> [Wouter Verhelst]
> > If you explicitly specify alignment like that, you disable any
> > automatic stuff the compiler might otherwise want to perform.
> 
> Sure.  I guess I wonder about why the alignment requirement isn't
> fulfilled when asked for the aligment of the sizeof(regex_t).  Can
> someone with m68k test and provide the answer for these questions:
> 
>   What is the value of sizeof(regex_t) on m68k?  What is the alignment
>   calculated for the struct?

sizeof(regex_t) is 30 on m68k, so I guess that's also what the
calculated alignment is.

The fact that the code works on, e.g., sparc probably means the relevant
structures there just happen to be aligned on the correct boundaries.

-- 
<Lo-lan-do> Home is where you have to wash the dishes.
  -- #debian-devel, Freenode, 2004-09-22



--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to