add some code
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
// Copyright 2018-2019 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "dsps_addc_platform.h"
|
||||
#if (dsps_addc_f32_ae32_enabled == 1)
|
||||
|
||||
// This is bi quad filter form II for ESP32 processor.
|
||||
.text
|
||||
.align 4
|
||||
.global dsps_addc_f32_ae32
|
||||
.type dsps_addc_f32_ae32,@function
|
||||
// The function implements the following C code:
|
||||
// esp_err_t dsps_addc_f32_ansi(const float *input, float *output, int len, float C, int step_in, int step_out)
|
||||
// {
|
||||
// for (int i = 0 ; i < len ; i++) {
|
||||
// output[i * step_out] = input[i * step_in] + C;
|
||||
// }
|
||||
// return ESP_OK;
|
||||
// }
|
||||
dsps_addc_f32_ae32:
|
||||
// input - a2
|
||||
// output - a3
|
||||
// len - a4
|
||||
// C - a5
|
||||
// step_in - a6
|
||||
// step_out - a7
|
||||
|
||||
entry a1, 16
|
||||
|
||||
slli a6, a6, 2 // a6 - step_in<<2
|
||||
slli a7, a7, 2 // a7 - step_out<<2
|
||||
wfr f0, a5 // a5 - load to the f0
|
||||
|
||||
loopnez a4, loop_end_addc_f32_ae32
|
||||
lsi f1, a2, 0
|
||||
|
||||
add.s f2, f1, f0 // f2 = f1 + f0
|
||||
add.n a2, a2, a6 // input1_ptr+=step_in;
|
||||
ssi f2, a3, 0
|
||||
add.n a3, a3, a7 // output+=step_out;
|
||||
loop_end_addc_f32_ae32:
|
||||
|
||||
movi.n a2, 0 // return status ESP_OK
|
||||
retw.n
|
||||
|
||||
#endif // dsps_addc_f32_ae32_enabled
|
||||
@@ -0,0 +1,30 @@
|
||||
// Copyright 2018-2019 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "dsps_addc.h"
|
||||
|
||||
esp_err_t dsps_addc_f32_ansi(const float *input, float *output, int len, float C, int step_in, int step_out)
|
||||
{
|
||||
if (NULL == input) {
|
||||
return ESP_ERR_DSP_PARAM_OUTOFRANGE;
|
||||
}
|
||||
if (NULL == output) {
|
||||
return ESP_ERR_DSP_PARAM_OUTOFRANGE;
|
||||
}
|
||||
|
||||
for (int i = 0 ; i < len ; i++) {
|
||||
output[i * step_out] = input[i * step_in] + C;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
// Copyright 2018-2019 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef _dsps_addc_H_
|
||||
#define _dsps_addc_H_
|
||||
#include "dsp_err.h"
|
||||
|
||||
#include "dsps_addc_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
|
||||
/**@{*/
|
||||
/**
|
||||
* @brief add constant
|
||||
*
|
||||
* The function adds constant to the input array
|
||||
* x[i*step_out] = y[i*step_in] + C; i=[0..len)
|
||||
* The implementation use ANSI C and could be compiled and run on any platform
|
||||
*
|
||||
* @param[in] input: input array
|
||||
* @param output: output array
|
||||
* @param len: amount of operations for arrays
|
||||
* @param C: constant value
|
||||
* @param step_in: step over input array (by default should be 1)
|
||||
* @param step_out: step over output array (by default should be 1)
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - One of the error codes from DSP library
|
||||
*/
|
||||
esp_err_t dsps_addc_f32_ansi(const float *input, float *output, int len, float C, int step_in, int step_out);
|
||||
esp_err_t dsps_addc_f32_ae32(const float *input, float *output, int len, float C, int step_in, int step_out);
|
||||
/**@}*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if CONFIG_DSP_OPTIMIZED
|
||||
#if (dsps_addc_f32_ae32_enabled == 1)
|
||||
#define dsps_addc_f32 dsps_addc_f32_ae32
|
||||
#else
|
||||
#define dsps_addc_f32 dsps_addc_f32_ansi
|
||||
#endif
|
||||
#else
|
||||
#define dsps_addc_f32 dsps_addc_f32_ansi
|
||||
#endif // CONFIG_DSP_OPTIMIZED
|
||||
|
||||
#endif // _dsps_addc_H_
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef _dsps_addc_platform_H_
|
||||
#define _dsps_addc_platform_H_
|
||||
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#ifdef __XTENSA__
|
||||
#include <xtensa/config/core-isa.h>
|
||||
#include <xtensa/config/core-matmap.h>
|
||||
|
||||
|
||||
#if ((XCHAL_HAVE_FP == 1) && (XCHAL_HAVE_LOOPS == 1))
|
||||
|
||||
#define dsps_addc_f32_ae32_enabled 1
|
||||
|
||||
#endif
|
||||
#endif // __XTENSA__
|
||||
|
||||
|
||||
#endif // _dsps_addc_platform_H_
|
||||
@@ -0,0 +1,71 @@
|
||||
// Copyright 2018-2019 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <string.h>
|
||||
#include "unity.h"
|
||||
#include "dsp_platform.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
#include "dsp_tests.h"
|
||||
#include "dsps_addc.h"
|
||||
#include "esp_attr.h"
|
||||
|
||||
static const char *TAG = "dsps_addc";
|
||||
|
||||
|
||||
TEST_CASE("dsps_addc_f32_ansi functionality", "[dsps]")
|
||||
{
|
||||
int n = 64;
|
||||
float x[n];
|
||||
float y[n];
|
||||
for (int i = 0 ; i < n ; i++) {
|
||||
x[i] = i;
|
||||
y[i] = i + 10;
|
||||
}
|
||||
dsps_addc_f32_ansi(x, x, n, 10, 1, 1);
|
||||
for (int i = 0 ; i < n ; i++) {
|
||||
if (x[i] != y[i]) {
|
||||
TEST_ASSERT_EQUAL(x[i], y[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("dsps_addc_f32 functionality", "[dsps]")
|
||||
{
|
||||
int n = 64;
|
||||
float x[n];
|
||||
float y[n];
|
||||
for (int i = 0 ; i < n ; i++) {
|
||||
x[i] = i;
|
||||
y[i] = i + 10;
|
||||
}
|
||||
dsps_addc_f32(x, x, n, 10, 1, 1);
|
||||
for (int i = 0 ; i < n ; i++) {
|
||||
if (x[i] != y[i]) {
|
||||
TEST_ASSERT_EQUAL(x[i], y[i]);
|
||||
}
|
||||
}
|
||||
|
||||
int repeat_count = 1;
|
||||
|
||||
dsps_addc_f32(x, x, n, 10, 1, 1);
|
||||
|
||||
unsigned int start_b = dsp_get_cpu_cycle_count();
|
||||
dsps_addc_f32(x, x, n, 10, 1, 1);
|
||||
unsigned int end_b = dsp_get_cpu_cycle_count();
|
||||
|
||||
float total_b = end_b - start_b;
|
||||
float cycles = total_b / (n * repeat_count);
|
||||
ESP_LOGI(TAG, "dsps_addc_f32 - %f cycles per sample \n", cycles);
|
||||
}
|
||||
Reference in New Issue
Block a user