Added support for building against Android API-9 SDK
[oota-llvm.git] / include / llvm / Support / MathExtras.h
index 7edc2ac2e7adb5cbc416c6ea902540dc00b268a4..340dc934934ceccb58ab28a4c5d023d1ab03e5a5 100644 (file)
 #include <intrin.h>
 #endif
 
+#ifdef __ANDROID_NDK__
+#include <android/api-level.h>
+#endif
+
 namespace llvm {
 /// \brief The behavior an operation has on an input of 0.
 enum ZeroBehavior {
@@ -449,6 +453,15 @@ inline unsigned countPopulation(T Value) {
   return detail::PopulationCounter<T, sizeof(T)>::count(Value);
 }
 
+/// Log2 - This function returns the log base 2 of the specified value
+inline double Log2(double Value) {
+#if defined(__ANDROID_API__) && __ANDROID_API__ < 18
+  return (double)__builtin_log2l(Value);
+#else
+  return log2(Value);
+#endif
+}
+
 /// Log2_32 - This function returns the floor log base 2 of the specified value,
 /// -1 if the value is zero. (32 bit edition.)
 /// Ex. Log2_32(32) == 5, Log2_32(1) == 0, Log2_32(0) == -1, Log2_32(6) == 2