<html><head><base href="x-msg://2846/"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Here's what Boehm produces in his libatomic package. Don't know if it helps or answers your question.<div><br></div><div>The C source:<br><div><br></div><div><div>int Atomic__CompareSwap_ordered (volatile AO_t *addr, AO_t *old, AO_t new)</div><div>{ return AO_compare_and_swap_full(addr, *old, new); }</div><div><br></div><div>generates:</div><div><br></div><div><div>.globl _Atomic__CompareSwap_ordered</div><div>_Atomic__CompareSwap_ordered:</div><div>LFB526:</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>pushq<span class="Apple-tab-span" style="white-space:pre"> </span>%rbp</div><div>LCFI42:</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>movq<span class="Apple-tab-span" style="white-space:pre"> </span>%rsp, %rbp</div><div>LCFI43:</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>movq<span class="Apple-tab-span" style="white-space:pre"> </span>(%rsi), %rax</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>lock; cmpxchgq %rdx, (%rdi); setz %al</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>movsbl<span class="Apple-tab-span" style="white-space:pre"> </span>%al,%eax</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>leave</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>ret</div><div>LFE526:</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>.align 4,0x90</div><div><br></div><div><br>
<br><div><div>On 12 Feb 2010, at 04:17, Jay K wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div class="hmmessage" style="font-size: 10pt; font-family: Verdana; ">Tony, currently I have atomic.compare_and_exchange generating e.g.:<br> <br> <br> load_address gv.2[_MM_Main] 56<br> 0000018E: 8D3538000000 LEA ESI gv.2[_MM_Main]+56<br> load_address gv.2[_MM_Main] 152<br> 00000194: 8D3D98000000 LEA EDI gv.2[_MM_Main]+152<br> load gv.2[_MM_Main] 156 Int.32 Int.32<br> compare_exchange Int.32 Int.32 Int.32<br> 0000019A: 8BC7 MOV EAX EDI<br> 0000019C: 8B1D9C000000 MOV EBX gv.2[_MM_Main]+156<br> declare_temp 4 4 Addr F tv.35[T$35] -4<br> 000001A2: 8975FC MOV tv.35[T$35] ESI<br> 000001A5: F00FB15DFC LOCK CMPXCHG tv.35[T$35]:Addr EBX<br> <br><br>This might not be correct, but it is close.<br> <br><br>Now, the thing is, the eax register is special to lock cmpxchg.<br> It always holds the comparison value.<br><br>The point is, if cg.compare_exchange took its parameters as<br>parameters instead of on the stack, it could chose the<br>right register right away, instead of as above where it<br>choses the wrong one and then must mov it.<br> <br>Easy to change it like that?<br> <br><br>I realize this is an m3back deficiency.<br>It does the register allocation too early.<br><br> - Jay<br><br><br></div></blockquote></div><br></div></div></div></div></body></html>