From 14ee911978f71d7b15024534af1271084c6f7a07 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Sat, 10 Mar 2018 20:52:39 +0100 Subject: [PATCH] lstm: Use MS C intrinsic function for faster calculation of log2 (#1369) Signed-off-by: Stefan Weil --- lstm/lstm.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lstm/lstm.cpp b/lstm/lstm.cpp index 97f8ff0acf..4b570f688e 100644 --- a/lstm/lstm.cpp +++ b/lstm/lstm.cpp @@ -24,6 +24,10 @@ #include #include +#if !defined(__GNUC__) && defined(_MSC_VER) +#include // _BitScanReverse +#endif + #include "fullyconnected.h" #include "functions.h" #include "networkscratch.h" @@ -74,6 +78,10 @@ static inline uint32_t ceil_log2(uint32_t n) #if defined(__GNUC__) // Use fast inline assembler code for gcc or clang. uint32_t l2 = 31 - __builtin_clz(n); +#elif defined(_MSC_VER) + // Use fast intrinsic function for MS compiler. + unsigned long l2 = 0; + _BitScanReverse(&l2, n); #else if (n == 0) return UINT_MAX; if (n == 1) return 0;