Skip to content

Commit 90c1fb9

Browse files
committed
Use gcc/clang isnan and isinf builtin functions where available.
These are used heavily in the building of look-up tables at start-up time and therefore improve vipsthumbnail perf by ~4%.
1 parent af8b43b commit 90c1fb9

File tree

4 files changed

+22
-10
lines changed

4 files changed

+22
-10
lines changed

libvips/arithmetic/max.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ vips_max_stop( VipsStatistic *statistic, void *seq )
322322
TYPE m; \
323323
\
324324
for( i = 0; i < sz && values->n < values->size; i++ ) \
325-
if( !isnan( p[i] ) ) \
325+
if( !VIPS_ISNAN( p[i] ) ) \
326326
vips_values_add( values, p[i], x + i / bands, y ); \
327327
m = values->value[0]; \
328328
\
@@ -342,7 +342,7 @@ vips_max_stop( VipsStatistic *statistic, void *seq )
342342
for( i = 0; i < sz && values->n < values->size; i++ ) { \
343343
TYPE mod2 = p[0] * p[0] + p[1] * p[1]; \
344344
\
345-
if( !isnan( mod2 ) ) \
345+
if( !VIPS_ISNAN( mod2 ) ) \
346346
vips_values_add( values, p[i], x + i / bands, y ); \
347347
\
348348
p += 2; \

libvips/arithmetic/min.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ vips_min_stop( VipsStatistic *statistic, void *seq )
325325
TYPE m; \
326326
\
327327
for( i = 0; i < sz && values->n < values->size; i++ ) \
328-
if( !isnan( p[i] ) ) \
328+
if( !VIPS_ISNAN( p[i] ) ) \
329329
vips_values_add( values, p[i], x + i / bands, y ); \
330330
m = values->value[0]; \
331331
\
@@ -345,7 +345,7 @@ vips_min_stop( VipsStatistic *statistic, void *seq )
345345
for( i = 0; i < sz && values->n < values->size; i++ ) { \
346346
TYPE mod2 = p[0] * p[0] + p[1] * p[1]; \
347347
\
348-
if( !isnan( mod2 ) ) \
348+
if( !VIPS_ISNAN( mod2 ) ) \
349349
vips_values_add( values, p[i], x + i / bands, y ); \
350350
\
351351
p += 2; \

libvips/colour/LabQ2sRGB.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,9 @@ vips_col_scRGB2sRGB( int range, int *lut,
273273
* Don't use isnormal(), it is false for 0.0 and for subnormal
274274
* numbers.
275275
*/
276-
if( isnan( R ) || isinf( R ) ||
277-
isnan( G ) || isinf( G ) ||
278-
isnan( B ) || isinf( B ) ) {
276+
if( VIPS_ISNAN( R ) || VIPS_ISINF( R ) ||
277+
VIPS_ISNAN( G ) || VIPS_ISINF( G ) ||
278+
VIPS_ISNAN( B ) || VIPS_ISINF( B ) ) {
279279
*r = 0;
280280
*g = 0;
281281
*b = 0;
@@ -370,9 +370,9 @@ vips_col_scRGB2BW( int range, int *lut, float R, float G, float B,
370370
* Don't use isnormal(), it is false for 0.0 and for subnormal
371371
* numbers.
372372
*/
373-
if( isnan( R ) || isinf( R ) ||
374-
isnan( G ) || isinf( G ) ||
375-
isnan( B ) || isinf( B ) ) {
373+
if( VIPS_ISNAN( R ) || VIPS_ISINF( R ) ||
374+
VIPS_ISNAN( G ) || VIPS_ISINF( G ) ||
375+
VIPS_ISNAN( B ) || VIPS_ISINF( B ) ) {
376376
*g = 0;
377377

378378
return( -1 );

libvips/include/vips/util.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ extern "C" {
4040
#endif /*__cplusplus*/
4141

4242
#include <stdio.h>
43+
#include <math.h>
4344

4445
/* Some platforms don't have M_PI :-(
4546
*/
@@ -157,6 +158,17 @@ G_STMT_START { \
157158

158159
#define VIPS_CLIP_NONE( V, SEQ ) {}
159160

161+
/* The built-in isnan and isinf functions provided by gcc 4+ and clang are
162+
* up to 7x faster than their libc equivalent included from <math.h>.
163+
*/
164+
#if defined(__clang__) || (__GNUC__ >= 4)
165+
#define VIPS_ISNAN( V ) __builtin_isnan( V )
166+
#define VIPS_ISINF( V ) __builtin_isinf( V )
167+
#else
168+
#define VIPS_ISNAN( V ) isnan( V )
169+
#define VIPS_ISINF( V ) isinf( V )
170+
#endif
171+
160172
/* Not all platforms have PATH_MAX (eg. Hurd) and we don't need a platform one
161173
* anyway, just a static buffer big enough for almost any path.
162174
*/

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy