This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [3.1.1] Re: GCC performance regression - its memset!
- From: Jack Lloyd <lloyd at acm dot jhu dot edu>
- To: <gcc at gcc dot gnu dot org>
- Date: Tue, 21 May 2002 10:49:56 -0400 (EDT)
- Subject: Re: [3.1.1] Re: GCC performance regression - its memset!
- Organization: JHU ACM/CS/SRL
This looks to be an endian issue.
Some code:
------------- CUT ----------------
#include <stdio.h>
void foo(void *x, int y)
{
__builtin_memset(x, 0, y);
}
int main()
{
int x[2] = { 0x5a5a5a5a, 0x5a5a5a5a };
printf("%08X %08X\n", x[0], x[1]);
foo(x, 5);
printf("%08X %08X\n", x[0], x[1]);
return 0;
}
------------- CUT ----------------
Let's try this on x86:
5A5A5A5A 5A5A5A5A
00000000 5A5A5A00
And again on SPARC:
5A5A5A5A 5A5A5A5A
00000000 005A5A5A
where it comes out what you expect, at least if you expect what I expect
(or something...)
And, honestly, I'm not sure if this is how it's supposed to be or not.
What are the rules for doing a memset across part of an object? Certainly,
in both cases it sets 5 bytes to zero, and those bytes are contiguous in
memory. The thing is, I can't imagine how you could actually change this on
x86 to work like it does on a big-endian machine, because you would have to
know the size of the type involved.
HTH,
-Jack
On Mon, 20 May 2002, Glen Nakamura wrote:
> > Hi Jakub,
> >
> > As I've mentioned in a previous e-mail, I believe that this test
> > case is poorly formed; quite clearly the x argument to foo is
> > incorrectly aligned for the type. On many platforms, the above
> > code (and even with foo defined as "*x = 0;") will fail at runtime.
> >
> > The benefit of Jan's patch is that on machines without alignment
> > restrictions, we'll still produce the "expected behaviour" for
> > incorrectly written programs. Mozilla's source code is incorrect
> > and needs to be fixed (use void* rather than void**). This isn't
> > really a correctness PR, more a quality of implementation for
> > undefined behaviour PR.
> >
> > Roger
>
> Aloha,
>
> FWIW, I think this really is a regression... The problem is really
> that memset doesn't properly set bytes at the tail of the buffer.
> How about this testcase?
>
> - Glen Nakamura
>
>
> /* PR optimization/6703 */
> extern void abort (void);
> extern void exit (int);
>
> void foo (int *x, int y)
> {
> __builtin_memset (x, 0, y);
> }
>
> int main ()
> {
> int x[2] = { 0x5a5a5a5a, 0x5a5a5a5a };
>
> if (x[1] != 0x5a5a5a5a)
> abort ();
> foo (x, 5);
> if (x[1] == 0x5a5a5a5a)
> abort ();
> exit (0);
> }
>