LIBML  Version 3.2.4
LIBML DSP Software Library
Data Structures | Macros | Typedefs | Enumerations | Functions
tpt_math.h File Reference
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include <limits.h>
#include <math.h>
#include <assert.h>
#include "cosine_values.h"
#include "tpt_math_f16.h"
#include "tpt_math_fast.h"
#include "tpt_math_vector.h"
#include "tpt_math_support.h"
#include "tpt_math_complex.h"
#include "tpt_math_matrix.h"
#include "tpt_math_transform.h"
#include "tpt_math_filter.h"
#include "tpt_math_controller.h"
#include "tpt_math_statistics.h"
#include "tpt_math_svm.h"
#include "tpt_math_distance.h"
#include "tpt_internals.h"
#include "tpt_math_config.h"
Include dependency graph for tpt_math.h:

Data Structures

struct  tpt_linear_interpolate_f32_s
 Instance structure for the floating-point Linear Interpolate function. More...
 
struct  tpt_bilinear_interpolate_f32_s
 Instance structure for the floating-point bilinear interpolation function. More...
 
struct  tpt_bilinear_interpolate_q7_s
 Instance structure for the Q7 bilinear interpolation function. More...
 
struct  tpt_bilinear_interpolate_q15_s
 Instance structure for the Q15 bilinear interpolation function. More...
 
struct  tpt_bilinear_interpolate_q31_s
 Instance structure for the Q31 bilinear interpolation function. More...
 

Macros

#define __FORCEINLINE   __attribute__((always_inline)) inline
 
#define LIKELY(EXPR)   (EXPR)
 
#define UNLIKELY(EXPR)   (EXPR)
 
#define SWAP(x, y, T)
 
#define SQUARE(val)   val * val
 
#define OPT_BRANCH_PREDICTION   1
 
#define OPT_HIGHLY_ACCURATE   0
 
#define TPT_MATH_LOOPUNROLL   8
 
#define Q63_MAX   (q63_t)0x7FFFFFFFFFFFFFFFLL
 
#define Q63_MIN   (q63_t)0x8000000000000000LL
 
#define Q31_MAX   (q31_t)0x7FFFFFFF
 
#define Q31_MIN   (q31_t)0x80000000
 
#define Q15_MAX   (q15_t)0x7FFF
 
#define Q15_MIN   (q15_t)0x8000
 
#define Q7_MAX   (q7_t)0x7F
 
#define Q7_MIN   (q7_t)0x80
 
#define ABS(val, bit)    (val > 0) ? val : ((val == Q##bit##_MIN) ? Q##bit##_MAX : -val)
 
#define CLIP(val, bit)    ((val) > UINT##bit##_MAX) ? UINT##bit##_MAX : ((val) < 0 ? 0U : (val))
 
#define CLIPS(val, bit)
 
#define SCALE_COL_T(T, A, ROW, v, i, aRows, aCols)
 
#define SCALE_COL_F32(A, ROW, v, i, aRows, aCols)    SCALE_COL_T(f32_t, A, ROW, v, i, aRows, aCols)
 
#define SCALE_COL_F64(A, ROW, v, i, aRows, aCols)    SCALE_COL_T(f64_t, A, ROW, v, i, aRows, aCols)
 
#define F32_TO_Q7(val)   (q7_t)((fminf(fmaxf(val, -1.0f), 1.0f)) * (1LL << 7))
 Convert F32 to Q7 format This will use saturating arithmetic. More...
 
#define F32_TO_Q15(val)   (q15_t)((fminf(fmaxf(val, -1.0f), 1.0f)) * (1LL << 15))
 Convert F32 to Q15 format This will use saturating arithmetic. More...
 
#define F32_TO_Q31(val)   (q31_t)((fminf(fmaxf(val, -1.0f), 1.0f)) * (1LL << 31))
 Convert F32 to Q31 format This will use saturating arithmetic. More...
 
#define Q7_TO_F32(val)   ((val) * 7.81250000e-03F)
 Convert Q7 to F32 format. More...
 
#define Q15_TO_F32(val)   ((val) * 3.05175781e-05F)
 Convert Q15 to F32 format. More...
 
#define Q31_TO_F32(val)   ((val) * 4.65661287e-10F)
 Convert Q31 to F32 format. More...
 
#define F64_TO_Q7(val)   (q7_t)((fmin(fmax(val, -1.0f), 1.0)) * (1LL << 7))
 Convert F64 to Q7 format This will use saturating arithmetic. More...
 
