Re: Cleanup for cryptographic algorithms vs. compiler optimizations

From: Tijl Coosemans <tijl_at_coosemans.org>
Date: Mon, 14 Jun 2010 19:38:15 +0200
On Friday 11 June 2010 23:31:57 Dag-Erling Smørgrav wrote:
> Tijl Coosemans <tijl_at_coosemans.org> writes:
>> Dag-Erling Smørgrav <des_at_des.no> 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)
Received on Mon Jun 14 2010 - 15:38:19 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:04 UTC