-
Notifications
You must be signed in to change notification settings - Fork 110
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
Basic math and bitwise operators #154
Open
tcptomato
wants to merge
6
commits into
parallella:master
Choose a base branch
from
tcptomato:math_ops
base: master
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.
Open
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
28a3570
Wrote the sum and sum square functions as a template and added instan…
2d83de3
Added restrict keyword on the input vector.
207f875
Fixed description for scalar function.
b81ca3d
Vector-vector and vector-scalar basic math operations implemented as …
90e0cfc
Bitwise logic operator templates/instances for all suported types.
9591a95
Fixed missing index in output vector.
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
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,83 @@ | ||
#include <pal.h> | ||
|
||
/** | ||
* | ||
* Element wise vector 'bitwise and' between input vectors 'a' and 'b' | ||
* | ||
* @param a Pointer to first input vector | ||
* | ||
* @param b Pointer to second input vector | ||
* | ||
* @param c Pointer to output vector | ||
* | ||
* @param n Size of 'a' and 'c' vector. | ||
* | ||
* @param p Number of processor to use (task parallelism) | ||
* | ||
* @param team Team to work with | ||
* | ||
* @return None | ||
* | ||
*/ | ||
|
||
#define GEN_FUNC_AND(NAME,TYPE) \ | ||
/** NAME TYPE */ \ | ||
void NAME(const TYPE * restrict a, const TYPE * restrict b, TYPE * restrict c, int n) \ | ||
{ \ | ||
*(c) = *(a) & *(b); \ | ||
for (;--n;) \ | ||
*(c + n) = *(a + n) & *(b + n); \ | ||
} | ||
|
||
GEN_FUNC_AND(p_and_int8,int8_t); | ||
GEN_FUNC_AND(p_and_uint8,uint8_t); | ||
|
||
GEN_FUNC_AND(p_and_int16,int16_t); | ||
GEN_FUNC_AND(p_and_uint16,uint16_t); | ||
|
||
GEN_FUNC_AND(p_and_int32,int32_t); | ||
GEN_FUNC_AND(p_and_uint32,uint32_t); | ||
|
||
GEN_FUNC_AND(p_and_int64,int64_t); | ||
GEN_FUNC_AND(p_and_uint64,uint64_t); | ||
|
||
/** | ||
* | ||
* Element wise vector 'bitwise and' between input vector 'a' and scalar 'b' | ||
* | ||
* @param a Pointer to input vector | ||
* | ||
* @param b Pointer to input scalar | ||
* | ||
* @param c Pointer to output vector | ||
* | ||
* @param n Size of 'a' and 'c' vector. | ||
* | ||
* @param p Number of processor to use (task parallelism) | ||
* | ||
* @param team Team to work with | ||
* | ||
* @return None | ||
* | ||
*/ | ||
|
||
#define GEN_FUNC_ANDS(NAME,TYPE) \ | ||
/** NAME TYPE */ \ | ||
void NAME(const TYPE * restrict a, const TYPE * restrict b, TYPE * restrict c, int n) \ | ||
{ \ | ||
*(c) = *(a) & *(b); \ | ||
for (;--n;) \ | ||
*(c + n) = *(a + n) & *(b); \ | ||
} | ||
|
||
GEN_FUNC_ANDS(p_ands_int8,int8_t); | ||
GEN_FUNC_ANDS(p_ands_uint8,uint8_t); | ||
|
||
GEN_FUNC_ANDS(p_ands_int16,int16_t); | ||
GEN_FUNC_ANDS(p_ands_uint16,uint16_t); | ||
|
||
GEN_FUNC_ANDS(p_ands_int32,int32_t); | ||
GEN_FUNC_ANDS(p_ands_uint32,uint32_t); | ||
|
||
GEN_FUNC_ANDS(p_ands_int64,int64_t); | ||
GEN_FUNC_ANDS(p_ands_uint64,uint64_t); |
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
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
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,41 @@ | ||
#include <pal.h> | ||
|
||
/** | ||
* | ||
* Element wise vector 'bitwise not' of input vector 'a' | ||
* | ||
* @param a Pointer to input vector | ||
* | ||
* @param c Pointer to output vector | ||
* | ||
* @param n Size of 'a' and 'c' vector. | ||
* | ||
* @param p Number of processor to use (task parallelism) | ||
* | ||
* @param team Team to work with | ||
* | ||
* @return None | ||
* | ||
*/ | ||
|
||
#define GEN_FUNC(NAME,TYPE) \ | ||
/** NAME TYPE */ \ | ||
void NAME(const TYPE * restrict a, TYPE * restrict c, int n) \ | ||
{ \ | ||
*c = ~*(a); \ | ||
for (;--n;) \ | ||
*c = ~*(a + n); \ | ||
} | ||
|
||
|
||
GEN_FUNC(p_not_int8,int8_t); | ||
GEN_FUNC(p_not_uint8,uint8_t); | ||
|
||
GEN_FUNC(p_not_int16,int16_t); | ||
GEN_FUNC(p_not_uint16,uint16_t); | ||
|
||
GEN_FUNC(p_not_int32,int32_t); | ||
GEN_FUNC(p_not_uint32,uint32_t); | ||
|
||
GEN_FUNC(p_not_int64,int64_t); | ||
GEN_FUNC(p_not_uint64,uint64_t); |
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.
*(c + n) = ~*(a + n); \
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.
@mateunho Thanks, fixed.
@aolofsson Yes, loops are very shallow ( will look into the possibility of using a duff's device to do some unrolling, or if -funroll-all-loops can be used without pigging out on size). Also I noticed it can be counterproductive to have a decreasing index.
What I think we should do now is to define a number of platforms we want to target and the compiler flags we want to use ( O2 or O3, and more importantly on x86 the SSE flags. Or should we split x86 in 2 ).
What is the preferred method of implementing platform specific code? #ifdef tree?