1 // -*- C++ -*-
2 /** @file */
3 #pragma once
4 
5 /** \addtogroup GenericNumber
6  *  \ingroup NUMBER
7  *  @{
8  *  \addtogroup GenericQ7Number Q7
9  *  \ingroup GenericNumber
10  *  @{
11  */
12 
13 /**
14  * @brief      Q7 features
15  */
16 template<>
17 struct number_traits<Q7>
18 {
19    //! Is not float
20    static constexpr bool is_float = false;
21 
22    //! Is fixed point
23    static constexpr bool is_fixed = true;
24 
25    //! Accumulator datatype
26    typedef Q<17,14> accumulator;
27 
28    /**
29     * @brief      One value
30     *
31     * @return     One value in Q7
32     */
onenumber_traits33    static constexpr Q7 one() {return Q7::one();};
34 
35 
36    //! Compute type
37    typedef Q7 compute_type;
38 };
39 
40 /**
41  * @brief      Vector descrition when no vector architecture
42  *
43  * @tparam     arch  Current architecture
44  */
45 template<typename arch>
46 struct vector_traits<Q7,arch,
47     typename std::enable_if<!std::is_base_of<Helium,arch>::value &&
48                             !std::is_base_of<Neon,arch>::value &&
49                             !std::is_base_of<DSP,arch>::value>::type> {
50   //! Current datatype
51   typedef Q7 type;
52 
53   //! Storage datatype (int8_t)
54   typedef type::value_type storage_type;
55 
56   // No vector type but must still be defined
57   //! Dummy datatype when no vector instructions
58   typedef bool vector;
59   //! Dummy datatype when no vector instructions
60   typedef bool temp_accumulator;
61   //! Dummy datatype when no vector instructions
62   typedef uint32_t predicate_t;
63 
64 
65   //! No vector instructions
66   static constexpr bool has_vector = false;
67   //! Is not float
68   static constexpr bool is_float = false;
69   //! Is fixed point
70   static constexpr bool is_fixed = true;
71   //! No predicated loop
72   static constexpr bool has_predicate = false;
73 };
74 
75 /**
76  * Inner implementation of generic intrinsics
77  * \ingroup GenericNumber
78  */
79 namespace inner {
80     /**
81      * @brief      Convert from accumulator with saturation
82      *
83      * @param[in]  a     Accumulator value
84      *
85      * @return     Q7 value
86      */
from_accumulator(const Q<17,14> a)87     __STATIC_FORCEINLINE Q7 from_accumulator(const Q<17,14> a)
88     {
89         return(Q7(__SSAT(a.v >> 7, 8)));
90     };
91 
92 /**
93  * @brief      Multiply and accumulate
94  *
95  * @param[in]  acc   Accumulator
96  * @param[in]  a     First operand
97  * @param[in]  b     Second operand
98  *
99  * @return     acc + a*b
100  */
mac(const Q<17,14> acc,const Q7 a,const Q7 b)101     __STATIC_FORCEINLINE Q<17,14> mac(const Q<17,14> acc,const Q7 a,const Q7 b)
102     {
103       return(accumulate(acc , mult(a,b)));
104     };
105 }
106 
107 /*! @} */
108 /*! @} */