Hi Mark,

Mark Kettenis wrote on Fri, Sep 25, 2015 at 11:37:17PM +0200:
> Ingo Schwarze wrote:
>> Mark Kettenis wrote on Fri, Sep 25, 2015 at 02:27:52PM -0600:

>>> CVSROOT:    /cvs
>>> Module name:        src
>>> Changes by: kette...@cvs.openbsd.org        2015/09/25 14:27:52
>>> 
>>> Modified files:
>>>     sys/dev/pci/drm: drm_linux.h 
>>> 
>>> Log message:
>>> Apparently 0 is not a power of 2
>>> (despite <sys/param.h> claiming that it is).
>>> Fixes inteldrm(4) on the GM45 chipset.

>> Heh.  It also claims that INT_MIN is a power of 2,
>> which isn't true either...
>> 
>> Then again, INT_MIN is weird anyway, given that
>> INT_MIN == -INT_MIN && INT_MIN != 0.
>> 
>> Or do you think
>> 
>>   (x > 0 && (((x) - 1) & (x)) == 0)
>> 
>> would be even safer?

> Well, the is_power_of_2() macro in drm_linux.h is now bug-compatible
> with Linux, which is what matters ;).
> 
> And perhaps it is intentional that powerof2(0) is true.  Even Linux
> has it that way.  I'd say this is better left like it is now.

I am not surprised that you chose with deliberation,
which is why i didn't send a patch in the first place...

It just seemed so weird that

 (1) is_power_of_2() and powerof2() are intentionally different and

 (2) intentionally, neither of them is mathematically correct
     for the complete range of whole numbers of all common types

that i thought it might make sense to ask, just to make sure that's
indeed how it's all intended and nothing was accidentally overlooked.

Case closed, thanks  :)
  Ingo

Reply via email to