#define F64_TO_Q15(val)   (q15_t)((fmin(fmax(val, -1.0f), 1.0)) * (1LL << 15))
 Convert F64 to Q15 format This will use saturating arithmetic. More...
 
#define F64_TO_Q31(val)   (q31_t)((fmin(fmax(val, -1.0), 1.0)) * (1LL << 31))
 Convert F64 to Q31 format This will use saturating arithmetic. More...
 
#define Q7_TO_F64(val)   ((val) * 7.812500000000000000e-03)
 Convert Q7 to F64 format. More...
 
#define Q15_TO_F64(val)   ((val) * 3.051757812500000000e-05)
 Convert Q15 to F64 format. More...
 
#define Q31_TO_F64(val)   ((val) * 4.656612873077392578e-10)
 Convert Q31 to F64 format. More...
 

Typedefs

typedef long double f128_t
 128-bit floating-point type definition. More...
 
typedef double f64_t
 64-bit floating-point type definition. More...
 
typedef float f32_t
 32-bit floating-point type definition. More...
 
typedef int64_t q63_t
 64-bit fractional data type in 1.63 format. More...
 
typedef int32_t q31_t
 32-bit fractional data type in 1.31 format. More...
 
typedef int16_t q15_t
 16-bit fractional data type in 1.15 format. More...
 
typedef int8_t q7_t
 8-bit fractional data type in 1.7 format. More...
 
typedef int16_t q1_14_t
 16-bit fractional data type in 2.14 format. More...
 
typedef int16_t q2_13_t
 16-bit fractional data type in 3.13 format. More...
 
typedef int16_t q3_12_t
 16-bit fractional data type in 4.12 format. More...
 
typedef int16_t q4_11_t
 16-bit fractional data type in 5.11 format. More...
 
typedef int16_t q5_10_t
 16-bit fractional data type in 6.10 format. More...
 
typedef int16_t q6_9_t
 16-bit fractional data type in 7.9 format. More...
 
typedef int32_t q1_30_t
 32-bit fractional data type in 2.30 format. More...
 
typedef int32_t q2_29_t
 32-bit fractional data type in 3.29 format. More...
 
typedef int32_t q3_28_t
 32-bit fractional data type in 4.28 format. More...
 
typedef int32_t q4_27_t
 32-bit fractional data type in 5.27 format. More...
 
typedef int32_t q5_26_t
 32-bit fractional data type in 6.26 format. More...
 
typedef int32_t q6_25_t
 32-bit fractional data type in 7.25 format. More...
 
typedef int32_t q7_24_t
 32-bit fractional data type in 8.24 format. More...
 
typedef int32_t q17_14_t
 32-bit fractional data type in 18.14 format. More...
 
typedef int64_t q1_62_t
 64-bit fractional data type in 2.62 format. More...
 
typedef int64_t q15_48_t
 64-bit fractional data type in 16.48 format. More...
 
typedef int64_t q33_30_t
 64-bit fractional data type in 34.30 format. More...
 
typedef enum tpt_status_e tpt_status
 Error status returned by some functions in the library. More...
 
typedef struct tpt_linear_interpolate_f32_s tpt_linear_interpolate_f32_t
 Instance structure for the floating-point Linear Interpolate function. More...
 
typedef struct tpt_bilinear_interpolate_f32_s tpt_bilinear_interpolate_f32_t
 Instance structure for the floating-point bilinear interpolation function. More...
 
typedef struct tpt_bilinear_interpolate_q7_s tpt_bilinear_interpolate_q7_t
 Instance structure for the Q7 bilinear interpolation function. More...
 
typedef struct tpt_bilinear_interpolate_q15_s tpt_bilinear_interpolate_q15_t
 Instance structure for the Q15 bilinear interpolation function. More...
 
typedef struct tpt_bilinear_interpolate_q31_s tpt_bilinear_interpolate_q31_t
 Instance structure for the Q31 bilinear interpolation function. More...
 

Enumerations

enum  tpt_status_e { TPT_MATH_SUCCESS = 0 , TPT_MATH_ARGUMENT_ERROR = -1 , TPT_MATH_SINGULAR = -5 , TPT_MATH_DECOMPOSITION_FAILURE = -7 }
 Error status returned by some functions in the library. More...
 

Functions

static q7_t clip_q63_to_q7 (q63_t x)
 Clips Q63 to Q7 values. More...
 
static q15_t clip_q63_to_q15 (q63_t x)
 Clips Q63 to Q15 values. More...
 
static q31_t clip_q63_to_q31 (q63_t x)
 Clips Q63 to Q31 values. More...
 
static q7_t clip_q31_to_q7 (q31_t x)
 Clips Q31 to Q7 values. More...
 
static q15_t clip_q31_to_q15 (q31_t x)
 Clips Q31 to Q15 values. More...
 
static q7_t clip_q15_to_q7 (q15_t x)
 Clips Q15 to Q7 values. More...
 
static int32_t __SSAT (int32_t aValue, uint32_t aBits)
 
static uint32_t __USAT (int32_t aValue, uint32_t aBits)
 
static uint8_t __CLZ (uint32_t aData)
 
static uint8_t __CLZ32 (uint32_t aData)
 
static q63_t mult32x64 (q63_t x, q31_t y)
 Multiplies 32 X 64 and returns 32 bit result in 2.30 format. More...
 
static q31_t mult32x32_keep32 (q31_t acc, q31_t x, q31_t y)
 Multiplies 32 X 32 and returns 32 bit result in 1.31 format. More...
 
static f32_t tpt_linear_interpolate_f32 (tpt_linear_interpolate_f32_t *aFunction, f32_t aX)
 Process function for the floating-point Linear Interpolation Function. More...
 
static q31_t tpt_linear_interpolate_q31 (q31_t *pYData, q31_t aX, uint32_t nValues)
 Process function for the Q31 Linear Interpolation Function. More...
 
static q15_t tpt_linear_interpolate_q15 (q15_t *pYData, q31_t aX, uint32_t nValues)
 Process function for the Q15 Linear Interpolation Function. More...
 
static q7_t tpt_linear_interpolate_q7 (q7_t *pYData, q31_t aX, uint32_t nValues)
 Process function for the Q7 Linear Interpolation Function. More...
 
static f32_t tpt_bilinear_interpolate_f32 (const tpt_bilinear_interpolate_f32_t *aFunction, f32_t aX, f32_t aY)
 Floating-point bilinear interpolation. More...
 
static q31_t tpt_bilinear_interpolate_q31 (tpt_bilinear_interpolate_q31_t *aFunction, q31_t aX, q31_t aY)
 Q31 bilinear interpolation. More...
 
static q15_t tpt_bilinear_interpolate_q15 (tpt_bilinear_interpolate_q15_t *aFunction, q31_t aX, q31_t aY)
 Q15 bilinear interpolation. More...
 
static q7_t tpt_bilinear_interpolate_q7 (tpt_bilinear_interpolate_q7_t *aFunction, q31_t aX, q31_t aY)
 Q7 bilinear interpolation. More...
 

Macro Definition Documentation

◆ __FORCEINLINE

#define __FORCEINLINE   __attribute__((always_inline)) inline

◆ ABS

