ESP-IDF Firmware
Firmware architecture and call graph
Loading...
Searching...
No Matches
dspi_dotprod_u16_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 "
dspi_dotprod.h
"
16
17
esp_err_t
dspi_dotprod_u16_ansi
(
image2d_t
*in_image,
image2d_t
*filter, uint16_t *out_value,
int
count_x,
int
count_y,
int
shift)
18
{
19
if
(in_image->
step_x
* count_x > in_image->
stride_x
) {
20
return
ESP_ERR_DSP_PARAM_OUTOFRANGE
;
21
}
22
if
(in_image->
step_y
* count_y > in_image->
stride_y
) {
23
return
ESP_ERR_DSP_PARAM_OUTOFRANGE
;
24
}
25
if
(filter->
step_x
* count_x > filter->
stride_x
) {
26
return
ESP_ERR_DSP_PARAM_OUTOFRANGE
;
27
}
28
if
(filter->
step_y
* count_y > filter->
stride_y
) {
29
return
ESP_ERR_DSP_PARAM_OUTOFRANGE
;
30
}
31
32
uint16_t *i_data = (uint16_t *)in_image->
data
;
33
uint16_t *f_data = (uint16_t *)filter->
data
;
34
int
i_step = in_image->
stride_x
* in_image->
step_y
;
35
int
f_step = filter->
stride_x
* filter->
step_y
;
36
37
int64_t acc = 0;
38
for
(
int
y
= 0;
y
< count_y;
y
++) {
39
for
(
int
x
= 0;
x
< count_x;
x
++) {
40
acc += (int32_t)i_data[in_image->
step_x
*
x
] * (int32_t)f_data[filter->
step_x
*
x
];
41
}
42
i_data += i_step;
43
f_data += f_step;
44
}
45
acc += 1 << (shift - 1);
// round operation
46
acc >>= shift;
47
*out_value = acc;
48
return
ESP_OK
;
49
}
ESP_ERR_DSP_PARAM_OUTOFRANGE
#define ESP_ERR_DSP_PARAM_OUTOFRANGE
Definition
dsp_err_codes.h:22
image2d_t
struct image2d_s image2d_t
dspi_dotprod.h
dspi_dotprod_u16_ansi
esp_err_t dspi_dotprod_u16_ansi(image2d_t *in_image, image2d_t *filter, uint16_t *out_value, int count_x, int count_y, int shift)
Definition
dspi_dotprod_u16_ansi.c:17
esp_err_t
int esp_err_t
Definition
esp_err.h:21
ESP_OK
#define ESP_OK
Definition
esp_err.h:23
image2d_s::stride_x
int stride_x
Definition
dsp_types.h:28
image2d_s::stride_y
int stride_y
Definition
dsp_types.h:29
image2d_s::data
void * data
Definition
dsp_types.h:25
image2d_s::step_y
int step_y
Definition
dsp_types.h:27
image2d_s::step_x
int step_x
Definition
dsp_types.h:26
y
float y[1024]
Definition
test_fir.c:11
x
float x[1024]
Definition
test_fir.c:10
components
espressif__esp-dsp
modules
dotprod
fixed
dspi_dotprod_u16_ansi.c
Generated by
1.16.1