Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DSP basic_maths_functions #476

Draft
wants to merge 23 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
acfcdcb
DSP example abs_f32
Antoine-V74 Mar 21, 2024
bd714cb
DSP abs_f32
Antoine-V74 Mar 21, 2024
923982d
DSP n1
Antoine-V74 Mar 21, 2024
8f0678e
Merge branch 'main' of https://github.com/Antoine-V74/x-heep into main
Antoine-V74 Mar 21, 2024
6640d2e
Delete sw/applications/example_dsp/riscv_abs_f32
Antoine-V74 Mar 21, 2024
0a1ee3f
DSP n2
Antoine-V74 Mar 22, 2024
90823ed
Merge branch 'main' of https://github.com/Antoine-V74/x-heep into main
Antoine-V74 Mar 22, 2024
9203a9c
first commit
Antoine-V74 Mar 25, 2024
fb64104
Merge branch 'main' of https://github.com/Antoine-V74/x-heep into main
Antoine-V74 Mar 27, 2024
11216b0
dsp functions added
Antoine-V74 Mar 27, 2024
f171f5d
remove tests func
Antoine-V74 Mar 27, 2024
4609570
End of Basic fucntions
Antoine-V74 Mar 27, 2024
2d96903
Dsp Basic Math Functions
Antoine-V74 Apr 18, 2024
7ca1fc6
Complex functions
Antoine-V74 Apr 20, 2024
532973e
every functions modified so far, some of the filtering folder need to…
Antoine-V74 May 16, 2024
71e699c
new functions tested
Antoine-V74 May 19, 2024
aeabfda
Merge branch 'esl-epfl:main' into main
Antoine-V74 May 31, 2024
d4fba88
cmake modification
Antoine-V74 May 31, 2024
24eebc4
Merge branch 'main' of https://github.com/Antoine-V74/x-heep into main
Antoine-V74 May 31, 2024
0a191ba
Merge branch 'esl-epfl:main' into main
Antoine-V74 Jun 7, 2024
dbbe362
Merge branch 'main' of https://github.com/Antoine-V74/x-heep into main
Antoine-V74 Jun 7, 2024
14f369c
Last adjustments
Antoine-V74 Jun 25, 2024
053ea82
last modifications
Antoine-V74 Jun 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions sw/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ FOREACH(file_path ${new_list})
SET(add 1)
elseif( ${file_path} MATCHES "${SOURCE_PATH}external/" )
SET(add 1)
elseif( ${file_path} MATCHES "${SOURCE_PATH}dsp/inc/" )
SET(add 1)
endif()

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Expand Down Expand Up @@ -140,6 +142,8 @@ FOREACH(file_path IN LISTS new_list)
SET(app_found 1)
elseif( ${file_path} MATCHES "${SOURCE_PATH}applications/${PROJECT}/" ) # other sources
SET(add 1)
elseif( ${file_path} MATCHES "${SOURCE_PATH}dsp/" )
SET(add 1)
endif()

if( add EQUAL 1 ) # If the file path matched one of the criteria, add it to the list
Expand Down
Binary file added sw/applications/example_dsp/main
Binary file not shown.
130 changes: 130 additions & 0 deletions sw/applications/example_dsp/riscv_sub_q7.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#include <stdio.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing license -

#include <stdlib.h>
#include "/home/antoine/FORKs/CMSIS-DSP-PULPino/inc/riscv_math.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should not use absolute path

