I am trying to write inline assembly with my C code to perform compare and swap operation. My code is:
typedef struct node {
int data;
struct node * next;
struct node * backlink;
int flag;
int mark;
} node_lf;
typedef struct searchfrom {
node_lf * current;
node_lf * next;
} return_sf;
typedef struct csArg {
node_lf * node;
int mark;
int flag;
} cs_arg;
typedef struct return_tryFlag {
node_lf * node;
int result;
} return_tf;
static inline node_lf cs(node_lf * address, cs_arg *old_val, cs_arg *new_val)
{
node_lf value = *address;
__asm__ __volatile__("lock; cmpxchg16b %0; setz %1;"
:"=m"(*(volatile node_lf *)address),
"=q"(value)
:"m"(*(volatile node_lf *)address),
"a"(old_val->mark), "d"(old_val->flag),
"b"(new_val->mark), "c"(new_val->flag)
:"memory");
return value;
}
GCC gives this error when the code is compiled:
linkedlist.c: In function 'cs': linkedlist.c:45:3: error: impossible constraint in 'asm'
__asm__ __volatile__
("lock; cmpxchg16b %0; setz %1;":"=m"(*(volatile node_lf
What is wrong in my code? And how can I fix this?
I am trying to implement the equivalent of this code:
node_lf cs (node_lf * address, cs_arg *old_val, cs_arg *new_val ) {
node_lf value = *address;
if (value.next == old_val->node && value.mark == old_val->mark &&
value.flag == old_val->flag) {
address->next = new_val->node;
address->mark = new_val->mark;
address->flag = new_val->flag;
}
return value;
}