24 #define XCC_ASSERT(cond,msg) ({char msg[(cond)?1:(-1)]; 0;})
38 #define FORCE_TYPE(TP,x) \
39 ({ union { TP x1; typeof(x) x2; } _u ; _u.x2 = (x); _u.x1; })
48 #define xcc_slbar_VOID() do{\
49 xcc_SItype _tmp1, _tmp2;\
50 __asm__("xchgl %1,%0": "=m"(_tmp1), "=r"(_tmp2) :: "memory");\
54 #define xcc_rawcas_DI(loc,ov,nv) __xcc_rawcas_DI((loc),(ov),(nv))
56 __xcc_rawcas_DI(xcc_DItype *loc, xcc_DItype ov, xcc_DItype nv){
58 union { xcc_DItype
v; xcc_SItype w2[2]; } u;
60 __asm__ __volatile__(
"lock; cmpxchg8b %0\n"
64 :
"=m"(*loc),
"=r"(
s),
"=A"(ov)
65 :
"m" (*loc),
"1"(
s),
"2"(ov),
66 "b"(u.w2[0]),
"c"(u.w2[1]) :
"cc");
70 #define xcc_rawcas_SI(loc,ov,nv) __xcc_rawcas_SI((loc),(ov),(nv))
72 __xcc_rawcas_SI(xcc_SItype *loc, xcc_SItype ov, xcc_SItype nv){
74 __asm__ __volatile__(
"lock; cmpxchgl %6,%0\n"
78 :
"=m"(*loc),
"=r"(
s),
"=a"(ov)
79 :
"m"(*loc),
"1"(
s),
"2"(ov),
"q"(nv) :
"cc");
83 #define xcc_rawcas_HI(loc,ov,nv) __xcc_rawcas_HI((loc),(ov),(nv))
85 __xcc_rawcas_HI(xcc_HItype *loc, xcc_HItype ov, xcc_HItype nv){
87 __asm__ __volatile__(
"lock; cmpxchgw %6,%0\n"
91 :
"=m"(*loc),
"=r"(
s),
"=a"(ov)
92 :
"m"(*loc),
"1"(
s),
"2"(ov),
"q"(nv) :
"cc");
96 #define xcc_cas_HI(loc,ov,nv) __xcc_cas_HI((loc),(ov),(nv))
98 __xcc_cas_HI(xcc_HItype *loc, xcc_HItype ov, xcc_HItype nv){
99 return (*loc != ov) || xcc_rawcas_HI(loc,ov,nv);
103 #define xcc_rawcas_QI(loc,ov,nv) __xcc_rawcas_QI((loc),(ov),(nv))
104 extern __inline__
int
105 __xcc_rawcas_QI(xcc_QItype *loc, xcc_QItype ov, xcc_QItype nv){
107 __asm__ __volatile__(
"lock; cmpxchgb %6,%0\n"
111 :
"=m"(*loc),
"=r"(
s),
"=a"(ov)
112 :
"m"(*loc),
"1"(
s),
"2"(ov),
"q"(nv) :
"cc");
116 #define xcc_cas_QI(loc,ov,nv) __xcc_cas_QI((loc),(ov),(nv))
117 extern __inline__
int
118 __xcc_cas_QI(xcc_QItype *loc, xcc_QItype ov, xcc_QItype nv){
119 return (*loc != ov) || xcc_rawcas_QI(loc,ov,nv);
122 #define xcc_atomic_swap_DI(loc,v) __xcc_atomic_swap_DI((loc),(v))
123 extern __inline__ xcc_DItype
125 __asm__ __volatile__(
"movl %%eax,%%ebx\n"
126 " movl %%edx,%%ecx\n"
132 :
"=m"(*loc),
"=A"(val) :
"m"(*loc),
"1"(val)
133 :
"ecx",
"ebx",
"cc");
138 #define xcc_atomic_swap_SI(loc,v) __xcc_atomic_swap_SI((loc),(v))
139 extern __inline__ xcc_SItype
141 __asm__ __volatile__(
"xchgl %1,%0"
142 :
"=m"(*loc),
"=r"(val) :
"m"(*loc),
"1"(val));
147 #define xcc_atomic_swap_HI(loc,v) __xcc_atomic_swap_HI((loc),(v))
148 extern __inline__ xcc_HItype
150 __asm__ __volatile__(
"xchgw %1,%0"
151 :
"=m"(*loc),
"=r"(val) :
"m"(*loc),
"1"(val));
155 #define xcc_atomic_swap_QI(loc,v) __xcc_atomic_swap_QI((loc),(v))
156 extern __inline__ xcc_QItype
158 __asm__ __volatile__(
"xchgb %1,%0"
159 :
"=m"(*loc),
"=r"(val) :
"m"(*loc),
"1"(val));
163 #define xcc_atomic_write_DI(loc,v) __xcc_atomic_write_DI((loc),(v))
164 extern __inline__
void
165 __xcc_atomic_write_DI(xcc_DItype *loc, xcc_DItype val){
167 __asm__ __volatile__(
"movl %%eax,%%ebx\n"
168 " movl %%edx,%%ecx\n"
174 :
"=m"(*loc),
"=A"(tmp) :
"A"(val)
175 :
"ecx",
"ebx",
"cc");
178 #define xcc_atomic_read_DI(loc) __xcc_atomic_read_DI(loc)
179 extern __inline__ xcc_DItype
180 __xcc_atomic_read_DI(xcc_DItype *loc){
182 __asm__ __volatile__(
"movl %%eax,%%ebx\n"
183 " movl %%edx,%%ecx\n"
186 :
"=A"(val) :
"m"(*loc)
187 :
"ecx",
"ebx",
"cc",
"memory");
196 #define xcc_aabar_VOID() __asm__ __volatile__("mb":::"memory")
198 #define xcc_rawcas_DI(loc,ov,nv) xcc_cas_DI((loc),(ov),(nv))
199 #define xcc_cas_DI(loc,ov,nv) __xcc_cas_DI((loc),(ov),(nv))
200 extern __inline__
int
201 __xcc_cas_DI(xcc_DItype *loc, xcc_DItype ov, xcc_DItype nv){
204 __asm__ __volatile__(
"ldq_l %0,%5\n"
210 :
"=&r"(tmp),
"=&r"(cmp),
"=m"(*loc)
211 :
"r"(ov),
"r"(nv),
"m"(*loc));
215 #define xcc_rawcas_SI(loc,ov,nv) xcc_cas_SI((loc),(ov),(nv))
216 #define xcc_cas_SI(loc,ov,nv) __xcc_cas_SI((loc),(ov),(nv))
217 extern __inline__
int
218 __xcc_cas_SI(xcc_SItype *loc, xcc_SItype ov, xcc_SItype nv){
221 __asm__ __volatile__(
"ldl_l %0,%5\n"
227 :
"=&r"(tmp),
"=&r"(cmp),
"=m"(*loc)
228 :
"rI"(ov),
"rI"(nv),
"m"(*loc));
232 #define xcc_atomic_write_HI(loc,v) __xcc_atomic_write_HI((loc),(v))
233 extern __inline__
void
234 __xcc_atomic_write_HI(xcc_HItype *loc, xcc_HItype val){
235 xcc_DItype _tmp1, _tmp2, *_tmpa, *_tmpb;
236 __asm__ __volatile__(
"lda %3,%0\n"
239 "1: ldq_l %1,0(%4)\n"
244 :
"=m"(*loc),
"=r"(_tmp1),
"=r"(_tmp2),
245 "=&r"(_tmpa),
"=&r"(_tmpb)
246 :
"m"(*loc),
"r"(val));
250 #define xcc_atomic_write_QI(loc,v) __xcc_atomic_write_QI((loc),(v))
251 extern __inline__
void
252 __xcc_atomic_write_QI(xcc_QItype *loc, xcc_QItype val){
253 xcc_DItype _tmp1, _tmp2, *_tmpa, *_tmpb;
254 __asm__ __volatile__(
"lda %3,%0\n"
257 "1: ldq_l %1,0(%4)\n"
262 :
"=m"(*loc),
"=r"(_tmp1),
"=r"(_tmp2),
263 "=&r"(_tmpa),
"=&r"(_tmpb)
264 :
"m"(*loc),
"r"(val));
272 #define xcc_slbar_VOID() __asm__("membar #StoreLoad"::: "memory")
274 #define xcc_rawcas_DI(loc,ov,nv) __xcc_rawcas_DI((loc),(ov),(nv))
275 extern __inline__
int
276 __xcc_rawcas_DI(xcc_DItype *loc, xcc_DItype ov, xcc_DItype nv){
277 xcc_DItype tmpa, tmpb, ovm=ov, nvm=nv;
278 __asm__ __volatile__(
"ldx %6,%2\n"
282 :
"=m"(*loc),
"=m"(nvm),
"=&r"(tmpa),
"=&r"(tmpb)
283 :
"m"(*loc),
"r"(loc),
"m"(nvm),
"m"(ovm) :
"cc");
288 #define xcc_rawcas_SI(loc,ov,nv) __xcc_rawcas_SI((loc),(ov),(nv))
289 extern __inline__
int
290 __xcc_rawcas_SI(xcc_SItype *loc, xcc_SItype ov, xcc_SItype nv){
291 __asm__ __volatile__(
"cas [%3],%5,%1"
292 :
"=m"(*loc),
"=&r"(nv)
293 :
"m"(*loc),
"r"(loc),
"1"(nv),
"r"(ov) :
"cc");
303 #define xcc_aabar_VOID() __asm__ __volatile__("sync":::"memory")
304 #define xcc_isync_VOID() __asm__ __volatile__("isync":::"memory")
305 #define xcc_ssbar_VOID() __asm__ __volatile__("eieio":::"memory")
307 #define xcc_rawcas_DI(loc,ov,nv) xcc_cas_SI((loc),(ov),(nv))
308 #define xcc_cas_DI(loc,ov,nv) XCC_ASSERT(0,_64bit_cas_not_support)
309 #define xcc_atomic_swap_DI(loc,v) XCC_ASSERT(0,_64bit_cas_not_support)
310 #define xcc_cas_DF(loc,ov,nv) XCC_ASSERT(0,_64bit_cas_not_support)
311 #define xcc_atomic_swap_DF(loc,v) XCC_ASSERT(0,_64bit_cas_not_support)
313 #define xcc_rawcas_SI(loc,ov,nv) xcc_cas_SI((loc),(ov),(nv))
314 #define xcc_cas_SI(loc,ov,nv) __xcc_cas_SI((loc),(ov),(nv))
315 extern __inline__
int
316 __xcc_cas_SI(xcc_SItype *loc, xcc_SItype ov, xcc_SItype nv){
319 __asm__ __volatile__(
"lwarx %2,0,%4\n"
326 :
"=m"(*loc),
"=r"(cmp),
"=&r"(tmp)
327 :
"m"(*loc),
"r"(loc),
"r"(nv),
"r"(ov),
"1"(cmp) :
"cc");
336 #define xcc_rawcas_DI(loc,ov,nv) xcc_cas_DI((loc),(ov),(nv))
337 #define xcc_cas_DI(loc,ov,nv) __xcc_cas_DI((loc),(ov),(nv))
338 extern __inline__
int
339 __xcc_cas_DI(xcc_DItype *loc, xcc_DItype ov, xcc_DItype nv){
342 __asm__ __volatile__(
".set noreorder\n"
350 :
"=&r"(tmp),
"=&r"(cmp),
"=m"(*loc)
351 :
"r"(ov),
"r"(nv),
"m"(*loc));
355 #define xcc_rawcas_SI(loc,ov,nv) xcc_cas_SI((loc),(ov),(nv))
356 #define xcc_cas_SI(loc,ov,nv) __xcc_cas_SI((loc),(ov),(nv))
357 extern __inline__
int
358 __xcc_cas_SI(xcc_SItype *loc, xcc_SItype ov, xcc_SItype nv){
361 __asm__ __volatile__(
".set noreorder\n"
369 :
"=&r"(tmp),
"=&r"(cmp),
"=m"(*loc)
370 :
"r"(ov),
"r"(nv),
"m"(*loc));
380 #ifndef xcc_nnbar_VOID
381 #define xcc_nnbar_VOID() __asm__ __volatile__("":::"memory")
385 #define xcc_cas_DI(loc,ov,nv) __xcc_cas_DI((loc),(ov),(nv))
386 extern __inline__
int
388 return (*loc != ov) || xcc_rawcas_DI(loc,ov,nv);
393 #define xcc_cas_SI(loc,ov,nv) __xcc_cas_SI((loc),(ov),(nv))
394 extern __inline__
int
396 return (*loc != ov) || xcc_rawcas_SI(loc,ov,nv);
401 #define xcc_cas_HI(loc,ov,nv) __xcc_cas_HI((loc),(ov),(nv))
402 extern __inline__
int
404 int ofs = (loc - (xcc_HItype *)(xcc_SItype *)0) & 1;
405 xcc_SItype *p = (xcc_SItype *)(loc - ofs), uov = *p;
406 union { xcc_SItype
v; xcc_HItype
s[2]; } unv;
408 if(unv.s[ofs] != ov)
return 1;
410 return xcc_rawcas_SI(p,uov,unv.v);
415 #define xcc_cas_QI(loc,ov,nv) __xcc_cas_QI((loc),(ov),(nv))
416 extern __inline__
int
418 int ofs = (loc - (xcc_QItype *)(xcc_SItype *)0) & 3;
419 xcc_SItype *p = (xcc_SItype *)(loc - ofs), uov = *p;
420 union { xcc_SItype
v; xcc_QItype c[4]; } unv;
422 if(unv.c[ofs] != ov)
return 1;
424 return xcc_rawcas_SI(p,uov,unv.v);
429 #define xcc_cas_DF(loc,ov,nv) __xcc_cas_DF((loc),(ov),(nv))
430 extern __inline__
int
439 #define xcc_cas_SF(loc,ov,nv) __xcc_cas_SF((loc),(ov),(nv))
440 extern __inline__
int
448 #ifndef xcc_atomic_swap_DI
449 #define xcc_atomic_swap_DI(loc,v) __xcc_atomic_swap_DI((loc),(v))
450 extern __inline__ xcc_DItype
453 do{ ov = *loc; }
while(xcc_rawcas_DI(loc,ov,val));
458 #ifndef xcc_atomic_swap_SI
459 #define xcc_atomic_swap_SI(loc,v) __xcc_atomic_swap_SI((loc),(v))
460 extern __inline__ xcc_SItype
463 do{ ov = *loc; }
while(xcc_rawcas_SI(loc,ov,val));
468 #ifndef xcc_atomic_swap_HI
469 #define xcc_atomic_swap_HI(loc,v) __xcc_atomic_swap_HI((loc),(v))
470 extern __inline__ xcc_HItype
472 int ofs = (loc- (xcc_HItype *)(xcc_SItype *)0) & 1;
473 xcc_SItype *p = (xcc_SItype *)(loc - ofs), uov;
474 union { xcc_SItype
v; xcc_HItype
s[2]; } unv;
475 do{ unv.v = uov = *p; unv.s[ofs] = val;
476 }
while(xcc_rawcas_SI(p,uov,unv.v));
477 unv.v = uov;
return unv.s[ofs];
481 #ifndef xcc_atomic_swap_QI
482 #define xcc_atomic_swap_QI(loc,v) __xcc_atomic_swap_QI((loc),(v))
483 extern __inline__ xcc_QItype
485 int ofs = (loc- (xcc_QItype *)(xcc_SItype *)0) & 3;
486 xcc_SItype *p = (xcc_SItype *)(loc - ofs), uov;
487 union { xcc_SItype
v; xcc_QItype c[4]; } unv;
488 do{ unv.v = uov = *p ; unv.c[ofs] = val;
489 }
while(xcc_rawcas_SI(p,uov,unv.v));
490 unv.v = uov;
return unv.c[ofs];
494 #ifndef xcc_atomic_swap_DF
495 #define xcc_atomic_swap_DF(loc,v) __xcc_atomic_swap_DF((loc),(v))
496 extern __inline__ xcc_DFtype
504 #ifndef xcc_atomic_swap_SF
505 #define xcc_atomic_swap_SF(loc,v) __xcc_atomic_swap_SF((loc),(v))
506 extern __inline__ xcc_SFtype
524 #define xcc_atomic_read_long_long(loc)\
525 (sizeof(*(loc))==8 ? xcc_atomic_read_DI((xcc_DItype *)(loc)) :\
526 XCC_ASSERT((sizeof(*(loc))==8), atomic_read_long_long))
528 #define xcc_atomic_write_long_long(loc,v)\
529 do{ if(sizeof(*(loc))==8) xcc_atomic_write_DI((xcc_DItype *)(loc),(v)); \
530 else XCC_ASSERT((sizeof(*(loc))==8), atomic_write_long_long); }while(0)
532 #define xcc_slbar() xcc_slbar_VOID()
533 #define xcc_sabar() xcc_slbar_VOID()
534 #define xcc_albar() xcc_slbar_VOID()
535 #define xcc_aabar() xcc_slbar_VOID()
537 #define xcc_start_access_after_lock() xcc_nnbar_VOID()
538 #define xcc_start_read_after_lock() xcc_nnbar_VOID()
539 #define xcc_start_write_after_lock() xcc_nnbar_VOID()
546 #define xcc_atomic_write_char(loc,v)\
547 do{ if(sizeof(*(loc))==1) xcc_atomic_write_QI((xcc_QItype *)(loc),(v)); \
548 else XCC_ASSERT((sizeof(*(loc))==1), atomic_write_char); }while(0)
550 #define xcc_atomic_write_short(loc,v)\
551 do{ if(sizeof(*(loc))==2) xcc_atomic_write_HI((xcc_HItype *)(loc),(v)); \
552 else XCC_ASSERT((sizeof(*(loc))==2), atomic_write_short); }while(0)
554 #define xcc_defaultbar_VOID() xcc_aabar_VOID()
556 #define XCC_LONG_TYPE_SIZE 8
557 #define XCC_PTR_TYPE_SIZE 8
566 #define xcc_slbar() xcc_slbar_VOID()
567 #define xcc_sabar() xcc_slbar_VOID()
568 #define xcc_albar() xcc_slbar_VOID()
569 #define xcc_aabar() xcc_slbar_VOID()
571 #define xcc_start_access_after_lock() xcc_nnbar_VOID()
572 #define xcc_start_read_after_lock() xcc_nnbar_VOID()
573 #define xcc_start_write_after_lock() xcc_nnbar_VOID()
582 #define xcc_atomic_read_long_long(loc) XCC_ASSERT(0, atomic_read_long_long)
583 #define xcc_atomic_write_long_long(loc,v)\
584 do{ XCC_ASSERT((sizeof(*(loc))==8), atomic_write_long_long); }while(0)
585 #define xcc_atomic_swap_long_long(loc,v) XCC_ASSERT(0, atomic_swap_long_long)
586 #define xcc_cas_long_long(loc,ov,nv) XCC_ASSERT(0, cas_long_long)
587 #define xcc_atomic_swap_double(loc,v) XCC_ASSERT(0, atomic_swap_double)
588 #define xcc_cas_double(loc,ov,nv) XCC_ASSERT(0, cas_double)
590 #define xcc_defaultbar_VOID() xcc_aabar_VOID()
591 #define xcc_ssbar() xcc_ssbar_VOID()
592 #define xcc_start_access_after_lock() xcc_isync_VOID()
593 #define xcc_start_read_after_lock() xcc_isync_VOID()
594 #define xcc_start_write_after_lock() xcc_isync_VOID()
601 #define XCC_INT_TYPE_SIZE (_MIPS_SZINT/8)
602 #define XCC_LONG_TYPE_SIZE (_MIPS_SZLONG/8)
603 #define XCC_PTR_TYPE_SIZE (_MIPS_SZPTR/8)
611 #ifndef XCC_CHAR_TYPE_SIZE
612 #define XCC_CHAR_TYPE_SIZE 1
614 #ifndef XCC_SHORT_TYPE_SIZE
615 #define XCC_SHORT_TYPE_SIZE 2
617 #ifndef XCC_INT_TYPE_SIZE
618 #define XCC_INT_TYPE_SIZE 4
620 #ifndef XCC_LONG_TYPE_SIZE
621 #define XCC_LONG_TYPE_SIZE 4
623 #ifndef XCC_LONG_LONG_TYPE_SIZE
624 #define XCC_LONG_LONG_TYPE_SIZE 8
626 #ifndef XCC_FLOAT_TYPE_SIZE
627 #define XCC_FLOAT_TYPE_SIZE 4
629 #ifndef XCC_DOUBLE_TYPE_SIZE
630 #define XCC_DOUBLE_TYPE_SIZE 8
632 #ifndef XCC_PTR_TYPE_SIZE
633 #define XCC_PTR_TYPE_SIZE 4
636 #ifndef xcc_atomic_read_char
637 #define xcc_atomic_read_char(loc) (*(volatile char *)(loc))
639 #ifndef xcc_atomic_read_short
640 #define xcc_atomic_read_short(loc) (*(volatile short *)(loc))
642 #ifndef xcc_atomic_read_int
643 #define xcc_atomic_read_int(loc) (*(volatile int *)(loc))
645 #ifndef xcc_atomic_read_long
646 #define xcc_atomic_read_long(loc) (*(volatile long *)(loc))
649 #ifndef xcc_atomic_read_long_long
650 #define xcc_atomic_read_long_long(loc) (*(volatile long long *)(loc))
652 #ifndef xcc_atomic_read_float
653 #define xcc_atomic_read_float(loc) (*(volatile float *)(loc))
655 #ifndef xcc_atomic_read_double
656 #define xcc_atomic_read_double(loc) (*(volatile double *)(loc))
658 #ifndef xcc_atomic_read_ptr
659 #define xcc_atomic_read_ptr(loc) (*(void * volatile *)(loc))
663 #ifndef xcc_atomic_write_char
664 #define xcc_atomic_write_char(loc,v) do{*(volatile char *)(loc)=(v);}while(0)
666 #ifndef xcc_atomic_write_short
667 #define xcc_atomic_write_short(loc,v) do{*(volatile short *)(loc)=(v);}while(0)
669 #ifndef xcc_atomic_write_int
670 #define xcc_atomic_write_int(loc,v) do{*(volatile int *)(loc)=(v);}while(0)
672 #ifndef xcc_atomic_write_long
673 #define xcc_atomic_write_long(loc,v) do{*(volatile long *)(loc)=(v);}while(0)
676 #ifndef xcc_atomic_write_long_long
677 #define xcc_atomic_write_long_long(loc,v)\
678 do{*(volatile long long *)(loc)=(v);}while(0)
680 #ifndef xcc_atomic_write_float
681 #define xcc_atomic_write_float(loc,v)\
682 do{*(volatile float *)(loc)=(v);}while(0)
684 #ifndef xcc_atomic_write_double
685 #define xcc_atomic_write_double(loc,v)\
686 do{*(volatile double *)(loc)=(v);}while(0)
688 #ifndef xcc_atomic_write_ptr
689 #define xcc_atomic_write_ptr(loc,v) do{*(void * volatile *)(loc)=(v);}while(0)
692 #ifndef xcc_atomic_swap_char
693 #define xcc_atomic_swap_char(loc,v)\
694 (sizeof(*(loc))==1 ? xcc_atomic_swap_QI((xcc_QItype *)(loc),(v)) :\
695 XCC_ASSERT((sizeof(*(loc))==1), atomic_swap_char))
698 #ifndef xcc_atomic_swap_short
699 #define xcc_atomic_swap_short(loc,v)\
700 (sizeof(*(loc))==2 ? xcc_atomic_swap_HI((xcc_HItype *)(loc),(v)) :\
701 XCC_ASSERT((sizeof(*(loc))==2), atomic_swap_short))
704 #if XCC_INT_TYPE_SIZE == 4
705 #ifndef xcc_atomic_swap_int
706 #define xcc_atomic_swap_int(loc,v)\
707 (sizeof(*(loc))==4 ? xcc_atomic_swap_SI((xcc_SItype *)(loc),(v)) :\
708 XCC_ASSERT((sizeof(*(loc))==4), atomic_swap_int))
710 #elif XCC_INT_TYPE_SIZE == 8
711 #ifndef xcc_atomic_swap_int
712 #define xcc_atomic_swap_int(loc,v)\
713 (sizeof(*(loc))==8 ? xcc_atomic_swap_DI((xcc_DItype *)(loc),(v)) :\
714 XCC_ASSERT((sizeof(*(loc))==8), atomic_swap_int))
718 #if XCC_LONG_TYPE_SIZE == 4
719 #ifndef xcc_atomic_swap_long
720 #define xcc_atomic_swap_long(loc,v)\
721 (sizeof(*(loc))==4 ? xcc_atomic_swap_SI((xcc_SItype *)(loc),(v)) :\
722 XCC_ASSERT((sizeof(*(loc))==4), atomic_swap_long))
724 #elif XCC_LONG_TYPE_SIZE == 8
725 #ifndef xcc_atomic_swap_long
726 #define xcc_atomic_swap_long(loc,v)\
727 (sizeof(*(loc))==8 ? xcc_atomic_swap_DI((xcc_DItype *)(loc),(v)) :\
728 XCC_ASSERT((sizeof(*(loc))==8), atomic_swap_long))
732 #ifndef xcc_atomic_swap_long_long
733 #define xcc_atomic_swap_long_long(loc,v)\
734 (sizeof(*(loc))==8 ? xcc_atomic_swap_DI((xcc_DItype *)(loc),(v)) :\
735 XCC_ASSERT((sizeof(*(loc))==8), atomic_swap_long_long))
738 #ifndef xcc_atomic_swap
739 #define xcc_atomic_swap(loc,v)\
740 (sizeof(*(loc))==1 ? xcc_atomic_swap_QI((xcc_QItype *)(loc),(v)) :\
741 sizeof(*(loc))==2 ? xcc_atomic_swap_HI((xcc_HItype *)(loc),(v)) :\
742 sizeof(*(loc))==4 ? xcc_atomic_swap_SI((xcc_SItype *)(loc),(v)) :\
743 sizeof(*(loc))==8 ? xcc_atomic_swap_DI((xcc_DItype *)(loc),(v)) :\
744 XCC_ASSERT(((sizeof(*(loc))==1) && (__alignof__(*(loc))==1) ||\
745 (sizeof(*(loc))==2) && (__alignof__(*(loc))==2) ||\
746 (sizeof(*(loc))==4) && (__alignof__(*(loc))==4) ||\
747 (sizeof(*(loc))==8) && (__alignof__(*(loc))==8)),\
751 #ifndef xcc_atomic_swap_float
752 #define xcc_atomic_swap_float(loc,v)\
753 (sizeof(*(loc))==4 ? xcc_atomic_swap_SF((xcc_SFtype *)(loc),(v)) :\
754 XCC_ASSERT((sizeof(*(loc))==4), atomic_swap_float))
757 #ifndef xcc_atomic_swap_double
758 #define xcc_atomic_swap_double(loc,v)\
759 (sizeof(*(loc))==8 ? xcc_atomic_swap_DF((xcc_DFtype *)(loc),(v)) :\
760 XCC_ASSERT((sizeof(*(loc))==8), atomic_swap_double))
763 #if XCC_PTR_TYPE_SIZE == 4
764 #ifndef xcc_atomic_swap_ptr
765 #define xcc_atomic_swap_ptr(loc,v)\
766 (sizeof(*(loc))==4 ? \
767 xcc_atomic_swap_SI((xcc_SItype *)(loc),(xcc_SItype)(v)) :\
768 XCC_ASSERT((sizeof(*(loc))==4), atomic_swap_ptr))
770 #elif XCC_PTR_TYPE_SIZE == 8
771 #ifndef xcc_atomic_swap_ptr
772 #define xcc_atomic_swap_ptr(loc,v)\
773 (sizeof(*(loc))==8 ? \
774 xcc_atomic_swap_DI((xcc_DItype *)(loc),(xcc_DItype)(v)) :\
775 XCC_ASSERT((sizeof(*(loc))==8), atomic_swap_ptr))
780 #define xcc_cas_char(loc,ov,nv)\
781 (sizeof(*(loc))==1 ? xcc_cas_QI((xcc_QItype *)(loc),(ov),(nv)) :\
782 XCC_ASSERT((sizeof(*(loc))==1), cas_char))
785 #ifndef xcc_cas_short
786 #define xcc_cas_short(loc,ov,nv)\
787 (sizeof(*(loc))==2 ? xcc_cas_HI((xcc_HItype *)(loc),(ov),(nv)) :\
788 XCC_ASSERT((sizeof(*(loc))==2), cas_short))
791 #if XCC_INT_TYPE_SIZE == 4
793 #define xcc_cas_int(loc,ov,nv)\
794 (sizeof(*(loc))==4 ? xcc_cas_SI((xcc_SItype *)(loc),(ov),(nv)) :\
795 XCC_ASSERT((sizeof(*(loc))==4), cas_int))
797 #elif XCC_INT_TYPE_SIZE == 8
799 #define xcc_cas_int(loc,ov,nv)\
800 (sizeof(*(loc))==8 ? xcc_cas_DI((xcc_DItype *)(loc),(ov),(nv)) :\
801 XCC_ASSERT((sizeof(*(loc))==8), cas_int))
806 #if XCC_INT_TYPE_SIZE == 4
807 #ifndef xcc_rawcas_int
808 #define xcc_rawcas_int(loc,ov,nv)\
809 (sizeof(*(loc))==4 ? xcc_rawcas_SI((xcc_SItype *)(loc),(ov),(nv)) :\
810 XCC_ASSERT((sizeof(*(loc))==4), rawcas_int))
812 #elif XCC_INT_TYPE_SIZE == 8
813 #ifndef xcc_rawcas_int
814 #define xcc_rawcas_int(loc,ov,nv)\
815 (sizeof(*(loc))==8 ? xcc_rawcas_DI((xcc_DItype *)(loc),(ov),(nv)) :\
816 XCC_ASSERT((sizeof(*(loc))==8), rawcas_int))
820 #if XCC_LONG_TYPE_SIZE == 4
822 #define xcc_cas_long(loc,ov,nv)\
823 (sizeof(*(loc))==4 ? xcc_cas_SI((xcc_SItype *)(loc),(ov),(nv)) :\
824 XCC_ASSERT((sizeof(*(loc))==4), cas_long))
826 #elif XCC_LONG_TYPE_SIZE == 8
828 #define xcc_cas_long(loc,ov,nv)\
829 (sizeof(*(loc))==8 ? xcc_cas_DI((xcc_DItype *)(loc),(ov),(nv)) :\
830 XCC_ASSERT((sizeof(*(loc))==8), cas_long))
834 #ifndef xcc_cas_long_long
835 #define xcc_cas_long_long(loc,ov,nv)\
836 (sizeof(*(loc))==8 ? xcc_cas_DI((xcc_DItype *)(loc),(ov),(nv)) :\
837 XCC_ASSERT((sizeof(*(loc))==8), cas_long_long))
840 #ifndef xcc_cas_float
841 #define xcc_cas_float(loc,ov,nv)\
842 (sizeof(*(loc))==4 ? xcc_cas_SF((xcc_SFtype *)(loc),(ov),(nv)) :\
843 XCC_ASSERT((sizeof(*(loc))==4), cas_float))
846 #ifndef xcc_cas_double
847 #define xcc_cas_double(loc,ov,nv)\
848 (sizeof(*(loc))==8 ? xcc_cas_DF((xcc_DFtype *)(loc),(ov),(nv)) :\
849 XCC_ASSERT((sizeof(*(loc))==8), cas_double))
852 #if XCC_PTR_TYPE_SIZE == 4
854 #define xcc_cas_ptr(loc,ov,nv)\
855 (sizeof(*(loc))==4 ? \
856 xcc_cas_SI((xcc_SItype *)(loc),(xcc_SItype)(ov),(xcc_SItype)(nv)) :\
857 XCC_ASSERT((sizeof(*(loc))==4), cas_ptr))
859 #elif XCC_PTR_TYPE_SIZE == 8
861 #define xcc_cas_ptr(loc,ov,nv)\
862 (sizeof(*(loc))==8 ? \
863 xcc_cas_DI((xcc_DItype *)(loc),(xcc_DItype)(ov),(xcc_DItype)(nv)) :\
864 XCC_ASSERT((sizeof(*(loc))==8), cas_ptr))
868 #ifndef xcc_defaultbar_VOID
869 #define xcc_defaultbar_VOID() xcc_nnbar_VOID()
873 #define xcc_ssbar() xcc_defaultbar_VOID()
876 #define xcc_slbar() xcc_defaultbar_VOID()
879 #define xcc_sabar() xcc_defaultbar_VOID()
882 #define xcc_lsbar() xcc_defaultbar_VOID()
885 #define xcc_llbar() xcc_defaultbar_VOID()
888 #define xcc_labar() xcc_defaultbar_VOID()
891 #define xcc_asbar() xcc_defaultbar_VOID()
894 #define xcc_albar() xcc_defaultbar_VOID()
897 #define xcc_aabar() xcc_defaultbar_VOID()
901 #ifndef xcc_start_access_after_lock
902 #define xcc_start_access_after_lock() xcc_aabar()
904 #ifndef xcc_start_access_after_read
905 #define xcc_start_access_after_read() xcc_labar()
907 #ifndef xcc_start_access_after_write
908 #define xcc_start_access_after_write() xcc_sabar()
910 #ifndef xcc_start_read_after_lock
911 #define xcc_start_read_after_lock() xcc_albar()
913 #ifndef xcc_start_read_after_read
914 #define xcc_start_read_after_read() xcc_llbar()
916 #ifndef xcc_start_read_after_write
917 #define xcc_start_read_after_write() xcc_slbar()
919 #ifndef xcc_start_write_after_lock
920 #define xcc_start_write_after_lock() xcc_asbar()
922 #ifndef xcc_start_write_after_read
923 #define xcc_start_write_after_read() xcc_lsbar()
925 #ifndef xcc_start_write_after_write
926 #define xcc_start_write_after_write() xcc_ssbar()
929 #ifndef xcc_finish_access_before_unlock
930 #define xcc_finish_access_before_unlock() xcc_asbar()
932 #ifndef xcc_finish_access_before_read
933 #define xcc_finish_access_before_read() xcc_albar()
935 #ifndef xcc_finish_access_before_write
936 #define xcc_finish_access_before_write() xcc_asbar()
938 #ifndef xcc_finish_read_before_unlock
939 #define xcc_finish_read_before_unlock() xcc_lsbar()
941 #ifndef xcc_finish_read_before_read
942 #define xcc_finish_read_before_read() xcc_llbar()
944 #ifndef xcc_finish_read_before_write
945 #define xcc_finish_read_before_write() xcc_lsbar()
947 #ifndef xcc_finish_write_before_unlock
948 #define xcc_finish_write_before_unlock() xcc_ssbar()
950 #ifndef xcc_finish_write_before_read
951 #define xcc_finish_write_before_read() xcc_slbar()
953 #ifndef xcc_finish_write_before_write
954 #define xcc_finish_write_before_write() xcc_ssbar()
957 #ifndef xcc_LOCK_INITIALIZER
958 #define xcc_LOCK_INITIALIZER 0
961 #define xcc_lock_t int
964 #define xcc_try_lock(loc) xcc_cas_int((loc),0,1)
966 #ifndef xcc_spin_lock
967 #define xcc_spin_lock(loc) __xcc_spin_lock(loc)
968 extern __inline__
void
971 #ifndef xcc_release_lock
972 #define xcc_release_lock(loc) xcc_atomic_write_int((loc),0)
975 #ifndef xcc_RWLOCK_INITIALIZER
976 #define xcc_RWLOCK_INITIALIZER 0
979 #define xcc_rwlock_t int
981 #ifndef xcc_try_rlock
982 #define xcc_try_rlock(loc) __xcc_try_rlock(loc)
983 extern __inline__
int
989 #ifndef xcc_spin_rlock
990 #define xcc_spin_rlock(loc) __xcc_spin_rlock(loc)
991 extern __inline__
void
994 #ifndef xcc_release_rlock
995 #define xcc_release_rlock(loc) __xcc_release_rlock(loc)
996 extern __inline__
void
1001 #ifndef xcc_try_wlock
1002 #define xcc_try_wlock(loc) xcc_cas_int((loc),0,-1)
1004 #ifndef xcc_spin_wlock
1005 #define xcc_spin_wlock(loc) __xcc_spin_wlock(loc)
1006 extern __inline__
void
1009 #ifndef xcc_release_wlock
1010 #define xcc_release_wlock(loc) xcc_atomic_write_int((loc),0)
1019 #define atomic_read_char(loc) xcc_atomic_read_char(&(loc))
1020 #define atomic_read_short(loc) xcc_atomic_read_short(&(loc))
1021 #define atomic_read_int(loc) xcc_atomic_read_int(&(loc))
1022 #define atomic_read_long(loc) xcc_atomic_read_long(&(loc))
1023 #define atomic_read_long_long(loc) xcc_atomic_read_long_long(&(loc))
1024 #define atomic_read_float(loc) xcc_atomic_read_float(&(loc))
1025 #define atomic_read_double(loc) xcc_atomic_read_double(&(loc))
1026 #define atomic_read_ptr(loc) xcc_atomic_read_ptr(&(loc))
1028 #define atomic_read_volatile_char(loc) atomic_read_char(loc)
1029 #define atomic_read_volatile_short(loc) atomic_read_short(loc)
1030 #define atomic_read_volatile_int(loc) atomic_read_int(loc)
1031 #define atomic_read_volatile_long(loc) atomic_read_long(loc)
1032 #define atomic_read_volatile_long_long(loc) atomic_read_long_long(loc)
1033 #define atomic_read_volatile_float(loc) atomic_read_float(loc)
1034 #define atomic_read_volatile_double(loc) atomic_read_double(loc)
1035 #define atomic_read_volatile_ptr(loc) atomic_read_ptr(loc)
1037 #define read_volatile_char(loc) atomic_read_char(loc)
1038 #define read_volatile_short(loc) atomic_read_short(loc)
1039 #define read_volatile_int(loc) atomic_read_int(loc)
1040 #define read_volatile_long(loc) atomic_read_long(loc)
1041 #define read_volatile_long_long(loc) atomic_read_long_long(loc)
1042 #define read_volatile_float(loc) atomic_read_float(loc)
1043 #define read_volatile_double(loc) atomic_read_double(loc)
1044 #define read_volatile_ptr(loc) atomic_read_ptr(loc)
1046 #define atomic_write_char(loc,v) xcc_atomic_write_char(&(loc),(v))
1047 #define atomic_write_short(loc,v) xcc_atomic_write_short(&(loc),(v))
1048 #define atomic_write_int(loc,v) xcc_atomic_write_int(&(loc),(v))
1049 #define atomic_write_long(loc,v) xcc_atomic_write_long(&(loc),(v))
1050 #define atomic_write_long_long(loc,v) xcc_atomic_write_long_long(&(loc),(v))
1051 #define atomic_write_float(loc,v) xcc_atomic_write_float(&(loc),(v))
1052 #define atomic_write_double(loc,v) xcc_atomic_write_double(&(loc),(v))
1053 #define atomic_write_ptr(loc,v) xcc_atomic_write_ptr(&(loc),(v))
1055 #define atomic_write_volatile_char(loc, v) atomic_write_char((loc), (v))
1056 #define atomic_write_volatile_short(loc, v) atomic_write_short((loc), (v))
1057 #define atomic_write_volatile_int(loc, v) atomic_write_int((loc), (v))
1058 #define atomic_write_volatile_long(loc, v) atomic_write_long((loc), (v))
1059 #define atomic_write_volatile_long_long(loc, v) \
1060 atomic_write_long_long((loc), (v))
1061 #define atomic_write_volatile_float(loc, v) atomic_write_float((loc), (v))
1062 #define atomic_write_volatile_double(loc, v) atomic_write_double((loc), (v))
1063 #define atomic_write_volatile_ptr(loc, v) atomic_write_ptr((loc), (v))
1065 #define write_volatile_char(loc, v) atomic_write_char((loc), (v))
1066 #define write_volatile_short(loc, v) atomic_write_short((loc), (v))
1067 #define write_volatile_int(loc, v) atomic_write_int((loc), (v))
1068 #define write_volatile_long(loc, v) atomic_write_long((loc), (v))
1069 #define write_volatile_long_long(loc, v) atomic_write_long_long((loc), (v))
1070 #define write_volatile_float(loc, v) atomic_write_float((loc), (v))
1071 #define write_volatile_double(loc, v) atomic_write_double((loc), (v))
1072 #define write_volatile_ptr(loc, v) atomic_write_ptr((loc), (v))
1074 #define atomic_swap_char(loc,v) xcc_atomic_swap_char(&(loc),(v))
1075 #define atomic_swap_short(loc,v) xcc_atomic_swap_short(&(loc),(v))
1076 #define atomic_swap_int(loc,v) xcc_atomic_swap_int(&(loc),(v))
1077 #define atomic_swap_long(loc,v) xcc_atomic_swap_long(&(loc),(v))
1078 #define atomic_swap_long_long(loc,v) xcc_atomic_swap_long_long(&(loc),(v))
1079 #define atomic_swap_float(loc,v) xcc_atomic_swap_float(&(loc),(v))
1080 #define atomic_swap_double(loc,v) xcc_atomic_swap_double(&(loc),(v))
1081 #define atomic_swap_ptr(loc,v) xcc_atomic_swap_ptr(&(loc),(v))
1083 #define atomic_swap(loc,v) xcc_atomic_swap(&(loc),(v))
1085 #define cas_char(loc,ov,nv) xcc_cas_char(&(loc),(ov),(nv))
1086 #define cas_short(loc,ov,nv) xcc_cas_short(&(loc),(ov),(nv))
1087 #define cas_int(loc,ov,nv) xcc_cas_int(&(loc),(ov),(nv))
1088 #define cas_long(loc,ov,nv) xcc_cas_long(&(loc),(ov),(nv))
1089 #define cas_long_long(loc,ov,nv) xcc_cas_long_long(&(loc),(ov),(nv))
1090 #define cas_float(loc,ov,nv) xcc_cas_float(&(loc),(ov),(nv))
1091 #define cas_double(loc,ov,nv) xcc_cas_double(&(loc),(ov),(nv))
1092 #define cas_ptr(loc,ov,nv) xcc_cas_ptr(&(loc),(ov),(nv))
1094 #define ssbar() xcc_ssbar()
1095 #define slbar() xcc_slbar()
1096 #define sabar() xcc_sabar()
1097 #define lsbar() xcc_lsbar()
1098 #define llbar() xcc_llbar()
1099 #define labar() xcc_labar()
1100 #define asbar() xcc_asbar()
1101 #define albar() xcc_albar()
1102 #define aabar() xcc_aabar()
1104 #define start_access_after_lock() xcc_start_access_after_lock()
1105 #define start_access_after_read() xcc_start_access_after_read()
1106 #define start_access_after_write() xcc_start_access_after_write()
1107 #define start_read_after_lock() xcc_start_read_after_lock()
1108 #define start_read_after_read() xcc_start_read_after_read()
1109 #define start_read_after_write() xcc_start_read_after_write()
1110 #define start_write_after_lock() xcc_start_write_after_lock()
1111 #define start_write_after_read() xcc_start_write_after_read()
1112 #define start_write_after_write() xcc_start_write_after_write()
1114 #define finish_access_before_unlock() xcc_finish_access_before_unlock()
1115 #define finish_access_before_read() xcc_finish_access_before_read()
1116 #define finish_access_before_write() xcc_finish_access_before_write()
1117 #define finish_read_before_unlock() xcc_finish_read_before_unlock()
1118 #define finish_read_before_read() xcc_finish_read_before_read()
1119 #define finish_read_before_write() xcc_finish_read_before_write()
1120 #define finish_write_before_unlock() xcc_finish_write_before_unlock()
1121 #define finish_write_before_read() xcc_finish_write_before_read()
1122 #define finish_write_before_write() xcc_finish_write_before_write()
1124 #define LOCK_INITIALIZER xcc_LOCK_INITIALIZER
1125 #define lock_t xcc_lock_t
1126 #define try_lock(loc) xcc_try_lock(&(loc))
1127 #define spin_lock(loc) xcc_spin_lock(&(loc))
1128 #define release_lock(loc) xcc_release_lock(&(loc))
1130 #define RWLOCK_INITIALIZER xcc_RWLOCK_INITIALIZER
1132 #define try_rlock(loc) xcc_try_rlock(&(loc))
1133 #define spin_rlock(loc) xcc_spin_rlock(&(loc))
1134 #define release_rlock(loc) xcc_release_rlock(&(loc))
1135 #define try_wlock(loc) xcc_try_wlock(&(loc))
1136 #define spin_wlock(loc) xcc_spin_wlock(&(loc))
1137 #define release_wlock(loc) xcc_release_wlock(&(loc))