#include "/home/antoine/FORKs/CMSIS-DSP-PULPino/inc/x_heep_emul.h"
// HAD RO MODIFY THE X_HEEP_EMUL FILE AND ADD ADD2v
int main(int argc, char *argv[])
{
/*
void perf_enable_id( int eventid){
cpu_perf_conf_events(SPR_PCER_EVENT_MASK(eventid));
cpu_perf_conf(SPR_PCMR_ACTIVE | SPR_PCMR_SATURATE);
};
*/
#define PRINT_F32(X,Y) printf("\n"); for(int i =0 ; i < (Y); i++) printf("%d ",(int)(X[i]*100)); \
printf("\n\n")
#define PRINT_Q(X,Y) printf("\n"); for(int i =0 ; i < (Y); i++) printf("0x%X ",X[i]); \
printf("\n\n")
//#define PRINT_OUTPUT /*for testing functionality for each function, removed while benchmarking*/
#define MAX_BLOCKSIZE 32
#define EVENT_ID 0x00 /*number of cycles ID for benchmarking*/
q7_t result_q7[MAX_BLOCKSIZE];
q7_t srcA_buf_q7[MAX_BLOCKSIZE] =
{
0x75, 0x13, 0x15,
0x44, 0x11, 0x1C,
0x52, 0x0B, 0x83,
0x91, 0x33, 0x25,
0x1A, 0x4D, 0x6F,
0x26, 0x01, 0xF1,
0xAC, 0x66, 0x76,
0x54, 0x87, 0x36,
0x22, 0x33, 0xE1,
0x61, 0x54, 0x35,
0x91, 0x49
};

q7_t srcB_buf_q7[MAX_BLOCKSIZE] =
{
0x75, 0x13, 0x15,
0x44, 0x11, 0x1C,
0x52, 0x0B, 0x83,
0x91, 0x33, 0x25,
0x1A, 0x4D, 0x6F,
0x26, 0x01, 0xF1,
0xAC, 0x66, 0x76,
0x54, 0x87, 0x36,
0x22, 0x33, 0xE1,
0x61, 0x54, 0x35,
0x91, 0x49
};

void riscv_sub_q7(
q7_t * pSrcA,
q7_t * pSrcB,
q7_t * pDst,
uint32_t blockSize)
{
uint32_t blkCnt; /* loop counter */


#if defined (USE_DSP_RISCV)

shortV VectInA;
shortV VectInB;
shortV VectInC;
/*loop Unrolling */
blkCnt = blockSize >> 1u;

while (blkCnt > 0u)
{
/*read 2 elements from each source*/
VectInA[0] = (short)pSrcA[0];
VectInA[1] = (short)pSrcA[1];
VectInB[0] = (short)pSrcB[0];
VectInB[1] = (short)pSrcB[1];
/*subract them*/
VectInC = x_heep_sub2(VectInA,VectInB);
/*saturate the results then save to destination buufer*/
*pDst++ =(q7_t)x_heep_clip(VectInC[0],7);
*pDst++ =(q7_t)x_heep_clip(VectInC[1],7);
/*increment source buffer*/
pSrcA+=2;
pSrcB+=2;
/*decrement loop counter*/
blkCnt--;
}

blkCnt = blockSize % 0x2u;

while (blkCnt > 0u)
{
/* C = A + B */
/* subtract then saturate*/
*pDst++ =(q7_t)x_heep_clip((*pSrcA++ - *pSrcB++),7);
/* Decrement the loop counter */
blkCnt--;
}

#else

/* Initialize blkCnt with number of samples */
blkCnt = blockSize;

while(blkCnt > 0u)
{
/* C = A - B */
/* Subtract and then store the result in the destination buffer. */
*pDst++ = (q7_t) __SSAT((q15_t) * pSrcA++ - *pSrcB++, 8);

/* Decrement the loop counter */
blkCnt--;
}
#endif
}



riscv_sub_q7(srcA_buf_q7, srcB_buf_q7, result_q7, MAX_BLOCKSIZE);
PRINT_Q(result_q7,MAX_BLOCKSIZE);
printf("\nCorrect answer:\n");
printf("0x7F 0x26 0x2A 0x7F 0x22 0x38 0x7F 0x16 0x80 0x80 0x66 0x4A 0x34 0x7F 0x7F 0x4C 0x2 0xE2 0x80 0x7F 0x7F 0x7F 0x80 0x6C 0x44 0x66 0xC2 0x7F 0x7F 0x6A 0x80 0x7F");
printf("\n");
printf("hello world!\n");
return EXIT_SUCCESS;
}





167 changes: 167 additions & 0 deletions sw/dsp/Basic_maths/riscv_abs_f32.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
/* ----------------------------------------------------------------------
* Copyright (C) 2010-2014 ARM Limited. All rights reserved.
*
* $Date: 19. March 2015
* $Revision: V.1.4.5
*
* Project: CMSIS DSP Library
* Title: arm_abs_f32.c
*
* Description: Vector absolute value.
*
* Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* - Neither the name of ARM LIMITED nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.

Modifications 2017 Mostafa Saleh (Ported to RISC-V PULPino)
Modifications 2024 ESL
* ---------------------------------------------------------------------------- */

#include "riscv_math.h"
#include <math.h>

/**
* @ingroup groupMath
*/

/**
* @defgroup BasicAbs Vector Absolute Value
*
* Computes the absolute value of a vector on an element-by-element basis.
*
* <pre>
* pDst[n] = abs(pSrc[n]), 0 <= n < blockSize.
* </pre>
*
* The functions support in-place computation allowing the source and
* destination pointers to reference the same memory buffer.
* There are separate functions for floating-point, Q7, Q15, and Q31 data types.
*/

/**
* @addtogroup BasicAbs
* @{
*/

/**
* @brief Floating-point vector absolute value.
* @param[in] *pSrc points to the input buffer
* @param[out] *pDst points to the output buffer
* @param[in] blockSize number of samples in each vector
* @return none.
*/

void riscv_abs_f32(
float32_t * pSrc,
float32_t * pDst,
uint32_t blockSize)
{
uint32_t blkCnt; /* loop counter */

#if defined (USE_DSP_RISCV)

float32_t in1, in2, in3, in4; /* temporary variables */

/*loop Unrolling */
blkCnt = blockSize >> 2u;

/* First part of the processing with loop unrolling. Compute 4 outputs at a time.
** a second loop below computes the remaining 1 to 3 samples. */
while (blkCnt > 0u)
{
/* C = |A| */
/* Calculate absolute and then store the results in the destination buffer. */
/* read sample from source */
in1 = *pSrc;
in2 = *(pSrc + 1);
in3 = *(pSrc + 2);

/* find absolute value */
in1 = fabsf(in1);

/* read sample from source */
in4 = *(pSrc + 3);

/* find absolute value */
in2 = fabsf(in2);

/* read sample from source */
*pDst = in1;

/* find absolute value */
in3 = fabsf(in3);

/* find absolute value */
in4 = fabsf(in4);

/* store result to destination */
*(pDst + 1) = in2;

/* store result to destination */
*(pDst + 2) = in3;

/* store result to destination */
*(pDst + 3) = in4;


/* Update source pointer to process next sampels */
pSrc += 4u;

/* Update destination pointer to process next sampels */
pDst += 4u;

/* Decrement the loop counter */
blkCnt--;
}

/* If the blockSize is not a multiple of 4, compute any remaining output samples here.
** No loop unrolling is used. */
blkCnt = blockSize % 0x4u;

#else

/* Initialize blkCnt with number of samples */
blkCnt = blockSize;

#endif

while(blkCnt > 0u)
{
/* C = |A| */
/* Calculate absolute and then store the results in the destination buffer. */
*pDst++ = fabsf(*pSrc++);

/* Decrement the loop counter */
blkCnt--;
}
}

/**
* @} end of BasicAbs group
*/


Loading