From owner-freebsd-current@FreeBSD.ORG Mon Jun 14 17:38:19 2010 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 05B571065688 for ; Mon, 14 Jun 2010 17:38:19 +0000 (UTC) (envelope-from tijl@coosemans.org) Received: from mailrelay010.isp.belgacom.be (mailrelay010.isp.belgacom.be [195.238.6.177]) by mx1.freebsd.org (Postfix) with ESMTP id 8D75D8FC18 for ; Mon, 14 Jun 2010 17:38:18 +0000 (UTC) X-Belgacom-Dynamic: yes X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av0EAOYEFkxbsdE3/2dsb2JhbACDHZtlcrAQkGmBJoMFbwQ Received: from 55.209-177-91.adsl-dyn.isp.belgacom.be (HELO kalimero.tijl.coosemans.org) ([91.177.209.55]) by relay.skynet.be with ESMTP; 14 Jun 2010 19:38:16 +0200 Received: from kalimero.tijl.coosemans.org (kalimero.tijl.coosemans.org [127.0.0.1]) by kalimero.tijl.coosemans.org (8.14.4/8.14.4) with ESMTP id o5EHcFDM015866 for ; Mon, 14 Jun 2010 19:38:15 +0200 (CEST) (envelope-from tijl@coosemans.org) From: Tijl Coosemans To: freebsd-current@freebsd.org Date: Mon, 14 Jun 2010 19:38:15 +0200 User-Agent: KMail/1.13.3 (FreeBSD/8.1-PRERELEASE; KDE/4.4.4; i386; ; ) References: <20100611162118.GR39829@acme.spoerlein.net> <201006112304.10952.tijl@coosemans.org> <86y6els1bm.fsf@ds4.des.no> In-Reply-To: <86y6els1bm.fsf@ds4.des.no> MIME-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <201006141938.15200.tijl@coosemans.org> Subject: Re: Cleanup for cryptographic algorithms vs. compiler optimizations X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Jun 2010 17:38:19 -0000 On Friday 11 June 2010 23:31:57 Dag-Erling Sm=C3=B8rgrav wrote: > Tijl Coosemans writes: >> Dag-Erling Sm=C3=B8rgrav 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)