public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* How to make use of CMPXCHG16B?
@ 2012-01-08  2:32 Borg Onion
  2012-01-08 11:42 ` Borg Onion
  0 siblings, 1 reply; 2+ messages in thread
From: Borg Onion @ 2012-01-08  2:32 UTC (permalink / raw)
  To: gcc-help

Hello,

I'm trying to figure out how to make use of CMPXCHG16B.  The GCC
manual looks to point towards __sync_val_compare_and_swap() with
__int128 data types and the -mcx16 compile flag.  But this data type
is not present when I try to compile with it, nor do I think my 4th
generation Opteron is capable of holding __int128 values in its
registers.  So what's the equivalent of .Net's
_InterlockedCompareExchange128()
[http://msdn.microsoft.com/en-us/library/bb514094.aspx] in GCC-land?
I'm trying to avoid having to (re?)implement it myself as these folks
did:

http://stackoverflow.com/questions/4825400/cmpxchg16b-correct

Thanks for any guidance,

--Borg Onion

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

* Re: How to make use of CMPXCHG16B?
  2012-01-08  2:32 How to make use of CMPXCHG16B? Borg Onion
@ 2012-01-08 11:42 ` Borg Onion
  0 siblings, 0 replies; 2+ messages in thread
From: Borg Onion @ 2012-01-08 11:42 UTC (permalink / raw)
  To: gcc-help

Of course, it helps if you actually use GCC 4.6 and not 4.5.3 when
trying to compile.  D'oh!  My bad.  Please ignore.  Everything works
as expected/documented:

~/t $ cat test.c
#include <stdio.h>

void main()
{
        __int128 a = 1, b;
        b = __sync_val_compare_and_swap(&a, 1, 2);
        printf("Returned value = %d, New value = %d\n", (int)b, (int)a);
}
~/t $ gcc-4.6.3-pre9999 -mcx16 test.c -o test
~/t $ ./test
Returned value = 1, New value = 2
~/t $ objdump -d test | grep cmpxchg16b
  40059e:       f0 48 0f c7 0e          lock cmpxchg16b (%rsi)
~/t $



On 7 January 2012 17:25, Borg Onion <borg.onion@gmail.com> wrote:
> Hello,
>
> I'm trying to figure out how to make use of CMPXCHG16B.  The GCC
> manual looks to point towards __sync_val_compare_and_swap() with
> __int128 data types and the -mcx16 compile flag.  But this data type
> is not present when I try to compile with it, nor do I think my 4th
> generation Opteron is capable of holding __int128 values in its
> registers.  So what's the equivalent of .Net's
> _InterlockedCompareExchange128()
> [http://msdn.microsoft.com/en-us/library/bb514094.aspx] in GCC-land?
> I'm trying to avoid having to (re?)implement it myself as these folks
> did:
>
> http://stackoverflow.com/questions/4825400/cmpxchg16b-correct
>
> Thanks for any guidance,
>
> --Borg Onion



-- 
--Borg Onion

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

end of thread, other threads:[~2012-01-08  2:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-08  2:32 How to make use of CMPXCHG16B? Borg Onion
2012-01-08 11:42 ` Borg Onion

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).