How to use __sync_bool_compare_and_swap_16 on x86_64
Jeff Donner
jeffrey.donner@gmail.com
Thu Jul 2 02:15:00 GMT 2009
Hi,
__sync_bool_compare_and_swap(int64_t*, int64_t, int64_t) and the
equivalent __sync_bool_compare_and_swap_8(...) work with 4.4.0 (and
trunk),
and __sync_bool_compare_and_swap_16 will /compile/ when you pass
128-byte structs by value, strangely. However, this won't link.
Is it possible to use __sync_bool_compare_and_swap_16 from GCC 4.4.+
at all? And if not, could it be added? I can see where the lack of any
128-byte native type to put in the signature makes a problem.
Thanks,
Jeff
#include <assert.h>
#include <iostream>
using namespace std;
struct Storage128 {
Storage128(int* ptr_, int refs_)
: ptr(ptr_)
, refs(refs_)
, remnant(0)
{}
int* ptr; // 64bits
int refs; // 32
int remnant; // 32
};
int main()
{
int three = 3;
int five = 5;
Storage128 victim(&three, 0);
Storage128 old(&three, 0);
Storage128 novo(&five, 0);
assert(sizeof(victim) == 16);
bool swapped = __sync_bool_compare_and_swap(&victim, three, five);
assert(swapped);
cout << *victim.ptr << endl;
}
More information about the Gcc-help
mailing list