Date: Mon, 14 Jun 2010 19:38:15 +0200 From: Tijl Coosemans <tijl@coosemans.org> To: freebsd-current@freebsd.org Subject: Re: Cleanup for cryptographic algorithms vs. compiler optimizations Message-ID: <201006141938.15200.tijl@coosemans.org> In-Reply-To: <86y6els1bm.fsf@ds4.des.no> References: <20100611162118.GR39829@acme.spoerlein.net> <201006112304.10952.tijl@coosemans.org> <86y6els1bm.fsf@ds4.des.no>
next in thread | previous in thread | raw e-mail | index | archive | help
On Friday 11 June 2010 23:31:57 Dag-Erling Sm=C3=B8rgrav wrote: > Tijl Coosemans <tijl@coosemans.org> writes: >> Dag-Erling Sm=C3=B8rgrav <des@des.no> writes: >>> #define FORCE_ASSIGN(type, var, value) \ >>> *(volatile type *)&(var) =3D (value) >> memset can be optimised away as well. The only way is to declare >> those variables volatile. >=20 > Assigning through a volatile pointer, as in FORCE_ASSIGN(), also > works, even if the variable itself is not volatile. Just thought of problem with this macro when var is a pointer. Then volatile applies to the referenced memory and not the variable. So you should move the volatile keyword, like so: #define FORCE_ASSIGN(type, var, value) \ *(type volatile *)&(var) =3D (value) And if you can use GNU extensions this can be simplified to: #define FORCE_ASSIGN(var, value) \ *(typeof(var) volatile *)&(var) =3D (value)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201006141938.15200.tijl>