Date: Fri, 11 Jun 2010 23:04:10 +0200 From: Tijl Coosemans <tijl@coosemans.org> To: freebsd-current@freebsd.org Subject: Re: Cleanup for cryptographic algorithms vs. compiler optimizations Message-ID: <201006112304.10952.tijl@coosemans.org> In-Reply-To: <867hm5tl6u.fsf@ds4.des.no> References: <20100611162118.GR39829@acme.spoerlein.net> <867hm5tl6u.fsf@ds4.des.no>
next in thread | previous in thread | raw e-mail | index | archive | help
On Friday 11 June 2010 21:37:29 Dag-Erling Sm=C3=B8rgrav wrote: > Ulrich Sp=C3=B6rlein <uqs@spoerlein.net> writes: >> optimizing compilers have a tendency to remove assignments that have >> no side effects. The code in sys/crypto/sha2/sha2.c is doing a lot >> of zeroing variables, which is however optimized away. [...] Is >> there a canonical way to zero those variables and should we use them >> (memset perhaps? what are the performance implications?) >=20 > If you stick these variables in a struct, you can memset the struct > to zero them; if there are many of them, it may be faster than > zeroing them individually. >=20 > Alternatively, you can use something like this: >=20 > #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. None of the assignments below are removed for instance: volatile int a =3D 0; a =3D 1; a =3D 2;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201006112304.10952.tijl>