Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1695 from WalterBright/fix16743
Browse files Browse the repository at this point in the history
fix Issue 16743 - Intrinsic recognition sometimes fails if a software…
  • Loading branch information
andralex committed Nov 25, 2016
2 parents 60af18f + 7f90cdc commit dc622e5
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions src/core/bitop.d
Original file line number Diff line number Diff line change
Expand Up @@ -72,27 +72,28 @@ unittest
*/
int bsf(uint v) pure
{
static if (size_t.sizeof == ulong.sizeof)
{
pragma(inline, true);
return bsf(cast(ulong) v);
}
else
return softBsf!uint(v);
pragma(inline, false); // so intrinsic detection will work
return softBsf!uint(v);
}

/// ditto
int bsf(ulong v) pure
{
static if (size_t.sizeof == uint.sizeof)
static if (size_t.sizeof == ulong.sizeof) // 64 bit code gen
{
pragma(inline, false); // so intrinsic detection will work
return softBsf!ulong(v);
}
else
{
/* intrinsic not available for 32 bit code,
* make do with 32 bit bsf
*/
const sv = Split64(v);
return (sv.lo == 0)?
bsf(sv.hi) + 32 :
bsf(sv.lo);
}
else
return softBsf!ulong(v);
}

///
Expand All @@ -119,27 +120,28 @@ unittest
*/
int bsr(uint v) pure
{
static if (size_t.sizeof == ulong.sizeof)
{
pragma(inline, true);
return bsr(cast(ulong) v);
}
else
return softBsr!uint(v);
pragma(inline, false); // so intrinsic detection will work
return softBsr!uint(v);
}

/// ditto
int bsr(ulong v) pure
{
static if (size_t.sizeof == uint.sizeof)
static if (size_t.sizeof == ulong.sizeof) // 64 bit code gen
{
pragma(inline, false); // so intrinsic detection will work
return softBsr!ulong(v);
}
else
{
/* intrinsic not available for 32 bit code,
* make do with 32 bit bsr
*/
const sv = Split64(v);
return (sv.hi == 0)?
bsr(sv.lo) :
bsr(sv.hi) + 32;
}
else
return softBsr!ulong(v);
}

///
Expand Down

0 comments on commit dc622e5

Please sign in to comment.