DSPLIB User Guide
DSPLIB_utility.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (C) 2023 Texas Instruments Incorporated - https://www.ti.com/
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the
14  * distribution.
15  *
16  * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  ******************************************************************************/
33 
34 #ifndef COMMON_DSPLIB_UTILITY_H_
35 #define COMMON_DSPLIB_UTILITY_H_ 1
36 
37 /*******************************************************************************
38  *
39  * INCLUDES
40  *
41  ******************************************************************************/
42 
43 #include <float.h> // for max float, double values
44 #include <limits.h> // for min, max integer values
45 #include <math.h>
46 
47 #include "DSPLIB_bufParams.h"
48 #include "DSPLIB_types.h"
49 
50 /*******************************************************************************
51  *
52  * EXTERNAL VARIABLES
53  *
54  ******************************************************************************/
55 #ifdef __cplusplus
56 extern "C" {
57 #endif /* __cplusplus */
58 extern uint64_t beg_count; /* Begin cycle count for profiling */
59 extern uint64_t end_count; /* End cycle count for profiling */
60 extern uint64_t overhead; /* Cycle profiling overhead */
61 #ifdef __cplusplus
62 }
63 #endif /* __cplusplus */
64 
65 /*******************************************************************************
66  *
67  * Definition and arithmetic for DSPLIB_int128_t class
68  *
69  ******************************************************************************/
70 
71 // Define a 128-bit integer class to allow natural-c implementations of DSPLIB
72 // 32-bit input/output functions to be templated. The class is implemented in
73 // a header file for easy sharing. All member functions, including constructors
74 // are declared inline for two reasons: (1) performance and (2) necessary for
75 // implementing the class in a multiple-inclusion header file.
76 
78  public:
79  int64_t hi;
80  int64_t lo;
81  DSPLIB_int128_t(int64_t h,
82  int64_t l); // constructor for both high and low specified
83  DSPLIB_int128_t(int64_t l); // constructor for just low specified (sign extends to high)
84  DSPLIB_int128_t(); // constructor for neither field specified
85  DSPLIB_int128_t operator+(const DSPLIB_int128_t &) const; // operator +
86  DSPLIB_int128_t operator>>(const int8_t &) const; // operator >>
87 };
88 
89 // define constructor
90 inline DSPLIB_int128_t::DSPLIB_int128_t(int64_t h, int64_t l)
91 {
92  hi = h;
93  lo = l;
94 }
95 
96 // define constructor
98 {
99  // sign extend l
100  hi = (((uint64_t) l & 0x8000000000000000ULL) != 0LL) ? (int64_t) 0xffffffffffffffffULL
101  : (int64_t) 0x0000000000000000ULL;
102  lo = l;
103 }
104 
105 // define constructor
107 {
108  hi = 0x0000000000000000LL;
109  lo = 0x0000000000000000LL;
110 }
111 
112 #endif
uint64_t end_count
uint64_t overhead
uint64_t beg_count
DSPLIB_int128_t operator>>(const int8_t &) const
DSPLIB_int128_t operator+(const DSPLIB_int128_t &) const