Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 13 Mar 1999 17:47:39 -0500 (EST)
From:      Thomas David Rivers <rivers@dignus.com>
To:        dennis@etinc.com, hackers@FreeBSD.ORG
Subject:   Re: 'C' language question
Message-ID:  <199903132247.RAA05825@lakes.dignus.com>
In-Reply-To: <199903132232.RAA19255@etinc.com>

next in thread | previous in thread | raw e-mail | index | archive | help
> 
> 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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199903132247.RAA05825>