1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143
|
/* GCC macros for XC-cube primitives for XC-cube shared memory model.
version 0.10
Copyright (C) 2001 Masahiro Yasugi.
Supported platform:
__i386__
__alpha__
__sparc_v9__
_POWER _ARCH_PPC
__mips__
GCC compilation options:
for UltraSparc: -mcpu=ultrasparc
for PowerPC: -mcpu=powerpc
*/
#ifndef XCCMEM_H
#define XCCMEM_H
/*
* assertion
*/
#define XCC_ASSERT(cond,msg) ({char msg[(cond)?1:(-1)]; 0;})
/*
* Tools for instructions
*/
typedef int xcc_DItype __attribute__ ((mode (DI)));
typedef int xcc_SItype __attribute__ ((mode (SI)));
typedef int xcc_HItype __attribute__ ((mode (HI)));
typedef int xcc_QItype __attribute__ ((mode (QI)));
typedef float xcc_SFtype __attribute__ ((mode (SF)));
typedef float xcc_DFtype __attribute__ ((mode (DF)));
#define FORCE_TYPE(TP,x) \
({ union { TP x1; typeof(x) x2; } _u ; _u.x2 = (x); _u.x1; })
/*
* Instructions
*/
#ifdef __i386__
/* lock add $0,(%esp) とどっちが速い? */
#define xcc_slbar_VOID() do{\
xcc_SItype _tmp1, _tmp2;\
__asm__("xchgl %1,%0": "=m"(_tmp1), "=r"(_tmp2) :: "memory");\
}while(0)
#define xcc_rawcas_DI(loc,ov,nv) __xcc_rawcas_DI((loc),(ov),(nv))
extern __inline__ int
__xcc_rawcas_DI(xcc_DItype *loc, xcc_DItype ov, xcc_DItype nv){
int s = 0;
union { xcc_DItype v; xcc_SItype w2[2]; } u;
u.v = nv;
__asm__ __volatile__("lock; cmpxchg8b %0\n"
" jz 1f\n"
" inc %1\n"
"1:"
: "=m"(*loc), "=r"(s), "=A"(ov)
: "m" (*loc), "1"(s), "2"(ov),
"b"(u.w2[0]), "c"(u.w2[1]) : "cc");
return s;
}
#define xcc_rawcas_SI(loc,ov,nv) __xcc_rawcas_SI((loc),(ov),(nv))
extern __inline__ int
__xcc_rawcas_SI(xcc_SItype *loc, xcc_SItype ov, xcc_SItype nv){
int s = 0;
__asm__ __volatile__("lock; cmpxchgl %6,%0\n"
" jz 1f\n"
" inc %1\n"
"1:"
: "=m"(*loc), "=r"(s), "=a"(ov)
: "m"(*loc), "1"(s), "2"(ov), "q"(nv) : "cc");
return s;
}
#define xcc_rawcas_HI(loc,ov,nv) __xcc_rawcas_HI((loc),(ov),(nv))
extern __inline__ int
__xcc_rawcas_HI(xcc_HItype *loc, xcc_HItype ov, xcc_HItype nv){
int s = 0;
__asm__ __volatile__("lock; cmpxchgw %6,%0\n"
" jz 1f\n"
" inc %1\n"
"1:"
: "=m"(*loc), "=r"(s), "=a"(ov)
: "m"(*loc), "1"(s), "2"(ov), "q"(nv) : "cc");
return s;
}
#define xcc_cas_HI(loc,ov,nv) __xcc_cas_HI((loc),(ov),(nv))
extern __inline__ int
__xcc_cas_HI(xcc_HItype *loc, xcc_HItype ov, xcc_HItype nv){
return (*loc != ov) || xcc_rawcas_HI(loc,ov,nv);
}
#define xcc_rawcas_QI(loc,ov,nv) __xcc_rawcas_QI((loc),(ov),(nv))
extern __inline__ int
__xcc_rawcas_QI(xcc_QItype *loc, xcc_QItype ov, xcc_QItype nv){
int s = 0;
__asm__ __volatile__("lock; cmpxchgb %6,%0\n"
" jz 1f\n"
" inc %1\n"
"1:"
: "=m"(*loc), "=r"(s), "=a"(ov)
: "m"(*loc), "1"(s), "2"(ov), "q"(nv) : "cc");
return s;
}
#define xcc_cas_QI(loc,ov,nv) __xcc_cas_QI((loc),(ov),(nv))
extern __inline__ int
__xcc_cas_QI(xcc_QItype *loc, xcc_QItype ov, xcc_QItype nv){
return (*loc != ov) || xcc_rawcas_QI(loc,ov,nv);
}
#define xcc_atomic_swap_DI(loc,v) __xcc_atomic_swap_DI((loc),(v))
extern __inline__ xcc_DItype
__xcc_atomic_swap_DI(xcc_DItype *loc, xcc_DItype val){
__asm__ __volatile__("movl %%eax,%%ebx\n"
" movl %%edx,%%ecx\n"
" lock\n"
" cmpxchg8b %0\n"
"1: lock\n"
" cmpxchg8b %0\n"
" jnz 1b"
: "=m"(*loc), "=A"(val) : "m"(*loc), "1"(val)
: "ecx", "ebx", "cc");
return val;
}
/* lock 必要?? */
#define xcc_atomic_swap_SI(loc,v) __xcc_atomic_swap_SI((loc),(v))
extern __inline__ xcc_SItype
__xcc_atomic_swap_SI(xcc_SItype *loc, xcc_SItype val){
__asm__ __volatile__("xchgl %1,%0"
: "=m"(*loc), "=r"(val) : "m"(*loc), "1"(val));
return val;
}
#define xcc_atomic_swap_HI(loc,v) __xcc_atomic_swap_HI((loc),(v))
extern __inline__ xcc_HItype
__xcc_atomic_swap_HI(xcc_HItype *loc, xcc_HItype val){
__asm__ __volatile__("xchgw %1,%0"
: "=m"(*loc), "=r"(val) : "m"(*loc), "1"(val));
return val;
}
#define xcc_atomic_swap_QI(loc,v) __xcc_atomic_swap_QI((loc),(v))
extern __inline__ xcc_QItype
__xcc_atomic_swap_QI(xcc_QItype *loc, xcc_QItype val){
__asm__ __volatile__("xchgb %1,%0"
: "=m"(*loc), "=r"(val) : "m"(*loc), "1"(val));
return val;
}
#define xcc_atomic_write_DI(loc,v) __xcc_atomic_write_DI((loc),(v))
extern __inline__ void
__xcc_atomic_write_DI(xcc_DItype *loc, xcc_DItype val){
xcc_DItype tmp;
__asm__ __volatile__("movl %%eax,%%ebx\n"
" movl %%edx,%%ecx\n"
" lock\n"
" cmpxchg8b %0\n"
"1: lock\n"
" cmpxchg8b %0\n"
" jnz 1b"
: "=m"(*loc), "=A"(tmp) : "A"(val)
: "ecx", "ebx", "cc");
}
#define xcc_atomic_read_DI(loc) __xcc_atomic_read_DI(loc)
extern __inline__ xcc_DItype
__xcc_atomic_read_DI(xcc_DItype *loc){
xcc_DItype val;
__asm__ __volatile__("movl %%eax,%%ebx\n"
" movl %%edx,%%ecx\n"
" lock\n"
" cmpxchg8b %1"
: "=A"(val) : "m"(*loc)
: "ecx", "ebx", "cc", "memory");
return val;
}
#endif /* __i386__ */
#ifdef __alpha__
/* __alpha_ev4__ __alpha_ev5__ __alpha_ev6__ */
#define xcc_aabar_VOID() __asm__ __volatile__("mb":::"memory")
#define xcc_rawcas_DI(loc,ov,nv) xcc_cas_DI((loc),(ov),(nv))
#define xcc_cas_DI(loc,ov,nv) __xcc_cas_DI((loc),(ov),(nv))
extern __inline__ int
__xcc_cas_DI(xcc_DItype *loc, xcc_DItype ov, xcc_DItype nv){
int cmp;
xcc_DItype tmp;
__asm__ __volatile__("ldq_l %0,%5\n"
" cmpeq %0,%3,%1\n"
" beq %1,1f\n"
" mov %4,%1\n"
" stq_c %1,%2\n"
"1:"
: "=&r"(tmp),"=&r"(cmp),"=m"(*loc)
: "r"(ov),"r"(nv),"m"(*loc));
return !cmp;
}
#define xcc_rawcas_SI(loc,ov,nv) xcc_cas_SI((loc),(ov),(nv))
#define xcc_cas_SI(loc,ov,nv) __xcc_cas_SI((loc),(ov),(nv))
extern __inline__ int
__xcc_cas_SI(xcc_SItype *loc, xcc_SItype ov, xcc_SItype nv){
int cmp;
xcc_SItype tmp;
__asm__ __volatile__("ldl_l %0,%5\n"
" cmpeq %0,%3,%1\n"
" beq %1,1f\n"
" mov %4,%1\n"
" stl_c %1,%2\n"
"1:"
: "=&r"(tmp),"=&r"(cmp),"=m"(*loc)
: "rI"(ov),"rI"(nv),"m"(*loc));
return !cmp;
}
#define xcc_atomic_write_HI(loc,v) __xcc_atomic_write_HI((loc),(v))
extern __inline__ void
__xcc_atomic_write_HI(xcc_HItype *loc, xcc_HItype val){
xcc_DItype _tmp1, _tmp2, *_tmpa, *_tmpb;
__asm__ __volatile__("lda %3,%0\n"
" bic %3,7,%4\n"
" inswl %6,%3,%2\n"
"1: ldq_l %1,0(%4)\n"
" mskwl %1,%3,%1\n"
" bis %1,%2,%1\n"
" stq_c %1,0(%4)\n"
" bne %1,1b"
: "=m"(*loc),"=r"(_tmp1),"=r"(_tmp2),
"=&r"(_tmpa),"=&r"(_tmpb)
: "m"(*loc), "r"(val));
}
#define xcc_atomic_write_QI(loc,v) __xcc_atomic_write_QI((loc),(v))
extern __inline__ void
__xcc_atomic_write_QI(xcc_QItype *loc, xcc_QItype val){
xcc_DItype _tmp1, _tmp2, *_tmpa, *_tmpb;
__asm__ __volatile__("lda %3,%0\n"
" bic %3,7,%4\n"
" insbl %6,%3,%2\n"
"1: ldq_l %1,0(%4)\n"
" mskbl %1,%3,%1\n"
" bis %1,%2,%1\n"
" stq_c %1,0(%4)\n"
" bne %1,1b"
: "=m"(*loc),"=r"(_tmp1),"=r"(_tmp2),
"=&r"(_tmpa),"=&r"(_tmpb)
: "m"(*loc), "r"(val));
}
#endif /* __alpha__ */
#ifdef __sparc_v9__
#ifndef __arch64__
#define xcc_slbar_VOID() __asm__("membar #StoreLoad"::: "memory")
#define xcc_rawcas_DI(loc,ov,nv) __xcc_rawcas_DI((loc),(ov),(nv))
extern __inline__ int
__xcc_rawcas_DI(xcc_DItype *loc, xcc_DItype ov, xcc_DItype nv){
xcc_DItype tmpa, tmpb, ovm=ov, nvm=nv;
__asm__ __volatile__("ldx %6,%2\n"
" ldx %7,%3\n"
" casx [%5],%3,%2\n"
" stx %2,%1"
: "=m"(*loc),"=m"(nvm),"=&r"(tmpa),"=&r"(tmpb)
: "m"(*loc),"r"(loc),"m"(nvm),"m"(ovm) : "cc");
nv = nvm;
return (nv != ov);
}
#define xcc_rawcas_SI(loc,ov,nv) __xcc_rawcas_SI((loc),(ov),(nv))
extern __inline__ int
__xcc_rawcas_SI(xcc_SItype *loc, xcc_SItype ov, xcc_SItype nv){
__asm__ __volatile__("cas [%3],%5,%1"
: "=m"(*loc),"=&r"(nv)
: "m"(*loc),"r"(loc),"1"(nv),"r"(ov) : "cc");
return (nv != ov);
}
#endif /* not __arch64__ */
#endif /* __sparc_v9__ */
#ifdef _POWER
#ifdef _ARCH_PPC
#define xcc_aabar_VOID() __asm__ __volatile__("sync":::"memory")
#define xcc_isync_VOID() __asm__ __volatile__("isync":::"memory")
#define xcc_ssbar_VOID() __asm__ __volatile__("eieio":::"memory")
#define xcc_rawcas_DI(loc,ov,nv) xcc_cas_SI((loc),(ov),(nv))
#define xcc_cas_DI(loc,ov,nv) XCC_ASSERT(0,_64bit_cas_not_support)
#define xcc_atomic_swap_DI(loc,v) XCC_ASSERT(0,_64bit_cas_not_support)
#define xcc_cas_DF(loc,ov,nv) XCC_ASSERT(0,_64bit_cas_not_support)
#define xcc_atomic_swap_DF(loc,v) XCC_ASSERT(0,_64bit_cas_not_support)
#define xcc_rawcas_SI(loc,ov,nv) xcc_cas_SI((loc),(ov),(nv))
#define xcc_cas_SI(loc,ov,nv) __xcc_cas_SI((loc),(ov),(nv))
extern __inline__ int
__xcc_cas_SI(xcc_SItype *loc, xcc_SItype ov, xcc_SItype nv){
int cmp = 1;
xcc_SItype tmp;
__asm__ __volatile__("lwarx %2,0,%4\n"
" cmpw %6,%2\n"
" bne- 1f\n"
" stwcx. %5,0,%4\n"
" bne- 1f\n"
" li %1,0\n"
"1:"
: "=m"(*loc),"=r"(cmp),"=&r"(tmp)
: "m"(*loc),"r"(loc),"r"(nv),"r"(ov),"1"(cmp) : "cc");
return cmp;
}
#endif /* _ARCH_PPC */
#endif /* _POWER */
#ifdef __mips__
#define xcc_rawcas_DI(loc,ov,nv) xcc_cas_DI((loc),(ov),(nv))
#define xcc_cas_DI(loc,ov,nv) __xcc_cas_DI((loc),(ov),(nv))
extern __inline__ int
__xcc_cas_DI(xcc_DItype *loc, xcc_DItype ov, xcc_DItype nv){
int cmp;
xcc_DItype tmp;
__asm__ __volatile__(".set noreorder\n"
" lld %0,%5\n"
" bne %0,%3,1f\n"
" or %1,$0,$0\n"
" or %1,%4,$0\n"
" scd %1,%2\n"
"1:\n"
" .set reorder"
: "=&r"(tmp),"=&r"(cmp),"=m"(*loc)
: "r"(ov),"r"(nv),"m"(*loc));
return !cmp;
}
#define xcc_rawcas_SI(loc,ov,nv) xcc_cas_SI((loc),(ov),(nv))
#define xcc_cas_SI(loc,ov,nv) __xcc_cas_SI((loc),(ov),(nv))
extern __inline__ int
__xcc_cas_SI(xcc_SItype *loc, xcc_SItype ov, xcc_SItype nv){
int cmp;
xcc_SItype tmp;
__asm__ __volatile__(".set noreorder\n"
" ll %0,%5\n"
" bne %0,%3,1f\n"
" or %1,$0,$0\n"
" or %1,%4,$0\n"
" sc %1,%2\n"
"1:\n"
" .set reorder"
: "=&r"(tmp),"=&r"(cmp),"=m"(*loc)
: "r"(ov),"r"(nv),"m"(*loc));
return !cmp;
}
#endif /* __mips__ */
/*
* Common inst. and common emulations
*/
#ifndef xcc_nnbar_VOID
#define xcc_nnbar_VOID() __asm__ __volatile__("":::"memory")
#endif
#ifndef xcc_cas_DI
#define xcc_cas_DI(loc,ov,nv) __xcc_cas_DI((loc),(ov),(nv))
extern __inline__ int
__xcc_cas_DI(xcc_DItype *loc, xcc_DItype ov, xcc_DItype nv){
return (*loc != ov) || xcc_rawcas_DI(loc,ov,nv);
}
#endif
#ifndef xcc_cas_SI
#define xcc_cas_SI(loc,ov,nv) __xcc_cas_SI((loc),(ov),(nv))
extern __inline__ int
__xcc_cas_SI(xcc_SItype *loc, xcc_SItype ov, xcc_SItype nv){
return (*loc != ov) || xcc_rawcas_SI(loc,ov,nv);
}
#endif
#ifndef xcc_cas_HI
#define xcc_cas_HI(loc,ov,nv) __xcc_cas_HI((loc),(ov),(nv))
extern __inline__ int
__xcc_cas_HI(xcc_HItype *loc, xcc_HItype ov, xcc_HItype nv){
int ofs = (loc - (xcc_HItype *)(xcc_SItype *)0) & 1;
xcc_SItype *p = (xcc_SItype *)(loc - ofs), uov = *p;
union { xcc_SItype v; xcc_HItype s[2]; } unv;
unv.v = uov;
if(unv.s[ofs] != ov) return 1;
unv.s[ofs] = nv;
return xcc_rawcas_SI(p,uov,unv.v);
}
#endif
#ifndef xcc_cas_QI
#define xcc_cas_QI(loc,ov,nv) __xcc_cas_QI((loc),(ov),(nv))
extern __inline__ int
__xcc_cas_QI(xcc_QItype *loc, xcc_QItype ov, xcc_QItype nv){
int ofs = (loc - (xcc_QItype *)(xcc_SItype *)0) & 3;
xcc_SItype *p = (xcc_SItype *)(loc - ofs), uov = *p;
union { xcc_SItype v; xcc_QItype c[4]; } unv;
unv.v = uov;
if(unv.c[ofs] != ov) return 1;
unv.c[ofs] = nv;
return xcc_rawcas_SI(p,uov,unv.v);
}
#endif
#ifndef xcc_cas_DF
#define xcc_cas_DF(loc,ov,nv) __xcc_cas_DF((loc),(ov),(nv))
extern __inline__ int
__xcc_cas_DF(xcc_DFtype *loc, xcc_DFtype ov, xcc_DFtype nv){
return xcc_cas_DI((xcc_DItype *)loc,
FORCE_TYPE(xcc_DItype,ov),
FORCE_TYPE(xcc_DItype,nv));
}
#endif
#ifndef xcc_cas_SF
#define xcc_cas_SF(loc,ov,nv) __xcc_cas_SF((loc),(ov),(nv))
extern __inline__ int
__xcc_cas_SF(xcc_SFtype *loc, xcc_SFtype ov, xcc_SFtype nv){
return xcc_cas_SI((xcc_SItype *)loc,
FORCE_TYPE(xcc_SItype,ov),
FORCE_TYPE(xcc_SItype,nv));
}
#endif
#ifndef xcc_atomic_swap_DI
#define xcc_atomic_swap_DI(loc,v) __xcc_atomic_swap_DI((loc),(v))
extern __inline__ xcc_DItype
__xcc_atomic_swap_DI(xcc_DItype *loc, xcc_DItype val){
xcc_DItype ov;
do{ ov = *loc; }while(xcc_rawcas_DI(loc,ov,val));
return ov;
}
#endif
#ifndef xcc_atomic_swap_SI
#define xcc_atomic_swap_SI(loc,v) __xcc_atomic_swap_SI((loc),(v))
extern __inline__ xcc_SItype
__xcc_atomic_swap_SI(xcc_SItype *loc, xcc_SItype val){
xcc_SItype ov;
do{ ov = *loc; }while(xcc_rawcas_SI(loc,ov,val));
return ov;
}
#endif
#ifndef xcc_atomic_swap_HI
#define xcc_atomic_swap_HI(loc,v) __xcc_atomic_swap_HI((loc),(v))
extern __inline__ xcc_HItype
__xcc_atomic_swap_HI(xcc_HItype *loc, xcc_HItype val){
int ofs = (loc- (xcc_HItype *)(xcc_SItype *)0) & 1;
xcc_SItype *p = (xcc_SItype *)(loc - ofs), uov;
union { xcc_SItype v; xcc_HItype s[2]; } unv;
do{ unv.v = uov = *p; unv.s[ofs] = val;
}while(xcc_rawcas_SI(p,uov,unv.v));
unv.v = uov; return unv.s[ofs];
}
#endif
#ifndef xcc_atomic_swap_QI
#define xcc_atomic_swap_QI(loc,v) __xcc_atomic_swap_QI((loc),(v))
extern __inline__ xcc_QItype
__xcc_atomic_swap_QI(xcc_QItype *loc, xcc_QItype val){
int ofs = (loc- (xcc_QItype *)(xcc_SItype *)0) & 3;
xcc_SItype *p = (xcc_SItype *)(loc - ofs), uov;
union { xcc_SItype v; xcc_QItype c[4]; } unv;
do{ unv.v = uov = *p ; unv.c[ofs] = val;
}while(xcc_rawcas_SI(p,uov,unv.v));
unv.v = uov; return unv.c[ofs];
}
#endif
#ifndef xcc_atomic_swap_DF
#define xcc_atomic_swap_DF(loc,v) __xcc_atomic_swap_DF((loc),(v))
extern __inline__ xcc_DFtype
__xcc_atomic_swap_DF(xcc_DFtype *loc, xcc_DFtype val){
return FORCE_TYPE(xcc_DFtype,
xcc_atomic_swap_DI((xcc_DItype *)(loc),
FORCE_TYPE(xcc_DItype,val)));
}
#endif
#ifndef xcc_atomic_swap_SF
#define xcc_atomic_swap_SF(loc,v) __xcc_atomic_swap_SF((loc),(v))
extern __inline__ xcc_SFtype
__xcc_atomic_swap_SF(xcc_SFtype *loc, xcc_SFtype val){
return FORCE_TYPE(xcc_SFtype,
xcc_atomic_swap_SI((xcc_SItype *)(loc),
FORCE_TYPE(xcc_SItype,val)));
}
#endif
/* end of Instructions */
/* *//* *//* *//* *//* */
/*
* data mapping
*/
#ifdef __i386__
#define xcc_atomic_read_long_long(loc)\
(sizeof(*(loc))==8 ? xcc_atomic_read_DI((xcc_DItype *)(loc)) :\
XCC_ASSERT((sizeof(*(loc))==8), atomic_read_long_long))
#define xcc_atomic_write_long_long(loc,v)\
do{ if(sizeof(*(loc))==8) xcc_atomic_write_DI((xcc_DItype *)(loc),(v)); \
else XCC_ASSERT((sizeof(*(loc))==8), atomic_write_long_long); }while(0)
#define xcc_slbar() xcc_slbar_VOID()
#define xcc_sabar() xcc_slbar_VOID()
#define xcc_albar() xcc_slbar_VOID()
#define xcc_aabar() xcc_slbar_VOID()
#define xcc_start_access_after_lock() xcc_nnbar_VOID()
#define xcc_start_read_after_lock() xcc_nnbar_VOID()
#define xcc_start_write_after_lock() xcc_nnbar_VOID()
#endif /* __i386__ */
#ifdef __alpha__
/* __alpha_ev4__ __alpha_ev5__ __alpha_ev6__ */
#define xcc_atomic_write_char(loc,v)\
do{ if(sizeof(*(loc))==1) xcc_atomic_write_QI((xcc_QItype *)(loc),(v)); \
else XCC_ASSERT((sizeof(*(loc))==1), atomic_write_char); }while(0)
#define xcc_atomic_write_short(loc,v)\
do{ if(sizeof(*(loc))==2) xcc_atomic_write_HI((xcc_HItype *)(loc),(v)); \
else XCC_ASSERT((sizeof(*(loc))==2), atomic_write_short); }while(0)
#define xcc_defaultbar_VOID() xcc_aabar_VOID()
#define XCC_LONG_TYPE_SIZE 8
#define XCC_PTR_TYPE_SIZE 8
#endif /* __alpha__ */
#ifdef __sparc_v9__
#ifndef __arch64__
/* -mcpu=ultrasparc */
/* assuming TSO */
#define xcc_slbar() xcc_slbar_VOID()
#define xcc_sabar() xcc_slbar_VOID()
#define xcc_albar() xcc_slbar_VOID()
#define xcc_aabar() xcc_slbar_VOID()
#define xcc_start_access_after_lock() xcc_nnbar_VOID()
#define xcc_start_read_after_lock() xcc_nnbar_VOID()
#define xcc_start_write_after_lock() xcc_nnbar_VOID()
#endif /* ! __arch64__ */
#endif /* __sparc_v9__ */
#ifdef _POWER
#ifdef _ARCH_PPC
/* -mcpu=powerpc */
#define xcc_atomic_read_long_long(loc) XCC_ASSERT(0, atomic_read_long_long)
#define xcc_atomic_write_long_long(loc,v)\
do{ XCC_ASSERT((sizeof(*(loc))==8), atomic_write_long_long); }while(0)
#define xcc_atomic_swap_long_long(loc,v) XCC_ASSERT(0, atomic_swap_long_long)
#define xcc_cas_long_long(loc,ov,nv) XCC_ASSERT(0, cas_long_long)
#define xcc_atomic_swap_double(loc,v) XCC_ASSERT(0, atomic_swap_double)
#define xcc_cas_double(loc,ov,nv) XCC_ASSERT(0, cas_double)
#define xcc_defaultbar_VOID() xcc_aabar_VOID()
#define xcc_ssbar() xcc_ssbar_VOID()
#define xcc_start_access_after_lock() xcc_isync_VOID()
#define xcc_start_read_after_lock() xcc_isync_VOID()
#define xcc_start_write_after_lock() xcc_isync_VOID()
#endif /* _ARCH_PPC */
#endif /* _POWER */
#ifdef __mips__
#define XCC_INT_TYPE_SIZE (_MIPS_SZINT/8)
#define XCC_LONG_TYPE_SIZE (_MIPS_SZLONG/8)
#define XCC_PTR_TYPE_SIZE (_MIPS_SZPTR/8)
#endif /* __mips__ */
/*
* Common data mapping and/or common (usual) GNUC case
*/
#ifndef XCC_CHAR_TYPE_SIZE
#define XCC_CHAR_TYPE_SIZE 1
#endif
#ifndef XCC_SHORT_TYPE_SIZE
#define XCC_SHORT_TYPE_SIZE 2
#endif
#ifndef XCC_INT_TYPE_SIZE
#define XCC_INT_TYPE_SIZE 4
#endif
#ifndef XCC_LONG_TYPE_SIZE
#define XCC_LONG_TYPE_SIZE 4
#endif
#ifndef XCC_LONG_LONG_TYPE_SIZE
#define XCC_LONG_LONG_TYPE_SIZE 8
#endif
#ifndef XCC_FLOAT_TYPE_SIZE
#define XCC_FLOAT_TYPE_SIZE 4
#endif
#ifndef XCC_DOUBLE_TYPE_SIZE
#define XCC_DOUBLE_TYPE_SIZE 8
#endif
#ifndef XCC_PTR_TYPE_SIZE
#define XCC_PTR_TYPE_SIZE 4
#endif
#ifndef xcc_atomic_read_char
#define xcc_atomic_read_char(loc) (*(volatile char *)(loc))
#endif
#ifndef xcc_atomic_read_short
#define xcc_atomic_read_short(loc) (*(volatile short *)(loc))
#endif
#ifndef xcc_atomic_read_int
#define xcc_atomic_read_int(loc) (*(volatile int *)(loc))
#endif
#ifndef xcc_atomic_read_long
#define xcc_atomic_read_long(loc) (*(volatile long *)(loc))
#endif
/* long long: except for i386, PPC32, MIPS1/2 */
#ifndef xcc_atomic_read_long_long
#define xcc_atomic_read_long_long(loc) (*(volatile long long *)(loc))
#endif
#ifndef xcc_atomic_read_float
#define xcc_atomic_read_float(loc) (*(volatile float *)(loc))
#endif
#ifndef xcc_atomic_read_double
#define xcc_atomic_read_double(loc) (*(volatile double *)(loc))
#endif
#ifndef xcc_atomic_read_ptr
#define xcc_atomic_read_ptr(loc) (*(void * volatile *)(loc))
#endif
/* char: except for Alhpa */
#ifndef xcc_atomic_write_char
#define xcc_atomic_write_char(loc,v) do{*(volatile char *)(loc)=(v);}while(0)
#endif
#ifndef xcc_atomic_write_short
#define xcc_atomic_write_short(loc,v) do{*(volatile short *)(loc)=(v);}while(0)
#endif
#ifndef xcc_atomic_write_int
#define xcc_atomic_write_int(loc,v) do{*(volatile int *)(loc)=(v);}while(0)
#endif
#ifndef xcc_atomic_write_long
#define xcc_atomic_write_long(loc,v) do{*(volatile long *)(loc)=(v);}while(0)
#endif
/* long long: except for i386, PPC32, MIPS1/2 */
#ifndef xcc_atomic_write_long_long
#define xcc_atomic_write_long_long(loc,v)\
do{*(volatile long long *)(loc)=(v);}while(0)
#endif
#ifndef xcc_atomic_write_float
#define xcc_atomic_write_float(loc,v)\
do{*(volatile float *)(loc)=(v);}while(0)
#endif
#ifndef xcc_atomic_write_double
#define xcc_atomic_write_double(loc,v)\
do{*(volatile double *)(loc)=(v);}while(0)
#endif
#ifndef xcc_atomic_write_ptr
#define xcc_atomic_write_ptr(loc,v) do{*(void * volatile *)(loc)=(v);}while(0)
#endif
#ifndef xcc_atomic_swap_char
#define xcc_atomic_swap_char(loc,v)\
(sizeof(*(loc))==1 ? xcc_atomic_swap_QI((xcc_QItype *)(loc),(v)) :\
XCC_ASSERT((sizeof(*(loc))==1), atomic_swap_char))
#endif
#ifndef xcc_atomic_swap_short
#define xcc_atomic_swap_short(loc,v)\
(sizeof(*(loc))==2 ? xcc_atomic_swap_HI((xcc_HItype *)(loc),(v)) :\
XCC_ASSERT((sizeof(*(loc))==2), atomic_swap_short))
#endif
#if XCC_INT_TYPE_SIZE == 4
#ifndef xcc_atomic_swap_int
#define xcc_atomic_swap_int(loc,v)\
(sizeof(*(loc))==4 ? xcc_atomic_swap_SI((xcc_SItype *)(loc),(v)) :\
XCC_ASSERT((sizeof(*(loc))==4), atomic_swap_int))
#endif
#elif XCC_INT_TYPE_SIZE == 8
#ifndef xcc_atomic_swap_int
#define xcc_atomic_swap_int(loc,v)\
(sizeof(*(loc))==8 ? xcc_atomic_swap_DI((xcc_DItype *)(loc),(v)) :\
XCC_ASSERT((sizeof(*(loc))==8), atomic_swap_int))
#endif
#endif /* XCC_INT_TYPE_SIZE == 8 */
#if XCC_LONG_TYPE_SIZE == 4
#ifndef xcc_atomic_swap_long
#define xcc_atomic_swap_long(loc,v)\
(sizeof(*(loc))==4 ? xcc_atomic_swap_SI((xcc_SItype *)(loc),(v)) :\
XCC_ASSERT((sizeof(*(loc))==4), atomic_swap_long))
#endif
#elif XCC_LONG_TYPE_SIZE == 8
#ifndef xcc_atomic_swap_long
#define xcc_atomic_swap_long(loc,v)\
(sizeof(*(loc))==8 ? xcc_atomic_swap_DI((xcc_DItype *)(loc),(v)) :\
XCC_ASSERT((sizeof(*(loc))==8), atomic_swap_long))
#endif
#endif /* XCC_LONG_TYPE_SIZE == 8 */
#ifndef xcc_atomic_swap_long_long
#define xcc_atomic_swap_long_long(loc,v)\
(sizeof(*(loc))==8 ? xcc_atomic_swap_DI((xcc_DItype *)(loc),(v)) :\
XCC_ASSERT((sizeof(*(loc))==8), atomic_swap_long_long))
#endif
#ifndef xcc_atomic_swap
#define xcc_atomic_swap(loc,v)\
(sizeof(*(loc))==1 ? xcc_atomic_swap_QI((xcc_QItype *)(loc),(v)) :\
sizeof(*(loc))==2 ? xcc_atomic_swap_HI((xcc_HItype *)(loc),(v)) :\
sizeof(*(loc))==4 ? xcc_atomic_swap_SI((xcc_SItype *)(loc),(v)) :\
sizeof(*(loc))==8 ? xcc_atomic_swap_DI((xcc_DItype *)(loc),(v)) :\
XCC_ASSERT(((sizeof(*(loc))==1) && (__alignof__(*(loc))==1) ||\
(sizeof(*(loc))==2) && (__alignof__(*(loc))==2) ||\
(sizeof(*(loc))==4) && (__alignof__(*(loc))==4) ||\
(sizeof(*(loc))==8) && (__alignof__(*(loc))==8)),\
atomic_swap))
#endif
#ifndef xcc_atomic_swap_float
#define xcc_atomic_swap_float(loc,v)\
(sizeof(*(loc))==4 ? xcc_atomic_swap_SF((xcc_SFtype *)(loc),(v)) :\
XCC_ASSERT((sizeof(*(loc))==4), atomic_swap_float))
#endif
#ifndef xcc_atomic_swap_double
#define xcc_atomic_swap_double(loc,v)\
(sizeof(*(loc))==8 ? xcc_atomic_swap_DF((xcc_DFtype *)(loc),(v)) :\
XCC_ASSERT((sizeof(*(loc))==8), atomic_swap_double))
#endif
#if XCC_PTR_TYPE_SIZE == 4
#ifndef xcc_atomic_swap_ptr
#define xcc_atomic_swap_ptr(loc,v)\
(sizeof(*(loc))==4 ? \
xcc_atomic_swap_SI((xcc_SItype *)(loc),(xcc_SItype)(v)) :\
XCC_ASSERT((sizeof(*(loc))==4), atomic_swap_ptr))
#endif
#elif XCC_PTR_TYPE_SIZE == 8
#ifndef xcc_atomic_swap_ptr
#define xcc_atomic_swap_ptr(loc,v)\
(sizeof(*(loc))==8 ? \
xcc_atomic_swap_DI((xcc_DItype *)(loc),(xcc_DItype)(v)) :\
XCC_ASSERT((sizeof(*(loc))==8), atomic_swap_ptr))
#endif
#endif /* XCC_PTR_TYPE_SIZE == 8 */
#ifndef xcc_cas_char
#define xcc_cas_char(loc,ov,nv)\
(sizeof(*(loc))==1 ? xcc_cas_QI((xcc_QItype *)(loc),(ov),(nv)) :\
XCC_ASSERT((sizeof(*(loc))==1), cas_char))
#endif
#ifndef xcc_cas_short
#define xcc_cas_short(loc,ov,nv)\
(sizeof(*(loc))==2 ? xcc_cas_HI((xcc_HItype *)(loc),(ov),(nv)) :\
XCC_ASSERT((sizeof(*(loc))==2), cas_short))
#endif
#if XCC_INT_TYPE_SIZE == 4
#ifndef xcc_cas_int
#define xcc_cas_int(loc,ov,nv)\
(sizeof(*(loc))==4 ? xcc_cas_SI((xcc_SItype *)(loc),(ov),(nv)) :\
XCC_ASSERT((sizeof(*(loc))==4), cas_int))
#endif
#elif XCC_INT_TYPE_SIZE == 8
#ifndef xcc_cas_int
#define xcc_cas_int(loc,ov,nv)\
(sizeof(*(loc))==8 ? xcc_cas_DI((xcc_DItype *)(loc),(ov),(nv)) :\
XCC_ASSERT((sizeof(*(loc))==8), cas_int))
#endif
#endif /* XCC_INT_TYPE_SIZE == 8 */
/* raw cas */
#if XCC_INT_TYPE_SIZE == 4
#ifndef xcc_rawcas_int
#define xcc_rawcas_int(loc,ov,nv)\
(sizeof(*(loc))==4 ? xcc_rawcas_SI((xcc_SItype *)(loc),(ov),(nv)) :\
XCC_ASSERT((sizeof(*(loc))==4), rawcas_int))
#endif
#elif XCC_INT_TYPE_SIZE == 8
#ifndef xcc_rawcas_int
#define xcc_rawcas_int(loc,ov,nv)\
(sizeof(*(loc))==8 ? xcc_rawcas_DI((xcc_DItype *)(loc),(ov),(nv)) :\
XCC_ASSERT((sizeof(*(loc))==8), rawcas_int))
#endif
#endif /* XCC_INT_TYPE_SIZE == 8 */
#if XCC_LONG_TYPE_SIZE == 4
#ifndef xcc_cas_long
#define xcc_cas_long(loc,ov,nv)\
(sizeof(*(loc))==4 ? xcc_cas_SI((xcc_SItype *)(loc),(ov),(nv)) :\
XCC_ASSERT((sizeof(*(loc))==4), cas_long))
#endif
#elif XCC_LONG_TYPE_SIZE == 8
#ifndef xcc_cas_long
#define xcc_cas_long(loc,ov,nv)\
(sizeof(*(loc))==8 ? xcc_cas_DI((xcc_DItype *)(loc),(ov),(nv)) :\
XCC_ASSERT((sizeof(*(loc))==8), cas_long))
#endif
#endif /* XCC_LONG_TYPE_SIZE == 8 */
#ifndef xcc_cas_long_long
#define xcc_cas_long_long(loc,ov,nv)\
(sizeof(*(loc))==8 ? xcc_cas_DI((xcc_DItype *)(loc),(ov),(nv)) :\
XCC_ASSERT((sizeof(*(loc))==8), cas_long_long))
#endif
#ifndef xcc_cas_float
#define xcc_cas_float(loc,ov,nv)\
(sizeof(*(loc))==4 ? xcc_cas_SF((xcc_SFtype *)(loc),(ov),(nv)) :\
XCC_ASSERT((sizeof(*(loc))==4), cas_float))
#endif
#ifndef xcc_cas_double
#define xcc_cas_double(loc,ov,nv)\
(sizeof(*(loc))==8 ? xcc_cas_DF((xcc_DFtype *)(loc),(ov),(nv)) :\
XCC_ASSERT((sizeof(*(loc))==8), cas_double))
#endif
#if XCC_PTR_TYPE_SIZE == 4
#ifndef xcc_cas_ptr
#define xcc_cas_ptr(loc,ov,nv)\
(sizeof(*(loc))==4 ? \
xcc_cas_SI((xcc_SItype *)(loc),(xcc_SItype)(ov),(xcc_SItype)(nv)) :\
XCC_ASSERT((sizeof(*(loc))==4), cas_ptr))
#endif
#elif XCC_PTR_TYPE_SIZE == 8
#ifndef xcc_cas_ptr
#define xcc_cas_ptr(loc,ov,nv)\
(sizeof(*(loc))==8 ? \
xcc_cas_DI((xcc_DItype *)(loc),(xcc_DItype)(ov),(xcc_DItype)(nv)) :\
XCC_ASSERT((sizeof(*(loc))==8), cas_ptr))
#endif
#endif /* XCC_PTR_TYPE_SIZE == 8 */
#ifndef xcc_defaultbar_VOID
#define xcc_defaultbar_VOID() xcc_nnbar_VOID()
#endif
#ifndef xcc_ssbar
#define xcc_ssbar() xcc_defaultbar_VOID()
#endif
#ifndef xcc_slbar
#define xcc_slbar() xcc_defaultbar_VOID()
#endif
#ifndef xcc_sabar
#define xcc_sabar() xcc_defaultbar_VOID()
#endif
#ifndef xcc_lsbar
#define xcc_lsbar() xcc_defaultbar_VOID()
#endif
#ifndef xcc_llbar
#define xcc_llbar() xcc_defaultbar_VOID()
#endif
#ifndef xcc_labar
#define xcc_labar() xcc_defaultbar_VOID()
#endif
#ifndef xcc_asbar
#define xcc_asbar() xcc_defaultbar_VOID()
#endif
#ifndef xcc_albar
#define xcc_albar() xcc_defaultbar_VOID()
#endif
#ifndef xcc_aabar
#define xcc_aabar() xcc_defaultbar_VOID()
#endif
/* Pentium's spinlock means aabar() Alpha's spinlock does not */
#ifndef xcc_start_access_after_lock
#define xcc_start_access_after_lock() xcc_aabar()
#endif
#ifndef xcc_start_access_after_read
#define xcc_start_access_after_read() xcc_labar()
#endif
#ifndef xcc_start_access_after_write
#define xcc_start_access_after_write() xcc_sabar()
#endif
#ifndef xcc_start_read_after_lock
#define xcc_start_read_after_lock() xcc_albar()
#endif
#ifndef xcc_start_read_after_read
#define xcc_start_read_after_read() xcc_llbar()
#endif
#ifndef xcc_start_read_after_write
#define xcc_start_read_after_write() xcc_slbar()
#endif
#ifndef xcc_start_write_after_lock
#define xcc_start_write_after_lock() xcc_asbar()
#endif
#ifndef xcc_start_write_after_read
#define xcc_start_write_after_read() xcc_lsbar()
#endif
#ifndef xcc_start_write_after_write
#define xcc_start_write_after_write() xcc_ssbar()
#endif
#ifndef xcc_finish_access_before_unlock
#define xcc_finish_access_before_unlock() xcc_asbar()
#endif
#ifndef xcc_finish_access_before_read
#define xcc_finish_access_before_read() xcc_albar()
#endif
#ifndef xcc_finish_access_before_write
#define xcc_finish_access_before_write() xcc_asbar()
#endif
#ifndef xcc_finish_read_before_unlock
#define xcc_finish_read_before_unlock() xcc_lsbar()
#endif
#ifndef xcc_finish_read_before_read
#define xcc_finish_read_before_read() xcc_llbar()
#endif
#ifndef xcc_finish_read_before_write
#define xcc_finish_read_before_write() xcc_lsbar()
#endif
#ifndef xcc_finish_write_before_unlock
#define xcc_finish_write_before_unlock() xcc_ssbar()
#endif
#ifndef xcc_finish_write_before_read
#define xcc_finish_write_before_read() xcc_slbar()
#endif
#ifndef xcc_finish_write_before_write
#define xcc_finish_write_before_write() xcc_ssbar()
#endif
#ifndef xcc_LOCK_INITIALIZER
#define xcc_LOCK_INITIALIZER 0
#endif
#ifndef xcc_lock_t
#define xcc_lock_t int
#endif
#ifndef xcc_try_lock
#define xcc_try_lock(loc) xcc_cas_int((loc),0,1)
#endif
#ifndef xcc_spin_lock
#define xcc_spin_lock(loc) __xcc_spin_lock(loc)
extern __inline__ void
__xcc_spin_lock(int *loc){ while(xcc_try_lock(loc)) xcc_llbar(); }
#endif
#ifndef xcc_release_lock
#define xcc_release_lock(loc) xcc_atomic_write_int((loc),0)
#endif
#ifndef xcc_RWLOCK_INITIALIZER
#define xcc_RWLOCK_INITIALIZER 0
#endif
#ifndef xcc_rwlock_t
#define xcc_rwlock_t int
#endif
#ifndef xcc_try_rlock
#define xcc_try_rlock(loc) __xcc_try_rlock(loc)
extern __inline__ int
__xcc_try_rlock(int *loc){
int c=xcc_atomic_read_int(loc);
return ((c<0) || xcc_rawcas_int(loc,c,c+1));
}
#endif
#ifndef xcc_spin_rlock
#define xcc_spin_rlock(loc) __xcc_spin_rlock(loc)
extern __inline__ void
__xcc_spin_rlock(int *loc){ while(xcc_try_rlock(loc)) xcc_llbar(); }
#endif
#ifndef xcc_release_rlock
#define xcc_release_rlock(loc) __xcc_release_rlock(loc)
extern __inline__ void
__xcc_release_rlock(int *loc){
int c; do{c = *loc;}while(xcc_rawcas_int(loc,c,c-1));
}
#endif
#ifndef xcc_try_wlock
#define xcc_try_wlock(loc) xcc_cas_int((loc),0,-1)
#endif
#ifndef xcc_spin_wlock
#define xcc_spin_wlock(loc) __xcc_spin_wlock(loc)
extern __inline__ void
__xcc_spin_wlock(int *loc){ while(xcc_try_wlock(loc)) xcc_llbar(); }
#endif
#ifndef xcc_release_wlock
#define xcc_release_wlock(loc) xcc_atomic_write_int((loc),0)
#endif
/* *//* *//* *//* *//* */
/*
* xccmem API primitives
*/
#define atomic_read_char(loc) xcc_atomic_read_char(&(loc))
#define atomic_read_short(loc) xcc_atomic_read_short(&(loc))
#define atomic_read_int(loc) xcc_atomic_read_int(&(loc))
#define atomic_read_long(loc) xcc_atomic_read_long(&(loc))
#define atomic_read_long_long(loc) xcc_atomic_read_long_long(&(loc))
#define atomic_read_float(loc) xcc_atomic_read_float(&(loc))
#define atomic_read_double(loc) xcc_atomic_read_double(&(loc))
#define atomic_read_ptr(loc) xcc_atomic_read_ptr(&(loc))
#define atomic_read_volatile_char(loc) atomic_read_char(loc)
#define atomic_read_volatile_short(loc) atomic_read_short(loc)
#define atomic_read_volatile_int(loc) atomic_read_int(loc)
#define atomic_read_volatile_long(loc) atomic_read_long(loc)
#define atomic_read_volatile_long_long(loc) atomic_read_long_long(loc)
#define atomic_read_volatile_float(loc) atomic_read_float(loc)
#define atomic_read_volatile_double(loc) atomic_read_double(loc)
#define atomic_read_volatile_ptr(loc) atomic_read_ptr(loc)
#define read_volatile_char(loc) atomic_read_char(loc)
#define read_volatile_short(loc) atomic_read_short(loc)
#define read_volatile_int(loc) atomic_read_int(loc)
#define read_volatile_long(loc) atomic_read_long(loc)
#define read_volatile_long_long(loc) atomic_read_long_long(loc)
#define read_volatile_float(loc) atomic_read_float(loc)
#define read_volatile_double(loc) atomic_read_double(loc)
#define read_volatile_ptr(loc) atomic_read_ptr(loc)
#define atomic_write_char(loc,v) xcc_atomic_write_char(&(loc),(v))
#define atomic_write_short(loc,v) xcc_atomic_write_short(&(loc),(v))
#define atomic_write_int(loc,v) xcc_atomic_write_int(&(loc),(v))
#define atomic_write_long(loc,v) xcc_atomic_write_long(&(loc),(v))
#define atomic_write_long_long(loc,v) xcc_atomic_write_long_long(&(loc),(v))
#define atomic_write_float(loc,v) xcc_atomic_write_float(&(loc),(v))
#define atomic_write_double(loc,v) xcc_atomic_write_double(&(loc),(v))
#define atomic_write_ptr(loc,v) xcc_atomic_write_ptr(&(loc),(v))
#define atomic_write_volatile_char(loc, v) atomic_write_char((loc), (v))
#define atomic_write_volatile_short(loc, v) atomic_write_short((loc), (v))
#define atomic_write_volatile_int(loc, v) atomic_write_int((loc), (v))
#define atomic_write_volatile_long(loc, v) atomic_write_long((loc), (v))
#define atomic_write_volatile_long_long(loc, v) \
atomic_write_long_long((loc), (v))
#define atomic_write_volatile_float(loc, v) atomic_write_float((loc), (v))
#define atomic_write_volatile_double(loc, v) atomic_write_double((loc), (v))
#define atomic_write_volatile_ptr(loc, v) atomic_write_ptr((loc), (v))
#define write_volatile_char(loc, v) atomic_write_char((loc), (v))
#define write_volatile_short(loc, v) atomic_write_short((loc), (v))
#define write_volatile_int(loc, v) atomic_write_int((loc), (v))
#define write_volatile_long(loc, v) atomic_write_long((loc), (v))
#define write_volatile_long_long(loc, v) atomic_write_long_long((loc), (v))
#define write_volatile_float(loc, v) atomic_write_float((loc), (v))
#define write_volatile_double(loc, v) atomic_write_double((loc), (v))
#define write_volatile_ptr(loc, v) atomic_write_ptr((loc), (v))
#define atomic_swap_char(loc,v) xcc_atomic_swap_char(&(loc),(v))
#define atomic_swap_short(loc,v) xcc_atomic_swap_short(&(loc),(v))
#define atomic_swap_int(loc,v) xcc_atomic_swap_int(&(loc),(v))
#define atomic_swap_long(loc,v) xcc_atomic_swap_long(&(loc),(v))
#define atomic_swap_long_long(loc,v) xcc_atomic_swap_long_long(&(loc),(v))
#define atomic_swap_float(loc,v) xcc_atomic_swap_float(&(loc),(v))
#define atomic_swap_double(loc,v) xcc_atomic_swap_double(&(loc),(v))
#define atomic_swap_ptr(loc,v) xcc_atomic_swap_ptr(&(loc),(v))
#define atomic_swap(loc,v) xcc_atomic_swap(&(loc),(v))
#define cas_char(loc,ov,nv) xcc_cas_char(&(loc),(ov),(nv))
#define cas_short(loc,ov,nv) xcc_cas_short(&(loc),(ov),(nv))
#define cas_int(loc,ov,nv) xcc_cas_int(&(loc),(ov),(nv))
#define cas_long(loc,ov,nv) xcc_cas_long(&(loc),(ov),(nv))
#define cas_long_long(loc,ov,nv) xcc_cas_long_long(&(loc),(ov),(nv))
#define cas_float(loc,ov,nv) xcc_cas_float(&(loc),(ov),(nv))
#define cas_double(loc,ov,nv) xcc_cas_double(&(loc),(ov),(nv))
#define cas_ptr(loc,ov,nv) xcc_cas_ptr(&(loc),(ov),(nv))
#define ssbar() xcc_ssbar()
#define slbar() xcc_slbar()
#define sabar() xcc_sabar()
#define lsbar() xcc_lsbar()
#define llbar() xcc_llbar()
#define labar() xcc_labar()
#define asbar() xcc_asbar()
#define albar() xcc_albar()
#define aabar() xcc_aabar()
#define start_access_after_lock() xcc_start_access_after_lock()
#define start_access_after_read() xcc_start_access_after_read()
#define start_access_after_write() xcc_start_access_after_write()
#define start_read_after_lock() xcc_start_read_after_lock()
#define start_read_after_read() xcc_start_read_after_read()
#define start_read_after_write() xcc_start_read_after_write()
#define start_write_after_lock() xcc_start_write_after_lock()
#define start_write_after_read() xcc_start_write_after_read()
#define start_write_after_write() xcc_start_write_after_write()
#define finish_access_before_unlock() xcc_finish_access_before_unlock()
#define finish_access_before_read() xcc_finish_access_before_read()
#define finish_access_before_write() xcc_finish_access_before_write()
#define finish_read_before_unlock() xcc_finish_read_before_unlock()
#define finish_read_before_read() xcc_finish_read_before_read()
#define finish_read_before_write() xcc_finish_read_before_write()
#define finish_write_before_unlock() xcc_finish_write_before_unlock()
#define finish_write_before_read() xcc_finish_write_before_read()
#define finish_write_before_write() xcc_finish_write_before_write()
#define LOCK_INITIALIZER xcc_LOCK_INITIALIZER
#define lock_t xcc_lock_t
#define try_lock(loc) xcc_try_lock(&(loc))
#define spin_lock(loc) xcc_spin_lock(&(loc))
#define release_lock(loc) xcc_release_lock(&(loc))
#define RWLOCK_INITIALIZER xcc_RWLOCK_INITIALIZER
// #define rwlock_t xcc_rwlock_t /* R.Hanai */
#define try_rlock(loc) xcc_try_rlock(&(loc))
#define spin_rlock(loc) xcc_spin_rlock(&(loc))
#define release_rlock(loc) xcc_release_rlock(&(loc))
#define try_wlock(loc) xcc_try_wlock(&(loc))
#define spin_wlock(loc) xcc_spin_wlock(&(loc))
#define release_wlock(loc) xcc_release_wlock(&(loc))
/* end of xccmem API primitives */
/* *//* *//* *//* *//* */
#endif /* not XCCMEM_H */
|