towforce wrote: ↑Thu Sep 03, 2020 3:54 pm
It looks like a language issue rather than visual studio. In C derived languages, it's normally something like:
b [0] = 0 != (v & 1);
b [1] = 0 != (v & 2);
b [2] = 0 != (v & 4);
b [3] = 0 != (v & 8);
etc.
Basically 0 != (v & Math.Pow(2, bitnumber))
I fear you haven't got my question correctly.
My issue is not a language issue, it is really a compiler issue:
1) I have already working methods in language C to get the least significant bit.
2) In order to improve performance I am looking for an intrinsic function which is compiler dependent.
3) In gcc there are two functions,
4) In Visual Studio I have just found one.
5) I am looking for the second intrinsic function in Visual Studio other than "__lzcnt64"
this is not exactly the same but you may be looking for _BitscanForward64 and _BitscanReverse64, which translate to bsf/bsr x86 instructions
I believe __lzcnt64 is available on relatively new machines only
bsf/bsr both return the index of the least (forward) or most (reverse) bit, but is undefined for zero, so you should explicitly check for 0 yourself
mar wrote: ↑Thu Sep 03, 2020 4:52 pm
this is not exactly the same but you may be looking for _BitscanForward64 and _BitscanReverse64, which translate to bsf/bsr x86 instructions
I believe __lzcnt64 is available on relatively new machines only
bsf/bsr both return the index of the least (forward) or most (reverse) bit, but is undefined for zero, so you should explicitly check for 0 yourself
If I remember correct from 1997, we were using beta dev version of what became Visual Studio and CSTal had the asm instruction in some sort of macro. I’ll look up what I do now when I get home, but am fairly sure there’s a standard fast way that works, may well be the Mar instructions above, and I do think you indeed have to check you’re giving them non zero data.
Btw, are you compiling SF NNUE in VS, I got stuck on compile errors demanding c++17 support?
mar wrote: ↑Thu Sep 03, 2020 4:52 pm
this is not exactly the same but you may be looking for _BitscanForward64 and _BitscanReverse64, which translate to bsf/bsr x86 instructions
I believe __lzcnt64 is available on relatively new machines only
bsf/bsr both return the index of the least (forward) or most (reverse) bit, but is undefined for zero, so you should explicitly check for 0 yourself
Thank you. _BitscanForward64 helps me a bit, even it is not as fast as __lzcnt64. (< 10% gain)
chrisw wrote: ↑Thu Sep 03, 2020 5:56 pm
If I remember correct from 1997, we were using beta dev version of what became Visual Studio and CSTal had the asm instruction in some sort of macro. I’ll look up what I do now when I get home, but am fairly sure there’s a standard fast way that works, may well be the Mar instructions above, and I do think you indeed have to check you’re giving them non zero data.
OliverBr wrote: ↑Thu Sep 03, 2020 3:43 pm
Hello,
For gcc/clang both intrinsic functions are available for most and least significant bit (leading/trailing zeros):