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

Right shift operation not working #62

Open
NK-Nikunj opened this issue Mar 20, 2020 · 2 comments
Open

Right shift operation not working #62

NK-Nikunj opened this issue Mar 20, 2020 · 2 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@NK-Nikunj
Copy link

Issue type: Error

While utilizing the Right shift and Left shift bitwise operators, I'm getting an error:

/home/nk/opt/nsimd/include/nsimd/cxx_adv_api_functions.hpp:998:16: error: no matching function for call to ‘shr(const simd_vector&, int&, float, nsimd::cpu)’
  998 |   ret.car = shr(a0.car, a1, T(), SimdExt());

Reproducing the error

Here is the minimal program to reproduce the issue:

#include <iostream>
#include <nsimd/nsimd-all.hpp>

int main()
{
    nsimd::pack<float> f(42.0f);
    nsimd::pack<float> f2 = nsimd::shr(f2, 1);

    std::cout << f2 << std::endl;

    return 0;
}

Is there something I'm doing wrong?

Expected behavior

Essentially I wish to change a simd vector, say [1, 2, 3, 4] to look like [0,1,2,3] using the right shift operation.

@gquintin gquintin added enhancement New feature or request question Further information is requested labels Mar 24, 2020
@gquintin
Copy link
Contributor

Hi NK-Nikunj,

The error you are facing is the expected behavior of NSIMD. Let me give you details: the shr, shl and shra operators work on integer types only (hence the error) and work element-wise. I mean that

v = [1 ; 2 ; 3 ; 4]
v << n == [1 << n ; 2 << n ; 3 << n ; 4 << n]

From what you describe, what you want is a shuffle but we do not have this one yet. Moreover I have questions for you on what you want exactly :

  • Do you want this shuffle to work on a 4-elements basis i mean given v = [1 ; 2 ; 3 ; 4 ; 5 ; 6 ; 7 ; 8 ]:

    shuffle(v, 1) = [ 2 ; 3 ; 4 ; 1 ; 6 ; 7 ; 8 ; 5 ]
    

    or

    shuffle(v, 1) = [ 2 ; 3 ; 4 ; 5 ; 6 ; 7 ; 8 ; 1 ]
    

    ?

  • Do you want it only a 4-elements SIMD vectors? Do your algorithm have this constraint? Do you want it to be length agnostic?

I am asking you these according to #8, there are two ways to have shuffles length angostic.

@NK-Nikunj
Copy link
Author

@gquintin I want it to be length agnostic. My apologies, I should've seen this comment before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants