Skip to content

Commit

Permalink
added most_significant_bit* methods to scalar_arith.h
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislav Shwartsman committed Nov 23, 2023
1 parent 32c7c38 commit 1cfd97e
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions bochs/cpu/scalar_arith.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ BX_CPP_INLINE unsigned lzcntw(Bit16u val_16)
return count;
}

BX_CPP_INLINE unsigned most_significant_bitw(Bit16u val_16)
{
return 15 - lzcntw(val_16);
}

BX_CPP_INLINE unsigned lzcntd(Bit32u val_32)
{
Bit32u mask = 0x80000000;
Expand All @@ -100,6 +105,11 @@ BX_CPP_INLINE unsigned lzcntd(Bit32u val_32)
return count;
}

BX_CPP_INLINE unsigned most_significant_bitd(Bit32u val_32)
{
return 31 - lzcntd(val_32);
}

BX_CPP_INLINE unsigned lzcntq(Bit64u val_64)
{
Bit64u mask = BX_CONST64(0x8000000000000000);
Expand All @@ -113,6 +123,11 @@ BX_CPP_INLINE unsigned lzcntq(Bit64u val_64)
return count;
}

BX_CPP_INLINE unsigned most_significant_bitq(Bit64u val_64)
{
return 63 - lzcntq(val_64);
}

// popcnt

BX_CPP_INLINE unsigned popcntb(Bit8u val_8)
Expand Down

0 comments on commit 1cfd97e

Please sign in to comment.