#define ABS (   val,
  bit 
)     (val > 0) ? val : ((val == Q##bit##_MIN) ? Q##bit##_MAX : -val)

◆ CLIP

#define CLIP (   val,
  bit 
)     ((val) > UINT##bit##_MAX) ? UINT##bit##_MAX : ((val) < 0 ? 0U : (val))

◆ CLIPS

#define CLIPS (   val,
  bit 
)
Value:
((val) < Q##bit##_MIN) ? Q##bit##_MIN \
: ((val) > Q##bit##_MAX) ? Q##bit##_MAX \
: (val)

◆ F32_TO_Q15

#define F32_TO_Q15 (   val)    (q15_t)((fminf(fmaxf(val, -1.0f), 1.0f)) * (1LL << 15))

Convert F32 to Q15 format This will use saturating arithmetic.

◆ F32_TO_Q31

#define F32_TO_Q31 (   val)    (q31_t)((fminf(fmaxf(val, -1.0f), 1.0f)) * (1LL << 31))

Convert F32 to Q31 format This will use saturating arithmetic.

◆ F32_TO_Q7

#define F32_TO_Q7 (   val)    (q7_t)((fminf(fmaxf(val, -1.0f), 1.0f)) * (1LL << 7))

Convert F32 to Q7 format This will use saturating arithmetic.

◆ F64_TO_Q15

#define F64_TO_Q15 (   val)    (q15_t)((fmin(fmax(val, -1.0f), 1.0)) * (1LL << 15))

Convert F64 to Q15 format This will use saturating arithmetic.

◆ F64_TO_Q31

#define F64_TO_Q31 (   val)    (q31_t)((fmin(fmax(val, -1.0), 1.0)) * (1LL << 31))

Convert F64 to Q31 format This will use saturating arithmetic.

◆ F64_TO_Q7

#define F64_TO_Q7 (   val)    (q7_t)((fmin(fmax(val, -1.0f), 1.0)) * (1LL << 7))

Convert F64 to Q7 format This will use saturating arithmetic.

◆ LIKELY

#define LIKELY (   EXPR)    (EXPR)

◆ OPT_BRANCH_PREDICTION

#define OPT_BRANCH_PREDICTION   1

◆ OPT_HIGHLY_ACCURATE

#define OPT_HIGHLY_ACCURATE   0

◆ Q15_MAX

#define Q15_MAX   (q15_t)0x7FFF

◆ Q15_MIN

#define Q15_MIN   (q15_t)0x8000

◆ Q15_TO_F32

#define Q15_TO_F32 (   val)    ((val) * 3.05175781e-05F)

Convert Q15 to F32 format.

◆ Q15_TO_F64

#define Q15_TO_F64 (   val)    ((val) * 3.051757812500000000e-05)

Convert Q15 to F64 format.

◆ Q31_MAX

#define Q31_MAX   (q31_t)0x7FFFFFFF

◆ Q31_MIN

#define Q31_MIN   (q31_t)0x80000000

◆ Q31_TO_F32

#define Q31_TO_F32 (   val)    ((val) * 4.65661287e-10F)

Convert Q31 to F32 format.

◆ Q31_TO_F64

#define Q31_TO_F64 (   val)    ((val) * 4.656612873077392578e-10)

Convert Q31 to F64 format.

◆ Q63_MAX

#define Q63_MAX   (q63_t)0x7FFFFFFFFFFFFFFFLL

◆ Q63_MIN

#define Q63_MIN   (q63_t)0x8000000000000000LL

◆ Q7_MAX

#define Q7_MAX   (q7_t)0x7F

◆ Q7_MIN

#define Q7_MIN   (q7_t)0x80

◆ Q7_TO_F32

#define Q7_TO_F32 (   val)    ((val) * 7.81250000e-03F)

Convert Q7 to F32 format.

◆ Q7_TO_F64

#define Q7_TO_F64 (   val)    ((val) * 7.812500000000000000e-03)

Convert Q7 to F64 format.

◆ SCALE_COL_F32

#define SCALE_COL_F32 (   A,
  ROW,
  v,
  i,
  aRows,
  aCols 
)     SCALE_COL_T(f32_t, A, ROW, v, i, aRows, aCols)

◆ SCALE_COL_F64

#define SCALE_COL_F64 (   A,
  ROW,
  v,
  i,
  aRows,
  aCols 
)     SCALE_COL_T(f64_t, A, ROW, v, i, aRows, aCols)

◆ SCALE_COL_T

#define SCALE_COL_T (   T,
  A,
  ROW,
  v,
  i,
  aRows,
  aCols 
)
Value:
{ \
int32_t _w; \
T* data = A; \
const int32_t _numCols = aCols; \
const int32_t nb = aRows - ROW; \
\
data += i + _numCols * (ROW); \
\
for (_w = 0; _w < nb; _w++) \
{ \
*data *= v; \
data += _numCols; \
} \
}
#define A
Definition: tpt_pow_f32.c:86

◆ SQUARE

#define SQUARE (   val)    val * val

◆ SWAP

#define SWAP (   x,
  y,
  T 
)
Value:
do \
{ \
T tmp = x; \
\
x = y; \
y = tmp; \
} while (0)

◆ TPT_MATH_LOOPUNROLL

#define TPT_MATH_LOOPUNROLL   8

◆ UNLIKELY

#define UNLIKELY (   EXPR)    (EXPR)

Typedef Documentation

◆ f128_t

typedef long double f128_t

128-bit floating-point type definition.

◆ f32_t

typedef float f32_t

32-bit floating-point type definition.

◆ f64_t

typedef double f64_t

64-bit floating-point type definition.

◆ q15_48_t

typedef int64_t q15_48_t

64-bit fractional data type in 16.48 format.

◆ q15_t

typedef int16_t q15_t

16-bit fractional data type in 1.15 format.

◆ q17_14_t

typedef int32_t q17_14_t

32-bit fractional data type in 18.14 format.

◆ q1_14_t

typedef int16_t q1_14_t

16-bit fractional data type in 2.14 format.

◆ q1_30_t

typedef int32_t q1_30_t

32-bit fractional data type in 2.30 format.

◆ q1_62_t

typedef int64_t q1_62_t

64-bit fractional data type in 2.62 format.

