1 // -*- C++ -*-
2 /** @file */
3 #pragma once
4 
5 #ifdef DOXYGEN
6 #define ARM_FLOAT16_SUPPORTED
7 #endif
8 
9 /** \addtogroup GenericNumber
10  *  \ingroup NUMBER
11  *  @{
12  *  \addtogroup GenericHalfNumber Half
13  *  \ingroup GenericNumber
14  *  @{
15  */
16 
17 #if defined(ARM_FLOAT16_SUPPORTED)
18 
19 /**
20  * @brief      Feature of float16 datatype
21  */
22 template<>
23 struct number_traits<float16_t>
24 {
25    //! It is a float number
26    static constexpr bool is_float = true;
27    //! It is not a fixed point number
28    static constexpr bool is_fixed = false;
29    //! Accumulator datatype
30    typedef float16_t accumulator;
31 
32    /**
33     * @brief      One value
34     *
35     * @return     One value in f16
36     */
onenumber_traits37    static constexpr float16_t one() {return  ((float16_t)1.0f);};
38 
39    //! Compute datatype
40    typedef _Float16 compute_type;
41 };
42 
43 
44 #if !defined(ARM_MATH_MVE_FLOAT16)
45 /**
46  * @brief      float16 vector descrition when no vector architecture
47  */
48 template<>
49 struct vector_traits<float16_t> {
50   //! Float16 datatype
51   typedef float16_t type;
52   //! Float16 storage type
53   typedef float16_t storage_type;
54 
55   // No vector type but must still be defined
56   //! Dummy type when no vector instruction is supported
57   typedef bool vector;
58   //! Dummy type when no vector instruction is supported
59   typedef bool temp_accumulator;
60   //! Dummy type when no vector instruction is supported
61   typedef uint32_t predicate_t;
62 
63   //! No vector instruction
64   static constexpr bool has_vector = false;
65   //! Is float
66   static constexpr bool is_float = true;
67   //! Not fixed point
68   static constexpr bool is_fixed = false;
69   //! Has predicated loop
70   static constexpr bool has_predicate = false;
71 };
72 #endif
73 
74 /**
75  * Inner implementation of generic intrinsics
76  * \ingroup GenericNumber
77  */
78 namespace inner {
79    /**
80     * @brief      Convert from accumulator datatype
81     *
82     * @param[in]  a     Value
83     *
84     * @return     Converted from accumulator datatype
85     */
from_accumulator(const float16_t a)86    __STATIC_FORCEINLINE float16_t from_accumulator(const float16_t a)
87    {
88      return(a);
89    };
90 
91 /**
92  * @brief      Multiply and accumulate
93  *
94  * @param[in]  acc   Accumulator
95  * @param[in]  a     First operand
96  * @param[in]  b     Second operand
97  *
98  * @return     acc + a*b
99  */
mac(const float16_t acc,const float16_t a,const float16_t b)100   __STATIC_FORCEINLINE float16_t mac(const float16_t acc,const float16_t a,const float16_t b)
101   {
102      return((_Float16)acc+(_Float16)a*(_Float16)b);
103   };
104 
105 
106 /**
107  * @brief      Accumulate
108  *
109  * @param      a     Accumulator
110  * @param[in]  b     Value to accumulate
111  */
accumulate(float16_t & a,const float16_t & b)112 __STATIC_FORCEINLINE void accumulate(float16_t &a,const float16_t &b)
113 {
114    a += (_Float16)b;
115 }
116 
117 /**
118  * @brief      Multiply
119  *
120  * @param      a     First operand
121  * @param[in]  b     Second operand
122  *
123  * @return     a*b
124  */
mult(float16_t & a,const float16_t & b)125 __STATIC_FORCEINLINE float16_t mult(float16_t &a,const float16_t &b)
126 {
127    return((_Float16)a*(_Float16)b);
128 }
129 
130 }
131 
132 #endif
133 
134 /*! @} */
135 /*! @} */