* Forgetting return values
@ 2009-05-28 18:55 Jamie Prescott
2009-05-28 19:10 ` Adam Nemet
0 siblings, 1 reply; 5+ messages in thread
From: Jamie Prescott @ 2009-05-28 18:55 UTC (permalink / raw)
To: gcc
What am I missing?
I have a simple:
static inline int set_prop(char const *path, char const *name,
void const *data, int size)
{
int error;
asm volatile ("int\t11\n\t"
: "=a0" (error): "a0" (path), "a1" (name), "a2" (data),
"a3" (size));
return error;
}
extern int calc(int);
int proc(int i)
{
int j = calc(i);
return set_prop(0, 0, &j, sizeof(int));
}
The aX classes maps to the rX registers, no problem for GCC in there.
The code above, compiled with GCC 4.4.0 and -O3 produces:
_proc:
push FP
mov SP,FP
sub SP,4,SP
call _calc
mov 0,r0
mov 4,r3
add FP,-4,r2
mov r0,r1
; APP
; 69 "xxxx.c" 1
int 11
; NO_APP
add SP,4,SP
pop FP
ret
GCC forgets about the calc() return value, and passes an address (FP-4) that
has never been written into.
buf if I add a "memory" clobber to the asm inline, everything comes back to
normal:
_proc:
push FP
mov SP,FP
sub SP,4,SP
call _calc
str.w r0,FP[-4]
mov 0,r0
mov 4,r3
add FP,-4,r2
mov r0,r1
; APP
; 69 "xxxx.c" 1
int 11
; NO_APP
add SP,4,SP
pop FP
ret
Why is the memory clobber required, and why GCC does not understand to
sync the value to memory when passing the address to a function?
Thanks,
- Jamie
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Forgetting return values
2009-05-28 18:55 Forgetting return values Jamie Prescott
@ 2009-05-28 19:10 ` Adam Nemet
2009-05-28 20:59 ` Jamie Prescott
0 siblings, 1 reply; 5+ messages in thread
From: Adam Nemet @ 2009-05-28 19:10 UTC (permalink / raw)
To: Jamie Prescott; +Cc: gcc
Jamie Prescott <jpresss@yahoo.com> writes:
> static inline int set_prop(char const *path, char const *name,
> void const *data, int size)
> {
> int error;
>
> asm volatile ("int\t11\n\t"
> : "=a0" (error): "a0" (path), "a1" (name), "a2" (data),
> "a3" (size));
>
> return error;
> }
>
> extern int calc(int);
>
> int proc(int i)
> {
> int j = calc(i);
>
> return set_prop(0, 0, &j, sizeof(int));
> }
...
>
> Why is the memory clobber required, and why GCC does not understand to
> sync the value to memory when passing the address to a function?
Because you never inform GCC that you will use the value at
address *NAME. Try to use "m"(*name) rather than "a1"(name) in the asm.
Adam
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Forgetting return values
2009-05-28 19:10 ` Adam Nemet
@ 2009-05-28 20:59 ` Jamie Prescott
2009-05-28 21:01 ` Adam Nemet
[not found] ` <4A1EDC7E.4040209@redhat.com>
0 siblings, 2 replies; 5+ messages in thread
From: Jamie Prescott @ 2009-05-28 20:59 UTC (permalink / raw)
To: Adam Nemet; +Cc: gcc
> From: Adam Nemet <anemet@caviumnetworks.com>
> To: Jamie Prescott <jpresss@yahoo.com>
> Cc: gcc@gcc.gnu.org
> Sent: Thursday, May 28, 2009 11:10:49 AM
> Subject: Re: Forgetting return values
>
> Jamie Prescott writes:
> > static inline int set_prop(char const *path, char const *name,
> > void const *data, int size)
> > {
> > int error;
> >
> > asm volatile ("int\t11\n\t"
> > : "=a0" (error): "a0" (path), "a1" (name), "a2" (data),
> > "a3" (size));
> >
> > return error;
> > }
> >
> > extern int calc(int);
> >
> > int proc(int i)
> > {
> > int j = calc(i);
> >
> > return set_prop(0, 0, &j, sizeof(int));
> > }
> ...
> >
> > Why is the memory clobber required, and why GCC does not understand to
> > sync the value to memory when passing the address to a function?
>
> Because you never inform GCC that you will use the value at
> address *NAME. Try to use "m"(*name) rather than "a1"(name) in the asm.
That's 'data', not 'name'. But OK, got it. unfortunately, I cannot use "m" since
that value need to go into a specific register.
Any other solution?
- Jamie
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Forgetting return values
2009-05-28 20:59 ` Jamie Prescott
@ 2009-05-28 21:01 ` Adam Nemet
[not found] ` <4A1EDC7E.4040209@redhat.com>
1 sibling, 0 replies; 5+ messages in thread
From: Adam Nemet @ 2009-05-28 21:01 UTC (permalink / raw)
To: Jamie Prescott; +Cc: gcc
Jamie Prescott writes:
> > From: Adam Nemet <anemet@caviumnetworks.com>
> > Jamie Prescott writes:
> > > static inline int set_prop(char const *path, char const *name,
> > > void const *data, int size)
> > > {
> > > int error;
> > >
> > > asm volatile ("int\t11\n\t"
> > > : "=a0" (error): "a0" (path), "a1" (name), "a2" (data),
> > > "a3" (size));
> > >
> > > return error;
> > > }
> > >
> > > extern int calc(int);
> > >
> > > int proc(int i)
> > > {
> > > int j = calc(i);
> > >
> > > return set_prop(0, 0, &j, sizeof(int));
> > > }
> > ...
> > >
> > > Why is the memory clobber required, and why GCC does not understand to
> > > sync the value to memory when passing the address to a function?
> >
> > Because you never inform GCC that you will use the value at
> > address *NAME. Try to use "m"(*name) rather than "a1"(name) in the asm.
>
> That's 'data', not 'name'. But OK, got it. unfortunately, I cannot use "m" since
> that value need to go into a specific register.
> Any other solution?
You can also have it *in addition* as an argument to the asm that's never
used:
asm volatile ("int\t11\n\t"
: "=a0" (error): "a0" (path), "a1" (name), "a2" (data),
"a3" (size), "m"(*data));
after changing data's type into something that can be dereferenced.
Adam
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Forgetting return values
[not found] ` <4A1EDC7E.4040209@redhat.com>
@ 2009-05-28 21:05 ` Jamie Prescott
0 siblings, 0 replies; 5+ messages in thread
From: Jamie Prescott @ 2009-05-28 21:05 UTC (permalink / raw)
To: Andrew Haley; +Cc: Adam Nemet, gcc-help, gcc
> From: Andrew Haley <aph@redhat.com>
> To: Jamie Prescott <jpresss@yahoo.com>
> Cc: Adam Nemet <anemet@caviumnetworks.com>; "gcc-help@gcc.gnu.org" <gcc-help@gcc.gnu.org>
> Sent: Thursday, May 28, 2009 11:48:30 AM
> Subject: Re: Forgetting return values
>
> Jamie Prescott wrote:
> >> From: Adam Nemet
>
> >>> Why is the memory clobber required, and why GCC does not understand to
> >>> sync the value to memory when passing the address to a function?
> >> Because you never inform GCC that you will use the value at
> >> address *NAME. Try to use "m"(*name) rather than "a1"(name) in the asm.
> >
> > That's 'data', not 'name'. But OK, got it. unfortunately, I cannot use "m"
> since
> > that value need to go into a specific register.
>
> This is not appropriate for gcc@, which is for gcc development.
Sorry, I posted to gcc@ because I thought it was a problem with my TARGET.
- Jamie
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-05-28 18:55 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-28 18:55 Forgetting return values Jamie Prescott
2009-05-28 19:10 ` Adam Nemet
2009-05-28 20:59 ` Jamie Prescott
2009-05-28 21:01 ` Adam Nemet
[not found] ` <4A1EDC7E.4040209@redhat.com>
2009-05-28 21:05 ` Jamie Prescott
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).