Re: Fw: Possible missed optimization opportunity with const?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



David Brown wrote:

> If it is a hardware register, you normally want to put a "volatile"

> there so that you get exactly the number of reads you want. And if you
> only want to read it once, then read it only once.=C2=A0 Sometimes it is
> easier to write things in clear and simple code, rather than hoping the> compiler will optimise the unnecessary source code.

There are many cases where there are values at hardware addresses which are const.

One example is a hardware configuration register. Many modern microcontrollers
are fabricated with more interfaces than can be physically bonded out in a particular
packaging. For example,a microcontroller die may have a 4 USB interfaces, 4 SPI,
and 4 I2C ports. However, this die may be placed in a packaging where there is only
space for some of the signals to be exposed. So a particular chip might have
2 USB interfaces, 2 SPI interfaces, and 2 I2C ports. Another chip in the same family
might have 1 USB interface, 3 SPI interfaces, and 2 I2C ports. So there may be a static
hardware configuration register which describes the number of interfaces of each type
for that particular chip.


Another example is mask-programmed ROM or EPROM. These devices are usually fairly slow
with access times ranging from 125 ns to 450 ns. Since these devicesare so slow, it is preferable to avoid unnecessary reads to the device. The values
in a mask-programmed ROM cannot be changed, and the values in an EPROM can only
be changed when the device is powered off and exposed to UV light for several minutes,
so the values are effectively const and do not change at runtime.

Toshi



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux