HPM SDK
HPMicro Software Development Kit
DSP Sort Functions

Modules

 NN Activation Functions
 The activation functions are used to filter out some input data. They include sigmoid, tanh and ReLU (Rectified Linear Unit) functions.
 
 NN Basic Functions
 The basic functions are used to perform element-wise basic arithmetic operations.
 
 NN Concatenation Functions
 The concatenation functions are used to concatenate the tensor along the specified axis.
 
 NN Convolution Functions
 The convolution functions transform the input matrix into a column vector with im2col, and then use matrix-matrix multiplication to get the convolution result.
 
 NN Fully Connected Functions
 The fully connected functions multiply the input vector by a weight matrix and add a bias, if any, to the result. The supported combinations of input vector and weight matrix are (signed 8-bit integer, signed 8-bit integer), (unsigned 8-bit integer, signed 8-bit integer), (signed 16-bit integer, signed 8-bit integer), (signed 16-bit integer, signed 16-bit integer) and (16-bit half-precision floating point, 16-bit half-precision floating point).
 
 NN Pooling Functions
 The pooling functions are used to downsample input data. They include max and average pooling functions.
 
 NN Softmax Functions
 The softmax functions are exponential functions with base 2.
 
 NN Utils Functions
 Utils functions are miscellaneous auxiliary tools.
 

Macros

#define LEFT_SHIFT(_shift)   (_shift > 0 ? _shift : 0)
 
#define RIGHT_SHIFT(_shift)   (_shift > 0 ? 0 : -_shift)
 
#define Q31_MAX   ((q31_t)(0x7FFFFFFFL))
 
#define Q31_MIN   ((q31_t)(0x80000000L))
 

Functions

static void hpm_dsp_sort_init_f32 (riscv_dsp_sort_f32_t *instance, riscv_dsp_sort_alg alg, riscv_dsp_sort_order order)
 
static void hpm_dsp_sort_f32 (const riscv_dsp_sort_f32_t *instance, float32_t *src, float32_t *dst, uint32_t size)
 Generic sorting function. More...
 
static void hpm_dsp_sort_merge_init_f32 (riscv_dsp_sort_merge_f32_t *instance, riscv_dsp_sort_order order, float32_t *buf)
 
static void hpm_dsp_sort_merge_f32 (const riscv_dsp_sort_merge_f32_t *instance, float32_t *src, float32_t *dst, uint32_t size)
 Merge sort. More...
 
static void write_q15x2_ia (q15_t **pQ15, q31_t value)
 
__STATIC_FORCEINLINE q31_t hpm_nn_read_q15x2_ia (const q15_t **in_q15)
 Read 2 q15 elements and post increment pointer. More...
 
__STATIC_FORCEINLINE q31_t hpm_nn_sat_doubling_high_mult (const q31_t m1, const q31_t m2)
 Saturating doubling high multiply. Result matches NEON instruction VQRDMULH. More...
 
__STATIC_FORCEINLINE q31_t hpm_nn_divide_by_power_of_two (const q31_t dividend, const q31_t exponent)
 Rounding divide by power of two. More...
 
__STATIC_FORCEINLINE q31_t hpm_nn_requantize (const q31_t val, const q31_t multiplier, const q31_t shift)
 
__STATIC_FORCEINLINE q31_t hpm_nn_read_q7x4_ia (const q7_t **in_q7)
 Read 4 q7 from q7 pointer and post increment pointer. More...
 
__STATIC_FORCEINLINE const q7_t * read_and_pad_reordered (const q7_t *source, q31_t *out1, q31_t *out2)
 read and expand one q7 word into two q15 words with reordering More...
 
__STATIC_FORCEINLINE const q7_t * read_and_pad (const q7_t *source, q31_t *out1, q31_t *out2)
 read and expand one q7 word into two q15 words More...
 
__STATIC_FORCEINLINE int32_t hpm_nn_read_s8x4_ia (const int8_t **in_s8)
 Read 4 s8 from s8 pointer and post increment pointer. More...
 
__STATIC_FORCEINLINE void hpm_nn_q7_to_q15_with_offset (const int8_t *src, int16_t *dst, int32_t block_size, int16_t offset)
 

Detailed Description

The generic sort function sorts elements of a vector by the algorithm and sorting order specified in its instance structure. The algorithms to be chosen from to perform the generic sorting include bitonic sort, bubble sort, heap sort, insertion sort, quick sort and selection sort. Andes DSP library only supports the generic sort function for floating-point data.

Macro Definition Documentation

