0 is not a power of 2

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Tue May 19 07:36:59 PDT 2015


On 5/19/15 2:35 AM, Martin Nowak wrote:
> On Tuesday, 19 May 2015 at 07:56:27 UTC, Atila Neves wrote:
>> Aren't predictable branches cheap on current architectures?
>
> Yes they are, and it seems one would rarely if ever call isPowOf2 with 0
> in std.allocator. A good thing to do, is to use a good hardware event
> profiler like perf, and record the branch misses. Perf is also the right
> tool to compare the branchless version (I doubt it's significantly
> better, especially since the felt of the 0 branch is just a constant).

Yah measuring on-line is clearly the way to go. A comment on the 
branches - the branch predictor has a limited capacity so branching here 
might take resources away from other places. -- Andrei


More information about the Digitalmars-d mailing list