-
Notifications
You must be signed in to change notification settings - Fork 83
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
Antoine-V74
wants to merge
23
commits into
esl-epfl:main
Choose a base branch
from
Antoine-V74:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
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 bd714cb
DSP abs_f32
Antoine-V74 923982d
DSP n1
Antoine-V74 8f0678e
Merge branch 'main' of https://github.com/Antoine-V74/x-heep into main
Antoine-V74 6640d2e
Delete sw/applications/example_dsp/riscv_abs_f32
Antoine-V74 0a1ee3f
DSP n2
Antoine-V74 90823ed
Merge branch 'main' of https://github.com/Antoine-V74/x-heep into main
Antoine-V74 9203a9c
first commit
Antoine-V74 fb64104
Merge branch 'main' of https://github.com/Antoine-V74/x-heep into main
Antoine-V74 11216b0
dsp functions added
Antoine-V74 f171f5d
remove tests func
Antoine-V74 4609570
End of Basic fucntions
Antoine-V74 2d96903
Dsp Basic Math Functions
Antoine-V74 7ca1fc6
Complex functions
Antoine-V74 532973e
every functions modified so far, some of the filtering folder need to…
Antoine-V74 71e699c
new functions tested
Antoine-V74 aeabfda
Merge branch 'esl-epfl:main' into main
Antoine-V74 d4fba88
cmake modification
Antoine-V74 24eebc4
Merge branch 'main' of https://github.com/Antoine-V74/x-heep into main
Antoine-V74 0a191ba
Merge branch 'esl-epfl:main' into main
Antoine-V74 dbbe362
Merge branch 'main' of https://github.com/Antoine-V74/x-heep into main
Antoine-V74 14f369c
Last adjustments
Antoine-V74 053ea82
last modifications
Antoine-V74 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include "/home/antoine/FORKs/CMSIS-DSP-PULPino/inc/riscv_math.h" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
*/ | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing license -