<html><head><base href="x-msg://2939/"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">
<div>Let's be explicit here. You want compare_exchange to take an explicit Var? For which argument? The memory location being manipulated or the expected value?</div><div><br></div><div><div>compare_exchange (t: MType; u: ZType; r: IType;</div><div> success, failure: MemoryOrder);</div><div>(* tmp := Mem[s2.A].t;</div><div> IF (tmp = Mem[s1.A].t)</div><div> THEN Mem [s2.A].t := s0.u; s2.r := 1; pop(2);</div><div> ELSE Mem [s1.A].t := tmp; s2.r := 0; pop(2);</div><div> END;</div><div> This is permitted to fail spuriously, leaving Mem [s1.A] unchanged.</div><div>*)</div><div><br></div><div>So, you want s1 to be a Var or s2?</div></div><div><br></div><div><div><br></div><div>On 12 Feb 2010, at 12:42, Jay K wrote:</div></div><div><br class="Apple-interchange-newline"><blockquote type="cite"><div class="hmmessage" style="font-size: 10pt; font-family: Verdana; ">It is easier to generate more efficient code if the variable is passed as a parameter to cg.compare_exchange instead of on the stack.<br>We can defer register allocation until we know we must use eax, instead of allocating it "wherever" and then moving it to eax once we know that is where it is needed, as it always will be.<br>We can also generate more efficient code for fetch_op if passed function parameters since we don't need to get the address in a register.<br> <br>Again, if m3back were multi pass or somehow smarter, it'd be moot.<br>I'll be looking into make it one or both of these maybe sometime soon.<br> <br> - Jay<br> <br><hr id="stopSpelling">From:<span class="Apple-converted-space"> </span><a href="mailto:hosking@cs.purdue.edu">hosking@cs.purdue.edu</a><br>Date: Fri, 12 Feb 2010 09:49:14 -0500<br>To:<span class="Apple-converted-space"> </span><a href="mailto:jay.krell@cornell.edu">jay.krell@cornell.edu</a><br>CC:<span class="Apple-converted-space"> </span><a href="mailto:m3devel@elegosoft.com">m3devel@elegosoft.com</a><br>Subject: Re: [M3devel] cg.compare_exchange should take more parameters in function call, fewer on stack?<br><br>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="ecxApple-tab-span" style="white-space: pre; "></span>pushq<span class="ecxApple-tab-span" style="white-space: pre; "> </span>%rbp</div><div>LCFI42:</div><div><span class="ecxApple-tab-span" style="white-space: pre; "></span>movq<span class="ecxApple-tab-span" style="white-space: pre; "> </span>%rsp, %rbp</div><div>LCFI43:</div><div><span class="ecxApple-tab-span" style="white-space: pre; "></span>movq<span class="ecxApple-tab-span" style="white-space: pre; "> </span>(%rsi), %rax</div><div><span class="ecxApple-tab-span" style="white-space: pre; "></span>lock; cmpxchgq %rdx, (%rdi); setz %al</div><div><span class="ecxApple-tab-span" style="white-space: pre; "></span>movsbl<span class="ecxApple-tab-span" style="white-space: pre; "> </span>%al,%eax</div><div><span class="ecxApple-tab-span" style="white-space: pre; "></span>leave</div><div><span class="ecxApple-tab-span" style="white-space: pre; "></span>ret</div><div>LFE526:</div><div><span class="ecxApple-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="ecxApple-interchange-newline"><blockquote><div class="ecxhmmessage" 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></div><br class="Apple-interchange-newline"></blockquote></div><br></body></html>