Differences

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

Link to this comparison view

Next revision
Previous revision
std:bit [2023/04/08 16:17] – created rajitstd:bit [2025/09/16 14:32] (current) rajit
Line 1: Line 1:
-====== Bit-manipulation Functions ======+====== Namespace std::bit  ====== 
 + 
 +This namespace contains bit-manipulation functions that can make the ACT description more legible. 
 + 
 +<code act> 
 +export template<pint N, W> function repeat(int<W> x) : int<N*W>; 
 +</code> 
 +This concatenates ''N'' copies of the ''W''-bit input ''x'' to create an output of width ''N*W''
 + 
 + 
 +<code act> 
 +export template<pint W, W2> function sign_extend(int<W> x) : int<W2>; 
 +</code> 
 +This sign-extends the integer ''x'' (bitwidth ''W'') to bitwidth ''W2''. ''W2'' must be strictly larger than ''W''
 + 
 + 
 +<code act> 
 +export template<pint W> function rol(int<W> x) : int<W>; 
 +</code> 
 +Left rotate the ''W'' bit integer by 1. The MSB of ''x'' becomes the LSB of the result (rotating shift). 
 + 
 +<code act> 
 +export template<pint W> function ror(int<W> x) : int<W>; 
 +</code> 
 +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. 
 + 
 +