From 14e94647bf09d9841cfa0ac650aa37ffc1e3862c Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Fri, 17 Dec 2010 16:06:10 +0000 Subject: [PATCH] cogl-util: Add an internal wrapper for the ffs function The ffs function is defined in C99 so if we want to use it in Cogl we need to provide a fallback for MSVC. This adds a configure check for the function and then a fallback using a while loop if it is not available. http://bugzilla.clutter-project.org/show_bug.cgi?id=2491 --- cogl/cogl-util.c | 21 +++++++++++++++++++++ cogl/cogl-util.h | 8 ++++++++ 2 files changed, 29 insertions(+) diff --git a/cogl/cogl-util.c b/cogl/cogl-util.c index 29165872b..d38049a93 100644 --- a/cogl/cogl-util.c +++ b/cogl/cogl-util.c @@ -218,3 +218,24 @@ _cogl_util_one_at_a_time_mix (unsigned int hash) return hash; } +/* The 'ffs' function is part of C99 so it isn't always available */ +#ifndef HAVE_FFS + +int +_cogl_util_ffs (int num) +{ + int i = 1; + + if (num == 0) + return 0; + + while ((num & 1) == 0) + { + num >>= 1; + i++; + } + + return i; +} + +#endif /* HAVE_FFS */ diff --git a/cogl/cogl-util.h b/cogl/cogl-util.h index 0ac56c9d9..e32fcd68e 100644 --- a/cogl/cogl-util.h +++ b/cogl/cogl-util.h @@ -95,4 +95,12 @@ _cogl_util_one_at_a_time_hash (unsigned int hash, unsigned int _cogl_util_one_at_a_time_mix (unsigned int hash); +/* The 'ffs' function is part of C99 so it isn't always available */ +#ifdef HAVE_FFS +#define _cogl_util_ffs ffs +#else +int +_cogl_util_ffs (int num); +#endif + #endif /* __COGL_UTIL_H */