-
Notifications
You must be signed in to change notification settings - Fork 287
Add shift by multiple constant #1220
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
Draft
AntoinePrv
wants to merge
17
commits into
xtensor-stack:master
Choose a base branch
from
AntoinePrv:shift-var
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.
Draft
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
62fd989
Add bitwise_lshift multiple test
AntoinePrv 26f4b4e
Add AVX2 constant var left shift
AntoinePrv 4e5fe40
Add multiple constant bitwise_lshift sse
AntoinePrv 2e90f58
Add multiple constant bitwise_lshift common
AntoinePrv 17e4b6a
Fix sse2
AntoinePrv cdf4280
Fix common fwd
AntoinePrv 431d801
Fix sse2
AntoinePrv 0b42f50
Fix utils
AntoinePrv 1cd12f9
Fix shift utility
AntoinePrv c89a5ea
Fix Avx2
AntoinePrv 1ce42e9
Remove unused var
AntoinePrv 270a662
Fix typos
AntoinePrv 523bbba
Don't run test on missing architectures
AntoinePrv fb76fd7
Fix test on scalars
AntoinePrv 7cd6920
Fx avx2 build
AntoinePrv 5f32d72
Deactivate xsimd bathc code whrn no arch
AntoinePrv caaab2a
Fix Avx2 if constexpr
AntoinePrv 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 hidden or 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 hidden or 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,71 @@ | ||
| /*************************************************************************** | ||
| * Copyright (c) Johan Mabille, Sylvain Corlay, Wolf Vollprecht and * | ||
| * Martin Renou * | ||
| * Copyright (c) QuantStack * | ||
| * Copyright (c) Serge Guelton * | ||
| * Copyright (c) Marco Barbone * | ||
| * * | ||
| * Distributed under the terms of the BSD 3-Clause License. * | ||
| * * | ||
| * The full license is in the file LICENSE, distributed with this software. * | ||
| ****************************************************************************/ | ||
|
|
||
| #ifndef XSIMD_UTILS_SHIFTS_HPP | ||
| #define XSIMD_UTILS_SHIFTS_HPP | ||
|
|
||
| #include "xsimd/config/xsimd_inline.hpp" | ||
| #include "xsimd/types/xsimd_batch.hpp" | ||
|
|
||
| namespace xsimd | ||
| { | ||
| namespace kernel | ||
| { | ||
| namespace utils | ||
| { | ||
| template <typename I, I offset, I length, I... Vs> | ||
| struct select_stride | ||
| { | ||
| static constexpr I values_array[] = { Vs... }; | ||
|
|
||
| template <typename K> | ||
| static constexpr K get(K i, K) | ||
| { | ||
| return static_cast<K>(values_array[length * i + offset]); | ||
| } | ||
| }; | ||
|
|
||
| template <typename I> | ||
| constexpr I lsb_mask(I bit_index) | ||
| { | ||
| return static_cast<I>((I { 1 } << bit_index) - I { 1 }); | ||
| } | ||
|
|
||
| template <class T, class T2, class A, T... Vs> | ||
| XSIMD_INLINE batch<T, A> bitwise_lshift_as_twice_larger( | ||
| batch<T, A> const& self, batch_constant<T, A, Vs...>) noexcept | ||
| { | ||
| static_assert(sizeof(T2) == 2 * sizeof(T), "One size must be twice the other"); | ||
|
|
||
| const auto self2 = bitwise_cast<T2>(self); | ||
|
|
||
| // Lower byte: shift as twice the size and mask bits flowing to higher byte. | ||
| constexpr auto shifts_lo = make_batch_constant<T2, select_stride<T, 0, 2, Vs...>, A>(); | ||
| constexpr auto mask_lo = lsb_mask<T2>(8 * sizeof(T)); | ||
| const auto shifted_lo = bitwise_lshift(self2, shifts_lo); | ||
| const batch<T2, A> batch_mask_lo { mask_lo }; | ||
| const auto masked_lo = bitwise_and(shifted_lo, batch_mask_lo); | ||
|
|
||
| // Higher byte: mask bits that would flow from lower byte and shift as twice the size. | ||
| constexpr auto shifts_hi = make_batch_constant<T2, select_stride<T, 1, 2, Vs...>, A>(); | ||
| constexpr auto mask_hi = mask_lo << (8 * sizeof(T)); | ||
| const batch<T2, A> batch_mask_hi { mask_hi }; | ||
| const auto masked_hi = bitwise_and(self2, batch_mask_hi); | ||
| const auto shifted_hi = bitwise_lshift(masked_hi, shifts_hi); | ||
|
|
||
| return bitwise_cast<T>(bitwise_or(masked_lo, shifted_hi)); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #endif |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
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.
I named this
utilascommonseems to be more used for implementing thecommonarchitecture.