tech-kern archive

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

Re: Make condition variables take absolute wakeup time

On Wed, 07 May 2008, der Mouse wrote:
> > These days, does hz >> 2 ever generate better code than hz / 4?
> <kernel.h> says hz is signed, [...]

With unsigned types, I'd hope that a decent compiler would emit the same
code for both, using either a shift or a divide instruction according to
its knowledge of which is faster or smaller.  gcc on i386 emits shift
instructions for both source code cases, with or without "-Os".

With signed types, if the value is negative, the result from the shift
is implementation defined, so I'd recommend not using a shift there.
Even if shifting a negative value works in the "obvious" way, (-3 >> 2)
would be -1, while (-3 / 2) would be 0.

--apb (Alan Barrett)

Home | Main Index | Thread Index | Old Index