Skip to content

Bits.h in MSVC #76

Closed
Closed

Description

@qi7chen

It seems the effort to port Bits.h to MSVC have a little bit problem:
__builtin_ffs(x) won't return 0 when x is not 0, but _BitScanForward(index, mask) can load index to zero when mask's LSB is 1.

I make this:

#ifdef _MSC_VER
    unsigned long index;
    return (_BitScanForward(&index, x) ? index + 1 : 0);
#else
    return __builtin_ffs(x);
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions