From 16970c0de736133435e63a0efe43b860464199c4 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Fri, 1 May 2009 02:42:04 +0000 Subject: cleanup, speed up git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@905 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- converter/other/bmptopnm.c | 2 +- converter/other/jpeg2000/libjasper/jpc/jpc_math.c | 128 ++++++++++++---------- converter/other/pamtogif.c | 2 +- 3 files changed, 71 insertions(+), 61 deletions(-) (limited to 'converter') diff --git a/converter/other/bmptopnm.c b/converter/other/bmptopnm.c index 30b1012f..647ae3c6 100644 --- a/converter/other/bmptopnm.c +++ b/converter/other/bmptopnm.c @@ -421,7 +421,7 @@ lsbZeroCount(unsigned int const mask) Use GCC built-in when available. -----------------------------------------------------------------------------*/ -#if ( defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 304) ) +#if HAVE_GCC_BITCOUNT { return ( mask==0 ? sizeof(mask)*8 : __builtin_ctz(mask) ); } diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_math.c b/converter/other/jpeg2000/libjasper/jpc/jpc_math.c index d860847d..72e3ac37 100644 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_math.c +++ b/converter/other/jpeg2000/libjasper/jpc/jpc_math.c @@ -1,3 +1,72 @@ +#include +#include +#include +#include +#include +#include + +#include "jpc_math.h" + + + +/* Calculate the integer quantity floor(log2(x)), where x is a positive + integer. */ +int +jpc_floorlog2(int const arg) { + + int y; + int x; + + assert(arg > 0); + + y = 0; + x = arg; + while (x > 1) { + x >>= 1; + ++y; + } + return y; +} + + + +/* + jpc_floorlog2() and jpc_firstone() do the same thing. + The only difference is how input 0 is handled. + +n : 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 +ceil(log2(n)) : x 0 1 2 2 3 3 3 3 4 4 4 4 4 4 4 4 5 5 5 +floor(log2(n)) : x 0 1 1 2 2 2 2 3 3 3 3 3 3 3 3 4 4 4 4 +31-__builtin_clz(n): x 0 1 1 2 2 2 2 3 3 3 3 3 3 3 3 4 4 4 4 +jpc_floorlog2(n) : x 0 1 1 2 2 2 2 3 3 3 3 3 3 3 3 4 4 4 4 +jpc_firstone(n) :-1 0 1 1 2 2 2 2 3 3 3 3 3 3 3 3 4 4 4 4 + +*/ + + + +int +jpc_firstone(int const arg) { +/*---------------------------------------------------------------------------- + Calculate the bit position of the first leading one in a nonnegative + integer. +-----------------------------------------------------------------------------*/ + int n; + int x; + + assert(arg >= 0); + + n = -1; + x = arg; + while (x > 0) { + x >>= 1; + ++n; + } + return n; +} + + + /* * Copyright (c) 1999-2000 Image Power, Inc. and the University of * British Columbia. @@ -109,62 +178,3 @@ * * __END_OF_JASPER_LICENSE__ */ - -/* - * Math Library - * - * $Id$ - */ - -/******************************************************************************\ -* Includes -\******************************************************************************/ - -#include -#include -#include -#include -#include -#include - -#include "jpc_math.h" - -/******************************************************************************\ -* Miscellaneous Functions -\******************************************************************************/ - -/* Calculate the integer quantity floor(log2(x)), where x is a positive - integer. */ -int jpc_floorlog2(int x) -{ - int y; - - /* The argument must be positive. */ - assert(x > 0); - - y = 0; - while (x > 1) { - x >>= 1; - ++y; - } - return y; -} - -/* Calculate the bit position of the first leading one in a nonnegative - integer. */ -/* This function is the basically the same as ceillog2(x), except that the - allowable range for x is slightly different. */ -int jpc_firstone(int x) -{ - int n; - - /* The argument must be nonnegative. */ - assert(x >= 0); - - n = -1; - while (x > 0) { - x >>= 1; - ++n; - } - return n; -} diff --git a/converter/other/pamtogif.c b/converter/other/pamtogif.c index b8df9626..0c8c0f9e 100644 --- a/converter/other/pamtogif.c +++ b/converter/other/pamtogif.c @@ -864,7 +864,7 @@ typedef struct { static unsigned int nSignificantBits( unsigned int const arg ){ -#if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 304) +#if HAVE_GCC_BITCOUNT return (arg == 0) ? 0 : 8 * sizeof(unsigned int) - __builtin_clz(arg); -- cgit 1.4.1