summaryrefslogtreecommitdiff
path: root/misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/misc.c b/misc.c
index 06e790019..5f86d8445 100644
--- a/misc.c
+++ b/misc.c
@@ -601,11 +601,18 @@ void IncreaseDate()
/* XXX: check if year 2050 was reached */
}
-int FindFirstBit(uint32 x)
+int FindFirstBit(uint32 value)
{
- int i = 0;
- assert(x != 0);
- for(;!(x&1);i++,x>>=1);
+ // This is much faster then the one that was before here.
+ // Created by Darkvater.. blame him if it is wrong ;)
+ // Btw, the macro FINDFIRSTBIT is better to use when your value is
+ // not more then 128.
+ byte i = 0;
+ if (value & 0xffff0000) { value >>= 16; i += 16; }
+ if (value & 0x0000ff00) { value >>= 8; i += 8; }
+ if (value & 0x000000f0) { value >>= 4; i += 4; }
+ if (value & 0x0000000c) { value >>= 2; i += 2; }
+ if (value & 0x00000002) { i += 1; }
return i;
}