From f5b1ed2faf007ac9c8ef12b2db2ea4bb725f19b0 Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Mon, 16 Jun 2008 16:35:23 -0700 Subject: replace popcount with ctz --- src/main.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/main.c b/src/main.c index e67792f..f093b91 100644 --- a/src/main.c +++ b/src/main.c @@ -34,23 +34,19 @@ void usage(){ exit(1); } -static int popcount(unsigned long mask){ +unsigned int getshift(unsigned int mask){ #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) - return __builtin_popcount(mask); + return __builtin_ctz(mask); #else - int y; - - y = (mask >> 1) & 033333333333; - y = mask - y - ((y >> 1) & 033333333333); - return (((y + (y >> 3)) & 030707070707) % 077); + int i = 0; + while((mask & 1) == 0){ + i++; + mask >>= 1; + } + return i; #endif } - -unsigned int getshift(unsigned int mask){ - return popcount((mask - 1) & ~mask) & 31; -} - void setaspect(int w, int h){ XSizeHints *hints = XAllocSizeHints(); hints->flags = PAspect; -- cgit v1.2.3