Skip to content

Commit 14ee911

Browse files
stweilzdenop
authored andcommitted
lstm: Use MS C intrinsic function for faster calculation of log2 (#1369)
Signed-off-by: Stefan Weil <[email protected]>
1 parent 960007e commit 14ee911

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

lstm/lstm.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
#include <stdio.h>
2525
#include <stdlib.h>
2626

27+
#if !defined(__GNUC__) && defined(_MSC_VER)
28+
#include <intrin.h> // _BitScanReverse
29+
#endif
30+
2731
#include "fullyconnected.h"
2832
#include "functions.h"
2933
#include "networkscratch.h"
@@ -74,6 +78,10 @@ static inline uint32_t ceil_log2(uint32_t n)
7478
#if defined(__GNUC__)
7579
// Use fast inline assembler code for gcc or clang.
7680
uint32_t l2 = 31 - __builtin_clz(n);
81+
#elif defined(_MSC_VER)
82+
// Use fast intrinsic function for MS compiler.
83+
unsigned long l2 = 0;
84+
_BitScanReverse(&l2, n);
7785
#else
7886
if (n == 0) return UINT_MAX;
7987
if (n == 1) return 0;

0 commit comments

Comments
 (0)