From owner-freebsd-hackers Sat Mar 13 14:48: 7 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from smtp1.vnet.net (smtp1.vnet.net [166.82.1.31]) by hub.freebsd.org (Postfix) with ESMTP id 4BAF014E9B for ; Sat, 13 Mar 1999 14:48:04 -0800 (PST) (envelope-from rivers@dignus.com) Received: from dignus.com (ponds.vnet.net [166.82.177.48]) by smtp1.vnet.net (8.9.1a/8.9.1) with ESMTP id RAA19214; Sat, 13 Mar 1999 17:47:40 -0500 (EST) Received: from lakes.dignus.com (lakes.dignus.com [10.0.0.3]) by dignus.com (8.9.2/8.8.5) with ESMTP id RAA04271; Sat, 13 Mar 1999 17:47:39 -0500 (EST) Received: (from rivers@localhost) by lakes.dignus.com (8.9.2/8.6.9) id RAA05825; Sat, 13 Mar 1999 17:47:39 -0500 (EST) Date: Sat, 13 Mar 1999 17:47:39 -0500 (EST) From: Thomas David Rivers Message-Id: <199903132247.RAA05825@lakes.dignus.com> To: dennis@etinc.com, hackers@FreeBSD.ORG Subject: Re: 'C' language question In-Reply-To: <199903132232.RAA19255@etinc.com> Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > > I have a memory mapped controller that requires that all of its > register reads and writes be 32 bits....the follow code: > > *reg |= 0x80000000; > > generates a byte OR (ORB instruction) which trashes the register with > gcc 2.9.2....a stupid "optimization" that happens to be wrong in this > case. > > is there a declaration that will force the compiler to generate a 32bit > OR (ORL instruction) on this? > > Dennis > Interesting problem... I don't believe the C language speaks to this; because the operation may be implemented as the compiler sees fit, as long as it gets the right answer (and, it would, in this case.) Perhaps, if you play around with volatile a bit, you can get a full 32-bit move, something like: volatile int i; i = *reg; i |= 0x80000000; *reg = i; The assigment of *reg = i should move all 32 bits, and you really don't care how the OR is accomplished. Also, because of the volatile keyword, the compiler can't eliminate the reference. But - this will force moves to/from memory - which may be a performance issue for you in a device driver... - Dave Rivers - To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message