Cleanup for cryptographic algorithms vs. compiler optimizations

Tijl Coosemans tijl at
Mon Jun 14 17:38:19 UTC 2010

On Friday 11 June 2010 23:31:57 Dag-Erling Smørgrav wrote:
> Tijl Coosemans <tijl at> writes:
>> Dag-Erling Smørgrav <des at> writes:
>>> #define FORCE_ASSIGN(type, var, value) \
>>>         *(volatile type *)&(var) = (value)
>> memset can be optimised away as well. The only way is to declare
>> those variables volatile.
> 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) = (value)

And if you can use GNU extensions this can be simplified to:

#define FORCE_ASSIGN(var, value) \
        *(typeof(var) volatile *)&(var) = (value)

More information about the freebsd-current mailing list