Skip to content

Commit c7e8d70

Browse files
author
xiaying
committed
Audio:Bugfix: Fix bug for use clz error in windows
1 parent 54fe65f commit c7e8d70

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

tools/audio/source/audio.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,37 @@
1010
#include <MNN/expr/MathOp.hpp>
1111
#include <MNN/expr/NeuralNetWorkOp.hpp>
1212
#include <cmath>
13+
#include <algorithm>
1314
#include <complex>
1415
#include <fstream>
1516
#include <iostream>
1617
#include <limits>
1718
#ifndef M_PI
1819
#define M_PI 3.141592654
1920
#endif
21+
#ifdef _MSC_VER
22+
#define NOMINMAX
23+
#include <intrin.h>
24+
#include <windows.h>
25+
#endif
2026

2127
namespace MNN {
2228
namespace AUDIO {
23-
29+
#ifdef _MSC_VER
30+
inline uint32_t mnn_clz( uint32_t value ) {
31+
DWORD leading_zero = 0;
32+
if (_BitScanReverse(&leading_zero, value)) {
33+
return 31 - leading_zero;
34+
}else {
35+
// Same remarks as above
36+
return 32;
37+
}
38+
}
39+
#else
40+
inline uint32_t mnn_clz( uint32_t value ) {
41+
return __builtin_clz(value);
42+
}
43+
#endif
2444
struct WaveHeader {
2545
void SeekToDataChunk(std::istream &is) {
2646
// a t a d
@@ -263,7 +283,7 @@ unsigned int next_power_of_2(unsigned int x) {
263283
return 1;
264284
if ((x & (x - 1)) == 0)
265285
return x;
266-
return 1U << (32 - __builtin_clz(x));
286+
return 1U << (32 - mnn_clz(x));
267287
}
268288

269289
VARP hamming_window(int n_fft, bool periodic, float alpha, float beta) {

0 commit comments

Comments
 (0)