Date: Mon, 5 Mar 2012 10:25:25 -0500 From: Rich Felker <dalias@...ifal.cx> To: musl@...ts.openwall.com Subject: Re: libm On Mon, Mar 05, 2012 at 04:17:11PM +0100, Szabolcs Nagy wrote: > * Rich Felker <dalias@...ifal.cx> [2012-03-05 09:04:59 -0500]: > > On Mon, Mar 05, 2012 at 09:51:35AM +0100, Szabolcs Nagy wrote: > > Hm? If you need a macro to test whether an argument is an integer or > > floating point, try this: > > > > #define __IS_FP(x) !!((1?1:(x))/2) > > oh nice > (and subtle) Note that it avoids evaluating x too, so it's safe in macros that need to avoid evaluating the argument more than once. > > adopted it. In any case I see no good way to define them without > > compound literals except the function calls.. > > > > btw while testing these macros i noticed that when > multiple classification macros are used fpclassify > gets called many times > (with the previous solution) > > the extra calls could be optimized by adding > __attribute__((const)) to fpclassify > (resulted less calls, smaller code size etc) Indeed. I was wrongly thinking they'd need __attribute__((__pure__)) rather than const, which is trickier because it's only available in newish gcc. But const has been around since before 2.95 even, so just #ifdef __GNUC__ is a sufficient check for using it. Alternatively I might just move the definitions of fpclassify (at least for non-LD types) back into math.h as static inline. This would let gcc optimize it down a lot more. Rich
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.