Re: GCC 3.4.3, __sync_fetch_and_add on SunOS 5.10 sparc

Peter van Dijk <[email protected]>
Newsgroups gmane.network.dns.powerdns.devel
Message-ID <[email protected]>
Hello,

On Oct 2, 2013, at 19:16 , a b wrote:

> However, on sparc, the compilation fails because GCC 3.4.3 does not include the __sync_fetch_and_add() function (macro?).
> 
> On i86pc, the compilation passes because of this bit of code:
> 
>     // the below is necessary because __sync_fetch_and_add is not universally available on i386.. I 3> RHEL5.
>     #if defined( __GNUC__ ) && ( defined( __i386__ ) || defined( __x86_64__ ) )
>     static int atomic_exchange_and_add( unsigned int * pw, int dv )
>     {
>         // int r = *pw;
>         // *pw += dv;
>         // return r;
> 
>         int r;
> 
>         __asm__ __volatile__
>         (
>             "lock\n\t"
>             "xadd %1, %0":
>             "+m"( *pw ), "=r"( r ): // outputs (%0, %1)
>             "1"( dv ): // inputs (%2 == %1)
>             "memory", "cc" // clobbers
>         );
> 
>         return r;
>     }
> 
> Obviously, the x86 assembler bit cannot work on sparc, and since the __sync_fetch_and_add() is unavailable, it fails.
> 
> My "fix" for that was this:
> 
>     #else
>     static int atomic_exchange_and_add( unsigned int * pw, int dv )
>     {
>       #if(((__GNUC__ == 3) && (__GNUC_MINOR__ == 4) && (__GNUC_PATCHLEVEL__ == 3)) && defined(__sparc__))
>       int r = *pw;
>       *pw += dv;
>       return(r);
>       #else
>       return __sync_fetch_and_add(pw, dv);
>       #endif
>     }
>     #endif
> 
> But I do not trust myself to have fully understood the code and the intent. Can someone who has worked on this code confirm or deny that this is a sane fix?

Apologies for my late response; I was triggered by your report of a recursor crash (which I presume is unrelated as it happened on x86).

This fix is not right - it lacks the synchronous aspect of the original. I'm not sure how to fix this portably - if we knew, we would have done so..

We do strongly advise using a more recent gcc if at all possible.

Kind regards,
-- 
Peter van Dijk
Netherlabs Computer Consulting BV - http://www.netherlabs.nl/

_______________________________________________
Pdns-dev mailing list
[email protected]
http://mailman.powerdns.com/mailman/listinfo/pdns-dev
signature.asc (application/pgp-signature, 841 B)
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org

iQIcBAEBAgAGBQJSigqeAAoJENz1E/p+7Rnzr3UQAMghMkaqdDDj89ZM2t56Plyc
tgy8PhSvRI2gNiV2jWBmBPMNQau5AnTaJ+PLp6hTXMNe6uhDH+Ho7uVYdZPQMN34
k9exW83g7+6qg/LfGA3HCm3RNEa1TxlE5lDs8G3t1IMxU00QSnUq8xTkb7H93JDQ
zRNNPKsyJnq2r0qaVAxh8x6qPPljwg2hDjjNdZYB1KYFFtatOjUaBNTmNX5R4xdo
TUTAgVmuT0Bd/sl+8shtgkvN36Vo/KVBsBxWl6NX6YH+gdiB9Y1+hOk4R926myCp
EFke4dylztlCd2N5P52RJIjITCXv/ZLMc56UwDPOM/RjkURzGKfHTvJN6FloHCcF
tBhN1WcsUFZnkqCIFcqI1bbKZWtm+h+aHrLz/Ajr/TWETVssIp0Zq4sDer/wW+9E
z40VYFdGRYvTaVVV+YQHYfTMOxbr6lIZi072+/v9MtTPw/SPH2JgIqYGSAu/8bi5
NxedPQufb2QzKVu4mI2uoQ18dxkG4QMvYh7SEiyGERbXhQwmLyNIZm2gNc//YowA
yY07CA6tbpWcsOcUeaSkcvpzs0Xsz0AsvtXhofitp+3y7nw6AJcu4yMMS3XDjXLo
kcaZaUUg+duif+somS+By+/6mGDfef2rVZjPluTwnQysg1MEDc1i3vJfDgvsIs7c
f3HD8bpPwboyB8aPO9Vg
=J9gT
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.