Actually, I looked at doing just that.  And while this is possible, my 
experience suggest that gcc's built-ins don't do *quite* the same 
thing.  For example, __builtin_ffs() returns 0 if no bits are set, or 
the 1-based bit position if a bit is set.  BitScanForward return a BOOL 
to indicate no bits are set, and a 0-based bit position is returned in 
the pointer passed as p1.

Yes, you can write a routine to jigger the output of the __builtin to 
match the behavior MSVC programmers expect, but the code tends to be 
sub-optimal.  For example (IIRC), when you subtract 1 from ffs to turn 
it back to 0-based, the asm that ultimately gets produced uses the BSF 
instruction, adds one, then subtracts 1.<sigh>

If I were talking with the MS team when they were first writing 
BitScanForward, I would have encouraged them to go the way ffs does.  
However, if the goal here is to support MSVC ports, I think the inlines 
are a better (more efficient) way to go.

dw

On 3/28/2013 3:52 AM, Václav Zeman wrote:
> Why are those intrinsics even implemented using inline assembler
> instead of GCC's own built-in functions like __builtin_ffs() for
> _BitScanForward(), __sync_add_and_fetch() for _InterlockedAdd(), etc.?
>


------------------------------------------------------------------------------
Own the Future-Intel(R) Level Up Game Demo Contest 2013
Rise to greatness in Intel's independent game demo contest. Compete 
for recognition, cash, and the chance to get your game on Steam. 
$5K grand prize plus 10 genre and skill prizes. Submit your demo 
by 6/6/13. http://altfarm.mediaplex.com/ad/ck/12124-176961-30367-2
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to