◆ LEFT_SHIFT

#define LEFT_SHIFT (   _shift)    (_shift > 0 ? _shift : 0)

◆ Q31_MAX

#define Q31_MAX   ((q31_t)(0x7FFFFFFFL))

◆ Q31_MIN

#define Q31_MIN   ((q31_t)(0x80000000L))

◆ RIGHT_SHIFT

#define RIGHT_SHIFT (   _shift)    (_shift > 0 ? 0 : -_shift)

Function Documentation

◆ hpm_dsp_sort_f32()

static void hpm_dsp_sort_f32 ( const riscv_dsp_sort_f32_t *  instance,
float32_t *  src,
float32_t *  dst,
uint32_t  size 
)
inlinestatic

#include <middleware/hpm_math/hpm_math.h>

Generic sorting function.

Parameters
[in]instancepointer of the instance structure
[in]srcpointer of the input vector
[out]dstpointer of the output vector
[in]sizenumber of elements in a vector

Note:

  1. The possible sorting algorithms for the generic sorting (i.e., options for alg) include
    • RISCV_DSP_SORT_BITONIC bitonic sort
    • RISCV_DSP_SORT_BUBBLE bubble sort
    • RISCV_DSP_SORT_HEAP heap sort
    • RISCV_DSP_SORT_INSERTION insertion sort
    • RISCV_DSP_SORT_QUICK quick sort
    • RISCV_DSP_SORT_SELECTION selection sort
  2. The possible sorting orders for the generic sorting (i.e., options for order) include
    • RISCV_DSP_SORT_DESCENDING descending order
    • RISCV_DSP_SORT_ASCENDING ascending order
  3. To ensure correct results, you must initialize the instance structure with the function riscv_dsp_sort_init_f32 before using this function riscv_dsp_sort_f32. For how to use the two functions, please refer to the code examples below.

Example

      With the input size as 100, sorting order as ascending and sorting algorithm as quick
      sort, the code example of generic sorting is as follows:

         #define size 100
         riscv_dsp_sort_f32_t *instance;
         float32_t src[size] = {};
         float32_t dst[size];
         riscv_dsp_sort_init_f32(instance, RISCV_DSP_SORT_QUICK,
         RISCV_DSP_SORT_ASCENDING);
         riscv_dsp_sort_f32(instance, src, dst, size);
    

◆ hpm_dsp_sort_init_f32()

static void hpm_dsp_sort_init_f32 ( riscv_dsp_sort_f32_t *  instance,
riscv_dsp_sort_alg  alg,
riscv_dsp_sort_order  order 
)
inlinestatic

#include <middleware/hpm_math/hpm_math.h>

Parameters
[in,out]instancepointer of the instance structure
[in]algdesired sorting algorithm
[in]orderdesired sorting order

Note:

  1. This function has to be called to initialize the instance structure before the function riscv_dsp_sort_f32 is executed. Please refer to code examples.
  2. The possible sorting algorithms for the generic sorting (i.e., options for alg) include
    • RISCV_DSP_SORT_BITONIC bitonic sort
    • RISCV_DSP_SORT_BUBBLE bubble sort
    • RISCV_DSP_SORT_HEAP heap sort
    • RISCV_DSP_SORT_INSERTION insertion sort
    • RISCV_DSP_SORT_QUICK quick sort
    • RISCV_DSP_SORT_SELECTION selection sort
  3. The possible sorting orders for the generic sorting (i.e., options for order) include
    • RISCV_DSP_SORT_DESCENDING descending order
    • RISCV_DSP_SORT_ASCENDING ascending order

◆ hpm_dsp_sort_merge_f32()

static void hpm_dsp_sort_merge_f32 ( const riscv_dsp_sort_merge_f32_t *  instance,
float32_t *  src,
float32_t *  dst,
uint32_t  size 
)
inlinestatic

#include <middleware/hpm_math/hpm_math.h>

Merge sort.

Parameters
[in]instancepointer of the instance structure.
[in]srcpointer of the input vector
[out]dstpointer of the output vector
[in]sizenumber of elements in a vector

Note:

  1. The possible sorting orders for the merge sorting (i.e., options for order) include
    • RISCV_DSP_SORT_DESCENDING descending order
    • RISCV_DSP_SORT_ASCENDING ascending order
  2. To ensure correct results, you must initialize the instance structure with the function riscv_dsp_sort_merge_init_f32 before using this function riscv_dsp_sort_merge_f32. For how to use the two functions, please refer to the code example below.

