--- radeon_cs_gem.c.orig 2014-11-23 13:22:34.000000000 -0500 +++ radeon_cs_gem.c 2014-11-23 13:24:46.000000000 -0500 @@ -81,11 +81,27 @@ /** * result is undefined if called with ~0 */ + /* __builtin_ctz returns number of trailing zeros. */ +/* static uint32_t get_first_zero(const uint32_t n) { - /* __builtin_ctz returns number of trailing zeros. */ return 1 << __builtin_ctz(~n); } +*/ + +#include +static uint32_t get_first_zero(const uint32_t n) +{ + unsigned int x,i, s, nn ; + nn=(unsigned int) n; + x=0;i=0;s=sizeof(n); + for(i=1;i<=sizeof(n)*CHAR_BIT;++i) + { + if( (nn & 1) == 0 ) ++x; else break; + nn=nn>>1; + } + return (uint32_t) x; +} /** * Returns a free id for cs.