Add a C implementation of leading_bit and clz to optimize Patricia tree
[SXSI/xpathcomp.git] / src / OCamlDriver.cpp
index 4a31dad..6b4e773 100644 (file)
@@ -45,6 +45,15 @@ extern "C" {
 }
 
 
+extern "C" value caml_clz(value i)
+{
+  return Val_long( ((sizeof(unsigned long)*8) - __builtin_clzl(Long_val(i))) - 1);
+}
+
+extern "C" value caml_leading_bit(value i)
+{
+  return Val_long( ( 1 << (sizeof(unsigned long)*8 - __builtin_clzl(Long_val(i)) - 1)));
+}
 
 /** XMLTreeBuilder bindings
  *