PandA-2024.02
Macros | Functions | Variables
math_function.hpp File Reference

mathematical utility function not provided by standard libraries More...

#include <boost/version.hpp>
#include <boost/math/common_factor_rt.hpp>
#include <limits>
#include <type_traits>
Include dependency graph for math_function.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define EXACT_POWER_OF_2_OR_ZERO_P(x)   (((x) & ((x)-1)) == 0)
 Test whether a value is zero of a power of two. More...
 

Functions

template<typename Integer >
Integer GreatestCommonDivisor (const Integer first, const Integer second)
 Return the greatest common divisor. More...
 
template<typename Integer >
Integer LeastCommonMultiple (const Integer first, const Integer second)
 Return the least common multiple of two integers. More...
 
template<typename T >
compute_n_bytes (T bitsize)
 
template<typename T , std::enable_if_t< std::is_unsigned< T >::value, bool > = true>
floor_log2 (T x)
 Given X, an unsigned number, return the largest int Y such that 2**Y <= X. If X is 0, return -1. More...
 
template<typename T , std::enable_if_t< std::is_unsigned< T >::value, bool > = true>
exact_log2 (T x)
 Return the logarithm of X, base 2, considering X unsigned, if X is a power of 2. More...
 
template<typename T , std::enable_if_t< std::is_unsigned< T >::value, bool > = true>
ceil_log2 (T x)
 Return the smallest n such that 2**n >= X. More...
 
return static_cast< T > (x)
 
template<typename T , std::enable_if_t< std::is_unsigned< T >::value, bool > = true>
constexpr T get_aligned_bitsize (T bitsize)
 
template<typename T , std::enable_if_t< std::is_unsigned< T >::value, bool > = true>
constexpr T get_aligned_bitsize (T bitsize, T align)
 
template<typename T , std::enable_if_t< std::is_unsigned< T >::value, bool > = true>
constexpr T get_aligned_ac_bitsize (T bitsize)
 
template<typename T , std::enable_if_t< std::is_unsigned< T >::value, bool > = true>
resize_1_8_pow2 (T value)
 

Variables

template<typename T , std::enable_if_t< std::is_unsigned< T >::value, bool > = true>
 x = x >> 2
 Return the smallest n such that 2^n >= _x. More...
 

Detailed Description

mathematical utility function not provided by standard libraries

Author
Marco Lattuada lattu.nosp@m.ada@.nosp@m.elet..nosp@m.poli.nosp@m.mi.it $Revision$ $Date$ Last modified by $Author$

Definition in file math_function.hpp.

Macro Definition Documentation

◆ EXACT_POWER_OF_2_OR_ZERO_P

#define EXACT_POWER_OF_2_OR_ZERO_P (   x)    (((x) & ((x)-1)) == 0)

Test whether a value is zero of a power of two.

Definition at line 97 of file math_function.hpp.

Referenced by IR_lowering::division_by_a_constant(), and IR_lowering::expand_MC().

Function Documentation

◆ ceil_log2()

template<typename T , std::enable_if_t< std::is_unsigned< T >::value, bool > = true>
T ceil_log2 ( x)
inline

◆ compute_n_bytes()

template<typename T >
T compute_n_bytes ( bitsize)
inline

◆ exact_log2()

template<typename T , std::enable_if_t< std::is_unsigned< T >::value, bool > = true>
T exact_log2 ( x)
inline

Return the logarithm of X, base 2, considering X unsigned, if X is a power of 2.

Otherwise, returns -1.

Definition at line 141 of file math_function.hpp.

References floor_log2(), and symmetry::value.

Referenced by synth_mult().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ floor_log2()

template<typename T , std::enable_if_t< std::is_unsigned< T >::value, bool > = true>
T floor_log2 ( x)
inline

Given X, an unsigned number, return the largest int Y such that 2**Y <= X. If X is 0, return -1.

Definition at line 101 of file math_function.hpp.

References symmetry::value.

Referenced by ceil_log2(), IR_lowering::division_by_a_constant(), exact_log2(), IR_lowering::expand_MC(), IR_lowering::expand_sdiv_pow2(), IR_lowering::expand_smod_pow2(), and synth_mult().

Here is the caller graph for this function:

◆ get_aligned_ac_bitsize()

template<typename T , std::enable_if_t< std::is_unsigned< T >::value, bool > = true>
constexpr T get_aligned_ac_bitsize ( bitsize)
inline

Definition at line 197 of file math_function.hpp.

References symmetry::value.

Referenced by InterfaceInfer::interface_info::update().

Here is the caller graph for this function:

◆ get_aligned_bitsize() [1/2]

template<typename T , std::enable_if_t< std::is_unsigned< T >::value, bool > = true>
constexpr T get_aligned_bitsize ( bitsize)
inline

Definition at line 180 of file math_function.hpp.

References max, and symmetry::value.

Referenced by InterfaceInfer::Exec(), fu_binding::fill_array_ref_memory(), tree_manipulation::GetCustomIntegerType(), and InterfaceInfer::interface_info::update().

Here is the caller graph for this function:

◆ get_aligned_bitsize() [2/2]

template<typename T , std::enable_if_t< std::is_unsigned< T >::value, bool > = true>
constexpr T get_aligned_bitsize ( bitsize,
align 
)
inline

Definition at line 191 of file math_function.hpp.

References max, and symmetry::value.

◆ GreatestCommonDivisor()

template<typename Integer >
Integer GreatestCommonDivisor ( const Integer  first,
const Integer  second 
)

Return the greatest common divisor.

Parameters
firstis the first operand
secondis the second operand
Returns
the greatest common divisor of first and second

Definition at line 65 of file math_function.hpp.

◆ LeastCommonMultiple()

template<typename Integer >
Integer LeastCommonMultiple ( const Integer  first,
const Integer  second 
)

Return the least common multiple of two integers.

Parameters
firstis the first operand
secondis the second operand
Returns
the least common multiple of first and second

Definition at line 81 of file math_function.hpp.

◆ resize_1_8_pow2()

template<typename T , std::enable_if_t< std::is_unsigned< T >::value, bool > = true>
T resize_1_8_pow2 ( value)
inline

◆ static_cast< T >()

return static_cast< T > ( x  )

Referenced by ceil_log2().

Here is the caller graph for this function:

Variable Documentation

◆ x

template<typename T , std::enable_if_t< std::is_unsigned< T >::value, bool > = true>
x = x >> 2

Generated on Mon Feb 12 2024 13:03:35 for PandA-2024.02 by doxygen 1.8.13