* atomic_add_and_test
@ 2003-06-16 19:40 Mark Lobo
2003-06-20 11:51 ` atomic_add_and_test Maciej Hrebien
0 siblings, 1 reply; 2+ messages in thread
From: Mark Lobo @ 2003-06-16 19:40 UTC (permalink / raw)
To: linux-assembly
Guys
Im trying to implement this function which I absolutely need. The function
is as follows:
int atomic_add_and_test(atomic_t *value, int addval)
This adds "addval" to "value" and returns the old value of "value" back.
Im not an expert at assembly syntax, Im not even sure how to write this
function. I had done some 886 assembly and some microcontroller assembly
stuff, but that was ages back. I would really really appreciate if someone
can correct the source I have below. I did try to read up and I will
definitely learn it back:) But I need this right now, so I would really
appreciate it if someone can correct this for me:) This might be assembly
101:) but Im unfortunately its been ages since I did it.
static __inline__ int32_t atomic_add_and_test(atomic_t * p_plValue, int32_t
p_lAdd)
{
int32_t l_lResult;
__asm__ __volatile__ (
"push %%EBX;"
"movl %1, %%EBX;"
"movl %2, %%EAX;"
"lock; xadd %%EAX, (%%EBX);"
"inc %%EAX;"
"mov %%EAX, %0;"
"pop %%EBX"
: "=g"(l_lResult) : "g"(p_plValue), "g"(p_lAdd):"%eax", "ebx" );
return l_lResult;
}
Thanks!
Mark
_________________________________________________________________
Protect your PC - get McAfee.com VirusScan Online
http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: atomic_add_and_test
2003-06-16 19:40 atomic_add_and_test Mark Lobo
@ 2003-06-20 11:51 ` Maciej Hrebien
0 siblings, 0 replies; 2+ messages in thread
From: Maciej Hrebien @ 2003-06-20 11:51 UTC (permalink / raw)
To: linux-assembly
Mark Lobo wrote:
>
> static __inline__ int32_t atomic_add_and_test(atomic_t * p_plValue, int32_t
> p_lAdd)
> {
> int32_t l_lResult;
> __asm__ __volatile__ (
> "push %%EBX;"
> "movl %1, %%EBX;"
> "movl %2, %%EAX;"
> "lock; xadd %%EAX, (%%EBX);"
> "inc %%EAX;"
> "mov %%EAX, %0;"
> "pop %%EBX"
> : "=g"(l_lResult) : "g"(p_plValue), "g"(p_lAdd):"%eax", "ebx" );
> return l_lResult;
> }
Can't you just:
inline int add_and_test(int* value, int to_add)
{
int old_result;
asm volatile("
lock
xadd %%eax,(%%ebx)
" : "=eax" (old_result) : "a" (to_add), "b" (value) );
return old_result;
}
? Do you have to push %ebx on stack? Why do you inc %eax after xadd?
Regards,
--
Maciej Hrebien
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2003-06-20 11:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-06-16 19:40 atomic_add_and_test Mark Lobo
2003-06-20 11:51 ` atomic_add_and_test Maciej Hrebien
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).