ESP-IDF Firmware
Firmware architecture and call graph
Loading...
Searching...
No Matches
dspm_mult_s16_ansi.c File Reference
#include "dsps_dotprod.h"
#include "dspm_mult.h"
Include dependency graph for dspm_mult_s16_ansi.c:

Go to the source code of this file.

Functions

esp_err_t dspm_mult_s16_ansi (const int16_t *A, const int16_t *B, int16_t *C, int m, int n, int k, int shift)
 Matrix multiplication 16 bit signeg int.

Function Documentation

◆ dspm_mult_s16_ansi()

esp_err_t dspm_mult_s16_ansi ( const int16_t * A,
const int16_t * B,
int16_t * C,
int m,
int n,
int k,
int shift )

Matrix multiplication 16 bit signeg int.

Matrix multiplication for two signed 16 bit fixed point matrices: C[m][k] = (A[m][n] * B[n][k]) >> (15- shift) The extension (_ansi) use ANSI C and could be compiled and run on any platform. The extension (_ae32) is optimized for ESP32 chip.

Parameters
[in]Ainput matrix A[m][n]
[in]Binput matrix B[n][k]
Cresult matrix C[m][k]
[in]mmatrix dimension
[in]nmatrix dimension
[in]kmatrix dimension
[in]shiftevery result will be shifted and stored as 16 bit signed value.
Returns
  • ESP_OK on success
  • One of the error codes from DSP library

Definition at line 21 of file dspm_mult_s16_ansi.c.

22{
23 int final_shift = shift - 15;
24 for (int i = 0 ; i < m ; i++) {
25 for (int j = 0 ; j < k ; j++) {
26 // This code also could be used
27 //dsps_dotprode_f32_ae32(&A[i*n],&B[j],&C[i*k + j],n,1,n);
28 long long acc = 0x7fff >> shift;
29 for (int s = 0; s < n ; s++) {
30 acc += (int32_t)A[i * n + s] * (int32_t)B[s * k + j];
31 }
32 if (final_shift > 0) {
33 C[i * k + j] = (acc << final_shift);
34 } else {
35 C[i * k + j] = (acc >> (-final_shift));
36 }
37 }
38 }
39 return ESP_OK;
40}
#define ESP_OK
Definition esp_err.h:23
float C[4][16]
Definition test_mmult.c:22
const int m
Definition test_mmult.c:16
float B[8][16]
Definition test_mmult.c:21
float A[4][8]
Definition test_mmult.c:20
const int n
Definition test_mmult.c:17
const int k
Definition test_mmult.c:18

References A, B, C, ESP_OK, k, m, and n.