Skip to content

Commit

Permalink
Improved C++ documentation (inner operators)
Browse files Browse the repository at this point in the history
  • Loading branch information
christophe0606 committed Mar 5, 2024
1 parent 5cb0858 commit 0732932
Show file tree
Hide file tree
Showing 20 changed files with 1,554 additions and 36 deletions.
2 changes: 1 addition & 1 deletion Documentation/Doxygen/dsp.dxy.in
Original file line number Diff line number Diff line change
Expand Up @@ -2430,7 +2430,7 @@ INCLUDE_FILE_PATTERNS =
# recursively expanded use the := operator instead of the = operator.
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.

PREDEFINED = HAS_VECTOR HAS_PREDICATED_LOOP ARM_MATH_NEON=1 ARM_FLOAT16_SUPPORTED=1 __STATIC_FORCEINLINE= __ALIGNED(x)=
PREDEFINED = DOXYGEN HAS_VECTOR HAS_PREDICATED_LOOP ARM_MATH_NEON=1 ARM_FLOAT16_SUPPORTED=1 __STATIC_FORCEINLINE= __ALIGNED(x)=

# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
# tag can be used to specify a list of macro names that should be expanded. The
Expand Down
69 changes: 66 additions & 3 deletions dsppp/Include/dsppp/DSP/q15.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,46 @@
#if defined(ARM_MATH_DSP)
#if !defined(ARM_MATH_MVEI) && !defined(ARM_MATH_MVEF) && !defined(ARM_MATH_NEON)


/**
* @brief Representation of a vector when DSP extension supported
*/
struct Q15DSPVector {
/**
* @brief Create new 0 initialized vector
*/
Q15DSPVector():v(0){};

/**
* @brief Create vector initialized from value
*
* @param[in] val The value
*/
explicit Q15DSPVector(int32_t val):v(val){};

/**
* @brief Return value in vector
*/
operator int32_t(){return v;};

int32_t v;
};

/**
* @brief Vector description for Q15 with DSP extensions
*/
template<>
struct vector_traits<Q15,DSP,typename std::enable_if<true>::type>
{
//! Scalar datatype
typedef Q15 type;

//! Storage datatype
typedef type::value_type storage_type;

//! Vector datatype
typedef Q15DSPVector vector;

//! Accumulator datatype
typedef Q<33,30> temp_accumulator;

/*
Expand All @@ -48,30 +73,61 @@ struct vector_traits<Q15,DSP,typename std::enable_if<true>::type>
predicate but they are not called in this context.
*/
typedef uint32_t predicate_t;

/**
* Dummy type since there is no predicated loop for
* DSP extensions
*/
typedef uint32_t predicate_t;

//! Has some vector instructions
static constexpr bool has_vector = true;

//! Is not float
static constexpr bool is_float = false;

//! Is fixed point
static constexpr bool is_fixed = true;

//! No predicated loops
static constexpr bool has_predicate = false;

//! Number of lanes
static constexpr int nb_lanes = 2;

/**
* @brief Zero accumulator
*
* @return Zero accumulator
*/
static Q<33,30> temp_acc_zero()
{
return(Q<33,30>());
}

/**
* @brief Value to write in a lane to write 0
*
* @return Zero value for a lane
*/
static constexpr int16_t zero_lane() {return 0;};

/**
* @brief Convert to lane value
*
* @param[in] x Value
*
* @return Lane value
*/
static constexpr int16_t lane_value(const Q15 x) {return x.v;};


};



/**
* \ingroup DSPNumber
*/
namespace inner {

/* Needed to build but not used */
Expand All @@ -83,6 +139,13 @@ namespace inner {
};
};

/**
* @brief Vector const
*
* @param[in] val The value
*
* @return The static forceinline.
*/
__STATIC_FORCEINLINE Q15DSPVector vconst(Q15 val)
{
return(Q15DSPVector(__PKHBT(val.v, val.v, 16)));
Expand Down
93 changes: 92 additions & 1 deletion dsppp/Include/dsppp/Helium/basic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@
*/

#if defined(ARM_MATH_MVEI) || defined(ARM_MATH_MVEF)
/**
* @brief Fill evaluator for Helium
*
* @param v Destination value
* @param[in] val Initialization value
* @param[in] l Vector length
*
* @tparam T Scalar datatype
* @tparam DST Destination datatype
* @tparam <unnamed> Check if has vector indexing
*/
template<typename T,typename DST,
typename std::enable_if<has_vector_inst<DST>() &&
IsVector<DST>::value &&
Expand All @@ -36,6 +47,18 @@ inline void _Fill(DST &v,
}
}

