add some code

This commit is contained in:
2025-09-05 13:25:11 +08:00
parent 9ff0a99e7a
commit 3cf1229a85
8911 changed files with 2535396 additions and 0 deletions

View File

@@ -0,0 +1,77 @@
// 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_mulc_platform.h"
#if (dsps_mulc_s16_ae32_enabled == 1)
.text
.align 4
.global dsps_mulc_s16_ae32
.type dsps_mulc_s16_ae32,@function
// The function implements the following C code:
// esp_err_t dsps_mulc_f32_ansi(const float *input, float *output, int len, float C, int step_in, int step_out)
// {
// for (int i = 0 ; i < len ; i++) {
// int32_t acc = (int32_t)input[i * step_in] * (int32_t)C;
// output[i * step_out] = (int16_t)(acc>>15);
// }
// return ESP_OK;
// }
dsps_mulc_s16_ae32:
// input - a2
// output - a3
// len - a4
// C - a5
// step_in - a6
// step_out - a7
entry a1, 16
movi.n a8, 15 // output shift
ssr a8
srli a4, a4, 1 // a4 = a4>>1
slli a6, a6, 2 // a6 - step_in<<3, because we load two inputs per loop
slli a7, a7, 1 // a7 - step_out<<2
addi a6, a6, -4;
addi a2, a2, -4;
ldinc m0, a2
loopnez a4, loop_end_mulc_f32_ae32
add.n a2, a2, a6 // input+=step_input;
mul.DA.LL m0, a5
rsr a8, acchi
rsr a9, acclo
src a8, a8, a9 // Here result in a8
s16i a8, a3, 0 // store result to the putput
// rsr a9, acclo
// s16i a9, a3, 0 // store result to the putput
add.n a3, a3, a7 // output+=step_out;
mul.DA.HL m0, a5
rsr a8, acchi
rsr a9, acclo
ldinc m0, a2 // load next data
src a10, a8, a9 // Here result in a8
s16i a10, a3, 0 // store result to the putput
// // rsr a9, acclo
// // s16i a9, a3, 0 // store result to the putput
add.n a3, a3, a7 // output+=step_out;
loop_end_mulc_f32_ae32:
movi.n a2, 0 // return status ESP_OK
retw.n
#endif // dsps_mulc_s16_ae32_enabled

View File

@@ -0,0 +1,31 @@
// 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_mulc.h"
esp_err_t dsps_mulc_s16_ansi(const int16_t *input, int16_t *output, int len, int16_t 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++) {
int32_t acc = (int32_t)input[i * step_in] * (int32_t)C;
output[i * step_out] = (int16_t)(acc >> 15);
}
return ESP_OK;
}

View File

@@ -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_mulc_platform.h"
#if (dsps_mulc_f32_ae32_enabled == 1)
// This is bi quad filter form II for ESP32 processor.
.text
.align 4
.global dsps_mulc_f32_ae32
.type dsps_mulc_f32_ae32,@function
// The function implements the following C code:
// esp_err_t dsps_mulc_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_mulc_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_mulc_f32_ae32
lsi f1, a2, 0
mul.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_mulc_f32_ae32:
movi.n a2, 0 // return status ESP_OK
retw.n
#endif // dsps_mulc_f32_ae32_enabled

View File

@@ -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_mulc.h"
esp_err_t dsps_mulc_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;
}

View File