Example

    With the input size as 100 and sorting order as descending, the code example of merge
    sorting is as follows:

    #define size 100
    riscv_dsp_sort_merge_f32_t *instance;
    float32_t src[size] = {};
    float32_t buf[size];
    float32_t dst[size];
    riscv_dsp_sort_merge_init_f32(instance, RISCV_DSP_SORT_DESCENDING, buf);
    riscv_dsp_sort_merge_f32(instance, src, dst, size);
    

◆ hpm_dsp_sort_merge_init_f32()

static void hpm_dsp_sort_merge_init_f32 ( riscv_dsp_sort_merge_f32_t *  instance,
riscv_dsp_sort_order  order,
float32_t *  buf 
)
inlinestatic

#include <middleware/hpm_math/hpm_math.h>

Parameters
[in,out]instancepointer of the instance structure.
[in]orderdesired sorting order
[in]bufpointer of the working buffer

Note:

  1. This function has to be called to initialize the instance structure before the function riscv_dsp_sort_merge_f32 is executed. Please refer to Section 2.11.2.2 for a code example.
  2. The possible sorting orders for the merge sorting (i.e., options for order) include
    • RISCV_DSP_SORT_DESCENDING descending order
    • RISCV_DSP_SORT_ASCENDING ascending order

◆ hpm_nn_divide_by_power_of_two()

__STATIC_FORCEINLINE q31_t hpm_nn_divide_by_power_of_two ( const q31_t  dividend,
const q31_t  exponent 
)

#include <middleware/hpm_math/hpm_math.h>

Rounding divide by power of two.

Parameters
[in]dividend- Dividend
[in]exponent- Divisor = power(2, exponent) Range: [0, 31]
Returns
Rounded result of division. Midpoint is rounded away from zero.

◆ hpm_nn_q7_to_q15_with_offset()

__STATIC_FORCEINLINE void hpm_nn_q7_to_q15_with_offset ( const int8_t *  src,
int16_t *  dst,
int32_t  block_size,
int16_t  offset 
)

◆ hpm_nn_read_q15x2_ia()

__STATIC_FORCEINLINE q31_t hpm_nn_read_q15x2_ia ( const q15_t **  in_q15)

#include <middleware/hpm_math/hpm_math.h>

Read 2 q15 elements and post increment pointer.

Parameters
[in]in_q15Pointer to pointer that holds address of input.
Returns
q31 value

◆ hpm_nn_read_q7x4_ia()

__STATIC_FORCEINLINE q31_t hpm_nn_read_q7x4_ia ( const q7_t **  in_q7)

#include <middleware/hpm_math/hpm_math.h>

Read 4 q7 from q7 pointer and post increment pointer.

Parameters
[in]in_q7Pointer to pointer that holds address of input.
Returns
q31 value

◆ hpm_nn_read_s8x4_ia()

__STATIC_FORCEINLINE int32_t hpm_nn_read_s8x4_ia ( const int8_t **  in_s8)

#include <middleware/hpm_math/hpm_math.h>

Read 4 s8 from s8 pointer and post increment pointer.

Parameters
[in]in_s8Pointer to pointer that holds address of input.
Returns
q31 value

◆ hpm_nn_requantize()

__STATIC_FORCEINLINE q31_t hpm_nn_requantize ( const q31_t  val,
const q31_t  multiplier,
const q31_t  shift 
)

◆ hpm_nn_sat_doubling_high_mult()

__STATIC_FORCEINLINE q31_t hpm_nn_sat_doubling_high_mult ( const q31_t  m1,
const q31_t  m2 
)

#include <middleware/hpm_math/hpm_math.h>

Saturating doubling high multiply. Result matches NEON instruction VQRDMULH.

Parameters
[in]m1Multiplicand
[in]m2Multiplier
Returns
Result of multiplication.

◆ read_and_pad()

__STATIC_FORCEINLINE const q7_t* read_and_pad ( const q7_t *  source,
q31_t *  out1,
q31_t *  out2 
)

#include <middleware/hpm_math/hpm_math.h>

read and expand one q7 word into two q15 words

◆ read_and_pad_reordered()

__STATIC_FORCEINLINE const q7_t* read_and_pad_reordered ( const q7_t *  source,
q31_t *  out1,
q31_t *  out2 
)

#include <middleware/hpm_math/hpm_math.h>

read and expand one q7 word into two q15 words with reordering

◆ write_q15x2_ia()

static void write_q15x2_ia ( q15_t **  pQ15,
q31_t  value 
)
inlinestatic