diff options
author | John Hawthorn <jhawthor@uvic.ca> | 2008-06-16 16:35:23 -0700 |
---|---|---|
committer | John Hawthorn <jhawthor@uvic.ca> | 2008-06-16 16:35:23 -0700 |
commit | f5b1ed2faf007ac9c8ef12b2db2ea4bb725f19b0 (patch) | |
tree | 1703121c0c860b763c2b2afb14ba5a2e868b471f | |
parent | e97407561d66bf0aa4d02905e0b2693455b34a6b (diff) | |
download | mirror-meh-f5b1ed2faf007ac9c8ef12b2db2ea4bb725f19b0.tar.gz mirror-meh-f5b1ed2faf007ac9c8ef12b2db2ea4bb725f19b0.tar.bz2 mirror-meh-f5b1ed2faf007ac9c8ef12b2db2ea4bb725f19b0.zip |
replace popcount with ctz
-rw-r--r-- | src/main.c | 20 |
1 files changed, 8 insertions, 12 deletions
@@ -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; |