◆ q2_13_t

typedef int16_t q2_13_t

16-bit fractional data type in 3.13 format.

◆ q2_29_t

typedef int32_t q2_29_t

32-bit fractional data type in 3.29 format.

◆ q31_t

typedef int32_t q31_t

32-bit fractional data type in 1.31 format.

◆ q33_30_t

typedef int64_t q33_30_t

64-bit fractional data type in 34.30 format.

◆ q3_12_t

typedef int16_t q3_12_t

16-bit fractional data type in 4.12 format.

◆ q3_28_t

typedef int32_t q3_28_t

32-bit fractional data type in 4.28 format.

◆ q4_11_t

typedef int16_t q4_11_t

16-bit fractional data type in 5.11 format.

◆ q4_27_t

typedef int32_t q4_27_t

32-bit fractional data type in 5.27 format.

◆ q5_10_t

typedef int16_t q5_10_t

16-bit fractional data type in 6.10 format.

◆ q5_26_t

typedef int32_t q5_26_t

32-bit fractional data type in 6.26 format.

◆ q63_t

typedef int64_t q63_t

64-bit fractional data type in 1.63 format.

◆ q6_25_t

typedef int32_t q6_25_t

32-bit fractional data type in 7.25 format.

◆ q6_9_t

typedef int16_t q6_9_t

16-bit fractional data type in 7.9 format.

◆ q7_24_t

typedef int32_t q7_24_t

32-bit fractional data type in 8.24 format.

◆ q7_t

typedef int8_t q7_t

8-bit fractional data type in 1.7 format.

◆ tpt_bilinear_interpolate_f32_t

Instance structure for the floating-point bilinear interpolation function.

◆ tpt_bilinear_interpolate_q15_t

Instance structure for the Q15 bilinear interpolation function.

◆ tpt_bilinear_interpolate_q31_t

Instance structure for the Q31 bilinear interpolation function.

◆ tpt_bilinear_interpolate_q7_t

Instance structure for the Q7 bilinear interpolation function.

◆ tpt_linear_interpolate_f32_t

Instance structure for the floating-point Linear Interpolate function.

◆ tpt_status

typedef enum tpt_status_e tpt_status

Error status returned by some functions in the library.

Enumeration Type Documentation

◆ tpt_status_e

Error status returned by some functions in the library.

Enumerator
TPT_MATH_SUCCESS 

No error.

TPT_MATH_ARGUMENT_ERROR 

One or more arguments are incorrect.

TPT_MATH_SINGULAR 

Input matrix is singular.

TPT_MATH_DECOMPOSITION_FAILURE 

Decomposition Failed.

Function Documentation

◆ __CLZ()

static uint8_t __CLZ ( uint32_t  aData)
inlinestatic

◆ __CLZ32()

static uint8_t __CLZ32 ( uint32_t  aData)
inlinestatic

◆ __SSAT()

static int32_t __SSAT ( int32_t  aValue,
uint32_t  aBits 
)
inlinestatic

◆ __USAT()

static uint32_t __USAT ( int32_t  aValue,
uint32_t  aBits 
)
inlinestatic

◆ clip_q15_to_q7()

static q7_t clip_q15_to_q7 ( q15_t  x)
inlinestatic

Clips Q15 to Q7 values.

◆ clip_q31_to_q15()

static q15_t clip_q31_to_q15 ( q31_t  x)
inlinestatic

Clips Q31 to Q15 values.

◆ clip_q31_to_q7()

static q7_t clip_q31_to_q7 ( q31_t  x)
inlinestatic

Clips Q31 to Q7 values.

◆ clip_q63_to_q15()

static q15_t clip_q63_to_q15 ( q63_t  x)
inlinestatic

Clips Q63 to Q15 values.

◆ clip_q63_to_q31()

static q31_t clip_q63_to_q31 ( q63_t  x)
inlinestatic

Clips Q63 to Q31 values.

◆ clip_q63_to_q7()

static q7_t clip_q63_to_q7 ( q63_t  x)
inlinestatic

Clips Q63 to Q7 values.

◆ mult32x32_keep32()

static q31_t mult32x32_keep32 ( q31_t  acc,
q31_t  x,
q31_t  y 
)
inlinestatic

Multiplies 32 X 32 and returns 32 bit result in 1.31 format.

◆ mult32x64()

static q63_t mult32x64 ( q63_t  x,
q31_t  y 
)
inlinestatic

Multiplies 32 X 64 and returns 32 bit result in 2.30 format.