Csd 1.1.4; VERSION ${PROJECT_VERSION}
Loading...
Searching...
No Matches
Classes | Functions | Variables
csd Namespace Reference

Classes

class  invalid_csd_format
 Exception thrown when invalid CSD characters are encountered. More...
 
struct  MultiplierSpec
 Specification for a single CSD multiplier coefficient. More...
 

Functions

auto to_csd (double decimal_value, int places) -> std::string
 
auto to_csd_i (int decimal_value) -> std::string
 
auto to_csdnnz (double decimal_value, unsigned int nnz) -> std::string
 Convert a floating-point number to CSD with limited non-zero digits.
 
auto to_csdnnz_i (int decimal_value, unsigned int nnz) -> std::string
 Convert an integer to CSD with limited non-zero digits.
 
CONSTEXPR14 auto to_decimal_using_switch (const char *csd) -> double
 
CONSTEXPR14 auto to_decimal_integral (const char *&csd) -> int
 Convert the integral part of a CSD string to a decimal.
 
CONSTEXPR14 auto to_decimal_fractional (const char *csd) -> double
 Convert the fractional part of a CSD string to a decimal.
 
CONSTEXPR14 auto to_decimal (const char *csd) -> double
 Convert the CSD string to a decimal.
 
CONSTEXPR14 auto to_decimal_i (const char *csd) -> int
 Convert CSD string to integer.
 
auto generate_csd_multiplier (const std::string &csd_str, int input_width, int max_power) -> std::string
 Generate Verilog code for a single CSD multiplier module.
 
auto generate_csd_multipliers (const std::vector< MultiplierSpec > &coeffs, const std::string &module_name="csd_filter") -> std::string
 Generate Verilog for multiple CSD multipliers with cross-CSE.
 
auto longest_repeated_substring (const char *sv, size_t len) -> std::string
 Find the longest repeated non-overlapping substring.
 
void log_with_spdlog (const std::string &message)
 Log a message using spdlog.
 

Variables

constexpr int MAX_DECIMAL_PLACES = 20
 Maximum number of decimal places supported by CSD conversion.
 
constexpr unsigned int MIN_NONZERO_DIGITS = 1
 Minimum value for non-zero digit count in CSDNNZ functions.
 

Function Documentation

◆ generate_csd_multiplier()

auto csd::generate_csd_multiplier ( const std::string &  csd_str,
int  input_width,
int  max_power 
) -> std::string

Generate Verilog code for a single CSD multiplier module.

Converts a Canonical Signed Digit (CSD) string into a synthesizable Verilog module that performs constant multiplication using shifts and additions/subtractions.

Parameters
[in]csd_strCSD string using '+', '-', '0' (e.g. "+00-00+0+")
[in]input_widthBit width of the input signal x
[in]max_powerHighest power of two in the CSD (must be len(csd)-1)
Returns
Verilog module code as a string
Exceptions
std::invalid_argumentif csd_str length doesn't match max_power+1 or if the string contains characters other than '+', '-', '0'

◆ generate_csd_multipliers()

auto csd::generate_csd_multipliers ( const std::vector< MultiplierSpec > &  coeffs,
const std::string &  module_name = "csd_filter" 
) -> std::string

Generate Verilog for multiple CSD multipliers with cross-CSE.

When the same CSD substring appears in multiple coefficients, a shared sub-expression wire is created - reducing total adder count across the entire filter.

All coefficients must share the same input_width and max_power so that the same bit position encodes the same power of two.

Parameters
[in]coeffsList of coefficient specifications
[in]module_nameName for the generated Verilog module
Returns
Verilog module code
Exceptions
std::invalid_argumenton validation failure or width mismatch

◆ log_with_spdlog()

void csd::log_with_spdlog ( const std::string &  message)

Log a message using spdlog.

This function logs a message using the spdlog library. It provides a simple interface for logging messages throughout the csd library without exposing the full spdlog API.

Parameters
[in]messageThe message to log