1 // -*- C++ -*-
2 /** @file */
3 #pragma once
4 
5 /** \addtogroup GenericNumber
6  *  \ingroup NUMBER
7  *  @{
8  *  \addtogroup GenericFloatNumber Float
9  *  \ingroup GenericNumber
10  *  @{
11  */
12 
13 /**
14  * @brief      Features for float
15  */
16 template<>
17 struct number_traits<float>
18 {
19    //! It is a float number
20    static constexpr bool is_float = true;
21 
22    //! It is not a fixed point
23    static constexpr bool is_fixed = false;
24 
25    //! Accumulator datatype for this scalar datatype
26    typedef float accumulator;
27 
28   /**
29     * @brief      One for this datatype
30     *
31     * @return     Return 1 representation for this datatype
32     */
onenumber_traits33    static constexpr float one() {return 1.0f;};
34 
35    //! Compute datatype for this scalar datatype
36    typedef float compute_type;
37 };
38 
39 
40 /*
41 
42 If arch is not deriving from Neon or Helium, then there are
43 no vectors for float
44 
45 */
46 
47 /**
48  * @brief      Vector instructions for float when no Helium or Neon
49  *
50  * @tparam     arch  Current architecture
51  */
52 template<typename arch>
53 struct vector_traits<float,arch,
54     typename std::enable_if<!std::is_base_of<Helium,arch>::value &&
55                             !std::is_base_of<Neon,arch>::value>::type> {
56 
57   //! Current type
58   typedef float type;
59 
60   //! Current storage type
61   typedef float storage_type;
62 
63   // No vector type but must still be defined
64 
65   //! Dummy type. Not used when no vector instructions
66   typedef bool vector;
67   //! Dummy type. Not used when no vector instructions
68   typedef bool temp_accumulator;
69   //! Dummy type. Not used when no vector instructions
70   typedef uint32_t predicate_t;
71 
72 
73   //! No vector instructions for this datatype
74   static constexpr bool has_vector = false;
75   //! Is float
76   static constexpr bool is_float = true;
77   //! Is fixed
78   static constexpr bool is_fixed = false;
79 
80   //! No predicated loop
81   static constexpr bool has_predicate = false;
82 
83 };
84 
85 /**
86  * Inner implementation of generic intrinsics
87  * \ingroup GenericNumber
88  */
89 namespace inner {
90    /**
91     * @brief      Convert from accumulator representtaion
92     *
93     * @param[in]  a     Value
94     *
95     * @return     Accumulator value converted to current datatype
96     */
from_accumulator(const float a)97   __STATIC_FORCEINLINE float from_accumulator(const float a)
98   {
99      return(a);
100   };
101 
102 /**
103  * @brief      Scalar multiply and accumulate
104  *
105  * @param[in]  acc   Accumulator
106  * @param[in]  a     Operand
107  * @param[in]  b     Operand
108  *
109  * @return     acc + a*b
110  */
mac(const float acc,const float a,const float b)111   __STATIC_FORCEINLINE float mac(const float acc,const float a,const float b)
112   {
113      return(acc+a*b);
114   };
115 
116 /**
117  * @brief      Scalar accumulate
118  *
119  * @param      a     Accumulator
120  * @param[in]  b     Operand
121  */
accumulate(float & a,const float & b)122 __STATIC_FORCEINLINE void accumulate(float &a,const float &b)
123 {
124    a += b;
125 }
126 
127 /**
128  * @brief      Scalar multiply
129  *
130  * @param      a     Operand
131  * @param[in]  b     Operand
132  *
133  * @return     a*b
134  */
mult(float & a,const float & b)135 __STATIC_FORCEINLINE float mult(float &a,const float &b)
136 {
137    return(a*b);
138 }
139 
140 }
141 
142 
143 /*! @} */
144 /*! @} */
145 
146 
147