Skip to content

Commit

Permalink
lstm: Use MS C intrinsic function for faster calculation of log2 (#1369)
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Weil <[email protected]>
  • Loading branch information
stweil authored and zdenop committed Mar 10, 2018
1 parent 960007e commit 14ee911
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lstm/lstm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
#include <stdio.h>
#include <stdlib.h>

#if !defined(__GNUC__) && defined(_MSC_VER)
#include <intrin.h> // _BitScanReverse
#endif

#include "fullyconnected.h"
#include "functions.h"
#include "networkscratch.h"
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 14ee911

Please sign in to comment.