Just swapped it into mine ....OliverBr wrote: ↑Thu Sep 03, 2020 7:16 pmThank you. To already existing includesmar wrote: ↑Thu Sep 03, 2020 6:45 pm I did some googling and you you want is:
then useCode: Select all
#include <immintrin.h>
note that those are BMI1 (actually lzcnt was orginally ABM and tzcnt was added later as part of BMI1 as far as I understand)Code: Select all
_tzcnt_u64(x) _lzcnt_u64(x)
does the job. I didn't need to include explicitly immintrin.h, but I think VS2019 is doing it implicitly.Code: Select all
#include <windows.h> #include <conio.h> ... _lzcnt_u64(x)
It works perfectly.
_BitScanForward worked, too, but is slower. Both are clearly faster than own implemented methods.
was using code derived from this over-heavy Microsoft example:
Code: Select all
// BitScanForward.cpp
// compile with: /EHsc
#include <iostream>
#include <intrin.h>
using namespace std;
#pragma intrinsic(_BitScanForward)
int main()
{
unsigned long mask = 0x1000;
unsigned long index;
unsigned char isNonzero;
cout << "Enter a positive integer as the mask: " << flush;
cin >> mask;
isNonzero = _BitScanForward(&index, mask);
if (isNonzero)
{
cout << "Mask: " << mask << " Index: " << index << endl;
}
else
{
cout << "No set bits found. Mask is zero." << endl;
}
}
Code: Select all
inline int scanforward64(u64 x)
{
return ((int)_tzcnt_u64(x));
}