Commit 0732932f authored by Christophe Favergeon's avatar Christophe Favergeon
Browse files

Improved C++ documentation (inner operators)

parent 5cb08580
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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
+66 −3
Original line number Diff line number Diff line
@@ -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;

  /*
@@ -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 */
@@ -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)));
+92 −1
Original line number Diff line number Diff line
@@ -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 &&
@@ -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>() &&
@@ -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>
@@ -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>
@@ -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...>)
{
@@ -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>
@@ -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>
+452 −8

File changed.

Preview size limit exceeded, changes collapsed.

+132 −0
Original line number Diff line number Diff line
@@ -17,39 +17,88 @@
 */

#if defined(ARM_MATH_MVE_FLOAT16)

/**
 * @brief      Vector features for f16 on Helium
 *
 * @tparam     arch  Current architecture
 */
template<typename arch>
struct vector_traits<float16_t,arch,typename std::enable_if<std::is_base_of<Helium,arch>::value>::type> 
{
  //! Scalar datatype
  typedef float16_t type;
  //! Storage datatype
  typedef float16_t storage_type;
  //! Vector datatype
  typedef float16x8_t vector;
  //! Temp accumulator datatype
  typedef float16x8_t temp_accumulator;
  //! Predicate datatype
  typedef mve_pred16_t predicate_t;

  //! Has vector instructions
  static constexpr bool has_vector = true;
  //! Is float
  static constexpr bool is_float = true;
  //! Is not fixed point
  static constexpr bool is_fixed = false;
  //! Has predicated loop
  static constexpr bool has_predicate = true;

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

  /**
   * @brief      Vector of 0
   *
   * @return     Vector of 0
   */
  static float16x8_t temp_acc_zero()
  {
     return(vdupq_n_f16(0.0f));
  }

  /**
   * @brief      Value to write 0 in a lane
   *
   * @return     Value to write 0 in a lane
   * 
   * f16 suffix not supported in C++ 
   */
  static constexpr float16_t zero_lane() {return 0.0f;};
  // Useful in fixed point since lane value is an int and not a Q something

  /**
   * @brief      Convert from lane value
   *
   * @param[in]  x     Lane value
   *
   * @return     Lane value with current datatype
   */
  static constexpr float16_t lane_value(const float16_t x) {return x;};

};


/**
 * \ingroup HeliumNumber
 */
namespace inner {


   /**
    * @brief      vctpq for Helium and f16
    */
   template<>
   struct vctpq<float16_t>{
       /**
        * @brief      Make predicate
        *
        * @param[in]  v     Remaining iterations
        *
        * @return     Predicate
        */
       static mve_pred16_t mk(uint32_t v)
       
       {
@@ -57,22 +106,52 @@ namespace inner {
       };
   };
   
   /**
    * @brief      Vector const
    *
    * @param[in]  v     Initialization value
    *
    * @return     Vector of const
    */
   __STATIC_FORCEINLINE float16x8_t vconst(float16_t v)
   {
      return(vdupq_n_f16(v));
   }

   /**
    * @brief      Vector of const with tail predicate
    *
    * @param[in]  v     The initialization parameter
    * @param[in]  p0    The predicate
    *
    * @return     The initialized vector with const and predicate
    */
   __STATIC_FORCEINLINE float16x8_t vconst_tail(const float16_t v,
                                                const mve_pred16_t p0)
  {
     return(vdupq_x_n_f16(v,p0));
  }

  /**
   * @brief      Vector negate
   *
   * @param[in]  a     Vector
   *
   * @return     Negate of vector
   */
   __STATIC_FORCEINLINE float16x8_t vneg(const float16x8_t a)
  {
     return(vnegq(a));
  };

  /**
   * @brief      Vector negate with tail predicate
   *
   * @param[in]  a     Vector
   * @param[in]  p0    Predicate
   *
   * @return     Negate of vector with tail predicate
   */
  __STATIC_FORCEINLINE float16x8_t vneg(const float16x8_t a,
                                        const mve_pred16_t p0)
  {
@@ -85,24 +164,57 @@ namespace inner {

   */

   /**
    * @brief      Vector + Vector
    *
    * @param[in]  a     Vector
    * @param[in]  b     Vector
    *
    * @return     a + b
    */
   __STATIC_FORCEINLINE float16x8_t vadd(const float16x8_t a,
                                         const float16x8_t b)
   {
      return(vaddq(a,b));
   };

   /**
    * @brief      Vector + Scalar
    *
    * @param[in]  a     Vector
    * @param[in]  b     Scalar
    *
    * @return     a + b
    */
   __STATIC_FORCEINLINE float16x8_t vadd(const float16x8_t a,
                                         const float16_t b)
   {
      return(vaddq_n_f16(a,b));
   };

   /**
    * @brief      Scalar + Vector
    *
    * @param[in]  a     Scalar
    * @param[in]  b     Vector
    *
    * @return     a + b
    */
   __STATIC_FORCEINLINE float16x8_t vadd(const float16_t a,
                                         const float16x8_t b)
   {
      return(vaddq_n_f16(b,a));
   };

   /**
    * @brief      Vector + Vector with tail predicate 
    *
    * @param[in]  a     Vector
    * @param[in]  b     Vector
    * @param[in]  p0    predicate
    *
    * @return     a + b with tail predicate
    */
   __STATIC_FORCEINLINE float16x8_t vadd(const float16x8_t a,
                                         const float16x8_t b,
                                         const mve_pred16_t p0)
@@ -110,6 +222,15 @@ namespace inner {
     return(vaddq_x(a,b,p0));
   };

   /**
    * @brief      Vector + Scalar with tail predicate
    *
    * @param[in]  a     Vector
    * @param[in]  b     Scalar
    * @param[in]  p0    Predicate
    *
    * @return     a + b with tail predicate
    */
   __STATIC_FORCEINLINE float16x8_t vadd(const float16x8_t a,
                                         const float16_t b,
                                         const mve_pred16_t p0)
@@ -117,6 +238,15 @@ namespace inner {
     return(vaddq_x_n_f16(a,b,p0));
   };

   /**
    * @brief      Scalar + Vector with tail predicate
    *
    * @param[in]  a     Scalar
    * @param[in]  b     Vector
    * @param[in]  p0    Predicate
    *
    * @return     a + b with tail predicate
    */
   __STATIC_FORCEINLINE float16x8_t vadd(const float16_t a,
                                         const float16x8_t b,
                                         const mve_pred16_t p0)
@@ -512,8 +642,10 @@ namespace inner {
       }
    };


}


#endif

/*! @} */
Loading