4 typedef unsigned int UInt
;
5 typedef unsigned long long int ULong
;
7 void do_cmpxchg8b ( /*OUT*/
8 ULong
* rdxOut
, ULong
* raxOut
,
9 ULong
* memHiOut
, ULong
* memLoOut
,
12 ULong rdxIn
, ULong raxIn
,
13 ULong memHiIn
, ULong memLoIn
,
14 ULong rcxIn
, ULong rbxIn
)
18 mem
[0] = (UInt
)memLoIn
;
19 mem
[1] = (UInt
)memHiIn
;
24 block
[4] = (ULong
)&mem
[0];
28 "\tmovq 0(%%r11),%%rdx\n"
29 "\tmovq 8(%%r11),%%rax\n"
30 "\tmovq 16(%%r11),%%rcx\n"
31 "\tmovq 24(%%r11),%%rbx\n"
32 "\tmovq 32(%%r11),%%r10\n"
33 "\tlock cmpxchg8b (%%r10)\n"
34 "\tmovabsq $0,%%r10\n"
36 "\tmovq %%r10,40(%%r11)\n"
37 "\tmovq %%rdx,0(%%r11)\n"
38 "\tmovq %%rax,8(%%r11)\n"
40 : /*in*/ "r"(&block
[0])
41 : /*trash*/ "%r11", "%r10", "%rax", "%rbx", "%rcx", "%rdx",
45 *memLoOut
= (ULong
)mem
[0];
46 *memHiOut
= (ULong
)mem
[1];
50 void try8b ( ULong d
, ULong a
, ULong mHi
, ULong mLo
, ULong c
, ULong b
)
52 ULong dd
, aa
, mmHi
, mmLo
, zz
;
53 do_cmpxchg8b( &dd
, &aa
, &mmHi
, &mmLo
, &zz
,
55 printf(" Q d:a=%llx:%llx mem=%llx:%llx c:b=%llx:%llx "
56 "-> z=%lld d:a=%llx:%llx mem=%llx:%llx\n",
57 d
,a
, mHi
,mLo
, c
,b
, zz
, dd
,aa
, mmHi
,mmLo
);
60 void do_cmpxchg16b ( /*OUT*/
61 ULong
* rdxOut
, ULong
* raxOut
,
62 ULong
* memHiOut
, ULong
* memLoOut
,
65 ULong rdxIn
, ULong raxIn
,
66 ULong memHiIn
, ULong memLoIn
,
67 ULong rcxIn
, ULong rbxIn
)
69 ULong mem
[2] __attribute__((aligned(16)));
77 block
[4] = (ULong
)&mem
[0];
81 "\tmovq 0(%%r11),%%rdx\n"
82 "\tmovq 8(%%r11),%%rax\n"
83 "\tmovq 16(%%r11),%%rcx\n"
84 "\tmovq 24(%%r11),%%rbx\n"
85 "\tmovq 32(%%r11),%%r10\n"
86 "\t.byte 0xf0, 0x49, 0x0f, 0xc7, 0x0a\n" /* lock cmpxchg16b (%%r10) */
87 "\tmovabsq $0,%%r10\n"
89 "\tmovq %%r10,40(%%r11)\n"
90 "\tmovq %%rdx,0(%%r11)\n"
91 "\tmovq %%rax,8(%%r11)\n"
93 : /*in*/ "r"(&block
[0])
94 : /*trash*/ "%r11", "%r10", "%rax", "%rbx", "%rcx", "%rdx",
103 void try16b ( ULong d
, ULong a
, ULong mHi
, ULong mLo
, ULong c
, ULong b
)
105 ULong dd
, aa
, mmHi
, mmLo
, zz
;
106 do_cmpxchg16b( &dd
, &aa
, &mmHi
, &mmLo
, &zz
,
108 printf("QQ d:a=%llx:%llx mem=%llx:%llx c:b=%llx:%llx "
109 "-> z=%lld d:a=%llx:%llx mem=%llx:%llx\n",
110 d
,a
, mHi
,mLo
, c
,b
, zz
, dd
,aa
, mmHi
,mmLo
);
115 ULong z
= 0xDEADBEEF00000000ULL
;
117 try8b( 0,1, 5,4, 3,2 );
118 try8b( 0,1, 0,1, 3,2 );
120 try8b( 0,1, 0,4, 3,2 );
121 try8b( 0,1, 0,0, 3,2 );
123 try8b( 0,1, 5,0, 3,2 );
124 try8b( 0,1, 1,1, 3,2 );
126 try8b( 0+z
,1+z
, 5+z
,4+z
, 3+z
,2+z
);
127 try8b( 0+z
,1+z
, 0+z
,1+z
, 3+z
,2+z
);
129 try8b( 0+z
,1+z
, 0+z
,4+z
, 3+z
,2+z
);
130 try8b( 0+z
,1+z
, 0+z
,0+z
, 3+z
,2+z
);
132 try8b( 0+z
,1+z
, 5+z
,0+z
, 3+z
,2+z
);
133 try8b( 0+z
,1+z
, 1+z
,1+z
, 3+z
,2+z
);
135 try16b( 0,1, 5,4, 3,2 );
136 try16b( 0,1, 0,1, 3,2 );
138 try16b( 0,1, 0,4, 3,2 );
139 try16b( 0,1, 0,0, 3,2 );
141 try16b( 0,1, 5,0, 3,2 );
142 try16b( 0,1, 1,1, 3,2 );
144 try16b( 0+z
,1+z
, 5+z
,4+z
, 3+z
,2+z
);
145 try16b( 0+z
,1+z
, 0+z
,1+z
, 3+z
,2+z
);
147 try16b( 0+z
,1+z
, 0+z
,4+z
, 3+z
,2+z
);
148 try16b( 0+z
,1+z
, 0+z
,0+z
, 3+z
,2+z
);
150 try16b( 0+z
,1+z
, 5+z
,0+z
, 3+z
,2+z
);
151 try16b( 0+z
,1+z
, 1+z
,1+z
, 3+z
,2+z
);