@@ -0,0 +1,74 @@
// 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_mulc_H_
#define _dsps_mulc_H_
#include "dsp_err.h"
#include "dsps_mulc_platform.h"
#ifdef __cplusplus
extern "C"
{
#endif
/**@{*/
/**
* @brief multiply constant
*
* The function multiplies input array to the constant value
* 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_mulc_f32_ansi(const float *input, float *output, int len, float C, int step_in, int step_out);
esp_err_t dsps_mulc_f32_ae32(const float *input, float *output, int len, float C, int step_in, int step_out);
esp_err_t dsps_mulc_s16_ae32(const int16_t *input, int16_t *output, int len, int16_t C, int step_in, int step_out);
esp_err_t dsps_mulc_s16_ansi(const int16_t *input, int16_t *output, int len, int16_t C, int step_in, int step_out);
#ifdef __cplusplus
}
#endif
#if CONFIG_DSP_OPTIMIZED
#if (dsps_mulc_f32_ae32_enabled == 1)
#define dsps_mulc_f32 dsps_mulc_f32_ae32
#else //
#define dsps_mulc_f32 dsps_mulc_f32_ansi
#endif
#if (dsps_mulc_s16_ae32_enabled == 1)
#define dsps_mulc_s16 dsps_mulc_s16_ae32
#else
#define dsps_mulc_s16 dsps_mulc_s16_ansi
#endif // dsps_mulc_s16_ae32_enabled
#else
#define dsps_mulc_f32 dsps_mulc_f32_ansi
#define dsps_mulc_s16 dsps_mulc_s16_ansi
#endif
#endif // _dsps_mulc_H_

View File

@@ -0,0 +1,25 @@
#ifndef _dsps_mulc_platform_H_
#define _dsps_mulc_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_mulc_f32_ae32_enabled 1
#endif
#if ((XCHAL_HAVE_LOOPS == 1) && (XCHAL_HAVE_MAC16 == 1))
#define dsps_mulc_s16_ae32_enabled 1
#endif //
#endif // __XTENSA__
#endif // _dsps_mulc_platform_H_

View File

@@ -0,0 +1,70 @@
// 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_mulc.h"
#include "esp_attr.h"
static const char *TAG = "dsps_mulc";
TEST_CASE("dsps_mulc_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_mulc_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_mulc_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_mulc_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_mulc_f32(x, x, n, 10, 1, 1);
unsigned int start_b = dsp_get_cpu_cycle_count();
dsps_mulc_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_mulc_f32 - %f cycles per sample \n", cycles);
}

View File

@@ -0,0 +1,61 @@
// 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_mulc.h"
#include "esp_attr.h"
static const char *TAG = "dsps_mulc";
TEST_CASE("dsps_mulc_s16 functionality", "[dsps]")
{
int n = 64;
int16_t x[n];
int16_t y[n];
int32_t temp;
int16_t test_const = 0x2000;
for (int i = 0 ; i < n ; i++) {
x[i] = i << 4;
temp = (int32_t)x[i] * (int32_t)test_const;
y[i] = temp >> 15;
}
dsps_mulc_s16(x, x, n, test_const, 1, 1);
for (int i = 0 ; i < n ; i++) {
if (x[i] != y[i]) {
TEST_ASSERT_EQUAL(x[i], y[i]);
}
}
}
TEST_CASE("dsps_mulc_s16 benchmark", "[dsps]")
{
const int n = 256;
int16_t x[n];
for (int i = 0 ; i < n ; i++) {
x[i] = i << 4;
}
unsigned int start_b = dsp_get_cpu_cycle_count();
dsps_mulc_s16(x, x, n, 10, 1, 1);
unsigned int end_b = dsp_get_cpu_cycle_count();
float cycles = end_b - start_b;
ESP_LOGI(TAG, "dsps_mulc_s16 - %f cycles per sample \n", cycles);
}

View File

@@ -0,0 +1,61 @@
// 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_mulc.h"
#include "esp_attr.h"
static const char *TAG = "dsps_mulc";
TEST_CASE("dsps_mulc_s16_ansi functionality", "[dsps]")
{
int n = 64;
int16_t x[n];
int16_t y[n];
int32_t temp;
int16_t test_const = 0x2000;
for (int i = 0 ; i < n ; i++) {
x[i] = i << 4;
temp = (int32_t)x[i] * (int32_t)test_const;
y[i] = temp >> 15;
}
dsps_mulc_s16_ansi(x, x, n, test_const, 1, 1);
for (int i = 0 ; i < n ; i++) {
if (x[i] != y[i]) {
TEST_ASSERT_EQUAL(x[i], y[i]);
}
}
}
TEST_CASE("dsps_mulc_s16 benchmark", "[dsps]")
{
const int n = 256;
int16_t x[n];
for (int i = 0 ; i < n ; i++) {
x[i] = i << 4;
}
unsigned int start_b = dsp_get_cpu_cycle_count();
dsps_mulc_s16_ansi(x, x, n, 10, 1, 1);
unsigned int end_b = dsp_get_cpu_cycle_count();
float cycles = end_b - start_b;
ESP_LOGI(TAG, "dsps_mulc_f32 - %f cycles per sample \n", cycles);
}