/**
* @brief Fill2D evaluator for Helium
*
* @param v Destination value
* @param[in] val Initialization value
* @param[in] rows Number of rows
* @param[in] cols Number of columns
*
* @tparam T Scalar datatype
* @tparam DST Destination datatype
* @tparam <unnamed> Check only matrix indexing supported
*/
template<typename T,typename DST,
typename std::enable_if<has_vector_inst<DST>() &&
must_use_matrix_idx<DST>() &&
Expand Down Expand Up @@ -80,6 +103,17 @@ inline void _Fill2D(DST &v,
}
}

/**
* @brief Eval function for Helium
*
* @param v Destination
* @param[in] other Expression to evaluate
* @param[in] l Vector length
*
* @tparam DA Destination datatype
* @tparam DB Expression datatype
* @tparam <unnamed> Check vector indexing and compatible vectors
*/
template<typename DA,typename DB,
typename std::enable_if<has_vector_inst<DA>() &&
vector_idx_pair<DA,DB>(),bool>::type = true>
Expand All @@ -100,7 +134,18 @@ inline void eval(DA &v,
}
}


/**
* @brief Eval2D function for Helium
*
* @param v Destination vector
* @param[in] other Expression to evaluate
* @param[in] rows Number of rows
* @param[in] cols Number of columns
*
* @tparam DA Destination datatype
* @tparam DB Source datatype
* @tparam <unnamed> Check has only matrix indexing
*/
template<typename DA,typename DB,
typename std::enable_if<has_vector_inst<DA>() &&
must_use_matrix_idx_pair<DA,DB>(),bool>::type = true>
Expand Down Expand Up @@ -146,12 +191,27 @@ inline void eval2D(DA &v,
}


/**
* @brief Display the matrix content for debug purpose
* @param stream Output stream
* @param other The matrix to display
* @return the stream
*
*/
static std::ostream& operator<< (std::ostream& stream, const float32x4_t& other)
{
stream << "(" << other[0] << "," <<other[1] << "," <<other[2] << "," <<other[3] << ")";
return(stream);
}

/**
* @brief Print tuple for debug
*
* @param[in] _tup Tuple
*
* @tparam TupType Tuple datatype
* @tparam I List of tuple indexes
*/
template<class TupType, size_t... I>
void printt(const TupType& _tup, std::index_sequence<I...>)
{
Expand All @@ -160,12 +220,32 @@ void printt(const TupType& _tup, std::index_sequence<I...>)
std::cout << ")\n";
}

/**
* @brief Print tuple
*
* @param[in] _tup Tuple
*
* @tparam T Datatype for tuple elements
*/
template<class... T>
void printt (const std::tuple<T...>& _tup)
{
printt(_tup, std::make_index_sequence<sizeof...(T)>());
}

/**
* @brief Dor product for Helium
*
* @param[in] a First expression
* @param[in] b Second expression
* @param[in] l Vector length
*
* @tparam DA First operand datatype
* @tparam DB Second operand datatype
* @tparam <unnamed> Check vector indexing and compatible vectors
*
* @return Dot product of vector expressions
*/
template<typename DA,typename DB,
typename std::enable_if<has_vector_inst<DA>() &&
vector_idx_pair<DA,DB>(),bool>::type = true>
Expand Down Expand Up @@ -193,6 +273,17 @@ inline DotResult<DA> _dot(const DA& a,
return(inner::vreduce(acc));
}

/**
* @brief Swap operator for Helium
*
* @param a First opetand
* @param b Second operand
* @param[in] l Vector length
*
* @tparam DA First operand datatype
* @tparam DB Second operand datatype
* @tparam <unnamed> Check vector indexing and compatible vectors
*/
template<typename DA,typename DB,
typename std::enable_if<has_vector_inst<DA>() &&
vector_idx_pair<DA,DB>(),bool>::type = true>
Expand Down
Loading

0 comments on commit 0732932

Please sign in to comment.