emacs-devel
[Top][All Lists]
Advanced

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

Re: Proposal: block-based vector allocator


From: Ken Raeburn
Subject: Re: Proposal: block-based vector allocator
Date: Tue, 22 May 2012 01:23:30 -0400

On May 21, 2012, at 09:48, Dmitry Antipov wrote:
> On 05/21/2012 05:02 PM, Andreas Schwab wrote:
> 
>> It doesn't make much sense to try to find such a trivial but non-std
>> macro in a system header.
> 
> Hm, glibc provides some not-so-trivial bits (assuming gcc):
> 
> # define roundup(x, y)  (__builtin_constant_p (y) && powerof2 (y)             
> \
>                         ? (((x) + (y) - 1) & ~((y) - 1))                     \
>                         : ((((x) + ((y) - 1)) / (y)) * (y)))
> 
> It seems to be a very negligible optimization, but why not use it if 
> available?

Because a good compiler should be able to make that optimization itself if you 
use the simple, straightforward version?  (You might have to use an unsigned 
type for x.)  My Mac's compiler does.  I get the impression glibc has a lot of 
optimizations targeted at older versions of gcc.

You need to supply the fallback version anyways, so just use the version 
optimized for human readability and maintenance, instead of jumping through 
hoops to dig through multiple system headers for a trivial arithmetic macro to 
maybe save a few microseconds on a system with outdated software.

Ken


reply via email to

[Prev in Thread] Current Thread [Next in Thread]