[M3devel] fetch_and_op?

Tony Hosking hosking at cs.purdue.edu
Thu Jan 21 15:23:59 CET 2010


I want to implement the <cstdatomic.h> soon-to-be standard.  That is defined as fetch_and_op.

Antony Hosking | Associate Professor | Computer Science | Purdue University
305 N. University Street | West Lafayette | IN 47907 | USA
Office +1 765 494 6001 | Mobile +1 765 427 5484




On 21 Jan 2010, at 08:29, Jay K wrote:

> (* tmp := Mem [s1.A].t;
>    Mem [s1.A].t := tmp op s0.u;
>    s1.u := tmp; pop *)
> 
> 
> Tony, are you sure you want to return the old value, not the new value?
> That's not great on x86.
> I believe for "or" and "and", you end up having to do a compare exchange loops.
>  
>  
> For xor, add, sub, you can compute the old value, ok.
> But if caller wanted the old value, he can do that himself also.
> Caller can also write a compare_exchange loop.
>  
>  
> Therefore, I think it should be:
>  
> (* tmp := Mem [s1.A].t;
>    Mem [s1.A].t := tmp op s0.u;
>    s1.u := tmp op s0.u; pop *)
> 
> There is of course value in storing the value in mem and stack, since mem
> can change right away.
>  
>  
>  - Jay
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20100121/f0359ad5/attachment-0002.html>


More information about the M3devel mailing list