Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
std:bit [2025/09/16 14:30] rajitstd:bit [2025/09/16 14:32] (current) rajit
Line 13: Line 13:
 </code> </code>
 This sign-extends the integer ''x'' (bitwidth ''W'') to bitwidth ''W2''. ''W2'' must be strictly larger than ''W''. This sign-extends the integer ''x'' (bitwidth ''W'') to bitwidth ''W2''. ''W2'' must be strictly larger than ''W''.
 +
  
 <code act> <code act>
Line 23: Line 24:
 </code> </code>
 Right rotate ''x'' by one, with the LSB of ''x'' becoming the MSB of the result. Right rotate ''x'' by one, with the LSB of ''x'' becoming the MSB of the result.
 +
 +<code act>
 +export template<pint W>  function find_msb_pos(int<W> x) : int<std::ceil_log2(W)>;
 +</code>
 +This function assumes that ''x'' is non-zero, and returns the bit position of the most significant one in ''x''.
 +
 +<code act>
 +export template<pint W> function popcount(int<W> x) : int<std::ceil_log2(W+1)>;
 +</code>
 +This function returns a count of the number of bits of ''x'' that are set to 1.
 +