# Basic Math Functions for Neural Network Computation

void riscv_nn_accumulate_q7_to_q15(q15_t *pDst, const q7_t *pSrc, uint32_t length)
void riscv_nn_add_q7(const q7_t *input, q31_t *output, uint32_t block_size)
void riscv_nn_mult_q15(q15_t *pSrcA, q15_t *pSrcB, q15_t *pDst, const uint16_t out_shift, uint32_t blockSize)
void riscv_nn_mult_q7(q7_t *pSrcA, q7_t *pSrcB, q7_t *pDst, const uint16_t out_shift, uint32_t blockSize)
group NNBasicMath

Basic Math Functions for Neural Network Computation.

Functions

void riscv_nn_accumulate_q7_to_q15(q15_t *pDst, const q7_t *pSrc, uint32_t length)

Converts the elements from a q7 vector and accumulate to a q15 vector.

The equation used for the conversion process is:

Description:

Parameters
• *src[in] points to the q7 input vector

• *dst[out] points to the q15 output vector

• block_size[in] length of the input vector

void riscv_nn_add_q7(const q7_t *input, q31_t *output, uint32_t block_size)

Non-saturating addition of elements of a q7 vector.

2^24 samples can be added without saturating the result.

Description:

The equation used for the conversion process is:

Parameters
• *input[in] Pointer to the q7 input vector

• *output[out] Pointer to the q31 output variable.

• block_size[in] length of the input vector

void riscv_nn_mult_q15(q15_t *pSrcA, q15_t *pSrcB, q15_t *pDst, const uint16_t out_shift, uint32_t blockSize)

Q7 vector multiplication with variable output shifts.

q7 vector multiplication with variable output shifts

Scaling and Overflow Behavior:

The function uses saturating arithmetic. Results outside of the allowable Q15 range [0x8000 0x7FFF] will be saturated.

Parameters
• *pSrcA[in] pointer to the first input vector

• *pSrcB[in] pointer to the second input vector

• *pDst[out] pointer to the output vector

• out_shift[in] amount of right-shift for output

• blockSize[in] number of samples in each vector

void riscv_nn_mult_q7(q7_t *pSrcA, q7_t *pSrcB, q7_t *pDst, const uint16_t out_shift, uint32_t blockSize)

Q7 vector multiplication with variable output shifts.

q7 vector multiplication with variable output shifts

Scaling and Overflow Behavior:

The function uses saturating arithmetic. Results outside of the allowable Q7 range [0x80 0x7F] will be saturated.

Parameters
• *pSrcA[in] pointer to the first input vector

• *pSrcB[in] pointer to the second input vector

• *pDst[out] pointer to the output vector

• out_shift[in] amount of right-shift for output

• blockSize[in] number of samples in each vector