public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* How can I tell the compiler to not store excessively?
@ 2004-08-31  3:22 Mike Sharov
  2004-08-31 12:01 ` Falk Hueffner
  0 siblings, 1 reply; 2+ messages in thread
From: Mike Sharov @ 2004-08-31  3:22 UTC (permalink / raw)
  To: gcc-help

Dear gcc-help,
I am trying to write several inline assembly functions to facilitate
use of MMX instructions and I would like for them to be concatenated
without transfer in and out of registers between calls if the data is
already loaded in a register. Example:
===========================================
#include <stdio.h>

typedef int mmx_t __attribute__ ((mode(V8QI)));

inline void padd (const char* p, char* r)
{
    asm ("paddb %1, %0" : "=&y"(*(mmx_t*)r) : "y"(*(const mmx_t*)p), 
"0"(*(mmx_t*)r));
}

inline void psub (const char* p, char* r)
{
    asm ("psubb %1, %0" : "=&y"(*(mmx_t*)r) : "y"(*(const mmx_t*)p), 
"0"(*(mmx_t*)r));
}

int main (void)
{
    char v1[8], v2[8];
    padd (v1, v2);
    psub (v1, v2);
    printf ("v2[3] = %d\n", v2[3]);
    return (0);
}
===========================================
Here I would like to see v1 and v2 loaded into registers before the call to
padd and not leave them until the return from psub. Now, gcc already can do
this for the read-only v1, generating the following (-O3 -march=athlon-mp):
===========================================
        pxor    %mm0, %mm0
        movl    %esp, %ebp
.LCFI1:
        subl    $24, %esp
.LCFI2:
        movq    -8(%ebp), %mm1
        andl    $-16, %esp
#APP
        paddb %mm0, %mm1
#NO_APP
        movq    %mm1, -8(%ebp)
        subl    $16, %esp
#APP
        psubb %mm0, %mm1
#NO_APP
        movq    %mm1, -8(%ebp)
        movsbl  -5(%ebp),%eax
        movl    $.LC0, (%esp)
        movl    %eax, 4(%esp)
        call    printf
===========================================
Here %mm0 is not reloaded because it remains the same value for both
padd and psub calls. However, the value from %mm1 is stored into v2
twice; the first time after padd and the second time after psub. It
is understandable that the optimizer would do this, because, for
example, several threads could be accessing v2 concurrently. Is it
possible to add some directives to the source code above to tell
the optimizer that it is ok to keep v2 in a register until something
(like the printf) actually asks for its contents through another method?

-- 
Mike Sharov
msharov@talentg.com


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

* Re: How can I tell the compiler to not store excessively?
  2004-08-31  3:22 How can I tell the compiler to not store excessively? Mike Sharov
@ 2004-08-31 12:01 ` Falk Hueffner
  0 siblings, 0 replies; 2+ messages in thread
From: Falk Hueffner @ 2004-08-31 12:01 UTC (permalink / raw)
  To: Mike Sharov; +Cc: gcc-help

Mike Sharov <msharov@talentg.com> writes:

> I am trying to write several inline assembly functions to facilitate
> use of MMX instructions and I would like for them to be concatenated
> without transfer in and out of registers between calls if the data is
> already loaded in a register.

I'd recommend you use try the macros from <mmintrin.h> like _m_paddb.
If they don't produce proper code, please file a bug report.

-- 
	Falk

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

end of thread, other threads:[~2004-08-31  7:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-31  3:22 How can I tell the compiler to not store excessively? Mike Sharov
2004-08-31 12:01 ` Falk Hueffner

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 read-only IMAP folder(s) and NNTP newsgroup(s).