ESP-IDF Firmware
Firmware architecture and call graph
Loading...
Searching...
No Matches
dspm_mult_s16_ansi.c
Go to the documentation of this file.
1// Copyright 2018-2019 Espressif Systems (Shanghai) PTE LTD
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#include "dsps_dotprod.h"
16#include "dspm_mult.h"
17
18// Matrinx A(m,n), m - amount or rows, n - amount of columns
19// C(m,k) = A(m,n)*B(n,k)
20// c(i,j) = sum(a(i,s)*b(s,j)) , s=1..n
21esp_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)
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}
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.
int esp_err_t
Definition esp_err.h:21
#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